GPU: a list's state prelude is made the first time it has work to do #3234

Open
Luislariosss wants to merge 2 commits from upstream-pr/3236 into main
Luislariosss commented 2026-11-26 14:07:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-26T14:07:55Z.


Problem

Every HostList made a D3D12CommandAllocator and a direct command list for its state prelude when the list was created. The prelude only runs when a list has a depth twin or a state transition to record before its work, and most lists never do: the pair was made and closed for nothing, for every list the title creates.

Change

crates/victory-gpu/src/host.rs: the prelude is a OnceLock, made by HostList::prelude the first time it has work to do. Same allocator and list type, same thread (the submitting one). If creation fails it goes to fail — see Failure path below.

Failure path

On main, a failed CreateCommandAllocator/CreateCommandList for the prelude happens inside new_list() and comes back as an Err the callers degrade through: next_segment returns None, restart skips the replacement, and the title's list is handed out without a host backing (commands recorded into it are no-ops, logged with a warning). With this change the same failure happens at the first submission that needs the prelude, inside get_or_init, and calls fail(), which ends the run — the same thing a failed prelude recording already does on main, because a list with a state or twin to move cannot run without its prelude.

Lists that never move a state or a twin never reach get_or_init at all; that is most of them, and it is why this change halves what new_list() allocates. The creation is now most likely to matter exactly where this change helps most, on a low-RAM machine near the commit limit, so the fail message names memory pressure as the likely cause.

Measurement

Ryzen 5 9600X, RX 9060 XT 16 GB, 15.2 GB RAM, Windows. Same branch and runner, cold cache; only this commit differs between the two runs (r39 before, r42 after).

commit (whole system) r39 before r42 after
at ~100 s 42.1 GB 39.6 GB
at ~160 s 44.6 GB 42.9 GB
at ~280 s 44.8 GB 43.1 GB
end (895-904 s) 45.6 GB, 904 s alive 44.6 GB, 900 s alive

Free RAM at the end: 1,084 MB before, 1,269 MB after. Loose windows still go idle (642 windows, 3.0 GB reclaimed in r42 against 720 windows, 3.4 GB in r39), so the eviction keeps working with the prelude made later. Zero allocation errors, exceptions or device removals in either run.

Free RAM is noisy because of standby; commit is the number that matters for the pagefile.

Tests

cargo test -p victory-gpu: 231 passed, 1 ignored (232). With --all-features: 246 passed, 1 ignored (247). Clippy clean with --all-targets in both. cargo build -p victory --locked clean.

Risk

prelude() is also touched by #3162 (a pool per use) and #2908 (parallel recording). This change is orthogonal — the first pair is still made on demand — but whichever lands second will need a small rebase.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5511511590 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3236). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-26T14:07:55Z. --- ### Problem Every `HostList` made a `D3D12CommandAllocator` and a direct command list for its state prelude when the list was created. The prelude only runs when a list has a depth twin or a state transition to record before its work, and most lists never do: the pair was made and closed for nothing, for every list the title creates. ### Change `crates/victory-gpu/src/host.rs`: the prelude is a `OnceLock`, made by `HostList::prelude` the first time it has work to do. Same allocator and list type, same thread (the submitting one). If creation fails it goes to `fail` — see Failure path below. ### Failure path On `main`, a failed `CreateCommandAllocator`/`CreateCommandList` for the prelude happens inside `new_list()` and comes back as an `Err` the callers degrade through: `next_segment` returns `None`, `restart` skips the replacement, and the title's list is handed out without a host backing (commands recorded into it are no-ops, logged with a warning). With this change the same failure happens at the first submission that needs the prelude, inside `get_or_init`, and calls `fail()`, which ends the run — the same thing a failed prelude *recording* already does on `main`, because a list with a state or twin to move cannot run without its prelude. Lists that never move a state or a twin never reach `get_or_init` at all; that is most of them, and it is why this change halves what `new_list()` allocates. The creation is now most likely to matter exactly where this change helps most, on a low-RAM machine near the commit limit, so the `fail` message names memory pressure as the likely cause. ### Measurement Ryzen 5 9600X, RX 9060 XT 16 GB, 15.2 GB RAM, Windows. Same branch and runner, cold cache; only this commit differs between the two runs (r39 before, r42 after). | commit (whole system) | r39 before | r42 after | |---|---|---| | at ~100 s | 42.1 GB | 39.6 GB | | at ~160 s | 44.6 GB | 42.9 GB | | at ~280 s | 44.8 GB | 43.1 GB | | end (895-904 s) | 45.6 GB, 904 s alive | 44.6 GB, 900 s alive | Free RAM at the end: 1,084 MB before, 1,269 MB after. Loose windows still go idle (642 windows, 3.0 GB reclaimed in r42 against 720 windows, 3.4 GB in r39), so the eviction keeps working with the prelude made later. Zero allocation errors, exceptions or device removals in either run. Free RAM is noisy because of standby; commit is the number that matters for the pagefile. ### Tests `cargo test -p victory-gpu`: 231 passed, 1 ignored (232). With `--all-features`: 246 passed, 1 ignored (247). Clippy clean with `--all-targets` in both. `cargo build -p victory --locked` clean. ### Risk `prelude()` is also touched by #3162 (a pool per use) and #2908 (parallel recording). This change is orthogonal — the first pair is still made on demand — but whichever lands second will need a small rebase.
AurumCarlos commented 2026-11-26 14:18:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T14:18:24Z.

Review: COMMENTED


Nice, small change, and the commit numbers are a good way to show it. The OnceLock is only touched from prelude() on the submitting thread, host() must exist for a HostList to exist, and spare lists keep their prelude once made, so reuse through SPARE still benefits. I agree with the note about #3162 needing a rebase.

One behaviour change worth stating, because "no behaviour change" isn't quite true for the failure path. On main, a failed CreateCommandAllocator/CreateCommandList for the prelude happens inside new_list() and comes back as an Err. Its callers degrade: next_segment returns None, restart skips the replacement (_ => continue), and list creation fails back to the title. With this change, the same failure happens at submission inside get_or_init and goes to fail(..), which aborts the process unless ON_FAILURE is set.

The PR targets exactly the near-full-commit situation where that creation is most likely to fail, so it moves an out-of-memory from a point the title can survive to one it can't. Recording the prelude already calls fail on error, so this may well be acceptable (a list that needs a prelude can't run without one). But the description should say so, and the fail message could name memory pressure as the likely cause, so a report from a low-RAM machine is easy to read.

<!-- greyfinch-sync:Marvisak/VIctory:review:6075673684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3236#pullrequestreview-6075673684). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T14:18:24Z. **Review:** COMMENTED --- Nice, small change, and the commit numbers are a good way to show it. The `OnceLock` is only touched from `prelude()` on the submitting thread, `host()` must exist for a `HostList` to exist, and spare lists keep their prelude once made, so reuse through `SPARE` still benefits. I agree with the note about #3162 needing a rebase. One behaviour change worth stating, because "no behaviour change" isn't quite true for the failure path. On `main`, a failed `CreateCommandAllocator`/`CreateCommandList` for the prelude happens inside `new_list()` and comes back as an `Err`. Its callers degrade: `next_segment` returns `None`, `restart` skips the replacement (`_ => continue`), and list creation fails back to the title. With this change, the same failure happens at submission inside `get_or_init` and goes to `fail(..)`, which aborts the process unless `ON_FAILURE` is set. The PR targets exactly the near-full-commit situation where that creation is most likely to fail, so it moves an out-of-memory from a point the title can survive to one it can't. Recording the prelude already calls `fail` on error, so this may well be acceptable (a list that needs a prelude can't run without one). But the description should say so, and the `fail` message could name memory pressure as the likely cause, so a report from a low-RAM machine is easy to read.
oni-swr commented 2026-11-26 16:05:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T15:03:50Z.


