GPU: snapshot RTV and DSV descriptors across command-list cuts #3215

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3217 into main
fuzeofficlal commented 2026-11-26 13:31:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:31:12Z.


Summary

Snapshot resolved render-target and depth-stencil view descriptors at OMSetRenderTargets call time so mid-list segment cuts (Wait32BitValueX / Wait64BitValueX -> State::cut) replay the originally bound targets instead of re-reading guest CPU descriptor heap memory.

Problem

In D3D12, OMSetRenderTargets snapshots CPU-only RTV and DSV descriptors when the command is recorded; a title is allowed to immediately overwrite those CPU descriptor slots for later passes or release transient CPU RTV/DSV descriptor heaps right after the call.

Previously, Fixed::targets in crates/victory-gpu/src/draw.rs stored only the raw guest CPU descriptor handle addresses (Option<(Vec<u64>, u64)>), and State::cut re-invoked State::set_targets with those handles when starting a new host command-list segment. As a result, a legal command list that overwrote or freed its CPU RTV/DSV descriptors before a mid-list Wait32BitValueX/Wait64BitValueX:

  • silently bound the newly written render target, depth buffer, or subresource slice on subsequent segments (misrendering and corrupting unrelated targets), or
  • read freed descriptor heap memory (use-after-free) and silently dropped bound targets when the freed slot no longer held a matching tag.

Fix

  • Replace raw descriptor handles in Fixed::targets with snapshotted Targets storing each bound Target<D> (resource pointer and resolved D3D12_RENDER_TARGET_VIEW_DESC / D3D12_DEPTH_STENCIL_VIEW_DESC).
  • Extract State::bind_targets shared by State::set_targets and State::cut, preserving the snapshot across multiple consecutive cuts without re-reading guest CPU descriptor heap memory.
  • Add end-to-end GPU regression tests in crates/victory-gpu/src/draw.rs covering:
    1. Overwriting CPU RTV slot, DSV slot (verified via hardware LESS depth test), and explicit Texture2DArray slice view descriptors across one and two consecutive Wait64BitValueX cuts.
    2. Releasing transient CPU RTV and DSV descriptor heaps before a Wait64BitValueX cut, plus explicit unbinding (0 targets, null depth) before a cut.

Verification

  • Verified both new tests fail on unmodified main (Segment 1 misses the snapshotted render target after CPU descriptor overwrite or transient heap release) and pass after the fix.
  • cargo test --locked -p victory-gpu --lib cut_preserves_ -- --nocapture --test-threads=1 (RTX 5090 default, RTX 5090 --features diagnostics + VICTORY_D3D12_DEBUG=1, and WARP VICTORY_D3D12_WARP=1 + VICTORY_D3D12_DEBUG=1): 2 passed, 0 failed across all three configurations.
  • Full victory-gpu --lib suite passed on RTX 5090 default (231 passed), RTX 5090 diagnostics + Debug Layer (245 passed), and WARP + Debug Layer (245 passed).
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: clean.
  • git diff --check, rustfmt --edition 2024 --check on modified hunks, and cargo run --locked -p xtask -- policy: clean (191 files ok).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6627739696 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3217). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:31:12Z. --- ### Summary Snapshot resolved render-target and depth-stencil view descriptors at `OMSetRenderTargets` call time so mid-list segment cuts (`Wait32BitValueX` / `Wait64BitValueX` -> `State::cut`) replay the originally bound targets instead of re-reading guest CPU descriptor heap memory. ### Problem In D3D12, `OMSetRenderTargets` snapshots CPU-only RTV and DSV descriptors when the command is recorded; a title is allowed to immediately overwrite those CPU descriptor slots for later passes or release transient CPU RTV/DSV descriptor heaps right after the call. Previously, `Fixed::targets` in `crates/victory-gpu/src/draw.rs` stored only the raw guest CPU descriptor handle addresses (`Option<(Vec<u64>, u64)>`), and `State::cut` re-invoked `State::set_targets` with those handles when starting a new host command-list segment. As a result, a legal command list that overwrote or freed its CPU RTV/DSV descriptors before a mid-list `Wait32BitValueX`/`Wait64BitValueX`: - silently bound the newly written render target, depth buffer, or subresource slice on subsequent segments (misrendering and corrupting unrelated targets), or - read freed descriptor heap memory (use-after-free) and silently dropped bound targets when the freed slot no longer held a matching tag. ### Fix - Replace raw descriptor handles in `Fixed::targets` with snapshotted `Targets` storing each bound `Target<D>` (`resource` pointer and resolved `D3D12_RENDER_TARGET_VIEW_DESC` / `D3D12_DEPTH_STENCIL_VIEW_DESC`). - Extract `State::bind_targets` shared by `State::set_targets` and `State::cut`, preserving the snapshot across multiple consecutive cuts without re-reading guest CPU descriptor heap memory. - Add end-to-end GPU regression tests in `crates/victory-gpu/src/draw.rs` covering: 1. Overwriting CPU RTV slot, DSV slot (verified via hardware `LESS` depth test), and explicit `Texture2DArray` slice view descriptors across one and two consecutive `Wait64BitValueX` cuts. 2. Releasing transient CPU RTV and DSV descriptor heaps before a `Wait64BitValueX` cut, plus explicit unbinding (`0` targets, null depth) before a cut. ### Verification - Verified both new tests fail on unmodified `main` (Segment 1 misses the snapshotted render target after CPU descriptor overwrite or transient heap release) and pass after the fix. - `cargo test --locked -p victory-gpu --lib cut_preserves_ -- --nocapture --test-threads=1` (RTX 5090 default, RTX 5090 `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, and WARP `VICTORY_D3D12_WARP=1` + `VICTORY_D3D12_DEBUG=1`): 2 passed, 0 failed across all three configurations. - Full `victory-gpu --lib` suite passed on RTX 5090 default (231 passed), RTX 5090 diagnostics + Debug Layer (245 passed), and WARP + Debug Layer (245 passed). - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: clean. - `git diff --check`, `rustfmt --edition 2024 --check` on modified hunks, and `cargo run --locked -p xtask -- policy`: clean (`191 files ok`).
