feat(libSceAjm): implement sceAjmBatchJobInlineBuffer #11238

Merged
zaryabzip merged 2 commits from upstream-pr/11238 into main 2026-10-28 23:16:13 +00:00
zaryabzip commented 2026-10-25 22:26:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-25T22:26:39Z.


What

Implements sceAjmBatchJobInlineBuffer in libSceAjm and in libSceAjmi. In libSceAjm it was the one PS4 batch builder still a stub after #9637 implemented sceAjmBatchJobControlBufferRa, sceAjmBatchJobRunBufferRa and sceAjmBatchJobRunSplitBufferRa. It goes in Ajm.cpp beside them, so libSceAjm and libSceAjm.native both export it. sceAjmBatchStartBuffer already skips inline chunks (kind 7), so a batch that carries a job's input inline now runs.

The behaviour is firmware 13.42's routine. BunnyFl ran it in an x86-64 emulator for both libSceAjm.sprx and libSceAjmi.sprx, which share the same 73-byte routine. It has not been measured on a console. The signature is void* (void* position, const void* data, size_t size, const void** batch_address), and the routine:

  • writes header word 0 as (word & ~0x1f) | 7, so bits 5-31 of what was already at position stay, as in fpPS4. shadPS4 and prosper write the word fresh. The reader takes the kind from the low bits, so the kept bits don't change parsing;
  • puts the size rounded up to 8 in word 1, keeping its low 32 bits, and uses the full 64-bit size for the copy and the returned cursor;
  • copies the data right after the header, leaves the padding as it was, and sets *batch_address to the copy;
  • checks nothing.

In libSceAjmi the export stays sceAjmBatchJobInlineBuffer_nid_disambig1, the way #9637 kept sceAjmBatchJobRunBufferRa there, so the patched libSceAjmi.prx exports stlghnic3Jc under its own name. It is now the same routine instead of a throwing stub. sceAjmBatchJobRunBufferRa in libSceAjmi still throws: the same comment says its code matches libSceAjm's, but it was not run.

The test in GuestAjm.cpp resolves both exports at runtime, so it also builds on main. The libSceAjmi one comes from the libSceAjmi.prx that add_test passes as an argument. It checks:

  • for both libraries, the header words (0xCDCDCDC7 over a 0xCD-filled buffer), the return value, *batch_address, the copied bytes and the untouched padding, for 13 bytes and for 0 bytes;
  • for libSceAjm, a full batch through sceAjmBatchStartBuffer: inline ATRAC9 initialize parameters, a control job built with sceAjmBatchJobControlBufferRa that reads them through the returned address, and a run job. The results match TestConsoleHandWrittenJobs.

guest_ajm_tests now also links ${CMAKE_DL_LIBS}, as guest_audio_propagation_tests does for dlsym.

Both debt entries cite the firmware run.

Tested

