Skip to content

Commit

Permalink
Merge #1550
Browse files Browse the repository at this point in the history
1550: Update submission indices on all stateless resources r=pythonesque a=kvark

**Connections**
This is partially a regression by #1547, but also fixing more things.

**Description**
We stopped tracking the stateless resources included in bind groups. But we still need to update their submission indices, so that they don't get removed too early.
The PR also does the same for render bundles, but with a twist: bind groups used in a bundle are merged early.

**Testing**
untested


Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
bors[bot] and kvark authored Jun 24, 2021
2 parents 8ddb3be + cfed43f commit ebe2152
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
8 changes: 8 additions & 0 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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();
}
}
Expand Down
36 changes: 29 additions & 7 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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
Expand Down Expand Up @@ -703,15 +704,21 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
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);
Expand All @@ -722,10 +729,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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();
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl<A: hal::Api> Access<QuerySet<A>> for Device<A> {}
impl<A: hal::Api> Access<QuerySet<A>> for CommandBuffer<A> {}
impl<A: hal::Api> Access<QuerySet<A>> for RenderPipeline<A> {}
impl<A: hal::Api> Access<QuerySet<A>> for ComputePipeline<A> {}
impl<A: hal::Api> Access<QuerySet<A>> for Sampler<A> {}
impl<A: hal::Api> Access<ShaderModule<A>> for Device<A> {}
impl<A: hal::Api> Access<ShaderModule<A>> for BindGroupLayout<A> {}
impl<A: hal::Api> Access<Buffer<A>> for Root {}
Expand Down
5 changes: 5 additions & 0 deletions wgpu-core/src/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ impl<S: ResourceState> ResourceTracker<S> {
.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();
Expand Down

0 comments on commit ebe2152

Please sign in to comment.