You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] DXC generates invalid SPIR-V when using RawBufferLoad with a struct. #5327
Composite objects in the StorageBuffer, PhysicalStorageBuffer, Uniform, and PushConstant Storage Classes must be explicitly laid out. The following apply to all the aggregate and matrix types describing such an object, recursively through their nested types:
Each structure-type member must have an Offset decoration.
SPIRV-Tools started to validate this rule, meaning DXC now fails hard.
Seems like we simply don't generate the Offset member decoration when the offset is not explicit.
Looking at the code, I see 2 places to handle that:
LowerTypeVisitor.cpp: only add the offset decoration when required.
EmitVisitor.cpp: always add the offset decoration.
Method 1:
To fix this in the LowerTypeVisitor.cpp, we should not only pass the layout, but also the storage class where the type is used (which here is what's changing the offsets/decorations).
Then, depending on the storage class, the offset will be set in the type or not, the the rest of the code should handle it.
This seems to be the clean method, but requires some larger changes to the lowerTypeVisitor.
Method 2:
The second method is a bit more basic: always add the decoration.
I don't think the spec is against always specifying the Offset member decoration.
This would allow us to have a simple fix.
Bitfields should be handled correctly since the fields are already squashed.
Specific offsets (layout rule by ex), the offset is pre-computed, so we don't have to compute it. Otherwise we have the full-type, so we should always have the correct size.
changed the title [-]DXC generates invalid SPIR-V when using RawBufferLoad with a struct.[/-][+][SPIR-V] DXC generates invalid SPIR-V when using RawBufferLoad with a struct.[/+]on Jun 27, 2023
Initial exploration shows the method 2 won't be that trivial:
some edge cases needs to be handled, like a RuntimeArray in the struct. I believe it's not legal to add any member after if it's a VLA, but unsure.
Some internal structures layouts, like SparseResidencyStruct. Handling those would mean computing the correct size for all those specific types.
From the amount of special cases I need to handle just by poking at it, it seems the "this method is simpler" argument is not valid anymore.
I'll fallback on the method 1, which seems safer than always setting the Offset decoration.
Activity
[-]DXC generates invalid SPIR-V when using RawBufferLoad with a struct.[/-][+][SPIR-V] DXC generates invalid SPIR-V when using RawBufferLoad with a struct.[/+]Keenuts commentedon Jun 27, 2023
Initial exploration shows the method 2 won't be that trivial:
From the amount of special cases I need to handle just by poking at it, it seems the "this method is simpler" argument is not valid anymore.
I'll fallback on the method 1, which seems safer than always setting the Offset decoration.
s-perron commentedon Jun 28, 2023
Will a fix for this issue also fix #5122?
Keenuts commentedon Jun 28, 2023
Not sure, but I guess I'll figure out once solved?
Emit Offset decoration for PhysicalStorage structs
Emit Offset decoration for PhysicalStorage structs
[SPIRV] Emit Offset decoration for PhysicalStorage structs (#5392)