GPU: opt-in system-RAM budget for idle windows #77

Manually merged
github merged 1 commit from github-bot/gh-77 into main 2026-11-26 08:21:46 +00:00 AGit
Owner

@⁠Adika713 on GitHub · 2026-11-26 02:15 UTC · original
Adika713:mem/system-ram-window-budget → main · +238 −6 · 2 files · 1 commits · merged 2026-11-26 08:17 UTC

What and why

The reported problem is host RAM pressure, but PR #72's new watermark reads DXGI LOCAL VRAM only. This adds an opt-in host-RAM pressure band and caps only idle title-window copies when the process or the PC is under pressure. It does not change a larger pagefile or hide commit exhaustion.

What is in it

  • host::RamBand / ram_band() / ram_sample(): Calm, Watch and High bands from process working set, private bytes, free physical RAM and commit headroom. Process and machine thresholds are fractions of total physical RAM and commit limit; free-RAM and headroom floors are absolute. Entering Watch/High needs higher pressure than leaving it, so one sample near a threshold does not toggle policy.
  • VICTORY_WINDOW_BUDGET_MB, off by default. Unset or 0 keeps today's sweep exactly. With a positive value, Watch caps unique idle-window bytes at that many MiB and reduces the idle timeout to 10 s; High halves the byte cap and reduces it to 2 s. A failed Windows query leaves the band and cap unchanged.
  • shadow::window_victims() removes only the oldest still-idle, still-unreferenced copies until the unique bytes fit the cap. A copy standing under several keys is counted once. The same safety checks as the existing sweep apply: no list, descriptor slot or submission may hold the copy or its buffer.
  • Five game-free unit tests cover band entry, hysteresis and exit, plus oldest-first eviction and duplicate-counting.

Tested

RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB, Windows 11. Exact command in an isolated target dir:

cargo test --locked -p victory-gpu --lib -- --test-threads=1

  • Targeted ram_band: 3 passed / 0 failed.
  • Targeted window_budget: 2 passed / 0 failed.
  • Full victory-gpu lib: 330 passed / 1 failed / 34 ignored, 365 tests, exit 101. The only failure is the pre-existing descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in; base 0a43566 has the same failure (325 passed / 1 failed / 34 ignored, exit 101). No new failure.

Logs: _agent_reports\logs\mem-window-budget-lib.log and .exit.txt in the local report tree.

Not tested

No game run: the local window is black, and target RX 7900 XTX / i9-12900K / 64 GB hardware is unavailable. No working-set, commit, FPS-percentile or visual before/after claim is made. This branch overlaps shadow.rs and host.rs with PR #72 and will conflict if both are merged as-is; the two approaches should be reconciled before merge.

AI use

OpenCode, model Big Pickle.

**@⁠Adika713** on GitHub · 2026-11-26 02:15 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/77) `Adika713:mem/system-ram-window-budget` → `main` · +238 −6 · 2 files · 1 commits · merged 2026-11-26 08:17 UTC ## What and why The reported problem is host RAM pressure, but PR #72's new watermark reads DXGI `LOCAL` VRAM only. This adds an opt-in host-RAM pressure band and caps only idle title-window copies when the process or the PC is under pressure. It does not change a larger pagefile or hide commit exhaustion. ## What is in it - `host::RamBand` / `ram_band()` / `ram_sample()`: Calm, Watch and High bands from process working set, private bytes, free physical RAM and commit headroom. Process and machine thresholds are fractions of total physical RAM and commit limit; free-RAM and headroom floors are absolute. Entering Watch/High needs higher pressure than leaving it, so one sample near a threshold does not toggle policy. - `VICTORY_WINDOW_BUDGET_MB`, off by default. Unset or `0` keeps today's sweep exactly. With a positive value, Watch caps unique idle-window bytes at that many MiB and reduces the idle timeout to 10 s; High halves the byte cap and reduces it to 2 s. A failed Windows query leaves the band and cap unchanged. - `shadow::window_victims()` removes only the oldest still-idle, still-unreferenced copies until the unique bytes fit the cap. A copy standing under several keys is counted once. The same safety checks as the existing sweep apply: no list, descriptor slot or submission may hold the copy or its buffer. - Five game-free unit tests cover band entry, hysteresis and exit, plus oldest-first eviction and duplicate-counting. ## Tested RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB, Windows 11. Exact command in an isolated target dir: `cargo test --locked -p victory-gpu --lib -- --test-threads=1` - Targeted `ram_band`: 3 passed / 0 failed. - Targeted `window_budget`: 2 passed / 0 failed. - Full `victory-gpu` lib: 330 passed / 1 failed / 34 ignored, 365 tests, exit 101. The only failure is the pre-existing `descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in`; base `0a43566` has the same failure (325 passed / 1 failed / 34 ignored, exit 101). No new failure. Logs: `_agent_reports\logs\mem-window-budget-lib.log` and `.exit.txt` in the local report tree. ## Not tested No game run: the local window is black, and target RX 7900 XTX / i9-12900K / 64 GB hardware is unavailable. No working-set, commit, FPS-percentile or visual before/after claim is made. This branch overlaps `shadow.rs` and `host.rs` with PR #72 and will conflict if both are merged as-is; the two approaches should be reconciled before merge. ## AI use OpenCode, model Big Pickle.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:47 +00:00
Author
Owner

