From b94a12b91086ea004d9b78fa8a14fd4726af9e76 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 6 Mar 2020 15:46:35 -0500 Subject: Wave intrinsics for Vector and Matrix types (#1262) * Update slang-binaries to verison with SPIR-V version support. * Support vec and matrix Wave intrinsics on vk. Added wave-vector.slang test Add wave-diverge.slang test Add support for more wave intrinsics to vk. * Test out Wave intrinsic support for matrices. * Remove matrix glsl intrinsics -> not available. Fix some typo. --- tests/hlsl-intrinsic/wave-active-product.slang | 2 +- tests/hlsl-intrinsic/wave-diverge.slang | 26 +++++++++++++++ .../hlsl-intrinsic/wave-diverge.slang.expected.txt | 4 +++ tests/hlsl-intrinsic/wave-matrix.slang | 37 ++++++++++++++++++++++ .../hlsl-intrinsic/wave-matrix.slang.expected.txt | 8 +++++ tests/hlsl-intrinsic/wave-vector.slang | 29 +++++++++++++++++ .../hlsl-intrinsic/wave-vector.slang.expected.txt | 8 +++++ tests/hlsl-intrinsic/wave.slang | 2 +- 8 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 tests/hlsl-intrinsic/wave-diverge.slang create mode 100644 tests/hlsl-intrinsic/wave-diverge.slang.expected.txt create mode 100644 tests/hlsl-intrinsic/wave-matrix.slang create mode 100644 tests/hlsl-intrinsic/wave-matrix.slang.expected.txt create mode 100644 tests/hlsl-intrinsic/wave-vector.slang create mode 100644 tests/hlsl-intrinsic/wave-vector.slang.expected.txt (limited to 'tests') diff --git a/tests/hlsl-intrinsic/wave-active-product.slang b/tests/hlsl-intrinsic/wave-active-product.slang index 351df1635..ca3fdcb77 100644 --- a/tests/hlsl-intrinsic/wave-active-product.slang +++ b/tests/hlsl-intrinsic/wave-active-product.slang @@ -2,7 +2,7 @@ //DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute //TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute //TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer outputBuffer; diff --git a/tests/hlsl-intrinsic/wave-diverge.slang b/tests/hlsl-intrinsic/wave-diverge.slang new file mode 100644 index 000000000..ab83a1553 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-diverge.slang @@ -0,0 +1,26 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = int(dispatchThreadID.x); + + int value = 0; + + if (idx == 2) + { + // diverge + return; + } + + value = WaveActiveMin(idx + 1); + + outputBuffer[idx] = value; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-diverge.slang.expected.txt b/tests/hlsl-intrinsic/wave-diverge.slang.expected.txt new file mode 100644 index 000000000..68b8a88e2 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-diverge.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +0 +1 diff --git a/tests/hlsl-intrinsic/wave-matrix.slang b/tests/hlsl-intrinsic/wave-matrix.slang new file mode 100644 index 000000000..022182164 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-matrix.slang @@ -0,0 +1,37 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(8, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + const int idx = int(dispatchThreadID.x); + + // NOTE! dxc only supports bit ops on uint and associated types NOT int + // Also GLSL does not have built in support for int matrices. So we'll just try with float for now + // GLSL does not support matrix types for Wave like intrinsics + + matrix v0 = matrix(idx + 1, idx + 2, idx + 3, idx + 4); + matrix v1 = matrix(v0) + matrix(1, 1, 1, 1); + + + matrix uv0 = matrix(v0[0][0], v0[0][1], v0[1][0], v0[0][1]); + + matrix r0 = WaveActiveSum(v0); + matrix r1 = WaveActiveSum(v1); + matrix r2 = WaveActiveBitXor(uv0); + matrix r3 = WaveActiveBitOr(uv0); + matrix r4 = WaveActiveBitAnd(uv0); + + matrix r5 = r2 + r3 + r4; + matrix r6 = matrix(r5[0][0], r5[0][1], r5[1][0], r5[1][1]); + + matrix r = r0 + matrix(r1) + r6; + + outputBuffer[idx] = r[0][0] + r[0][1] + r[1][0] + r[1][1]; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-matrix.slang.expected.txt b/tests/hlsl-intrinsic/wave-matrix.slang.expected.txt new file mode 100644 index 000000000..23f9285c3 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-matrix.slang.expected.txt @@ -0,0 +1,8 @@ +1EC +1EC +1EC +1EC +1EC +1EC +1EC +1EC diff --git a/tests/hlsl-intrinsic/wave-vector.slang b/tests/hlsl-intrinsic/wave-vector.slang new file mode 100644 index 000000000..808f0c5f6 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-vector.slang @@ -0,0 +1,29 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(8, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + const int idx = int(dispatchThreadID.x); + + int2 v0 = int2(idx + 1, idx + 2); + float2 v1 = float2(idx + 2, idx + 3); + // NOTE! dxc only supports bit ops on uint and associated types NOT int + uint2 uv0 = v0; + + int2 r0 = WaveActiveSum(v0); + float2 r1 = WaveActiveSum(v1); + int2 r2 = WaveActiveBitXor(uv0); + int2 r3 = WaveActiveBitOr(uv0); + int2 r4 = WaveActiveBitAnd(uv0); + + int2 r = r0 + int2(r1) + r2 + r3 + r4; + + outputBuffer[idx] = r.x + r.y; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-vector.slang.expected.txt b/tests/hlsl-intrinsic/wave-vector.slang.expected.txt new file mode 100644 index 000000000..eb6984bb6 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-vector.slang.expected.txt @@ -0,0 +1,8 @@ +D6 +D6 +D6 +D6 +D6 +D6 +D6 +D6 diff --git a/tests/hlsl-intrinsic/wave.slang b/tests/hlsl-intrinsic/wave.slang index 9fc9dc26d..d8273080c 100644 --- a/tests/hlsl-intrinsic/wave.slang +++ b/tests/hlsl-intrinsic/wave.slang @@ -2,7 +2,7 @@ //DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute //TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 //TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer outputBuffer; -- cgit v1.2.3