perf(agc): deliver end-of-pipe interrupts after their work without draining #409

Merged
oneandonlydean merged 1 commit from upstream-pr/409 into main 2026-10-03 06:35:22 +00:00
oneandonlydean commented 2026-10-02 21:28:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T21:28:41Z.


What

A RELEASE_MEM with an interrupt select (an end-of-pipe interrupt) drained the device: the queue worker submitted everything recorded, waited for the GPU, then stored the label on the CPU and delivered the interrupt. PPSA21564 issues about 300 of these per frame, so the graphics worker and the GPU took turns. In a profile of my integration branch at the title screen, RELEASE_MEM handling took about 2.3 s of every 10 s of the graphics worker, almost all of it waiting.

This PR keeps the packet's meaning (the interrupt reaches the queue's event once the work before it completed and its label landed) without the CPU wait:

  • The label is recorded like any other label: stored by the GPU behind the recorded work (WriteLabelOnGpu), or kept as a completion action behind pending write-backs (reasons 5 and 6), exactly as for a RELEASE_MEM without an interrupt. With nothing recorded (reason 1) it is stored on the CPU and the interrupt is delivered at once, as before.
  • The delivery becomes a completion action of the batch holding the work before the packet: the open batch, or the newest in-flight batch when none is open (Recorder::AfterRecordedWork, VulkanDevice::AfterRecordedWork). It is appended after that batch's earlier completions, so a label kept as a completion action lands first. It is counted with the completion labels, so idle queue workers and WAIT_REG_MEM pollers reap its batch; it also starts the label flush deadline, like a pending label.
  • When draws or dispatches were recorded since the last submit, the batch is submitted at once, so the interrupt follows exactly the work before it.
  • When nothing but labels was recorded since the last submit (back-to-back releases separated only by waits, events and labels, about 80% of them in PPSA21564), the batch holding the label stores stays open instead of going out as a batch of its own. It is submitted with the next work, at the label flush deadline (1 ms by default, checked between packets and while a WAIT_REG_MEM polls), at a wait on one of its labels, at a flip or at the end of the submission, like any other pending label.
  • A label WriteLabelOnGpu refuses (reasons 2 to 4), a label that does not decode, and APS5_DRAIN_ALL still drain as before.

Ordering guarantees:

  • Labels are still written by the GPU in record order, in the same command stream as every other label; nothing is moved to a CPU store out of order.
  • An interrupt is delivered only after the batch holding the work before it completed and after that batch's earlier completion stores ran, so it never arrives early. It can arrive later than before, by at most the flush deadline plus the work recorded into the same batch in the meantime.
  • Latency stays bounded because the action counts as a pending label: the deadline, waits on its labels, flips and the end of a submission all submit the open batch. A WAIT_REG_MEM for something the CPU does on the interrupt cannot hold the batch back either: its poll submits the batch once the deadline passed.

Two variants I tried first and dropped, for context:

  • leaving the batch open even with draws recorded, so the delivery also waited for the packets recorded after the RELEASE_MEM: PPSA21564's intro presented a garbage frame in 5 of 25 runs;
  • turning label-only end-of-pipe labels into CPU stores at the previous batch's reap: later GPU-stored labels could land before them, and a profiled PPSA21564 run died on a corrupt command packet.

Tests:

  • testEndOfPipeLabelsWithoutWork (agc_driver_tests): two back-to-back end-of-pipe labels with no work before them land, satisfy a WAIT_REG_MEM on the compute queue, and raise both interrupts. Without a device (CI) this covers the CPU path only.
  • afterRecordedWorkTests (agc_driver_recorder_tests, needs a Vulkan device, run by hand like the rest of that binary): an idle recorder refuses the action; an action behind the open batch is pending and starts the label flush deadline; actions behind the open batch, behind a completion label and behind an in-flight batch run once each, in order, only when their batch is reaped, and after the completion label recorded ahead of them landed.

