Skip to content

Small changes to facilitate fuzzing #7970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,20 @@ impl RenderBundleEncoder {
.map_pass_err(scope)?;
}
RenderCommand::DrawIndirect { .. }
| RenderCommand::MultiDrawIndirectCount { .. } => unimplemented!(),
RenderCommand::PushDebugGroup { color: _, len: _ } => unimplemented!(),
RenderCommand::InsertDebugMarker { color: _, len: _ } => unimplemented!(),
RenderCommand::PopDebugGroup => unimplemented!(),
| RenderCommand::MultiDrawIndirectCount { .. }
| RenderCommand::PushDebugGroup { color: _, len: _ }
| RenderCommand::InsertDebugMarker { color: _, len: _ }
| RenderCommand::PopDebugGroup => {
unimplemented!("not supported by a render bundle")
}
// Must check the TIMESTAMP_QUERY_INSIDE_PASSES feature
RenderCommand::WriteTimestamp { .. }
| RenderCommand::BeginOcclusionQuery { .. }
| RenderCommand::EndOcclusionQuery
| RenderCommand::BeginPipelineStatisticsQuery { .. }
| RenderCommand::EndPipelineStatisticsQuery => unimplemented!(),
| RenderCommand::EndPipelineStatisticsQuery => {
unimplemented!("not supported by a render bundle")
}
RenderCommand::ExecuteBundle(_)
| RenderCommand::SetBlendConstant(_)
| RenderCommand::SetStencilReference(_)
Expand Down
28 changes: 22 additions & 6 deletions wgpu-core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ const _: () = {
#[cfg_attr(
any(feature = "serde", feature = "replay"),
derive(serde::Deserialize),
serde(from = "SerialId")
serde(try_from = "SerialId")
)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RawId(NonZeroU64);

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

/// Unzip a raw identifier into its components.
Expand Down Expand Up @@ -101,10 +105,22 @@ impl From<RawId> for SerialId {
}
}

impl From<SerialId> for RawId {
fn from(id: SerialId) -> Self {
match id {
SerialId::Id(index, epoch) => RawId::zip(index, epoch),
pub struct ZeroIdError;

impl fmt::Display for ZeroIdError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "IDs may not be zero")
}
}

impl TryFrom<SerialId> for RawId {
type Error = ZeroIdError;
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
let SerialId::Id(index, epoch) = id;
if index == 0 && epoch == 0 {
Err(ZeroIdError)
} else {
Ok(RawId::zip(index, epoch))
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion wgpu-core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ where

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