feat(libSceNKWebKit): implement WebCore ViewportArguments resolution and scale helpers #15125

Merged
ashwin280802 merged 4 commits from upstream-pr/15125 into main 2026-11-07 10:55:17 +00:00
ashwin280802 commented 2026-11-02 17:40:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ashwin280802 on 2026-11-02T17:40:09Z.


What

Implements four libSceNKWebKit exports from WebCore's ViewportArguments.cpp, all pure float math:

  • computeViewportAttributes(ViewportArguments, int, int, int, float, IntSize)
  • restrictMinimumScaleFactorToViewportSize(ViewportAttributes&, IntSize, float)
  • computeMinimumScaleFactorForContentContained(const ViewportAttributes&, const IntSize&, const IntSize&)
  • restrictScaleFactorToInitialScaleIfNotUserScalable(ViewportAttributes&)

Source: ViewportArguments.cpp L47-L291 (helpers, ViewportArguments::resolve and the four functions) and ViewportArguments.h L44-L104 (struct layouts).

Divergences from the source: resolve is a file-local function rather than a member, and the ASSERTs are dropped. The struct layouts (ViewportArguments 56 bytes, ViewportAttributes 36 bytes, Type without the iOS-only values) come from that 11.x source and are pinned with static_assert; I did not check them against the console binary, so they are listed in the layouts entry of the library's debt file.

Overlap: I compared this branch with the 15 open PRs that can be merged against main. Each touches the export count line in the debt file, and #14172 also edits the layouts line I extend; none shares an export or a new file. I read the added lines of the three PRs that conflict with main (#13515, #14152, #14212) and found none of these names.

Tested

Windows 11, MinGW GCC 15.2.0, Release, at 88fa5584e0.

ctest --test-dir build-vp -R nkwebkit --output-on-failure; the new test is nkwebkit_webcoreviewport. Its cases cover the Implicit, ViewportMeta and CSSDeviceAdaptation paths, clamping, a device pixel ratio of 2, the pass-through fields and each helper.

 8/10 Test #2685: nkwebkit_webcoregeometry .........   Passed    0.01 sec
 9/10 Test #2686: nkwebkit_webcoreviewport .........   Passed    0.01 sec
10/10 Test #2687: nkwebkit_wtf .....................   Passed    0.01 sec
100% tests passed, 0 tests failed out of 10
All conventions checks passed.

The last line is python3 tools/check_conventions.py --base origin/main.

I changed 138 conditions and statements one at a time (136 compiled) and the test failed on 126. The 10 survivors cannot be observed with finite inputs: six are static_assert deletions, and the other four leave the result unchanged because a later line recomputes the same value or the changed term is multiplied by 1 or ignored by a max.

Not verified: the full Windows suite at this revision; the Linux suite, which I could not run because the container cannot configure CMake from a git worktree on my machine; the struct layouts against the console binary.

