Skip to content

Commit 0e937c8

Browse files
authored
make Ids a u64 internally (#3178)
1 parent 3c82a4c commit 0e937c8

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

wgpu-core/src/id.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub(crate) struct Valid<I>(pub I);
167167
pub trait TypedId: Copy {
168168
fn zip(index: Index, epoch: Epoch, backend: Backend) -> Self;
169169
fn unzip(self) -> (Index, Epoch, Backend);
170+
fn into_raw(self) -> NonZeroId;
170171
}
171172

172173
#[allow(trivial_numeric_casts)]
@@ -187,6 +188,10 @@ impl<T> TypedId for Id<T> {
187188
self.backend(),
188189
)
189190
}
191+
192+
fn into_raw(self) -> NonZeroId {
193+
self.0
194+
}
190195
}
191196

192197
pub type AdapterId = Id<crate::instance::Adapter<Dummy>>;

wgpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ name = "water"
7676
test = true
7777

7878
[features]
79-
default = ["wgsl"]
79+
default = ["wgsl", "expose-ids"]
8080
spirv = ["naga/spv-in"]
8181
glsl = ["naga/glsl-in"]
8282
wgsl = ["wgc?/wgsl"]

wgpu/src/backend/direct.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -832,46 +832,50 @@ pub(crate) struct CommandEncoder {
832832
open: bool,
833833
}
834834

835-
pub(crate) type Id = (u32, u32, wgt::Backend);
836-
837835
impl<T: wgc::id::TypedId> crate::GlobalId for T {
838-
fn global_id(&self) -> Id {
839-
self.unzip()
836+
#[allow(clippy::useless_conversion)] // because not(id32)
837+
fn global_id(&self) -> u64 {
838+
T::into_raw(*self).get().into()
840839
}
841840
}
842841

843842
impl crate::GlobalId for Surface {
844-
fn global_id(&self) -> Id {
843+
#[allow(clippy::useless_conversion)] // because not(id32)
844+
fn global_id(&self) -> u64 {
845845
use wgc::id::TypedId;
846-
self.id.unzip()
846+
self.id.into_raw().get().into()
847847
}
848848
}
849849

850850
impl crate::GlobalId for Device {
851-
fn global_id(&self) -> Id {
851+
#[allow(clippy::useless_conversion)] // because not(id32)
852+
fn global_id(&self) -> u64 {
852853
use wgc::id::TypedId;
853-
self.id.unzip()
854+
self.id.into_raw().get().into()
854855
}
855856
}
856857

857858
impl crate::GlobalId for Buffer {
858-
fn global_id(&self) -> Id {
859+
#[allow(clippy::useless_conversion)] // because not(id32)
860+
fn global_id(&self) -> u64 {
859861
use wgc::id::TypedId;
860-
self.id.unzip()
862+
self.id.into_raw().get().into()
861863
}
862864
}
863865

864866
impl crate::GlobalId for Texture {
865-
fn global_id(&self) -> Id {
867+
#[allow(clippy::useless_conversion)] // because not(id32)
868+
fn global_id(&self) -> u64 {
866869
use wgc::id::TypedId;
867-
self.id.unzip()
870+
self.id.into_raw().get().into()
868871
}
869872
}
870873

871874
impl crate::GlobalId for CommandEncoder {
872-
fn global_id(&self) -> Id {
875+
#[allow(clippy::useless_conversion)] // because not(id32)
876+
fn global_id(&self) -> u64 {
873877
use wgc::id::TypedId;
874-
self.id.unzip()
878+
self.id.into_raw().get().into()
875879
}
876880
}
877881

wgpu/src/backend/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))]
22
mod web;
33
#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))]
4-
pub(crate) use web::{BufferMappedRange, Context, Id, QueueWriteBuffer};
4+
pub(crate) use web::{BufferMappedRange, Context, QueueWriteBuffer};
55

66
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
77
mod direct;
88
#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))]
9-
pub(crate) use direct::{BufferMappedRange, Context, Id, QueueWriteBuffer};
9+
pub(crate) use direct::{BufferMappedRange, Context, QueueWriteBuffer};

wgpu/src/backend/web.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ unsafe impl<T> Sync for Identified<T> {}
3232

3333
impl<T> crate::GlobalId for Identified<T> {
3434
#[cfg(not(feature = "expose-ids"))]
35-
fn global_id(&self) -> Id {
35+
fn global_id(&self) -> u64 {
3636
0
3737
}
3838

3939
#[cfg(feature = "expose-ids")]
40-
fn global_id(&self) -> Id {
40+
fn global_id(&self) -> u64 {
4141
self.1
4242
}
4343
}
4444

45-
pub(crate) type Id = u64;
46-
4745
#[cfg(feature = "expose-ids")]
4846
static NEXT_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
4947

wgpu/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use wgt::{
4343
QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
4444
};
4545

46-
use backend::{BufferMappedRange, Context as C, Id as BackendId, QueueWriteBuffer};
46+
use backend::{BufferMappedRange, Context as C, QueueWriteBuffer};
4747

4848
/// Filter for error scopes.
4949
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd)]
@@ -165,7 +165,7 @@ trait RenderPassInner<Ctx: Context>: RenderInner<Ctx> {
165165
}
166166

167167
trait GlobalId {
168-
fn global_id(&self) -> BackendId;
168+
fn global_id(&self) -> u64;
169169
}
170170

171171
trait Context: Debug + Send + Sized + Sync {
@@ -3805,7 +3805,7 @@ impl Surface {
38053805
#[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))]
38063806
#[repr(transparent)]
38073807
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
3808-
pub struct Id(BackendId);
3808+
pub struct Id(u64);
38093809

38103810
#[cfg(feature = "expose-ids")]
38113811
impl Adapter {

0 commit comments

Comments
 (0)