fix(agc): store pending storage-image results when queues idle #3777

Merged
MarcZX10 merged 3 commits from upstream-pr/3777 into main 2026-10-11 22:04:40 +00:00
MarcZX10 commented 2026-10-11 16:39:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T16:39:48Z.


What

Fixes #3272.

Storage image results can remain pending on the GPU while the guest CPU polls guest memory directly. Queue workers previously waited for work or completion labels without publishing those results, so a polling title could wait forever before its next flip or driver-side read.

When a worker reaches its idle wait, it stores pending image results only when it is queue 0 and all queue workers have no queued or running work and no GPU completion labels pending. The worker releases the queue mutex before taking the GPU mutex, flushes pending storage images, and submits those stores. Queue 0 is notified when the last running worker completes so it can recheck global idleness. This scopes write-back to global queue-idle periods instead of flushing whenever any individual queue goes idle between other queued work.

Prior art: closed PR #3334 proposed the same queue-idle store-and-submit direction and reported Ratchet & Clank: Rift Apart passing the frame-450 wait with that change. This PR credits that approach and adds its own regression through the production queue worker.

The agc_driver_store_idle_results execution test submits a compute packet through AgcDriver::Submit, then polls guest memory using direct CPU loads without a wait, a flush call, or another submission. It fails when the queue-worker idle-store path is disabled.

Tested

  • Linux x86_64, Release, llvmpipe: built agc_driver_store_idle_results_tests; CTest agc_driver_store_idle_results passed 1/1.
  • Regression check: disabling the queue-worker idle-store path makes agc_driver_store_idle_results fail because the result never reaches guest memory.
  • python3 tools/check_conventions.py --base upstream/main passed.
  • git diff --check passed.
  • The issue reporter reports Ratchet & Clank: Rift Apart passes the frame-450 wait in 3/3 runs with their analogous change, then stops later at #3274. I did not run the title.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820626337 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T16:39:48Z. --- ### What Fixes #3272. Storage image results can remain pending on the GPU while the guest CPU polls guest memory directly. Queue workers previously waited for work or completion labels without publishing those results, so a polling title could wait forever before its next flip or driver-side read. When a worker reaches its idle wait, it stores pending image results only when it is queue 0 and all queue workers have no queued or running work and no GPU completion labels pending. The worker releases the queue mutex before taking the GPU mutex, flushes pending storage images, and submits those stores. Queue 0 is notified when the last running worker completes so it can recheck global idleness. This scopes write-back to global queue-idle periods instead of flushing whenever any individual queue goes idle between other queued work. **Prior art:** closed PR #3334 proposed the same queue-idle store-and-submit direction and reported Ratchet & Clank: Rift Apart passing the frame-450 wait with that change. This PR credits that approach and adds its own regression through the production queue worker. The `agc_driver_store_idle_results` execution test submits a compute packet through `AgcDriver::Submit`, then polls guest memory using direct CPU loads without a wait, a flush call, or another submission. It fails when the queue-worker idle-store path is disabled. ### Tested - Linux x86_64, Release, llvmpipe: built `agc_driver_store_idle_results_tests`; CTest `agc_driver_store_idle_results` passed 1/1. - Regression check: disabling the queue-worker idle-store path makes `agc_driver_store_idle_results` fail because the result never reaches guest memory. - `python3 tools/check_conventions.py --base upstream/main` passed. - `git diff --check` passed. - The issue reporter reports Ratchet & Clank: Rift Apart passes the frame-450 wait in 3/3 runs with their analogous change, then stops later at #3274. I did not run the title. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 16:51:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T16:51:19Z.

Review: CHANGES_REQUESTED


Thanks for the PR. Built and ran it on Linux (agc_driver_store_idle_results passes, 10/10 repeats), but two things need fixing before it can merge:

  • tests/execution/StoreIdleResults.cpp:102 and :108 call device->StoreIdleResults() directly, so the test never goes through the queue worker. The actual fix is QueueWorker.cpp:107-110; with those four lines removed the test still passes, so the #3272 deadlock is not covered. Please make the test submit work on a queue (compute dispatch writing the storage image), then wait for the value to appear in guest memory with no further submission and no direct call to StoreIdleResults. It must fail without the QueueWorker.cpp change.
  • QueueWorker.cpp:107-110 now takes GpuMutex and flushes every pending storage image each time any queue (including queues 1+) goes idle, which can happen between submissions of the same frame. Please add before/after numbers (frame time or a flush count on a workload that keeps storage images pending) or scope the flush to the case that needs it.

Also, the description says this is independently authored, but the design is the same as the one in #3334 (closed by the intake bot); please credit it in the PR body if it was a basis.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5484120853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#pullrequestreview-5484120853). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T16:51:19Z. **Review:** CHANGES_REQUESTED --- Thanks for the PR. Built and ran it on Linux (`agc_driver_store_idle_results` passes, 10/10 repeats), but two things need fixing before it can merge: - `tests/execution/StoreIdleResults.cpp:102` and `:108` call `device->StoreIdleResults()` directly, so the test never goes through the queue worker. The actual fix is `QueueWorker.cpp:107-110`; with those four lines removed the test still passes, so the #3272 deadlock is not covered. Please make the test submit work on a queue (compute dispatch writing the storage image), then wait for the value to appear in guest memory with no further submission and no direct call to `StoreIdleResults`. It must fail without the `QueueWorker.cpp` change. - `QueueWorker.cpp:107-110` now takes `GpuMutex` and flushes every pending storage image each time any queue (including queues 1+) goes idle, which can happen between submissions of the same frame. Please add before/after numbers (frame time or a flush count on a workload that keeps storage images pending) or scope the flush to the case that needs it. Also, the description says this is independently authored, but the design is the same as the one in #3334 (closed by the intake bot); please credit it in the PR body if it was a basis.
MarcZX10 commented 2026-10-11 17:10:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:10:39Z.

Review: COMMENTED


Thanks for the review. I updated the regression to exercise the production queue worker: it submits a compute dispatch through AgcDriver::Submit and polls guest memory directly, without calling StoreIdleResults, waiting for completion, or submitting another packet. The test passes 10 consecutive runs with the idle-store path and fails when that path is disabled, so it covers the behavior in QueueWorker.cpp.

I also scoped write-back to queue 0 and only after the worker holds the queue mutex and confirms that every queue has no queued or running work and there are no completion labels pending. Queue 1+ no longer triggers a flush merely because its own queue is idle. VulkanDevice::StoreIdleResults returns immediately when there are no pending storage images, so the remaining work is confined to global idle periods where there may be a CPU poll waiting for those results.

Validation on Linux x86_64, Release, llvmpipe: build passed; agc_driver_store_idle_results passed 10/10; with the idle-store condition disabled, the same test fails because guest memory remains unchanged; conventions and git diff --check pass. The updated pull request has the required AI-assisted disclosure.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5484180040 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#pullrequestreview-5484180040). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T17:10:39Z. **Review:** COMMENTED --- Thanks for the review. I updated the regression to exercise the production queue worker: it submits a compute dispatch through `AgcDriver::Submit` and polls guest memory directly, without calling `StoreIdleResults`, waiting for completion, or submitting another packet. The test passes 10 consecutive runs with the idle-store path and fails when that path is disabled, so it covers the behavior in `QueueWorker.cpp`. I also scoped write-back to queue 0 and only after the worker holds the queue mutex and confirms that every queue has no queued or running work and there are no completion labels pending. Queue 1+ no longer triggers a flush merely because its own queue is idle. `VulkanDevice::StoreIdleResults` returns immediately when there are no pending storage images, so the remaining work is confined to global idle periods where there may be a CPU poll waiting for those results. Validation on Linux x86_64, Release, llvmpipe: build passed; `agc_driver_store_idle_results` passed 10/10; with the idle-store condition disabled, the same test fails because guest memory remains unchanged; conventions and `git diff --check` pass. The updated pull request has the required AI-assisted disclosure.
MarcZX10 commented 2026-10-11 17:14:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:14:42Z.


Thanks for the review. I updated the PR to address both points:

  • The regression now submits an actual compute packet through AgcDriver::Submit and checks guest memory with direct CPU loads. It does not call StoreIdleResults, wait for the driver, or submit more work. I verified it fails when the queue-worker store path is disabled and passes with the fix.
  • The store now runs only on queue 0 when all queues have no pending or running work and GPU completion labels are clear. The worker activity count covers the dequeue-to-execution handoff; queue 0 is woken to recheck idle state when the last active worker completes or blocks in a memory wait. This avoids flushing just because an individual queue goes idle while another queue is still active.
  • The PR description now credits the same queue-idle store-and-submit direction proposed in closed #3334 and distinguishes that title report from my fixture test. I did not run the game.

On Linux x86_64 with llvmpipe, the Release test target builds and agc_driver_store_idle_results passes 1/1. The conventions check and git diff --check pass. The latest commits are 6693cd6 and 42ac947.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111582782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#issuecomment-6111582782). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T17:14:42Z. --- Thanks for the review. I updated the PR to address both points: - The regression now submits an actual compute packet through `AgcDriver::Submit` and checks guest memory with direct CPU loads. It does not call `StoreIdleResults`, wait for the driver, or submit more work. I verified it fails when the queue-worker store path is disabled and passes with the fix. - The store now runs only on queue 0 when all queues have no pending or running work and GPU completion labels are clear. The worker activity count covers the dequeue-to-execution handoff; queue 0 is woken to recheck idle state when the last active worker completes or blocks in a memory wait. This avoids flushing just because an individual queue goes idle while another queue is still active. - The PR description now credits the same queue-idle store-and-submit direction proposed in closed #3334 and distinguishes that title report from my fixture test. I did not run the game. On Linux x86_64 with llvmpipe, the Release test target builds and `agc_driver_store_idle_results` passes 1/1. The conventions check and `git diff --check` pass. The latest commits are `6693cd6` and `42ac947`.
MarcZX10 commented 2026-10-11 17:41:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:41:28Z.


CI has now finished on head 42ac947f9:

  • Passed: eligibility, conventions, report, Ubuntu Debug/Release, macOS Intel Debug/Release, both macOS write-watch jobs, and the Linux/Windows/macOS relinker matrix.
  • Skipped by repository policy: full Linux and Windows build/test jobs, which require a collaborator-triggered workflow dispatch.

No code changed after my review response. @adriadam10, the updated head is ready for re-review when convenient.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111826019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#issuecomment-6111826019). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T17:41:28Z. --- CI has now finished on head `42ac947f9`: - **Passed:** eligibility, conventions, report, Ubuntu Debug/Release, macOS Intel Debug/Release, both macOS write-watch jobs, and the Linux/Windows/macOS relinker matrix. - **Skipped by repository policy:** full Linux and Windows build/test jobs, which require a collaborator-triggered workflow dispatch. No code changed after my review response. @adriadam10, the updated head is ready for re-review when convenient.
github-actions[bot] commented 2026-10-11 20:06:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T20:06:35Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3956 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L178
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113187640 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#issuecomment-6113187640). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T20:06:35Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3956 | `core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp` [L178](https://github.com/boykopovar/AnyPS5/blob/1be2ca2028f1caf4640a765941bfca2fae7d53f2/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp#L178) | | |
adriadam10 commented 2026-10-11 22:01:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:01:38Z.

Review: APPROVED


Checked on Linux: agc_driver_store_idle_results passes 10/10, fails with the non-test changes reverted, and the rest of the libSceAgcDriver ctest scope is green. The test now goes through AgcDriver::Submit and the queue worker, and the idle store is limited to queue 0 once every queue is idle, as asked. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5485174653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3777#pullrequestreview-5485174653). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:01:38Z. **Review:** APPROVED --- Checked on Linux: `agc_driver_store_idle_results` passes 10/10, fails with the non-test changes reverted, and the rest of the libSceAgcDriver ctest scope is green. The test now goes through `AgcDriver::Submit` and the queue worker, and the idle store is limited to queue 0 once every queue is idle, as asked. Merging.
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!3777
No description provided.