Repository navigation
Conversation
…without vkDeviceWaitIdle VulkanFence::completed confirmed a UINT64_MAX counter with vkDeviceWaitIdle under the submit lock. On an RTX 2070 SUPER (NVIDIA 616.56) that call blocked for 270 s in a world-load boot while the list-value releaser waited for the same lock to submit a held batch: the title froze and the loss was reported minutes after it happened. QueueHolds::submitted_value already records the highest value anyone asked of a fence (its initial value, CPU Signals and submitted ones). Below UINT64_MAX, no Signal can have produced the reading, so the device is marked lost at once; at UINT64_MAX the reading is the value. vk_fence_lost_by_counter covers both, a second read on the lost device, and a read while another thread holds the submit lock.
lixonik
left a comment
There was a problem hiding this comment.
Built the exact PR head with MSVC on Windows 11, and vk_fence_lost_by_counter passed on NVIDIA GeForce RTX 5070 (610.88). A scratch-only test of a real CPU timeline signal found a false device-loss classification in a concurrent counter read. Details inline.
AI-assisted.
| // That is decided without vkDeviceWaitIdle: under the submit lock it can block for minutes on such a | ||
| // device (measured 270 s on NVIDIA 616.56), and meanwhile the releaser cannot submit the held batch a | ||
| // queue's Wait may be waiting for, so the title froze and the loss was reported minutes late. | ||
| if (context_.holds().submitted_value(semaphore_) != UINT64_MAX) |
There was a problem hiding this comment.
[P2] Account for a legitimate max-value signal while publication is in flight.
signal() calls vkSignalSemaphore before it updates QueueHolds. I used the existing interposition harness to pause a CPU signal to UINT64_MAX just after the real Vulkan call succeeded, then read the same fence on another thread before the wrapper returned. The fence went from UINT64_MAX - 1 to UINT64_MAX on the real device, and the reader marked the healthy device lost because the bookkeeping still held UINT64_MAX - 1. The queue-submit path also publishes after the Vulkan call. Track an in-flight max signal or synchronize that narrow window without waiting for device idle.
|
One game boot with this PR. AI-assisted (Claude Code). Runtime: Result:
This is one boot. The 270 s stall needs the same timing to come back, so this does not show the stall can never happen. It does show that the changed branch is taken in a real loss, and that the report then comes promptly and points at the hang. |
|
Answers to the two questions, as author of 35e38ba (AI-assisted, Claude Code):
Not checked by me: this PR's head in a game run. |
…rt's wait with diagnostics on Review of ProjectLeonida#2365: VulkanFence::signal, the queue submit that signals a fence and the COM fence callback record their value with QueueHolds::signaled only after the Vulkan call returns. A counter read on another thread in that window saw UINT64_MAX with the record one below and called a healthy device lost (found by lixonik). QueueHolds::asking now announces the value before each of the three calls, and completed() decides from asked_value, the larger of the two records. With the device-fault diagnostics on, completed() still calls vkDeviceWaitIdle after marking the loss: on NVIDIA 621.24 vkGetDeviceFaultInfoEXT answered only once a call had returned VK_ERROR_DEVICE_LOST (quartz-heron-58). The context is lost by then, so the wait can stall only a diagnostic run. vk_fence_lost_by_counter case 6: a Signal(UINT64_MAX) announced but not yet recorded is not a loss.
|
Thanks to both of you. Pushed in @lixonik's window (P2):
@quartz-heron-58's point 2:
Tests:
|
lixonik
left a comment
There was a problem hiding this comment.
Re-tested 69b1338 on RTX 5070 (610.88, Windows 11). The full fence suite and my original concurrent CPU-signal case both passed. The real vkSignalSemaphore reached UINT64_MAX, the reader ran before VulkanFence::signal() published completion, and the device remained healthy. This verifies the earlier finding. I did not exercise a separate GPU-queue interleaving.
AI-assisted.
tiguan26
left a comment
There was a problem hiding this comment.
Approving 69b1338.
Merged into current main (d1dff79): only vulkan_backend.h auto-merges, no conflicts. Cross-built with clang-cl 19 + xwin and run under Wine 11.22 on llvmpipe: all 27 fence and queue tests pass (ctest -R "fence|queue_query|presenter_sync|wait_registration"), including vk_fence_lost_by_counter, d3d12_fence_device_lost_counter, d3d12_fence_timing (held CPU signals) and vk_presenter_sync.
Read the diff with lixonik's P2 in mind. Every path that can signal a D3D12 fence's semaphore now announces its value first: VulkanFence::signal, the fence-signalling vkQueueSubmit in VulkanQueue, and the COM fence callback. The two other vkSignalSemaphore/signal sites are the dispatcher's wakeup semaphore and the sparse-bind progress ticket, which completed() never reads. asked_ is cleared with fences_ in remove_fence. Deciding from what was asked instead of a vkDeviceWaitIdle under the submit lock removes the multi-minute stall HasiKe measured, and the wait is kept only for fault diagnostics on an already-lost context.
The updated test uses asking(), so it can't run against main's code as a before/after check; the lixonik and HasiKe runs above cover the real-driver side. AI-assisted (Claude Code, Claude Opus 5.5).
Item: RT-FENCE-MAX-CONFIRM-NO-STALL (claim and analysis in #1608)
What and why
VulkanFence::completed(runtime/src/vulkan_backend.h) handles the NVIDIA case where a lost device first shows as a timeline counter of UINT64_MAX. It confirmed that withvkDeviceWaitIdleunder the submit lock.In a cold world-load boot on an RTX 2070 SUPER (NVIDIA 616.56), that call blocked for 270 s:
submit-lock: held 270089 ms by thread 17780, t=200.490..470.579 s. I resolved the runtime's own submit-lock stack dump against the build's PDB:Pump::run→take_landed→VulkanFence::completed→vkDeviceWaitIdle.Pump::release_loop→Fence::Signal→VulkanQueue::release_held→QueueHolds::pump_ready→execute_now→SubmitMutex::lock, in the middle of submitting a held batch.VulkanFence::completedreader, and a compile worker.Nothing could submit for 4.5 minutes, so the title froze. The loss, and the
LEONIDA_DEVICE_FAULTreport, came 270 s after the fault, so that report describes the device after the wait.QueueHolds::submitted_value(semaphore)already knows the highest value anyone asked of the fence: its initial value (add_fence), CPU Signals (signaled) and submitted Signals. This PR uses that:vkDeviceWaitIdleand no submit lock.Behaviour change, for @quartz-heron-58 (author of 35e38ba)
Case 3 of
vk_fence_lost_by_counterwas "UINT64_MAX on a device that is not lost records no loss whenvkDeviceWaitIdlesucceeds". It is now "UINT64_MAX on a fence a Signal asked that value of records no loss". Two open questions from me:vkDeviceWaitIdle"is also what a driver needs to have returned beforevkGetDeviceFaultInfoEXTanswers". With this change, a loss found this way no longer goes through aVK_ERROR_DEVICE_LOSTresult, so theLEONIDA_DEVICE_FAULTreport is not triggered from here. If you want the report kept, I can add avkDeviceWaitIdleafter the loss is marked, only with the fault diagnostics on. It then stalls only diagnostic runs, and by then the context is already lost.Tests
vk_fence_lost_by_counter, rewritten:vkDeviceWaitIdle.vkDeviceWaitIdle.Results:
mainfbf100b1bthe new test fails (exit 1). With this change it passes.xbox_presentandd3d12_set_descriptor_heaps. Both also fail on unmodifiedmainfbf100b1bon this machine.xbox_presentis the known one (xbox_present_test: a resize round whose present was out of date has no readback (TEST-XBOX-PRESENT-RESIZE-OUT-OF-DATE) #2259).vk_fence_*,d3d12_fence_*,list_value_wait_budget,xbox_list_value_fallback,wait_registration_*.The 270 s stall itself came from one boot in about five, so I have not shown in a game boot that it is gone. I'll run more cold world-load boots with this change and report there.
Environment: RTX 2070 SUPER, NVIDIA 616.56, Windows 11 Pro 26300, MSVC (VS 18) RelWithDebInfo via
scripts/build_runtime.ps1 -FetchSdl3. No game files in the change or the test.AI-assisted (Claude Code).