Reclaim idle textures when the texture budget fills #512

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

@⁠suren1013 on GitHub · 2026-11-27 07:58 UTC · original
suren1013:codex/texture-budget-eviction → a-publier · +152 −26 · 2 files · 2 commits · draft

No description provided.

**@⁠suren1013** on GitHub · 2026-11-27 07:58 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512) `suren1013:codex/texture-budget-eviction` → `a-publier` · +152 −26 · 2 files · 2 commits · draft *No description provided.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:59:32 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 11:40 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 d58c262: victory-gpu 398 passed, 1 failed, 34 ignored. The failure, watch::tests::a_view_mapped_beside_a_guarded_one_makes_it_check_again, did not come back in 10 runs alone, here or on the base. It is a watch flake (#450 fixes them), not this PR.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-27 11:40 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7217345087) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `d58c262`: `victory-gpu` 398 passed, 1 failed, 34 ignored. The failure, `watch::tests::a_view_mapped_beside_a_guarded_one_makes_it_check_again`, did not come back in 10 runs alone, here or on the base. It is a `watch` flake (#450 fixes them), not this PR. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:08 UTC · original · reviewed

AI-assisted review. I checked the texture-budget boundary handling and left one input-validation edge case inline.

**@⁠gut0to** on GitHub · 2026-11-27 13:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#pullrequestreview-6088631829) · **reviewed** AI-assisted review. I checked the texture-budget boundary handling and left one input-validation edge case inline.
@ -1766,0 +1782,4 @@
static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
*LIMIT.get_or_init(|| {
let mb = std::env::var("VICTORY_TEXTURE_BUDGET_MB").ok()?;
mb.trim().parse::<u64>().ok().map(|mb| mb << 20)
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:08 UTC · original

AI-assisted review: A left shift here silently discards high bits when the parsed MiB value exceeds u64::MAX / (1 << 20), so an extreme but valid u64 input can become a much smaller budget (or zero) and change eviction behavior. Could this use checked_mul(1 << 20) and treat overflow as an invalid setting, with a boundary test?

**@⁠gut0to** on GitHub · 2026-11-27 13:08 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#discussion_r4719773135) AI-assisted review: A left shift here silently discards high bits when the parsed MiB value exceeds u64::MAX / (1 << 20), so an extreme but valid u64 input can become a much smaller budget (or zero) and change eviction behavior. Could this use checked_mul(1 << 20) and treat overflow as an invalid setting, with a boundary test?
Author
Owner

@⁠Gabriel-Ramaldes on GitHub · 2026-11-27 13:33 UTC · original

In-game test on AMD RDNA 4 with 32 GB, at d58c262 (a-publier 4eb6cfd + this PR).

Setup:

  • Windows 11 Pro 26300, RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 3700X, 32 GB DDR4.
  • Diagnostics build; cargo test --locked -p victory-gpu --lib -- --test-threads=1: 399 passed, 0 failed, 34 ignored.
  • scripts\play.ps1's settings (Series X), the same manual save restored before each run (balcony, ~6,500 draws), 300 s, warm-up first, mirrored order.
  • Since the PR only acts with a texture budget, both builds ran with VICTORY_TEXTURE_BUDGET_MB=6144. That is below the ~7-8 GB of host textures this scene ends with on 4eb6cfd without a budget.
build (VICTORY_TEXTURE_BUDGET_MB=6144) median frame mean worst 1-s line private at the end host textures at the end (last memory: line)
4eb6cfd 147.1 / 112.5 ms 196.8 / 127.9 1,237 / 420 32.7 / 32.3 GB 7.2 / 7.4 GB
this PR 111.7 / 125.8 ms* 115.3 / 124.0 148 / 141 32.9 / 33.3 GB 8.0 / 7.9 GB

* The second run of the PR ended on another camera (11,100 draws against ~6,500), so its frame time is not comparable.

  • Stability: no long stalls in the PR's runs. The base with the same budget had one 1.2 s line and one 420 ms line.
  • The budget is not held:
    • the memory line's host textures end at 7.9-8.0 GB with the PR, above the 6,144 MB budget and above the base's 7.2-7.4 GB with the same budget;
    • private bytes do not drop either.
    • The memory line may count more than filled_texture_bytes(), so this may be expected, but on this PC the switch did not lower memory.
  • Crash at start, not caused by this PR: two of four starts of this build died at t+33 s with #143's signature (victory-image-…dll+0x2215c35, write 0x0, before the world). #386's build had one too, the same day.

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

**@⁠Gabriel-Ramaldes** on GitHub · 2026-11-27 13:33 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7219624479) In-game test on AMD RDNA 4 with 32 GB, at `d58c262` (`a-publier` `4eb6cfd` + this PR). **Setup:** - Windows 11 Pro 26300, RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 3700X, 32 GB DDR4. - Diagnostics build; `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: 399 passed, 0 failed, 34 ignored. - `scripts\play.ps1`'s settings (Series X), the same manual save restored before each run (balcony, ~6,500 draws), 300 s, warm-up first, mirrored order. - Since the PR only acts with a texture budget, both builds ran with `VICTORY_TEXTURE_BUDGET_MB=6144`. That is below the ~7-8 GB of host textures this scene ends with on `4eb6cfd` without a budget. | build (`VICTORY_TEXTURE_BUDGET_MB=6144`) | median frame | mean | worst 1-s line | private at the end | host textures at the end (last `memory:` line) | |---|---|---|---|---|---| | `4eb6cfd` | 147.1 / 112.5 ms | 196.8 / 127.9 | 1,237 / 420 | 32.7 / 32.3 GB | 7.2 / 7.4 GB | | this PR | 111.7 / 125.8 ms* | 115.3 / 124.0 | 148 / 141 | 32.9 / 33.3 GB | 8.0 / 7.9 GB | \* The second run of the PR ended on another camera (11,100 draws against ~6,500), so its frame time is not comparable. - **Stability:** no long stalls in the PR's runs. The base with the same budget had one 1.2 s line and one 420 ms line. - **The budget is not held:** - the memory line's host textures end at 7.9-8.0 GB with the PR, above the 6,144 MB budget and above the base's 7.2-7.4 GB with the same budget; - private bytes do not drop either. - The memory line may count more than `filled_texture_bytes()`, so this may be expected, but on this PC the switch did not lower memory. - **Crash at start, not caused by this PR:** two of four starts of this build died at t+33 s with #143's signature (`victory-image-…dll+0x2215c35`, write 0x0, before the world). #386's build had one too, the same day. AI-assisted (Claude Code); no game files.
Author
Owner

@⁠suren1013 on GitHub · 2026-11-27 14:17 UTC · original

In-game test on AMD RDNA 4 with 32 GB, at d58c262 (a-publier 4eb6cfd + this PR).

Setup:

  • Windows 11 Pro 26300, RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 3700X, 32 GB DDR4.
  • Diagnostics build; cargo test --locked -p victory-gpu --lib -- --test-threads=1: 399 passed, 0 failed, 34 ignored.
  • scripts\play.ps1's settings (Series X), the same manual save restored before each run (balcony, ~6,500 draws), 300 s, warm-up first, mirrored order.
  • Since the PR only acts with a texture budget, both builds ran with VICTORY_TEXTURE_BUDGET_MB=6144. That is below the ~7-8 GB of host textures this scene ends with on 4eb6cfd without a budget.

build (VICTORY_TEXTURE_BUDGET_MB=6144) median frame mean worst 1-s line private at the end host textures at the end (last memory: line)
4eb6cfd 147.1 / 112.5 ms 196.8 / 127.9 1,237 / 420 32.7 / 32.3 GB 7.2 / 7.4 GB
this PR 111.7 / 125.8 ms* 115.3 / 124.0 148 / 141 32.9 / 33.3 GB 8.0 / 7.9 GB

  • The second run of the PR ended on another camera (11,100 draws against ~6,500), so its frame time is not comparable.

  • Stability: no long stalls in the PR's runs. The base with the same budget had one 1.2 s line and one 420 ms line.

  • The budget is not held:

    • the memory line's host textures end at 7.9-8.0 GB with the PR, above the 6,144 MB budget and above the base's 7.2-7.4 GB with the same budget;
    • private bytes do not drop either.
    • The memory line may count more than filled_texture_bytes(), so this may be expected, but on this PC the switch did not lower memory.
  • Crash at start, not caused by this PR: two of four starts of this build died at t+33 s with Every start after the first faults within ~2 minutes at victory-image+0x2215c35 (RX 9070 XT, RDNA4, 4/4) #143's signature (victory-image-…dll+0x2215c35, write 0x0, before the world). Reclaim idle upload memory under host pressure #386's build had one too, the same day.

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

Thanks for the detailed run. The shorter stalls in both completed runs are noted, though two runs aren't enough to conclude much.

How did you pass the budget? It looks like play.ps1 clears inherited VICTORY_* variables, so it may need -More @{ VICTORY_TEXTURE_BUDGET_MB = '6144' }. If you already did that, please ignore this.

If the budget was active, it would also help to compare the budget's own counter with DXGI memory usage on a fixed camera, if the build can print them. I'm keeping this PR as a draft until the budget is shown to hold.

**@⁠suren1013** on GitHub · 2026-11-27 14:17 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7220597978) > In-game test on AMD RDNA 4 with 32 GB, at `d58c262` (`a-publier` `4eb6cfd` + this PR). > > **Setup:** > > * Windows 11 Pro 26300, RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 3700X, 32 GB DDR4. > * Diagnostics build; `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: 399 passed, 0 failed, 34 ignored. > * `scripts\play.ps1`'s settings (Series X), the same manual save restored before each run (balcony, ~6,500 draws), 300 s, warm-up first, mirrored order. > * Since the PR only acts with a texture budget, both builds ran with `VICTORY_TEXTURE_BUDGET_MB=6144`. That is below the ~7-8 GB of host textures this scene ends with on `4eb6cfd` without a budget. > > build (`VICTORY_TEXTURE_BUDGET_MB=6144`) median frame mean worst 1-s line private at the end host textures at the end (last `memory:` line) > `4eb6cfd` 147.1 / 112.5 ms 196.8 / 127.9 1,237 / 420 32.7 / 32.3 GB 7.2 / 7.4 GB > this PR 111.7 / 125.8 ms* 115.3 / 124.0 148 / 141 32.9 / 33.3 GB 8.0 / 7.9 GB > * The second run of the PR ended on another camera (11,100 draws against ~6,500), so its frame time is not comparable. > > * **Stability:** no long stalls in the PR's runs. The base with the same budget had one 1.2 s line and one 420 ms line. > * **The budget is not held:** > > * the memory line's host textures end at 7.9-8.0 GB with the PR, above the 6,144 MB budget and above the base's 7.2-7.4 GB with the same budget; > * private bytes do not drop either. > * The memory line may count more than `filled_texture_bytes()`, so this may be expected, but on this PC the switch did not lower memory. > * **Crash at start, not caused by this PR:** two of four starts of this build died at t+33 s with [Every start after the first faults within ~2 minutes at victory-image+0x2215c35 (RX 9070 XT, RDNA4, 4/4) #143](https://git.gtahub.st/github/Belobug--VIctory-Belobug-AMD/issues/143)'s signature (`victory-image-…dll+0x2215c35`, write 0x0, before the world). [Reclaim idle upload memory under host pressure #386](https://git.gtahub.st/github/Belobug--VIctory-Belobug-AMD/pulls/386)'s build had one too, the same day. > > AI-assisted (Claude Code); no game files. Thanks for the detailed run. The shorter stalls in both completed runs are noted, though two runs aren't enough to conclude much. How did you pass the budget? It looks like play.ps1 clears inherited VICTORY_* variables, so it may need -More @{ VICTORY_TEXTURE_BUDGET_MB = '6144' }. If you already did that, please ignore this. If the budget was active, it would also help to compare the budget's own counter with DXGI memory usage on a fixed camera, if the build can print them. I'm keeping this PR as a draft until the budget is shown to hold.
Author
Owner

@⁠suren1013 on GitHub · 2026-11-27 14:20 UTC · original
On crates/victory-gpu/src/resource.rs line 1785 (outdated):

@@ -1763,6 +1777,41 @@ fn texture_floor_bytes(vram_budget: Option<u64>) -> u64 {
     }
 }
 
+#[cfg(windows)]
+fn texture_budget_bytes() -> Option<u64> {
+    static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new();
+    *LIMIT.get_or_init(|| {
+        let mb = std::env::var("VICTORY_TEXTURE_BUDGET_MB").ok()?;
+        mb.trim().parse::<u64>().ok().map(|mb| mb << 20)

Fixed in 5ad5246: the conversion now uses checked_mul, and an out-of-range value falls back to the default budget behavior, like any other invalid setting. The new test covers the largest valid MiB value and the first overflowing value. Unit tests only so far; the full GPU suite hasn't been run on Windows yet, and this hasn't been run in-game.

**@⁠suren1013** on GitHub · 2026-11-27 14:20 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#discussion_r4720481343) On `crates/victory-gpu/src/resource.rs` line 1785 (outdated): ```diff @@ -1763,6 +1777,41 @@ fn texture_floor_bytes(vram_budget: Option<u64>) -> u64 { } } +#[cfg(windows)] +fn texture_budget_bytes() -> Option<u64> { + static LIMIT: std::sync::OnceLock<Option<u64>> = std::sync::OnceLock::new(); + *LIMIT.get_or_init(|| { + let mb = std::env::var("VICTORY_TEXTURE_BUDGET_MB").ok()?; + mb.trim().parse::<u64>().ok().map(|mb| mb << 20) ``` Fixed in 5ad5246: the conversion now uses checked_mul, and an out-of-range value falls back to the default budget behavior, like any other invalid setting. The new test covers the largest valid MiB value and the first overflowing value. Unit tests only so far; the full GPU suite hasn't been run on Windows yet, and this hasn't been run in-game.
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/512/head:github-bot/gh-512'
git switch 'github-bot/gh-512'

Merge

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