Add opt-in VRAM-first residency and ReBAR pool scaling #522

Closed
github-bot wants to merge 2 commits from github-bot/gh-522 into main AGit
Owner

@⁠Ayphex on GitHub · 2026-12-04 21:29 UTC · original
Ayphex:exp/vram-first-residency → main · +1764 −111 · 16 files · 2 commits · closed without merging

Summary

Adds an opt-in, configurable VRAM-first residency mode (VICTORY_VRAM_FIRST=1) for Linux + AMD RADV GPUs with full Resizable BAR (ReBAR / SAM) (where um loads), while keeping VICTORY_VRAM_FIRST=0 (default) bit-for-bit identical to baseline and safely falling back on native Windows, NVIDIA, and WARP.

Key Changes

  • VRAM Policy & Telemetry (crates/victory-gpu/src/um/vram_policy.rs):
    • Core switches: VICTORY_VRAM_FIRST, VICTORY_VRAM_BUDGET_MB, VICTORY_VRAM_CLASSES (tiles,textures,rt,bvh,buffers or bitmask), VICTORY_VRAM_REBAR, and VICTORY_VRAM_STATS.
    • Tile residency tuning switches: VICTORY_TILE_TAINT (sticky|backoff|off, default sticky), VICTORY_TILE_QUIESCE_TICKS (default 15 ticks / 3.0 s), and VICTORY_TILE_PROMOTE_CAP_MB (default 16 MiB/tick).
    • Automatic safe VRAM budget calculation with headroom (13,808 MiB on a 16 GiB card) and live kernel VRAM + free-VRAM gating to prevent VK_ERROR_OUT_OF_DEVICE_MEMORY.
    • Periodic [vram-first] telemetry logging and F3 HUD status/counters (gtt_fallbacks, held_back, cpu_read_demotions, cold_wc_demotions, plus tile[tainted_tile_ranges, taint_skips, quiescent_promotions, paced_deferrals, peak_tiles_mb, avg_tiles_mb]).
  • Tile Quiescence, Sticky CPU-Read Taint & Pacing (residency.rs, safecopy.rs, resource.rs):
    • Sticky per-page CPU-read taint (or exponential 10 -> 40 -> 160 -> permanent backoff) prevents repeatedly demoted PhysicalTiles pages from churning through retire/promote/fault cycles, and clears cleanly (along with class, quiesce, and STRIKES) when a physical tile page is unmapped, remapped, or freed.
    • Write- & read-quiescence promotion promotes untainted, non-TEX_SOURCE, GPU-SEEN PhysicalTiles pages after VICTORY_TILE_QUIESCE_TICKS quiet ticks, resetting the countdown on CPU touch, host read_through, and pool-window wrote_through.
    • Per-tick promotion pacing (VICTORY_TILE_PROMOTE_CAP_MB) caps quiescent tile migrations per 200 ms pass with async kicks to protect 1% lows.
    • Clean class routing & texture budget: isolates PhysicalTiles under VramClasses::TILES (fixing buffers leaking into tiles and accurately attributing up_tiles), and avoids double-applying room_percent (86%) on top of vf_budget in resource::room().
  • Committed Buffer Pools (lazy.rs, um.rs, xmem.rs, draw.rs, records.rs, texture.rs, memory.rs):
    • Registers non-WC committed XMemVirtualAlloc pools as paged CommittedBuffers (lazy::register_committed) when VramClasses::BUFFERS is enabled, with VICTORY_VRAM_FIRST=0 gated cleanly for exact baseline parity.
    • Supports VICTORY_VRAM_REBAR=0 fallback (bypasses direct ReBAR upload pools).
  • vkd3d-proton ReBAR Pool Scaling (patches/vkd3d.patch):
    • Scales rebar_budget from heap/16 (~1 GiB) up to min(heap/4, 3072 MiB) (bounded by VICTORY_VRAM_BUDGET_MB / 4) when VICTORY_VRAM_FIRST=1, disables HVV upload when VICTORY_VRAM_REBAR=0, and matches Rust's boolean env parsing (1|true|on|yes / 0|false|off|no, trimmed, case-insensitive).
  • Docs (docs/SETTINGS.md, run.conf.default): Documented all switches and Linux + AMD RADV ReBAR scope.

Benchmarks (RX 6800 XT 16 GB Full ReBAR, i9-12900K, VICTORY_BENCH=nort, 3840x2160 FSR4 Quality, 60 s timed window)

Back-to-Back Head-to-Head (origin/main vs. A1 786f5c7 vs. A1.5 04763db)

Config Binary CLASSES Avg FPS vs. main 1% Low vs. main Power tiles VRAM (Peak / Last-60s) cpu_read_demotions taint_skips gtt_fallbacks
origin/main 3fe840c off 22.6 — 9.8 — 178.1 W — — — —
A1.5 buffers 04763db buffers 22.9 +1.3% 10.2 +4.1% 181.3 W 0 / 0 MB 120 0 0
A1 buffers 786f5c7 buffers 23.2 +2.7% 10.7 +9.2% 182.9 W 172 / 142 MB 872 — 0
A1 all 786f5c7 all 23.9 +5.8% 11.8 +20.4% 184.9 W 169 / 135 MB 962 — 0
A1.5 all (default) 04763db all 24.2 +7.1% 11.8 +20.4% 187.7 W 577 / 466 MB 1,925 (9,048 quiet up) 478,176 0

