fix(agc): build a replayed compute pipeline once when a dispatch races it #12657

Merged
chitters2004 merged 1 commit from upstream-pr/12657 into main 2026-10-30 19:13:10 +00:00
chitters2004 commented 2026-10-29 00:35:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-10-29T00:35:12Z.


What

VulkanDevice::ReplayComputePipeline checked computePipelines and computePipelinesBuilding but never registered its own build in computePipelinesBuilding. A dispatch through computePipeline() 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 in computePipelinesBuilding before it builds, the same protocol computePipeline() 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:

  • The replay holds no lock while it compiles, and it runs on the journal's own replay threads, not on a shared worker pool, so the wait can't hold up other kinds of work.
  • A build that fails erases its entry and passes the exception to every waiter, so a waiter can't hang.
  • The replay started that build before the dispatch asked for it, so the wait is never longer than compiling from scratch.

#5925's ahead builds call ReplayComputePipeline too, so they get the same guarantee.

#12147 adds a CompileBudget::Hold to the same function. As agreed with milescoviello in this PR's comments, #12147 lands first. This branch now has #12147's head a937addfb8 and current main bb04a4f1ea merged 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. Against main + #12147, the diff is the same two files as before (VulkanDevice.cpp and tests/execution/PipelineJournal.cpp).

Tested

Windows 11, RTX 3080.

  • agc_driver_pipeline_journal adds ReplayRacesDispatchTests. 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.
    • Without the fix it fails on every run (5 of 5): 51–52 pipelines built for 33 entries.
    • With the fix it passes on every run (10 of 10).
  • Paired run after the merge, full builds with submodules at their pinned commits, 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:
    • main bb04a4f1ea + #12147 (ae682b33ca): 25 of 25 passed, 0 VUID- lines.
    • That + this head ab270dae66 (85f1c5ffa4): 25 of 25 passed, 0 VUID- lines. agc_driver_pipeline_journal then passed 10 of 10 repeats.
    • Neither log says the layer was not found.
  • GTA V (PPSA04263), frame replay of a 3-frame capture with --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/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #12147
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080, driver 621.01, Windows 11 Pro 26220
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5059989944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12657). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-10-29T00:35:12Z. --- ### What `VulkanDevice::ReplayComputePipeline` checked `computePipelines` and `computePipelinesBuilding` but never registered its own build in `computePipelinesBuilding`. A dispatch through `computePipeline()` 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 in `computePipelinesBuilding` before it builds, the same protocol `computePipeline()` 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: - The replay holds no lock while it compiles, and it runs on the journal's own replay threads, not on a shared worker pool, so the wait can't hold up other kinds of work. - A build that fails erases its entry and passes the exception to every waiter, so a waiter can't hang. - The replay started that build before the dispatch asked for it, so the wait is never longer than compiling from scratch. #5925's ahead builds call `ReplayComputePipeline` too, so they get the same guarantee. #12147 adds a `CompileBudget::Hold` to the same function. As agreed with milescoviello in this PR's comments, #12147 lands first. This branch now has #12147's head `a937addfb8` and current `main` `bb04a4f1ea` merged 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. Against `main` + #12147, the diff is the same two files as before (`VulkanDevice.cpp` and `tests/execution/PipelineJournal.cpp`). ### Tested Windows 11, RTX 3080. - `agc_driver_pipeline_journal` adds `ReplayRacesDispatchTests`. 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`. - Without the fix it fails on every run (5 of 5): 51–52 pipelines built for 33 entries. - With the fix it passes on every run (10 of 10). - Paired run after the merge, full builds with submodules at their pinned commits, `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: - `main` `bb04a4f1ea` + #12147 (`ae682b33ca`): 25 of 25 passed, 0 `VUID-` lines. - That + this head `ab270dae66` (`85f1c5ffa4`): 25 of 25 passed, 0 `VUID-` lines. `agc_driver_pipeline_journal` then passed 10 of 10 repeats. - Neither log says the layer was not found. - GTA V (PPSA04263), frame replay of a 3-frame capture with `--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/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #12147 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 621.01, Windows 11 Pro 26220 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12657
No description provided.