Windows 11 Home 25H2 (i7-11800H, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2, Release, BUILD_TESTING=ON) at 249fdf9246, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3) with it merged into main f1efa4ddc2:

  • No warnings in the changed files on either host.
  • ctest -R "guest_ajm|atrac9": 100% tests passed, 0 tests failed out of 6 on Windows, and out of 7 on Linux (Linux adds guest_ajm_teardown). The others are guest_ajm, guest_ajm_vibration, guest_ajm_wvorbis, atrac9_gradient, atrac9_config_data and ngs2_atrac9.
  • guest_ajm with --repeat until-fail:3: 3 of 3 on both hosts.
  • Baseline: on main with only this GuestAjm.cpp and the guest_ajm CMake changes, guest_ajm builds and then aborts with sceAjmBatchJobInlineBuffer is not exported by libSceAjm.native.prx on both hosts (Windows exit 0xc0000409).
  • The patched libSceAjmi.prx, libSceAjm.prx and libSceAjm.native.prx each export stlghnic3Jc once (objdump -p on Windows, nm -D on Linux).
  • The head, 53608ab573, changes only the failure message's library name on Linux, which printed (null). Rechecked on WSL2 merged into main 84ffc1ae2d: guest_ajm passes with no warnings, and the baseline message names libSceAjm.native.prx.
  • tools/check_conventions.py passes.

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 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: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009341144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11238). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-25T22:26:39Z. --- ### What Implements `sceAjmBatchJobInlineBuffer` in libSceAjm and in libSceAjmi. In libSceAjm it was the one PS4 batch builder still a stub after #9637 implemented `sceAjmBatchJobControlBufferRa`, `sceAjmBatchJobRunBufferRa` and `sceAjmBatchJobRunSplitBufferRa`. It goes in `Ajm.cpp` beside them, so libSceAjm and libSceAjm.native both export it. `sceAjmBatchStartBuffer` already skips inline chunks (kind 7), so a batch that carries a job's input inline now runs. The behaviour is firmware 13.42's routine. BunnyFl [ran it in an x86-64 emulator](https://github.com/boykopovar/AnyPS5/pull/11238#issuecomment-6418132093) for both `libSceAjm.sprx` and `libSceAjmi.sprx`, which share the same 73-byte routine. It has not been measured on a console. The signature is `void* (void* position, const void* data, size_t size, const void** batch_address)`, and the routine: - writes header word 0 as `(word & ~0x1f) | 7`, so bits 5-31 of what was already at `position` stay, as in [fpPS4](https://github.com/red-prig/fpPS4/blob/04cefd43e6fddd1ab033e7980cd356d14c964905/src/ajm/ps4_libsceajm.pas#L399-L410). [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/30f4170896ce974353a6f6486d0ecec179aec54b/src/core/libraries/ajm/ajm_batch.cpp#L406-L420) and [prosper](https://github.com/mattias800/prosper/blob/66433758f62d4cff6104d34a394eb42465d964b2/prosper/src/hle/audio/hle_audio.cpp#L2873-L2885) write the word fresh. The reader takes the kind from the low bits, so the kept bits don't change parsing; - puts the size rounded up to 8 in word 1, keeping its low 32 bits, and uses the full 64-bit size for the copy and the returned cursor; - copies the data right after the header, leaves the padding as it was, and sets `*batch_address` to the copy; - checks nothing. In libSceAjmi the export stays `sceAjmBatchJobInlineBuffer_nid_disambig1`, the way #9637 kept `sceAjmBatchJobRunBufferRa` there, so the patched `libSceAjmi.prx` exports `stlghnic3Jc` under its own name. It is now the same routine instead of a throwing stub. `sceAjmBatchJobRunBufferRa` in libSceAjmi still throws: the same comment says its code matches libSceAjm's, but it was not run. The test in `GuestAjm.cpp` resolves both exports at runtime, so it also builds on `main`. The libSceAjmi one comes from the `libSceAjmi.prx` that `add_test` passes as an argument. It checks: - for both libraries, the header words (0xCDCDCDC7 over a 0xCD-filled buffer), the return value, `*batch_address`, the copied bytes and the untouched padding, for 13 bytes and for 0 bytes; - for libSceAjm, a full batch through `sceAjmBatchStartBuffer`: inline ATRAC9 initialize parameters, a control job built with `sceAjmBatchJobControlBufferRa` that reads them through the returned address, and a run job. The results match `TestConsoleHandWrittenJobs`. `guest_ajm_tests` now also links `${CMAKE_DL_LIBS}`, as `guest_audio_propagation_tests` does for `dlsym`. Both debt entries cite the firmware run. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Home 25H2 (i7-11800H, WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2, Release, `BUILD_TESTING=ON`) at 249fdf9246, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3) with it merged into `main` f1efa4ddc2: - No warnings in the changed files on either host. - `ctest -R "guest_ajm|atrac9"`: `100% tests passed, 0 tests failed out of 6` on Windows, and `out of 7` on Linux (Linux adds `guest_ajm_teardown`). The others are `guest_ajm`, `guest_ajm_vibration`, `guest_ajm_wvorbis`, `atrac9_gradient`, `atrac9_config_data` and `ngs2_atrac9`. - `guest_ajm` with `--repeat until-fail:3`: 3 of 3 on both hosts. - Baseline: on `main` with only this `GuestAjm.cpp` and the `guest_ajm` CMake changes, `guest_ajm` builds and then aborts with `sceAjmBatchJobInlineBuffer is not exported by libSceAjm.native.prx` on both hosts (Windows exit 0xc0000409). - The patched `libSceAjmi.prx`, `libSceAjm.prx` and `libSceAjm.native.prx` each export `stlghnic3Jc` once (`objdump -p` on Windows, `nm -D` on Linux). - The head, 53608ab573, changes only the failure message's library name on Linux, which printed `(null)`. Rechecked on WSL2 merged into `main` 84ffc1ae2d: `guest_ajm` passes with no warnings, and the baseline message names `libSceAjm.native.prx`. - `tools/check_conventions.py` passes. ### 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 - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-25 22:30:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:30:13Z.

Review: APPROVED


Reviewed exact head 3052f69ccbb937883e657669c1fdb93429d4d4d5. The builder writes a kind-7 inline chunk, rounds the payload region to eight bytes, sets the returned address after the header, and leaves the padding untouched; the added end-to-end test feeds that address into a control job and runs a batch. The three cited emulator implementations agree on the basic layout, while the PR records the remaining differences and lack of a retail-console measurement in technical debt. Current-main conventions and diff-check pass. Hosted product/relinker jobs were skipped by path policy; the author reports focused Windows and WSL tests, which I did not rerun locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645685383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11238#pullrequestreview-5645685383). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:30:13Z. **Review:** APPROVED --- Reviewed exact head `3052f69ccbb937883e657669c1fdb93429d4d4d5`. The builder writes a kind-7 inline chunk, rounds the payload region to eight bytes, sets the returned address after the header, and leaves the padding untouched; the added end-to-end test feeds that address into a control job and runs a batch. The three cited emulator implementations agree on the basic layout, while the PR records the remaining differences and lack of a retail-console measurement in technical debt. Current-main conventions and diff-check pass. Hosted product/relinker jobs were skipped by path policy; the author reports focused Windows and WSL tests, which I did not rerun locally.
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!11238
No description provided.