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

Open
superhero-520 wants to merge 1 commit from upstream-pr/2038 into main
superhero-520 commented 2026-11-29 08:06:42 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by superhero-520 on 2026-11-29T08:06:42Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5548873410 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038). Originally posted by [superhero-520](https://github.com/superhero-520) on 2026-11-29T08:06:42Z. --- ## 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.
tyr0nsur commented 2026-11-30 06:35:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T06:35:37Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7270807317 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038#issuecomment-7270807317). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T06:35:37Z. --- 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.
tyr0nsur commented 2026-11-30 09:42:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T09:42:26Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7274575247 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2038#issuecomment-7274575247). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T09:42:26Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2038:upstream-pr/2038'
git switch 'upstream-pr/2038'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2038'
git switch 'upstream-pr/2038'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2038'
git switch 'upstream-pr/2038'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2038'
git switch 'main'
git merge --squash 'upstream-pr/2038'
git switch 'main'
git merge --ff-only 'upstream-pr/2038'
git switch 'main'
git merge 'upstream-pr/2038'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!2038
No description provided.