vulkan: a fence counter of UINT64_MAX no Signal asked for is a loss, without vkDeviceWaitIdle (RT-FENCE-MAX-CONFIRM-NO-STALL) #2365

Closed
HasiKe wants to merge 3 commits from upstream-pr/2365 into main
HasiKe commented 2026-11-26 15:40:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-26T15:40:21Z.


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 with vkDeviceWaitIdle under 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:

  • The holder is the list-value pump: Pump::run → take_landed → VulkanFence::completed → vkDeviceWaitIdle.
  • The releaser waits for the lock: Pump::release_loop → Fence::Signal → VulkanQueue::release_held → QueueHolds::pump_ready → execute_now → SubmitMutex::lock, in the middle of submitting a held batch.
  • So does another VulkanFence::completed reader, and a compile worker.

Nothing could submit for 4.5 minutes, so the title froze. The loss, and the LEONIDA_DEVICE_FAULT report, 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:

  • Below UINT64_MAX: no Signal can have produced a counter of UINT64_MAX, so the device is marked lost at once ("a fence's counter read UINT64_MAX, a value no Signal asked for"). No vkDeviceWaitIdle and no submit lock.
  • At UINT64_MAX: the reading is the value, and nothing is recorded.

Behaviour change, for @quartz-heron-58 (author of 35e38baee)

Case 3 of vk_fence_lost_by_counter was "UINT64_MAX on a device that is not lost records no loss when vkDeviceWaitIdle succeeds". It is now "UINT64_MAX on a fence a Signal asked that value of records no loss". Two open questions from me:

  1. Was the old case 3 a measured driver case, i.e. a counter of UINT64_MAX with no Signal for it on a device that was fine? If it was, this needs another way to tell the two cases apart.
  2. The removed comment said vkDeviceWaitIdle "is also what a driver needs to have returned before vkGetDeviceFaultInfoEXT answers". With this change, a loss found this way no longer goes through a VK_ERROR_DEVICE_LOST result, so the LEONIDA_DEVICE_FAULT report is not triggered from here. If you want the report kept, I can add a vkDeviceWaitIdle after 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:

  1. UINT64_MAX with no Signal for it marks the loss once and never calls vkDeviceWaitIdle.
  2. A second read on the lost device asks the driver nothing.
  3. UINT64_MAX on a fence with a recorded Signal(UINT64_MAX) records no loss and does not call vkDeviceWaitIdle.
  4. An ordinary value never reaches it.
  5. New: a reading while another thread holds the submit lock still answers and marks the loss.

