fix(victory-gpu): scope table caches to their heap and binding group #288

Open
github-bot wants to merge 3 commits from github-bot/gh-288 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:16 UTC · original
mauroalvare:fix/victory-ready-tables-cache → main · +50 −7 · 1 files · 3 commits · open

Vice-Tay

Vice-Tay keeps readiness on each table snapshot. Include the host heap ID in the snapshot key and give each compiled binding group a stable identity so a reused plan address cannot inherit a different group's readiness.

Two focused tests cover matching table addresses and contents across different heaps and the identities assigned to successive binding groups.

Earlier Neptune description

Summary

Fixes two descriptor-table caching bugs in third_party/victory/crates/victory-gpu/src/draw.rs (State::tables) that are active under the default Neptune settings (VICTORY_READY_TABLES=1, VICTORY_TABLES_BY_CONTENT=1):

  1. ready_tables ignores which table entries and access kinds a draw actually uses.
    ready_tables was keyed only on (table_or_0, n, descriptor_content_hash). When one pipeline (or one RootIndexedView root-constant value) populates ready_tables for a table of length n while accessing only a subset of its slots, a subsequent draw in the same command list using the same table contents with a different pipeline or root-constant index hits ready_tables and skips readable() for every newly accessed entry:
    • A texture previously in RENDER_TARGET (or another write state) is never transitioned to SHADER_RESOURCE (D3D12 state violation / stale sampling).
    • A newly read buffer SRV never calls shadow.refresh(), so the GPU reads stale/zero bytes.
    • A newly written buffer UAV never calls shadow.gpu_writes(), so GPU writes are silently lost instead of copied back to title memory (and UAV textures are never transitioned to UNORDERED_ACCESS).
  2. fresh_tables (and seen_tables) omit the bound view heap from their key.
    Unlike root_srv_slots and root_uav_slots, fresh_tables did not include the bound descriptor heap pointer in its key. Switching view heaps (SetDescriptorHeaps) within a command list and binding a table with matching (n, content_hash) returned dynamic slot offsets allocated in the previous heap while the new heap's corresponding slots remained unpopulated/null.

What changed

  • Include heap_id = std::ptr::from_ref(heap) as usize in fresh_tables, seen_tables, and ready_tables keys.
  • Key ready_tables on (table_key, usage_hash), where usage_hash hashes the non-CBV (table_offset_dwords, kind) entries from used and the deduplicated selected indices from RootIndexedView that this draw passes to readable(). Repeated draws with the same heap, table contents, and accessed entries keep hitting ready_tables without regression.
  • Added 5 synthetic GPU unit tests in draw::tests covering texture state transition, UAV write-back, RootIndexedView buffer refresh, cross-heap table isolation, and ready_tables cache reuse.

Reproduction and test results

Base commit: c4c93bdc413191a9dc909998d2d53080a3f0c880 (LooperSalty/AnyXboxX:main).
Hardware: 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 VICTORY_D3D12_DEBUG=1 runs without ID3D12InfoQueue validation; all assertions verify real GPU readbacks and HostList resource-state tracking on both RTX 5070 Ti and WARP.

Before fix (base c4c93bdc + the 5 tests, RTX 5070 Ti)

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

Result: 1 passed; 4 failed:

  • fresh_tables_do_not_collide_across_descriptor_heaps: GPU read 0 instead of 0xCAFE_BABE (unpopulated slot in second heap).
  • ready_tables_refreshes_buffer_when_root_indexed_selection_changes: GPU read 0 instead of 0xDEAD_BEEF (shadow.refresh() skipped).
  • ready_tables_tracks_uav_writes_for_newly_used_slot: title memory remained 0 instead of 0x4477_6611 (shadow.gpu_writes() skipped).
  • ready_tables_transitions_texture_newly_read_from_cached_table: tex_a stayed in 0x4 (RENDER_TARGET) instead of 0xc0 (SHADER_RESOURCE).
  • ready_tables_reuses_entry_when_heap_and_usage_match: passed.

After fix

Command Adapter / Mode Result
cargo test --locked -p victory-gpu draw::tests -- --test-threads=1 RTX 5070 Ti (default) 5 passed, 0 failed (0.30s)
VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::tests -- --test-threads=1 RTX 5070 Ti (diagnostics) 5 passed, 0 failed (0.47s)
VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::tests -- --test-threads=1 WARP (diagnostics) 5 passed, 0 failed (0.17s)
cargo test --locked -p victory-loader --test load_probe Smoke (hle-probe) 2 passed, 0 failed (0.75s)
cargo xtask policy (in third_party/victory) Asset policy asset policy: 199 files ok
cargo clippy --locked -p victory-gpu --tests Clippy 0 warnings in draw.rs

