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
- https://github.com/gpuweb/gpuweb/issues/3905
- https://github.com/gpuweb/gpuweb/pull/3849/files#r1122411287
This commit is contained in:
Erich Gubler 2024-07-23 21:55:46 -04:00
parent ea75a8ced4
commit ca767f7d74
2 changed files with 27 additions and 8 deletions

View File

@ -3146,8 +3146,23 @@ impl Device {
} }
let aspect = hal::FormatAspects::from(ds.format); let aspect = hal::FormatAspects::from(ds.format);
if ds.is_depth_enabled() && !aspect.contains(hal::FormatAspects::DEPTH) { match (
break 'error Some(pipeline::DepthStencilStateError::FormatNotDepth(ds.format)); 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) { if ds.stencil.is_enabled() && !aspect.contains(hal::FormatAspects::STENCIL) {
break 'error Some(pipeline::DepthStencilStateError::FormatNotStencil( break 'error Some(pipeline::DepthStencilStateError::FormatNotStencil(

View File

@ -4884,10 +4884,12 @@ pub struct DepthStencilState {
/// ///
/// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass /// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass
pub format: TextureFormat, pub format: TextureFormat,
/// If disabled, depth will not be written to. /// If disabled, depth will not be written to. Must be specified if `format` has a depth
pub depth_write_enabled: bool, /// component.
/// Comparison function used to compare depth values in the depth test. pub depth_write_enabled: Option<bool>,
pub depth_compare: CompareFunction, /// 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. /// Stencil state.
#[cfg_attr(feature = "serde", serde(default))] #[cfg_attr(feature = "serde", serde(default))]
pub stencil: StencilState, pub stencil: StencilState,
@ -4900,13 +4902,15 @@ impl DepthStencilState {
/// Returns true if the depth testing is enabled. /// Returns true if the depth testing is enabled.
#[must_use] #[must_use]
pub fn is_depth_enabled(&self) -> bool { 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. /// Returns true if the state doesn't mutate the depth buffer.
#[must_use] #[must_use]
pub fn is_depth_read_only(&self) -> bool { 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. /// Returns true if the state doesn't mutate the stencil.