fix(victory-gpu): clear per-list table caches when replaying onto a new host list #433

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

@⁠mauroalvare on GitHub · 2026-11-26 18:42 UTC · original
mauroalvare:fix/victory-cut-replay-fresh-tables → main · +305 −3 · 2 files · 1 commits · open

Summary

Fixes constant-buffer corruption and scratch-buffer lifetime bugs when a title command list is cut onto a new HostList (list::cut at a memory wait, or list::value_written under VICTORY_CUT_WRITES=1) and continues recording via draw::State::replay.

When a descriptor table containing a constant buffer (View::Constant) is prepared on Part 1 (HostList #1), State::tables allocates a dynamic descriptor slot pointing into Part 1's scratch upload buffer (list1.scratch(...)), schedules list1.defer_constants(...), and caches that dynamic slot in State::fresh_tables.

Previously, State::replay did not clear fresh_tables (nor ready_tables, seen_tables, or window) when switching to Part 2 (HostList #2):

  • Any draw or dispatch in Part 2 using the same CBV descriptor table hit fresh_tables and reused Part 1's dynamic descriptor slot, skipping list2.scratch(...) and list2.defer_constants(...).
  • Because list::detach_parts runs Part 1 first (before Part 2's memory wait is satisfied), list::recycle calls list1.reset() (returning Part 1's scratch chunks to the global SPARE pool) or drops Part 1 entirely (when the idle pool is full or VICTORY_LIST_POOL=0) before Part 2 even executes.
  • When Part 2 executes on the GPU, its shader reads either another command list's overwritten constants from the recycled scratch chunk, stale constants from Part 1, or a freed upload buffer GPU VA.

What changed

  • draw::State::replay (third_party/victory/crates/victory-gpu/src/draw.rs): Clear fresh_tables, ready_tables, seen_tables, and window when replaying state onto a new HostList after a cut. Already-allocated dynamic descriptor slots remain tracked in State::dynamic so Part 1's slots stay alive until the last part finishes.
  • draw::State::dispatch (third_party/victory/crates/victory-gpu/src/draw.rs): Call self.after_our_pass(list) instead of self.replay(list) after self.ambient(list, p), since the ambient compute pass runs on the same HostList (preserving fresh_tables for that list while still forcing heaps, root signatures, and PSO to rebind).
  • Synthetic GPU regression tests (third_party/victory/crates/victory-gpu/src/draw/cut_tables_tests.rs): Added three synthetic tests exercising real compute shader CBV reads across a State::replay cut (both when Part 1 recycles its scratch chunk and another list overwrites it with 0xBAD0F00D, and when Part 1 is dropped before Part 2 runs), plus same-list after_our_pass cache preservation.

Reproduction and test results

  • Base commit: 8e32daa (LooperSalty/AnyXboxX:main)
  • Hardware / environment: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2140), Rust 1.98.1.
  • All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (d3d12SDKLayers.dll) is not installed on this machine, so GPU validation checks real shader execution and readback buffers on both RTX 5070 Ti and WARP.

Before fix (base 8e32daa + tests, RTX 5070 Ti)

cargo test --locked -p victory-gpu draw::cut_tables_tests -- --test-threads=1 --nocapture

Result: 1 passed, 2 failed:

  • cut_list_replayed_cbv_table_reads_updated_constants_after_part1_recycles: FAILED — Part 2 reused Part 1's dynamic slot (slot1=64, slot2=64) and the GPU read 0xbad0f00d (from another command list that reused Part 1's pooled scratch chunk) instead of 0x33334444.
  • cut_list_replayed_cbv_table_survives_dropped_part1: FAILED — Part 2 reused Part 1's dynamic slot (slot1=64, slot2=64) and read stale 0xaaaabbbb instead of 0x55667788.

After fix (synthetic tests)

Command Adapter / Mode Result
cargo test --locked -p victory-gpu draw::cut_tables_tests -- --test-threads=1 --nocapture RTX 5070 Ti (default) 3 passed, 0 failed (0.38s)
VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::cut_tables_tests -- --test-threads=1 RTX 5070 Ti (diagnostics) 3 passed, 0 failed (0.33s)
VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::cut_tables_tests -- --test-threads=1 WARP (diagnostics) 3 passed, 0 failed (0.08s)
cargo test --locked -p victory-gpu depth_bounds_pipeline_loads_and_filters_draws -- --test-threads=1 RTX 5070 Ti (existing State::replay GPU test) 1 passed, 0 failed (0.30s)
cargo test --locked -p victory-gpu draw:: -- --test-threads=1 RTX 5070 Ti (all draw tests) 8 passed, 0 failed, 1 ignored (benchmark)
cargo test --locked -p victory-loader --test load_probe Smoke (hle-probe) 2 passed, 0 failed (0.24s)
cargo xtask policy (in third_party/victory) Asset policy asset policy: 216 files ok
cargo clippy --locked -p victory-gpu --tests Clippy 0 warnings in draw.rs and cut_tables_tests.rs

