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

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3150 into main
fuzeofficlal commented 2026-11-26 10:24:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:24:20Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5508239291 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3150). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:24:20Z. --- ### 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`.
Dukestar69 commented 2026-11-26 10:26:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:26:51Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6072409156 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3150#pullrequestreview-6072409156). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:26:51Z. **Review:** APPROVED --- 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).
Jackster commented 2026-11-26 23:02:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:11Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

clear_dsv_skips_empty_masked_flags passes; the other clear tests are unchanged. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205197699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3150#issuecomment-7205197699). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:11Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `cargo test -p victory-gpu --lib`: 232 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. `clear_dsv_skips_empty_masked_flags` passes; the other clear tests are unchanged. Synthetic only. AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3150:upstream-pr/3150'
git switch 'upstream-pr/3150'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3150'
git switch 'upstream-pr/3150'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3150'
git switch 'upstream-pr/3150'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3150'
git switch 'main'
git merge --squash 'upstream-pr/3150'
git switch 'main'
git merge --ff-only 'upstream-pr/3150'
git switch 'main'
git merge 'upstream-pr/3150'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3148
No description provided.