victory-gpu: reclaim idle ahead buffers by default under pressure, back off on sustained OOM/device removal, and report buffer OOMs #2015

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

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by superhero-520 on 2026-11-29T07:26:08Z.


Summary

Rebased cleanly onto v2026.11.29.05 (41adb551), reusing upstream first() (residency::scaled_default(..., 512, 4096)), trim_idle(), RetryGate, and uav_buffer_now(), while keeping the remaining valuable reliability fixes for low-RAM / low-VRAM hosts.

Root Cause

  1. Default-path idle ahead buffers never reclaimed once pools are full (crates/victory-gpu/src/ahead.rs):
    • Without opting into VICTORY_LOWSPEC_ADAPTIVE=1, fill() only paused refills under residency::pressured() || critical_commit() — and when both pools were already full (!more_shared && !more_card), it looped at the idle sleep without ever checking memory/VRAM pressure or trimming already-allocated idle buffers.
  2. No clean worker exit on D3D12 device removal (crates/victory-gpu/src/ahead.rs):
    • After DXGI_ERROR_DEVICE_REMOVED / DEVICE_HUNG, fill() kept attempting buffer allocations instead of checking GetDeviceRemovedReason(), releasing idle buffers, and exiting cleanly.
  3. Fixed 50 ms retry cadence under sustained OOM (crates/victory-gpu/src/ahead.rs):
    • Upstream RetryGate caps failure rate at a fixed 50 ms per lane (20 attempts/sec indefinitely during prolonged OOM).
  4. Missing OOM pressure feedback in buffer allocation helpers (crates/victory-gpu/src/host.rs):
    • read_back_buffer, shared_buffer_own, and uav_buffer_now did not notify crate::residency::allocation_error(&e) on E_OUTOFMEMORY.

Re-Evaluated Scope on v2026.11.29.05

  • Upstream 158d3177 lowered the default pre-allocation count on < 24 GiB RAM hosts from 4096 to 512 via residency::scaled_default(..., 512, 4096).
  • Consequently, on 16 GB RAM hosts, the maximum logical idle ahead pool size under default configuration is now 64 MiB (32 MiB shared + 32 MiB card), not the older 512 MiB ceiling (which still applies on >= 24 GiB RAM hosts with low VRAM or commit pressure).
  • Reclaimed logical buffer counts/MiB represent released D3D12 resource objects, not an equivalent guaranteed drop in OS physical RAM or physical VRAM usage.

Fix Design

  • crates/victory-gpu/src/ahead.rs:
    • On every loop iteration in the default path (before checking !more_shared && !more_card), check residency::pressured(), residency::critical_commit(), and DXGI local VRAM usage via next_card_vram_pressure() (enters at >= 85% of budget, clears only at <= 70%, matching card_has_room() to prevent reclaim/rebuild oscillation).
    • Reclaim idle buffers outside each pool mutex via trim_idle() (updated to drop removed resources outside the lock and return the freed count), cap post-reclaim want to KEPT, and log logical_shared_mb / logical_card_mb.
    • Check GetDeviceRemovedReason() on allocation failures, during pressure pauses, and periodically when idle; on removal, drop all idle buffers outside locks and exit fill() cleanly.
    • Extend RetryGate with RetryGate::exponential(50ms, 1000ms) per independent lane (shared_retry, card_retry): escalates 50 -> 100 -> 200 -> 400 -> 800 -> 1000 ms on consecutive failures and is never reset by pressured() / critical_commit() pauses (resolving earlier review feedback), while leaving RetryGate::default() at fixed 50 ms so upstream retry_tests stay 100% unchanged.
  • crates/victory-gpu/src/host.rs:
    • Call crate::residency::allocation_error(&e) in the Err(e) paths of read_back_buffer, shared_buffer_own, and uav_buffer_now (which triggers only on E_OUTOFMEMORY, ignoring device-removed errors).

