Add a field in BasePass to store errors

This commit is contained in:
Andy Leiserson 2025-06-06 14:48:43 -07:00
parent 0c629bb3c2
commit 09c08037c9
5 changed files with 35 additions and 16 deletions

View File

@ -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<RenderCommand>,
base: BasePass<RenderCommand, Infallible>,
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<BasePass<RenderCommand>>,
base: Option<BasePass<RenderCommand, Infallible>>,
) -> Result<Self, CreateRenderBundleError> {
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<RenderCommand> {
pub(crate) fn to_base_pass(&self) -> BasePass<RenderCommand, Infallible> {
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<Label<'a>>;
pub struct RenderBundle {
// Normalized command stream. It can be executed verbatim,
// without re-binding anything on the pipeline change.
base: BasePass<ArcRenderCommand>,
base: BasePass<ArcRenderCommand, Infallible>,
pub(super) is_depth_read_only: bool,
pub(super) is_stencil_read_only: bool,
pub(crate) device: Arc<Device>,

View File

@ -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<BasePass<ArcComputeCommand>>,
base: Option<BasePass<ArcComputeCommand, Infallible>>,
/// 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<ArcComputeCommand>, ComputePassError> {
) -> Result<&'a mut BasePass<ArcComputeCommand, Infallible>, 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<super::ComputeCommand>,
base: BasePass<super::ComputeCommand, core::convert::Infallible>,
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,

View File

@ -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<C> {
pub struct BasePass<C, E> {
pub label: Option<String>,
/// 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<E>,
/// The stream of commands.
pub commands: Vec<C>,
@ -842,10 +852,11 @@ pub struct BasePass<C> {
pub push_constant_data: Vec<u32>,
}
impl<C: Clone> BasePass<C> {
impl<C: Clone, E: Clone> BasePass<C, E> {
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(),

View File

@ -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<BasePass<ArcRenderCommand>>,
base: Option<BasePass<ArcRenderCommand, Infallible>>,
/// 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<ArcRenderCommand>, RenderPassError> {
) -> Result<&'a mut BasePass<ArcRenderCommand, Infallible>, 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<super::RenderCommand>,
base: BasePass<super::RenderCommand, core::convert::Infallible>,
color_attachments: &[Option<RenderPassColorAttachment>],
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,

View File

@ -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<crate::command::RenderCommand>,
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
},
DestroyRenderBundle(id::RenderBundleId),
CreateQuerySet {
@ -192,11 +192,11 @@ pub enum Command {
PopDebugGroup,
InsertDebugMarker(String),
RunComputePass {
base: crate::command::BasePass<crate::command::ComputeCommand>,
base: crate::command::BasePass<crate::command::ComputeCommand, Infallible>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,
},
RunRenderPass {
base: crate::command::BasePass<crate::command::RenderCommand>,
base: crate::command::BasePass<crate::command::RenderCommand, Infallible>,
target_colors: Vec<Option<crate::command::RenderPassColorAttachment>>,
target_depth_stencil: Option<crate::command::RenderPassDepthStencilAttachment>,
timestamp_writes: Option<crate::command::PassTimestampWrites>,