perf(victory): evict LRU staging upload buffers across size classes and trim idle pool RAM #289

Manually merged
github merged 1 commit from github-bot/gh-289 into main 2026-11-26 14:23:02 +00:00 AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:23 UTC · original
mauroalvare:perf/victory-stage-pool-lru → main · +424 −47 · 1 files · 1 commits · merged 2026-11-26 14:21 UTC

## Change

In third_party/victory/crates/victory-gpu/src/texture.rs, STAGE_POOL (VICTORY_STAGE_POOL_MB, 256 MiB by default) caches freed D3D12 texture staging upload buffers by power-of-two size class, but had three streaming/RAM issues:

  1. Size-class starvation: Staging::drop only cached a returned buffer when pool.bytes + size <= most. Once an earlier streaming phase filled the pool cap with one size class (e.g., 4 MiB textures), subsequent streaming of another size class (e.g., 1 MiB textures) could never enter the pool — hitting 0% pool reuse and issuing CreateCommittedResource + Release for every single texture upload.
  2. No idle RAM reclamation: texture::let_go_idle() dropped idle Staging entries under RAM pressure, whose Drop pushed their upload buffers directly into STAGE_POOL, where they remained pinned permanently without ever being trimmed.
  3. Redundant write-combined zeroing: stage_buffer() zeroed the full power-of-two class capacity size (up to 2× bytes) instead of the actual GetCopyableFootprints extent bytes ([0..bytes)), writing unnecessary zeros over write-combined upload memory past the last subresource footprint.

This change:

  • Switches each StagePool size class to a VecDeque with monotonic return sequence numbers and moment timestamps, evicting the globally least-recently-used cached buffer(s) across all size classes when returning a buffer that fits within the cap (size <= most), and dropping evicted ID3D12Resources outside the pool mutex.
  • Trims idle cached buffers from STAGE_POOL in texture::let_go_idle() using the same ram_idle_ms / IDLE_FRAMES thresholds as STAGING.
  • Zeros only [0..bytes) on pool reuse (preventing stale texture data while avoiding redundant writes to the unused power-of-two tail [bytes..size)).
  • Leaves stage_pool_most() untouched to avoid conflicts with PR #256.

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880
GPU: NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver 32.0.16.2140), --release build, same machine and driver.

Synthetic multi-phase streaming benchmark (texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle: 32 MiB pool filled by 8 × 4 MiB Phase-1 buffers, then 200 sequential 600 KiB / 1 MiB-class Phase-2 uploads, plus 1.1 MiB reuse of a 2 MiB buffer with 512×512 RGBA8 GPU upload + readback verification, plus idle trim):

Metric Base (c4c93bd) Fix (47b02cb)
Phase-2 pool hits (200 uploads) 0 / 200 (0%) 199 / 200 (99.5%)
Phase-2 CreateCommittedResource upload allocs 200 1 (-99.5%)
Phase-2 elapsed time (--release, RTX 5070 Ti) 85.37 ms 5.82–7.34 ms (~11.6–14.7× faster)
Unused tail [bytes..size) on 1.1 MiB in 2 MiB buffer Zeroed redundantly (946,176 B extra WC writes) Untouched ([0..bytes) still zeroed; 512×512 RGBA8 GPU readback matches)
Cached upload RAM after idle trim 32 MiB pinned indefinitely 0 MiB (28 MiB trimmed first for stale Phase-1, then 1 MiB Phase-2)

Commands run from third_party/victory (Rust 1.98.1):

cargo test --locked --release -p victory-gpu --lib texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle -- --exact --nocapture  → 1 passed; 0 failed (1.46s)
cargo test --locked -p victory-gpu --lib texture::                                                                                                            → 5 passed; 0 failed (1.46s)
cargo test --locked -p victory-gpu --features diagnostics --lib texture::                                                                                     → 5 passed; 0 failed (1.43s)
cargo clippy --locked -p victory-gpu --tests                                                                                                                  → 0 warnings in victory-gpu/src/texture.rs
cargo xtask policy                                                                                                                                            → asset policy: 199 files ok

Note: Python tests (pytest / ruff) were not modified because this PR only touches third_party/victory.

Oracle and test data

  • Synthetic multi-phase D3D12 upload buffer workload and 512×512 RGBA8 GPU upload + readback test built in texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle on the local RTX 5070 Ti.
  • Failure case on base (c4c93bd with VICTORY_STAGE_POOL_MB=32): fails with hits=0 made=200 elapsed_ms=85.37 and tail_untouched=false.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: no test count hundred crossed / no README change needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic D3D12 streaming workload).
  • Code taken from another project: none.

Made with AI assistance (Antigravity / Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-26 01:23 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/289) `mauroalvare:perf/victory-stage-pool-lru` → `main` · +424 −47 · 1 files · 1 commits · merged 2026-11-26 14:21 UTC ## Change In `third_party/victory/crates/victory-gpu/src/texture.rs`, `STAGE_POOL` (`VICTORY_STAGE_POOL_MB`, 256 MiB by default) caches freed D3D12 texture staging upload buffers by power-of-two size class, but had three streaming/RAM issues: 1. **Size-class starvation**: `Staging::drop` only cached a returned buffer when `pool.bytes + size <= most`. Once an earlier streaming phase filled the pool cap with one size class (e.g., 4 MiB textures), subsequent streaming of another size class (e.g., 1 MiB textures) could never enter the pool — hitting 0% pool reuse and issuing `CreateCommittedResource` + `Release` for every single texture upload. 2. **No idle RAM reclamation**: `texture::let_go_idle()` dropped idle `Staging` entries under RAM pressure, whose `Drop` pushed their upload buffers directly into `STAGE_POOL`, where they remained pinned permanently without ever being trimmed. 3. **Redundant write-combined zeroing**: `stage_buffer()` zeroed the full power-of-two class capacity `size` (up to 2× `bytes`) instead of the actual `GetCopyableFootprints` extent `bytes` (`[0..bytes)`), writing unnecessary zeros over write-combined upload memory past the last subresource footprint. This change: - Switches each `StagePool` size class to a `VecDeque` with monotonic return sequence numbers and `moment` timestamps, evicting the globally least-recently-used cached buffer(s) across all size classes when returning a buffer that fits within the cap (`size <= most`), and dropping evicted `ID3D12Resource`s outside the pool mutex. - Trims idle cached buffers from `STAGE_POOL` in `texture::let_go_idle()` using the same `ram_idle_ms` / `IDLE_FRAMES` thresholds as `STAGING`. - Zeros only `[0..bytes)` on pool reuse (preventing stale texture data while avoiding redundant writes to the unused power-of-two tail `[bytes..size)`). - Leaves `stage_pool_most()` untouched to avoid conflicts with PR #256. ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` GPU: `NVIDIA GeForce RTX 5070 Ti` (15995 MiB VRAM, driver `32.0.16.2140`), `--release` build, same machine and driver. Synthetic multi-phase streaming benchmark (`texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle`: 32 MiB pool filled by 8 × 4 MiB Phase-1 buffers, then 200 sequential 600 KiB / 1 MiB-class Phase-2 uploads, plus 1.1 MiB reuse of a 2 MiB buffer with 512×512 RGBA8 GPU upload + readback verification, plus idle trim): | Metric | Base (`c4c93bd`) | Fix (`47b02cb`) | | --- | --- | --- | | Phase-2 pool hits (200 uploads) | `0 / 200` (0%) | `199 / 200` (99.5%) | | Phase-2 `CreateCommittedResource` upload allocs | `200` | `1` (-99.5%) | | Phase-2 elapsed time (`--release`, RTX 5070 Ti) | `85.37 ms` | `5.82–7.34 ms` (~11.6–14.7× faster) | | Unused tail `[bytes..size)` on 1.1 MiB in 2 MiB buffer | Zeroed redundantly (`946,176 B` extra WC writes) | Untouched (`[0..bytes)` still zeroed; 512×512 RGBA8 GPU readback matches) | | Cached upload RAM after idle trim | `32 MiB` pinned indefinitely | `0 MiB` (`28 MiB` trimmed first for stale Phase-1, then `1 MiB` Phase-2) | Commands run from `third_party/victory` (Rust `1.98.1`): ``` cargo test --locked --release -p victory-gpu --lib texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle -- --exact --nocapture → 1 passed; 0 failed (1.46s) cargo test --locked -p victory-gpu --lib texture:: → 5 passed; 0 failed (1.46s) cargo test --locked -p victory-gpu --features diagnostics --lib texture:: → 5 passed; 0 failed (1.43s) cargo clippy --locked -p victory-gpu --tests → 0 warnings in victory-gpu/src/texture.rs cargo xtask policy → asset policy: 199 files ok ``` Note: Python tests (`pytest` / `ruff`) were not modified because this PR only touches `third_party/victory`. ## Oracle and test data - Synthetic multi-phase D3D12 upload buffer workload and 512×512 RGBA8 GPU upload + readback test built in `texture::stage_pool_tests::stage_pool_evicts_lru_across_size_classes_and_trims_idle` on the local RTX 5070 Ti. - Failure case on base (`c4c93bd` with `VICTORY_STAGE_POOL_MB=32`): fails with `hits=0 made=200 elapsed_ms=85.37` and `tail_untouched=false`. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: no test count hundred crossed / no README change needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic D3D12 streaming workload). - [x] Code taken from another project: none. Made with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:05 +00:00
github manually merged commit 887b89e8fa into main 2026-11-26 14:23:02 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.