fix(gpu): settle targets_room_kept() at 720p (Series S) #563

Manually merged
github merged 2 commits from github-bot/gh-563 into gh-pr/563/base 2026-12-05 21:13:52 +00:00 AGit
Owner

@⁠ratatrampa007 on GitHub · 2026-12-05 07:24 UTC · original
ratatrampa007:fix/720p-targets-settle → main · +183 −22 · 1 files · 2 commits · merged 2026-12-05 21:08 UTC

Summary

targets_room_kept() in crates/victory-gpu/src/resource.rs reserves 3,072 MiB (most) for host-written render targets and releases the unused reserve to 0 once targets stop growing for 20 s and targets >= most / 2 (1,536 MiB).

At 720p (CONSOLE=series-s, VICTORY_OUTPUT=1280x720, scales 0.85–1.0), in-world host-written render targets settle around ~1.0–1.25 GiB — always below 1,536 MiB. As a result, targets_room_kept() never settles to 0 and permanently adds ~1.8 GiB of phantom VRAM usage to every room(), vram_plan(), and pool::spares() check for the entire session:

  • room() stays closed (no room for new ones fires continuously).
  • vram_plan() stays pinned in URGENT_MS (1.2 s) eviction mode with grace = 0, causing relentless texture eviction/re-upload churn and permanently holding draining texture blocks.

Change

  • Extract targets_room_for(targets, since, now) and lower TARGETS_SETTLE_FLOOR from most / 2 (1,536 MiB) to 768 MiB (768 << 20):
    • Safely above the ~652 MiB pre-world footprint documented in resource.rs (load time remains protected).
    • Safely below both scaled and native 720p Series S in-world footprints (~1.0–1.25 GiB) as well as 1080p/1440p (~2.25–3.1 GiB), so the unused reserve is released after 20 s of stability.
  • Add unit test resource::tests::targets_room_settles_at_720p_but_not_pre_world covering pre-world (652 MiB), 720p (1,004 MiB & 1,260 MiB), and 1080p/1440p (2,350 MiB).

Measured impact (RX 6600 8 GB, RADV, Series S 1280x720 [Native], 30 FPS cap)

Metric Before (e92fd7a, 3 h session) After fix (same GPU/res, higher LOD) After + tight-textures (b581f7e, 2 h session)
Median FPS (all / int / ext) 19.00 / 21.26 / 17.27 23.27 / 30.00 / 22.41 27.45 / 29.42 / 23.95
gpu_wait_ms median 26.10 ms 15.76 ms (-40%) 16.12 ms
xmem on-card / free VRAM 7 MB / 514 MB 676 MB / 932 MB 680 MB / 933 MB
Pages waiting for room 6,897 (max 8,039) 0 (max 0) 0 (max 0)
Texture re-upload rate ~46 GB/h (138 GB in 3 h) ~18 GB/h ~12 GB/h (-74%)

(Note: the rdna2-3 branch has the same targets >= most / 2 check at crates/victory-gpu/src/resource.rs:2093 if you want to cherry-pick it there too.)

Verification

  • cargo run --locked -p xtask -- policy → asset policy: 359 files ok
  • ./build.sh test -p victory-gpu --lib -- targets_room → 1 passed; 0 failed
  • Multi-hour gameplay runs (0 crashes, 0 waiting pages) on RX 6600 8 GB / Arch Linux / RADV.
**@⁠ratatrampa007** on GitHub · 2026-12-05 07:24 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/563) `ratatrampa007:fix/720p-targets-settle` → `main` · +183 −22 · 1 files · 2 commits · merged 2026-12-05 21:08 UTC ## Summary `targets_room_kept()` in `crates/victory-gpu/src/resource.rs` reserves 3,072 MiB (`most`) for host-written render targets and releases the unused reserve to `0` once targets stop growing for 20 s **and** `targets >= most / 2` (1,536 MiB). At **720p (`CONSOLE=series-s`, `VICTORY_OUTPUT=1280x720`, scales `0.85`–`1.0`)**, in-world host-written render targets settle around **~1.0–1.25 GiB** — always below `1,536 MiB`. As a result, `targets_room_kept()` **never settles to `0`** and permanently adds **~1.8 GiB of phantom VRAM usage** to every `room()`, `vram_plan()`, and `pool::spares()` check for the entire session: - `room()` stays closed (`no room for new ones` fires continuously). - `vram_plan()` stays pinned in `URGENT_MS` (1.2 s) eviction mode with `grace = 0`, causing relentless texture eviction/re-upload churn and permanently holding draining texture blocks. ## Change - Extract `targets_room_for(targets, since, now)` and lower `TARGETS_SETTLE_FLOOR` from `most / 2` (`1,536 MiB`) to **`768 MiB`** (`768 << 20`): - Safely above the `~652 MiB` pre-world footprint documented in `resource.rs` (load time remains protected). - Safely below both scaled and native 720p Series S in-world footprints (`~1.0–1.25 GiB`) as well as 1080p/1440p (`~2.25–3.1 GiB`), so the unused reserve is released after 20 s of stability. - Add unit test `resource::tests::targets_room_settles_at_720p_but_not_pre_world` covering pre-world (`652 MiB`), 720p (`1,004 MiB` & `1,260 MiB`), and 1080p/1440p (`2,350 MiB`). ## Measured impact (RX 6600 8 GB, RADV, Series S `1280x720 [Native]`, 30 FPS cap) | Metric | Before (`e92fd7a`, 3 h session) | After fix (same GPU/res, higher LOD) | After + `tight-textures` (`b581f7e`, 2 h session) | |---|---:|---:|---:| | Median FPS (all / int / ext) | 19.00 / 21.26 / 17.27 | **23.27 / 30.00 / 22.41** | **27.45 / 29.42 / 23.95** | | `gpu_wait_ms` median | 26.10 ms | **15.76 ms** (-40%) | **16.12 ms** | | `xmem` on-card / free VRAM | 7 MB / 514 MB | **676 MB / 932 MB** | **680 MB / 933 MB** | | Pages waiting for room | 6,897 (max 8,039) | **0 (max 0)** | **0 (max 0)** | | Texture re-upload rate | ~46 GB/h (138 GB in 3 h) | ~18 GB/h | **~12 GB/h** (-74%) | *(Note: the `rdna2-3` branch has the same `targets >= most / 2` check at `crates/victory-gpu/src/resource.rs:2093` if you want to cherry-pick it there too.)* ## Verification - `cargo run --locked -p xtask -- policy` → `asset policy: 359 files ok` - `./build.sh test -p victory-gpu --lib -- targets_room` → `1 passed; 0 failed` - Multi-hour gameplay runs (0 crashes, 0 waiting pages) on RX 6600 8 GB / Arch Linux / RADV.
targets_room_kept() reserves 3,072 MiB for host-written render targets and releases the unused reserve after 20 s of stability once targets reach the floor. Previously the floor was most / 2 (1,536 MiB).

At 1280x720 (and scaled 720p) on Series S, in-world render targets settle around 1.0-1.25 GiB, never reaching 1,536 MiB. As a result, targets_room_kept() permanently reported ~1.8 GiB of phantom VRAM usage for the entire session, forcing room() closed and pinning vram_plan() in urgent 1.2 s eviction mode.

Lower the settle floor to 768 MiB — safely above the ~652 MiB pre-world footprint while letting 720p in-world sessions settle cleanly after 20 s.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 07:27:00 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 07:42 UTC · original

Checked head bf3ce7b on native Windows (MSVC), one NVIDIA desktop card plus WARP, against main at b581f7e. I did not run the game, so everything below comes from reading the code and running the unit tests.

The change does what the body says. On the default path the only difference is the floor. The reserve now drops to 0 once targets are at least 768 MiB and haven't grown 64 MiB in the last 20 s, where main needed 1,536 MiB. Under 768 MiB, or inside the 20 s, it still returns 3,072 MiB minus the targets, same as before. At 1,004 to 1,260 MiB of targets, that leftover is about 1.8 to 2.0 GiB, which matches the phantom figure in the body. The extracted targets_room_for matches the old expression. Dropping settle > 0 loses nothing since settle was a constant 20,000. Nothing can overflow, because the constants fit easily and both subtractions saturate. The env switches near this code (VICTORY_TEXTURE_ROOM_PERCENT and VICTORY_TEXTURE_ROOM_CAP_PERCENT) only move the thresholds in room(). Neither changes what targets_room_kept returns.

The change applies to everyone, with no switch. It matters for any state that holds targets between 768 and 1,536 MiB for 20 s, and that band isn't limited to 720p. The body says 1080p sits at 2.25 GiB and up, and the doc comment does give 2,255 MB and up after the first frame, but it doesn't name a resolution. #481 reports Series X at 1080p sitting at 1.45 to 1.53 GB, just under the old line. If that holds, this PR also releases the reserve for Series X at 1080p, so 1080p isn't untouched in every case. Leaving the world below 768 MiB brings the full reserve back at once, and a 64 MiB step after a release brings it back for another 20 s. That matches main.

