metal, gpu: support non-monotonic and rewound ID3D12Fence signals over MTLSharedEvent #476
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS#476
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Sheffy007 on GitHub · 2026-11-27 21:42 UTC · original
Refs #460, #258
Problem
ID3D12Fence::SignalandID3D12CommandQueue::Signalallow setting a fence to anyu64value, including lowering/rewinding a fence (such as resetting a reusable binary fence to0before signalling1again) or repeating a value. On macOS, however,victory-metalmaps a fence directly onto a singleMTLSharedEventvalue:MTLSharedEvent.signaledValueis strictly monotonic in Metal:setSignaledValue(v)andencodeSignalEvent(_, v)silently ignore anyv <= signaledValue.1once and the title resets it viaID3D12Fence::Signal(0),MTLSharedEvent.signaledValueremains1. Within 1 ms (glue::refresh->Title::completed->fence::raise) or on the nextGetCompletedValue()/SetEventOnCompletion(1, ...), the stale1overwrites the fence back to1and fires completion events while new GPU work is still in flight, andID3D12CommandQueue::Wait(fence, 1)skips waiting altogether.ID3D12CommandQueue::Signal(fence, 1)calls encodeencodeSignalEvent(_, 1)on an event already at1, becoming GPU no-ops instead of waiting for the command buffer to finish.Title::fence_valueclampscompleted(&f).max(initial)(preventing lowering belowinitial), andfence::completed/set_event_on_completionpoll outside thewaiterslock before callingraise, allowing a concurrentID3D12Fence::Signal(0)to be clobbered by a stale poll result or ignoring a GPU-sideQueue::Signal(fence, 0).Proposed Fix
MTLSharedEventhigh-water ticket alongside the logical D3D12(epoch, current)value and in-flight(raw_ticket, d3d_value)GPU signals insidevictory_metal::metal::FencesoMTLSharedEventalways advances monotonically whilecompleted,signal,wait,encodeWaitForEvent, andencodeSignalEventobserve exact D3D12 values across rewinds and repeated signals.crates/victory-gpu/src/fence.rsupdates by fence epoch under thewaiterslock and remove the.max(initial)clamp inTitle::fence_valueso neither stale polls norinitialoverwrite a CPU or GPU rewind.Signal(0)->Queue::Signal(1)cycles,Queue::Waitacross rewinds,SetEventOnCompletion, and GPU-side fence rewinds.@Sheffy007 on GitHub · 2026-11-27 21:42 UTC · original
/claim
@github-actions[bot] on GitHub · 2026-11-27 21:43 UTC · original
Claimed by @Sheffy007. Open a draft pull request with
Refs #472in its description within 24 hours, or the claim expires.github-bot referenced this issue2026-11-27 21:59:38 +00:00