Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/serde feature #5149

Merged
merged 18 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ 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", "arrayvec/serde"]

## deserialize
deserialize = ["dep:serde", "wgt/deserialize", "arrayvec/serde"]
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

## Enable API tracing.
trace = ["ron", "serde", "wgt/trace", "arrayvec/serde", "naga/serialize"]
trace = ["ron", "serialize", "naga/serialize"]

## Enable API replaying
replay = ["serde", "wgt/replay", "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"]
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

## Enable `ShaderModuleSource::Wgsl`
wgsl = ["naga/wgsl-in"]
Expand Down
28 changes: 14 additions & 14 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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`].
Expand All @@ -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.
///
Expand All @@ -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.
///
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -734,8 +734,8 @@ impl<A: HalApi> Resource<PipelineLayoutId> for PipelineLayout<A> {

#[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,
Expand All @@ -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]>),
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
18 changes: 6 additions & 12 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,14 +40,8 @@ use std::{fmt, mem, str};

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(
any(feature = "serial-pass", feature = "trace"),
derive(serde::Serialize)
)]
#[cfg_attr(
any(feature = "serial-pass", feature = "replay"),
derive(serde::Deserialize)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
pub enum ComputeCommand {
SetBindGroup {
index: u32,
Expand Down Expand Up @@ -151,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(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,
Expand Down
20 changes: 4 additions & 16 deletions wgpu-core/src/command/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,8 @@ impl crate::error::PrettyError for RenderCommandError {
}

#[derive(Clone, Copy, Debug, Default)]
#[cfg_attr(
any(feature = "serial-pass", feature = "trace"),
derive(serde::Serialize)
)]
#[cfg_attr(
any(feature = "serial-pass", feature = "replay"),
derive(serde::Deserialize)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct Rect<T> {
pub x: T,
pub y: T,
Expand All @@ -143,14 +137,8 @@ pub struct Rect<T> {

#[doc(hidden)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(
any(feature = "serial-pass", feature = "trace"),
derive(serde::Serialize)
)]
#[cfg_attr(
any(feature = "serial-pass", feature = "replay"),
derive(serde::Deserialize)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub enum RenderCommand {
SetBindGroup {
index: u32,
Expand Down
10 changes: 2 additions & 8 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,8 @@ pub struct BasePassRef<'a, C> {
/// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker
#[doc(hidden)]
#[derive(Debug)]
#[cfg_attr(
any(feature = "serial-pass", feature = "trace"),
derive(serde::Serialize)
)]
#[cfg_attr(
any(feature = "serial-pass", feature = "replay"),
derive(serde::Deserialize)
)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct BasePass<C> {
pub label: Option<String>,

Expand Down
47 changes: 28 additions & 19 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,9 +56,12 @@ 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,
Expand All @@ -69,9 +72,12 @@ 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.
///
Expand All @@ -84,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(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<V> {
/// Operation to perform to the output attachment at the start of a
/// renderpass.
Expand Down Expand Up @@ -122,8 +128,8 @@ impl<V> PassChannel<V> {
/// 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,
Expand All @@ -136,8 +142,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,
Expand Down Expand Up @@ -188,9 +194,12 @@ 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,
Expand All @@ -199,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(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,
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor<Label<'a>>;

#[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,
Expand Down Expand Up @@ -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<id::BindGroupLayoutId, { hal::MAX_BIND_GROUPS }>,
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/device/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
Expand Down
Loading