Results:

  • On main fbf100b1b the new test fails (exit 1). With this change it passes.
  • Full runtime CTest, 486 tests: all pass except xbox_present and d3d12_set_descriptor_heaps. Both also fail on unmodified main fbf100b1b on this machine. xbox_present is the known one (#2259).
  • Fence-related tests pass: 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5512970106 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365). Originally posted by [HasiKe](https://github.com/HasiKe) on 2026-11-26T15:40:21Z. --- Item: RT-FENCE-MAX-CONFIRM-NO-STALL ([claim and analysis in #1608](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7195994285)) ### 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 with `vkDeviceWaitIdle` **under 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: - The holder is the list-value pump: `Pump::run` → `take_landed` → `VulkanFence::completed` → `vkDeviceWaitIdle`. - The releaser waits for the lock: `Pump::release_loop` → `Fence::Signal` → `VulkanQueue::release_held` → `QueueHolds::pump_ready` → `execute_now` → `SubmitMutex::lock`, in the middle of submitting a held batch. - So does another `VulkanFence::completed` reader, and a compile worker. Nothing could submit for 4.5 minutes, so the title froze. The loss, and the `LEONIDA_DEVICE_FAULT` report, 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: - **Below UINT64_MAX:** no Signal can have produced a counter of UINT64_MAX, so the device is marked lost at once ("a fence's counter read UINT64_MAX, a value no Signal asked for"). No `vkDeviceWaitIdle` and no submit lock. - **At UINT64_MAX:** the reading is the value, and nothing is recorded. ### Behaviour change, for @quartz-heron-58 (author of 35e38baee) Case 3 of `vk_fence_lost_by_counter` was "UINT64_MAX on a device that is not lost records no loss when `vkDeviceWaitIdle` succeeds". It is now "UINT64_MAX on a fence a Signal asked that value of records no loss". Two open questions from me: 1. Was the old case 3 a measured driver case, i.e. a counter of UINT64_MAX with no Signal for it on a device that was fine? If it was, this needs another way to tell the two cases apart. 2. The removed comment said `vkDeviceWaitIdle` "is also what a driver needs to have returned before `vkGetDeviceFaultInfoEXT` answers". With this change, a loss found this way no longer goes through a `VK_ERROR_DEVICE_LOST` result, so the `LEONIDA_DEVICE_FAULT` report is not triggered from here. If you want the report kept, I can add a `vkDeviceWaitIdle` after 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: 1. UINT64_MAX with no Signal for it marks the loss once and never calls `vkDeviceWaitIdle`. 2. A second read on the lost device asks the driver nothing. 3. UINT64_MAX on a fence with a recorded Signal(UINT64_MAX) records no loss and does not call `vkDeviceWaitIdle`. 4. An ordinary value never reaches it. 5. New: a reading while another thread holds the submit lock still answers and marks the loss. Results: - On `main` `fbf100b1b` the new test **fails** (exit 1). With this change it passes. - Full runtime CTest, 486 tests: all pass except `xbox_present` and `d3d12_set_descriptor_heaps`. Both also fail on unmodified `main` `fbf100b1b` on this machine. `xbox_present` is the known one (#2259). - Fence-related tests pass: `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).
lixonik commented 2026-11-26 15:43:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:43:51Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6076962393 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#pullrequestreview-6076962393). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:43:51Z. **Review:** COMMENTED --- 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.
lixonik commented 2026-11-26 15:43:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:43:51Z.

Code review location: runtime/src/vulkan_backend.h; line 2501

@@ -2492,18 +2492,14 @@ class VulkanFence {
         if (value == UINT64_MAX) {
             // A lost device can show itself here first: measured on NVIDIA 621.24 and reported on 617.14, the counter
             // query succeeds with UINT64_MAX (and vkWaitSemaphores with a zero timeout succeeds too) before any call
-            // has returned VK_ERROR_DEVICE_LOST. vkDeviceWaitIdle is what then says so, and it is also what a driver
-            // needs to have returned before vkGetDeviceFaultInfoEXT answers (LEONIDA_DEVICE_FAULT=1). When
-            // vkDeviceWaitIdle succeeds, nothing is recorded and the value is returned as the driver gave it.
-            VkResult idle = VK_SUCCESS;
-            {
-                std::lock_guard lock(context_.submit_mutex());
-                idle = context_.observe_result(context_.vk.vkDeviceWaitIdle(context_.device()),
-                                               "vkDeviceWaitIdle (a fence counter of UINT64_MAX)");
-            }
-            if (idle == VK_ERROR_DEVICE_LOST)
-                context_.mark_device_lost(
-                    "a fence's counter read UINT64_MAX and vkDeviceWaitIdle then returned VK_ERROR_DEVICE_LOST");
+            // has returned VK_ERROR_DEVICE_LOST. The fence's record says whether anyone asked for that value: its
+            // initial value, a CPU Signal or a submitted one (QueueHolds::submitted_value). Asked for, the reading is
+            // the value and nothing is recorded. Not asked for, no Signal can have produced it, so the device is lost.
+            // 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)

[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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4710614219 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2365#discussion_r4710614219). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:43:51Z. **Code review location:** `runtime/src/vulkan_backend.h`; line 2501 ~~~~diff @@ -2492,18 +2492,14 @@ class VulkanFence { if (value == UINT64_MAX) { // A lost device can show itself here first: measured on NVIDIA 621.24 and reported on 617.14, the counter // query succeeds with UINT64_MAX (and vkWaitSemaphores with a zero timeout succeeds too) before any call - // has returned VK_ERROR_DEVICE_LOST. vkDeviceWaitIdle is what then says so, and it is also what a driver - // needs to have returned before vkGetDeviceFaultInfoEXT answers (LEONIDA_DEVICE_FAULT=1). When - // vkDeviceWaitIdle succeeds, nothing is recorded and the value is returned as the driver gave it. - VkResult idle = VK_SUCCESS; - { - std::lock_guard lock(context_.submit_mutex()); - idle = context_.observe_result(context_.vk.vkDeviceWaitIdle(context_.device()), - "vkDeviceWaitIdle (a fence counter of UINT64_MAX)"); - } - if (idle == VK_ERROR_DEVICE_LOST) - context_.mark_device_lost( - "a fence's counter read UINT64_MAX and vkDeviceWaitIdle then returned VK_ERROR_DEVICE_LOST"); + // has returned VK_ERROR_DEVICE_LOST. The fence's record says whether anyone asked for that value: its + // initial value, a CPU Signal or a submitted one (QueueHolds::submitted_value). Asked for, the reading is + // the value and nothing is recorded. Not asked for, no Signal can have produced it, so the device is lost. + // 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) ~~~~ --- [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.
HasiKe commented 2026-11-26 15:48:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-26T15:48:19Z.


One game boot with this PR. AI-assisted (Claude Code).

Runtime: main fbf100b1b (which has #2195) plus this PR. Recipe: RTX 2070 SUPER, NVIDIA 616.56, a cold boot (no caches), LEONIDA_ASYNC_PIPELINES=1, LEONIDA_COMPILE_GATE=0, LEONIDA_DEVICE_FAULT=2, the watchdog kicked, 660 s.

Result:

  • The new path fired. The log says the device was lost (a fence's counter read UINT64_MAX, a value no Signal asked for).
  • The report follows at once. The next submission gets VK_ERROR_DEVICE_LOST from vkQueueSubmit (present), and the fault report is taken at t=304.8 s. The report says submit lock held by thread 2680 for 0 ms.
  • No stall. There is no submit-lock: held or device-stall line anywhere in the log. The boot this PR comes from had the lock held for 270 s at this point.
  • The timing is right. nvlddmkm 153 came at 16:46:49. The boot started at 16:41:43, so the driver reset and the reported loss fall in the same second, rather than 270 s apart.
  • The report now shows the real fault:
    • 45 instruction-pointer addresses, so waves were still running.
    • The direct queue is at a draw: _MS_VS_TransformD_c5fd36bb_Wrapped~153 + %PS_DeferredTextured_942fcba4_Wrapped~30.
    • The compute queues are at lib_cs_01468, command 16. That is the same shape as the GPU-hang boots in #1608, now without the wait in front of it.

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7196774917 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2365#issuecomment-7196774917). Originally posted by [HasiKe](https://github.com/HasiKe) on 2026-11-26T15:48:19Z. --- One game boot with this PR. AI-assisted (Claude Code). **Runtime:** `main` `fbf100b1b` (which has #2195) plus this PR. Recipe: RTX 2070 SUPER, NVIDIA 616.56, a cold boot (no caches), `LEONIDA_ASYNC_PIPELINES=1`, `LEONIDA_COMPILE_GATE=0`, `LEONIDA_DEVICE_FAULT=2`, the watchdog kicked, 660 s. **Result:** - **The new path fired.** The log says `the device was lost (a fence's counter read UINT64_MAX, a value no Signal asked for)`. - **The report follows at once.** The next submission gets `VK_ERROR_DEVICE_LOST from vkQueueSubmit (present)`, and the fault report is taken at t=304.8 s. The report says `submit lock held by thread 2680 for 0 ms`. - **No stall.** There is no `submit-lock: held` or `device-stall` line anywhere in the log. The boot this PR comes from had the lock held for 270 s at this point. - **The timing is right.** `nvlddmkm` 153 came at 16:46:49. The boot started at 16:41:43, so the driver reset and the reported loss fall in the same second, rather than 270 s apart. - **The report now shows the real fault:** - 45 instruction-pointer addresses, so waves were still running. - The direct queue is at a draw: `_MS_VS_TransformD_c5fd36bb_Wrapped~153` + `%PS_DeferredTextured_942fcba4_Wrapped~30`. - The compute queues are at `lib_cs_01468`, command 16. That is the same shape as the GPU-hang boots in #1608, now without the wait in front of it. 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.
quartz-heron-58 commented 2026-11-26 15:56:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-26T15:56:19Z.


Answers to the two questions, as author of 35e38ba (AI-assisted, Claude Code):

  1. Case 3 was not a measured driver case. What I measured (RTX 4080, NVIDIA 621.24) was only the lost case: vkGetSemaphoreCounterValue succeeding with UINT64_MAX, and vkWaitSemaphores succeeding on it, before any call had returned VK_ERROR_DEVICE_LOST. I never saw UINT64_MAX on a healthy device with no Signal for it. Case 3 was a synthetic guard (interposed driver table) so that the value alone was not taken as proof. Deciding from what was asked of the fence covers the same concern, so I have no objection to dropping the vkDeviceWaitIdle. The window lixonik describes (the Vulkan signal done, the bookkeeping not yet updated) is the one place where the new rule can call a healthy device lost, so that needs closing.

  2. The sentence about vkGetDeviceFaultInfoEXT comes from the same machine: there the driver did not answer the fault query until some call had returned VK_ERROR_DEVICE_LOST. I measured that with vkDeviceWaitIdle as the call; I did not test whether a later vkQueueSubmit returning the error serves equally. Your boot above suggests it does on 616.56 (the report follows the next submission). The case not covered is a loss found here when nothing submits afterwards, for example a title that stops on reading the value. A vkDeviceWaitIdle only with the fault diagnostics on, after the loss is marked, would keep the report for that case and stalls nothing in ordinary runs, so yes, I would keep it in that form.

Not checked by me: this PR's head in a game run.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7196955107 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2365#issuecomment-7196955107). Originally posted by [quartz-heron-58](https://github.com/quartz-heron-58) on 2026-11-26T15:56:19Z. --- Answers to the two questions, as author of 35e38ba (AI-assisted, Claude Code): 1. Case 3 was not a measured driver case. What I measured (RTX 4080, NVIDIA 621.24) was only the lost case: vkGetSemaphoreCounterValue succeeding with UINT64_MAX, and vkWaitSemaphores succeeding on it, before any call had returned VK_ERROR_DEVICE_LOST. I never saw UINT64_MAX on a healthy device with no Signal for it. Case 3 was a synthetic guard (interposed driver table) so that the value alone was not taken as proof. Deciding from what was asked of the fence covers the same concern, so I have no objection to dropping the vkDeviceWaitIdle. The window lixonik describes (the Vulkan signal done, the bookkeeping not yet updated) is the one place where the new rule can call a healthy device lost, so that needs closing. 2. The sentence about vkGetDeviceFaultInfoEXT comes from the same machine: there the driver did not answer the fault query until some call had returned VK_ERROR_DEVICE_LOST. I measured that with vkDeviceWaitIdle as the call; I did not test whether a later vkQueueSubmit returning the error serves equally. Your boot above suggests it does on 616.56 (the report follows the next submission). The case not covered is a loss found here when nothing submits afterwards, for example a title that stops on reading the value. A vkDeviceWaitIdle only with the fault diagnostics on, after the loss is marked, would keep the report for that case and stalls nothing in ordinary runs, so yes, I would keep it in that form. Not checked by me: this PR's head in a game run.
HasiKe commented 2026-11-26 16:38:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-26T16:38:26Z.


Thanks to both of you. Pushed in 69b1338f2, on top of a merge of main d5634defe. AI-assisted (Claude Code).

@lixonik's window (P2):

  • QueueHolds::asking(semaphore, value) now records the value before each of the three calls that can signal a D3D12 fence's semaphore:
    • VulkanFence::signal (vkSignalSemaphore);
    • the vkQueueSubmit in VulkanQueue that signals the fence;
    • the COM fence callback's vkSignalSemaphore (d3d12_com.cpp).
  • completed() decides from asked_value, the larger of that record and the existing signaled() one. A reader that sees UINT64_MAX while such a call is still returning therefore finds the value already announced.
  • A failed call leaves the announcement in place. That can only make a later UINT64_MAX count as asked-for, never turn a healthy device into a lost one.
  • The other two vkSignalSemaphore/submit-signal sites in the backend (the fence dispatcher's wakeup semaphore and the queues' progress timelines) are not D3D12 fences; completed() never reads them.
  • New case 6 in vk_fence_lost_by_counter: a Signal(UINT64_MAX) announced but not yet recorded (submitted_value still UINT64_MAX - 1) reads as the value, with no loss and no vkDeviceWaitIdle.

@quartz-heron-58's point 2:

  • With the fault diagnostics on (context.device_fault()), completed() still calls vkDeviceWaitIdle under the submit lock, but only after it has marked the loss, and only the first time.
  • Without diagnostics there is no wait at all, so ordinary runs cannot stall.

Tests:

  • Full runtime CTest, 483 tests: all pass except xbox_present and d3d12_set_descriptor_heaps, the same two that fail on unmodified main here.
  • vk_fence_lost_by_counter passes with all six cases.
  • RTX 2070 SUPER, NVIDIA 616.56, Windows 11, MSVC RelWithDebInfo.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7197908070 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2365#issuecomment-7197908070). Originally posted by [HasiKe](https://github.com/HasiKe) on 2026-11-26T16:38:26Z. --- Thanks to both of you. Pushed in `69b1338f2`, on top of a merge of `main` `d5634defe`. AI-assisted (Claude Code). **@lixonik's window (P2):** - `QueueHolds::asking(semaphore, value)` now records the value **before** each of the three calls that can signal a D3D12 fence's semaphore: - `VulkanFence::signal` (`vkSignalSemaphore`); - the `vkQueueSubmit` in `VulkanQueue` that signals the fence; - the COM fence callback's `vkSignalSemaphore` (`d3d12_com.cpp`). - `completed()` decides from `asked_value`, the larger of that record and the existing `signaled()` one. A reader that sees UINT64_MAX while such a call is still returning therefore finds the value already announced. - A failed call leaves the announcement in place. That can only make a later UINT64_MAX count as asked-for, never turn a healthy device into a lost one. - The other two `vkSignalSemaphore`/submit-signal sites in the backend (the fence dispatcher's wakeup semaphore and the queues' progress timelines) are not D3D12 fences; `completed()` never reads them. - New case 6 in `vk_fence_lost_by_counter`: a Signal(UINT64_MAX) announced but not yet recorded (`submitted_value` still `UINT64_MAX - 1`) reads as the value, with no loss and no `vkDeviceWaitIdle`. **@quartz-heron-58's point 2:** - With the fault diagnostics on (`context.device_fault()`), `completed()` still calls `vkDeviceWaitIdle` under the submit lock, but only **after** it has marked the loss, and only the first time. - Without diagnostics there is no wait at all, so ordinary runs cannot stall. **Tests:** - Full runtime CTest, 483 tests: all pass except `xbox_present` and `d3d12_set_descriptor_heaps`, the same two that fail on unmodified `main` here. - `vk_fence_lost_by_counter` passes with all six cases. - RTX 2070 SUPER, NVIDIA 616.56, Windows 11, MSVC RelWithDebInfo.
lixonik commented 2026-11-26 18:02:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T18:02:11Z.

Review: COMMENTED


Re-tested 69b1338f2 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6078731847 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#pullrequestreview-6078731847). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T18:02:11Z. **Review:** COMMENTED --- Re-tested 69b1338f2 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 commented 2026-11-27 02:29:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T02:29:34Z.

Review: APPROVED


Approving 69b1338f2.

Merged into current main (d1dff7949): 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6082702795 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#pullrequestreview-6082702795). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T02:29:34Z. **Review:** APPROVED --- Approving 69b1338f2. Merged into current main (d1dff7949): 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).
zmasi commented 2026-11-29 00:59:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:59:39Z.


#2365 | head 69b1338f2e (merged cleanly with main 48bae6cade — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(list_value_wait_budget|vk_fence_lost_by_counter|xbox_list_value_fallback)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: building vk_fence_lost_by_counter_test against main's runtime/src/vulkan_backend.h fails vk_fence_lost_by_counter at line 90: driver::idle_calls.load() == 0 (VulkanFence::completed calls vkDeviceWaitIdle under submit_mutex_) | green on PR+main: 3/3 CTests (list_value_wait_budget, vk_fence_lost_by_counter — all 6 cases including submit_mutex_ contention and in-flight QueueHolds::asking(UINT64_MAX), xbox_list_value_fallback) pass in 1.59 s on RTX 3090 with 0 Khronos validation errors (check_no_game_data.py 0 violations; minor non-blocking note in VulkanFence::completed: first = !context_.is_device_lost() before mark_device_lost(...) is a non-atomic check-then-set — returning the winning exchange bool from mark_device_lost avoids two concurrent UINT64_MAX readers both entering the LEONIDA_DEVICE_FAULT vkDeviceWaitIdle branch) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248488320 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#issuecomment-7248488320). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T00:59:39Z. --- #2365 | head 69b1338f2e97df44fd3e573f8c26888a76c1bcd7 (merged cleanly with main 48bae6cade49aea69f63eb8871572dcd6931cd4b — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(list_value_wait_budget|vk_fence_lost_by_counter|xbox_list_value_fallback)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `vk_fence_lost_by_counter_test` against `main`'s `runtime/src/vulkan_backend.h` fails `vk_fence_lost_by_counter` at `line 90: driver::idle_calls.load() == 0` (`VulkanFence::completed` calls `vkDeviceWaitIdle` under `submit_mutex_`) | green on PR+main: `3/3` CTests (`list_value_wait_budget`, `vk_fence_lost_by_counter` — all 6 cases including `submit_mutex_` contention and in-flight `QueueHolds::asking(UINT64_MAX)`, `xbox_list_value_fallback`) pass in `1.59 s` on RTX 3090 with `0` Khronos validation errors (`check_no_game_data.py` `0` violations; minor non-blocking note in `VulkanFence::completed`: `first = !context_.is_device_lost()` before `mark_device_lost(...)` is a non-atomic check-then-set — returning the winning exchange bool from `mark_device_lost` avoids two concurrent `UINT64_MAX` readers both entering the `LEONIDA_DEVICE_FAULT` `vkDeviceWaitIdle` branch) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 commented 2026-11-29 04:27:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:27:48Z.

Review: COMMENTED


Static audit of 69b1338f2 against the PR base and the supplied main revision. No builds, tests, or GPU runs were performed.

  • [MAJOR] runtime/src/queue_holds.h:111 — If a queue's only Signal(UINT64_MAX) fails with VK_ERROR_OUT_OF_HOST_MEMORY, the pre-submit announcement at runtime/src/vulkan_backend.h:4483 survives even though the submitted value stays below max. When a later device loss first surfaces as VK_SUCCESS with a fabricated max, the early return at runtime/src/vulkan_backend.h:2502 skips marking the context lost, so GetDeviceRemovedReason() still returns S_OK. Keep each max announcement live only while its driver call is outstanding, then publish success and retire the announcement under the same lock. A failed call should remove only its own announcement. Please cover a failed max submit followed by an injected max counter through the queue and fence entry points.
  • [MINOR] runtime/src/vulkan_backend.h:2503 — Two concurrent readers can both see a healthy context before either marks the device lost. With diagnostics enabled, both then call vkDeviceWaitIdle under the submit mutex. Use the existing atomic transition result from set_device_lost() to gate the diagnostic wait to a single caller.
  • [MINOR] runtime/test/vk_fence_lost_by_counter_test.cpp:129 — If the counter read regresses to taking the submit mutex, case 5 blocks on the read and never tells the holder to release it. Run the read on a worker, check completion with a deadline while the mutex is held, and release and join before asserting the result.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6101397822 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#pullrequestreview-6101397822). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T04:27:48Z. **Review:** COMMENTED --- Static audit of `69b1338f2` against the PR base and the supplied main revision. No builds, tests, or GPU runs were performed. - **[MAJOR] `runtime/src/queue_holds.h:111`** — If a queue's only `Signal(UINT64_MAX)` fails with `VK_ERROR_OUT_OF_HOST_MEMORY`, the pre-submit announcement at `runtime/src/vulkan_backend.h:4483` survives even though the submitted value stays below max. When a later device loss first surfaces as `VK_SUCCESS` with a fabricated max, the early return at `runtime/src/vulkan_backend.h:2502` skips marking the context lost, so `GetDeviceRemovedReason()` still returns `S_OK`. Keep each max announcement live only while its driver call is outstanding, then publish success and retire the announcement under the same lock. A failed call should remove only its own announcement. Please cover a failed max submit followed by an injected max counter through the queue and fence entry points. - **[MINOR] `runtime/src/vulkan_backend.h:2503`** — Two concurrent readers can both see a healthy context before either marks the device lost. With diagnostics enabled, both then call `vkDeviceWaitIdle` under the submit mutex. Use the existing atomic transition result from `set_device_lost()` to gate the diagnostic wait to a single caller. - **[MINOR] `runtime/test/vk_fence_lost_by_counter_test.cpp:129`** — If the counter read regresses to taking the submit mutex, case 5 blocks on the read and never tells the holder to release it. Run the read on a worker, check completion with a deadline while the mutex is held, and release and join before asserting the result. AI-assisted.
aslan2142 commented 2026-12-01 16:44:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:44:08Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318127608 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2365#issuecomment-7318127608). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:44:08Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2365
No description provided.