fix(agc): build a replayed compute pipeline once when a dispatch races it #12657
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12657"
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?
Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-10-29T00:35:12Z.
What
VulkanDevice::ReplayComputePipelinecheckedcomputePipelinesandcomputePipelinesBuildingbut never registered its own build incomputePipelinesBuilding. A dispatch throughcomputePipeline()while a journal replay worker was compiling the same pipeline found neither entry and compiled it again, and one of the two results was thrown away. The replay now registers a promise incomputePipelinesBuildingbefore it builds, the same protocolcomputePipeline()already uses. A concurrent dispatch waits for the replay's pipeline instead of building its own, and a failed build erases the entry and passes the exception to waiters.A dispatch that finds the replay's build in progress now waits for it instead of compiling its own copy. The wait is safe:
#5925's ahead builds call
ReplayComputePipelinetoo, so they get the same guarantee.#12147 adds a
CompileBudget::Holdto the same function. As agreed with milescoviello in this PR's comments, #12147 lands first. This branch now has #12147's heada937addfb8and currentmainbb04a4f1eamerged in, with the hold before the registration: check both maps, take the hold, check again under the lock and register, then build, publish and erase. Againstmain+ #12147, the diff is the same two files as before (VulkanDevice.cppandtests/execution/PipelineJournal.cpp).Tested
Windows 11, RTX 3080.
agc_driver_pipeline_journaladdsReplayRacesDispatchTests. It journals 32 compute pipelines, then on a new device dispatches all of them while the replay runs. It requires that the device builds exactly one pipeline per replayed entry:ComputePipelinesCreated() == replayedCompute + replayPresent.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "pipeline_journal|compute_pipeline|pipelined_dispatch|pipeline_library_clear|^agc_driver_compute_prebuild_share$|^agc_compile_budget$|^agc_driver_registration_prepare_stack$|^agc_driver_shutdown_threads" -V. The pattern adds #12147's budget and prebuild tests:mainbb04a4f1ea+ #12147 (ae682b33ca): 25 of 25 passed, 0VUID-lines.ab270dae66(85f1c5ffa4): 25 of 25 passed, 0VUID-lines.agc_driver_pipeline_journalthen passed 10 of 10 repeats.--cold-pipelines, three runs with and three without this change: every run built 97 compute pipelines, all by the journal replay (97 compute built, 0 present). In this scene the replay finishes each pipeline before a dispatch needs it, so the race doesn't occur here and the change makes no difference to it. The test above is what shows the race.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code