(In an earlier daytime/twilight run on the same build, A1.5 CLASSES=all peaked at 26.7 FPS avg / 13.2 1% low / 188.3 W / 681 MB tiles in VRAM, with steady-state in-world demotions at 11–43 per 10 s.)

Verification

  • git apply --check patches/vkd3d.patch passes cleanly against deps/vkd3d HEAD.
  • ./build.sh compiles with 0 warnings / 0 errors.
  • PKG=victory-gpu ./build.sh test --lib -- um:: passes 12/12 tests under Wine (including sticky taint, 10 -> 40 -> 160 -> permanent backoff, unmap/remap clearing, quiescence reset on CPU touch/write, pacing cap + deferral accounting, class attribution, and knob parsing).
  • cargo xtask policy passes (359 files ok) and branch merges cleanly onto current origin/main (b581f7e).
**@⁠Ayphex** on GitHub · 2026-12-04 21:29 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/522) `Ayphex:exp/vram-first-residency` → `main` · +1764 −111 · 16 files · 2 commits · closed without merging ## Summary Adds an opt-in, configurable **VRAM-first residency** mode (`VICTORY_VRAM_FIRST=1`) for **Linux + AMD RADV GPUs with full Resizable BAR (ReBAR / SAM)** (where `um` loads), while keeping `VICTORY_VRAM_FIRST=0` (default) bit-for-bit identical to baseline and safely falling back on native Windows, NVIDIA, and WARP. ### Key Changes - **VRAM Policy & Telemetry (`crates/victory-gpu/src/um/vram_policy.rs`)**: - Core switches: `VICTORY_VRAM_FIRST`, `VICTORY_VRAM_BUDGET_MB`, `VICTORY_VRAM_CLASSES` (`tiles,textures,rt,bvh,buffers` or bitmask), `VICTORY_VRAM_REBAR`, and `VICTORY_VRAM_STATS`. - Tile residency tuning switches: `VICTORY_TILE_TAINT` (`sticky|backoff|off`, default `sticky`), `VICTORY_TILE_QUIESCE_TICKS` (default `15` ticks / `3.0 s`), and `VICTORY_TILE_PROMOTE_CAP_MB` (default `16` MiB/tick). - Automatic safe VRAM budget calculation with headroom (`13,808 MiB` on a 16 GiB card) and live kernel VRAM + free-VRAM gating to prevent `VK_ERROR_OUT_OF_DEVICE_MEMORY`. - Periodic `[vram-first]` telemetry logging and F3 HUD status/counters (`gtt_fallbacks`, `held_back`, `cpu_read_demotions`, `cold_wc_demotions`, plus `tile[tainted_tile_ranges, taint_skips, quiescent_promotions, paced_deferrals, peak_tiles_mb, avg_tiles_mb]`). - **Tile Quiescence, Sticky CPU-Read Taint & Pacing (`residency.rs`, `safecopy.rs`, `resource.rs`)**: - **Sticky per-page CPU-read taint** (or exponential `10 -> 40 -> 160 -> permanent` backoff) prevents repeatedly demoted `PhysicalTiles` pages from churning through retire/promote/fault cycles, and clears cleanly (along with `class`, `quiesce`, and `STRIKES`) when a physical tile page is unmapped, remapped, or freed. - **Write- & read-quiescence promotion** promotes untainted, non-`TEX_SOURCE`, GPU-`SEEN` `PhysicalTiles` pages after `VICTORY_TILE_QUIESCE_TICKS` quiet ticks, resetting the countdown on CPU touch, host `read_through`, and pool-window `wrote_through`. - **Per-tick promotion pacing** (`VICTORY_TILE_PROMOTE_CAP_MB`) caps quiescent tile migrations per 200 ms pass with async kicks to protect 1% lows. - **Clean class routing & texture budget**: isolates `PhysicalTiles` under `VramClasses::TILES` (fixing `buffers` leaking into tiles and accurately attributing `up_tiles`), and avoids double-applying `room_percent` (86%) on top of `vf_budget` in `resource::room()`. - **Committed Buffer Pools (`lazy.rs`, `um.rs`, `xmem.rs`, `draw.rs`, `records.rs`, `texture.rs`, `memory.rs`)**: - Registers non-WC committed `XMemVirtualAlloc` pools as paged `CommittedBuffers` (`lazy::register_committed`) when `VramClasses::BUFFERS` is enabled, with `VICTORY_VRAM_FIRST=0` gated cleanly for exact baseline parity. - Supports `VICTORY_VRAM_REBAR=0` fallback (bypasses direct ReBAR upload pools). - **`vkd3d-proton` ReBAR Pool Scaling (`patches/vkd3d.patch`)**: - Scales `rebar_budget` from `heap/16` (~1 GiB) up to `min(heap/4, 3072 MiB)` (bounded by `VICTORY_VRAM_BUDGET_MB / 4`) when `VICTORY_VRAM_FIRST=1`, disables HVV upload when `VICTORY_VRAM_REBAR=0`, and matches Rust's boolean env parsing (`1|true|on|yes` / `0|false|off|no`, trimmed, case-insensitive). - **Docs (`docs/SETTINGS.md`, `run.conf.default`)**: Documented all switches and Linux + AMD RADV ReBAR scope. ## Benchmarks (RX 6800 XT 16 GB Full ReBAR, i9-12900K, `VICTORY_BENCH=nort`, 3840x2160 FSR4 Quality, 60 s timed window) ### Back-to-Back Head-to-Head (`origin/main` vs. A1 `786f5c7` vs. A1.5 `04763db`) | Config | Binary | `CLASSES` | Avg FPS | vs. `main` | 1% Low | vs. `main` | Power | `tiles` VRAM (Peak / Last-60s) | `cpu_read_demotions` | `taint_skips` | `gtt_fallbacks` | |---|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:| | `origin/main` | `3fe840c` | off | 22.6 | — | 9.8 | — | 178.1 W | — | — | — | — | | A1.5 `buffers` | `04763db` | `buffers` | 22.9 | +1.3% | 10.2 | +4.1% | 181.3 W | 0 / 0 MB | 120 | 0 | 0 | | A1 `buffers` | `786f5c7` | `buffers` | 23.2 | +2.7% | 10.7 | +9.2% | 182.9 W | 172 / 142 MB | 872 | — | 0 | | A1 `all` | `786f5c7` | `all` | 23.9 | +5.8% | **11.8** | **+20.4%** | 184.9 W | 169 / 135 MB | 962 | — | 0 | | **A1.5 `all` (default)** | **`04763db`** | **`all`** | **24.2** | **+7.1%** | **11.8** | **+20.4%** | **187.7 W** | **577 / 466 MB** | 1,925 (`9,048` quiet up) | **478,176** | **0** | *(In an earlier daytime/twilight run on the same build, A1.5 `CLASSES=all` peaked at **26.7 FPS avg / 13.2 1% low / 188.3 W / 681 MB** tiles in VRAM, with steady-state in-world demotions at `11–43` per 10 s.)* ## Verification - `git apply --check patches/vkd3d.patch` passes cleanly against `deps/vkd3d` `HEAD`. - `./build.sh` compiles with `0` warnings / `0` errors. - `PKG=victory-gpu ./build.sh test --lib -- um::` passes `12/12` tests under Wine (including sticky taint, `10 -> 40 -> 160 -> permanent` backoff, unmap/remap clearing, quiescence reset on CPU touch/write, pacing cap + deferral accounting, class attribution, and knob parsing). - `cargo xtask policy` passes (`359 files ok`) and branch merges cleanly onto current `origin/main` (`b581f7e`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 21:31:45 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 22:07 UTC · original