@⁠iLucasRT on GitHub · 2026-11-26 03:57 UTC · original

Tested on an RX 7900 XTX 24 GB, Ryzen 7 5800X3D, 64 GB RAM, Windows 11, on top of this repo's main with VICTORY_WINDOW_BUDGET_MB=2048. One 25-minute session played into the open world (run YP4), compared with the same build without this PR (YP3, same save, same settings).

Window copies peaked at 6.2 GB (5.0-5.9 GB most of the session), against 9.2 GB in YP3 by minute 11.
Process private bytes levelled off at about 40 GB for the whole 25 minutes; YP3 was at 42-43 GB by minute 11.
Free commit stayed at 4-6 GB most of the session (lowest 1.8 GB); in YP3 it fell to 1.1-1.2 GB, and the device was lost at minute 12 after an 18 s stall with no work of ours on the card. YP4 ran its full 25 minutes with no device loss.
Caveat: the same build also kept fewer empty 64 MB texture blocks while commit is short, and included #24 and #87, so not all of the gain is this PR's. The window share (about 3-4 GB less) is this PR's alone. On a 64 GB machine the Watch band is mostly entered through commit headroom, not through private bytes against the commit limit.

Thanks!

**@⁠iLucasRT** on GitHub · 2026-11-26 03:57 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/77#issuecomment-7182167860) Tested on an RX 7900 XTX 24 GB, Ryzen 7 5800X3D, 64 GB RAM, Windows 11, on top of this repo's main with `VICTORY_WINDOW_BUDGET_MB=2048`. One 25-minute session played into the open world (run YP4), compared with the same build without this PR (YP3, same save, same settings). Window copies peaked at 6.2 GB (5.0-5.9 GB most of the session), against 9.2 GB in YP3 by minute 11. Process private bytes levelled off at about 40 GB for the whole 25 minutes; YP3 was at 42-43 GB by minute 11. Free commit stayed at 4-6 GB most of the session (lowest 1.8 GB); in YP3 it fell to 1.1-1.2 GB, and the device was lost at minute 12 after an 18 s stall with no work of ours on the card. YP4 ran its full 25 minutes with no device loss. Caveat: the same build also kept fewer empty 64 MB texture blocks while commit is short, and included #24 and #87, so not all of the gain is this PR's. The window share (about 3-4 GB less) is this PR's alone. On a 64 GB machine the Watch band is mostly entered through commit headroom, not through private bytes against the commit limit. Thanks!
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:56 UTC · original

Merged into main in the next push (tests pass); thanks.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:56 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/77#issuecomment-7185996266) Merged into main in the next push (tests pass); thanks.
github manually merged commit 4c04dda3cf into main 2026-11-26 08:21:46 +00:00
Author
Owner

@⁠MoonYueya on GitHub · 2026-11-26 09:42 UTC · original

