diff options
| author | Harsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com> | 2025-09-10 17:31:36 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 12:01:36 +0000 |
| commit | 3d0f5ee55788dca324641ae9268ee37dc4d7d9d5 (patch) | |
| tree | 71100ca80c7646853858cd4e244f971d6485ee6c /tests/compute | |
| parent | 2020a102e9e0ea2f39a0f2b2a75085c3607ce734 (diff) | |
CUDA: Fix compiler crash with unsized array field - nonuniformres-as-… (#8380)
…function-parameter.slang #8315
Root Cause:
CUDA compilation crashed with `assert failure:
!seenFinalUnsizedArrayField` because unsized arrays like
`RWStructuredBuffer<uint> globalBuffer[]` were not the final field in
generated parameter structs, violating the layout constraint in
slang-ir-layout.cpp.
Fix:
Extended `collectGlobalUniformParameters` to automatically reorder
struct fields for CUDA targets - regular fields first, unsized arrays
last. Other targets preserve original order.
Impact:
- Enables CUDA support for nonuniform resource indexing as function
parameters
- Zero impact on existing GLSL/HLSL/SPIRV targets
- Automatic handling - no manual parameter reordering required
Files: slang-emit.cpp, slang-ir-collect-global-uniforms.cpp/.h, test
file
---------
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
Diffstat (limited to 'tests/compute')
| -rw-r--r-- | tests/compute/nonuniformres-as-function-parameter.slang | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/compute/nonuniformres-as-function-parameter.slang b/tests/compute/nonuniformres-as-function-parameter.slang index 38fb2a478..fcf8598f6 100644 --- a/tests/compute/nonuniformres-as-function-parameter.slang +++ b/tests/compute/nonuniformres-as-function-parameter.slang @@ -2,6 +2,7 @@ //TEST:SIMPLE(filecheck=CHECK_GLSL_SPV):-target spirv -entry main -stage compute -emit-spirv-via-glsl //TEST:SIMPLE(filecheck=CHECK_GLSL):-target glsl -entry main -stage compute //TEST:SIMPLE(filecheck=CHECK_HLSL):-target hlsl -entry main -stage compute +//TEST:SIMPLE(filecheck=CHECK_CUDA):-target cuda -entry main -stage compute RWStructuredBuffer<uint> globalBuffer[] : register(u0, space1); RWStructuredBuffer<uint3> outputBuffer; @@ -81,6 +82,7 @@ void main(uint2 pixelIndex : SV_DispatchThreadID) // CHECK_GLSL: func_0({{.*}}nonuniformEXT({{.*}})) // CHECK_HLSL: func_0(globalBuffer_0[NonUniformResourceIndex({{.*}})]) + // CHECK_CUDA: func_{{[0-9]+}}(globalParams_{{[0-9]+}}->globalBuffer_{{[0-9]+}}[{{.*}}]) MyStruct myStruct = func(buffer); int bufferIdx2 = pixelIndex.y; @@ -103,6 +105,7 @@ void main(uint2 pixelIndex : SV_DispatchThreadID) // CHECK_GLSL: func_1({{.*}}nonuniformEXT({{.*}})) // CHECK_HLSL: func_0(globalBuffer_0[NonUniformResourceIndex({{.*}})]) + // CHECK_CUDA: func_{{[0-9]+}}(globalParams_{{[0-9]+}}->globalBuffer_{{[0-9]+}}[{{.*}}]) MyStruct myStruct2 = func(buffer2); // Test case 3: Test the case that we handle the uniformity correctly, the NonUniformResourceIndex will not propagate @@ -114,6 +117,7 @@ void main(uint2 pixelIndex : SV_DispatchThreadID) // Test to make sure this command is not decorated with NonUniform: // CHECK_SPV-NOT: OpDecorate %[[VAR4]] NonUniform + // CHECK_CUDA: func_{{[0-9]+}}(globalParams_{{[0-9]+}}->globalBuffer_{{[0-9]+}}[{{.*}}]) MyStruct myStruct3 = func(buffer3); @@ -130,6 +134,7 @@ void main(uint2 pixelIndex : SV_DispatchThreadID) // // Since after the nested cast, the index data type is 'uint' now, make sure it calls the same function as the test case 1. // CHECK_GLSL: func_0({{.*}}nonuniformEXT({{.*}})) + // CHECK_CUDA: func_{{[0-9]+}}(globalParams_{{[0-9]+}}->globalBuffer_{{[0-9]+}}[{{.*}}]) RWStructuredBuffer<uint> buffer4 = globalBuffer[(uint)((int)NonUniformResourceIndex(bufferIdx))]; MyStruct myStruct4 = func(buffer4); |
