Skip to content

Runtime: propagate device loss found by the retire-ticket progress query (D3D-599) - #6149

Open
abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:d3d599-progress-counter
Open

abilliontokens wants to merge 1 commit into
ItsNotRexed:mainfrom
abilliontokens:d3d599-progress-counter

Conversation

@abilliontokens

Copy link
Copy Markdown
Contributor

D3D-599 — vk_queue_query_sync progress-counter device loss not propagated on AMD

Fixes board item D3D-599 (#313): vk_queue_query_sync failed on an RX 9070 XT (AMD 26.11.2, Windows) at main 561b65a8 with progress counter device loss NOT propagated (the check 00832c18 added). It passed at 3faac557.

AI-assisted (omp orchestrator).

Root cause (our code, not the driver)

VulkanContext::completed_retire_ticket() queries each pending submission's timeline semaphore with vkGetSemaphoreCounterValue through RetireTickets::completed, but treated every non-VK_SUCCESS result as "this ticket has not completed yet":

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

A VK_ERROR_DEVICE_LOST seen there was swallowed — the context was never marked lost, so the queue went on to acquire, record and submit new command buffers. Every other counter query in the layer already propagates it: VulkanQueue::completed() (the queue's own progress semaphore), VulkanFence::completed(), and the wait/submit paths all call mark_device_lost() on VK_ERROR_DEVICE_LOST. This one was the exception.

VulkanQueue::acquire() runs completed_retire_ticket() before recycle_finished()'s completed(), so whichever query runs first observes the loss. When the retire-ticket query is first, it consumes the error and the queue's own query then reads a healthy counter. That is why the failure is driver/timing dependent: on the AMD driver the retire ticket is still pending at that point, so its query runs first; on NVIDIA the queue's own completed() happens to observe it. It is not AMD-specific driver behaviour — the layer dropped the error on any driver where the ordering went this way.

Fix

Mark the context lost when the retire-ticket query returns VK_ERROR_DEVICE_LOST, and report no completed ticket so nothing is retired against a lost device. mark_device_lost() is called outside submit_mutex_, matching submit()'s existing pattern (notifying the fence dispatcher can run callbacks that submit). No test change: vk_queue_query_sync's section 5 (added by 00832c18) is the regression test and now passes.

Relation to other open PRs

Tested

  • Commit: 3a21e3aea (head of d3d599-progress-counter, based on main 561b65a8)
  • Windows 11, MSVC 19.44 / Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0
  • AMD: AMD Radeon RX 9060 XT, AMDVLK (Vulkan driver 2.0.373)
  • NVIDIA: NVIDIA GeForce RTX 5060 Ti, driver 621.24

Commands and results:

# build (VS dev env)
cmake -S runtime -B C:\Work\D3D599\build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
ninja -C C:\Work\D3D599\build vk_queue_query_sync_test

# AMD (RX 9060 XT) — before fix: "progress counter device loss NOT propagated", exit 1
#                    — after fix:
./vk_queue_query_sync_test.exe
#   queue/query sync: injected nonfatal execute=0, device-loss execute=9, context_lost=1, interceptions=2
#   queue/query sync: progress counter device loss marks context and rejects work
#   vk_queue_query_sync_test: ok            (exit 0)
ctest -R "^vk_queue_query_sync$" --output-on-failure
#   1/1 Test #113: vk_queue_query_sync ... Passed

# NVIDIA (RTX 5060 Ti) — after fix: identical GREEN
#   device-loss execute=9, context_lost=1, interceptions=2 ... ok (exit 0)
ctest -R "^vk_queue_query_sync$" --output-on-failure
#   1/1 Test #113: vk_queue_query_sync ... Passed

# related sync tests, both GPUs:
ctest -R "^(vk_queue|vk_queue_query_sync|vk_fence_dispatcher_sync|vk_presenter_sync)$" --output-on-failure
#   AMD:    4/4 Passed (vk_sync_validation skipped, no validation layer)
#   NVIDIA: 4/4 Passed

Also verified the unfixed code on NVIDIA passes (the bug is ordering-dependent, not NVIDIA-safe by design) and the unfixed code on AMD fails, confirming the layer — not the driver — dropped the error.

No game files, no game data.

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 (00832c1) 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.
@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 3a21e3ae on the GPU where vk_queue_query_sync fails on main: Radeon 610M (RDNA2, AMD 26.11.2 / 32.0.21045.29003), plus an RTX 5070 Ti Laptop (NVIDIA 621.24). Windows 11 26200, MSVC 14.44 RelWithDebInfo (full build), Vulkan SDK 1.4.363.0. Pass: it fixes the AMD failure.

AI-assisted (Claude Code). Synthetic tests only, no game files.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3a21e3aea481bb9f9d9bfe9360c5b972fb19f7bb on Windows 11, MSVC 19.44, Vulkan SDK/layer 1.4.363, RTX 5070 Ti.

  • cmake -S runtime -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON; built and ran vk_fence_dispatcher_sync_test and vk_queue_query_sync_test.
  • Both exit 0 (fence dispatcher device-loss cases ok; queue/query progress-loss case "marks context and rejects work"). git diff --check clean.
  • Logic is correct: DEVICE_LOST from vkGetSemaphoreCounterValue is recorded by reference under the lock, mark_device_lost() runs outside submit_mutex_, and 0 is returned so the ticket is not mistaken for "incomplete".
  • Test gap: neither run exercises completed_retire_ticket itself returning DEVICE_LOST; the existing tests cover the queue acquire/fence-dispatch paths. A one-case mock test would lock this in.
  • Independent of 6107 (same theme, different function); no stack.

Verdict: mergeable; test gap only. First-frame: if the earliest submissions report DEVICE_LOST, the context is now marked lost instead of polling incomplete tickets.

@PeterGrieffindor

Copy link
Copy Markdown

Tested 3a21e3ae on the card where this was found: AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (LLPC), Windows driver 32.0.32029.2010, Windows 11 Pro build 26300, MSVC 14.51, scripts\build_runtime.ps1 -FetchSdl3: pass, it fixes the failure here. No game files.

Build vk_queue_query_sync alone Its last lines
main 561b65a8 Failed, 2 of 2 injected nonfatal execute=0, device-loss execute=0, context_lost=0, interceptions=2, then progress counter device loss NOT propagated (line 468: progress_loss_ok)
this head Passed, 5 of 5 injected nonfatal execute=0, device-loss execute=9, context_lost=1, interceptions=2, then progress counter device loss marks context and rejects work

AI-assisted (Claude Mythos 5.2).

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 3a21e3a on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • Built the full runtime (MSVC 19.44, Ninja, RelWithDebInfo). vk_queue_query_sync_test exits 0 in 3 of 3 runs with LEONIDA_VK_VALIDATION=0 and 3 of 3 with =1; it prints progress counter device loss marks context and rejects work. vk_queue_test and vk_fence_dispatcher_sync_test exit 0 with validation 0 and 1.
  • Negative control: runtime/src/vulkan_backend.h reverted to merge base 561b65a8, same test source. Validation 0: exit 1 in 3 of 3 runs with progress counter device loss NOT propagated (context_lost=0). Validation 1: exit 1 in 2 of 3 runs, exit 0 in 1. So the failure on this GPU is reproduced on the base and fixed by the PR.
  • ctest -R "queue|fence|d3d12_vulkan_device|d3d12_com|vk_" -E sparse_queue_family with validation 1: 31 of 33 pass. vk_pipeline_check_cli failed and d3d12_queue_wait timed out under load. Both pass when run alone (2 of 2).
  • Not done: no other GPU, no D3D12 debug layer.

AI-assisted (Claude Code).

Kam471 added a commit to Kam471/Leonida that referenced this pull request Nov 23, 2026
The kit now ships gta6rt-final.exe (base ba4b0bd + ItsNotRexed#3777 + ItsNotRexed#5867/ItsNotRexed#5808/ItsNotRexed#5851 + ItsNotRexed#6230 @ 255efe0 + ItsNotRexed#6107/ItsNotRexed#6149 + runtime layer 7bce00b + ItsNotRexed#6351 XMemTransferMemory). Prefer it, fall back to gta6rt-final-pre-xmem.exe, then to the trace-only gta6rt.exe; verify the selected binary's hash and the five strings that decide capture and the Series startup path. Add the discover-presentx-slot.ps1 helper and its launch-exeday.ps1 bin caveat.
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.

5 participants