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

Open
github-bot wants to merge 1 commit from github-bot/gh-3236 into main AGit
Owner

@⁠Luislariosss on GitHub · 2026-11-26 14:07 UTC · original
Luislariosss:perf/lazy-prelude → main · +28 −13 · 1 files · 1 commits · open

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), same error path (fail) if creation fails. No API or behaviour change.

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.

**@⁠Luislariosss** on GitHub · 2026-11-26 14:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3236) `Luislariosss:perf/lazy-prelude` → `main` · +28 −13 · 1 files · 1 commits · open ### 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), same error path (`fail`) if creation fails. No API or behaviour change. ### 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.
Every host list made an allocator and a command list for its prelude up front, and most lists never touch a depth twin or a state: one pair fewer for each of them.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:12:09 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 14:18 UTC · original · reviewed

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.

**@⁠AurumCarlos** on GitHub · 2026-11-26 14:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3236#pullrequestreview-6075673684) · **reviewed** 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.
Author
Owner

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

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).

**@⁠oni-swr** on GitHub · 2026-11-26 15:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3236#issuecomment-7195728023) 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).
Author
Owner

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

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 16:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3236#pullrequestreview-6077326142) · **approved these changes** 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).
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/3236/head:github-bot/gh-3236'
git switch 'github-bot/gh-3236'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3236'
git switch 'github-bot/gh-3236'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3236'
git switch 'github-bot/gh-3236'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3236'
git switch 'main'
git merge --squash 'github-bot/gh-3236'
git switch 'main'
git merge --ff-only 'github-bot/gh-3236'
git switch 'main'
git merge 'github-bot/gh-3236'
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!3236
No description provided.