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"
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::static_xdevs)
138 * with a 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::static_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::static_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::static_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 */
221 struct xrt_device *static_xdevs[XRT_SYSTEM_MAX_DEVICES];
222
223 /*!
224 * The number of elements in @ref static_xdevs that are valid in the
225 * static device list.
226 */
228
229 /*!
230 * Observing pointers for devices in some static (unchangeable) roles.
231 *
232 * All pointers in this struct must also exist in @ref static_xdevs.
233 * The association between a member of this struct and a given device
234 * cannot change during runtime.
235 */
236 struct
237 {
238 /*!
239 * An observing pointer to the device serving as the "head"
240 * (and HMD).
241 *
242 * Required.
243 */
245
246 /*!
247 * An observing pointer to the device providing eye tracking
248 * (optional).
249 */
251
252 /*!
253 * An observing pointer to the device providing face tracking
254 * (optional).
255 */
257
258 /*!
259 * An observing pointer to the device providing body tracking
260 * (optional).
261 */
263
264 /*!
265 * Devices providing optical (or otherwise more directly
266 * measured than from controller estimation) hand tracking.
267 */
268 struct
269 {
270 struct
271 {
272 /*!
273 * An observing pointer to the device providing
274 * unobstructed hand-tracking for the left hand (optional).
275 *
276 * can reference the same xrt_device instance as
277 * @ref hand_tracking::conforming::left, if provides both input types.
278 */
280
281 /*!
282 * An observing pointer to the device providing
283 * unobstructed hand-tracking for the right hand (optional).
284 *
285 * can reference the same xrt_device instance as
286 * @ref hand_tracking::conforming::right, if provides both input types.
287 */
289 } unobstructed;
290
291 struct
292 {
293 /*!
294 * An observing pointer to the device providing
295 * conforming (controller) hand-tracking for the left hand (optional).
296 *
297 * can reference the same xrt_device instance as
298 * @ref hand_tracking::unobstructed::left, if provides both input types.
299 */
300 struct xrt_device *left;
301
302 /*!
303 * An observing pointer to the device providing
304 * conforming (controller) hand-tracking for the right hand (optional).
305 *
306 * can reference the same xrt_device instance as
307 * @ref hand_tracking::unobstructed::right, if provides both input types.
308 */
309 struct xrt_device *right;
310 } conforming;
311 } hand_tracking;
312 } static_roles;
313
314
315 /*!
316 * Function to get the dynamic input device roles from this system
317 * devices, see @ref xrt_system_roles for more information.
318 *
319 * @param xsysd Pointer to self
320 * @param[out] out_roles Pointer to xrt_system_roles
321 */
322 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
323
324 /*!
325 * Increment the usage count of a feature.
326 * When the feature is used for the first time, then the feature will be begun.
327 *
328 * @param xsysd Pointer to self
329 * @param type Which feature is being counted.
330 */
331 xrt_result_t (*feature_inc)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
332
333 /*!
334 * Decrement the usage count of a feature.
335 * When the feature is not used by the current application any more, then the feature will be ended.
336 *
337 * @param xsysd Pointer to self
338 * @param type Which feature is being counted.
339 */
340 xrt_result_t (*feature_dec)(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type);
341
342 /*!
343 * Destroy all the devices that are owned by this system devices.
344 *
345 * Code consuming this interface should use @ref xrt_system_devices_destroy.
346 *
347 * @param xsysd Pointer to self
348 */
349 void (*destroy)(struct xrt_system_devices *xsysd);
350};
351
352/*!
353 * @copydoc xrt_system_devices::get_roles
354 *
355 * Helper for calling through the function pointer.
356 *
357 * @public @memberof xrt_system_devices
358 */
359XRT_NONNULL_ALL static inline xrt_result_t
361{
362 return xsysd->get_roles(xsysd, out_roles);
363}
364
365/*!
366 * @copydoc xrt_system_devices::feature_inc
367 *
368 * Helper for calling through the function pointer.
369 *
370 * @public @memberof xrt_system_devices
371 */
372XRT_NONNULL_ALL static inline xrt_result_t
374{
375 return xsysd->feature_inc(xsysd, type);
376}
377
378/*!
379 * @copydoc xrt_system_devices::feature_dec
380 *
381 * Helper for calling through the function pointer.
382 *
383 * @public @memberof xrt_system_devices
384 */
385XRT_NONNULL_ALL static inline xrt_result_t
387{
388 return xsysd->feature_dec(xsysd, type);
389}
390
391/*!
392 * Destroy an xrt_system_devices and owned devices - helper function.
393 *
394 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
395 *
396 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
397 * `*xsysd_ptr` to NULL.
398 *
399 * @public @memberof xrt_system_devices
400 */
401XRT_NONNULL_ALL static inline void
403{
404 struct xrt_system_devices *xsysd = *xsysd_ptr;
405 if (xsysd == NULL) {
406 return;
407 }
408
409 *xsysd_ptr = NULL;
410 xsysd->destroy(xsysd);
411}
412
413
414#ifdef __cplusplus
415}
416#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:2398
enum xrt_result xrt_result_t
Result type used across Monado.
Main compositor server interface.
Definition xrt_compositor.h:2260
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:949
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:331
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:322
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:402
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition xrt_system.h:349
size_t static_xdev_count
The number of elements in static_xdevs that are valid in the static device list.
Definition xrt_system.h:227
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition xrt_system.h:244
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition xrt_system.h:256
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition xrt_system.h:250
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:386
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:340
struct xrt_device * left
An observing pointer to the device providing unobstructed hand-tracking for the left hand (optional).
Definition xrt_system.h:279
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:360
struct xrt_device * right
An observing pointer to the device providing unobstructed hand-tracking for the right hand (optional)...
Definition xrt_system.h:288
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition xrt_system.h:262
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:373
Properties provided by the system.
Definition xrt_system.h:44
Data associating a device index (in xrt_system_devices::static_xdevs) with a given "role" for dynamic...
Definition xrt_system.h:154
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: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::static_xdevs for the user's gamepad device, or negative if none availabl...
Definition xrt_system.h:185
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: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:737
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.