Dukestar69 commented 2026-11-26 14:01:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:52:46Z.

Review: APPROVED


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

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

Cleanly snapshots RTV and DSV descriptors across command-list cuts so subsequent CPU descriptor overwrites or heap releases do not corrupt bound targets.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6075295488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3217#pullrequestreview-6075295488). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:52:46Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 22/22 passed on RTX 5090 and WARP (including `cut_preserves_snapshotted_targets_after_cpu_descriptor_overwrite` and `cut_preserves_targets_after_cpu_descriptor_heaps_released_and_handles_unbind`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly snapshots RTV and DSV descriptors across command-list cuts so subsequent CPU descriptor overwrites or heap releases do not corrupt bound targets. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 15:02:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:05:01Z.


WARP test report: head bb003dd4 (parent and control base: main 63bcca43)

  • Adapter: Microsoft Basic Render Driver (WARP). A local, uncommitted probe asserted the host device's adapter name before each run; it passed and was reverted.
  • Environment: VICTORY_WARP=1, VICTORY_D3D12_WARP=1, cargo test -j 4 -p victory-gpu --features diagnostics --lib, rustc 1.98.1, Windows 11, dxil.dll from the Windows SDK 10.0.26100.0.
  • Head: draw::tests::cut_preserves_snapshotted_targets_after_cpu_descriptor_overwrite and draw::tests::cut_preserves_targets_after_cpu_descriptor_heaps_released_and_handles_unbind both pass. The whole victory-gpu lib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored.
  • Control: main's draw.rs code with this PR's test module. Both new tests fail, each with a wrong texel read back from the render target: Segment 1 must still draw into snapshotted rt_a after rtv_slot was overwritten and Segment 1 must still draw into rt after transient CPU RTV/DSV heaps were released (left 4294901760, right 4278190335).
  • Not tested: synthetic render targets and a fullscreen draw only. No physical GPU, no title, and the real driver behaviour for descriptor snapshots on other adapters.

AI-assisted: verification by Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194252360 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3217#issuecomment-7194252360). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T14:05:01Z. --- **WARP test report: head `bb003dd4`** (parent and control base: main `63bcca43`) - Adapter: Microsoft Basic Render Driver (WARP). A local, uncommitted probe asserted the host device's adapter name before each run; it passed and was reverted. - Environment: `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `cargo test -j 4 -p victory-gpu --features diagnostics --lib`, rustc 1.98.1, Windows 11, `dxil.dll` from the Windows SDK 10.0.26100.0. - Head: `draw::tests::cut_preserves_snapshotted_targets_after_cpu_descriptor_overwrite` and `draw::tests::cut_preserves_targets_after_cpu_descriptor_heaps_released_and_handles_unbind` both pass. The whole `victory-gpu` lib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored. - Control: main's `draw.rs` code with this PR's test module. Both new tests fail, each with a wrong texel read back from the render target: `Segment 1 must still draw into snapshotted rt_a after rtv_slot was overwritten` and `Segment 1 must still draw into rt after transient CPU RTV/DSV heaps were released` (left 4294901760, right 4278190335). - Not tested: synthetic render targets and a fullscreen draw only. No physical GPU, no title, and the real driver behaviour for descriptor snapshots on other adapters. AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
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/3217:upstream-pr/3217'
git switch 'upstream-pr/3217'

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/3217'
git switch 'upstream-pr/3217'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3217'
git switch 'upstream-pr/3217'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3217'
git switch 'main'
git merge --squash 'upstream-pr/3217'
git switch 'main'
git merge --ff-only 'upstream-pr/3217'
git switch 'main'
git merge 'upstream-pr/3217'
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!3215
No description provided.