GPU: an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed (#944) #953

Manually merged
github merged 1 commit from github-bot/gh-953 into main 2026-11-29 08:20:37 +00:00 AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 09:50 UTC · original
kibagami-nc:fix/upload-oom-frees-spare-chunks → main · +123 −9 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

Rebuilt on main 32ecacf (force-pushed). Main now pools copy sources (UPLOAD_SPARE, up to 1 GiB of each kind, from 924911f), and its sweep keeps some spares under pressure while plenty of the PC's memory is free. This change leaves that sweep alone. On an E_OUTOFMEMORY refusal it now frees every spare no list holds, the scratch chunks and the pooled copy sources, through free_all_spares, then asks once more. With the pool, a refusal now has much more to free than in Exopus-0x65f7ad0's run below, where the scratch chunks were already gone. cargo test -p victory-gpu --lib --locked on the rebuilt branch: 478 passed, 37 ignored. Clippy is clean in both builds, with main's own manual_is_multiple_of allowed.

What happens

An upload buffer comes out of the PC's memory the card may use: D3D12's non-local budget, about half the RAM. That budget can run out while the PC itself still has memory free.

#944 shows it: an RTX 4060 Laptop with 15.7 GB of RAM, and three runs with the same switches.

  • In the failing run: in 4 s at world load, 368 upload buffers of 262,144 bytes were refused with 0x8007000E. That size is SCRATCH_FIRST, a list's first scratch chunk. Then a host state prelude did not record (0x8007000E), and the run ended there.
  • The other two runs loaded and played.

Meanwhile the spare scratch chunks, the ones no list holds, are upload buffers in that same budget: up to 128 MiB of them on a PC with 32 GB or less (SPARE_MOST). Only the once-a-second sweep frees them, and only while residency::pressured() holds. That is decided by the PC's free physical memory and commit, not by this budget. So they stayed kept while new ones were refused. The 368 refused buffers came to about 92 MiB.

The change

crates/victory-gpu/src/host.rs:

  • Host::upload_buffer asks once more when a buffer is refused with E_OUTOFMEMORY, after trim_spare_chunks freed the spare chunks. trim_spare_chunks now returns the bytes it freed. It frees them as the sweep does: no list holds them, and their submissions have run.
  • The rule is in make_or_free_and_retry, which can be tested without running out of memory:
  • A buffer made on the second try is logged the first time and at each power of two, with the MB freed.
  • Any other refusal fails as before (no upload buffer, residency::allocation_error).

This keeps a run going through a spike while chunks are spare. It does not make room the title or the texture queue have already taken. #944's failing run also had its texture queue fall far behind first.

Tests

  • New host::spare::an_out_of_memory_refusal_is_tried_again_once_memory_is_given_back:
  • cargo test -p victory-gpu --lib --locked: 454 passed, 36 ignored.
  • Clippy (-D warnings, default and --all-features): nothing in the changed lines. It stops on main's own manual_is_multiple_of (fixed in #665). With that lint allowed, both builds are clean.
  • Lock order: trim_spare_chunks takes the spare pool's lock, and no caller of upload_buffer holds it. take_chunk lets it go before it makes a new chunk.

Not run with the game. On a PC like #944's, a log with this change would show was made once the spare scratch chunks were freed where no upload buffer was before. Read-back and shared buffers fail the same way under that budget (#804 counts both), and could take the same step if a log shows them refused while chunks are spare.

Seen by others (#944)

  • KIFIR4KK, a 32 GB control on the same card class (desktop RTX 4060 8 GB, same build). In three runs the texture queue was even more saturated (18,461 to 22,983 slots due) and the PC reached host memory pressure. There was not one 0x8007000E or no upload buffer. That fits a budget of the PC's memory running out on 15.7 GB, rather than the card's own.
  • ArturoWolff, Linux under GE-Proton, RTX 4060 desktop 8 GB, 16 GB, sampling the budgets once a second. Their runs end in another way: no refusal, no budget sampled past its limit, and no spare scratch at the last samples. So this change does not bear on that failure, as they note, and it does not contradict the Windows one.

Tested by Exopus-0x65f7ad0 (RTX 5060 Ti 8 GB, 16 GB, Windows 11 26300)

Four starts with this change and the switches that had failed there that morning, on the same save. Three ran through with no refusal at all. One still died, about the rate seen without it (#944: 1 in 3).

  • In that run the second try did fire, four times, but it freed only 0 to 3 MB each time: the spare chunks were already gone.
  • The first refusals were a 2.2 MB upload buffer and an 8 MB shared buffer, not scratch chunks.
  • The card's own memory was over its line at the same moment (7032 MB against a line of 6325 MB).
  • It ended 19 s later on a host command list did not close (0x8007000E).

So on that machine the spare chunks are not what runs dry. The whole budget outside the card's memory was used up while the card's own memory was full. This change is harmless there (it only acts on E_OUTOFMEMORY), but it does not prevent that failure. What fills the budget during world load is the lead: texture staging, and copies moved out of the card's memory. #986 and #991 work on that side.

No game files, dumps or extracted data are included.

**@⁠kibagami-nc** on GitHub · 2026-11-28 09:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/953) `kibagami-nc:fix/upload-oom-frees-spare-chunks` → `main` · +123 −9 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC **Rebuilt on main `32ecacf` (force-pushed).** Main now pools copy sources (`UPLOAD_SPARE`, up to 1 GiB of each kind, from 924911f), and its sweep keeps some spares under pressure while plenty of the PC's memory is free. This change leaves that sweep alone. On an `E_OUTOFMEMORY` refusal it now frees every spare no list holds, the scratch chunks **and** the pooled copy sources, through `free_all_spares`, then asks once more. With the pool, a refusal now has much more to free than in Exopus-0x65f7ad0's run below, where the scratch chunks were already gone. `cargo test -p victory-gpu --lib --locked` on the rebuilt branch: 478 passed, 37 ignored. Clippy is clean in both builds, with main's own `manual_is_multiple_of` allowed. ## What happens An upload buffer comes out of the PC's memory the card may use: D3D12's non-local budget, about half the RAM. That budget can run out while the PC itself still has memory free. #944 shows it: an RTX 4060 Laptop with 15.7 GB of RAM, and three runs with the same switches. - **In the failing run:** in 4 s at world load, 368 upload buffers of 262,144 bytes were refused with `0x8007000E`. That size is `SCRATCH_FIRST`, a list's first scratch chunk. Then `a host state prelude did not record (0x8007000E)`, and the run ended there. - **The other two runs** loaded and played. Meanwhile the spare scratch chunks, the ones no list holds, are upload buffers in that same budget: up to 128 MiB of them on a PC with 32 GB or less (`SPARE_MOST`). Only the once-a-second sweep frees them, and only while `residency::pressured()` holds. That is decided by the PC's free physical memory and commit, not by this budget. So they stayed kept while new ones were refused. The 368 refused buffers came to about 92 MiB. ## The change `crates/victory-gpu/src/host.rs`: - `Host::upload_buffer` asks once more when a buffer is refused with `E_OUTOFMEMORY`, after `trim_spare_chunks` freed the spare chunks. `trim_spare_chunks` now returns the bytes it freed. It frees them as the sweep does: no list holds them, and their submissions have run. - The rule is in `make_or_free_and_retry`, which can be tested without running out of memory: - A buffer made on the second try is logged the first time and at each power of two, with the MB freed. - Any other refusal fails as before (`no upload buffer`, `residency::allocation_error`). This keeps a run going through a spike while chunks are spare. It does not make room the title or the texture queue have already taken. #944's failing run also had its texture queue fall far behind first. ## Tests - **New** `host::spare::an_out_of_memory_refusal_is_tried_again_once_memory_is_given_back`: - **`cargo test -p victory-gpu --lib --locked`**: 454 passed, 36 ignored. - **Clippy** (`-D warnings`, default and `--all-features`): nothing in the changed lines. It stops on `main`'s own `manual_is_multiple_of` (fixed in #665). With that lint allowed, both builds are clean. - **Lock order:** `trim_spare_chunks` takes the spare pool's lock, and no caller of `upload_buffer` holds it. `take_chunk` lets it go before it makes a new chunk. Not run with the game. On a PC like #944's, a log with this change would show `was made once the spare scratch chunks were freed` where `no upload buffer` was before. Read-back and shared buffers fail the same way under that budget (#804 counts both), and could take the same step if a log shows them refused while chunks are spare. ## Seen by others (#944) - **KIFIR4KK**, a 32 GB control on the same card class (desktop RTX 4060 8 GB, same build). In three runs the texture queue was even more saturated (18,461 to 22,983 slots due) and the PC reached `host memory pressure`. There was not one `0x8007000E` or `no upload buffer`. That fits a budget of the PC's memory running out on 15.7 GB, rather than the card's own. - **ArturoWolff**, Linux under GE-Proton, RTX 4060 desktop 8 GB, 16 GB, sampling the budgets once a second. Their runs end in another way: no refusal, no budget sampled past its limit, and no spare scratch at the last samples. So this change does not bear on that failure, as they note, and it does not contradict the Windows one. ## Tested by Exopus-0x65f7ad0 (RTX 5060 Ti 8 GB, 16 GB, Windows 11 26300) Four starts with this change and the switches that had failed there that morning, on the same save. Three ran through with no refusal at all. **One still died**, about the rate seen without it (#944: 1 in 3). - In that run the second try did fire, four times, but it freed only 0 to 3 MB each time: the spare chunks were already gone. - The first refusals were a 2.2 MB upload buffer and an 8 MB shared buffer, not scratch chunks. - The card's own memory was over its line at the same moment (`7032 MB against a line of 6325 MB`). - It ended 19 s later on `a host command list did not close (0x8007000E)`. So on that machine the spare chunks are not what runs dry. The whole budget outside the card's memory was used up while the card's own memory was full. This change is harmless there (it only acts on `E_OUTOFMEMORY`), but it does not prevent that failure. What fills the budget during world load is the lead: texture staging, and copies moved out of the card's memory. #986 and #991 work on that side. No game files, dumps or extracted data are included.
An upload buffer comes out of the PC's memory the card may use, a D3D12
budget of about half the RAM. That budget can run out while the PC still
has memory free: on a 15.7 GB laptop, 368 buffers of 256 KiB (lists'
first scratch chunks) were refused with 0x8007000E in 4 s at world load,
a host state prelude did not record, and the run ended (#944). The spare
scratch chunks no list holds are upload buffers in that same budget, up
to 128 MiB of them on such a PC, and only the sweep frees them, once the
PC itself is short of memory.

Host::upload_buffer now frees them when a buffer is refused with
E_OUTOFMEMORY and asks once more. A buffer made that way is logged at
the first time and at each power of two. Any other refusal, and one with
nothing spare to free, fails as before.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:30:48 +00:00
Author
Owner

@⁠Exopus-0x65f7ad0 on GitHub · 2026-11-28 13:12 UTC · original

Tested on a machine close to #944's: RTX 5060 Ti 8 GB (DXGI local budget ~7.0 GB), 16 GB RAM, Windows 11 26300. Base 63b902f plus this PR merged; the few extra local commits don't touch host.rs upload or scratch code. README launcher defaults with -Dlss balanced, which is the switch set that died this morning on the same machine without the PR (2,711 × no upload buffer 0x8007000E, then a host state prelude did not record).

Runs with this PR (4 starts, same switches, same save)

Start Survived no upload buffer no shared buffer "made once the spare scratch chunks were freed" lines fps after load
13:05 yes 0 0 0 14.7 avg on a 90 s scripted walk
13:55 no 18,779 5,060 4 (times=1,2,4,8; freed_mb = 0, 3, 0, 0) —
13:58 yes 0 0 0 19
14:05 yes 0 0 0 17

So 1 of 4 still died, about the same rate as without the PR (#944 had 1 of 3).

What the failing run shows

  • The retry path does fire. But by then the spare chunks are already gone: it freed 0–3 MB each time, against the ~92 MiB estimated in #944.
  • The refusals were not only SCRATCH_FIRST (262,144 bytes). The first two in the log are a 2,228,224-byte upload buffer and an 8,388,608-byte shared buffer, both at 12:58:18. So the whole non-local budget was exhausted, not just the scratch pool.
  • The card's own memory was full at the same moment:
    texture queue's room: 6244 MB in use ... + 1592 MB kept for render targets = 7032 MB against a line of 6325 MB (90.0 % of a budget of 7028 MB): no room.
    My guess is that local overflow is being demoted into the same non-local budget.
  • It ended 19 s after the first refusal, on a different line than #944: host GPU failure: a host command list did not close (0x8007000E), with host copies in the card's memory could not be brought up to date (0x8007000E) just before it. No prelude did not record this time.

Take-away

The change looks correct and harmless: no regressions in the 3 good runs, and the retry rule only acts on E_OUTOFMEMORY. On an 8 GB / 16 GB machine, though, the spare scratch chunks are not the reservoir that runs dry. Whatever demotes into the non-local budget during world load, while VRAM is at ~100 %, is the real driver. A cap on the non-local side (texture staging plus card-copy demotion), or backing off texture admission sooner once no room is reported, would probably matter more here. #986 (smaller staging blocks after OOM) and #991 (pooled buffers) also touch this; I'll run #991 next on the same machine and post there.

Logs are available if useful (they contain only the emulator's own lines).

**@⁠Exopus-0x65f7ad0** on GitHub · 2026-11-28 13:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/953#issuecomment-7239768877) Tested on a machine close to #944's: **RTX 5060 Ti 8 GB (DXGI local budget ~7.0 GB), 16 GB RAM**, Windows 11 26300. Base `63b902f` plus this PR merged; the few extra local commits don't touch `host.rs` upload or scratch code. README launcher defaults with `-Dlss balanced`, which is the switch set that died this morning on the same machine without the PR (2,711 × `no upload buffer` 0x8007000E, then `a host state prelude did not record`). ### Runs with this PR (4 starts, same switches, same save) | Start | Survived | `no upload buffer` | `no shared buffer` | "made once the spare scratch chunks were freed" lines | fps after load | |---|---|---|---|---|---| | 13:05 | yes | 0 | 0 | 0 | 14.7 avg on a 90 s scripted walk | | 13:55 | **no** | 18,779 | 5,060 | 4 (`times`=1,2,4,8; `freed_mb` = 0, 3, 0, 0) | — | | 13:58 | yes | 0 | 0 | 0 | 19 | | 14:05 | yes | 0 | 0 | 0 | 17 | So 1 of 4 still died, about the same rate as without the PR (#944 had 1 of 3). ### What the failing run shows - The retry path **does fire**. But by then the spare chunks are already gone: it freed **0–3 MB** each time, against the ~92 MiB estimated in #944. - The refusals were not only `SCRATCH_FIRST` (262,144 bytes). The first two in the log are a **2,228,224-byte** upload buffer and an **8,388,608-byte** shared buffer, both at `12:58:18`. So the whole non-local budget was exhausted, not just the scratch pool. - The card's own memory was full at the same moment: `texture queue's room: 6244 MB in use ... + 1592 MB kept for render targets = 7032 MB against a line of 6325 MB (90.0 % of a budget of 7028 MB): no room`. My guess is that local overflow is being demoted into the same non-local budget. - It ended 19 s after the first refusal, on a different line than #944: `host GPU failure: a host command list did not close (0x8007000E)`, with `host copies in the card's memory could not be brought up to date (0x8007000E)` just before it. No `prelude did not record` this time. ### Take-away The change looks correct and harmless: no regressions in the 3 good runs, and the retry rule only acts on `E_OUTOFMEMORY`. On an 8 GB / 16 GB machine, though, the spare scratch chunks are not the reservoir that runs dry. Whatever demotes into the non-local budget during world load, while VRAM is at ~100 %, is the real driver. A cap on the non-local side (texture staging plus card-copy demotion), or backing off texture admission sooner once `no room` is reported, would probably matter more here. #986 (smaller staging blocks after OOM) and #991 (pooled buffers) also touch this; I'll run #991 next on the same machine and post there. Logs are available if useful (they contain only the emulator's own lines).
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 13:46 UTC · original

Thank you, that is the test this needed, and it answers it. The retry fires, but by then there is nothing spare to free (0 to 3 MB), and the refusals start with an ordinary 2.2 MB upload buffer and an 8 MB shared buffer while the card's own memory is over its line. So on an 8 GB / 16 GB PC the spare chunks are not the reservoir that runs dry, and this change does not prevent that crash. I put your runs and that conclusion in the description, so nobody takes it for the fix of #944.

I'll keep it open as a small, harmless hardening for a spike while chunks are spare, unless the maintainer prefers to drop it. I'll look at what moves into that budget while the card is full, and wait for your #991 numbers before touching the same paths.

**@⁠kibagami-nc** on GitHub · 2026-11-28 13:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/953#issuecomment-7240174054) Thank you, that is the test this needed, and it answers it. The retry fires, but by then there is nothing spare to free (0 to 3 MB), and the refusals start with an ordinary 2.2 MB upload buffer and an 8 MB shared buffer while the card's own memory is over its line. So on an 8 GB / 16 GB PC the spare chunks are not the reservoir that runs dry, and this change does not prevent that crash. I put your runs and that conclusion in the description, so nobody takes it for the fix of #944. I'll keep it open as a small, harmless hardening for a spike while chunks are spare, unless the maintainer prefers to drop it. I'll look at what moves into that budget while the card is full, and wait for your #991 numbers before touching the same paths.
github-bot force-pushed github-bot/gh-953 from f87534e336 to d8ae70b310 2026-11-28 19:19:31 +00:00 Compare
github manually merged commit d75a0b5b1d into main 2026-11-29 08:20:37 +00:00
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/trustno1-coder--VIctory-NVIDIA!953
No description provided.