feat(libSceJxr): implement decoder post-processing helpers #16282

Merged
Noxy-HNR merged 12 commits from upstream-pr/16282 into main 2026-11-09 01:47:13 +00:00
Noxy-HNR commented 2026-11-06 03:47:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-06T03:47:56Z.


What

Four libSceJxr decoder post-processing helpers currently throw: slideOneMBRow, updatePostProcInfo, postProcMB and postProcBlock. They now call jxrlib's postprocess.c, built from 3rdparty/jxrlib, through a C bridge (src/NativePostProc.c). No jxrlib logic is copied into core/.

  • slideOneMBRow swaps each channel's previous and current macroblock-info rows, and marks the new rows bumpy at the top or bottom edge.
  • updatePostProcInfo records a macroblock's DC and its macroblock and block textures.
  • postProcMB smooths the 2-pixel macroblock boundaries between four neighbouring macroblocks and stores their block DCs.
  • postProcBlock deblocks the 16 blocks of the upper-left macroblock.

All four work on the caller's tagPostProcInfo* [16][2] row table, 88-byte LP64 tagPostProcInfo entries (the bridge asserts the layout) and PixelI macroblock rows. The C++ adapters in src/PostProc.cpp throw on a null table, a null macroblock or row the call dereferences, more than 16 channels, a channel past 15, and a column or row width whose byte offset overflows. Before calling jxrlib they open host writes on exactly the table, info entries and pixel ranges each call writes, so a read-only guest page throws instead of faulting. The row length is not an argument, so a column past the caller's row cannot be detected.

cmake/Jxr.cmake builds postprocess.c with -fwrapv. Its smoothing and DC comparisons overflow Int on extreme pixel or DC values, which is undefined behaviour in the host build. With -fwrapv they wrap instead, and in-range results don't change.

The row table comes from initPostProc and is released by termPostProc, which #16267 and #16269 added to main. 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.

This branch is built on #15689, which includes #15479, so the diff also shows their commits. This PR's own change is commit 3980822836; the merge commits after it bring in the updated #15689. It goes right after #15689.

Tested

New guest_jxr_postproc test. Each case builds a randomized row table and macroblock rows, clones it, runs the guest export on one copy and jxrlib directly on the other, and compares the rows, the pixels and the table pointers (by offset):

  • slideOneMBRow for 0, 1, 3 and 16 channels, widths 0 to 12, every top/bottom combination, three slides in a row.
  • updatePostProcInfo for every column and several channels, with dense, sparse and all-zero macroblocks (smooth and bumpy textures).
  • postProcMB and postProcBlock for every column 0 to 12, thresholds 0, 1, 4 and 100, and flat and mixed textures. Also extreme values (random 32-bit pixels and DCs, threshold INT32_MAX).
  • Every rejected argument listed above, checking that a rejected call changes nothing.
  • On Windows: guest pages made read-only with sceKernelMprotect (checked with VirtualQuery). Each call is rejected exactly when a page it writes is read-only, and succeeds once write access is restored.
  • Sabotage check: replacing each jxrlib call in the bridge, or changing the threshold passed to postProcMB/postProcBlock by one, makes the test fail.

