GPU: hand off held command-list resources in Drop instead of non-atomic Release check #3218
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3220"
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 fuzeofficlal on 2026-11-26T13:33:54Z.
Problem
list_releaseincrates/victory-gpu/src/list.rschecked whether the command list was about to be destroyed by callingobject::refs(this) == 1before callingobject::release_boxed::<List>(this).When two threads each hold a COM reference to a submitted command list (
refs == 2) whoseHostListsegment is still held on a queue (for example, blocked behind aWait32BitValueX/Wait64BitValueXwait) and callRelease()concurrently:object::refs(this) == 2 != 1and skipleave(held, uploads, state).object::release_boxed::<List>(this)then atomically decrements the reference count2 -> 1 -> 0and immediately dropsBox<List>.Upload::dropcallsVirtualFree(MEM_RELEASE)and unregisters the list's0x4a0upload memory while the queuedHostListstill references it, anddraw::State::dropimmediately returns the list's dynamic descriptor slots to the view heap before the queued commands execute.Fix
#[cfg(windows)] Drop for Listto perform theleave(held, uploads, state)handoff directly insideDrop::drop(&mut self), matching howHeapandResourcerun final-release cleanup.list_releasetoobject::release_boxed::<List>(this), which already performs the atomicfetch_update(AcqRel, Acquire)transition1 -> 0soDrop::dropruns exactly once with exclusive access (get_mut()) on the final releasing thread.object::refshelper fromcrates/victory-gpu/src/object.rs(list_releasewas its only caller).Verification
Added two deterministic multi-threaded regression tests in
crates/victory-gpu/src/list.rs:list::tests::concurrent_list_release_while_held_keeps_upload_memory_alive: races two threads callingRelease()on a list whoseHostListsegment is held, asserting that the handoff attaches deferred cleanup to the held segment, keeps the0x4a0upload memory mapped with intact contents, and cleans it up onHostList::reset(). Fails immediately on round 0 before this fix.list::tests::concurrent_list_release_while_queued_preserves_upload_until_execution: submits aWait64BitValueX+CopyMemoryToMemoryXcommand list to a queue, concurrently releases it from two threads while held, then unblocks the wait and verifies the full 64-byte payload arrives intact.All checks pass on both hardware D3D12 and WARP (including with
VICTORY_D3D12_DEBUG=1 --features diagnostics), fullvictory-gpuWARP suite (248 passed, 0 failed, 1 ignored), workspaceclippy --all-targets(default and--all-features) with-D warnings, andxtaskrepository policy.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:51:24Z.
Review: APPROVED
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib list:: -- --test-threads=1: 6/6 passed (includingconcurrent_list_release_while_held_keeps_upload_memory_aliveandconcurrent_list_release_while_queued_preserves_upload_until_execution).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly hands off held command-list resources in
Dropinstead of a racy non-atomicReleasecheck.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T13:49:34Z.
WARP verification of head
fae44e953026951c4af53a038f4f1413f18ce395(on origin/main63bcca4; no earlier verification on this PR)Environment: Windows 11, no physical GPU used.
VICTORY_WARP=1andVICTORY_D3D12_WARP=1set in every process, with--features diagnostics(the host only honours the WARP switch in that build). A local probe (not committed) printed and asserted the host device's adapter:Microsoft Basic Render Driver, DXGI flags0x2(software).Commands (
-j 4,--locked,--test-threads=1):cargo test -p victory-gpu --features diagnostics --lib concurrent_list_release: 2 passedcargo test -p victory-gpu --features diagnostics --lib: 248 passed, 0 failed, 1 ignored (main: 246 passed, 0 failed, 1 ignored)Control (main's
list.rs+ this PR's two tests only):concurrent_list_release_while_held_keeps_upload_memory_alivefails at round 0 ("held host list must own the released list's deferred cleanup");concurrent_list_release_while_queued_preserves_upload_until_executionstill passes on main under WARP, so only the first test discriminates here. The second is still a useful end-to-end check but does not prove the fix on this adapter.Diff review: moving the hand-off into
Drop for Listis sound (runs once, after the atomic final release;get_mutneeds no lock) andobject::refshas no other users. No correctness concern found.AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
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.