GPU: hand off held command-list resources in Drop instead of non-atomic Release check #3220

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

@⁠fuzeofficlal on GitHub · 2026-11-26 13:33 UTC · original
fuzeofficlal:fix/gpu-list-release-drop-race → main · +192 −20 · 2 files · 1 commits · open

Problem

list_release in crates/victory-gpu/src/list.rs checked whether the command list was about to be destroyed by calling object::refs(this) == 1 before calling object::release_boxed::<List>(this).

When two threads each hold a COM reference to a submitted command list (refs == 2) whose HostList segment is still held on a queue (for example, blocked behind a Wait32BitValueX / Wait64BitValueX wait) and call Release() concurrently:

  1. Both threads observe object::refs(this) == 2 != 1 and skip leave(held, uploads, state).
  2. object::release_boxed::<List>(this) then atomically decrements the reference count 2 -> 1 -> 0 and immediately drops Box<List>.
  3. Upload::drop calls VirtualFree(MEM_RELEASE) and unregisters the list's 0x4a0 upload memory while the queued HostList still references it, and draw::State::drop immediately returns the list's dynamic descriptor slots to the view heap before the queued commands execute.

Fix

  • Implement #[cfg(windows)] Drop for List to perform the leave(held, uploads, state) handoff directly inside Drop::drop(&mut self), matching how Heap and Resource run final-release cleanup.
  • Simplify list_release to object::release_boxed::<List>(this), which already performs the atomic fetch_update(AcqRel, Acquire) transition 1 -> 0 so Drop::drop runs exactly once with exclusive access (get_mut()) on the final releasing thread.
  • Remove the now-unused object::refs helper from crates/victory-gpu/src/object.rs (list_release was 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 calling Release() on a list whose HostList segment is held, asserting that the handoff attaches deferred cleanup to the held segment, keeps the 0x4a0 upload memory mapped with intact contents, and cleans it up on HostList::reset(). Fails immediately on round 0 before this fix.
  • list::tests::concurrent_list_release_while_queued_preserves_upload_until_execution: submits a Wait64BitValueX + CopyMemoryToMemoryX command 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), full victory-gpu WARP suite (248 passed, 0 failed, 1 ignored), workspace clippy --all-targets (default and --all-features) with -D warnings, and xtask repository policy.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 13:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3220) `fuzeofficlal:fix/gpu-list-release-drop-race` → `main` · +192 −20 · 2 files · 1 commits · open ### Problem `list_release` in `crates/victory-gpu/src/list.rs` checked whether the command list was about to be destroyed by calling `object::refs(this) == 1` *before* calling `object::release_boxed::<List>(this)`. When two threads each hold a COM reference to a submitted command list (`refs == 2`) whose `HostList` segment is still held on a queue (for example, blocked behind a `Wait32BitValueX` / `Wait64BitValueX` wait) and call `Release()` concurrently: 1. Both threads observe `object::refs(this) == 2 != 1` and skip `leave(held, uploads, state)`. 2. `object::release_boxed::<List>(this)` then atomically decrements the reference count `2 -> 1 -> 0` and immediately drops `Box<List>`. 3. `Upload::drop` calls `VirtualFree(MEM_RELEASE)` and unregisters the list's `0x4a0` upload memory while the queued `HostList` still references it, and `draw::State::drop` immediately returns the list's dynamic descriptor slots to the view heap before the queued commands execute. ### Fix - Implement `#[cfg(windows)] Drop for List` to perform the `leave(held, uploads, state)` handoff directly inside `Drop::drop(&mut self)`, matching how `Heap` and `Resource` run final-release cleanup. - Simplify `list_release` to `object::release_boxed::<List>(this)`, which already performs the atomic `fetch_update(AcqRel, Acquire)` transition `1 -> 0` so `Drop::drop` runs exactly once with exclusive access (`get_mut()`) on the final releasing thread. - Remove the now-unused `object::refs` helper from `crates/victory-gpu/src/object.rs` (`list_release` was 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 calling `Release()` on a list whose `HostList` segment is held, asserting that the handoff attaches deferred cleanup to the held segment, keeps the `0x4a0` upload memory mapped with intact contents, and cleans it up on `HostList::reset()`. Fails immediately on round 0 before this fix. - `list::tests::concurrent_list_release_while_queued_preserves_upload_until_execution`: submits a `Wait64BitValueX` + `CopyMemoryToMemoryX` command 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`), full `victory-gpu` WARP suite (`248 passed, 0 failed, 1 ignored`), workspace `clippy --all-targets` (default and `--all-features`) with `-D warnings`, and `xtask` repository policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:35:56 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 13:49 UTC · original

WARP verification of head fae44e953026951c4af53a038f4f1413f18ce395 (on origin/main 63bcca4; no earlier verification on this PR)

Environment: Windows 11, no physical GPU used. VICTORY_WARP=1 and VICTORY_D3D12_WARP=1 set 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 flags 0x2 (software).

Commands (-j 4, --locked, --test-threads=1):

  • cargo test -p victory-gpu --features diagnostics --lib concurrent_list_release: 2 passed
  • cargo 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_alive fails at round 0 ("held host list must own the released list's deferred cleanup"); concurrent_list_release_while_queued_preserves_upload_until_execution still 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 List is sound (runs once, after the atomic final release; get_mut needs no lock) and object::refs has no other users. No correctness concern found.

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

**@⁠oni-swr** on GitHub · 2026-11-26 13:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3220#issuecomment-7193889655) **WARP verification of head `fae44e953026951c4af53a038f4f1413f18ce395`** (on origin/main `63bcca4`; no earlier verification on this PR) Environment: Windows 11, no physical GPU used. `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1` set 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 flags `0x2` (software). Commands (`-j 4`, `--locked`, `--test-threads=1`): - `cargo test -p victory-gpu --features diagnostics --lib concurrent_list_release`: 2 passed - `cargo 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_alive` fails at round 0 ("held host list must own the released list's deferred cleanup"); `concurrent_list_release_while_queued_preserves_upload_until_execution` still 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 List` is sound (runs once, after the atomic final release; `get_mut` needs no lock) and `object::refs` has no other users. No correctness concern found. AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
Author
Owner

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

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: 6/6 passed (including concurrent_list_release_while_held_keeps_upload_memory_alive and concurrent_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 Drop instead of a racy non-atomic Release check.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 13:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3220#pullrequestreview-6075275805) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: 6/6 passed (including `concurrent_list_release_while_held_keeps_upload_memory_alive` and `concurrent_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 `Drop` instead of a racy non-atomic `Release` check. 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/3220/head:github-bot/gh-3220'
git switch 'github-bot/gh-3220'

Merge

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