Skip to content

Commit

Permalink
Error instead of panic in check bind (gfx-rs#6012)
Browse files Browse the repository at this point in the history
Removed zipping of binding entries introduced in 4a19ac2 (to make sure binding numbers actually match) and add unknown error for fallback.
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
sagudev authored and cwfitzgerald committed Jul 31, 2024
1 parent 24aeee2 commit e3b5c1a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 89 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Bottom level categories:

## Unreleased

### Bug Fixes

#### General

- Fix function for checking bind compatibility to error instead of panic. By @sagudev [#6012](https://github.com/gfx-rs/wgpu/pull/6012)

## 22.0.0 (2024-07-17)

### Overview
Expand Down
69 changes: 35 additions & 34 deletions wgpu-core/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,49 +142,50 @@ mod compat {

let mut errors = Vec::new();

let mut expected_bgl_entries = expected_bgl.entries.iter();
let mut assigned_bgl_entries = assigned_bgl.entries.iter();
let zipped = crate::utils::ZipWithProperAdvance::new(
&mut expected_bgl_entries,
&mut assigned_bgl_entries,
);

for ((&binding, expected_entry), (_, assigned_entry)) in zipped {
if assigned_entry.visibility != expected_entry.visibility {
errors.push(EntryError::Visibility {
binding,
expected: expected_entry.visibility,
assigned: assigned_entry.visibility,
});
}
if assigned_entry.ty != expected_entry.ty {
errors.push(EntryError::Type {
binding,
expected: expected_entry.ty,
assigned: assigned_entry.ty,
});
}
if assigned_entry.count != expected_entry.count {
errors.push(EntryError::Count {
binding,
expected: expected_entry.count,
assigned: assigned_entry.count,
});
for (&binding, expected_entry) in expected_bgl.entries.iter() {
if let Some(assigned_entry) = assigned_bgl.entries.get(binding) {
if assigned_entry.visibility != expected_entry.visibility {
errors.push(EntryError::Visibility {
binding,
expected: expected_entry.visibility,
assigned: assigned_entry.visibility,
});
}
if assigned_entry.ty != expected_entry.ty {
errors.push(EntryError::Type {
binding,
expected: expected_entry.ty,
assigned: assigned_entry.ty,
});
}
if assigned_entry.count != expected_entry.count {
errors.push(EntryError::Count {
binding,
expected: expected_entry.count,
assigned: assigned_entry.count,
});
}
} else {
errors.push(EntryError::ExtraExpected { binding });
}
}

for (&binding, _) in expected_bgl_entries {
errors.push(EntryError::ExtraExpected { binding });
for (&binding, _) in assigned_bgl.entries.iter() {
if !expected_bgl.entries.contains_key(binding) {
errors.push(EntryError::ExtraAssigned { binding });
}
}

for (&binding, _) in assigned_bgl_entries {
errors.push(EntryError::ExtraAssigned { binding });
}
#[derive(Clone, Debug, Error)]
#[error("Unknown reason")]
struct Unknown();

Err(Error::Incompatible {
expected_bgl: expected_bgl.error_ident(),
assigned_bgl: assigned_bgl.error_ident(),
inner: MultiError::new(errors.drain(..)).unwrap(),
inner: MultiError::new(errors.drain(..)).unwrap_or_else(|| {
MultiError::new(core::iter::once(Unknown())).unwrap()
}),
})
}
} else {
Expand Down
1 change: 0 additions & 1 deletion wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub mod resource;
mod snatch;
pub mod storage;
mod track;
mod utils;
// This is public for users who pre-compile shaders while still wanting to
// preserve all run-time checks that `wgpu-core` does.
// See <https://github.com/gfx-rs/wgpu/issues/3103>, after which this can be
Expand Down
54 changes: 0 additions & 54 deletions wgpu-core/src/utils.rs

This file was deleted.

0 comments on commit e3b5c1a

Please sign in to comment.