perf(gpu,loader): adaptive RAM/VRAM memory pools and faster submit preparation #480

Closed
github-bot wants to merge 1 commit from github-bot/gh-480 into a-publier AGit
Owner

@⁠bla1r1 on GitHub · 2026-11-27 05:53 UTC · original
bla1r1:perf/adaptive-memory-and-submit → a-publier · +580 −103 · 10 files · 1 commits · closed without merging

Summary

Improves memory scaling on 8 GB VRAM / 24–32 GB RAM systems (while scaling upward on larger cards) and cuts CPU/copy-queue stalls on the submission path.

Changes

  • Adaptive RAM/VRAM budgets & trimming (host.rs, list.rs, pool.rs, residency.rs, resource.rs, texture.rs, shadow.rs)
    • Scale target local VRAM budget (default_room_percent_for: 78% for <= 9 GiB, 85% for <= 12 GiB, 90% for > 12 GiB).
    • Adjust ram_band physical working-set hysteresis thresholds (Watch >= 70%, High >= 80%, recovery <= 60% / 75%) so 24–32 GB hosts do not stay stuck in High pressure around ~14 GiB.
    • Add RamBand-aware trimming and budgets for UPLOAD_POOL (128 / 64 / 32 / 0 MiB), SPARE scratch chunks (trim_spare_chunks_to), idle HostList pools (idle_limits / trim_idle), let_go_idle(), and snapshot buffers (snapshot_budget_bytes: 768 / 512 / 256 / 64 MiB + trim_snapshots).
  • Submission & worker throughput (host.rs, shadow.rs, land.rs)
    • Skip redundant copy-queue resident() / synchronous mapped() waits for CPU L0 shared_buffer() allocations (D3D12_HEAP_FLAG_NONE) and remove synchronous mapped() stalls on future-list-only uav_buffer()s.
    • Scale wide_threads() ((n * 3) / 4, clamped 2..=6) and land::threads() (n / 2, clamped 2..=6).
    • Handle DXGI_STATUS_OCCLUDED cleanly in frame metering (VICTORY_METER_OCCLUDED).
  • Loader & build ergonomics (resolution.rs, Cargo.toml)
    • Accept string aliases (own / fsr) alongside numeric IDs in parse_upscaler (VICTORY_UPSCALER).
    • Tune dev and diag Cargo profiles (incremental = true, higher codegen-units, reduced dependency debuginfo) for faster local rebuilds.

Verification

  • cargo test --workspace --locked: all workspace crates and xtask policy/switch tests pass (0 failures).
  • cargo build --locked --profile diag -p victory --features diagnostics and cargo build --locked --release -p victory: clean builds.
  • Measured on Windows 11 (i7-9700K, 27.9 GB RAM, RX 6600 8 GB, Adrenalin 26.11.2, --console series-s, 5 renderer ports, 135 s release run):
    • Synchronous mapped() waits reduced from 38,400 calls / 39,236 ms to 600 calls / 245.7 ms with 0 device resets (DXGI_ERROR_DEVICE_RESET).
    • Peak host memory: 19,072.8 MB WS / 18,692.6 MB Private.
    • Menus run at 29.3–30.1 FPS; heavy opening 3D cutscene runs at 0.5–4.7 FPS on this 8C CPU.