RTX 3080 (10 GB) measurement of ffc2cf6, opt-in path enabled with
VICTORY_WINDOW_BUDGET_MB, against f59a315 of MoonYueya/VIctory-Kira (this repo's e2a28ec plus the open NVIDIA PRs, without this one).

Setup as in the PR #72 comment: Ryzen 7 7700, 31.1 GB, Windows 11, driver
32.0.16.1742, same save and switch set, per-build caches, 480 s per run,
unattended into the world.

control f59a315 2048 MiB 256 MiB
world frame time, median 450 ms 392 ms 390 ms (-13%)
world frame time, p90 / worst 1091 / 5832 ms 635 / 1041 ms 575 / 2416 ms
passes that made none for lack of room (last) 535 396 113 (-79%)
card use / DXGI budget (last) 9194 / 7790 MB 9173 / 7547 MB 8254 / 7545 MB
window copies let go 551 / 2,468 MB 362 / 1,852 MB 325 / 1,432 MB
private memory (last) 28,019 MB 29,077 MB 25,985 MB
picture mean / sd (median, world) 74.1 / 53.7 73.5 / 52.9 73.1 / 52.7
black frames (world sample) 0 3 / 51 0
device removed / panic / untranslated 0 / 0 / 0 0 / 0 / 0 0 / 0 / 0

So: on this machine the PR does what it says and costs nothing measurable.
Frame time improves rather than degrades, lack of room drops by 79% at the
tighter setting, and the picture numbers stay within 2% of the control.

Two honest limits on what this shows.

  1. At 2048 MiB the cap never engaged: the log has no sweep: line at all and
    the live window copies were only ~1.6-2.0 GB, so that run really proves
    "merging the PR with the switch on does not regress", not "the budget
    works". Only the 256 MiB run actually put the cap in force.
  2. This 31 GB host sits in your High band almost continuously (free physical
    under 2 GB for most samples, commit headroom 1.5-3 GB), so the band logic
    is exercised but the Calm path is not. Someone on a 64 GB machine would
    see a different mix, as iLucasRT's 25-minute YP3/YP4 comparison showed.

One number moved the other way and I could not attribute it: passed over unmapped rose from 2,516 to 11,298 / 12,000. Frame time and lack of room
both improved in the same runs, so I do not think it is a regression in the
usual sense, but I did not isolate it and would not want it read as a claim
either way.

Three black frames out of 51 in the 2048 MiB run are the one thing I would
flag for a second look: the 256 MiB run and the control both had zero, and
the control's own black frame warnings are all in the first 22 frames
(menu/loading), not in the world. Given the sampling density (one picture
every 8th world frame) I am treating it as sampling noise, but it is worth
one longer run before this is called clean.

Verdict here: keep it, default off as it is. It is a strictly-additive path
that changes nothing unless the variable is set, and when it is set the cost
is inside the noise floor.

AI-assisted: an AI agent ran the builds, runs and measurements.

**@⁠MoonYueya** on GitHub · 2026-11-26 09:42 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/77#issuecomment-7188363901) RTX 3080 (10 GB) measurement of `ffc2cf6`, opt-in path enabled with `VICTORY_WINDOW_BUDGET_MB`, against `f59a315` of [MoonYueya/VIctory-Kira](https://github.com/MoonYueya/VIctory-Kira) (this repo's `e2a28ec` plus the open NVIDIA PRs, without this one). Setup as in the PR #72 comment: Ryzen 7 7700, 31.1 GB, Windows 11, driver 32.0.16.1742, same save and switch set, per-build caches, 480 s per run, unattended into the world. | | control `f59a315` | 2048 MiB | 256 MiB | |---|---|---|---| | world frame time, median | 450 ms | 392 ms | **390 ms (-13%)** | | world frame time, p90 / worst | 1091 / 5832 ms | 635 / 1041 ms | 575 / 2416 ms | | passes that made none for lack of room (last) | 535 | 396 | **113 (-79%)** | | card use / DXGI budget (last) | 9194 / 7790 MB | 9173 / 7547 MB | 8254 / 7545 MB | | window copies let go | 551 / 2,468 MB | 362 / 1,852 MB | **325 / 1,432 MB** | | private memory (last) | 28,019 MB | 29,077 MB | 25,985 MB | | picture mean / sd (median, world) | 74.1 / 53.7 | 73.5 / 52.9 | 73.1 / 52.7 | | black frames (world sample) | 0 | 3 / 51 | 0 | | device removed / panic / untranslated | 0 / 0 / 0 | 0 / 0 / 0 | 0 / 0 / 0 | So: on this machine the PR does what it says and costs nothing measurable. Frame time improves rather than degrades, `lack of room` drops by 79% at the tighter setting, and the picture numbers stay within 2% of the control. Two honest limits on what this shows. 1. At 2048 MiB the cap never engaged: the log has no `sweep:` line at all and the live window copies were only ~1.6-2.0 GB, so that run really proves "merging the PR with the switch on does not regress", not "the budget works". Only the 256 MiB run actually put the cap in force. 2. This 31 GB host sits in your High band almost continuously (free physical under 2 GB for most samples, commit headroom 1.5-3 GB), so the band logic is exercised but the Calm path is not. Someone on a 64 GB machine would see a different mix, as iLucasRT's 25-minute YP3/YP4 comparison showed. One number moved the other way and I could not attribute it: `passed over unmapped` rose from 2,516 to 11,298 / 12,000. Frame time and `lack of room` both improved in the same runs, so I do not think it is a regression in the usual sense, but I did not isolate it and would not want it read as a claim either way. Three black frames out of 51 in the 2048 MiB run are the one thing I would flag for a second look: the 256 MiB run and the control both had zero, and the control's own `black frame` warnings are all in the first 22 frames (menu/loading), not in the world. Given the sampling density (one picture every 8th world frame) I am treating it as sampling noise, but it is worth one longer run before this is called clean. Verdict here: keep it, default off as it is. It is a strictly-additive path that changes nothing unless the variable is set, and when it is set the cost is inside the noise floor. *AI-assisted: an AI agent ran the builds, runs and measurements.*
Author
Owner

@⁠MoonYueya on GitHub · 2026-11-26 16:04 UTC · original

Correction to my RTX 3080 comment above (same machine, same ffc2cf6 code in MoonYueya/VIctory-Kira).

I wrote that at 2048 MiB "the cap never engaged". That reading was wrong, and so was calling the variable a cap.

What the code does. In let_go_idle (crates/victory-gpu/src/shadow.rs), with VICTORY_WINDOW_BUDGET_MB unset or 0, keep is u64::MAX and the sweep takes the (0..eligible.len()).collect() path, so it lets go of every eligible window copy. With the variable set, keep follows the RAM band: in Calm it stays u64::MAX (every eligible copy goes, as unset), in Watch it is the budget, in High half of it, and the sweep lets copies go only down to keep. So a set value keeps the same or more idle window copies than leaving it unset, never fewer. In practice the variable is a floor, not a ceiling.

What the earlier logs show. Running ram_band again over the memory: lines of my four earlier runs, the band was High for most samples in each of them (69 to 76 of 81 to 87). In the runs with a budget, the eligible bytes settled right at budget / 2, the High value: 1,028 MB for 2048, 260 MB for 512, 132 MB for 256. So the band was working. Only the 256 MiB setting was small enough to come close to the unset behaviour.

Three new 430 s runs. All three use the same build, RTX 3080 10 GB, 31 GB RAM. To make the number hold whatever the band, the two budget columns add a local opt-in switch, VICTORY_WINDOW_BUDGET_ALWAYS=1, on the public branch experiment/winbudget of my fork (e89a3d0). It is not part of this PR. In these runs the band was High for only a minority of samples, which is why the switch was needed.

no budget 1024 MiB + ALWAYS 512 MiB + ALWAYS
copies the sweeps let go 787 / 3,680 MB 263 / 1,288 MB 133 / 656 MB
live window copies, median 3,556 MB 4,560 MB 3,840 MB
private memory, peak 28,248 MB 28,431 MB 28,037 MB
card use / budget, last 8,515 / 7,893 MB 8,871 / 7,782 MB 8,834 / 7,583 MB
device removed / panic 0 / 0 0 / 0 0 / 0

Each column is a single run. The three runs reached different scenes (median draws per world frame 4,517 / 4,930 / 6,300), so I am not reading anything into frame time from these.

If the intent of the PR is "under RAM pressure, keep idle window memory below N", it would need to evict down to N when usage is above it, rather than keep up to N. Marvisak/VIctory 63bcca4 uses that high/low-mark shape for card textures. I have not written that change. The earlier 13 % frame time / 79 % lack of room numbers at 256 MiB were single runs with this PR merged against a control build without it, in possibly different scenes, so please treat them as unexplained rather than as evidence for the cap.

Measured and written with AI assistance.

**@⁠MoonYueya** on GitHub · 2026-11-26 16:04 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/77#issuecomment-7197151049) Correction to my RTX 3080 comment above (same machine, same `ffc2cf6` code in [MoonYueya/VIctory-Kira](https://github.com/MoonYueya/VIctory-Kira)). I wrote that at 2048 MiB "the cap never engaged". That reading was wrong, and so was calling the variable a cap. **What the code does.** In `let_go_idle` (`crates/victory-gpu/src/shadow.rs`), with `VICTORY_WINDOW_BUDGET_MB` unset or 0, `keep` is `u64::MAX` and the sweep takes the `(0..eligible.len()).collect()` path, so it lets go of **every** eligible window copy. With the variable set, `keep` follows the RAM band: in Calm it stays `u64::MAX` (every eligible copy goes, as unset), in Watch it is the budget, in High half of it, and the sweep lets copies go only down to `keep`. So a set value keeps the same or *more* idle window copies than leaving it unset, never fewer. In practice the variable is a floor, not a ceiling. **What the earlier logs show.** Running `ram_band` again over the `memory:` lines of my four earlier runs, the band was High for most samples in each of them (69 to 76 of 81 to 87). In the runs with a budget, the eligible bytes settled right at `budget / 2`, the High value: 1,028 MB for 2048, 260 MB for 512, 132 MB for 256. So the band was working. Only the 256 MiB setting was small enough to come close to the unset behaviour. **Three new 430 s runs.** All three use the same build, RTX 3080 10 GB, 31 GB RAM. To make the number hold whatever the band, the two budget columns add a local opt-in switch, `VICTORY_WINDOW_BUDGET_ALWAYS=1`, on the public branch [`experiment/winbudget`](https://github.com/MoonYueya/VIctory-Kira/tree/experiment/winbudget) of my fork (`e89a3d0`). It is not part of this PR. In these runs the band was High for only a minority of samples, which is why the switch was needed. | | no budget | 1024 MiB + ALWAYS | 512 MiB + ALWAYS | |---|---|---|---| | copies the sweeps let go | 787 / 3,680 MB | 263 / 1,288 MB | 133 / 656 MB | | live window copies, median | 3,556 MB | 4,560 MB | 3,840 MB | | private memory, peak | 28,248 MB | 28,431 MB | 28,037 MB | | card use / budget, last | 8,515 / 7,893 MB | 8,871 / 7,782 MB | 8,834 / 7,583 MB | | device removed / panic | 0 / 0 | 0 / 0 | 0 / 0 | Each column is a single run. The three runs reached different scenes (median draws per world frame 4,517 / 4,930 / 6,300), so I am not reading anything into frame time from these. If the intent of the PR is "under RAM pressure, keep idle window memory below N", it would need to evict down to N when usage is above it, rather than keep up to N. Marvisak/VIctory `63bcca4` uses that high/low-mark shape for card textures. I have not written that change. The earlier 13 % frame time / 79 % `lack of room` numbers at 256 MiB were single runs with this PR merged against a control build without it, in possibly different scenes, so please treat them as unexplained rather than as evidence for the cap. *Measured and written with AI assistance.*
This discussion has been locked. Commenting is limited to contributors.
No description provided.