runtime: propagate device loss found by the retire-ticket progress query (OLD-6149) #408

Manually merged
github merged 1 commit from gh-pr/408/head into gh-pr/408/base 2026-11-26 08:58:24 +00:00
Owner

@⁠Len1k on GitHub · 2026-11-24 04:45 UTC · original
Len1k:old-6149-retire-ticket-device-loss → main · +17 −6 · 1 files · 1 commits · merged 2026-11-24 14:38 UTC

Carries over the fix from the deleted repository's PR #6149, which was not preserved under old-pr/. Commit 3a21e3aea481bb9f9d9bfe9360c5b972fb19f7bb in the abilliontokens/Leonida fork has the only change; this branch keeps it as-is (same diff, +17/−6, one file) on main d2cd6c0d.

Claimed in the coordination issue as: claiming: OLD-6149 (first reported there as a finding:).

What it fixes

VulkanContext::completed_retire_ticket() (runtime/src/vulkan_backend.h) queries each pending ticket's timeline semaphore with vkGetSemaphoreCounterValue but treats every non-VK_SUCCESS result as "not completed yet":

return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value;

When the driver returns VK_ERROR_DEVICE_LOST here, that result is discarded: the context is never marked lost and the queue goes on to acquire, record and submit against a lost device. vk_queue_query_sync then fails at line 468: progress_loss_ok ("progress counter device loss NOT propagated"). Every other counter query in the layer already calls mark_device_lost(); this one was the exception. The fix records the VkResult, sets a lost flag, calls mark_device_lost() outside submit_mutex_ (as submit() does — notifying the fence dispatcher can run callbacks that submit again) and returns 0 so nothing is retired against a lost device.

Tested on RDNA1 (RX 5700 XT, gfx1010)

AMD Radeon RX 5700 XT (Navi 10, PCI 1002:731f), AMD proprietary 26.11.2, Windows 11 Pro 10.0.26200, subgroup 32..64. Built with llvm-mingw 23.1.6 (static), CMake 4.4.5, llvm-mc 23.1.6, SPIRV-Tools v2026.4. Synthetic tests only, no game files.

  • On main at a0e1876 (the function is byte-identical there and at d2cd6c0d): vk_queue_query_sync_test exits 1 in 5/5 direct runs and 4/5 ctest runs; full ctest 61/64 passed, this one failure, 2 skipped.
  • With this hunk: 5/5 direct and 5/5 ctest pass; full ctest 62/64 passed, 0 failed, 2 skipped (shader_library_corpus, vk_sync_validation); full run_gpu_tests.py unchanged at 213/241 passed, 28 skipped, 0 failed.
  • The earlier #6149 thread reported the same on RDNA2, RDNA3 and RTX, so it is not card-specific.

AI-assisted (OpenCode). The commit keeps abilliontokens' authorship and message; only its parent is the current main.

