From cfed43face0311d9ca5638307ff713f8ecd6ce78 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 24 Jun 2021 01:40:18 -0400 Subject: [PATCH] Update submission indices on all stateless resources --- wgpu-core/src/command/render.rs | 8 ++++++++ wgpu-core/src/device/queue.rs | 36 ++++++++++++++++++++++++++------- wgpu-core/src/hub.rs | 1 + wgpu-core/src/track/mod.rs | 5 +++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index cdb87fd6c7..de9db623bb 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1720,6 +1720,14 @@ impl Global { info.trackers .merge_extend(&bundle.used) .map_pass_err(scope)?; + // Start tracking the bind groups specifically, as they are the only + // compound resources, to make it easier to update submission indices + // later at submission time. + cmd_buf + .trackers + .bind_groups + .merge_extend(&bundle.used.bind_groups) + .unwrap(); state.reset_bundle(); } } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 7769155fc4..8d67aecc59 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -616,7 +616,8 @@ impl Global { let (mut buffer_guard, mut token) = hub.buffers.write(&mut token); let (texture_guard, mut token) = hub.textures.write(&mut token); let (texture_view_guard, mut token) = hub.texture_views.read(&mut token); - let (sampler_guard, _) = hub.samplers.read(&mut token); + let (sampler_guard, mut token) = hub.samplers.read(&mut token); + let (query_set_guard, _) = hub.query_sets.read(&mut token); let mut required_buffer_inits = RequiredBufferInits::default(); //Note: locking the trackers has to be done after the storages @@ -703,15 +704,21 @@ impl Global { } } for id in cmdbuf.trackers.bind_groups.used() { - if !bind_group_guard[id].life_guard.use_at(submit_index) { + let bg = &bind_group_guard[id]; + if !bg.life_guard.use_at(submit_index) { device.temp_suspected.bind_groups.push(id); } - } - for id in cmdbuf.trackers.samplers.used() { - if !sampler_guard[id].life_guard.use_at(submit_index) { - device.temp_suspected.samplers.push(id); + // We need to update the submission indices for the contained + // state-less (!) resources as well, so that they don't get + // deleted too early if the parent bind group goes out of scope. + for sub_id in bg.used.views.used() { + texture_view_guard[sub_id].life_guard.use_at(submit_index); + } + for sub_id in bg.used.samplers.used() { + sampler_guard[sub_id].life_guard.use_at(submit_index); } } + assert!(cmdbuf.trackers.samplers.is_empty()); for id in cmdbuf.trackers.compute_pipes.used() { if !compute_pipe_guard[id].life_guard.use_at(submit_index) { device.temp_suspected.compute_pipelines.push(id); @@ -722,10 +729,25 @@ impl Global { device.temp_suspected.render_pipelines.push(id); } } + for id in cmdbuf.trackers.query_sets.used() { + if !query_set_guard[id].life_guard.use_at(submit_index) { + device.temp_suspected.query_sets.push(id); + } + } for id in cmdbuf.trackers.bundles.used() { - if !render_bundle_guard[id].life_guard.use_at(submit_index) { + let bundle = &render_bundle_guard[id]; + if !bundle.life_guard.use_at(submit_index) { device.temp_suspected.render_bundles.push(id); } + // We need to update the submission indices for the contained + // state-less (!) resources as well, excluding the bind groups. + // They don't get deleted too early if the bundle goes out of scope. + for sub_id in bundle.used.compute_pipes.used() { + compute_pipe_guard[sub_id].life_guard.use_at(submit_index); + } + for sub_id in bundle.used.render_pipes.used() { + render_pipe_guard[sub_id].life_guard.use_at(submit_index); + } } let mut baked = cmdbuf.into_baked(); diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 2315d1915e..85676e44b8 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -263,6 +263,7 @@ impl Access> for Device {} impl Access> for CommandBuffer {} impl Access> for RenderPipeline {} impl Access> for ComputePipeline {} +impl Access> for Sampler {} impl Access> for Device {} impl Access> for BindGroupLayout {} impl Access> for Root {} diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index aa8dd97b2c..9d36df5601 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -271,6 +271,11 @@ impl ResourceTracker { .map(move |(&index, resource)| Valid(S::Id::zip(index, resource.epoch, backend))) } + /// Return true if there is nothing here. + pub fn is_empty(&self) -> bool { + self.map.is_empty() + } + /// Clear the tracked contents. fn clear(&mut self) { self.map.clear();