feat(libfreetype): implement LCD geometry and variation axis flags #16394

Merged
Noxy-HNR merged 3 commits from upstream-pr/16394 into main 2026-11-11 11:26:07 +00:00
Noxy-HNR commented 2026-11-06 16:00:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Noxy-HNR on 2026-11-06T16:00:42Z.


What

Two libfreetype exports currently throw: FT_Library_SetLcdGeometry (Xxtq+Qr5lzI) and FT_Get_Var_Axis_Flags (+sDVkl3aAR8). They now call the bundled FreeType (3rdparty/freetype) through thin adapters in src/LibraryHelpers.cpp, and the module gets its own CMakeLists.txt to link it. The names come from the NID database already cited in the debt file. No FreeType logic is copied into core/.

  • FT_Library_SetLcdGeometry takes the guest library handle from libSceFreeType and its three LP64 FT_Vector subpixel offsets, converts them to host FT_Vector, and sets them on the library's native handle. Later FT_RENDER_MODE_LCD and FT_RENDER_MODE_LCD_V renders through libSceFreeType use them. A null library or null array returns FreeType's own errors. On Windows, a coordinate that does not fit the 32-bit host FT_Pos throws through NotImplemented_nid_no_patch.
  • FT_Get_Var_Axis_Flags passes the guest FT_MM_Var record straight to FreeType. Its 32-byte layout is the same on the guest and on both hosts, and a static_assert checks it. FreeType reads the 16-bit flag array that follows the record. Before writing the flags output, the adapter opens a host write. A refused write returns FT_Err_Invalid_Argument and leaves it unchanged.

The bundled FreeType is built without FT_CONFIG_OPTION_SUBPIXEL_RENDERING, so FT_Library_SetLcdGeometry stores the geometry as FreeType's Harmony LCD renderer expects. A console build with that option would return FT_Err_Unimplemented_Feature instead. The console signatures and options are not measured, and the debt file records this. No title unblock is claimed.

Tested

Current verification (2026-11-07), head c5dfe3d648, merging main 1b7fd528e9: Windows 11 x86-64, WinLibs MinGW GCC 15.2, Ninja, Release, full project configuration with BUILD_TESTING=ON, -j 18. Built guest_legacy_freetype_library_fixture and ran the focused raw and NID-patched tests matching guest_legacy_freetype_library(_nid)?: 2/2 passed in each of three runs, none skipped. Test-private patched modules and executable keep validation independent of the global all-library target. Current conventions, whitespace and public-header checks passed. The fixture uses configuration-specific output directories and publishes patched files only after successful patching. No new Linux, macOS, console or title runtime result is claimed.

Manual full-build dispatch for this head returned HTTP 403 (repository admin rights required). Automatic checks are tracked separately; a skipped job is not a pass.

Historical verification follows; results below retain their original heads and do not establish validation of the current head.

New guest_legacy_freetype_library and guest_legacy_freetype_library_nid tests load the raw and NID-patched libfreetype and libSceFreeType modules and compare them with the bundled FreeType called directly:

  • FT_Library_SetLcdGeometry: six geometries (FreeType's default, wider and vertical offsets, mixed signs, all zero, and large offsets) at 13 and 32 pixels in LCD and LCD_V modes. The guest render after each call matches FreeType's render with the same geometry, byte for byte, including size, pitch and bearings. The non-default geometries change the render. A second guest library keeps its own geometry. The input array is not modified. Null library and null array errors match FreeType.
  • FT_Get_Var_Axis_Flags: records with 0, 1, 4 and 8 axes, indexes inside and outside the range up to UINT32_MAX. Each result and error matches FreeType, a failed call leaves the output unchanged, and the record is never modified. Null record and null output errors match FreeType.
  • On Windows: the record, the flags output and the geometry array are placed in guest pages made read-only with sceKernelMprotect (checked with VirtualQuery). A read-only flags output is refused without changing either page, a read-only record and geometry array still work, and the query succeeds once write access is restored.
  • Sabotage check: swapping each vector's x and y, ignoring the geometry, writing the flags output on an error, and reading the previous axis each make both tests fail.

Results:

  • Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head 52d463737f on upstream ea3ae18716: ctest -R guest_legacy_freetype_library 2/2 passed in each of 3 runs.
  • Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release, 52d463737f merged with upstream 82fcf46d25: ctest -R guest_legacy_freetype_library 2/2 passed in each of 3 runs, including the read-only page checks, and ctest -R guest_freetype 61/61 passed.
  • python tools/check_conventions.py --base origin/main and python core/libs/tests/test_public_headers.py --audit-only (406 libraries, 30,649 exports): passed.
  • python tools/pr_overlap.py --branch claude/freetype-library-helpers (1,886 open PRs): no shared exports. core/libs/prx/libfreetype/CMakeLists.txt is also added by #15408 and by #15439, #15442, #15444, #15447 and #15468, which implement other libfreetype exports, so whichever lands later merges main and keeps every source and test. #15468 also rewrites the debt line that lists FT_Get_Var_Axis_Flags among the callable NIDs; the later of the two updates it. No open PR adds or removes these two functions or their NIDs.

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:5190705060 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16394). Originally posted by [Noxy-HNR](https://github.com/Noxy-HNR) on 2026-11-06T16:00:42Z. --- ### What Two libfreetype exports currently throw: `FT_Library_SetLcdGeometry` (`Xxtq+Qr5lzI`) and `FT_Get_Var_Axis_Flags` (`+sDVkl3aAR8`). They now call the bundled FreeType (`3rdparty/freetype`) through thin adapters in `src/LibraryHelpers.cpp`, and the module gets its own `CMakeLists.txt` to link it. The names come from the NID database already cited in the debt file. No FreeType logic is copied into `core/`. - `FT_Library_SetLcdGeometry` takes the guest library handle from `libSceFreeType` and its three LP64 `FT_Vector` subpixel offsets, converts them to host `FT_Vector`, and sets them on the library's native handle. Later `FT_RENDER_MODE_LCD` and `FT_RENDER_MODE_LCD_V` renders through `libSceFreeType` use them. A null library or null array returns FreeType's own errors. On Windows, a coordinate that does not fit the 32-bit host `FT_Pos` throws through `NotImplemented_nid_no_patch`. - `FT_Get_Var_Axis_Flags` passes the guest `FT_MM_Var` record straight to FreeType. Its 32-byte layout is the same on the guest and on both hosts, and a `static_assert` checks it. FreeType reads the 16-bit flag array that follows the record. Before writing the flags output, the adapter opens a host write. A refused write returns `FT_Err_Invalid_Argument` and leaves it unchanged. The bundled FreeType is built without `FT_CONFIG_OPTION_SUBPIXEL_RENDERING`, so `FT_Library_SetLcdGeometry` stores the geometry as FreeType's Harmony LCD renderer expects. A console build with that option would return `FT_Err_Unimplemented_Feature` instead. The console signatures and options are not measured, and the debt file records this. No title unblock is claimed. ### 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. --> Current verification (2026-11-07), head `c5dfe3d648`, merging main `1b7fd528e9`: Windows 11 x86-64, WinLibs MinGW GCC 15.2, Ninja, Release, full project configuration with `BUILD_TESTING=ON`, `-j 18`. Built `guest_legacy_freetype_library_fixture` and ran the focused raw and NID-patched tests matching `guest_legacy_freetype_library(_nid)?`: **2/2 passed in each of three runs**, none skipped. Test-private patched modules and executable keep validation independent of the global all-library target. Current conventions, whitespace and public-header checks passed. The fixture uses configuration-specific output directories and publishes patched files only after successful patching. No new Linux, macOS, console or title runtime result is claimed. Manual full-build dispatch for this head returned HTTP 403 (repository admin rights required). Automatic checks are tracked separately; a skipped job is not a pass. Historical verification follows; results below retain their original heads and do not establish validation of the current head. New `guest_legacy_freetype_library` and `guest_legacy_freetype_library_nid` tests load the raw and NID-patched `libfreetype` and `libSceFreeType` modules and compare them with the bundled FreeType called directly: - `FT_Library_SetLcdGeometry`: six geometries (FreeType's default, wider and vertical offsets, mixed signs, all zero, and large offsets) at 13 and 32 pixels in LCD and LCD_V modes. The guest render after each call matches FreeType's render with the same geometry, byte for byte, including size, pitch and bearings. The non-default geometries change the render. A second guest library keeps its own geometry. The input array is not modified. Null library and null array errors match FreeType. - `FT_Get_Var_Axis_Flags`: records with 0, 1, 4 and 8 axes, indexes inside and outside the range up to `UINT32_MAX`. Each result and error matches FreeType, a failed call leaves the output unchanged, and the record is never modified. Null record and null output errors match FreeType. - On Windows: the record, the flags output and the geometry array are placed in guest pages made read-only with `sceKernelMprotect` (checked with `VirtualQuery`). A read-only flags output is refused without changing either page, a read-only record and geometry array still work, and the query succeeds once write access is restored. - Sabotage check: swapping each vector's x and y, ignoring the geometry, writing the flags output on an error, and reading the previous axis each make both tests fail. Results: - Linux x86-64 (Ubuntu 24.04, GCC 13), Release, head `52d463737f` on upstream `ea3ae18716`: `ctest -R guest_legacy_freetype_library` **2/2 passed in each of 3 runs**. - Windows 11 x86-64, WinLibs MinGW GCC 15.2.0, Release, `52d463737f` merged with upstream `82fcf46d25`: `ctest -R guest_legacy_freetype_library` **2/2 passed in each of 3 runs**, including the read-only page checks, and `ctest -R guest_freetype` 61/61 passed. - `python tools/check_conventions.py --base origin/main` and `python core/libs/tests/test_public_headers.py --audit-only` (406 libraries, 30,649 exports): passed. - `python tools/pr_overlap.py --branch claude/freetype-library-helpers` (1,886 open PRs): no shared exports. `core/libs/prx/libfreetype/CMakeLists.txt` is also added by #15408 and by #15439, #15442, #15444, #15447 and #15468, which implement other libfreetype exports, so whichever lands later merges `main` and keeps every source and test. #15468 also rewrites the debt line that lists `FT_Get_Var_Axis_Flags` among the callable NIDs; the later of the two updates it. No open PR adds or removes these two functions or their NIDs. 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!16394
No description provided.