feat(libScePsml): implement the MFSR query exports #8290

Merged
akkadbakkad89 merged 4 commits from upstream-pr/8290 into main 2026-10-21 12:02:17 +00:00
akkadbakkad89 commented 2026-10-20 09:03:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-20T09:03:58Z.


What

Real signatures and semantics for five libScePsml MFSR query exports, reversed from the APR-EMU fakelib/libScePsml.sprx bundled with the PPSA20397 dump, which imports three of them:

  • scePsmlMfsrGetDispatchMfsrPacketSizeInDwords(context, out) — validates the handle and writes 0x600 dwords, the size the dispatch packet builders write
  • scePsmlMfsrGetMipmapBias(context, bias, dimension) — writes log2f(dimension / context->inputWidth) - 1.0f; CreateContext800M3_2 now records the input width/height from the parameter's 16-bit pair at 0x18, falling back to descriptor0 + 0x20
  • scePsmlMfsrSelectConfig, scePsmlMfsrRequestCapture, scePsmlMfsrIsCaptureInProgress — validate the handle and return 0 (the fakelib's RequestCapture only sets a once-flag and logs; IsCaptureInProgress reports no capture)

Guard order from the fakelib: 0x8A810001 before init, 0x8A810005 for a null or foreign handle (the fakelib checks a leading engine id 0xA9C4/0x9231; the existing handle map plays the same role), 0x8A810009 for a null output pointer. The GetDispatchMfsrPacket* builders still throw — the 0x158-byte template's packet-construction routine is not yet understood; recorded in the debt file.

Tested

Extended guest_psml with before-init error checks, valid-context queries (packet size 0x600, mip bias 0/–1 for 2×/1× dimensions via both dimension paths), foreign-handle and null-output error codes; ctest -R guest_psml passes on Linux x86-64.

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:4933507521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-20T09:03:58Z. --- ### What Real signatures and semantics for five `libScePsml` MFSR query exports, reversed from the APR-EMU `fakelib/libScePsml.sprx` bundled with the PPSA20397 dump, which imports three of them: - `scePsmlMfsrGetDispatchMfsrPacketSizeInDwords(context, out)` — validates the handle and writes `0x600` dwords, the size the dispatch packet builders write - `scePsmlMfsrGetMipmapBias(context, bias, dimension)` — writes `log2f(dimension / context->inputWidth) - 1.0f`; `CreateContext800M3_2` now records the input width/height from the parameter's 16-bit pair at `0x18`, falling back to `descriptor0 + 0x20` - `scePsmlMfsrSelectConfig`, `scePsmlMfsrRequestCapture`, `scePsmlMfsrIsCaptureInProgress` — validate the handle and return 0 (the fakelib's `RequestCapture` only sets a once-flag and logs; `IsCaptureInProgress` reports no capture) Guard order from the fakelib: `0x8A810001` before init, `0x8A810005` for a null or foreign handle (the fakelib checks a leading engine id `0xA9C4`/`0x9231`; the existing handle map plays the same role), `0x8A810009` for a null output pointer. The `GetDispatchMfsrPacket*` builders still throw — the 0x158-byte template's packet-construction routine is not yet understood; recorded in the debt file. ### Tested Extended `guest_psml` with before-init error checks, valid-context queries (packet size `0x600`, mip bias `0`/`–1` for 2×/1× dimensions via both dimension paths), foreign-handle and null-output error codes; `ctest -R guest_psml` passes on Linux x86-64. ### Checklist - [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
github-actions[bot] commented 2026-10-20 09:04:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T09:04:49Z.


Progress report (a07e985 → 988f98f)

📈 System libraries: 60.53% (+0.07%, +5 implemented functions)

✅ 5 implemented
Library Name
libScePsml_debug scePsmlMfsrGetDispatchMfsrPacketSizeInDwords
libScePsml_debug scePsmlMfsrGetMipmapBias
libScePsml_debug scePsmlMfsrIsCaptureInProgress
libScePsml_debug scePsmlMfsrRequestCapture
libScePsml_debug scePsmlMfsrSelectConfig
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287440768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6287440768). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T09:04:49Z. --- <!-- progress-report --> ### Progress report (a07e985 → 988f98f) 📈 **System libraries**: 60.53% (+0.07%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libScePsml_debug | `scePsmlMfsrGetDispatchMfsrPacketSizeInDwords` | | libScePsml_debug | `scePsmlMfsrGetMipmapBias` | | libScePsml_debug | `scePsmlMfsrIsCaptureInProgress` | | libScePsml_debug | `scePsmlMfsrRequestCapture` | | libScePsml_debug | `scePsmlMfsrSelectConfig` | </details>
github-actions[bot] commented 2026-10-20 09:14:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T09:14:30Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestPsml.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287609889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6287609889). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T09:14:30Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestPsml.cpp` |
oneandonlydean commented 2026-10-20 11:32:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T11:32:12Z.


Thanks, the guard order and the new query results read well, and the test covers each path.

One change before merge: the new debt line in docs/dev/debt/libScePsml_debug.md names the dump the fakelib came from by its title ID. The repository docs shouldn't name specific titles or title IDs. Please describe the source without the ID (for example "semantics from the APR-EMU fakelib/libScePsml.sprx") and keep the rest of the line as it is.

Two small points, not blocking:

  • MfsrInputDimensions reads the width at descriptor0 + 0x20 when the parameter pair at 0x18 is zero, and the debt line says that indirection is inferred. If it's wrong, GetMipmapBias returns a bias from unrelated bytes. Returning 0x8A810005 for a zero width with no fallback would fail visibly instead. Keep the fallback if you have a caller that needs it, but please say which case it serves in the debt line.
  • FindMfsrObject returns the object pointer after dropping the lock, so a concurrent ReleaseContext on the same handle could free it while GetMipmapBias reads it. Copying the two dimensions out under the lock avoids that.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289885189 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6289885189). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T11:32:12Z. --- Thanks, the guard order and the new query results read well, and the test covers each path. One change before merge: the new debt line in `docs/dev/debt/libScePsml_debug.md` names the dump the fakelib came from by its title ID. The repository docs shouldn't name specific titles or title IDs. Please describe the source without the ID (for example "semantics from the APR-EMU `fakelib/libScePsml.sprx`") and keep the rest of the line as it is. Two small points, not blocking: - `MfsrInputDimensions` reads the width at `descriptor0 + 0x20` when the parameter pair at 0x18 is zero, and the debt line says that indirection is inferred. If it's wrong, `GetMipmapBias` returns a bias from unrelated bytes. Returning `0x8A810005` for a zero width with no fallback would fail visibly instead. Keep the fallback if you have a caller that needs it, but please say which case it serves in the debt line. - `FindMfsrObject` returns the object pointer after dropping the lock, so a concurrent `ReleaseContext` on the same handle could free it while `GetMipmapBias` reads it. Copying the two dimensions out under the lock avoids that.
akkadbakkad89 commented 2026-10-20 12:24:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-20T12:24:48Z.


All three addressed in 9fc0c88:

  • Debt line: title ID dropped — the entry now reads "semantics from the APR-EMU fakelib/libScePsml.sprx" with the rest unchanged (and trimmed to stay under the 1000-char lint).
  • FindMfsrObject race: it now copies the object fields out under g_mfsrMutex (FindMfsrObject(handle, &out)); every caller — including the validate-only ones that also dereferenced ->kind/->inputWidth after the lock — works on a snapshot, so a concurrent ReleaseContext can no longer free the object mid-read.
  • Fallback case: kept and now described in the debt line — it serves callers that pass a descriptor pointer at the parameter's 0x20 offset (the layout the earlier entries record), rather than inline dimensions at 0x18. On the error side, GetMipmapBias already returns 0x8A810005 when the recorded width is 0, so a wrong indirection fails there rather than producing a bias from unrelated bytes.

guest_psml passes; conventions clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290775585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6290775585). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-20T12:24:48Z. --- All three addressed in `9fc0c88`: - **Debt line**: title ID dropped — the entry now reads "semantics from the APR-EMU `fakelib/libScePsml.sprx`" with the rest unchanged (and trimmed to stay under the 1000-char lint). - **`FindMfsrObject` race**: it now copies the object fields out under `g_mfsrMutex` (`FindMfsrObject(handle, &out)`); every caller — including the validate-only ones that also dereferenced `->kind`/`->inputWidth` after the lock — works on a snapshot, so a concurrent `ReleaseContext` can no longer free the object mid-read. - **Fallback case**: kept and now described in the debt line — it serves callers that pass a descriptor pointer at the parameter's 0x20 offset (the layout the earlier entries record), rather than inline dimensions at 0x18. On the error side, `GetMipmapBias` already returns `0x8A810005` when the recorded width is 0, so a wrong indirection fails there rather than producing a bias from unrelated bytes. `guest_psml` passes; conventions clean.
nikowolf123 commented 2026-10-20 22:04:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:04:09Z.


Two entries in docs/dev/debt/libScePsml_debug.md that this PR doesn't touch now contradict the new code and the new entry on line 14. CONTRIBUTING.md says "A pull request that closes a gap removes its entry, or cuts it to what is still open".

Line 5 still says "The other context parameter fields (a 16-bit size pair at 0x18, two descriptor pointers at 0x20 and 0x28) are not read." scePsmlMfsrCreateContext800M3_2 now reads the pair at 0x18 through MfsrInputDimensions. When the width there is 0, it dereferences the pointer at 0x20 and reads the width and height at descriptor0 + 0x20 and + 0x22. The new guest_psml cases test both paths. Someone chasing a fault in CreateContext800M3_2 for a parameter with a zero pair would be told that this pointer is never read. Only the pointer at 0x28 is still unread, so I'd cut the sentence to "The descriptor pointer at 0x28 is not read." Editing that line will show the non-blocking debt-length warning, because the entry is already 1538 characters long.

Line 15 still ends with "so the dispatch, mip bias and capture calls still throw". scePsmlMfsrGetMipmapBias, scePsmlMfsrRequestCapture and scePsmlMfsrIsCaptureInProgress no longer call NotImplemented_nid_no_patch. For example, scePsmlMfsrGetMipmapBias(context, &bias, 1920) on a context created with width 1920 returns 0 and writes -1.0f, as the new test checks. Line 14 already records that the GetDispatchMfsrPacket* calls still throw, so line 15 can end at "which AnyPS5 reports as 0".

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302772915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6302772915). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T22:04:09Z. --- Two entries in `docs/dev/debt/libScePsml_debug.md` that this PR doesn't touch now contradict the new code and the new entry on line 14. [CONTRIBUTING.md](https://github.com/boykopovar/AnyPS5/blob/9fc0c88550c263f0bb1afe55d94317fcc6c60af4/CONTRIBUTING.md#L73) says "A pull request that closes a gap removes its entry, or cuts it to what is still open". [Line 5](https://github.com/boykopovar/AnyPS5/blob/9fc0c88550c263f0bb1afe55d94317fcc6c60af4/docs/dev/debt/libScePsml_debug.md#L5) still says "The other context parameter fields (a 16-bit size pair at 0x18, two descriptor pointers at 0x20 and 0x28) are not read." `scePsmlMfsrCreateContext800M3_2` now reads the pair at 0x18 through [`MfsrInputDimensions`](https://github.com/boykopovar/AnyPS5/blob/9fc0c88550c263f0bb1afe55d94317fcc6c60af4/core/libs/prx/libScePsml_debug/Export.cpp#L108). When the width there is 0, it dereferences the pointer at 0x20 and reads the width and height at `descriptor0 + 0x20` and `+ 0x22`. The new `guest_psml` cases test both paths. Someone chasing a fault in `CreateContext800M3_2` for a parameter with a zero pair would be told that this pointer is never read. Only the pointer at 0x28 is still unread, so I'd cut the sentence to "The descriptor pointer at 0x28 is not read." Editing that line will show the non-blocking `debt-length` warning, because the entry is already 1538 characters long. [Line 15](https://github.com/boykopovar/AnyPS5/blob/9fc0c88550c263f0bb1afe55d94317fcc6c60af4/docs/dev/debt/libScePsml_debug.md#L15) still ends with "so the dispatch, mip bias and capture calls still throw". [`scePsmlMfsrGetMipmapBias`, `scePsmlMfsrRequestCapture` and `scePsmlMfsrIsCaptureInProgress`](https://github.com/boykopovar/AnyPS5/blob/9fc0c88550c263f0bb1afe55d94317fcc6c60af4/core/libs/prx/libScePsml_debug/Export.cpp#L237) no longer call `NotImplemented_nid_no_patch`. For example, `scePsmlMfsrGetMipmapBias(context, &bias, 1920)` on a context created with width 1920 returns 0 and writes `-1.0f`, as the new test checks. Line 14 already records that the `GetDispatchMfsrPacket*` calls still throw, so line 15 can end at "which AnyPS5 reports as 0".
akkadbakkad89 commented 2026-10-21 05:22:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T05:22:40Z.


Both entries cut in 988f98f40c:

  • Line 5 now ends at "The descriptor pointer at 0x28 is not read." — the pair at 0x18 and the pointer at 0x20 are both consumed by MfsrInputDimensions, as you noted.
  • Line 15 now ends at "which AnyPS5 reports as 0" — the mip-bias and capture calls return 0 in the new code; the dispatch throw is covered by the line-14 entry.

The line-5 edit does trip the non-blocking debt-length warning as predicted; left it as the minimal correct cut rather than rewriting the whole entry.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308725918 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6308725918). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-21T05:22:40Z. --- Both entries cut in `988f98f40c`: - Line 5 now ends at "The descriptor pointer at 0x28 is not read." — the pair at 0x18 and the pointer at 0x20 are both consumed by `MfsrInputDimensions`, as you noted. - Line 15 now ends at "which AnyPS5 reports as 0" — the mip-bias and capture calls return 0 in the new code; the dispatch throw is covered by the line-14 entry. The line-5 edit does trip the non-blocking debt-length warning as predicted; left it as the minimal correct cut rather than rewriting the whole entry.
adriadam10 commented 2026-10-21 12:02:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T12:02:48Z.


Checked the five MFSR query exports against the diff, the guard order, the mip-bias values (3840/1920 → 0, 1920/1920 → -1) and the new guest_psml cases (each failed on main, where these threw); the lock-copy fix for FindMfsrObject and the debt edits requested by @oneandonlydean and @nikowolf123 are in; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315418131 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8290#issuecomment-6315418131). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T12:02:48Z. --- Checked the five MFSR query exports against the diff, the guard order, the mip-bias values (3840/1920 → 0, 1920/1920 → -1) and the new `guest_psml` cases (each failed on main, where these threw); the lock-copy fix for `FindMfsrObject` and the debt edits requested by @oneandonlydean and @nikowolf123 are in; merged.
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!8290
No description provided.