**@⁠Len1k** on GitHub · 2026-11-24 04:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/408) `Len1k:old-6149-retire-ticket-device-loss` → `main` · +17 −6 · 1 files · 1 commits · merged 2026-11-24 14:38 UTC Carries over the fix from the deleted repository's PR #6149, which was not preserved under `old-pr/`. Commit `3a21e3aea481bb9f9d9bfe9360c5b972fb19f7bb` in the `abilliontokens/Leonida` fork has the only change; this branch keeps it as-is (same diff, +17/−6, one file) on `main` `d2cd6c0d`. **Claimed in the coordination issue as:** `claiming: OLD-6149` (first reported there as a `finding:`). ### What it fixes `VulkanContext::completed_retire_ticket()` (`runtime/src/vulkan_backend.h`) queries each pending ticket's timeline semaphore with `vkGetSemaphoreCounterValue` but treats every non-`VK_SUCCESS` result as "not completed yet": ```cpp return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value; ``` When the driver returns `VK_ERROR_DEVICE_LOST` here, that result is discarded: the context is never marked lost and the queue goes on to acquire, record and submit against a lost device. `vk_queue_query_sync` then fails at `line 468: progress_loss_ok` ("progress counter device loss NOT propagated"). Every other counter query in the layer already calls `mark_device_lost()`; this one was the exception. The fix records the `VkResult`, sets a `lost` flag, calls `mark_device_lost()` **outside** `submit_mutex_` (as `submit()` does — notifying the fence dispatcher can run callbacks that submit again) and returns 0 so nothing is retired against a lost device. ### Tested on RDNA1 (RX 5700 XT, gfx1010) AMD Radeon RX 5700 XT (Navi 10, PCI 1002:731f), AMD proprietary 26.11.2, Windows 11 Pro 10.0.26200, subgroup 32..64. Built with llvm-mingw 23.1.6 (static), CMake 4.4.5, llvm-mc 23.1.6, SPIRV-Tools v2026.4. Synthetic tests only, no game files. - On `main` at `a0e1876` (the function is byte-identical there and at `d2cd6c0d`): `vk_queue_query_sync_test` exits 1 in **5/5** direct runs and **4/5** `ctest` runs; full `ctest` 61/64 passed, this one failure, 2 skipped. - With this hunk: **5/5** direct and **5/5** `ctest` pass; full `ctest` **62/64 passed, 0 failed, 2 skipped** (`shader_library_corpus`, `vk_sync_validation`); full `run_gpu_tests.py` unchanged at **213/241 passed, 28 skipped, 0 failed**. - The earlier #6149 thread reported the same on RDNA2, RDNA3 and RTX, so it is not card-specific. AI-assisted (OpenCode). The commit keeps `abilliontokens`' authorship and message; only its parent is the current `main`.
VulkanContext::completed_retire_ticket() queried each pending submission's
timeline semaphore with vkGetSemaphoreCounterValue but treated every
non-VK_SUCCESS result as "not completed yet". A VK_ERROR_DEVICE_LOST seen
there was swallowed, so the context was never marked lost and the queue went
on to acquire, record and submit new command buffers.

Every other counter query in the layer (the queue's own progress query in
VulkanQueue::completed(), VulkanFence::completed(), the wait and submit
paths) already calls mark_device_lost() on VK_ERROR_DEVICE_LOST; this one
was the exception.

acquire() runs completed_retire_ticket() before recycle_finished()'s
completed(), so whichever query runs first observes the loss. When the
retire-ticket query is the first to see it, it consumes the error and the
queue's own query then reads a healthy counter. That is why
vk_queue_query_sync's section 5 (00832c18) failed on the RX 9070 XT /
AMD 26.11.2 but passed on NVIDIA: the retire ticket is still pending there,
so its query runs first.

Mark the context lost here too, outside submit_mutex_ as submit() does, and
report no completed ticket so nothing is retired against a lost device.

Fixes D3D-599.

(cherry picked from commit 3a21e3aea481bb9f9d9bfe9360c5b972fb19f7bb)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:58:22 +00:00
github manually merged commit a44e66e9a3 into gh-pr/408/base 2026-11-26 08:58:24 +00:00
Author
Owner

@⁠LewisCodesWebsites on GitHub · 2026-11-24 11:53 UTC · original

Tested a44e66e9a (cherry-picked onto main 21625bca8) on AMD Radeon 660M (RDNA2 iGPU), Adrenalin 32.0.21045.1000, Windows 11 26200, MSVC 2026: vk_queue_query_sync passes (on main it fails at line 468, "progress counter device loss NOT propagated"). AI-assisted.

**@⁠LewisCodesWebsites** on GitHub · 2026-11-24 11:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/408#issuecomment-7130689373) Tested a44e66e9a (cherry-picked onto main 21625bca8) on AMD Radeon 660M (RDNA2 iGPU), Adrenalin 32.0.21045.1000, Windows 11 26200, MSVC 2026: `vk_queue_query_sync` passes (on main it fails at line 468, "progress counter device loss NOT propagated"). AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.