feat(gpu): default-on background driver shader cache working-set trim #306

Merged
Androtim merged 1 commit from upstream-pr/306 into main 2026-12-02 07:49:24 +00:00
Androtim commented 2026-12-02 07:42:53 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T07:42:53Z.


Summary

Adds default-on background working-set trimming (VirtualUnlock in 64 MiB chunks from a lowest-priority background thread) for mapped GPU driver shader cache files (NVIDIA DXCache *.nvph, Windows D3DSCache *.dxcache, and vendor DXCache / ShaderCache blobs >= 16 MiB) once pipeline creation goes quiet.

Adapted from GPL-3.0 upstream idea (HypeLobbiesHD/ViceLite 07ceab34) with MiniVI improvements:

  • Default-on with VICTORY_DRIVER_TRIM=0 kill-switch only (no opt-in toggle).
  • 64 MiB chunked VirtualUnlock with periodic 1 ms yields and active pipeline abort checks (ACTIVE_CALLS > 0 / re-arm) so Windows' process working-set lock never stalls frame preparation.
  • Event-driven empty-walk cooldown (30 s + >= 5 s quiet floor) with zero idle polling when no driver cache is mapped yet, while still catching caches mapped lazily later in a session.
  • Zero K32QueryWorkingSetEx working-set query overhead in plain --release builds (in_memory() resident probe runs only under --features diagnostics).
  • Tracks ACTIVE_CALLS across pipeline::library::pipeline() calls (RAII PipelineActivity) and exposes pipeline::quiet_ms() for host::sweep().

Closes the #1 Rank 1 System RAM lever in #276.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy -> 321 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked -- drivercache -> 5 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings -> clean
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings -> clean
  • objdump -p D:\victory-build\minivi\release\MiniVI.exe | Select-String "DLL Name" -> standard Windows DLLs only

Same-Path (victory.exe) Plain --release Paired 90s A/B Benchmarks (RTX 4060 Ti 8 GB / i7-13700F / 32 GB RAM, -PlayParity, NO --features diagnostics)

1. Active 2 GiB Driver Cache Unlock Observed (paired-*-drivertrim2-1440p-90s):
When NVIDIA held the 2,048 MB DXCache\*.nvph mapping open, background VirtualUnlock fired 3 times (2048 MB unlocked of 2048 MB mapped, 1 region, 32 chunks, 1098 ms initial walk, 40 ms & 38 ms cached subsequent trims):

Metric main (79e8487) PR (feat/driver-shader-cache-trim) Delta
Median FPS 13.5 fps (74.0 ms) 14.7 fps (68.1 ms) +1.2 fps (+8.9%)
Preparing / Copyback 29.1 ms / 14.5 ms 28.0 ms / 11.7 ms -1.1 ms / -2.8 ms
Working Set (avg / med / max) 18,868 / 20,717 / 21,652 MB 16,480 / 19,459 / 19,849 MB -2,388 / -1,258 / -1,803 MB
Host Free RAM (med / min / end) 1,046 / 435 / 845 MB 3,035 / 2,769 / 2,769 MB +1,989 / +2,334 / +1,924 MB
Crashes / Device Removed / Panics 0 0 0

2. Final Branch Code Cleanliness (paired-*-drivertrim5-*, 1440p + 4K DLSS Quality):
With warm host pipeline library (where the driver already released/skipped mapping a >= 16 MiB cache in the 90s window), the idle path logs once (0 mapped cache regions found) with zero polling overhead or instability:

Profile Build Median FPS preparing copyback working_set_mb med free_ram_mb med Crashes
1440p Parity (90s) main (79e8487) 14.9 fps (67.0 ms) 26.8 ms 11.1 ms 18,866 MB 2,644 MB 0
1440p Parity (90s) PR (drivertrim5) 15.0 fps (66.7 ms) 27.6 ms 11.5 ms 18,786 MB 2,708 MB 0
4K DLSS Quality (90s) main (79e8487) 6.7 fps (148.5 ms) 23.75 ms 15.25 ms 19,753 MB 2,144 MB 0
4K DLSS Quality (90s) PR (drivertrim5) 6.4 fps (155.7 ms) 19.75 ms 13.95 ms 20,047 MB 1,945 MB 0

Visual Verification (--features diagnostics, 1440p 90s, diag-pr-drivertrim-1440p-90s)

  • All 6 gates PASS (world_windows=21, max_draws=12548, crashes=0, used_max=6268 MB / budget_min=6696 MB, over=0 MB, final_waiting=2770, mapped_rate=2.52 ms/s)
  • Visual PNGs (24): lit=20/24, luma=99.91, near_black=0.06%, edge_energy=7.82, magenta=0.0% (frame-2582.png, frame-2598.png, frame-2614.png inspected visually — sharp water, foliage, structures, zero magenta/confetti artifacts).
<!-- greyfinch-sync:Androtim/MiniVI:issue:5602077028 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/306). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T07:42:53Z. --- ## Summary Adds default-on background working-set trimming (`VirtualUnlock` in 64 MiB chunks from a lowest-priority background thread) for mapped GPU driver shader cache files (`NVIDIA DXCache *.nvph`, `Windows D3DSCache *.dxcache`, and vendor `DXCache` / `ShaderCache` blobs >= 16 MiB) once pipeline creation goes quiet. Adapted from GPL-3.0 upstream idea (`HypeLobbiesHD/ViceLite` `07ceab34`) with MiniVI improvements: - **Default-on** with `VICTORY_DRIVER_TRIM=0` kill-switch only (no opt-in toggle). - **64 MiB chunked `VirtualUnlock`** with periodic `1 ms` yields and active pipeline abort checks (`ACTIVE_CALLS > 0` / re-arm) so Windows' process working-set lock never stalls frame preparation. - **Event-driven empty-walk cooldown (`30 s` + `>= 5 s` quiet floor)** with zero idle polling when no driver cache is mapped yet, while still catching caches mapped lazily later in a session. - **Zero `K32QueryWorkingSetEx` working-set query overhead in plain `--release` builds** (`in_memory()` resident probe runs only under `--features diagnostics`). - Tracks `ACTIVE_CALLS` across `pipeline::library::pipeline()` calls (RAII `PipelineActivity`) and exposes `pipeline::quiet_ms()` for `host::sweep()`. Closes the #1 Rank 1 System RAM lever in `#276`. ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` -> `321 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked -- drivercache` -> `5 passed; 0 failed` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` -> clean - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings` -> clean - `objdump -p D:\victory-build\minivi\release\MiniVI.exe | Select-String "DLL Name"` -> standard Windows DLLs only ### Same-Path (`victory.exe`) Plain `--release` Paired 90s A/B Benchmarks (RTX 4060 Ti 8 GB / i7-13700F / 32 GB RAM, `-PlayParity`, NO `--features diagnostics`) **1. Active 2 GiB Driver Cache Unlock Observed (`paired-*-drivertrim2-1440p-90s`):** When NVIDIA held the `2,048 MB` `DXCache\*.nvph` mapping open, background `VirtualUnlock` fired 3 times (`2048 MB unlocked of 2048 MB mapped`, 1 region, 32 chunks, `1098 ms` initial walk, `40 ms` & `38 ms` cached subsequent trims): | Metric | `main` (`79e8487`) | PR (`feat/driver-shader-cache-trim`) | Delta | |---|---:|---:|---:| | Median FPS | `13.5 fps` (`74.0 ms`) | **`14.7 fps` (`68.1 ms`)** | **`+1.2 fps` (`+8.9%`)** | | Preparing / Copyback | `29.1 ms` / `14.5 ms` | **`28.0 ms` / `11.7 ms`** | **`-1.1 ms` / `-2.8 ms`** | | Working Set (`avg` / `med` / `max`) | `18,868` / `20,717` / `21,652 MB` | **`16,480` / `19,459` / `19,849 MB`** | **`-2,388` / `-1,258` / `-1,803 MB`** | | Host Free RAM (`med` / `min` / `end`) | `1,046` / `435` / `845 MB` | **`3,035` / `2,769` / `2,769 MB`** | **`+1,989` / `+2,334` / `+1,924 MB`** | | Crashes / Device Removed / Panics | `0` | `0` | `0` | **2. Final Branch Code Cleanliness (`paired-*-drivertrim5-*`, 1440p + 4K DLSS Quality):** With warm host pipeline library (where the driver already released/skipped mapping a >= 16 MiB cache in the 90s window), the idle path logs once (`0 mapped cache regions found`) with zero polling overhead or instability: | Profile | Build | Median FPS | `preparing` | `copyback` | `working_set_mb` med | `free_ram_mb` med | Crashes | |---|---|---:|---:|---:|---:|---:|---:| | **1440p Parity (90s)** | `main` (`79e8487`) | `14.9 fps` (`67.0 ms`) | `26.8 ms` | `11.1 ms` | `18,866 MB` | `2,644 MB` | `0` | | **1440p Parity (90s)** | **PR (`drivertrim5`)** | **`15.0 fps` (`66.7 ms`)** | `27.6 ms` | `11.5 ms` | **`18,786 MB`** | **`2,708 MB`** | `0` | | **4K DLSS Quality (90s)** | `main` (`79e8487`) | `6.7 fps` (`148.5 ms`) | `23.75 ms` | `15.25 ms` | `19,753 MB` | `2,144 MB` | `0` | | **4K DLSS Quality (90s)** | **PR (`drivertrim5`)** | `6.4 fps` (`155.7 ms`) | **`19.75 ms`** | **`13.95 ms`** | `20,047 MB` | `1,945 MB` | `0` | ### Visual Verification (`--features diagnostics`, 1440p 90s, `diag-pr-drivertrim-1440p-90s`) - **All 6 gates PASS** (`world_windows=21`, `max_draws=12548`, `crashes=0`, `used_max=6268 MB / budget_min=6696 MB`, `over=0 MB`, `final_waiting=2770`, `mapped_rate=2.52 ms/s`) - **Visual PNGs (24):** `lit=20/24`, `luma=99.91`, `near_black=0.06%`, `edge_energy=7.82`, `magenta=0.0%` (`frame-2582.png`, `frame-2598.png`, `frame-2614.png` inspected visually — sharp water, foliage, structures, zero magenta/confetti artifacts).
Androtim commented 2026-12-02 07:49:21 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T07:49:21Z.


Autonomous architectural audit PASSED on 5053127f (CI 46834921431 GREEN):

  • Code review: Clean default-on implementation (VICTORY_DRIVER_TRIM=0 safety kill-switch only), 64 MiB chunked VirtualUnlock with 1 ms yields and active PipelineActivity abort checks, event-driven empty-walk cooldown (30 s + >= 5 s quiet floor), zero K32QueryWorkingSetEx overhead in plain --release builds, and safe RunningGuard / spawn-failure cleanup.
  • Plain --release A/B (0 crashes / 0 DRED):
    • Active 2 GiB driver cache mapping (1440p 90s): 13.5 -> 14.7 fps (+1.2 fps / +8.9%), preparing 29.1 -> 28.0 ms, copyback 14.5 -> 11.7 ms, working set -2,388 MB avg / -1,803 MB max, host free RAM +1,989 MB med / +2,334 MB min (435 -> 2,769 MB).
    • Idle/warm-library path (1440p & 4K 90s): zero polling overhead, 1440p 14.9 -> 15.0 fps, 4K preparing 23.75 -> 19.75 ms and copyback 15.25 -> 13.95 ms.
  • Diagnostics check (1440p 90s): All 6 gates PASS (luma=99.91, near_black=0.06%, edge_energy=7.82, magenta=0.0%, final_waiting=2,770).

Squash-merging into main.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7338652163 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/306#issuecomment-7338652163). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T07:49:21Z. --- Autonomous architectural audit **PASSED** on `5053127f` (CI `46834921431` GREEN): - **Code review:** Clean default-on implementation (`VICTORY_DRIVER_TRIM=0` safety kill-switch only), 64 MiB chunked `VirtualUnlock` with `1 ms` yields and active `PipelineActivity` abort checks, event-driven empty-walk cooldown (`30 s` + `>= 5 s` quiet floor), zero `K32QueryWorkingSetEx` overhead in plain `--release` builds, and safe `RunningGuard` / spawn-failure cleanup. - **Plain `--release` A/B (`0` crashes / `0` DRED):** - Active 2 GiB driver cache mapping (`1440p` 90s): `13.5 -> 14.7 fps` (`+1.2 fps` / `+8.9%`), preparing `29.1 -> 28.0 ms`, copyback `14.5 -> 11.7 ms`, working set `-2,388 MB` avg / `-1,803 MB` max, host free RAM `+1,989 MB` med / `+2,334 MB` min (`435 -> 2,769 MB`). - Idle/warm-library path (`1440p` & `4K` 90s): zero polling overhead, `1440p` `14.9 -> 15.0 fps`, `4K` preparing `23.75 -> 19.75 ms` and copyback `15.25 -> 13.95 ms`. - **Diagnostics check (`1440p` 90s):** All 6 gates PASS (`luma=99.91`, `near_black=0.06%`, `edge_energy=7.82`, `magenta=0.0%`, `final_waiting=2,770`). Squash-merging into `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
Androtim/MiniVI!306
No description provided.