diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index b5d3180645..457b0b9142 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -421,6 +421,14 @@ pub struct BindGroupLayoutDescriptor<'a> { pub(crate) type BindEntryMap = FastHashMap; +/// Bind group layout. +/// +/// The lifetime of BGLs is a bit special. They are only referenced on CPU +/// without considering GPU operations. And on CPU they get manual +/// inc-refs and dec-refs. In particular, the following objects depend on them: +/// - produced bind groups +/// - produced pipeline layouts +/// - pipelines with implicit layouts #[derive(Debug)] pub struct BindGroupLayout { pub(crate) raw: A::BindGroupLayout, diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 1d099094d1..c4b36f9745 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -397,6 +397,10 @@ impl LifetimeTracker { if let Some(res) = hub.bind_groups.unregister_locked(id.0, &mut *guard) { self.suspected_resources.add_trackers(&res.used); + self.suspected_resources + .bind_group_layouts + .push(res.layout_id); + let submit_index = res.life_guard.life_count(); self.active .iter_mut() diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 61179ba214..3746154210 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1606,6 +1606,9 @@ impl Device { .map_err(DeviceError::from)? }; + // manually add a dependency on BGL + layout.multi_ref_count.inc(); + Ok(binding_model::BindGroup { raw, device_id: Stored { @@ -1874,6 +1877,7 @@ impl Device { .bind_group_layouts .iter() .map(|&id| { + // manually add a dependency to BGL bgl_guard.get(id).unwrap().multi_ref_count.inc(); id::Valid(id) })