fix(libkernel): submit APR command buffers asynchronously #2455

Closed
Scramblrrrr wants to merge 1 commit from upstream-pr/2455 into main
Scramblrrrr commented 2026-10-09 21:50:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-09T21:50:36Z.


What

APR submission currently runs the command stream synchronously. A stream that waits for a value written by its submitting thread after the call returns therefore deadlocks. PPSA11386 (007 First Light) records a WaitOnAddress followed by a file read, submits through sceKernelAprSubmitCommandBufferAndGetId, writes the awaited value immediately after submission, then calls sceKernelAprWaitCommandBuffer. The submit never reaches that write on main.

Snapshot each submitted command stream into an owned FIFO job and return its submission ID immediately. Completion waits now wait for that job and propagate execution exceptions instead of always returning success. Successful jobs release their command storage and completion records; repeated waits remain valid. Buffers with invalid bounds and unknown IDs are rejected. Execution failures without an observable submission ID terminate instead of silently reporting success.

The asynchronous contract is corroborated by ampr_emu's APR submission reactor. No game assets or title-specific constants are added. AMM submission remains unchanged.

On Windows the queue has process lifetime: destroying a worker during PRX teardown joins under the loader lock and hangs. Linux uses a stoppable worker and cancels unsatisfied waits during queue destruction. Priority scheduling, console error codes, ID rollover, result-buffer layout and unloading libkernel while the Windows process stays alive remain unverified and are recorded in TechnicalDebt.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, Ryzen 7 7800X3D / RTX 5070 Ti.

  • guest_ampr_markers passed in 0.07 seconds, including existing command recording, counters, waits, event queues, file gather/scatter and AMM mapping cases. Existing APR checks explicitly wait for completion before inspecting results.
  • New regression verifies submission returns before an unsatisfied address wait, completion remains blocked until the caller releases it, and overwriting the original buffer after submission does not alter execution. It also checks repeat waits, unknown IDs, malformed buffer bounds and worker-exception propagation.
  • Five focused tests passed together: guest_ampr_markers, agc_shader_device_profile, agc_driver_runtime_images, agc_spirv_module and agc_structurizer. The shader tests were run on a local integration build containing upstream #2311 and #2282; those changes are not included in this PR. The APR source and test baseline are unchanged between that build's base and this PR's current-main base.
  • PPSA11386 diagnostic launch progressed past the reproduced file-reading deadlock and reached another shader compilation failure. That launch also uses local display/SSL changes, the dump-provided PlayGo module and a debugger-only Share Play bypass. No rendered frame, menu, controls or playable stability is claimed.
  • tools/check_conventions.py --base origin/main and git diff --check passed. Linux has not been run locally.

Checklist

  • Based on current main; no other open PR found implementing asynchronous APR submission
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except permitted namespace/header conventions
  • Unimplemented execution paths fail; no silent success bypass added
  • No investigation files, logs, screenshots or game assets added
  • No new third-party code
  • Generic behavior rather than a title-specific workaround
  • Depends on: none for this change; diagnostic title progress uses the integration changes listed above
  • AI-assisted: yes, with Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806243827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2455). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-09T21:50:36Z. --- ### What APR submission currently runs the command stream synchronously. A stream that waits for a value written by its submitting thread after the call returns therefore deadlocks. PPSA11386 (007 First Light) records a WaitOnAddress followed by a file read, submits through sceKernelAprSubmitCommandBufferAndGetId, writes the awaited value immediately after submission, then calls sceKernelAprWaitCommandBuffer. The submit never reaches that write on main. Snapshot each submitted command stream into an owned FIFO job and return its submission ID immediately. Completion waits now wait for that job and propagate execution exceptions instead of always returning success. Successful jobs release their command storage and completion records; repeated waits remain valid. Buffers with invalid bounds and unknown IDs are rejected. Execution failures without an observable submission ID terminate instead of silently reporting success. The asynchronous contract is corroborated by [ampr_emu's APR submission reactor](https://github.com/drakmor/ampr_emu/blob/main/src/ampr_emu_apr_services.cpp). No game assets or title-specific constants are added. AMM submission remains unchanged. On Windows the queue has process lifetime: destroying a worker during PRX teardown joins under the loader lock and hangs. Linux uses a stoppable worker and cancels unsatisfied waits during queue destruction. Priority scheduling, console error codes, ID rollover, result-buffer layout and unloading libkernel while the Windows process stays alive remain unverified and are recorded in TechnicalDebt. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, Ryzen 7 7800X3D / RTX 5070 Ti. - guest_ampr_markers passed in 0.07 seconds, including existing command recording, counters, waits, event queues, file gather/scatter and AMM mapping cases. Existing APR checks explicitly wait for completion before inspecting results. - New regression verifies submission returns before an unsatisfied address wait, completion remains blocked until the caller releases it, and overwriting the original buffer after submission does not alter execution. It also checks repeat waits, unknown IDs, malformed buffer bounds and worker-exception propagation. - Five focused tests passed together: guest_ampr_markers, agc_shader_device_profile, agc_driver_runtime_images, agc_spirv_module and agc_structurizer. The shader tests were run on a local integration build containing upstream #2311 and #2282; those changes are not included in this PR. The APR source and test baseline are unchanged between that build's base and this PR's current-main base. - PPSA11386 diagnostic launch progressed past the reproduced file-reading deadlock and reached another shader compilation failure. That launch also uses local display/SSL changes, the dump-provided PlayGo module and a debugger-only Share Play bypass. No rendered frame, menu, controls or playable stability is claimed. - tools/check_conventions.py --base origin/main and git diff --check passed. Linux has not been run locally. ### Checklist - [x] Based on current main; no other open PR found implementing asynchronous APR submission - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except permitted namespace/header conventions - [x] Unimplemented execution paths fail; no silent success bypass added - [x] No investigation files, logs, screenshots or game assets added - [x] No new third-party code - [x] Generic behavior rather than a title-specific workaround - [x] Depends on: none for this change; diagnostic title progress uses the integration changes listed above - [x] AI-assisted: yes, with Codex
github-actions[bot] commented 2026-10-09 22:01:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:01:30Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089982069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2455#issuecomment-6089982069). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:01:30Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Scramblrrrr commented 2026-10-10 10:48:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-10T10:48:39Z.


Coordination update: SleglJan/AnyPS5#20 is the agreed canonical APR implementation. Its detached priority lanes and libc shutdown hook avoid joining from loader-lock teardown. Our exact b225b3fb Windows cross-check passed 30 runs of each of guest_ampr_markers, guest_ampr_lane_failure and guest_ampr_shutdown (90/90); the collaborator also reports Windows CI passing. I am keeping this overlapping PR closed rather than advancing a second APR implementation. If a distinct Windows teardown failure is reproduced, it will be addressed on the canonical branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096713771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2455#issuecomment-6096713771). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-10T10:48:39Z. --- Coordination update: SleglJan/AnyPS5#20 is the agreed canonical APR implementation. Its detached priority lanes and libc shutdown hook avoid joining from loader-lock teardown. Our exact b225b3fb Windows cross-check passed 30 runs of each of guest_ampr_markers, guest_ampr_lane_failure and guest_ampr_shutdown (90/90); the collaborator also reports Windows CI passing. I am keeping this overlapping PR closed rather than advancing a second APR implementation. If a distinct Windows teardown failure is reproduced, it will be addressed on the canonical branch.

Pull request closed

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!2455
No description provided.