metal, gpu: support non-monotonic and rewound ID3D12Fence signals over MTLSharedEvent #472
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T21:42:50Z.
Refs #456, #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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T21:42:51Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T21:43:01Z.
Claimed by @Sheffy007. Open a draft pull request with
Refs #472in its description within 24 hours, or the claim expires.