Skip to content

Commit 08182d1

Browse files
[rs] Implement more derives for Operations (gfx-rs#450)
* Implement more derives for `Operations` * Use `trace` / `replay` features for serialization * Set `store` to default
1 parent d1dea85 commit 08182d1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

wgpu/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ all-features = true
1717

1818
[features]
1919
default = []
20-
trace = ["wgc/trace"]
21-
replay = ["wgc/replay"]
20+
trace = ["serde", "wgc/trace"]
21+
replay = ["serde", "wgc/replay"]
2222
subscriber = ["wgc/subscriber"]
2323
# Make Vulkan backend available on platforms where it is by default not, e.g. macOS
2424
vulkan = ["wgc/gfx-backend-vulkan"]
@@ -44,6 +44,7 @@ raw-window-handle = "0.3"
4444
smallvec = "1"
4545
tracing = { version = "0.1", default-features = false, features = ["std"] }
4646
typed-arena = "2.0.1"
47+
serde = { version = "1", features = ["derive"], optional = true }
4748

4849
#Note: we may consider switching this to "dev-dependencies" if users
4950
# want to opt into X11 explicitly.

wgpu/src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ use std::{
2222

2323
use futures::FutureExt as _;
2424
use parking_lot::Mutex;
25+
#[cfg(feature = "trace")]
26+
use serde::Serialize;
27+
#[cfg(feature = "replay")]
28+
use serde::Deserialize;
2529

2630
#[cfg(not(target_arch = "wasm32"))]
2731
pub use wgc::instance::{AdapterInfo, DeviceType};
@@ -797,23 +801,42 @@ pub enum BindingResource<'a> {
797801
}
798802

799803
/// Operation to perform to the output attachment at the start of a renderpass.
800-
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
804+
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
805+
#[cfg_attr(feature = "trace", derive(Serialize))]
806+
#[cfg_attr(feature = "replay", derive(Deserialize))]
801807
pub enum LoadOp<V> {
802808
/// Clear with a specified value.
803809
Clear(V),
804810
/// Load from memory.
805811
Load,
806812
}
807813

814+
impl<V: Default> Default for LoadOp<V> {
815+
fn default() -> Self {
816+
Self::Clear(Default::default())
817+
}
818+
}
819+
808820
/// Pair of load and store operations for an attachment aspect.
809-
#[derive(Clone, Debug, Hash, PartialEq)]
821+
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
822+
#[cfg_attr(feature = "trace", derive(Serialize))]
823+
#[cfg_attr(feature = "replay", derive(Deserialize))]
810824
pub struct Operations<V> {
811825
/// How data should be read through this attachment.
812826
pub load: LoadOp<V>,
813827
/// Whether data will be written to through this attachment.
814828
pub store: bool,
815829
}
816830

831+
impl<V: Default> Default for Operations<V> {
832+
fn default() -> Self {
833+
Self {
834+
load: Default::default(),
835+
store: true,
836+
}
837+
}
838+
}
839+
817840
/// Describes a color attachment to a [`RenderPass`].
818841
#[derive(Clone)]
819842
pub struct RenderPassColorAttachmentDescriptor<'a> {

0 commit comments

Comments
 (0)