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