GPU: keep fences alive while queues wait on them #3227
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3227
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3227"
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?
@fuzeofficlal on GitHub · 2026-11-26 13:45 UTC · original
fuzeofficlal:fix/gpu-fence-wait-lifetime→main· +340 −30 · 2 files · 1 commits · openSummary
Fix a use-after-free in
ID3D12CommandQueue::Waitwhen a title releases its own fence reference while a command queue still has a pendingItem::FenceWaitfor that fence.Under D3D12,
ID3D12CommandQueue::Waitholds an internal reference on the fence until the wait is satisfied, so titles can legally release the fence immediately after queuingWait(for example after pairingqueue_a->Signal(fence, v)withqueue_b->Wait(fence, v), or when satisfying the fence later via a GPU bottom-of-pipe write tofence->GetGPUVirtualAddress()).Previously,
queue::signalretained the fence withfence::keepand released it when signaled, butqueue::waitstored rawfence as usizeinsideItem::FenceWaitwithout callingfence::keep, andHeld::pumppoppedItem::FenceWaitwithout releasing a reference. Once the title released the fence (and any queuedSignalreleased its own reference), subsequentFenceWaitpolls inHeld::pumpor the held-work timer dereferenced freedFencememory.Changes
crates/victory-gpu/src/hold.rs: ParameterizeItem<S, F = usize>,Held<S, F = usize>, andWorld<'a, S, F = usize>over the fence token typeFsoHeld::pumppasses&Ftoworld.fence, movesFintoworld.signal, and dropsFwhen popping a satisfiedItem::FenceWait.crates/victory-gpu/src/queue.rs:CopyRAIIKeptFenceguard (#[cfg(windows)]) that callsfence::keepon construction andfence::let_goonDrop, and use it as the fence token type inqueue::Holdingfor bothItem::SignalandItem::FenceWait. Every completion path andHelddrop now balanceskeep/let_goautomatically.E_INVALIDARG) and checkfence::value(fence) < valueunder theheld()lock inqueue::waitbefore retaining and enqueuingItem::FenceWait.hold::tests::fence_tokens_are_dropped_once_on_completion_and_on_held_drop: verifies fence tokens remain alive while blocked and are dropped exactly once on completion or when a non-emptyHeldis dropped.queue::tests::cross_queue_fence_wait_keeps_fence_alive_until_satisfied: verifies cross-queueSignal+Waitwith immediate titleRelease, observer refcount balance across pending polls / CPUSignal/ already-satisfiedWait/ null-fenceE_INVALIDARG, andWaitholding the sole remaining reference until satisfied by a GPU bottom-of-pipe write to the fence GPU virtual address.Verification
queued FenceWait must hold its own reference: left 2, right 3).cargo test --locked -p victory-gpu --libpassed on RTX 5090 (default: 231 passed), RTX 5090 +--features diagnostics+VICTORY_D3D12_DEBUG=1(--test-threads=1: 245 passed), and WARP +--features diagnostics+VICTORY_D3D12_DEBUG=1(--test-threads=1: 245 passed).cargo clippy --workspace --all-targets --locked -- -D warningsand--all-featurespassed with 0 warnings.git diff --check,rustfmt --edition 2024 --checkon modified hunks, andcargo run --locked -p xtask -- policy(191 files ok) all passed.@Dukestar69 on GitHub · 2026-11-26 13:48 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib hold:: -- --test-threads=1: 11/11 passed (includingfence_tokens_are_dropped_once_on_completion_and_on_held_drop).cargo test -p victory-gpu --lib queue:: -- --test-threads=1: 6/6 passed (includingcross_queue_fence_wait_keeps_fence_alive_until_satisfied);fence::: 2/2 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly keeps fences alive while queues are waiting on them and drops fence tokens cleanly on completion or held-queue drop.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 14:04 UTC · original
WARP test report: head
8ef3f17d(parent and control base: main63bcca43)VICTORY_WARP=1,VICTORY_D3D12_WARP=1,cargo test -j 4 -p victory-gpu --features diagnostics --lib, rustc 1.98.1, Windows 11,dxil.dllfrom the Windows SDK 10.0.26100.0.hold::tests::fence_tokens_are_dropped_once_on_completion_and_on_held_dropandqueue::tests::cross_queue_fence_wait_keeps_fence_alive_until_satisfiedboth pass. The wholevictory-gpulib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored.queue.rscode with this PR's test module.cross_queue_fence_wait_keeps_fence_alive_until_satisfiedfails:queued FenceWait must hold its own reference(left 2, right 3).holdtest has no control. It uses the PR's newHeld<S, F>andItem<S, F>types, which main doesn't have, so it can't be built against main. Only the Wait/Signal reference counting inqueue.rswas exercised, with synthetic fences, queues and buffers. No physical GPU and no title.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.