Wave 2.0-B: Fix system RAM leaks, add RAM/commit telemetry & 6-8 GB VRAM auto-presets #445

Manually merged
github merged 2 commits from github-bot/gh-445 into gh-pr/445/base 2026-12-06 01:52:36 +00:00 AGit
Owner

@⁠Androtim on GitHub · 2026-12-06 00:51 UTC · original
Androtim:feat/v2.0-ram-leak-and-vram-presets → v2.0 · +1171 −96 · 19 files · 2 commits · merged 2026-12-06 01:51 UTC

Summary — MiniVI v2.0 Wave 2.0-B

Addresses the sustained system RAM leak/growth (~3–5 GB per 10 minutes), adds periodic process RAM/commit telemetry, and adds 6 GB / 8 GB DXGI VRAM smart auto-presets for --stream-budget (without touching main).

(Started from origin/feat/v2.0-foundation f980573 and rebased cleanly onto origin/v2.0 8e7e963 after #443 merged; 19 files changed.)


1. System RAM Leak & Growth Fixes (larp-hle, larp-gpu, apps/larp)

Every host-memory pool, staging allocator, command-list hold queue, descriptor cache, thread-local scratch buffer, and heap allocation path was audited:

  1. DirectStorage Staging Gate & Ordering (crates/larp-hle/src/modules/dstorage.rs) — Ported from upstream gamingwithhomie/larp PR #276 (credited in NOTICE):
    • Updated staging_bytes() to charge plain-file bounce buffers (MEMORY_SOURCE == 0) and ZLIB | BCPACK overlapping intermediate_size decode buffers so streaming bursts cannot blow past the 32 MiB STAGING gate.
    • Validated destination before I/O and moved plain-file read into the bounce buffer before opening guarded title destination pages (into_destination).
  2. Upload Staging Arena Reclamation (crates/larp-gpu/src/staging.rs, shadow.rs, heapfeed.rs):
    • Staging::arenas (OWNED_SENDS and heapfeed::FEED) previously only appended 16 MiB Upload buffers and never released idle arenas after bursts.
    • Switched arenas to Vec<Option<Arena>> (keeping queued Piece::arena indices stable), reused None slots, popped trailing Nones, and added Staging::reclaim_idle() called during host::sweep() / shadow::let_go_idle() (keeping <= 2 warm idle arenas normally, 0 below 2 GiB free RAM) with COM drops performed outside locks.
  3. Auxiliary Command List Pools, List Scratch Containers & SPARE Trimming (crates/larp-gpu/src/host.rs):
    • small_list() and copy_list() previously left finished entries in SMALL_LISTS / COPY_LISTS retaining their held: Vec<Arc<Shadow>> (pinning Shadows and 4 MiB loose windows with strong_count > 1) and retained unbounded finished ID3D12GraphicsCommandLists after bursts. Extracted shared sweep_aux_pool() + periodic reclaim_idle_aux_lists() in sweep() to immediately drop finished held/lease objects and cap idle finished lists at 32 outside pool locks.
    • Applied Reuse::reuse() (> 256 KiB capacity drop) in HostList::clear() to named, entries, away, twins, card_reads, card_fills, card_declared, card_closed, and notes.
    • Added Spare::trim_to() + trim_spare() in sweep() to shrink pooled SPARE scratch buffers from 128 MiB down to 32 MiB (< 4 GiB free RAM) or 0 (< 2 GiB free RAM).
  4. Command Allocator Pool Cap (crates/larp-gpu/src/allocators.rs):
    • FREE[DIRECT / COPY] pooled ID3D12CommandAllocators without limit; capped at 32 per kind (MAX_FREE_ALLOCATORS) and added trim_free() in sweep() (32 / 16 / 8 by free RAM) with drops outside locks.
  5. Descriptor Heap Drop & Per-Frame WHOLE Pruning (crates/larp-gpu/src/descriptor.rs, draw.rs):
    • Wired descriptor::Heap::drop to call draw::forget_heap() so destroyed shader-visible descriptor heaps immediately remove their Picks entries from KEPT_HEAP_PICKS instead of leaking Arc<Shadow> spans.
    • Added prune_stale_whole() in draw.rs to drop expired last < frame entries from WHOLE once len > 256.
  6. Shadow Snapshot Pool & Weak Compaction (crates/larp-gpu/src/shadow.rs):
    • Added idle timestamp tracking (POOL_USED_AT) + trim_snapshot_pool() in let_go_idle() to trim 512+ MiB snapshot Vec<u8> pools to 64 MiB after 15s idle or < 4 GiB free RAM, and to 0 after 30s idle or < 2 GiB free RAM (outside locks).
    • Pruned dead Weak<Shadow>s and oversized capacity from CARDED during let_go_idle().
  7. Worker Thread-Local & Texture Event Cleanup (crates/larp-gpu/src/texevents.rs, bufobj.rs, finals.rs):
    • Shrunk thread-local spike scratch buffers (texevents::with_runs::READ, plus diagnostics bufobj::check::SCRATCH and finals::check::SCRATCH) down to 4 MiB after oversized texture/buffer reads.
    • Cleaned up stale Objects::filled entries in texevents::release() and Objects::last_set in object_released().
  8. mimalloc Global Allocator (Cargo.toml, apps/larp/Cargo.toml, apps/larp/src/main.rs, apps/larp/src/bin/larp.rs):
    • Enabled mimalloc (0.1.52, default features — pure Rust #[global_allocator] without C hook override) on Windows non-diagnostics builds of MiniVI and larp to prevent Windows CRT heap fragmentation / cross-thread lock contention and purge idle multi-MB decode/bounce pages back to the OS promptly (copystat::HEAP remains intact under diagnostics).
  9. RAM & Commit Telemetry (crates/larp-gpu/src/host.rs):
    • Exposed private_bytes() outside diagnostics builds and appended RAM <mb> MB (<gib> GiB), commit <mb> MB (<gib> GiB) (formatted via format_ram_commit) to the periodic 5-second tracing::info! stats line.

2. 6 GB & 8 GB VRAM Smart Auto-Presets (apps/larp/src/play.rs, apps/larp/src/run.rs)

  • Queries the selected DXGI adapter's dedicated video memory via CreateDXGIFactory1 (honoring LARP_ADAPTER / VICTORY_ADAPTER index or substring, or selecting the primary hardware adapter) when neither --stream-budget nor LARP_STREAM_BUDGET (VICTORY_STREAM_BUDGET) is explicitly provided:
    • <= 6.5 GiB VRAM: auto-selects --stream-budget 1500 and logs cleanly
    • <= 8.5 GiB VRAM: auto-selects --stream-budget 2500 and logs cleanly
    • > 8.5 GiB VRAM: leaves uncapped (None)
  • Explicit --stream-budget and LARP_STREAM_BUDGET / VICTORY_STREAM_BUDGET (including 0 / off / uncapped) always override auto-presets across play and run.

Verification

  • cargo xtask policy: 503 files ok, 0 violations
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
  • cargo check --workspace --features diagnostics --locked: 0 errors
  • cargo test --workspace --locked: all non-ignored unit tests pass across every workspace crate (including new PR #276 staging gate, staging slot reclaim, aux list sweep, allocator pool cap, heap drop / whole prune, snapshot pool trim, spare trim, telemetry format, and 3-tier + override VRAM preset tests)
  • cargo build --release --locked --bin MiniVI: builds cleanly (with DXC set)
**@⁠Androtim** on GitHub · 2026-12-06 00:51 UTC · [original](https://github.com/Androtim/MiniVI/pull/445) `Androtim:feat/v2.0-ram-leak-and-vram-presets` → `v2.0` · +1171 −96 · 19 files · 2 commits · merged 2026-12-06 01:51 UTC ## Summary — MiniVI v2.0 Wave 2.0-B Addresses the sustained system RAM leak/growth (~3–5 GB per 10 minutes), adds periodic process RAM/commit telemetry, and adds 6 GB / 8 GB DXGI VRAM smart auto-presets for `--stream-budget` (without touching `main`). *(Started from `origin/feat/v2.0-foundation` `f980573` and rebased cleanly onto `origin/v2.0` `8e7e963` after `#443` merged; 19 files changed.)* --- ### 1. System RAM Leak & Growth Fixes (`larp-hle`, `larp-gpu`, `apps/larp`) Every host-memory pool, staging allocator, command-list hold queue, descriptor cache, thread-local scratch buffer, and heap allocation path was audited: 1. **DirectStorage Staging Gate & Ordering (`crates/larp-hle/src/modules/dstorage.rs`)** — *Ported from upstream `gamingwithhomie/larp` PR #276 (credited in `NOTICE`):* - Updated `staging_bytes()` to charge plain-file bounce buffers (`MEMORY_SOURCE == 0`) and `ZLIB | BCPACK` overlapping `intermediate_size` decode buffers so streaming bursts cannot blow past the 32 MiB `STAGING` gate. - Validated destination before I/O and moved plain-file read into the bounce buffer *before* opening guarded title destination pages (`into_destination`). 2. **Upload Staging Arena Reclamation (`crates/larp-gpu/src/staging.rs`, `shadow.rs`, `heapfeed.rs`):** - `Staging::arenas` (`OWNED_SENDS` and `heapfeed::FEED`) previously only appended 16 MiB Upload buffers and never released idle arenas after bursts. - Switched `arenas` to `Vec<Option<Arena>>` (keeping queued `Piece::arena` indices stable), reused `None` slots, popped trailing `None`s, and added `Staging::reclaim_idle()` called during `host::sweep()` / `shadow::let_go_idle()` (keeping `<= 2` warm idle arenas normally, `0` below 2 GiB free RAM) with COM drops performed outside locks. 3. **Auxiliary Command List Pools, List Scratch Containers & `SPARE` Trimming (`crates/larp-gpu/src/host.rs`):** - `small_list()` and `copy_list()` previously left finished entries in `SMALL_LISTS` / `COPY_LISTS` retaining their `held: Vec<Arc<Shadow>>` (pinning `Shadow`s and 4 MiB loose windows with `strong_count > 1`) and retained unbounded finished `ID3D12GraphicsCommandList`s after bursts. Extracted shared `sweep_aux_pool()` + periodic `reclaim_idle_aux_lists()` in `sweep()` to immediately drop finished `held`/`lease` objects and cap idle finished lists at `32` outside pool locks. - Applied `Reuse::reuse()` (> 256 KiB capacity drop) in `HostList::clear()` to `named`, `entries`, `away`, `twins`, `card_reads`, `card_fills`, `card_declared`, `card_closed`, and `notes`. - Added `Spare::trim_to()` + `trim_spare()` in `sweep()` to shrink pooled `SPARE` scratch buffers from `128 MiB` down to `32 MiB` (< 4 GiB free RAM) or `0` (< 2 GiB free RAM). 4. **Command Allocator Pool Cap (`crates/larp-gpu/src/allocators.rs`):** - `FREE[DIRECT / COPY]` pooled `ID3D12CommandAllocator`s without limit; capped at `32` per kind (`MAX_FREE_ALLOCATORS`) and added `trim_free()` in `sweep()` (`32 / 16 / 8` by free RAM) with drops outside locks. 5. **Descriptor Heap Drop & Per-Frame `WHOLE` Pruning (`crates/larp-gpu/src/descriptor.rs`, `draw.rs`):** - Wired `descriptor::Heap::drop` to call `draw::forget_heap()` so destroyed shader-visible descriptor heaps immediately remove their `Picks` entries from `KEPT_HEAP_PICKS` instead of leaking `Arc<Shadow>` spans. - Added `prune_stale_whole()` in `draw.rs` to drop expired `last < frame` entries from `WHOLE` once `len > 256`. 6. **Shadow Snapshot Pool & Weak Compaction (`crates/larp-gpu/src/shadow.rs`):** - Added idle timestamp tracking (`POOL_USED_AT`) + `trim_snapshot_pool()` in `let_go_idle()` to trim `512+ MiB` snapshot `Vec<u8>` pools to `64 MiB` after 15s idle or `< 4 GiB` free RAM, and to `0` after 30s idle or `< 2 GiB` free RAM (outside locks). - Pruned dead `Weak<Shadow>`s and oversized capacity from `CARDED` during `let_go_idle()`. 7. **Worker Thread-Local & Texture Event Cleanup (`crates/larp-gpu/src/texevents.rs`, `bufobj.rs`, `finals.rs`):** - Shrunk thread-local spike scratch buffers (`texevents::with_runs::READ`, plus diagnostics `bufobj::check::SCRATCH` and `finals::check::SCRATCH`) down to `4 MiB` after oversized texture/buffer reads. - Cleaned up stale `Objects::filled` entries in `texevents::release()` and `Objects::last_set` in `object_released()`. 8. **`mimalloc` Global Allocator (`Cargo.toml`, `apps/larp/Cargo.toml`, `apps/larp/src/main.rs`, `apps/larp/src/bin/larp.rs`):** - Enabled `mimalloc` (`0.1.52`, default features — pure Rust `#[global_allocator]` without C hook override) on Windows non-`diagnostics` builds of `MiniVI` and `larp` to prevent Windows CRT heap fragmentation / cross-thread lock contention and purge idle multi-MB decode/bounce pages back to the OS promptly (`copystat::HEAP` remains intact under `diagnostics`). 9. **RAM & Commit Telemetry (`crates/larp-gpu/src/host.rs`):** - Exposed `private_bytes()` outside `diagnostics` builds and appended `RAM <mb> MB (<gib> GiB), commit <mb> MB (<gib> GiB)` (formatted via `format_ram_commit`) to the periodic 5-second `tracing::info!` stats line. --- ### 2. 6 GB & 8 GB VRAM Smart Auto-Presets (`apps/larp/src/play.rs`, `apps/larp/src/run.rs`) - Queries the selected DXGI adapter's dedicated video memory via `CreateDXGIFactory1` (honoring `LARP_ADAPTER` / `VICTORY_ADAPTER` index or substring, or selecting the primary hardware adapter) when neither `--stream-budget` nor `LARP_STREAM_BUDGET` (`VICTORY_STREAM_BUDGET`) is explicitly provided: - `<= 6.5 GiB` VRAM: auto-selects `--stream-budget 1500` and logs cleanly - `<= 8.5 GiB` VRAM: auto-selects `--stream-budget 2500` and logs cleanly - `> 8.5 GiB` VRAM: leaves uncapped (`None`) - Explicit `--stream-budget` and `LARP_STREAM_BUDGET` / `VICTORY_STREAM_BUDGET` (including `0` / `off` / `uncapped`) always override auto-presets across `play` and `run`. --- ### Verification - `cargo xtask policy`: 503 files ok, 0 violations - `cargo clippy --workspace --all-targets --locked -- -D warnings`: 0 warnings - `cargo check --workspace --features diagnostics --locked`: 0 errors - `cargo test --workspace --locked`: all non-ignored unit tests pass across every workspace crate (including new PR #276 staging gate, staging slot reclaim, aux list sweep, allocator pool cap, heap drop / whole prune, snapshot pool trim, spare trim, telemetry format, and 3-tier + override VRAM preset tests) - `cargo build --release --locked --bin MiniVI`: builds cleanly (with `DXC` set)
- Import audited gamingwithhomie/larp workspace (commit f782a04, GPL-3.0-or-later)
  targeting v2.0, keeping LICENSE and adding NOTICE + upstream attributions.
- Update xtask clean-room asset policy for larp crates, text extensions
  (.views, .interface, .h, .cpp, .def, .ini, .ftl), shader sources, and
  neutralize title-specific strings across code, docs, and locales.
- Add [[bin]] MiniVI (alongside larp), embed compiled shader-replace assets
  via OUT_DIR include_bytes! with optional disk override, add dual MSVC/GNU
  Agility SDK exports (agility-gnu.def + -luuid), and port PR #265 HLSL fix.
- Implement MiniVI.exe play CLI compatibility (--series-s, --res, --dlss,
  --framegen, --framegen-ready, --fg-type, --fps, --preload, --stream-budget,
  repeatable --set), VICTORY_* -> LARP_* runtime translation (incl. adapter,
  bink skip, HW RT gate, keys script conversion, restart exit code, live file),
  minivi-play-YYYYMMDD-HHMMSS.log teeing + Log: <path> output, and MiniVI
  v2.0 (<sha>) stamp in logs and the F9 performance overlay.
- Update CI (main + v2.0, DXC setup, policy, clippy, workspace tests) and
  release workflow (PE32+ export/import checks, SHA-256, and automatic
  --prerelease + warning banner when tag contains '-').
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 00:53:14 +00:00
github-bot force-pushed github-bot/gh-445 from 3ff3d2a979 to efdb65bc56 2026-12-06 01:01:12 +00:00 Compare
github-bot changed target branch from v2.0 to gh-pr/445/base 2026-12-06 01:52:35 +00:00
github manually merged commit d5d570fca9 into gh-pr/445/base 2026-12-06 01:52:36 +00:00
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/Androtim--MiniVI!445
No description provided.