Skip to content

Commit 5ac2ed1

Browse files
andyleisersonteoxoy
authored andcommitted
Fix serde feature gating
1 parent c501ef6 commit 5ac2ed1

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

wgpu-core/src/command/compute_command.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::command::{serde_object_reference_struct, ArcReferences, ReferenceType};
1+
#[cfg(feature = "serde")]
2+
use crate::command::serde_object_reference_struct;
3+
use crate::command::{ArcReferences, ReferenceType};
24

35
#[cfg(feature = "serde")]
46
use macro_rules_attribute::apply;

wgpu-core/src/command/encoder_command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct IdReferences;
3535
/// This is used for trace recording and playback. Recording stores the pointer
3636
/// value of `Arc` references in the trace. Playback uses the integer values
3737
/// as keys to a `HashMap`.
38+
#[cfg(feature = "serde")]
3839
#[doc(hidden)]
3940
#[derive(Clone, Debug)]
4041
pub struct PointerReferences;
@@ -58,6 +59,7 @@ impl ReferenceType for IdReferences {
5859
type Tlas = id::TlasId;
5960
}
6061

62+
#[cfg(feature = "serde")]
6163
impl ReferenceType for PointerReferences {
6264
type Buffer = id::PointerId<id::markers::Buffer>;
6365
type Surface = id::PointerId<id::markers::Surface>;

wgpu-core/src/command/render_command.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use wgt::{BufferAddress, BufferSize, Color};
22

33
use super::{DrawCommandFamily, Rect};
4-
use crate::command::{serde_object_reference_struct, ArcReferences, ReferenceType};
4+
#[cfg(feature = "serde")]
5+
use crate::command::serde_object_reference_struct;
6+
use crate::command::{ArcReferences, ReferenceType};
57

68
#[cfg(feature = "serde")]
79
use macro_rules_attribute::apply;

wgpu-core/src/id.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::{storage::StorageItem, Epoch, Index};
2-
use alloc::sync::Arc;
1+
use crate::{Epoch, Index};
32
use core::{
43
cmp::Ordering,
54
fmt::{self, Debug},
@@ -96,21 +95,25 @@ pub enum SerialId {
9695
Id(Index, Epoch),
9796
}
9897

98+
#[cfg(feature = "serde")]
9999
impl From<RawId> for SerialId {
100100
fn from(id: RawId) -> Self {
101101
let (index, epoch) = id.unzip();
102102
Self::Id(index, epoch)
103103
}
104104
}
105105

106+
#[cfg(feature = "serde")]
106107
pub struct ZeroIdError;
107108

109+
#[cfg(feature = "serde")]
108110
impl fmt::Display for ZeroIdError {
109111
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110112
write!(f, "IDs may not be zero")
111113
}
112114
}
113115

116+
#[cfg(feature = "serde")]
114117
impl TryFrom<SerialId> for RawId {
115118
type Error = ZeroIdError;
116119
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
@@ -127,21 +130,24 @@ impl TryFrom<SerialId> for RawId {
127130
///
128131
/// This is used for tracing.
129132
#[allow(dead_code)]
130-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
131-
#[derive(Debug)]
133+
#[cfg(feature = "serde")]
134+
#[derive(Debug, serde::Serialize, serde::Deserialize)]
132135
pub enum PointerId<T: Marker> {
133136
// The only variant forces RON to not ignore "Id"
134137
PointerId(usize, #[serde(skip)] PhantomData<T>),
135138
}
136139

140+
#[cfg(feature = "serde")]
137141
impl<T: Marker> Copy for PointerId<T> {}
138142

143+
#[cfg(feature = "serde")]
139144
impl<T: Marker> Clone for PointerId<T> {
140145
fn clone(&self) -> Self {
141146
*self
142147
}
143148
}
144149

150+
#[cfg(feature = "serde")]
145151
impl<T: Marker> PartialEq for PointerId<T> {
146152
fn eq(&self, other: &Self) -> bool {
147153
let PointerId::PointerId(this, _) = self;
@@ -150,25 +156,28 @@ impl<T: Marker> PartialEq for PointerId<T> {
150156
}
151157
}
152158

159+
#[cfg(feature = "serde")]
153160
impl<T: Marker> Eq for PointerId<T> {}
154161

162+
#[cfg(feature = "serde")]
155163
impl<T: Marker> Hash for PointerId<T> {
156164
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
157165
let PointerId::PointerId(this, _) = self;
158166
this.hash(state);
159167
}
160168
}
161169

162-
impl<T: StorageItem> From<&Arc<T>> for PointerId<T::Marker> {
163-
fn from(arc: &Arc<T>) -> Self {
170+
#[cfg(feature = "serde")]
171+
impl<T: crate::storage::StorageItem> From<&alloc::sync::Arc<T>> for PointerId<T::Marker> {
172+
fn from(arc: &alloc::sync::Arc<T>) -> Self {
164173
// Since the memory representation of `Arc<T>` is just a pointer to
165174
// `ArcInner<T>`, it would be nice to use that pointer as the trace ID,
166175
// since many `into_trace` implementations would then be no-ops at
167176
// runtime. However, `Arc::as_ptr` returns a pointer to the contained
168177
// data, not to the `ArcInner`. The `ArcInner` stores the reference
169178
// counts before the data, so the machine code for this conversion has
170179
// to add an offset to the pointer.
171-
PointerId::PointerId(Arc::as_ptr(arc) as usize, PhantomData)
180+
PointerId::PointerId(alloc::sync::Arc::as_ptr(arc) as usize, PhantomData)
172181
}
173182
}
174183

0 commit comments

Comments
 (0)