GPU: back off texture heap growth after out-of-memory #3264

Open
yumaste wants to merge 1 commit from upstream-pr/3266 into main
yumaste commented 2026-11-26 15:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yumaste on 2026-11-26T15:05:59Z.


When D3D12 refuses a new 64 MiB placement heap with E_OUTOFMEMORY, each subsequent small texture can otherwise repeat that driver call before trying a committed texture.

Wait 500 ms before attempting another full heap after that specific error. Free ranges in existing heaps are still considered first. A miss still returns to the existing committed-texture path, and other HRESULTs do not activate the delay. The timer starts when the failed call returns. The policy uses the same D3D12 API on all adapters.

In a synthetic burst of 64 requests following a refusal, the allocator calls the heap factory once instead of 64 times. The regression verifies that allocation is retried when the delay expires and that a free range is reused during the delay in an actual D3D12 heap. WARP GPU suite passed (247 passed, one ignored) and strict Clippy passed. The new regression also passed on a physical NVIDIA RTX 5080 Laptop GPU with both PRs applied. AMD hardware validation remains open. No title files were used.

Clean trial merges with #3259, #3265, #3230, #3228 and #2972. #3259 covers upload staging buffers, while this change covers the default heaps that hold the textures themselves.

Inspired by codec_d's pool-growth backoff in cool_fox.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5512450561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3266). Originally posted by [yumaste](https://github.com/yumaste) on 2026-11-26T15:05:59Z. --- When D3D12 refuses a new 64 MiB placement heap with E_OUTOFMEMORY, each subsequent small texture can otherwise repeat that driver call before trying a committed texture. Wait 500 ms before attempting another full heap after that specific error. Free ranges in existing heaps are still considered first. A miss still returns to the existing committed-texture path, and other HRESULTs do not activate the delay. The timer starts when the failed call returns. The policy uses the same D3D12 API on all adapters. In a synthetic burst of 64 requests following a refusal, the allocator calls the heap factory once instead of 64 times. The regression verifies that allocation is retried when the delay expires and that a free range is reused during the delay in an actual D3D12 heap. WARP GPU suite passed (247 passed, one ignored) and strict Clippy passed. The new regression also passed on a physical NVIDIA RTX 5080 Laptop GPU with both PRs applied. AMD hardware validation remains open. No title files were used. Clean trial merges with #3259, #3265, #3230, #3228 and #2972. #3259 covers upload staging buffers, while this change covers the default heaps that hold the textures themselves. Inspired by [codec_d's pool-growth backoff in cool_fox](https://github.com/DoubleGhosty/cool_fox/commit/ab75ac3e02ba9fe5b45297c6254bafe5660a1a68).
Dukestar69 commented 2026-11-26 15:07:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:07:19Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):

  • Backing off new 64 MiB CreateHeap attempts for 500 ms after E_OUTOFMEMORY while continuing to reuse freed heap ranges and letting callers fall back to committed textures avoids repeated failing heap allocations under VRAM pressure.
  • cargo test -p victory-gpu --lib placement:: -- --test-threads=1 (RTX 5090): 3 passed, 0 failed (including out_of_memory_backs_off_growth_but_not_reuse).
  • VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib placement:: -- --test-threads=1 (WARP): 3 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6076465102 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3266#pullrequestreview-6076465102). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T15:07:19Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Backing off new 64 MiB `CreateHeap` attempts for 500 ms after `E_OUTOFMEMORY` while continuing to reuse freed heap ranges and letting callers fall back to committed textures avoids repeated failing heap allocations under VRAM pressure. - `cargo test -p victory-gpu --lib placement:: -- --test-threads=1` (RTX 5090): 3 passed, 0 failed (including `out_of_memory_backs_off_growth_but_not_reuse`). - `VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib placement:: -- --test-threads=1` (WARP): 3 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 16:10:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T16:10:01Z.


WARP verification report (test report only, no code changes)

  • PR head: 87c6d350
  • main: 63bcca43 (control); WARP software adapter forced with VICTORY_WARP=1 VICTORY_D3D12_WARP=1, --features diagnostics, d3d10warp.dll 10.0.26100.9818; dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0, via VICTORY_DXIL).
  • Each new/changed test run in its own process (--exact), -j 4, synthetic tests only, no game data. Command: cargo test -p victory-gpu --lib --features diagnostics -j 4 -- --exact <test>.
  • New test placement::tests::out_of_memory_backs_off_growth_but_not_reuse (also the changed placement::tests::a_range_is_reused_only_once_nothing_holds_its_texture): both pass on the PR (1 passed each). The test's WARP-device part (reuse of a free range while growth is backed off) ran.
  • Control on main: the test needs the injectable now/make parameters of Heaps::allocate, so I added only that hook to main and left out the backoff logic. The test fails on main at assert_eq!(calls.get(), 1) (left 64, right 1: 64 heap creations for 64 refused allocations instead of 1). That is a main-plus-hook control, not unmodified main.
  • victory-gpu lib suite: PR 247 passed, 0 failed, 1 ignored on 8 of 9 runs; main 246 passed, 0 failed, 1 ignored on 6 of 6. One full-suite run of the PR (the first) had 1 failure, descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record (the slot views the record written last); it passed on its own and in 8 full-suite reruns. This PR does not touch descriptors. That test sets a global WHILE_PREPARING hook that other tests share, which #3265 moves to a thread-local, so this may be a pre-existing flake; I did not reproduce it on main (6 runs).
  • Not tested: physical GPU.

