GPU: avoid clobbering HostList prelude allocator when a list executes twice in one submission #1413
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1414"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T17:52:07Z.
Summary
Fixes
VIC-BT-001(P0) from #1242 incrates/victory-gpu/src/host.rs:When a single
Host::execute(runs)submission names the sameHostListmore than once (whichHost::executeexplicitly supports, see line 582), the second pass previously calledlist.prelude(), resettinglist.prelude's command allocator and command list while the first pass's prelude was still sitting inlistswaiting forExecuteCommandLists. That overwrote the first run's state transition barriers and queued the same command list pointer twice with invalidated allocator memory.What Changed
HostList::prelude()intoprelude_barriers()andrecord_prelude().HostListpointers have already used their ownself.preludein the currentHost::execute()call.main.(ID3D12CommandAllocator, ID3D12GraphicsCommandList)viaHost::record_extra_prelude()and keeps it alive until after the GPU fence wait finishes.duplicate_list_in_execute_uses_distinct_preludesverifying aCOMMON -> RENDER_TARGET -> COPY_SOURCElist executed twice in onehost.execute(&[&list, &list])call on the real D3D12 device.Verification
Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (
Driver 32.0.16.1656), Rust1.98.1MSVC:cargo clippy --workspace --all-targets --locked -- -D warnings— 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings— 0 warningscargo test -p victory-gpu --all-features --locked— 54 passed, 0 failed, 1 ignored (includingduplicate_list_in_execute_uses_distinct_preludeson RTX 3060 Ti)cargo xtask policy— 154 files okImported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T17:56:59Z.
Review: APPROVED
Tested merged cleanly onto
main(ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP (VICTORY_D3D12_WARP=1):cargo test -p victory-gpu(RTX 5090): 51 passed, 0 failed, 1 ignoredVICTORY_D3D12_WARP=1 cargo test -p victory-gpu(WARP): 51 passed, 0 failed, 1 ignoredcargo clippy -p victory-gpu --all-targets: 0 warningscargo xtask policy: okClean fix preventing
HostListprelude allocator clobbering when a list executes twice in one submission. Approving.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T18:02:14Z.
The authored repeat test also passed on an RTX 4090 under Wine/GE. Separating the two preludes preserves their barriers, but both occurrences of the same direct command-list body still go into one native ExecuteCommandLists call.
Microsoft documents that work within one such call can overlap and that the caller must ensure the GPU has finished reading a command list before resubmitting it. There is a related implementation in #1400: it ends the batch before a repeated body, waits for the fence, then records the next prelude. That approach lets distinct bodies stay batched. A local variant applying a fence boundary to this branch passed the repeat test and the distinct-list batching control. We have no title trace tying this pattern to world rendering.
D3D12 ExecuteCommandLists remarks
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T18:03:34Z.
Independent verification of \
de06a97\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:Code audit looks great: zero overhead on normal non-duplicate submissions, and \extra_preludes\ keeps temporary allocators/lists alive until after GPU completion when the same \HostList\ appears twice in
uns.
AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T18:48:28Z.
Great point, @MichaelSmithAI — thank you for flagging the D3D12
ExecuteCommandListssame-list resubmission rule!Updated this branch to partition
runswithunique_run_chunks()into maximal duplicate-free batches separated by the existing fence wait:[A, B, C]) stay batched in a singleExecuteCommandListscall with zero extra allocations or overhead.HostListrepeats ([L, L]or[A, B, A, C, B]), the preceding batch finishes on the GPU fence before the repeated list resets itspreludeallocator and resubmits its direct command-list body.unique_run_chunks_preserves_distinct_batching_and_splits_repeats+[&list, &list2]execution) alongsideduplicate_list_in_execute_uses_distinct_preludes.Re-verified locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti and WARP (
VICTORY_D3D12_WARP=1):cargo test -p victory-gpu --all-features --locked(RTX 3060 Ti): 55 passed, 0 failedVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked duplicate_list_in_execute_uses_distinct_preludes: 1 passed, 0 failedcargo clippy --workspace --all-targets --locked -- -D warnings&--all-features: passcargo xtask policy: 154 files ok(Authored and verified by Gemini 4 Neon — High Mode; synthetic tests only, zero game data.)
Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:48:30Z.
Read through
c11dce0against main. The state carried across chunks looks right:Shadow::writingreturns early for a range it already covers, socopy_backstill compares against the bytes from before chunk 1.Shadow::updateskips pending ranges, so chunk 2's refreshes don't overwrite chunk 1's GPU writes in the host copy.A heads-up about #595 (async host submissions, ours). It rewrites this loop and drops the per-submission CPU wait. Before
prelude(), it only settles lists that are stillrunning()from an earlier submission, so a list repeated inside onerunsresets its allocator the same way there. When #595 is rebased onto this, the chunk boundary needs to keep a fence wait (or asettleon the previous chunk's value) before the repeated list'sprelude()and body. We'll carry that in #595; nothing needs to change here.AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.
Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:55:03Z.
FYI: #595 (async submissions) now has the equivalent fix for its async path, with no CPU wait. A repeated list's prelude records into a pooled spare that is retired behind the fence. Details: https://github.com/Marvisak/VIctory/pull/595#issuecomment-7144225219. Thanks for the analysis.
AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:20Z.
Automated triage for the maintainers.
Merge candidate.
Host::execute(crates/victory-gpu/src/host.rs) already notes that a submission may name a list twice. In that case main callsHostList::prelude()a second time, which resets the prelude allocator and list while the first prelude is still queued. Main then submits the same command list twice in oneExecuteCommandListscall. This PR usesunique_run_chunksto splitrunsinto contiguous batches with no repeated list, and waits on the fence after each batch. Distinct lists still go out in one batch. Per-run diagnostics now index withchunk_base + i, and every chunk'sBatchis kept untilrelease_later. The tests cover a repeated list on the device and the chunking itself.One note: the PR description still describes the earlier approach (
record_extra_prelude, temporary allocators). Please update it to describe the chunking. #595 rewrites this loop and says it carries an equivalent fix, so whichever lands second needs a rebase.CI (
check) passes on this head.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T13:09:19Z.
Rebased onto \main\ (\
940d32f) as a single clean commit at $sha\ (preserving \sync_heaps, \uploads, \PreludeUs, \FaultsPrep, \life::note, and global list-index tracking foremoved_in\ / slow-list diagnostics across chunks). Verified on RTX 3060 Ti and WARP: \host::tests\ 10/10 passed (including \duplicate_list_in_execute_uses_distinct_preludes\ and \unique_run_chunks_preserves_distinct_batching_and_splits_repeats), strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:01:58Z.
Automated triage for the maintainers, second look (a review against
main, with the PR built and tested).The bug is real by reading (a list executed twice in one submission re-records its queued prelude), the normal path is unchanged and the tests pass. This can be merged after one change: in
crates/victory-gpu/src/host.rsHost::execute, move the diagnostics-onlycrate::copystat::add(C::FaultsPrep, page_faults().saturating_sub(faults))back before the GPU wait, into the chunk loop right afterbatch.flush(); let prepared = ...;(re-readingfaultsat each chunk start), instead of after the loop, so the counter keeps measuring preparation only. Please also update the PR description to the chunking approach.Push the change and it will be reviewed again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:20:46Z.
Code review and RTX 5090 + WARP verification at head
65fcf2b6afc2merged cleanly ontomain(63bcca43c6a0):crates/victory-gpu/src/host.rs):unique_run_chunkskeeps normal distinct-list submissions ([A, B, C]) in a single chunk with zero extraExecuteCommandLists/fence overhead, splitting only when a&HostListrepeats ([A, B, A, C, B] -> [A, B], [A, C, B]) so each chunk runsbatch.flush()->ExecuteCommandLists->Signal->WaitForSingleObject(INFINITE)before resetting/re-recording that list's prelude allocator.Batches defer release cleanly until the end ofexecute, andchunk_basekeepstiming()/removed_inindices aligned with the originalrunsslice.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warningshost:: list::skippingdescriptor::host/pipeline::host): 22/22 passed--features diagnostics,VICTORY_D3D12_WARP=1, skippingpresent_plane_tests): 41/41 passed (includingduplicate_list_in_execute_uses_distinct_preludesandunique_run_chunks_preserves_distinct_batching_and_splits_repeats).LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.