victory-gpu: drop idle TEXTURES and SMALL pool spares over VRAM budget and critical commit #2038

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

@⁠superhero-520 on GitHub · 2026-11-29 08:06 UTC · original
superhero-520:fix/pool-zero-spare-over-budget → main · +649 −39 · 1 files · 1 commits · open

Summary

Rebased cleanly onto v2026.11.29.05 (41adb551), reusing upstream SPARES, Pool::with_budget, STAGING_SPARES, and BUFFER_SPARES, while closing the remaining over-budget / critical-commit spare-heap retention gaps for both TEXTURES and SMALL dedicated-VRAM texture pools.

Root Cause

  • Under v2026.11.29.05, SPARES defaults to 2 (128 MiB of 64 MiB ID3D12Heap blocks per pool) and only shrinks when residency::pressured() is true (1 spare = 64 MiB per pool) or via explicit VICTORY_TEXTURE_SPARES=0.
  • When dedicated DXGI VRAM usage meets or exceeds the adapter budget (used >= budget, common on 6 GiB GPUs such as RTX 3060 Laptop with a ~4.7–5.2 GiB local budget) or OS commit hits residency::critical_commit(), empty 64 MiB heaps in TEXTURES (and SMALL, when enabled) remain retained instead of being returned to D3D12/WDDM.
  • When VICTORY_RIPE_BLOCKS is enabled, Ripe also continued pre-allocating ahead heaps while VRAM was over budget.
  • Finally, trimming empty heaps inside the pool mutex previously dropped D3D12 COM heap objects while holding the lock.

Scope & SMALL Pool Activation Notes

  • By default, apps/victory/src/play.rs sets VICTORY_POOL_SMALL=0, so SMALL allocates 0 heaps in default configurations; the maximum empty-spare ceiling under default settings is 2 × 64 MiB = 128 MiB in TEXTURES alone.
  • When VICTORY_POOL_SMALL=1 (or unset outside play), SMALL also allocates 64 MiB ID3D12Heaps for 4 KiB-aligned small textures and shares SPARES with TEXTURES (combined empty-spare ceiling 256 MiB).
  • These numbers represent logical upper bounds on retained empty pool heaps, not guaranteed real-world physical VRAM savings (actual physical VRAM reduction depends on whether empty 64 MiB heaps exist at the moment pressure occurs and on OS/WDDM residency).

Fix Design (crates/victory-gpu/src/pool.rs)

  1. VRAM-tight hysteresis + critical-commit zero-spare limit (TEXTURES & SMALL):
    • Added VRAM_TIGHT / next_vram_tight() latching at used >= budget and clearing only below 95% of budget to prevent release/reallocate oscillation near the budget boundary.
    • texture_spare_limit() returns 0 when residency::critical_commit() || vram_tight, 1 under host memory pressure (matching upstream), and normal SPARES otherwise — applied to both TEXTURES and SMALL while leaving host-side STAGING and BUFFER spare budgets unaffected by local VRAM pressure.
  2. Reuse-before-trim at limit == 0 (no thrashing):
    • Split reclaim() into release_ready() (GPU-fence-safe retirement after REST frames) and trim_empty() -> Vec<B>.
    • In Pool::cut(), a newly retired empty block is reused first (composing with upstream fullest_first()) before any excess empty blocks are trimmed.
  3. Lock-free COM drops:
    • room() and take_from_with_growth() collect evicted Vec<B> under the mutex and drop the D3D12 heaps outside the lock.
  4. Over-budget ahead-heap guard:
    • Separated Ripe.prefer_ripe from Ripe.ahead so VICTORY_RIPE_BLOCKS stops spawning speculative ahead heaps when VRAM is tight or commit is critical.

Verification & Results

