Skip to content

Commit

Permalink
Fix double decoration if a binding array contains a struct with a run…
Browse files Browse the repository at this point in the history
…time array (#5776)
  • Loading branch information
Vecvec authored Jun 10, 2024
1 parent 5790514 commit 73401ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions naga/src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &[]);
}
}
_ => (),
};
Expand Down
1 change: 0 additions & 1 deletion naga/tests/out/spv/binding-buffer-arrays.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73401ed

Please sign in to comment.