summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-01-22 11:58:40 -0500
committerGitHub <noreply@github.com>2025-01-22 08:58:40 -0800
commit18f12ad9c999f672ae7b61878e2242ebb3da94ac (patch)
tree76ff4bac892d7055a05df772955d403764727cab
parent14211ec3c4e56e59f479dbac23123ea61eab7d91 (diff)
Use SPIRV integer vector dot product instructions (#6141)
* Use SPIRV integer vector dot product instructions * fix test --------- Co-authored-by: Yong He <yonghe@outlook.com>
-rw-r--r--source/slang/hlsl.meta.slang24
-rw-r--r--tests/hlsl-intrinsic/vector-dot-int.slang45
-rw-r--r--tests/hlsl-intrinsic/vector-dot-int.slang.expected.txt9
3 files changed, 62 insertions, 16 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 371659fc9..97e2c7be5 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -8292,6 +8292,30 @@ T dot(vector<T, N> x, vector<T, N> y)
{
case hlsl: __intrinsic_asm "dot";
case wgsl: __intrinsic_asm "dot";
+ case spirv:
+ {
+ spirv_asm
+ {
+ OpCapability DotProduct;
+ OpCapability DotProductInputAll;
+ OpExtension "SPV_KHR_integer_dot_product";
+ };
+
+ if (__isSignedInt<T>())
+ {
+ return spirv_asm
+ {
+ result:$$T = OpSDot $x $y;
+ };
+ }
+ else
+ {
+ return spirv_asm
+ {
+ result:$$T = OpUDot $x $y;
+ };
+ }
+ }
default:
T result = T(0);
for(int i = 0; i < N; ++i)
diff --git a/tests/hlsl-intrinsic/vector-dot-int.slang b/tests/hlsl-intrinsic/vector-dot-int.slang
index 922bd001d..db0d0e5db 100644
--- a/tests/hlsl-intrinsic/vector-dot-int.slang
+++ b/tests/hlsl-intrinsic/vector-dot-int.slang
@@ -1,8 +1,12 @@
-//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -shaderobj
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
+
+// No 16-bit and 64-bit integer support on DX11.
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type -xslang -DDX11
+
+//TEST(compute, vulkan):SIMPLE(filecheck=CHECK_SPV): -stage compute -entry computeMain -target spirv
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<int> outputBuffer;
@@ -10,14 +14,31 @@ RWStructuredBuffer<int> outputBuffer;
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
- int idx = int(dispatchThreadID.x);
+ int index = int(dispatchThreadID.x);
+ uint outIndex = 0;
- float tmp = dot(float3(idx), float3(1));
-
- int3 a = { idx + 1, idx + 2, idx + 3};
+ // CHECK_SPV: OpSDot
+ int3 a = { index - 1, index - 2, index - 3};
int3 b = { 1, 2, 3};
+ outputBuffer[outIndex++] = dot(a, b);
+
+ // CHECK_SPV: OpUDot
+ uint3 c = { index + 1, index + 2, index + 3};
+ uint3 d = { 2, 4, 6};
+ outputBuffer[outIndex++] = int(dot(c, d));
- int result = dot(a, b);
+#if !defined(DX11)
+ // CHECK_SPV: OpUDot
+ uint64_t2 e = { index + 1, index + 2};
+ uint64_t2 f = { 4, 8};
+ outputBuffer[outIndex++] = int(dot(e, f));
- outputBuffer[idx] = result;
-} \ No newline at end of file
+ // CHECK_SPV: OpSDot
+ int16_t4 g = { int16_t(index + 1), int16_t(index + 2), int16_t(index + 3), int16_t(index + 4)};
+ int16_t4 h = { -1, 2, 2, -1};
+ outputBuffer[outIndex++] = int(dot(g, h));
+#else
+ outputBuffer[outIndex++] = 20;
+ outputBuffer[outIndex++] = 5;
+#endif
+}
diff --git a/tests/hlsl-intrinsic/vector-dot-int.slang.expected.txt b/tests/hlsl-intrinsic/vector-dot-int.slang.expected.txt
index 18ff54819..ce9de1d20 100644
--- a/tests/hlsl-intrinsic/vector-dot-int.slang.expected.txt
+++ b/tests/hlsl-intrinsic/vector-dot-int.slang.expected.txt
@@ -1,4 +1,5 @@
-E
-0
-0
-0 \ No newline at end of file
+type: int32_t
+-14
+28
+20
+5