Automated & Real D3D12 Tests (RTX 3060 Laptop 6 GiB, Windows 11, D3D12 debug layer)

  • cargo test --locked -p victory-gpu --lib pool::tests:: -- --nocapture --test-threads=1: 36 passed, 0 failed, 3 ignored (0.69s):
    • d3d12_over_budget_and_critical_commit_reclaim_textures_and_small_pools: TEXTURES retained heaps 3 (192 MiB, empty=2) -> 1 (64 MiB, empty=0); reuse-at-zero new heaps = 0; cross-pool critical commit (TEXTURES + SMALL, 4KiB_small_align=true): empty after = 0 + 0; debug layer errors: None.
    • d3d12_over_budget_ripe_blocks_stops_ahead_heap_allocations: ahead heaps 1 (retained=2, 128 MiB) -> 0 (retained=1, 64 MiB).
    • d3d12_concurrent_zero_spare_allocation_and_reclaim_is_safe: 4 threads × 16 placements, drained cleanly to 0 after REST, debug layer errors: None.
  • cargo clippy --locked -p victory-gpu --all-targets & --all-features: 0 warnings in pool.rs.
  • cargo check --profile diag --locked -p victory --features diagnostics, cargo test --locked -p victory, cargo build --release --locked -p victory, cargo run --locked -p xtask -- policy --staged: all passed.
  • Note on full victory-gpu --lib suite: 928 passed, 2 pre-existing unrelated failures already present on untouched 41adb551 (shared_root_signatures_load_from_library_and_execute_across_pso_switches missing dxcompiler.dll in test CWD, and every_switch_of_the_translator_is_in_the_key stale VICTORY_SCALAR_SPLITS).

Live Gameplay Smoke & Regression Check (RTX 3060 Laptop 6 GiB + Ryzen 7 5800H + 16 GB RAM)

  • Config: Series S, internal 960×540 -> DLSS Performance (Model K) -> output 1920×1080, RT OFF, warm pipeline library (4,972 loaded, 0 in-world slow loads).
  • FG OFF (D1): 5.86 FPS (log 6.61 FPS), 0 OOM, 0 device-removed; combined with PR #2015 (E1): 6.63 FPS (1% Low 2.10, P99 391.4 ms), 0 OOM, 0 device-removed (baseline v2026.11.29.05 3-run mean: 5.68 FPS).
  • FSR 3 2X (D-fsr2 & E-fsr2): FSR 3 swap chain active with 0 failed prepare dispatches, 0 OOM, 0 device-removed; E-fsr2 matched baseline rendered FPS (6.62 vs 6.61 FPS) with lower P99 (386.0 vs 460.6 ms).

Limitations & Known Risks

  • Short 72-second single-area live benchmark runs primarily stream textures in without emptying whole 64 MiB texture heaps; live multi-area open-world soak testing (30+ minutes) to measure real-world empty-heap reclamation frequency and long-session stability is still in progress.
  • Zero OOM / zero TDR in short benchmark runs does not prove all OOM/TDR crashes are eliminated on 6 GiB GPUs.
  • Dropping empty heaps under sustained over-budget pressure means that if VRAM pressure fluctuates around 95%–100% and a burst later requires a brand-new 64 MiB heap, D3D12 heap creation will be paid once (mitigated by the 95% hysteresis band and reuse-before-trim).

AI Assistance Disclosure

AI-Assisted: Rebased, refined, tested, and documented with AI assistance (Antigravity / Gemini), with all D3D12 tests, clippy/policy checks, and live hardware runs verified on local RTX 3060 Laptop hardware.

**@⁠superhero-520** on GitHub · 2026-11-29 08:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038) `superhero-520:fix/pool-zero-spare-over-budget` → `main` · +649 −39 · 1 files · 1 commits · open ## Summary Rebased cleanly onto `v2026.11.29.05` (`41adb551`), reusing upstream `SPARES`, `Pool::with_budget`, `STAGING_SPARES`, and `BUFFER_SPARES`, while closing the remaining over-budget / critical-commit spare-heap retention gaps for both `TEXTURES` and `SMALL` dedicated-VRAM texture pools. ## Root Cause - Under `v2026.11.29.05`, `SPARES` defaults to `2` (128 MiB of 64 MiB `ID3D12Heap` blocks per pool) and only shrinks when `residency::pressured()` is true (`1` spare = 64 MiB per pool) or via explicit `VICTORY_TEXTURE_SPARES=0`. - When dedicated DXGI VRAM usage meets or exceeds the adapter budget (`used >= budget`, common on 6 GiB GPUs such as RTX 3060 Laptop with a ~4.7–5.2 GiB local budget) or OS commit hits `residency::critical_commit()`, empty 64 MiB heaps in `TEXTURES` (and `SMALL`, when enabled) remain retained instead of being returned to D3D12/WDDM. - When `VICTORY_RIPE_BLOCKS` is enabled, `Ripe` also continued pre-allocating ahead heaps while VRAM was over budget. - Finally, trimming empty heaps inside the pool mutex previously dropped D3D12 COM heap objects while holding the lock. ### Scope & `SMALL` Pool Activation Notes - By default, `apps/victory/src/play.rs` sets `VICTORY_POOL_SMALL=0`, so `SMALL` allocates 0 heaps in default configurations; the maximum empty-spare ceiling under default settings is `2 × 64 MiB = 128 MiB` in `TEXTURES` alone. - When `VICTORY_POOL_SMALL=1` (or unset outside `play`), `SMALL` also allocates 64 MiB `ID3D12Heap`s for 4 KiB-aligned small textures and shares `SPARES` with `TEXTURES` (combined empty-spare ceiling `256 MiB`). - These numbers represent **logical upper bounds on retained empty pool heaps**, **not** guaranteed real-world physical VRAM savings (actual physical VRAM reduction depends on whether empty 64 MiB heaps exist at the moment pressure occurs and on OS/WDDM residency). ## Fix Design (`crates/victory-gpu/src/pool.rs`) 1. **VRAM-tight hysteresis + critical-commit zero-spare limit (`TEXTURES` & `SMALL`)**: - Added `VRAM_TIGHT` / `next_vram_tight()` latching at `used >= budget` and clearing only below `95%` of budget to prevent release/reallocate oscillation near the budget boundary. - `texture_spare_limit()` returns `0` when `residency::critical_commit() || vram_tight`, `1` under host memory pressure (matching upstream), and normal `SPARES` otherwise — applied to both `TEXTURES` and `SMALL` while leaving host-side `STAGING` and `BUFFER` spare budgets unaffected by local VRAM pressure. 2. **Reuse-before-trim at `limit == 0` (no thrashing)**: - Split `reclaim()` into `release_ready()` (GPU-fence-safe retirement after `REST` frames) and `trim_empty() -> Vec<B>`. - In `Pool::cut()`, a newly retired empty block is reused first (composing with upstream `fullest_first()`) before any excess empty blocks are trimmed. 3. **Lock-free COM drops**: - `room()` and `take_from_with_growth()` collect evicted `Vec<B>` under the mutex and drop the D3D12 heaps outside the lock. 4. **Over-budget ahead-heap guard**: - Separated `Ripe.prefer_ripe` from `Ripe.ahead` so `VICTORY_RIPE_BLOCKS` stops spawning speculative ahead heaps when VRAM is tight or commit is critical. ## Verification & Results ### Automated & Real D3D12 Tests (RTX 3060 Laptop 6 GiB, Windows 11, D3D12 debug layer) - `cargo test --locked -p victory-gpu --lib pool::tests:: -- --nocapture --test-threads=1`: **36 passed, 0 failed, 3 ignored** (`0.69s`): - `d3d12_over_budget_and_critical_commit_reclaim_textures_and_small_pools`: `TEXTURES` retained heaps `3 (192 MiB, empty=2)` -> `1 (64 MiB, empty=0)`; reuse-at-zero new heaps `= 0`; cross-pool critical commit (`TEXTURES + SMALL`, `4KiB_small_align=true`): empty after `= 0 + 0`; debug layer errors: `None`. - `d3d12_over_budget_ripe_blocks_stops_ahead_heap_allocations`: ahead heaps `1 (retained=2, 128 MiB)` -> `0 (retained=1, 64 MiB)`. - `d3d12_concurrent_zero_spare_allocation_and_reclaim_is_safe`: 4 threads × 16 placements, drained cleanly to 0 after `REST`, debug layer errors: `None`. - `cargo clippy --locked -p victory-gpu --all-targets` & `--all-features`: **0 warnings in `pool.rs`**. - `cargo check --profile diag --locked -p victory --features diagnostics`, `cargo test --locked -p victory`, `cargo build --release --locked -p victory`, `cargo run --locked -p xtask -- policy --staged`: all passed. - Note on full `victory-gpu --lib` suite: 928 passed, 2 pre-existing unrelated failures already present on untouched `41adb551` (`shared_root_signatures_load_from_library_and_execute_across_pso_switches` missing `dxcompiler.dll` in test CWD, and `every_switch_of_the_translator_is_in_the_key` stale `VICTORY_SCALAR_SPLITS`). ### Live Gameplay Smoke & Regression Check (RTX 3060 Laptop 6 GiB + Ryzen 7 5800H + 16 GB RAM) - Config: Series S, internal `960×540` -> DLSS Performance (Model K) -> output `1920×1080`, RT OFF, warm pipeline library (`4,972` loaded, `0` in-world slow loads). - **FG OFF (`D1`)**: `5.86 FPS` (`log 6.61 FPS`), 0 OOM, 0 device-removed; combined with PR #2015 (`E1`): `6.63 FPS` (`1% Low 2.10`, `P99 391.4 ms`), 0 OOM, 0 device-removed (baseline `v2026.11.29.05` 3-run mean: `5.68 FPS`). - **FSR 3 2X (`D-fsr2` & `E-fsr2`)**: FSR 3 swap chain active with `0` failed prepare dispatches, `0` OOM, `0` device-removed; `E-fsr2` matched baseline rendered FPS (`6.62` vs `6.61 FPS`) with lower P99 (`386.0` vs `460.6 ms`). ## Limitations & Known Risks - Short 72-second single-area live benchmark runs primarily stream textures *in* without emptying whole 64 MiB texture heaps; live multi-area open-world soak testing (30+ minutes) to measure real-world empty-heap reclamation frequency and long-session stability is still in progress. - Zero OOM / zero TDR in short benchmark runs does **not** prove all OOM/TDR crashes are eliminated on 6 GiB GPUs. - Dropping empty heaps under sustained over-budget pressure means that if VRAM pressure fluctuates around 95%–100% and a burst later requires a brand-new 64 MiB heap, D3D12 heap creation will be paid once (mitigated by the 95% hysteresis band and reuse-before-trim). ## AI Assistance Disclosure AI-Assisted: Rebased, refined, tested, and documented with AI assistance (Antigravity / Gemini), with all D3D12 tests, clippy/policy checks, and live hardware runs verified on local RTX 3060 Laptop hardware.
When DXGI reports VRAM usage at or above budget (`used >= budget`), or when
host commit is critical (`residency::critical_commit()`), `pool::room()` still
retained `SPARE = 2` empty 64 MiB `ID3D12Heap` blocks in `TEXTURES` (up to
128 MiB theoretical idle retention), whereas `STAGING`, `UPLOADS`, and `SHARED`
already dropped to 0 spares under critical commit.

Default vs. non-default `VICTORY_RIPE_BLOCKS` impact:
- Default launcher configuration (`apps/victory/src/play.rs` and
  `scripts/play-foxhound.ps1` set `VICTORY_RIPE_BLOCKS=0`): `short_ahead()` is
  already inactive. The effective change is allowing `TEXTURES` to drop idle
  empty 64 MiB heaps (only after `REST` has elapsed) down to 0 spares when VRAM
  is at/over budget or commit is critical, while reusing a newly rested block
  for an incoming allocation before trimming.
- Non-default configuration (`VICTORY_RIPE_BLOCKS > 0`, or unset env defaulting
  to `12`): driving `TEXTURE_SPARES` to 0 also sets `Ripe.ahead = 0` so
  `short_ahead()` stops pre-allocating new 64 MiB VRAM heaps over budget, while
  `Ripe.prefer_ripe` preserves ripe-block preference and unripe fallback.

Safeguards:
- Keep `TEXTURE_SPARES` separate from host-RAM `SPARES` so VRAM over-budget
  does not force `STAGING`/`UPLOADS`/`SHARED` to 0 spares.
- Add 95% VRAM recovery hysteresis (`VRAM_TIGHT` / `VRAM_RECOVER_PERCENT = 95`,
  ~255 MiB on 6 GiB and ~347 MiB on 8 GiB, wider than 128 MiB) so dropping 2
  empty blocks does not oscillate at the budget boundary.
