From a7e0298dc515abccbc84e4bb2c98881b8fb7e693 Mon Sep 17 00:00:00 2001 From: Luo Zhihao Date: Fri, 29 May 2026 23:28:50 +0800 Subject: [PATCH] Validate LoadOp and StoreOp are None for attachments without corresponding depth or stencil aspect (#9567) Co-authored-by: Erich Gubler --- CHANGELOG.md | 1 + cts_runner/test.lst | 3 +-- .../zero_init_texture_after_discard.rs | 4 ++-- wgpu-core/src/command/render.rs | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85147c7f4..ae486eb80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -191,6 +191,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505). - Add clip distances validation for `maxInterStageShaderVariables`. By @ErichDonGubler in [#8762](https://github.com/gfx-rs/wgpu/pull/8762). This may break some existing programs, but it compiles with the WebGPU spec. - Bring immediates in line with webgpu spec. By @atlv24 in [#9280](https://github.com/gfx-rs/wgpu/pull/9280). +- Validate `LoadOp` and `StoreOp` are `None` for attachments without corresponding depth or stencil aspect. By @beicause in [#9567](https://github.com/gfx-rs/wgpu/pull/9567). #### DX12 diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 8841dcc6d..8ff500c3d 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -252,8 +252,7 @@ fails-if(dx12) webgpu:api,validation,render_pass,attachment_compatibility:render webgpu:api,validation,render_pass,attachment_compatibility:render_pass_or_bundle_and_pipeline,sample_count:* webgpu:api,validation,render_pass,render_pass_descriptor:attachments,* webgpu:api,validation,render_pass,render_pass_descriptor:color_attachments,* -webgpu:api,validation,render_pass,render_pass_descriptor:depth_stencil_attachment,depth_clear_value:* -webgpu:api,validation,render_pass,render_pass_descriptor:depth_stencil_attachment,sample_counts_mismatch:* +webgpu:api,validation,render_pass,render_pass_descriptor:depth_stencil_attachment,* webgpu:api,validation,render_pass,render_pass_descriptor:occlusionQuerySet,query_set_type:* webgpu:api,validation,render_pass,render_pass_descriptor:resolveTarget,* webgpu:api,validation,render_pass,render_pass_descriptor:timestampWrite,query_index:* diff --git a/tests/tests/wgpu-gpu/zero_init_texture_after_discard.rs b/tests/tests/wgpu-gpu/zero_init_texture_after_discard.rs index 193971f61..8bb9305ac 100644 --- a/tests/tests/wgpu-gpu/zero_init_texture_after_discard.rs +++ b/tests/tests/wgpu-gpu/zero_init_texture_after_discard.rs @@ -274,7 +274,7 @@ impl<'ctx> TestCase<'ctx> { depth_stencil_attachment: self.format.is_depth_stencil_format().then_some( RenderPassDepthStencilAttachment { view: &self.texture.create_view(&TextureViewDescriptor::default()), - depth_ops: Some(Operations { + depth_ops: self.format.has_depth_aspect().then_some(Operations { load: LoadOp::Load, store: StoreOp::Discard, }), @@ -304,7 +304,7 @@ impl<'ctx> TestCase<'ctx> { load: LoadOp::Clear(0.0), store: StoreOp::Store, }), - stencil_ops: Some(Operations { + stencil_ops: self.format.has_stencil_aspect().then_some(Operations { load: LoadOp::Load, store: StoreOp::Discard, }), diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 46c75c7cd..eb1536087 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -806,6 +806,16 @@ pub enum AttachmentError { ReadOnlyWithLoad, #[error("StoreOp must be None for read-only attachments")] ReadOnlyWithStore, + #[error("Depth `LoadOp` and `StoreOp` (`{ops:?}`) must be `None` for attachments (`{format:?}`) without depth aspect")] + DepthOpsWithoutAspect { + format: wgt::TextureFormat, + ops: (Option>>, Option), + }, + #[error("Stencil `LoadOp` and `StoreOp` (`{ops:?}`) must be `None` for attachments (`{format:?}`) without stencil aspect")] + StencilOpsWithoutAspect { + format: wgt::TextureFormat, + ops: (Option>>, Option), + }, #[error("Attachment without load")] NoLoad, #[error("Attachment without store")] @@ -1849,11 +1859,23 @@ impl Global { Err(AttachmentError::NoClearValue) })? } else { + if depth_stencil_attachment.depth.load_op.is_some() || depth_stencil_attachment.depth.store_op.is_some() { + return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::DepthOpsWithoutAspect { + format, + ops: (depth_stencil_attachment.depth.load_op, depth_stencil_attachment.depth.store_op) + })); + } ResolvedPassChannel::ReadOnly }, stencil: if format.has_stencil_aspect() { depth_stencil_attachment.stencil.resolve(|clear| Ok(clear.unwrap_or_default()))? } else { + if depth_stencil_attachment.stencil.load_op.is_some() || depth_stencil_attachment.stencil.store_op.is_some() { + return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::StencilOpsWithoutAspect { + format, + ops: (depth_stencil_attachment.stencil.load_op, depth_stencil_attachment.stencil.store_op) + })); + } ResolvedPassChannel::ReadOnly }, })