perf(gpu): cache host root/IA state, drop phantom listed raw twins, and hold List::state per thin chunk #395

Merged
Androtim merged 4 commits from upstream-pr/395 into main 2026-12-03 15:06:19 +00:00
Androtim commented 2026-12-03 13:38:18 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:38:18Z.


Summary

Eliminates three major command-recording and descriptor CPU bottlenecks along the VICTORY_THIN translation path (crates/victory-gpu), cutting per-frame recording thread CPU overhead without altering host GPU rendering semantics:

  1. Per-command-list host root & IA binding cache (crates/victory-gpu/src/rootcache.rs, draw.rs, VICTORY_STATE_CACHE=0 escape hatch)

    • Adds StateCache inside draw::State tracking emitted graphics and compute root bindings (Set*Root32BitConstants, Set*Root32BitConstant, Set*RootConstantBufferView, Set*RootShaderResourceView, Set*RootUnorderedAccessView, Set*RootDescriptorTable) plus input-assembler bindings (IASetPrimitiveTopology, IASetVertexBuffers with minimal changed contiguous range trimming, IASetIndexBuffer).
    • Preserves all resource transitions, shadow.refresh, residency tracking, and indirect batching side effects; invalidates properly across State::reset, State::replay (external passes/list cuts), SetDescriptorHeaps, Set*RootSignature, rectangles() scratch VB swaps, and internal compute passes (ambient, open_batch, indirect bounds clamping).
  2. Skip phantom raw-twin D3D12 descriptor creation in make_listed_batched (crates/victory-gpu/src/descriptor/host.rs)

    • HostHeap::make_listed_batched previously passed Some(views.slot(at + 1)) unconditionally to make_twinned, even when self.twins was empty (raw_twins=false on NVIDIA) or !twinned(&view).
    • On live 4K runs this generated ~27,562 unused raw-twin descriptor creations per frame (twin_window, GetGPUVirtualAddress, CreateShaderResourceView/CreateUnorderedAccessView/null_buffer_view) whose output slot was never copied (if made.twin && twins).
    • Now passes listed_twin_slot(twin, twins, views.slot(at + 1)) (None when !twins or !twin), while lazily populating ListView::twin_made if a cached view record is ever reused on a heap with twins.
  3. Chunk-scoped List::state lock holding in thin::translate (crates/victory-gpu/src/list.rs, list/thin.rs)

    • Adds StateHold (HELD_STATE TLS) around each thin::translate chunk (~65k calls/frame) and routes with_state_on and list replay (cut, write_value) through with_locked_state, removing per-call Mutex<draw::State> lock/unlock churn across translated commands while staying panic- and re-entrancy-safe.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu test --workspace -- --test-threads=1 (victory-gpu: 845 passed, 0 failed, 39 ignored; victory-hle: 249 passed, 0 failed, 3 ignored; apps/victory: 47 passed + 2 census passed; victory-core: 15 passed; victory-formats: 69 passed, 7 ignored; victory-game: 3 passed; victory-loader --lib: 63 passed + 1 no_dll_planting; note victory-loader --test load_probe failed on MinGW ld.exe due to MSVC /DELAYLOAD: flag)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-pe -p victory-pipeline -p xtask --locked (victory-pe: 36 passed; victory-pipeline: 13 passed; xtask: 8 passed including policy::tests::repository_passes_policy)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1 (905 passed, 1 failed timeline::report::tests::real_waits_are_recorded_with_who_ended_them on MinGW symbol lookup, 40 ignored; includes unit tests for rootcache, listed_views_skip_raw_twin_when_heap_has_no_twins, and state_hold_reuses_held_mutex_across_calls_and_releases_on_drop)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings (passed)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features --locked -- -D warnings (passed)
