Make implicit ids actually errors to start with

This commit is contained in:
Dzmitry Malyshau committed 2021-04-20 17:32:40 -04:00
1 parent 8704a6e3b5
commit 8505a39f6a
3 files changed
+16 -17

No files matched your search

+2 -1
View File
@@ -1109,7 +1109,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.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)?;
+8 -6
View File
@@ -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<Label<'a>>;
pub fn all_buffer_stages() -> hal::pso::PipelineStage {
@@ -1844,7 +1846,7 @@ impl<B: GfxBackend> Device<B> {
}
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<B: GfxBackend> Device<B> {
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<B: GfxBackend> Device<B> {
// 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<B: GfxBackend> Device<B> {
// 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);
}
}
+6 -10
View File
@@ -160,19 +160,10 @@ impl<T, I: TypedId> Storage<T, I> {
}
}
fn make_room_impl(&mut self, index: usize) {
fn insert_impl(&mut self, index: usize, element: Element<T>) {
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<T>) {
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<T, I: TypedId> Storage<T, I> {
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<T> {
let (index, epoch, _) = id.unzip();
match std::mem::replace(&mut self.map[index as usize], Element::Vacant) {