Repository navigation
Conversation
When ID3D12Fence::Signal is deferred behind a pending GPU queue signal, Fence::Signal enqueues a FenceWaitDispatcher callback that calls vkSignalSemaphore directly instead of going through VulkanFence::signal. That callback previously never notified QueueHolds via holds().signaled(semaphore, value) and holds().pump_ready(), leaving any cross-queue Wait-before-Signal batch stalled on that fence value forever even after GetCompletedValue() reached it. Record whether vkSignalSemaphore succeeded, decrement held_ first, and then call holds().signaled(semaphore, value) and holds().pump_ready() with no dispatcher or queue lock held. Add cross-queue regression cases to check_held_cpu_signal in d3d12_fence_timing_test.cpp covering both a Wait queued before the held CPU Signal and a Wait queued while the CPU Signal is already held. Claim: ItsNotRexed#4084 (comment) AI-assisted: yes (Antigravity)
Kam471
left a comment
There was a problem hiding this comment.
Built d3d12_fence_timing_test at 8dfe9bce and ran it on Windows 11, RTX 5070 Ti: exit 0, ctest -R d3d12_fence_timing -> 1/1 passed (1.64 s).
The held CPU-signal cases, multiple-fence waits, adapter LUID, custom heap properties and both clock-calibration paths (submitted-timestamp fallback and the calibrated-timestamps extension) all pass, including the queue-capability gate. No blocking issue.
|
Tested 8dfe9bc on RTX 5090, 621.24, Windows 11: pass. Built the runtime from this tree and ran Notifying |
|
Tested 8dfe9bc on Windows 11, MSVC 14.51, with NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and AMD Radeon(TM) Graphics (driver 32.0.21043.5001): pass. The build has no validation layers.
I also made a synthetic probe. Queue A waits behind a gate and has a signal of 100 in its queue. Then the CPU signals 110 and 120. Queues B and C wait on those values. Negative control: the new test of this head, linked with the libraries of main The full ctest result will follow if it shows a difference. I found no defect. AI-assisted. |
|
Tested 8dfe9bc on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11 Pro 26300, i7-14700K / 64 GB, MSVC 14.44 RelWithDebInfo (
Baseline on No game files. AI-assisted (Claude Code). |
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the current head 8dfe9bce. The deferred CPU-signal path notifies queue holds after the signal, and the independent Windows timing test covers waits before and after the deferred signal. No blocking issue found.
|
Tested 8dfe9bc on AMD Radeon RX 9060 XT (RDNA4), Windows 11, driver 26.10.1 (LLPC), Vulkan SDK 1.4.363.0, MSVC RelWithDebInfo.
Independent check on a second AMD RDNA4 part. AI-assisted (Devin). |
|
Review from working on the same path (I had reproduced it as D3D-481, now released as a duplicate of this; code read + a local implementation on RTX 3060, not a run of this PR's head):
AI-assisted (Claude). |
|
Tested 8dfe9bc (merged onto main 2d3369a, clean merge, only Pass: the fix and its new test do what the PR says.
Not caused by this PR (same result on unmodified main under Wine):
Not covered: no validation layer on this box ( Code read: the callback only pumps after |
|
Measured @requiemsnkrp's point 1 with a local probe added to
But the VUID isn't specific to this PR. A control on Host reference (same GPU, D3D12 debug layer on): releasing the fence right after the CPU signal is legal. B ran 50/50 both ways (with and without the gate), with 0 debug-layer messages, and a queue Gap left vs the host (not this PR's to fix): with #4663 + this PR, 16–24 of 200 batches are still dropped. That happens when F is released before the GPU reaches the queued value: AI-assisted (Claude Code). No game files. |
…l (D3D-496 case 1) check_released_postponed_signal runs @Exopus-0x65f7ad0's scenario 200 times on a fresh fence each time: queue A Wait(gate, i) + Signal(F, 1), CPU F->Signal(2) (held behind A's Signal), queue B Wait(F, 2) + Signal(done, i), then F->Release(). Even iterations release F before opening the gate, so the GPU cannot have reached 1 and the postponed Signal is lost; odd ones release it 0-1.9 ms after. B's batch must run every time, as on the host runtime, which the test also runs as the reference. With ItsNotRexed#4663 + ItsNotRexed#4282 alone the layer drops B's batch on every early release (100/200 here). With D3D-496 case 2 (a released fence's wait counts as reached) it runs 200/200, on the host too.
Summary
Fixes a cross-queue Wait-before-Signal deadlock in
runtime/shims/d3d12_com.cppwhere a deferred CPUID3D12Fence::Signal(value)callback advanced the Vulkan timeline semaphore without notifyingQueueHolds.Root Cause
When
Fence::Signal(value)is called while a GPUqueue->Signal(fence, queued)is still pending (held_->load() != 0 || fence_.completed() < queued), it defers the signal throughFenceWaitDispatcher. Oncequeuedcompletes:VulkanFence::signal()(runtime/src/vulkan_backend.h), which callsvkSignalSemaphore,context_.holds().signaled(semaphore_, value), andcontext_.holds().pump_ready().Fence::Signal()called rawvkSignalSemaphoreand decrementedheld_, but never calledcontext->holds().signaled(semaphore, value)orcontext->holds().pump_ready().As a result, any batch held in
QueueHoldswaiting forfence >= valueremained stalled indefinitely—even afterfence->GetCompletedValue()had already reachedvalue—until queue teardown discarded it.Changes
runtime/shims/d3d12_com.cpp:Fence::Signal()'s deferred callback, capture whethervkGetSemaphoreCounterValue(...) == VK_SUCCESS,now >= queued && now < value, andvkSignalSemaphore(...) == VK_SUCCESS.held->fetch_sub(1)before pumping ready holds (so concurrentFence::Signalcallers see the updated count), then callcontext->holds().signaled(semaphore, value)andcontext->holds().pump_ready()if the semaphore was signaled.FenceWaitDispatcherunlocksmutex_prior to invoking callbacks, andQueueHolds::signaled()/pump_ready()require no queue lock held.runtime/test/d3d12_fence_timing_test.cpp:check_held_cpu_signal()with two cross-queue regression scenarios (exercised on both the wrapped device proxy and the standalone Vulkan device):Wait(f, 70) + Signal(done, 1)queued before held CPUf->Signal(70)behind Queue AWait(gate, 3) + Signal(f, 60).Wait(f, 90) + Signal(done, 2)queued while CPUf->Signal(90)is already held behind Queue AWait(gate, 4) + Signal(f, 80).Verification (No Game Files)
d3d12_com.cpponorigin/mainaa2988cc):LEONIDA_VK_VALIDATION=1 d3d12_fence_timing_test.exefailed with exit code1:held CPU signal did not wake QueueHolds: f=70 done=0[rt] d3d12: queue destroyed with 1 held operation(s) never submitted: waits for a fence value (70) that no Signal reached; the fence was never signaled10.0.26200, NVIDIA GeForce RTX 4060 8 GB, Vulkan SDK1.4.363.0, MSVC19.44.35230.0, CMake4.4.4, Ninja1.13.2):LEONIDA_VK_VALIDATION=1 d3d12_fence_timing_test.exe: PASS,0 validation errors, wrapped + standalone devices both verified.LEONIDA_VK_VALIDATION=1 ctest --output-on-failure -R "^(d3d12_fence_timing|d3d12_queue_wait|d3d12_queue_wait_timeout|d3d12_fence_events|d3d12_fence_waiter|vk_fence_dispatcher_sync)$": 6/6 passed (100% tests passed) in6.79 sec./W4compilation,git diff --checkclean, LF line endings preserved (CRLF=0).Coordination & Related PRs
VkSemaphorelifetime in the sameFence::Signalcallback capture list (lifetime = fence_.retain()); both changes are complementary and rebase trivially together.AI-assisted with Neon (Antigravity).