Note: running the full cargo test --locked -p victory-gpu -- --test-threads=1 suite passed 188/191 non-ignored tests (including all 5 new draw::tests); 3 pre-existing unrelated tests failed (descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others).

AI assistance

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

Rebase verification

Rebased on c41c224 and kept the indirect routing tests from main. All five descriptor-cache regressions passed.

cargo test --locked --offline -j 5 -p victory-gpu -- --test-threads=1 reported 257 passed, 3 failed, and 4 ignored. Running the same suite on the base reported 252 passed, 3 failed, and 4 ignored. Both runs failed the same assertions in spans_say_the_next_start_and_the_lowest_level_viewed (expected Some(1), got None), warp_card_fetch_copies_flagged_pieces_to_their_slots, and warp_card_patch_writes_the_masked_bytes_and_no_others.

All five descriptor-cache tests also passed with the PR merged into 8e32daa locally, including the off-thread texture preparation from #395.

**@⁠mauroalvare** on GitHub · 2026-11-26 01:16 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/288) `mauroalvare:fix/victory-ready-tables-cache` → `main` · +50 −7 · 1 files · 3 commits · open ## Vice-Tay Vice-Tay keeps readiness on each table snapshot. Include the host heap ID in the snapshot key and give each compiled binding group a stable identity so a reused plan address cannot inherit a different group's readiness. Two focused tests cover matching table addresses and contents across different heaps and the identities assigned to successive binding groups. <details> <summary>Earlier Neptune description</summary> ## Summary Fixes two descriptor-table caching bugs in `third_party/victory/crates/victory-gpu/src/draw.rs` (`State::tables`) that are active under the default Neptune settings (`VICTORY_READY_TABLES=1`, `VICTORY_TABLES_BY_CONTENT=1`): 1. **`ready_tables` ignores which table entries and access kinds a draw actually uses.** `ready_tables` was keyed only on `(table_or_0, n, descriptor_content_hash)`. When one pipeline (or one `RootIndexedView` root-constant value) populates `ready_tables` for a table of length `n` while accessing only a subset of its slots, a subsequent draw in the same command list using the same table contents with a different pipeline or root-constant index hits `ready_tables` and skips `readable()` for every newly accessed entry: - A texture previously in `RENDER_TARGET` (or another write state) is never transitioned to `SHADER_RESOURCE` (`D3D12` state violation / stale sampling). - A newly read buffer SRV never calls `shadow.refresh()`, so the GPU reads stale/zero bytes. - A newly written buffer UAV never calls `shadow.gpu_writes()`, so GPU writes are silently lost instead of copied back to title memory (and UAV textures are never transitioned to `UNORDERED_ACCESS`). 2. **`fresh_tables` (and `seen_tables`) omit the bound view heap from their key.** Unlike `root_srv_slots` and `root_uav_slots`, `fresh_tables` did not include the bound descriptor heap pointer in its key. Switching view heaps (`SetDescriptorHeaps`) within a command list and binding a table with matching `(n, content_hash)` returned dynamic slot offsets allocated in the previous heap while the new heap's corresponding slots remained unpopulated/null. ## What changed - Include `heap_id = std::ptr::from_ref(heap) as usize` in `fresh_tables`, `seen_tables`, and `ready_tables` keys. - Key `ready_tables` on `(table_key, usage_hash)`, where `usage_hash` hashes the non-CBV `(table_offset_dwords, kind)` entries from `used` and the deduplicated `selected` indices from `RootIndexedView` that this draw passes to `readable()`. Repeated draws with the same heap, table contents, and accessed entries keep hitting `ready_tables` without regression. - Added 5 synthetic GPU unit tests in `draw::tests` covering texture state transition, UAV write-back, `RootIndexedView` buffer refresh, cross-heap table isolation, and `ready_tables` cache reuse. ## Reproduction and test results Base commit: `c4c93bdc413191a9dc909998d2d53080a3f0c880` (`LooperSalty/AnyXboxX:main`). Hardware: 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 `VICTORY_D3D12_DEBUG=1` runs without `ID3D12InfoQueue` validation; all assertions verify real GPU readbacks and `HostList` resource-state tracking on both RTX 5070 Ti and WARP. ### Before fix (base `c4c93bdc` + the 5 tests, RTX 5070 Ti) ```powershell cargo test --locked -p victory-gpu draw::tests -- --test-threads=1 ``` Result: **1 passed; 4 failed**: - `fresh_tables_do_not_collide_across_descriptor_heaps`: GPU read `0` instead of `0xCAFE_BABE` (unpopulated slot in second heap). - `ready_tables_refreshes_buffer_when_root_indexed_selection_changes`: GPU read `0` instead of `0xDEAD_BEEF` (`shadow.refresh()` skipped). - `ready_tables_tracks_uav_writes_for_newly_used_slot`: title memory remained `0` instead of `0x4477_6611` (`shadow.gpu_writes()` skipped). - `ready_tables_transitions_texture_newly_read_from_cached_table`: `tex_a` stayed in `0x4` (`RENDER_TARGET`) instead of `0xc0` (`SHADER_RESOURCE`). - `ready_tables_reuses_entry_when_heap_and_usage_match`: passed. ### After fix | Command | Adapter / Mode | Result | | --- | --- | --- | | `cargo test --locked -p victory-gpu draw::tests -- --test-threads=1` | RTX 5070 Ti (default) | **5 passed, 0 failed** (0.30s) | | `VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::tests -- --test-threads=1` | RTX 5070 Ti (`diagnostics`) | **5 passed, 0 failed** (0.47s) | | `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics draw::tests -- --test-threads=1` | WARP (`diagnostics`) | **5 passed, 0 failed** (0.17s) | | `cargo test --locked -p victory-loader --test load_probe` | Smoke (`hle-probe`) | **2 passed, 0 failed** (0.75s) | | `cargo xtask policy` (in `third_party/victory`) | Asset policy | **asset policy: 199 files ok** | | `cargo clippy --locked -p victory-gpu --tests` | Clippy | **0 warnings in `draw.rs`** | Note: running the full `cargo test --locked -p victory-gpu -- --test-threads=1` suite passed 188/191 non-ignored tests (including all 5 new `draw::tests`); 3 pre-existing unrelated tests failed (`descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`). ## AI assistance Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code, synthetic tests, and local GPU/WARP runs were inspected and verified on this machine. ## Rebase verification Rebased on `c41c224` and kept the indirect routing tests from main. All five descriptor-cache regressions passed. `cargo test --locked --offline -j 5 -p victory-gpu -- --test-threads=1` reported 257 passed, 3 failed, and 4 ignored. Running the same suite on the base reported 252 passed, 3 failed, and 4 ignored. Both runs failed the same assertions in `spans_say_the_next_start_and_the_lowest_level_viewed` (expected `Some(1)`, got `None`), `warp_card_fetch_copies_flagged_pieces_to_their_slots`, and `warp_card_patch_writes_the_masked_bytes_and_no_others`. All five descriptor-cache tests also passed with the PR merged into `8e32daa` locally, including the off-thread texture preparation from #395. </details>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:03 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 14:01 UTC · original

