Skip to content

Commit 2c81896

Browse files
Small changes to facilitate fuzzing (#7970)
1 parent 9794870 commit 2c81896

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

wgpu-core/src/command/bundle.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,20 @@ impl RenderBundleEncoder {
435435
.map_pass_err(scope)?;
436436
}
437437
RenderCommand::DrawIndirect { .. }
438-
| RenderCommand::MultiDrawIndirectCount { .. } => unimplemented!(),
439-
RenderCommand::PushDebugGroup { color: _, len: _ } => unimplemented!(),
440-
RenderCommand::InsertDebugMarker { color: _, len: _ } => unimplemented!(),
441-
RenderCommand::PopDebugGroup => unimplemented!(),
438+
| RenderCommand::MultiDrawIndirectCount { .. }
439+
| RenderCommand::PushDebugGroup { color: _, len: _ }
440+
| RenderCommand::InsertDebugMarker { color: _, len: _ }
441+
| RenderCommand::PopDebugGroup => {
442+
unimplemented!("not supported by a render bundle")
443+
}
442444
// Must check the TIMESTAMP_QUERY_INSIDE_PASSES feature
443445
RenderCommand::WriteTimestamp { .. }
444446
| RenderCommand::BeginOcclusionQuery { .. }
445447
| RenderCommand::EndOcclusionQuery
446448
| RenderCommand::BeginPipelineStatisticsQuery { .. }
447-
| RenderCommand::EndPipelineStatisticsQuery => unimplemented!(),
449+
| RenderCommand::EndPipelineStatisticsQuery => {
450+
unimplemented!("not supported by a render bundle")
451+
}
448452
RenderCommand::ExecuteBundle(_)
449453
| RenderCommand::SetBlendConstant(_)
450454
| RenderCommand::SetStencilReference(_)

wgpu-core/src/id.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ const _: () = {
3434
#[cfg_attr(
3535
any(feature = "serde", feature = "replay"),
3636
derive(serde::Deserialize),
37-
serde(from = "SerialId")
37+
serde(try_from = "SerialId")
3838
)]
3939
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4040
pub struct RawId(NonZeroU64);
4141

4242
impl RawId {
4343
/// Zip together an identifier and return its raw underlying representation.
44+
///
45+
/// # Panics
46+
///
47+
/// If both ID components are zero.
4448
pub fn zip(index: Index, epoch: Epoch) -> RawId {
4549
let v = (index as u64) | ((epoch as u64) << 32);
46-
Self(NonZeroU64::new(v).unwrap())
50+
Self(NonZeroU64::new(v).expect("IDs may not be zero"))
4751
}
4852

4953
/// Unzip a raw identifier into its components.
@@ -101,10 +105,22 @@ impl From<RawId> for SerialId {
101105
}
102106
}
103107

104-
impl From<SerialId> for RawId {
105-
fn from(id: SerialId) -> Self {
106-
match id {
107-
SerialId::Id(index, epoch) => RawId::zip(index, epoch),
108+
pub struct ZeroIdError;
109+
110+
impl fmt::Display for ZeroIdError {
111+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112+
write!(f, "IDs may not be zero")
113+
}
114+
}
115+
116+
impl TryFrom<SerialId> for RawId {
117+
type Error = ZeroIdError;
118+
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
119+
let SerialId::Id(index, epoch) = id;
120+
if index == 0 && epoch == 0 {
121+
Err(ZeroIdError)
122+
} else {
123+
Ok(RawId::zip(index, epoch))
108124
}
109125
}
110126
}

wgpu-core/src/storage.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ where
9494

9595
pub(crate) fn remove(&mut self, id: Id<T::Marker>) -> T {
9696
let (index, epoch) = id.unzip();
97-
match mem::replace(&mut self.map[index as usize], Element::Vacant) {
97+
let stored = self
98+
.map
99+
.get_mut(index as usize)
100+
.unwrap_or_else(|| panic!("{}[{:?}] does not exist", self.kind, id));
101+
match mem::replace(stored, Element::Vacant) {
98102
Element::Occupied(value, storage_epoch) => {
99103
assert_eq!(epoch, storage_epoch, "id epoch mismatch");
100104
value

0 commit comments

Comments
 (0)