Monado OpenXR Runtime
Loading...
Searching...
No Matches
xrt_system.h
Go to the documentation of this file.
1// Copyright 2020-2024, Collabora, Ltd.
2// Copyright 2023-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Header for system objects.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Korcan Hussein <korcan.hussein@collabora.com>
9 * @ingroup xrt_iface
10 */
11
12#pragma once
13
14#include "xrt/xrt_compiler.h"
15#include "xrt/xrt_defines.h"
16#include "xrt/xrt_device.h"
19#include "xrt/xrt_io_cache.h"
20#include "xrt/xrt_limits.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26struct xrt_instance;
29struct xrt_session;
31struct xrt_session_info;
32
33
34/*
35 *
36 * System.
37 *
38 */
39
40#define XRT_SYSTEM_ID 1
41
42#define XRT_MAX_SYSTEM_NAME_SIZE 256
43
44/*!
45 * Properties provided by the system.
46 */
48{
49 uint32_t vendor_id;
50 char name[XRT_MAX_SYSTEM_NAME_SIZE];
51 enum xrt_form_factor form_factor;
52};
53
54/*!
55 * A system is a collection of devices, policies and optionally a compositor
56 * that is organised into a chosive group that is usable by one user, most of
57 * the functionality of a system is exposed through other objects, this is the
58 * main object. It is from this you create sessions that is used to by apps to
59 * interact with the "system".
60 *
61 * Sibling objects: @ref xrt_system_devices, @ref xrt_system_compositor and
62 * @ref xrt_space_overseer.
63 *
64 * @ingroup xrt_iface
65 */
67{
68 /*!
69 * Create a @ref xrt_session and optionally a @ref xrt_compositor_native
70 * for this system.
71 *
72 * param[in] xsys Pointer to self.
73 * param[in] xsi Session info.
74 * param[out] out_xs Created session.
75 * param[out] out_xcn Native compositor for this session, optional.
76 */
78 const struct xrt_session_info *xsi,
79 struct xrt_session **out_xs,
80 struct xrt_compositor_native **out_xcn);
81
82 /*!
83 * Destroy the system, must be destroyed after system devices and system
84 * compositor has been destroyed.
85 *
86 * Code consuming this interface should use @ref xrt_system_destroy.
87 *
88 * @param xsys Pointer to self
89 */
90 void (*destroy)(struct xrt_system *xsys);
91
92 struct xrt_system_properties properties;
93};
94
95/*!
96 * @copydoc xrt_system::create_session
97 *
98 * Helper for calling through the function pointer.
99 *
100 * @public @memberof xrt_system
101 */
102static inline xrt_result_t
104 const struct xrt_session_info *xsi,
105 struct xrt_session **out_xs,
106 struct xrt_compositor_native **out_xcn)
107{
108 return xsys->create_session(xsys, xsi, out_xs, out_xcn);
109}
110
111/*!
112 * Destroy an xrt_system - helper function.
113 *
114 * @param[in,out] xsys_ptr A pointer to the xrt_system struct pointer.
115 *
116 * Will destroy the system if `*xsys_ptr` is not NULL. Will then set
117 * `*xsys_ptr` to NULL.
118 *
119 * @public @memberof xrt_system
120 */
121XRT_NONNULL_ALL static inline void
123{
124 struct xrt_system *xsys = *xsys_ptr;
125 if (xsys == NULL) {
126 return;
127 }
128
129 *xsys_ptr = NULL;
130 xsys->destroy(xsys);
131}
132
133
134/*
135 *
136 * System devices.
137 *
138 */
139
140/*!
141 * Data associating a device index (in @ref xrt_system_devices::static_xdevs)
142 * with a given "role" for dynamic role switching.
143 *
144 * For each of the named roles, a negative value means unpopulated/not available.
145 *
146 * Populated by a call from the @ref xrt_system_devices interface.
147 *
148 * When the caller of @ref xrt_system_devices_get_roles sees a change (based on
149 * comparing @ref xrt_system_roles::generation_id) the caller must do the needed
150 * actions to handle device changes. For example, for the OpenXR state tracker
151 * this may include rebinding, queuing a change to the current interaction
152 * profile, and queuing the events associated with such a change.
153 *
154 * @see xrt_system_devices
155 * @ingroup xrt_iface
156 */
158{
159 /*!
160 * Monotonically increasing generation counter for the association
161 * between role and index.
162 *
163 * Increment whenever the roles are changed.
164 *
165 * All valid values are greater then zero; this is to
166 * make init easier where any cache can start at zero and be guaranteed
167 * to be replaced with a new @ref xrt_system_roles.
168 *
169 * alignas for 32 bit client support, see @ref ipc-design
170 */
171 XRT_ALIGNAS(8) uint64_t generation_id;
172
173 /*!
174 * Index in @ref xrt_system_devices::static_xdevs for the user's left
175 * controller/hand, or negative if none available.
176 */
177 int32_t left;
178
179 /*!
180 * Index in @ref xrt_system_devices::static_xdevs for the user's right
181 * controller/hand, or negative if none available.
182 */
183 int32_t right;
184
185 /*!
186 * Index in @ref xrt_system_devices::static_xdevs for the user's gamepad
187 * device, or negative if none available.
188 */
189 int32_t gamepad;
190
191 enum xrt_device_name left_profile;
192
193 enum xrt_device_name right_profile;
194
195 enum xrt_device_name gamepad_profile;
196};
197
198/*!
199 * Guaranteed invalid constant for @ref xrt_system_roles, not using designated
200 * initializers due to C++.
201 *
202 * @ingroup xrt_iface
203 * @relates xrt_system_roles
204 */
205#define XRT_SYSTEM_ROLES_INIT \
206 { \
207 0, -1, -1, -1, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, \
208 }
209
210/*!
211 * Features supported by a @ref xrt_system_devices as a whole, modeled after
212 * @ref xrt_device_supported.
213 *
214 * Filled in by the system when the system devices are created, and read by
215 * the state trackers so they don't have to inspect individual devices.
216 *
217 * @see xrt_device_supported, xrt_system_devices::supported
218 * @ingroup xrt_iface
219 */
221{
222 bool orientation_tracking;
223 bool position_tracking;
224 bool hand_tracking;
225 bool eye_gaze;
226 bool presence;
227 bool force_feedback;
228 bool face_tracking;
229
230 //! Body tracking with @ref XRT_INPUT_FB_BODY_TRACKING.
232 //! Body tracking with @ref XRT_INPUT_META_FULL_BODY_TRACKING.
234 //! Body tracking with @ref XRT_INPUT_BD_BODY_TRACKING or @ref XRT_INPUT_BD_BODY_TRACKING_WITHOUT_ARM.
236 bool body_tracking_calibration;
237 bool body_tracking_fidelity;
238
239 bool planes;
240 enum xrt_plane_detection_capability_flags_ext plane_capability_flags;
241};
242
243
244/*!
245 * A collection of @ref xrt_device, and an interface for identifying the roles
246 * they have been assigned.
247 *
248 * @see xrt_device, xrt_instance.
249 */
251{
252 /*!
253 * Features supported by these system devices. Filled in by the system
254 * at creation time and is static, it doesn't change during runtime.
255 * State trackers use this field to decide which features to announce
256 * support for to applications, for instance which extensions or system
257 * properties to expose.
258 *
259 * On systems that support hot-plug the capabilities themselves may come
260 * and go, for example a @ref xrt_hand_tracker object may stop returning
261 * hand poses when a device is unplugged. So for features backed by
262 * hot-plug capable interfaces, such as hand-tracking, these fields only
263 * describe possible capabilities rather than currently available ones.
264 */
266
267 /*!
268 * All devices known in the system.
269 *
270 * This is conventionally considered the "owning" reference to the devices.
271 * Valid entries are contiguous.
272 */
273 struct xrt_device *static_xdevs[XRT_SYSTEM_MAX_DEVICES];
274
275 /*!
276 * The number of elements in @ref static_xdevs that are valid in the
277 * static device list.
278 */
280
281 /*!
282 * Observing pointers for devices in some static (unchangeable) roles.
283 *
284 * All pointers in this struct must also exist in @ref static_xdevs.
285 * The association between a member of this struct and a given device
286 * cannot change during runtime.
287 */
288 struct
289 {
290 /*!
291 * An observing pointer to the device serving as the "head"
292 * (and HMD).
293 *
294 * Required.
295 */
297
298 /*!
299 * An observing pointer to the device providing eye tracking
300 * (optional).
301 */
303
304 /*!
305 * An observing pointer to the device providing face tracking
306 * (optional).
307 */
309
310 /*!
311 * An observing pointer to the device providing body tracking
312 * (optional).
313 */
315
316 /*!
317 * Devices providing optical (or otherwise more directly
318 * measured than from controller estimation) hand tracking.
319 */
320 struct
321 {
322 struct
323 {
324 /*!
325 * An observing pointer to the device providing
326 * unobstructed hand-tracking for the left hand (optional).
327 *
328 * can reference the same xrt_device instance as
329 * @ref hand_tracking::conforming::left, if provides both input types.
330 */
332
333 /*!
334 * An observing pointer to the device providing
335 * unobstructed hand-tracking for the right hand (optional).
336 *
337 * can reference the same xrt_device instance as
338 * @ref hand_tracking::conforming::right, if provides both input types.
339 */
341 } unobstructed;
342
343 struct
344 {
345 /*!
346 * An observing pointer to the device providing
347 * conforming (controller) hand-tracking for the left hand (optional).
348 *
349 * can reference the same xrt_device instance as
350 * @ref hand_tracking::unobstructed::left, if provides both input types.
351 */
352 struct xrt_device *left;
353
354 /*!
355 * An observing pointer to the device providing
356 * conforming (controller) hand-tracking for the right hand (optional).
357 *
358 * can reference the same xrt_device instance as
359 * @ref hand_tracking::unobstructed::right, if provides both input types.
360 */
361 struct xrt_device *right;
362 } conforming;
363 } hand_tracking;
364 } static_roles;
365
366 /*!
367 * Function to get the dynamic input device roles from this system
368 * devices, see @ref xrt_system_roles for more information.
369 *
370 * @param xsysd Pointer to self
371 * @param[out] out_roles Pointer to xrt_system_roles
372 */
373 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
374
375 /*!
376 * Create a @ref xrt_body_tracker from this system devices object.
377 *
378 * @param xsysd Pointer to self.
379 * @param info Body-tracker creation info.
380 * @param out_xbt Created body tracker.
381 */
382 xrt_result_t (*create_body_tracker)(struct xrt_system_devices *xsysd,
383 const struct xrt_body_tracker_create_info *info,
384 struct xrt_body_tracker **out_xbt);
385
386 /*!
387 * Create a @ref xrt_hand_tracker from this system devices object.
388 *
389 * @param xsysd Pointer to self.
390 * @param info Hand-tracker creation info.
391 * @param out_xht Created hand tracker.
392 */
393 xrt_result_t (*create_hand_tracker)(struct xrt_system_devices *xsysd,
394 const struct xrt_hand_tracker_create_info *info,
395 struct xrt_hand_tracker **out_xht);
396
397 /*!
398 * Create a @ref xrt_io_cache from this system devices object.
399 *
400 * @param xsysd Pointer to self.
401 * @param xso Space overseer used when creating input spaces.
402 * @param out_xic Created input/output cache.
403 */
404 xrt_result_t (*create_io_cache)(struct xrt_system_devices *xsysd,
405 struct xrt_space_overseer *xso,
406 struct xrt_io_cache **out_xic);
407
408 /*!
409 * Increment the usage count of a feature.
410 * When the feature is used for the first time, then the feature will be begun.
411 *
412 * @param xsysd Pointer to self
413 * @param type Which feature is being counted.
414 */
415 xrt_result_t (*feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
416
417 /*!
418 * Decrement the usage count of a feature.
419 * When the feature is not used by the current application any more, then the feature will be ended.
420 *
421 * @param xsysd Pointer to self
422 * @param type Which feature is being counted.
423 */
424 xrt_result_t (*feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
425
426 /*!
427 * Destroy all the devices that are owned by this system devices.
428 *
429 * Code consuming this interface should use @ref xrt_system_devices_destroy.
430 *
431 * @param xsysd Pointer to self
432 */
433 void (*destroy)(struct xrt_system_devices *xsysd);
434};
435
436/*!
437 * @copydoc xrt_system_devices::get_roles
438 *
439 * Helper for calling through the function pointer.
440 *
441 * @public @memberof xrt_system_devices
442 */
443XRT_NONNULL_ALL static inline xrt_result_t
445{
446 return xsysd->get_roles(xsysd, out_roles);
447}
448
449/*!
450 * @copydoc xrt_system_devices::create_body_tracker
451 *
452 * @public @memberof xrt_system_devices
453 */
454XRT_NONNULL_ALL static inline xrt_result_t
456 const struct xrt_body_tracker_create_info *info,
457 struct xrt_body_tracker **out_xbt)
458{
459 return xsysd->create_body_tracker(xsysd, info, out_xbt);
460}
461
462/*!
463 * @copydoc xrt_system_devices::create_hand_tracker
464 *
465 * @public @memberof xrt_system_devices
466 */
467XRT_NONNULL_ALL static inline xrt_result_t
469 const struct xrt_hand_tracker_create_info *info,
470 struct xrt_hand_tracker **out_xht)
471{
472 return xsysd->create_hand_tracker(xsysd, info, out_xht);
473}
474
475/*!
476 * @copydoc xrt_system_devices::create_io_cache
477 *
478 * @public @memberof xrt_system_devices
479 */
480XRT_NONNULL_ALL static inline xrt_result_t
482 struct xrt_space_overseer *xso,
483 struct xrt_io_cache **out_xic)
484{
485 return xsysd->create_io_cache(xsysd, xso, out_xic);
486}
487
488/*!
489 * @copydoc xrt_system_devices::feature_inc
490 *
491 * Helper for calling through the function pointer.
492 *
493 * @public @memberof xrt_system_devices
494 */
495XRT_NONNULL_ALL static inline xrt_result_t
497{
498 return xsysd->feature_inc(xsysd, type);
499}
500
501/*!
502 * @copydoc xrt_system_devices::feature_dec
503 *
504 * Helper for calling through the function pointer.
505 *
506 * @public @memberof xrt_system_devices
507 */
508XRT_NONNULL_ALL static inline xrt_result_t
510{
511 return xsysd->feature_dec(xsysd, type);
512}
513
514/*!
515 * Destroy an xrt_system_devices and owned devices - helper function.
516 *
517 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
518 *
519 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
520 * `*xsysd_ptr` to NULL.
521 *
522 * @public @memberof xrt_system_devices
523 */
524XRT_NONNULL_ALL static inline void
526{
527 struct xrt_system_devices *xsysd = *xsysd_ptr;
528 if (xsysd == NULL) {
529 return;
530 }
531
532 *xsysd_ptr = NULL;
533 xsysd->destroy(xsysd);
534}
535
536
537#ifdef __cplusplus
538}
539#endif
xrt_plane_detection_capability_flags_ext
Caps for a plane detector, see xrt_device.
Definition xrt_plane_detector.h:30
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition xrt_limits.h:26
xrt_form_factor
What form factor is this device, mostly maps onto OpenXR's XrFormFactor.
Definition xrt_defines.h:2501
enum xrt_result xrt_result_t
Result type used across Monado.
Creation parameters for xrt_body_tracker.
Definition xrt_body_tracker.h:30
A body tracker, owns the policy for selecting which device and body-tracking source back a single Ope...
Definition xrt_body_tracker.h:102
Main compositor server interface.
Definition xrt_compositor.h:2176
A single HMD or input device.
Definition xrt_device.h:345
Creation parameters for xrt_hand_tracker.
Definition xrt_hand_tracker.h:35
A hand tracker that owns device/source selection policy.
Definition xrt_hand_tracker.h:76
This interface acts as a root object for Monado.
Definition xrt_instance.h:124
A cache of flattened device inputs and outputs.
Definition xrt_io_cache.h:116
Session information, mostly overlay extension data.
Definition xrt_compositor.h:936
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition xrt_session.h:264
Object that oversees and manages spaces, one created for each XR system.
Definition xrt_space.h:97
Features supported by a xrt_system_devices as a whole, modeled after xrt_device_supported.
Definition xrt_system.h:221
bool full_body_tracking_meta
Body tracking with XRT_INPUT_META_FULL_BODY_TRACKING.
Definition xrt_system.h:233
bool body_tracking_bd
Body tracking with XRT_INPUT_BD_BODY_TRACKING or XRT_INPUT_BD_BODY_TRACKING_WITHOUT_ARM.
Definition xrt_system.h:235
bool body_tracking_fb
Body tracking with XRT_INPUT_FB_BODY_TRACKING.
Definition xrt_system.h:231
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:251
xrt_result_t(* feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Increment the usage count of a feature.
Definition xrt_system.h:415
xrt_result_t(* create_io_cache)(struct xrt_system_devices *xsysd, struct xrt_space_overseer *xso, struct xrt_io_cache **out_xic)
Create a xrt_io_cache from this system devices object.
Definition xrt_system.h:404
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_create_io_cache(struct xrt_system_devices *xsysd, struct xrt_space_overseer *xso, struct xrt_io_cache **out_xic)
Create a xrt_io_cache from this system devices object.
Definition xrt_system.h:481
xrt_result_t(* get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles)
Function to get the dynamic input device roles from this system devices, see xrt_system_roles for mor...
Definition xrt_system.h:373
static XRT_NONNULL_ALL void xrt_system_devices_destroy(struct xrt_system_devices **xsysd_ptr)
Destroy an xrt_system_devices and owned devices - helper function.
Definition xrt_system.h:525
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_create_body_tracker(struct xrt_system_devices *xsysd, const struct xrt_body_tracker_create_info *info, struct xrt_body_tracker **out_xbt)
Create a xrt_body_tracker from this system devices object.
Definition xrt_system.h:455
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition xrt_system.h:433
size_t static_xdev_count
The number of elements in static_xdevs that are valid in the static device list.
Definition xrt_system.h:279
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition xrt_system.h:296
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition xrt_system.h:308
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition xrt_system.h:302
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_feature_dec(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Decrement the usage count of a feature.
Definition xrt_system.h:509
xrt_result_t(* feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Decrement the usage count of a feature.
Definition xrt_system.h:424
xrt_result_t(* create_hand_tracker)(struct xrt_system_devices *xsysd, const struct xrt_hand_tracker_create_info *info, struct xrt_hand_tracker **out_xht)
Create a xrt_hand_tracker from this system devices object.
Definition xrt_system.h:393
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_create_hand_tracker(struct xrt_system_devices *xsysd, const struct xrt_hand_tracker_create_info *info, struct xrt_hand_tracker **out_xht)
Create a xrt_hand_tracker from this system devices object.
Definition xrt_system.h:468
struct xrt_device * left
An observing pointer to the device providing unobstructed hand-tracking for the left hand (optional).
Definition xrt_system.h:331
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_get_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles)
Function to get the dynamic input device roles from this system devices, see xrt_system_roles for mor...
Definition xrt_system.h:444
xrt_result_t(* create_body_tracker)(struct xrt_system_devices *xsysd, const struct xrt_body_tracker_create_info *info, struct xrt_body_tracker **out_xbt)
Create a xrt_body_tracker from this system devices object.
Definition xrt_system.h:382
struct xrt_device * right
An observing pointer to the device providing unobstructed hand-tracking for the right hand (optional)...
Definition xrt_system.h:340
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition xrt_system.h:314
static XRT_NONNULL_ALL xrt_result_t xrt_system_devices_feature_inc(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type)
Increment the usage count of a feature.
Definition xrt_system.h:496
Properties provided by the system.
Definition xrt_system.h:48
Data associating a device index (in xrt_system_devices::static_xdevs) with a given "role" for dynamic...
Definition xrt_system.h:158
int32_t right
Index in xrt_system_devices::static_xdevs for the user's right controller/hand, or negative if none a...
Definition xrt_system.h:183
XRT_ALIGNAS(8) uint64_t generation_id
Monotonically increasing generation counter for the association between role and index.
int32_t gamepad
Index in xrt_system_devices::static_xdevs for the user's gamepad device, or negative if none availabl...
Definition xrt_system.h:189
int32_t left
Index in xrt_system_devices::static_xdevs for the user's left controller/hand, or negative if none av...
Definition xrt_system.h:177
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition xrt_system.h:67
xrt_result_t(* create_session)(struct xrt_system *xsys, const struct xrt_session_info *xsi, struct xrt_session **out_xs, struct xrt_compositor_native **out_xcn)
Create a xrt_session and optionally a xrt_compositor_native for this system.
Definition xrt_system.h:77
static XRT_NONNULL_ALL void xrt_system_destroy(struct xrt_system **xsys_ptr)
Destroy an xrt_system - helper function.
Definition xrt_system.h:122
static xrt_result_t xrt_system_create_session(struct xrt_system *xsys, const struct xrt_session_info *xsi, struct xrt_session **out_xs, struct xrt_compositor_native **out_xcn)
Create a xrt_session and optionally a xrt_compositor_native for this system.
Definition xrt_system.h:103
void(* destroy)(struct xrt_system *xsys)
Destroy the system, must be destroyed after system devices and system compositor has been destroyed.
Definition xrt_system.h:90
Header defining xrt body tracker.
Header holding common defines.
Common defines and enums for XRT.
xrt_device_name
A enum that is used to name devices so that the state trackers can reason about the devices easier.
Definition xrt_defines.h:824
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition xrt_device.h:280
Header defining xrt hand tracker.
Header defining xrt input/output cache.
Header for limits of the XRT interfaces.