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