-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIRV] Empty struct in cbuffer causes compilation to fail #2882
Comments
Thanks for reporting @baldurk |
This is an old issue, but I took a look at it. The empty struct is being assigned an offset of 12 by DXC. Relevant spir-v:
For reference glslang produces the following offsets:
That seems reasonable. Using
However, while investigating the spir-v spec, I noticed the following validation rule regarding composite objects: "- The ArrayStride, MatrixStride, and Offset decorations must be large enough to hold the size of Am I misinterpreting the spec? |
We have a special case to that the the size and alignment for an empty struct is `{1,0}`. However that is not correct. See https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#interfaces-alignment-requirements. > An empty structure has a base alignment equal to the size of the smallest scalar type permitted by the capabilities declared in the SPIR-V module. (e.g., for a 1 byte aligned empty struct in the StorageBuffer storage class, StorageBuffer8BitAccess or UniformAndStorageBuffer8BitAccess must be declared in the SPIR-V module. I'm not 100% sure how DXC handle this minimum alignment, but I figured I would inialize the alignment to 1. If there are not members, then it will remain 1, and I would let the rest of the logic happen. No special case. Fixes microsoft#2882
We have a special case to that the the size and alignment for an empty struct is `{1,0}`. However that is not correct. See https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#interfaces-alignment-requirements. > An empty structure has a base alignment equal to the size of the smallest scalar type permitted by the capabilities declared in the SPIR-V module. (e.g., for a 1 byte aligned empty struct in the StorageBuffer storage class, StorageBuffer8BitAccess or UniformAndStorageBuffer8BitAccess must be declared in the SPIR-V module. I'm not 100% sure how DXC handle this minimum alignment, but I figured I would inialize the alignment to 1. If there are not members, then it will remain 1, and I would let the rest of the logic happen. No special case. Fixes #2882
If an empty struct is declared in a cbuffer (or a nested struct inside) the compilation seems to break trying to align members properly to their alignment requirements around that struct:
When compiling with latest dxc (
dxcompiler.dll: 1.6 - 1.5.0.2653 (f0d4419f)
) I get this error:With the offset of 12 coming wrongly from the
float2 c
trying to pack directly afterfloat3 a
. If I allow scalar layout with-fvk-use-scalar-layout
then it doesn't complain since a tight packing is valid.The text was updated successfully, but these errors were encountered: