Skip to content

DepthStencilState validation fixes#8840

Open
andyleiserson wants to merge 1 commit intogfx-rs:trunkfrom
andyleiserson:jj-branches/mxx
Open

DepthStencilState validation fixes#8840
andyleiserson wants to merge 1 commit intogfx-rs:trunkfrom
andyleiserson:jj-branches/mxx

Conversation

@andyleiserson
Copy link
Contributor

@andyleiserson andyleiserson commented Jan 8, 2026

The depth-related fields are optional in the WebGPU API, and must be specified iff they are relevant to the configuration. In order to have wgpu-core provide a common implementation of this validation for all the JS clients, this changes pipeline descriptors to use a new DepthStencilStateIdl struct that matches the spec (at least for the enable/compare -- it still differs from the spec in that the depth bias and stencil configuration are not inlined).

DepthStencilState is maintained as-is so that implementations can keep the same struct literals and just add a call to .into(). I also added some associated method constructors that will be forwards-compatible with making DepthStencilState look like DepthStencilStateIdl.

There is some related discussion in Matrix. We may decide to create a separate DepthState struct instead.

This PR conflicts with #8856. Whichever lands second should enable the entire depth_stencil_state suite.

Testing
Enables some relevant CTS tests.

Squash or Rebase? Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@andyleiserson
Copy link
Contributor Author

(Responding to discussion of a possible DepthState struct in matrix): The rules are that depthWriteEnabled must be provided if using a depth format; depthCompare must be provided if depthWriteEnabled is true or if stencil has an active depthFailOp. So while depthWriteEnabled could be mandatory in DepthState, depthCompare would still need to be optional. I think that makes it harder to justify a breaking change to introduce DepthState.

A data point: https://github.com/search?q=language%3ARust+RenderPipelineDescriptor+DepthStencilState&type=code finds 6.7k files 😬. Even the need to add .into() doesn't seem great, but I couldn't figure out an alternative that didn't involve duplicating or adding a type parameter to all the pipeline descriptors.

@andyleiserson
Copy link
Contributor Author

andyleiserson commented Jan 27, 2026

@cwfitzgerald you had proposed a different change that would create a separate DepthState struct. Does the issue of depthCompare needing to be optional even within DepthState (see #8840 (comment)) change your thinking at all?

(And I guess separately from that, there's also a question of whether to offer a migration via DepthStencilStateIdl like it is now, or to just inflict the full pain and change DepthStencilState to look the way we want.)

The depth-related fields are optional in the WebGPU API, and must be
specified iff they are relevant to the configuration.

Fixes gfx-rs#8830
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants