feat(libSceJxr): implement codec row-state and coding-context reset helpers #15689

Merged
Noxy-HNR merged 13 commits from upstream-pr/15689 into main 2026-11-09 01:47:15 +00:00
Noxy-HNR commented 2026-11-04 05:58:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-04T05:58:18Z.


What

Implements seven libSceJxr exports as thin adapters over the pinned jxrlib (3rdparty/jxrlib, f7521879862b9085318e814c6157490dd9dbbdb4), through a C bridge in jxr_lookup_native:

  • checkImageBuffer and getTilePos (strcodec.c)
  • initMRPtr, advanceMRPtr, advanceOneMBRow and swapMRPtr (strcodec.c)
  • ResetCodingContext (image.c)

They act on the caller's LP64 CWMImageStrCodec (35,944 bytes) and its alpha codec, or on a 704-byte CCodingContext. _Static_asserts pin the sizes and the field offsets used. The prototypes come from jxrlib's strcodec.h; matching the export names to them is an inference.

  • Writes go through GuestArena::HostWrite. A codec, alpha codec or context that the host may not write throws std::invalid_argument, and no byte changes. checkImageBuffer only reads.
  • Inputs that would make jxrlib read or write out of bounds throw std::invalid_argument instead:
    • a null codec or context
    • more than 16 channels in either codec
    • more than 4096 tile columns or rows
    • a current tile index past the last tile when it would be read
    • in advanceMRPtr: a secondary codec (jxrlib asserts this), an unknown color format (it indexes cblkChromas), or a null row buffer it would advance

The debt entry records what is inferred, and the remaining-export count drops by seven.

Tested

New guest_jxr_rows test. It builds randomized codec pairs and runs each export on one copy and jxrlib's own function on a clone. It then compares the codecs (pointers by offset), row buffers, prediction rows and coding context. Coverage:

  • checkImageBuffer: YUV and non-YUV data, 7 color formats, 6 bit depths, 8 unit sizes and random strides, at each of 6 widths × 7 row counts.
  • getTilePos: walks a 12×8 macroblock grid for every 1–4 × 1–4 tile layout.
  • Row pointers: all 9 color formats, 1, 3, 4 and 16 channels, with and without an alpha codec, through initMRPtr, three advanceMRPtr calls, swapMRPtr and advanceOneMBRow.
  • ResetCodingContext: 8 random contexts.
  • Every rejection listed above.
  • Windows only: 7 guest direct-memory pages are made read-only with sceKernelMprotect, and PAGE_READONLY is confirmed with VirtualQuery. checkImageBuffer still reads the codec. Each mutating export throws with every page byte-for-byte unchanged, including when only the alpha codec is read-only. After write access is restored, the calls succeed.
  • Negative controls: on Windows, with the codec write check in Rows.cpp removed, the test crashes with an access violation (0xc0000005) on the read-only page. On Linux, with the jxrlib calls in getTilePos and swapMRPtr stubbed out, it fails with "getTilePos differs from jxrlib".

Results:

  • Current head 93b082c157, with main 04cdd52760 (after #14933) and the updated #15479 merged in: Ubuntu 24.04 x86-64, GCC 13.3.0, Release, ctest -R guest_jxr passed 12/12 (adding guest_jxr_quantizer from main) in each of 3 runs. Windows 11 x86-64, WinLibs GCC 15.2.0, Release: 12/12 passed.
  • Ubuntu 24.04 x86-64, GCC 13.3.0, Release: ctest -R guest_jxr passed 10/10 in each of 3 runs. With #15479 merged in, 11/11 (adding guest_jxr_predict) in each of 3 runs.
  • Windows 11 x86-64, WinLibs GCC 15.2.0, Release: ctest -R guest_jxr passed 10/10 in each of 3 runs, including the read-only page checks. No new warnings. With #15479 merged in, 11/11 in each of 3 runs.
  • python3 tools/check_conventions.py --base origin/main and git diff --check: passed. Merges cleanly with main at b8efa6292a.
  • python3 tools/pr_overlap.py --branch claude/jxr-row-state: no open PR implements the same exports or adds the same files. The other open libSceJxr PRs overlap only on the debt count line and neighbouring lines in Export.cpp and Api.hpp. #15479 changes the same debt lines, so this branch merges it in with those lines resolved, and this PR goes right after it. The check could not compare #7645, which conflicts with main; its libSceJxr/CMakeLists.txt change applies cleanly on top of this branch.

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: #15479
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5149669944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15689). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-04T05:58:18Z. --- ### What Implements seven libSceJxr exports as thin adapters over the pinned jxrlib (`3rdparty/jxrlib`, `f7521879862b9085318e814c6157490dd9dbbdb4`), through a C bridge in `jxr_lookup_native`: - `checkImageBuffer` and `getTilePos` ([strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L96-L170)) - `initMRPtr`, `advanceMRPtr`, `advanceOneMBRow` and `swapMRPtr` ([strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L175-L234)) - `ResetCodingContext` ([image.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/image.c#L148-L168)) They act on the caller's LP64 `CWMImageStrCodec` (35,944 bytes) and its alpha codec, or on a 704-byte `CCodingContext`. `_Static_assert`s pin the sizes and the field offsets used. The prototypes come from jxrlib's `strcodec.h`; matching the export names to them is an inference. - Writes go through `GuestArena::HostWrite`. A codec, alpha codec or context that the host may not write throws `std::invalid_argument`, and no byte changes. `checkImageBuffer` only reads. - Inputs that would make jxrlib read or write out of bounds throw `std::invalid_argument` instead: - a null codec or context - more than 16 channels in either codec - more than 4096 tile columns or rows - a current tile index past the last tile when it would be read - in `advanceMRPtr`: a secondary codec (jxrlib asserts this), an unknown color format (it indexes `cblkChromas`), or a null row buffer it would advance The debt entry records what is inferred, and the remaining-export count drops by seven. ### 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_rows` test. It builds randomized codec pairs and runs each export on one copy and jxrlib's own function on a clone. It then compares the codecs (pointers by offset), row buffers, prediction rows and coding context. Coverage: - `checkImageBuffer`: YUV and non-YUV data, 7 color formats, 6 bit depths, 8 unit sizes and random strides, at each of 6 widths × 7 row counts. - `getTilePos`: walks a 12×8 macroblock grid for every 1–4 × 1–4 tile layout. - Row pointers: all 9 color formats, 1, 3, 4 and 16 channels, with and without an alpha codec, through `initMRPtr`, three `advanceMRPtr` calls, `swapMRPtr` and `advanceOneMBRow`. - `ResetCodingContext`: 8 random contexts. - Every rejection listed above. - Windows only: 7 guest direct-memory pages are made read-only with `sceKernelMprotect`, and `PAGE_READONLY` is confirmed with `VirtualQuery`. `checkImageBuffer` still reads the codec. Each mutating export throws with every page byte-for-byte unchanged, including when only the alpha codec is read-only. After write access is restored, the calls succeed. - Negative controls: on Windows, with the codec write check in `Rows.cpp` removed, the test crashes with an access violation (0xc0000005) on the read-only page. On Linux, with the jxrlib calls in `getTilePos` and `swapMRPtr` stubbed out, it fails with "getTilePos differs from jxrlib". Results: - Current head `93b082c157`, with `main` `04cdd52760` (after #14933) and the updated #15479 merged in: Ubuntu 24.04 x86-64, GCC 13.3.0, Release, `ctest -R guest_jxr` passed 12/12 (adding `guest_jxr_quantizer` from `main`) in each of 3 runs. Windows 11 x86-64, WinLibs GCC 15.2.0, Release: 12/12 passed. - Ubuntu 24.04 x86-64, GCC 13.3.0, Release: `ctest -R guest_jxr` passed 10/10 in each of 3 runs. With #15479 merged in, 11/11 (adding `guest_jxr_predict`) in each of 3 runs. - Windows 11 x86-64, WinLibs GCC 15.2.0, Release: `ctest -R guest_jxr` passed 10/10 in each of 3 runs, including the read-only page checks. No new warnings. With #15479 merged in, 11/11 in each of 3 runs. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check`: passed. Merges cleanly with `main` at b8efa6292a. - `python3 tools/pr_overlap.py --branch claude/jxr-row-state`: no open PR implements the same exports or adds the same files. The other open libSceJxr PRs overlap only on the debt count line and neighbouring lines in `Export.cpp` and `Api.hpp`. #15479 changes the same debt lines, so this branch merges it in with those lines resolved, and this PR goes right after it. The check could not compare #7645, which conflicts with `main`; its `libSceJxr/CMakeLists.txt` change applies cleanly on top of this branch. 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: #15479 <!-- #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!15689
No description provided.