Monado OpenXR Runtime
xrt_system.h
Go to the documentation of this file.
1// Copyright 2020-2024, Collabora, Ltd.
2// Copyright 2023, 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
18#include <stdalign.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};
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 */
117static 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 * Maximum number of devices simultaneously usable by an implementation of
138 * @ref xrt_system_devices
139 *
140 * @ingroup xrt_iface
141 */
142#define XRT_SYSTEM_MAX_DEVICES (32)
143
144/*!
145 * Data associating a device index (in @ref xrt_system_devices::xdevs) with a
146 * given "role" for dynamic role switching.
147 *
148 * For each of the named roles, a negative value means unpopulated/not available.
149 *
150 * Populated by a call from the @ref xrt_system_devices interface.
151 *
152 * When the caller of @ref xrt_system_devices_get_roles sees a change (based on
153 * comparing @ref generation_id) the caller must do the needed actions to handle
154 * device changes. For example, for the OpenXR state tracker this may include
155 * rebinding, queuing a change to the current interaction profile, and queuing
156 * the events associated with such a change.
157 *
158 * @see xrt_system_devices
159 * @ingroup xrt_iface
160 */
162{
163 /*!
164 * Monotonically increasing generation counter for the association
165 * between role and index.
166 *
167 * Increment whenever the roles are changed.
168 *
169 * All valid values are greater then zero; this is to
170 * make init easier where any cache can start at zero and be guaranteed
171 * to be replaced with a new @ref xrt_system_roles.
172 *
173 * alignas for 32 bit client support, see @ref ipc-design
174 */
175 alignas(8) uint64_t generation_id;
176
177 /*!
178 * Index in @ref xrt_system_devices::xdevs for the user's left
179 * controller/hand, or negative if none available.
180 */
181 int32_t left;
182
183 /*!
184 * Index in @ref xrt_system_devices::xdevs for the user's right
185 * controller/hand, or negative if none available.
186 */
187 int32_t right;
188
189 /*!
190 * Index in @ref xrt_system_devices::xdevs for the user's gamepad
191 * device, or negative if none available.
192 */
193 int32_t gamepad;
194
195 enum xrt_device_name left_profile;
196
197 enum xrt_device_name right_profile;
198
199 enum xrt_device_name gamepad_profile;
200};
201
202/*!
203 * Guaranteed invalid constant for @ref xrt_system_roles, not using designated
204 * initializers due to C++.
205 *
206 * @ingroup xrt_iface
207 * @relates xrt_system_roles
208 */
209#define XRT_SYSTEM_ROLES_INIT \
210 { \
211 0, -1, -1, -1, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, XRT_DEVICE_INVALID, \
212 }
213
214
215/*!
216 * A collection of @ref xrt_device, and an interface for identifying the roles
217 * they have been assigned.
218 *
219 * @see xrt_device, xrt_instance.
220 */
222{
223 /*!
224 * All devices known in the system.
225 *
226 * This is conventionally considered the "owning" reference to the devices.
227 * Valid entries are contiguous.
228 */
230
231 /*!
232 * The number of elements in @ref xdevs that are valid.
233 */
235
236 /*!
237 * Observing pointers for devices in some static (unchangeable) roles.
238 *
239 * All pointers in this struct must also exist in @ref xdevs. The
240 * association between a member of this struct and a given device
241 * cannot change during runtime.
242 */
243 struct
244 {
245 /*!
246 * An observing pointer to the device serving as the "head"
247 * (and HMD).
248 *
249 * Required.
250 */
252
253 /*!
254 * An observing pointer to the device providing eye tracking
255 * (optional).
256 */
258
259 /*!
260 * An observing pointer to the device providing face tracking
261 * (optional).
262 */
264
265 /*!
266 * An observing pointer to the device providing body tracking
267 * (optional).
268 */
270
271 /*!
272 * Devices providing optical (or otherwise more directly
273 * measured than from controller estimation) hand tracking.
274 */
275 struct
276 {
277
278 /*!
279 * An observing pointer to the device providing hand
280 * tracking for the left hand (optional).
281 *
282 * Currently this is used for both optical and
283 * controller driven hand-tracking.
284 */
286
287 /*!
288 * An observing pointer to the device providing hand
289 * tracking for the right hand (optional).
290 *
291 * Currently this is used for both optical and
292 * controller driven hand-tracking.
293 */
297
298
299 /*!
300 * Function to get the dynamic input device roles from this system
301 * devices, see @ref xrt_system_roles for more information.
302 *
303 * @param xsysd Pointer to self
304 * @param[out] out_roles Pointer to xrt_system_roles
305 */
306 xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
307
308 /*!
309 * Increment the usage count of a feature.
310 * When the feature is used for the first time, then the feature will be begun.
311 *
312 * @param xsysd Pointer to self
313 * @param type Which feature is being counted.
314 */
316
317 /*!
318 * Decrement the usage count of a feature.
319 * When the feature is not used by the current application any more, then the feature will be ended.
320 *
321 * @param xsysd Pointer to self
322 * @param type Which feature is being counted.
323 */
325
326 /*!
327 * Destroy all the devices that are owned by this system devices.
328 *
329 * Code consuming this interface should use @ref xrt_system_devices_destroy.
330 *
331 * @param xsysd Pointer to self
332 */
333 void (*destroy)(struct xrt_system_devices *xsysd);
334};
335
336/*!
337 * @copydoc xrt_system_devices::get_roles
338 *
339 * Helper for calling through the function pointer.
340 *
341 * @public @memberof xrt_system_devices
342 */
343static inline xrt_result_t
345{
346 return xsysd->get_roles(xsysd, out_roles);
347}
348
349/*!
350 * @copydoc xrt_system_devices::feature_inc
351 *
352 * Helper for calling through the function pointer.
353 *
354 * @public @memberof xrt_system_devices
355 */
356static inline xrt_result_t
358{
359 return xsysd->feature_inc(xsysd, type);
360}
361
362/*!
363 * @copydoc xrt_system_devices::feature_dec
364 *
365 * Helper for calling through the function pointer.
366 *
367 * @public @memberof xrt_system_devices
368 */
369static inline xrt_result_t
371{
372 return xsysd->feature_dec(xsysd, type);
373}
374
375/*!
376 * Destroy an xrt_system_devices and owned devices - helper function.
377 *
378 * @param[in,out] xsysd_ptr A pointer to the xrt_system_devices struct pointer.
379 *
380 * Will destroy the system devices if `*xsysd_ptr` is not NULL. Will then set
381 * `*xsysd_ptr` to NULL.
382 *
383 * @public @memberof xrt_system_devices
384 */
385static inline void
387{
388 struct xrt_system_devices *xsysd = *xsysd_ptr;
389 if (xsysd == NULL) {
390 return;
391 }
392
393 *xsysd_ptr = NULL;
394 xsysd->destroy(xsysd);
395}
396
397
398#ifdef __cplusplus
399}
400#endif
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition: xrt_system.h:142
enum xrt_result xrt_result_t
Result type used across Monado.
Main compositor server interface.
Definition: xrt_compositor.h:2233
A single HMD or input device.
Definition: xrt_device.h:244
This interface acts as a root object for Monado.
Definition: xrt_instance.h:114
Session information, mostly overlay extension data.
Definition: xrt_compositor.h:935
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:246
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition: xrt_system.h:222
static 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:357
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:315
size_t xdev_count
The number of elements in xdevs that are valid.
Definition: xrt_system.h:234
static 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:344
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:306
static 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:370
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition: xrt_system.h:333
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition: xrt_system.h:251
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition: xrt_system.h:263
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition: xrt_system.h:257
struct xrt_device * xdevs[(32)]
All devices known in the system.
Definition: xrt_system.h:229
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:324
struct xrt_device * left
An observing pointer to the device providing hand tracking for the left hand (optional).
Definition: xrt_system.h:285
struct xrt_system_devices::@239 static_roles
Observing pointers for devices in some static (unchangeable) roles.
struct xrt_system_devices::@239::@240 hand_tracking
Devices providing optical (or otherwise more directly measured than from controller estimation) hand ...
struct xrt_device * right
An observing pointer to the device providing hand tracking for the right hand (optional).
Definition: xrt_system.h:294
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition: xrt_system.h:269
static 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:386
Properties provided by the system.
Definition: xrt_system.h:45
Data associating a device index (in xrt_system_devices::xdevs) with a given "role" for dynamic role s...
Definition: xrt_system.h:162
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:187
uint64_t generation_id
Monotonically increasing generation counter for the association between role and index.
Definition: xrt_system.h:175
int32_t gamepad
Index in xrt_system_devices::xdevs for the user's gamepad device, or negative if none available.
Definition: xrt_system.h:193
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:181
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_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
static void xrt_system_destroy(struct xrt_system **xsys_ptr)
Destroy an xrt_system - helper function.
Definition: xrt_system.h:118
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:712
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition: xrt_device.h:229