summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2024-05-01 19:16:38 -0400
committerGitHub <noreply@github.com>2024-05-01 16:16:38 -0700
commit4533c825fe628e08228037b846ee9d10004fd56f (patch)
tree8437b102233878c96f1ee95161751a318d992a1b
parent853987defb7090d77938593c271413d92447f7b1 (diff)
SPIRV: Fix storage class for unwrapped pointers (#4068)
In SPIRV legalization, a struct wrapper is created around push constants but is not itself legalized. Putting the struct type into the work list causes the storage access of the push constant pointer to be PhysicalStorageBuffer as expected, instead of Function scope that was produced without the added struct legalization. Adds a SPIRV test that exercises the fix. Fixes #3946 Co-authored-by: Yong He <yonghe@outlook.com>
-rw-r--r--source/slang/slang-ir-spirv-legalize.cpp1
-rw-r--r--tests/spirv/pointer-bug-3.slang10
2 files changed, 11 insertions, 0 deletions
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp
index 2f392a178..311ff0e89 100644
--- a/source/slang/slang-ir-spirv-legalize.cpp
+++ b/source/slang/slang-ir-spirv-legalize.cpp
@@ -182,6 +182,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
IRBuilder builder(cbParamInst);
builder.setInsertBefore(cbParamInst);
auto structType = builder.createStructType();
+ addToWorkList(structType);
StringBuilder sb;
sb << "cbuffer_";
getTypeNameHint(sb, innerType);
diff --git a/tests/spirv/pointer-bug-3.slang b/tests/spirv/pointer-bug-3.slang
new file mode 100644
index 000000000..60fa70a6e
--- /dev/null
+++ b/tests/spirv/pointer-bug-3.slang
@@ -0,0 +1,10 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -O0
+
+[[vk::push_constant]] float4 *positions;
+[shader("vertex")]
+float4 main()
+{
+ return positions[0];
+}
+// NOT %cbuffer__t = OpTypeStruct %_ptr_Function_v4float
+// CHECK: %cbuffer__t = OpTypeStruct %_ptr_PhysicalStorageBuffer_v4float