- Preserve `REST` (2500 ms) protection and never release live or resting pieces.
- In `Pool::cut()` at `limit == 0`, reserve a range for the current allocation
  before trimming remaining empty blocks so newly rested heaps are reused with
  zero destroy-then-recreate thrashing.
- Drop reclaimed `Vec<B>` heaps/buffers outside each pool mutex in `room()` and
  `take_from()`.

Tests:
- Added 4 deterministic policy/pool unit tests and 2 real D3D12 before/after
  comparison tests in `crates/victory-gpu/src/pool.rs` covering both default
  (`VICTORY_RIPE_BLOCKS=0`) and non-default (`VICTORY_RIPE_BLOCKS=4`) paths.

AI-Assisted: Developed and verified with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 08:09:36 +00:00
github-bot changed title from victory-gpu: reclaim idle TEXTURES pool heaps over VRAM budget and critical commit to victory-gpu: drop idle TEXTURES and SMALL pool spares over VRAM budget and critical commit 2026-11-30 05:13:15 +00:00
github-bot force-pushed github-bot/gh-2038 from a0bcf10dfa to b18a0ae668 2026-11-30 05:13:16 +00:00 Compare
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 06:35 UTC · original · edited 2026-11-30 06:47 UTC

I reproduced an in-flight case on b18a0ae. If a texture take starts making an ahead heap, then room() sets the spare limit to zero and finishes its sweep before the driver returns, the take still inserts the newly empty heap. In the deterministic regression the requested piece was valid, but the pool retained one empty block after the zero-spare sweep.

Cherry-pickable fix. It rechecks before asking the driver and checks the pool's current spare limit before keeping the result. At zero it returns the requested piece and releases any completed ahead heap outside the pool mutex. The regression fails with one empty block on the PR head and passes with zero on the fix.

Windows 11, RTX 4060 8 GiB, driver 621.14. The pool test filter reported 37 passed, 0 failed, 3 ignored, including the existing real D3D12 cases. The existing over-budget test dropped its pool footprint from three retained heaps to one (192 → 64 MiB). That is heap accounting in a test with synthetic pressure. Gameplay VRAM and frame times remain unmeasured.

DXGI follow-up: I instrumented the same D3D12 test with #3766 stacked locally. In three fresh processes, DXGI_MEMORY_SEGMENT_GROUP_LOCAL::CurrentUsage fell from 213,327,872 to 79,110,144 bytes immediately after dropping the two heaps (exactly 128 MiB). Usage stayed at that level after 250 ms and 1 s, and the budget was unchanged. The pressure trigger was simulated; the heaps and DXGI queries were real. This measures the driver-reported local usage for that test case. In-game savings still depend on whether whole heaps become empty along the route.

