perf(gpu,hle): port ecosystem dstorage cache, prelude sharing, host buffer keep, one-call parts, and dynamic descriptor chunking #403

Merged
Androtim merged 3 commits from upstream-pr/403 into main 2026-12-03 19:16:59 +00:00
Androtim commented 2026-12-03 17:37:59 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T17:37:59Z.


Summary

Ports five high-impact CPU/GPU FPS and memory optimizations from upstream GPL-3.0 forks into MiniVI with strict concurrency invariants, 8 GB VRAM / 16 GB RAM commit-floor guards, clean-room title neutrality, and unit tests for every invariant:

  1. Decoded DirectStorage Chunk LRU Cache (VICTORY_DSTORAGE_CACHE, VICTORY_DSTORAGE_CACHE_MB)

    • Sharded 16-way DecodedCache in crates/victory-hle/src/modules/dstorage.rs admitting decoded ZLIB / BCPACK file chunks starting on their second identical decode request (avoiding RAM churn on one-shot streaming reads).
    • Auto-scales default limit to 512 MiB when victory_gpu::tiny_host_ram() (<= 18 GiB host RAM) and 1536 MiB otherwise (VICTORY_DSTORAGE_CACHE=0 or VICTORY_DSTORAGE_CACHE_MB=0 disables).
    • Hardened concurrency & commit guards for 16 GB RAM safety:
      • 128-bit case- and slash-insensitive FNV-1a path hash (file_id), bounded per-shard first-sight history (4096 keys/shard), and Arc<[u8]> zero-copy hits outside shard locks.
      • CommitSampler probes victory_gpu::commit_left() (GlobalMemoryStatusEx::ullAvailPageFile) on first admission and at least every 32 ms or 4 MiB admitted (added_since deduction between polls), strictly enforcing a 3 GiB free commit floor, proactive 25% trim below 2.5 GiB, and full cache drain below 1.5 GiB.
      • All bytes updates (fetch_add/fetch_sub) run strictly under the owning shard lock so concurrent trim() passes cannot race or underflow byte totals.
  2. Shared Prelude Pooling on Reset (VICTORY_PRELUDE_SHARED)

    • crates/victory-gpu/src/host/prelude.rs, host.rs, copystat.rs: routes record_prelude pops through take_prelude_from_pool() with PRELUDES_TAKEN / preludes_spare() / PRELUDES_GONE instrumentation and VICTORY_PRELUDE_SHARED=0 kill switch alongside VICTORY_PRELUDE_POOL.
  3. Keep Host Buffers Under Budget (VICTORY_KEEP_HOST_BUFFERS)

    • crates/victory-gpu/src/host/keep.rs, crates/victory-gpu/src/list.rs: off by default (switch::on); when enabled, suppresses periodic 30 s command allocator remakes (allocator_refresh) and idle list age trimming (list::trim_stale_idle / list::recycle) while host RAM (residency::pressured()) and DXGI local + shared video memory budgets remain unconstrained (cached every 100 ms in card_over_budget_lately()). Pressure trimming (trim_on_pressure) remains active.
  4. Merge Joined Flight Parts Into One ExecuteCommandLists Call (VICTORY_PARTS_ONE_CALL)

    • crates/victory-gpu/src/host/parts.rs, host/place.rs, host.rs: off by default (switch::on + D3D12 Enhanced Barriers support check via place::enhanced_barriers); inserts pooled global enhanced-barrier command lists (place::wait_for_all) before interior part cuts across both Host::send_published and Host::submit (late && !publish), rolling back unused barrier lists on partial failure and holding PooledPreludes alive in Sent/Flight until GPU fence landing.
    • keep and parts helpers/tests (alongside prelude pooling) are cleanly placed in crates/victory-gpu/src/host/{keep,parts,prelude}.rs so crates/victory-gpu/src/host.rs stays under the 640 KiB xtask policy file-size limit (650,272 bytes).
  5. Per-Thread Dynamic Descriptor Chunking (VICTORY_DYNAMIC_CHUNK) & Read-Lock-First shadow::loose

    • crates/victory-gpu/src/descriptor/host.rs, apps/victory/src/play.rs, scripts/play-minivi.ps1: adds CHUNKS = 32 per-thread (u32, u32) bump buckets on HostHeap (0 default at library level, "256" in launcher settings) with exact free / too_long bookkeeping on chunk tail return and acyclic chunks -> next drain_chunk_tails() before any refusal.
    • crates/victory-gpu/src/shadow.rs: checks LOOSE.read() first across all lookup modes (named, tails, fine) via loose_in, serializes misses with MAKING outside LOOSE.write() (made_window), and locks MAKING before LOOSE.write() in in_place_let_go.

Upstream GPL-3.0 Attribution

  • ReZOnGithub/VIctory-lap commit 133b952 (GPL-3.0): VICTORY_DSTORAGE_CACHE + VICTORY_PRELUDE_SHARED (diagnostic VICTORY_PROBE_RAM omitted; title/path literals replaced with title-neutral equivalents).
  • lobomfz/VIctory-xmem PR #332 (0e8e798, GPL-3.0): VICTORY_KEEP_HOST_BUFFERS.
  • lobomfz/VIctory-xmem PR #330 (294219a, d192205, GPL-3.0): VICTORY_PARTS_ONE_CALL.
  • SandBar-developer/VIctory-SandBar commit d0132b2 (GPL-3.0): VICTORY_DYNAMIC_CHUNK + read-lock-first shadow::loose.

Verification

Verified locally with RUSTUP_TOOLCHAIN=1.98.1-x86_64-pc-windows-gnu and C:\msys64\mingw64\bin;C:\msys64\ucrt64\bin; prepended to PATH:

  • cargo xtask policy — passed (asset policy: 355 files ok).
  • cargo test -p xtask --locked — 8 passed; 0 failed.
  • cargo clippy --workspace --all-targets -- -D warnings — passed.
  • cargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings — passed.
  • cargo test -p victory-gpu -- --test-threads=1 — 877 passed; 0 failed; 39 ignored (includes descriptor::host::chunk_tests, host::keep::keep_tests, host::parts::part_call_tests incl. D3D12 hardware + debug layer check, host::prelude::tests, list::bc_copy_tests, shadow::window_tests::loose_in_shares_read_lock_on_hit_and_creates_once_outside_write_lock).
  • cargo test -p victory-hle -- --test-threads=1 — 254 passed; 0 failed; 3 ignored (1 passed in tests/no_dll_planting.rs, includes 5 modules::dstorage::tests::decoded_cache_* tests).
  • cargo test -p victory -- --test-threads=1 — 47 passed; 0 failed (2 passed in tests/census.rs).
<!-- greyfinch-sync:Androtim/MiniVI:issue:5631733455 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/403). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T17:37:59Z. --- ## Summary Ports five high-impact CPU/GPU FPS and memory optimizations from upstream GPL-3.0 forks into MiniVI with strict concurrency invariants, 8 GB VRAM / 16 GB RAM commit-floor guards, clean-room title neutrality, and unit tests for every invariant: 1. **Decoded DirectStorage Chunk LRU Cache (`VICTORY_DSTORAGE_CACHE`, `VICTORY_DSTORAGE_CACHE_MB`)** - Sharded 16-way `DecodedCache` in `crates/victory-hle/src/modules/dstorage.rs` admitting decoded `ZLIB` / `BCPACK` file chunks starting on their second identical decode request (avoiding RAM churn on one-shot streaming reads). - Auto-scales default limit to **512 MiB** when `victory_gpu::tiny_host_ram()` (`<= 18 GiB` host RAM) and **1536 MiB** otherwise (`VICTORY_DSTORAGE_CACHE=0` or `VICTORY_DSTORAGE_CACHE_MB=0` disables). - Hardened concurrency & commit guards for 16 GB RAM safety: - 128-bit case- and slash-insensitive FNV-1a path hash (`file_id`), bounded per-shard first-sight history (`4096` keys/shard), and `Arc<[u8]>` zero-copy hits outside shard locks. - `CommitSampler` probes `victory_gpu::commit_left()` (`GlobalMemoryStatusEx::ullAvailPageFile`) on first admission and at least every `32 ms` or `4 MiB` admitted (`added_since` deduction between polls), strictly enforcing a **3 GiB** free commit floor, proactive 25% trim below **2.5 GiB**, and full cache drain below **1.5 GiB**. - All `bytes` updates (`fetch_add`/`fetch_sub`) run strictly under the owning shard lock so concurrent `trim()` passes cannot race or underflow byte totals. 2. **Shared Prelude Pooling on Reset (`VICTORY_PRELUDE_SHARED`)** - `crates/victory-gpu/src/host/prelude.rs`, `host.rs`, `copystat.rs`: routes `record_prelude` pops through `take_prelude_from_pool()` with `PRELUDES_TAKEN` / `preludes_spare()` / `PRELUDES_GONE` instrumentation and `VICTORY_PRELUDE_SHARED=0` kill switch alongside `VICTORY_PRELUDE_POOL`. 3. **Keep Host Buffers Under Budget (`VICTORY_KEEP_HOST_BUFFERS`)** - `crates/victory-gpu/src/host/keep.rs`, `crates/victory-gpu/src/list.rs`: off by default (`switch::on`); when enabled, suppresses periodic 30 s command allocator remakes (`allocator_refresh`) and idle list age trimming (`list::trim_stale_idle` / `list::recycle`) while host RAM (`residency::pressured()`) and DXGI local + shared video memory budgets remain unconstrained (cached every 100 ms in `card_over_budget_lately()`). Pressure trimming (`trim_on_pressure`) remains active. 4. **Merge Joined Flight Parts Into One `ExecuteCommandLists` Call (`VICTORY_PARTS_ONE_CALL`)** - `crates/victory-gpu/src/host/parts.rs`, `host/place.rs`, `host.rs`: off by default (`switch::on` + D3D12 Enhanced Barriers support check via `place::enhanced_barriers`); inserts pooled global enhanced-barrier command lists (`place::wait_for_all`) before interior part cuts across both `Host::send_published` and `Host::submit` (`late && !publish`), rolling back unused barrier lists on partial failure and holding `PooledPreludes` alive in `Sent`/`Flight` until GPU fence landing. - `keep` and `parts` helpers/tests (alongside prelude pooling) are cleanly placed in `crates/victory-gpu/src/host/{keep,parts,prelude}.rs` so `crates/victory-gpu/src/host.rs` stays under the 640 KiB `xtask policy` file-size limit (`650,272` bytes). 5. **Per-Thread Dynamic Descriptor Chunking (`VICTORY_DYNAMIC_CHUNK`) & Read-Lock-First `shadow::loose`** - `crates/victory-gpu/src/descriptor/host.rs`, `apps/victory/src/play.rs`, `scripts/play-minivi.ps1`: adds `CHUNKS = 32` per-thread `(u32, u32)` bump buckets on `HostHeap` (`0` default at library level, `"256"` in launcher settings) with exact `free` / `too_long` bookkeeping on chunk tail return and acyclic `chunks -> next` `drain_chunk_tails()` before any refusal. - `crates/victory-gpu/src/shadow.rs`: checks `LOOSE.read()` first across all lookup modes (`named`, `tails`, `fine`) via `loose_in`, serializes misses with `MAKING` outside `LOOSE.write()` (`made_window`), and locks `MAKING` before `LOOSE.write()` in `in_place_let_go`. ## Upstream GPL-3.0 Attribution - `ReZOnGithub/VIctory-lap` commit `133b952` (GPL-3.0): `VICTORY_DSTORAGE_CACHE` + `VICTORY_PRELUDE_SHARED` (diagnostic `VICTORY_PROBE_RAM` omitted; title/path literals replaced with title-neutral equivalents). - `lobomfz/VIctory-xmem` PR #332 (`0e8e798`, GPL-3.0): `VICTORY_KEEP_HOST_BUFFERS`. - `lobomfz/VIctory-xmem` PR #330 (`294219a`, `d192205`, GPL-3.0): `VICTORY_PARTS_ONE_CALL`. - `SandBar-developer/VIctory-SandBar` commit `d0132b2` (GPL-3.0): `VICTORY_DYNAMIC_CHUNK` + read-lock-first `shadow::loose`. ## Verification Verified locally with `RUSTUP_TOOLCHAIN=1.98.1-x86_64-pc-windows-gnu` and `C:\msys64\mingw64\bin;C:\msys64\ucrt64\bin;` prepended to `PATH`: - `cargo xtask policy` — passed (`asset policy: 355 files ok`). - `cargo test -p xtask --locked` — `8 passed; 0 failed`. - `cargo clippy --workspace --all-targets -- -D warnings` — passed. - `cargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings` — passed. - `cargo test -p victory-gpu -- --test-threads=1` — `877 passed; 0 failed; 39 ignored` (includes `descriptor::host::chunk_tests`, `host::keep::keep_tests`, `host::parts::part_call_tests` incl. D3D12 hardware + debug layer check, `host::prelude::tests`, `list::bc_copy_tests`, `shadow::window_tests::loose_in_shares_read_lock_on_hit_and_creates_once_outside_write_lock`). - `cargo test -p victory-hle -- --test-threads=1` — `254 passed; 0 failed; 3 ignored` (`1 passed` in `tests/no_dll_planting.rs`, includes 5 `modules::dstorage::tests::decoded_cache_*` tests). - `cargo test -p victory -- --test-threads=1` — `47 passed; 0 failed` (`2 passed` in `tests/census.rs`).
Androtim commented 2026-12-03 18:03:55 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T18:03:55Z.


Triage (df0efa24, CI check PASS):

  • Strong 5-part ecosystem bundle (+1,896/-210, 13 files), but marked triage: needs work under the no-opt-in-toggle policy:
    • VICTORY_KEEP_HOST_BUFFERS (crates/victory-gpu/src/host/keep.rs) and VICTORY_PARTS_ONE_CALL (crates/victory-gpu/src/host/parts.rs) are wired as off-by-default opt-in toggles (crate::switch::on(...)). Only =0 kill-switches for default-on replacements are allowed.
    • Please either flip them to default-on with =0 kill-switches (once verified safe and faster under Gate 2 Audit + Gate 3 plain---release A/B), or split/drop any sub-feature not yet ready to replace the default path.
    • VICTORY_DSTORAGE_CACHE, VICTORY_PRELUDE_SHARED, and VICTORY_DYNAMIC_CHUNK=256 (in play.rs / play-minivi.ps1) are already default-on and look clean.
  • Once toggles are resolved, we will proceed to Gate 2 Audit (#282) + Gate 3 plain---release A/B (also note overlap in host.rs, list.rs, descriptor/host.rs, play.rs with #393 and #404).
<!-- greyfinch-sync:Androtim/MiniVI:comment:7387541298 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/403#issuecomment-7387541298). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T18:03:55Z. --- Triage (`df0efa24`, **CI `check` PASS**): - Strong 5-part ecosystem bundle (`+1,896/-210`, 13 files), **but marked `triage: needs work` under the no-opt-in-toggle policy:** - `VICTORY_KEEP_HOST_BUFFERS` (`crates/victory-gpu/src/host/keep.rs`) and `VICTORY_PARTS_ONE_CALL` (`crates/victory-gpu/src/host/parts.rs`) are wired as **off-by-default opt-in toggles** (`crate::switch::on(...)`). Only `=0` kill-switches for default-on replacements are allowed. - Please either flip them to **default-on with `=0` kill-switches** (once verified safe and faster under Gate 2 Audit + Gate 3 plain-`--release` A/B), or split/drop any sub-feature not yet ready to replace the default path. - `VICTORY_DSTORAGE_CACHE`, `VICTORY_PRELUDE_SHARED`, and `VICTORY_DYNAMIC_CHUNK=256` (in `play.rs` / `play-minivi.ps1`) are already default-on and look clean. - Once toggles are resolved, we will proceed to **Gate 2 Audit (`#282`)** + **Gate 3 plain-`--release` A/B** (also note overlap in `host.rs`, `list.rs`, `descriptor/host.rs`, `play.rs` with `#393` and `#404`).
Androtim commented 2026-12-03 19:02:15 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T19:02:15Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-rebase · CI (check): passing

This PR no longer merges cleanly into main.

To change the verdict: Rebase onto current main and resolve conflicts; CI and triage will run again automatically.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7389057614 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/403#issuecomment-7389057614). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T19:02:15Z. --- <!-- minivi-triage v1 head=e217efe04066571848847a5e0907dc736ff52e99 verdict=needs-rebase ci=passing at=2026-12-03T19:02:54Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-rebase` · **CI (`check`):** `passing` This PR no longer merges cleanly into `main`. **To change the verdict:** Rebase onto current `main` and resolve conflicts; CI and triage will run again automatically. --- _Generated with Antigravity CLI (`agy`)._
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!403
No description provided.