**@⁠bla1r1** on GitHub · 2026-11-27 05:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/480) `bla1r1:perf/adaptive-memory-and-submit` → `a-publier` · +580 −103 · 10 files · 1 commits · closed without merging ## Summary Improves memory scaling on 8 GB VRAM / 24–32 GB RAM systems (while scaling upward on larger cards) and cuts CPU/copy-queue stalls on the submission path. ### Changes - **Adaptive RAM/VRAM budgets & trimming (`host.rs`, `list.rs`, `pool.rs`, `residency.rs`, `resource.rs`, `texture.rs`, `shadow.rs`)** - Scale target local VRAM budget (`default_room_percent_for`: `78%` for `<= 9 GiB`, `85%` for `<= 12 GiB`, `90%` for `> 12 GiB`). - Adjust `ram_band` physical working-set hysteresis thresholds (`Watch >= 70%`, `High >= 80%`, recovery `<= 60% / 75%`) so 24–32 GB hosts do not stay stuck in `High` pressure around ~14 GiB. - Add `RamBand`-aware trimming and budgets for `UPLOAD_POOL` (`128 / 64 / 32 / 0 MiB`), `SPARE` scratch chunks (`trim_spare_chunks_to`), idle `HostList` pools (`idle_limits` / `trim_idle`), `let_go_idle()`, and snapshot buffers (`snapshot_budget_bytes`: `768 / 512 / 256 / 64 MiB` + `trim_snapshots`). - **Submission & worker throughput (`host.rs`, `shadow.rs`, `land.rs`)** - Skip redundant copy-queue `resident()` / synchronous `mapped()` waits for CPU `L0` `shared_buffer()` allocations (`D3D12_HEAP_FLAG_NONE`) and remove synchronous `mapped()` stalls on future-list-only `uav_buffer()`s. - Scale `wide_threads()` (`(n * 3) / 4`, clamped `2..=6`) and `land::threads()` (`n / 2`, clamped `2..=6`). - Handle `DXGI_STATUS_OCCLUDED` cleanly in frame metering (`VICTORY_METER_OCCLUDED`). - **Loader & build ergonomics (`resolution.rs`, `Cargo.toml`)** - Accept string aliases (`own` / `fsr`) alongside numeric IDs in `parse_upscaler` (`VICTORY_UPSCALER`). - Tune `dev` and `diag` Cargo profiles (`incremental = true`, higher `codegen-units`, reduced dependency debuginfo) for faster local rebuilds. ## Verification - `cargo test --workspace --locked`: all workspace crates and `xtask` policy/switch tests pass (0 failures). - `cargo build --locked --profile diag -p victory --features diagnostics` and `cargo build --locked --release -p victory`: clean builds. - Measured on Windows 11 (`i7-9700K`, `27.9 GB RAM`, `RX 6600 8 GB`, Adrenalin 26.11.2, `--console series-s`, 5 renderer ports, 135 s release run): - Synchronous `mapped()` waits reduced from `38,400 calls / 39,236 ms` to `600 calls / 245.7 ms` with `0` device resets (`DXGI_ERROR_DEVICE_RESET`). - Peak host memory: `19,072.8 MB WS` / `18,692.6 MB Private`. - Menus run at `29.3–30.1 FPS`; heavy opening 3D cutscene runs at `0.5–4.7 FPS` on this 8C CPU.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 05:57:11 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 07:01 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At 4b4e4c1: victory-gpu 401 passed, 0 failed, 34 ignored; victory-loader 57 passed.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 07:01 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/480#issuecomment-7212070698) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `4b4e4c1`: `victory-gpu` 401 passed, 0 failed, 34 ignored; `victory-loader` 57 passed. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠gw1337x on GitHub · 2026-11-27 08:50 UTC · original

Tested in the title on RDNA 3: RX 7800 XT 16 GB, driver 32.0.32015.7029, Ryzen 7 9800X3D, 32 GB RAM, Windows 11 26200 (Memory Integrity off). Diagnostics builds (--profile diag --features diagnostics) of 4b4e4c1 and its base 4eb6cfd, same boot.

Settings: scripts/play.ps1 settings plus VICTORY_PORT_CONSTANTS/DESCRIPTORS/CBV/GUARD/JOURNAL=1, Series X profile, ray tracing off. Method: 270 s hands-off from a Chapter I boat save; fps is the layer's 1 s figure from the window title, sampled every second, 45-265 s with 1000+ draws ("steady" from 205 s); per-frame figures from VICTORY_TIMELINE windows of 30 frames at 200 s and 240 s.

Run (order) Build median / steady fps seconds < 15 fps card running / idle per frame host lists made peak commit
2 4eb6cfd 27.0 / 28.0 22 31.6-32.1 / 2.7-3.0 ms 2,901 32.6 GB
3 4b4e4c1 17.0 / 18.0 70 33.5-34.8 / 21.0-31.1 ms 91,332 33.0 GB
5 4eb6cfd 26.5 / 29.0 14 30.9-32.2 / 2.5 ms 2,886 33.8 GB
6 4b4e4c1 18.0 / 18.0 45 33.0-33.5 / 18.5-21.8 ms 91,216 32.6 GB
7 4b4e4c1 code, base Cargo.toml layer's log: 16.7 / 17.4 16 (log, 5 s samples) - 98,490 32.6 GB

