Repository navigation
Description
Queued fence rewind leaves the shim completion word at its prior value
The queued fence completion shadow assumes that fence values only increase. A queue signal that lowers the desktop fence value can complete while both the shim GetCompletedValue method and its cached completion address remain at the earlier larger value.
This is reproducible using only the source-built startup_fence_values fixture. It does not require title inputs or SDK binaries.
Reproduction
Use the source-built fixture in #3279, commit a5a92ea1c8b36de70c19babebaf054ef639b3c6a. Configure and build normally, then run:
. .\tools\dev.ps1
cmake --build --preset dev --target startup_fence_values --parallel 4
$env:X2W_D3D12_PERMISSIVE = '1'
$env:X2W_D3D12_LIST_NOOP = '1'
$env:X2W_D3D12_RENDER = '1'
$env:X2W_D3D12_DEBUG = '1'
.\out\build\dev\startup_fence_values.exe warp --queue-rewindThe CPU signals establish value 7. The fixture blocks a queue on a different fence, enqueues Signal(3) and a separate queue completion marker, then releases the blocker. After the marker completes, it polls the completion address before calling the shim GetCompletedValue method.
Observed after the focused CPU correction:
cpu Signal(9): desktop=9 method=9 address=9 PASS
cpu Signal(2): desktop=2 method=2 address=2 PASS
cpu Signal(0): desktop=0 method=0 address=0 PASS
cpu Signal(7): desktop=7 method=7 address=7 PASS
queue Signal(3): desktop=3 method=7 address=7 FAIL
fence values: 1 failures
The lower queue signal must not become visible before it executes, and after queue completion the desktop value, method result and completion word should agree.
Cause and limits of a simple fix
fence_reached currently performs an atomic maximum. Merely changing the queued callback to assign its target, or sample the desktop fence, is insufficient: SetEventOnCompletion(3) is already satisfied while the current fence is 7, before the queue executes Signal(3). A separate queue-order completion marker, or equivalent independent mechanism, is needed to publish queued rewinds at the correct time.
There is also a source-visible mixed CPU/queue interleaving: a callback retaining an older larger queue target can run after a successful CPU rewind and overwrite the lower shadow through fence_reached. That interleaving was not induced in this run. The passing CPU fixture has no command queue and does not cover pending callbacks.
The optional diagnostic deliberately returns failure and is excluded from passing CTest registrations. The focused CPU Signal fix does not claim to resolve this queued case. Concurrent producer ordering, callback setup failures and device removal need explicit handling in any general queue fix. The CPU patch leaves the shim completion method as a cached-word read and introduces no new lock there.
Environment
Base 240e0fb9c460f24d51683abe2d4cce2800b136c1 with the focused CPU Signal correction; x64 Debug; Windows 10 Pro 10.0.19045; MSVC 19.43.34810; Microsoft Basic Render Driver (WARP), raw DXGI driver version 2814751014983330; D3D12 debug layer enabled. The queued diagnostic was measured on WARP. The passing CPU correction was separately verified on NVIDIA GeForce RTX 4070 Ti SUPER.
Public D3D12 synchronization guidance explicitly permits fence rewinding: https://learn.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization
Activity