Skip to content

Vulkan support for SHADER_EARLY_DEPTH_TEST and fix to conservative depth optimizations #7676

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

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

dzamkov
Copy link

@dzamkov dzamkov commented May 8, 2025

Connections
#3961: Resolves for Vulkan and GL backends
#4408: Resolves for Vulkan backend

Description

  1. Support for forced early fragment tests and conservative depth in the Vulkan/SPIR backend, using the Naga-specific @early_depth_test attribute
  2. Fixes design issue which prevents useful conservative depth optimizations in GLSL

Originally, I had only planned to do the first, but while reviewing the specs and doing research for this change, I discovered that the current design of Naga's EarlyDepthTest doesn't make sense. There are two use cases for early fragment tests:

  1. Forcing early fragment tests while disabling late tests: Typically used when the fragment shader writes to storage buffers and these writes must be prevented when depth/stencil tests fail
  2. Permitting early fragment tests while still having late tests enabled: Typically used when the fragment shader changes the frag_depth in a predictable way, allowing an additional early depth/stencil test to optimize away unnecessary shader invocations without changing behavior

These use cases are incompatible with each other. In both Vulkan and GLSL, forcing early fragment tests disables late tests, which means that writing to frag_depth is either useless or an error. Currently, Naga doesn't allow writing a conservative depth specifier without also forcing early fragment tests, invalidating the conservative depth specifier.

To salvage conservative depth optimizations, I have reworked EarlyDepthTest into an enum with variants corresponding to the two use cases above. To make this more explicit, @early_depth_test(force) is now required to force early fragment tests.

Testing

  • Added snapshot tests and reviewed output
  • Integrated into a personal project and verified that forced early fragment tests work as expected

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.

@dzamkov dzamkov requested a review from a team as a code owner May 8, 2025 00:21
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.

1 participant