The open source OpenXR runtime
0
fork

Configure Feed

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

illixr: Add initial integration.

authored by

Jae Lee and committed by
Jakob Bornecrantz
a71de192 15320d9e

+493 -3
+6 -1
CMakeLists.txt
··· 156 156 # Most users won't touch these. 157 157 mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR) 158 158 159 + # ILLIXR 160 + set(ILLIXR_PATH "" CACHE PATH "Path to ILLIXR headers") 161 + 159 162 if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 160 163 set(XRT_HAVE_LIBUDEV ON) 161 164 set(XRT_HAVE_INTERNAL_HID ON) ··· 178 181 cmake_dependent_option(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" ON "XRT_HAVE_V4L2" OFF) 179 182 cmake_dependent_option(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" ON "XRT_HAVE_DBUS" OFF) 180 183 cmake_dependent_option(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" ON "XRT_HAVE_DBUS" OFF) 184 + cmake_dependent_option(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" ON "ILLIXR_PATH" OFF) 181 185 182 186 option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON) 183 187 cmake_dependent_option(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" ON "XRT_HAVE_LINUX OR ANDROID" OFF) ··· 195 199 196 200 # You can set this from a superproject to add a driver 197 201 # All drivers must be listed in here to be included in the generated header! 198 - list(APPEND AVAILABLE_DRIVERS "ANDROID" ARDUINO DUMMY HDK HYDRA NS OHMD PSMV PSVR RS V4L2 VIVE DAYDREAM REMOTE SURVIVE HANDTRACKING) 202 + list(APPEND AVAILABLE_DRIVERS "ANDROID" ARDUINO DUMMY HDK HYDRA NS OHMD PSMV PSVR RS V4L2 VIVE DAYDREAM REMOTE SURVIVE HANDTRACKING ILLIXR) 199 203 200 204 201 205 # Package name needs to be known by the native code itself. ··· 315 319 message(STATUS "# DRIVER_DUMMY: ${XRT_BUILD_DRIVER_DUMMY}") 316 320 message(STATUS "# DRIVER_HDK: ${XRT_BUILD_DRIVER_HDK}") 317 321 message(STATUS "# DRIVER_HYDRA: ${XRT_BUILD_DRIVER_HYDRA}") 322 + message(STATUS "# DRIVER_ILLIXR: ${XRT_BUILD_DRIVER_ILLIXR}") 318 323 message(STATUS "# DRIVER_NS: ${XRT_BUILD_DRIVER_NS}") 319 324 message(STATUS "# DRIVER_OHMD: ${XRT_BUILD_DRIVER_OHMD}") 320 325 message(STATUS "# DRIVER_HANDTRACKING: ${XRT_BUILD_DRIVER_HANDTRACKING}")
+17 -1
src/xrt/drivers/CMakeLists.txt
··· 231 231 list(APPEND ENABLED_DRIVERS android) 232 232 endif() 233 233 234 + if (XRT_BUILD_DRIVER_ILLIXR) 235 + set(ILLIXR_SOURCE_FILES 236 + illixr/illixr_device.cpp 237 + illixr/illixr_interface.h 238 + illixr/illixr_prober.c 239 + illixr/illixr_component.cpp 240 + illixr/illixr_component.h 241 + ) 242 + 243 + add_library(drv_illixr STATIC ${ILLIXR_SOURCE_FILES}) 244 + target_link_libraries(drv_illixr PUBLIC ${CMAKE_DL_LIBS} xrt-interfaces aux_util aux_os) 245 + target_include_directories(drv_illixr PUBLIC ${ILLIXR_PATH}) 246 + target_compile_options(drv_illixr PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>) 247 + list(APPEND ENABLED_HEADSET_DRIVERS illixr) 248 + endif() 249 + 234 250 if(ENABLED_HEADSET_DRIVERS) 235 251 set(ENABLED_DRIVERS ${ENABLED_HEADSET_DRIVERS} ${ENABLED_DRIVERS}) 236 252 list(SORT ENABLED_DRIVERS) ··· 238 254 message(STATUS "Enabled drivers: ${ENABLED_DRIVERS}") 239 255 else() 240 256 message(FATAL_ERROR "You must enable at least one headset driver to build Monado.") 241 - endif() 257 + endif()
+84
src/xrt/drivers/illixr/illixr_component.cpp
··· 1 + // Copyright 2020-2021, The Board of Trustees of the University of Illinois. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief ILLIXR plugin 6 + * @author RSIM Group <illixr@cs.illinois.edu> 7 + * @ingroup drv_illixr 8 + */ 9 + 10 + 11 + #include "xrt/xrt_device.h" 12 + 13 + #include <iostream> 14 + #include "common/plugin.hpp" 15 + #include "common/phonebook.hpp" 16 + #include "common/switchboard.hpp" 17 + #include "common/data_format.hpp" 18 + #include "common/pose_prediction.hpp" 19 + 20 + using namespace ILLIXR; 21 + 22 + /// Dummy plugin class for an instance during phonebook registration 23 + class illixr_plugin : public plugin 24 + { 25 + public: 26 + illixr_plugin(std::string name_, phonebook *pb_) 27 + : plugin{name_, pb_}, sb{pb->lookup_impl<switchboard>()}, 28 + sb_pose{pb->lookup_impl<pose_prediction>()}, 29 + sb_eyebuffer{sb->publish<rendered_frame>("eyebuffer")}, 30 + sb_vsync_estimate{ 31 + sb->subscribe_latest<time_type>("vsync_estimate")} 32 + {} 33 + 34 + const std::shared_ptr<switchboard> sb; 35 + const std::shared_ptr<pose_prediction> sb_pose; 36 + const std::unique_ptr<writer<rendered_frame>> sb_eyebuffer; 37 + const std::unique_ptr<reader_latest<time_type>> sb_vsync_estimate; 38 + fast_pose_type prev_pose; /* stores a copy of pose each time 39 + illixr_read_pose() is called */ 40 + std::chrono::time_point<std::chrono::system_clock> 41 + sample_time; /* when prev_pose was stored */ 42 + }; 43 + 44 + static illixr_plugin *illixr_plugin_obj = nullptr; 45 + 46 + extern "C" plugin * 47 + illixr_monado_create_plugin(phonebook *pb) 48 + { 49 + illixr_plugin_obj = new illixr_plugin{"illixr_plugin", pb}; 50 + illixr_plugin_obj->start(); 51 + return illixr_plugin_obj; 52 + } 53 + 54 + extern "C" struct xrt_pose 55 + illixr_read_pose() 56 + { 57 + assert(illixr_plugin_obj && 58 + "illixr_plugin_obj must be initialized first."); 59 + 60 + if (!illixr_plugin_obj->sb_pose->fast_pose_reliable()) { 61 + std::cerr << "Pose not reliable yet; returning best guess" 62 + << std::endl; 63 + } 64 + struct xrt_pose ret; 65 + const fast_pose_type fast_pose = 66 + illixr_plugin_obj->sb_pose->get_fast_pose(); 67 + const pose_type pose = fast_pose.pose; 68 + 69 + // record when the pose was read for use in write_frame 70 + illixr_plugin_obj->sample_time = std::chrono::system_clock::now(); 71 + 72 + ret.orientation.x = pose.orientation.x(); 73 + ret.orientation.y = pose.orientation.y(); 74 + ret.orientation.z = pose.orientation.z(); 75 + ret.orientation.w = pose.orientation.w(); 76 + ret.position.x = pose.position.x(); 77 + ret.position.y = pose.position.y(); 78 + ret.position.z = pose.position.z(); 79 + 80 + // store pose in static variable for use in write_frame 81 + illixr_plugin_obj->prev_pose = fast_pose; // copy member variables 82 + 83 + return ret; 84 + }
+23
src/xrt/drivers/illixr/illixr_component.h
··· 1 + // Copyright 2020-2021, The Board of Trustees of the University of Illinois. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief ILLIXR plugin 6 + * @author RSIM Group <illixr@cs.illinois.edu> 7 + * @ingroup drv_illixr 8 + */ 9 + 10 + #pragma once 11 + 12 + #ifdef __cplusplus 13 + extern "C" { 14 + #endif 15 + 16 + void * 17 + illixr_monado_create_plugin(void *pb); 18 + struct xrt_pose 19 + illixr_read_pose(); 20 + 21 + #ifdef __cplusplus 22 + } 23 + #endif
+231
src/xrt/drivers/illixr/illixr_device.cpp
··· 1 + // Copyright 2020-2021, The Board of Trustees of the University of Illinois. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief ILLIXR HMD 6 + * @author RSIM Group <illixr@cs.illinois.edu> 7 + * @ingroup drv_illixr 8 + */ 9 + 10 + #include <math.h> 11 + #include <stdio.h> 12 + #include <unistd.h> 13 + #include <stdlib.h> 14 + #include <string.h> 15 + #include <assert.h> 16 + #include <dlfcn.h> 17 + #include <alloca.h> 18 + #include <string> 19 + #include <sstream> 20 + 21 + #include "math/m_api.h" 22 + #include "xrt/xrt_device.h" 23 + #include "util/u_var.h" 24 + #include "util/u_misc.h" 25 + #include "util/u_debug.h" 26 + #include "util/u_device.h" 27 + #include "util/u_time.h" 28 + #include "util/u_distortion_mesh.h" 29 + 30 + #include "illixr_component.h" 31 + #include "common/dynamic_lib.hpp" 32 + #include "common/runtime.hpp" 33 + 34 + /* 35 + * 36 + * Structs and defines. 37 + * 38 + */ 39 + 40 + struct illixr_hmd 41 + { 42 + struct xrt_device base; 43 + 44 + struct xrt_pose pose; 45 + 46 + bool print_spew; 47 + bool print_debug; 48 + 49 + const char *path; 50 + const char *comp; 51 + ILLIXR::dynamic_lib *runtime_lib; 52 + ILLIXR::runtime *runtime; 53 + }; 54 + 55 + 56 + /* 57 + * 58 + * Functions 59 + * 60 + */ 61 + 62 + static inline struct illixr_hmd * 63 + illixr_hmd(struct xrt_device *xdev) 64 + { 65 + return (struct illixr_hmd *)xdev; 66 + } 67 + 68 + DEBUG_GET_ONCE_BOOL_OPTION(illixr_spew, "ILLIXR_PRINT_SPEW", false) 69 + DEBUG_GET_ONCE_BOOL_OPTION(illixr_debug, "ILLIXR_PRINT_DEBUG", false) 70 + 71 + #define DH_SPEW(dh, ...) \ 72 + do { \ 73 + if (dh->print_spew) { \ 74 + fprintf(stderr, "%s - ", __func__); \ 75 + fprintf(stderr, __VA_ARGS__); \ 76 + fprintf(stderr, "\n"); \ 77 + } \ 78 + } while (false) 79 + 80 + #define DH_DEBUG(dh, ...) \ 81 + do { \ 82 + if (dh->print_debug) { \ 83 + fprintf(stderr, "%s - ", __func__); \ 84 + fprintf(stderr, __VA_ARGS__); \ 85 + fprintf(stderr, "\n"); \ 86 + } \ 87 + } while (false) 88 + 89 + #define DH_ERROR(dh, ...) \ 90 + do { \ 91 + fprintf(stderr, "%s - ", __func__); \ 92 + fprintf(stderr, __VA_ARGS__); \ 93 + fprintf(stderr, "\n"); \ 94 + } while (false) 95 + 96 + static void 97 + illixr_hmd_destroy(struct xrt_device *xdev) 98 + { 99 + struct illixr_hmd *dh = illixr_hmd(xdev); 100 + dh->runtime->stop(); 101 + delete dh->runtime; 102 + delete dh->runtime_lib; 103 + 104 + // Remove the variable tracking. 105 + u_var_remove_root(dh); 106 + 107 + u_device_free(&dh->base); 108 + } 109 + 110 + static void 111 + illixr_hmd_update_inputs(struct xrt_device *xdev) 112 + { 113 + // Empty 114 + } 115 + 116 + static void 117 + illixr_hmd_get_tracked_pose(struct xrt_device *xdev, 118 + enum xrt_input_name name, 119 + uint64_t at_timestamp_ns, 120 + struct xrt_space_relation *out_relation) 121 + { 122 + if (name != XRT_INPUT_GENERIC_HEAD_POSE) { 123 + DH_ERROR(illixr_hmd(xdev), "unknown input name"); 124 + return; 125 + } 126 + 127 + out_relation->pose = illixr_read_pose(); 128 + out_relation->relation_flags = (enum xrt_space_relation_flags)( 129 + XRT_SPACE_RELATION_ORIENTATION_VALID_BIT | 130 + XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT | 131 + XRT_SPACE_RELATION_POSITION_VALID_BIT | 132 + XRT_SPACE_RELATION_POSITION_TRACKED_BIT); 133 + } 134 + 135 + static void 136 + illixr_hmd_get_view_pose(struct xrt_device *xdev, 137 + struct xrt_vec3 *eye_relation, 138 + uint32_t view_index, 139 + struct xrt_pose *out_pose) 140 + { 141 + struct xrt_pose pose = illixr_read_pose(); 142 + 143 + *out_pose = pose; 144 + } 145 + 146 + std::vector<std::string> 147 + split(const std::string &s, char delimiter) 148 + { 149 + std::vector<std::string> tokens; 150 + std::string token; 151 + std::istringstream tokenStream{s}; 152 + while (std::getline(tokenStream, token, delimiter)) { 153 + tokens.push_back(token); 154 + } 155 + return tokens; 156 + } 157 + 158 + static int 159 + illixr_rt_launch(struct illixr_hmd *dh, const char *path, const char *comp) 160 + { 161 + dh->runtime_lib = new ILLIXR::dynamic_lib{ 162 + ILLIXR::dynamic_lib::create(std::string{path})}; 163 + dh->runtime = 164 + dh->runtime_lib->get<ILLIXR::runtime *(*)()>("runtime_factory")(); 165 + dh->runtime->load_so(split(std::string{comp}, ':')); 166 + dh->runtime->load_plugin_factory( 167 + (ILLIXR::plugin_factory)illixr_monado_create_plugin); 168 + 169 + return 0; 170 + } 171 + 172 + extern "C" struct xrt_device * 173 + illixr_hmd_create(const char *path_in, const char *comp_in) 174 + { 175 + struct illixr_hmd *dh; 176 + enum u_device_alloc_flags flags = (enum u_device_alloc_flags)( 177 + U_DEVICE_ALLOC_HMD | U_DEVICE_ALLOC_TRACKING_NONE); 178 + dh = U_DEVICE_ALLOCATE(struct illixr_hmd, flags, 1, 0); 179 + dh->base.update_inputs = illixr_hmd_update_inputs; 180 + dh->base.get_tracked_pose = illixr_hmd_get_tracked_pose; 181 + dh->base.get_view_pose = illixr_hmd_get_view_pose; 182 + dh->base.destroy = illixr_hmd_destroy; 183 + dh->base.name = XRT_DEVICE_GENERIC_HMD; 184 + dh->base.device_type = XRT_DEVICE_TYPE_HMD; 185 + dh->base.hmd->blend_mode = XRT_BLEND_MODE_OPAQUE; 186 + dh->pose.orientation.w = 1.0f; // All other values set to zero. 187 + dh->print_spew = debug_get_bool_option_illixr_spew(); 188 + dh->print_debug = debug_get_bool_option_illixr_debug(); 189 + dh->path = path_in; 190 + dh->comp = comp_in; 191 + 192 + // Print name. 193 + snprintf(dh->base.str, XRT_DEVICE_NAME_LEN, "ILLIXR"); 194 + 195 + // Setup input. 196 + dh->base.inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; 197 + 198 + // Setup info. 199 + struct u_device_simple_info info; 200 + info.display.w_pixels = 2048; 201 + info.display.h_pixels = 1024; 202 + info.display.w_meters = 0.14f; 203 + info.display.h_meters = 0.07f; 204 + info.lens_horizontal_separation_meters = 0.13f / 2.0f; 205 + info.lens_vertical_position_meters = 0.07f / 2.0f; 206 + info.views[0].fov = 85.0f * (M_PI / 180.0f); 207 + info.views[1].fov = 85.0f * (M_PI / 180.0f); 208 + 209 + if (!u_device_setup_split_side_by_side(&dh->base, &info)) { 210 + DH_ERROR(dh, "Failed to setup basic device info"); 211 + illixr_hmd_destroy(&dh->base); 212 + return NULL; 213 + } 214 + 215 + // Setup variable tracker. 216 + u_var_add_root(dh, "ILLIXR", true); 217 + u_var_add_pose(dh, &dh->pose, "pose"); 218 + 219 + if (dh->base.hmd->distortion.preferred == XRT_DISTORTION_MODEL_NONE) { 220 + // Setup the distortion mesh. 221 + u_distortion_mesh_set_none(&dh->base); 222 + } 223 + 224 + // start ILLIXR runtime 225 + if (illixr_rt_launch(dh, dh->path, dh->comp) != 0) { 226 + DH_ERROR(dh, "Failed to load ILLIXR Runtime"); 227 + illixr_hmd_destroy(&dh->base); 228 + } 229 + 230 + return &dh->base; 231 + }
+48
src/xrt/drivers/illixr/illixr_interface.h
··· 1 + // Copyright 2020-2021, The Board of Trustees of the University of Illinois. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief ILLIXR driver interface 6 + * @author RSIM Group <illixr@cs.illinois.edu> 7 + * @ingroup drv_illixr 8 + */ 9 + 10 + #pragma once 11 + 12 + #ifdef __cplusplus 13 + extern "C" { 14 + #endif 15 + 16 + /*! 17 + * @defgroup drv_illixr illixr driver. 18 + * @ingroup drv 19 + * 20 + * @brief illixr driver. 21 + */ 22 + 23 + /*! 24 + * Create a auto prober for illixr devices. 25 + * 26 + * @ingroup drv_illixr 27 + */ 28 + struct xrt_auto_prober * 29 + illixr_create_auto_prober(void); 30 + 31 + /*! 32 + * Create a illixr hmd. 33 + * 34 + * @ingroup drv_illixr 35 + */ 36 + struct xrt_device * 37 + illixr_hmd_create(const char *path, const char *comp); 38 + 39 + /*! 40 + * @dir drivers/illixr 41 + * 42 + * @brief @ref drv_illixr files. 43 + */ 44 + 45 + 46 + #ifdef __cplusplus 47 + } 48 + #endif
+67
src/xrt/drivers/illixr/illixr_prober.c
··· 1 + // Copyright 2020-2021, The Board of Trustees of the University of Illinois. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief ILLIXR prober 6 + * @author RSIM Group <illixr@cs.illinois.edu> 7 + * @ingroup drv_illixr 8 + */ 9 + 10 + #include "xrt/xrt_prober.h" 11 + #include "util/u_misc.h" 12 + #include "util/u_debug.h" 13 + 14 + #include "illixr_interface.h" 15 + 16 + 17 + struct illixr_prober 18 + { 19 + struct xrt_auto_prober base; 20 + }; 21 + 22 + static inline struct illixr_prober * 23 + illixr_prober(struct xrt_auto_prober *p) 24 + { 25 + return (struct illixr_prober *)p; 26 + } 27 + 28 + static void 29 + illixr_prober_destroy(struct xrt_auto_prober *p) 30 + { 31 + struct illixr_prober *dp = illixr_prober(p); 32 + 33 + free(dp); 34 + } 35 + 36 + static struct xrt_device * 37 + illixr_prober_autoprobe(struct xrt_auto_prober *xap, 38 + cJSON *attached_data, 39 + bool no_hmds, 40 + struct xrt_prober *xp) 41 + { 42 + struct illixr_prober *dp = illixr_prober(xap); 43 + (void)dp; 44 + 45 + if (no_hmds) { 46 + return NULL; 47 + } 48 + 49 + const char *illixr_path, *illixr_comp; 50 + illixr_path = getenv("ILLIXR_PATH"); 51 + illixr_comp = getenv("ILLIXR_COMP"); 52 + if (!illixr_path || !illixr_comp) { 53 + return NULL; 54 + } 55 + 56 + return illixr_hmd_create(illixr_path, illixr_comp); 57 + } 58 + 59 + struct xrt_auto_prober * 60 + illixr_create_auto_prober() 61 + { 62 + struct illixr_prober *dp = U_TYPED_CALLOC(struct illixr_prober); 63 + dp->base.destroy = illixr_prober_destroy; 64 + dp->base.lelo_dallas_autoprobe = illixr_prober_autoprobe; 65 + 66 + return &dp->base; 67 + }
+1 -1
src/xrt/state_trackers/prober/CMakeLists.txt
··· 89 89 target_link_libraries(st_prober PRIVATE 90 90 drv_remote 91 91 ) 92 - endif() 92 + endif()
+4
src/xrt/targets/cli/cli_cmd_probe.c
··· 92 92 printf(" libsurvive,"); 93 93 #endif 94 94 95 + #ifdef XRT_BUILD_DRIVER_ILLIXR 96 + printf(" ILLIXR,"); 97 + #endif 98 + 95 99 printf("\n"); 96 100 97 101 // Initialize the prober.
+4
src/xrt/targets/common/CMakeLists.txt
··· 88 88 target_link_libraries(target_lists PRIVATE drv_android) 89 89 endif() 90 90 91 + if(XRT_BUILD_DRIVER_ILLIXR) 92 + target_link_libraries(target_lists PRIVATE drv_illixr) 93 + endif() 94 + 91 95 #### 92 96 # Instance 93 97 #
+8
src/xrt/targets/common/target_lists.c
··· 62 62 #include "android/android_prober.h" 63 63 #endif 64 64 65 + #ifdef XRT_BUILD_DRIVER_ILLIXR 66 + #include "illixr/illixr_interface.h" 67 + #endif 68 + 65 69 /*! 66 70 * Each entry should be a vendor ID (VID), product ID (PID), a "found" function, 67 71 * and a string literal name. ··· 148 152 149 153 #ifdef XRT_BUILD_DRIVER_ANDROID 150 154 android_create_auto_prober, 155 + #endif 156 + 157 + #ifdef XRT_BUILD_DRIVER_ILLIXR 158 + illixr_create_auto_prober, 151 159 #endif 152 160 153 161 #ifdef XRT_BUILD_DRIVER_DUMMY