From e267ce24e37b9b7f98921f75abc150c1463b1d6d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 27 Mar 2020 16:16:27 -0400 Subject: Adds WaveShuffle intrinsic (#1298) * Support for WaveReadLaneAt with dynamic (but uniform across Wave) on Vk by enabling VK1.4. Fixed wave-lane-at.slang test to test with laneId that is uniform across the Wave. * Added WaveShuffle intrinsic. Test for WaveShuffle intrinsic. * Added some documentation on WaveShuffle * Fix that version required for subgroupBroadcast to be non constexpr is actually 1.5 --- tests/hlsl-intrinsic/wave-lane-at-vk.slang | 2 +- tests/hlsl-intrinsic/wave-lane-at.slang | 2 +- tests/hlsl-intrinsic/wave-shuffle-vk.slang | 33 +++++++++++++++++ .../wave-shuffle-vk.slang.expected.txt | 4 +++ tests/hlsl-intrinsic/wave-shuffle.slang | 42 ++++++++++++++++++++++ .../hlsl-intrinsic/wave-shuffle.slang.expected.txt | 4 +++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/hlsl-intrinsic/wave-shuffle-vk.slang create mode 100644 tests/hlsl-intrinsic/wave-shuffle-vk.slang.expected.txt create mode 100644 tests/hlsl-intrinsic/wave-shuffle.slang create mode 100644 tests/hlsl-intrinsic/wave-shuffle.slang.expected.txt (limited to 'tests') diff --git a/tests/hlsl-intrinsic/wave-lane-at-vk.slang b/tests/hlsl-intrinsic/wave-lane-at-vk.slang index 137632f16..0d52f781e 100644 --- a/tests/hlsl-intrinsic/wave-lane-at-vk.slang +++ b/tests/hlsl-intrinsic/wave-lane-at-vk.slang @@ -9,7 +9,7 @@ RWStructuredBuffer outputBuffer; // `The input lane index must be uniform across the wave.`. -// The same restriction applies to glsl/SPIR-V 1.4 +// The same restriction applies to glsl/SPIR-V 1.5 // So we are going to use the input buffer to achieve this. //TEST_INPUT:ubuffer(data=[1 2 3 0], stride=4):name inputBuffer diff --git a/tests/hlsl-intrinsic/wave-lane-at.slang b/tests/hlsl-intrinsic/wave-lane-at.slang index 8661dbc55..c3caaa4e8 100644 --- a/tests/hlsl-intrinsic/wave-lane-at.slang +++ b/tests/hlsl-intrinsic/wave-lane-at.slang @@ -9,7 +9,7 @@ RWStructuredBuffer outputBuffer; // Note from HLSL: `The input lane index must be uniform across the wave.`. -// The same restriction applies to glsl/SPIR-V 1.4 +// The same restriction applies to glsl/SPIR-V 1.5 // So we are going to use the input buffer to achieve this. //TEST_INPUT:ubuffer(data=[1 2 3 0], stride=4):name inputBuffer diff --git a/tests/hlsl-intrinsic/wave-shuffle-vk.slang b/tests/hlsl-intrinsic/wave-shuffle-vk.slang new file mode 100644 index 000000000..01fb59155 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-shuffle-vk.slang @@ -0,0 +1,33 @@ +// Disabled because main tests is wave-shuffle.slang, this just tests VK +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//DISABLE_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; + + // Scalar + + value += WaveShuffle(idx, (idx + 1) & 3); + + // vector + + { + float2 v = float2(idx + 1, idx + 2); + float2 readValue = WaveShuffle(v, (idx - 1) & 3); + + value += int(readValue[0] + readValue[1]); + } + + outputBuffer[idx] = value; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-shuffle-vk.slang.expected.txt b/tests/hlsl-intrinsic/wave-shuffle-vk.slang.expected.txt new file mode 100644 index 000000000..b20444fc5 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-shuffle-vk.slang.expected.txt @@ -0,0 +1,4 @@ +A +5 +8 +7 diff --git a/tests/hlsl-intrinsic/wave-shuffle.slang b/tests/hlsl-intrinsic/wave-shuffle.slang new file mode 100644 index 000000000..093babcce --- /dev/null +++ b/tests/hlsl-intrinsic/wave-shuffle.slang @@ -0,0 +1,42 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//Disabled on D3D, because in general WaveShuffle requires hardware that doesn't have the 'uniform laneId across Wave' restriction. +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +// Disabled because vk doesn't currently support matrix types. See wave-shuffle-vk.slang +//DISABLE_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; + + // Scalar + + value += WaveShuffle(idx, (idx + 1) & 3); + + // vector + + { + float2 v = float2(idx + 1, idx + 2); + float2 readValue = WaveShuffle(v, (idx - 1) & 3); + + value += int(readValue[0] + readValue[1]); + } + + // matrix + { + matrix v = matrix(idx, idx - 1, idx * 3, idx - 2); + + matrix readValue = WaveShuffle(v, (idx - 1) & 3); + + value += int(readValue[0][0] + readValue[0][1] + readValue[1][0] + readValue[1][1]); + } + + outputBuffer[idx] = value; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-shuffle.slang.expected.txt b/tests/hlsl-intrinsic/wave-shuffle.slang.expected.txt new file mode 100644 index 000000000..a327b0804 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-shuffle.slang.expected.txt @@ -0,0 +1,4 @@ +19 +2 +B +10 -- cgit v1.2.3