AI assistance

Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code changes, synthetic GPU tests, and local RTX 5070 Ti and WARP runs were inspected and verified on this machine.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:42 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/433) `mauroalvare:fix/victory-cut-replay-fresh-tables` → `main` · +305 −3 · 2 files · 1 commits · open ## Summary Fixes constant-buffer corruption and scratch-buffer lifetime bugs when a title command list is cut onto a new `HostList` (`list::cut` at a memory wait, or `list::value_written` under `VICTORY_CUT_WRITES=1`) and continues recording via `draw::State::replay`. When a descriptor table containing a constant buffer (`View::Constant`) is prepared on Part 1 (`HostList` #1), `State::tables` allocates a dynamic descriptor slot pointing into Part 1's scratch upload buffer (`list1.scratch(...)`), schedules `list1.defer_constants(...)`, and caches that dynamic slot in `State::fresh_tables`. Previously, `State::replay` did not clear `fresh_tables` (nor `ready_tables`, `seen_tables`, or `window`) when switching to Part 2 (`HostList` #2): - Any draw or dispatch in Part 2 using the same CBV descriptor table hit `fresh_tables` and reused Part 1's dynamic descriptor slot, skipping `list2.scratch(...)` and `list2.defer_constants(...)`. - Because `list::detach_parts` runs Part 1 first (before Part 2's memory wait is satisfied), `list::recycle` calls `list1.reset()` (returning Part 1's scratch chunks to the global `SPARE` pool) or drops Part 1 entirely (when the idle pool is full or `VICTORY_LIST_POOL=0`) **before Part 2 even executes**. - When Part 2 executes on the GPU, its shader reads either another command list's overwritten constants from the recycled scratch chunk, stale constants from Part 1, or a freed upload buffer GPU VA. ## What changed - **`draw::State::replay`** (`third_party/victory/crates/victory-gpu/src/draw.rs`): Clear `fresh_tables`, `ready_tables`, `seen_tables`, and `window` when replaying state onto a new `HostList` after a cut. Already-allocated dynamic descriptor slots remain tracked in `State::dynamic` so Part 1's slots stay alive until the last part finishes. - **`draw::State::dispatch`** (`third_party/victory/crates/victory-gpu/src/draw.rs`): Call `self.after_our_pass(list)` instead of `self.replay(list)` after `self.ambient(list, p)`, since the ambient compute pass runs on the **same** `HostList` (preserving `fresh_tables` for that list while still forcing heaps, root signatures, and PSO to rebind). - **Synthetic GPU regression tests** (`third_party/victory/crates/victory-gpu/src/draw/cut_tables_tests.rs`): Added three synthetic tests exercising real compute shader CBV reads across a `State::replay` cut (both when Part 1 recycles its scratch chunk and another list overwrites it with `0xBAD0F00D`, and when Part 1 is dropped before Part 2 runs), plus same-list `after_our_pass` cache preservation. ## Reproduction and test results - **Base commit**: `8e32daa` (`LooperSalty/AnyXboxX:main`) - **Hardware / environment**: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `32.0.16.2140`), Rust `1.98.1`. - All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (`d3d12SDKLayers.dll`) is not installed on this machine, so GPU validation checks real shader execution and readback buffers on both RTX 5070 Ti and WARP. ### Before fix (base `8e32daa` + tests, RTX 5070 Ti) ```powershell cargo test --locked -p victory-gpu draw::cut_tables_tests -- --test-threads=1 --nocapture ``` Result: **1 passed, 2 failed**: - `cut_list_replayed_cbv_table_reads_updated_constants_after_part1_recycles`: **FAILED** — Part 2 reused Part 1's dynamic slot (`slot1=64, slot2=64`) and the GPU read **`0xbad0f00d`** (from another command list that reused Part 1's pooled scratch chunk) instead of **`0x33334444`**. - `cut_list_replayed_cbv_table_survives_dropped_part1`: **FAILED** — Part 2 reused Part 1's dynamic slot (`slot1=64, slot2=64`) and read stale **`0xaaaabbbb`** instead of **`0x55667788`**. ### After fix (synthetic tests) | Command | Adapter / Mode | Result | | --- | --- | --- | | `cargo test --locked -p victory-gpu draw::cut_tables_tests -- --test-threads=1 --nocapture` | RTX 5070 Ti (default) | **3 passed, 0 failed** (0.38s) | | `VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::cut_tables_tests -- --test-threads=1` | RTX 5070 Ti (`diagnostics`) | **3 passed, 0 failed** (0.33s) | | `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::cut_tables_tests -- --test-threads=1` | WARP (`diagnostics`) | **3 passed, 0 failed** (0.08s) | | `cargo test --locked -p victory-gpu depth_bounds_pipeline_loads_and_filters_draws -- --test-threads=1` | RTX 5070 Ti (existing `State::replay` GPU test) | **1 passed, 0 failed** (0.30s) | | `cargo test --locked -p victory-gpu draw:: -- --test-threads=1` | RTX 5070 Ti (all `draw` tests) | **8 passed, 0 failed, 1 ignored** (benchmark) | | `cargo test --locked -p victory-loader --test load_probe` | Smoke (`hle-probe`) | **2 passed, 0 failed** (0.24s) | | `cargo xtask policy` (in `third_party/victory`) | Asset policy | **asset policy: 216 files ok** | | `cargo clippy --locked -p victory-gpu --tests` | Clippy | **0 warnings in `draw.rs` and `cut_tables_tests.rs`** | ## AI assistance Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code changes, synthetic GPU tests, and local RTX 5070 Ti and WARP runs were inspected and verified on this machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:46:55 +00:00
github-bot force-pushed github-bot/gh-433 from a4f706aae8 to 7fa7e26ac1 2026-11-26 19:50:50 +00:00 Compare
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-433'
git switch 'github-bot/gh-433'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-433'
git switch 'github-bot/gh-433'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-433'
git switch 'main'
git merge --squash 'github-bot/gh-433'
git switch 'main'
git merge --ff-only 'github-bot/gh-433'
git switch 'main'
git merge 'github-bot/gh-433'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.