Skip to content

Commit 81a9d76

Browse files
WIP: feat: only require depth config. for fmts. w/ depth
TODO: Ensure that the following changes and discussion get represented in code: - https://github.com/gpuweb/gpuweb/pull/4318/files - gpuweb/gpuweb#3905 - https://github.com/gpuweb/gpuweb/pull/3849/files#r1122411287
1 parent 894d036 commit 81a9d76

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

wgpu-core/src/device/resource.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,8 +3279,23 @@ impl Device {
32793279
}
32803280

32813281
let aspect = hal::FormatAspects::from(ds.format);
3282-
if ds.is_depth_enabled() && !aspect.contains(hal::FormatAspects::DEPTH) {
3283-
break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(ds.format));
3282+
match (
3283+
aspect.contains(hal::FormatAspects::DEPTH),
3284+
ds.depth_write_enabled.zip(ds.depth_compare),
3285+
) {
3286+
(true, Some(_)) | (false, None) => (),
3287+
(true, None) => {
3288+
break 'error Some(pipeline::DepthStencilStateError::DepthOpsNotSpecified {
3289+
format: ds.format,
3290+
depth_write_enabled: ds.depth_write_enabled,
3291+
depth_compare: ds.depth_compare,
3292+
})
3293+
}
3294+
(false, Some(_)) => {
3295+
break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(
3296+
ds.format,
3297+
))
3298+
}
32843299
}
32853300
if ds.stencil.is_enabled() && !aspect.contains(hal::FormatAspects::STENCIL) {
32863301
break 'error Some(pipeline::DepthStencilStateError::FormatNotStencil(

wgpu-types/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,10 +4470,12 @@ pub struct DepthStencilState {
44704470
///
44714471
/// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass
44724472
pub format: TextureFormat,
4473-
/// If disabled, depth will not be written to.
4474-
pub depth_write_enabled: bool,
4475-
/// Comparison function used to compare depth values in the depth test.
4476-
pub depth_compare: CompareFunction,
4473+
/// If disabled, depth will not be written to. Must be specified if `format` has a depth
4474+
/// component.
4475+
pub depth_write_enabled: Option<bool>,
4476+
/// Comparison function used to compare depth values in the depth test. Must be specified if
4477+
/// `format` has a depth component.
4478+
pub depth_compare: Option<CompareFunction>,
44774479
/// Stencil state.
44784480
#[cfg_attr(feature = "serde", serde(default))]
44794481
pub stencil: StencilState,
@@ -4486,13 +4488,15 @@ impl DepthStencilState {
44864488
/// Returns true if the depth testing is enabled.
44874489
#[must_use]
44884490
pub fn is_depth_enabled(&self) -> bool {
4489-
self.depth_compare != CompareFunction::Always || self.depth_write_enabled
4491+
self.depth_compare
4492+
.map_or(false, |dc| dc != CompareFunction::Always)
4493+
|| self.depth_write_enabled
44904494
}
44914495

44924496
/// Returns true if the state doesn't mutate the depth buffer.
44934497
#[must_use]
44944498
pub fn is_depth_read_only(&self) -> bool {
4495-
!self.depth_write_enabled
4499+
self.depth_write_enabled.map_or(false, |enabled| !enabled)
44964500
}
44974501

44984502
/// Returns true if the state doesn't mutate the stencil.

0 commit comments

Comments
 (0)