Skip to content

Commit e3b5c1a

Browse files
sagudevcwfitzgerald
authored andcommitted
Error instead of panic in check bind (gfx-rs#6012)
Removed zipping of binding entries introduced in 4a19ac2 (to make sure binding numbers actually match) and add unknown error for fallback. # Conflicts: # CHANGELOG.md
1 parent 24aeee2 commit e3b5c1a

File tree

4 files changed

+41
-89
lines changed

4 files changed

+41
-89
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Bottom level categories:
3939

4040
## Unreleased
4141

42+
### Bug Fixes
43+
44+
#### General
45+
46+
- Fix function for checking bind compatibility to error instead of panic. By @sagudev [#6012](https://github.com/gfx-rs/wgpu/pull/6012)
47+
4248
## 22.0.0 (2024-07-17)
4349

4450
### Overview

wgpu-core/src/command/bind.rs

+35-34
Original file line numberDiff line numberDiff line change
@@ -142,49 +142,50 @@ mod compat {
142142

143143
let mut errors = Vec::new();
144144

145-
let mut expected_bgl_entries = expected_bgl.entries.iter();
146-
let mut assigned_bgl_entries = assigned_bgl.entries.iter();
147-
let zipped = crate::utils::ZipWithProperAdvance::new(
148-
&mut expected_bgl_entries,
149-
&mut assigned_bgl_entries,
150-
);
151-
152-
for ((&binding, expected_entry), (_, assigned_entry)) in zipped {
153-
if assigned_entry.visibility != expected_entry.visibility {
154-
errors.push(EntryError::Visibility {
155-
binding,
156-
expected: expected_entry.visibility,
157-
assigned: assigned_entry.visibility,
158-
});
159-
}
160-
if assigned_entry.ty != expected_entry.ty {
161-
errors.push(EntryError::Type {
162-
binding,
163-
expected: expected_entry.ty,
164-
assigned: assigned_entry.ty,
165-
});
166-
}
167-
if assigned_entry.count != expected_entry.count {
168-
errors.push(EntryError::Count {
169-
binding,
170-
expected: expected_entry.count,
171-
assigned: assigned_entry.count,
172-
});
145+
for (&binding, expected_entry) in expected_bgl.entries.iter() {
146+
if let Some(assigned_entry) = assigned_bgl.entries.get(binding) {
147+
if assigned_entry.visibility != expected_entry.visibility {
148+
errors.push(EntryError::Visibility {
149+
binding,
150+
expected: expected_entry.visibility,
151+
assigned: assigned_entry.visibility,
152+
});
153+
}
154+
if assigned_entry.ty != expected_entry.ty {
155+
errors.push(EntryError::Type {
156+
binding,
157+
expected: expected_entry.ty,
158+
assigned: assigned_entry.ty,
159+
});
160+
}
161+
if assigned_entry.count != expected_entry.count {
162+
errors.push(EntryError::Count {
163+
binding,
164+
expected: expected_entry.count,
165+
assigned: assigned_entry.count,
166+
});
167+
}
168+
} else {
169+
errors.push(EntryError::ExtraExpected { binding });
173170
}
174171
}
175172

176-
for (&binding, _) in expected_bgl_entries {
177-
errors.push(EntryError::ExtraExpected { binding });
173+
for (&binding, _) in assigned_bgl.entries.iter() {
174+
if !expected_bgl.entries.contains_key(binding) {
175+
errors.push(EntryError::ExtraAssigned { binding });
176+
}
178177
}
179178

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

184183
Err(Error::Incompatible {
185184
expected_bgl: expected_bgl.error_ident(),
186185
assigned_bgl: assigned_bgl.error_ident(),
187-
inner: MultiError::new(errors.drain(..)).unwrap(),
186+
inner: MultiError::new(errors.drain(..)).unwrap_or_else(|| {
187+
MultiError::new(core::iter::once(Unknown())).unwrap()
188+
}),
188189
})
189190
}
190191
} else {

wgpu-core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ pub mod resource;
7171
mod snatch;
7272
pub mod storage;
7373
mod track;
74-
mod utils;
7574
// This is public for users who pre-compile shaders while still wanting to
7675
// preserve all run-time checks that `wgpu-core` does.
7776
// See <https://github.com/gfx-rs/wgpu/issues/3103>, after which this can be

wgpu-core/src/utils.rs

-54
This file was deleted.

0 commit comments

Comments
 (0)