fix(agc): build the store-pages compute variant before taking the GPU mutex #28001

Open
muhmuhkuh wants to merge 1 commit from upstream-pr/28001 into main
muhmuhkuh commented 2026-11-28 02:57:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by muhmuhkuh on 2026-11-28T02:57:30Z.


What

PrepareDispatch builds a dispatch's {0, 0, 0} zero-base compute pipeline before the GPU mutex is taken (computePipeline), so recording finds it. A module that stores through store pages also needs its store-pages variant, though, and recordDispatch built that variant on first use (specializedComputePipeline(..., {0, 0, 0}, true)), with the GPU mutex held. For a large module that is a full second pipeline build, several seconds long, and every other queue waits on the mutex meanwhile.

Change:

  • PrepareDispatch builds the store-pages variant right after the pipeline when the module has one (objects->storePages), through the same specializedComputePipeline call and key the recording path uses. Recording then finds it in splitPipelines.
  • Nothing else changes: a module without store pages builds nothing extra, the split workgroup-offset variants are still built when recorded, and a dispatch that was not prepared still builds the variant at recording time.

Tested

Built and run on main 4814cae8551 and on this branch on the same machine and GPU.

  • New agc_driver_bda_store_heap_mirror_store_pages_outside_mutex (BdaStoreHeapMirror --store-pages-outside-mutex): compiles a store into a heap mirror, prepares it with PrepareDispatch outside the GPU mutex, records it with Dispatch while the test holds the GPU mutex, and checks that every thread's store reached guest memory, that the pipeline and its store-pages variant were built, and that ComputePipelineCounts().underGpuMutex did not change.
  • Windows 11, NVIDIA GeForce RTX 3080 Ti, driver 610.88, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest --test-dir build -R 'agc_driver_bda_store_heap_mirror|agc_driver_compute_pipeline_outside_gpu_mutex' -V:
    • main: 6/6 passed;
    • main with only the new test: it fails with "recording a prepared store into a heap mirror created 1 compute pipeline(s) under the GPU mutex";
    • this branch: 7/7 passed;
    • the validation layer was loaded, no log contains was not found but was requested by env var VK_INSTANCE_LAYERS; VUID- lines: 0 on main, 0 on this branch.
  • The same change behind an opt-in switch on another branch: the test was red without the switch (the message above) and green with it, validation layer loaded, no VUID- lines.
  • tools/check_conventions.py --base origin/main: All conventions checks passed.
  • tools/pr_overlap.py --branch fix/agc-store-pages-before-gpu-mutex: no overlap with the pull requests it could compare. It cannot compare 63 open pull requests that touch VulkanDevice.cpp and conflict with main themselves. Checked by hand with git diff against their merge bases: none adds a specializedComputePipeline call or this test; #7642, #9508, #10193, #13928, #13929, #22692 and #26197 change other lines in PrepareDispatch, none of its pipeline building.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • Fixes: none
  • Unblocks: none (seen in PPSA38500 while chasing a GPU-mutex stall; this path has not been hit there yet, the change rests on the code and the test)
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved GPU compute dispatch reliability when page storage is enabled, helping ensure that dispatched work completes and its results are written to memory.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5536011903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28001). Originally posted by [muhmuhkuh](https://github.com/muhmuhkuh) on 2026-11-28T02:57:30Z. --- ### What `PrepareDispatch` builds a dispatch's `{0, 0, 0}` zero-base compute pipeline before the GPU mutex is taken (`computePipeline`), so recording finds it. A module that stores through store pages also needs its store-pages variant, though, and `recordDispatch` built that variant on first use (`specializedComputePipeline(..., {0, 0, 0}, true)`), with the GPU mutex held. For a large module that is a full second pipeline build, several seconds long, and every other queue waits on the mutex meanwhile. Change: - `PrepareDispatch` builds the store-pages variant right after the pipeline when the module has one (`objects->storePages`), through the same `specializedComputePipeline` call and key the recording path uses. Recording then finds it in `splitPipelines`. - Nothing else changes: a module without store pages builds nothing extra, the split workgroup-offset variants are still built when recorded, and a dispatch that was not prepared still builds the variant at recording time. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Built and run on `main` `4814cae8551` and on this branch on the same machine and GPU. - New `agc_driver_bda_store_heap_mirror_store_pages_outside_mutex` (`BdaStoreHeapMirror --store-pages-outside-mutex`): compiles a store into a heap mirror, prepares it with `PrepareDispatch` outside the GPU mutex, records it with `Dispatch` while the test holds the GPU mutex, and checks that every thread's store reached guest memory, that the pipeline and its store-pages variant were built, and that `ComputePipelineCounts().underGpuMutex` did not change. - Windows 11, NVIDIA GeForce RTX 3080 Ti, driver 610.88, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest --test-dir build -R 'agc_driver_bda_store_heap_mirror|agc_driver_compute_pipeline_outside_gpu_mutex' -V`: - `main`: 6/6 passed; - `main` with only the new test: it fails with "recording a prepared store into a heap mirror created 1 compute pipeline(s) under the GPU mutex"; - this branch: 7/7 passed; - the validation layer was loaded, no log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`; `VUID-` lines: 0 on `main`, 0 on this branch. - The same change behind an opt-in switch on another branch: the test was red without the switch (the message above) and green with it, validation layer loaded, no `VUID-` lines. - `tools/check_conventions.py --base origin/main`: `All conventions checks passed.` - `tools/pr_overlap.py --branch fix/agc-store-pages-before-gpu-mutex`: no overlap with the pull requests it could compare. It cannot compare 63 open pull requests that touch `VulkanDevice.cpp` and conflict with `main` themselves. Checked by hand with `git diff` against their merge bases: none adds a `specializedComputePipeline` call or this test; #7642, #9508, #10193, #13928, #13929, #22692 and #26197 change other lines in `PrepareDispatch`, none of its pipeline building. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] Fixes: none - [x] Unblocks: none (seen in PPSA38500 while chasing a GPU-mutex stall; this path has not been hit there yet, the change rests on the code and the test) - [x] GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 610.88, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved GPU compute dispatch reliability when page storage is enabled, helping ensure that dispatched work completes and its results are written to memory. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Plyxen commented 2026-11-28 07:01:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T07:01:35Z.

Review: APPROVED


Checked head 8d27fcfebe. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main 4c7578e0a4 together with #28006, #27985, #28002, #27991, #27987, #28007, #27994. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure is windows_read_trap_unknown, which fails on main too (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and the 1.4.363 layer inserted, matches main on the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Only agc_driver_linear_target_import_creation fails, as on main (fixed in #28029), and neither log has a VUID- or SYNC-HAZARD line.

agc_driver_bda_store_heap_mirror_store_pages_outside_mutex passes. The GPU suite list above predates the new tests, so I applied this PR again with #27987 and #28007 and ran the new tests 3 times on each GPU with the same environment: all pass, with the layer inserted and no VUID- or SYNC-HAZARD line.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096379216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28001#pullrequestreview-6096379216). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T07:01:35Z. **Review:** APPROVED --- Checked head `8d27fcfebe`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `4c7578e0a4` together with #28006, #27985, #28002, #27991, #27987, #28007, #27994. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. In the full CPU suite (5,135 tests) the only failure is `windows_read_trap_unknown`, which fails on `main` too (fixed in #28028). The full GPU suite (2,249 tests) on both GPUs, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` and the 1.4.363 layer inserted, matches `main` on the same machine. The GPUs were an NVIDIA RTX 5080 (621.24) and an AMD Radeon gfx1036 iGPU (26.11.2). Only `agc_driver_linear_target_import_creation` fails, as on `main` (fixed in #28029), and neither log has a `VUID-` or `SYNC-HAZARD` line. `agc_driver_bda_store_heap_mirror_store_pages_outside_mutex` passes. The GPU suite list above predates the new tests, so I applied this PR again with #27987 and #28007 and ran the new tests 3 times on each GPU with the same environment: all pass, with the layer inserted and no `VUID-` or `SYNC-HAZARD` line. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-28 07:30:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T07:30:27Z.

Review: APPROVED


Reviewed — looks good

The change at head 8d27fcfebe4e9122ec7a779583c6f419dadab230 prebuilds the store-pages specialization during dispatch preparation, and the inspected call path uses that same cached specialization while recording.

What I ran

Read the prepared review bundle and pinned source with repo_read.py reader tools. No tests or builds were run by me; the test results in the PR description are author-reported.

Results

Check Result Note
Changed-line review passed All added lines were read.
Targeted call-path review passed Matching specialization key confirmed.
Tests and build not run Author reports Windows 11 test runs.

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or builds were run in this review. The author's reported test results, validation-layer output, and convention checks were not independently verified. VulkanDevice.cpp was read through the pinned reader because it was excluded from the review folder; the other changed files were read in full. No other files were excluded by the review manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096520875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28001#pullrequestreview-6096520875). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T07:30:27Z. **Review:** APPROVED --- # Reviewed — looks good The change at head `8d27fcfebe4e9122ec7a779583c6f419dadab230` prebuilds the store-pages specialization during dispatch preparation, and the inspected call path uses that same cached specialization while recording. ## What I ran Read the prepared review bundle and pinned source with `repo_read.py` reader tools. No tests or builds were run by me; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed-line review | passed | All added lines were read. | | Targeted call-path review | passed | Matching specialization key confirmed. | | Tests and build | not run | Author reports Windows 11 test runs. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or builds were run in this review. The author's reported test results, validation-layer output, and convention checks were not independently verified. `VulkanDevice.cpp` was read through the pinned reader because it was excluded from the review folder; the other changed files were read in full. No other files were excluded by the review manifest. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 20:37:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:37:47Z.

Review: COMMENTED


PrepareDispatch now warms the {0, 0, 0} store-pages specialization. When a dispatch exceeds a device workgroup limit, recording still builds nonzero-offset variants with specializedComputePipeline(..., {xBase, yBase, zBase}, storePages). Could the PR state that the lock guarantee covers the zero-base case and add an over-limit check if the guarantee is meant to cover chunked dispatches too?

Source review at 8d27fcfebe. The head trial-merges onto 700fae9438. Paired Vulkan execution is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6178076828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28001#pullrequestreview-6178076828). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T20:37:47Z. **Review:** COMMENTED --- `PrepareDispatch` now warms the `{0, 0, 0}` store-pages specialization. When a dispatch exceeds a device workgroup limit, recording still builds nonzero-offset variants with `specializedComputePipeline(..., {xBase, yBase, zBase}, storePages)`. Could the PR state that the lock guarantee covers the zero-base case and add an over-limit check if the guarantee is meant to cover chunked dispatches too? Source review at `8d27fcfebe`. The head trial-merges onto `700fae9438`. Paired Vulkan execution is pending. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28001:upstream-pr/28001'
git switch 'upstream-pr/28001'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28001'
git switch 'upstream-pr/28001'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28001'
git switch 'upstream-pr/28001'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28001'
git switch 'main'
git merge --squash 'upstream-pr/28001'
git switch 'main'
git merge --ff-only 'upstream-pr/28001'
git switch 'main'
git merge 'upstream-pr/28001'
git push origin 'main'
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!28001
No description provided.