mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:55:52 +01:00
[PR #1836] runtime: fix deadlock, dropped timestamps, and stop races in GPU label Completions #1848
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1848
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1836
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-gpu-labels-completions-safety📝 Commits (1)
8de0dc9runtime: fix deadlock, dropped timestamps, and stop races in GPU label Completions📊 Changes
3 files changed (+586 additions, -58 deletions)
View changed files
📝
runtime/CMakeLists.txt(+13 -0)📝
runtime/src/vulkan_gpu_labels.h(+170 -58)➕
runtime/test/gpu_label_completions_test.cpp(+403 -0)📄 Description
Item ID:
RT-GPU-LABELS-COMPLETIONS-SAFETYClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162941588
Summary
Fixes a reproducible lock-order deadlock, dropped GPU timestamp queries, unnecessary query-pool/timestamp commands for non-timestamp labels, and shutdown races in
leonida::label::Completions(runtime/src/vulkan_gpu_labels.h):Completions::mutex_<->VulkanContext::resource_mutex_deadlock inCompletions::run()run()previously heldCompletions::mutex_acrosspublish(b)->store_value()->value_sink::arena()->write_arena_value()->VulkanContext::is_sparse_va()(which acquiresstd::shared_lock(resource_mutex_),runtime/src/vulkan_backend.h:1915) andkernel_writes::begin_write().VulkanQueue::execute()holdsstd::shared_lock(resource_mutex_)while callinggpu_labels_.begin_record()andgpu_labels_.record()(which acquireCompletions::mutex_). Any concurrent resource registration/destruction waiting onstd::unique_lock(resource_mutex_)blocks new shared readers and deadlocks all three threads.run()now swapspending_into a local batch list, releasesmutex_before pollingvkGetFenceStatusand runningpublish(), then re-acquiresmutex_to accumulateerrors_/expired_, recycle completed batches, and preserve FIFO ordering of still-pending batches before newly arrived ones (looping immediately without sleeping whenclosing_becomes true or new batches arrived while unlocked).VK_QUERY_RESULT_WAIT_BITfor signaled timestamp labelsvkGetFenceStatus == VK_SUCCESS, Vulkan allowsvkGetQueryPoolResultswithoutVK_QUERY_RESULT_WAIT_BITto returnVK_NOT_READY, which previously incrementederrors_and silently dropped the timestamp label. Because every recorded timestamp query in the batch has already executed once its fence signals, passingVK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BITsafely waits for writeback visibility without risk of hanging.clock != 1labelsrecord()unconditionally allocated aVkQueryPooland emittedvkCmdResetQueryPool+vkCmdWriteTimestamp(BOTTOM_OF_PIPE)even forclock == 0(immediate value) andclock == 2(system QPC) labels that never read a Vulkan query. Storing a per-entry dense query index (no_queryforclock != 1) avoids query-pool bloat, unnecessary pipeline stalls, and invalid timestamp commands on queue families withtimestampValidBits == 0.stop(),~Completions(),initialize())stopping_undermutex_so concurrentstop(dev)calls wait cleanly for teardown to finish instead of racing onworker_.join()/vkDestroyFence/vkDestroyQueryPool.record()andsubmit_fence()calls oncestopping_is set (beforevkDeviceWaitIdle), moveworker_out under lock before joining, readdevice_under lock in~Completions(), and resetdevice_ifstd::threadconstruction throws ininitialize().Tests
Added pure-CPU mock-Vulkan test
runtime/test/gpu_label_completions_test.cpp(registered as CTestgpu_label_completionsunderif(TARGET Vulkan::Headers)inruntime/CMakeLists.txt).Verified locally on macOS arm64 (Apple Clang) with the pinned Khronos
Vulkan-Headers(6802bb4733b63ed5efd3adb308a6c885ef180ea1):gpu_label_completions_test: PASS under ASan+UBSan, PASS under TSan (0 races), PASS under-O2(3 consecutive runs),-Wall -Wextra -Werror -Wno-missing-field-initializers.main'sruntime/src/vulkan_gpu_labels.h: Test 1 reproducibly deadlocks (4 s timeout under TSan).replay_pipeline_compiles_test.cppagainst the updated header.python3 -I scripts/check_no_game_data.py ...andpython3 -I tests/test_text_write_line_endings.pypass.Disclosure
gpu_label_storeandxbox_gpu_label_completionrely on CI / reviewers)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.