mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:30:52 +01:00
[PR #1742] [MERGED] runtime: unlock resource_mutex while compiling unbuilt pipelines #1757
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#1757
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/1742
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:fix/pipeline-compile-unlock-resources📝 Commits (2)
3ab657bruntime: unlock resource_mutex while compiling unbuilt pipelinesd33ada4runtime: fix test identifiers and preserve serial compile short-circuit📊 Changes
5 files changed (+706 additions, -205 deletions)
View changed files
📝
runtime/CMakeLists.txt(+10 -0)📝
runtime/src/vulkan_backend.h(+251 -188)📝
runtime/src/vulkan_replay.h(+78 -17)➕
runtime/test/replay_pipeline_compile_unlock_test.cpp(+291 -0)📝
runtime/test/replay_pipeline_compiles_test.cpp(+76 -0)📄 Description
Item ID:
RT-PIPELINE-COMPILE-UNLOCK-RESOURCESClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7160038060
Addresses finding: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157762911 (render thread stalled on
VulkanContext::remove_resource->resource_mutex_behind 2–5 s compute pipeline compiles at world start, tripping the title's hang watchdog)Root cause
VulkanContextpreviously guarded both resources (resources_,buffer_vas_,query_pools_,add_resource()/remove_resource()) and registered pipelines (pipelines_,graphics_pipelines_,pipeline_workers_,device_fault_->pipeline_names) under onestd::shared_mutex resource_mutex_.VulkanQueue::execute_now()(runtime/src/vulkan_backend.h) heldstd::shared_lock(resource_mutex_)acrossprepare()andbuild_pipelines()to keepPipelineStateobjects alive during compilation. Whenever a queue compiled unbuilt world shaders (2–5 s each invkCreateComputePipelines),VulkanContext::remove_resource()/add_resource()on the title's render thread blocked onstd::unique_lock(resource_mutex_), creating a lock convoy that also stalled other queues andVulkanPresenteruntil the hang watchdog fired.Changes
runtime/src/vulkan_backend.h:VulkanContext::pipeline_mutex_(std::shared_mutex) to guardpipelines_,graphics_pipelines_,pipeline_workers_, anddevice_fault_->pipeline_namesindependently ofresource_mutex_, keeping a strict lock hierarchy:state_mutex_->pipeline_mutex_->resource_mutex_->tracker_mutex_->submit_mutex_.VulkanQueue::execute_now()to holdpipeline_lockacrossprepare()/ compilation /emit(), always collect unbuilt pipelines viaPipelineCompiles(both withpipeline_workers_and in serial mode), and on pass 0 when!compiles.empty()retire uncommitted pass-0 helper state and releasetracker_lockandresource_lockbefore runningcompiles.build(...)underpipeline_lockalone. Pass 1 then re-acquiresresource_lockand re-prepares against current resources so no staleVkBuffer/VkImagehandle can survive a concurrent resource update.compiles.empty()).runtime/src/vulkan_replay.h:PipelineCompiles::lookup()/contains_ticket(), optionalpriorparameter toPipelineCompiles::build()andbuild_pipelines(), and sharedcheck_compiled_pipelines()so pass-1 re-preparation reuses prior outcomes (preventing doublebuild()calls or duplicateunresolved_atlogs on non-strict failed compute dispatches).runtime/test/replay_pipeline_compiles_test.cpp,runtime/test/replay_pipeline_compile_unlock_test.cpp,runtime/CMakeLists.txt:replay_pipeline_compiles_testwithprior_compiles_reusecovering pass-1 reuse of built and non-strict failed compute dispatches.replay_pipeline_compile_unlock_testverifying (both withPipelineWorkers(2)and serialpipeline_workers_ == nullptr) thatadd_resource(),remove_resource(), and a secondVulkanQueue::execute()complete while a slow compile is blocked inbuild(), thatremove_pipeline()safely waits onpipeline_mutex_until compilation ends, that concurrent resource replacement is picked up on pass 1 (vkCmdCopyBufferbinds the newVkBuffer), and that a non-strict failed compute dispatch invokesbuild()only once.Verification
Vulkan::Headersinstalled)python3 -I scripts/check_no_game_data.py runtime/src/vulkan_replay.h runtime/src/vulkan_backend.h runtime/test/replay_pipeline_compiles_test.cpp runtime/test/replay_pipeline_compile_unlock_test.cpp runtime/CMakeLists.txt: PASS.python3 -I tests/test_text_write_line_endings.py: 3/3 OK.runtime/src/vulkan_backend.h,runtime/src/vulkan_replay.h,runtime/test/replay_pipeline_compiles_test.cpp, andruntime/test/replay_pipeline_compile_unlock_test.cpprequireVulkan::Headers(not present on this macOS host) and rely on CI (replay_pipeline_compiles,replay_pipeline_compiles_strict,replay_pipeline_compile_unlock, and existingvk_queue_*/vk_presenter_synctests).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.