From 4533c825fe628e08228037b846ee9d10004fd56f Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Wed, 1 May 2024 19:16:38 -0400 Subject: 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 --- source/slang/slang-ir-spirv-legalize.cpp | 1 + tests/spirv/pointer-bug-3.slang | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/spirv/pointer-bug-3.slang 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 -- cgit v1.2.3