This PR now conflicts with main in third_party/victory/crates/victory-gpu/src/draw.rs. Please rebase on main, re-check the change against the current code there, run cargo test for the crate and force-push your branch.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 14:01 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/288#issuecomment-7194171697) This PR now conflicts with main in `third_party/victory/crates/victory-gpu/src/draw.rs`. Please rebase on main, re-check the change against the current code there, run `cargo test` for the crate and force-push your branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot force-pushed github-bot/gh-288 from 5a28a7516a to 822b369236 2026-11-26 18:10:38 +00:00 Compare
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 18:25 UTC · original

I rebased and pushed the descriptor-cache fix, keeping the indirect-routing tests from main. All five cache regressions also passed with the branch merged locally into 8e32daa, including #395's off-thread texture preparation.

The full local victory-gpu run reported 257 passed and three failures. Those same three failures reproduced on the base: one descriptor-span test and two WARP indirect-copy tests.

The latest CI run passed.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:25 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/288#issuecomment-7200437533) I rebased and pushed the descriptor-cache fix, keeping the indirect-routing tests from main. All five cache regressions also passed with the branch merged locally into `8e32daa`, including #395's off-thread texture preparation. The full local `victory-gpu` run reported 257 passed and three failures. Those same three failures reproduced on the base: one descriptor-span test and two WARP indirect-copy tests. [The latest CI run passed](https://github.com/LooperSalty/AnyXboxX/actions/runs/45873040283).
github-bot force-pushed github-bot/gh-288 from 822b369236 to b806f3ebbf 2026-11-26 19:51:00 +00:00 Compare
github-bot changed title from fix(victory-gpu): key fresh_tables by view heap and ready_tables by accessed entries to fix(victory-gpu): scope table caches to their heap and binding group 2026-11-27 00:37:13 +00:00
github-bot force-pushed github-bot/gh-288 from b806f3ebbf to cd720c92b6 2026-11-27 00:37:16 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/288/head:github-bot/gh-288'
git switch 'github-bot/gh-288'

Merge

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