Checked 786f5c7 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It merges cleanly onto current main.

In short, on native D3D12 the VRAM-first path is almost entirely inert, because everything it steers lives behind um, and um::load only takes an AMD adapter with the RADV alias extension (um.rs:592, the vkMapMemory2 probes after it). On NVIDIA and WARP um::get() is None, so pool/pool_classified return None, init_budget (only caller um.rs:517) never runs and active_budget_bytes() stays 0. I confirmed that with a throwaway test with VICTORY_VRAM_FIRST=1: both pool calls return None, budget 0, snapshot total/budget 0. So the committed-pool promotion test I wanted to write isn't possible here, there are no pools to promote.

Tests

  • cargo test -p victory-gpu --lib (env unset), PR vs main: same 5 failures on both (the two indirect::host_list_*, the two pipeline::host library loads, the flaky watch one), nothing new. Main shows a couple more passes only because the PR branch is a few commits behind (main's newer framegen tests).
  • Same with VICTORY_VRAM_FIRST=1 VICTORY_VRAM_STATS=1: identical result. The PR's own 6 tests (um::vram_policy::tests, um::residency::tests) pass natively too.
  • victory-hle --lib with VICTORY_NATIVE_INPUT=0: 162 passed, same as main.
  • Full victory-gpu lib with --features diagnostics, VICTORY_D3D12_DEBUG=1 and VICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0 VICTORY_VRAM_STATS=1, on the card and on WARP, PR vs main: same failures (on WARP plus the usual descriptor::host views test), nothing new and no debug-layer errors from the new path.
  • Clippy with and without diagnostics: no new warnings vs main.

Native answers to the ReBAR/budget questions

  • ReBAR is detected from the Vulkan memory types: a DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT type on a heap of at least 4 GiB (um.rs:508-510). Live usage comes from the RADV private alias query usage_full (um.rs:849), not DXGI. Nothing in the PR calls QueryVideoMemoryInfo or uses D3D12_HEAP_TYPE_GPU_UPLOAD, so there's no OPTIONS16 check to miss. Natively it falls back safely, no divide by zero, and it can't switch on for WARP or an integrated part since um never loads there.
  • The DXGI budget does flow into resource::room (resource.rs:1787), but with active_budget_bytes() at 0 it keeps the DXGI budget unchanged.
  • The one switch path that does reach native D3D12 is upload_buffer with VICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0 (host.rs:7543), which takes the existing upload_in(size, true) CUSTOM / WRITE_BACK / L0 heap that texture_staging already uses. I checked it: heap comes back CUSTOM, CPU write and read back fine, a GPU copy into a readback buffer matches byte for byte, and the debug layer stays quiet, on the card and on WARP. With REBAR left at 1 it's a plain UPLOAD heap as before.

Off path (env unset) vs main
Mostly gated, but not quite bit-for-bit

  • lazy.rs:589, unbind now needs HELD before the VirtualFree(MEM_PRESERVE_PLACEHOLDER), with no switch check. On main any BOUND page with REAL or KEPT gets its placeholder back. I couldn't find a normal path where a bound page lacks HELD (binds land in placeholders that lazy::reserved marks), so probably no visible change, but a page bound in a placeholder that wasn't marked would now keep its private commit and the next bind there would fail. A dedicated bit for registered committed pages, or gating on vram_policy::has(BUFFERS), would keep main's behaviour exact.
  • residency.rs:1020, the off branch of the up-space math now uses live read at line 807 instead of re-reading LIVE_VRAM like main did. Only a few microseconds of staleness, but not identical.
  • xmem.rs:281, unback calls unregister_committed unconditionally, a lock/unlock per 64K page on every free. It shouldn't match anything with the switch off, it's just extra work.
  • Harmless but ungated: a per-page class array in every paged pool (residency.rs:311), three new page bitmaps, an extra load in hidden() (residency.rs:395), add_tier2/sub_tier2 in placed() (residency.rs:551) and on pool close, usage_full plus four stores each tick (residency.rs:801), a snapshot() per panel frame.
  • VICTORY_VRAM_STATS=1 alone, with FIRST unset, changes the HUD xmem row and prints a stats line (natively that line is all zeros). Probably intended, just noting it.

On path, read only (couldn't run it here)

  • gtt_fallbacks mixes units. In tick it adds held_back every pass (residency.rs:1052), which is a count of pages waiting right now, so summing it each tick grows with time rather than with events. In card_room it adds 1 per refused pool (um.rs:924 onwards). The 3 in the benchmark table probably means "pools refused", but the in-game counter will look a lot bigger after a while.
  • pool_to_card retags the pool as WriteCombined and adds its bytes to the WC counter (um.rs:1280, um.rs:1311), but pages that were promoted under the old kind stay counted there, and the saturating sub_tier2 hides the drift. Telemetry only.
  • class bits per page are never cleared, so a pool page that once held a BVH stays BVH-weighted after the title reuses it.
  • card_room under the switch compares kernel used plus the request against budget minus 512 MiB (um.rs:941), not against what's actually free. Is used per process or the whole heap? If it's per process, another app holding VRAM wouldn't be seen.
  • Env parsing differs between the Rust side (yes, any case, trimmed) and the vkd3d patch (exact 1/true/on), so e.g. VICTORY_VRAM_FIRST=yes turns on the residency policy but not the larger ReBAR upload budget.
  • The kick going async (kick(true) sets HIDDEN, residency.rs:1152) matches what the mesa patch does with HIDDEN on a PLACE kick, so that looks right.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 22:07 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/522#issuecomment-7425546021) Checked 786f5c7 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It merges cleanly onto current main. In short, on native D3D12 the VRAM-first path is almost entirely inert, because everything it steers lives behind `um`, and `um::load` only takes an AMD adapter with the RADV alias extension (um.rs:592, the `vkMapMemory2` probes after it). On NVIDIA and WARP `um::get()` is None, so `pool`/`pool_classified` return None, `init_budget` (only caller um.rs:517) never runs and `active_budget_bytes()` stays 0. I confirmed that with a throwaway test with `VICTORY_VRAM_FIRST=1`: both pool calls return None, budget 0, snapshot total/budget 0. So the committed-pool promotion test I wanted to write isn't possible here, there are no pools to promote. Tests - `cargo test -p victory-gpu --lib` (env unset), PR vs main: same 5 failures on both (the two `indirect::host_list_*`, the two `pipeline::host` library loads, the flaky `watch` one), nothing new. Main shows a couple more passes only because the PR branch is a few commits behind (main's newer framegen tests). - Same with `VICTORY_VRAM_FIRST=1 VICTORY_VRAM_STATS=1`: identical result. The PR's own 6 tests (`um::vram_policy::tests`, `um::residency::tests`) pass natively too. - `victory-hle --lib` with `VICTORY_NATIVE_INPUT=0`: 162 passed, same as main. - Full `victory-gpu` lib with `--features diagnostics`, `VICTORY_D3D12_DEBUG=1` and `VICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0 VICTORY_VRAM_STATS=1`, on the card and on WARP, PR vs main: same failures (on WARP plus the usual `descriptor::host` views test), nothing new and no debug-layer errors from the new path. - Clippy with and without diagnostics: no new warnings vs main. Native answers to the ReBAR/budget questions - ReBAR is detected from the Vulkan memory types: a DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT type on a heap of at least 4 GiB (um.rs:508-510). Live usage comes from the RADV private alias query `usage_full` (um.rs:849), not DXGI. Nothing in the PR calls `QueryVideoMemoryInfo` or uses `D3D12_HEAP_TYPE_GPU_UPLOAD`, so there's no OPTIONS16 check to miss. Natively it falls back safely, no divide by zero, and it can't switch on for WARP or an integrated part since `um` never loads there. - The DXGI budget does flow into `resource::room` (resource.rs:1787), but with `active_budget_bytes()` at 0 it keeps the DXGI budget unchanged. - The one switch path that does reach native D3D12 is `upload_buffer` with `VICTORY_VRAM_FIRST=1 VICTORY_VRAM_REBAR=0` (host.rs:7543), which takes the existing `upload_in(size, true)` CUSTOM / WRITE_BACK / L0 heap that `texture_staging` already uses. I checked it: heap comes back CUSTOM, CPU write and read back fine, a GPU copy into a readback buffer matches byte for byte, and the debug layer stays quiet, on the card and on WARP. With REBAR left at 1 it's a plain UPLOAD heap as before. Off path (env unset) vs main Mostly gated, but not quite bit-for-bit - lazy.rs:589, `unbind` now needs HELD before the `VirtualFree(MEM_PRESERVE_PLACEHOLDER)`, with no switch check. On main any BOUND page with REAL or KEPT gets its placeholder back. I couldn't find a normal path where a bound page lacks HELD (binds land in placeholders that `lazy::reserved` marks), so probably no visible change, but a page bound in a placeholder that wasn't marked would now keep its private commit and the next bind there would fail. A dedicated bit for registered committed pages, or gating on `vram_policy::has(BUFFERS)`, would keep main's behaviour exact. - residency.rs:1020, the off branch of the up-space math now uses `live` read at line 807 instead of re-reading `LIVE_VRAM` like main did. Only a few microseconds of staleness, but not identical. - xmem.rs:281, `unback` calls `unregister_committed` unconditionally, a lock/unlock per 64K page on every free. It shouldn't match anything with the switch off, it's just extra work. - Harmless but ungated: a per-page `class` array in every paged pool (residency.rs:311), three new page bitmaps, an extra load in `hidden()` (residency.rs:395), `add_tier2`/`sub_tier2` in `placed()` (residency.rs:551) and on pool close, `usage_full` plus four stores each tick (residency.rs:801), a `snapshot()` per panel frame. - `VICTORY_VRAM_STATS=1` alone, with FIRST unset, changes the HUD xmem row and prints a stats line (natively that line is all zeros). Probably intended, just noting it. On path, read only (couldn't run it here) - `gtt_fallbacks` mixes units. In `tick` it adds `held_back` every pass (residency.rs:1052), which is a count of pages waiting right now, so summing it each tick grows with time rather than with events. In `card_room` it adds 1 per refused pool (um.rs:924 onwards). The 3 in the benchmark table probably means "pools refused", but the in-game counter will look a lot bigger after a while. - `pool_to_card` retags the pool as WriteCombined and adds its bytes to the WC counter (um.rs:1280, um.rs:1311), but pages that were promoted under the old kind stay counted there, and the saturating `sub_tier2` hides the drift. Telemetry only. - `class` bits per page are never cleared, so a pool page that once held a BVH stays BVH-weighted after the title reuses it. - `card_room` under the switch compares kernel `used` plus the request against budget minus 512 MiB (um.rs:941), not against what's actually free. Is `used` per process or the whole heap? If it's per process, another app holding VRAM wouldn't be seen. - Env parsing differs between the Rust side (`yes`, any case, trimmed) and the vkd3d patch (exact `1`/`true`/`on`), so e.g. `VICTORY_VRAM_FIRST=yes` turns on the residency policy but not the larger ReBAR upload budget. - The kick going async (`kick(true)` sets HIDDEN, residency.rs:1152) matches what the mesa patch does with HIDDEN on a PLACE kick, so that looks right. AI-assisted: yes
Author
Owner

@⁠Ayphex on GitHub · 2026-12-04 23:16 UTC · original

Thanks a ton @⁠Kal0s-design for testing 786f5c7 on native Windows / NVIDIA / WARP and for the detailed audit — every one of those catches was spot-on.

Pushed follow-up commit 04763db onto this branch addressing all of the review items plus the A1.5 tile-residency iteration (without rewriting 786f5c7 so review history stays intact):

Review Fixes in 04763db

  • Strict VICTORY_VRAM_FIRST=0 parity:
    • lazy.rs unbind(): gated the HELD / committed-page branch on vram_policy::has(VramClasses::BUFFERS) so baseline VirtualFree(MEM_PRESERVE_PLACEHOLDER) behavior is exact when off.
    • xmem.rs unback(): gated unregister_committed() on vram_policy::has(VramClasses::BUFFERS) to avoid per-page lock/unlock work on the off path.
    • residency.rs: re-reads LIVE_VRAM.load(Ordering::Relaxed) in the off branch of space, and gates the TEX_SOURCE clear in hidden() on VramClasses::TEXTURES.
  • gtt_fallbacks mixed units: kept gtt_fallbacks strictly as pool-level fallback events (card_room) and moved held_back to its own gauge (held_back= in [vram-first] telemetry).
  • Stale per-page class bits: clear_tile_state() now clears class (along with taint, quiesce, STRIKES, hits, age) whenever a PhysicalTiles page is unmapped or freshly remapped.
  • pool_to_card accounting: subtracts any previously promoted bytes returned by residency::closed(id) from old_kind and LIVE_VRAM before adding WriteCombined bytes.
  • card_room free-VRAM check: checks against budget.min(total) - 512 MiB so global kernel VRAM pressure (e.g. other apps) is respected even if total < budget.
  • patches/vkd3d.patch env parsing: aligned victory_vram_first_enabled / victory_vram_rebar_disabled with Rust's parse_bool_env (1|true|on|yes and 0|false|off|no, trimmed, case-insensitive).
  • Docs: clarified in docs/SETTINGS.md and the PR description that VICTORY_VRAM_FIRST=1 targets Linux + AMD RADV ReBAR (where um loads) and safely falls back on native Windows / NVIDIA / WARP.

A1.5 Tile Quiescence + Sticky CPU-Read Taint + Pacing

  • Added sticky per-page CPU-read taint (VICTORY_TILE_TAINT=sticky|backoff|off), write/read-quiescence promotion for untainted GPU-SEEN PhysicalTiles (VICTORY_TILE_QUIESCE_TICKS=15), per-tick promotion pacing (VICTORY_TILE_PROMOTE_CAP_MB=16), clean PhysicalTiles vs. CommittedBuffers class isolation, and a fix for double-headroom reduction in resource::room().
  • Back-to-back RX 6800 XT 4K FSR4 Quality (VICTORY_BENCH=nort, 60 s) verification: origin/main 22.6 FPS (9.8 1% low) -> A1 all 23.9 FPS (11.8 1% low, 169 MB tiles) -> A1.5 all 24.2 FPS (+7.1%, 11.8 1% low +20.4%, 577 MB tiles in VRAM, 478k taint skips, 0 fallbacks).
  • Verified 12/12 um:: unit tests pass, 0 build warnings, cargo xtask policy passes, patches/vkd3d.patch applies cleanly, and the branch merges cleanly onto current origin/main (b581f7e).
**@⁠Ayphex** on GitHub · 2026-12-04 23:16 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/522#issuecomment-7426902972) Thanks a ton @⁠Kal0s-design for testing `786f5c7` on native Windows / NVIDIA / WARP and for the detailed audit — every one of those catches was spot-on. Pushed follow-up commit `04763db` onto this branch addressing all of the review items plus the A1.5 tile-residency iteration (without rewriting `786f5c7` so review history stays intact): ### Review Fixes in `04763db` - **Strict `VICTORY_VRAM_FIRST=0` parity**: - `lazy.rs` `unbind()`: gated the `HELD` / committed-page branch on `vram_policy::has(VramClasses::BUFFERS)` so baseline `VirtualFree(MEM_PRESERVE_PLACEHOLDER)` behavior is exact when off. - `xmem.rs` `unback()`: gated `unregister_committed()` on `vram_policy::has(VramClasses::BUFFERS)` to avoid per-page lock/unlock work on the off path. - `residency.rs`: re-reads `LIVE_VRAM.load(Ordering::Relaxed)` in the off branch of `space`, and gates the `TEX_SOURCE` clear in `hidden()` on `VramClasses::TEXTURES`. - **`gtt_fallbacks` mixed units**: kept `gtt_fallbacks` strictly as pool-level fallback events (`card_room`) and moved `held_back` to its own gauge (`held_back=` in `[vram-first]` telemetry). - **Stale per-page `class` bits**: `clear_tile_state()` now clears `class` (along with `taint`, `quiesce`, `STRIKES`, `hits`, `age`) whenever a `PhysicalTiles` page is unmapped or freshly remapped. - **`pool_to_card` accounting**: subtracts any previously promoted bytes returned by `residency::closed(id)` from `old_kind` and `LIVE_VRAM` before adding `WriteCombined` bytes. - **`card_room` free-VRAM check**: checks against `budget.min(total) - 512 MiB` so global kernel VRAM pressure (e.g. other apps) is respected even if `total < budget`. - **`patches/vkd3d.patch` env parsing**: aligned `victory_vram_first_enabled` / `victory_vram_rebar_disabled` with Rust's `parse_bool_env` (`1|true|on|yes` and `0|false|off|no`, trimmed, case-insensitive). - **Docs**: clarified in `docs/SETTINGS.md` and the PR description that `VICTORY_VRAM_FIRST=1` targets Linux + AMD RADV ReBAR (where `um` loads) and safely falls back on native Windows / NVIDIA / WARP. ### A1.5 Tile Quiescence + Sticky CPU-Read Taint + Pacing - Added sticky per-page CPU-read taint (`VICTORY_TILE_TAINT=sticky|backoff|off`), write/read-quiescence promotion for untainted GPU-`SEEN` `PhysicalTiles` (`VICTORY_TILE_QUIESCE_TICKS=15`), per-tick promotion pacing (`VICTORY_TILE_PROMOTE_CAP_MB=16`), clean `PhysicalTiles` vs. `CommittedBuffers` class isolation, and a fix for double-headroom reduction in `resource::room()`. - Back-to-back RX 6800 XT 4K FSR4 Quality (`VICTORY_BENCH=nort`, 60 s) verification: `origin/main` `22.6 FPS` (`9.8` 1% low) -> A1 `all` `23.9 FPS` (`11.8` 1% low, `169 MB` tiles) -> A1.5 `all` **`24.2 FPS`** (**`+7.1%`**, **`11.8`** 1% low **`+20.4%`**, **`577 MB`** tiles in VRAM, `478k` taint skips, `0` fallbacks). - Verified `12/12` `um::` unit tests pass, `0` build warnings, `cargo xtask policy` passes, `patches/vkd3d.patch` applies cleanly, and the branch merges cleanly onto current `origin/main` (`b581f7e`).
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 00:02 UTC · original

Re-checked 04763db on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It still merges cleanly onto current main.

Most of the earlier points are fixed. With the env unset, unbind is back to main's condition (lazy.rs:590, the new branch at :598 only runs under BUFFERS), unregister_committed is gated (xmem.rs:281), the off branch of space re-reads LIVE_VRAM (residency.rs:1242), and the TEX_SOURCE clear in hidden() is gated (residency.rs:504). held_back has its own gauge now (residency.rs:1274), so gtt_fallbacks only counts refused pools (um.rs:948). The pool_to_card accounting subtracts what was already on the card (um.rs:1291-1295), and the vkd3d patch parses the env the same way as parse_bool_env.

A few things left.

  • card_room (um.rs:942). budget.min(total) doesn't change anything in practice, because compute_budget_with already keeps the budget at least the headroom below total. So my question is still open: is used from the RADV usage query per process or for the whole heap? If it's per process, other apps' VRAM still isn't seen.
  • Class bits. clear_tile_state (residency.rs:399) only runs for PhysicalTiles pages with FIRST on. In CommittedBuffers and WC pools the bits still stay set until the pool is freed. A stale CLASS_BVH still changes the weight and the cold threshold, and a stale CLASS_BUF keeps a page out of is_texture_only (residency.rs:567).
  • clear_tile_state also does flags.fetch_and(ON_CARD) on remap, so RETIRED, CROWDED and the strike count reset along with the taint. Fine if that's on purpose, just pointing it out since main keeps strikes for the page's lifetime.
  • Still ungated with the env unset. These only run where um loads, so nothing here touches native D3D12. The new taint and quiesce arrays sit next to class in every paged pool (residency.rs:314-316). closed() walks taint for tile pools (residency.rs:346). add_tier2/sub_tier2 run in placed() (residency.rs:662/667), usage_full plus update_kernel_usage run every tick (residency.rs:965), and note_promotion/note_cpu_read_demotion run per moved page (residency.rs:1347, 1360, 1375). All cheap. The one new call that does reach native is residency::wrote_through in safecopy::through (safecopy.rs:180). It returns at the enabled() check (residency.rs:764), so it's one call plus a cached load per write-through chunk.
  • VICTORY_VRAM_STATS=1 alone now also samples the tile counters on each pass (residency.rs:995). Harmless.
  • The rest of the A1.5 code (taint, quiescence, pacing) reads its settings through tile_taint_mode()/tile_quiesce_ticks(), which return Off/0 when FIRST is off. Everything else is behind vram_first, so I found nothing new on the off path apart from the items above.

Tests

  • cargo test -p victory-gpu --lib, env unset, PR vs main: same 5 known failures on both (two indirect::host_list_*, two pipeline::host library loads, the flaky watch one). In one of three PR runs, host::refresh_tests::unchanged_ranges_are_known also failed (write-watch, "written on its last page"). It passed the other two full runs and 5 runs on its own, and host.rs isn't touched, so I think it's just flaky under parallel tests.
  • Same with VICTORY_VRAM_FIRST=1: same 5, nothing new. The new um::residency tests (taint, backoff, quiescence, cap) pass natively.
  • victory-hle --lib with VICTORY_NATIVE_INPUT=0: 162 passed, same as main.
  • Clippy with and without diagnostics: one new warning, manual_checked_division at vram_policy.rs:532 (the avg_tiles division). checked_div(samples).unwrap_or(0) would clear it.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 00:02 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/522#issuecomment-7427791182) Re-checked 04763db on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). It still merges cleanly onto current main. Most of the earlier points are fixed. With the env unset, `unbind` is back to main's condition (lazy.rs:590, the new branch at :598 only runs under BUFFERS), `unregister_committed` is gated (xmem.rs:281), the off branch of `space` re-reads `LIVE_VRAM` (residency.rs:1242), and the `TEX_SOURCE` clear in `hidden()` is gated (residency.rs:504). `held_back` has its own gauge now (residency.rs:1274), so `gtt_fallbacks` only counts refused pools (um.rs:948). The `pool_to_card` accounting subtracts what was already on the card (um.rs:1291-1295), and the vkd3d patch parses the env the same way as `parse_bool_env`. A few things left. - `card_room` (um.rs:942). `budget.min(total)` doesn't change anything in practice, because `compute_budget_with` already keeps the budget at least the headroom below total. So my question is still open: is `used` from the RADV usage query per process or for the whole heap? If it's per process, other apps' VRAM still isn't seen. - Class bits. `clear_tile_state` (residency.rs:399) only runs for PhysicalTiles pages with FIRST on. In CommittedBuffers and WC pools the bits still stay set until the pool is freed. A stale `CLASS_BVH` still changes the weight and the cold threshold, and a stale `CLASS_BUF` keeps a page out of `is_texture_only` (residency.rs:567). - `clear_tile_state` also does `flags.fetch_and(ON_CARD)` on remap, so RETIRED, CROWDED and the strike count reset along with the taint. Fine if that's on purpose, just pointing it out since main keeps strikes for the page's lifetime. - Still ungated with the env unset. These only run where `um` loads, so nothing here touches native D3D12. The new `taint` and `quiesce` arrays sit next to `class` in every paged pool (residency.rs:314-316). `closed()` walks `taint` for tile pools (residency.rs:346). `add_tier2`/`sub_tier2` run in `placed()` (residency.rs:662/667), `usage_full` plus `update_kernel_usage` run every tick (residency.rs:965), and `note_promotion`/`note_cpu_read_demotion` run per moved page (residency.rs:1347, 1360, 1375). All cheap. The one new call that does reach native is `residency::wrote_through` in `safecopy::through` (safecopy.rs:180). It returns at the `enabled()` check (residency.rs:764), so it's one call plus a cached load per write-through chunk. - `VICTORY_VRAM_STATS=1` alone now also samples the tile counters on each pass (residency.rs:995). Harmless. - The rest of the A1.5 code (taint, quiescence, pacing) reads its settings through `tile_taint_mode()`/`tile_quiesce_ticks()`, which return Off/0 when FIRST is off. Everything else is behind `vram_first`, so I found nothing new on the off path apart from the items above. Tests - `cargo test -p victory-gpu --lib`, env unset, PR vs main: same 5 known failures on both (two `indirect::host_list_*`, two `pipeline::host` library loads, the flaky `watch` one). In one of three PR runs, `host::refresh_tests::unchanged_ranges_are_known` also failed (write-watch, "written on its last page"). It passed the other two full runs and 5 runs on its own, and host.rs isn't touched, so I think it's just flaky under parallel tests. - Same with `VICTORY_VRAM_FIRST=1`: same 5, nothing new. The new `um::residency` tests (taint, backoff, quiescence, cap) pass natively. - `victory-hle --lib` with `VICTORY_NATIVE_INPUT=0`: 162 passed, same as main. - Clippy with and without diagnostics: one new warning, `manual_checked_division` at vram_policy.rs:532 (the `avg_tiles` division). `checked_div(samples).unwrap_or(0)` would clear it. AI-assisted: yes
Author
Owner

@⁠luisaugustz on GitHub · 2026-12-05 13:30 UTC · original

Measured on RX 9070 XT 16 GB + Ryzen 7 5800X, RADV with full ReBAR, 3840x2160 output with FSR 4 Performance, ray tracing on (VICTORY_BVH_IN_PLACE=1). I applied it by hand on top of b581f7e: five hunks in um/residency.rs conflicted with local changes, and the vkd3d.patch part was left out.

Runs Spawn downtown route (#554)
Baseline 5 / 10 31.6 16.4
VICTORY_VRAM_FIRST=1 2 / 5 33.0 15.5 (18.5, 15.8, 14.0, 15.2, 14.1)
VICTORY_VRAM_CLASSES=tiles,textures,rt,bvh 1 / 2 33.0 15.5
VICTORY_VRAM_CLASSES=bvh 0 / 1 device removed after about 4 min

City: title memory goes off the card. In the city, VRAM-first seems to move almost all title memory off the card:

Baseline VRAM-first
xmem pool on the card 3.3 GB 0.1 GB
Card VRAM 14.2 GB 13.4–13.7 GB
GTT 10.9 GB 12.4–13.0 GB
Texture handles alive about 52k about 120k
Card time per frame (HUD) about 50 ms 67–75 ms

At 4K the card's total use is already above the computed 13,744 MB budget, so I think the pass stays "pressed" and keeps demoting.

The first minute looks faster, but isn't. The first minute of each VRAM-first run looked much faster (25+ fps), but it also drew far fewer draws, about 5–6k against 7–10k. That looks like streaming lagging behind, not a speedup.

Two problems:

  • Autosave dialog: one VRAM-first run of six showed the title's "couldn't autosave" dialog about a minute into the route. None of about 40 other runs did.
  • Device removed with VICTORY_VRAM_CLASSES=bvh: amdgpu logged a gfxhub page fault (SQC (data), MAPPING_ERROR, PERMISSION_FAULTS: 0x3) from the vkd3d_queue thread, then device removed (0x887A0005). This was with VICTORY_BVH_IN_PLACE=1.

Full tables are in #591.

**@⁠luisaugustz** on GitHub · 2026-12-05 13:30 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/522#issuecomment-7438792601) Measured on RX 9070 XT 16 GB + Ryzen 7 5800X, RADV with full ReBAR, 3840x2160 output with FSR 4 Performance, ray tracing on (`VICTORY_BVH_IN_PLACE=1`). I applied it by hand on top of `b581f7e`: five hunks in `um/residency.rs` conflicted with local changes, and the `vkd3d.patch` part was left out. | | Runs | Spawn | `downtown` route (#554) | |---|---|---|---| | Baseline | 5 / 10 | 31.6 | 16.4 | | `VICTORY_VRAM_FIRST=1` | 2 / 5 | 33.0 | 15.5 (18.5, 15.8, 14.0, 15.2, 14.1) | | `VICTORY_VRAM_CLASSES=tiles,textures,rt,bvh` | 1 / 2 | 33.0 | 15.5 | | `VICTORY_VRAM_CLASSES=bvh` | 0 / 1 | | device removed after about 4 min | **City: title memory goes off the card.** In the city, VRAM-first seems to move almost all title memory off the card: | | Baseline | VRAM-first | |---|---|---| | `xmem pool` on the card | 3.3 GB | 0.1 GB | | Card VRAM | 14.2 GB | 13.4–13.7 GB | | GTT | 10.9 GB | 12.4–13.0 GB | | Texture handles alive | about 52k | about 120k | | Card time per frame (HUD) | about 50 ms | 67–75 ms | At 4K the card's total use is already above the computed 13,744 MB budget, so I think the pass stays "pressed" and keeps demoting. **The first minute looks faster, but isn't.** The first minute of each VRAM-first run looked much faster (25+ fps), but it also drew far fewer draws, about 5–6k against 7–10k. That looks like streaming lagging behind, not a speedup. **Two problems:** - **Autosave dialog:** one VRAM-first run of six showed the title's "couldn't autosave" dialog about a minute into the route. None of about 40 other runs did. - **Device removed with `VICTORY_VRAM_CLASSES=bvh`:** `amdgpu` logged a `gfxhub` page fault (`SQC (data)`, `MAPPING_ERROR`, `PERMISSION_FAULTS: 0x3`) from the `vkd3d_queue` thread, then device removed (`0x887A0005`). This was with `VICTORY_BVH_IN_PLACE=1`. Full tables are in #591.
github-bot closed this pull request 2026-12-05 21:20:06 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.