From 776ed52157cb4db47a26fa96fb05afc68f6847d6 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 3 Oct 2023 15:24:21 +0200 Subject: [PATCH] Fully support bind group layout deduplication in Pipeline::get_bind_group_layout --- wgpu-core/src/device/global.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index b8817146a2c..e592d113bab 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -1924,7 +1924,24 @@ impl Global { 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::::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); };