Skip to content

[SPIRV] Emit Offset decoration for PhysicalStorage structs - #5392

Merged
Steven Perron (s-perron) merged 3 commits into
microsoft:mainfrom
Keenuts:fix-5327
Jul 7, 2023
Merged

Steven Perron (s-perron) merged 3 commits into
microsoft:mainfrom
Keenuts:fix-5327

Conversation

@Keenuts

Copy link
Copy Markdown
Collaborator

When the SPV_EXT_physical_storage_buffer extensions is used, vulkan can load raw addresses. For structs loaded through this mecanism, the offsets must be explicit.

This commit fixes decoration emission by attaching the correct layout when a struct is loaded using this extensions.
(Specifying a layout different than void forces explicit offsets).

Fixes #5327

@Keenuts

Copy link
Copy Markdown
Collaborator Author

This PR fails tests right now (requires fixes in #5390)

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. I just want to understand how we get a null operand. That seems like an error on the part of the caller.

Comment thread tools/clang/lib/SPIRV/SpirvBuilder.cpp Resolved
@AppVeyorBot

Copy link
Copy Markdown

@AppVeyorBot

Copy link
Copy Markdown

When DXC emits an error, the rest of the expression is
still parsed until we go back to the root and show the error.

This means some functions could return a nullptr, which is not
accounted for in many places.
The subsequent change will add a case where is breaks, so this commit
adds a few additional null-checks.

Signed-off-by: Nathan Gauër <[email protected]>
When the SPV_EXT_physical_storage_buffer extensions
is used, vulkan can load raw addresses. For structs loaded
through this mecanism, the offsets must be explicit.

This commit fixes decoration emission by attaching the correct
layout when a struct is loaded using this extensions.
(Specifying a layout different than void forces explicit offsets).

Fixes microsoft#5327

Signed-off-by: Nathan Gauër <[email protected]>
@s-perron
Steven Perron (s-perron) enabled auto-merge (squash) July 7, 2023 16:11
@s-perron
Steven Perron (s-perron) merged commit 6289ba3 into microsoft:main Jul 7, 2023
@Keenuts
Nathan Gauër (Keenuts) deleted the fix-5327 branch July 7, 2023 17:18
Steven Perron (s-perron) added a commit to s-perron/DirectXShaderCompiler that referenced this pull request Jun 18, 2024
The first first fix in microsoft#5392 was not correct. It relied on the layout
rule for the address to be the correct layout rule, but that is not
always the case. The address is just an integer that could exist in any
storage class. The correct solution is to explicitly set the layout rule
for the BitCast operation when expanding the RawBuffer* functions. We
know that the result of the BitCast is a pointer to the physical storage
buffer storage class, so we know the layout need to be the storage
buffer layout.

Fixes microsoft#6554
Steven Perron (s-perron) added a commit that referenced this pull request Jun 25, 2024
The first first fix in #5392 was not correct. It relied on the layout
rule for the address to be the correct layout rule, but that is not
always the case. The address is just an integer that could exist in any
storage class. The correct solution is to explicitly set the layout rule
for the BitCast operation when expanding the RawBuffer* functions. We
know that the result of the BitCast is a pointer to the physical storage
buffer storage class, so we know the layout need to be the storage
buffer layout.

Fixes #6554
Mxr (SjMxr233) pushed a commit to ShaderHelper/DirectXShaderCompiler that referenced this pull request Jul 24, 2025
)

The first first fix in microsoft#5392 was not correct. It relied on the layout
rule for the address to be the correct layout rule, but that is not
always the case. The address is just an integer that could exist in any
storage class. The correct solution is to explicitly set the layout rule
for the BitCast operation when expanding the RawBuffer* functions. We
know that the result of the BitCast is a pointer to the physical storage
buffer storage class, so we know the layout need to be the storage
buffer layout.

Fixes microsoft#6554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[SPIR-V] DXC generates invalid SPIR-V when using RawBufferLoad with a struct.

4 participants