From 54b057a5f5ff25937a7c173c650b5bbb59bb1e1d Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 14:08:21 +0100 Subject: [PATCH 01/18] Add serde, serialize, deserialize features to wgpu and wgpu-core Remove trace, replay features from wgpu-types --- deno_webgpu/Cargo.toml | 2 +- player/Cargo.toml | 2 +- tests/Cargo.toml | 2 +- wgpu-core/Cargo.toml | 13 +++++++++++-- wgpu-info/Cargo.toml | 2 +- wgpu-types/Cargo.toml | 5 +++-- wgpu/Cargo.toml | 13 +++++++++++-- 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index d1097c658d..9f6d96a95b 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -22,7 +22,7 @@ surface = ["wgpu-core/raw-window-handle", "dep:raw-window-handle"] deno_core.workspace = true serde = { workspace = true, features = ["derive"] } tokio = { workspace = true, features = ["full"] } -wgpu-types = { workspace = true, features = ["trace", "replay", "serde"] } +wgpu-types = { workspace = true, features = ["serde"] } raw-window-handle = { workspace = true, optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgpu-core] diff --git a/player/Cargo.toml b/player/Cargo.toml index 63493a4ee2..f50fd2e5d0 100644 --- a/player/Cargo.toml +++ b/player/Cargo.toml @@ -29,7 +29,7 @@ winit = { workspace = true, optional = true } [dependencies.wgt] workspace = true -features = ["replay"] +features = ["deserialize"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] workspace = true diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 7c0288388d..e3c0f21ec4 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -38,7 +38,7 @@ serde_json.workspace = true serde.workspace = true wgpu-macros.workspace = true wgpu.workspace = true -wgt = { workspace = true, features = ["replay"] } +wgt = { workspace = true, features = ["deserialize"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger.workspace = true diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 95507bd7e2..70336fac12 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -47,11 +47,20 @@ renderdoc = ["hal/renderdoc"] ## to the validation carried out at public APIs in all builds. strict_asserts = ["wgt/strict_asserts"] +## serde +serde = ["serialize", "deserialize", "wgt/serde"] + +## serialize +serialize = ["dep:serde", "wgt/serialize"] + +## deserialize +deserialize = ["dep:serde", "wgt/deserialize"] + ## Enable API tracing. -trace = ["ron", "serde", "wgt/trace", "arrayvec/serde", "naga/serialize"] +trace = ["ron", "serialize", "arrayvec/serde", "naga/serialize"] ## Enable API replaying -replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"] +replay = ["deserialize", "arrayvec/serde", "naga/deserialize"] ## Enable serializable compute/render passes, and bundle encoders. serial-pass = ["serde", "wgt/serde", "arrayvec/serde"] diff --git a/wgpu-info/Cargo.toml b/wgpu-info/Cargo.toml index a729bbc885..59fc074fa8 100644 --- a/wgpu-info/Cargo.toml +++ b/wgpu-info/Cargo.toml @@ -17,4 +17,4 @@ pico-args.workspace = true serde.workspace = true serde_json.workspace = true wgpu.workspace = true -wgpu-types = { workspace = true, features = ["trace", "replay"] } +wgpu-types = { workspace = true, features = ["serde"] } diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 7528b18c0a..b2fbcd0f11 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -28,8 +28,9 @@ targets = [ [lib] [features] -trace = ["serde"] -replay = ["serde"] +serde = ["serialize", "deserialize"] +serialize = ["dep:serde"] +deserialize = ["dep:serde"] strict_asserts = [] fragile-send-sync-non-atomic-wasm = [] diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index cc97e4d249..04347e3bff 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -78,13 +78,22 @@ strict_asserts = ["wgc?/strict_asserts", "wgt/strict_asserts"] ## Log all API entry points at info instead of trace level. api_log_info = ["wgc/api_log_info"] +## serde +serde = ["serialize", "deserialize", "wgc/serde"] + +## serialize +serialize = ["dep:serde", "wgc/serialize"] + +## deserialize +deserialize = ["dep:serde", "wgc/deserialize"] + ## Allow writing of trace capture files. ## See [`Adapter::request_device`]. -trace = ["serde", "wgc/trace"] +trace = ["serialize", "wgc/trace"] ## Allow deserializing of trace capture files that were written with the `trace` feature. ## To replay a trace file use the [wgpu player](https://github.com/gfx-rs/wgpu/tree/trunk/player). -replay = ["serde", "wgc/replay"] +replay = ["deserialize", "wgc/replay"] #! ### Other # -------------------------------------------------------------------- From 4b4213dcf81bee4c0f924c7e783789388f618e09 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 14:16:28 +0100 Subject: [PATCH 02/18] Do not use trace, replay in wgpu-types anymore --- wgpu-types/src/lib.rs | 398 ++++++++++++++++++++++-------------------- 1 file changed, 206 insertions(+), 192 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index fa2a8df5f8..d91b8eea07 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -9,8 +9,10 @@ )] #![warn(missing_docs, unsafe_op_in_unsafe_fn)] -#[cfg(any(feature = "serde", test))] -use serde::{Deserialize, Serialize}; +#[cfg(any(feature = "serialize", test))] +use serde::Serialize; +#[cfg(any(feature = "deserialize", test))] +use serde::Deserialize; use std::hash::{Hash, Hasher}; use std::path::PathBuf; use std::{num::NonZeroU32, ops::Range}; @@ -26,7 +28,7 @@ pub mod math; // behavior to this macro (unspecified bit do not produce an error). macro_rules! impl_bitflags { ($name:ident) => { - #[cfg(feature = "serde")] + #[cfg(feature = "serialize")] impl serde::Serialize for $name { fn serialize(&self, serializer: S) -> Result where @@ -36,7 +38,7 @@ macro_rules! impl_bitflags { } } - #[cfg(feature = "serde")] + #[cfg(feature = "deserialize")] impl<'de> serde::Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result<$name, D::Error> where @@ -92,7 +94,8 @@ pub const QUERY_SIZE: u32 = 8; /// Backends supported by wgpu. #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum Backend { /// Dummy backend, used for testing. Empty = 0, @@ -128,9 +131,9 @@ impl Backend { /// https://gpuweb.github.io/gpuweb/#enumdef-gpupowerpreference). #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum PowerPreference { #[default] /// Power usage is not considered when choosing an adapter. @@ -197,8 +200,8 @@ impl From for Backends { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurequestadapteroptions). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct RequestAdapterOptions { /// Power preference for the adapter. pub power_preference: PowerPreference, @@ -989,21 +992,22 @@ impl InstanceFlags { /// [`downlevel_defaults()`]: Limits::downlevel_defaults #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase", default))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase", default))] pub struct Limits { /// Maximum allowed value for the `size.width` of a texture created with `TextureDimension::D1`. /// Defaults to 8192. Higher is "better". - #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension1D"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension1D"))] pub max_texture_dimension_1d: u32, /// Maximum allowed value for the `size.width` and `size.height` of a texture created with `TextureDimension::D2`. /// Defaults to 8192. Higher is "better". - #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension2D"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension2D"))] pub max_texture_dimension_2d: u32, /// Maximum allowed value for the `size.width`, `size.height`, and `size.depth_or_array_layers` /// of a texture created with `TextureDimension::D3`. /// Defaults to 2048. Higher is "better". - #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension3D"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension3D"))] pub max_texture_dimension_3d: u32, /// Maximum allowed value for the `size.depth_or_array_layers` of a texture created with `TextureDimension::D2`. /// Defaults to 256. Higher is "better". @@ -1368,7 +1372,8 @@ impl Limits { /// Represents the sets of additional limits on an adapter, /// which take place when running on downlevel backends. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct DownlevelLimits {} #[allow(unknown_lints)] // derivable_impls is nightly only currently @@ -1381,7 +1386,8 @@ impl Default for DownlevelLimits { /// Lists various ways the underlying platform does not conform to the WebGPU standard. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct DownlevelCapabilities { /// Combined boolean flags. pub flags: DownlevelFlags, @@ -1590,7 +1596,8 @@ impl DownlevelFlags { /// Collections of shader features a device supports if they support less than WebGPU normally allows. // TODO: Fill out the differences between shader models more completely #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum ShaderModel { /// Extremely limited shaders, including a total instruction limit. Sm2, @@ -1603,7 +1610,8 @@ pub enum ShaderModel { /// Supported physical device types. #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum DeviceType { /// Other or Unknown. Other, @@ -1621,7 +1629,8 @@ pub enum DeviceType { /// Information about an adapter. #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct AdapterInfo { /// Adapter name pub name: String, @@ -1664,8 +1673,8 @@ pub struct AdapterInfo { /// https://gpuweb.github.io/gpuweb/#gpudevicedescriptor). #[repr(C)] #[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct DeviceDescriptor { /// Debug label for the device. pub label: L, @@ -1727,27 +1736,27 @@ impl_bitflags!(ShaderStages); /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureviewdimension). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum TextureViewDimension { /// A one dimensional texture. `texture_1d` in WGSL and `texture1D` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "1d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "1d"))] D1, /// A two dimensional texture. `texture_2d` in WGSL and `texture2D` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "2d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d"))] #[default] D2, /// A two dimensional array texture. `texture_2d_array` in WGSL and `texture2DArray` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "2d-array"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d-array"))] D2Array, /// A cubemap texture. `texture_cube` in WGSL and `textureCube` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "cube"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "cube"))] Cube, /// A cubemap array texture. `texture_cube_array` in WGSL and `textureCubeArray` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "cube-array"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "cube-array"))] CubeArray, /// A three dimensional texture. `texture_3d` in WGSL and `texture3D` in GLSL. - #[cfg_attr(feature = "serde", serde(rename = "3d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "3d"))] D3, } @@ -1772,9 +1781,9 @@ impl TextureViewDimension { /// used with the first render target. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum BlendFactor { /// 0.0 Zero = 0, @@ -1835,9 +1844,9 @@ impl BlendFactor { /// https://gpuweb.github.io/gpuweb/#enumdef-gpublendoperation). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum BlendOperation { /// Src + Dst #[default] @@ -1858,9 +1867,9 @@ pub enum BlendOperation { /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendcomponent). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct BlendComponent { /// Multiplier for the source, which is produced by the fragment shader. pub src_factor: BlendFactor, @@ -1914,9 +1923,9 @@ impl Default for BlendComponent { /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendstate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct BlendState { /// Color equation. pub color: BlendComponent, @@ -1954,9 +1963,9 @@ impl BlendState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpucolortargetstate). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct ColorTargetState { /// The [`TextureFormat`] of the image that this pipeline will render to. Must match the format /// of the corresponding color attachment in [`CommandEncoder::begin_render_pass`][CEbrp] @@ -1964,10 +1973,10 @@ pub struct ColorTargetState { /// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass pub format: TextureFormat, /// The blending that is used for this pipeline. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub blend: Option, /// Mask which enables/disables writes to different color/alpha channel. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub write_mask: ColorWrites, } @@ -1987,9 +1996,9 @@ impl From for ColorTargetState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuprimitivetopology). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum PrimitiveTopology { /// Vertex data is a list of points. Each vertex is a new point. PointList = 0, @@ -2028,9 +2037,9 @@ impl PrimitiveTopology { /// https://gpuweb.github.io/gpuweb/#enumdef-gpufrontface). #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum FrontFace { /// Triangles with vertices in counter clockwise order are considered the front face. /// @@ -2050,9 +2059,9 @@ pub enum FrontFace { /// except that the `"none"` value is represented using `Option` instead. #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum Face { /// Front face Front = 0, @@ -2063,9 +2072,9 @@ pub enum Face { /// Type of drawing mode for polygons #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum PolygonMode { /// Polygons are filled #[default] @@ -2082,33 +2091,33 @@ pub enum PolygonMode { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuprimitivestate). #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct PrimitiveState { /// The primitive topology used to interpret vertices. pub topology: PrimitiveTopology, /// When drawing strip topologies with indices, this is the required format for the index buffer. /// This has no effect on non-indexed or non-strip draws. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub front_face: FrontFace, /// The face culling mode. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub cull_mode: Option, /// If set to true, the polygon depth is not clipped to 0-1 before rasterization. /// /// Enabling this requires `Features::DEPTH_CLIP_CONTROL` to be enabled. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub unclipped_depth: bool, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` /// /// Setting this to `Line` requires `Features::POLYGON_MODE_LINE` to be enabled. /// /// Setting this to `Point` requires `Features::POLYGON_MODE_POINT` to be enabled. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub polygon_mode: PolygonMode, /// If set to true, the primitives are rendered with conservative overestimation. I.e. any rastered pixel touched by it is filled. /// Only valid for PolygonMode::Fill! @@ -2123,9 +2132,9 @@ pub struct PrimitiveState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpumultisamplestate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct MultisampleState { /// The number of samples calculated per pixel (for MSAA). For non-multisampled textures, /// this should be `1` @@ -2212,7 +2221,8 @@ impl_bitflags!(TextureFormatFeatureFlags); /// /// Features are defined by WebGPU specification unless `Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES` is enabled. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct TextureFormatFeatures { /// Valid bits for `TextureDescriptor::Usage` provided for format creation. pub allowed_usages: TextureUsages, @@ -2223,7 +2233,8 @@ pub struct TextureFormatFeatures { /// ASTC block dimensions #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum AstcBlock { /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). B4x4, @@ -2258,7 +2269,8 @@ pub enum AstcBlock { /// ASTC RGBA channel #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum AstcChannel { /// 8 bit integer RGBA, [0, 255] converted to/from linear-color float [0, 1] in shader. /// @@ -2587,7 +2599,7 @@ pub enum TextureFormat { }, } -#[cfg(any(feature = "serde", test))] +#[cfg(any(feature = "deserialize", test))] impl<'de> Deserialize<'de> for TextureFormat { fn deserialize(deserializer: D) -> Result where @@ -2726,7 +2738,7 @@ impl<'de> Deserialize<'de> for TextureFormat { } } -#[cfg(any(feature = "serde", test))] +#[cfg(any(feature = "serialize", test))] impl Serialize for TextureFormat { fn serialize(&self, serializer: S) -> Result where @@ -4366,8 +4378,8 @@ impl MaintainResult { /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct StencilState { /// Front face mode. pub front: StencilFaceState, @@ -4414,8 +4426,8 @@ impl StencilState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct DepthBiasState { /// Constant depth biasing factor, in basic units of the depth format. pub constant: i32, @@ -4456,8 +4468,8 @@ impl Eq for DepthBiasState {} /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Debug, Hash, PartialEq, Eq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct DepthStencilState { /// Format of the depth/stencil buffer, must be special depth format. Must match the format /// of the depth/stencil attachment in [`CommandEncoder::begin_render_pass`][CEbrp]. @@ -4469,10 +4481,10 @@ pub struct DepthStencilState { /// Comparison function used to compare depth values in the depth test. pub depth_compare: CompareFunction, /// Stencil state. - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub stencil: StencilState, /// Depth bias state. - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub bias: DepthBiasState, } @@ -4504,8 +4516,9 @@ impl DepthStencilState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuindexformat). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum IndexFormat { /// Indices are 16 bit unsigned integers. Uint16 = 0, @@ -4520,9 +4533,9 @@ pub enum IndexFormat { /// https://gpuweb.github.io/gpuweb/#enumdef-gpustenciloperation). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum StencilOperation { /// Keep stencil value unchanged. #[default] @@ -4554,9 +4567,9 @@ pub enum StencilOperation { /// https://gpuweb.github.io/gpuweb/#dictdef-gpustencilfacestate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct StencilFaceState { /// Comparison function that determines if the fail_op or pass_op is used on the stencil buffer. pub compare: CompareFunction, @@ -4605,9 +4618,9 @@ impl Default for StencilFaceState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpucomparefunction). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum CompareFunction { /// Function never passes Never = 1, @@ -4700,9 +4713,9 @@ impl CompareFunction { /// [`Instance`]: VertexStepMode::Instance #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum VertexStepMode { /// Vertex data is advanced every vertex. #[default] @@ -4722,9 +4735,9 @@ pub enum VertexStepMode { /// [`vertex_attr_array`]: ../wgpu/macro.vertex_attr_array.html #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct VertexAttribute { /// Format of the input pub format: VertexFormat, @@ -4740,9 +4753,9 @@ pub struct VertexAttribute { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuvertexformat). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "lowercase"))] pub enum VertexFormat { /// Two unsigned bytes (u8). `vec2` in shaders. Uint8x2 = 0, @@ -4900,8 +4913,8 @@ impl_bitflags!(BufferUsages); /// https://gpuweb.github.io/gpuweb/#dictdef-gpubufferdescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct BufferDescriptor { /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. pub label: L, @@ -4935,8 +4948,8 @@ impl BufferDescriptor { /// Corresponds to [WebGPU `GPUCommandEncoderDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpucommandencoderdescriptor). #[repr(C)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct CommandEncoderDescriptor { /// Debug label for the command encoder. This will show up in graphics debuggers for easy identification. @@ -4961,8 +4974,8 @@ impl Default for CommandEncoderDescriptor> { /// Behavior of the presentation engine based on frame rate. #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum PresentMode { /// Chooses FifoRelaxed -> Fifo based on availability. /// @@ -5034,9 +5047,9 @@ pub enum PresentMode { /// compositing. #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "lowercase"))] pub enum CompositeAlphaMode { /// Chooses either `Opaque` or `Inherit` automatically,depending on the /// `alpha_mode` that the current surface can support. @@ -5134,8 +5147,8 @@ impl Default for SurfaceCapabilities { /// [`Surface`]: ../wgpu/struct.Surface.html #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct SurfaceConfiguration { /// The usage of the swap chain. The only supported usage is `RENDER_ATTACHMENT`. pub usage: TextureUsages, @@ -5261,8 +5274,9 @@ impl PresentationTimestamp { /// This is not to be used as a generic color type, only for specific wgpu interfaces. #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct Color { /// Red component of the color pub r: f64, @@ -5320,17 +5334,17 @@ impl Color { /// https://gpuweb.github.io/gpuweb/#enumdef-gputexturedimension). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum TextureDimension { /// 1D texture - #[cfg_attr(feature = "serde", serde(rename = "1d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "1d"))] D1, /// 2D texture - #[cfg_attr(feature = "serde", serde(rename = "2d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d"))] D2, /// 3D texture - #[cfg_attr(feature = "serde", serde(rename = "3d"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "3d"))] D3, } @@ -5340,9 +5354,9 @@ pub enum TextureDimension { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuorigin2ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct Origin2d { /// pub x: u32, @@ -5376,9 +5390,9 @@ impl std::fmt::Debug for Origin2d { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuorigin3ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct Origin3d { /// X position of the origin pub x: u32, @@ -5419,16 +5433,16 @@ impl std::fmt::Debug for Origin3d { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuextent3ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct Extent3d { /// Width of the extent pub width: u32, /// Height of the extent pub height: u32, /// The depth of the extent or the number of array layers - #[cfg_attr(feature = "serde", serde(default = "default_depth"))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default = "default_depth"))] pub depth_or_array_layers: u32, } @@ -5438,7 +5452,7 @@ impl std::fmt::Debug for Extent3d { } } -#[cfg(feature = "serde")] +#[cfg(feature = "deserialize")] fn default_depth() -> u32 { 1 } @@ -5619,8 +5633,8 @@ fn test_max_mips() { /// https://gpuweb.github.io/gpuweb/#dictdef-gputexturedescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct TextureDescriptor { /// Debug label of the texture. This will show up in graphics debuggers for easy identification. pub label: L, @@ -5751,9 +5765,9 @@ impl TextureDescriptor { /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureaspect). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum TextureAspect { /// Depth, Stencil, and Color. #[default] @@ -5776,9 +5790,9 @@ pub enum TextureAspect { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuaddressmode). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum AddressMode { /// Clamp the value to the edge of the texture /// @@ -5810,9 +5824,9 @@ pub enum AddressMode { /// https://gpuweb.github.io/gpuweb/#enumdef-gpufiltermode). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum FilterMode { /// Nearest neighbor sampling. /// @@ -5827,8 +5841,8 @@ pub enum FilterMode { /// A range of push constant memory to pass to a shader stage. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct PushConstantRange { /// Stage push constant range is visible from. Each stage can only be served by at most one range. /// One range can serve multiple stages however. @@ -5844,8 +5858,8 @@ pub struct PushConstantRange { /// https://gpuweb.github.io/gpuweb/#dictdef-gpucommandbufferdescriptor). #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct CommandBufferDescriptor { /// Debug label of this command buffer. pub label: L, @@ -5866,8 +5880,8 @@ impl CommandBufferDescriptor { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderbundleencoderdescriptor). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct RenderBundleDepthStencil { /// Format of the attachment. pub format: TextureFormat, @@ -5894,8 +5908,8 @@ pub struct RenderBundleDepthStencil { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderbundledescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct RenderBundleDescriptor { /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification. pub label: L, @@ -5931,8 +5945,8 @@ impl Default for RenderBundleDescriptor> { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagedatalayout). #[repr(C)] #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ImageDataLayout { /// Offset into the buffer that is the start of the texture. Must be a multiple of texture block size. /// For non-compressed textures, this is 1. @@ -5972,8 +5986,8 @@ pub struct ImageDataLayout { /// Corresponds to [WebGPU `GPUBufferBindingType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpubufferbindingtype). #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum BufferBindingType { /// A buffer for uniform values. /// @@ -6038,8 +6052,8 @@ pub enum BufferBindingType { /// Corresponds to [WebGPU `GPUTextureSampleType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gputexturesampletype). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum TextureSampleType { /// Sampling returns floats. /// @@ -6121,9 +6135,9 @@ impl Default for TextureSampleType { /// Corresponds to [WebGPU `GPUStorageTextureAccess`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpustoragetextureaccess). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum StorageTextureAccess { /// The texture can only be written in the shader and it: /// - may or may not be annotated with `write` (WGSL). @@ -6184,9 +6198,9 @@ pub enum StorageTextureAccess { /// https://gpuweb.github.io/gpuweb/#enumdef-gpusamplerbindingtype). #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum SamplerBindingType { /// The sampling result is produced based on more than a single color sample from a texture, /// e.g. when bilinear interpolation is enabled. @@ -6205,8 +6219,8 @@ pub enum SamplerBindingType { /// Corresponds to WebGPU's mutually exclusive fields within [`GPUBindGroupLayoutEntry`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum BindingType { /// A buffer binding. /// @@ -6222,7 +6236,7 @@ pub enum BindingType { /// for each dynamic binding in increasing order of binding number. /// /// [RPsbg]: ../wgpu/struct.RenderPass.html#method.set_bind_group - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] has_dynamic_offset: bool, /// The minimum size for a [`BufferBinding`] matching this entry, in bytes. @@ -6250,7 +6264,7 @@ pub enum BindingType { /// [minimum buffer binding size]: https://www.w3.org/TR/webgpu/#minimum-buffer-binding-size /// [`create_render_pipeline`]: ../wgpu/struct.Device.html#method.create_render_pipeline /// [`create_compute_pipeline`]: ../wgpu/struct.Device.html#method.create_compute_pipeline - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] min_binding_size: Option, }, /// A sampler that can be used to sample a texture. @@ -6355,8 +6369,8 @@ impl BindingType { /// Corresponds to [WebGPU `GPUBindGroupLayoutEntry`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct BindGroupLayoutEntry { /// Binding index. Must match shader index and be unique inside a BindGroupLayout. A binding /// of index 1, would be described as `layout(set = 0, binding = 1) uniform` in shaders. @@ -6370,7 +6384,7 @@ pub struct BindGroupLayoutEntry { /// If this value is Some and `ty` is `BindingType::Texture`, [`Features::TEXTURE_BINDING_ARRAY`] must be supported. /// /// If this value is Some and `ty` is any other variant, bind group creation will fail. - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub count: Option, } @@ -6380,8 +6394,8 @@ pub struct BindGroupLayoutEntry { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopybuffer). #[repr(C)] #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ImageCopyBuffer { /// The buffer to be copied to/from. pub buffer: B, @@ -6395,8 +6409,8 @@ pub struct ImageCopyBuffer { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexture). #[repr(C)] #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ImageCopyTexture { /// The texture to be copied to/from. pub texture: T, @@ -6405,10 +6419,10 @@ pub struct ImageCopyTexture { /// The base texel of the texture in the selected `mip_level`. Together /// with the `copy_size` argument to copy functions, defines the /// sub-region of the texture to copy. - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub origin: Origin3d, /// The copy aspect. - #[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub aspect: TextureAspect, } @@ -6528,9 +6542,9 @@ unsafe impl Sync for ExternalImageSource {} /// Corresponds to [HTML Canvas `PredefinedColorSpace`]( /// https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace). #[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum PredefinedColorSpace { /// sRGB color space Srgb, @@ -6544,8 +6558,8 @@ pub enum PredefinedColorSpace { /// Corresponds to [WebGPU `GPUImageCopyTextureTagged`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexturetagged). #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ImageCopyTextureTagged { /// The texture to be copied to/from. pub texture: T, @@ -6576,9 +6590,9 @@ impl ImageCopyTextureTagged { /// Subresource range within an image #[repr(C)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct ImageSubresourceRange { /// Aspect of the texture. Color textures must be [`TextureAspect::All`][TAA]. /// @@ -6678,8 +6692,8 @@ impl ImageSubresourceRange { /// Color variation to use when sampler addressing mode is [`AddressMode::ClampToBorder`] #[repr(C)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum SamplerBorderColor { /// [0, 0, 0, 0] TransparentBlack, @@ -6701,8 +6715,8 @@ pub enum SamplerBorderColor { /// Corresponds to [WebGPU `GPUQuerySetDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuquerysetdescriptor). #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct QuerySetDescriptor { /// Debug label for the query set. pub label: L, @@ -6729,8 +6743,8 @@ impl QuerySetDescriptor { /// Corresponds to [WebGPU `GPUQueryType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpuquerytype). #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum QueryType { /// Query returns a single 64-bit number, serving as an occlusion boolean. Occlusion, @@ -6876,8 +6890,8 @@ impl DispatchIndirectArgs { /// Describes how shader bound checks should be performed. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ShaderBoundChecks { runtime_checks: bool, } From d7c8f5f15f26817dbfbba695f02a66d56829d60a Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 15:00:58 +0100 Subject: [PATCH 03/18] Make use of deserialize, serialize features in wgpu-core --- wgpu-core/Cargo.toml | 10 ++++----- wgpu-core/src/binding_model.rs | 28 +++++++++++------------ wgpu-core/src/command/bundle.rs | 4 ++-- wgpu-core/src/command/compute.rs | 12 +++++----- wgpu-core/src/command/draw.rs | 8 +++---- wgpu-core/src/command/mod.rs | 4 ++-- wgpu-core/src/command/render.rs | 38 ++++++++++++++++---------------- wgpu-core/src/device/mod.rs | 8 +++---- wgpu-core/src/device/trace.rs | 8 +++---- wgpu-core/src/id.rs | 8 +++---- wgpu-core/src/pipeline.rs | 38 ++++++++++++++++---------------- wgpu-core/src/resource.rs | 8 +++---- 12 files changed, 87 insertions(+), 87 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 70336fac12..cacf7336f5 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -51,19 +51,19 @@ strict_asserts = ["wgt/strict_asserts"] serde = ["serialize", "deserialize", "wgt/serde"] ## serialize -serialize = ["dep:serde", "wgt/serialize"] +serialize = ["dep:serde", "wgt/serialize", "arrayvec/serde"] ## deserialize -deserialize = ["dep:serde", "wgt/deserialize"] +deserialize = ["dep:serde", "wgt/deserialize", "arrayvec/serde"] ## Enable API tracing. -trace = ["ron", "serialize", "arrayvec/serde", "naga/serialize"] +trace = ["ron", "serialize", "naga/serialize"] ## Enable API replaying -replay = ["deserialize", "arrayvec/serde", "naga/deserialize"] +replay = ["deserialize", "naga/deserialize"] ## Enable serializable compute/render passes, and bundle encoders. -serial-pass = ["serde", "wgt/serde", "arrayvec/serde"] +serial-pass = ["serde", "wgt/serde"] ## Enable `ShaderModuleSource::Wgsl` wgsl = ["naga/wgsl-in"] diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 833920ea35..6c7ebf481f 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -21,9 +21,9 @@ use crate::{ use arrayvec::ArrayVec; -#[cfg(feature = "replay")] +#[cfg(feature = "deserialize")] use serde::Deserialize; -#[cfg(feature = "trace")] +#[cfg(feature = "serialize")] use serde::Serialize; use std::{borrow::Cow, ops::Range, sync::Arc}; @@ -406,8 +406,8 @@ impl BindingTypeMaxCountValidator { /// Bindable resource and the slot to bind it to. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct BindGroupEntry<'a> { /// Slot for which binding provides resource. Corresponds to an entry of the same /// binding index in the [`BindGroupLayoutDescriptor`]. @@ -418,8 +418,8 @@ pub struct BindGroupEntry<'a> { /// Describes a group of bindings and the resources to be bound. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct BindGroupDescriptor<'a> { /// Debug label of the bind group. /// @@ -433,8 +433,8 @@ pub struct BindGroupDescriptor<'a> { /// Describes a [`BindGroupLayout`]. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct BindGroupLayoutDescriptor<'a> { /// Debug label of the bind group layout. /// @@ -582,8 +582,8 @@ pub enum PushConstantUploadError { /// /// A `PipelineLayoutDescriptor` can be used to create a pipeline layout. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct PipelineLayoutDescriptor<'a> { /// Debug label of the pipeine layout. /// @@ -734,8 +734,8 @@ impl Resource for PipelineLayout { #[repr(C)] #[derive(Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(Serialize))] -#[cfg_attr(feature = "replay", derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct BufferBinding { pub buffer_id: BufferId, pub offset: wgt::BufferAddress, @@ -745,8 +745,8 @@ pub struct BufferBinding { // Note: Duplicated in `wgpu-rs` as `BindingResource` // They're different enough that it doesn't make sense to share a common type #[derive(Debug, Clone)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum BindingResource<'a> { Buffer(BufferBinding), BufferArray(Cow<'a, [BufferBinding]>), diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 5d474f6a3a..2d9319ad2f 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -197,8 +197,8 @@ fn validate_indexed_draw( /// Describes a [`RenderBundleEncoder`]. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct RenderBundleEncoderDescriptor<'a> { /// Debug label of the render bundle encoder. /// diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index ef56f54985..85ea6a98a5 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -29,9 +29,9 @@ use crate::{ }; use hal::CommandEncoder as _; -#[cfg(any(feature = "serial-pass", feature = "replay"))] +#[cfg(feature = "deserialize")] use serde::Deserialize; -#[cfg(any(feature = "serial-pass", feature = "trace"))] +#[cfg(feature = "serialize")] use serde::Serialize; use thiserror::Error; @@ -41,11 +41,11 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] #[cfg_attr( - any(feature = "serial-pass", feature = "trace"), + feature = "serialize", derive(serde::Serialize) )] #[cfg_attr( - any(feature = "serial-pass", feature = "replay"), + feature = "deserialize", derive(serde::Deserialize) )] pub enum ComputeCommand { @@ -151,8 +151,8 @@ impl fmt::Debug for ComputePass { /// Describes the writing of timestamp values in a compute pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct ComputePassTimestampWrites { /// The query set to write the timestamps to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 058ba81f95..67dd2cbf05 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -127,11 +127,11 @@ impl crate::error::PrettyError for RenderCommandError { #[derive(Clone, Copy, Debug, Default)] #[cfg_attr( - any(feature = "serial-pass", feature = "trace"), + feature = "serialize", derive(serde::Serialize) )] #[cfg_attr( - any(feature = "serial-pass", feature = "replay"), + feature = "deserialize", derive(serde::Deserialize) )] pub struct Rect { @@ -144,11 +144,11 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] #[cfg_attr( - any(feature = "serial-pass", feature = "trace"), + feature = "serialize", derive(serde::Serialize) )] #[cfg_attr( - any(feature = "serial-pass", feature = "replay"), + feature = "deserialize", derive(serde::Deserialize) )] pub enum RenderCommand { diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 784d158bce..50478f9a09 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -339,11 +339,11 @@ pub struct BasePassRef<'a, C> { #[doc(hidden)] #[derive(Debug)] #[cfg_attr( - any(feature = "serial-pass", feature = "trace"), + feature = "serialize", derive(serde::Serialize) )] #[cfg_attr( - any(feature = "serial-pass", feature = "replay"), + feature = "deserialize", derive(serde::Deserialize) )] pub struct BasePass { diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 9f31d3c6d0..5286ab69d9 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -40,9 +40,9 @@ use wgt::{ TextureViewDimension, VertexStepMode, }; -#[cfg(any(feature = "serial-pass", feature = "replay"))] +#[cfg(feature = "deserialize")] use serde::Deserialize; -#[cfg(any(feature = "serial-pass", feature = "trace"))] +#[cfg(feature = "serialize")] use serde::Serialize; use std::sync::Arc; @@ -56,9 +56,9 @@ use super::{ /// Operation to perform to the output attachment at the start of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum LoadOp { /// Clear the output attachment with the clear color. Clearing is faster than loading. Clear = 0, @@ -69,9 +69,9 @@ pub enum LoadOp { /// Operation to perform to the output attachment at the end of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum StoreOp { /// Discards the content of the render target. /// @@ -84,8 +84,8 @@ pub enum StoreOp { /// Describes an individual channel within a render pass, such as color, depth, or stencil. #[repr(C)] #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct PassChannel { /// Operation to perform to the output attachment at the start of a /// renderpass. @@ -122,8 +122,8 @@ impl PassChannel { /// Describes a color attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct RenderPassColorAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -136,8 +136,8 @@ pub struct RenderPassColorAttachment { /// Describes a depth/stencil attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct RenderPassDepthStencilAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -188,9 +188,9 @@ impl RenderPassDepthStencilAttachment { /// Location to write a timestamp to (beginning or end of the pass). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] pub enum RenderPassTimestampLocation { Beginning = 0, End = 1, @@ -199,8 +199,8 @@ pub enum RenderPassTimestampLocation { /// Describes the writing of timestamp values in a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct RenderPassTimestampWrites { /// The query set to write the timestamp to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index c417952c40..419e08915c 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -42,8 +42,8 @@ pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum HostMap { Read, Write, @@ -457,8 +457,8 @@ pub struct MissingFeatures(pub wgt::Features); pub struct MissingDownlevelFlags(pub wgt::DownlevelFlags); #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ImplicitPipelineContext { pub root_id: id::PipelineLayoutId, pub group_ids: ArrayVec, diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 315b7e8e84..e1f7e29446 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -33,8 +33,8 @@ pub(crate) fn new_render_bundle_encoder_descriptor<'a>( #[allow(clippy::large_enum_variant)] #[derive(Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum Action<'a> { Init { desc: crate::device::DeviceDescriptor<'a>, @@ -126,8 +126,8 @@ pub enum Action<'a> { } #[derive(Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum Command { CopyBufferToBuffer { src: id::BufferId, diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 739beb7180..82a30b102d 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -56,19 +56,19 @@ type Dummy = hal::api::Empty; serde(from = "SerialId") )] #[cfg_attr( - all(feature = "serde", not(feature = "trace")), + all(feature = "serialize", not(feature = "trace")), derive(serde::Serialize) )] #[cfg_attr( - all(feature = "serde", not(feature = "replay")), + all(feature = "deserialize", not(feature = "replay")), derive(serde::Deserialize) )] pub struct Id(NonZeroId, PhantomData); // This type represents Id in a more readable (and editable) way. #[allow(dead_code)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] enum SerialId { // The only variant forces RON to not ignore "Id" Id(Index, Epoch, Backend), diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 7fb45321f0..0eb349ade2 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -38,11 +38,11 @@ pub enum ShaderModuleSource<'a> { } #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ShaderModuleDescriptor<'a> { pub label: Label<'a>, - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] pub shader_bound_checks: wgt::ShaderBoundChecks, } @@ -208,8 +208,8 @@ impl CreateShaderModuleError { /// Describes a programmable pipeline stage. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ProgrammableStageDescriptor<'a> { /// The compiled shader module for this stage. pub module: ShaderModuleId, @@ -236,8 +236,8 @@ pub enum ImplicitLayoutError { /// Describes a compute pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ComputePipelineDescriptor<'a> { pub label: Label<'a>, /// The layout of bind groups for this pipeline. @@ -311,9 +311,9 @@ impl ComputePipeline { /// Describes how the vertex buffer is interpreted. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] pub struct VertexBufferLayout<'a> { /// The stride, in bytes, between elements of this buffer. pub array_stride: wgt::BufferAddress, @@ -325,8 +325,8 @@ pub struct VertexBufferLayout<'a> { /// Describes the vertex process in a render pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct VertexState<'a> { /// The compiled vertex stage and its entry point. pub stage: ProgrammableStageDescriptor<'a>, @@ -336,8 +336,8 @@ pub struct VertexState<'a> { /// Describes fragment processing in a render pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct FragmentState<'a> { /// The compiled fragment stage and its entry point. pub stage: ProgrammableStageDescriptor<'a>, @@ -347,8 +347,8 @@ pub struct FragmentState<'a> { /// Describes a render (graphics) pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct RenderPipelineDescriptor<'a> { pub label: Label<'a>, /// The layout of bind groups for this pipeline. @@ -356,13 +356,13 @@ pub struct RenderPipelineDescriptor<'a> { /// The vertex processing state for this pipeline. pub vertex: VertexState<'a>, /// The properties of the pipeline at the primitive assembly and rasterization level. - #[cfg_attr(any(feature = "replay", feature = "trace"), serde(default))] + #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] pub primitive: wgt::PrimitiveState, /// The effect of draw calls on the depth and stencil aspects of the output target, if any. - #[cfg_attr(any(feature = "replay", feature = "trace"), serde(default))] + #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] pub depth_stencil: Option, /// The multi-sampling properties of the pipeline. - #[cfg_attr(any(feature = "replay", feature = "trace"), serde(default))] + #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] pub multisample: wgt::MultisampleState, /// The fragment processing state for this pipeline. pub fragment: Option>, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index b08216eeeb..f1fd6cc240 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1186,8 +1186,8 @@ impl Borrow for Texture { /// Describes a [`TextureView`]. #[derive(Clone, Debug, Default, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize), serde(default))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize), serde(default))] pub struct TextureViewDescriptor<'a> { /// Debug label of the texture view. /// @@ -1343,8 +1343,8 @@ impl Resource for TextureView { /// Describes a [`Sampler`] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct SamplerDescriptor<'a> { /// Debug label of the sampler. /// From e0a56c0778a0dd43ef205ce4b75852ff26038fb2 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 15:05:06 +0100 Subject: [PATCH 04/18] Make use of serialize, deserialize features in wgpu --- wgpu/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 9b4af33cd6..697bf7d6cf 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1115,8 +1115,8 @@ static_assertions::assert_impl_all!(BufferBinding<'_>: Send, Sync); /// Corresponds to [WebGPU `GPULoadOp`](https://gpuweb.github.io/gpuweb/#enumdef-gpuloadop), /// plus the corresponding clearValue. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum LoadOp { /// Loads the specified value for this attachment into the render pass. /// @@ -1143,8 +1143,8 @@ impl Default for LoadOp { /// /// Corresponds to [WebGPU `GPUStoreOp`](https://gpuweb.github.io/gpuweb/#enumdef-gpustoreop). #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum StoreOp { /// Stores the resulting value of the render pass for this attachment. #[default] @@ -1166,8 +1166,8 @@ pub enum StoreOp { /// This type is unique to the Rust API of `wgpu`. In the WebGPU specification, /// separate `loadOp` and `storeOp` fields are used instead. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct Operations { /// How data should be read through this attachment. pub load: LoadOp, From 52996872dd8daf7341bca25633e8cc8a68948f99 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 15:06:41 +0100 Subject: [PATCH 05/18] Run cargo fmt --- wgpu-core/src/command/compute.rs | 10 +- wgpu-core/src/command/draw.rs | 20 +-- wgpu-core/src/command/mod.rs | 10 +- wgpu-core/src/command/render.rs | 15 +- wgpu-core/src/pipeline.rs | 5 +- wgpu-types/src/lib.rs | 229 ++++++++++++++++++++++++------- 6 files changed, 206 insertions(+), 83 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 85ea6a98a5..0839bdcb42 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -40,14 +40,8 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr( - feature = "serialize", - derive(serde::Serialize) -)] -#[cfg_attr( - feature = "deserialize", - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum ComputeCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 67dd2cbf05..dc5b4a831c 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -126,14 +126,8 @@ impl crate::error::PrettyError for RenderCommandError { } #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr( - feature = "serialize", - derive(serde::Serialize) -)] -#[cfg_attr( - feature = "deserialize", - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct Rect { pub x: T, pub y: T, @@ -143,14 +137,8 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr( - feature = "serialize", - derive(serde::Serialize) -)] -#[cfg_attr( - feature = "deserialize", - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub enum RenderCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 50478f9a09..0c6d34fa17 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -338,14 +338,8 @@ pub struct BasePassRef<'a, C> { /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] #[derive(Debug)] -#[cfg_attr( - feature = "serialize", - derive(serde::Serialize) -)] -#[cfg_attr( - feature = "deserialize", - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct BasePass { pub label: Option, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 5286ab69d9..b94c7c0502 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -58,7 +58,10 @@ use super::{ #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum LoadOp { /// Clear the output attachment with the clear color. Clearing is faster than loading. Clear = 0, @@ -71,7 +74,10 @@ pub enum LoadOp { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum StoreOp { /// Discards the content of the render target. /// @@ -190,7 +196,10 @@ impl RenderPassDepthStencilAttachment { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum RenderPassTimestampLocation { Beginning = 0, End = 1, diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 0eb349ade2..3fe9aa71bf 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -313,7 +313,10 @@ impl ComputePipeline { #[derive(Clone, Debug)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct VertexBufferLayout<'a> { /// The stride, in bytes, between elements of this buffer. pub array_stride: wgt::BufferAddress, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index d91b8eea07..4c86ee565c 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -9,10 +9,10 @@ )] #![warn(missing_docs, unsafe_op_in_unsafe_fn)] -#[cfg(any(feature = "serialize", test))] -use serde::Serialize; #[cfg(any(feature = "deserialize", test))] use serde::Deserialize; +#[cfg(any(feature = "serialize", test))] +use serde::Serialize; use std::hash::{Hash, Hasher}; use std::path::PathBuf; use std::{num::NonZeroU32, ops::Range}; @@ -133,7 +133,10 @@ impl Backend { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum PowerPreference { #[default] /// Power usage is not considered when choosing an adapter. @@ -994,20 +997,32 @@ impl InstanceFlags { #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase", default))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase", default) +)] pub struct Limits { /// Maximum allowed value for the `size.width` of a texture created with `TextureDimension::D1`. /// Defaults to 8192. Higher is "better". - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension1D"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "maxTextureDimension1D") + )] pub max_texture_dimension_1d: u32, /// Maximum allowed value for the `size.width` and `size.height` of a texture created with `TextureDimension::D2`. /// Defaults to 8192. Higher is "better". - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension2D"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "maxTextureDimension2D") + )] pub max_texture_dimension_2d: u32, /// Maximum allowed value for the `size.width`, `size.height`, and `size.depth_or_array_layers` /// of a texture created with `TextureDimension::D3`. /// Defaults to 2048. Higher is "better". - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "maxTextureDimension3D"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "maxTextureDimension3D") + )] pub max_texture_dimension_3d: u32, /// Maximum allowed value for the `size.depth_or_array_layers` of a texture created with `TextureDimension::D2`. /// Defaults to 256. Higher is "better". @@ -1740,23 +1755,41 @@ impl_bitflags!(ShaderStages); #[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum TextureViewDimension { /// A one dimensional texture. `texture_1d` in WGSL and `texture1D` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "1d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "1d") + )] D1, /// A two dimensional texture. `texture_2d` in WGSL and `texture2D` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "2d") + )] #[default] D2, /// A two dimensional array texture. `texture_2d_array` in WGSL and `texture2DArray` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d-array"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "2d-array") + )] D2Array, /// A cubemap texture. `texture_cube` in WGSL and `textureCube` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "cube"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "cube") + )] Cube, /// A cubemap array texture. `texture_cube_array` in WGSL and `textureCubeArray` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "cube-array"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "cube-array") + )] CubeArray, /// A three dimensional texture. `texture_3d` in WGSL and `texture3D` in GLSL. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "3d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "3d") + )] D3, } @@ -1783,7 +1816,10 @@ impl TextureViewDimension { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum BlendFactor { /// 0.0 Zero = 0, @@ -1846,7 +1882,10 @@ impl BlendFactor { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum BlendOperation { /// Src + Dst #[default] @@ -1869,7 +1908,10 @@ pub enum BlendOperation { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct BlendComponent { /// Multiplier for the source, which is produced by the fragment shader. pub src_factor: BlendFactor, @@ -1925,7 +1967,10 @@ impl Default for BlendComponent { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct BlendState { /// Color equation. pub color: BlendComponent, @@ -1965,7 +2010,10 @@ impl BlendState { #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct ColorTargetState { /// The [`TextureFormat`] of the image that this pipeline will render to. Must match the format /// of the corresponding color attachment in [`CommandEncoder::begin_render_pass`][CEbrp] @@ -1998,7 +2046,10 @@ impl From for ColorTargetState { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum PrimitiveTopology { /// Vertex data is a list of points. Each vertex is a new point. PointList = 0, @@ -2039,7 +2090,10 @@ impl PrimitiveTopology { #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum FrontFace { /// Triangles with vertices in counter clockwise order are considered the front face. /// @@ -2061,7 +2115,10 @@ pub enum FrontFace { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum Face { /// Front face Front = 0, @@ -2074,7 +2131,10 @@ pub enum Face { #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum PolygonMode { /// Polygons are filled #[default] @@ -2093,7 +2153,10 @@ pub enum PolygonMode { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct PrimitiveState { /// The primitive topology used to interpret vertices. pub topology: PrimitiveTopology, @@ -2134,7 +2197,10 @@ pub struct PrimitiveState { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct MultisampleState { /// The number of samples calculated per pixel (for MSAA). For non-multisampled textures, /// this should be `1` @@ -4518,7 +4584,10 @@ impl DepthStencilState { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum IndexFormat { /// Indices are 16 bit unsigned integers. Uint16 = 0, @@ -4535,7 +4604,10 @@ pub enum IndexFormat { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum StencilOperation { /// Keep stencil value unchanged. #[default] @@ -4569,7 +4641,10 @@ pub enum StencilOperation { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct StencilFaceState { /// Comparison function that determines if the fail_op or pass_op is used on the stencil buffer. pub compare: CompareFunction, @@ -4620,7 +4695,10 @@ impl Default for StencilFaceState { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum CompareFunction { /// Function never passes Never = 1, @@ -4715,7 +4793,10 @@ impl CompareFunction { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum VertexStepMode { /// Vertex data is advanced every vertex. #[default] @@ -4737,7 +4818,10 @@ pub enum VertexStepMode { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct VertexAttribute { /// Format of the input pub format: VertexFormat, @@ -4755,7 +4839,10 @@ pub struct VertexAttribute { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "lowercase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "lowercase") +)] pub enum VertexFormat { /// Two unsigned bytes (u8). `vec2` in shaders. Uint8x2 = 0, @@ -5049,7 +5136,10 @@ pub enum PresentMode { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "lowercase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "lowercase") +)] pub enum CompositeAlphaMode { /// Chooses either `Opaque` or `Inherit` automatically,depending on the /// `alpha_mode` that the current surface can support. @@ -5276,7 +5366,10 @@ impl PresentationTimestamp { #[derive(Clone, Copy, Debug, Default, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct Color { /// Red component of the color pub r: f64, @@ -5338,13 +5431,22 @@ impl Color { #[cfg_attr(feature = "deserialize", derive(Deserialize))] pub enum TextureDimension { /// 1D texture - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "1d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "1d") + )] D1, /// 2D texture - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "2d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "2d") + )] D2, /// 3D texture - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename = "3d"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename = "3d") + )] D3, } @@ -5356,7 +5458,10 @@ pub enum TextureDimension { #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct Origin2d { /// pub x: u32, @@ -5392,7 +5497,10 @@ impl std::fmt::Debug for Origin2d { #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct Origin3d { /// X position of the origin pub x: u32, @@ -5435,14 +5543,20 @@ impl std::fmt::Debug for Origin3d { #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct Extent3d { /// Width of the extent pub width: u32, /// Height of the extent pub height: u32, /// The depth of the extent or the number of array layers - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default = "default_depth"))] + #[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(default = "default_depth") + )] pub depth_or_array_layers: u32, } @@ -5767,7 +5881,10 @@ impl TextureDescriptor { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum TextureAspect { /// Depth, Stencil, and Color. #[default] @@ -5792,7 +5909,10 @@ pub enum TextureAspect { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum AddressMode { /// Clamp the value to the edge of the texture /// @@ -5826,7 +5946,10 @@ pub enum AddressMode { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum FilterMode { /// Nearest neighbor sampling. /// @@ -6137,7 +6260,10 @@ impl Default for TextureSampleType { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum StorageTextureAccess { /// The texture can only be written in the shader and it: /// - may or may not be annotated with `write` (WGSL). @@ -6200,7 +6326,10 @@ pub enum StorageTextureAccess { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum SamplerBindingType { /// The sampling result is produced based on more than a single color sample from a texture, /// e.g. when bilinear interpolation is enabled. @@ -6544,7 +6673,10 @@ unsafe impl Sync for ExternalImageSource {} #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "kebab-case"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "kebab-case") +)] pub enum PredefinedColorSpace { /// sRGB color space Srgb, @@ -6592,7 +6724,10 @@ impl ImageCopyTextureTagged { #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(rename_all = "camelCase"))] +#[cfg_attr( + any(feature = "serialize", feature = "deserialize"), + serde(rename_all = "camelCase") +)] pub struct ImageSubresourceRange { /// Aspect of the texture. Color textures must be [`TextureAspect::All`][TAA]. /// From 294d2b4e05f4e33e31da6bee40bc94c92b3cf40a Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 19:59:19 +0100 Subject: [PATCH 06/18] Use serde(default) for deserialize only --- wgpu-core/src/pipeline.rs | 8 ++++---- wgpu-types/src/lib.rs | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 3fe9aa71bf..6cd9267135 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -42,7 +42,7 @@ pub enum ShaderModuleSource<'a> { #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct ShaderModuleDescriptor<'a> { pub label: Label<'a>, - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub shader_bound_checks: wgt::ShaderBoundChecks, } @@ -359,13 +359,13 @@ pub struct RenderPipelineDescriptor<'a> { /// The vertex processing state for this pipeline. pub vertex: VertexState<'a>, /// The properties of the pipeline at the primitive assembly and rasterization level. - #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub primitive: wgt::PrimitiveState, /// The effect of draw calls on the depth and stencil aspects of the output target, if any. - #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub depth_stencil: Option, /// The multi-sampling properties of the pipeline. - #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub multisample: wgt::MultisampleState, /// The fragment processing state for this pipeline. pub fragment: Option>, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 4c86ee565c..c8ad654f30 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2021,10 +2021,10 @@ pub struct ColorTargetState { /// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass pub format: TextureFormat, /// The blending that is used for this pipeline. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub blend: Option, /// Mask which enables/disables writes to different color/alpha channel. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub write_mask: ColorWrites, } @@ -2162,25 +2162,25 @@ pub struct PrimitiveState { pub topology: PrimitiveTopology, /// When drawing strip topologies with indices, this is the required format for the index buffer. /// This has no effect on non-indexed or non-strip draws. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub front_face: FrontFace, /// The face culling mode. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub cull_mode: Option, /// If set to true, the polygon depth is not clipped to 0-1 before rasterization. /// /// Enabling this requires `Features::DEPTH_CLIP_CONTROL` to be enabled. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub unclipped_depth: bool, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` /// /// Setting this to `Line` requires `Features::POLYGON_MODE_LINE` to be enabled. /// /// Setting this to `Point` requires `Features::POLYGON_MODE_POINT` to be enabled. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub polygon_mode: PolygonMode, /// If set to true, the primitives are rendered with conservative overestimation. I.e. any rastered pixel touched by it is filled. /// Only valid for PolygonMode::Fill! @@ -4547,10 +4547,10 @@ pub struct DepthStencilState { /// Comparison function used to compare depth values in the depth test. pub depth_compare: CompareFunction, /// Stencil state. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub stencil: StencilState, /// Depth bias state. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub bias: DepthBiasState, } @@ -5554,7 +5554,7 @@ pub struct Extent3d { pub height: u32, /// The depth of the extent or the number of array layers #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), + feature = "deserialize", serde(default = "default_depth") )] pub depth_or_array_layers: u32, @@ -6365,7 +6365,7 @@ pub enum BindingType { /// for each dynamic binding in increasing order of binding number. /// /// [RPsbg]: ../wgpu/struct.RenderPass.html#method.set_bind_group - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] has_dynamic_offset: bool, /// The minimum size for a [`BufferBinding`] matching this entry, in bytes. @@ -6393,7 +6393,7 @@ pub enum BindingType { /// [minimum buffer binding size]: https://www.w3.org/TR/webgpu/#minimum-buffer-binding-size /// [`create_render_pipeline`]: ../wgpu/struct.Device.html#method.create_render_pipeline /// [`create_compute_pipeline`]: ../wgpu/struct.Device.html#method.create_compute_pipeline - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] min_binding_size: Option, }, /// A sampler that can be used to sample a texture. @@ -6513,7 +6513,7 @@ pub struct BindGroupLayoutEntry { /// If this value is Some and `ty` is `BindingType::Texture`, [`Features::TEXTURE_BINDING_ARRAY`] must be supported. /// /// If this value is Some and `ty` is any other variant, bind group creation will fail. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub count: Option, } @@ -6548,10 +6548,10 @@ pub struct ImageCopyTexture { /// The base texel of the texture in the selected `mip_level`. Together /// with the `copy_size` argument to copy functions, defines the /// sub-region of the texture to copy. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub origin: Origin3d, /// The copy aspect. - #[cfg_attr(any(feature = "serialize", feature = "deserialize"), serde(default))] + #[cfg_attr(feature = "deserialize", serde(default))] pub aspect: TextureAspect, } From 14e7ae3e5d2d87cae3d31e0a2639530267616774 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 20:16:15 +0100 Subject: [PATCH 07/18] Fix serial-pass feature --- wgpu-core/Cargo.toml | 4 ++-- wgpu-core/src/command/compute.rs | 12 +++++----- wgpu-core/src/command/draw.rs | 8 +++---- wgpu-core/src/command/mod.rs | 4 ++-- wgpu-core/src/command/render.rs | 38 ++++++++++++++++---------------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index cacf7336f5..96ea736d23 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -48,7 +48,7 @@ renderdoc = ["hal/renderdoc"] strict_asserts = ["wgt/strict_asserts"] ## serde -serde = ["serialize", "deserialize", "wgt/serde"] +serde = ["serialize", "deserialize", "serial-pass", "wgt/serde"] ## serialize serialize = ["dep:serde", "wgt/serialize", "arrayvec/serde"] @@ -63,7 +63,7 @@ trace = ["ron", "serialize", "naga/serialize"] replay = ["deserialize", "naga/deserialize"] ## Enable serializable compute/render passes, and bundle encoders. -serial-pass = ["serde", "wgt/serde"] +serial-pass = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enable `ShaderModuleSource::Wgsl` wgsl = ["naga/wgsl-in"] diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 0839bdcb42..4b60e9821b 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -29,9 +29,9 @@ use crate::{ }; use hal::CommandEncoder as _; -#[cfg(feature = "deserialize")] +#[cfg(any(feature = "deserialize", feature = "serial-pass"))] use serde::Deserialize; -#[cfg(feature = "serialize")] +#[cfg(any(feature = "serialize", feature = "serial-pass"))] use serde::Serialize; use thiserror::Error; @@ -40,8 +40,8 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] pub enum ComputeCommand { SetBindGroup { index: u32, @@ -145,8 +145,8 @@ impl fmt::Debug for ComputePass { /// Describes the writing of timestamp values in a compute pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] pub struct ComputePassTimestampWrites { /// The query set to write the timestamps to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index dc5b4a831c..26cb66b166 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -126,8 +126,8 @@ impl crate::error::PrettyError for RenderCommandError { } #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] pub struct Rect { pub x: T, pub y: T, @@ -137,8 +137,8 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] pub enum RenderCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 0c6d34fa17..8ca5bb47f4 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -338,8 +338,8 @@ pub struct BasePassRef<'a, C> { /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] #[derive(Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] pub struct BasePass { pub label: Option, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index b94c7c0502..66cf3e008f 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -40,9 +40,9 @@ use wgt::{ TextureViewDimension, VertexStepMode, }; -#[cfg(feature = "deserialize")] +#[cfg(any(feature = "deserialize", feature = "serial-pass"))] use serde::Deserialize; -#[cfg(feature = "serialize")] +#[cfg(any(feature = "serialize", feature = "serial-pass"))] use serde::Serialize; use std::sync::Arc; @@ -56,10 +56,10 @@ use super::{ /// Operation to perform to the output attachment at the start of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), + any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), serde(rename_all = "kebab-case") )] pub enum LoadOp { @@ -72,10 +72,10 @@ pub enum LoadOp { /// Operation to perform to the output attachment at the end of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), + any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), serde(rename_all = "kebab-case") )] pub enum StoreOp { @@ -90,8 +90,8 @@ pub enum StoreOp { /// Describes an individual channel within a render pass, such as color, depth, or stencil. #[repr(C)] #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] pub struct PassChannel { /// Operation to perform to the output attachment at the start of a /// renderpass. @@ -128,8 +128,8 @@ impl PassChannel { /// Describes a color attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] pub struct RenderPassColorAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -142,8 +142,8 @@ pub struct RenderPassColorAttachment { /// Describes a depth/stencil attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] pub struct RenderPassDepthStencilAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -194,10 +194,10 @@ impl RenderPassDepthStencilAttachment { /// Location to write a timestamp to (beginning or end of the pass). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), + any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), serde(rename_all = "kebab-case") )] pub enum RenderPassTimestampLocation { @@ -208,8 +208,8 @@ pub enum RenderPassTimestampLocation { /// Describes the writing of timestamp values in a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] +#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] pub struct RenderPassTimestampWrites { /// The query set to write the timestamp to. pub query_set: id::QuerySetId, From d6ec7c3d29861680d9df8f320c77f72eee5c48ce Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 20:18:47 +0100 Subject: [PATCH 08/18] Add a comment for new features --- wgpu-core/Cargo.toml | 6 +++--- wgpu/Cargo.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 96ea736d23..06eda4663b 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -47,13 +47,13 @@ renderdoc = ["hal/renderdoc"] ## to the validation carried out at public APIs in all builds. strict_asserts = ["wgt/strict_asserts"] -## serde +## Enables serde functionality on common wgpu types. serde = ["serialize", "deserialize", "serial-pass", "wgt/serde"] -## serialize +## Enables serialize functionality on common wgpu types. serialize = ["dep:serde", "wgt/serialize", "arrayvec/serde"] -## deserialize +## Enables deserialize functionality on common wgpu types. deserialize = ["dep:serde", "wgt/deserialize", "arrayvec/serde"] ## Enable API tracing. diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 04347e3bff..024267f85c 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -78,13 +78,13 @@ strict_asserts = ["wgc?/strict_asserts", "wgt/strict_asserts"] ## Log all API entry points at info instead of trace level. api_log_info = ["wgc/api_log_info"] -## serde +## Enables serde functionality on common wgpu types. serde = ["serialize", "deserialize", "wgc/serde"] -## serialize +## Enables serialize functionality on common wgpu types. serialize = ["dep:serde", "wgc/serialize"] -## deserialize +## Enables deserialize functionality on common wgpu types. deserialize = ["dep:serde", "wgc/deserialize"] ## Allow writing of trace capture files. From 1ccd6a0b50d9b864ce14205e6d5219c50caba52a Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 20:27:37 +0100 Subject: [PATCH 09/18] Add CHANGELOG entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53a43857bc..7eebcccc35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,12 +67,15 @@ Bottom level categories: - `tan` - `tanh` - Eager release of GPU resources comes from device.trackers. By @bradwerth in [#5075](https://github.com/gfx-rs/wgpu/pull/5075) +- `wgpu`, `wgpu-core` and `wgpu-types` now have `serialize` and `deserialize` features. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) +- `wgpu-types`'s `trace` and `replay` features have been replaced by `serialize` and `deserialize` respectively. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) ### Bug Fixes #### General - Fix `panic!` when dropping `Instance` without `InstanceFlags::VALIDATION`. By @hakolao in [#5134](https://github.com/gfx-rs/wgpu/pull/5134) +- Fix `serde` feature not compiling for `wgpu-types`. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) #### WGL From 4429eb006b82056a4fe8d4e6a51a48e96261e925 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 20:28:56 +0100 Subject: [PATCH 10/18] Run cargo fmt --- wgpu-core/src/command/compute.rs | 15 +++++++-- wgpu-core/src/command/draw.rs | 20 +++++++++--- wgpu-core/src/command/mod.rs | 10 ++++-- wgpu-core/src/command/render.rs | 53 ++++++++++++++++++++++++++------ wgpu-types/src/lib.rs | 5 +-- 5 files changed, 80 insertions(+), 23 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 4b60e9821b..f6ff0d1c25 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -40,8 +40,14 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] +#[cfg_attr( + any(feature = "serialize", feature = "serial-pass"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(serde::Deserialize) +)] pub enum ComputeCommand { SetBindGroup { index: u32, @@ -146,7 +152,10 @@ impl fmt::Debug for ComputePass { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] pub struct ComputePassTimestampWrites { /// The query set to write the timestamps to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 26cb66b166..cb1cec3c9a 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -126,8 +126,14 @@ impl crate::error::PrettyError for RenderCommandError { } #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] +#[cfg_attr( + any(feature = "serialize", feature = "serial-pass"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(serde::Deserialize) +)] pub struct Rect { pub x: T, pub y: T, @@ -137,8 +143,14 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] +#[cfg_attr( + any(feature = "serialize", feature = "serial-pass"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(serde::Deserialize) +)] pub enum RenderCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 8ca5bb47f4..171c76512e 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -338,8 +338,14 @@ pub struct BasePassRef<'a, C> { /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] #[derive(Debug)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(serde::Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(serde::Deserialize))] +#[cfg_attr( + any(feature = "serialize", feature = "serial-pass"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(serde::Deserialize) +)] pub struct BasePass { pub label: Option, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 66cf3e008f..aafe620a4d 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -57,9 +57,16 @@ use super::{ #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] +#[cfg_attr( + any( + feature = "serialize", + feature = "deserialize", + feature = "serial-pass" + ), serde(rename_all = "kebab-case") )] pub enum LoadOp { @@ -73,9 +80,16 @@ pub enum LoadOp { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] +#[cfg_attr( + any( + feature = "serialize", + feature = "deserialize", + feature = "serial-pass" + ), serde(rename_all = "kebab-case") )] pub enum StoreOp { @@ -91,7 +105,10 @@ pub enum StoreOp { #[repr(C)] #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] pub struct PassChannel { /// Operation to perform to the output attachment at the start of a /// renderpass. @@ -129,7 +146,10 @@ impl PassChannel { #[repr(C)] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] pub struct RenderPassColorAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -143,7 +163,10 @@ pub struct RenderPassColorAttachment { #[repr(C)] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] pub struct RenderPassDepthStencilAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -195,9 +218,16 @@ impl RenderPassDepthStencilAttachment { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] #[cfg_attr( - any(feature = "serialize", feature = "deserialize", feature = "serial-pass"), + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] +#[cfg_attr( + any( + feature = "serialize", + feature = "deserialize", + feature = "serial-pass" + ), serde(rename_all = "kebab-case") )] pub enum RenderPassTimestampLocation { @@ -209,7 +239,10 @@ pub enum RenderPassTimestampLocation { #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr(any(feature = "deserialize", feature = "serial-pass"), derive(Deserialize))] +#[cfg_attr( + any(feature = "deserialize", feature = "serial-pass"), + derive(Deserialize) +)] pub struct RenderPassTimestampWrites { /// The query set to write the timestamp to. pub query_set: id::QuerySetId, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c8ad654f30..c50437b783 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -5553,10 +5553,7 @@ pub struct Extent3d { /// Height of the extent pub height: u32, /// The depth of the extent or the number of array layers - #[cfg_attr( - feature = "deserialize", - serde(default = "default_depth") - )] + #[cfg_attr(feature = "deserialize", serde(default = "default_depth"))] pub depth_or_array_layers: u32, } From 4f048e0bd1155afd84c2b0d5f2d998e0ee5823f8 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sat, 27 Jan 2024 20:38:03 +0100 Subject: [PATCH 11/18] serial-pass also needs serde features for Id --- wgpu-core/src/id.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 82a30b102d..ddaeac9620 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -56,11 +56,17 @@ type Dummy = hal::api::Empty; serde(from = "SerialId") )] #[cfg_attr( - all(feature = "serialize", not(feature = "trace")), + all( + any(feature = "serialize", feature = "serial-pass"), + not(feature = "trace") + ), derive(serde::Serialize) )] #[cfg_attr( - all(feature = "deserialize", not(feature = "replay")), + all( + any(feature = "deserialize", feature = "serial-pass"), + not(feature = "replay") + ), derive(serde::Deserialize) )] pub struct Id(NonZeroId, PhantomData); From 273684f1b0ce6c67e0163b08cadaca77813b57c1 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 12:49:48 +0100 Subject: [PATCH 12/18] Add feature documentation to lib.rs docs --- wgpu-core/src/lib.rs | 3 +++ wgpu/src/lib.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 74c27bd960..df775e256a 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -13,6 +13,9 @@ //! [https://renderdoc.org/](https://renderdoc.org/) //! - **`strict_asserts`** --- Apply run-time checks, even in release builds. These are in addition //! to the validation carried out at public APIs in all builds. +//! - **`serde`** --- Enables serde functionality on common wgpu types. +//! - **`serialize`** ---Enables serialize functionality on common wgpu types. +//! - **`deserialize`** --- Enables deserialize functionality on common wgpu types. //! - **`trace`** --- Enable API tracing. //! - **`replay`** --- Enable API replaying //! - **`serial-pass`** --- Enable serializable compute/render passes, and bundle encoders. diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 697bf7d6cf..f7035e8675 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -37,6 +37,9 @@ //! - **`strict_asserts`** --- Apply run-time checks, even in release builds. These are in addition //! to the validation carried out at public APIs in all builds. //! - **`api_log_info`** --- Log all API entry points at info instead of trace level. +//! - **`serde`** --- Enables serde functionality on common wgpu types. +//! - **`serialize`** ---Enables serialize functionality on common wgpu types. +//! - **`deserialize`** --- Enables deserialize functionality on common wgpu types. //! - **`trace`** --- Allow writing of trace capture files. See [`Adapter::request_device`]. //! - **`replay`** --- Allow deserializing of trace capture files that were written with the `trace` //! feature. To replay a trace file use the [wgpu From 297df84bd1c52fd0e0c1fab1a7750cbdd6b06e3d Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 12:38:28 +0100 Subject: [PATCH 13/18] wgpu-types implicit serde feature --- player/Cargo.toml | 2 +- tests/Cargo.toml | 2 +- wgpu-core/Cargo.toml | 4 +- wgpu-types/Cargo.toml | 3 - wgpu-types/src/lib.rs | 470 ++++++++++++------------------------------ 5 files changed, 138 insertions(+), 343 deletions(-) diff --git a/player/Cargo.toml b/player/Cargo.toml index f50fd2e5d0..6c391cb4d6 100644 --- a/player/Cargo.toml +++ b/player/Cargo.toml @@ -29,7 +29,7 @@ winit = { workspace = true, optional = true } [dependencies.wgt] workspace = true -features = ["deserialize"] +features = ["serde"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] workspace = true diff --git a/tests/Cargo.toml b/tests/Cargo.toml index e3c0f21ec4..c4cbaa9e3e 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -38,7 +38,7 @@ serde_json.workspace = true serde.workspace = true wgpu-macros.workspace = true wgpu.workspace = true -wgt = { workspace = true, features = ["deserialize"] } +wgt = { workspace = true, features = ["serde"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger.workspace = true diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 06eda4663b..2539c4ff20 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -51,10 +51,10 @@ strict_asserts = ["wgt/strict_asserts"] serde = ["serialize", "deserialize", "serial-pass", "wgt/serde"] ## Enables serialize functionality on common wgpu types. -serialize = ["dep:serde", "wgt/serialize", "arrayvec/serde"] +serialize = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enables deserialize functionality on common wgpu types. -deserialize = ["dep:serde", "wgt/deserialize", "arrayvec/serde"] +deserialize = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enable API tracing. trace = ["ron", "serialize", "naga/serialize"] diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index b2fbcd0f11..ff3649f24b 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -28,9 +28,6 @@ targets = [ [lib] [features] -serde = ["serialize", "deserialize"] -serialize = ["dep:serde"] -deserialize = ["dep:serde"] strict_asserts = [] fragile-send-sync-non-atomic-wasm = [] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c50437b783..c57823e580 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -9,9 +9,8 @@ )] #![warn(missing_docs, unsafe_op_in_unsafe_fn)] -#[cfg(any(feature = "deserialize", test))] +#[cfg(any(feature = "serde", test))] use serde::Deserialize; -#[cfg(any(feature = "serialize", test))] use serde::Serialize; use std::hash::{Hash, Hasher}; use std::path::PathBuf; @@ -28,7 +27,7 @@ pub mod math; // behavior to this macro (unspecified bit do not produce an error). macro_rules! impl_bitflags { ($name:ident) => { - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] impl serde::Serialize for $name { fn serialize(&self, serializer: S) -> Result where @@ -38,7 +37,7 @@ macro_rules! impl_bitflags { } } - #[cfg(feature = "deserialize")] + #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result<$name, D::Error> where @@ -94,8 +93,7 @@ pub const QUERY_SIZE: u32 = 8; /// Backends supported by wgpu. #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Backend { /// Dummy backend, used for testing. Empty = 0, @@ -131,12 +129,8 @@ impl Backend { /// https://gpuweb.github.io/gpuweb/#enumdef-gpupowerpreference). #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum PowerPreference { #[default] /// Power usage is not considered when choosing an adapter. @@ -203,8 +197,7 @@ impl From for Backends { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurequestadapteroptions). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct RequestAdapterOptions { /// Power preference for the adapter. pub power_preference: PowerPreference, @@ -995,34 +988,21 @@ impl InstanceFlags { /// [`downlevel_defaults()`]: Limits::downlevel_defaults #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase", default) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase", default))] pub struct Limits { /// Maximum allowed value for the `size.width` of a texture created with `TextureDimension::D1`. /// Defaults to 8192. Higher is "better". - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "maxTextureDimension1D") - )] + #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension1D"))] pub max_texture_dimension_1d: u32, /// Maximum allowed value for the `size.width` and `size.height` of a texture created with `TextureDimension::D2`. /// Defaults to 8192. Higher is "better". - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "maxTextureDimension2D") - )] + #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension2D"))] pub max_texture_dimension_2d: u32, /// Maximum allowed value for the `size.width`, `size.height`, and `size.depth_or_array_layers` /// of a texture created with `TextureDimension::D3`. /// Defaults to 2048. Higher is "better". - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "maxTextureDimension3D") - )] + #[cfg_attr(feature = "serde", serde(rename = "maxTextureDimension3D"))] pub max_texture_dimension_3d: u32, /// Maximum allowed value for the `size.depth_or_array_layers` of a texture created with `TextureDimension::D2`. /// Defaults to 256. Higher is "better". @@ -1387,8 +1367,7 @@ impl Limits { /// Represents the sets of additional limits on an adapter, /// which take place when running on downlevel backends. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DownlevelLimits {} #[allow(unknown_lints)] // derivable_impls is nightly only currently @@ -1401,8 +1380,7 @@ impl Default for DownlevelLimits { /// Lists various ways the underlying platform does not conform to the WebGPU standard. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DownlevelCapabilities { /// Combined boolean flags. pub flags: DownlevelFlags, @@ -1611,8 +1589,7 @@ impl DownlevelFlags { /// Collections of shader features a device supports if they support less than WebGPU normally allows. // TODO: Fill out the differences between shader models more completely #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ShaderModel { /// Extremely limited shaders, including a total instruction limit. Sm2, @@ -1625,8 +1602,7 @@ pub enum ShaderModel { /// Supported physical device types. #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum DeviceType { /// Other or Unknown. Other, @@ -1644,8 +1620,7 @@ pub enum DeviceType { /// Information about an adapter. #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct AdapterInfo { /// Adapter name pub name: String, @@ -1688,8 +1663,7 @@ pub struct AdapterInfo { /// https://gpuweb.github.io/gpuweb/#gpudevicedescriptor). #[repr(C)] #[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DeviceDescriptor { /// Debug label for the device. pub label: L, @@ -1751,45 +1725,26 @@ impl_bitflags!(ShaderStages); /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureviewdimension). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum TextureViewDimension { /// A one dimensional texture. `texture_1d` in WGSL and `texture1D` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "1d") - )] + #[cfg_attr(feature = "serde", serde(rename = "1d"))] D1, /// A two dimensional texture. `texture_2d` in WGSL and `texture2D` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "2d") - )] + #[cfg_attr(feature = "serde", serde(rename = "2d"))] #[default] D2, /// A two dimensional array texture. `texture_2d_array` in WGSL and `texture2DArray` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "2d-array") - )] + #[cfg_attr(feature = "serde", serde(rename = "2d-array"))] D2Array, /// A cubemap texture. `texture_cube` in WGSL and `textureCube` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "cube") - )] + #[cfg_attr(feature = "serde", serde(rename = "cube"))] Cube, /// A cubemap array texture. `texture_cube_array` in WGSL and `textureCubeArray` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "cube-array") - )] + #[cfg_attr(feature = "serde", serde(rename = "cube-array"))] CubeArray, /// A three dimensional texture. `texture_3d` in WGSL and `texture3D` in GLSL. - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "3d") - )] + #[cfg_attr(feature = "serde", serde(rename = "3d"))] D3, } @@ -1814,12 +1769,8 @@ impl TextureViewDimension { /// used with the first render target. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum BlendFactor { /// 0.0 Zero = 0, @@ -1880,12 +1831,8 @@ impl BlendFactor { /// https://gpuweb.github.io/gpuweb/#enumdef-gpublendoperation). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum BlendOperation { /// Src + Dst #[default] @@ -1906,12 +1853,8 @@ pub enum BlendOperation { /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendcomponent). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct BlendComponent { /// Multiplier for the source, which is produced by the fragment shader. pub src_factor: BlendFactor, @@ -1965,12 +1908,8 @@ impl Default for BlendComponent { /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendstate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct BlendState { /// Color equation. pub color: BlendComponent, @@ -2008,12 +1947,8 @@ impl BlendState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpucolortargetstate). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct ColorTargetState { /// The [`TextureFormat`] of the image that this pipeline will render to. Must match the format /// of the corresponding color attachment in [`CommandEncoder::begin_render_pass`][CEbrp] @@ -2021,10 +1956,10 @@ pub struct ColorTargetState { /// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass pub format: TextureFormat, /// The blending that is used for this pipeline. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub blend: Option, /// Mask which enables/disables writes to different color/alpha channel. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub write_mask: ColorWrites, } @@ -2044,12 +1979,8 @@ impl From for ColorTargetState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuprimitivetopology). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum PrimitiveTopology { /// Vertex data is a list of points. Each vertex is a new point. PointList = 0, @@ -2088,12 +2019,8 @@ impl PrimitiveTopology { /// https://gpuweb.github.io/gpuweb/#enumdef-gpufrontface). #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum FrontFace { /// Triangles with vertices in counter clockwise order are considered the front face. /// @@ -2113,12 +2040,8 @@ pub enum FrontFace { /// except that the `"none"` value is represented using `Option` instead. #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Face { /// Front face Front = 0, @@ -2129,12 +2052,8 @@ pub enum Face { /// Type of drawing mode for polygons #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum PolygonMode { /// Polygons are filled #[default] @@ -2151,36 +2070,32 @@ pub enum PolygonMode { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuprimitivestate). #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct PrimitiveState { /// The primitive topology used to interpret vertices. pub topology: PrimitiveTopology, /// When drawing strip topologies with indices, this is the required format for the index buffer. /// This has no effect on non-indexed or non-strip draws. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub front_face: FrontFace, /// The face culling mode. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub cull_mode: Option, /// If set to true, the polygon depth is not clipped to 0-1 before rasterization. /// /// Enabling this requires `Features::DEPTH_CLIP_CONTROL` to be enabled. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub unclipped_depth: bool, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` /// /// Setting this to `Line` requires `Features::POLYGON_MODE_LINE` to be enabled. /// /// Setting this to `Point` requires `Features::POLYGON_MODE_POINT` to be enabled. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub polygon_mode: PolygonMode, /// If set to true, the primitives are rendered with conservative overestimation. I.e. any rastered pixel touched by it is filled. /// Only valid for PolygonMode::Fill! @@ -2195,12 +2110,8 @@ pub struct PrimitiveState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpumultisamplestate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct MultisampleState { /// The number of samples calculated per pixel (for MSAA). For non-multisampled textures, /// this should be `1` @@ -2287,8 +2198,7 @@ impl_bitflags!(TextureFormatFeatureFlags); /// /// Features are defined by WebGPU specification unless `Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES` is enabled. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TextureFormatFeatures { /// Valid bits for `TextureDescriptor::Usage` provided for format creation. pub allowed_usages: TextureUsages, @@ -2299,8 +2209,7 @@ pub struct TextureFormatFeatures { /// ASTC block dimensions #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum AstcBlock { /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). B4x4, @@ -2335,8 +2244,7 @@ pub enum AstcBlock { /// ASTC RGBA channel #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum AstcChannel { /// 8 bit integer RGBA, [0, 255] converted to/from linear-color float [0, 1] in shader. /// @@ -2665,7 +2573,7 @@ pub enum TextureFormat { }, } -#[cfg(any(feature = "deserialize", test))] +#[cfg(any(feature = "serde", test))] impl<'de> Deserialize<'de> for TextureFormat { fn deserialize(deserializer: D) -> Result where @@ -2804,7 +2712,7 @@ impl<'de> Deserialize<'de> for TextureFormat { } } -#[cfg(any(feature = "serialize", test))] +#[cfg(any(feature = "serde", test))] impl Serialize for TextureFormat { fn serialize(&self, serializer: S) -> Result where @@ -4444,8 +4352,7 @@ impl MaintainResult { /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct StencilState { /// Front face mode. pub front: StencilFaceState, @@ -4492,8 +4399,7 @@ impl StencilState { /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DepthBiasState { /// Constant depth biasing factor, in basic units of the depth format. pub constant: i32, @@ -4534,8 +4440,7 @@ impl Eq for DepthBiasState {} /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] #[derive(Clone, Debug, Hash, PartialEq, Eq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DepthStencilState { /// Format of the depth/stencil buffer, must be special depth format. Must match the format /// of the depth/stencil attachment in [`CommandEncoder::begin_render_pass`][CEbrp]. @@ -4547,10 +4452,10 @@ pub struct DepthStencilState { /// Comparison function used to compare depth values in the depth test. pub depth_compare: CompareFunction, /// Stencil state. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub stencil: StencilState, /// Depth bias state. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub bias: DepthBiasState, } @@ -4582,12 +4487,8 @@ impl DepthStencilState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuindexformat). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum IndexFormat { /// Indices are 16 bit unsigned integers. Uint16 = 0, @@ -4602,12 +4503,8 @@ pub enum IndexFormat { /// https://gpuweb.github.io/gpuweb/#enumdef-gpustenciloperation). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum StencilOperation { /// Keep stencil value unchanged. #[default] @@ -4639,12 +4536,8 @@ pub enum StencilOperation { /// https://gpuweb.github.io/gpuweb/#dictdef-gpustencilfacestate). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct StencilFaceState { /// Comparison function that determines if the fail_op or pass_op is used on the stencil buffer. pub compare: CompareFunction, @@ -4693,12 +4586,8 @@ impl Default for StencilFaceState { /// https://gpuweb.github.io/gpuweb/#enumdef-gpucomparefunction). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum CompareFunction { /// Function never passes Never = 1, @@ -4791,12 +4680,8 @@ impl CompareFunction { /// [`Instance`]: VertexStepMode::Instance #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum VertexStepMode { /// Vertex data is advanced every vertex. #[default] @@ -4816,12 +4701,8 @@ pub enum VertexStepMode { /// [`vertex_attr_array`]: ../wgpu/macro.vertex_attr_array.html #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct VertexAttribute { /// Format of the input pub format: VertexFormat, @@ -4837,12 +4718,8 @@ pub struct VertexAttribute { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuvertexformat). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "lowercase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum VertexFormat { /// Two unsigned bytes (u8). `vec2` in shaders. Uint8x2 = 0, @@ -5000,8 +4877,7 @@ impl_bitflags!(BufferUsages); /// https://gpuweb.github.io/gpuweb/#dictdef-gpubufferdescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BufferDescriptor { /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. pub label: L, @@ -5035,8 +4911,7 @@ impl BufferDescriptor { /// Corresponds to [WebGPU `GPUCommandEncoderDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpucommandencoderdescriptor). #[repr(C)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct CommandEncoderDescriptor { /// Debug label for the command encoder. This will show up in graphics debuggers for easy identification. @@ -5061,8 +4936,7 @@ impl Default for CommandEncoderDescriptor> { /// Behavior of the presentation engine based on frame rate. #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum PresentMode { /// Chooses FifoRelaxed -> Fifo based on availability. /// @@ -5134,12 +5008,8 @@ pub enum PresentMode { /// compositing. #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "lowercase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum CompositeAlphaMode { /// Chooses either `Opaque` or `Inherit` automatically,depending on the /// `alpha_mode` that the current surface can support. @@ -5237,8 +5107,7 @@ impl Default for SurfaceCapabilities { /// [`Surface`]: ../wgpu/struct.Surface.html #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SurfaceConfiguration { /// The usage of the swap chain. The only supported usage is `RENDER_ATTACHMENT`. pub usage: TextureUsages, @@ -5364,12 +5233,8 @@ impl PresentationTimestamp { /// This is not to be used as a generic color type, only for specific wgpu interfaces. #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Color { /// Red component of the color pub r: f64, @@ -5427,26 +5292,16 @@ impl Color { /// https://gpuweb.github.io/gpuweb/#enumdef-gputexturedimension). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum TextureDimension { /// 1D texture - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "1d") - )] + #[cfg_attr(feature = "serde", serde(rename = "1d"))] D1, /// 2D texture - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "2d") - )] + #[cfg_attr(feature = "serde", serde(rename = "2d"))] D2, /// 3D texture - #[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename = "3d") - )] + #[cfg_attr(feature = "serde", serde(rename = "3d"))] D3, } @@ -5456,12 +5311,8 @@ pub enum TextureDimension { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuorigin2ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Origin2d { /// pub x: u32, @@ -5495,12 +5346,8 @@ impl std::fmt::Debug for Origin2d { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuorigin3ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Origin3d { /// X position of the origin pub x: u32, @@ -5541,19 +5388,15 @@ impl std::fmt::Debug for Origin3d { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuextent3ddict). #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Extent3d { /// Width of the extent pub width: u32, /// Height of the extent pub height: u32, /// The depth of the extent or the number of array layers - #[cfg_attr(feature = "deserialize", serde(default = "default_depth"))] + #[cfg_attr(feature = "serde", serde(default = "default_depth"))] pub depth_or_array_layers: u32, } @@ -5563,7 +5406,7 @@ impl std::fmt::Debug for Extent3d { } } -#[cfg(feature = "deserialize")] +#[cfg(feature = "serde")] fn default_depth() -> u32 { 1 } @@ -5744,8 +5587,7 @@ fn test_max_mips() { /// https://gpuweb.github.io/gpuweb/#dictdef-gputexturedescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TextureDescriptor { /// Debug label of the texture. This will show up in graphics debuggers for easy identification. pub label: L, @@ -5876,12 +5718,8 @@ impl TextureDescriptor { /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureaspect). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum TextureAspect { /// Depth, Stencil, and Color. #[default] @@ -5904,12 +5742,8 @@ pub enum TextureAspect { /// https://gpuweb.github.io/gpuweb/#enumdef-gpuaddressmode). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum AddressMode { /// Clamp the value to the edge of the texture /// @@ -5941,12 +5775,8 @@ pub enum AddressMode { /// https://gpuweb.github.io/gpuweb/#enumdef-gpufiltermode). #[repr(C)] #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum FilterMode { /// Nearest neighbor sampling. /// @@ -5961,8 +5791,7 @@ pub enum FilterMode { /// A range of push constant memory to pass to a shader stage. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PushConstantRange { /// Stage push constant range is visible from. Each stage can only be served by at most one range. /// One range can serve multiple stages however. @@ -5978,8 +5807,7 @@ pub struct PushConstantRange { /// https://gpuweb.github.io/gpuweb/#dictdef-gpucommandbufferdescriptor). #[repr(C)] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CommandBufferDescriptor { /// Debug label of this command buffer. pub label: L, @@ -6000,8 +5828,7 @@ impl CommandBufferDescriptor { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderbundleencoderdescriptor). #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RenderBundleDepthStencil { /// Format of the attachment. pub format: TextureFormat, @@ -6028,8 +5855,7 @@ pub struct RenderBundleDepthStencil { /// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderbundledescriptor). #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct RenderBundleDescriptor { /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification. pub label: L, @@ -6065,8 +5891,7 @@ impl Default for RenderBundleDescriptor> { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagedatalayout). #[repr(C)] #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImageDataLayout { /// Offset into the buffer that is the start of the texture. Must be a multiple of texture block size. /// For non-compressed textures, this is 1. @@ -6106,8 +5931,7 @@ pub struct ImageDataLayout { /// Corresponds to [WebGPU `GPUBufferBindingType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpubufferbindingtype). #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum BufferBindingType { /// A buffer for uniform values. /// @@ -6172,8 +5996,7 @@ pub enum BufferBindingType { /// Corresponds to [WebGPU `GPUTextureSampleType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gputexturesampletype). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum TextureSampleType { /// Sampling returns floats. /// @@ -6255,12 +6078,8 @@ impl Default for TextureSampleType { /// Corresponds to [WebGPU `GPUStorageTextureAccess`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpustoragetextureaccess). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum StorageTextureAccess { /// The texture can only be written in the shader and it: /// - may or may not be annotated with `write` (WGSL). @@ -6321,12 +6140,8 @@ pub enum StorageTextureAccess { /// https://gpuweb.github.io/gpuweb/#enumdef-gpusamplerbindingtype). #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum SamplerBindingType { /// The sampling result is produced based on more than a single color sample from a texture, /// e.g. when bilinear interpolation is enabled. @@ -6345,8 +6160,7 @@ pub enum SamplerBindingType { /// Corresponds to WebGPU's mutually exclusive fields within [`GPUBindGroupLayoutEntry`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry). #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum BindingType { /// A buffer binding. /// @@ -6362,7 +6176,7 @@ pub enum BindingType { /// for each dynamic binding in increasing order of binding number. /// /// [RPsbg]: ../wgpu/struct.RenderPass.html#method.set_bind_group - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] has_dynamic_offset: bool, /// The minimum size for a [`BufferBinding`] matching this entry, in bytes. @@ -6390,7 +6204,7 @@ pub enum BindingType { /// [minimum buffer binding size]: https://www.w3.org/TR/webgpu/#minimum-buffer-binding-size /// [`create_render_pipeline`]: ../wgpu/struct.Device.html#method.create_render_pipeline /// [`create_compute_pipeline`]: ../wgpu/struct.Device.html#method.create_compute_pipeline - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] min_binding_size: Option, }, /// A sampler that can be used to sample a texture. @@ -6495,8 +6309,7 @@ impl BindingType { /// Corresponds to [WebGPU `GPUBindGroupLayoutEntry`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BindGroupLayoutEntry { /// Binding index. Must match shader index and be unique inside a BindGroupLayout. A binding /// of index 1, would be described as `layout(set = 0, binding = 1) uniform` in shaders. @@ -6510,7 +6323,7 @@ pub struct BindGroupLayoutEntry { /// If this value is Some and `ty` is `BindingType::Texture`, [`Features::TEXTURE_BINDING_ARRAY`] must be supported. /// /// If this value is Some and `ty` is any other variant, bind group creation will fail. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub count: Option, } @@ -6520,8 +6333,7 @@ pub struct BindGroupLayoutEntry { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopybuffer). #[repr(C)] #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImageCopyBuffer { /// The buffer to be copied to/from. pub buffer: B, @@ -6535,8 +6347,7 @@ pub struct ImageCopyBuffer { /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexture). #[repr(C)] #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImageCopyTexture { /// The texture to be copied to/from. pub texture: T, @@ -6545,10 +6356,10 @@ pub struct ImageCopyTexture { /// The base texel of the texture in the selected `mip_level`. Together /// with the `copy_size` argument to copy functions, defines the /// sub-region of the texture to copy. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub origin: Origin3d, /// The copy aspect. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub aspect: TextureAspect, } @@ -6668,12 +6479,8 @@ unsafe impl Sync for ExternalImageSource {} /// Corresponds to [HTML Canvas `PredefinedColorSpace`]( /// https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace). #[derive(Copy, Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum PredefinedColorSpace { /// sRGB color space Srgb, @@ -6687,8 +6494,7 @@ pub enum PredefinedColorSpace { /// Corresponds to [WebGPU `GPUImageCopyTextureTagged`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuimagecopytexturetagged). #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImageCopyTextureTagged { /// The texture to be copied to/from. pub texture: T, @@ -6719,12 +6525,8 @@ impl ImageCopyTextureTagged { /// Subresource range within an image #[repr(C)] #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct ImageSubresourceRange { /// Aspect of the texture. Color textures must be [`TextureAspect::All`][TAA]. /// @@ -6824,8 +6626,7 @@ impl ImageSubresourceRange { /// Color variation to use when sampler addressing mode is [`AddressMode::ClampToBorder`] #[repr(C)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum SamplerBorderColor { /// [0, 0, 0, 0] TransparentBlack, @@ -6847,8 +6648,7 @@ pub enum SamplerBorderColor { /// Corresponds to [WebGPU `GPUQuerySetDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuquerysetdescriptor). #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct QuerySetDescriptor { /// Debug label for the query set. pub label: L, @@ -6875,8 +6675,7 @@ impl QuerySetDescriptor { /// Corresponds to [WebGPU `GPUQueryType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpuquerytype). #[derive(Copy, Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum QueryType { /// Query returns a single 64-bit number, serving as an occlusion boolean. Occlusion, @@ -7022,8 +6821,7 @@ impl DispatchIndirectArgs { /// Describes how shader bound checks should be performed. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ShaderBoundChecks { runtime_checks: bool, } From b118819116a602a72e096fc0a3b6ac099c16b518 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 18:31:46 +0100 Subject: [PATCH 14/18] wgpu-core explicit serde feature --- wgpu-core/Cargo.toml | 15 ++---- wgpu-core/src/binding_model.rs | 21 +++----- wgpu-core/src/command/bundle.rs | 9 ++-- wgpu-core/src/command/compute.rs | 27 ++++------- wgpu-core/src/command/draw.rs | 20 ++------ wgpu-core/src/command/mod.rs | 10 +--- wgpu-core/src/command/render.rs | 83 ++++++++------------------------ wgpu-core/src/device/mod.rs | 10 ++-- wgpu-core/src/device/trace.rs | 6 +-- wgpu-core/src/id.rs | 13 ++--- wgpu-core/src/lib.rs | 3 -- wgpu-core/src/pipeline.rs | 34 +++++-------- wgpu-core/src/resource.rs | 7 ++- wgpu/Cargo.toml | 12 ++--- 14 files changed, 75 insertions(+), 195 deletions(-) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 2539c4ff20..7aa4349b1a 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -48,22 +48,13 @@ renderdoc = ["hal/renderdoc"] strict_asserts = ["wgt/strict_asserts"] ## Enables serde functionality on common wgpu types. -serde = ["serialize", "deserialize", "serial-pass", "wgt/serde"] - -## Enables serialize functionality on common wgpu types. -serialize = ["dep:serde", "wgt/serde", "arrayvec/serde"] - -## Enables deserialize functionality on common wgpu types. -deserialize = ["dep:serde", "wgt/serde", "arrayvec/serde"] +serde = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enable API tracing. -trace = ["ron", "serialize", "naga/serialize"] +trace = ["ron", "serde", "naga/serialize"] ## Enable API replaying -replay = ["deserialize", "naga/deserialize"] - -## Enable serializable compute/render passes, and bundle encoders. -serial-pass = ["dep:serde", "wgt/serde", "arrayvec/serde"] +replay = ["serde", "naga/deserialize"] ## Enable `ShaderModuleSource::Wgsl` wgsl = ["naga/wgsl-in"] diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 6c7ebf481f..65c4044273 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -21,9 +21,8 @@ use crate::{ use arrayvec::ArrayVec; -#[cfg(feature = "deserialize")] +#[cfg(feature = "serde")] use serde::Deserialize; -#[cfg(feature = "serialize")] use serde::Serialize; use std::{borrow::Cow, ops::Range, sync::Arc}; @@ -406,8 +405,7 @@ impl BindingTypeMaxCountValidator { /// Bindable resource and the slot to bind it to. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BindGroupEntry<'a> { /// Slot for which binding provides resource. Corresponds to an entry of the same /// binding index in the [`BindGroupLayoutDescriptor`]. @@ -418,8 +416,7 @@ pub struct BindGroupEntry<'a> { /// Describes a group of bindings and the resources to be bound. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BindGroupDescriptor<'a> { /// Debug label of the bind group. /// @@ -433,8 +430,7 @@ pub struct BindGroupDescriptor<'a> { /// Describes a [`BindGroupLayout`]. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BindGroupLayoutDescriptor<'a> { /// Debug label of the bind group layout. /// @@ -582,8 +578,7 @@ pub enum PushConstantUploadError { /// /// A `PipelineLayoutDescriptor` can be used to create a pipeline layout. #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PipelineLayoutDescriptor<'a> { /// Debug label of the pipeine layout. /// @@ -734,8 +729,7 @@ impl Resource for PipelineLayout { #[repr(C)] #[derive(Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize))] -#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BufferBinding { pub buffer_id: BufferId, pub offset: wgt::BufferAddress, @@ -745,8 +739,7 @@ pub struct BufferBinding { // Note: Duplicated in `wgpu-rs` as `BindingResource` // They're different enough that it doesn't make sense to share a common type #[derive(Debug, Clone)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum BindingResource<'a> { Buffer(BufferBinding), BufferArray(Cow<'a, [BufferBinding]>), diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 2d9319ad2f..49def22d45 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -197,8 +197,7 @@ fn validate_indexed_draw( /// Describes a [`RenderBundleEncoder`]. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RenderBundleEncoderDescriptor<'a> { /// Debug label of the render bundle encoder. /// @@ -226,7 +225,7 @@ pub struct RenderBundleEncoderDescriptor<'a> { } #[derive(Debug)] -#[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct RenderBundleEncoder { base: BasePass, parent_id: id::DeviceId, @@ -235,9 +234,9 @@ pub struct RenderBundleEncoder { pub(crate) is_stencil_read_only: bool, // Resource binding dedupe state. - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_bind_groups: BindGroupStateChange, - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_pipeline: StateChange, } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index f6ff0d1c25..f9d5c74cd2 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -29,9 +29,9 @@ use crate::{ }; use hal::CommandEncoder as _; -#[cfg(any(feature = "deserialize", feature = "serial-pass"))] +#[cfg(feature = "serde")] use serde::Deserialize; -#[cfg(any(feature = "serialize", feature = "serial-pass"))] +#[cfg(feature = "serde")] use serde::Serialize; use thiserror::Error; @@ -40,14 +40,8 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr( - any(feature = "serialize", feature = "serial-pass"), - derive(serde::Serialize) -)] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum ComputeCommand { SetBindGroup { index: u32, @@ -98,16 +92,16 @@ pub enum ComputeCommand { EndPipelineStatisticsQuery, } -#[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ComputePass { base: BasePass, parent_id: id::CommandEncoderId, timestamp_writes: Option, // Resource binding dedupe state. - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_bind_groups: BindGroupStateChange, - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_pipeline: StateChange, } @@ -151,11 +145,8 @@ impl fmt::Debug for ComputePass { /// Describes the writing of timestamp values in a compute pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize))] pub struct ComputePassTimestampWrites { /// The query set to write the timestamps to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index cb1cec3c9a..d9bbb66330 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -126,14 +126,8 @@ impl crate::error::PrettyError for RenderCommandError { } #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr( - any(feature = "serialize", feature = "serial-pass"), - derive(serde::Serialize) -)] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub struct Rect { pub x: T, pub y: T, @@ -143,14 +137,8 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr( - any(feature = "serialize", feature = "serial-pass"), - derive(serde::Serialize) -)] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum RenderCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 171c76512e..3e42f9d4bb 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -338,14 +338,8 @@ pub struct BasePassRef<'a, C> { /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] #[derive(Debug)] -#[cfg_attr( - any(feature = "serialize", feature = "serial-pass"), - derive(serde::Serialize) -)] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(serde::Deserialize) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub struct BasePass { pub label: Option, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index aafe620a4d..c7a4b5817d 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -40,9 +40,9 @@ use wgt::{ TextureViewDimension, VertexStepMode, }; -#[cfg(any(feature = "deserialize", feature = "serial-pass"))] +#[cfg(feature = "serde")] use serde::Deserialize; -#[cfg(any(feature = "serialize", feature = "serial-pass"))] +#[cfg(feature = "serde")] use serde::Serialize; use std::sync::Arc; @@ -56,19 +56,8 @@ use super::{ /// Operation to perform to the output attachment at the start of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] -#[cfg_attr( - any( - feature = "serialize", - feature = "deserialize", - feature = "serial-pass" - ), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum LoadOp { /// Clear the output attachment with the clear color. Clearing is faster than loading. Clear = 0, @@ -79,19 +68,8 @@ pub enum LoadOp { /// Operation to perform to the output attachment at the end of a renderpass. #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] -#[cfg_attr( - any( - feature = "serialize", - feature = "deserialize", - feature = "serial-pass" - ), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum StoreOp { /// Discards the content of the render target. /// @@ -104,11 +82,8 @@ pub enum StoreOp { /// Describes an individual channel within a render pass, such as color, depth, or stencil. #[repr(C)] #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize))] pub struct PassChannel { /// Operation to perform to the output attachment at the start of a /// renderpass. @@ -145,11 +120,8 @@ impl PassChannel { /// Describes a color attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize))] pub struct RenderPassColorAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -162,11 +134,8 @@ pub struct RenderPassColorAttachment { /// Describes a depth/stencil attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize))] pub struct RenderPassDepthStencilAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -217,19 +186,8 @@ impl RenderPassDepthStencilAttachment { /// Location to write a timestamp to (beginning or end of the pass). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] -#[cfg_attr( - any( - feature = "serialize", - feature = "deserialize", - feature = "serial-pass" - ), - serde(rename_all = "kebab-case") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum RenderPassTimestampLocation { Beginning = 0, End = 1, @@ -238,11 +196,8 @@ pub enum RenderPassTimestampLocation { /// Describes the writing of timestamp values in a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(any(feature = "serialize", feature = "serial-pass"), derive(Serialize))] -#[cfg_attr( - any(feature = "deserialize", feature = "serial-pass"), - derive(Deserialize) -)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize))] pub struct RenderPassTimestampWrites { /// The query set to write the timestamp to. pub query_set: id::QuerySetId, @@ -266,7 +221,7 @@ pub struct RenderPassDescriptor<'a> { pub occlusion_query_set: Option, } -#[cfg_attr(feature = "serial-pass", derive(Deserialize, Serialize))] +#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] pub struct RenderPass { base: BasePass, parent_id: id::CommandEncoderId, @@ -276,9 +231,9 @@ pub struct RenderPass { occlusion_query_set_id: Option, // Resource binding dedupe state. - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_bind_groups: BindGroupStateChange, - #[cfg_attr(feature = "serial-pass", serde(skip))] + #[cfg_attr(feature = "serde", serde(skip))] current_pipeline: StateChange, } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 419e08915c..2d53026162 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -42,15 +42,14 @@ pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum HostMap { Read, Write, } #[derive(Clone, Debug, Hash, PartialEq)] -#[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct AttachmentData { pub colors: ArrayVec, { hal::MAX_COLOR_ATTACHMENTS }>, pub resolves: ArrayVec, @@ -74,7 +73,7 @@ pub enum RenderPassCompatibilityCheckType { } #[derive(Clone, Debug, Hash, PartialEq)] -#[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub(crate) struct RenderPassContext { pub attachments: AttachmentData, pub sample_count: u32, @@ -457,8 +456,7 @@ pub struct MissingFeatures(pub wgt::Features); pub struct MissingDownlevelFlags(pub wgt::DownlevelFlags); #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImplicitPipelineContext { pub root_id: id::PipelineLayoutId, pub group_ids: ArrayVec, diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index e1f7e29446..0802b610d8 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -33,8 +33,7 @@ pub(crate) fn new_render_bundle_encoder_descriptor<'a>( #[allow(clippy::large_enum_variant)] #[derive(Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Action<'a> { Init { desc: crate::device::DeviceDescriptor<'a>, @@ -126,8 +125,7 @@ pub enum Action<'a> { } #[derive(Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Command { CopyBufferToBuffer { src: id::BufferId, diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index ddaeac9620..f55a077f6a 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -56,25 +56,18 @@ type Dummy = hal::api::Empty; serde(from = "SerialId") )] #[cfg_attr( - all( - any(feature = "serialize", feature = "serial-pass"), - not(feature = "trace") - ), + all(feature = "serde", not(feature = "trace")), derive(serde::Serialize) )] #[cfg_attr( - all( - any(feature = "deserialize", feature = "serial-pass"), - not(feature = "replay") - ), + all(feature = "serde", not(feature = "replay")), derive(serde::Deserialize) )] pub struct Id(NonZeroId, PhantomData); // This type represents Id in a more readable (and editable) way. #[allow(dead_code)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] enum SerialId { // The only variant forces RON to not ignore "Id" Id(Index, Epoch, Backend), diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index df775e256a..4c167dafe9 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -14,11 +14,8 @@ //! - **`strict_asserts`** --- Apply run-time checks, even in release builds. These are in addition //! to the validation carried out at public APIs in all builds. //! - **`serde`** --- Enables serde functionality on common wgpu types. -//! - **`serialize`** ---Enables serialize functionality on common wgpu types. -//! - **`deserialize`** --- Enables deserialize functionality on common wgpu types. //! - **`trace`** --- Enable API tracing. //! - **`replay`** --- Enable API replaying -//! - **`serial-pass`** --- Enable serializable compute/render passes, and bundle encoders. //! - **`wgsl`** --- Enable `ShaderModuleSource::Wgsl` //! - **`fragile-send-sync-non-atomic-wasm`** --- Implement `Send` and `Sync` on Wasm, but only if //! atomics are not enabled. diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 6cd9267135..b6c3bf5bfe 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -38,11 +38,10 @@ pub enum ShaderModuleSource<'a> { } #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ShaderModuleDescriptor<'a> { pub label: Label<'a>, - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub shader_bound_checks: wgt::ShaderBoundChecks, } @@ -208,8 +207,7 @@ impl CreateShaderModuleError { /// Describes a programmable pipeline stage. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ProgrammableStageDescriptor<'a> { /// The compiled shader module for this stage. pub module: ShaderModuleId, @@ -236,8 +234,7 @@ pub enum ImplicitLayoutError { /// Describes a compute pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ComputePipelineDescriptor<'a> { pub label: Label<'a>, /// The layout of bind groups for this pipeline. @@ -311,12 +308,8 @@ impl ComputePipeline { /// Describes how the vertex buffer is interpreted. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] -#[cfg_attr( - any(feature = "serialize", feature = "deserialize"), - serde(rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct VertexBufferLayout<'a> { /// The stride, in bytes, between elements of this buffer. pub array_stride: wgt::BufferAddress, @@ -328,8 +321,7 @@ pub struct VertexBufferLayout<'a> { /// Describes the vertex process in a render pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct VertexState<'a> { /// The compiled vertex stage and its entry point. pub stage: ProgrammableStageDescriptor<'a>, @@ -339,8 +331,7 @@ pub struct VertexState<'a> { /// Describes fragment processing in a render pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FragmentState<'a> { /// The compiled fragment stage and its entry point. pub stage: ProgrammableStageDescriptor<'a>, @@ -350,8 +341,7 @@ pub struct FragmentState<'a> { /// Describes a render (graphics) pipeline. #[derive(Clone, Debug)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RenderPipelineDescriptor<'a> { pub label: Label<'a>, /// The layout of bind groups for this pipeline. @@ -359,13 +349,13 @@ pub struct RenderPipelineDescriptor<'a> { /// The vertex processing state for this pipeline. pub vertex: VertexState<'a>, /// The properties of the pipeline at the primitive assembly and rasterization level. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub primitive: wgt::PrimitiveState, /// The effect of draw calls on the depth and stencil aspects of the output target, if any. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub depth_stencil: Option, /// The multi-sampling properties of the pipeline. - #[cfg_attr(feature = "deserialize", serde(default))] + #[cfg_attr(feature = "serde", serde(default))] pub multisample: wgt::MultisampleState, /// The fragment processing state for this pipeline. pub fragment: Option>, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index f1fd6cc240..85384939f6 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1186,8 +1186,8 @@ impl Borrow for Texture { /// Describes a [`TextureView`]. #[derive(Clone, Debug, Default, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize), serde(default))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(default))] pub struct TextureViewDescriptor<'a> { /// Debug label of the texture view. /// @@ -1343,8 +1343,7 @@ impl Resource for TextureView { /// Describes a [`Sampler`] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SamplerDescriptor<'a> { /// Debug label of the sampler. /// diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 024267f85c..ec402fd734 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -79,21 +79,15 @@ strict_asserts = ["wgc?/strict_asserts", "wgt/strict_asserts"] api_log_info = ["wgc/api_log_info"] ## Enables serde functionality on common wgpu types. -serde = ["serialize", "deserialize", "wgc/serde"] - -## Enables serialize functionality on common wgpu types. -serialize = ["dep:serde", "wgc/serialize"] - -## Enables deserialize functionality on common wgpu types. -deserialize = ["dep:serde", "wgc/deserialize"] +serde = ["dep:serde", "wgc/serde"] ## Allow writing of trace capture files. ## See [`Adapter::request_device`]. -trace = ["serialize", "wgc/trace"] +trace = ["serde", "wgc/trace"] ## Allow deserializing of trace capture files that were written with the `trace` feature. ## To replay a trace file use the [wgpu player](https://github.com/gfx-rs/wgpu/tree/trunk/player). -replay = ["deserialize", "wgc/replay"] +replay = ["serde", "wgc/replay"] #! ### Other # -------------------------------------------------------------------- From 4357e7f61c52e0f619360cd861e5b09b607ef916 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 18:38:43 +0100 Subject: [PATCH 15/18] wgpu explicit serde feature --- wgpu/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index f7035e8675..cd3df23f27 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -38,8 +38,6 @@ //! to the validation carried out at public APIs in all builds. //! - **`api_log_info`** --- Log all API entry points at info instead of trace level. //! - **`serde`** --- Enables serde functionality on common wgpu types. -//! - **`serialize`** ---Enables serialize functionality on common wgpu types. -//! - **`deserialize`** --- Enables deserialize functionality on common wgpu types. //! - **`trace`** --- Allow writing of trace capture files. See [`Adapter::request_device`]. //! - **`replay`** --- Allow deserializing of trace capture files that were written with the `trace` //! feature. To replay a trace file use the [wgpu @@ -1118,8 +1116,7 @@ static_assertions::assert_impl_all!(BufferBinding<'_>: Send, Sync); /// Corresponds to [WebGPU `GPULoadOp`](https://gpuweb.github.io/gpuweb/#enumdef-gpuloadop), /// plus the corresponding clearValue. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum LoadOp { /// Loads the specified value for this attachment into the render pass. /// @@ -1146,8 +1143,7 @@ impl Default for LoadOp { /// /// Corresponds to [WebGPU `GPUStoreOp`](https://gpuweb.github.io/gpuweb/#enumdef-gpustoreop). #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum StoreOp { /// Stores the resulting value of the render pass for this attachment. #[default] @@ -1169,8 +1165,7 @@ pub enum StoreOp { /// This type is unique to the Rust API of `wgpu`. In the WebGPU specification, /// separate `loadOp` and `storeOp` fields are used instead. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Operations { /// How data should be read through this attachment. pub load: LoadOp, From 8ce9c83315812f726602ce8b7a176b30a21a2d9e Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 18:42:35 +0100 Subject: [PATCH 16/18] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eebcccc35..b3842124fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,8 +67,8 @@ Bottom level categories: - `tan` - `tanh` - Eager release of GPU resources comes from device.trackers. By @bradwerth in [#5075](https://github.com/gfx-rs/wgpu/pull/5075) -- `wgpu`, `wgpu-core` and `wgpu-types` now have `serialize` and `deserialize` features. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) - `wgpu-types`'s `trace` and `replay` features have been replaced by `serialize` and `deserialize` respectively. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) +- `wgpu-core`'s `serial-pass` feature has been removed. Use `serde` instead. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) ### Bug Fixes From f748c43d0aed69aad50190b2dfaea8f8d74a3ce3 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 18:52:56 +0100 Subject: [PATCH 17/18] Fix compilation with default features --- wgpu-core/src/binding_model.rs | 1 + wgpu-types/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 65c4044273..fe4f977d03 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -23,6 +23,7 @@ use arrayvec::ArrayVec; #[cfg(feature = "serde")] use serde::Deserialize; +#[cfg(feature = "serde")] use serde::Serialize; use std::{borrow::Cow, ops::Range, sync::Arc}; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c57823e580..7c39c32e03 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -11,6 +11,7 @@ #[cfg(any(feature = "serde", test))] use serde::Deserialize; +#[cfg(any(feature = "serde", test))] use serde::Serialize; use std::hash::{Hash, Hasher}; use std::path::PathBuf; From 4558e5cc0efd73c866b00032f1145451b1db1199 Mon Sep 17 00:00:00 2001 From: KirmesBude Date: Sun, 28 Jan 2024 20:23:58 +0100 Subject: [PATCH 18/18] Address review comments --- CHANGELOG.md | 2 +- wgpu-core/Cargo.toml | 2 +- wgpu-core/src/command/compute.rs | 6 ++---- wgpu-core/src/command/draw.rs | 6 ++---- wgpu-core/src/command/mod.rs | 3 +-- wgpu-core/src/command/render.rs | 12 ++++-------- wgpu-core/src/lib.rs | 2 +- wgpu/Cargo.toml | 2 +- wgpu/src/lib.rs | 2 +- 9 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3842124fc..0cd61fdea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,7 @@ Bottom level categories: - `tan` - `tanh` - Eager release of GPU resources comes from device.trackers. By @bradwerth in [#5075](https://github.com/gfx-rs/wgpu/pull/5075) -- `wgpu-types`'s `trace` and `replay` features have been replaced by `serialize` and `deserialize` respectively. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) +- `wgpu-types`'s `trace` and `replay` features have been replaced by the `serde` feature. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) - `wgpu-core`'s `serial-pass` feature has been removed. Use `serde` instead. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149) diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 7aa4349b1a..d66f7b7d3a 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -47,7 +47,7 @@ renderdoc = ["hal/renderdoc"] ## to the validation carried out at public APIs in all builds. strict_asserts = ["wgt/strict_asserts"] -## Enables serde functionality on common wgpu types. +## Enables serialization via `serde` on common wgpu types. serde = ["dep:serde", "wgt/serde", "arrayvec/serde"] ## Enable API tracing. diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index f9d5c74cd2..cd7949b3da 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -40,8 +40,7 @@ use std::{fmt, mem, str}; #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] -#[cfg_attr(feature = "serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ComputeCommand { SetBindGroup { index: u32, @@ -145,8 +144,7 @@ impl fmt::Debug for ComputePass { /// Describes the writing of timestamp values in a compute pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ComputePassTimestampWrites { /// The query set to write the timestamps to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index d9bbb66330..e03a78ee93 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -126,8 +126,7 @@ impl crate::error::PrettyError for RenderCommandError { } #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] -#[cfg_attr(feature = "serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Rect { pub x: T, pub y: T, @@ -137,8 +136,7 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] -#[cfg_attr(feature = "serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum RenderCommand { SetBindGroup { index: u32, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 3e42f9d4bb..40ac0628f0 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -338,8 +338,7 @@ pub struct BasePassRef<'a, C> { /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] #[derive(Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] -#[cfg_attr(feature = "serde", derive(serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BasePass { pub label: Option, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index c7a4b5817d..fedc6f7c89 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -82,8 +82,7 @@ pub enum StoreOp { /// Describes an individual channel within a render pass, such as color, depth, or stencil. #[repr(C)] #[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PassChannel { /// Operation to perform to the output attachment at the start of a /// renderpass. @@ -120,8 +119,7 @@ impl PassChannel { /// Describes a color attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct RenderPassColorAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -134,8 +132,7 @@ pub struct RenderPassColorAttachment { /// Describes a depth/stencil attachment to a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct RenderPassDepthStencilAttachment { /// The view to use as an attachment. pub view: id::TextureViewId, @@ -196,8 +193,7 @@ pub enum RenderPassTimestampLocation { /// Describes the writing of timestamp values in a render pass. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize))] -#[cfg_attr(feature = "serde", derive(Deserialize))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct RenderPassTimestampWrites { /// The query set to write the timestamp to. pub query_set: id::QuerySetId, diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 4c167dafe9..5413be6b63 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -13,7 +13,7 @@ //! [https://renderdoc.org/](https://renderdoc.org/) //! - **`strict_asserts`** --- Apply run-time checks, even in release builds. These are in addition //! to the validation carried out at public APIs in all builds. -//! - **`serde`** --- Enables serde functionality on common wgpu types. +//! - **`serde`** --- Enables serialization via `serde` on common wgpu types. //! - **`trace`** --- Enable API tracing. //! - **`replay`** --- Enable API replaying //! - **`wgsl`** --- Enable `ShaderModuleSource::Wgsl` diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ec402fd734..a0c1926713 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -78,7 +78,7 @@ strict_asserts = ["wgc?/strict_asserts", "wgt/strict_asserts"] ## Log all API entry points at info instead of trace level. api_log_info = ["wgc/api_log_info"] -## Enables serde functionality on common wgpu types. +## Enables serialization via `serde` on common wgpu types. serde = ["dep:serde", "wgc/serde"] ## Allow writing of trace capture files. diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index cd3df23f27..b963fa695b 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -37,7 +37,7 @@ //! - **`strict_asserts`** --- Apply run-time checks, even in release builds. These are in addition //! to the validation carried out at public APIs in all builds. //! - **`api_log_info`** --- Log all API entry points at info instead of trace level. -//! - **`serde`** --- Enables serde functionality on common wgpu types. +//! - **`serde`** --- Enables serialization via `serde` on common wgpu types. //! - **`trace`** --- Allow writing of trace capture files. See [`Adapter::request_device`]. //! - **`replay`** --- Allow deserializing of trace capture files that were written with the `trace` //! feature. To replay a trace file use the [wgpu