Results:

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head 40ea2a1518 on upstream 6bf3a19b81 (after #16267 and #16269 merged): ctest -R guest_jxr 15/15 passed in each of 3 runs. Earlier, 1a408e876d on upstream c36ab99c74 also passed 15/15 in each of 3 runs. The first version, 3980822836 on upstream 04cdd52760, passed 13/13 in each of 3 runs.
  • Linux source probe (GCC 13, -fsanitize=signed-integer-overflow -fno-sanitize-recover=all) on postprocess.c with the test's case generator: in-range cases are clean with or without -fwrapv. Extreme cases stop with signed overflow at postprocess.c:187 without -fwrapv, and are clean with it.
  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: head 40ea2a1518, ctest -R guest_jxr 15/15 passed in each of 3 runs, including the read-only page checks. Earlier, 1a408e876d also passed 15/15 in each of 3 runs. The first version, 3980822836, passed 13/13 in each of 3 runs, including the read-only page checks, and the build log shows postprocess.c compiled with -fwrapv.
  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (406 libraries, 30,646 exports): passed.
  • python tools/pr_overlap.py --branch claude/jxr-postproc (1,894 open PRs): no shared exports. It could not compare 11 open libSceJxr PRs that conflict with main (#15148, #15232, #15626, #15645, #15646, #15684, #15771, #15772, #15774, and #14905 and #14916, which have since merged). Checked by hand, none of them adds these four functions. They overlap only on neighbouring lines of CMakeLists.txt, Export.cpp, include/Api.hpp and the debt file.

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: #15689
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5182576333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16282). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-06T03:47:56Z. --- ### What Four libSceJxr decoder post-processing helpers currently throw: `slideOneMBRow`, `updatePostProcInfo`, `postProcMB` and `postProcBlock`. They now call jxrlib's [postprocess.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/decode/postprocess.c#L100-L300), built from `3rdparty/jxrlib`, through a C bridge (`src/NativePostProc.c`). No jxrlib logic is copied into `core/`. - `slideOneMBRow` swaps each channel's previous and current macroblock-info rows, and marks the new rows bumpy at the top or bottom edge. - `updatePostProcInfo` records a macroblock's DC and its macroblock and block textures. - `postProcMB` smooths the 2-pixel macroblock boundaries between four neighbouring macroblocks and stores their block DCs. - `postProcBlock` deblocks the 16 blocks of the upper-left macroblock. All four work on the caller's `tagPostProcInfo* [16][2]` row table, 88-byte LP64 `tagPostProcInfo` entries (the bridge asserts the layout) and `PixelI` macroblock rows. The C++ adapters in `src/PostProc.cpp` throw on a null table, a null macroblock or row the call dereferences, more than 16 channels, a channel past 15, and a column or row width whose byte offset overflows. Before calling jxrlib they open host writes on exactly the table, info entries and pixel ranges each call writes, so a read-only guest page throws instead of faulting. The row length is not an argument, so a column past the caller's row cannot be detected. `cmake/Jxr.cmake` builds `postprocess.c` with `-fwrapv`. Its smoothing and DC comparisons overflow `Int` on extreme pixel or DC values, which is undefined behaviour in the host build. With `-fwrapv` they wrap instead, and in-range results don't change. The row table comes from `initPostProc` and is released by `termPostProc`, which #16267 and #16269 added to `main`. 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. This branch is built on #15689, which includes #15479, so the diff also shows their commits. This PR's own change is commit `3980822836`; the merge commits after it bring in the updated #15689. It goes right after #15689. ### 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_postproc` test. Each case builds a randomized row table and macroblock rows, clones it, runs the guest export on one copy and jxrlib directly on the other, and compares the rows, the pixels and the table pointers (by offset): - `slideOneMBRow` for 0, 1, 3 and 16 channels, widths 0 to 12, every top/bottom combination, three slides in a row. - `updatePostProcInfo` for every column and several channels, with dense, sparse and all-zero macroblocks (smooth and bumpy textures). - `postProcMB` and `postProcBlock` for every column 0 to 12, thresholds 0, 1, 4 and 100, and flat and mixed textures. Also extreme values (random 32-bit pixels and DCs, threshold `INT32_MAX`). - Every rejected argument listed above, checking that a rejected call changes nothing. - On Windows: guest pages made read-only with `sceKernelMprotect` (checked with `VirtualQuery`). Each call is rejected exactly when a page it writes is read-only, and succeeds once write access is restored. - Sabotage check: replacing each jxrlib call in the bridge, or changing the threshold passed to `postProcMB`/`postProcBlock` by one, makes the test fail. Results: - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head `40ea2a1518` on upstream `6bf3a19b81` (after #16267 and #16269 merged): `ctest -R guest_jxr` **15/15 passed in each of 3 runs**. Earlier, `1a408e876d` on upstream `c36ab99c74` also passed 15/15 in each of 3 runs. The first version, `3980822836` on upstream `04cdd52760`, passed 13/13 in each of 3 runs. - Linux source probe (GCC 13, `-fsanitize=signed-integer-overflow -fno-sanitize-recover=all`) on `postprocess.c` with the test's case generator: in-range cases are clean with or without `-fwrapv`. Extreme cases stop with signed overflow at `postprocess.c:187` without `-fwrapv`, and are clean with it. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release: head `40ea2a1518`, `ctest -R guest_jxr` **15/15 passed in each of 3 runs**, including the read-only page checks. Earlier, `1a408e876d` also passed 15/15 in each of 3 runs. The first version, `3980822836`, passed 13/13 in each of 3 runs, including the read-only page checks, and the build log shows `postprocess.c` compiled with `-fwrapv`. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (406 libraries, 30,646 exports): passed. - `python tools/pr_overlap.py --branch claude/jxr-postproc` (1,894 open PRs): no shared exports. It could not compare 11 open libSceJxr PRs that conflict with `main` (#15148, #15232, #15626, #15645, #15646, #15684, #15771, #15772, #15774, and #14905 and #14916, which have since merged). Checked by hand, none of them adds these four functions. They overlap only on neighbouring lines of `CMakeLists.txt`, `Export.cpp`, `include/Api.hpp` and the debt file. 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: #15689 <!-- #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!16282
No description provided.