Skip to content

vulkan: say once when the device is lost (RT-DEVICE-LOST-LOG) - #980

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
CLHelper:runtime/device-lost-log
Nov 25, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
CLHelper:runtime/device-lost-log

Conversation

@CLHelper

@CLHelper CLHelper commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-DEVICE-LOST-LOG (#14 (comment))

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)

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 a title takes its
own device-removed path (on the retail boot an int3 at game_scarlett_master.exe+0x2474606, reached from its frame wait
reading a fence's completed value as ~0), and nothing in the log said the device had gone first.

set_device_lost() sets the flag with an exchange and, the first time for a device, prints one stderr line saying where
the loss was seen. mark_device_lost() takes that place as an optional argument; the dispatcher passes its own two.
device_lost_reports counts the lines for tests.

Tests: vk_fence_dispatcher_sync_test cases 3 and 4 check one line per device, from mark_device_lost() and from the
dispatcher's vkGetSemaphoreCounterValue path, and none from a later call on the same device.

AI-assisted.
@KernelSmoker

Copy link
Copy Markdown
Contributor

Test note for my approval above: reviewed current head 5c1f77e1d4bafb3cba8c3e2037de28cb376f633e. The first transition of the per-context lost flag is reported once via atomic exchange; later dispatcher/context paths do not emit duplicate lines. Both explicit mark and dispatcher counter-error paths assert once-only behavior. Built vk_fence_dispatcher_sync_test in a disposable Fedora 45 Vulkan-tools image; CTest: 1/1 passed (0.32 s). The container exposed llvmpipe, so this verifies the test path with a software device; it does not establish RTX 3090 execution or hardware device-loss behavior. git diff --check passed. Hosted checks were pending at review time.

@KernelSmoker

Copy link
Copy Markdown
Contributor

Follow-up to my earlier software Vulkan run: I built the same vk_fence_dispatcher_sync_test target in the disposable Fedora 45 image, then ran the executable on the host with the NVIDIA x86_64 Vulkan ICD selected. It reported NVIDIA GeForce RTX 3090 (driver 620.73.04) and all six fence-dispatcher scenarios passed, including the once-only report assertions for synthetic context-mark and vkGetSemaphoreCounterValue device-loss paths. This exercises the real NVIDIA Vulkan device setup; it does not induce a physical GPU failure or use game data.

@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: RT-DEVICE-LOST-LOG: when the device is lost, the layer prints one stderr line per device. An atomic exchange keeps the context path and the dispatcher path from both printing. KernelSmoker approved it (llvmpipe and RTX 3090).

Why it's good: vk_fence_dispatcher_sync, vk_queue and vk_queue_query_sync pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 0f98d19, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main 507029d: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main 9c5e706: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

@QemmHD
QemmHD merged commit 2dabfc9 into ProjectLeonida:main Nov 25, 2026
7 of 13 checks passed
quartz-heron-58 added a commit to quartz-heron-58/leonida that referenced this pull request Nov 25, 2026
Main now has its own device-fault report (LEONIDA_DEVICE_FAULT=1, from ProjectLeonida#984)
and ProjectLeonida#980's device-lost line, so this branch's vulkan_device_fault.h, its
report code and vk_device_fault_test are dropped in favour of main's.

What stays is the case main does not cover: a loss the driver shows only as
a timeline counter of UINT64_MAX. VulkanFence::completed() then asks
vkDeviceWaitIdle through observe_result, so main's report runs, and marks
the device lost when that returns VK_ERROR_DEVICE_LOST.
vk_fence_lost_by_counter_test is adapted to main's reporter.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants