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

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

@⁠fuzeofficlal on GitHub · 2026-11-26 13:31 UTC · original
fuzeofficlal:fix/gpu-cut-snapshot-targets → main · +749 −18 · 1 files · 1 commits · open

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).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 13:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3217) `fuzeofficlal:fix/gpu-cut-snapshot-targets` → `main` · +749 −18 · 1 files · 1 commits · open ### 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`).
OMSetRenderTargets snapshots CPU-only RTV and DSV descriptors at call time, so
a title may legally overwrite the CPU descriptor slots or release transient CPU
RTV/DSV descriptor heaps immediately afterwards.

Previously, Fixed::targets stored only the raw guest CPU descriptor handle
addresses and State::cut called set_targets again when Wait32BitValueX or
Wait64BitValueX split a command list into a new host segment. That re-read the
guest CPU descriptor heap memory at the time of the cut, silently binding
overwritten render/depth targets or dereferencing freed heap memory and
dropping targets on subsequent segments.

Snapshot the resolved target resource pointers and view descriptions in
Fixed::targets when OMSetRenderTargets runs, and replay those snapshots in
State::cut without touching guest CPU descriptor memory again.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:35:51 +00:00
Author
Owner

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

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

**@⁠Dukestar69** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3217#pullrequestreview-6075295488) · **approved these changes** 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 14:05 UTC · original

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

**@⁠oni-swr** on GitHub · 2026-11-26 14:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3217#issuecomment-7194252360) **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 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/3217/head:github-bot/gh-3217'
git switch 'github-bot/gh-3217'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3217'
git switch 'github-bot/gh-3217'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3217'
git switch 'github-bot/gh-3217'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3217'
git switch 'main'
git merge --squash 'github-bot/gh-3217'
git switch 'main'
git merge --ff-only 'github-bot/gh-3217'
git switch 'main'
git merge 'github-bot/gh-3217'
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!3217
No description provided.