Skip to content

Commit

Permalink
Remove id32 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Dec 21, 2023
1 parent 9eea31a commit 788cd8f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 0 additions & 2 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"]
## Enable serializable compute/render passes, and bundle encoders.
serial-pass = ["serde", "wgt/serde", "arrayvec/serde"]

id32 = []

## Enable `ShaderModuleSource::Wgsl`
wgsl = ["naga/wgsl-in"]

Expand Down
9 changes: 0 additions & 9 deletions wgpu-core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ use std::{
};
use wgt::{Backend, WasmNotSendSync};

#[cfg(feature = "id32")]
type IdType = u32;
#[cfg(not(feature = "id32"))]
type IdType = u64;
#[cfg(feature = "id32")]
type NonZeroId = std::num::NonZeroU32;
#[cfg(not(feature = "id32"))]
type NonZeroId = std::num::NonZeroU64;
#[cfg(feature = "id32")]
type ZippedIndex = u16;
#[cfg(not(feature = "id32"))]
type ZippedIndex = Index;

const INDEX_BITS: usize = std::mem::size_of::<ZippedIndex>() * 8;
Expand Down
8 changes: 2 additions & 6 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3064,9 +3064,7 @@ where
T: 'static + WasmNotSendSync,
{
fn from(id: ObjectId) -> Self {
// If the id32 feature is enabled in wgpu-core, this will make sure that the id fits in a NonZeroU32.
#[allow(clippy::useless_conversion)]
let id = id.id().try_into().expect("Id exceeded 32-bits");
let id = id.id();
// SAFETY: The id was created via the impl below
unsafe { Self::from_raw(id) }
}
Expand All @@ -3077,9 +3075,7 @@ where
T: 'static + WasmNotSendSync,
{
fn from(id: wgc::id::Id<T>) -> Self {
// If the id32 feature is enabled in wgpu-core, the conversion is not useless
#[allow(clippy::useless_conversion)]
let id = id.into_raw().into();
let id = id.into_raw();
Self::from_global_id(id)
}
}
Expand Down
8 changes: 8 additions & 0 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5170,6 +5170,14 @@ impl Surface<'_> {
#[repr(transparent)]
pub struct Id<T>(NonZeroU64, PhantomData<*mut T>);

impl<T> Id<T> {
/// For testing use only. We provide no guarentees about the actual value of the ids.
#[doc(hidden)]
pub fn inner(&self) -> u64 {
self.0.get()
}
}

// SAFETY: `Id` is a bare `NonZeroU64`, the type parameter is a marker purely to avoid confusing Ids
// returned for different types , so `Id` can safely implement Send and Sync.
unsafe impl<T> Send for Id<T> {}
Expand Down

0 comments on commit 788cd8f

Please sign in to comment.