diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 125fe29322..ecbe817ab0 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -17,8 +17,8 @@ all-features = true [features] default = [] -trace = ["wgc/trace"] -replay = ["wgc/replay"] +trace = ["serde", "wgc/trace"] +replay = ["serde", "wgc/replay"] subscriber = ["wgc/subscriber"] # Make Vulkan backend available on platforms where it is by default not, e.g. macOS vulkan = ["wgc/gfx-backend-vulkan"] @@ -44,6 +44,7 @@ raw-window-handle = "0.3" smallvec = "1" tracing = { version = "0.1", default-features = false, features = ["std"] } typed-arena = "2.0.1" +serde = { version = "1", features = ["derive"], optional = true } #Note: we may consider switching this to "dev-dependencies" if users # want to opt into X11 explicitly. diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 5076b453ba..73c8e87cf4 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -22,6 +22,10 @@ use std::{ use futures::FutureExt as _; use parking_lot::Mutex; +#[cfg(feature = "trace")] +use serde::Serialize; +#[cfg(feature = "replay")] +use serde::Deserialize; #[cfg(not(target_arch = "wasm32"))] pub use wgc::instance::{AdapterInfo, DeviceType}; @@ -797,7 +801,9 @@ pub enum BindingResource<'a> { } /// Operation to perform to the output attachment at the start of a renderpass. -#[derive(Clone, Copy, Debug, Hash, PartialEq)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub enum LoadOp { /// Clear with a specified value. Clear(V), @@ -805,8 +811,16 @@ pub enum LoadOp { Load, } +impl Default for LoadOp { + fn default() -> Self { + Self::Clear(Default::default()) + } +} + /// Pair of load and store operations for an attachment aspect. -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Operations { /// How data should be read through this attachment. pub load: LoadOp, @@ -814,6 +828,15 @@ pub struct Operations { pub store: bool, } +impl Default for Operations { + fn default() -> Self { + Self { + load: Default::default(), + store: true, + } + } +} + /// Describes a color attachment to a [`RenderPass`]. #[derive(Clone)] pub struct RenderPassColorAttachmentDescriptor<'a> {