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

Matrix of the form matCx2 not getting translated properly when in a uniform buffer #4371

Open
Tracked by #3674 ...
teoxoy opened this issue Mar 20, 2022 · 2 comments · Fixed by gfx-rs/naga#1802
Open
Tracked by #3674 ...
Assignees
Labels
area: naga back-end Outputs of naga shader conversion help required We need community help to make this happen. lang: GLSL OpenGL Shading Language lang: SPIR-V Vulkan's Shading Language naga Shader Translator type: bug Something isn't working

Comments

@teoxoy
Copy link
Member

teoxoy commented Mar 20, 2022

WGSL expects a matCx2 to have a matrix stride of 8 (inner vector components to be aligned to 8 bytes including itself).
SPIR-V/GLSL/HLSL expect a matCx2 to have a matrix stride of 16 (inner vector components to be aligned to 16 bytes including itself).

Solution

Replace matCx2 with a sequence of C vec2's (since vec2s alignment is 8) and reconstruct the matrix in the shader.

References

WGSL Alignment and Size
GLSL Standard Uniform Block Layout
HLSL DirectXShaderCompiler Buffer-Packing Wiki
Vulkan Offset and Stride Assignment

Related issues

gfx-rs/naga#1400 (gfx-rs/naga#1400 (comment)), #4375, #4376 - inverse of this issue (concerning the frontends)

@teoxoy
Copy link
Member Author

teoxoy commented Apr 11, 2022

Reopened since the PR only solved the issue in the HLSL backend. The GLSL backend still needs changes.

@teoxoy teoxoy reopened this Apr 11, 2022
@teoxoy teoxoy added lang: GLSL OpenGL Shading Language and removed lang: HLSL D3D Shading Language labels Apr 11, 2022
@cwfitzgerald cwfitzgerald added the help required We need community help to make this happen. label Oct 26, 2022
@teoxoy
Copy link
Member Author

teoxoy commented Jan 19, 2023

We'll have to do this for spv as well... See gfx-rs/naga#2034.

@teoxoy teoxoy added the lang: SPIR-V Vulkan's Shading Language label Jan 19, 2023
@teoxoy teoxoy changed the title [glsl/hlsl-out] Matrix of the form matCx2 from WGSL not getting translated properly to GLSL/HLSL (only in uniform buffers) Matrix of the form matCx2 not getting translated properly when in an uniform buffer Jan 19, 2023
@cwfitzgerald cwfitzgerald added the naga Shader Translator label Oct 25, 2023
@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added type: bug Something isn't working and removed kind: bug labels Oct 25, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Nov 3, 2023
@jimblandy jimblandy changed the title Matrix of the form matCx2 not getting translated properly when in an uniform buffer Matrix of the form matCx2 not getting translated properly when in a uniform buffer Apr 21, 2024
@jimblandy jimblandy self-assigned this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion help required We need community help to make this happen. lang: GLSL OpenGL Shading Language lang: SPIR-V Vulkan's Shading Language naga Shader Translator type: bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants