fix(agc): wake a dormant queue 0 when queued commits finish so the idle store sees their results #20132

Open
moong15 wants to merge 2 commits from upstream-pr/20132 into main
moong15 commented 2026-11-14 17:27:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-11-14T17:27:50Z.


What

With APS5_PIPELINE_DISPATCH=1 and APS5_PIPELINE_DISPATCH_MISSES=1, queue 0 can go dormant while dispatch items are still queued on the draw committer. When the committer then records them, their storage results become pending, but nothing wakes queue 0. The idle store never runs for those results, so they never reach guest memory.

The committer now wakes queue 0 when its queue empties. If queue 0 is dormant, it bumps idleEpoch and notifies, and queue 0 re-checks for idle results (Driver::WakeDormantQueue0, called from DrawPipeline::run outside the pipeline mutex). The dormant check runs under the driver mutex. Queue 0 holds that mutex from its last pending-results check until it waits, so a commit that empties the queue between the two cannot be missed. Queue 0 never blocks on the committer.

agc_driver_store_idle_results_pipelined_dispatch and agc_driver_idle_store_over_unmap_pipelined_dispatch run the two existing idle-store tests with both switches on.

Related, separate path: #20015 ends the idle store's quiet period early for a completion the draw pipeline adds. This PR wakes a queue 0 that is already dormant when queued commits finish.

Tested

Windows 11 (10.0.26300), AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Vulkan 1.4.359. Base main 2bc1db7ca8 (main's later commits do not touch libSceAgcDriver; rebased onto fbd7f5557e). Every run used ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer with Khronos validation layer 1.4.335 and ctest -j1. Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation", none shows was not found but was requested by env var VK_INSTANCE_LAYERS, and none contains VUID-.

Reproduction, 3 runs each:

Build Switches agc_driver_store_idle_results agc_driver_idle_store_over_unmap
main off Passed Passed
main APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1 Failed: "the queue-idle store did not bring the result to guest memory without a direct flush or further submission" Failed: "the queue's idle store did not settle the results of the unmapped surface"
this PR registered _pipelined_dispatch variants Passed Passed

Focused set, 3 runs each, ctest --test-dir build -R <pattern> -V: store_idle_results, _wake, _disabled, _pipelined_dispatch, idle_store_over_unmap, _pipelined_dispatch, idle_store_yields, storage_read_during_idle_store, two_device_pending_store, pipelined_dispatch_item, pipelined_dispatch_misses. This PR passed 11 of 11; main passed the 9 that exist there. No VUID- on either.

Full agc set on this PR: 1746 of 1757 passed. The 11 failures (f16_conversion_float_mode, float16_misc, float16_modifiers, float16_rounding, fp16_overflow, ldexp_f16_inline_constants, pixel_helper_waterfall, sdwa_ldexp_f16, vop2_modifier_forms, sample_order_grid_reference, and upload_cache_read_only_flush, which does not compile on MinGW because of setenv) fail the same way on main on this machine. No VUID- in either log.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 10.0.26300
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved queue handling so processing can resume when the first queue becomes idle after its final task completes.
    • Updated synchronization around queue completion to help ensure waiting work is notified consistently.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5314207943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20132). Originally posted by [moong15](https://github.com/moong15) on 2026-11-14T17:27:50Z. --- ### What With `APS5_PIPELINE_DISPATCH=1` and `APS5_PIPELINE_DISPATCH_MISSES=1`, queue 0 can go dormant while dispatch items are still queued on the draw committer. When the committer then records them, their storage results become pending, but nothing wakes queue 0. The idle store never runs for those results, so they never reach guest memory. The committer now wakes queue 0 when its queue empties. If queue 0 is dormant, it bumps `idleEpoch` and notifies, and queue 0 re-checks for idle results (`Driver::WakeDormantQueue0`, called from `DrawPipeline::run` outside the pipeline mutex). The dormant check runs under the driver mutex. Queue 0 holds that mutex from its last pending-results check until it waits, so a commit that empties the queue between the two cannot be missed. Queue 0 never blocks on the committer. `agc_driver_store_idle_results_pipelined_dispatch` and `agc_driver_idle_store_over_unmap_pipelined_dispatch` run the two existing idle-store tests with both switches on. Related, separate path: #20015 ends the idle store's quiet period early for a completion the draw pipeline adds. This PR wakes a queue 0 that is already dormant when queued commits finish. ### Tested Windows 11 (10.0.26300), AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Vulkan 1.4.359. Base `main` 2bc1db7ca8 (main's later commits do not touch `libSceAgcDriver`; rebased onto fbd7f5557e). Every run used `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` with Khronos validation layer 1.4.335 and `ctest -j1`. Each log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"`, none shows `was not found but was requested by env var VK_INSTANCE_LAYERS`, and none contains `VUID-`. Reproduction, 3 runs each: | Build | Switches | `agc_driver_store_idle_results` | `agc_driver_idle_store_over_unmap` | |---|---|---|---| | main | off | Passed | Passed | | main | `APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1` | Failed: "the queue-idle store did not bring the result to guest memory without a direct flush or further submission" | Failed: "the queue's idle store did not settle the results of the unmapped surface" | | this PR | registered `_pipelined_dispatch` variants | Passed | Passed | Focused set, 3 runs each, `ctest --test-dir build -R <pattern> -V`: `store_idle_results`, `_wake`, `_disabled`, `_pipelined_dispatch`, `idle_store_over_unmap`, `_pipelined_dispatch`, `idle_store_yields`, `storage_read_during_idle_store`, `two_device_pending_store`, `pipelined_dispatch_item`, `pipelined_dispatch_misses`. This PR passed 11 of 11; main passed the 9 that exist there. No `VUID-` on either. Full `agc` set on this PR: 1746 of 1757 passed. The 11 failures (`f16_conversion_float_mode`, `float16_misc`, `float16_modifiers`, `float16_rounding`, `fp16_overflow`, `ldexp_f16_inline_constants`, `pixel_helper_waterfall`, `sdwa_ldexp_f16`, `vop2_modifier_forms`, `sample_order_grid_reference`, and `upload_cache_read_only_flush`, which does not compile on MinGW because of `setenv`) fail the same way on main on this machine. No `VUID-` in either log. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 10.0.26300 - [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 queue handling so processing can resume when the first queue becomes idle after its final task completes. * Updated synchronization around queue completion to help ensure waiting work is notified consistently. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-23 04:34:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T04:34:19Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed change blocks merging, and the inspected synchronization flow and added test registrations support the stated fix.

What I ran

Reviewed head 92a7f9574a60f5e2071bf457bc03da63235ce6d3 using repo_read.py to read the prepared review bundle and targeted source context. No commands or tests were run.

Results

Check Result Note
Changed code review passed All five changed files read
Tests in this review not run Author-reported results only
Negative control not run No test mutation performed

Findings

Blocking

None.

Non-blocking

None.

Sources

The commit-pinned diff adds a queue 0 wake after its pipeline becomes empty, with the wake outside the pipeline mutex. The dormant wait and the new wake both synchronize through the driver mutex; changing idleEpoch causes queue 0 to recheck idle results. The tests register both idle-store scenarios with pipeline dispatch switches enabled.

Not verified

No build, test, or negative control was run for this review. The Windows/Vulkan test results in the PR description are author-reported. Read: Driver.hpp, DrawPipeline.cpp, QueueWorker.cpp, both changed CMake test files, and the prepared description.md, commits.md, manifest.json, and diff.patch. Excluded: none of the changed files; files.json was unavailable in the prepared review folder.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016614031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20132#pullrequestreview-6016614031). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T04:34:19Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed change blocks merging, and the inspected synchronization flow and added test registrations support the stated fix. ## What I ran Reviewed head `92a7f9574a60f5e2071bf457bc03da63235ce6d3` using `repo_read.py` to read the prepared review bundle and targeted source context. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All five changed files read | | Tests in this review | not run | Author-reported results only | | Negative control | not run | No test mutation performed | ## Findings ### Blocking None. ### Non-blocking None. ## Sources The commit-pinned diff adds a queue 0 wake after its pipeline becomes empty, with the wake outside the pipeline mutex. The dormant wait and the new wake both synchronize through the driver mutex; changing `idleEpoch` causes queue 0 to recheck idle results. The tests register both idle-store scenarios with pipeline dispatch switches enabled. ## Not verified No build, test, or negative control was run for this review. The Windows/Vulkan test results in the PR description are author-reported. Read: `Driver.hpp`, `DrawPipeline.cpp`, `QueueWorker.cpp`, both changed CMake test files, and the prepared `description.md`, `commits.md`, `manifest.json`, and `diff.patch`. Excluded: none of the changed files; `files.json` was unavailable in the prepared review folder. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-30 06:41:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:41:48Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and focused test registrations support the stated queue wake behavior.

What I ran

  • Read the prepared diff and all five changed files at head 9ccd796f5d2a54f7e4d039135b2f0a5552c56058, including the queue worker’s idle wait logic.
  • Used repo_read.py search and range reads to inspect the dormant flag, idle epoch, and test registrations. No tests were run.

Results

Check Result Note
Changed code review passed Wake uses the queue worker mutex and idle epoch.
Test execution not run Test results in the PR description are author reported.

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • No tests were run in this review; the Windows, GPU, Vulkan, and ctest results in the description were not independently verified.
  • Read all changed files listed in manifest.json: Driver.hpp, DrawPipeline.cpp, QueueWorker.cpp, and both changed CMake test files. files.json exclusions were not inspected.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6107871091 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20132#pullrequestreview-6107871091). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T06:41:48Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and focused test registrations support the stated queue wake behavior. ## What I ran - Read the prepared diff and all five changed files at head `9ccd796f5d2a54f7e4d039135b2f0a5552c56058`, including the queue worker’s idle wait logic. - Used `repo_read.py` search and range reads to inspect the dormant flag, idle epoch, and test registrations. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Wake uses the queue worker mutex and idle epoch. | | Test execution | not run | Test results in the PR description are author reported. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - No tests were run in this review; the Windows, GPU, Vulkan, and `ctest` results in the description were not independently verified. - Read all changed files listed in `manifest.json`: `Driver.hpp`, `DrawPipeline.cpp`, `QueueWorker.cpp`, and both changed CMake test files. `files.json` exclusions were not inspected. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-03 14:07:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:07:42Z.

Review: APPROVED


I read the diff at 9ccd796f5d. Windows 11, GCC 15.2, merged into main at 6c6b29320fe together with other open PRs (so not an isolated build), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).

  • agc_driver_store_idle_results (with _wake, _disabled and _pipelined_dispatch) and the other agc_driver_idle_store tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a VUID- or SYNC-HAZARD line.
  • Control (the same tree with only this PR's source change taken out): agc_driver_store_idle_results_pipelined_dispatch fails: "the queue-idle store did not bring the result to guest memory without a direct flush or further submission".

agc_driver_idle_store_over_unmap and its _pipelined_dispatch form skip themselves on both GPUs.

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171367069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20132#pullrequestreview-6171367069). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T14:07:42Z. **Review:** APPROVED --- I read the diff at `9ccd796f5d`. Windows 11, GCC 15.2, merged into `main` at `6c6b29320fe` together with other open PRs (so not an isolated build), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2). - `agc_driver_store_idle_results` (with `_wake`, `_disabled` and `_pipelined_dispatch`) and the other `agc_driver_idle_store` tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a `VUID-` or `SYNC-HAZARD` line. - Control (the same tree with only this PR's source change taken out): `agc_driver_store_idle_results_pipelined_dispatch` fails: "the queue-idle store did not bring the result to guest memory without a direct flush or further submission". `agc_driver_idle_store_over_unmap` and its `_pipelined_dispatch` form skip themselves on both GPUs. Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 22:24:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:24:01Z.

Review: COMMENTED


The trial merge onto a1b75b0947 was clean. The final queue-0 commit now notifies the dormant worker after releasing the pipeline mutex, avoiding a direct mutex-order inversion with the new wake call. The pipelined-dispatch CTests should exercise the case where a final commit makes idle storage eligible without another submission. Please preserve those cases when integrating the pending-image work. Paired lavapipe validation is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179663365 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20132#pullrequestreview-6179663365). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:24:01Z. **Review:** COMMENTED --- The trial merge onto `a1b75b0947` was clean. The final queue-0 commit now notifies the dormant worker after releasing the pipeline mutex, avoiding a direct mutex-order inversion with the new wake call. The pipelined-dispatch CTests should exercise the case where a final commit makes idle storage eligible without another submission. Please preserve those cases when integrating the pending-image work. Paired lavapipe validation 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/20132:upstream-pr/20132'
git switch 'upstream-pr/20132'

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