Texture store: bound the kept levels by host memory, and let them go at a steady pace (peak private 3.0 → 0.9 GiB under pressure) #625

Open
github-bot wants to merge 3 commits from github-bot/gh-625 into a-publier AGit
Owner

@⁠11run11 on GitHub · 2026-11-27 14:49 UTC · original
11run11:performance/T-0039-texstore-bound → a-publier · +343 −16 · 1 files · 3 commits · open

With VICTORY_TEXTURE_STORE on, the store keeps up to 4 GiB of the larger levels in memory, whatever the host has free. On PCs with 16–32 GB that space competes with the title, which is the situation in #546 (RX 9070 XT, 32 GB, memory at the ceiling) and #600 (out of memory on 16 GB). The kept levels are a cache of files the store has already written, so they can be released under pressure and read back when needed.

The change (crates/victory-gpu/src/texstore.rs only)

  • kept_limit(total, headroom) sets the bound. Headroom is free commit (commit limit less commit charge), sampled at most every 250 ms with GlobalMemoryStatusEx. It was min(free RAM, free commit) until 9e24db7; see the in-game numbers in the comments. The bound is a quarter of 4 GiB on hosts with ≤32 GiB, at most an eighth of headroom, and below 6 GiB of headroom a ramp down to nothing at 2 GiB. The ramp has no steps.
  • Kept levels are an LRU. When the limit falls, trim releases at most 64 MiB per 16 ms window, however many lookups call it, so a drop is spread over frames. Making room for a newly kept texture is still immediate (one for one).
  • Released levels are returned to the caller and freed after the store's lock is released, so frees never block other lookups.
  • VICTORY_TEXSTORE_BOUND=0 keeps the old fixed 4 GiB bound. Nothing changes while the store is off, which is the default.

Tested

Windows 11, RX 9070 XT, Rust 1.98.1, --features diagnostics.

  • cargo test -p victory-gpu --features diagnostics: 448 passed, 0 failed. New tests: kept_limit_follows_host_memory (which also checks that the limit never rises as headroom falls), kept_evicts_least_recent_first and kept_trims_a_large_drop_in_steps.
  • A synthetic streaming stress test (texstore_pressure_synthetic_stream, #[ignore]) simulates a 32 GiB host whose headroom falls from 10 GiB as the title grows. Each of its 768 frames keeps a new 4 MiB texture and looks up four earlier ones. Results over 5 runs:
peak private worst frame p99 frame misses (of 2861)
VICTORY_TEXSTORE_BOUND=0 3093 MiB 0.29–0.54 ms 0.27 ms 0
bound, 64 MiB per call (first version) 947 MiB 7.1–11.5 ms 0.7–1.1 ms 539
bound, this PR 947 MiB 0.78–1.20 ms 0.69–1.13 ms 535
  • A small original test title (Night Courier, WARP): 6/6 GPU frames match. The synthetic x64 guest passes. I did not test commercial titles.
  • It merges cleanly with #555, which changes where the store's folder is.

Limits and risks

  • A miss reads the level back from the store's folder. In the stress test, misses (19%) come from lookups 200 textures back, older than a 932 MiB budget can hold, and each is one file read. On a slow disk that read costs more than keeping the level would have.
  • Headroom is sampled every 250 ms, so a very fast allocation burst by the title can still overshoot before the store reacts.

CI

Belobug's own ci.yml, unmodified, passes on this branch in my fork (Clippy with -D warnings, default and diagnostics tests): https://github.com/11run11/VIctory-Belobug-11run/actions/runs/46033108523 (commit 9e24db7).

**@⁠11run11** on GitHub · 2026-11-27 14:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/625) `11run11:performance/T-0039-texstore-bound` → `a-publier` · +343 −16 · 1 files · 3 commits · open With `VICTORY_TEXTURE_STORE` on, the store keeps up to 4 GiB of the larger levels in memory, whatever the host has free. On PCs with 16–32 GB that space competes with the title, which is the situation in #546 (RX 9070 XT, 32 GB, memory at the ceiling) and #600 (out of memory on 16 GB). The kept levels are a cache of files the store has already written, so they can be released under pressure and read back when needed. ## The change (`crates/victory-gpu/src/texstore.rs` only) - `kept_limit(total, headroom)` sets the bound. Headroom is free commit (commit limit less commit charge), sampled at most every 250 ms with `GlobalMemoryStatusEx`. It was `min(free RAM, free commit)` until `9e24db7`; see the in-game numbers in the comments. The bound is a quarter of 4 GiB on hosts with ≤32 GiB, at most an eighth of headroom, and below 6 GiB of headroom a ramp down to nothing at 2 GiB. The ramp has no steps. - Kept levels are an LRU. When the limit falls, `trim` releases at most 64 MiB per 16 ms window, however many lookups call it, so a drop is spread over frames. Making room for a newly kept texture is still immediate (one for one). - Released levels are returned to the caller and freed after the store's lock is released, so frees never block other lookups. - `VICTORY_TEXSTORE_BOUND=0` keeps the old fixed 4 GiB bound. Nothing changes while the store is off, which is the default. ## Tested Windows 11, RX 9070 XT, Rust 1.98.1, `--features diagnostics`. - `cargo test -p victory-gpu --features diagnostics`: 448 passed, 0 failed. New tests: `kept_limit_follows_host_memory` (which also checks that the limit never rises as headroom falls), `kept_evicts_least_recent_first` and `kept_trims_a_large_drop_in_steps`. - A synthetic streaming stress test (`texstore_pressure_synthetic_stream`, `#[ignore]`) simulates a 32 GiB host whose headroom falls from 10 GiB as the title grows. Each of its 768 frames keeps a new 4 MiB texture and looks up four earlier ones. Results over 5 runs: | | peak private | worst frame | p99 frame | misses (of 2861) | |---|---|---|---|---| | `VICTORY_TEXSTORE_BOUND=0` | 3093 MiB | 0.29–0.54 ms | 0.27 ms | 0 | | bound, 64 MiB per call (first version) | 947 MiB | 7.1–11.5 ms | 0.7–1.1 ms | 539 | | bound, this PR | 947 MiB | 0.78–1.20 ms | 0.69–1.13 ms | 535 | - A small original test title (Night Courier, WARP): 6/6 GPU frames match. The synthetic x64 guest passes. I did not test commercial titles. - It merges cleanly with #555, which changes where the store's folder is. ## Limits and risks - A miss reads the level back from the store's folder. In the stress test, misses (19%) come from lookups 200 textures back, older than a 932 MiB budget can hold, and each is one file read. On a slow disk that read costs more than keeping the level would have. - Headroom is sampled every 250 ms, so a very fast allocation burst by the title can still overshoot before the store reacts. ## CI Belobug's own `ci.yml`, unmodified, passes on this branch in my fork (Clippy with `-D warnings`, default and diagnostics tests): https://github.com/11run11/VIctory-Belobug-11run/actions/runs/46033108523 (commit 9e24db7).
The bound's trim released up to 64 MiB per call, and a lookup calls it, so
when the limit fell (headroom crossing 6 GiB stepped it from 768 to 256 MiB)
one frame freed ~320 MiB: a 7-11 ms frame in the synthetic stream.

- trim releases at most 64 MiB per 16 ms window, however many calls;
- room for a newly kept texture is still made at once (one for one);
- levels let go are handed back and dropped after the store's lock;
- the limit ramps from 768 MiB at 6 GiB of headroom to 0 at 2 GiB.

Synthetic stream, 5 runs: worst frame 7.1-11.5 ms -> 0.78-1.20 ms; misses
539 -> 535; peak private 947 MiB unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:56:43 +00:00
Author
Owner

@⁠gw1337x on GitHub · 2026-11-27 15:48 UTC · original

In-game numbers on a 32 GB PC where free RAM bottoms out at about 0.5 GB, the situation this PR targets. Memory Integrity was off.

PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, Belobug launcher settings plus the 5 port switches, warm shader caches. Both sides ran with VICTORY_TEXTURE_STORE pointing at the same folder, which one base run had filled first. #625 (2ff0f1d) on 4eb6cfd vs 4eb6cfd, interleaved (base, PR, base, PR).

base 1 #625 1 base 2 #625 2
Store: held in memory at the end 1926 MB 27 MB (limit 73) 1664 MB 114 MB (limit 167)
Store: levels read from the folder 2239 5183 2567 4530
Peak commit 35.4 GB 33.8 GB 35.8 GB 34.2 GB
Private peak 36.3 GB 34.3 GB 36.6 GB 34.7 GB
Lowest free RAM 0.57 GB 0.62 GB 0.53 GB 0.63 GB
Steady fps (log, last minute) 28.7 28.4 28.2 28.6
Frame time p95 (450 frames, 100-240 s) 64.6 ms 96.5 ms 65.6 ms 89.9 ms
Frame time p99 120.9 ms 219.1 ms 97.2 ms 190.9 ms
Frames over 50 ms 57 73 53 94
Frame time at 140 s (timeline) 57.9 ms 89.7 ms 61.9 ms 88.5 ms
  • Memory: the bound works. The store holds 27-114 MB instead of 1.7-1.9 GB, and peak commit drops by 1.6 GB. With the store off, peak commit on this PC is 33.2-34.2 GB, so the store's memory cost is close to gone. Lowest free RAM doesn't change.
  • Frame times: both PR runs have a worse tail (p95, p99, frames over 50 ms), mostly at 140-170 s while the scene loads. They also read about twice as many levels back from the folder. That the two happen together is all I measured, not that the reads cause the slower frames. At 140 s the critical path in the PR runs is a title thread outside our spans and a wait ended by Sleep. What that thread waits on is not measured.
  • Other checks: steady fps is the same and there's no device loss. This is 2 runs per side.

AI-assisted (Claude Code); numbers from the run logs and timelines.

**@⁠gw1337x** on GitHub · 2026-11-27 15:48 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/625#issuecomment-7222509237) In-game numbers on a 32 GB PC where free RAM bottoms out at about 0.5 GB, the situation this PR targets. Memory Integrity was off. PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, Belobug launcher settings plus the 5 port switches, warm shader caches. Both sides ran with `VICTORY_TEXTURE_STORE` pointing at the same folder, which one base run had filled first. #625 (`2ff0f1d`) on `4eb6cfd` vs `4eb6cfd`, interleaved (base, PR, base, PR). | | base 1 | #625 1 | base 2 | #625 2 | |---|---|---|---|---| | Store: held in memory at the end | 1926 MB | 27 MB (limit 73) | 1664 MB | 114 MB (limit 167) | | Store: levels read from the folder | 2239 | 5183 | 2567 | 4530 | | Peak commit | 35.4 GB | 33.8 GB | 35.8 GB | 34.2 GB | | Private peak | 36.3 GB | 34.3 GB | 36.6 GB | 34.7 GB | | Lowest free RAM | 0.57 GB | 0.62 GB | 0.53 GB | 0.63 GB | | Steady fps (log, last minute) | 28.7 | 28.4 | 28.2 | 28.6 | | Frame time p95 (450 frames, 100-240 s) | 64.6 ms | 96.5 ms | 65.6 ms | 89.9 ms | | Frame time p99 | 120.9 ms | 219.1 ms | 97.2 ms | 190.9 ms | | Frames over 50 ms | 57 | 73 | 53 | 94 | | Frame time at 140 s (timeline) | 57.9 ms | 89.7 ms | 61.9 ms | 88.5 ms | - **Memory:** the bound works. The store holds 27-114 MB instead of 1.7-1.9 GB, and peak commit drops by 1.6 GB. With the store off, peak commit on this PC is 33.2-34.2 GB, so the store's memory cost is close to gone. Lowest free RAM doesn't change. - **Frame times:** both PR runs have a worse tail (p95, p99, frames over 50 ms), mostly at 140-170 s while the scene loads. They also read about twice as many levels back from the folder. That the two happen together is all I measured, not that the reads cause the slower frames. At 140 s the critical path in the PR runs is a title thread outside our spans and a wait ended by `Sleep`. What that thread waits on is not measured. - **Other checks:** steady fps is the same and there's no device loss. This is 2 runs per side. AI-assisted (Claude Code); numbers from the run logs and timelines.
In-game numbers on #625 (32 GB, free RAM ~0.5 GB): with the bound on
min(free RAM, free commit) the store kept 27-114 MB instead of 1.7-1.9 GB and
read twice as many levels back from its folder, the p99 frame time doubled,
and the lowest free RAM did not change. Running out of commit is what ends a
title (E_OUTOFMEMORY, #600); under RAM pressure alone the system pages kept
levels out. The bound now follows free commit only. The store's report line
gives the free commit and free RAM of the last sample beside the limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠11run11 on GitHub · 2026-11-27 16:22 UTC · original

Thank you, this is exactly the case I could not measure here.

My reading of it: the bound used min(free RAM, free commit). On your PC free RAM sits at ~0.5 GB, so the limit fell to almost nothing (73/167 MB), and every miss became a synchronous read from the folder on the lookup's thread. That fits the doubled folder reads and the worse tail. Your "lowest free RAM doesn't change" row also says that letting the levels go didn't give the system any RAM back. Under RAM pressure alone, Windows pages them out anyway. What ends a title is running out of commit (E_OUTOFMEMORY, #600), and that is where the bound did help (peak commit −1.6 GB).

9e24db7 therefore bounds the kept levels by free commit only. The store's report line now gives the limit together with the free commit and free RAM of the last sample, so a run shows what the limit followed.

If you can repeat the same interleaved runs on 9e24db7, the numbers to compare are the p95/p99 tail, the folder reads, and peak commit. If commit headroom on your PC is large, I would expect the store to hold close to its old amount: little gain there, and no tail cost.

**@⁠11run11** on GitHub · 2026-11-27 16:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/625#issuecomment-7223194133) Thank you, this is exactly the case I could not measure here. My reading of it: the bound used `min(free RAM, free commit)`. On your PC free RAM sits at ~0.5 GB, so the limit fell to almost nothing (73/167 MB), and every miss became a synchronous read from the folder on the lookup's thread. That fits the doubled folder reads and the worse tail. Your "lowest free RAM doesn't change" row also says that letting the levels go didn't give the system any RAM back. Under RAM pressure alone, Windows pages them out anyway. What ends a title is running out of commit (`E_OUTOFMEMORY`, #600), and that is where the bound did help (peak commit −1.6 GB). `9e24db7` therefore bounds the kept levels by free commit only. The store's report line now gives the limit together with the free commit and free RAM of the last sample, so a run shows what the limit followed. If you can repeat the same interleaved runs on `9e24db7`, the numbers to compare are the p95/p99 tail, the folder reads, and peak commit. If commit headroom on your PC is large, I would expect the store to hold close to its old amount: little gain there, and no tail cost.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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