Skip to content

Commit

Permalink
SPIRV: Fix storage class for unwrapped pointers (shader-slang#4068)
Browse files Browse the repository at this point in the history
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 shader-slang#3946

Co-authored-by: Yong He <[email protected]>
  • Loading branch information
cheneym2 and csyonghe authored May 1, 2024
1 parent 853987d commit 4533c82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/slang/slang-ir-spirv-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/spirv/pointer-bug-3.slang
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4533c82

Please sign in to comment.