Hold BGL alive by BG (#2075)

This commit is contained in:
Dzmitry Malyshau
2021-10-15 11:40:49 -04:00
committed by GitHub
parent ec8413dfcb
commit 41c595cfcf
3 changed files with 16 additions and 0 deletions

View File

@@ -421,6 +421,14 @@ pub struct BindGroupLayoutDescriptor<'a> {
pub(crate) type BindEntryMap = FastHashMap<u32, wgt::BindGroupLayoutEntry>;
/// 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<A: hal::Api> {
pub(crate) raw: A::BindGroupLayout,

View File

@@ -397,6 +397,10 @@ impl<A: HalApi> LifetimeTracker<A> {
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()

View File

@@ -1606,6 +1606,9 @@ impl<A: HalApi> Device<A> {
.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<A: HalApi> Device<A> {
.bind_group_layouts
.iter()
.map(|&id| {
// manually add a dependency to BGL
bgl_guard.get(id).unwrap().multi_ref_count.inc();
id::Valid(id)
})