From 28c93c3fb889f01b0826e0ad559db3790f62d2d8 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Thu, 5 Sep 2024 01:30:10 +0900 Subject: [PATCH] steamvr_lh support --- CMakeLists.txt | 2 ++ common/wivrn_config.h.in | 2 ++ server/CMakeLists.txt | 10 ++++---- server/driver/wivrn_session.cpp | 41 ++++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12936955..2c97a92b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,8 @@ auto_option(WIVRN_USE_X264 "Enable x264 software encoder" AUTO) auto_option(WIVRN_USE_PIPEWIRE "Enable pipewire backend" AUTO) auto_option(WIVRN_USE_PULSEAUDIO "Enable pulseaudio backend" AUTO) +option(WIVRN_FEATURE_STEAMVR_LIGHTHOUSE "Enable SteamVR Lighthouse driver" OFF) + option(WIVRN_OPENXR_INSTALL_ABSOLUTE_RUNTIME_PATH OFF) option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON) diff --git a/common/wivrn_config.h.in b/common/wivrn_config.h.in index d8c8f109..f6cbd90e 100644 --- a/common/wivrn_config.h.in +++ b/common/wivrn_config.h.in @@ -29,4 +29,6 @@ #cmakedefine WIVRN_USE_PIPEWIRE #cmakedefine WIVRN_USE_PULSEAUDIO +#cmakedefine WIVRN_FEATURE_STEAMVR_LIGHTHOUSE + #define WIVRN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 4def6445..049bbe84 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -15,7 +15,7 @@ set(XRT_BUILD_DRIVER_REMOTE OFF) set(XRT_BUILD_DRIVER_RIFT_S OFF) set(XRT_BUILD_DRIVER_ROKID OFF) set(XRT_BUILD_DRIVER_SIMULATED OFF) -set(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE OFF) +set(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE ${WIVRN_FEATURE_STEAMVR_LIGHTHOUSE}) set(XRT_BUILD_DRIVER_TWRAP OFF) set(XRT_BUILD_DRIVER_VF OFF) set(XRT_BUILD_DRIVER_VIVE OFF) @@ -29,9 +29,6 @@ set(XRT_FEATURE_SERVICE_SYSTEMD OFF) set(XRT_FEATURE_SLAM OFF) set(XRT_FEATURE_STEAMVR_PLUGIN OFF) set(XRT_FEATURE_WINDOW_PEEK OFF) -set(XRT_FEATURE_STEAMVR_PLUGIN OFF) -set(XRT_FEATURE_WINDOW_PEEK OFF) -set(XRT_FEATURE_WINDOW_PEEK OFF) set(XRT_FEATURE_OPENXR_FACE_TRACKING2_FB ON) set(XRT_HAVE_BLUETOOTH OFF) @@ -101,6 +98,11 @@ target_include_directories(wivrn-server PRIVATE .) target_link_libraries(wivrn-server PRIVATE CLI11::CLI11) +if (WIVRN_FEATURE_STEAMVR_LIGHTHOUSE) + target_include_directories(wivrn-server SYSTEM PRIVATE ${monado_SOURCE_DIR}/src/xrt/drivers/steamvr_lh/) + target_link_libraries(wivrn-server PRIVATE drv_steamvr_lh) +endif() + if(WIVRN_USE_NVENC) target_sources(wivrn-server PRIVATE encoder/video_encoder_nvenc.cpp) endif() diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index bd979757..6b8aa033 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -33,6 +33,7 @@ #include "audio/audio_setup.h" #include "wivrn_comp_target.h" +#include "wivrn_config.h" #include "wivrn_controller.h" #include "wivrn_eye_tracker.h" #include "wivrn_fb_face2_tracker.h" @@ -44,6 +45,10 @@ #include #include +#ifdef WIVRN_FEATURE_STEAMVR_LIGHTHOUSE +#include "steamvr_lh_interface.h" +#endif + struct wivrn_comp_target_factory : public comp_target_factory { std::shared_ptr session; @@ -162,13 +167,43 @@ xrt_result_t xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wi if (self->hmd->face_tracking_supported) usysds->base.base.static_roles.face = self->hmd.get(); - if (self->left_hand) + xrt_device * active_left_hand = nullptr; + xrt_device * active_right_hand = nullptr; + +#ifdef WIVRN_FEATURE_STEAMVR_LIGHTHOUSE + auto use_steamvr_lh = std::getenv("WIVRN_USE_STEAMVR_LH"); + xrt_system_devices * lhdevs = NULL; + + if (use_steamvr_lh && steamvr_lh_create_devices(&lhdevs) == XRT_SUCCESS) { + for (int i = 0; i < lhdevs->xdev_count; i++) + { + auto lhdev = lhdevs->xdevs[i]; + devices->xdevs[n++] = lhdev; + switch (lhdev->device_type) + { + case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER: + active_left_hand = lhdev; + break; + case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER: + active_right_hand = lhdev; + break; + default: + break; + } + } + } +#endif + + if (self->left_hand && !active_left_hand) + { + active_left_hand = self->left_hand.get(); devices->xdevs[n++] = self->left_hand.get(); usysds->base.base.static_roles.hand_tracking.left = self->left_hand.get(); } - if (self->right_hand) + if (self->right_hand && !active_right_hand) { + active_right_hand = self->right_hand.get(); devices->xdevs[n++] = self->right_hand.get(); usysds->base.base.static_roles.hand_tracking.right = self->right_hand.get(); } @@ -187,7 +222,7 @@ xrt_result_t xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wi } devices->xdev_count = n; - u_system_devices_static_finalize(usysds, self->left_hand.get(), self->right_hand.get()); + u_system_devices_static_finalize(usysds, active_left_hand, active_right_hand); wivrn_comp_target_factory ctf(self, self->info.preferred_refresh_rate); auto xret = comp_main_create_system_compositor(self->hmd.get(), &ctf, out_xsysc);