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/*!
212 * A collection of @ref xrt_device, and an interface for identifying the roles
213 * they have been assigned.
214 *
215 * @see xrt_device, xrt_instance.
216 */
218{
219 /*!
220 * All devices known in the system.
221 *
222 * This is conventionally considered the "owning" reference to the devices.
223 * Valid entries are contiguous.
224 */
225 struct xrt_device *static_xdevs[XRT_SYSTEM_MAX_DEVICES];
226
227 /*!
228 * The number of elements in @ref static_xdevs that are valid in the
229 * static device list.
230 */
232
233 /*!
234 * Observing pointers for devices in some static (unchangeable) roles.
235 *
236 * All pointers in this struct must also exist in @ref static_xdevs.
237 * The association between a member of this struct and a given device
238 * cannot change during runtime.
239 */
240 struct
241 {
242 /*!
243 * An observing pointer to the device serving as the "head"
244 * (and HMD).
245 *
246 * Required.
247 */
249
250 /*!
251 * An observing pointer to the device providing eye tracking
252 * (optional).
253 */
255
256 /*!
257 * An observing pointer to the device providing face tracking
258 * (optional).
259 */
261
262 /*!
263 * An observing pointer to the device providing body tracking
264 * (optional).
265 */
267
268 /*!
269 * Devices providing optical (or otherwise more directly
270 * measured than from controller estimation) hand tracking.
271 */
272 struct
273 {
274 struct
275 {
276 /*!
277 * An observing pointer to the device providing
278 * unobstructed hand-tracking for the left hand (optional).
279 *
280 * can reference the same xrt_device instance as
281 * @ref hand_tracking::conforming::left, if provides both input types.
282 */
284
285 /*!
286 * An observing pointer to the device providing
287 * unobstructed hand-tracking for the right hand (optional).
288 *
289 * can reference the same xrt_device instance as
290 * @ref hand_tracking::conforming::right, if provides both input types.
291 */
293 } unobstructed;
294
295 struct
296 {
297 /*!
298 * An observing pointer to the device providing
299 * conforming (controller) hand-tracking for the left hand (optional).
300 *
301 * can reference the same xrt_device instance as
302 * @ref hand_tracking::unobstructed::left, if provides both input types.
303 */
304 struct xrt_device *left;
305
306 /*!
307 * An observing pointer to the device providing
308 * conforming (controller) hand-tracking for the right hand (optional).
309 *
310 * can reference the same xrt_device instance as
311 * @ref hand_tracking::unobstructed::right, if provides both input types.
312 */
313 struct xrt_device *right;
314 } conforming;
315 } hand_tracking;
316 } static_roles;
317
318
319 /*!
320 * Function to get the dynamic input device roles from this system
321 * devices, see @ref xrt_system_roles for more information.
322 *
323 * @param xsysd Pointer to self
324 * @param[out] out_roles Pointer to xrt_system_roles
325 */
326 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
327
328 /*!
329 * Create a @ref xrt_body_tracker from this system devices object.
330 *
331 * @param xsysd Pointer to self.
332 * @param info Body-tracker creation info.
333 * @param out_xbt Created body tracker.
334 */
335 xrt_result_t (*create_body_tracker)(struct xrt_system_devices *xsysd,
336 const struct xrt_body_tracker_create_info *info,
337 struct xrt_body_tracker **out_xbt);
338
339 /*!
340 * Create a @ref xrt_hand_tracker from this system devices object.
341 *
342 * @param xsysd Pointer to self.
343 * @param info Hand-tracker creation info.
344 * @param out_xht Created hand tracker.
345 */
346 xrt_result_t (*create_hand_tracker)(struct xrt_system_devices *xsysd,
347 const struct xrt_hand_tracker_create_info *info,
348 struct xrt_hand_tracker **out_xht);
349
350 /*!
351 * Create a @ref xrt_io_cache from this system devices object.
352 *
353 * @param xsysd Pointer to self.
354 * @param xso Space overseer used when creating input spaces.
355 * @param out_xic Created input/output cache.
356 */
357 xrt_result_t (*create_io_cache)(struct xrt_system_devices *xsysd,
358 struct xrt_space_overseer *xso,
359 struct xrt_io_cache **out_xic);
360
361 /*!
362 * Increment the usage count of a feature.
363 * When the feature is used for the first time, then the feature will be begun.
364 *
365 * @param xsysd Pointer to self
366 * @param type Which feature is being counted.
367 */
368 xrt_result_t (*feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
369
370 /*!
371 * Decrement the usage count of a feature.
372 * When the feature is not used by the current application any more, then the feature will be ended.
373 *
374 * @param xsysd Pointer to self
375 * @param type Which feature is being counted.
376 */
377 xrt_result_t (*feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
378
379 /*!
380 * Destroy all the devices that are owned by this system devices.
381 *
382 * Code consuming this interface should use @ref xrt_system_devices_destroy.
383 *
384 * @param xsysd Pointer to self
385 */
386 void (*destroy)(struct xrt_system_devices *xsysd);
387};
388
389/*!
390 * @copydoc xrt_system_devices::get_roles
391 *
392 * Helper for calling through the function pointer.
393 *
394 * @public @memberof xrt_system_devices
395 */
396XRT_NONNULL_ALL static inline xrt_result_t
398{
399 return xsysd->get_roles(xsysd, out_roles);
400}
401
402/*!
403 * @copydoc xrt_system_devices::create_body_tracker
404 *
405 * @public @memberof xrt_system_devices
406 */
407XRT_NONNULL_ALL static inline xrt_result_t
409 const struct xrt_body_tracker_create_info *info,
410 struct xrt_body_tracker **out_xbt)
411{
412 return xsysd->create_body_tracker(xsysd, info, out_xbt);
413}
414
415/*!
416 * @copydoc xrt_system_devices::create_hand_tracker
417 *
418 * @public @memberof xrt_system_devices
419 */
420XRT_NONNULL_ALL static inline xrt_result_t
422 const struct xrt_hand_tracker_create_info *info,
423 struct xrt_hand_tracker **out_xht)
424{
425 return xsysd->create_hand_tracker(xsysd, info, out_xht);
426}
427
428/*!
429 * @copydoc xrt_system_devices::create_io_cache
430 *
431 * @public @memberof xrt_system_devices
432 */
433XRT_NONNULL_ALL static inline xrt_result_t
435 struct xrt_space_overseer *xso,
436 struct xrt_io_cache **out_xic)
437{
438 return xsysd->create_io_cache(xsysd, xso, out_xic);
439}
440
441/*!
442 * @copydoc xrt_system_devices::feature_inc
443 *
444 * Helper for calling through the function pointer.
445 *
446 * @public @memberof xrt_system_devices
447 */
448XRT_NONNULL_ALL static inline xrt_result_t
450{
451 return xsysd->feature_inc(xsysd, type);
452}
453
454/*!
455 * @copydoc xrt_system_devices::feature_dec
456 *
457 * Helper for calling through the function pointer.
458 *
459 * @public @memberof xrt_system_devices
460 */
461XRT_NONNULL_ALL static inline xrt_result_t
463{
464 return xsysd->feature_dec(xsysd, type);
465}
466
467/*!
468 * Destroy an xrt_system_devices and owned devices - helper function.
469 *
470 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
471 *
472 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
473 * `*xsysd_ptr` to NULL.
474 *
475 * @public @memberof xrt_system_devices
476 */
477XRT_NONNULL_ALL static inline void
479{
480 struct xrt_system_devices *xsysd = *xsysd_ptr;
481 if (xsysd == NULL) {
482 return;
483 }
484
485 *xsysd_ptr = NULL;
486 xsysd->destroy(xsysd);
487}
488
489
490#ifdef __cplusplus
491}
492#endif
#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:2444
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:2226
A single HMD or input device.
Definition xrt_device.h:328
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:986
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
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:218
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:368
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:357
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:434
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:326
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:478
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:408
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition xrt_system.h:386
size_t static_xdev_count
The number of elements in static_xdevs that are valid in the static device list.
Definition xrt_system.h:231
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition xrt_system.h:248
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition xrt_system.h:260
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition xrt_system.h:254
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:462
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:377
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:346
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:421
struct xrt_device * left
An observing pointer to the device providing unobstructed hand-tracking for the left hand (optional).
Definition xrt_system.h:283
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:397
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:335
struct xrt_device * right
An observing pointer to the device providing unobstructed hand-tracking for the right hand (optional)...
Definition xrt_system.h:292
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition xrt_system.h:266
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:449
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:767
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition xrt_device.h:263
Header defining xrt hand tracker.
Header defining xrt input/output cache.
Header for limits of the XRT interfaces.