[PR #3442] [MERGED] Libraries: Improved libSceHmd stubs #3468

Closed
opened 2026-02-27 22:03:48 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/3442
Author: @StevenMiller123
Created: 8/21/2025
Status: Merged
Merged: 8/21/2025
Merged by: @georgemoralis

Base: mainHead: hmd-stubs


📝 Commits (10+)

📊 Changes

8 files changed (+725 additions, -443 deletions)

View changed files

📝 CMakeLists.txt (+2 -0)
📝 src/common/elf_info.h (+1 -0)
📝 src/core/libraries/hmd/hmd.cpp (+232 -391)
📝 src/core/libraries/hmd/hmd.h (+116 -52)
src/core/libraries/hmd/hmd_distortion.cpp (+107 -0)
src/core/libraries/hmd/hmd_error.h (+27 -0)
src/core/libraries/hmd/hmd_reprojection.cpp (+238 -0)
📝 src/emulator.cpp (+2 -0)

📄 Description

Like my previous PRs, this PR focuses on emulating libSceHmd functions as if the PSVR headset is not connected. This library is much more of a mess, due to a variety of bugs in the firmware library, which I show later in this PR description.

libSceHmd has three main components, the base library, the sceHmdDistortion sublibrary, and the sceHmdReprojection sublibrary. Both distortion and reprojection functions are fairly independant from the main library, with separate initialization functions, separate global variables, a separate shared memory allocation, and much more. As such, I've separated functions related to distortion and reprojection into separate files, though most of my focus was on the primary libSceHmd functions.

Along with the libSceHmd functions I've implemented, I also added a check during emulator startup to log if the game's param.sfo specifies PSVR support or PSVR requirements. While specifying these in a game's param.sfo doesn't seem to affect library behavior, it's safe to assume games that require PSVR won't properly check if a PSVR is connected, since the PS4 doesn't let you boot PSVR-required games without connecting a PSVR headset.

Throughout this PR, you'll see many functions returning ORBIS_HMD_ERROR_HANDLE_INVALID. This was a large point of confusion for me while testing, but the core issue is in how the actual library checks for a connected PSVR headset. Much of the library reads straight from device memory, and working functions check an field within this memory space that seems to be intended for checking if a headset is connected. There are several internal functions that just check for the presence of this device mapping, which exists so long as the library is loaded.

Attached are images from my library decompilation demonstrating the most common form of this bug.
image
image
As is visible here, the library does have an error check for ORBIS_HMD_ERROR_DEVICE_DISCONNECTED, but it relies on this GetUserId function returning an error. Since GetUserId succeeds so long as the library is initialized, this error check is never actually hit on real hardware. I haven't been able to figure out what user_id is outputted by GetUserId, but as far as I've been able to test, it's not what the library expects.

Here's an example of an internal function with a working error check.
image
image

TLDR: All the seemingly random ORBIS_HMD_ERROR_HANDLE_INVALID error returns are intentional, and are the result of me replicating bugs within the actual library.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/3442 **Author:** [@StevenMiller123](https://github.com/StevenMiller123) **Created:** 8/21/2025 **Status:** ✅ Merged **Merged:** 8/21/2025 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `hmd-stubs` --- ### 📝 Commits (10+) - [`275fd02`](https://github.com/shadps4-emu/shadPS4/commit/275fd02b0c657abee32163633359f94ed2b8a4d2) Initial work - [`7e046fd`](https://github.com/shadps4-emu/shadPS4/commit/7e046fd17be70400dee292e50df90fd1917ec66b) More work - [`6271067`](https://github.com/shadps4-emu/shadPS4/commit/62710674cc6db2c7e838a2196028f9eb326b2a9f) More stuff - [`fae85f9`](https://github.com/shadps4-emu/shadPS4/commit/fae85f9f643622e2ed4fa5fd42e82f291f5a576f) Update hmd.cpp - [`f038236`](https://github.com/shadps4-emu/shadPS4/commit/f03823638b7a363cf9738d9564705ab45a392646) Separate Reprojection and Distortion functions - [`9aa8d6f`](https://github.com/shadps4-emu/shadPS4/commit/9aa8d6fd0f995bc344e5dc47e00985b8c7599921) Fix weird Git issue - [`4be916d`](https://github.com/shadps4-emu/shadPS4/commit/4be916d2c392f494dce5127381f499be9c8498a6) Improve error documentation - [`2fc3a79`](https://github.com/shadps4-emu/shadPS4/commit/2fc3a7936ac34f19c4c8dea294f617a276f14a8c) Fix sceHmdGet2DEyeOffset - [`86e6150`](https://github.com/shadps4-emu/shadPS4/commit/86e615021556c7a3ffdb8ae9d7b099d7da4920fe) Merge remote-tracking branch 'upstream/main' into hmd-stubs - [`b3962ac`](https://github.com/shadps4-emu/shadPS4/commit/b3962acf7255f2befe9133384cf816d90380ba05) Update hmd.cpp ### 📊 Changes **8 files changed** (+725 additions, -443 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+2 -0) 📝 `src/common/elf_info.h` (+1 -0) 📝 `src/core/libraries/hmd/hmd.cpp` (+232 -391) 📝 `src/core/libraries/hmd/hmd.h` (+116 -52) ➕ `src/core/libraries/hmd/hmd_distortion.cpp` (+107 -0) ➕ `src/core/libraries/hmd/hmd_error.h` (+27 -0) ➕ `src/core/libraries/hmd/hmd_reprojection.cpp` (+238 -0) 📝 `src/emulator.cpp` (+2 -0) </details> ### 📄 Description Like my previous PRs, this PR focuses on emulating libSceHmd functions as if the PSVR headset is not connected. This library is much more of a mess, due to a variety of bugs in the firmware library, which I show later in this PR description. libSceHmd has three main components, the base library, the sceHmdDistortion sublibrary, and the sceHmdReprojection sublibrary. Both distortion and reprojection functions are fairly independant from the main library, with separate initialization functions, separate global variables, a separate shared memory allocation, and much more. As such, I've separated functions related to distortion and reprojection into separate files, though most of my focus was on the primary libSceHmd functions. Along with the libSceHmd functions I've implemented, I also added a check during emulator startup to log if the game's param.sfo specifies PSVR support or PSVR requirements. While specifying these in a game's param.sfo doesn't seem to affect library behavior, it's safe to assume games that require PSVR won't properly check if a PSVR is connected, since the PS4 doesn't let you boot PSVR-required games without connecting a PSVR headset. Throughout this PR, you'll see many functions returning `ORBIS_HMD_ERROR_HANDLE_INVALID`. This was a large point of confusion for me while testing, but the core issue is in how the actual library checks for a connected PSVR headset. Much of the library reads straight from device memory, and working functions check an field within this memory space that seems to be intended for checking if a headset is connected. There are several internal functions that just check for the presence of this device mapping, which exists so long as the library is loaded. Attached are images from my library decompilation demonstrating the most common form of this bug. <img width="539" height="232" alt="image" src="https://github.com/user-attachments/assets/0670e529-2485-46b5-acdd-b6c17d69cc50" /> <img width="391" height="204" alt="image" src="https://github.com/user-attachments/assets/07d5bdef-fca8-4aa6-bc86-5556da2cb17b" /> As is visible here, the library does have an error check for `ORBIS_HMD_ERROR_DEVICE_DISCONNECTED`, but it relies on this `GetUserId` function returning an error. Since `GetUserId` succeeds so long as the library is initialized, this error check is never actually hit on real hardware. I haven't been able to figure out what user_id is outputted by `GetUserId`, but as far as I've been able to test, it's not what the library expects. Here's an example of an internal function with a working error check. <img width="538" height="35" alt="image" src="https://github.com/user-attachments/assets/e21996ac-1c89-486b-8602-3b35bf3f5222" /> <img width="139" height="60" alt="image" src="https://github.com/user-attachments/assets/78bc3dec-0315-4f57-80ab-c8e676b939db" /> TLDR: All the seemingly random `ORBIS_HMD_ERROR_HANDLE_INVALID` error returns are intentional, and are the result of me replicating bugs within the actual library. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 22:03:48 +03:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
starred/shadPS4#3468
No description provided.