Skip to content

Commit

Permalink
WIP: feat: only require depth config. for fmts. w/ depth
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ErichDonGubler committed Nov 12, 2024
1 parent ea75a8c commit ca767f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
19 changes: 17 additions & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3146,8 +3146,23 @@ impl Device {
}

let aspect = hal::FormatAspects::from(ds.format);
if ds.is_depth_enabled() && !aspect.contains(hal::FormatAspects::DEPTH) {
break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(ds.format));
match (
aspect.contains(hal::FormatAspects::DEPTH),
ds.depth_write_enabled.zip(ds.depth_compare),
) {
(true, Some(_)) | (false, None) => (),
(true, None) => {
break 'error Some(pipeline::DepthStencilStateError::DepthOpsNotSpecified {
format: ds.format,
depth_write_enabled: ds.depth_write_enabled,
depth_compare: ds.depth_compare,
})
}
(false, Some(_)) => {
break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(
ds.format,
))
}
}
if ds.stencil.is_enabled() && !aspect.contains(hal::FormatAspects::STENCIL) {
break 'error Some(pipeline::DepthStencilStateError::FormatNotStencil(
Expand Down
16 changes: 10 additions & 6 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4884,10 +4884,12 @@ pub struct DepthStencilState {
///
/// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass
pub format: TextureFormat,
/// If disabled, depth will not be written to.
pub depth_write_enabled: bool,
/// Comparison function used to compare depth values in the depth test.
pub depth_compare: CompareFunction,
/// If disabled, depth will not be written to. Must be specified if `format` has a depth
/// component.
pub depth_write_enabled: Option<bool>,
/// Comparison function used to compare depth values in the depth test. Must be specified if
/// `format` has a depth component.
pub depth_compare: Option<CompareFunction>,
/// Stencil state.
#[cfg_attr(feature = "serde", serde(default))]
pub stencil: StencilState,
Expand All @@ -4900,13 +4902,15 @@ impl DepthStencilState {
/// Returns true if the depth testing is enabled.
#[must_use]
pub fn is_depth_enabled(&self) -> bool {
self.depth_compare != CompareFunction::Always || self.depth_write_enabled
self.depth_compare
.map_or(false, |dc| dc != CompareFunction::Always)
|| self.depth_write_enabled
}

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

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

0 comments on commit ca767f7

Please sign in to comment.