Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: only require depth config. for fmts. w/ depth #6026

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading