From 00a6032eb7f51877da8d24fce01bb5ea9be54a89 Mon Sep 17 00:00:00 2001 From: Jamie Nicol Date: Tue, 19 Nov 2024 15:27:47 +0000 Subject: [PATCH] [naga spv-out] Handle nested arrays when adding matrix decorations 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. --- naga/src/back/spv/writer.rs | 13 +++++++------ naga/tests/out/spv/globals.spvasm | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index 5cc37de78..b3dd14532 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -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, diff --git a/naga/tests/out/spv/globals.spvasm b/naga/tests/out/spv/globals.spvasm index 4aa6a10ad..31e836531 100644 --- a/naga/tests/out/spv/globals.spvasm +++ b/naga/tests/out/spv/globals.spvasm @@ -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