GPU: revalidate depth state after a colour twin transition #3041

Open
ghptc wants to merge 1 commit from upstream-pr/3041 into main
ghptc commented 2026-11-29 19:43:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ghptc on 2026-11-29T19:43:32Z.


What it changes

A graphics draw can keep the same DSV bound while an intervening command changes that texture's list state. For a single-plane depth texture, a shader can write the colour twin and the next depth draw can copy it back, leaving the texture in COPY_DEST. An intervening read of the depth resource as an SRV can leave it in shader-resource state. The draw's cached state previously contained only the desired DSV state. It could skip the transition back even when the command list recorded a different actual state.

Include the command-list epoch in the cached key when the DSV has a colour twin. Read the epoch after twin_use and remember it after ensure_state. Consecutive draws in the same state and epoch still use the cache. The existing cache remains in use for resources without a twin. A transition on another resource can advance the list epoch and cause an additional tracker lookup.

#1541 publishes dirty depth planes after the writer and replays bindings for that path. #2770 changes which draws mark depth/stencil written. This patch preserves main's existing write classification and can be applied independently of #2770. If both changes land, keep #2770's write predicate as the third argument and retain twin_use's returned flag for the epoch key.

Validation

An offline Rust control extracted the state and twin logic from f889bb076fa884fff8d2b6f0b50ac86f72abfd98 and this port. It modeled the command list and replaced graphics calls with CPU state checks.

  • After a simulated draw → UAV write to the colour twin → draw, the baseline left COPY_DEST (0x400) instead of DEPTH_WRITE (0x10). The candidate restored 0x10.
  • After a simulated draw → SRV read → draw, the baseline left the shader read state (0xc0). The candidate restored 0x10.
  • Identical draws at a stable epoch reused the cache. Epoch changes preserved the state-only cache on the no-twin control, and explicit replay invalidated it.

This control covers the state logic of a single-plane depth resource. The full Windows runtime, GPU and visual output are outside its scope. The invalid baseline sequence was evaluated in CPU state only.

Adapted from 8fa7b9799b0bf99eb558e50f8b3394c34f6f78e2, with the original authorship retained.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554399489 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3041). Originally posted by [ghptc](https://github.com/ghptc) on 2026-11-29T19:43:32Z. --- ## What it changes A graphics draw can keep the same DSV bound while an intervening command changes that texture's list state. For a single-plane depth texture, a shader can write the colour twin and the next depth draw can copy it back, leaving the texture in `COPY_DEST`. An intervening read of the depth resource as an SRV can leave it in shader-resource state. The draw's cached state previously contained only the desired DSV state. It could skip the transition back even when the command list recorded a different actual state. Include the command-list epoch in the cached key when the DSV has a colour twin. Read the epoch after `twin_use` and remember it after `ensure_state`. Consecutive draws in the same state and epoch still use the cache. The existing cache remains in use for resources without a twin. A transition on another resource can advance the list epoch and cause an additional tracker lookup. #1541 publishes dirty depth planes after the writer and replays bindings for that path. #2770 changes which draws mark depth/stencil written. This patch preserves main's existing write classification and can be applied independently of #2770. If both changes land, keep #2770's write predicate as the third argument and retain `twin_use`'s returned flag for the epoch key. ## Validation An offline Rust control extracted the state and twin logic from `f889bb076fa884fff8d2b6f0b50ac86f72abfd98` and this port. It modeled the command list and replaced graphics calls with CPU state checks. - After a simulated draw → UAV write to the colour twin → draw, the baseline left `COPY_DEST` (`0x400`) instead of `DEPTH_WRITE` (`0x10`). The candidate restored `0x10`. - After a simulated draw → SRV read → draw, the baseline left the shader read state (`0xc0`). The candidate restored `0x10`. - Identical draws at a stable epoch reused the cache. Epoch changes preserved the state-only cache on the no-twin control, and explicit replay invalidated it. This control covers the state logic of a single-plane depth resource. The full Windows runtime, GPU and visual output are outside its scope. The invalid baseline sequence was evaluated in CPU state only. Adapted from `8fa7b9799b0bf99eb558e50f8b3394c34f6f78e2`, with the original authorship retained.
tyr0nsur commented 2026-12-01 14:42:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-12-01T14:42:47Z.


I applied 72cfdb94 on top of current main 5fabb46e. It applies cleanly, but cargo check --locked -p victory-gpu --all-targets fails with E0308 in the newer ClearState path. last_depth_state is now (u32, u64), and that reset still assigns 0.

Locally, the same check passes after resetting it to (0, 0) and updating the existing ClearState test to seed (0x10, 7) and expect (0, 0). The nonzero epoch also checks that the reset clears both fields. No title was used.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7314703088 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3041#issuecomment-7314703088). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-12-01T14:42:47Z. --- I applied `72cfdb94` on top of current main `5fabb46e`. It applies cleanly, but `cargo check --locked -p victory-gpu --all-targets` fails with E0308 in the newer `ClearState` path. `last_depth_state` is now `(u32, u64)`, and that reset still assigns `0`. Locally, the same check passes after resetting it to `(0, 0)` and updating the existing ClearState test to seed `(0x10, 7)` and expect `(0, 0)`. The nonzero epoch also checks that the reset clears both fields. No title was used.
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/3041:upstream-pr/3041'
git switch 'upstream-pr/3041'

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/3041'
git switch 'upstream-pr/3041'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3041'
git switch 'upstream-pr/3041'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3041'
git switch 'main'
git merge --squash 'upstream-pr/3041'
git switch 'main'
git merge --ff-only 'upstream-pr/3041'
git switch 'main'
git merge 'upstream-pr/3041'
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
trustno1-coder/VIctory-NVIDIA!3041
No description provided.