feat(libSceAjm): run PS4 batch buffer jobs in the console's chunk layout #9637
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9637"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T05:43:51Z.
What
Knowledge is Power: Decades (CUSA12435, Wwise), the one PS4 title observed, builds its AJM batches with the PS4 SDK's inline batch helpers, which end in four libSceAjm exports:
sceAjmBatchJobControlBufferRa,sceAjmBatchJobRunBufferRa,sceAjmBatchJobRunSplitBufferRaandsceAjmBatchStartBuffer. Unlike the PS5 builders, whose batch records are private to the library, here the batch buffer belongs to the title: the SDK code reads the position each builder returns, sizes the buffer for the console's jobs and may write chunks itself. So the buffer has to use the console's layout. Onmain, #9433 added the PS4libSceAjmwith three of the four as throwing stubs, andsceAjmBatchJobRunBufferRa(ElslOCpOIns) is only a throwing stub inlibSceAjmi.This implements the layout in
libSceAjm.native/src/Ajm.cpp, whichlibSceAjmis built from:sceAjmBatchStartBufferwalks the chunks, skips inline-data chunks, turns each job into the library's existing control, run or statistics job and runs it with the existing decoders (ATRAC9, MP3, M4AAC, Opus), so the sideband results are the ones the PS5 path writes. LikesceAjmBatchStart, it rejects a context that initialization did not allocate, and the batch belongs to its context.0x11output run,0x12output control), bits 6-25 the payload. The builders leave bits 5, 26, 27 and 31 as they were, and a title that reuses its batch memory carries the previous batch's bytes there, so those bits are ignored.RUN_MULTIPLE_FRAMESreports which side ran out, as the console does:PARTIAL_INPUT(0x8) when the input ran out with room left, on a superframe boundary or not;NOT_ENOUGH_ROOM(0x10) when the room ran out with input left, after any number of frames, and with nothing consumed for a zero room; both (0x18) when the input ended just as the output filled, which is every Wwise run job. The ATRAC9 format reports the frame's bitrate (frame bytes x 8 x sample rate / 256: 168000, 84000 and 384000 measured). Resampled runs keep the earlier rule, as they were not measured.RUN_MULTIPLE_FRAMESdecodes exactly one ATRAC9 frame and reports 0, as the probe measured on the PS4. A job from the PS5 builders still decodes its whole input, which FMOD in PPSA29141 relies on; the PS5 console's behaviour there is not measured.sceAjmBatchStartBufferreturns0x80930011(MALFORMED_BATCH) and fills the error record with0x80930016(INVALID_ADDRESS), the job chunk's address, the chunk's offset in the job and the job's return address. A size that is not a multiple of 8, a chunk that overruns its job or the batch, and a job without a flags chunk are refused the same way, not measured; the record then holds0x80930011. Unknown chunk kinds and control flags other than RESET, INITIALIZE and SIDEBAND_GAPLESS_DECODE throw.libSceAjm/Export.cppare dropped. The throwingsceAjmBatchJobRunBufferRaoflibSceAjmistays, declared assceAjmBatchJobRunBufferRa_nid_disambig1: the NID patcher exports it under the name's NID, so a title importing it fromlibSceAjmistill gets the not-implemented error at call time, and the two libraries no longer export one name.The layout (chunk kinds 0, 1, 2, 3, 4, 6, 7, 17, 18, the builders' chunk order, statistics instance
0x80000) follows shadPS4's PS4 library reimplementation. A GoldHEN user-mode plugin dumped 32 545 batches that Knowledge is Power: Decades (CUSA12435, Wwise) started on a PS4. They confirmed the 64-byte control and 80-byte run jobs byte for byte, the header bits above, and the0x18result and bitrate of all 14 680 traced run jobs, which each decode 4 frames into exactly 4 frames of room. Probe runs of one of the title's ATRAC9 streams through the same builders on the PS4 (fresh instance per case: input ending with room left, room ending with input left, half a superframe of room, zero room, exact fit) gave the result rules above, showed that a run withoutRUN_MULTIPLE_FRAMESdecodes exactly one frame on the console (kept as the whole input here, which a PS5 title needs; noted in the debt), that the console rejects the tests' synthetic silent superframe after three frames where LibAtrac9 decodes four, and that LibAtrac9 matches the console's PCM of that stream within 4 LSB (83.5% of samples exactly). The statistics instance and the inline chunk come from shadPS4 only; the debt entries say what is measured and what is not. The PS5sceAjmBatchStartpath and its records are unchanged, apart from the ATRAC9 exact-fit result and bitrate, which both paths share.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, NVIDIA RTX 2080, on
mainat7e69be6793, merged into this branch. This was first opened as Get-fix/AnyPS5#17 against #6977's branch, where it was reviewed and extended with the PS4 measurements; it is opened here as one commit at Get-fix's request.guest_ajmpasses, with seven new cases:TestConsoleBufferJobsbuilds a control job (with a return address), a run job and a split run job with the three builders, checks the returned positions and the chunk words, starts the batch withsceAjmBatchStartBufferand checks the control result and both run sidebands (result, consumed, written, total samples, frames) and the decoded PCM.TestConsoleHandWrittenJobswrites a batch word by word: an inline chunk holding ATRAC9 initialize parameters, a control job whose input points into it, a run job and a statistics job. It checks their results, then that a size not a multiple of 8, a job without flags and an overrunning job return0x80930011, and that an unknown chunk kind throws.TestConsoleStaleHeaderBitsruns a hand-written batch with every bit the console's builders never write set, and checks it runs exactly as the clean batch.TestAt9FlagRulesruns the five fits above and checks the result, the bytes consumed, the output written and the frame count of each.TestConsoleBufferEdgesruns a job with zero-size input and output chunks beside real ones (decodes as without them), a job whose only output has size zero (0x10, nothing consumed), and two batches with a null input or output address, which are refused with the measured error record while the control job before them stays unrun.TestConsoleEmptyBatchchecks the empty-batch contract: a null batch address is0x80930005with size 0 or 16, a null batch id is0x80930005, and a batch of zero bytes at a non-null address starts, returns an id and completes at once.TestConsoleSingleFrameRunruns a console job withoutRUN_MULTIPLE_FRAMESon a whole superframe with room for four frames and checks that one frame is decoded with result 0, the PCM after it untouched.0x18; the helpers that stream a decode accept0x8and0x10where one side runs out.guest_ajm_vibrationpasses; its exact-fit run now expects0x18(it expected 0 before). Vibration streams were not in the trace.check_conventionspasses; the patchedlibSceAjmi.prxstill exportsElslOCpOIns(objdump).ps4probe, the console's builders, a control job before each run job): zero-size input and output chunks alone, beside a real chunk and with a null address; null addresses with a nonzero size as the first or second input chunk and as the output chunk. They gave the rules above; the refused batches ran nothing.0x6001, run flags0xc00000001001, 56-byte sidebands), every one with result 0 under that commit's rules, about 650 s of decoded PCM per run, and the title reached its animated title screen. One of the four runs stopped before that on aUnityGfxDeviceWorkerfault in the guest heap that runs with every AJM job skipped also hit; it is not in AJM. Without this PR the title aborts at its firstsceAjmBatchJobControlBufferRa(not implemented).#9483 changes the last lines of
sceAjmBatchStart's job loop, next to where this moves the batch registration intoRegisterBatch, so the two conflict in three lines; #9481 and #9034 also add debt entries tolibSceAjm.native.md. I can rebase onto whichever lands first.Checklist
main(7e69be6793, merged in); no other open PR implements the same functions (searched boykopovar/AnyPS5 and Get-fix/AnyPS5 for Ajm, BufferRa and StartBuffer)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)sceAjmBatchJobControlBufferRawithout thisImported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:13:19Z.
Two findings from review, the first is the one I would block on.
1. The removed libSceAjmi stub turns a runtime error into an unresolved import. The diff deletes
sceAjmBatchJobRunBufferRafromcore/libs/prx/libSceAjmi/Export.cpp. That export is in the PS5 3.20 export table for module libSceAjmi (the debt entry cites that list), so a title importing it under that module previously hitNotImplemented_nid_no_patchat call time; after this PR the import doesn't resolve and the title dies at startup instead — and per CONTRIBUTING missing imports must surface as clear startup errors, not as a silent behavioral change via another module. The PR keeps the siblingsceAjmBatchJobInlineBufferstub in place, which is the declare-in-place pattern it follows elsewhere, and the name-disambiguation machinery (_nid_no_patchhandling intools/nid_names.py) exists precisely for this libSceAjm/libSceAjmi collision. Also,docs/dev/debt/libSceAjmi.mdis unchanged on this branch and still says "5 named callable exports ... throw throughNotImplemented_nid_no_patch", while the Export.cpp it links now contains onlysceAjmBatchJobInlineBuffer. Either keep the stub, or remove the export intentionally and update that debt entry to say so.Verified on the branch: the file now holds only the InlineBuffer stub, and the debt file is byte-identical to main's.
2. Asymmetric input/output buffering in
RunConsoleJob's PS4-buffer block. Inputs are pushed whensize != 0alone, outputs requireptr && size. A null-input-with-nonzero-size batch then reaches the copy path; and a zero-size output room silently becomes a buffer-less run, where the PS5 path answersNOT_ENOUGH_ROOMunder the new flag rules. If the PS4-measured behavior really differs in both cases, say so in the debt entry; otherwise the two paths should share the same predicate.Also worth folding into the debt entry: the ATRAC9 result-flag values that the new
//comments inGuestAjm.cppcarry ("PARTIAL_INPUT | NOT_ENOUGH_ROOM as on the console", the 0x8/0x10/0x18 splits) are console-measured behavior, and debt entries are where behavior provenance lives. The conventions gate passed only because the PR touches technical debt, so those comments are tolerated — the values should not live only in the test.The chunk-walk bounds checks, the ATRAC9 bitrate math and the result-identity with the PS5 path all check out; no null-deref path reaches
RegisterBatchfrom either call site.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:21:10Z.
Review: CHANGES_REQUESTED
The PS4 trace evidence and title stop are substantial, and the batch bounds/result handling have received useful independent review. Current-head blockers remain:
sceAjmBatchJobRunBufferRafromlibSceAjmiremoves an existing throwing export. That changes a title importing this module from a call-timeNotImplemented_nid_no_patcherror to an unresolved import at startup, anddocs/dev/debt/libSceAjmi.mdstill claims five exports throw although only one remains. Preserve the stub (the NID-name disambiguation supports the collision) or intentionally remove it with aligned debt documentation and evidence.RunConsoleJob, inputs are queued for any nonzero size even with a null pointer, while outputs require both pointer and size. That can feed a null input into the copy path and silently omit a zero-size output buffer. Please align the predicates or add PS4-measured evidence and debt text for these cases.Hosted eligibility/conventions/intake/labels/report pass; product test jobs were skipped by path filters. The detailed Windows tests and PS4 probes are author-reported; I did not rerun the audio suite locally. The shared-code overlaps with #9483 and debt overlap with #8468 require an agreed order/dependency before merge.
Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T09:44:41Z.
Thanks both. Pushed cb3e854a59 and 589189b661; point by point:
sceAjmBatchJobRunBufferRa_nid_disambig1, the suffixcore/libs/nidandtools/nid_names.pystrip before hashing: the patchedlibSceAjmi.prxstill exportsElslOCpOIns(checked with objdump), a title importing it from libSceAjmi gets the not-implemented error at call time as onmain, and the two libraries no longer define one name, whichcheck_conventionsrefuses as a duplicate export.docs/dev/debt/libSceAjmi.mdsays so.{ptr, 0}as the only output gives0x10with nothing consumed, the same as no output chunk;{ptr, 0}as the only input gives 0, the same as no input chunk;{NULL, 0}behaves the same; a zero-size chunk next to a real one changes nothing;sceAjmBatchStartBufferreturn0x80930011and fill the error record with0x80930016, the job chunk's address, the chunk's offset in the job (24, 40 and 48 in those batches) and the job's return address, and the control job before it does not run.The reader now does the same: it reads the whole batch first, inputs and outputs share one predicate, a refused job runs nothing, and the error record is filled as measured. Debt entry "sceAjmBatchStartBuffer refusals"; test
TestConsoleBufferEdges.//comments inGuestAjm.cppare gone. The 0x8/0x10/0x18 rules and the stale header bits were already in the debt entries, which are their home.sceAjmBatchStart's loop and one debt line, both trivial). If you would rather merge this first, those two rebase in minutes as well.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:51:43Z.
Review: CHANGES_REQUESTED
Thanks for the follow-up evidence. The latest head addresses my earlier findings: the libSceAjmi throwing export is restored with NID disambiguation, and the buffer edge rules now match the reported PS4 probes. The title is linked to the correct Game bring-up discussion, and the current-main conventions check and
git diff --checkpass.One new correctness issue:
sceAjmBatchStartBufferallows(batch == nullptr, batch_size == 0)past its parameter check, then evaluatesbatch + batch_size. Pointer arithmetic on a null pointer is undefined even for an offset of zero. Please either reject a null batch explicitly or avoid forming the end pointer unlessbatchis nonnull, and add a regression for the chosen empty-batch contract.Before merge, the current base also needs updating: this PR targets
4a17c71, 62 commits behindmainat8b3a6ba. It still overlaps open #9483 inAjm.cppand #8468 in the AJM debt file; CONTRIBUTING.md requires agreeing with those authors on landing order and recording any dependency, while the checklist currently saysDepends on: none. Please coordinate and correct the checklist before the rebase/merge.Validation on this Linux host: exact-head
git diff --checkandtools/check_conventions.pyagainst current main pass. I attempted a focused full configure, but it stops before compilation because this host has no SDL2 development package and the SDL2 submodule is not initialized; no localguest_ajmrun is claimed. Hosted product jobs are skipped by path filters. The author reports Windowsguest_ajm/vibration tests and PS4 FW 10.71 probes; those are not independently reproduced here.Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T13:35:10Z.
Thanks. Pushed ef01ffaf38 (on top of the main merge 29364e1cf0):
sceAjmBatchStartBuffernow rejects a null batch address with0x80930005whatever the size, the PS5 builders' answer for a null buffer (sceAjmBatchInitialize), so the end pointer is only formed from a real address. A batch of zero bytes keeps its contract: it starts, runs nothing and completes at once.TestConsoleEmptyBatchcovers a null batch with size 0 and 16, a null batch id, and the empty batch's start, wait and second wait. I tried to measure both on the PS4 with the same probe harness as before; the console itself froze at the null-batch call before a result was written and had to be power-cycled, so neither the null nor the empty batch is measured on a console, and I will not retry that one on hardware. The debt entry "sceAjmBatchStartBuffer null and empty batches" says what is measured and what is not.mainat830ccd121fis merged into the branch (no Ajm file changed onmainsince4a17c71);guest_ajm,guest_ajm_vibrationandcheck_conventionspass on it.Depends on: #9483, #8468. If either author prefers the other order, I will switch.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T00:10:12Z.
Review: APPROVED
The previous findings are addressed on the current head: null batch storage is rejected before end-pointer formation, the empty-batch test uses valid non-null storage, and the debt/description now state that contract consistently. The branch merges cleanly with current main, and conventions, labels and report pass. Product build/test jobs are skipped by repository path filters; the author reports guest_ajm and guest_ajm_vibration pass 3/3 on this head, which I did not independently rerun. #9483 remains correctly listed as a dependency and must land first per the agreed order.