1346: Make implicit ids actually errors to start with r=kvark a=kvark

**Connections**
Follow-up to #1341

**Description**
Turns out, leaving the indices `Vacant` is also not an option, since the `hub.rs` code considers this an internal error (unexpected), and panics.

**Testing**
Tested on Austin's examples in Gecko

Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
bors[bot] 2021-04-20 21:35:12 +00:00 committed by GitHub
commit 43798a502f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 17 deletions

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)?;

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

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) {