(Runs 1 and 4 were another PR.) Run 7 puts back the base's Cargo.toml (codegen-units 16, not incremental) to rule out the profile change; the drop stays, so it comes from the code.

What showed:

  • On this card fps drops by about 10 (28-29 to 17-18 steady) in all three runs of the PR. In runs 3 and 6 the card is idle 18-31 ms a frame against 2.5-3 ms on the base (run 7 had no timeline).
  • In the 240 s window's chain back through all frames, the PR's runs have "landed lists reset and given back" at 18.7 and 10.1 ms a frame, the largest or second-largest item. On the base it is not in the top 14; there the chain is the card running submissions (27 ms a frame).
  • The layer's count of host lists made is about 31 times the base's (91-98 thousand against 2.9 thousand per run).
  • Peak commit is the same (32.6-33.8 GB against 32.6-33.8 GB), and free RAM is no higher in a way I can tell apart from noise. No device loss.

I did not split which of the PR's changes makes the lists be made again; the count and the span point at host-list reuse, but that is not isolated.

**@⁠gw1337x** on GitHub · 2026-11-27 08:50 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/480#issuecomment-7213982218) Tested in the title on RDNA 3: RX 7800 XT 16 GB, driver 32.0.32015.7029, Ryzen 7 9800X3D, 32 GB RAM, Windows 11 26200 (Memory Integrity off). Diagnostics builds (`--profile diag --features diagnostics`) of `4b4e4c1` and its base `4eb6cfd`, same boot. Settings: `scripts/play.ps1` settings plus `VICTORY_PORT_CONSTANTS/DESCRIPTORS/CBV/GUARD/JOURNAL=1`, Series X profile, ray tracing off. Method: 270 s hands-off from a Chapter I boat save; fps is the layer's 1 s figure from the window title, sampled every second, 45-265 s with 1000+ draws ("steady" from 205 s); per-frame figures from `VICTORY_TIMELINE` windows of 30 frames at 200 s and 240 s. | Run (order) | Build | median / steady fps | seconds < 15 fps | card running / idle per frame | host lists made | peak commit | |---|---|---|---|---|---|---| | 2 | `4eb6cfd` | 27.0 / 28.0 | 22 | 31.6-32.1 / 2.7-3.0 ms | 2,901 | 32.6 GB | | 3 | `4b4e4c1` | 17.0 / 18.0 | 70 | 33.5-34.8 / 21.0-31.1 ms | 91,332 | 33.0 GB | | 5 | `4eb6cfd` | 26.5 / 29.0 | 14 | 30.9-32.2 / 2.5 ms | 2,886 | 33.8 GB | | 6 | `4b4e4c1` | 18.0 / 18.0 | 45 | 33.0-33.5 / 18.5-21.8 ms | 91,216 | 32.6 GB | | 7 | `4b4e4c1` code, base `Cargo.toml` | layer's log: 16.7 / 17.4 | 16 (log, 5 s samples) | - | 98,490 | 32.6 GB | (Runs 1 and 4 were another PR.) Run 7 puts back the base's `Cargo.toml` (codegen-units 16, not incremental) to rule out the profile change; the drop stays, so it comes from the code. What showed: - On this card fps drops by about 10 (28-29 to 17-18 steady) in all three runs of the PR. In runs 3 and 6 the card is idle 18-31 ms a frame against 2.5-3 ms on the base (run 7 had no timeline). - In the 240 s window's chain back through all frames, the PR's runs have "landed lists reset and given back" at 18.7 and 10.1 ms a frame, the largest or second-largest item. On the base it is not in the top 14; there the chain is the card running submissions (27 ms a frame). - The layer's count of host lists made is about 31 times the base's (91-98 thousand against 2.9 thousand per run). - Peak commit is the same (32.6-33.8 GB against 32.6-33.8 GB), and free RAM is no higher in a way I can tell apart from noise. No device loss. I did not split which of the PR's changes makes the lists be made again; the count and the span point at host-list reuse, but that is not isolated.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 10:14 UTC · original

