Skip to content

Commit

Permalink
Fully support bind group layout deduplication in Pipeline::get_bind_g…
Browse files Browse the repository at this point in the history
…roup_layout
  • Loading branch information
nical committed Oct 3, 2023
1 parent 64668ed commit 6b135e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ pub struct BindGroupLayoutInner<A: hal::Api> {
}

impl<A: hal::Api> BindGroupLayout<A> {
#[track_caller]
pub(crate) fn assume_deduplicated(&self) -> &BindGroupLayoutInner<A> {
self.as_inner().unwrap()
}
Expand Down
19 changes: 18 additions & 1 deletion wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,24 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index),
};

bgl_guard[*id].multi_ref_count.inc();
let layout = &bgl_guard[*id];
layout.multi_ref_count.inc();

if G::ids_are_generated_in_wgpu() {
return (id.0, None);
}

// The ID is provided externally, so we must create a new bind group layout
// with the given ID as a duplicate of the existing one.
let new_layout = BindGroupLayout {
device_id: layout.device_id.clone(),
inner: crate::binding_model::BglOrDuplicate::<A>::Duplicate(*id),
multi_ref_count: crate::MultiRefCount::new(),
};

let fid = hub.bind_group_layouts.prepare(id_in);
let id = fid.assign(new_layout, &mut Token::root());

return (id.0, None);
};

Expand Down

0 comments on commit 6b135e8

Please sign in to comment.