<!-- greyfinch-sync:Androtim/MiniVI:issue:5627605110 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/395). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:38:18Z. --- ## Summary Eliminates three major command-recording and descriptor CPU bottlenecks along the `VICTORY_THIN` translation path (`crates/victory-gpu`), cutting per-frame recording thread CPU overhead without altering host GPU rendering semantics: 1. **Per-command-list host root & IA binding cache (`crates/victory-gpu/src/rootcache.rs`, `draw.rs`, `VICTORY_STATE_CACHE=0` escape hatch)** - Adds `StateCache` inside `draw::State` tracking emitted graphics and compute root bindings (`Set*Root32BitConstants`, `Set*Root32BitConstant`, `Set*RootConstantBufferView`, `Set*RootShaderResourceView`, `Set*RootUnorderedAccessView`, `Set*RootDescriptorTable`) plus input-assembler bindings (`IASetPrimitiveTopology`, `IASetVertexBuffers` with minimal changed contiguous range trimming, `IASetIndexBuffer`). - Preserves all resource transitions, `shadow.refresh`, residency tracking, and indirect batching side effects; invalidates properly across `State::reset`, `State::replay` (external passes/list cuts), `SetDescriptorHeaps`, `Set*RootSignature`, `rectangles()` scratch VB swaps, and internal compute passes (`ambient`, `open_batch`, indirect bounds clamping). 2. **Skip phantom raw-twin D3D12 descriptor creation in `make_listed_batched` (`crates/victory-gpu/src/descriptor/host.rs`)** - `HostHeap::make_listed_batched` previously passed `Some(views.slot(at + 1))` unconditionally to `make_twinned`, even when `self.twins` was empty (`raw_twins=false` on NVIDIA) or `!twinned(&view)`. - On live 4K runs this generated ~27,562 unused raw-twin descriptor creations per frame (`twin_window`, `GetGPUVirtualAddress`, `CreateShaderResourceView`/`CreateUnorderedAccessView`/`null_buffer_view`) whose output slot was never copied (`if made.twin && twins`). - Now passes `listed_twin_slot(twin, twins, views.slot(at + 1))` (`None` when `!twins` or `!twin`), while lazily populating `ListView::twin_made` if a cached view record is ever reused on a heap with twins. 3. **Chunk-scoped `List::state` lock holding in `thin::translate` (`crates/victory-gpu/src/list.rs`, `list/thin.rs`)** - Adds `StateHold` (`HELD_STATE` TLS) around each `thin::translate` chunk (~65k calls/frame) and routes `with_state_on` and list `replay` (`cut`, `write_value`) through `with_locked_state`, removing per-call `Mutex<draw::State>` lock/unlock churn across translated commands while staying panic- and re-entrancy-safe. ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu test --workspace -- --test-threads=1` (`victory-gpu`: 845 passed, 0 failed, 39 ignored; `victory-hle`: 249 passed, 0 failed, 3 ignored; `apps/victory`: 47 passed + 2 census passed; `victory-core`: 15 passed; `victory-formats`: 69 passed, 7 ignored; `victory-game`: 3 passed; `victory-loader --lib`: 63 passed + 1 `no_dll_planting`; note `victory-loader --test load_probe` failed on MinGW `ld.exe` due to MSVC `/DELAYLOAD:` flag) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-pe -p victory-pipeline -p xtask --locked` (`victory-pe`: 36 passed; `victory-pipeline`: 13 passed; `xtask`: 8 passed including `policy::tests::repository_passes_policy`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1` (905 passed, 1 failed `timeline::report::tests::real_waits_are_recorded_with_who_ended_them` on MinGW symbol lookup, 40 ignored; includes unit tests for `rootcache`, `listed_views_skip_raw_twin_when_heap_has_no_twins`, and `state_hold_reuses_held_mutex_across_calls_and_releases_on_drop`) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` (passed) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features --locked -- -D warnings` (passed)
Androtim commented 2026-12-03 14:01:50 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T14:01:50Z.


Triage (e1322a6c, CI check PASS):

  • High-leverage Rank #2 recording-thread CPU optimization (+649/-134 across rootcache.rs, draw.rs, descriptor/host.rs, list.rs, list/thin.rs, lib.rs): per-list host root/IA cache (VICTORY_STATE_CACHE=0 kill-switch), skipping ~27.5k/frame phantom listed raw twins, and chunk-scoped List::state. Note file overlap in descriptor/host.rs & draw.rs with #393 (and draw.rs with #394) — merge sequentially once verified.
  • Holding auto-merge for Gate 2 Deep Reasoning Audit (#282) + Gate 3 plain --release A/B vs main (931e127e, 0 crashes/DRED) + --features diagnostics visual check.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7380774101 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/395#issuecomment-7380774101). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T14:01:50Z. --- Triage (`e1322a6c`, **CI `check` PASS**): - High-leverage Rank #2 recording-thread CPU optimization (`+649/-134` across `rootcache.rs`, `draw.rs`, `descriptor/host.rs`, `list.rs`, `list/thin.rs`, `lib.rs`): per-list host root/IA cache (`VICTORY_STATE_CACHE=0` kill-switch), skipping ~27.5k/frame phantom listed raw twins, and chunk-scoped `List::state`. Note file overlap in `descriptor/host.rs` & `draw.rs` with `#393` (and `draw.rs` with `#394`) — merge sequentially once verified. - Holding auto-merge for **Gate 2 Deep Reasoning Audit (`#282`)** + **Gate 3 plain `--release` A/B** vs `main` (`931e127e`, `0` crashes/DRED) + `--features diagnostics` visual check.
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
Androtim/MiniVI!395
No description provided.