feat(libSceHmd): answer ten buffer and device queries the way the disconnected-headset path implies #8256

Merged
YossiYad merged 5 commits from upstream-pr/8256 into main 2026-10-21 12:03:19 +00:00
YossiYad commented 2026-10-20 07:13:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-20T07:13:48Z.


What

libSceHmd implements the disconnected-headset path (sceHmdOpen reports DEVICE_DISCONNECTED, so no handle is ever open). Ten more of its exports were throwing stubs without parameters; they now answer as that path implies:

  • sceHmdDistortionGetWorkMemorySize / Align return 0x20000 / 0x400; sceHmdReprojectionQueryGarlicBuffSize / Align return 0x100000 / 0x100; sceHmdReprojectionQueryOnionBuffSize / Align return 0x810 / 0x100.
  • sceHmdGetFieldOfView(handle, out), sceHmdGet2DEyeOffset(handle, left, right) and sceHmdGetInertialSensorData(handle, data, count) return HANDLE_INVALID (0x81110003) after initialization and NOT_INITIALIZED before it, as sceHmdGetDeviceInformationByHandle already does; sceHmdGetFieldOfView returns PARAMETER_NULL for a null output first. No output is written.
  • sceHmdGetAssyError(data) returns PARAMETER_NULL for a null output, then DEVICE_DISCONNECTED (0x81110004) after initialization and NOT_INITIALIZED before it.

The constants, signatures and check order follow shadPS4 (PS4, no headset); none is measured on a PS5. Where shadPS4 checks the handle before initialization, these keep the library's existing order (initialization first). The ten "unknown signature" debt entries are replaced by one that says this.

sceHmdDistortionInitialize is left as it is: sceHmdInitialize deliberately refuses a distortion parameter here.

Tested

Linux (Fedora 44, GCC, Ninja, -DBUILD_TESTING=ON), rebased on main 3fd1cc393b:

  • guest_hmd passes with three new checks: the six sizes; the three handle queries for handles 0, -1, 1 and 0x0f000000 before and after initialization, with null outputs, and that no output byte changes; and sceHmdGetAssyError before and after initialization. The handle and assembly-error checks fail when the result ignores initialization.
  • Full ctest: 1670 of 1675 pass. The 5 failures (application_heap_scripting, application_heap_lazy, agc_driver_bda_device, agc_driver_guest_memory_lifetime, agc_driver_tessellation) fail the same way on main on this machine.
  • tools/progress.py --compare: libraries +0.16%, 10 functions implemented, none lost.
  • tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py finds no overlap; it could not compare GuestHmd.cpp with #6044, which conflicts with main and moves test registrations.

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:4932326749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-20T07:13:48Z. --- ### What libSceHmd implements the disconnected-headset path (`sceHmdOpen` reports `DEVICE_DISCONNECTED`, so no handle is ever open). Ten more of its exports were throwing stubs without parameters; they now answer as that path implies: - `sceHmdDistortionGetWorkMemorySize` / `Align` return `0x20000` / `0x400`; `sceHmdReprojectionQueryGarlicBuffSize` / `Align` return `0x100000` / `0x100`; `sceHmdReprojectionQueryOnionBuffSize` / `Align` return `0x810` / `0x100`. - `sceHmdGetFieldOfView(handle, out)`, `sceHmdGet2DEyeOffset(handle, left, right)` and `sceHmdGetInertialSensorData(handle, data, count)` return `HANDLE_INVALID` (`0x81110003`) after initialization and `NOT_INITIALIZED` before it, as `sceHmdGetDeviceInformationByHandle` already does; `sceHmdGetFieldOfView` returns `PARAMETER_NULL` for a null output first. No output is written. - `sceHmdGetAssyError(data)` returns `PARAMETER_NULL` for a null output, then `DEVICE_DISCONNECTED` (`0x81110004`) after initialization and `NOT_INITIALIZED` before it. The constants, signatures and check order follow [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/a808e76/src/core/libraries/hmd/hmd.cpp) (PS4, no headset); none is measured on a PS5. Where shadPS4 checks the handle before initialization, these keep the library's existing order (initialization first). The ten "unknown signature" debt entries are replaced by one that says this. `sceHmdDistortionInitialize` is left as it is: `sceHmdInitialize` deliberately refuses a distortion parameter here. ### Tested Linux (Fedora 44, GCC, Ninja, `-DBUILD_TESTING=ON`), rebased on `main` `3fd1cc393b`: - `guest_hmd` passes with three new checks: the six sizes; the three handle queries for handles `0`, `-1`, `1` and `0x0f000000` before and after initialization, with null outputs, and that no output byte changes; and `sceHmdGetAssyError` before and after initialization. The handle and assembly-error checks fail when the result ignores initialization. - Full `ctest`: 1670 of 1675 pass. The 5 failures (`application_heap_scripting`, `application_heap_lazy`, `agc_driver_bda_device`, `agc_driver_guest_memory_lifetime`, `agc_driver_tessellation`) fail the same way on `main` on this machine. - `tools/progress.py --compare`: libraries +0.16%, 10 functions implemented, none lost. - `tools/check_conventions.py --base upstream/main` passes. `tools/pr_overlap.py` finds no overlap; it could not compare `GuestHmd.cpp` with #6044, which conflicts with `main` and moves test registrations. ### 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
github-actions[bot] commented 2026-10-20 07:14:29 +00:00 (Migrated from github.com)

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


Progress report (3bd7173 → fd178d9)

📈 System libraries: 54.07% (+0.12%, +10 implemented functions)

✅ 10 implemented
Library Name
libSceHmd sceHmdDistortionGetWorkMemoryAlign
libSceHmd sceHmdDistortionGetWorkMemorySize
libSceHmd sceHmdGet2DEyeOffset
libSceHmd sceHmdGetAssyError
libSceHmd sceHmdGetFieldOfView
libSceHmd sceHmdGetInertialSensorData
libSceHmd sceHmdReprojectionQueryGarlicBuffAlign
libSceHmd sceHmdReprojectionQueryGarlicBuffSize
libSceHmd sceHmdReprojectionQueryOnionBuffAlign
libSceHmd sceHmdReprojectionQueryOnionBuffSize
⚪ 6 behaviourally empty (constant return or throw)
Library Name
libSceHmd sceHmdDistortionGetWorkMemoryAlign
libSceHmd sceHmdDistortionGetWorkMemorySize
libSceHmd sceHmdReprojectionQueryGarlicBuffAlign
libSceHmd sceHmdReprojectionQueryGarlicBuffSize
libSceHmd sceHmdReprojectionQueryOnionBuffAlign
libSceHmd sceHmdReprojectionQueryOnionBuffSize
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285524316 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256#issuecomment-6285524316). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T07:14:29Z. --- <!-- progress-report --> ### Progress report (3bd7173 → fd178d9) 📈 **System libraries**: 54.07% (+0.12%, +10 implemented functions) <details> <summary>✅ 10 implemented</summary> | Library | Name | | - | - | | libSceHmd | `sceHmdDistortionGetWorkMemoryAlign` | | libSceHmd | `sceHmdDistortionGetWorkMemorySize` | | libSceHmd | `sceHmdGet2DEyeOffset` | | libSceHmd | `sceHmdGetAssyError` | | libSceHmd | `sceHmdGetFieldOfView` | | libSceHmd | `sceHmdGetInertialSensorData` | | libSceHmd | `sceHmdReprojectionQueryGarlicBuffAlign` | | libSceHmd | `sceHmdReprojectionQueryGarlicBuffSize` | | libSceHmd | `sceHmdReprojectionQueryOnionBuffAlign` | | libSceHmd | `sceHmdReprojectionQueryOnionBuffSize` | </details> <details> <summary>⚪ 6 behaviourally empty (constant return or throw)</summary> | Library | Name | | - | - | | libSceHmd | `sceHmdDistortionGetWorkMemoryAlign` | | libSceHmd | `sceHmdDistortionGetWorkMemorySize` | | libSceHmd | `sceHmdReprojectionQueryGarlicBuffAlign` | | libSceHmd | `sceHmdReprojectionQueryGarlicBuffSize` | | libSceHmd | `sceHmdReprojectionQueryOnionBuffAlign` | | libSceHmd | `sceHmdReprojectionQueryOnionBuffSize` | </details>
github-actions[bot] commented 2026-10-20 07:20:53 +00:00 (Migrated from github.com)

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


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/GuestHmd.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285622741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256#issuecomment-6285622741). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T07:20:53Z. --- <!-- 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/GuestHmd.cpp` |
nikowolf123 commented 2026-10-20 20:40:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T20:40:56Z.


docs/dev/debt/libSceHmd.md#L9 says the results of sceHmdGetFieldOfView follow shadPS4, but before initialization they don't.

With a non-null output, Export.cpp#L381-L384 returns NOT_INITIALIZED (0x81110002) for every handle. GuestHmd.cpp#L45 asserts this through CheckHandleQueries(Hmd::NotInitialized) on line 80.

The cited shadPS4 hmd.cpp#L149-L175 checks in this order: null output, then handle != g_internal_handle (0 until a successful open), then the SDK >= 4.50 branch, and initialization last. So in shadPS4, sceHmdGetFieldOfView(1, buf) before sceHmdInitialize returns HANDLE_INVALID (0x81110003) for any SDK version. This PR follows the 4.50 branch for the eye offset and sensor queries, and on that branch handle 0 returns HANDLE_INVALID too.

The other three queries match shadPS4 before initialization. shadPS4 checks initialization first in sceHmdGet2DEyeOffset (L73) and sceHmdGetInertialSensorData (L179), and sceHmdGetAssyError has no handle.

The PR description gives the reason (to keep the library's initialization-first order), but the description does not stay in the repository. CONTRIBUTING.md asks a debt entry to state what differs. The libSceHttp and libSceAudio3d entries record their differences from shadPS4 this way; both notes were added during review of #3497 and #1849. I'd suggest one clause in the entry:

Before initialization `sceHmdGetFieldOfView` returns `NOT_INITIALIZED` for a non-null output, where shadPS4 checks the handle first and returns `HANDLE_INVALID`.

Alternatively, follow shadPS4's order with return fieldOfView ? Hmd::InvalidHandle : Hmd::ParameterNull;, and give field of view its own pre-initialization expectation in the test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301004018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256#issuecomment-6301004018). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T20:40:56Z. --- [docs/dev/debt/libSceHmd.md#L9](https://github.com/boykopovar/AnyPS5/blob/6cedb6a5fda4a2b7ad79e15044c177182cda0841/docs/dev/debt/libSceHmd.md#L9) says the results of `sceHmdGetFieldOfView` follow shadPS4, but before initialization they don't. With a non-null output, [Export.cpp#L381-L384](https://github.com/boykopovar/AnyPS5/blob/6cedb6a5fda4a2b7ad79e15044c177182cda0841/core/libs/prx/libSceHmd/Export.cpp#L381-L384) returns `NOT_INITIALIZED` (`0x81110002`) for every handle. [GuestHmd.cpp#L45](https://github.com/boykopovar/AnyPS5/blob/6cedb6a5fda4a2b7ad79e15044c177182cda0841/core/libs/tests/GuestHmd.cpp#L45) asserts this through `CheckHandleQueries(Hmd::NotInitialized)` on [line 80](https://github.com/boykopovar/AnyPS5/blob/6cedb6a5fda4a2b7ad79e15044c177182cda0841/core/libs/tests/GuestHmd.cpp#L80). The cited [shadPS4 hmd.cpp#L149-L175](https://github.com/shadps4-emu/shadPS4/blob/a808e7626e3c7de8d0f0fda6a91f620b42f6c762/src/core/libraries/hmd/hmd.cpp#L149-L175) checks in this order: null output, then `handle != g_internal_handle` (0 until a successful open), then the SDK >= 4.50 branch, and initialization last. So in shadPS4, `sceHmdGetFieldOfView(1, buf)` before `sceHmdInitialize` returns `HANDLE_INVALID` (`0x81110003`) for any SDK version. This PR follows the 4.50 branch for the eye offset and sensor queries, and on that branch handle 0 returns `HANDLE_INVALID` too. The other three queries match shadPS4 before initialization. shadPS4 checks initialization first in `sceHmdGet2DEyeOffset` ([L73](https://github.com/shadps4-emu/shadPS4/blob/a808e7626e3c7de8d0f0fda6a91f620b42f6c762/src/core/libraries/hmd/hmd.cpp#L73)) and `sceHmdGetInertialSensorData` ([L179](https://github.com/shadps4-emu/shadPS4/blob/a808e7626e3c7de8d0f0fda6a91f620b42f6c762/src/core/libraries/hmd/hmd.cpp#L179)), and `sceHmdGetAssyError` has no handle. The PR description gives the reason (to keep the library's initialization-first order), but the description does not stay in the repository. CONTRIBUTING.md asks a debt entry to state what differs. The libSceHttp and libSceAudio3d entries record their differences from shadPS4 this way; both notes were added during review of #3497 and #1849. I'd suggest one clause in the entry: ```markdown Before initialization `sceHmdGetFieldOfView` returns `NOT_INITIALIZED` for a non-null output, where shadPS4 checks the handle first and returns `HANDLE_INVALID`. ``` Alternatively, follow shadPS4's order with `return fieldOfView ? Hmd::InvalidHandle : Hmd::ParameterNull;`, and give field of view its own pre-initialization expectation in the test.
YossiYad commented 2026-10-21 06:32:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-21T06:32:38Z.


@nikowolf123 thanks, that difference should be in the repository and not only in the description. I added your clause to the debt entry (fd178d902): before initialization sceHmdGetFieldOfView returns NOT_INITIALIZED for a non-null output, where shadPS4 checks the handle first and returns HANDLE_INVALID. I kept the initialization-first order so all four queries answer the same way before sceHmdInitialize. The entry is now 929 characters, and check_conventions has no findings.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309675403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256#issuecomment-6309675403). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-21T06:32:38Z. --- @nikowolf123 thanks, that difference should be in the repository and not only in the description. I added your clause to the debt entry (`fd178d902`): before initialization `sceHmdGetFieldOfView` returns `NOT_INITIALIZED` for a non-null output, where shadPS4 checks the handle first and returns `HANDLE_INVALID`. I kept the initialization-first order so all four queries answer the same way before `sceHmdInitialize`. The entry is now 929 characters, and `check_conventions` has no findings.
adriadam10 commented 2026-10-21 12:05:04 +00:00 (Migrated from github.com)

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


Checked the sizes, alignments, error codes and check order against shadPS4 (hmd_distortion.cpp, hmd_reprojection.cpp, hmd.cpp); they match, and the one deviation (initialization before handle) is recorded in the debt entry. The new guest_hmd checks fail without the change because those exports threw before; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315459712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8256#issuecomment-6315459712). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T12:05:04Z. --- Checked the sizes, alignments, error codes and check order against shadPS4 (`hmd_distortion.cpp`, `hmd_reprojection.cpp`, `hmd.cpp`); they match, and the one deviation (initialization before handle) is recorded in the debt entry. The new `guest_hmd` checks fail without the change because those exports threw before; 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!8256
No description provided.