From 758bb16d014af327b71af6b236d232a14aafff45 Mon Sep 17 00:00:00 2001 From: yanchith Date: Tue, 24 Sep 2019 19:04:35 +0200 Subject: [PATCH] Make sure submissions are tracked --- wgpu-native/src/command/mod.rs | 1 + wgpu-native/src/device.rs | 13 +++++++++++-- wgpu-native/src/resource.rs | 6 ++++++ wgpu-native/src/track/mod.rs | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index baf4cfc05..56f77e1e3 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -160,6 +160,7 @@ impl CommandBuffer { }); base.views.merge_extend(&head.views).unwrap(); base.bind_groups.merge_extend(&head.bind_groups).unwrap(); + base.samplers.merge_extend(&head.samplers).unwrap(); let stages = all_buffer_stages() | all_image_stages(); unsafe { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 77843a002..7a1407764 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -1273,7 +1273,9 @@ pub fn device_create_bind_group( } binding_model::BindingResource::Sampler(id) => { assert_eq!(decl.ty, binding_model::BindingType::Sampler); - let sampler = &sampler_guard[id]; + let sampler = used.samplers + .use_extend(&*sampler_guard, id, (), ()) + .unwrap(); hal::pso::Descriptor::Sampler(&sampler.raw) } binding_model::BindingResource::TextureView(id) => { @@ -1471,7 +1473,8 @@ pub fn queue_submit(queue_id: QueueId, command_buffer_ids: &[Comm let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); let (buffer_guard, mut token) = hub.buffers.read(&mut token); let (texture_guard, mut token) = hub.textures.read(&mut token); - let (mut texture_view_guard, _) = hub.texture_views.write(&mut token); + let (mut texture_view_guard, mut token) = hub.texture_views.write(&mut token); + let (sampler_guard, _) = hub.samplers.read(&mut token); //TODO: if multiple command buffers are submitted, we can re-use the last // native command buffer of the previous chain instead of always creating @@ -1524,6 +1527,12 @@ pub fn queue_submit(queue_id: QueueId, command_buffer_ids: &[Comm .submission_index .store(submit_index, Ordering::Release); } + for id in comb.trackers.samplers.used() { + sampler_guard[id] + .life_guard + .submission_index + .store(submit_index, Ordering::Release); + } // execute resource transitions let mut transit = device.com_allocator.extend(comb); diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index fd0c67c80..a543a5244 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -363,3 +363,9 @@ pub struct Sampler { pub(crate) device_id: Stored, pub(crate) life_guard: LifeGuard, } + +impl Borrow for Sampler { + fn borrow(&self) -> &RefCount { + &self.life_guard.ref_count + } +} diff --git a/wgpu-native/src/track/mod.rs b/wgpu-native/src/track/mod.rs index b1d1a4470..105a35086 100644 --- a/wgpu-native/src/track/mod.rs +++ b/wgpu-native/src/track/mod.rs @@ -441,6 +441,7 @@ impl TrackerSet { self.textures.clear(); self.views.clear(); self.bind_groups.clear(); + self.samplers.clear(); } /// Try to optimize the tracking representation. @@ -449,6 +450,7 @@ impl TrackerSet { self.textures.optimize(); self.views.optimize(); self.bind_groups.optimize(); + self.samplers.optimize(); } /// Merge all the trackers of another instance by extending @@ -458,6 +460,7 @@ impl TrackerSet { self.textures.merge_extend(&other.textures).unwrap(); self.views.merge_extend(&other.views).unwrap(); self.bind_groups.merge_extend(&other.bind_groups).unwrap(); + self.samplers.merge_extend(&other.samplers).unwrap(); } pub fn backend(&self) -> Backend {