diff --git a/CHANGELOG.md b/CHANGELOG.md index 787cb76a4e..ad6c7913e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -170,6 +170,10 @@ By @atlv24 in [#5383](https://github.com/gfx-rs/wgpu/pull/5383) - Added support for pipeline-overridable constants to the WebGPU backend by @DouglasDwyer in [#5688](https://github.com/gfx-rs/wgpu/pull/5688) +#### Naga + +- In spv-out don't decorate a `BindingArray`'s type with `Block` if the type is a struct with a runtime array by @Vecvec in [#5776](https://github.com/gfx-rs/wgpu/pull/5776) + ## v0.20.0 (2024-04-28) ### Major Changes diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index 4b1aa3026a..72c3d47733 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -1763,8 +1763,27 @@ impl Writer { if let crate::AddressSpace::Storage { .. } = global_variable.space { match ir_module.types[global_variable.ty].inner { crate::TypeInner::BindingArray { base, .. } => { - let decorated_id = self.get_type_id(LookupType::Handle(base)); - self.decorate(decorated_id, Decoration::Block, &[]); + let ty = &ir_module.types[base]; + let mut should_decorate = true; + // Check if the type has a runtime array. + // A normal runtime array gets validated out, + // so only structs can be with runtime arrays + if let crate::TypeInner::Struct { ref members, .. } = ty.inner { + // only the last member in a struct can be dynamically sized + if let Some(last_member) = members.last() { + if let &crate::TypeInner::Array { + size: crate::ArraySize::Dynamic, + .. + } = &ir_module.types[last_member.ty].inner + { + should_decorate = false; + } + } + } + if should_decorate { + let decorated_id = self.get_type_id(LookupType::Handle(base)); + self.decorate(decorated_id, Decoration::Block, &[]); + } } _ => (), }; diff --git a/naga/tests/out/spv/binding-buffer-arrays.spvasm b/naga/tests/out/spv/binding-buffer-arrays.spvasm index 8595962cef..bac8757f36 100644 --- a/naga/tests/out/spv/binding-buffer-arrays.spvasm +++ b/naga/tests/out/spv/binding-buffer-arrays.spvasm @@ -19,7 +19,6 @@ OpMemberDecorate %10 0 Offset 0 OpDecorate %11 NonWritable OpDecorate %11 DescriptorSet 0 OpDecorate %11 Binding 0 -OpDecorate %7 Block OpDecorate %15 DescriptorSet 0 OpDecorate %15 Binding 10 OpDecorate %16 Block