Reclaim idle textures when the texture budget fills #512

Open
suren1013 wants to merge 2 commits from upstream-pr/512 into a-publier
suren1013 commented 2026-11-27 07:58:20 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by suren1013 on 2026-11-27T07:58:20Z.


No description provided.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5523209883 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512). Originally posted by [suren1013](https://github.com/suren1013) on 2026-11-27T07:58:20Z. --- _No description provided._
MamaLeVrai commented 2026-11-27 11:40:28 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-27T11:40:28Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7217345087 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7217345087). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-27T11:40:28Z. --- 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.
gut0to commented 2026-11-27 13:08:44 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T13:08:44Z.

Review: COMMENTED


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

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6088631829 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#pullrequestreview-6088631829). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T13:08:44Z. **Review:** COMMENTED --- AI-assisted review. I checked the texture-budget boundary handling and left one input-validation edge case inline.
gut0to commented 2026-11-27 13:08:45 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T13:08:45Z.

Code review location: crates/victory-gpu/src/resource.rs; line 1785

@@ -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)

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?

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4719773135 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#discussion_r4719773135). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T13:08:45Z. **Code review location:** `crates/victory-gpu/src/resource.rs`; line 1785 ~~~~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) ~~~~ --- 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?
Gabriel-Ramaldes commented 2026-11-27 13:33:00 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Gabriel-Ramaldes on 2026-11-27T13:33:00Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7219624479 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7219624479). Originally posted by [Gabriel-Ramaldes](https://github.com/Gabriel-Ramaldes) on 2026-11-27T13:33:00Z. --- 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.
suren1013 commented 2026-11-27 14:17:36 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by suren1013 on 2026-11-27T14:17:36Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7220597978 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#issuecomment-7220597978). Originally posted by [suren1013](https://github.com/suren1013) on 2026-11-27T14:17:36Z. --- > 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://github.com/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://github.com/Belobug/VIctory-Belobug-AMD/pull/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 commented 2026-11-27 14:20:20 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by suren1013 on 2026-11-27T14:20:20Z.

Code review location: crates/victory-gpu/src/resource.rs; line 1785

@@ -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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4720481343 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/512#discussion_r4720481343). Originally posted by [suren1013](https://github.com/suren1013) on 2026-11-27T14:20:20Z. **Code review location:** `crates/victory-gpu/src/resource.rs`; line 1785 ~~~~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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/512:upstream-pr/512'
git switch 'upstream-pr/512'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'a-publier'
git merge --no-ff 'upstream-pr/512'
git switch 'upstream-pr/512'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/512'
git switch 'upstream-pr/512'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'upstream-pr/512'
git switch 'a-publier'
git merge --squash 'upstream-pr/512'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/512'
git switch 'a-publier'
git merge 'upstream-pr/512'
git push origin 'a-publier'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Belobug/VIctory-Belobug-AMD!512
No description provided.