diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-01-14 20:32:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-14 10:32:29 -0800 |
| commit | cbdc7e1219e472fd74f7f559d7e417f233e7df39 (patch) | |
| tree | e051b90e317a875e264c2c8d951668bf0b7d3ad0 /tests | |
| parent | 971996b397711016d47fe961890d7001338c6f23 (diff) | |
Implement specialization constant support in numthreads / local_size (#5963)
* Allow using specialization constants in numthreads attribute
* Add support for GLSL local_size_x_id syntax
* Fix overeager specialization constant parsing
* Add diagnostics for specialization constant numthreads
* Remove unused variable
* Fix local_size_x_id not finding existing specialization constant
* Allow materializeGetWorkGroupSize to reference specialization constants
* Use SpvOpExecutionModeId for modes that require it
* Cleanup specialization constant numthreads code
* Add tests for specialization constant work group sizes
* Fix implicit Slang::Int -> int32_t cast
* Fix querying thread group size in reflection API
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/glsl/compute-shader-layout-id.slang | 19 | ||||
| -rw-r--r-- | tests/spirv/spec-constant-numthreads.slang | 35 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/glsl/compute-shader-layout-id.slang b/tests/glsl/compute-shader-layout-id.slang new file mode 100644 index 000000000..bee8137d8 --- /dev/null +++ b/tests/glsl/compute-shader-layout-id.slang @@ -0,0 +1,19 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main -allow-glsl +#version 450 + +[vk::constant_id(1)] +const int constValue1 = 0; + +[vk::constant_id(2)] +const int constValue3 = 5; + +// CHECK-DAG: OpExecutionModeId %main LocalSizeId %[[C0:[0-9A-Za-z_]+]] %[[C1:[0-9A-Za-z_]+]] %[[C2:[0-9A-Za-z_]+]] +// CHECK-DAG: OpDecorate %[[C0]] SpecId 1 +// CHECK-DAG: OpDecorate %[[C1]] SpecId 0 +// CHECK-DAG: OpDecorate %[[C2]] SpecId 2 + +layout(local_size_x_id = 1, local_size_y_id = 0, local_size_z = constValue3) in; +void main() +{ +} + diff --git a/tests/spirv/spec-constant-numthreads.slang b/tests/spirv/spec-constant-numthreads.slang new file mode 100644 index 000000000..5c133219c --- /dev/null +++ b/tests/spirv/spec-constant-numthreads.slang @@ -0,0 +1,35 @@ +//TEST:SIMPLE(filecheck=GLSL): -target glsl -allow-glsl +//TEST:SIMPLE(filecheck=GLSL): -target glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv -allow-glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK-DAG: OpExecutionModeId %computeMain1 LocalSizeId %[[C0:[0-9A-Za-z_]+]] %[[C1:[0-9A-Za-z_]+]] %[[C2:[0-9A-Za-z_]+]] +// CHECK-DAG: OpDecorate %[[C0]] SpecId 1 +// CHECK-DAG: OpDecorate %[[C1]] SpecId 0 +// CHECK-DAG: %[[C2]] = OpConstant %int 4 +// CHECK-DAG: OpStore %{{.*}} %[[C0]] +// CHECK-DAG: OpStore %{{.*}} %[[C1]] +// CHECK-DAG: OpStore %{{.*}} %[[C2]] + +// GLSL-DAG: layout(constant_id = 1) +// GLSL-DAG: int constValue0_0 = 0; +// GLSL-DAG: layout(constant_id = 0) +// GLSL-DAG: int constValue1_0 = 0; +// GLSL-DAG: layout(local_size_x_id = 1, local_size_y_id = 0, local_size_z = 4) in; + +[vk::specialization_constant] +const int constValue0 = 0; + +[vk::constant_id(0)] +const int constValue1 = 0; + +RWStructuredBuffer<int> outputBuffer; + +[numthreads(constValue0, constValue1, 4)] +void computeMain1() +{ + int3 size = WorkgroupSize(); + outputBuffer[0] = size.x; + outputBuffer[1] = size.y; + outputBuffer[2] = size.z; +} |