Verification & Results

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

  • cargo test --locked -p victory-gpu --lib ahead:: -- --nocapture --test-threads=1: 12 passed, 0 failed (0.39s):
    • All 8 upstream ahead tests remain intact and passing.
    • 4 new tests: exponential_retry_gate_backs_off_to_cap_and_survives_pressure_pauses, default_card_vram_pressure_has_hysteresis_aligned_with_card_room, trim_idle_drops_resources_outside_pool_mutex, and d3d12_trim_idle_releases_real_shared_and_card_buffers_cleanly (uses .expect(...) on buffer creation so allocation failures fail the test; debug layer errors: None).
  • cargo clippy --locked -p victory-gpu --all-targets & --all-features: 0 warnings in ahead.rs / modified host.rs lines.
  • 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: 924 passed, 2 pre-existing unrelated failures already present on untouched 41adb551 (shared_root_signatures_load_from_library_and_execute_across_pso_switches and every_switch_of_the_translator_is_in_the_key).

Live Gameplay Validation (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 (0 in-world slow loads).
  • Default-path reclaim observed live on every run containing PR #2015:
    • C1 (FG OFF): reclaimed 512 idle shared buffers (32 MiB logical, matching 16 GB scaled_default=512), 6.17 FPS (1% Low 1.87), 0 OOM / 0 device-removed.
    • E1 (combined with PR #2038, FG OFF): reclaimed 512 shared (32 MiB logical), 6.63 FPS (1% Low 2.10, P99 391.4 ms), 0 OOM / 0 device-removed.
    • G2 (combined with PR #2038 + perf fix, FG OFF): reclaimed 512 shared + 392 card = 904 idle buffers (56.5 MiB logical), 6.47 FPS, 0 OOM / 0 device-removed.
    • C-fsr2 / E-fsr2 (FSR 3 2X): FSR 3 active (0 failed prepare dispatches), 512 shared reclaimed, 0 OOM / 0 device-removed.

Limitations & Known Risks

  • Under default 16 GB RAM settings on v2026.11.29.05, the reclaimed logical volume is bounded by upstream's 512-buffer cap (<= 64 MiB total logical); physical RAM/VRAM savings are modest compared to pre-158d3177 builds, though preventing sustained OOM retry churn and exiting cleanly on device removal apply across all RAM sizes.
  • Short 72-second live benchmark runs with 0 OOM / 0 TDR do not prove long-session (30+ minute) OOM/TDR crashes are eliminated; extended open-world soak testing is in progress.

AI Assistance Disclosure

AI-Assisted: Rebased, refined, tested, and documented with AI assistance (Antigravity / Gemini), with all unit/D3D12 tests and live RTX 3060 hardware runs verified locally.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5548618279 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2015). Originally posted by [superhero-520](https://github.com/superhero-520) on 2026-11-29T07:26:08Z. --- ## Summary Rebased cleanly onto `v2026.11.29.05` (`41adb551`), reusing upstream `first()` (`residency::scaled_default(..., 512, 4096)`), `trim_idle()`, `RetryGate`, and `uav_buffer_now()`, while keeping the remaining valuable reliability fixes for low-RAM / low-VRAM hosts. ## Root Cause 1. **Default-path idle ahead buffers never reclaimed once pools are full (`crates/victory-gpu/src/ahead.rs`)**: - Without opting into `VICTORY_LOWSPEC_ADAPTIVE=1`, `fill()` only paused refills under `residency::pressured() || critical_commit()` — and when both pools were already full (`!more_shared && !more_card`), it looped at the idle sleep without ever checking memory/VRAM pressure or trimming already-allocated idle buffers. 2. **No clean worker exit on D3D12 device removal (`crates/victory-gpu/src/ahead.rs`)**: - After `DXGI_ERROR_DEVICE_REMOVED` / `DEVICE_HUNG`, `fill()` kept attempting buffer allocations instead of checking `GetDeviceRemovedReason()`, releasing idle buffers, and exiting cleanly. 3. **Fixed 50 ms retry cadence under sustained OOM (`crates/victory-gpu/src/ahead.rs`)**: - Upstream `RetryGate` caps failure rate at a fixed 50 ms per lane (20 attempts/sec indefinitely during prolonged OOM). 4. **Missing OOM pressure feedback in buffer allocation helpers (`crates/victory-gpu/src/host.rs`)**: - `read_back_buffer`, `shared_buffer_own`, and `uav_buffer_now` did not notify `crate::residency::allocation_error(&e)` on `E_OUTOFMEMORY`. ### Re-Evaluated Scope on `v2026.11.29.05` - Upstream `158d3177` lowered the default pre-allocation count on `< 24 GiB` RAM hosts from `4096` to `512` via `residency::scaled_default(..., 512, 4096)`. - Consequently, on 16 GB RAM hosts, the maximum **logical** idle ahead pool size under default configuration is now **64 MiB** (`32 MiB` shared + `32 MiB` card), not the older `512 MiB` ceiling (which still applies on `>= 24 GiB` RAM hosts with low VRAM or commit pressure). - Reclaimed logical buffer counts/MiB represent **released D3D12 resource objects**, **not** an equivalent guaranteed drop in OS physical RAM or physical VRAM usage. ## Fix Design - **`crates/victory-gpu/src/ahead.rs`**: - On every loop iteration in the default path (before checking `!more_shared && !more_card`), check `residency::pressured()`, `residency::critical_commit()`, and DXGI local VRAM usage via `next_card_vram_pressure()` (enters at `>= 85%` of budget, clears only at `<= 70%`, matching `card_has_room()` to prevent reclaim/rebuild oscillation). - Reclaim idle buffers outside each pool mutex via `trim_idle()` (updated to drop removed resources outside the lock and return the freed count), cap post-reclaim `want` to `KEPT`, and log `logical_shared_mb` / `logical_card_mb`. - Check `GetDeviceRemovedReason()` on allocation failures, during pressure pauses, and periodically when idle; on removal, drop all idle buffers outside locks and exit `fill()` cleanly. - Extend `RetryGate` with `RetryGate::exponential(50ms, 1000ms)` per independent lane (`shared_retry`, `card_retry`): escalates `50 -> 100 -> 200 -> 400 -> 800 -> 1000 ms` on consecutive failures and is **never reset by `pressured()` / `critical_commit()` pauses** (resolving earlier review feedback), while leaving `RetryGate::default()` at fixed 50 ms so upstream `retry_tests` stay 100% unchanged. - **`crates/victory-gpu/src/host.rs`**: - Call `crate::residency::allocation_error(&e)` in the `Err(e)` paths of `read_back_buffer`, `shared_buffer_own`, and `uav_buffer_now` (which triggers only on `E_OUTOFMEMORY`, ignoring device-removed errors). ## Verification & Results ### Automated & Real D3D12 Tests (RTX 3060 Laptop 6 GiB, Windows 11) - `cargo test --locked -p victory-gpu --lib ahead:: -- --nocapture --test-threads=1`: **12 passed, 0 failed** (`0.39s`): - All 8 upstream `ahead` tests remain intact and passing. - 4 new tests: `exponential_retry_gate_backs_off_to_cap_and_survives_pressure_pauses`, `default_card_vram_pressure_has_hysteresis_aligned_with_card_room`, `trim_idle_drops_resources_outside_pool_mutex`, and `d3d12_trim_idle_releases_real_shared_and_card_buffers_cleanly` (uses `.expect(...)` on buffer creation so allocation failures fail the test; debug layer errors: `None`). - `cargo clippy --locked -p victory-gpu --all-targets` & `--all-features`: **0 warnings in `ahead.rs` / modified `host.rs` lines**. - `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: 924 passed, 2 pre-existing unrelated failures already present on untouched `41adb551` (`shared_root_signatures_load_from_library_and_execute_across_pso_switches` and `every_switch_of_the_translator_is_in_the_key`). ### Live Gameplay Validation (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 (`0` in-world slow loads). - **Default-path reclaim observed live** on every run containing PR #2015: - `C1` (FG OFF): reclaimed `512` idle shared buffers (`32 MiB` logical, matching 16 GB `scaled_default=512`), `6.17 FPS` (`1% Low 1.87`), 0 OOM / 0 device-removed. - `E1` (combined with PR #2038, FG OFF): reclaimed `512` shared (`32 MiB` logical), `6.63 FPS` (`1% Low 2.10`, `P99 391.4 ms`), 0 OOM / 0 device-removed. - `G2` (combined with PR #2038 + perf fix, FG OFF): reclaimed `512` shared + `392` card = `904` idle buffers (`56.5 MiB` logical), `6.47 FPS`, 0 OOM / 0 device-removed. - `C-fsr2` / `E-fsr2` (FSR 3 2X): FSR 3 active (`0` failed prepare dispatches), `512` shared reclaimed, 0 OOM / 0 device-removed. ## Limitations & Known Risks - Under default 16 GB RAM settings on `v2026.11.29.05`, the reclaimed logical volume is bounded by upstream's `512`-buffer cap (`<= 64 MiB` total logical); physical RAM/VRAM savings are modest compared to pre-`158d3177` builds, though preventing sustained OOM retry churn and exiting cleanly on device removal apply across all RAM sizes. - Short 72-second live benchmark runs with 0 OOM / 0 TDR do **not** prove long-session (30+ minute) OOM/TDR crashes are eliminated; extended open-world soak testing is in progress. ## AI Assistance Disclosure AI-Assisted: Rebased, refined, tested, and documented with AI assistance (Antigravity / Gemini), with all unit/D3D12 tests and live RTX 3060 hardware runs verified locally.
tyr0nsur commented 2026-11-30 12:58:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T12:58:50Z.


I tested a follow-up for the DXGI non-local budget at 8a1abb0a. The ahead worker already checks physical RAM, commit and the local DXGI budget. On a discrete GPU, Windows can lower the non-local budget while those checks still leave room for speculative shared buffers (#1520).

The patch applies the existing 85% entry and 70% recovery thresholds to the non-local segment. The ahead worker pauses speculative shared refill and returns unused buffers. The block sweep shares the same pressure state, so it can release empty CPU-visible heaps after the normal rest even if releasing the ahead inventory first moved usage below 85%. Local VRAM has its own decision. Demand allocations retain their existing path.

With a simulated budget signal and real D3D12 allocations on an RTX 4060, DXGI non-local usage fell from 36 to 28 MiB after dropping 128 committed ahead buffers, and from 92 to 28 MiB in a separate test after a pooled shared heap became empty. A live view and its resting range kept that heap allocated. Both focused tests also passed on WARP, and the diagnostics suite passed 49 tests. These are standalone tests without a title.

Companion commit

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7279186932 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2015#issuecomment-7279186932). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T12:58:50Z. --- I tested a follow-up for the DXGI non-local budget at `8a1abb0a`. The ahead worker already checks physical RAM, commit and the local DXGI budget. On a discrete GPU, Windows can lower the non-local budget while those checks still leave room for speculative shared buffers (#1520). The patch applies the existing 85% entry and 70% recovery thresholds to the non-local segment. The ahead worker pauses speculative shared refill and returns unused buffers. The block sweep shares the same pressure state, so it can release empty CPU-visible heaps after the normal rest even if releasing the ahead inventory first moved usage below 85%. Local VRAM has its own decision. Demand allocations retain their existing path. With a simulated budget signal and real D3D12 allocations on an RTX 4060, DXGI non-local usage fell from 36 to 28 MiB after dropping 128 committed ahead buffers, and from 92 to 28 MiB in a separate test after a pooled shared heap became empty. A live view and its resting range kept that heap allocated. Both focused tests also passed on WARP, and the diagnostics suite passed 49 tests. These are standalone tests without a title. [Companion commit](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/45067991069a663c6aa19dfff69dabfa0bc03c3d)
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/2015:upstream-pr/2015'
git switch 'upstream-pr/2015'

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/2015'
git switch 'upstream-pr/2015'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2015'
git switch 'upstream-pr/2015'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2015'
git switch 'main'
git merge --squash 'upstream-pr/2015'
git switch 'main'
git merge --ff-only 'upstream-pr/2015'
git switch 'main'
git merge 'upstream-pr/2015'
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!2015
No description provided.