[PR #980] [MERGED] vulkan: say once when the device is lost (RT-DEVICE-LOST-LOG) #1016

Closed
opened 2026-11-26 20:19:48 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/980
Author: @CLHelper
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @QemmHD

Base: main ← Head: runtime/device-lost-log


📝 Commits (1)

  • 5c1f77e vulkan: say once when the device is lost (RT-DEVICE-LOST-LOG)

📊 Changes

2 files changed (+37 additions, -6 deletions)

View changed files

📝 runtime/src/vulkan_backend.h (+21 -4)
📝 runtime/test/vk_fence_dispatcher_sync_test.cpp (+16 -2)

📄 Description

Claimed in the coordination issue as: RT-DEVICE-LOST-LOG (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7137184715)

What and why

When the layer's Vulkan device is lost, VulkanContext::mark_device_lost() and the fence dispatcher's two VK_ERROR_DEVICE_LOST paths only set the device's lost flag. From then on every fence reads UINT64_MAX and device calls return DXGI_ERROR_DEVICE_REMOVED, so the title takes its own device-removed path, and nothing in the log said that the device went first.

On the retail boot that path is easy to misread. The title's frame wait gets the address of a fence's completed value (fence slot 12), spins on it, and when it reads ~0 it calls a fatal routine that ends in an int3 at game_scarlett_master.exe+0x2474606 (static reading of my own 1.0.2.1 copy: the wait at +0x4fb0ad0, call +0x2474870 when the value is -1, the routine at +0x2474500). With LEONIDA_SKIP_INT3 the title then runs on into reads of garbage addresses. In five runs of @DadaCap's boot-prototype on my machine, that int3 and the access violations after it were the only visible stop. The fence values come from GetCompletedValue. Correction after review elsewhere: I first wrote here that the layer answers UINT64_MAX only once its lost flag is set. That is not the whole story: on NVIDIA a lost device can first show up as vkGetSemaphoreCounterValue returning VK_SUCCESS with a counter of UINT64_MAX, and then the flag is never set and this pull request alone prints nothing. #1028 (which builds on this one) catches that case and adds the driver's fault report; @DesertGamer measured the same path on a fifth machine (#14).

The change (runtime/src/vulkan_backend.h, plus its test):

  • set_device_lost(flag, where) sets the flag with an exchange and, the first time for a device, prints one line on stderr: [rt] vulkan: the device was lost (<where>); its fences now read UINT64_MAX and device calls return DXGI_ERROR_DEVICE_REMOVED.
  • mark_device_lost() uses it, with an optional where (default: a Vulkan call returned VK_ERROR_DEVICE_LOST); every existing caller is unchanged. The dispatcher's two direct stores use it with their own where (vkWaitSemaphores and vkGetSemaphoreCounterValue in the fence dispatcher).
  • device_lost_reports counts the lines said in the process, for tests. Nothing else changes: the flag, the dispatcher wake-up and every return value behave as before.

Tested

Native Windows 11, MSVC 19.44, Ninja, RelWithDebInfo, on main a28927849 (merges cleanly on 42d705c85), RTX 4060 Laptop, NVIDIA 576.80, Vulkan SDK 1.4.363:

  • vk_fence_dispatcher_sync_test: case 3 now also checks one line from mark_device_lost() and none from a second call or from the dispatcher waking on the same flag; case 4 checks one line from the dispatcher's vkGetSemaphoreCounterValue path and none from a later mark_device_lost(). Passes.
  • d3d12_fence_device_lost_counter_test and d3d12_cross_device_validation_test, which lose devices on purpose, pass; the first prints the line once for each device it loses.
  • Mutation check: replacing the exchange with a plain store (a line on every call) fails vk_fence_dispatcher_sync_test at case 3.
  • gta6rt builds.

GPUs tested: NVIDIA GeForce RTX 4060 Laptop GPU, driver 576.80, Windows 11 (the three tests above).

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🔄 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/980 **Author:** [@CLHelper](https://github.com/CLHelper) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `runtime/device-lost-log` --- ### 📝 Commits (1) - [`5c1f77e`](https://github.com/ubiquitarianism/leonida/commit/5c1f77e1d4bafb3cba8c3e2037de28cb376f633e) vulkan: say once when the device is lost (RT-DEVICE-LOST-LOG) ### 📊 Changes **2 files changed** (+37 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_backend.h` (+21 -4) 📝 `runtime/test/vk_fence_dispatcher_sync_test.cpp` (+16 -2) </details> ### 📄 Description Claimed in the coordination issue as: RT-DEVICE-LOST-LOG (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7137184715) ### What and why When the layer's Vulkan device is lost, `VulkanContext::mark_device_lost()` and the fence dispatcher's two `VK_ERROR_DEVICE_LOST` paths only set the device's lost flag. From then on every fence reads `UINT64_MAX` and device calls return `DXGI_ERROR_DEVICE_REMOVED`, so the title takes its own device-removed path, and nothing in the log said that the device went first. On the retail boot that path is easy to misread. The title's frame wait gets the address of a fence's completed value (fence slot 12), spins on it, and when it reads `~0` it calls a fatal routine that ends in an `int3` at `game_scarlett_master.exe+0x2474606` (static reading of my own 1.0.2.1 copy: the wait at `+0x4fb0ad0`, `call +0x2474870` when the value is `-1`, the routine at `+0x2474500`). With `LEONIDA_SKIP_INT3` the title then runs on into reads of garbage addresses. In five runs of @DadaCap's `boot-prototype` on my machine, that `int3` and the access violations after it were the only visible stop. The fence values come from `GetCompletedValue`. Correction after review elsewhere: I first wrote here that the layer answers `UINT64_MAX` only once its lost flag is set. That is not the whole story: on NVIDIA a lost device can first show up as `vkGetSemaphoreCounterValue` returning `VK_SUCCESS` with a counter of `UINT64_MAX`, and then the flag is never set and this pull request alone prints nothing. #1028 (which builds on this one) catches that case and adds the driver's fault report; @DesertGamer measured the same path on a fifth machine (#14). The change (`runtime/src/vulkan_backend.h`, plus its test): - `set_device_lost(flag, where)` sets the flag with an exchange and, the first time for a device, prints one line on stderr: `[rt] vulkan: the device was lost (<where>); its fences now read UINT64_MAX and device calls return DXGI_ERROR_DEVICE_REMOVED`. - `mark_device_lost()` uses it, with an optional `where` (default: a Vulkan call returned `VK_ERROR_DEVICE_LOST`); every existing caller is unchanged. The dispatcher's two direct stores use it with their own `where` (`vkWaitSemaphores` and `vkGetSemaphoreCounterValue` in the fence dispatcher). - `device_lost_reports` counts the lines said in the process, for tests. Nothing else changes: the flag, the dispatcher wake-up and every return value behave as before. ### Tested Native Windows 11, MSVC 19.44, Ninja, RelWithDebInfo, on `main` `a28927849` (merges cleanly on `42d705c85`), RTX 4060 Laptop, NVIDIA 576.80, Vulkan SDK 1.4.363: - `vk_fence_dispatcher_sync_test`: case 3 now also checks one line from `mark_device_lost()` and none from a second call or from the dispatcher waking on the same flag; case 4 checks one line from the dispatcher's `vkGetSemaphoreCounterValue` path and none from a later `mark_device_lost()`. Passes. - `d3d12_fence_device_lost_counter_test` and `d3d12_cross_device_validation_test`, which lose devices on purpose, pass; the first prints the line once for each device it loses. - Mutation check: replacing the exchange with a plain store (a line on every call) fails `vk_fence_dispatcher_sync_test` at case 3. - `gta6rt` builds. GPUs tested: NVIDIA GeForce RTX 4060 Laptop GPU, driver 576.80, Windows 11 (the three tests above). AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:48 +01:00
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#1016
No description provided.