Tested

  • Linux (CachyOS, GCC 16), RTX 4090: ctest 125/125 pass, including testEndOfPipeLabelsWithoutWork. agc_driver_recorder_tests by hand: passes, including afterRecordedWorkTests.
  • Without the change: afterRecordedWorkTests does not build (it tests the new Recorder::AfterRecordedWork). testEndOfPipeLabelsWithoutWork has no device in agc_driver_tests, so it takes the CPU path and also passes on main; it guards the label-only case that the batch deferral changes.
  • PPSA21564: the same change (as three commits plus two debug switches, dropped here) has been on my integration branch for many runs of my visual regression check (intro, title, menu and a level), passing them with the shimmer check clean.
    • Drains: RELEASE_MEM handling went from about 2.3 s to about 0.45 s per 10 s of the graphics worker at the title.
    • Batches: about 85k per 10 s at the title before the label-only batches stayed open, about 70k of them holding nothing but label stores; about 18k after.

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 (attach them to this PR)
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none. #374 adds lines at the same spot in preparePacketMemory, so whichever lands second needs a small rebase.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4721669918 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/409). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T21:28:41Z. --- ### What A RELEASE_MEM with an interrupt select (an end-of-pipe interrupt) drained the device: the queue worker submitted everything recorded, waited for the GPU, then stored the label on the CPU and delivered the interrupt. PPSA21564 issues about 300 of these per frame, so the graphics worker and the GPU took turns. In a profile of my integration branch at the title screen, RELEASE_MEM handling took about 2.3 s of every 10 s of the graphics worker, almost all of it waiting. This PR keeps the packet's meaning (the interrupt reaches the queue's event once the work before it completed and its label landed) without the CPU wait: - The label is recorded like any other label: stored by the GPU behind the recorded work (`WriteLabelOnGpu`), or kept as a completion action behind pending write-backs (reasons 5 and 6), exactly as for a RELEASE_MEM without an interrupt. With nothing recorded (reason 1) it is stored on the CPU and the interrupt is delivered at once, as before. - The delivery becomes a completion action of the batch holding the work before the packet: the open batch, or the newest in-flight batch when none is open (`Recorder::AfterRecordedWork`, `VulkanDevice::AfterRecordedWork`). It is appended after that batch's earlier completions, so a label kept as a completion action lands first. It is counted with the completion labels, so idle queue workers and WAIT_REG_MEM pollers reap its batch; it also starts the label flush deadline, like a pending label. - When draws or dispatches were recorded since the last submit, the batch is submitted at once, so the interrupt follows exactly the work before it. - When nothing but labels was recorded since the last submit (back-to-back releases separated only by waits, events and labels, about 80% of them in PPSA21564), the batch holding the label stores stays open instead of going out as a batch of its own. It is submitted with the next work, at the label flush deadline (1 ms by default, checked between packets and while a WAIT_REG_MEM polls), at a wait on one of its labels, at a flip or at the end of the submission, like any other pending label. - A label `WriteLabelOnGpu` refuses (reasons 2 to 4), a label that does not decode, and `APS5_DRAIN_ALL` still drain as before. Ordering guarantees: - Labels are still written by the GPU in record order, in the same command stream as every other label; nothing is moved to a CPU store out of order. - An interrupt is delivered only after the batch holding the work before it completed and after that batch's earlier completion stores ran, so it never arrives early. It can arrive later than before, by at most the flush deadline plus the work recorded into the same batch in the meantime. - Latency stays bounded because the action counts as a pending label: the deadline, waits on its labels, flips and the end of a submission all submit the open batch. A WAIT_REG_MEM for something the CPU does on the interrupt cannot hold the batch back either: its poll submits the batch once the deadline passed. Two variants I tried first and dropped, for context: - leaving the batch open even with draws recorded, so the delivery also waited for the packets recorded after the RELEASE_MEM: PPSA21564's intro presented a garbage frame in 5 of 25 runs; - turning label-only end-of-pipe labels into CPU stores at the previous batch's reap: later GPU-stored labels could land before them, and a profiled PPSA21564 run died on a corrupt command packet. Tests: - `testEndOfPipeLabelsWithoutWork` (`agc_driver_tests`): two back-to-back end-of-pipe labels with no work before them land, satisfy a WAIT_REG_MEM on the compute queue, and raise both interrupts. Without a device (CI) this covers the CPU path only. - `afterRecordedWorkTests` (`agc_driver_recorder_tests`, needs a Vulkan device, run by hand like the rest of that binary): an idle recorder refuses the action; an action behind the open batch is pending and starts the label flush deadline; actions behind the open batch, behind a completion label and behind an in-flight batch run once each, in order, only when their batch is reaped, and after the completion label recorded ahead of them landed. ### Tested - Linux (CachyOS, GCC 16), RTX 4090: `ctest` 125/125 pass, including `testEndOfPipeLabelsWithoutWork`. `agc_driver_recorder_tests` by hand: passes, including `afterRecordedWorkTests`. - Without the change: `afterRecordedWorkTests` does not build (it tests the new `Recorder::AfterRecordedWork`). `testEndOfPipeLabelsWithoutWork` has no device in `agc_driver_tests`, so it takes the CPU path and also passes on `main`; it guards the label-only case that the batch deferral changes. - PPSA21564: the same change (as three commits plus two debug switches, dropped here) has been on my integration branch for many runs of my visual regression check (intro, title, menu and a level), passing them with the shimmer check clean. - Drains: RELEASE_MEM handling went from about 2.3 s to about 0.45 s per 10 s of the graphics worker at the title. - Batches: about 85k per 10 s at the title before the label-only batches stayed open, about 70k of them holding nothing but label stores; about 18k after. ### 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 (attach them to this PR) - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none. #374 adds lines at the same spot in `preparePacketMemory`, so whichever lands second needs a small rebase. - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 23:47:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T23:47:22Z.


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
#419 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19
#425 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19
#426 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp L6, L19
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5963246242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/409#issuecomment-5963246242). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T23:47:22Z. --- <!-- 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 | |---|---|---|---| | #419 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` [L6](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L6), [L19](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L19) | | | | #425 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` [L6](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L6), [L19](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L19) | | | | #426 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp` [L6](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L6), [L19](https://github.com/boykopovar/AnyPS5/blob/aa23d52878ce0b490d6ca051642cc73a928fa6e7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketMemory.cpp#L19) | | |
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!409
No description provided.