From 1e4265edd4ec4c44e3d8f209fca802727076aa46 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Thu, 9 Oct 2025 02:13:27 +0300 Subject: Allow 1D SV_DispatchThreadID in CPU targets (#8612) The varying param legalization pass didn't deal with this 1D form of SV_DispatchThreadID for CPU targets: ```slang void computeMain(int i : SV_DispatchThreadID) ``` Instead, it just overrode the type of `i` with a `uint3`, breaking lots of code that attempted to use `i` for something, like a `switch` statement for example. I ran across this when going through `language-feature` tests for the LLVM target, which will also use this legalization pass. I'm separately submitting this now because this also fixes the existing CPU target. The test I enable in this PR is one that was previously generating broken code on CPU. (somewhat related issue: #7468) --- tests/language-feature/enums/enum-switch-2.slang | 1 + .../language-feature/system-value-extraction.slang | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/language-feature/system-value-extraction.slang (limited to 'tests/language-feature') diff --git a/tests/language-feature/enums/enum-switch-2.slang b/tests/language-feature/enums/enum-switch-2.slang index f5266f35d..de4a4757b 100644 --- a/tests/language-feature/enums/enum-switch-2.slang +++ b/tests/language-feature/enums/enum-switch-2.slang @@ -1,4 +1,5 @@ //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cpu -compute -shaderobj -output-using-type //TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type enum class E : uint32_t diff --git a/tests/language-feature/system-value-extraction.slang b/tests/language-feature/system-value-extraction.slang new file mode 100644 index 000000000..12ca07a96 --- /dev/null +++ b/tests/language-feature/system-value-extraction.slang @@ -0,0 +1,31 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -dx11 -compute +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -dx12 -compute +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -cpu -compute +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -cuda -compute +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -wgsl -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -mtl -compute +//TEST(compute,vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK): -vk -compute + +// Slang allows the type of system value semantics to differ from their +// "canonical" type - e.g. `uint8_t tid : SV_DispatchThreadID` is technically +// valid and refers to the first element in the underlying uint3 vector. + +// TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(2, 4, 1)] +void computeMain( + uint ind : SV_GroupIndex, + vector tid: SV_DispatchThreadID, + int localTid : SV_GroupThreadID +){ + // CHECK: 0 + // CHECK-NEXT: 5 + // CHECK-NEXT: 8 + // CHECK-NEXT: D + // CHECK-NEXT: 10 + // CHECK-NEXT: 15 + // CHECK-NEXT: 18 + // CHECK-NEXT: 1D + outputBuffer[ind] = 4 * (tid.x + 2 * tid.y) + localTid; +} -- cgit v1.2.3