fix(agc): end the idle store's quiet period for a completion the draw pipeline adds #20015

Merged
imellag merged 1 commit from upstream-pr/20015 into main 2026-11-22 01:14:12 +00:00
imellag commented 2026-11-14 11:52:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-11-14T11:52:28Z.


What

Planet of Lana (PPSA19450) drops from about 30 fps to 13-17 fps some 30 s into gameplay on main, and stays there. It did not before #7978 (merged 2026-11-05): a tree of 2026-11-04 holds 28 fps in the same scene.

Cause: queue worker 0 waits out the idle store's 50 ms quiet period before it delivers an end-of-pipe interrupt the draw pipeline committed meanwhile.

  • The title starts its next frame on the graphics end-of-pipe event. Its frame ends with an interrupting RELEASE_MEM, which queue 0 hands to the draw pipeline.
  • Queue 0 then goes idle. With a storage-image result pending and no completion pending yet, it enters the quiet period (IdleResultsQuietPeriod, 50 ms) before the idle store.
  • The draw pipeline commits the label behind recorded work, which makes a completion pending, and the submission's completion notifies changed. The quiet period's wait only ends for queued work or an idle-epoch change, so the worker sleeps on and reaps the completion (and delivers the interrupt) only when the 50 ms run out.
  • Before #7978 every flip raised the event too, so the title never depended on the real interrupt's timing. Since #7978 it does. #7978 is right about the flip; this is the delivery path it exposed.

bd2197e919 fixed the same case for the dormant wait a few lines below (... || completionsPending()), with agc_driver_queue_zero_late_interrupt. This PR gives the quiet period's wait the same condition. The loop then finds idleResultsPending() false and goes to the completion poll, as it does after the dormant wait.

The same one-line condition is in @nicolasabosch's tracking draft #18515 (b900b496ae, found on UFC 6, "not for merge", to be split), together with an extra wakeQueueZeroForCompletions() after the label commit. This PR does not add that call: in the path measured here the submission's completion already notifies when a completion is pending (bd2197e919). If #18515's commit is split out first, this PR's test can go on top of it.

Tested

macOS 27.2, Apple M4 Pro, x86-64 Release under Rosetta 2, MoltenVK 1.4.2, main f0c9b11f91 (the libraries build on macOS except libcurl, #17425, which the title does not load).

  • New test agc_driver_queue_zero_quiet_interrupt (modelled on agc_driver_queue_zero_late_interrupt): a storage dispatch leaves a result pending, then, with the GPU mutex held so the draw pipeline cannot commit yet, an interrupting release is submitted and queue 0 goes back to its quiet period; the mutex is released and the time to the graphics event is measured. It passes when one of up to 5 measured rounds delivers within half the quiet period.
    • On main it fails 3 of 3 runs: queue 0 waited out the idle store's quiet period before it delivered an end-of-pipe interrupt the draw pipeline committed meanwhile (fastest of 2: 50.487708 ms) (also 57.3 and 50.8 ms).
    • With the change it passes 5 of 5 runs.
  • 33 tests matching ^agc_driver_(queue_zero|store_idle|idle_store|eop_interrupts|flip|flip_compute|submit|fill_completion_labels|linear_target_completion_points|copied_writer_copy|two_device_pending_store|store_over_untracked|storage_file_write)|^agc_driver$|^agc_submit pass with the change, with the Khronos validation layer inserted (checked in the loader log) and no VUID-.
  • Planet of Lana, same save and pad file, warm shader cache, alternated runs of main and main with this change. Presents per 10 s interval from launch (gameplay starts near 60 s):
run 70-80 s 80-90 s 90-100 s 100-110 s 110-120 s
main 1 377 305 129 138 138
change 1 356 314 326 330 329
main 2 356 280 142 142 (trace)
change 2 357 317 332 332 (trace)
  • tools/trace_digest.py on a 10 s trace of the second pair (APS5_TRACE_SECONDS=100:10):
    • main: 142 presents, frame p50 85.2 / p90 90.5 / p99 92.7 ms, GPU busy 15.5 ms per present; queue worker busy 21.3 ms and waiting 43.0 ms per frame, all of it Driver.WorkerWait.idle_and_completion_poll.
    • change: 333 presents, frame p50 30.0 / p90 32.0 / p99 35.8 ms, GPU busy 14.8 ms per present; queue worker busy 19.8 ms, waiting 3.7 ms per frame.
  • How the cause was found on main: a log of flips and end-of-pipe deliveries showed the event 6-7 ms after the flip in the good phase, and alternately 4 ms and about 56 ms after it in the slow phase; APS5_NO_IDLE_STORE=1 on unchanged main removes the drop (303 presents per 10 s).
  • God of War Ragnarök (PPSA28997), warm cache, one run each: 52.4 fps on main and 52.1 with the change over 100-150 s (no change expected: its worker does not sit in the quiet period).
  • python3 tools/check_conventions.py --base upstream/main passes.

Not run on Windows or Linux. The changed wait is common code.

tools/pr_overlap.py: #11436, #15136, #16791, #17786, #18078 and #18515 change QueueWorker.cpp; only #18515 touches this line (the same change, see above).

Checklist

  • Based on current main; no other open PR implements the same functions (the tracking draft #18515 carries the same line, see above)
  • 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: Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.2 (x86-64 under Rosetta 2)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5310942344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20015). Originally posted by [imellag](https://github.com/imellag) on 2026-11-14T11:52:28Z. --- ### What Planet of Lana (PPSA19450) drops from about 30 fps to 13-17 fps some 30 s into gameplay on `main`, and stays there. It did not before #7978 (merged 2026-11-05): a tree of 2026-11-04 holds 28 fps in the same scene. Cause: queue worker 0 waits out the idle store's 50 ms quiet period before it delivers an end-of-pipe interrupt the draw pipeline committed meanwhile. - The title starts its next frame on the graphics end-of-pipe event. Its frame ends with an interrupting `RELEASE_MEM`, which queue 0 hands to the draw pipeline. - Queue 0 then goes idle. With a storage-image result pending and no completion pending yet, it enters the quiet period (`IdleResultsQuietPeriod`, 50 ms) before the idle store. - The draw pipeline commits the label behind recorded work, which makes a completion pending, and the submission's completion notifies `changed`. The quiet period's wait only ends for queued work or an idle-epoch change, so the worker sleeps on and reaps the completion (and delivers the interrupt) only when the 50 ms run out. - Before #7978 every flip raised the event too, so the title never depended on the real interrupt's timing. Since #7978 it does. #7978 is right about the flip; this is the delivery path it exposed. bd2197e919 fixed the same case for the dormant wait a few lines below (`... || completionsPending()`), with `agc_driver_queue_zero_late_interrupt`. This PR gives the quiet period's wait the same condition. The loop then finds `idleResultsPending()` false and goes to the completion poll, as it does after the dormant wait. The same one-line condition is in @nicolasabosch's tracking draft #18515 (b900b496ae, found on UFC 6, "not for merge", to be split), together with an extra `wakeQueueZeroForCompletions()` after the label commit. This PR does not add that call: in the path measured here the submission's completion already notifies when a completion is pending (bd2197e919). If #18515's commit is split out first, this PR's test can go on top of it. ### Tested macOS 27.2, Apple M4 Pro, x86-64 Release under Rosetta 2, MoltenVK 1.4.2, `main` f0c9b11f91 (the libraries build on macOS except `libcurl`, #17425, which the title does not load). - New test `agc_driver_queue_zero_quiet_interrupt` (modelled on `agc_driver_queue_zero_late_interrupt`): a storage dispatch leaves a result pending, then, with the GPU mutex held so the draw pipeline cannot commit yet, an interrupting release is submitted and queue 0 goes back to its quiet period; the mutex is released and the time to the graphics event is measured. It passes when one of up to 5 measured rounds delivers within half the quiet period. - On `main` it fails 3 of 3 runs: `queue 0 waited out the idle store's quiet period before it delivered an end-of-pipe interrupt the draw pipeline committed meanwhile (fastest of 2: 50.487708 ms)` (also 57.3 and 50.8 ms). - With the change it passes 5 of 5 runs. - 33 tests matching `^agc_driver_(queue_zero|store_idle|idle_store|eop_interrupts|flip|flip_compute|submit|fill_completion_labels|linear_target_completion_points|copied_writer_copy|two_device_pending_store|store_over_untracked|storage_file_write)|^agc_driver$|^agc_submit` pass with the change, with the Khronos validation layer inserted (checked in the loader log) and no `VUID-`. - Planet of Lana, same save and pad file, warm shader cache, alternated runs of `main` and `main` with this change. Presents per 10 s interval from launch (gameplay starts near 60 s): | run | 70-80 s | 80-90 s | 90-100 s | 100-110 s | 110-120 s | |---|---|---|---|---|---| | `main` 1 | 377 | 305 | 129 | 138 | 138 | | change 1 | 356 | 314 | 326 | 330 | 329 | | `main` 2 | 356 | 280 | 142 | 142 | (trace) | | change 2 | 357 | 317 | 332 | 332 | (trace) | - `tools/trace_digest.py` on a 10 s trace of the second pair (`APS5_TRACE_SECONDS=100:10`): - `main`: 142 presents, frame p50 85.2 / p90 90.5 / p99 92.7 ms, GPU busy 15.5 ms per present; queue worker busy 21.3 ms and waiting 43.0 ms per frame, all of it `Driver.WorkerWait.idle_and_completion_poll`. - change: 333 presents, frame p50 30.0 / p90 32.0 / p99 35.8 ms, GPU busy 14.8 ms per present; queue worker busy 19.8 ms, waiting 3.7 ms per frame. - How the cause was found on `main`: a log of flips and end-of-pipe deliveries showed the event 6-7 ms after the flip in the good phase, and alternately 4 ms and about 56 ms after it in the slow phase; `APS5_NO_IDLE_STORE=1` on unchanged `main` removes the drop (303 presents per 10 s). - God of War Ragnarök (PPSA28997), warm cache, one run each: 52.4 fps on `main` and 52.1 with the change over 100-150 s (no change expected: its worker does not sit in the quiet period). - `python3 tools/check_conventions.py --base upstream/main` passes. Not run on Windows or Linux. The changed wait is common code. `tools/pr_overlap.py`: #11436, #15136, #16791, #17786, #18078 and #18515 change `QueueWorker.cpp`; only #18515 touches this line (the same change, see above). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (the tracking draft #18515 carries the same line, see above) - [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: Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.2 (x86-64 under Rosetta 2) - [x] AI-assisted: yes
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!20015
No description provided.