diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-30 12:03:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 12:03:23 -0700 |
| commit | de83628070614ec37349c9f334ed72a54a6889da (patch) | |
| tree | bc97f74013a073fc958b75e68089696e14d71412 /tests | |
| parent | f428a058ea48535a323c32d206ebc7e551c3c3e9 (diff) | |
Support specialization constants. (#4963)
* Support specialization constants.
* Fix.
* Fix.
* Fix.
* Fix.
* Make sure specialization constants have names.
* Clean up and support the dxc [vk::constant_id] syntax.
* Fix.
* Fix.
* Fix.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/language-feature/zero-initialize/struct.slang | 1 | ||||
| -rw-r--r-- | tests/spirv/specialization-constant.slang | 48 |
2 files changed, 48 insertions, 1 deletions
diff --git a/tests/language-feature/zero-initialize/struct.slang b/tests/language-feature/zero-initialize/struct.slang index 62f403903..efb1d8fc3 100644 --- a/tests/language-feature/zero-initialize/struct.slang +++ b/tests/language-feature/zero-initialize/struct.slang @@ -2,7 +2,6 @@ // CHECK-COUNT-3: {{.* }}= 0; //TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -xslang -zero-initialize -//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -entry computeMain -emit-spirv-directly -allow-glsl -xslang -zero-initialize //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -entry computeMain -allow-glsl -xslang -zero-initialize //TEST(smoke,compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-dx12 -use-dxil -compute -entry computeMain -allow-glsl -xslang -zero-initialize diff --git a/tests/spirv/specialization-constant.slang b/tests/spirv/specialization-constant.slang new file mode 100644 index 000000000..63141d25e --- /dev/null +++ b/tests/spirv/specialization-constant.slang @@ -0,0 +1,48 @@ +//TEST:SIMPLE(filecheck=GLSL): -target glsl +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK-DAG: OpDecorate %[[C0:[0-9A-Za-z_]+]] SpecId 0 +// CHECK-DAG: %[[C0]] = OpSpecConstant %int 1 + +// CHECK-DAG: OpDecorate %[[C1:[0-9A-Za-z_]+]] SpecId 7 +// CHECK-DAG: %[[C1]] = OpSpecConstant %float 3 + +// CHECK-DAG: OpDecorate %[[C2:[0-9A-Za-z_]+]] SpecId 1 +// CHECK-DAG: %[[C2]] = OpSpecConstantTrue %bool + +// CHECK-DAG: OpDecorate %[[C3:[0-9A-Za-z_]+]] SpecId 9 +// CHECK-DAG: %[[C3]] = OpSpecConstant %int 111 + +// GLSL-DAG: layout(constant_id = 0) +// GLSL-DAG: int constValue0_0 = 1; + +// GLSL-DAG: layout(constant_id = 7) +// GLSL-DAG: float constValue1_0 = 3.0; + +// GLSL-DAG: layout(constant_id = 1) +// GLSL-DAG: bool constValue2_0 = true; + +// GLSL-DAG: layout(constant_id = 9) +// GLSL-DAG: int constValue3_0 = 111; + +[vk::specialization_constant] +const int constValue0 = 1; + +[vk::constant_id(7)] +const float constValue1 = 3.0f; + +[SpecializationConstant] +const bool constValue2 = true; + +layout(constant_id = 9) const int constValue3 = 111; + +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain() +{ + if (constValue2) + outputBuffer[0] = constValue0 + (int)constValue1; + else + outputBuffer[0] = constValue3; +}
\ No newline at end of file |
