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

Open
opened 2026-11-26 21:21:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2365
Author: @HasiKe
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fence-max-no-stall


📝 Commits (3)

  • 63cdc82 vulkan: a fence counter of UINT64_MAX no Signal asked for is a loss, without vkDeviceWaitIdle
  • 022ef7a Merge remote-tracking branch 'origin/main' into fence-max-no-stall
  • 69b1338 vulkan: announce a Signal before its Vulkan call; keep the fault report's wait with diagnostics on

📊 Changes

4 files changed (+90 additions, -21 deletions)

View changed files

📝 runtime/shims/d3d12_com.cpp (+1 -0)
📝 runtime/src/queue_holds.h (+23 -1)
📝 runtime/src/vulkan_backend.h (+18 -10)
📝 runtime/test/vk_fence_lost_by_counter_test.cpp (+48 -10)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2365 **Author:** [@HasiKe](https://github.com/HasiKe) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fence-max-no-stall` --- ### 📝 Commits (3) - [`63cdc82`](https://github.com/ubiquitarianism/leonida/commit/63cdc8267ee2609a03867deba3103c6f1410641d) vulkan: a fence counter of UINT64_MAX no Signal asked for is a loss, without vkDeviceWaitIdle - [`022ef7a`](https://github.com/ubiquitarianism/leonida/commit/022ef7ab9696e90abb53c65c7bf5f50cf1116127) Merge remote-tracking branch 'origin/main' into fence-max-no-stall - [`69b1338`](https://github.com/ubiquitarianism/leonida/commit/69b1338f2e97df44fd3e573f8c26888a76c1bcd7) vulkan: announce a Signal before its Vulkan call; keep the fault report's wait with diagnostics on ### 📊 Changes **4 files changed** (+90 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_com.cpp` (+1 -0) 📝 `runtime/src/queue_holds.h` (+23 -1) 📝 `runtime/src/vulkan_backend.h` (+18 -10) 📝 `runtime/test/vk_fence_lost_by_counter_test.cpp` (+48 -10) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2368
No description provided.