From 6f68d3dffa0337256134ebf9187e57a33cd5234e Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 27 Feb 2024 11:08:21 +0100 Subject: [PATCH] Correctly set the tacker sizes before executing render bundles --- wgpu-core/src/command/bundle.rs | 38 +++++++++++++++++++++++++-------- wgpu-core/src/track/mod.rs | 24 +++------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 9000c1b4b..ddb112ec2 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -350,24 +350,44 @@ impl RenderBundleEncoder { ) -> Result, RenderBundleError> { let bind_group_guard = hub.bind_groups.read(); let pipeline_guard = hub.render_pipelines.read(); - let query_set_guard = hub.query_sets.read(); let buffer_guard = hub.buffers.read(); - let texture_guard = hub.textures.read(); let mut state = State { - trackers: RenderBundleScope::new( - &*buffer_guard, - &*texture_guard, - &*bind_group_guard, - &*pipeline_guard, - &*query_set_guard, - ), + trackers: RenderBundleScope::new(), pipeline: None, bind: (0..hal::MAX_BIND_GROUPS).map(|_| None).collect(), vertex: (0..hal::MAX_VERTEX_BUFFERS).map(|_| None).collect(), index: None, flat_dynamic_offsets: Vec::new(), }; + + let indices = &device.tracker_indices; + state + .trackers + .buffers + .write() + .set_size(indices.buffers.size()); + state + .trackers + .textures + .write() + .set_size(indices.textures.size()); + state + .trackers + .bind_groups + .write() + .set_size(indices.bind_groups.size()); + state + .trackers + .render_pipelines + .write() + .set_size(indices.render_pipelines.size()); + state + .trackers + .query_sets + .write() + .set_size(indices.query_sets.size()); + let mut commands = Vec::new(); let mut buffer_memory_init_actions = Vec::new(); let mut texture_memory_init_actions = Vec::new(); diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index c0895c44a..9ca37ebad 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -103,7 +103,6 @@ mod texture; use crate::{ binding_model, command, conv, hal_api::HalApi, id, pipeline, resource, snatch::SnatchGuard, - storage::Storage, }; use parking_lot::{Mutex, RwLock}; @@ -479,31 +478,14 @@ pub(crate) struct RenderBundleScope { impl RenderBundleScope { /// Create the render bundle scope and pull the maximum IDs from the hubs. - pub fn new( - buffers: &Storage>, - textures: &Storage>, - bind_groups: &Storage>, - render_pipelines: &Storage>, - query_sets: &Storage>, - ) -> Self { - let value = Self { + pub fn new() -> Self { + Self { buffers: RwLock::new(BufferUsageScope::new()), textures: RwLock::new(TextureUsageScope::new()), bind_groups: RwLock::new(StatelessTracker::new()), render_pipelines: RwLock::new(StatelessTracker::new()), query_sets: RwLock::new(StatelessTracker::new()), - }; - - value.buffers.write().set_size(buffers.len()); - value.textures.write().set_size(textures.len()); - value.bind_groups.write().set_size(bind_groups.len()); - value - .render_pipelines - .write() - .set_size(render_pipelines.len()); - value.query_sets.write().set_size(query_sets.len()); - - value + } } /// Merge the inner contents of a bind group into the render bundle tracker.