fix(libkernel): submit APR command buffers that were not constructed #2357

Merged
NahuelGenchi merged 1 commit from upstream-pr/2357 into main 2026-10-10 04:47:19 +00:00
NahuelGenchi commented 2026-10-09 16:14:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T16:14:34Z.


What

sceKernelAprSubmitCommandBuffer returned EINVAL for any buffer object that sceAmprAprCommandBufferConstructor had not tagged with BufferType::Apr. That tag is AnyPS5's own. In the retail object, as ampr_emu lays it out, the type word only holds state bits (gather/scatter valid, map active). The CommandBuffer constructor writes 0 there and the AprCommandBuffer constructor only zeroes the map and gather/scatter state. So a zero-filled object that was bound with SetBuffer is a valid APR buffer, and ampr_emu's submit does not check the type.

CRI's file system, as linked into Sonic Origins (PPSA05324), relies on this. It lays out its 0x28-byte AprCommandBuffer objects in its own zeroed work memory and never calls either constructor: it only calls SetBuffer, Reset and the record functions. Its first read is a ReadFile, a WriteAddress and a WriteKernelEventQueue, submitted with priority 1. That submit returned 0x80020016, CRI logged FS:Failed in submitCommandBuffer and stopped. No movie was ever opened, and the title stayed on a white screen after the SEGA logo (#2021).

The submit now only rejects a null buffer. sceAmprAprCommandBufferConstructor still sets the tag, and sceAmprCommandBufferGetType still returns it. ampr_emu returns 0 there, but that is a separate change.

Tested

Ubuntu 26.04, GCC 15.2, Release build, AMD Radeon R9 380 (RADV, Mesa 26.0.8).

  • guest_ampr_markers passes. The new check builds a buffer object as CRI does: zero-filled, no constructor, SetBuffer and Reset. It then records a ReadFile, a completion write and an AMPR event, and submits with priority 1. It checks the read data, the written value and the event on the queue. Without the change it fails at the submit (GuestAmpr.cpp:542).
  • guest_equeue_events passes.
  • Sonic Origins (PPSA05324), on the testing branch from #2021 with this change, at 960x540 (--res_x=960 --res_y=540):
    • CRI reads raw/movie/sonicteam_logo_4k.usm and the H.264 decoder is created ([videodec2] decoder 1: codec=1 max 3840x2160).
    • The Sonic Team logo movie plays, followed by the Retro Engine, Headcannon and CRIWARE logos and the auto-save notice.
    • Without the change, the same build stays white after the SEGA logo.
  • tools/check_conventions.py --base origin/main and git diff --check pass.

Checklist

  • Based on current main; no other open PR implements the same functions (#1616 reorders this object but keeps the check)
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802984901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2357). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T16:14:34Z. --- ### What `sceKernelAprSubmitCommandBuffer` returned `EINVAL` for any buffer object that `sceAmprAprCommandBufferConstructor` had not tagged with `BufferType::Apr`. That tag is AnyPS5's own. In the retail object, as [ampr_emu](https://github.com/drakmor/ampr_emu) lays it out, the type word only holds state bits (gather/scatter valid, map active). The `CommandBuffer` constructor writes 0 there and the `AprCommandBuffer` constructor only zeroes the map and gather/scatter state. So a zero-filled object that was bound with `SetBuffer` is a valid APR buffer, and ampr_emu's submit does not check the type. CRI's file system, as linked into Sonic Origins (PPSA05324), relies on this. It lays out its 0x28-byte `AprCommandBuffer` objects in its own zeroed work memory and never calls either constructor: it only calls `SetBuffer`, `Reset` and the record functions. Its first read is a `ReadFile`, a `WriteAddress` and a `WriteKernelEventQueue`, submitted with priority 1. That submit returned `0x80020016`, CRI logged `FS:Failed in submitCommandBuffer` and stopped. No movie was ever opened, and the title stayed on a white screen after the SEGA logo (#2021). The submit now only rejects a null buffer. `sceAmprAprCommandBufferConstructor` still sets the tag, and `sceAmprCommandBufferGetType` still returns it. ampr_emu returns 0 there, but that is a separate change. ### Tested Ubuntu 26.04, GCC 15.2, Release build, AMD Radeon R9 380 (RADV, Mesa 26.0.8). - `guest_ampr_markers` passes. The new check builds a buffer object as CRI does: zero-filled, no constructor, `SetBuffer` and `Reset`. It then records a `ReadFile`, a completion write and an AMPR event, and submits with priority 1. It checks the read data, the written value and the event on the queue. Without the change it fails at the submit (`GuestAmpr.cpp:542`). - `guest_equeue_events` passes. - Sonic Origins (PPSA05324), on the testing branch from #2021 with this change, at 960x540 (`--res_x=960 --res_y=540`): - CRI reads `raw/movie/sonicteam_logo_4k.usm` and the H.264 decoder is created (`[videodec2] decoder 1: codec=1 max 3840x2160`). - The Sonic Team logo movie plays, followed by the Retro Engine, Headcannon and CRIWARE logos and the auto-save notice. - Without the change, the same build stays white after the SEGA logo. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions (#1616 reorders this object but keeps the check) - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kikoarl commented 2026-10-09 17:52:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:52:31Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at 6c81134f:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified GuestAmpr.cpp test suite. Unconstructed APR command buffers now gracefully handle submission without asserting or crashing.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086302331 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2357#issuecomment-6086302331). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T17:52:31Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `6c81134f`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified `GuestAmpr.cpp` test suite. Unconstructed APR command buffers now gracefully handle submission without asserting or crashing. LGTM!
popcoder565 commented 2026-10-09 19:41:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:41:53Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 6c81134f, merged onto main 8b393b6e in one build with 31 other PRs that had no Windows run.

  • This PR's tests pass: guest_ampr_markers.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088010156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2357#issuecomment-6088010156). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T19:41:53Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `6c81134f`, merged onto `main` 8b393b6e in one build with 31 other PRs that had no Windows run. - This PR's tests pass: `guest_ampr_markers`. - Full ctest in that build: 520 of 521. The one failure is `guest_offline_imports`, broken by #2359 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
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!2357
No description provided.