There's one thing I couldn't settle from code. The 652 MB pre-world figure comes from runs 193, 197 and 198 (doc comment above TARGETS_ROOM_MOST), and that comment doesn't say which output those runs used either. 768 MiB is only about two 64 MiB steps above it. If a menu or loading screen at a higher output holds 800 to 1,500 MiB for 20 s, this PR gives the reserve away before the first world frame, which is the spike the reserve exists for. Main keeps it in that case. A short log of the targets figure before the first world frame at 1080p and 4K would answer it.

This overlaps with #481 (still open). That PR goes after the same reserve that never comes back for Series S, but behind VICTORY_RESERVE_RELEASE and off by default. It keeps a 512 MiB headroom over the targets and waits until the world has been drawn for 20 s, where this PR releases to 0 with no world check and no headroom. #481 also reports Series S targets growing about 190 MB in the two minutes after the give-back. Here, each 64 MiB of that growth would bring back the full 1.8 GiB or so for 20 s, rather than a 512 MiB margin. Each PR merges cleanly with current main, but they edit the same lines in targets_room_kept and conflict with each other. With the switch on, #481 returns before the line this PR changes, so the new floor would only apply with the switch off. It's worth choosing one approach or reconciling them.

The rdna2-3 note is right, the same targets >= most / 2 check is at resource.rs:2093 on that branch. URGENT_MS is 1,200 ms in host.rs, and grace is 0 whenever admissions are closed, as the body says. cargo run --locked -p xtask -- policy gives the same "359 files ok". The 720p footprint (1.0 to 1.25 GiB), the FPS, gpu_wait and re-upload numbers, and the 0 waiting pages all need the game, so I couldn't check them.

I ran cargo test -p victory-gpu --lib resource:: with --test-threads=2, skipping views_die_with_their_resource, and got 16 passed and 1 failed. The failure was buffer_data_reaches_the_host_texture, which then passed in the full-suite runs on both the PR and main, so it looks like the usual native flake. The new targets_room_settles_at_720p_but_not_pre_world passes. On the full victory-gpu lib suite the PR got 353 passed and 5 failed, and main got 353 passed and 4 failed. The extra test on the PR side is the new one, and it passed. On both, four of the failures are the two indirect host_list tests and the two pipeline::host library tests, which fail natively on main. The PR's fifth was the flaky watch test the_rest_of_the_one_asking_has_a_number_of_its_own, which then passed 3 out of 3 reruns. cargo fmt has nothing to say about the lines this PR touches.

