Merge pull request #478 from Sergio0694/dev/missing-intrinsics
Add HLSL Mad intrinsic
このコミットが含まれているのは:
4ファイル変更
+1271
-2
検索条件に一致するファイルはありません
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -1,4 +1,4 @@
|
||||
<#@include file="Hlsl.ttinclude" #>
|
||||
<#@include file="Hlsl.ttinclude" #>
|
||||
using ComputeSharp.Core.Intrinsics.Attributes;
|
||||
using ComputeSharp.Exceptions;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#@include file="Hlsl.MulOverloads.ttinclude" #>
|
||||
<#@include file="Hlsl.MulOverloads.ttinclude" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Text.RegularExpressions" #>
|
||||
@@ -1665,6 +1665,103 @@ var Intrinsics = new[]
|
||||
}
|
||||
},
|
||||
new
|
||||
{
|
||||
Name = "Mad",
|
||||
HlslName = "mad",
|
||||
Summary = "Performs an arithmetic multiply/add operation on three values.",
|
||||
Url = "https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/mad",
|
||||
Parameters = new[]
|
||||
{
|
||||
new { IsOut = false, Name = "m", Info = "The multiplication value." },
|
||||
new { IsOut = false, Name = "a", Info = "The first addition value." },
|
||||
new { IsOut = false, Name = "b", Info = "The second addition value." }
|
||||
},
|
||||
Returns = "The result of {param=m} * {param=a} + {param=b}.",
|
||||
Overloads = new[]
|
||||
{
|
||||
new { Return = "float", Params = new[] { "float", "float", "float" } },
|
||||
new { Return = "Float2", Params = new[] { "Float2", "Float2", "Float2" } },
|
||||
new { Return = "Float3", Params = new[] { "Float3", "Float3", "Float3" } },
|
||||
new { Return = "Float4", Params = new[] { "Float4", "Float4", "Float4" } },
|
||||
new { Return = "Float1x1", Params = new[] { "Float1x1", "Float1x1", "Float1x1" } },
|
||||
new { Return = "Float1x2", Params = new[] { "Float1x2", "Float1x2", "Float1x2" } },
|
||||
new { Return = "Float1x3", Params = new[] { "Float1x3", "Float1x3", "Float1x3" } },
|
||||
new { Return = "Float1x4", Params = new[] { "Float1x4", "Float1x4", "Float1x4" } },
|
||||
new { Return = "Float2x1", Params = new[] { "Float2x1", "Float2x1", "Float2x1" } },
|
||||
new { Return = "Float2x2", Params = new[] { "Float2x2", "Float2x2", "Float2x2" } },
|
||||
new { Return = "Float2x3", Params = new[] { "Float2x3", "Float2x3", "Float2x3" } },
|
||||
new { Return = "Float2x4", Params = new[] { "Float2x4", "Float2x4", "Float2x4" } },
|
||||
new { Return = "Float3x1", Params = new[] { "Float3x1", "Float3x1", "Float3x1" } },
|
||||
new { Return = "Float3x2", Params = new[] { "Float3x2", "Float3x2", "Float3x2" } },
|
||||
new { Return = "Float3x3", Params = new[] { "Float3x3", "Float3x3", "Float3x3" } },
|
||||
new { Return = "Float3x4", Params = new[] { "Float3x4", "Float3x4", "Float3x4" } },
|
||||
new { Return = "Float4x1", Params = new[] { "Float4x1", "Float4x1", "Float4x1" } },
|
||||
new { Return = "Float4x2", Params = new[] { "Float4x2", "Float4x2", "Float4x2" } },
|
||||
new { Return = "Float4x3", Params = new[] { "Float4x3", "Float4x3", "Float4x3" } },
|
||||
new { Return = "Float4x4", Params = new[] { "Float4x4", "Float4x4", "Float4x4" } },
|
||||
new { Return = "double", Params = new[] { "double", "double", "double" } },
|
||||
new { Return = "Double2", Params = new[] { "Double2", "Double2", "Double2" } },
|
||||
new { Return = "Double3", Params = new[] { "Double3", "Double3", "Double3" } },
|
||||
new { Return = "Double4", Params = new[] { "Double4", "Double4", "Double4" } },
|
||||
new { Return = "Double1x1", Params = new[] { "Double1x1", "Double1x1", "Double1x1" } },
|
||||
new { Return = "Double1x2", Params = new[] { "Double1x2", "Double1x2", "Double1x2" } },
|
||||
new { Return = "Double1x3", Params = new[] { "Double1x3", "Double1x3", "Double1x3" } },
|
||||
new { Return = "Double1x4", Params = new[] { "Double1x4", "Double1x4", "Double1x4" } },
|
||||
new { Return = "Double2x1", Params = new[] { "Double2x1", "Double2x1", "Double2x1" } },
|
||||
new { Return = "Double2x2", Params = new[] { "Double2x2", "Double2x2", "Double2x2" } },
|
||||
new { Return = "Double2x3", Params = new[] { "Double2x3", "Double2x3", "Double2x3" } },
|
||||
new { Return = "Double2x4", Params = new[] { "Double2x4", "Double2x4", "Double2x4" } },
|
||||
new { Return = "Double3x1", Params = new[] { "Double3x1", "Double3x1", "Double3x1" } },
|
||||
new { Return = "Double3x2", Params = new[] { "Double3x2", "Double3x2", "Double3x2" } },
|
||||
new { Return = "Double3x3", Params = new[] { "Double3x3", "Double3x3", "Double3x3" } },
|
||||
new { Return = "Double3x4", Params = new[] { "Double3x4", "Double3x4", "Double3x4" } },
|
||||
new { Return = "Double4x1", Params = new[] { "Double4x1", "Double4x1", "Double4x1" } },
|
||||
new { Return = "Double4x2", Params = new[] { "Double4x2", "Double4x2", "Double4x2" } },
|
||||
new { Return = "Double4x3", Params = new[] { "Double4x3", "Double4x3", "Double4x3" } },
|
||||
new { Return = "Double4x4", Params = new[] { "Double4x4", "Double4x4", "Double4x4" } },
|
||||
new { Return = "int", Params = new[] { "int", "int", "int" } },
|
||||
new { Return = "Int2", Params = new[] { "Int2", "Int2", "Int2" } },
|
||||
new { Return = "Int3", Params = new[] { "Int3", "Int3", "Int3" } },
|
||||
new { Return = "Int4", Params = new[] { "Int4", "Int4", "Int4" } },
|
||||
new { Return = "Int1x1", Params = new[] { "Int1x1", "Int1x1", "Int1x1" } },
|
||||
new { Return = "Int1x2", Params = new[] { "Int1x2", "Int1x2", "Int1x2" } },
|
||||
new { Return = "Int1x3", Params = new[] { "Int1x3", "Int1x3", "Int1x3" } },
|
||||
new { Return = "Int1x4", Params = new[] { "Int1x4", "Int1x4", "Int1x4" } },
|
||||
new { Return = "Int2x1", Params = new[] { "Int2x1", "Int2x1", "Int2x1" } },
|
||||
new { Return = "Int2x2", Params = new[] { "Int2x2", "Int2x2", "Int2x2" } },
|
||||
new { Return = "Int2x3", Params = new[] { "Int2x3", "Int2x3", "Int2x3" } },
|
||||
new { Return = "Int2x4", Params = new[] { "Int2x4", "Int2x4", "Int2x4" } },
|
||||
new { Return = "Int3x1", Params = new[] { "Int3x1", "Int3x1", "Int3x1" } },
|
||||
new { Return = "Int3x2", Params = new[] { "Int3x2", "Int3x2", "Int3x2" } },
|
||||
new { Return = "Int3x3", Params = new[] { "Int3x3", "Int3x3", "Int3x3" } },
|
||||
new { Return = "Int3x4", Params = new[] { "Int3x4", "Int3x4", "Int3x4" } },
|
||||
new { Return = "Int4x1", Params = new[] { "Int4x1", "Int4x1", "Int4x1" } },
|
||||
new { Return = "Int4x2", Params = new[] { "Int4x2", "Int4x2", "Int4x2" } },
|
||||
new { Return = "Int4x3", Params = new[] { "Int4x3", "Int4x3", "Int4x3" } },
|
||||
new { Return = "Int4x4", Params = new[] { "Int4x4", "Int4x4", "Int4x4" } },
|
||||
new { Return = "uint", Params = new[] { "uint", "uint", "uint" } },
|
||||
new { Return = "UInt2", Params = new[] { "UInt2", "UInt2", "UInt2" } },
|
||||
new { Return = "UInt3", Params = new[] { "UInt3", "UInt3", "UInt3" } },
|
||||
new { Return = "UInt4", Params = new[] { "UInt4", "UInt4", "UInt4" } },
|
||||
new { Return = "UInt1x1", Params = new[] { "UInt1x1", "UInt1x1", "UInt1x1" } },
|
||||
new { Return = "UInt1x2", Params = new[] { "UInt1x2", "UInt1x2", "UInt1x2" } },
|
||||
new { Return = "UInt1x3", Params = new[] { "UInt1x3", "UInt1x3", "UInt1x3" } },
|
||||
new { Return = "UInt1x4", Params = new[] { "UInt1x4", "UInt1x4", "UInt1x4" } },
|
||||
new { Return = "UInt2x1", Params = new[] { "UInt2x1", "UInt2x1", "UInt2x1" } },
|
||||
new { Return = "UInt2x2", Params = new[] { "UInt2x2", "UInt2x2", "UInt2x2" } },
|
||||
new { Return = "UInt2x3", Params = new[] { "UInt2x3", "UInt2x3", "UInt2x3" } },
|
||||
new { Return = "UInt2x4", Params = new[] { "UInt2x4", "UInt2x4", "UInt2x4" } },
|
||||
new { Return = "UInt3x1", Params = new[] { "UInt3x1", "UInt3x1", "UInt3x1" } },
|
||||
new { Return = "UInt3x2", Params = new[] { "UInt3x2", "UInt3x2", "UInt3x2" } },
|
||||
new { Return = "UInt3x3", Params = new[] { "UInt3x3", "UInt3x3", "UInt3x3" } },
|
||||
new { Return = "UInt3x4", Params = new[] { "UInt3x4", "UInt3x4", "UInt3x4" } },
|
||||
new { Return = "UInt4x1", Params = new[] { "UInt4x1", "UInt4x1", "UInt4x1" } },
|
||||
new { Return = "UInt4x2", Params = new[] { "UInt4x2", "UInt4x2", "UInt4x2" } },
|
||||
new { Return = "UInt4x3", Params = new[] { "UInt4x3", "UInt4x3", "UInt4x3" } },
|
||||
new { Return = "UInt4x4", Params = new[] { "UInt4x4", "UInt4x4", "UInt4x4" } }
|
||||
}
|
||||
},
|
||||
new
|
||||
{
|
||||
Name = "Max",
|
||||
HlslName = "max",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Tests.Attributes;
|
||||
using ComputeSharp.Tests.Extensions;
|
||||
@@ -771,4 +772,55 @@ public partial class ShaderRewriterTests
|
||||
destination[ThreadIds.X] = source[ThreadIds.X].AddAndGetSum(ThreadIds.X + 1);
|
||||
}
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void MiscHlslIntrinsics(Device device)
|
||||
{
|
||||
float[] data1 = { 1, 2, 0.4f, 3.14f, 2.4f, 0.8f, 0, 0 };
|
||||
int[] data2 = { 111, 222, 333, 2, 4, 8, 63, 42, 77, 0, 0, 0 };
|
||||
|
||||
using ReadWriteBuffer<float> buffer1 = device.Get().AllocateReadWriteBuffer(data1);
|
||||
using ReadWriteBuffer<int> buffer2 = device.Get().AllocateReadWriteBuffer(data2);
|
||||
|
||||
device.Get().For(1, new MiscHlslIntrinsicsShader(buffer1, buffer2));
|
||||
|
||||
float[] results1 = buffer1.ToArray();
|
||||
int[] results2 = buffer2.ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(
|
||||
expected: new[] { 1, 2, 0.4f, 3.14f, 2.4f, 0.8f, 2.8f, 7.08f },
|
||||
actual: results1,
|
||||
comparer: Comparer<float>.Create(static (x, y) => Math.Abs(x - y) < 0.000001f ? 0 : x.CompareTo(y)));
|
||||
|
||||
CollectionAssert.AreEqual(
|
||||
expected: new[] { 111, 222, 333, 2, 4, 8, 63, 42, 77, 285, 930, 2741 },
|
||||
actual: results2);
|
||||
}
|
||||
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct MiscHlslIntrinsicsShader : IComputeShader
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer1;
|
||||
public readonly ReadWriteBuffer<int> buffer2;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
float2 f1 = new(buffer1[0], buffer1[1]);
|
||||
float2 f2 = new(buffer1[2], buffer1[3]);
|
||||
float2 f3 = new(buffer1[4], buffer1[5]);
|
||||
int3 i1 = new(buffer2[0], buffer2[1], buffer2[2]);
|
||||
int3 i2 = new(buffer2[3], buffer2[4], buffer2[5]);
|
||||
int3 i3 = new(buffer2[6], buffer2[7], buffer2[8]);
|
||||
|
||||
float2 r1 = Hlsl.Mad(f1, f2, f3);
|
||||
int3 r2 = Hlsl.Mad(i1, i2, i3);
|
||||
|
||||
buffer1[6] = r1.X;
|
||||
buffer1[7] = r1.Y;
|
||||
buffer2[9] = r2.X;
|
||||
buffer2[10] = r2.Y;
|
||||
buffer2[11] = r2.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする