diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2025-06-26 14:39:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-26 12:39:40 -0700 |
| commit | bf94fc3f5b73033334db28846580f16df42d6a85 (patch) | |
| tree | 067435e49aae2e7bc6a9eba138984746f09371c3 /tests/spirv | |
| parent | d166fe8333c7dfc61c32fda5017461858eb4c3fa (diff) | |
Fix the invalid SPIRV decoration issue (#7527)
* Fix the invalid SPIRV decoration issue
Close #7508.
SPIRV doesn't allow decoration on type with Private or Function storage
class.
In our lowering logic, if the array type is used by buffer type it
will always have stride operand after lowering, so if the array is not
used by buffer type, it must be used only by thread_local or
group_shared variable, and it will not have stride operand. For this
case, we don't need to emit stride decoration for SPIRV.
Diffstat (limited to 'tests/spirv')
| -rw-r--r-- | tests/spirv/array-stride-decoration-1.slang | 29 | ||||
| -rw-r--r-- | tests/spirv/array-stride-decoration-2.slang | 29 | ||||
| -rw-r--r-- | tests/spirv/array-stride-decoration-3.slang | 31 | ||||
| -rw-r--r-- | tests/spirv/array-stride-decoration-4.slang | 34 |
4 files changed, 123 insertions, 0 deletions
diff --git a/tests/spirv/array-stride-decoration-1.slang b/tests/spirv/array-stride-decoration-1.slang new file mode 100644 index 000000000..5b0f7bc27 --- /dev/null +++ b/tests/spirv/array-stride-decoration-1.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -stage compute -emit-spirv-directly + +// The test check that if an array is used in function scope, we don't decorate it with array stride decoration. + +// The reason we have to check the SPIRV instead of using spirv-val is because slang uses spv1.6 as the target_env, +// but the issue only occurs when the target_env is vulkan1.2+ + +// CHECK: OpEntryPoint +// CHECK-NOT: OpDecorate %_arr_int_int_2 ArrayStride +struct S +{ + int[2] a; +} + +StructuredBuffer<S> input; + +RWStructuredBuffer<int> output; + +[shader("compute")] +void computeMain(uint3 id : SV_DispatchThreadID) +{ + S s; + s.a = input[0].a; + + for (int i = 0; i < 1; i++) + { + output[i] = s.a[i]; + } +} diff --git a/tests/spirv/array-stride-decoration-2.slang b/tests/spirv/array-stride-decoration-2.slang new file mode 100644 index 000000000..702004657 --- /dev/null +++ b/tests/spirv/array-stride-decoration-2.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -stage compute -emit-spirv-directly + +// The test check that if an array is used in thread-local, we don't decorate it with array stride decoration. + +// The reason we have to check the SPIRV instead of using spirv-val is because slang uses spv1.6 as the target_env, +// but the issue only occurs when the target_env is vulkan1.2+ + +// CHECK: OpEntryPoint +// CHECK-NOT: OpDecorate %_arr_int_int_2 ArrayStride +struct S +{ + int[2] a; +} + +ParameterBlock<S> input; + +static S s; + +RWStructuredBuffer<int> output; + +[shader("compute")] +void computeMain(uint3 id : SV_DispatchThreadID) +{ + s.a = input.a; + for (int i = 0; i < 1; i++) + { + output[i] = s.a[i]; + } +} diff --git a/tests/spirv/array-stride-decoration-3.slang b/tests/spirv/array-stride-decoration-3.slang new file mode 100644 index 000000000..79a6ef777 --- /dev/null +++ b/tests/spirv/array-stride-decoration-3.slang @@ -0,0 +1,31 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -stage compute -emit-spirv-directly + +// The test check that if an array is used in function parameter, we don't decorate it with array stride decoration. + +// The reason we have to check the SPIRV instead of using spirv-val is because slang uses spv1.6 as the target_env, +// but the issue only occurs when the target_env is vulkan1.2+ + +// CHECK: OpEntryPoint +// CHECK-NOT: OpDecorate %_arr_int_int_2_0 ArrayStride +struct S +{ + int[2] a; +} + +ParameterBlock<S> input; + +RWStructuredBuffer<int> output; + +void myfunc(int[2] a) +{ + for (int i = 0; i < 2; i++) + { + output[i] = a[i]; + } +} + +[shader("compute")] +void computeMain(uint3 id : SV_DispatchThreadID) +{ + myfunc(input.a); +} diff --git a/tests/spirv/array-stride-decoration-4.slang b/tests/spirv/array-stride-decoration-4.slang new file mode 100644 index 000000000..34de071ad --- /dev/null +++ b/tests/spirv/array-stride-decoration-4.slang @@ -0,0 +1,34 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -stage compute -emit-spirv-directly + +// The test check that if an array is used in workgroup, we don't decorate it with array stride decoration. + +// The reason we have to check the SPIRV instead of using spirv-val is because slang uses spv1.6 as the target_env, +// but the issue only occurs when the target_env is vulkan1.2+ + +// CHECK: OpEntryPoint +// CHECK-NOT: OpDecorate %_arr_int_int_2 ArrayStride +struct S +{ + int[2] a; +} + +ParameterBlock<S> input; + +RWStructuredBuffer<int> output; + +groupshared S s; + + +[shader("compute")] +void computeMain(uint3 id : SV_DispatchThreadID) +{ + if (id.x == 0) + { + for (int i = 0; i < 2; ++i) + { + s.a[i] = input.a[i]; + } + } + GroupMemoryBarrier(); + output[id.x] = s.a[id.x]; +} |
