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-out] account for "vector-relaxed" std140 layout for constant buffers #1783

Closed
teoxoy opened this issue Mar 20, 2022 · 0 comments · Fixed by #1786
Closed

[hlsl-out] account for "vector-relaxed" std140 layout for constant buffers #1783

teoxoy opened this issue Mar 20, 2022 · 0 comments · Fixed by #1786
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: HLSL High-Level Shading Language

Comments

@teoxoy
Copy link
Member

teoxoy commented Mar 20, 2022

HLSL uses "vector-relaxed" std140 layout for constant buffers, however the current implementation seems to assume std140 layout

The example below shows the issue.

Going from WGSL to HLSL trough naga translates the struct as if it had the same layout in HLSL.
When translating the same WGSL shader to SPIR-V via naga, the offsets are: 0, 8, 16.
However when translating the produced HLSL to SPIR-V via DXC, the offsets are: 0, 4, 12.

WGSL -> HLSL
wgsl_hlsl

WGSL -> SPIR-V
wgsl_spirv

HLSL -> SPIR-V
hlsl_spirv

Solution

Insert padding (when necessary) for vector members that are in constant buffers.

References

HLSL Packing Rules for Constant Variables
DirectXShaderCompiler Buffer-Packing Wiki
DirectXShaderCompiler Memory layout rules

@teoxoy teoxoy changed the title [hlsl-out] [hlsl-out] account for "vector-relaxed" std140 layout for constant buffers Mar 20, 2022
@kvark kvark added kind: bug Something isn't working area: back-end Outputs of shader conversion lang: HLSL High-Level Shading Language labels Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end Outputs of shader conversion kind: bug Something isn't working lang: HLSL High-Level Shading Language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants