perf(victory-gpu): reclaim idle host System RAM via MEM_DECOMMIT and cold pool/DXIL trimming #350

Open
github-bot wants to merge 1 commit from github-bot/gh-350 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 11:03 UTC · original
Vladimir-Human:perf/ram-footprint-decommit → main · +3236 −173 · 12 files · 1 commits · open

Summary

Ports host system RAM trimming and Windows MEM_DECOMMIT snapshot reclamation from fxceless/victory-fork#1286 onto LooperSalty/AnyXboxX, reducing host RAM pressure on 16–32 GB systems while preserving all existing AnyXboxX / Neptune concurrency and pooling features.

Key Changes

  1. Tiered host RAM policy & safe VM decommit (third_party/victory/crates/victory-gpu/src/ram_trim.rs, copystat.rs, lib.rs)
    • Adds TrimPolicy (Tight16 / Standard32 / Large, opt-in aggressive mode VICTORY_RAM_TRIM=1, automatic low/panic memory scaling, cached 250 ms via TrimPolicy::cached()).
    • Adds verify_safe_for_decommit (queries committed info.BaseAddress with non-resetting GetWriteWatch, rejecting MEM_WRITE_WATCH and MEM_MAPPED/MEM_IMAGE regions so write-watched or mapped title views are never touched).
    • Adds VmBlock / SnapshotBuffer (MEM_RESERVE virtual-address preservation with 64 KiB MEM_DECOMMIT / MEM_COMMIT and coalesced zero-piece scanning) plus ram_trim::diagnostics_line() logged in copystat.
  2. Shadow snapshot & remap reclamation (shadow.rs, watch.rs)
    • Upgrades Shadow::before and shadow::POOL to SnapshotBuffer with checked ensure_commit across all 7 access paths (Shadow::writing x3, find_all, copy_back_with, relay_merge, merge_under_writes).
    • Enforces warm_limit and panic_memory (including slot 0) in give_back_with while keeping MEM_RESERVE slots warm for VA reuse without page-fault churn.
    • Wires watch::title_memory_remapped -> shadow::title_memory_remapped, retiring single-owner contained LOOSE / EXACT shadows (preserving EXACT.0 monotonic tick, scanning wide LOOSE.range(..(end, 0)), bumping SHAPE (SeqCst) and re-checking can_retire) and MEM_DECOMMITting overlapping dead snapshot pages.
    • Releases idle CPU before snapshots on card promotion (card_make_before / copy_back_done), shrinks oversized thread-local TITLE scratch vecs in Shadow::copy(), and supports opt-in cold/zero reference trimming under strict pending -> before -> kept lock order (give_back always outside Shadow locks).
  3. Idle list, scratch, card-fetch, and staging pool trimming (list.rs, host.rs, texture.rs)
    • Adds list::let_go_idle_with + HostList::take_idle_caches (trimming ahead_chunks and indirect_args >= 1 MiB and dropping D3D12 COM buffers strictly outside locks, respecting VICTORY_LIST_POOL_IDLE_S and updating both TRIMMED_LISTS and ram_trim).
    • Adds age-based host::SPARE::trim, trim_card_work_with (CardWork::fetched_ms), HostList::reset vec capacity shrinking, and texture::trim_stage_pool_with + let_go_idle_with (timestamped STAGE_POOL, COM drops strictly outside STAGING and STAGE_POOL locks).
  4. Post-PSO DXIL release & lock-free guest container compression (pipeline.rs, pipeline/host.rs, pipeline/make.rs)
    • Stores guest containers in ContainerBlob (Raw(Arc<[u8]>) / Compressed { packed, orig_len } via existing zlib-rs), releasing self.container lock before translation, cache lookup, or disk I/O (with_container).
    • Adds DxilPin (building_dxil refcount) and trim_shaders_with across both graphics and compute shaders, preserving VICTORY_DROP_DXIL=1, DXIL_DROPS / KEPT[3] accounting, and transparent DXIL reload via shader_cache::host_shader.
  5. Preserved AnyXboxX / Neptune features
    • Keeps RwLock on BUFFERS / LOOSE + SHAPE / FOUND lookup cache (read-only scans in trim_cold_references_at and BUFFERS overlap checks use .read()), windowup.rs transient windows, VICTORY_WINDOW_REBAR, fold_buffers, VICTORY_LIST_POOL_MOST / _MB / _IDLE_S, VICTORY_STAGE_POOL_MB, VICTORY_DROP_DXIL=1, host::ram_idle_ms, and ramline.rs counters.

Verification (CARGO_TARGET_DIR='D:\cargo-targets\anyx-base')

  • cargo run -p xtask -- policy: asset policy: 199 files ok.
  • cargo clippy -p victory-gpu --all-targets -- -A deprecated (default & --features diagnostics): 0 warnings in added/modified lines.
  • Measured OS private-commit reduction (ram_trim::tests::stress_decommit_recommit_reuse_no_corruption_and_os_commit_drops):
    • Default: [ram_trim stress round 0..2] private commit before=341.6 MiB, after=85.1 MiB, delta=-256.5 MiB
    • --features diagnostics: [ram_trim stress round 0..2] private commit before=349.2 MiB, after=92.7 MiB, delta=-256.5 MiB
  • Targeted unit tests (--test-threads=1):
    • Default: ram_trim 13/13, shadow 39/39, pipeline 18/18, list 4/4, texture 16/16 (1 ignored), spare 2/2.
    • --features diagnostics: ram_trim 13/13, shadow 39/39, pipeline 21/21, list 6/6, texture 17/17 (1 ignored).
  • Full cargo test -p victory-gpu -- --test-threads=1: 198 passed; 3 failed; 3 ignored (the 3 failures are pre-existing on untouched origin/main: descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed and indirect::tests::warp_card_{fetch,patch}_*).
  • git diff --check & git merge-tree --write-tree origin/main HEAD: clean.

Credits

Ported from fxceless/victory-fork#1286.

