Skip to content

Commit

Permalink
WIP: Context dynamic dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Oct 24, 2022
1 parent 49415fe commit d8bc266
Show file tree
Hide file tree
Showing 8 changed files with 8,274 additions and 3,248 deletions.
12 changes: 12 additions & 0 deletions wgpu-core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl<T> From<SerialId> for Id<T> {
}

impl<T> Id<T> {
/// # Safety
///
/// The raw id must be valid for the type.
pub unsafe fn from_raw(raw: NonZeroId) -> Self {
Self(raw, PhantomData)
}

#[allow(dead_code)]
pub(crate) fn dummy(index: u32) -> Valid<Self> {
Valid(Id::zip(index, 1, Backend::Empty))
Expand Down Expand Up @@ -165,12 +172,17 @@ pub(crate) struct Valid<I>(pub I);
/// need to construct `Id` values directly, or access their components, like the
/// WGPU recording player, may use this trait to do so.
pub trait TypedId: Copy {
fn as_raw(&self) -> NonZeroId;
fn zip(index: Index, epoch: Epoch, backend: Backend) -> Self;
fn unzip(self) -> (Index, Epoch, Backend);
}

#[allow(trivial_numeric_casts)]
impl<T> TypedId for Id<T> {
fn as_raw(&self) -> NonZeroId {
self.0
}

fn zip(index: Index, epoch: Epoch, backend: Backend) -> Self {
assert_eq!(0, epoch >> EPOCH_BITS);
assert_eq!(0, (index as IdType) >> INDEX_BITS);
Expand Down
Loading

0 comments on commit d8bc266

Please sign in to comment.