Update submission indices on all stateless resources

This commit is contained in:
Dzmitry Malyshau
2021-06-24 01:40:18 -04:00
parent 632f85b703
commit cfed43face
4 changed files with 43 additions and 7 deletions

View File

@@ -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();
}
}

View File

@@ -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
@@ -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);
@@ -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();

View File

@@ -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 {}

View File

@@ -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();