Fix double decoration if a binding array contains a struct with a runtime array (#5776)

This commit is contained in:
Vecvec
2024-06-10 21:20:33 +12:00
committed by GitHub
parent 5790514e63
commit 73401ede25
3 changed files with 25 additions and 3 deletions

View File

@@ -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

View File

@@ -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, &[]);
}
}
_ => (),
};

View File

@@ -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