Not covered by a test: the by-value 56-byte ViewportArguments and sret ViewportAttributes calling convention from guest code. The test calls the exports with the same declarations, so it checks caller and callee agreement and the static_asserts check the layout, not a console caller.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5124714186 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15125). Originally posted by [ashwin280802](https://github.com/ashwin280802) on 2026-11-02T17:40:09Z. --- ### What Implements four `libSceNKWebKit` exports from WebCore's `ViewportArguments.cpp`, all pure float math: - `computeViewportAttributes(ViewportArguments, int, int, int, float, IntSize)` - `restrictMinimumScaleFactorToViewportSize(ViewportAttributes&, IntSize, float)` - `computeMinimumScaleFactorForContentContained(const ViewportAttributes&, const IntSize&, const IntSize&)` - `restrictScaleFactorToInitialScaleIfNotUserScalable(ViewportAttributes&)` Source: [`ViewportArguments.cpp` L47-L291](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/dom/ViewportArguments.cpp#L47-L291) (helpers, `ViewportArguments::resolve` and the four functions) and [`ViewportArguments.h` L44-L104](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/dom/ViewportArguments.h#L44-L104) (struct layouts). Divergences from the source: `resolve` is a file-local function rather than a member, and the `ASSERT`s are dropped. The struct layouts (`ViewportArguments` 56 bytes, `ViewportAttributes` 36 bytes, `Type` without the iOS-only values) come from that 11.x source and are pinned with `static_assert`; I did not check them against the console binary, so they are listed in the layouts entry of the library's debt file. Overlap: I compared this branch with the 15 open PRs that can be merged against `main`. Each touches the export count line in the debt file, and #14172 also edits the layouts line I extend; none shares an export or a new file. I read the added lines of the three PRs that conflict with `main` (#13515, #14152, #14212) and found none of these names. ### Tested Windows 11, MinGW GCC 15.2.0, Release, at 88fa5584e0. `ctest --test-dir build-vp -R nkwebkit --output-on-failure`; the new test is `nkwebkit_webcoreviewport`. Its cases cover the Implicit, ViewportMeta and CSSDeviceAdaptation paths, clamping, a device pixel ratio of 2, the pass-through fields and each helper. ``` 8/10 Test #2685: nkwebkit_webcoregeometry ......... Passed 0.01 sec 9/10 Test #2686: nkwebkit_webcoreviewport ......... Passed 0.01 sec 10/10 Test #2687: nkwebkit_wtf ..................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 10 All conventions checks passed. ``` The last line is `python3 tools/check_conventions.py --base origin/main`. I changed 138 conditions and statements one at a time (136 compiled) and the test failed on 126. The 10 survivors cannot be observed with finite inputs: six are `static_assert` deletions, and the other four leave the result unchanged because a later line recomputes the same value or the changed term is multiplied by 1 or ignored by a `max`. Not verified: the full Windows suite at this revision; the Linux suite, which I could not run because the container cannot configure CMake from a git worktree on my machine; the struct layouts against the console binary. Not covered by a test: the by-value 56-byte `ViewportArguments` and sret `ViewportAttributes` calling convention from guest code. The test calls the exports with the same declarations, so it checks caller and callee agreement and the `static_assert`s check the layout, not a console caller. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 19:32:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T19:32:39Z.

Review: APPROVED


Looks right, and the layouts and calling convention match the console module, which the description lists as unchecked. Firmware 13.42's system_ex/common_ex/lib/libSceNKWebKit.sprx (sha256 e63acdc164592330a287cf6914c265336b27a357098a449c1609f8f82e104409), disassembly only:

computeViewportAttributes (NugBItcC7YY, 0x1d5f20):

1d5f20: vcvtsi2ss %r8d ... ; shr $0x20,%r8     visibleViewport packed in r8
1d5f31: mov %rdi,%rax                          sret pointer
1d5f34: lea 0x8(%rsp),%rdi                     ViewportArguments by value on the stack
1d5f56/1d5f5a: vcvtsi2ss %edx / %ecx           deviceWidth, deviceHeight; xmm0 = devicePixelRatio
1d661e: vmovsd 0x28(%rdi),%xmm0                userZoom + orientation
1d6623: vmovss 0x30(%rdi),%xmm1                shrinkToFit
1d6628: movzbl 0x34(%rdi),%ecx                 viewportFit (one byte)
1d662c: vmovlps %xmm2,(%rax)                   layoutSize
1d6630: vmovsd %xmm0,0x14(%rax)                userScalable + orientation
1d6635: vmovss %xmm1,0x1c(%rax)                shrinkToFit
1d663a: mov %cl,0x20(%rax)                     viewportFit

Its reads of the arguments are exactly the fields at 0x0 through 0x34 in this PR's ViewportArguments (widthWasExplicit at 0x35 is never read, and this PR doesn't read it either). The result writes land on ViewportAttributes offsets 0x0 through 0x20, including initialScale, minimumScale and maximumScale at 0x8, 0xc and 0x10.

The three helpers use the same offsets:

  • restrictScaleFactorToInitialScaleIfNotUserScalable (0x1319c0): when userScalable (0x14) compares equal to 0.0, it copies initialScale (0x8) into 0xc and 0x10.
  • computeMinimumScaleFactorForContentContained (0x1ccf50): max(max(visible/contents), minimumScale at 0xc).
  • restrictMinimumScaleFactorToViewportSize (0xcb6e0): scales by 1/dpr when dpr != 1.0f, using a multiply (cb700/cb704) exactly as ConvertToUserSpace does, then stores the new minimum at 0xc.

Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto current main: nkwebkit_webcoreviewport, nkwebkit_webcoregeometry, nkwebkit_base and public_headers pass. With main's Export.cpp, InventoryExports.hpp and WebCoreExports.hpp, the new test doesn't build against the old declarations.

Non-blocking: the layouts entry in the debt file could now say the 56- and 36-byte layouts and the by-value/sret convention match the 13.42 module. I compared the field offsets and register use, not every branch of the arithmetic.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742208999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15125#pullrequestreview-5742208999). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T19:32:39Z. **Review:** APPROVED --- Looks right, and the layouts and calling convention match the console module, which the description lists as unchecked. Firmware 13.42's `system_ex/common_ex/lib/libSceNKWebKit.sprx` (sha256 `e63acdc164592330a287cf6914c265336b27a357098a449c1609f8f82e104409`), disassembly only: **`computeViewportAttributes`** (`NugBItcC7YY`, `0x1d5f20`): ``` 1d5f20: vcvtsi2ss %r8d ... ; shr $0x20,%r8 visibleViewport packed in r8 1d5f31: mov %rdi,%rax sret pointer 1d5f34: lea 0x8(%rsp),%rdi ViewportArguments by value on the stack 1d5f56/1d5f5a: vcvtsi2ss %edx / %ecx deviceWidth, deviceHeight; xmm0 = devicePixelRatio 1d661e: vmovsd 0x28(%rdi),%xmm0 userZoom + orientation 1d6623: vmovss 0x30(%rdi),%xmm1 shrinkToFit 1d6628: movzbl 0x34(%rdi),%ecx viewportFit (one byte) 1d662c: vmovlps %xmm2,(%rax) layoutSize 1d6630: vmovsd %xmm0,0x14(%rax) userScalable + orientation 1d6635: vmovss %xmm1,0x1c(%rax) shrinkToFit 1d663a: mov %cl,0x20(%rax) viewportFit ``` Its reads of the arguments are exactly the fields at 0x0 through 0x34 in this PR's `ViewportArguments` (`widthWasExplicit` at 0x35 is never read, and this PR doesn't read it either). The result writes land on `ViewportAttributes` offsets 0x0 through 0x20, including `initialScale`, `minimumScale` and `maximumScale` at 0x8, 0xc and 0x10. **The three helpers** use the same offsets: - `restrictScaleFactorToInitialScaleIfNotUserScalable` (`0x1319c0`): when `userScalable` (`0x14`) compares equal to 0.0, it copies `initialScale` (`0x8`) into `0xc` and `0x10`. - `computeMinimumScaleFactorForContentContained` (`0x1ccf50`): `max(max(visible/contents), minimumScale at 0xc)`. - `restrictMinimumScaleFactorToViewportSize` (`0xcb6e0`): scales by `1/dpr` when dpr != 1.0f, using a multiply (`cb700`/`cb704`) exactly as `ConvertToUserSpace` does, then stores the new minimum at `0xc`. Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto current `main`: `nkwebkit_webcoreviewport`, `nkwebkit_webcoregeometry`, `nkwebkit_base` and `public_headers` pass. With `main`'s `Export.cpp`, `InventoryExports.hpp` and `WebCoreExports.hpp`, the new test doesn't build against the old declarations. Non-blocking: the layouts entry in the debt file could now say the 56- and 36-byte layouts and the by-value/sret convention match the 13.42 module. I compared the field offsets and register use, not every branch of the arithmetic.
BunnyFl commented 2026-11-04 18:48:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T18:48:51Z.

Review: APPROVED


@ashwin280802 approved again at a14116375b.

The rebase: git range-diff against my approved 88fa5584e0 changes none of this PR's own +/- lines. The only difference is the debt file's hunk context, where main moved the lines around the entry.

What I ran: head a14116375b, which already contains main 9ab6a281ea. Windows 11, WinLibs GCC 15.2.0, Release:

  • nkwebkit_webcoreviewport and public_headers pass (2 of 2).
  • Mutation: with the default minimum scale in WebCoreViewport.cpp set to 0.5f instead of 0.25f, nkwebkit_webcoreviewport aborts (WebCore viewport check failed at line 34). So the tests cover the defaults.
  • tools/check_conventions.py --base upstream/main --head on the head: all checks passed.
  • pr_overlap.py --branch on the head:
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5773900988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15125#pullrequestreview-5773900988). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T18:48:51Z. **Review:** APPROVED --- @ashwin280802 approved again at `a14116375b`. **The rebase:** `git range-diff` against my approved `88fa5584e0` changes none of this PR's own `+`/`-` lines. The only difference is the debt file's hunk context, where `main` moved the lines around the entry. **What I ran:** head `a14116375b`, which already contains `main` `9ab6a281ea`. Windows 11, WinLibs GCC 15.2.0, Release: - `nkwebkit_webcoreviewport` and `public_headers` pass (2 of 2). - **Mutation:** with the default minimum scale in `WebCoreViewport.cpp` set to `0.5f` instead of `0.25f`, `nkwebkit_webcoreviewport` aborts (`WebCore viewport check failed at line 34`). So the tests cover the defaults. - `tools/check_conventions.py --base upstream/main --head` on the head: all checks passed. - `pr_overlap.py --branch` on the head: - About 20 NKWebKit PRs change the export count on lines 8 and 36 of `docs/dev/debt/libSceNKWebKit.md`, #14858 among them. Whichever lands later will need a rebase there. - It also lists #13486 under the four `WebCore` exports. That PR only carries the old argument-less inventory stubs that this PR removes, for example [`int APS5_VABI _ZN7WebCore25computeViewportAttributesENS_17ViewportArgumentsEiiifNS_7IntSizeE()`](https://github.com/boykopovar/AnyPS5/blob/0bde10d243b63a08556f9ceda6912cf5fef2b824/core/libs/prx/libSceNKWebKit/Export.cpp#L21579) in its `Export.cpp`. So it doesn't implement them.
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!15125
No description provided.