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/cuda/dispatch-thread-id-extraction.slang | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/cuda') diff --git a/tests/cuda/dispatch-thread-id-extraction.slang b/tests/cuda/dispatch-thread-id-extraction.slang index 5fc3c89a6..02705ff24 100644 --- a/tests/cuda/dispatch-thread-id-extraction.slang +++ b/tests/cuda/dispatch-thread-id-extraction.slang @@ -28,8 +28,9 @@ void computeMain3(int2 tid: SV_DispatchThreadID, StructuredBuffer src, RWS { dst[tid.x] = src[tid.x]; } -// CHECK: int _S3 = (slang_bit_cast(uint2 {(blockIdx * blockDim + threadIdx).x, (blockIdx * blockDim + threadIdx).y})).x; - +// CHECK: uint2 _S3 = uint2 {(blockIdx * blockDim + threadIdx).x, (blockIdx * blockDim + threadIdx).y}; +// CHECK: int2 _S4 = make_int2 ((int)_S3.x, (int)_S3.y); +// CHECK: int _S5 = _S4.x; [shader("compute")] [numthreads(1, 1, 1)] @@ -37,7 +38,7 @@ void computeMain4(int tid: SV_DispatchThreadID, StructuredBuffer src, RWSt { dst[tid.x] = src[tid.x]; } -// CHECK: int _S4 = (slang_bit_cast((blockIdx * blockDim + threadIdx).x)); +// CHECK: int _S6 = int((blockIdx * blockDim + threadIdx).x); [shader("compute")] [numthreads(1, 1, 1)] @@ -45,4 +46,4 @@ void computeMain5(int tid: SV_GroupIndex, StructuredBuffer src, RWStructur { dst[tid.x] = src[tid.x]; } -// CHECK: int _S5 = (slang_bit_cast((threadIdx.z * blockDim.y + threadIdx.y) * blockDim.x + threadIdx.x)); \ No newline at end of file +// CHECK: int _S7 = int((threadIdx.z * blockDim.y + threadIdx.y) * blockDim.x + threadIdx.x); -- cgit v1.2.3