-
Notifications
You must be signed in to change notification settings - Fork 193
[hlsl-out] fix matrix not being declared as transposed #1784
Conversation
I'm confused, this PR appears to be making the hlsl declaration types be the same as wgsl, with column first and then row, but the comments and the PR say that it should be inverted. |
HLSL's matrix type is of the form matrix type in GLSL/WGSL/MSL is of the form So passing column first, row second, to HLSL will cause the matrix to be the transposed version of the original. |
Before this PR, trying to change the access test as in 0d920f5 and passing the resulting HLSL code trough DXC results in the error below (too many elements in vector initialization (expected 4 elements, have 5)) see https://shader-playground.timjones.io/582968a71c9665f384078ed17280d4f3 With the fix in this PR this no longer happens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment, but otherwise looks okay
Thank you for the PR! |
No problem. Regarding documentation, there is already this nicely written note Lines 9 to 21 in 05f050f
is there anything else you'd like me to add? |
So to me this comment reads like the current code is already correct, isn't it? |
This line is not right and what this PR is solving. I fixed this doc line in this PR as well. This whole thing is quite confusing and I got confused as well while trying to fix it. |
The easiest way for me to visualize this was to compare DXC's SPIR-V output with naga's SPIR-V output since DXC is also transposing the matrix when translating to SPIR-V. DXC HLSL -> SPIR-V https://shader-playground.timjones.io/29a832dba447e0ba043258dc84a753e7 naga WGSL -> SPIR-V https://shader-playground.timjones.io/748b0d2af9ac941580a1278f2a853123 |
Sorry, I'm not following this. Here is the GLSL code for matrix type: TypeInner::Matrix {
columns,
rows,
width,
} => write!(
self.out,
"{}mat{}x{}",
glsl_scalar(crate::ScalarKind::Float, width)?.prefix,
columns as u8,
rows as u8
)?, Clearly it makes it so |
Sorry I think I made my explanation more confusing than it should have been. See last comment line below with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience!
I launched a small sanity test in https://github.com/gfx-rs/naga/runs/5714948153?check_suite_focus=true to see if the current algorithm produces invalid HLSL, and indeed that's the case.
HLSL uses inverted col/row notation (relative to GLSL, WGSL, MSL).
i.e.
mat3x2
in WGSL =float2x3
in HLSLReference: HLSL Matrix Doc
related to original change in #1199