From f308f064435e4e8889e1da3264c04f076f1ac8df Mon Sep 17 00:00:00 2001 From: Sam <16504129+sagudev@users.noreply.github.com> Date: Mon, 15 Jun 2026 15:08:13 +0200 Subject: [PATCH] [core] Make `ComputePassDescriptor` and `RenderPassDescriptor` ser/de (#9666) Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- deno_webgpu/command_encoder.rs | 4 ++-- wgpu-core/src/command/compute.rs | 1 + wgpu-core/src/command/render.rs | 8 +++++--- wgpu/src/backend/wgpu_core.rs | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 30f80f004..3bb6afdfa 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -131,8 +131,8 @@ impl GPUCommandEncoder { let wgpu_descriptor = wgpu_core::command::RenderPassDescriptor { label: crate::transform_label(descriptor.label.clone()), color_attachments, - depth_stencil_attachment: depth_stencil_attachment.as_ref(), - timestamp_writes: timestamp_writes.as_ref(), + depth_stencil_attachment, + timestamp_writes, occlusion_query_set: descriptor .occlusion_query_set .map(|query_set| query_set.id), diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 761aaca5e..476c0002e 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -107,6 +107,7 @@ impl fmt::Debug for ComputePass { } #[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ComputePassDescriptor<'a, PTW = PassTimestampWrites> { pub label: Label<'a>, /// Defines where and when timestamp values will be written for this pass. diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index fbbf0bd85..23afb89f5 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -255,14 +255,15 @@ pub struct ResolvedRenderPassDepthStencilAttachment { /// Describes the attachments of a render pass. #[derive(Clone, Debug, Default, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RenderPassDescriptor<'a> { pub label: Label<'a>, /// The color attachments of the render pass. pub color_attachments: Cow<'a, [Option]>, /// The depth and stencil attachment of the render pass, if any. - pub depth_stencil_attachment: Option<&'a RenderPassDepthStencilAttachment>, + pub depth_stencil_attachment: Option>, /// Defines where and when timestamp values will be written for this pass. - pub timestamp_writes: Option<&'a PassTimestampWrites>, + pub timestamp_writes: Option, /// Defines where the occlusion query results will be stored for this pass. pub occlusion_query_set: Option, /// The multiview array layers that will be used @@ -1868,7 +1869,7 @@ impl Global { arc_desc.depth_stencil_attachment = // https://gpuweb.github.io/gpuweb/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage - if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment { + if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment.as_ref() { let view = texture_views.get(depth_stencil_attachment.view).get()?; view.same_device(device)?; @@ -1921,6 +1922,7 @@ impl Global { arc_desc.timestamp_writes = desc .timestamp_writes + .as_ref() .map(|tw| { Global::validate_pass_timestamp_writes::( device, diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 738c847b5..29f1cf825 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2637,9 +2637,9 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { self.id, &wgc::command::RenderPassDescriptor { label: desc.label.map(Borrowed), - timestamp_writes: timestamp_writes.as_ref(), + timestamp_writes, color_attachments: Borrowed(&colors), - depth_stencil_attachment: depth_stencil.as_ref(), + depth_stencil_attachment: depth_stencil, occlusion_query_set: desc.occlusion_query_set.map(|qs| qs.inner.as_core().id), multiview_mask: desc.multiview_mask, },