The new test only covers targets_room_for, not the growth tracking in targets_room_kept. So I wrote a local test, not pushed, that copies that tracking and feeds it sequences. All of these behaved as expected. 767 MiB keeps the reserve, and 768 MiB at 20,000 ms releases it, but not at 19,999. A 720p-like run (652, then 1,004, then a slow creep) releases 20 s after the last 64 MiB step. 60 MiB of creep over 20 s still releases, and a further 4 MiB brings the reserve back. Re-growth after a release brings it back for 20 s. Falling below the floor brings it back at once. A 1080p-like run (652 then 2,300) behaves exactly like main. A state held at 900 MiB for 20 s releases here and not on main. Targets moving between 740 and 800 MiB switch the kept figure between 0 and about 2.3 GiB, which can open and close room() repeatedly. Main has the same edge at 1,536 MiB, but with a lower floor more states may sit near it.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 07:42 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/563#issuecomment-7434326265) Checked head bf3ce7b on native Windows (MSVC), one NVIDIA desktop card plus WARP, against main at b581f7e. I did not run the game, so everything below comes from reading the code and running the unit tests. The change does what the body says. On the default path the only difference is the floor. The reserve now drops to 0 once targets are at least 768 MiB and haven't grown 64 MiB in the last 20 s, where main needed 1,536 MiB. Under 768 MiB, or inside the 20 s, it still returns 3,072 MiB minus the targets, same as before. At 1,004 to 1,260 MiB of targets, that leftover is about 1.8 to 2.0 GiB, which matches the phantom figure in the body. The extracted targets_room_for matches the old expression. Dropping `settle > 0` loses nothing since settle was a constant 20,000. Nothing can overflow, because the constants fit easily and both subtractions saturate. The env switches near this code (VICTORY_TEXTURE_ROOM_PERCENT and VICTORY_TEXTURE_ROOM_CAP_PERCENT) only move the thresholds in room(). Neither changes what targets_room_kept returns. The change applies to everyone, with no switch. It matters for any state that holds targets between 768 and 1,536 MiB for 20 s, and that band isn't limited to 720p. The body says 1080p sits at 2.25 GiB and up, and the doc comment does give 2,255 MB and up after the first frame, but it doesn't name a resolution. #481 reports Series X at 1080p sitting at 1.45 to 1.53 GB, just under the old line. If that holds, this PR also releases the reserve for Series X at 1080p, so 1080p isn't untouched in every case. Leaving the world below 768 MiB brings the full reserve back at once, and a 64 MiB step after a release brings it back for another 20 s. That matches main. There's one thing I couldn't settle from code. The 652 MB pre-world figure comes from runs 193, 197 and 198 (doc comment above TARGETS_ROOM_MOST), and that comment doesn't say which output those runs used either. 768 MiB is only about two 64 MiB steps above it. If a menu or loading screen at a higher output holds 800 to 1,500 MiB for 20 s, this PR gives the reserve away before the first world frame, which is the spike the reserve exists for. Main keeps it in that case. A short log of the targets figure before the first world frame at 1080p and 4K would answer it. This overlaps with #481 (still open). That PR goes after the same reserve that never comes back for Series S, but behind VICTORY_RESERVE_RELEASE and off by default. It keeps a 512 MiB headroom over the targets and waits until the world has been drawn for 20 s, where this PR releases to 0 with no world check and no headroom. #481 also reports Series S targets growing about 190 MB in the two minutes after the give-back. Here, each 64 MiB of that growth would bring back the full 1.8 GiB or so for 20 s, rather than a 512 MiB margin. Each PR merges cleanly with current main, but they edit the same lines in targets_room_kept and conflict with each other. With the switch on, #481 returns before the line this PR changes, so the new floor would only apply with the switch off. It's worth choosing one approach or reconciling them. The rdna2-3 note is right, the same `targets >= most / 2` check is at resource.rs:2093 on that branch. URGENT_MS is 1,200 ms in host.rs, and grace is 0 whenever admissions are closed, as the body says. `cargo run --locked -p xtask -- policy` gives the same "359 files ok". The 720p footprint (1.0 to 1.25 GiB), the FPS, gpu_wait and re-upload numbers, and the 0 waiting pages all need the game, so I couldn't check them. I ran cargo test -p victory-gpu --lib resource:: with --test-threads=2, skipping views_die_with_their_resource, and got 16 passed and 1 failed. The failure was buffer_data_reaches_the_host_texture, which then passed in the full-suite runs on both the PR and main, so it looks like the usual native flake. The new targets_room_settles_at_720p_but_not_pre_world passes. On the full victory-gpu lib suite the PR got 353 passed and 5 failed, and main got 353 passed and 4 failed. The extra test on the PR side is the new one, and it passed. On both, four of the failures are the two indirect host_list tests and the two pipeline::host library tests, which fail natively on main. The PR's fifth was the flaky watch test the_rest_of_the_one_asking_has_a_number_of_its_own, which then passed 3 out of 3 reruns. cargo fmt has nothing to say about the lines this PR touches. The new test only covers targets_room_for, not the growth tracking in targets_room_kept. So I wrote a local test, not pushed, that copies that tracking and feeds it sequences. All of these behaved as expected. 767 MiB keeps the reserve, and 768 MiB at 20,000 ms releases it, but not at 19,999. A 720p-like run (652, then 1,004, then a slow creep) releases 20 s after the last 64 MiB step. 60 MiB of creep over 20 s still releases, and a further 4 MiB brings the reserve back. Re-growth after a release brings it back for 20 s. Falling below the floor brings it back at once. A 1080p-like run (652 then 2,300) behaves exactly like main. A state held at 900 MiB for 20 s releases here and not on main. Targets moving between 740 and 800 MiB switch the kept figure between 0 and about 2.3 GiB, which can open and close room() repeatedly. Main has the same edge at 1,536 MiB, but with a lower floor more states may sit near it. AI-assisted: yes
Address review feedback on #563: high-resolution (1080p/4K) menus or loading screens can hold 800-1,500 MiB of render targets for over 20 s before the first world frame. Keep the legacy `targets >= most / 2` (1,536 MiB) settle path unchanged, and allow the lower 768 MiB floor only after `TargetsRoomTracker` observes sustained active world draws (>= 1,000 draws/frame over >= 10-frame windows for 20 s, above menu ~7-85 and pause/reload ~250-420 draws/frame and below small interiors ~1,050-1,900 draws/frame). Returning below 1,000 draws/frame for 5 s resets `in_world`, restoring the full pre-world reserve across save reloads and menu transitions.

