summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-10 12:39:17 -0700
committerGitHub <noreply@github.com>2024-04-10 12:39:17 -0700
commita6d59d0e102e2d21d411a7ca1f8acaf3bf1f867c (patch)
tree03c28a604f1b5dc0b47aa24542d4dfd61b813aba /tests
parentc85dd531d31e5a241d220f20686a9c047432f1c6 (diff)
Properly compile `gl_WorkgroupSize`. (#3925)
* Properly compile `gl_WorkgroupSize`. * Update source/slang/slang-ir-translate-glsl-global-var.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/spirv/subgroup-size-2.slang33
-rw-r--r--tests/spirv/subgroup-size.slang16
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/spirv/subgroup-size-2.slang b/tests/spirv/subgroup-size-2.slang
new file mode 100644
index 000000000..68fee6fe6
--- /dev/null
+++ b/tests/spirv/subgroup-size-2.slang
@@ -0,0 +1,33 @@
+// Test that using workgroup size from more than one entrypoint result in
+// correct lowering into global variable.
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -fvk-use-entrypoint-name -O0
+
+RWStructuredBuffer<int> outputBuffer;
+
+uint3 f() { return WorkgroupSize(); }
+
+[shader("compute")]
+[numthreads(1u, 2u, 3)]
+void compute1()
+{
+ // CHECK-DAG: %[[VAR:[A-Za-z0-9_]+]] = OpVariable %_ptr_Private_v3int Private
+ // CHECK: OpStore %[[VAR]]
+
+ // CHECK-DAG: %[[CALL_RS:[A-Za-z0-9_]+]] = OpFunctionCall %v3uint %f
+ // CHECK: OpCompositeExtract %uint %[[CALL_RS]] 0
+ const int x = f().x;
+ outputBuffer[0] = x;
+
+ // CHECK-DAG: %[[PTR:[A-Za-z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer_int %outputBuffer %int_0 %uint_1
+ // CHECK: OpStore %[[PTR]] %int_2
+ outputBuffer[1] = WorkgroupSize().y;
+}
+
+[shader("compute")]
+[numthreads(4, 5, 6)]
+void compute2()
+{
+ const int x = f().x;
+ outputBuffer[0] = x;
+} \ No newline at end of file
diff --git a/tests/spirv/subgroup-size.slang b/tests/spirv/subgroup-size.slang
new file mode 100644
index 000000000..c2ed4a3d8
--- /dev/null
+++ b/tests/spirv/subgroup-size.slang
@@ -0,0 +1,16 @@
+import "glsl";
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -O0
+
+// CHECK-DAG: %[[CONST:[A-Za-z0-9_]+]] = OpConstantComposite %v3int %int_1 %int_2 %int_3
+// CHECK: OpBitcast %v3uint %[[CONST]]
+
+RWStructuredBuffer<int> outputBuffer;
+
+[shader("compute")]
+[numthreads(1u, 2u, 3)]
+void compute()
+{
+ const int x = gl_WorkGroupSize.x;
+ outputBuffer[0] = x;
+} \ No newline at end of file