Repository navigation
Emit Offset decoration for PhysicalStorage structs - #5388
Closed
Nathan Gauër (Keenuts) wants to merge 7 commits into
Closed
Nathan Gauër (Keenuts) wants to merge 7 commits into
Nathan Gauër (Keenuts) wants to merge 7 commits into
Conversation
Nathan Gauër (Keenuts)
requested review from
Cassandra Beckley (cassiebeckley) and
Steven Perron (s-perron)
July 4, 2023 15:41
Steven Perron (s-perron)
requested changes
Jul 4, 2023
Steven Perron (s-perron)
left a comment
Collaborator
There was a problem hiding this comment.
My main concern is that you are creating a new layout rule, and I do not understand why. Is there one that matches the existing layout?
Not for this PR, but we should decide how the layout rules should change with the options:
-fvk-use-dx-layout Use DirectX memory layout for Vulkan resources
-fvk-use-gl-layout Use strict OpenGL std140/std430 memory layout for Vulkan resources
-fvk-use-scalar-layout Use scalar memory layout for Vulkan resources
Technically the physical storage buffers are not Vulkan resources (not set or binding), but it would make sense that they match. We should wait to see if anyone wants it. Until then, we can always use the same layout.
| FxcCTBuffer, // fxc.exe layout rule for cbuffer/tbuffer | ||
| FxcSBuffer, // fxc.exe layout rule for structured buffers | ||
| Scalar, // VK_EXT_scalar_block_layout | ||
| Physical, // SPV_EXT_physical_storage_buffer |
Collaborator
There was a problem hiding this comment.
Why should Physical be its own layout? Shouldn't the layout of the data in the physical storage buffer match the layout in say structured buffers?
HLSL/SPIR-V structs have some layout differences due to bitfields being squashed. The reconstruction logic was using the AST layout, and not the new SPIR-V layout, meaning we could generate invalid indices during extraction/construction. This PR a potential bug with bitfields, while making the code reusable. Signed-off-by: Nathan Gauër <[email protected]>
Depending on the struct layout, the `Offset` decoration is not always required. When this storage class is setup, the decoration needs to be added. The tricky part if the mix of AST types and SPIRV types with bitfields: - in the AST, bitfields are represented as their own fields. - in SPIRV, bitfields are meld into 1 field when possible. This means we need to lower the type to SPIR-V to compute the correct offset. This would be fine if we could always generate the Offset decoration, but some types like image samplers are structs, and computing an offset for them is not clean (maybe no legal?). So I wanted to wait to know the storage type to determine if the decoration needed to be emitted of not.
Signed-off-by: Nathan Gauër <[email protected]>
Nathan Gauër (Keenuts)
force-pushed
the
fix-5327-lowering
branch
from
July 5, 2023 15:21
7ebb861 to
2068b80
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depending on the struct layout, the
Offsetdecoration is not always required.When this storage class is setup, the decoration needs to be added.
The tricky part if the mix of AST types and SPIRV types with bitfields:
This means we need to lower the type to SPIR-V to compute the correct offset.
This would be fine if we could always generate the Offset decoration, but some types like image samplers are structs, and computing an offset for them is not clean (maybe no legal?).
So we need to do it properly, and only generate offsets when the storage
type is physical.
Fixes #5327