runtime: unlock resource_mutex while compiling unbuilt pipelines #1742
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1742
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1742/head"
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?
@IlyassRS3 on GitHub · 2026-11-25 10:47 UTC · original
IlyassRS3:fix/pipeline-compile-unlock-resources→main· +706 −205 · 5 files · 2 commits · merged 2026-11-25 21:25 UTCItem ID:
RT-PIPELINE-COMPILE-UNLOCK-RESOURCESClaim: #1608
Addresses finding: #1608 (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).@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 10:47 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@abnalstlll-byte on GitHub · 2026-11-25 10:57 UTC · original · approved these changes
### Clean-Room & Technical Verification
main(bcaa13dad) is 100% clean with zero merge conflicts.check_no_game_data.pyclean).pipeline_mutex_(std::shared_mutex) to protect pipeline registry and compilation tasks, decoupling them fromresource_mutex_.VulkanQueue::execute_now(), releasesresource_lockandtracker_lockbefore executing long-runningcompiles.build(...)passes, completely unblocking render-thread resource registration (add_resource/remove_resource) and avoiding lock convoys that previously triggered the title's hang watchdog during world start shader compilation.resource_lockand re-prepares submissions against up-to-date resources while leveraging prior compilation outcomes inPipelineCompiles, preventing duplicate compilations or spurious failure logs.compiles.empty()).runtime/test/replay_pipeline_compile_unlock_test.cppandreplay_pipeline_compiles_test.cpp.LGTM! Approved.
@adrianmjim on GitHub · 2026-11-25 12:00 UTC · original
Built
5238021a2applied onto its basebcaa13dad(the current head92a2a93c5is a rebase of it, and the two test compile errors below are still in it) on Windows 11 build 26300 with VS 2022 (MSVC 19.44) RelWithDebInfo, and ran it on an AMD Radeon RX 7900 XT (driver 32.0.32029.2010). No game files.1. The two tests don't compile. The runtime itself builds, but the tests stop with:
QueueKindis nested inVulkanQueue(vulkan_backend.h,class VulkanQueue { enum class QueueKind ... }), andReplayResulthasunresolved_resource, notunresolved. With those two renames (VulkanQueue::QueueKind::compute,ReplayResult::unresolved_resource), everything builds. All the results below are with those renames applied locally.2. The new tests pass.
replay_pipeline_compile_unlockpasses 5 of 5, andreplay_pipeline_compilesandreplay_pipeline_compiles_strictpass too. So dovk_queue,vk_queue_query_sync,vk_presenter_sync,vk_queue_constructor_oom,d3d12_pipeline_workers_eager,d3d12_stub_pipelines,vulkan_device_faultandreplay_cpu_bench_selftest.3. A regression:
d3d12_pipeline_workersfails, 3 of 3. On the base it passes 3 of 3, built from the same tree with the PR taken out.That is
refused_graphics, serial case (threads "0"). When the driver refuses the 5th graphics compile, the base stops there: five creates, thenunsupported. With this PR,execute_now()always collects the unbuilt pipelines throughPipelineCompiles, also without workers, so a compile of every one of them is attempted before the refusal is acted on.So in serial mode a refused compile no longer cuts the pass short. The rest of the submission's pipelines are compiled first, as the workers path already did, so a failing submission takes longer before it is reported unsupported; compute pipelines can take 2-5 s each, per the description. The pipelines that did build are kept, so this moves the work earlier more than it adds work, but it is still a change for the serial path.
The description says collecting through
PipelineCompileswithout workers is intended. If the resulting refusal behaviour is intended too, the serial expectations inrefused_graphicsneed updating: line 688 (5 creates), and probably line 692 (kPipelines - 4on the retry), which the failed check at 688 kept from running. If not, the serial path should stop at the first refused compile as before.Whole
ctest -j 6(with the two renames): 382 of 386 pass or skip. The failures ared3d12_pipeline_workers(above), plusd3d12_texture_tiles,d3d12_clearandd3d12_geometry_views, which fail on this card onmaintoo.@IlyassRS3 on GitHub · 2026-11-25 12:16 UTC · original
Thank you @adrianmjim for the MSVC / RX 7900 XT build and
ctestrun — super helpful!Both items are now fixed and pushed (rebased on
main0d80bc5df):VulkanQueue::QueueKind::computeinreplay_pipeline_compile_unlock_test.cppand renamedReplayResult::unresolved->ReplayResult::unresolved_resourcein bothreplay_pipeline_compile_unlock_test.cppandreplay_pipeline_compiles_test.cpp.d3d12_pipeline_workers::refused_graphicsregression: addedPipelineCompiles::build_serial()/build_pipelines_serial()and routed the!context_.pipeline_workers_path through it. Serial mode still releasesresource_mutex_andtracker_mutex_across compilation, but compiles in command order and stops immediately at the first fatal refusal (a failed draw, failed indirect dispatch, or failed dispatch understrict_replay()), preservingrefused_graphics's 5-create /kPipelines - 4serial expectations without spending extra compile time after a fatal refusal. Also addedserial_stops_at_refused_draw()toreplay_pipeline_compiles_test.cpp.@aslan2142 on GitHub · 2026-11-25 21:25 UTC · original
Thank you, @IlyassRS3: the render thread no longer waits behind shader compiles for
resource_mutex_.mainf0cb45482(which already has #1832, #1896, #1814, #1759 and #1987). No test went from pass to fail.mainwithout this change too.replay_pipeline_compile_unlockpasses on both devices.main7b5232875+d33ada434: it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).
@GGandCo on GitHub · 2026-11-25 21:46 UTC · original
Intel integration verification of the merged fix: Windows 11, MSVC RelWithDebInfo, Intel UHD Graphics / i5-1334U, driver 32.0.101.6314. Integrated main
36572941cinto an existing private runtime tree; no changes to this PR's logic were needed.14/14 targeted tests passed with LEONIDA_VK_VALIDATION=1: replay_pipeline_compile_unlock, replay_pipeline_compiles and strict, d3d12_pipeline_workers and eager, vk_queue, vk_queue_query_sync, vk_presenter_sync, vk_queue_constructor_oom, vulkan_device_fault, xbox_bvh_builder, d3d12_unbound_tsharp_rules, d3d12_compute, and d3d12_m2_textured. This includes the serial-refusal behavior raised in the earlier review.
This is a targeted combined-tree result, not a full Windows-suite or playability claim. No game data included. AI-assisted with OpenAI Codex.