**@⁠tyr0nsur** on GitHub · 2026-11-30 06:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038#issuecomment-7270807317) · edited 2026-11-30 06:47 UTC I reproduced an in-flight case on `b18a0ae`. If a texture take starts making an ahead heap, then `room()` sets the spare limit to zero and finishes its sweep before the driver returns, the take still inserts the newly empty heap. In the deterministic regression the requested piece was valid, but the pool retained one empty block after the zero-spare sweep. [Cherry-pickable fix](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/53e9d893fd0ed123718838d2a95f8fc7d1167565). It rechecks before asking the driver and checks the pool's current spare limit before keeping the result. At zero it returns the requested piece and releases any completed ahead heap outside the pool mutex. The regression fails with one empty block on the PR head and passes with zero on the fix. Windows 11, RTX 4060 8 GiB, driver 621.14. The pool test filter reported 37 passed, 0 failed, 3 ignored, including the existing real D3D12 cases. The existing over-budget test dropped its pool footprint from three retained heaps to one (192 → 64 MiB). That is heap accounting in a test with synthetic pressure. Gameplay VRAM and frame times remain unmeasured. **DXGI follow-up:** I instrumented the same D3D12 test with #3766 stacked locally. In three fresh processes, `DXGI_MEMORY_SEGMENT_GROUP_LOCAL::CurrentUsage` fell from 213,327,872 to 79,110,144 bytes immediately after dropping the two heaps (exactly **128 MiB**). Usage stayed at that level after 250 ms and 1 s, and the budget was unchanged. The pressure trigger was simulated; the heaps and DXGI queries were real. This measures the driver-reported local usage for that test case. In-game savings still depend on whether whole heaps become empty along the route.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 09:42 UTC · original

The same empty heaps can be reclaimed before the full DXGI budget is reached. VICTORY_ROOM_REAL can already stop the texture queue at budget minus 256 MiB. With a synthetic 5,092 MiB budget and 4,882 MiB usage, the current pool policy still retained two empty heaps. The regression failed at that point before the change.

Follow-up cd7d849, stacked on the previously posted 53e9d89 ahead-heap fix, uses the queue’s raw line for entry. Recovery waits until there is room for both pools’ ordinary spares and keeps the existing 95% ceiling. VICTORY_ROOM_REAL=0 retains budget-level entry and the original recovery rule. The texture pools still reclaim only fully empty heaps after the existing retirement delay.

On RTX 4060 the regression dropped two real 64 MiB D3D12 heaps, keeping the live heap. The test process’s DXGI local usage went from 203 to 75 MiB immediately. The pressure input was simulated, and the heaps and driver query were real. The Windows pool/resource suite passed (82 passed, 4 ignored), the three focused tests passed under WARP, and staged asset policy passed. Live benefit depends on how often a route leaves whole heaps empty.

**@⁠tyr0nsur** on GitHub · 2026-11-30 09:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038#issuecomment-7274575247) The same empty heaps can be reclaimed before the full DXGI budget is reached. `VICTORY_ROOM_REAL` can already stop the texture queue at budget minus 256 MiB. With a synthetic 5,092 MiB budget and 4,882 MiB usage, the current pool policy still retained two empty heaps. The regression failed at that point before the change. [Follow-up cd7d849](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/cd7d8492c9be06face910c7f7446cb53029ef6e3), stacked on the previously posted `53e9d89` ahead-heap fix, uses the queue’s raw line for entry. Recovery waits until there is room for both pools’ ordinary spares and keeps the existing 95% ceiling. `VICTORY_ROOM_REAL=0` retains budget-level entry and the original recovery rule. The texture pools still reclaim only fully empty heaps after the existing retirement delay. On RTX 4060 the regression dropped two real 64 MiB D3D12 heaps, keeping the live heap. The test process’s DXGI local usage went from 203 to 75 MiB immediately. The pressure input was simulated, and the heaps and driver query were real. The Windows pool/resource suite passed (82 passed, 4 ignored), the three focused tests passed under WARP, and staged asset policy passed. Live benefit depends on how often a route leaves whole heaps empty.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pool.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/2038/head:github-bot/gh-2038'
git switch 'github-bot/gh-2038'

Merge

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