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_limits.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25struct xrt_instance;
27struct xrt_session;
29struct xrt_session_info;
30
31
32/*
33 *
34 * System.
35 *
36 */
37
38#define XRT_SYSTEM_ID 1
39
40#define XRT_MAX_SYSTEM_NAME_SIZE 256
41
42/*!
43 * Properties provided by the system.
44 */
46{
47 uint32_t vendor_id;
48 char name[XRT_MAX_SYSTEM_NAME_SIZE];
49 enum xrt_form_factor form_factor;
50};
51
52/*!
53 * A system is a collection of devices, policies and optionally a compositor
54 * that is organised into a chosive group that is usable by one user, most of
55 * the functionality of a system is exposed through other objects, this is the
56 * main object. It is from this you create sessions that is used to by apps to
57 * interact with the "system".
58 *
59 * Sibling objects: @ref xrt_system_devices, @ref xrt_system_compositor and
60 * @ref xrt_space_overseer.
61 *
62 * @ingroup xrt_iface
63 */
65{
66 /*!
67 * Create a @ref xrt_session and optionally a @ref xrt_compositor_native
68 * for this system.
69 *
70 * param[in] xsys Pointer to self.
71 * param[in] xsi Session info.
72 * param[out] out_xs Created session.
73 * param[out] out_xcn Native compositor for this session, optional.
74 */
76 const struct xrt_session_info *xsi,
77 struct xrt_session **out_xs,
78 struct xrt_compositor_native **out_xcn);
79
80 /*!
81 * Destroy the system, must be destroyed after system devices and system
82 * compositor has been destroyed.
83 *
84 * Code consuming this interface should use @ref xrt_system_destroy.
85 *
86 * @param xsys Pointer to self
87 */
88 void (*destroy)(struct xrt_system *xsys);
89
90 struct xrt_system_properties properties;
91};
92
93/*!
94 * @copydoc xrt_system::create_session
95 *
96 * Helper for calling through the function pointer.
97 *
98 * @public @memberof xrt_system
99 */
100static inline xrt_result_t
102 const struct xrt_session_info *xsi,
103 struct xrt_session **out_xs,
104 struct xrt_compositor_native **out_xcn)
105{
106 return xsys->create_session(xsys, xsi, out_xs, out_xcn);
107}
108
109/*!
110 * Destroy an xrt_system - helper function.
111 *
112 * @param[in,out] xsys_ptr A pointer to the xrt_system struct pointer.
113 *
114 * Will destroy the system if `*xsys_ptr` is not NULL. Will then set
115 * `*xsys_ptr` to NULL.
116 *
117 * @public @memberof xrt_system
118 */
119XRT_NONNULL_ALL static inline void
121{
122 struct xrt_system *xsys = *xsys_ptr;
123 if (xsys == NULL) {
124 return;
125 }
126
127 *xsys_ptr = NULL;
128 xsys->destroy(xsys);
129}
130
131
132/*
133 *
134 * System devices.
135 *
136 */
137
138/*!
139 * Data associating a device index (in @ref xrt_system_devices::static_xdevs)
140 * with a given "role" for dynamic role switching.
141 *
142 * For each of the named roles, a negative value means unpopulated/not available.
143 *
144 * Populated by a call from the @ref xrt_system_devices interface.
145 *
146 * When the caller of @ref xrt_system_devices_get_roles sees a change (based on
147 * comparing @ref xrt_system_roles::generation_id) the caller must do the needed
148 * actions to handle device changes. For example, for the OpenXR state tracker
149 * this may include rebinding, queuing a change to the current interaction
150 * profile, and queuing the events associated with such a change.
151 *
152 * @see xrt_system_devices
153 * @ingroup xrt_iface
154 */
156{
157 /*!
158 * Monotonically increasing generation counter for the association
159 * between role and index.
160 *
161 * Increment whenever the roles are changed.
162 *
163 * All valid values are greater then zero; this is to
164 * make init easier where any cache can start at zero and be guaranteed
165 * to be replaced with a new @ref xrt_system_roles.
166 *
167 * alignas for 32 bit client support, see @ref ipc-design
168 */
169 XRT_ALIGNAS(8) uint64_t generation_id;
170
171 /*!
172 * Index in @ref xrt_system_devices::static_xdevs for the user's left
173 * controller/hand, or negative if none available.
174 */
175 int32_t left;
176
177 /*!
178 * Index in @ref xrt_system_devices::static_xdevs for the user's right
179 * controller/hand, or negative if none available.
180 */
181 int32_t right;
182
183 /*!
184 * Index in @ref xrt_system_devices::static_xdevs for the user's gamepad
185 * device, or negative if none available.
186 */
187 int32_t gamepad;
188
189 enum xrt_device_name left_profile;
190
191 enum xrt_device_name right_profile;
192
193 enum xrt_device_name gamepad_profile;
194};
195
196/*!
197 * Guaranteed invalid constant for @ref xrt_system_roles, not using designated
198 * initializers due to C++.
199 *
200 * @ingroup xrt_iface
201 * @relates xrt_system_roles
202 */
203#define XRT_SYSTEM_ROLES_INIT \
204 { \
205 0, -1, -1, -1, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, \
206 }
207
208
209/*!
210 * A collection of @ref xrt_device, and an interface for identifying the roles
211 * they have been assigned.
212 *
213 * @see xrt_device, xrt_instance.
214 */
216{
217 /*!
218 * All devices known in the system.
219 *
220 * This is conventionally considered the "owning" reference to the devices.
221 * Valid entries are contiguous.
222 */
223 struct xrt_device *static_xdevs[XRT_SYSTEM_MAX_DEVICES];
224
225 /*!
226 * The number of elements in @ref static_xdevs that are valid in the
227 * static device list.
228 */
230
231 /*!
232 * Observing pointers for devices in some static (unchangeable) roles.
233 *
234 * All pointers in this struct must also exist in @ref static_xdevs.
235 * The association between a member of this struct and a given device
236 * cannot change during runtime.
237 */
238 struct
239 {
240 /*!
241 * An observing pointer to the device serving as the "head"
242 * (and HMD).
243 *
244 * Required.
245 */
247
248 /*!
249 * An observing pointer to the device providing eye tracking
250 * (optional).
251 */
253
254 /*!
255 * An observing pointer to the device providing face tracking
256 * (optional).
257 */
259
260 /*!
261 * An observing pointer to the device providing body tracking
262 * (optional).
263 */
265
266 /*!
267 * Devices providing optical (or otherwise more directly
268 * measured than from controller estimation) hand tracking.
269 */
270 struct
271 {
272 struct
273 {
274 /*!
275 * An observing pointer to the device providing
276 * unobstructed hand-tracking for the left hand (optional).
277 *
278 * can reference the same xrt_device instance as
279 * @ref hand_tracking::conforming::left, if provides both input types.
280 */
282
283 /*!
284 * An observing pointer to the device providing
285 * unobstructed hand-tracking for the right hand (optional).
286 *
287 * can reference the same xrt_device instance as
288 * @ref hand_tracking::conforming::right, if provides both input types.
289 */
291 } unobstructed;
292
293 struct
294 {
295 /*!
296 * An observing pointer to the device providing
297 * conforming (controller) hand-tracking for the left hand (optional).
298 *
299 * can reference the same xrt_device instance as
300 * @ref hand_tracking::unobstructed::left, if provides both input types.
301 */
302 struct xrt_device *left;
303
304 /*!
305 * An observing pointer to the device providing
306 * conforming (controller) hand-tracking for the right hand (optional).
307 *
308 * can reference the same xrt_device instance as
309 * @ref hand_tracking::unobstructed::right, if provides both input types.
310 */
311 struct xrt_device *right;
312 } conforming;
313 } hand_tracking;
314 } static_roles;
315
316
317 /*!
318 * Function to get the dynamic input device roles from this system
319 * devices, see @ref xrt_system_roles for more information.
320 *
321 * @param xsysd Pointer to self
322 * @param[out] out_roles Pointer to xrt_system_roles
323 */
324 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
325
326 /*!
327 * Create a @ref xrt_body_tracker from this system devices object.
328 *
329 * @param xsysd Pointer to self.
330 * @param info Body-tracker creation info.
331 * @param out_xbt Created body tracker.
332 */
333 xrt_result_t (*create_body_tracker)(struct xrt_system_devices *xsysd,
334 const struct xrt_body_tracker_create_info *info,
335 struct xrt_body_tracker **out_xbt);
336
337 /*!
338 * Create a @ref xrt_hand_tracker from this system devices object.
339 *
340 * @param xsysd Pointer to self.
341 * @param info Hand-tracker creation info.
342 * @param out_xht Created hand tracker.
343 */
344 xrt_result_t (*create_hand_tracker)(struct xrt_system_devices *xsysd,
345 const struct xrt_hand_tracker_create_info *info,
346 struct xrt_hand_tracker **out_xht);
347
348 /*!
349 * Increment the usage count of a feature.
350 * When the feature is used for the first time, then the feature will be begun.
351 *
352 * @param xsysd Pointer to self
353 * @param type Which feature is being counted.
354 */
355 xrt_result_t (*feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
356
357 /*!
358 * Decrement the usage count of a feature.
359 * When the feature is not used by the current application any more, then the feature will be ended.
360 *
361 * @param xsysd Pointer to self
362 * @param type Which feature is being counted.
363 */
364 xrt_result_t (*feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
365
366 /*!
367 * Destroy all the devices that are owned by this system devices.
368 *
369 * Code consuming this interface should use @ref xrt_system_devices_destroy.
370 *
371 * @param xsysd Pointer to self
372 */
373 void (*destroy)(struct xrt_system_devices *xsysd);
374};
375
376/*!
377 * @copydoc xrt_system_devices::get_roles
378 *
379 * Helper for calling through the function pointer.
380 *
381 * @public @memberof xrt_system_devices
382 */
383XRT_NONNULL_ALL static inline xrt_result_t
385{
386 return xsysd->get_roles(xsysd, out_roles);
387}
388
389/*!
390 * @copydoc xrt_system_devices::create_body_tracker
391 *
392 * @public @memberof xrt_system_devices
393 */
394XRT_NONNULL_ALL static inline xrt_result_t
396 const struct xrt_body_tracker_create_info *info,
397 struct xrt_body_tracker **out_xbt)
398{
399 return xsysd->create_body_tracker(xsysd, info, out_xbt);
400}
401
402/*!
403 * @copydoc xrt_system_devices::create_hand_tracker
404 *
405 * @public @memberof xrt_system_devices
406 */
407XRT_NONNULL_ALL static inline xrt_result_t
409 const struct xrt_hand_tracker_create_info *info,
410 struct xrt_hand_tracker **out_xht)
411{
412 return xsysd->create_hand_tracker(xsysd, info, out_xht);
413}
414
415/*!
416 * @copydoc xrt_system_devices::feature_inc
417 *
418 * Helper for calling through the function pointer.
419 *
420 * @public @memberof xrt_system_devices
421 */
422XRT_NONNULL_ALL static inline xrt_result_t
424{
425 return xsysd->feature_inc(xsysd, type);
426}
427
428/*!
429 * @copydoc xrt_system_devices::feature_dec
430 *
431 * Helper for calling through the function pointer.
432 *
433 * @public @memberof xrt_system_devices
434 */
435XRT_NONNULL_ALL static inline xrt_result_t
437{
438 return xsysd->feature_dec(xsysd, type);
439}
440
441/*!
442 * Destroy an xrt_system_devices and owned devices - helper function.
443 *
444 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
445 *
446 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
447 * `*xsysd_ptr` to NULL.
448 *
449 * @public @memberof xrt_system_devices
450 */
451XRT_NONNULL_ALL static inline void
453{
454 struct xrt_system_devices *xsysd = *xsysd_ptr;
455 if (xsysd == NULL) {
456 return;
457 }
458
459 *xsysd_ptr = NULL;
460 xsysd->destroy(xsysd);
461}
462
463
464#ifdef __cplusplus
465}
466#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:2408
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:2290
A single HMD or input device.
Definition xrt_device.h:340
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:121
Session information, mostly overlay extension data.
Definition xrt_compositor.h:978
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition xrt_session.h:264
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:216
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:355
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:324
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:452
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:395
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition xrt_system.h:373
size_t static_xdev_count
The number of elements in static_xdevs that are valid in the static device list.
Definition xrt_system.h:229
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition xrt_system.h:246
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition xrt_system.h:258
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition xrt_system.h:252
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:436
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:364
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:344
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:408
struct xrt_device * left
An observing pointer to the device providing unobstructed hand-tracking for the left hand (optional).
Definition xrt_system.h:281
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:384
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:333
struct xrt_device * right
An observing pointer to the device providing unobstructed hand-tracking for the right hand (optional)...
Definition xrt_system.h:290
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition xrt_system.h:264
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:423
Properties provided by the system.
Definition xrt_system.h:46
Data associating a device index (in xrt_system_devices::static_xdevs) with a given "role" for dynamic...
Definition xrt_system.h:156
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:181
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:187
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:175
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition xrt_system.h:65
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:75
static XRT_NONNULL_ALL void xrt_system_destroy(struct xrt_system **xsys_ptr)
Destroy an xrt_system - helper function.
Definition xrt_system.h:120
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:101
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:88
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:737
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition xrt_device.h:276
Header defining xrt hand tracker.
Header for limits of the XRT interfaces.