vr: add OpenXR headset output, VR tracker and VR controller input behind --vr #1726
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1726
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1726/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@LeandroSWR on GitHub · 2026-10-19 17:20 UTC · original
LeandroSWR:vr/openxr-support→main· +18 −1 · 3 files · 2 commits · closed without mergingAdds what a PSVR2 game needs to run on a real headset through OpenXR. All of the VR code is gated on
--vr(the virtual headset introduced earlier); without it nothing changes for any title. Includes two small GPU fixes that the first game I tested needed to stay alive.What it does
Headset output
VideoOutRegisterBuffers2is handled, including titles that flip the headset port before registering it. The HMD2 port shares the presentation layers with the main output.--vrthe eye image is also shown in the desktop window, so the picture is visible without a headset.KYTY_OPENXR=0turns the headset path off completely.Input
libSceVrTracker2(QueryMemory, Initialize, RegisterDevice, GetResult). Head and controller poses come from OpenXR, laid out the way the game reads the result.libPadgets the left/right VR controller ports (port types 3 and 4), VR controller state and the trigger-effect entry points. The VR handles (0x10,0x11) sit outside the per-player handle range; the tracker names a controller by this handle, so both share the constants incontroller.h.libHmd2: Open, reprojection frame, predicted display time, gaze and timing calls.GPU fixes (first two commits, independent of VR)
shader: shrink the per-invocation LDS array for non-compute stages— stages without a workgroup emulate LDS with one private array per invocation. The previous size (8192 dwords) multiplied across the invocations in flight into gigabytes of driver local memory and killed the device. 1024 dwords is enough for the lane-id-plus-small-offset addressing these shaders use; accesses beyond it were already bounds-checked.graphics: zero-initialize the BDA page table— device-local memory is uninitialized, so a missing entry must read as zero and fault in the shader instead of following a garbage pointer.Testing
main.Limitations
hA9LshbSkzw,retc+-uRMhk).psvr2.prxplugin) starts but shows no picture. It calls six functions that are not implemented here and describes its headset swapchain differently. That is left for a follow-up.Video
Note: This video has some extra patches that are game specific for correct rendering that are not part of this PR.
https://github.com/user-attachments/assets/cca45a5c-1113-46a0-803e-1b360f210d0b
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original · edited 2026-10-20 00:24 UTC
📝 Walkthrough
The changes add Windows OpenXR support and connect headset image presentation, HMD2 video output, and VR controller and tracker APIs. They also add one-time buffer-device-address page-table initialization and reduce the shader LDS fallback allocation for stages without workgroup input.
Suggested reviewers:
nmzik,pipe530Priority: ➖ Normal
Change: Feature
Merge Risk: 🟡 Moderate · up to
5eaf7With VR enabled, this change can crash the emulator during headset buffer registration or compute preview, and can overwrite unrelated game memory through HMD2 result calls. Fix these before merging. Several smaller VR input-state gaps can also be fixed in this change. Non-VR use is mostly unaffected.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 23.20% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 125 functions across 21 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/graphics/host_gpu/renderer/renderCompute.cppline 372 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4551
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41544
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 37285
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6294
Guard null image IDs before headset preview.
When a written compute image has a null descriptor,
ResolveTextureleavesimage_idempty.RebindImagesskips that binding, but the preview loop still callsGetImagewith the empty ID.GetImagerejects the invalid slot and can stop the emulator when VR preview is enabled.The binding-size mismatch is already rejected by
RebindImages, so only the image-ID guard is needed.🛡️ Suggested fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/graphics/presentation/openxrHeadset.cppline 419 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Clear
g.activeand the input state when the runtime ends the session.The runtime can send
XR_SESSION_STATE_EXITINGorXR_SESSION_STATE_LOSS_PENDING, for example when the user closes SteamVR or the headset disconnects. This case setsg.stop, andThreadMainthen returns.g.activestaystrueuntilOpenXrShutdownruns at window teardown.After that,
OpenXrGetControllerandOpenXrGetHeadPosestill return the last cachedg.inputandg.headvalues.vrInput.hsays these functions return false when no headset session is running, and the caller then uses the keyboard or gamepad. With the current code, the game keeps reading frozen VR input and does not fall back to the keyboard or gamepad. If a button was held at that moment, the game sees it as held.OpenXrQueueEyeSourcealso keeps copying frames into staging images that nothing reads.Set
g.activeto false and reset the cached input before the thread exits.🐛 Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/graphics/presentation/videoOut.cppline 1506 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4100
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 38715
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 17765
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9009
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5610
Check protection before reading descriptor words.
MappedTailonly proves that the address is in a tracked range. It does not prove that the host can read it. Query the protection and reject ranges that do not permit host reads beforestd::memcpy. ANoAccessdescriptor can otherwise fault duringVideoOutRegisterBuffers2.@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/graphics/presentation/videoOut.cppline 1698 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Choose the headset layout from all buffers, not only from
buffer_view[0].HeadsetDisplayAttributeuses only the address of slot 0 to setlinear, and only the mapped tail of slot 0 to check the footprint. Then line 1732 callsgroup.ImageInfofor every slot. In tiled mode,ImageInforequires each address to be 64 KiB aligned. If an address is not aligned, it callsEXIT.Here is a realistic failure:
The same problem occurs when a later slot has a smaller mapped tail than the candidate footprint.
Fix: treat the group as tiled only when every slot is 64 KiB aligned. Use the smallest mapped tail of all slots for the footprint check.
🐛 Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/libs/controller.cppline 1189 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Accept VR port opens only on player 1.
PadOpenusesuser_idto choose the player, and then callsOpenPorton that player. A user mapped to player 2 or higher can therefore open a VR port.OpenPortthen setsm_vr_open[hand]on that player and returnsPAD_HANDLE_VR_LEFT + hand.PlayerForHandlesends every VR handle tog_players[0].CheckPortHandleLockedthen checks them_vr_openflag of player 1, which is stillfalse. As a result:PAD_ERROR_INVALID_HANDLE.PadClosecannot close the port.PadOpencall returnsPAD_ERROR_ALREADY_OPENED.GetPortHandlehas the same mismatch. Reject VR port types whenm_player != 0, so that open state and handle routing use the same player.🐛 Proposed fix
Apply the same guard in
GetPortHandleand returnPAD_ERROR_NO_HANDLE.📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/libs/libHmd2.cppline 298 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 30678
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24452
Use the verified output argument for Hmd2 result writes.
LastGuestPointerselects the last argument that passes only the guest-address threshold. Ifarg1is the result buffer andarg2is another guest pointer,Hmd2GazeGetResultreads the size fromarg2, then can clear and overwrite that unrelated buffer.PredictedTimeOutputhas the same positional ambiguity because it always prefersarg1when both arguments look like guest pointers.Use the tested argument layout for
lAoFUedcfqAandSVEG+1D7qHA. Pass only the verified output argument to the writer instead of selecting a pointer by address.@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/libs/libPad.cppline 227 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Return the handle error from
PadVrControllerReadState.If
Controller::PadReadState(handle, &pad)fails because the handle is not valid or not open, this function still returnsOK. It also writes a default, disconnected report. The other handle-based pad entry points in this file return the result ofPadCheckHandle.With the current code, a game that uses a closed VR handle, or reads before it opens the port, gets success and does not detect its mistake. Return the error code from
PadReadState, except in the success case.🐛 Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original
On
src/libs/libVrTracker2.cppline 79 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not send an identity pose at the origin as a fully tracked pose when tracking is lost.
OpenXrGetHeadPosereturnsfalsein these cases:In these cases,
WritePosestill writesRESULT_STATE_TRACKEDandRESULT_FLAGS_VALID, together with position (0,0,0) and identity orientation. The game then moves its camera to the tracking origin for those frames, and then moves it back. A controller withpose_valid == falsegets the same result, so the hand moves to the origin.For the HMD, keep the last valid pose and send it again.
openxrHeadset.cppalready storesg.last_head_readfor this purpose. Do the same for each controller. Alternatively, report a state value that marks the pose as not tracked.Also applies to: 88-94
@coderabbitai[bot] on GitHub · 2026-10-19 17:56 UTC · original · reviewed
Actionable comments posted: 8
ℹ️ Review info
⚙️ Run configuration
d1d12ed8-ce0f-4b39-94a5-ba012a9449ae📥 Commits
Reviewing files that changed from the base of the PR and between
0cad4672e9and 5eaf7635cd7c4bbb6c20f098212c54db292f1123.📒 Files selected for processing: 23
3rdparty/CMakeLists.txtCMakeLists.txtsrc/graphics/host_gpu/renderer/commandScheduler.cppsrc/graphics/host_gpu/renderer/commandScheduler.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/presentation/headsetPreview.cppsrc/graphics/presentation/headsetPreview.hsrc/graphics/presentation/openxrHeadset.cppsrc/graphics/presentation/openxrHeadset.hsrc/graphics/presentation/presenter.hsrc/graphics/presentation/videoOut.cppsrc/graphics/presentation/vrInput.hsrc/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cppsrc/libs/controller.cppsrc/libs/controller.hsrc/libs/hmd2.hsrc/libs/libHmd2.cppsrc/libs/libPad.cppsrc/libs/libVrTracker2.cppsrc/libs/libs.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@Nmzik on GitHub · 2026-10-20 00:23 UTC · original
@LeandroSWR Main VR support has been merged along with struct fixes/ABIs/minor optimizations and Linux support. Please make sure your future PRs are based on it (unless we created a new bug :)) Thanks!
@Nmzik on GitHub · 2026-10-21 03:47 UTC · original
Credited
Pull request closed