GPU: a texture the host had no memory for is made again later, not refused for the rest of the run #3276

Open
github-bot wants to merge 3 commits from github-bot/gh-3276 into main AGit
Owner

@⁠lerapeurdu62280-debug on GitHub · 2026-11-26 15:27 UTC · original
lerapeurdu62280-debug:fix/texture-retry-after-oom → main · +204 −1 · 3 files · 3 commits · open

What and why

Resource::host stores any failed make_texture as Some(None) ("the host refused it"), and nothing ever clears that: evict only resets Some(Some(t)). So a single transient E_OUTOFMEMORY from CreateCommittedResource (VRAM full while the world streams, mostly on 8-12 GB cards) leaves that title texture without a host texture for the rest of the run, even after evictions have made room.

Change (resource.rs, plus a few lines in descriptor/host.rs and shadow.rs):

  • make_texture notes, in a thread-local, whether its last way (the committed creation) was refused with E_OUTOFMEMORY. Earlier ways (placed, castable) fall through to it, so only the final outcome counts.
  • Resource::host does not store Some(None) for such a refusal. It sets a per-resource refused_until and returns None. Within the wait it returns None at once, with no driver call; the next ask after it tries again.
  • The wait doubles with each refusal for want of memory in a row (500 ms, 1, 2, 4, then 8 s at most) and starts again from 500 ms once the texture is made. The refusal is logged once per texture, when its run of refusals starts (review by @⁠AurumCarlos).
  • Any other refusal (invalid description, etc.) is stored as Some(None) exactly as before.
  • Descriptor side: HostHeap::mirror already makes a draw-read texture slot again when it holds nothing (needs_remake). A slot that shaders only read through the heap is made when its read is marked, and each read is marked once: when mirror leaves a texture slot null for want of memory, it now calls shadow::forget_read, so the next read after the wait is marked and the slot is made (review by @⁠yumaste). Slots left null for other refusals are not re-armed.

This is the same defect a contributor reported on the avatarmanz fork (avatarmanz/VIctory-7900XTX#256, fixed there in avatarmanz/VIctory-7900XTX#293). Here the fix is smaller, thanks to needs_remake. It complements #3266 (backoff on placement-heap growth after OOM): that PR avoids repeating the heap call, this one gives the texture itself a second chance. #1272 (mip-drop on OOM) takes a different, larger route and conflicts with main.

Tested (Windows 10, RX 6600 (RDNA 2, Adrenalin 32.0.21045), Rust 1.98.1)

  • New resource::tests::a_texture_refused_for_want_of_memory_is_made_later: E_OUTOFMEMORY injected into the committed creation (a #[cfg(test)] thread-local; whether the injection was consumed tells whether the host was asked). No driver call within a wait, the second wait twice as long, the texture made after it; E_INVALIDARG stays refused with no further call. RETRY_MS is 100 ms in tests (0.6 s for the test). 5/5 runs. It fails with the retry disabled, and with the doubling disabled.
  • cargo test -p victory-gpu --locked: 229 passed, 3 failed. The 3 (compute_view_marks_rebind_after_depth_twin_conversion, a_texture_written_in_one_format_reads_in_another_through_a_placed_view, depth_bounds_control_a_title_draw) fail the same way on main (63bcca4) on this card.
  • cargo clippy -p victory-gpu --all-targets -D warnings, default and --all-features: clean.
  • Not run in the game, and no real VRAM exhaustion: the failure is injected.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

**@⁠lerapeurdu62280-debug** on GitHub · 2026-11-26 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276) `lerapeurdu62280-debug:fix/texture-retry-after-oom` → `main` · +204 −1 · 3 files · 3 commits · open ### What and why `Resource::host` stores any failed `make_texture` as `Some(None)` ("the host refused it"), and nothing ever clears that: `evict` only resets `Some(Some(t))`. So a single transient `E_OUTOFMEMORY` from `CreateCommittedResource` (VRAM full while the world streams, mostly on 8-12 GB cards) leaves that title texture without a host texture **for the rest of the run**, even after evictions have made room. Change (`resource.rs`, plus a few lines in `descriptor/host.rs` and `shadow.rs`): - `make_texture` notes, in a thread-local, whether its last way (the committed creation) was refused with `E_OUTOFMEMORY`. Earlier ways (placed, castable) fall through to it, so only the final outcome counts. - `Resource::host` does not store `Some(None)` for such a refusal. It sets a per-resource `refused_until` and returns `None`. Within the wait it returns `None` at once, with no driver call; the next ask after it tries again. - The wait doubles with each refusal for want of memory in a row (500 ms, 1, 2, 4, then 8 s at most) and starts again from 500 ms once the texture is made. The refusal is logged once per texture, when its run of refusals starts (review by @⁠AurumCarlos). - Any other refusal (invalid description, etc.) is stored as `Some(None)` exactly as before. - Descriptor side: `HostHeap::mirror` already makes a draw-read texture slot again when it holds nothing (`needs_remake`). A slot that shaders only read through the heap is made when its read is marked, and each read is marked once: when `mirror` leaves a texture slot null for want of memory, it now calls `shadow::forget_read`, so the next read after the wait is marked and the slot is made (review by @⁠yumaste). Slots left null for other refusals are not re-armed. This is the same defect a contributor reported on the avatarmanz fork (avatarmanz/VIctory-7900XTX#256, fixed there in avatarmanz/VIctory-7900XTX#293). Here the fix is smaller, thanks to `needs_remake`. It complements #3266 (backoff on placement-heap growth after OOM): that PR avoids repeating the heap call, this one gives the texture itself a second chance. #1272 (mip-drop on OOM) takes a different, larger route and conflicts with `main`. ### Tested (Windows 10, RX 6600 (RDNA 2, Adrenalin 32.0.21045), Rust 1.98.1) - New `resource::tests::a_texture_refused_for_want_of_memory_is_made_later`: `E_OUTOFMEMORY` injected into the committed creation (a `#[cfg(test)]` thread-local; whether the injection was consumed tells whether the host was asked). No driver call within a wait, the second wait twice as long, the texture made after it; `E_INVALIDARG` stays refused with no further call. `RETRY_MS` is 100 ms in tests (0.6 s for the test). 5/5 runs. **It fails with the retry disabled, and with the doubling disabled.** - `cargo test -p victory-gpu --locked`: 229 passed, 3 failed. The 3 (`compute_view_marks_rebind_after_depth_twin_conversion`, `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, `depth_bounds_control_a_title_draw`) fail the same way on `main` (63bcca4) on this card. - `cargo clippy -p victory-gpu --all-targets -D warnings`, default and `--all-features`: clean. - Not run in the game, and no real VRAM exhaustion: the failure is injected. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Resource::host noted any failed make_texture as Some(None), "the host
refused it", and nothing clears that (evict gives up only made textures):
one E_OUTOFMEMORY left the title texture without a host texture for the
rest of the run, even once evictions made room.

When the last creation make_texture tried was refused with E_OUTOFMEMORY,
the texture is not noted as refused: it is asked again after RETRY_MS
(500 ms), and made then if the host has room. Any other refusal is noted
as before. Draws already make a null slot again (`needs_remake`), so a
slot reading such a texture picks it up once it is made.

Test: a_texture_refused_for_want_of_memory_is_made_later injects one
E_OUTOFMEMORY (made after the wait) and one E_INVALIDARG (stays refused)
into the committed creation. It fails without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:31:01 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 15:33 UTC · original · reviewed

Good fix: an OOM refusal no longer poisons the resource, and other refusals stay Some(None). The flag is cleared before each attempt, so it can't leak between calls.

One thing to bound: a texture that keeps failing is retried every 500 ms for as long as VRAM stays full, and each retry is a CreateCommittedResource plus a warn!("no host texture"). With a few hundred such textures while the world streams, that's a lot of driver calls and log lines per second, exactly when the card is already struggling. Doubling RETRY_MS per consecutive OOM (capped at a few seconds), and/or logging the OOM case once per resource, would keep the second chance without the churn.

Nit: the test sleeps 2 × 600 ms; injecting the clock (or a test-only RETRY_MS) would keep the suite fast.

**@⁠AurumCarlos** on GitHub · 2026-11-26 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#pullrequestreview-6076824740) · **reviewed** Good fix: an OOM refusal no longer poisons the resource, and other refusals stay `Some(None)`. The flag is cleared before each attempt, so it can't leak between calls. One thing to bound: a texture that keeps failing is retried every 500 ms for as long as VRAM stays full, and each retry is a `CreateCommittedResource` plus a `warn!("no host texture")`. With a few hundred such textures while the world streams, that's a lot of driver calls and log lines per second, exactly when the card is already struggling. Doubling `RETRY_MS` per consecutive OOM (capped at a few seconds), and/or logging the OOM case once per resource, would keep the second chance without the churn. Nit: the test sleeps 2 × 600 ms; injecting the clock (or a test-only `RETRY_MS`) would keep the suite fast.
From review: a texture refused for want of memory was asked for every
500 ms while memory stayed short, each time a CreateCommittedResource and
a "no host texture" warning, for each such texture.

- The wait doubles with each refusal for want of memory in a row (500 ms,
  1, 2, 4, then 8 s at most) and starts again from 500 ms once the
  texture is made.
- The refusal is told once per texture, when its run of refusals starts;
  make_texture warns as before for every other refusal.
- RETRY_MS is 100 ms in tests: the test takes 0.6 s instead of 1.4 s. It
  also checks the second wait is twice as long (it fails without the
  doubling).

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

@⁠lerapeurdu62280-debug on GitHub · 2026-11-26 15:41 UTC · original

Thanks @⁠AurumCarlos, all three taken in 698f889:

  • The wait now doubles with each refusal for want of memory in a row (500 ms, 1 s, 2 s, 4 s, then 8 s at most), and goes back to 500 ms once the texture is made.
  • The OOM case is logged once per texture, when its run of refusals starts. make_texture no longer warns for OOM itself; every other refusal warns as before.
  • RETRY_MS is 100 ms under cfg(test), so the test takes 0.6 s instead of 1.4 s. It now also checks that the second wait is twice as long; it fails with the doubling disabled.
**@⁠lerapeurdu62280-debug** on GitHub · 2026-11-26 15:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#issuecomment-7196614348) Thanks @⁠AurumCarlos, all three taken in 698f889: - The wait now doubles with each refusal for want of memory in a row (500 ms, 1 s, 2 s, 4 s, then 8 s at most), and goes back to 500 ms once the texture is made. - The OOM case is logged once per texture, when its run of refusals starts. `make_texture` no longer warns for OOM itself; every other refusal warns as before. - `RETRY_MS` is 100 ms under `cfg(test)`, so the test takes 0.6 s instead of 1.4 s. It now also checks that the second wait is twice as long; it fails with the doubling disabled.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 15:44 UTC · original

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

  • PR head: 34fb1dc8
  • 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 test run in its own process (--exact), -j 4, synthetic tests only, no game data.
  • New test resource::tests::a_texture_refused_for_want_of_memory_is_made_later: passes on the PR (1 passed, 1.25 s).
  • Control on main: the test needs the failure-injection hook (FAIL_NEXT/RETRY_MS) from this PR, so I added only that hook to main and left out the retry logic. The test fails on main at the first "made later" assertion (E_OUTOFMEMORY: the texture stays refused after the wait). That is a main-plus-hook control, not unmodified main.
  • victory-gpu lib suite: PR 247 passed, 0 failed, 1 ignored; main 246 passed, 0 failed, 1 ignored. No failures on either, so none shared with main.
  • Not tested: physical GPU.

AI use: Claude Code (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-26 15:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#issuecomment-7196690361) WARP verification report (test report only, no code changes) - PR head: `34fb1dc8` - 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 test run in its own process (`--exact`), `-j 4`, synthetic tests only, no game data. - New test `resource::tests::a_texture_refused_for_want_of_memory_is_made_later`: **passes on the PR** (1 passed, 1.25 s). - Control on main: the test needs the failure-injection hook (`FAIL_NEXT`/`RETRY_MS`) from this PR, so I added only that hook to main and left out the retry logic. The test **fails on main** at the first "made later" assertion (`E_OUTOFMEMORY`: the texture stays refused after the wait). That is a main-plus-hook control, not unmodified main. - `victory-gpu` lib suite: PR 247 passed, 0 failed, 1 ignored; main 246 passed, 0 failed, 1 ignored. No failures on either, so none shared with main. - Not tested: physical GPU. AI use: Claude Code (Claude Sonnet 5.5)
Author
Owner

@⁠lerapeurdu62280-debug on GitHub · 2026-11-26 15:50 UTC · original

Thanks @⁠oni-swr. Note that the report is on the first commit (34fb1dc). The review follow-up, 698f889 (the doubling wait, one warning per texture, RETRY_MS = 100 ms under cfg(test)), came after it; the test there takes about 0.6 s, and the CI check passes on it.

**@⁠lerapeurdu62280-debug** on GitHub · 2026-11-26 15:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#issuecomment-7196832241) Thanks @⁠oni-swr. Note that the report is on the first commit (34fb1dc). The review follow-up, 698f889 (the doubling wait, one warning per texture, `RETRY_MS` = 100 ms under `cfg(test)`), came after it; the test there takes about 0.6 s, and the CI check passes on it.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 15:52 UTC · original · approved these changes

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

  • Distinguishing E_OUTOFMEMORY in make_texture so Resource::host retries with capped exponential backoff (500 ms up to 8 s) instead of permanently caching Some(None) — while still permanently caching non-OOM refusals like E_INVALIDARG — is clean and well-tested.
  • cargo test -p victory-gpu --lib resource:: -- --test-threads=1 (RTX 5090): 19 passed, 0 failed (including a_texture_refused_for_want_of_memory_is_made_later).
  • VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib resource::tests::a_texture_refused_for_want_of_memory_is_made_later -- --test-threads=1 (WARP): 1 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).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#pullrequestreview-6077071334) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Distinguishing `E_OUTOFMEMORY` in `make_texture` so `Resource::host` retries with capped exponential backoff (`500 ms` up to `8 s`) instead of permanently caching `Some(None)` — while still permanently caching non-OOM refusals like `E_INVALIDARG` — is clean and well-tested. - `cargo test -p victory-gpu --lib resource:: -- --test-threads=1` (RTX 5090): 19 passed, 0 failed (including `a_texture_refused_for_want_of_memory_is_made_later`). - `VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib resource::tests::a_texture_refused_for_want_of_memory_is_made_later -- --test-threads=1` (WARP): 1 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).
Author
Owner

@⁠yumaste on GitHub · 2026-11-26 16:00 UTC · original

I reproduced a gap in the descriptor retry path on this head (698f889), using WARP and the PR's existing FAIL_NEXT hook. If a slot is only read bindlessly, the first read can consume its only notification while the texture is still in backoff.

  1. Mirror an SRV for a synthetic committed D32 texture into a shader-visible heap and inject E_OUTOFMEMORY. The slot is null.
  2. Post a read mark and run shadow::take_reads followed by descriptor::make_read during the cooldown. The first read is seen, but the slot still has no resource.
  3. Expire refused_until, then post another read mark for the same slot. take_reads returns []; the slot stays null. Calling host_heap.mirror(slot, handle, true) explicitly at that point does create the resource and populate the slot.

reads_since clears the mapped marks but intentionally keeps the deduplication state. The null-slot path calls forget_read for a deferred placed view, but not for this already-attempted SRV. Could the failed bindless slots be rearmed or queued for a retry when the OOM wait ends? Keeping this tied to the transient OOM state would preserve the permanent-refusal behavior for other HRESULTs. The regression above does not require a game or real VRAM exhaustion.

I then re-ran the synthetic test with an explicit forget_read(slot) and one collection pass to clear the mark, before simulating the next GPU read. That read was reported and the slot recovered through make_read, without the explicit table read.

**@⁠yumaste** on GitHub · 2026-11-26 16:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#issuecomment-7197050560) I reproduced a gap in the descriptor retry path on this head (`698f889`), using WARP and the PR's existing `FAIL_NEXT` hook. If a slot is only read bindlessly, the first read can consume its only notification while the texture is still in backoff. 1. Mirror an SRV for a synthetic committed D32 texture into a shader-visible heap and inject `E_OUTOFMEMORY`. The slot is null. 2. Post a read mark and run `shadow::take_reads` followed by `descriptor::make_read` during the cooldown. The first read is seen, but the slot still has no resource. 3. Expire `refused_until`, then post another read mark for the same slot. `take_reads` returns `[]`; the slot stays null. Calling `host_heap.mirror(slot, handle, true)` explicitly at that point does create the resource and populate the slot. `reads_since` clears the mapped marks but intentionally keeps the deduplication state. The null-slot path calls `forget_read` for a deferred placed view, but not for this already-attempted SRV. Could the failed bindless slots be rearmed or queued for a retry when the OOM wait ends? Keeping this tied to the transient OOM state would preserve the permanent-refusal behavior for other HRESULTs. The regression above does not require a game or real VRAM exhaustion. I then re-ran the synthetic test with an explicit forget_read(slot) and one collection pass to clear the mark, before simulating the next GPU read. That read was reported and the slot recovered through make_read, without the explicit table read.
From review (yumaste): a heap slot that shaders only read through the
heap is made when its first read is marked (take_reads, make_read), and
each slot's read is marked once until forget_read. If that first read
came while its texture was refused for want of memory (or within the
wait after), the slot was made null and its one read mark was spent:
once the wait was over nothing asked for the texture again.

Resource::host now notes, per thread, that it gave nothing for want of
memory. HostHeap::mirror, when it leaves a texture slot null for that
reason, calls forget_read for the slot, as it already does for a placed
view it leaves for later: the slot's next read is marked, make_read
mirrors it, and the texture is made once the wait is over. Slots left
null for any other refusal are not re-armed.

Test: a_slot_left_null_for_want_of_memory_is_read_again (E_OUTOFMEMORY:
null, re-armed, made after the wait; E_INVALIDARG: null, not re-armed).
It fails without the forget_read; it passes on the RX 6600 and on WARP,
and with the D3D12 debug layer on.

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

@⁠lerapeurdu62280-debug on GitHub · 2026-11-26 16:15 UTC · original

Thanks @⁠yumaste, confirmed and fixed in ddc621b.

Resource::host now notes, per thread, when it gives nothing for want of memory: either refused now, or within the wait that follows. When HostHeap::mirror leaves a texture slot null for that reason, it calls crate::shadow::forget_read(index), as it already does for a placed view it leaves for later. The slot's next read is then marked again, make_read mirrors it (needs_remake sees nothing held), and the texture is made once the wait is over. Slots left null for any other refusal are not re-armed, so the permanent-refusal path is unchanged.

New test a_slot_left_null_for_want_of_memory_is_read_again: an SRV of a committed D32 texture is mirrored with E_OUTOFMEMORY injected. The slot is null and re-armed (shadow::forgotten, a cfg(test) accessor), and after the wait a mirror makes it. With E_INVALIDARG the slot is null and not re-armed. The test fails without the forget_read, and passes on an RX 6600 and on WARP, with the D3D12 debug layer on.

**@⁠lerapeurdu62280-debug** on GitHub · 2026-11-26 16:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3276#issuecomment-7197402513) Thanks @⁠yumaste, confirmed and fixed in ddc621b. `Resource::host` now notes, per thread, when it gives nothing for want of memory: either refused now, or within the wait that follows. When `HostHeap::mirror` leaves a texture slot null for that reason, it calls `crate::shadow::forget_read(index)`, as it already does for a placed view it leaves for later. The slot's next read is then marked again, `make_read` mirrors it (`needs_remake` sees nothing held), and the texture is made once the wait is over. Slots left null for any other refusal are not re-armed, so the permanent-refusal path is unchanged. New test `a_slot_left_null_for_want_of_memory_is_read_again`: an SRV of a committed D32 texture is mirrored with `E_OUTOFMEMORY` injected. The slot is null and re-armed (`shadow::forgotten`, a `cfg(test)` accessor), and after the wait a mirror makes it. With `E_INVALIDARG` the slot is null and not re-armed. The test fails without the `forget_read`, and passes on an RX 6600 and on WARP, with the D3D12 debug layer on.
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/3276/head:github-bot/gh-3276'
git switch 'github-bot/gh-3276'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3276'
git switch 'github-bot/gh-3276'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3276'
git switch 'github-bot/gh-3276'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3276'
git switch 'main'
git merge --squash 'github-bot/gh-3276'
git switch 'main'
git merge --ff-only 'github-bot/gh-3276'
git switch 'main'
git merge 'github-bot/gh-3276'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3276
No description provided.