diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 486246de2..4de6ecf16 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -85,6 +85,7 @@ use alloc::{ vec::Vec, }; use core::{ + convert::Infallible, num::{NonZeroU32, NonZeroU64}, ops::Range, }; @@ -153,7 +154,7 @@ pub struct RenderBundleEncoderDescriptor<'a> { #[derive(Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct RenderBundleEncoder { - base: BasePass, + base: BasePass, parent_id: id::DeviceId, pub(crate) context: RenderPassContext, pub(crate) is_depth_read_only: bool, @@ -170,7 +171,7 @@ impl RenderBundleEncoder { pub fn new( desc: &RenderBundleEncoderDescriptor, parent_id: id::DeviceId, - base: Option>, + base: Option>, ) -> Result { let (is_depth_read_only, is_stencil_read_only) = match desc.depth_stencil { Some(ds) => { @@ -248,7 +249,7 @@ impl RenderBundleEncoder { } #[cfg(feature = "trace")] - pub(crate) fn to_base_pass(&self) -> BasePass { + pub(crate) fn to_base_pass(&self) -> BasePass { self.base.clone() } @@ -466,6 +467,7 @@ impl RenderBundleEncoder { let render_bundle = RenderBundle { base: BasePass { label: desc.label.as_deref().map(str::to_owned), + error: None, commands, dynamic_offsets: flat_dynamic_offsets, string_data: self.base.string_data, @@ -863,7 +865,7 @@ pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor>; pub struct RenderBundle { // Normalized command stream. It can be executed verbatim, // without re-binding anything on the pipeline change. - base: BasePass, + base: BasePass, pub(super) is_depth_read_only: bool, pub(super) is_stencil_read_only: bool, pub(crate) device: Arc, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 80350504b..cc2864ca5 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -40,7 +40,7 @@ pub struct ComputePass { /// /// If this is `None`, the pass is in the 'ended' state and can no longer be used. /// Any attempt to record more commands will result in a validation error. - base: Option>, + base: Option>, /// Parent command buffer that this pass records commands into. /// @@ -80,7 +80,7 @@ impl ComputePass { fn base_mut<'a>( &'a mut self, scope: PassErrorScope, - ) -> Result<&'a mut BasePass, ComputePassError> { + ) -> Result<&'a mut BasePass, ComputePassError> { self.base .as_mut() .ok_or(ComputePassErrorInner::PassEnded) @@ -330,7 +330,7 @@ impl Global { pub fn compute_pass_end_with_unresolved_commands( &self, encoder_id: id::CommandEncoderId, - base: BasePass, + base: BasePass, timestamp_writes: Option<&PassTimestampWrites>, ) { #[cfg(feature = "trace")] @@ -346,6 +346,7 @@ impl Global { list.push(crate::device::trace::Command::RunComputePass { base: BasePass { label: base.label.clone(), + error: None, commands: base.commands.clone(), dynamic_offsets: base.dynamic_offsets.clone(), string_data: base.string_data.clone(), @@ -358,6 +359,7 @@ impl Global { let BasePass { label, + error: _, commands, dynamic_offsets, string_data, @@ -377,6 +379,7 @@ impl Global { compute_pass.base = Some(BasePass { label, + error: None, commands: super::ComputeCommand::resolve_compute_command_ids(&self.hub, &commands) .unwrap(), dynamic_offsets, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 5c950220c..b38b2bf18 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -817,9 +817,19 @@ crate::impl_storage_item!(CommandBuffer); #[doc(hidden)] #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct BasePass { +pub struct BasePass { pub label: Option, + /// If the pass is invalid, contains the error that caused the invalidation. + /// + /// If the pass is valid, this is `None`. + /// + /// Passes are serialized into traces. but we don't support doing so for + /// passes containing errors. These serde attributes allow `E` to be + /// `Infallible`. + #[cfg_attr(feature = "serde", serde(skip, default = "Option::default"))] + pub error: Option, + /// The stream of commands. pub commands: Vec, @@ -842,10 +852,11 @@ pub struct BasePass { pub push_constant_data: Vec, } -impl BasePass { +impl BasePass { fn new(label: &Label) -> Self { Self { label: label.as_deref().map(str::to_owned), + error: None, commands: Vec::new(), dynamic_offsets: Vec::new(), string_data: Vec::new(), diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 89032fdf4..8013ecc7e 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -249,7 +249,7 @@ pub struct RenderPass { /// /// If this is `None`, the pass is in the 'ended' state and can no longer be used. /// Any attempt to record more commands will result in a validation error. - base: Option>, + base: Option>, /// Parent command buffer that this pass records commands into. /// @@ -299,7 +299,7 @@ impl RenderPass { fn base_mut<'a>( &'a mut self, scope: PassErrorScope, - ) -> Result<&'a mut BasePass, RenderPassError> { + ) -> Result<&'a mut BasePass, RenderPassError> { self.base .as_mut() .ok_or(RenderPassErrorInner::PassEnded) @@ -1623,7 +1623,7 @@ impl Global { pub fn render_pass_end_with_unresolved_commands( &self, encoder_id: id::CommandEncoderId, - base: BasePass, + base: BasePass, color_attachments: &[Option], depth_stencil_attachment: Option<&RenderPassDepthStencilAttachment>, timestamp_writes: Option<&PassTimestampWrites>, @@ -1642,6 +1642,7 @@ impl Global { list.push(crate::device::trace::Command::RunRenderPass { base: BasePass { label: base.label.clone(), + error: None, commands: base.commands.clone(), dynamic_offsets: base.dynamic_offsets.clone(), string_data: base.string_data.clone(), @@ -1657,6 +1658,7 @@ impl Global { let BasePass { label, + error, commands, dynamic_offsets, string_data, @@ -1679,6 +1681,7 @@ impl Global { render_pass.base = Some(BasePass { label, + error, commands: super::RenderCommand::resolve_render_command_ids(&self.hub, &commands) .unwrap(), dynamic_offsets, diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 9291ba9f4..9d031bef8 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -1,5 +1,5 @@ use alloc::{string::String, vec::Vec}; -use core::ops::Range; +use core::{convert::Infallible, ops::Range}; #[cfg(feature = "trace")] use {alloc::borrow::Cow, std::io::Write as _}; @@ -109,7 +109,7 @@ pub enum Action<'a> { CreateRenderBundle { id: id::RenderBundleId, desc: crate::command::RenderBundleEncoderDescriptor<'a>, - base: crate::command::BasePass, + base: crate::command::BasePass, }, DestroyRenderBundle(id::RenderBundleId), CreateQuerySet { @@ -192,11 +192,11 @@ pub enum Command { PopDebugGroup, InsertDebugMarker(String), RunComputePass { - base: crate::command::BasePass, + base: crate::command::BasePass, timestamp_writes: Option, }, RunRenderPass { - base: crate::command::BasePass, + base: crate::command::BasePass, target_colors: Vec>, target_depth_stencil: Option, timestamp_writes: Option,