Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3280
Refs #3279
Summary
Fixes queued and CPU fence rewinds in
src/startup_stubs/d3d12_xs_device.cppso the shim'sGetCompletedValue()(slot 8) and polled completion word (slot 12) stay synchronized with the desktopID3D12Fencewithout adding any lock to the read path:queue_signal_and_track): On async-trackedCommandQueue::Signal(fence, value)calls, pairs the guestqueue->Signal(desktop_fence, value)under a per-queueSRWLOCK(queue_order_lock) with a signal on a strictly monotonic privatequeue_order_fence. The threadpool callback waits onqueue_order_fence->SetEventOnCompletion(order_seq, event), so a queued rewind below the fence's current value never fires early while the queue is blocked.fence_lock(publish_fence_completed/fence_signal): Both CPUfence_signaland asyncsignal_reachedcallbacks acquire the per-fenceSRWLOCK(fence_lock), read the actualID3D12Fence::GetCompletedValue(), and publish it viaInterlockedExchange64(&fence->own().completed, ...). This handles arbitrary rewinds (including 64-bit values and device removalUINT64_MAX), prevents two concurrent CPU callers from overwriting a newer value with a stale one, and prevents delayed queue callbacks from overwriting a newer CPU rewind.fence_completed_value(slot 8) andfence_completed_address(slot 12) remain lock-free reads ofWrapperOwn::completed.d3d12_xs.dllviaGetModuleHandleExW/FreeLibraryWhenCallbackReturnsand arm the threadpool wait beforeSetEventOnCompletion.Tests
Added
tests/startup_fence_rewind.cppandtests/cmake/startup_fence_rewind.cmake(registered inCMakePresets.jsonprpreset asstartup_fence_rewind_warp), covering:Signal()rewinds including 64-bit values (0x100000009 -> 9 -> 2 -> 0 -> 7) on both slot 8 and slot 12.7,Wait(gate, 1),Signal(target, 3),Signal(marker, 1)): verifiestargetstays7while blocked, then reaches3on both the polled completion word andGetCompletedValue()after unblock.Signal(target, 11)).queued Signal(20), thenCPU Signal(4)).Signal()calls from two threads.Verification
Environment: Windows 11 x64 (
10.0.26300.9974), MSVC19.44.35230, Windows SDK / DXC10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2140), Microsoft Basic Render Driver (10.0.26100.9818), D3D12 debug layer enabled (X2W_D3D12_DEBUG=1).Commit under test:
6668d4c9.dev: 4/4 passed (0 skipped), WARP + RTX 5080.release: 4/4 passed (0 skipped), WARP + RTX 5080.order_fence->SetEventOnCompletion(order_seq, event)withdesktop_fence->SetEventOnCompletion(value, event)causedstartup_fence_rewind_warpto fail (queue Signal(3) after unblock: method=7 address=7); after revertingsrc/, 4/4 passed again.No game files, dumps, or private paths included.