The open source OpenXR runtime
at main 350 lines 7.8 kB view raw
1// Copyright 2020-2024 Collabora, Ltd. 2// Copyright 2025, NVIDIA CORPORATION. 3// SPDX-License-Identifier: BSL-1.0 4/*! 5 * @file 6 * @brief Common protocol definition. 7 * @author Pete Black <pblack@collabora.com> 8 * @author Jakob Bornecrantz <jakob@collabora.com> 9 * @author Korcan Hussein <korcan.hussein@collabora.com> 10 * @ingroup ipc_shared 11 */ 12 13#pragma once 14 15#include "xrt/xrt_limits.h" 16#include "xrt/xrt_compiler.h" 17#include "xrt/xrt_compositor.h" 18#include "xrt/xrt_results.h" 19#include "xrt/xrt_defines.h" 20#include "xrt/xrt_future.h" 21#include "xrt/xrt_system.h" 22#include "xrt/xrt_session.h" 23#include "xrt/xrt_instance.h" 24#include "xrt/xrt_compositor.h" 25#include "xrt/xrt_device.h" 26#include "xrt/xrt_space.h" 27#include "xrt/xrt_tracking.h" 28#include "xrt/xrt_config_build.h" 29 30#include <assert.h> 31#include <sys/types.h> 32 33 34#define IPC_CRED_SIZE 1 // auth not implemented 35#define IPC_BUF_SIZE 2048 // must be >= largest message length in bytes 36#define IPC_MAX_VIEWS 8 // max views we will return configs for 37#define IPC_MAX_FORMATS 32 // max formats our server-side compositor supports 38#define IPC_MAX_DEVICES 8 // max number of devices we will map using shared mem 39#define IPC_MAX_LAYERS XRT_MAX_LAYERS 40#define IPC_MAX_SLOTS 128 41#define IPC_MAX_CLIENTS 32 42#define IPC_MAX_RAW_VIEWS 32 // Max views that we can get, artificial limit. 43#define IPC_EVENT_QUEUE_SIZE 32 44 45#define IPC_SHARED_MAX_INPUTS 1024 46#define IPC_SHARED_MAX_OUTPUTS 128 47#define IPC_SHARED_MAX_BINDINGS 64 48 49// example: v21.0.0-560-g586d33b5 50#define IPC_VERSION_NAME_LEN 64 51 52#if defined(XRT_OS_WINDOWS) && !defined(XRT_ENV_MINGW) 53typedef int pid_t; 54#endif 55 56/* 57 * 58 * Shared memory structs. 59 * 60 */ 61 62/*! 63 * A tracking in the shared memory area. 64 * 65 * @ingroup ipc 66 */ 67struct ipc_shared_tracking_origin 68{ 69 //! For debugging. 70 char name[XRT_TRACKING_NAME_LEN]; 71 72 //! What can the state tracker expect from this tracking system. 73 enum xrt_tracking_type type; 74 75 //! Initial offset of the tracking origin. 76 struct xrt_pose offset; 77}; 78 79/*! 80 * A binding in the shared memory area. 81 * 82 * @ingroup ipc 83 */ 84struct ipc_shared_binding_profile 85{ 86 enum xrt_device_name name; 87 88 //! Offset into the array of pairs where this input bindings starts. 89 uint32_t first_input_index; 90 //! Number of inputs. 91 uint32_t input_count; 92 93 //! Offset into the array of pairs where this output bindings starts. 94 uint32_t first_output_index; 95 //! Number of outputs. 96 uint32_t output_count; 97}; 98 99/*! 100 * A device in the shared memory area. 101 * 102 * @ingroup ipc 103 */ 104struct ipc_shared_device 105{ 106 //! Enum identifier of the device. 107 enum xrt_device_name name; 108 enum xrt_device_type device_type; 109 110 //! Which tracking system origin is this device attached to. 111 uint32_t tracking_origin_index; 112 113 //! A string describing the device. 114 char str[XRT_DEVICE_NAME_LEN]; 115 116 //! A unique identifier. Persistent across configurations, if possible. 117 char serial[XRT_DEVICE_NAME_LEN]; 118 119 //! Number of bindings. 120 uint32_t binding_profile_count; 121 //! 'Offset' into the array of bindings where the bindings starts. 122 uint32_t first_binding_profile_index; 123 124 //! Number of inputs. 125 uint32_t input_count; 126 //! 'Offset' into the array of inputs where the inputs starts. 127 uint32_t first_input_index; 128 129 //! Number of outputs. 130 uint32_t output_count; 131 //! 'Offset' into the array of outputs where the outputs starts. 132 uint32_t first_output_index; 133 134 //! The supported fields. 135 struct xrt_device_supported supported; 136}; 137 138/*! 139 * Data for a single composition layer. 140 * 141 * Similar in function to @ref comp_layer 142 * 143 * @ingroup ipc 144 */ 145struct ipc_layer_entry 146{ 147 //! @todo what is this used for? 148 uint32_t xdev_id; 149 150 /*! 151 * Up to two indices of swapchains to use. 152 * 153 * How many are actually used depends on the value of @p data.type 154 */ 155 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2]; 156 157 /*! 158 * All basic (trivially-serializable) data associated with a layer, 159 * aside from which swapchain(s) are used. 160 */ 161 struct xrt_layer_data data; 162}; 163 164/*! 165 * Render state for a single client, including all layers. 166 * 167 * @ingroup ipc 168 */ 169struct ipc_layer_slot 170{ 171 struct xrt_layer_frame_data data; 172 uint32_t layer_count; 173 struct ipc_layer_entry layers[IPC_MAX_LAYERS]; 174}; 175 176/*! 177 * A big struct that contains all data that is shared to a client, no pointers 178 * allowed in this. To get the inputs of a device you go: 179 * 180 * ```C++ 181 * struct xrt_input * 182 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input) 183 * { 184 * uint32_t index = ism->isdevs[device_id]->first_input_index + input; 185 * return &ism->inputs[index]; 186 * } 187 * ``` 188 * 189 * @ingroup ipc 190 */ 191struct ipc_shared_memory 192{ 193 /*! 194 * The git revision of the service, used by clients to detect version mismatches. 195 */ 196 char u_git_tag[IPC_VERSION_NAME_LEN]; 197 198 /*! 199 * Number of elements in @ref itracks that are populated/valid. 200 */ 201 uint32_t itrack_count; 202 203 /*! 204 * @brief Array of shared tracking origin data. 205 * 206 * Only @ref itrack_count elements are populated/valid. 207 */ 208 struct ipc_shared_tracking_origin itracks[XRT_SYSTEM_MAX_DEVICES]; 209 210 /*! 211 * Number of elements in @ref isdevs that are populated/valid. 212 */ 213 uint32_t isdev_count; 214 215 /*! 216 * @brief Array of shared data per device. 217 * 218 * Only @ref isdev_count elements are populated/valid. 219 */ 220 struct ipc_shared_device isdevs[XRT_SYSTEM_MAX_DEVICES]; 221 222 /*! 223 * Various roles for the devices. 224 */ 225 struct 226 { 227 int32_t head; 228 int32_t eyes; 229 int32_t face; 230 int32_t body; 231 232 struct 233 { 234 struct 235 { 236 int32_t left; 237 int32_t right; 238 } unobstructed; 239 240 struct 241 { 242 int32_t left; 243 int32_t right; 244 } conforming; 245 } hand_tracking; 246 } roles; 247 248 struct 249 { 250 struct 251 { 252 /*! 253 * Pixel properties of this display, not in absolute 254 * screen coordinates that the compositor sees. So 255 * before any rotation is applied by xrt_view::rot. 256 * 257 * The xrt_view::display::w_pixels & 258 * xrt_view::display::h_pixels become the recommended 259 * image size for this view. 260 * 261 * @todo doesn't account for overfill for timewarp or 262 * distortion? 263 */ 264 struct 265 { 266 uint32_t w_pixels; 267 uint32_t h_pixels; 268 } display; 269 } views[2]; 270 // view count 271 uint32_t view_count; 272 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES]; 273 uint32_t blend_mode_count; 274 } hmd; 275 276 struct xrt_input inputs[IPC_SHARED_MAX_INPUTS]; 277 278 struct xrt_output outputs[IPC_SHARED_MAX_OUTPUTS]; 279 280 struct ipc_shared_binding_profile binding_profiles[IPC_SHARED_MAX_BINDINGS]; 281 struct xrt_binding_input_pair input_pairs[IPC_SHARED_MAX_INPUTS]; 282 struct xrt_binding_output_pair output_pairs[IPC_SHARED_MAX_OUTPUTS]; 283 284 struct ipc_layer_slot slots[IPC_MAX_SLOTS]; 285 286 uint64_t startup_timestamp; 287 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext; 288}; 289 290/*! 291 * Initial info from a client when it connects. 292 */ 293struct ipc_client_description 294{ 295 pid_t pid; 296 struct xrt_application_info info; 297}; 298 299struct ipc_client_list 300{ 301 uint32_t ids[IPC_MAX_CLIENTS]; 302 uint32_t id_count; 303}; 304 305/*! 306 * State for a connected application. 307 * 308 * @ingroup ipc 309 */ 310struct ipc_app_state 311{ 312 // Stable and unique ID of the client, only unique within this instance. 313 uint32_t id; 314 315 bool primary_application; 316 bool session_active; 317 bool session_visible; 318 bool session_focused; 319 bool session_overlay; 320 bool io_active; 321 uint32_t z_order; 322 pid_t pid; 323 struct xrt_application_info info; 324}; 325 326 327/*! 328 * Arguments for creating swapchains from native images. 329 */ 330struct ipc_arg_swapchain_from_native 331{ 332 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES]; 333}; 334 335/*! 336 * Arguments for xrt_device::get_view_poses with two views. 337 */ 338struct ipc_info_get_view_poses_2 339{ 340 struct xrt_fov fovs[XRT_MAX_VIEWS]; 341 struct xrt_pose poses[XRT_MAX_VIEWS]; 342 struct xrt_space_relation head_relation; 343}; 344 345struct ipc_pcm_haptic_buffer 346{ 347 uint32_t num_samples; 348 float sample_rate; 349 bool append; 350};