From 8505a39f6ad329ad3cae8defe4bfbe57b11cf5ef Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 20 Apr 2021 17:32:40 -0400 Subject: [PATCH] Make implicit ids actually errors to start with --- wgpu-core/src/command/render.rs | 3 ++- wgpu-core/src/device/mod.rs | 14 ++++++++------ wgpu-core/src/hub.rs | 16 ++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index af5aee3c4..3db50d1af 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1109,7 +1109,8 @@ impl Global { .trackers .bind_groups .use_extend(&*bind_group_guard, bind_group_id, (), ()) - .unwrap(); + .map_err(|_| RenderCommandError::InvalidBindGroup(bind_group_id)) + .map_pass_err(scope)?; bind_group .validate_dynamic_bindings(&temp_offsets) .map_pass_err(scope)?; diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 4275b16ad..3379a4b82 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -56,6 +56,8 @@ pub const MAX_VERTEX_BUFFERS: usize = 16; pub const MAX_ANISOTROPY: u8 = 16; pub const SHADER_STAGE_COUNT: usize = 3; +const IMPLICIT_FAILURE: &str = "failed implicit"; + pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; pub fn all_buffer_stages() -> hal::pso::PipelineStage { @@ -1844,7 +1846,7 @@ impl Device { } None => { let bgl = self.create_bind_group_layout(self_id, None, map)?; - bgl_guard.insert(*bgl_id, bgl); + bgl_guard.force_replace(*bgl_id, bgl); } }; } @@ -1855,7 +1857,7 @@ impl Device { push_constant_ranges: Cow::Borrowed(&[]), //TODO? }; let layout = self.create_pipeline_layout(self_id, &layout_desc, bgl_guard)?; - pipeline_layout_guard.insert(ids.root_id, layout); + pipeline_layout_guard.force_replace(ids.root_id, layout); Ok(ids.root_id) } @@ -1874,9 +1876,9 @@ impl Device { // This has to be done first, or otherwise the IDs may be pointing to entries // that are not even in the storage. if let Some(ref ids) = implicit_context { - pipeline_layout_guard.make_room(ids.root_id); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); for &bgl_id in ids.group_ids.iter() { - bgl_guard.make_room(bgl_id); + bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); } } @@ -2005,9 +2007,9 @@ impl Device { // This has to be done first, or otherwise the IDs may be pointing to entries // that are not even in the storage. if let Some(ref ids) = implicit_context { - pipeline_layout_guard.make_room(ids.root_id); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); for &bgl_id in ids.group_ids.iter() { - bgl_guard.make_room(bgl_id); + bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); } } diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index d6a1dc785..5054a7f5c 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -160,19 +160,10 @@ impl Storage { } } - fn make_room_impl(&mut self, index: usize) { + fn insert_impl(&mut self, index: usize, element: Element) { if index >= self.map.len() { self.map.resize_with(index + 1, || Element::Vacant); } - } - - pub(crate) fn make_room(&mut self, id: I) { - let (index, _, _) = id.unzip(); - self.make_room_impl(index as usize) - } - - fn insert_impl(&mut self, index: usize, element: Element) { - self.make_room_impl(index); match std::mem::replace(&mut self.map[index], element) { Element::Vacant => {} _ => panic!("Index {:?} is already occupied", index), @@ -189,6 +180,11 @@ impl Storage { self.insert_impl(index as usize, Element::Error(epoch, label.to_string())) } + pub(crate) fn force_replace(&mut self, id: I, value: T) { + let (index, epoch, _) = id.unzip(); + self.map[index as usize] = Element::Occupied(value, epoch); + } + pub(crate) fn remove(&mut self, id: I) -> Option { let (index, epoch, _) = id.unzip(); match std::mem::replace(&mut self.map[index as usize], Element::Vacant) {