Skip to content

GPU: an early list reset leaves a held host list it cannot replace - #3002

Open
ZeOs360 wants to merge 2 commits into
Marvisak:mainfrom
ZeOs360:pr/list-restart-oom
Open

ZeOs360 wants to merge 2 commits into
Marvisak:mainfrom
ZeOs360:pr/list-restart-oom

Conversation

@ZeOs360

@ZeOs360 ZeOs360 commented Nov 26, 2026 •

Copy link
Copy Markdown

What

When the title resets a command list while a queue still holds part of it
(a wait the queue has not seen hold yet; D3D12 lets a list be reset as
soon as it is submitted), list::restart replaces each held host list
with a spare or a new one. When none can be made, because
CreateCommandAllocator/CreateCommandList fail with E_OUTOFMEMORY once
system memory for the GPU has run out, it kept the held host list in
place:

  • the title then recorded into a host list that was closed and that a
    queue held, and closing it again failed (Close returns E_FAIL: "a host
    command list did not close (0x80004005)");
  • a later submission of the title list would have run that host list a
    second time;
  • leave did not get it, so the title list's upload memory and draw
    state could be freed while the queue still ran that host list.

This PR makes the title list's host lists end before the first held one
that cannot be replaced:

  • it and any held after it are the queue's, and leave gets the last
    held one (the last to run);
  • the closed host lists after it go back to the spares once no queue holds
    them; those not recorded since the last reset are still open and are
    dropped, since resetting an open list fails;
  • a title list without a host list records nothing until its next reset,
    which takes a spare or makes one if it can; as D3D12 does when memory
    runs out, Reset and Close return E_OUTOFMEMORY for it, and its
    bottom-of-pipe writes are not done (they used to be done on the CPU at
    once, as without a host GPU, telling the title the list had run);
  • a wait that cannot start a new host list (the same failure) closes the
    one being recorded and loses the recording until the next reset: it
    used to be dropped, and what followed ran without it. Now nothing more
    is recorded, Close returns E_OUTOFMEMORY and a submission of the list
    runs nothing; the next reset resets its host lists in place;
  • next_segment tries the spares before making a new host list, and a
    host list that cannot be made is logged ("no host command list").

Tests

  • list::tests::early_reset_without_a_new_host_list_does_not_keep_the_closed_one:
    a list is closed and held (as by a queue), then reset while no host list
    can be made. The reset returns E_OUTOFMEMORY and the list has no host
    list afterwards; a bottom-of-pipe write recorded then does not land,
    closing it returns E_OUTOFMEMORY, and once the held one is given back,
    the next reset gets one again.
  • list::tests::a_reset_that_cannot_replace_a_held_host_list_cuts_the_list_there:
    three segments made, the list reset, then two recorded (the third still
    open) and both held. The last held one keeps what the title list owned
    (one more piece of work after it runs), and the title list holds none of
    them. Again with only the first held: the closed one cut off goes back
    to the spares, and the open one is dropped (with it reset instead, the
    test process stops at "a host command list did not reset").
  • list::tests::a_wait_without_a_new_host_list_loses_the_recording: a
    list cut once by a wait, then a second wait while no host list can be
    made. Nothing past it is recorded, no bottom-of-pipe write lands, Close
    returns E_OUTOFMEMORY, a submission gets no host lists, and the next
    reset, still without new host lists, starts again in the list's own
    first one.
  • cargo test -p victory-gpu: 234 passed. cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features: clean.
    cargo xtask policy: ok. The other crates' tests pass, except two
    victory-shader tests that fail on my machine with a DXIL validation
    error (rectangles_get_their_fourth_corner,
    elements_sharing_a_row_keep_their_order); this PR does not touch that
    crate.
  • Parallel runs of the crate's tests fail about as often as on main
    (2 of 30 against 1 of 30), each time in
    shadow::tests::partial_refresh_under_marked_range_updates_saved_bytes,
    which GPU: a marked page's copy-back writes only the bytes the shaders changed, with plain stores #2918 addresses.

In game

Machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11, Series X
profile, diagnostics build. My own copy of the title was used; only log
lines, counts and timings are reported here.

  • On this 16 GB machine every run of the prologue's intro sees
    CreateCommittedResource for shared (CUSTOM, L0) buffers fail with
    E_OUTOFMEMORY after 2.5 to 5 minutes. In one run of this change alone,
    making a host list then failed 41 times ("no host command list", which
    covers this case and the other places a host list is made), and no
    Close failed then.
  • The run still stopped 34 s after the first E_OUTOFMEMORY, at a Close
    that itself returned E_OUTOFMEMORY, as runs without this change do. That
    failure comes from the memory running out, not from the list kept in
    place; this PR does not address it, so it does not make such runs last
    longer.
  • Two earlier runs without this change (on an older main, 13f91ca)
    stopped there with E_FAIL instead, which matches a list closed twice; I
    did not confirm that with the debug layer, which is not installed here.

AI-assisted: written with Claude Code (Claude Opus 5.5) and reviewed by
Gemini 4 Neon. I read the code and the reviews, and ran the in-game tests
on my machine.

When the title resets a list that a queue still holds part of (a wait
the queue has not seen hold yet), restart() replaces each held host list
with a spare or a new one. When none could be made (CreateCommandList or
CreateCommandAllocator failing once system memory for the GPU ran out),
it kept the held one in place: the title then recorded into a list that
was closed and the queue's, closing it again failed (E_FAIL, "a host
command list did not close"), a later submission would have run it a
second time, and leave() did not get it, so the title list's uploads
and state could be freed while it ran.

Now the title list's host lists end before that one: it and any held
after it are the queue's, and leave() gets the last held one; the
closed ones after it go back to the spares once no queue holds them,
and those not recorded since the last reset (still open: resetting them
would fail) are dropped. A title list without a host list records
nothing until its next reset, which takes a spare or makes one if it
can. A wait that starts a new segment also takes a spare before making
a list, and a list that cannot be made is logged ("no host command
list").

In the prologue's intro on a 16 GB machine, once the shared buffers
began failing with E_OUTOFMEMORY, making a host list failed 41 times in
one run of this change alone ("no host command list"), and no Close
failed then. The run still stopped
34 s later, as runs without it do, at a Close that itself returned
E_OUTOFMEMORY: that failure is the allocation's, not this one.

Tests: early_reset_without_a_new_host_list_does_not_keep_the_closed_one
(no host list is left, closing does not fail, the next reset gets one);
a_reset_that_cannot_replace_a_held_host_list_cuts_the_list_there (three
segments made, reset, then two recorded so the third is still open, and
both held: the last held one keeps what the title list owned; again with
only the first held: the closed one cut off goes back to the spares and
the open one is dropped, which a reset of it would not survive).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — real bug correctly contained: previously an unreplaced held list stayed attached, so a later Close failed and submission could re-run it. The keep-cutoff drains everything past the failed segment (held last one keeps ownership via left, recorded ones recycle once the queue frees them, open ones drop since reset would fail), and the empty-hosts case now gets a list on reset. take_list() shares the spare pool with next_segment; NO_NEW_LIST gives a clean deterministic test hook.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review on ba252aa3 (static source inspection; no runtime GPU execution):

  • P2 — Failed replacement leaves hosts empty while Reset/Close still return S_OK, allowing dropped work and premature CPU completion writes (crates/victory-gpu/src/list.rs):
    • In restart, when segment 0 is still held by a queue and take_list() returns None, keep becomes 0 and hosts.drain(0..) leaves list.hosts empty, yet Reset and Close still return S_OK.
    • If the title subsequently records dispatches/draws followed by Write64BitValueBottomOfPipeX on that list, the recorded GPU commands silently no-op (with_state sees no host list), while the bottom-of-pipe completion write can still fire immediately on the CPU, releasing dependent queues onto stale data. Similarly, if restart retains a non-empty prefix and a later next_segment allocation fails during recording, subsequent waits/commands are silently dropped.
    • Suggest propagating the allocation failure from Reset when segment 0 cannot be replaced, and latching mid-recording segment allocation errors to fail Close (keeping incomplete recordings out of queue submission while still preserving the previously submitted queue-held host list).

Review follow-up. When a reset could not replace a held first host list,
the title list was left with none, yet Reset and Close returned S_OK and
a bottom-of-pipe write recorded next was done on the CPU at once (the
path for no host GPU), telling the title the list had run. A wait that
could not start a new host list (memory ran out) was dropped, and what
followed it ran without it.

Now, as D3D12 does, Reset and Close return E_OUTOFMEMORY for a list with
no host list to record into, and its bottom-of-pipe writes are not done.
A wait that finds no host list to go on in closes the one being recorded
and loses the recording until the next reset: nothing more is recorded,
Close returns E_OUTOFMEMORY and a submission of it runs nothing. The
next reset starts again in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@futurepro62

Copy link
Copy Markdown

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head ba252aa (on its base 63bcca4).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@ZeOs360

ZeOs360 commented Nov 26, 2026

Copy link
Copy Markdown
Author

@fuzeofficlal Thanks, both points were real. The first one this PR introduced: before it, that case kept the held list attached and the run stopped at Close ("a host command list did not close"); this PR had made it quiet. Fixed in 1ca6e50:

  • Reset and Close return E_OUTOFMEMORY for a list left with no host list to record into (as D3D12's Close does when recording ran out of memory), and a bottom-of-pipe write on such a list is no longer done on the CPU at once.
  • A wait that cannot start a new host list closes the one being recorded and loses the recording until the next reset: nothing more is recorded, Close returns E_OUTOFMEMORY and a submission of the list runs nothing. One detail: before, the commands after such a wait were not dropped; they went on into the same host list without the wait, so they could run too early. The next reset resets the list's own host lists in place, so it does not need a new one.
  • New test list::tests::a_wait_without_a_new_host_list_loses_the_recording; the two existing tests now expect E_OUTOFMEMORY and check that the write did not land.

cargo test -p victory-gpu: 234 passed; cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features: clean. I updated the description to match.

@ZeOs360
ZeOs360 requested a review from fuzeofficlal November 26, 2026 04:41

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. This fixes list::restart (victory-gpu/src/list.rs) for the case where a held host list cannot be replaced because making a new one fails. On main that path continues and leaves the closed, queue-held host list attached. The title then records into it and closes it again (E_FAIL), a later submission can run it twice, and leave does not get it, so the title list's uploads can be freed while the queue still runs it. The PR cuts the title list's host lists at the first held one that cannot be replaced, hands the last held one to leave, recycles the closed ones and drops the open ones. It also stops a failed wait in wait from letting later commands run without the wait. next_segment now tries SPARE first through take_list. I followed the keep/used indexing in restart and the new lost flag through host_list, segments, close, reset and defer_write, and found no gaps. The three new tests force the failure with a test-only switch and check each path.

One thing for the maintainer to weigh: Reset and Close now return E_OUTOFMEMORY to the title in this state, where main returned S_OK (and then E_FAIL). That is a host-failure path with no console counterpart, and the author reports that runs which run out of memory still stop there, so this is about correctness, not making those runs survive.

CI: passing. Recommending a look, not approving.


Generated by Claude Code

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Tracking a lost flag on List when a host list cannot be replaced on early reset or wait-cut cleanly avoids mutating a still-held host command list or executing commands past a missing wait.
  • cargo test -p victory-gpu list::tests -- --test-threads=1 (RTX 5090 & WARP): 7 passed, 0 failed on both (including all 3 new early-reset/wait-cut tests).
  • 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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed and verified 1ca6e507 on Windows 11 with RTX 5090, WARP (VICTORY_D3D12_WARP=1), and D3D12 Debug Layer (VICTORY_D3D12_DEBUG=1).

Both issues from the earlier review of ba252aa3 are cleanly resolved:

  • When restart (crates/victory-gpu/src/list.rs:291-342) cannot replace a queue-held host list at segment 0, reset (list.rs:555-557) and close (list.rs:525) now return E_OUTOFMEMORY, and defer_write (list.rs:1812-1815) suppresses premature CPU bottom-of-pipe writes when a host GPU is present.
  • When wait (list.rs:220-229) fails to allocate a next segment after recorded commands, closing the current host list and latching lost = true stops further recording (host_list returns None, segments returns empty, close returns E_OUTOFMEMORY) while keeping the closed segments resettable in place on the next reset.
  • Traced open/closed segment states across wait, restart, close, and recycle: only closed segments (k <= used) are reset or recycled, while untouched open trailing segments are dropped.

Verification:

  • cargo xtask policy (191 files ok) and cargo clippy -p victory-gpu --tests -- -D warnings (default and --all-features): clean.
  • RTX 5090 (default): list::tests 7/7 (including all three new tests), hold:: 10/10, queue:: 5/5 passed.
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): list::tests passed 5/5 consecutive runs (35/35) with zero Debug Layer errors.
  • WARP + VICTORY_D3D12_DEBUG=1 (--features diagnostics): list::tests 7/7, hold:: 10/10, queue:: 5/5 passed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants