fix(agc): store pending storage-image results when queues idle #3777
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3777"
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 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_resultsexecution test submits a compute packet throughAgcDriver::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
agc_driver_store_idle_results_tests; CTestagc_driver_store_idle_resultspassed 1/1.agc_driver_store_idle_resultsfail because the result never reaches guest memory.python3 tools/check_conventions.py --base upstream/mainpassed.git diff --checkpassed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported 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_resultspasses, 10/10 repeats), but two things need fixing before it can merge:tests/execution/StoreIdleResults.cpp:102and:108calldevice->StoreIdleResults()directly, so the test never goes through the queue worker. The actual fix isQueueWorker.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 toStoreIdleResults. It must fail without theQueueWorker.cppchange.QueueWorker.cpp:107-110now takesGpuMutexand 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.
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::Submitand polls guest memory directly, without callingStoreIdleResults, 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 inQueueWorker.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::StoreIdleResultsreturns 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_resultspassed 10/10; with the idle-store condition disabled, the same test fails because guest memory remains unchanged; conventions andgit diff --checkpass. The updated pull request has the required AI-assisted disclosure.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:
AgcDriver::Submitand checks guest memory with direct CPU loads. It does not callStoreIdleResults, 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.On Linux x86_64 with llvmpipe, the Release test target builds and
agc_driver_store_idle_resultspasses 1/1. The conventions check andgit diff --checkpass. The latest commits are6693cd6and42ac947.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T17:41:28Z.
CI has now finished on head
42ac947f9:No code changed after my review response. @adriadam10, the updated head is ready for re-review when convenient.
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.
main)core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppL178Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:01:38Z.
Review: APPROVED
Checked on Linux:
agc_driver_store_idle_resultspasses 10/10, fails with the non-test changes reverted, and the rest of the libSceAgcDriver ctest scope is green. The test now goes throughAgcDriver::Submitand the queue worker, and the idle store is limited to queue 0 once every queue is idle, as asked. Merging.