feat(libSceJxr): implement quantizer sharing and DC/AC prediction state helpers #15479

Merged
Noxy-HNR merged 6 commits from upstream-pr/15479 into main 2026-11-07 06:58:41 +00:00
Noxy-HNR commented 2026-11-03 14:43:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-03T14:43:00Z.


What

Five libSceJxr codec helpers currently throw: setUniformQuantizer, useDCQuantizer, useLPQuantizer, getDCACPredMode and updatePredInfo. They now call jxrlib's strcodec.c and strPredQuant.c, built from 3rdparty/jxrlib, through a C bridge (src/NativePredict.c). No jxrlib logic is copied into core/.

  • setUniformQuantizer points every tile's DC, LP or HP quantizers at tile 0's.
  • useDCQuantizer / useLPQuantizer copy a tile's DC quantizer into its first LP slot, or its LP quantizers into its HP slots.
  • getDCACPredMode picks the DC and AC prediction directions for a macroblock column from the current and previous prediction rows.
  • updatePredInfo stores a macroblock's DC, LP QP index and first AC row and column for the next prediction.

All five work on the caller's CWMImageStrCodec. The bridge asserts its LP64 layout (35,944 bytes, with the offsets these calls read), 432-byte tiles and 48-byte prediction entries. Before calling jxrlib, it throws on a null codec, tile table, used channel quantizer, prediction row, AC buffer or macroblock, more than 16 channels or quantizers, a tile past cNumOfSliceMinus1V, a column outside cmbWidth, a column 0 that needs a left neighbour, and an unknown color format. That the console's module uses these prototypes and layouts is inferred from the export names. Nothing is checked on a console, and the debt file records this. No title unblock is claimed.

allocateQuantizer, freeQuantizer, allocatePredInfo and freePredInfo are left as they are, because jxrlib allocates them with the host malloc.

Tested

New guest_jxr_predict test. Each case builds randomized codec state, clones it, runs the guest export on one copy and jxrlib directly on the other, and compares quantizer data, quantizer pointers (by offset) and prediction rows:

  • setUniformQuantizer for 1, 6, 11 and 16 channels, 1 to 4 tiles and all bands; useDCQuantizer and useLPQuantizer (0 to 16 quantizers) for every tile.
  • getDCACPredMode for every color format, every left/top context and every valid column, 8 random states each.
  • updatePredInfo for every color format and 1 to 16 channels, including a macroblock inside the codec itself.
  • Every rejected argument listed above.
  • Replacing any one of the five jxrlib calls in the bridge makes the test fail.

Results:

  • Current head 03fcc3d275, with main 04cdd52760 (after #14933) merged in: Linux x86-64 (Ubuntu 24.04, GCC 13), Release, ctest -R guest_jxr 11/11 passed in each of 3 runs. Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: 11/11 passed.
  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream d1ae628bc2: ctest -R guest_jxr 10/10 passed. Built with -fsanitize=undefined, the test reports no UBSan errors.
  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: the layout assertions hold, and ctest -R guest_jxr 10/10 passed in each of 3 runs, including the _patched lookup tests.
  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (405 libraries, 28,213 exports): passed.
  • python tools/pr_overlap.py --branch claude/jxr-predict (1,714 open PRs): no shared exports or new files, and no open PR mentions or adds these five functions. #14905, #14916, #15148 and #15232 touch neighbouring lines of CMakeLists.txt, Export.cpp, include/Api.hpp and the debt file, so whichever lands later will get main merged in. #15689 includes this PR and goes right after it.

No console or retail-title test.

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:5139194192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15479). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-03T14:43:00Z. --- ### What Five libSceJxr codec helpers currently throw: `setUniformQuantizer`, `useDCQuantizer`, `useLPQuantizer`, `getDCACPredMode` and `updatePredInfo`. They now call jxrlib's [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L876-L904) and [strPredQuant.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strPredQuant.c#L194-L306), built from `3rdparty/jxrlib`, through a C bridge (`src/NativePredict.c`). No jxrlib logic is copied into `core/`. - `setUniformQuantizer` points every tile's DC, LP or HP quantizers at tile 0's. - `useDCQuantizer` / `useLPQuantizer` copy a tile's DC quantizer into its first LP slot, or its LP quantizers into its HP slots. - `getDCACPredMode` picks the DC and AC prediction directions for a macroblock column from the current and previous prediction rows. - `updatePredInfo` stores a macroblock's DC, LP QP index and first AC row and column for the next prediction. All five work on the caller's `CWMImageStrCodec`. The bridge asserts its LP64 layout (35,944 bytes, with the offsets these calls read), 432-byte tiles and 48-byte prediction entries. Before calling jxrlib, it throws on a null codec, tile table, used channel quantizer, prediction row, AC buffer or macroblock, more than 16 channels or quantizers, a tile past `cNumOfSliceMinus1V`, a column outside `cmbWidth`, a column 0 that needs a left neighbour, and an unknown color format. That the console's module uses these prototypes and layouts is inferred from the export names. Nothing is checked on a console, and the debt file records this. No title unblock is claimed. `allocateQuantizer`, `freeQuantizer`, `allocatePredInfo` and `freePredInfo` are left as they are, because jxrlib allocates them with the host `malloc`. ### 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. --> New `guest_jxr_predict` test. Each case builds randomized codec state, clones it, runs the guest export on one copy and jxrlib directly on the other, and compares quantizer data, quantizer pointers (by offset) and prediction rows: - `setUniformQuantizer` for 1, 6, 11 and 16 channels, 1 to 4 tiles and all bands; `useDCQuantizer` and `useLPQuantizer` (0 to 16 quantizers) for every tile. - `getDCACPredMode` for every color format, every left/top context and every valid column, 8 random states each. - `updatePredInfo` for every color format and 1 to 16 channels, including a macroblock inside the codec itself. - Every rejected argument listed above. - Replacing any one of the five jxrlib calls in the bridge makes the test fail. Results: - Current head `03fcc3d275`, with `main` `04cdd52760` (after #14933) merged in: Linux x86-64 (Ubuntu 24.04, GCC 13), Release, `ctest -R guest_jxr` **11/11 passed in each of 3 runs**. Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: **11/11 passed**. - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, upstream `d1ae628bc2`: `ctest -R guest_jxr` **10/10 passed**. Built with `-fsanitize=undefined`, the test reports no UBSan errors. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: the layout assertions hold, and `ctest -R guest_jxr` **10/10 passed in each of 3 runs**, including the `_patched` lookup tests. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (405 libraries, 28,213 exports): passed. - `python tools/pr_overlap.py --branch claude/jxr-predict` (1,714 open PRs): no shared exports or new files, and no open PR mentions or adds these five functions. #14905, #14916, #15148 and #15232 touch neighbouring lines of `CMakeLists.txt`, `Export.cpp`, `include/Api.hpp` and the debt file, so whichever lands later will get `main` merged in. #15689 includes this PR and goes right after it. No console or retail-title test. ### 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 -->
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!15479
No description provided.