Expand `targets_room_settles_at_720p_but_not_pre_world` to cover the `TargetsRoomTracker` state machine end to end (high-res menu/pause protection, 720p settle timing, small-interior continuity, +64 MiB re-arm, 5 s leave-world reset, and the legacy >=1,536 MiB path).
Author
Owner

@⁠ratatrampa007 on GitHub · 2026-12-05 17:04 UTC · original

Thanks @⁠Kal0s-design for the thorough MSVC verification and for catching the 1080p/4K pre-world menu edge case!

Pushed follow-up commit 8249de4 to harden this while keeping it a self-contained 1-file change in crates/victory-gpu/src/resource.rs:

  • Pre-world / high-res menu protection (TargetsRoomTracker): Keeps the legacy targets >= TARGETS_ROOM_MOST / 2 (1,536 MiB) path unchanged, and gates the lower 768 MiB floor on sustained active world draws using crate::frame::current() and crate::draw::drawn() (>= 1,000 draws/frame averaged across >= 10-frame windows for 20 s). In real captures, boot/menus sit around 7-85 draws/frame and pause/map/save-reload screens around 250-420 draws/frame, whereas even compact interiors run 1,050-1,900+ draws/frame — so a 1080p/4K menu holding 800-1,500 MiB will never release the reserve early.
  • Save-reload / menu-return safety: Dropping below 1,000 draws/frame for 5 s clears in_world, restoring the full 3 GiB pre-world reserve for the next load.
  • Expanded unit test: targets_room_settles_at_720p_but_not_pre_world now drives TargetsRoomTracker directly across high-res menu/pause protection, 720p settle timing (19.999 s vs 20.000 s), small-interior continuity (1,200 draws/f), <64 MiB creep, +64 MiB re-arm, 5 s leave-world reset, and the legacy >= 1,536 MiB path (resource::tests: 17 passed, 0 failed; xtask policy: 359 files ok).

Re: #481 — good call flagging the overlap. #481 wires an opt-in VICTORY_RESERVE_RELEASE switch on top of #216, whereas this stays a minimal default fix with no dependency on #216 and no extra env switch. Happy to keep a residual headroom cushion or reconcile with #481 depending on whichever direction maintainers prefer.

**@⁠ratatrampa007** on GitHub · 2026-12-05 17:04 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/563#issuecomment-7441831347) Thanks @⁠Kal0s-design for the thorough MSVC verification and for catching the 1080p/4K pre-world menu edge case! Pushed follow-up commit `8249de4` to harden this while keeping it a self-contained 1-file change in `crates/victory-gpu/src/resource.rs`: - **Pre-world / high-res menu protection (`TargetsRoomTracker`):** Keeps the legacy `targets >= TARGETS_ROOM_MOST / 2` (`1,536 MiB`) path unchanged, and gates the lower `768 MiB` floor on sustained active world draws using `crate::frame::current()` and `crate::draw::drawn()` (`>= 1,000` draws/frame averaged across `>= 10`-frame windows for `20 s`). In real captures, boot/menus sit around `7-85` draws/frame and pause/map/save-reload screens around `250-420` draws/frame, whereas even compact interiors run `1,050-1,900+` draws/frame — so a 1080p/4K menu holding `800-1,500 MiB` will never release the reserve early. - **Save-reload / menu-return safety:** Dropping below `1,000` draws/frame for `5 s` clears `in_world`, restoring the full `3 GiB` pre-world reserve for the next load. - **Expanded unit test:** `targets_room_settles_at_720p_but_not_pre_world` now drives `TargetsRoomTracker` directly across high-res menu/pause protection, 720p settle timing (`19.999 s` vs `20.000 s`), small-interior continuity (`1,200` draws/f), `<64 MiB` creep, `+64 MiB` re-arm, `5 s` leave-world reset, and the legacy `>= 1,536 MiB` path (`resource::tests`: 17 passed, 0 failed; `xtask policy`: 359 files ok). Re: `#481` — good call flagging the overlap. `#481` wires an opt-in `VICTORY_RESERVE_RELEASE` switch on top of `#216`, whereas this stays a minimal default fix with no dependency on `#216` and no extra env switch. Happy to keep a residual headroom cushion or reconcile with `#481` depending on whichever direction maintainers prefer.
github-bot changed target branch from main to gh-pr/563/base 2026-12-05 21:13:51 +00:00
github manually merged commit 8249de4487 into gh-pr/563/base 2026-12-05 21:13:52 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.