diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-07 21:50:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-07 21:50:41 -0700 |
| commit | eb3970897049269602cc18cee644e437c0aff928 (patch) | |
| tree | 09c9b5c1f5d237563723d5d6a2c4050d996b9e32 | |
| parent | 997f040f48b5c34e20ad6b0f512bb9d1ae6e6128 (diff) | |
Make sure pointer local vars have `AliasedPointer` decoration. (#4132)
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 19 | ||||
| -rw-r--r-- | tests/bugs/gh-4111.slang | 31 |
2 files changed, 50 insertions, 0 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index a7cdfc8a3..8219d3534 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -4077,6 +4077,8 @@ struct SPIRVEmitContext return; if (ptrType->getAddressSpace() == SpvStorageClassPhysicalStorageBuffer) { + // If inst has a pointer type with PhysicalStorageBuffer address space, + // emit AliasedPointer decoration. emitOpDecorate( getSection(SpvLogicalSectionID::Annotations), nullptr, @@ -4084,6 +4086,23 @@ struct SPIRVEmitContext (as<IRVar>(inst) ? SpvDecorationAliasedPointer : SpvDecorationAliased) ); } + else + { + // If the pointee type is a pointer with StorageBuffer address space, + // we also want to emit AliasedPointer decoration. + ptrType = as<IRPtrType>(ptrType->getValueType()); + if (!ptrType) + return; + if (ptrType->getAddressSpace() == SpvStorageClassPhysicalStorageBuffer) + { + emitOpDecorate( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + varInst, + (as<IRVar>(inst) ? SpvDecorationAliasedPointer : SpvDecorationAliased) + ); + } + } } SpvInst* emitParam(SpvInstParent* parent, IRInst* inst) diff --git a/tests/bugs/gh-4111.slang b/tests/bugs/gh-4111.slang new file mode 100644 index 000000000..66d565d9f --- /dev/null +++ b/tests/bugs/gh-4111.slang @@ -0,0 +1,31 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// Check that a pointer typed local variable has `AliasedPointer` decoration. + +// CHECK: OpDecorate %b AliasedPointer +struct Buf +{ + uint test; +}; + +struct Push +{ + bool a_or_b; + Buf * a; + Buf * b; +}; + +[[vk::push_constant]] Push push; + +func tester(Buf * buf) +{ + buf->test = 1; +} + +[shader("compute")] +[numthreads(1, 1, 1)] +void main() +{ + Buf * b = push.a_or_b ? push.a : push.b; + tester(b); +}
\ No newline at end of file |