WARP verification at head 432b0069 (main 63bcca43 as control).

  • This PR adds no tests, so there is no new test to run and no failing control to show. It defers creating the state prelude's allocator and list (OnceLock).
  • Full victory-gpu lib suite on the head: 246 passed, 1 ignored, in 2 of 2 runs. That matches main (246 passed, 3 of 3 runs), so nothing regressed on WARP.
  • This does not show the saving the PR measures, and WARP does not exercise the lazily created prelude with real work. A test that counts the allocators and lists a list makes before it has work would pin the behaviour.

Software adapter (WARP, Microsoft Basic Render Driver), not a physical GPU. Synthetic tests only, no game files. Run with VICTORY_WARP=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics -j 4 and dxil.dll available. Test report only, no code changes.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195728023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3236#issuecomment-7195728023). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T15:03:50Z. --- WARP verification at head `432b0069` (main `63bcca43` as control). - This PR adds no tests, so there is no new test to run and no failing control to show. It defers creating the state prelude's allocator and list (`OnceLock`). - Full victory-gpu lib suite on the head: 246 passed, 1 ignored, in 2 of 2 runs. That matches main (246 passed, 3 of 3 runs), so nothing regressed on WARP. - This does not show the saving the PR measures, and WARP does not exercise the lazily created prelude with real work. A test that counts the allocators and lists a list makes before it has work would pin the behaviour. Software adapter (WARP, Microsoft Basic Render Driver), not a physical GPU. Synthetic tests only, no game files. Run with `VICTORY_WARP=1 VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics -j 4` and dxil.dll available. Test report only, no code changes. AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
Dukestar69 commented 2026-11-26 16:11:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T16:11:52Z.

Review: APPROVED


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

  • Lazily initializing HostList::prelude via OnceLock on first prelude work avoids allocating a D3D12 command allocator and command list for lists that never need state transitions or depth-twin preludes.
  • cargo test -p victory-gpu --lib host::tests:: -- --test-threads=1 (RTX 5090): 12 passed, 0 failed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1 (RTX 5090): 20 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:6077326142 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3236#pullrequestreview-6077326142). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T16:11:52Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Lazily initializing `HostList::prelude` via `OnceLock` on first prelude work avoids allocating a D3D12 command allocator and command list for lists that never need state transitions or depth-twin preludes. - `cargo test -p victory-gpu --lib host::tests:: -- --test-threads=1` (RTX 5090): 12 passed, 0 failed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1` (RTX 5090): 20 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).
Luislariosss commented 2026-11-26 20:29:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-26T20:29:12Z.


Both points taken:

  • The description now states the failure path (a new "Failure path" section), including the precise degradation on main: a failed creation comes back from new_list as an Err, next_segment returns None, restart skips the replacement, and the title's list is handed out without a host backing (commands recorded into it are no-ops, logged with a warning) — a degradation, not a failure the title sees.
  • The fail message now names the likely cause, in one clause: "a host state prelude was not made ({e}): likely memory pressure".

Pushed as 1371135. Thanks for the careful read — the next_segment/restart degradation is exactly the kind of detail that was hiding under "no behaviour change".

<!-- greyfinch-sync:Marvisak/VIctory:comment:7202739463 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3236#issuecomment-7202739463). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-26T20:29:12Z. --- Both points taken: - The description now states the failure path (a new "Failure path" section), including the precise degradation on `main`: a failed creation comes back from `new_list` as an `Err`, `next_segment` returns `None`, `restart` skips the replacement, and the title's list is handed out without a host backing (commands recorded into it are no-ops, logged with a warning) — a degradation, not a failure the title sees. - The `fail` message now names the likely cause, in one clause: "a host state prelude was not made ({e}): likely memory pressure". Pushed as 1371135. Thanks for the careful read — the `next_segment`/`restart` degradation is exactly the kind of detail that was hiding under "no behaviour change".
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/3236:upstream-pr/3236'
git switch 'upstream-pr/3236'

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/3236'
git switch 'upstream-pr/3236'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3236'
git switch 'upstream-pr/3236'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3236'
git switch 'main'
git merge --squash 'upstream-pr/3236'
git switch 'main'
git merge --ff-only 'upstream-pr/3236'
git switch 'main'
git merge 'upstream-pr/3236'
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!3234
No description provided.