The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

t/common: Implement SteamVR builder

authored by

BabbleBones and committed by
Jakob Bornecrantz
4eac541d d7ed1cb7

+245 -29
+6 -4
src/xrt/targets/common/CMakeLists.txt
··· 28 28 target_sources(target_lists PRIVATE target_builder_rift_s.c) 29 29 endif() 30 30 31 - if(XRT_BUILD_DRIVER_SURVIVE 32 - OR XRT_BUILD_DRIVER_VIVE 33 - OR XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 34 - ) 31 + if(XRT_BUILD_DRIVER_SURVIVE OR XRT_BUILD_DRIVER_VIVE) 35 32 target_sources(target_lists PRIVATE target_builder_lighthouse.c) 33 + endif() 34 + 35 + if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) 36 + target_sources(target_lists PRIVATE target_builder_steamvr.c) 36 37 endif() 37 38 38 39 if(XRT_BUILD_DRIVER_SIMULATED) ··· 171 172 172 173 if(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) 173 174 target_link_libraries(target_lists PRIVATE drv_steamvr_lh) 175 + target_sources(target_lists PRIVATE target_builder_steamvr.c) 174 176 endif() 175 177 176 178 if(XRT_BUILD_DRIVER_ANDROID)
+12
src/xrt/targets/common/target_builder_interface.h
··· 23 23 #define T_BUILDER_LIGHTHOUSE 24 24 #endif 25 25 26 + #if defined(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) || defined(XRT_DOXYGEN) 27 + #define T_BUILDER_STEAMVR 28 + #endif 29 + 26 30 #if defined(XRT_BUILD_DRIVER_NS) || defined(XRT_DOXYGEN) 27 31 #define T_BUILDER_NS 28 32 #endif ··· 64 68 */ 65 69 struct xrt_builder * 66 70 t_builder_legacy_create(void); 71 + #endif 72 + 73 + #ifdef T_BUILDER_STEAMVR 74 + /*! 75 + * Builder for SteamVR proprietary wrapper (vive, index, tundra trackers, etc.) 76 + */ 77 + struct xrt_builder * 78 + t_builder_steamvr_create(void); 67 79 #endif 68 80 69 81 #ifdef T_BUILDER_LIGHTHOUSE
+10 -25
src/xrt/targets/common/target_builder_lighthouse.c
··· 47 47 #include "survive/survive_interface.h" 48 48 #endif 49 49 50 - #ifdef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 51 - #include "steamvr_lh/steamvr_lh_interface.h" 52 - #endif 53 - 54 50 #ifdef XRT_BUILD_DRIVER_HANDTRACKING 55 51 #include "ht/ht_interface.h" 56 52 #include "ht_ctrl_emu/ht_ctrl_emu_interface.h" ··· 64 60 65 61 #if defined(XRT_BUILD_DRIVER_SURVIVE) 66 62 #define DEFAULT_DRIVER "survive" 67 - #elif defined(XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE) 68 - #define DEFAULT_DRIVER "steamvr" 69 63 #else 70 64 #define DEFAULT_DRIVER "vive" 71 65 #endif ··· 92 86 #define LH_ASSERT_(predicate) LH_ASSERT(predicate, "Assertion failed " #predicate) 93 87 94 88 static const char *driver_list[] = { 95 - #ifdef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 96 - "steamvr_lh", 97 - #endif 98 - 99 89 #ifdef XRT_BUILD_DRIVER_SURVIVE 100 90 "survive", 101 91 #endif ··· 309 299 bool have_survive_drv = false; 310 300 #endif 311 301 312 - #ifdef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 313 - bool have_steamvr_drv = true; 314 - #else 315 - bool have_steamvr_drv = false; 316 - #endif 317 - 318 302 const char *drv = debug_get_option_lh_impl(); 319 - if (have_steamvr_drv && strcmp(drv, "steamvr") == 0) { 303 + if (strcmp(drv, "steamvr") == 0) { 320 304 lhs->driver = DRIVER_STEAMVR; 321 305 } else if (have_survive_drv && strcmp(drv, "survive") == 0) { 322 306 lhs->driver = DRIVER_SURVIVE; ··· 327 311 if (have_survive_drv) { 328 312 selected = "survive"; 329 313 lhs->driver = DRIVER_SURVIVE; 330 - } else if (have_steamvr_drv) { 331 - selected = "steamvr"; 332 - lhs->driver = DRIVER_STEAMVR; 333 314 } else if (have_vive_drv) { 334 315 selected = "vive"; 335 316 lhs->driver = DRIVER_VIVE; ··· 337 318 LH_ASSERT_(false); 338 319 } 339 320 LH_WARN("Requested driver %s was not available, so we went with %s instead", drv, selected); 321 + } 322 + 323 + // Error on wrong configuration. 324 + if (lhs->driver == DRIVER_STEAMVR) { 325 + LH_ERROR("Use new env variable STEAMVR_LH_ENABLE=true to enable SteamVR driver"); 326 + return XRT_ERROR_PROBING_FAILED; 340 327 } 341 328 342 329 #ifdef XRT_BUILD_DRIVER_HANDTRACKING ··· 558 545 559 546 switch (lhs->driver) { 560 547 case DRIVER_STEAMVR: { 561 - #ifdef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 562 - xsysd->xdev_count += steamvr_lh_get_devices(&xsysd->xdevs[xsysd->xdev_count]); 563 - #endif 564 - break; 548 + assert(false); 549 + return XRT_ERROR_DEVICE_CREATION_FAILED; 565 550 } 566 551 case DRIVER_SURVIVE: { 567 552 #ifdef XRT_BUILD_DRIVER_SURVIVE ··· 790 775 lhs->base.base.open_system = u_builder_open_system_static_roles; 791 776 lhs->base.base.destroy = lighthouse_destroy; 792 777 lhs->base.base.identifier = "lighthouse"; 793 - lhs->base.base.name = "Lighthouse-tracked (Vive, Index, Tundra trackers, etc.) devices builder"; 778 + lhs->base.base.name = "Lighthouse-tracked FLOSS (Vive, Index, Tundra trackers, etc.) devices builder"; 794 779 lhs->base.base.driver_identifiers = driver_list; 795 780 lhs->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); 796 781
+213
src/xrt/targets/common/target_builder_steamvr.c
··· 1 + // Copyright 2023, Duncan Spaulding. 2 + // Copyright 2022-2023, Collabora, Ltd. 3 + // SPDX-License-Identifier: BSL-1.0 4 + /*! 5 + * @file 6 + * @brief Builder for SteamVR proprietary driver wrapper. 7 + * @author BabbleBones <BabbleBones@protonmail.com> 8 + * @author Jakob Bornecrantz <jakob@collabora.com> 9 + * @ingroup xrt_iface 10 + */ 11 + 12 + #include "tracking/t_hand_tracking.h" 13 + #include "tracking/t_tracking.h" 14 + 15 + #include "xrt/xrt_config_drivers.h" 16 + #include "xrt/xrt_device.h" 17 + #include "xrt/xrt_prober.h" 18 + 19 + #include "util/u_builders.h" 20 + #include "util/u_config_json.h" 21 + #include "util/u_debug.h" 22 + #include "util/u_device.h" 23 + #include "util/u_sink.h" 24 + #include "util/u_system_helpers.h" 25 + 26 + #include "vive/vive_builder.h" 27 + 28 + #include "target_builder_interface.h" 29 + 30 + #include "steamvr_lh/steamvr_lh_interface.h" 31 + 32 + #ifndef XRT_BUILD_DRIVER_STEAMVR_LIGHTHOUSE 33 + #error "This builder requires the SteamVR Lighthouse driver" 34 + #endif 35 + 36 + 37 + /* 38 + * 39 + * Misc stuff. 40 + * 41 + */ 42 + 43 + DEBUG_GET_ONCE_LOG_OPTION(steamvr_log, "STEAMVR_LH_LOG", U_LOGGING_WARN) 44 + DEBUG_GET_ONCE_BOOL_OPTION(steamvr_enable, "STEAMVR_LH_ENABLE", false) 45 + 46 + #define LH_TRACE(...) U_LOG_IFL_T(debug_get_log_option_steamvr_log(), __VA_ARGS__) 47 + #define LH_DEBUG(...) U_LOG_IFL_D(debug_get_log_option_steamvr_log(), __VA_ARGS__) 48 + #define LH_INFO(...) U_LOG_IFL_I(debug_get_log_option_steamvr_log(), __VA_ARGS__) 49 + #define LH_WARN(...) U_LOG_IFL_W(debug_get_log_option_steamvr_log(), __VA_ARGS__) 50 + #define LH_ERROR(...) U_LOG_IFL_E(debug_get_log_option_steamvr_log(), __VA_ARGS__) 51 + 52 + static const char *driver_list[] = { 53 + "steamvr_lh", 54 + }; 55 + 56 + struct steamvr_builder 57 + { 58 + struct xrt_builder base; 59 + 60 + /*! 61 + * Is our HMD a Valve Index? 62 + */ 63 + bool is_valve_index; 64 + }; 65 + 66 + 67 + /* 68 + * 69 + * Member functions. 70 + * 71 + */ 72 + 73 + static xrt_result_t 74 + steamvr_estimate_system(struct xrt_builder *xb, 75 + cJSON *config, 76 + struct xrt_prober *xp, 77 + struct xrt_builder_estimate *estimate) 78 + { 79 + struct steamvr_builder *svrb = (struct steamvr_builder *)xb; 80 + 81 + // Currently no built in support for hand tracking. 82 + bool have_hand_tracking = false; 83 + 84 + if (debug_get_bool_option_steamvr_enable()) { 85 + return vive_builder_estimate( // 86 + xp, // xp 87 + true, // have_6dof 88 + have_hand_tracking, // have_hand_tracking 89 + &svrb->is_valve_index, // out_have_valve_index 90 + estimate); // out_estimate 91 + } else { 92 + return XRT_SUCCESS; 93 + } 94 + } 95 + 96 + static xrt_result_t 97 + steamvr_open_system(struct xrt_builder *xb, 98 + cJSON *config, 99 + struct xrt_prober *xp, 100 + struct xrt_system_devices **out_xsysd, 101 + struct xrt_space_overseer **out_xso) 102 + { 103 + struct steamvr_builder *svrb = (struct steamvr_builder *)xb; 104 + struct u_system_devices_static *usysds = NULL; 105 + struct xrt_system_devices *xsysd = NULL; 106 + xrt_result_t result = XRT_SUCCESS; 107 + 108 + // Sanity checking. 109 + if (out_xsysd == NULL || *out_xsysd != NULL) { 110 + LH_ERROR("Invalid output system pointer"); 111 + return XRT_ERROR_DEVICE_CREATION_FAILED; 112 + } 113 + 114 + // Use the static system devices helper, no dynamic roles. 115 + usysds = u_system_devices_static_allocate(); 116 + xsysd = &usysds->base.base; 117 + 118 + // Do creation. 119 + xsysd->xdev_count += steamvr_lh_get_devices(&xsysd->xdevs[xsysd->xdev_count]); 120 + 121 + // Device indices. 122 + int head_idx = -1; 123 + int left_idx = -1; 124 + int right_idx = -1; 125 + 126 + // Look for regular devices. 127 + u_device_assign_xdev_roles(xsysd->xdevs, xsysd->xdev_count, &head_idx, &left_idx, &right_idx); 128 + 129 + // Sanity check. 130 + if (head_idx < 0) { 131 + LH_ERROR("Unable to find HMD"); 132 + result = XRT_ERROR_DEVICE_CREATION_FAILED; 133 + goto end_err; 134 + } 135 + 136 + // Devices to populate. 137 + struct xrt_device *head = NULL; 138 + struct xrt_device *left = NULL, *right = NULL; 139 + struct xrt_device *left_ht = NULL, *right_ht = NULL; 140 + 141 + // Always have a head. 142 + head = xsysd->xdevs[head_idx]; 143 + 144 + // It's okay if we didn't find controllers 145 + if (left_idx >= 0) { 146 + left = xsysd->xdevs[left_idx]; 147 + left_ht = u_system_devices_get_ht_device_left(xsysd); 148 + } 149 + 150 + if (right_idx >= 0) { 151 + right = xsysd->xdevs[right_idx]; 152 + right_ht = u_system_devices_get_ht_device_right(xsysd); 153 + } 154 + 155 + if (svrb->is_valve_index) { 156 + // This space left intentionally blank 157 + } 158 + 159 + // Assign to role(s). 160 + xsysd->static_roles.head = head; 161 + xsysd->static_roles.hand_tracking.left = left_ht; 162 + xsysd->static_roles.hand_tracking.right = right_ht; 163 + 164 + u_system_devices_static_finalize( // 165 + usysds, // usysds 166 + left, // left 167 + right); // right 168 + 169 + *out_xsysd = xsysd; 170 + u_builder_create_space_overseer_legacy( // 171 + head, // head 172 + left, // left 173 + right, // right 174 + xsysd->xdevs, // xdevs 175 + xsysd->xdev_count, // xdev_count 176 + out_xso); // out_xso 177 + 178 + return XRT_SUCCESS; 179 + 180 + end_err: 181 + xrt_system_devices_destroy(&xsysd); 182 + 183 + return result; 184 + } 185 + 186 + static void 187 + steamvr_destroy(struct xrt_builder *xb) 188 + { 189 + struct steamvr_builder *svrb = (struct steamvr_builder *)xb; 190 + free(svrb); 191 + } 192 + 193 + 194 + /* 195 + * 196 + * 'Exported' functions. 197 + * 198 + */ 199 + 200 + struct xrt_builder * 201 + t_builder_steamvr_create(void) 202 + { 203 + struct steamvr_builder *svrb = U_TYPED_CALLOC(struct steamvr_builder); 204 + svrb->base.estimate_system = steamvr_estimate_system; 205 + svrb->base.open_system = steamvr_open_system; 206 + svrb->base.destroy = steamvr_destroy; 207 + svrb->base.identifier = "steamvr"; 208 + svrb->base.name = "SteamVR proprietary wrapper (Vive, Index, Tundra trackers, etc.) devices builder"; 209 + svrb->base.driver_identifiers = driver_list; 210 + svrb->base.driver_identifier_count = ARRAY_SIZE(driver_list); 211 + 212 + return &svrb->base; 213 + }
+4
src/xrt/targets/common/target_lists.c
··· 128 128 t_builder_simula_create, 129 129 #endif // T_BUILDER_SIMULAVR 130 130 131 + #ifdef T_BUILDER_STEAMVR 132 + t_builder_steamvr_create, 133 + #endif // T_BUILDER_STEAMVR 134 + 131 135 #ifdef T_BUILDER_LIGHTHOUSE 132 136 t_builder_lighthouse_create, 133 137 #endif // T_BUILDER_LIGHTHOUSE