**@⁠Vladimir-Human** on GitHub · 2026-11-26 11:03 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/350) `Vladimir-Human:perf/ram-footprint-decommit` → `main` · +3236 −173 · 12 files · 1 commits · open ## Summary Ports host system RAM trimming and Windows `MEM_DECOMMIT` snapshot reclamation from [`fxceless/victory-fork#1286`](https://github.com/fxceless/victory-fork/pull/1286) onto `LooperSalty/AnyXboxX`, reducing host RAM pressure on 16–32 GB systems while preserving all existing `AnyXboxX` / Neptune concurrency and pooling features. ### Key Changes 1. **Tiered host RAM policy & safe VM decommit (`third_party/victory/crates/victory-gpu/src/ram_trim.rs`, `copystat.rs`, `lib.rs`)** - Adds `TrimPolicy` (`Tight16` / `Standard32` / `Large`, opt-in aggressive mode `VICTORY_RAM_TRIM=1`, automatic low/panic memory scaling, cached 250 ms via `TrimPolicy::cached()`). - Adds `verify_safe_for_decommit` (queries committed `info.BaseAddress` with non-resetting `GetWriteWatch`, rejecting `MEM_WRITE_WATCH` and `MEM_MAPPED`/`MEM_IMAGE` regions so write-watched or mapped title views are never touched). - Adds `VmBlock` / `SnapshotBuffer` (`MEM_RESERVE` virtual-address preservation with 64 KiB `MEM_DECOMMIT` / `MEM_COMMIT` and coalesced zero-piece scanning) plus `ram_trim::diagnostics_line()` logged in `copystat`. 2. **Shadow snapshot & remap reclamation (`shadow.rs`, `watch.rs`)** - Upgrades `Shadow::before` and `shadow::POOL` to `SnapshotBuffer` with checked `ensure_commit` across all 7 access paths (`Shadow::writing` x3, `find_all`, `copy_back_with`, `relay_merge`, `merge_under_writes`). - Enforces `warm_limit` and `panic_memory` (including slot 0) in `give_back_with` while keeping `MEM_RESERVE` slots warm for VA reuse without page-fault churn. - Wires `watch::title_memory_remapped` -> `shadow::title_memory_remapped`, retiring single-owner contained `LOOSE` / `EXACT` shadows (preserving `EXACT.0` monotonic tick, scanning wide `LOOSE.range(..(end, 0))`, bumping `SHAPE` (`SeqCst`) and re-checking `can_retire`) and `MEM_DECOMMIT`ting overlapping dead snapshot pages. - Releases idle CPU `before` snapshots on card promotion (`card_make_before` / `copy_back_done`), shrinks oversized thread-local `TITLE` scratch vecs in `Shadow::copy()`, and supports opt-in cold/zero reference trimming under strict `pending -> before -> kept` lock order (`give_back` always outside `Shadow` locks). 3. **Idle list, scratch, card-fetch, and staging pool trimming (`list.rs`, `host.rs`, `texture.rs`)** - Adds `list::let_go_idle_with` + `HostList::take_idle_caches` (trimming `ahead_chunks` and `indirect_args >= 1 MiB` and dropping D3D12 COM buffers strictly outside locks, respecting `VICTORY_LIST_POOL_IDLE_S` and updating both `TRIMMED_LISTS` and `ram_trim`). - Adds age-based `host::SPARE::trim`, `trim_card_work_with` (`CardWork::fetched_ms`), `HostList::reset` vec capacity shrinking, and `texture::trim_stage_pool_with` + `let_go_idle_with` (timestamped `STAGE_POOL`, COM drops strictly outside `STAGING` and `STAGE_POOL` locks). 4. **Post-PSO DXIL release & lock-free guest container compression (`pipeline.rs`, `pipeline/host.rs`, `pipeline/make.rs`)** - Stores guest containers in `ContainerBlob` (`Raw(Arc<[u8]>)` / `Compressed { packed, orig_len }` via existing `zlib-rs`), releasing `self.container` lock before translation, cache lookup, or disk I/O (`with_container`). - Adds `DxilPin` (`building_dxil` refcount) and `trim_shaders_with` across both graphics and compute shaders, preserving `VICTORY_DROP_DXIL=1`, `DXIL_DROPS` / `KEPT[3]` accounting, and transparent DXIL reload via `shader_cache::host_shader`. 5. **Preserved `AnyXboxX` / Neptune features** - Keeps `RwLock` on `BUFFERS` / `LOOSE` + `SHAPE` / `FOUND` lookup cache (read-only scans in `trim_cold_references_at` and `BUFFERS` overlap checks use `.read()`), `windowup.rs` transient windows, `VICTORY_WINDOW_REBAR`, `fold_buffers`, `VICTORY_LIST_POOL_MOST` / `_MB` / `_IDLE_S`, `VICTORY_STAGE_POOL_MB`, `VICTORY_DROP_DXIL=1`, `host::ram_idle_ms`, and `ramline.rs` counters. ### Verification (`CARGO_TARGET_DIR='D:\cargo-targets\anyx-base'`) - `cargo run -p xtask -- policy`: `asset policy: 199 files ok`. - `cargo clippy -p victory-gpu --all-targets -- -A deprecated` (default & `--features diagnostics`): **0 warnings** in added/modified lines. - **Measured OS private-commit reduction (`ram_trim::tests::stress_decommit_recommit_reuse_no_corruption_and_os_commit_drops`)**: - Default: `[ram_trim stress round 0..2] private commit before=341.6 MiB, after=85.1 MiB, delta=-256.5 MiB` - `--features diagnostics`: `[ram_trim stress round 0..2] private commit before=349.2 MiB, after=92.7 MiB, delta=-256.5 MiB` - **Targeted unit tests (`--test-threads=1`)**: - Default: `ram_trim` **13/13**, `shadow` **39/39**, `pipeline` **18/18**, `list` **4/4**, `texture` **16/16** (1 ignored), `spare` **2/2**. - `--features diagnostics`: `ram_trim` **13/13**, `shadow` **39/39**, `pipeline` **21/21**, `list` **6/6**, `texture` **17/17** (1 ignored). - **Full `cargo test -p victory-gpu -- --test-threads=1`**: **198 passed; 3 failed; 3 ignored** (the 3 failures are pre-existing on untouched `origin/main`: `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed` and `indirect::tests::warp_card_{fetch,patch}_*`). - `git diff --check` & `git merge-tree --write-tree origin/main HEAD`: clean. ### Credits Ported from [`fxceless/victory-fork#1286`](https://github.com/fxceless/victory-fork/pull/1286).
Ported from fxceless/victory-fork#1286 while preserving AnyXboxX/Neptune RwLock, SHAPE/FOUND cache, windowup, rebar, fold_buffers, VICTORY_LIST_POOL_IDLE_S, STAGE_POOL, VICTORY_DROP_DXIL, and ramline counters.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:31:14 +00:00
Author
Owner

