From df4ae64df67353382d7a0edaca4e61ceebe75fce Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Mon, 22 Dec 2025 18:33:59 -0800 Subject: [PATCH] Check GPUDepthStencilState.format even when neither is enabled (#8766) Fixes #8736 --- CHANGELOG.md | 6 ++++++ cts_runner/test.lst | 1 + wgpu-core/src/device/resource.rs | 8 ++++++++ wgpu-core/src/pipeline.rs | 2 ++ 4 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f43d84da9..1a428b381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,12 @@ Bottom level categories: - Added support for cooperative load/store operations in shaders. Currently only WGSL on the input and SPIR-V, METAL, and WGSL on the output are supported. By @kvark in [#8251](https://github.com/gfx-rs/wgpu/issues/8251). +### Bug Fixes + +#### General + +- Fixed validation of the texture format in GPUDepthStencilState when neither depth nor stencil is actually enabled. By @andyleiserson in [#8766](https://github.com/gfx-rs/wgpu/pull/8766). + ### Documentation #### General diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 62afa3008..bf25bb897 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -135,6 +135,7 @@ 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:resolveTarget,* webgpu:api,validation,render_pass,resolve:resolve_attachment:* +webgpu:api,validation,render_pipeline,depth_stencil_state:format:* webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_write:* webgpu:api,validation,resource_usages,buffer,in_pass_encoder:* // FAIL: 2 other cases in resource_usages,texture,in_pass_encoder. https://github.com/gfx-rs/wgpu/issues/3126 diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index f1e305a3f..ea730cb1e 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -4141,6 +4141,14 @@ impl Device { if let Some(ds) = depth_stencil_state { target_specified = true; let error = 'error: { + if !ds.format.is_depth_stencil_format() { + // This error case is not redundant with the aspect check below when + // neither depth nor stencil is enabled at all. + break 'error Some(pipeline::DepthStencilStateError::FormatNotDepthOrStencil( + ds.format, + )); + } + let format_features = self.describe_format_features(ds.format)?; if !format_features .allowed_usages diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index ee5bcb079..8e73d564e 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -617,6 +617,8 @@ pub enum ColorStateError { pub enum DepthStencilStateError { #[error("Format {0:?} is not renderable")] FormatNotRenderable(wgt::TextureFormat), + #[error("Format {0:?} is not a depth/stencil format")] + FormatNotDepthOrStencil(wgt::TextureFormat), #[error("Format {0:?} does not have a depth aspect, but depth test/write is enabled")] FormatNotDepth(wgt::TextureFormat), #[error("Format {0:?} does not have a stencil aspect, but stencil test/write is enabled")]