mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Fix serde feature gating
This commit is contained in:
parent
c501ef68df
commit
5ac2ed19cb
@ -1,4 +1,6 @@
|
|||||||
use crate::command::{serde_object_reference_struct, ArcReferences, ReferenceType};
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::command::serde_object_reference_struct;
|
||||||
|
use crate::command::{ArcReferences, ReferenceType};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use macro_rules_attribute::apply;
|
use macro_rules_attribute::apply;
|
||||||
|
|||||||
@ -35,6 +35,7 @@ pub struct IdReferences;
|
|||||||
/// This is used for trace recording and playback. Recording stores the pointer
|
/// This is used for trace recording and playback. Recording stores the pointer
|
||||||
/// value of `Arc` references in the trace. Playback uses the integer values
|
/// value of `Arc` references in the trace. Playback uses the integer values
|
||||||
/// as keys to a `HashMap`.
|
/// as keys to a `HashMap`.
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct PointerReferences;
|
pub struct PointerReferences;
|
||||||
@ -58,6 +59,7 @@ impl ReferenceType for IdReferences {
|
|||||||
type Tlas = id::TlasId;
|
type Tlas = id::TlasId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl ReferenceType for PointerReferences {
|
impl ReferenceType for PointerReferences {
|
||||||
type Buffer = id::PointerId<id::markers::Buffer>;
|
type Buffer = id::PointerId<id::markers::Buffer>;
|
||||||
type Surface = id::PointerId<id::markers::Surface>;
|
type Surface = id::PointerId<id::markers::Surface>;
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
use wgt::{BufferAddress, BufferSize, Color};
|
use wgt::{BufferAddress, BufferSize, Color};
|
||||||
|
|
||||||
use super::{DrawCommandFamily, Rect};
|
use super::{DrawCommandFamily, Rect};
|
||||||
use crate::command::{serde_object_reference_struct, ArcReferences, ReferenceType};
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::command::serde_object_reference_struct;
|
||||||
|
use crate::command::{ArcReferences, ReferenceType};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use macro_rules_attribute::apply;
|
use macro_rules_attribute::apply;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use crate::{storage::StorageItem, Epoch, Index};
|
use crate::{Epoch, Index};
|
||||||
use alloc::sync::Arc;
|
|
||||||
use core::{
|
use core::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
@ -96,6 +95,7 @@ pub enum SerialId {
|
|||||||
Id(Index, Epoch),
|
Id(Index, Epoch),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl From<RawId> for SerialId {
|
impl From<RawId> for SerialId {
|
||||||
fn from(id: RawId) -> Self {
|
fn from(id: RawId) -> Self {
|
||||||
let (index, epoch) = id.unzip();
|
let (index, epoch) = id.unzip();
|
||||||
@ -103,14 +103,17 @@ impl From<RawId> for SerialId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
pub struct ZeroIdError;
|
pub struct ZeroIdError;
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl fmt::Display for ZeroIdError {
|
impl fmt::Display for ZeroIdError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "IDs may not be zero")
|
write!(f, "IDs may not be zero")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl TryFrom<SerialId> for RawId {
|
impl TryFrom<SerialId> for RawId {
|
||||||
type Error = ZeroIdError;
|
type Error = ZeroIdError;
|
||||||
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
|
fn try_from(id: SerialId) -> Result<Self, ZeroIdError> {
|
||||||
@ -127,21 +130,24 @@ impl TryFrom<SerialId> for RawId {
|
|||||||
///
|
///
|
||||||
/// This is used for tracing.
|
/// This is used for tracing.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg(feature = "serde")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum PointerId<T: Marker> {
|
pub enum PointerId<T: Marker> {
|
||||||
// The only variant forces RON to not ignore "Id"
|
// The only variant forces RON to not ignore "Id"
|
||||||
PointerId(usize, #[serde(skip)] PhantomData<T>),
|
PointerId(usize, #[serde(skip)] PhantomData<T>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl<T: Marker> Copy for PointerId<T> {}
|
impl<T: Marker> Copy for PointerId<T> {}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl<T: Marker> Clone for PointerId<T> {
|
impl<T: Marker> Clone for PointerId<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl<T: Marker> PartialEq for PointerId<T> {
|
impl<T: Marker> PartialEq for PointerId<T> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
let PointerId::PointerId(this, _) = self;
|
let PointerId::PointerId(this, _) = self;
|
||||||
@ -150,8 +156,10 @@ impl<T: Marker> PartialEq for PointerId<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl<T: Marker> Eq for PointerId<T> {}
|
impl<T: Marker> Eq for PointerId<T> {}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
impl<T: Marker> Hash for PointerId<T> {
|
impl<T: Marker> Hash for PointerId<T> {
|
||||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||||
let PointerId::PointerId(this, _) = self;
|
let PointerId::PointerId(this, _) = self;
|
||||||
@ -159,8 +167,9 @@ impl<T: Marker> Hash for PointerId<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: StorageItem> From<&Arc<T>> for PointerId<T::Marker> {
|
#[cfg(feature = "serde")]
|
||||||
fn from(arc: &Arc<T>) -> Self {
|
impl<T: crate::storage::StorageItem> From<&alloc::sync::Arc<T>> for PointerId<T::Marker> {
|
||||||
|
fn from(arc: &alloc::sync::Arc<T>) -> Self {
|
||||||
// Since the memory representation of `Arc<T>` is just a pointer to
|
// Since the memory representation of `Arc<T>` is just a pointer to
|
||||||
// `ArcInner<T>`, it would be nice to use that pointer as the trace ID,
|
// `ArcInner<T>`, it would be nice to use that pointer as the trace ID,
|
||||||
// since many `into_trace` implementations would then be no-ops at
|
// since many `into_trace` implementations would then be no-ops at
|
||||||
@ -168,7 +177,7 @@ impl<T: StorageItem> From<&Arc<T>> for PointerId<T::Marker> {
|
|||||||
// data, not to the `ArcInner`. The `ArcInner` stores the reference
|
// data, not to the `ArcInner`. The `ArcInner` stores the reference
|
||||||
// counts before the data, so the machine code for this conversion has
|
// counts before the data, so the machine code for this conversion has
|
||||||
// to add an offset to the pointer.
|
// to add an offset to the pointer.
|
||||||
PointerId::PointerId(Arc::as_ptr(arc) as usize, PhantomData)
|
PointerId::PointerId(alloc::sync::Arc::as_ptr(arc) as usize, PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user