[naga hlsl-out] Handle additional cases of Cx2 matrices #7438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
Fixes #4423.
Description
Fixes the original issue in #4423, and a few more that I found while working on the fix. Because memory layouts differ between HLSL and WGSL in the case of C-column-by-2-row matrices, we store such matrices as C separate vectors. There is a comment in
back::hlsl
describing this in more detail. There are a lot of different kinds of accesses to these matrices that need to be adjusted in code generation, and we missed some:m
that is a Cx2 matrix, tried to obtain the value to be stored from memberm
in the source struct, but it is actually stored in C separate membersm_0
...m_<C-1>
.__matCx2
struct with C separate members.write_value_type
to declare a temporary for the value to be stored, butwrite_value_type
does not support writing struct types.The functional fixes are in the first commit. The second commit does some refactoring to use a helper method that I added in additional places, but it's just refactoring, and I'm not highly confident in any part of these changes, so I'd be fine to drop the refactoring commit if we decide it's not worth the risk.
Testing
Adds a snapshot test with a variety of Cx2 matrix cases.
Squash or Rebase?
If we keep the refactor commit, then rebase.
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.