Review of 4b4e4c1, with two semantic regressions shown by failing tests (on an RX 6950 XT; the tests are appended to the PR's own files, not committed):

  1. Under memory pressure, idle windows are freed less than when calm (shadow.rs let_go_idle, ~3036-3049). On a-publier, without VICTORY_WINDOW_BUDGET_MB (the default), keep stayed u64::MAX, so every eligible idle window went. Now the Watch band keeps total/8 and High keeps total/16. window_victims frees only what is above that, and min(idle_ms, 10_000) changes nothing when the base is already 10 s or less. Test: a 32 GiB machine with 3 GiB of idle windows. review_watch_frees_at_least_calm fails with calm frees 12 windows, watch frees 0.
  2. On 12 GB cards the texture cap now steps down before the room limit (resource.rs over_cap_max, default_room_percent_for). A 12 GB card's budget (~10,200 MB) is at most 10 GiB, so it counts as "tight", though the comment targets 6 to 8 GB cards. The mip cap drops to 512 at 82 % use while room_percent is 85 %; before, the cap (92 %) sat above the room limit (90 %). review_cap_not_below_room_on_12gb_card fails with room 85%: cap already 512 at 84% (left: 512, right: 1024).

Also, from reading:

  • A device-loss guard is removed: shared_buffer drops not_resident(), resident() and mapped(), and uav_buffer drops mapped(). The comment on mapped() (host.rs ~257-262) says MakeResident alone was not enough (runs n08/n11). That is safe only if these buffers' addresses never reach descriptor slots that lists already sent read. I could not confirm that for shared_buffer copies of title memory.
  • Residency is on by default (residency.rs:20, the same flip as #481's). limited_host_ram() is then true on any machine with 32 GiB or less, which lowers the bury lag from 64 to 16 submissions (that lag was itself a device-loss fix, host.rs ~615-620).
  • host.rs:6158: mem::take(&mut l.deferred().writes) replaces a clone. If a submission runs list A, then B, then A again, the second A contributes no writes, so the late path and the non-late path now disagree.

Checked with no issue: the upload pool's reuse and lifetimes, the trim functions' counters, the locks, the copying Option change.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 10:14 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/480#issuecomment-7215650746) Review of `4b4e4c1`, with two semantic regressions shown by failing tests (on an RX 6950 XT; the tests are appended to the PR's own files, not committed): 1. **Under memory pressure, idle windows are freed less than when calm** (`shadow.rs` `let_go_idle`, ~3036-3049). On `a-publier`, without `VICTORY_WINDOW_BUDGET_MB` (the default), `keep` stayed `u64::MAX`, so every eligible idle window went. Now the Watch band keeps `total/8` and High keeps `total/16`. `window_victims` frees only what is above that, and `min(idle_ms, 10_000)` changes nothing when the base is already 10 s or less. Test: a 32 GiB machine with 3 GiB of idle windows. `review_watch_frees_at_least_calm` fails with `calm frees 12 windows, watch frees 0`. 2. **On 12 GB cards the texture cap now steps down before the room limit** (`resource.rs` `over_cap_max`, `default_room_percent_for`). A 12 GB card's budget (~10,200 MB) is at most 10 GiB, so it counts as "tight", though the comment targets 6 to 8 GB cards. The mip cap drops to 512 at 82 % use while `room_percent` is 85 %; before, the cap (92 %) sat above the room limit (90 %). `review_cap_not_below_room_on_12gb_card` fails with `room 85%: cap already 512 at 84%` (`left: 512, right: 1024`). Also, from reading: - **A device-loss guard is removed:** `shared_buffer` drops `not_resident()`, `resident()` and `mapped()`, and `uav_buffer` drops `mapped()`. The comment on `mapped()` (host.rs ~257-262) says `MakeResident` alone was not enough (runs n08/n11). That is safe only if these buffers' addresses never reach descriptor slots that lists already sent read. I could not confirm that for `shared_buffer` copies of title memory. - **Residency is on by default** (`residency.rs:20`, the same flip as #481's). `limited_host_ram()` is then true on any machine with 32 GiB or less, which lowers the bury lag from 64 to 16 submissions (that lag was itself a device-loss fix, host.rs ~615-620). - **`host.rs:6158`:** `mem::take(&mut l.deferred().writes)` replaces a clone. If a submission runs list A, then B, then A again, the second A contributes no writes, so the late path and the non-late path now disagree. Checked with no issue: the upload pool's reuse and lifetimes, the trim functions' counters, the locks, the `copying` `Option` change. AI-assisted (Claude Code); no game data.
github-bot closed this pull request 2026-11-27 11:07:42 +00:00

Pull request closed

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