mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Hold BGL alive by BG (#2075)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user