@⁠Skyfrye on GitHub · 2026-11-26 14:43 UTC · original

For information: I tried this PR in an integration build on main at 2cc6593 (after #358 and #377), stacked with #354, #345 and my #278, #279, #292, #307, #360-#362, #381 and #382. It no longer applies to main. The conflicts are in what the code does, not just neighbouring lines: host.rs (4), pipeline.rs (1: the builder_spilled cache against #377's ACCC part), texture.rs (7: the staging pool, which #289 reworked in #358), watch.rs (1). I left it out of that build rather than guess at the merge. A rebase on current main would let it in the next one.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-26 14:43 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/350#issuecomment-7195218392) For information: I tried this PR in an integration build on `main` at `2cc6593` (after #358 and #377), stacked with #354, #345 and my #278, #279, #292, #307, #360-#362, #381 and #382. It no longer applies to `main`. The conflicts are in what the code does, not just neighbouring lines: host.rs (4), pipeline.rs (1: the `builder_spilled` cache against #377's ACCC part), texture.rs (7: the staging pool, which #289 reworked in #358), watch.rs (1). I left it out of that build rather than guess at the merge. A rebase on current `main` would let it in the next one. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot force-pushed github-bot/gh-350 from 0470f875a4 to 69a0a8cc33 2026-11-26 15:21:06 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 15:16 UTC · original

@⁠Skyfrye Rebased onto main at 26c11d4 (post-#358/#289, #377, and #383) at commit 69a0a8c.

Conflict harmonization summary:

  • texture.rs: Preserved #289/#358's StageEntry / VecDeque cross-class LRU eviction, [0..bytes) zeroing, zero_upload_tests, and StagePool::trim full 0-byte idle drain (ram_idle_ms + 4 frames); layered ram_trim::TrimPolicy tightening additively on top when panic_memory || pool_idle_ms < upstream_idle_ms, and kept Staging drops outside STAGING lock.
  • pipeline.rs: Preserved #377's ACCC fallback (victory_shader::emit::nvidia::enabled()) in both translate() and inside of_builder()'s cached builder_spilled.
  • host.rs & host/scratch_tests.rs: Preserved #358's FIFO-evicting Spare::give and ResultRing (trim_card_work_with checks work.taken.used() == 0) alongside Spare::trim / CardWork::fetched_ms, and preserved #383 (step_index, sync_batched, parallel_refresh).
  • shadow.rs & watch.rs: Preserved #377 (after_writer) and #358 (Card::prints/me, note_carded, FLAGGED, window_same, page_writes_mode) cleanly alongside SnapshotBuffer and title_memory_remapped.

Verified on 69a0a8c: cargo xtask policy (215 files ok), cargo clippy -p victory-gpu --lib --tests (0 new warnings), VICTORY_D3D12_DEBUG=1 ram_trim 14/14 and texture:: 8/8 (victory-gpu --lib: 252 passed default / 265 passed --features diagnostics, with only the 3 pre-existing main failures in descriptor::host and indirect::warp_card_{fetch,patch}). Ready for your next integration build.

**@⁠Vladimir-Human** on GitHub · 2026-11-26 15:16 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/350#issuecomment-7196032289) @⁠Skyfrye Rebased onto `main` at `26c11d4` (post-#358/#289, #377, and #383) at commit `69a0a8c`. Conflict harmonization summary: - **`texture.rs`:** Preserved #289/#358's `StageEntry` / `VecDeque` cross-class LRU eviction, `[0..bytes)` zeroing, `zero_upload_tests`, and `StagePool::trim` full 0-byte idle drain (`ram_idle_ms` + 4 frames); layered `ram_trim::TrimPolicy` tightening additively on top when `panic_memory || pool_idle_ms < upstream_idle_ms`, and kept `Staging` drops outside `STAGING` lock. - **`pipeline.rs`:** Preserved #377's `ACCC` fallback (`victory_shader::emit::nvidia::enabled()`) in both `translate()` and inside `of_builder()`'s cached `builder_spilled`. - **`host.rs` & `host/scratch_tests.rs`:** Preserved #358's FIFO-evicting `Spare::give` and `ResultRing` (`trim_card_work_with` checks `work.taken.used() == 0`) alongside `Spare::trim` / `CardWork::fetched_ms`, and preserved #383 (`step_index`, `sync_batched`, `parallel_refresh`). - **`shadow.rs` & `watch.rs`:** Preserved #377 (`after_writer`) and #358 (`Card::prints`/`me`, `note_carded`, `FLAGGED`, `window_same`, `page_writes_mode`) cleanly alongside `SnapshotBuffer` and `title_memory_remapped`. Verified on `69a0a8c`: `cargo xtask policy` (`215 files ok`), `cargo clippy -p victory-gpu --lib --tests` (0 new warnings), `VICTORY_D3D12_DEBUG=1` `ram_trim` 14/14 and `texture::` 8/8 (`victory-gpu --lib`: 252 passed default / 265 passed `--features diagnostics`, with only the 3 pre-existing `main` failures in `descriptor::host` and `indirect::warp_card_{fetch,patch}`). Ready for your next integration build.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 19:19 UTC · original

Noting that #409 (37d4686) replaced third_party/victory with the combined avatarmanz + cool_fox base, putting this branch in CONFLICTING.
The clean avatarmanz-lineage version is open at avatarmanz/VIctory-7900XTX#205 (and fxceless/victory-fork#1286); happy to re-port onto 37d4686+ once #409 settles if you want it here.

**@⁠Vladimir-Human** on GitHub · 2026-11-26 19:19 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/350#issuecomment-7201452354) Noting that #409 (`37d4686`) replaced `third_party/victory` with the combined `avatarmanz + cool_fox` base, putting this branch in `CONFLICTING`. The clean `avatarmanz`-lineage version is open at `avatarmanz/VIctory-7900XTX#205` (and `fxceless/victory-fork#1286`); happy to re-port onto `37d4686+` once `#409` settles if you want it here.
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/src/copystat.rs
  • third_party/victory/crates/victory-gpu/src/host.rs
  • third_party/victory/crates/victory-gpu/src/host/scratch_tests.rs
  • third_party/victory/crates/victory-gpu/src/lib.rs
  • third_party/victory/crates/victory-gpu/src/list.rs
  • third_party/victory/crates/victory-gpu/src/pipeline.rs
  • third_party/victory/crates/victory-gpu/src/pipeline/host.rs
  • third_party/victory/crates/victory-gpu/src/shadow.rs
  • third_party/victory/crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/350/head:github-bot/gh-350'
git switch 'github-bot/gh-350'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-350'
git switch 'github-bot/gh-350'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-350'
git switch 'github-bot/gh-350'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-350'
git switch 'main'
git merge --squash 'github-bot/gh-350'
git switch 'main'
git merge --ff-only 'github-bot/gh-350'
git switch 'main'
git merge 'github-bot/gh-350'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.