AI-assisted: verification by Claude Code (Claude Sonnet 5.5)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197271657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3266#issuecomment-7197271657). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T16:10:01Z. --- WARP verification report (test report only, no code changes) - PR head: `87c6d350` - main: `63bcca43` (control); WARP software adapter forced with `VICTORY_WARP=1 VICTORY_D3D12_WARP=1`, `--features diagnostics`, d3d10warp.dll 10.0.26100.9818; dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0, via `VICTORY_DXIL`). - Each new/changed test run in its own process (`--exact`), `-j 4`, synthetic tests only, no game data. Command: `cargo test -p victory-gpu --lib --features diagnostics -j 4 -- --exact <test>`. - New test `placement::tests::out_of_memory_backs_off_growth_but_not_reuse` (also the changed `placement::tests::a_range_is_reused_only_once_nothing_holds_its_texture`): **both pass on the PR** (1 passed each). The test's WARP-device part (reuse of a free range while growth is backed off) ran. - Control on main: the test needs the injectable `now`/`make` parameters of `Heaps::allocate`, so I added only that hook to main and left out the backoff logic. The test **fails on main** at `assert_eq!(calls.get(), 1)` (left 64, right 1: 64 heap creations for 64 refused allocations instead of 1). That is a main-plus-hook control, not unmodified main. - `victory-gpu` lib suite: PR 247 passed, 0 failed, 1 ignored on 8 of 9 runs; main 246 passed, 0 failed, 1 ignored on 6 of 6. One full-suite run of the PR (the first) had 1 failure, `descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` (`the slot views the record written last`); it passed on its own and in 8 full-suite reruns. This PR does not touch descriptors. That test sets a global `WHILE_PREPARING` hook that other tests share, which #3265 moves to a thread-local, so this may be a pre-existing flake; I did not reproduce it on main (6 runs). - Not tested: physical GPU. AI-assisted: verification by Claude Code (Claude Sonnet 5.5)
shortselow-byte commented 2026-11-27 01:30:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-27T01:30:19Z.


AMD hardware check at 87c6d350, on an RX 6900 XT (RDNA 2, Windows 11, no VICTORY_* variables, so the host device is the hardware adapter, not WARP):

  • placement::tests::out_of_memory_backs_off_growth_but_not_reuse: passes, including the part that creates a real 64 MiB heap and reuses its free range during the delay.
  • cargo test -p victory-gpu --lib --locked: 232 passed, 0 failed, 1 ignored. main 63bcca4 on the same card: 231 passed, 0 failed, 1 ignored. No test that passes on main fails here.

One in-game observation that may matter for the scope. On this machine (16 GB RAM, commit limit ~35 GB), GTA VI runs out of commit a few minutes into the world, so I looked at which allocations fail. In two runs (main, and main + #2974, which does not touch these paths), the logged E_OUTOFMEMORY refusals are almost all in Host::shared_buffer:

  • main: 100 no shared buffer warnings, then a host command list did not close and the run aborted at 179 s.
  • main + #2974: 177,750 no shared buffer warnings in 168 s (170,028 of them 4 MiB, 7,710 of 64 KiB), plus 163 no mapped buffer (Host::mapped_buffer, upload/readback buffers).

shared_buffer calls CreateCommittedResource again on every request and has no backoff, so after the first refusal it keeps hitting the driver at about 1,000 calls per second. On main a refused CreateHeap in placement.rs is not logged, so I cannot tell from these logs how often this PR's path was hit in game. I'm not claiming a gain or loss for this PR in game. The point is only that, on a low-RAM machine, the refusals I can see are in shared_buffer (and a few in mapped_buffer), which this PR does not cover.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207340047 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3266#issuecomment-7207340047). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-27T01:30:19Z. --- AMD hardware check at `87c6d350`, on an RX 6900 XT (RDNA 2, Windows 11, no `VICTORY_*` variables, so the host device is the hardware adapter, not WARP): - `placement::tests::out_of_memory_backs_off_growth_but_not_reuse`: passes, including the part that creates a real 64 MiB heap and reuses its free range during the delay. - `cargo test -p victory-gpu --lib --locked`: 232 passed, 0 failed, 1 ignored. `main` `63bcca4` on the same card: 231 passed, 0 failed, 1 ignored. No test that passes on `main` fails here. One in-game observation that may matter for the scope. On this machine (16 GB RAM, commit limit ~35 GB), GTA VI runs out of commit a few minutes into the world, so I looked at which allocations fail. In two runs (`main`, and `main` + #2974, which does not touch these paths), the logged `E_OUTOFMEMORY` refusals are almost all in `Host::shared_buffer`: - `main`: 100 `no shared buffer` warnings, then `a host command list did not close` and the run aborted at 179 s. - `main` + #2974: 177,750 `no shared buffer` warnings in 168 s (170,028 of them 4 MiB, 7,710 of 64 KiB), plus 163 `no mapped buffer` (`Host::mapped_buffer`, upload/readback buffers). `shared_buffer` calls `CreateCommittedResource` again on every request and has no backoff, so after the first refusal it keeps hitting the driver at about 1,000 calls per second. On `main` a refused `CreateHeap` in `placement.rs` is not logged, so I cannot tell from these logs how often this PR's path was hit in game. I'm not claiming a gain or loss for this PR in game. The point is only that, on a low-RAM machine, the refusals I can see are in `shared_buffer` (and a few in `mapped_buffer`), which this PR does not cover.
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/3266:upstream-pr/3266'
git switch 'upstream-pr/3266'

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 'main'
git merge --no-ff 'upstream-pr/3266'
git switch 'upstream-pr/3266'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3266'
git switch 'upstream-pr/3266'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3266'
git switch 'main'
git merge --squash 'upstream-pr/3266'
git switch 'main'
git merge --ff-only 'upstream-pr/3266'
git switch 'main'
git merge 'upstream-pr/3266'
git push origin 'main'
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
Marvisak/VIctory!3264
No description provided.