Skip to content
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

HLSL compilation produces scalar-requiring cbuffer offsets by default #3742

Open
baldurk opened this issue Sep 25, 2024 · 0 comments
Open

HLSL compilation produces scalar-requiring cbuffer offsets by default #3742

baldurk opened this issue Sep 25, 2024 · 0 comments

Comments

@baldurk
Copy link
Contributor

baldurk commented Sep 25, 2024

Given this HLSL shader:

cbuffer consts
{
  float o[4];
  float p;
};

float4 main() : SV_Target0 { return p.xxxx; }

glslang used to emit a cbuffer with p at offset 64, which complies with the normal Vulkan packing rules. It looks like in #3575 this was changed to emit an offset of 52. Doing so requires scalar block layout on the vulkan side and to me is an unexpected behaviour change:

$ glslang -D -V -S frag -e main test.hlsl
$ spirv-val --target-env vulkan1.1spv1.4 frag.spv
error: line 27: Structure id 14 decorated as Block for variable in Uniform storage class must
follow relaxed uniform buffer layout rules: member1 at offset 52 overlaps previous member
ending at offset 63
  %consts = OpTypeStruct %_arr_float_uint_4 %float

$ spirv-val --target-env vulkan1.1spv1.4 --scalar-block-layout frag.spv

Compare to dxc which by default puts p at an offset of 64, but has options -fvk-use-dx-layout and -fvk-use-scalar-layout to emit D3D-packed layouts or scalar packed layouts respectively, though both require scalar block layout to remove this rule.

This effectively breaks backwards compatibility - was that deliberate? If so is there any way to at least opt-out to this behaviour if you don't want to have it opt-in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant