Skip to content

Runtime: propagate queue progress counter device loss - #4501

Open
pmilewsskiedu-gif wants to merge 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/vulkan-queue-progress-device-loss-20261122
Open

pmilewsskiedu-gif wants to merge 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/vulkan-queue-progress-device-loss-20261122

Conversation

@pmilewsskiedu-gif

Copy link
Copy Markdown
Contributor

Independent coordinator claim posted before production changes: #4421 (comment)

Defect and correction

Unmodified main 03b09a086592a197db64d91655c6e65c30764d96 ignores VkResult from vkGetSemaphoreCounterValue in VulkanQueue::completed() (queue's internal submission-progress timeline). The returned counter is undefined on failure; a synthetic VK_ERROR_DEVICE_LOST with deliberately bogus returned counter 999 was treated as progress, the shared VulkanContext remained healthy, and VulkanQueue::execute accepted and submitted more commands despite the reported device loss. This differs from PR #4445, which fixes VulkanFence::completed() exposed by ID3D12Fence::GetCompletedValue; this PR fixes the distinct internal command-buffer reuse and sparse submit path.

Now the progress query checks the VkResult. It returns a conservative zero completed ticket on errors (never retires/reuses in-flight resources with undefined counter data); if DEVICE_LOST, it calls existing VulkanContext::mark_device_lost() to notify waiters. acquire() rechecks device loss after querying completion and refuses command-buffer reuse/allocation, and sparse submission rechecks after its own progress query. A transient VK_ERROR_OUT_OF_HOST_MEMORY leaves the context healthy; it does not manufacture progress or reject subsequent queue work.

Identical original-main-red / patched-green synthetic regression

Extended existing runtime/test/vk_queue_query_sync_test.cpp with a narrowly targeted one-shot Vulkan proc interceptor for the caller thread. The test drains outstanding retire tickets before issuing VulkanQueue::execute, so the injection reaches the queue's actual progress query, not the shared global-retirement query. It runs a transient OOM counter error followed by a DEVICE_LOST counter error, each with bogus output 999; no injected errors reach the actual ICD. Existing query-concurrency, pending wait and multi-queue stress scenarios still execute before this check. Baseline and patch same test source, SHA256 1C568CE1965C0D42A462036A31CD44A78A588229174EE73EBA2F50B0FCD85012, retained in test-only detached LeonidaQueueProgressLossBaseline20261122 and patched isolated worktree.

  • Original main RED on actual RTX 4060 Ti with LEONIDA_VK_VALIDATION=1: transient execute=success (0), device-loss execute=success (0), context_lost=0, 2 synthetic interceptions; test prints progress counter device loss NOT propagated, exit 1. All existing query tests run; test ensures normal query-pool cleanup before the negative verdict, avoiding artificial validation-leak warnings.
  • Patched GREEN: transient execute=success (0), loss execute=unsupported (9), context_lost=1, 2 synthetic interceptions; test prints marks context and rejects work, exit 0, zero validation errors.
  • MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0: vk_queue_query_sync, vk_command_replay, d3d12_queue_wait, d3d12_fence_timing 4/4 PASS (5.05s); new fault-injection test 12/12 consecutive repeats PASS (3.41s); git diff --check clean.

Limits and disclosure

These are synthetic VkResult faults, NOT genuine RTX driver device-loss events. This PR does not introduce native WARP semantics for Vulkan-internal queue progress (not a native D3D12 API). No full suite or other Vulkan vendors tested. No authentic GTA VI execution (game_scarlett_master.exe unavailable), proprietary game data or DRM bypass. Original synthetic tests and source only; AI-assisted implementation and validation. Head commit 00832c18cd3e429d7d9357466a9514be4101dfe1. Please review; I will not self-merge.

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

Built vk_queue_query_sync_test at 00832c18 and ran it on Windows 11: vk_queue_query_sync_test: ok, exit 0. It reports:

  • remove_query_pool serialized with QueryReplay::commit ok;
  • cross-queue QueryReplay::plan serialized with commit ok;
  • pending Wait() preserved across a failed vkQueueSubmit ok;
  • concurrent multi-queue query stress ok;
  • injected nonfatal execute=0, device-loss execute=9, context_lost=1, interceptions=2;
  • progress counter device loss marks context and rejects work.

No blocking issue.

@SphyserX

Copy link
Copy Markdown

Tested 00832c1 on Arch Linux (in a VM), GCC, Ninja, RelWithDebInfo, Mesa llvmpipe (LLVM 23.1.5): pass.

  • vk_queue_query_sync passes. Rebuilt with main's runtime/src/vulkan_backend.h and the PR's test, it fails as described: injected nonfatal execute=0, device-loss execute=0, context_lost=0, interceptions=2 and then progress counter device loss NOT propagated.
  • Full Linux CTest on the PR: 48 of 48 pass (shader_library_corpus and vk_sync_validation skipped, as on main).
  • Code read: in VulkanQueue, completed() is only called by acquire() and the two sparse-bind paths, never in a wait loop. So returning 0 on a failed query can't spin: on a transient error acquire() just allocates a fresh command buffer instead of reusing one, and after DEVICE_LOST it now returns nullptr before touching the slots.

@mrbean56

Copy link
Copy Markdown

Tested 00832c18cd on AMD Radeon RX 7800 XT (RADV NAVI32, Mesa 26.x, Vulkan 1.4.309), Linux: pass, negative control red.

  • Built vk_queue_query_sync_test and ran it on the GPU: OK. New line: progress counter device loss marks context and rejects work; the injected counters read nonfatal execute=0, device-loss execute=9, context_lost=1, interceptions=2.
  • Negative control, same test source with 03b09a08's runtime/src/vulkan_backend.h: exit 1, progress counter device loss NOT propagated, and the counters read device-loss execute=0, context_lost=0 — the test measures the propagation, not just the absence of a crash. The pre-existing cross-queue, Wait() and stress cases pass in both, so the change is additive.
  • The three call sites matter and are all covered: completed() now returns 0 on a failed timeline query and marks the context lost; acquire_command_buffer() re-checks after the drain so a lost device cannot hand out a slot; submit() re-checks after collect_bindings so no submit is recorded against a lost device. Returning 0 rather than the stale done is the safe direction for a retirement ticket — nothing is retired early, and the retirery path bails out on the lost context anyway.

No game data. AI-assisted.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 00832c18 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • vk_queue_query_sync passes.
  • ctest: 145 passed, 10 skipped, 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main 03b09a08.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 00832c1 merged with main 03b09a0 (already up to date) on native Windows 11, MSVC 14.51, full runtime/ build: pass on NVIDIA GeForce RTX 4080 SUPER and on Intel UHD 770 (driver 32.0.101.6129).

  • ctest -R vk_queue: vk_queue_query_sync passed (NVIDIA). The test run directly on both GPUs ends injected nonfatal execute=0, device-loss execute=9, context_lost=1, interceptions=2 / progress counter device loss marks context and rejects work / vk_queue_query_sync_test: ok.
  • Negative control: runtime/src/vulkan_backend.h from main with the PR's test: fails at progress_loss_ok (device-loss execute=0, context_lost=0, progress counter device loss NOT propagated).
  • Read the diff: the injected failure only fires on the test's own thread, so the nonfatal case (VK_ERROR_OUT_OF_HOST_MEMORY) shows the queue stays usable and the failed query returns 0 so no resource is retired off it. I did not run it under a validation layer beyond what the test itself enables.

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.

6 participants