Skip to content

Commit

Permalink
[naga spv-out] Handle nested arrays when adding matrix decorations
Browse files Browse the repository at this point in the history
Previously we only checked whether the outermost array's subtype was a
Matrix when determining whether to add ColMajor and MatrixStride
decorations, meaning arrays of arrays of matrices would not be
decorated.
  • Loading branch information
jamienicol authored and jimblandy committed Nov 20, 2024
1 parent 6f5014f commit 00a6032
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions naga/src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,12 +1800,13 @@ impl Writer {
}
}

// Matrices and arrays of matrices both require decorations,
// so "see through" an array to determine if they're needed.
let member_array_subty_inner = match arena[member.ty].inner {
crate::TypeInner::Array { base, .. } => &arena[base].inner,
ref other => other,
};
// Matrices and (potentially nested) arrays of matrices both require decorations,
// so "see through" any arrays to determine if they're needed.
let mut member_array_subty_inner = &arena[member.ty].inner;
while let crate::TypeInner::Array { base, .. } = *member_array_subty_inner {
member_array_subty_inner = &arena[base].inner;
}

if let crate::TypeInner::Matrix {
columns: _,
rows,
Expand Down
4 changes: 4 additions & 0 deletions naga/tests/out/spv/globals.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ OpDecorate %45 DescriptorSet 0
OpDecorate %45 Binding 6
OpDecorate %46 Block
OpMemberDecorate %46 0 Offset 0
OpMemberDecorate %46 0 ColMajor
OpMemberDecorate %46 0 MatrixStride 16
OpDecorate %48 DescriptorSet 0
OpDecorate %48 Binding 7
OpDecorate %49 Block
OpMemberDecorate %49 0 Offset 0
OpMemberDecorate %49 0 ColMajor
OpMemberDecorate %49 0 MatrixStride 8
OpDecorate %116 BuiltIn LocalInvocationId
%2 = OpTypeVoid
%3 = OpTypeBool
Expand Down

0 comments on commit 00a6032

Please sign in to comment.