feat(libSceJxr): allocate prediction rows on the guest heap #16827

Closed
MarrasFederico wants to merge 3 commits from upstream-pr/16827 into main
MarrasFederico commented 2026-11-07 17:25:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-07T17:25:11Z.


What

allocatePredInfo was a parameterless placeholder that threw. It now follows pinned jxrlib strPredQuant.c on the caller's LP64 CWMImageStrCodec: one guest malloc block of cmbWidth x channels x 2 prediction entries (48 bytes each) is split into a current and a previous row per channel, every entry's piAD points at its own iAD, and pPredInfoMemory keeps the block. A failed allocation returns ICERR_ERROR (-1) and leaves the codec unchanged; success returns ICERR_OK (0).

The block comes from the guest heap (malloc_nid_postfix), like allocateQuantizer, so the guest's own free or freePredInfo can release it. A null codec, more than 16 channels (jxrlib would write past PredInfo[16]) or a size that overflows size_t throws std::invalid_argument. Channels past cNumChannels keep their row pointers, as in jxrlib.

The test builds codecs with 1, 6, 11 and 16 channels and widths 1, 5 and 9, runs this export and jxrlib's own allocatePredInfo on copies, and checks that both produce the same row layout and piAD links and leave the unused channels alone; it also checks the null-codec and 17-channel errors.

allocatePredInfo - not measured on a PS5: prototype and layout are inferred from the export name; the debt entry is in docs/dev/debt/libSceJxr.md.

Tested

Ubuntu 26.04.1 LTS x86-64, GCC 15.2.0, Release, BUILD_TESTING=ON, base 12dafe416092f4ff2faca0a54891413fb2d0f7c1. No PS5 hardware or title was tested; Windows and macOS were not tested.

  • Built core/libs/prx/libSceJxr/all serially with nice -n 19 cmake --build build --parallel 2 --target core/libs/prx/libSceJxr/all.
  • ctest --test-dir build -R 'guest_jxr' --output-on-failure passes (100% tests passed out of 15).
  • On current main the export is a parameterless placeholder that throws through NotImplemented_nid_no_patch, so the new assertions cannot pass there.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check pass.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5204146054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16827). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-07T17:25:11Z. --- ### What `allocatePredInfo` was a parameterless placeholder that threw. It now follows pinned jxrlib [strPredQuant.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strPredQuant.c#L125-L155) on the caller's LP64 `CWMImageStrCodec`: one guest `malloc` block of `cmbWidth` x channels x 2 prediction entries (48 bytes each) is split into a current and a previous row per channel, every entry's `piAD` points at its own `iAD`, and `pPredInfoMemory` keeps the block. A failed allocation returns `ICERR_ERROR` (-1) and leaves the codec unchanged; success returns `ICERR_OK` (0). The block comes from the guest heap (`malloc_nid_postfix`), like `allocateQuantizer`, so the guest's own `free` or `freePredInfo` can release it. A null codec, more than 16 channels (jxrlib would write past `PredInfo[16]`) or a size that overflows `size_t` throws `std::invalid_argument`. Channels past `cNumChannels` keep their row pointers, as in jxrlib. The test builds codecs with 1, 6, 11 and 16 channels and widths 1, 5 and 9, runs this export and jxrlib's own `allocatePredInfo` on copies, and checks that both produce the same row layout and `piAD` links and leave the unused channels alone; it also checks the null-codec and 17-channel errors. [allocatePredInfo](https://github.com/MarrasFederico/AnyPS5/blob/c3708939a35d8e3c9d52991099a25af2ef2a5598/core/libs/prx/libSceJxr/src/Predict.cpp) - not measured on a PS5: prototype and layout are inferred from the export name; the debt entry is in `docs/dev/debt/libSceJxr.md`. ### Tested Ubuntu 26.04.1 LTS x86-64, GCC 15.2.0, Release, `BUILD_TESTING=ON`, base `12dafe416092f4ff2faca0a54891413fb2d0f7c1`. No PS5 hardware or title was tested; Windows and macOS were not tested. - Built `core/libs/prx/libSceJxr/all` serially with `nice -n 19 cmake --build build --parallel 2 --target core/libs/prx/libSceJxr/all`. - `ctest --test-dir build -R 'guest_jxr' --output-on-failure` passes (100% tests passed out of 15). - On current `main` the export is a parameterless placeholder that throws through `NotImplemented_nid_no_patch`, so the new assertions cannot pass there. - `python3 tools/check_conventions.py --base upstream/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 - [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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
gabichuuuuu commented 2026-11-08 18:18:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T18:18:47Z.

Review: COMMENTED


Windows run of head 0788d07102, merged alone onto main f35f1e5eca (clean merge). Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, BUILD_TESTING=ON.

  • All 16 guest_jxr* tests with --repeat until-fail:5: every run passes.
  • No runnable negative control: with main's libSceJxr/Export.cpp and this PR's header, the build stops with conflicting declaration of C function, because the test calls exports whose signatures only exist with this PR.

Merge order: every open libSceJxr PR from this series edits the same "remaining stubs" line in docs/dev/debt/libSceJxr.md, so each merge will conflict with the next one there.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5819052828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16827#pullrequestreview-5819052828). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T18:18:47Z. **Review:** COMMENTED --- Windows run of head `0788d07102`, merged alone onto `main` `f35f1e5eca` (clean merge). Setup: Windows 11, WinLibs GCC 15.2 (`x86_64-ucrt-posix-seh`), Release, `BUILD_TESTING=ON`. - All 16 `guest_jxr*` tests with `--repeat until-fail:5`: every run passes. - No runnable negative control: with `main`'s `libSceJxr/Export.cpp` and this PR's header, the build stops with `conflicting declaration of C function`, because the test calls exports whose signatures only exist with this PR. **Merge order:** every open libSceJxr PR from this series edits the same "remaining stubs" line in `docs/dev/debt/libSceJxr.md`, so each merge will conflict with the next one there.

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