Skip to content

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

Open
kibagami-nc wants to merge 1 commit into
trustno1-coder:mainfrom
kibagami-nc:fix/upload-oom-frees-spare-chunks
Open

kibagami-nc wants to merge 1 commit into
trustno1-coder:mainfrom
kibagami-nc:fix/upload-oom-frees-spare-chunks

Conversation

@kibagami-nc

@kibagami-nc kibagami-nc commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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 CI: the rest of main's clippy findings, so that with #1517 and #1459 both builds are clean #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.

suren1013 added a commit to suren1013/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
fylcr pushed a commit to fylcr/VIctory-NVIDIA-for-low-end that referenced this pull request Nov 28, 2026
…1-coder#923 trustno1-coder#890 trustno1-coder#1008 trustno1-coder#1005 trustno1-coder#801, and trustno1-coder#953 by hand

Merged from trustno1-coder/VIctory-NVIDIA, all aimed at the 8 GB card / 32 GB
RAM class of machine this fork targets:

  trustno1-coder#784  empty texture blocks kept in proportion to the card's budget
        (VICTORY_SPARE_SCALE=1)
  trustno1-coder#986  texture staging retried in smaller blocks after out-of-memory
  trustno1-coder#923  lists' upload buffers kept and used again, not made for each copy
  trustno1-coder#890  VICTORY_CARD_BUFFERS_MIN_KB, an 8 GB card's floor
  trustno1-coder#1008 fault-page bound raised to 16,384, <4 GiB strays skipped
  trustno1-coder#1005 >65,535-group indirect dispatches enabled on NVIDIA
  trustno1-coder#801  stall-free per-draw zero-alloc and COM fast paths

trustno1-coder#953 (an upload buffer refused for want of memory is asked again once the
spare scratch chunks are freed) conflicted with the tree's own try_upload_buffer
split; ported by hand with the same semantics and the same log line.

Not taken: trustno1-coder#991, trustno1-coder#1014, trustno1-coder#722 - they conflict in pool.rs / draw.rs /
memory.rs, which trustno1-coder#784, trustno1-coder#801 and trustno1-coder#1008 already changed here.
fylcr pushed a commit to fylcr/VIctory-NVIDIA-for-low-end that referenced this pull request Nov 28, 2026
… once

Same treatment trustno1-coder#953 gave upload buffers, extended to the two other buffers the
host makes while a world loads: the spare scratch chunks no list holds are
freed first, then the buffer is asked for once more. On a 32 GB host whose
pagefile is system-managed, the whole box can be out of commit for a moment at
world load (0x8007000E on a 4 MiB shared buffer, with 0.6 GB of commit left),
and the refusal poisons a command list that then fails to close.
@Exopus-0x65f7ad0

Copy link
Copy Markdown

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 Intermittent 0x8007000E at world load on an 8 GB card: same switches, 2 of 3 runs survive #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 Intermittent 0x8007000E at world load on an 8 GB card: same switches, 2 of 3 runs survive #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).

@kibagami-nc

Copy link
Copy Markdown
Contributor Author

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.

…the spares are freed (trustno1-coder#944)

Rebuilt on main, which now pools copy sources (UPLOAD_SPARE) and keeps some
spares under pressure while plenty of the PC's memory is free. The sweep's
rules are unchanged.

When CreateCommittedResource refuses an upload buffer with E_OUTOFMEMORY,
free_all_spares now frees every spare no list holds: the scratch chunks and
the pooled copy sources, whatever keeps_under_pressure would keep. The buffer
is then asked for once more. They are upload and shared buffers in the same
budget, which can run out while the PC still has memory free. With 15.7 GB of
RAM, 368 buffers of 256 KiB were refused in 4 s at world load and the run
ended there (trustno1-coder#944). Any other refusal fails as before. A buffer made on the
second try is logged the first time and at each power of two.

Test: an_out_of_memory_refusal_is_tried_again_once_memory_is_given_back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants