[rs] Implement more derives for Operations (#450)

* Implement more derives for `Operations`

* Use `trace` / `replay` features for serialization

* Set `store` to default
This commit is contained in:
Gabriel Majeri
2020-07-20 03:20:45 +03:00
committed by GitHub
parent d1dea85944
commit 08182d14bf
2 changed files with 28 additions and 4 deletions

View File

@@ -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.

View File

@@ -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<V> {
/// Clear with a specified value.
Clear(V),
@@ -805,8 +811,16 @@ pub enum LoadOp<V> {
Load,
}
impl<V: Default> Default for LoadOp<V> {
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<V> {
/// How data should be read through this attachment.
pub load: LoadOp<V>,
@@ -814,6 +828,15 @@ pub struct Operations<V> {
pub store: bool,
}
impl<V: Default> Default for Operations<V> {
fn default() -> Self {
Self {
load: Default::default(),
store: true,
}
}
}
/// Describes a color attachment to a [`RenderPass`].
#[derive(Clone)]
pub struct RenderPassColorAttachmentDescriptor<'a> {