GPU: ignore depth-stencil clears whose host flags mask to zero #3150

Open
github-bot wants to merge 1 commit from github-bot/gh-3150 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:24 UTC · original
fuzeofficlal:fix/gpu-clear-dsv-empty-flags → main · +178 −1 · 1 files · 1 commits · open

Summary

list::clear_dsv masks incoming ClearDepthStencilView flags with & 3 to strip console-only bits above D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, but still transitions the depth target, allocates a host DSV, and records ClearDepthStencilView(..., D3D12_CLEAR_FLAGS(0), ...) when the masked value is 0 (for example, flags == 0 or console-only flags such as 0x4).

D3D12 rejects ClearFlags == 0 (ID3D12CommandList::ClearDepthStencilView: Invalid ClearFlags value (0x0). ClearFlags must be either D3D12_CLEAR_FLAG_DEPTH (0x1) or D3D12_CLEAR_FLAG_STENCIL (0x2) or both (0x3).).

Fix

Mask flags with & 3 at the top of clear_dsv and return early when the result is 0, before transitioning the resource or recording the clear.

Testing

Added a synthetic D3D12 unit test (list::tests::clear_dsv_skips_empty_masked_flags) verifying that:

  • ClearDepthStencilView with 0 or console-only flags (0x4) records no clear or state transition and emits zero D3D12 debug layer errors (fails on main with Invalid ClearFlags value (0x0) under VICTORY_D3D12_DEBUG=1 and records a non-empty list without the debug layer).
  • Combining a host depth bit with a console bit (1 | 0x4) clears a D32_FLOAT texture to 0.25 (verified via GPU readback), and subsequent empty-masked clears leave the cleared depth untouched.

Verified on native D3D12 hardware and WARP (VICTORY_D3D12_WARP=1) with VICTORY_D3D12_DEBUG=1 and --features diagnostics, cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features), and cargo test -p xtask --locked policy::tests::repository_passes_policy.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3150) `fuzeofficlal:fix/gpu-clear-dsv-empty-flags` → `main` · +178 −1 · 1 files · 1 commits · open ### Summary `list::clear_dsv` masks incoming `ClearDepthStencilView` flags with `& 3` to strip console-only bits above `D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL`, but still transitions the depth target, allocates a host DSV, and records `ClearDepthStencilView(..., D3D12_CLEAR_FLAGS(0), ...)` when the masked value is `0` (for example, `flags == 0` or console-only flags such as `0x4`). D3D12 rejects `ClearFlags == 0` (`ID3D12CommandList::ClearDepthStencilView: Invalid ClearFlags value (0x0). ClearFlags must be either D3D12_CLEAR_FLAG_DEPTH (0x1) or D3D12_CLEAR_FLAG_STENCIL (0x2) or both (0x3).`). ### Fix Mask `flags` with `& 3` at the top of `clear_dsv` and return early when the result is `0`, before transitioning the resource or recording the clear. ### Testing Added a synthetic D3D12 unit test (`list::tests::clear_dsv_skips_empty_masked_flags`) verifying that: - `ClearDepthStencilView` with `0` or console-only flags (`0x4`) records no clear or state transition and emits zero D3D12 debug layer errors (fails on `main` with `Invalid ClearFlags value (0x0)` under `VICTORY_D3D12_DEBUG=1` and records a non-empty list without the debug layer). - Combining a host depth bit with a console bit (`1 | 0x4`) clears a `D32_FLOAT` texture to `0.25` (verified via GPU readback), and subsequent empty-masked clears leave the cleared depth untouched. Verified on native D3D12 hardware and WARP (`VICTORY_D3D12_WARP=1`) with `VICTORY_D3D12_DEBUG=1` and `--features diagnostics`, `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`), and `cargo test -p xtask --locked policy::tests::repository_passes_policy`.
ClearDepthStencilView strips console-only clear bits above bits 0..1 via flags & 3, which yields ClearFlags = 0 when a call passes 0 or only console-specific bits. D3D12 rejects ClearFlags == 0 (Invalid ClearFlags value (0x0)). Return early before transitioning the depth target or recording the clear when flags & 3 == 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:47 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:26 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090 and WARP.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly ignores depth-stencil clears whose masked host clear flags are zero.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 10:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3150#pullrequestreview-6072409156) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed on RTX 5090 and WARP. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly ignores depth-stencil clears whose masked host clear flags are zero. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3150/head:github-bot/gh-3150'
git switch 'github-bot/gh-3150'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3150'
git switch 'github-bot/gh-3150'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3150'
git switch 'github-bot/gh-3150'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3150'
git switch 'main'
git merge --squash 'github-bot/gh-3150'
git switch 'main'
git merge --ff-only 'github-bot/gh-3150'
git switch 'main'
git merge 'github-bot/gh-3150'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3150
No description provided.