Monado OpenXR Runtime
Loading...
Searching...
No Matches
xrt_io_cache.h
Go to the documentation of this file.
1// Copyright 2026, NVIDIA CORPORATION.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header defining xrt input/output cache.
6 * @ingroup xrt_iface
7 */
8
9#pragma once
10
11#include "xrt/xrt_defines.h"
12#include "xrt/xrt_results.h"
13#include "xrt/xrt_device.h"
14#include "xrt/xrt_limits.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21struct xrt_space;
23
24/*!
25 * Per-device layout entry describing where a device's inputs and outputs
26 * sit in the flattened cache arrays.
27 *
28 * @ingroup xrt_iface
29 */
31{
32 //! Unique identifier for this device.
34
35 //! Human-readable device name string.
36 XRT_ALIGNAS(8) char str[XRT_DEVICE_NAME_LEN];
37
38 //! Device name enum.
39 enum xrt_device_name name;
40
41 //! Index of this device's first input in the flattened input array.
42 uint32_t first_input;
43
44 //! Number of inputs contributed by this device.
45 uint32_t input_count;
46
47 //! Index of this device's first output in the flattened output array.
48 uint32_t first_output;
49
50 //! Number of outputs contributed by this device.
51 uint32_t output_count;
52};
53
54/*!
55 * Snapshot of the cache layout. Returned by @ref xrt_io_cache::get_info.
56 *
57 * @ref generation_id must be passed to @ref xrt_io_cache::read together with
58 * @ref input_count and @ref output_count. If the generation no longer matches the
59 * live cache layout, @ref xrt_io_cache::read sets @p out_stale to true and returns
60 * @ref XRT_SUCCESS without writing the arrays.
61 *
62 * The @ref head, @ref eyes, @ref left, @ref right and @ref gamepad fields
63 * describe the current role assignment as indices into @ref devices (mirroring
64 * how @ref xrt_system_roles indexes into @ref xrt_system_devices::static_xdevs).
65 * They let a consumer resolve interaction profiles for the top-level user paths
66 * without touching any @ref xrt_device. The controller roles (left, right,
67 * gamepad) are dynamic; the head and eyes roles are static but duplicated here
68 * for convenience so that a consumer can resolve every top-level path purely
69 * from the cache. A change to a dynamic role assignment also bumps
70 * @ref generation_id.
71 *
72 * @ingroup xrt_iface
73 */
75{
76 /*!
77 * Monotonically increasing layout generation; changes when devices,
78 * their input/output counts, or the role assignment below change.
79 */
80 uint64_t generation_id;
81
82 //! Per-device layout entries.
84
85 //! Number of entries in @ref devices that are valid.
86 XRT_ALIGNAS(8) uint32_t device_count;
87
88 //! Total number of inputs across all devices.
89 uint32_t input_count;
90
91 //! Total number of outputs across all devices.
92 uint32_t output_count;
93
94 //! Index into @ref devices for the user's head device, or -1 if none.
95 int32_t head;
96
97 //! Index into @ref devices for the user's eye tracker, or -1 if none.
98 int32_t eyes;
99
100 //! Index into @ref devices for the user's left controller, or -1 if none.
101 int32_t left;
102
103 //! Index into @ref devices for the user's right controller, or -1 if none.
104 int32_t right;
105
106 //! Index into @ref devices for the user's gamepad, or -1 if none.
107 int32_t gamepad;
108};
109
110/*!
111 * A cache of flattened device inputs and outputs.
112 *
113 * @ingroup xrt_iface
114 */
116{
117 /*!
118 * Query the current cache layout.
119 *
120 * @param xic Pointer to self.
121 * @param out_info Resulting layout snapshot.
122 */
123 xrt_result_t (*get_info)(struct xrt_io_cache *xic, struct xrt_io_cache_info *out_info);
124
125 /*!
126 * Read the current input and output values into caller-provided arrays.
127 *
128 * @param xic Pointer to self.
129 * @param generation_id Layout generation from the most recent @ref get_info call.
130 * @param input_count Capacity of @p inputs; must match the layout snapshot.
131 * @param inputs Output array for input values.
132 * @param output_count Capacity of @p outputs; must match the layout snapshot.
133 * @param outputs Output array for output metadata.
134 * @param out_stale Set to true when @p generation_id no longer matches the
135 * live layout; the arrays are not written in that case.
136 *
137 * @returns @ref XRT_ERROR_INVALID_ARGUMENT if @p input_count or @p output_count
138 * do not match the current layout while the generation still matches.
139 */
140 xrt_result_t (*read)(struct xrt_io_cache *xic,
141 uint64_t generation_id,
142 uint32_t input_count,
143 struct xrt_input *inputs,
144 uint32_t output_count,
145 struct xrt_output *outputs,
146 bool *out_stale);
147
148 /*!
149 * Create a space for an input on a specific device.
150 *
151 * @param xic Pointer to self.
152 * @param id Device to create the space on.
153 * @param name Input name to bind the space to.
154 * @param out_space Created space.
155 */
157 struct xrt_device_id id,
158 enum xrt_input_name name,
159 struct xrt_space **out_space);
160
161 /*!
162 * Set an output value on a specific device.
163 *
164 * @param xic Pointer to self.
165 * @param id Device to set the output on.
166 * @param name Output name.
167 * @param value Value to write.
168 */
169 xrt_result_t (*set_output)(struct xrt_io_cache *xic,
170 struct xrt_device_id id,
171 enum xrt_output_name name,
172 const struct xrt_output_value *value);
173
174 /*!
175 * Query the (device-wide) output limits for a device.
176 *
177 * @param xic Pointer to self.
178 * @param id Device to query.
179 * @param out_limits Resulting limits.
180 */
181 xrt_result_t (*get_output_limits)(struct xrt_io_cache *xic,
182 struct xrt_device_id id,
183 struct xrt_output_limits *out_limits);
184
185 /*!
186 * Destroy this cache.
187 *
188 * Code consuming this interface should use @ref xrt_io_cache_destroy.
189 */
190 void (*destroy)(struct xrt_io_cache *xic);
191};
192
193/*!
194 * @copydoc xrt_io_cache::get_info
195 *
196 * @public @memberof xrt_io_cache
197 */
198XRT_NONNULL_ALL static inline xrt_result_t
200{
201 return xic->get_info(xic, out_info);
202}
203
204/*!
205 * @copydoc xrt_io_cache::read
206 *
207 * @public @memberof xrt_io_cache
208 */
209static inline xrt_result_t
211 uint64_t generation_id,
212 uint32_t input_count,
213 struct xrt_input *inputs,
214 uint32_t output_count,
215 struct xrt_output *outputs,
216 bool *out_stale)
217{
218 return xic->read(xic, generation_id, input_count, inputs, output_count, outputs, out_stale);
219}
220
221/*!
222 * @copydoc xrt_io_cache::create_space
223 *
224 * @public @memberof xrt_io_cache
225 */
226XRT_NONNULL_ALL static inline xrt_result_t
228 struct xrt_device_id id,
229 enum xrt_input_name name,
230 struct xrt_space **out_space)
231{
232 return xic->create_space(xic, id, name, out_space);
233}
234
235/*!
236 * @copydoc xrt_io_cache::set_output
237 *
238 * @public @memberof xrt_io_cache
239 */
240XRT_NONNULL_ALL static inline xrt_result_t
242 struct xrt_device_id id,
243 enum xrt_output_name name,
244 const struct xrt_output_value *value)
245{
246 return xic->set_output(xic, id, name, value);
247}
248
249/*!
250 * @copydoc xrt_io_cache::get_output_limits
251 *
252 * @public @memberof xrt_io_cache
253 */
254XRT_NONNULL_ALL static inline xrt_result_t
256{
257 return xic->get_output_limits(xic, id, out_limits);
258}
259
260/*!
261 * Destroy an xrt_io_cache - helper function.
262 *
263 * @param[in,out] xic_ptr A pointer to the xrt_io_cache struct pointer.
264 *
265 * Will destroy the cache if `*xic_ptr` is not NULL. Will then set
266 * `*xic_ptr` to NULL.
267 *
268 * @public @memberof xrt_io_cache
269 */
270XRT_NONNULL_ALL static inline void
272{
273 struct xrt_io_cache *xic = *xic_ptr;
274 if (xic == NULL) {
275 return;
276 }
277
278 *xic_ptr = NULL;
279 xic->destroy(xic);
280}
281
282#ifdef __cplusplus
283}
284#endif
static struct u_space * create_space(enum u_space_type type, struct u_space *parent)
Creates a space, returns with a reference of one.
Definition b_space_overseer.c:539
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition xrt_limits.h:26
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:952
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_output_name
Name of a output with a baked in type.
Definition xrt_defines.h:1636
static struct device_info get_info(ohmd_device *dev, const char *prod)
Definition oh_device.c:536
A unique identifier for an xrt_device instance.
Definition xrt_device.h:47
A single named input, that sits on a xrt_device.
Definition xrt_device.h:236
Per-device layout entry describing where a device's inputs and outputs sit in the flattened cache arr...
Definition xrt_io_cache.h:31
uint32_t input_count
Number of inputs contributed by this device.
Definition xrt_io_cache.h:45
XRT_ALIGNAS(8) char str[XRT_DEVICE_NAME_LEN]
Human-readable device name string.
uint32_t first_input
Index of this device's first input in the flattened input array.
Definition xrt_io_cache.h:42
uint32_t first_output
Index of this device's first output in the flattened output array.
Definition xrt_io_cache.h:48
struct xrt_device_id id
Unique identifier for this device.
Definition xrt_io_cache.h:33
uint32_t output_count
Number of outputs contributed by this device.
Definition xrt_io_cache.h:51
Snapshot of the cache layout.
Definition xrt_io_cache.h:75
XRT_ALIGNAS(8) uint32_t device_count
Number of entries in devices that are valid.
uint64_t generation_id
Monotonically increasing layout generation; changes when devices, their input/output counts,...
Definition xrt_io_cache.h:80
A cache of flattened device inputs and outputs.
Definition xrt_io_cache.h:116
xrt_result_t(* get_output_limits)(struct xrt_io_cache *xic, struct xrt_device_id id, struct xrt_output_limits *out_limits)
Query the (device-wide) output limits for a device.
Definition xrt_io_cache.h:181
xrt_result_t(* create_space)(struct xrt_io_cache *xic, struct xrt_device_id id, enum xrt_input_name name, struct xrt_space **out_space)
Create a space for an input on a specific device.
Definition xrt_io_cache.h:156
void(* destroy)(struct xrt_io_cache *xic)
Destroy this cache.
Definition xrt_io_cache.h:190
xrt_result_t(* get_info)(struct xrt_io_cache *xic, struct xrt_io_cache_info *out_info)
Query the current cache layout.
Definition xrt_io_cache.h:123
static XRT_NONNULL_ALL xrt_result_t xrt_io_cache_get_info(struct xrt_io_cache *xic, struct xrt_io_cache_info *out_info)
Query the current cache layout.
Definition xrt_io_cache.h:199
static xrt_result_t xrt_io_cache_read(struct xrt_io_cache *xic, uint64_t generation_id, uint32_t input_count, struct xrt_input *inputs, uint32_t output_count, struct xrt_output *outputs, bool *out_stale)
Read the current input and output values into caller-provided arrays.
Definition xrt_io_cache.h:210
static XRT_NONNULL_ALL void xrt_io_cache_destroy(struct xrt_io_cache **xic_ptr)
Destroy an xrt_io_cache - helper function.
Definition xrt_io_cache.h:271
static XRT_NONNULL_ALL xrt_result_t xrt_io_cache_create_space(struct xrt_io_cache *xic, struct xrt_device_id id, enum xrt_input_name name, struct xrt_space **out_space)
Create a space for an input on a specific device.
Definition xrt_io_cache.h:227
static XRT_NONNULL_ALL xrt_result_t xrt_io_cache_get_output_limits(struct xrt_io_cache *xic, struct xrt_device_id id, struct xrt_output_limits *out_limits)
Query the (device-wide) output limits for a device.
Definition xrt_io_cache.h:255
static XRT_NONNULL_ALL xrt_result_t xrt_io_cache_set_output(struct xrt_io_cache *xic, struct xrt_device_id id, enum xrt_output_name name, const struct xrt_output_value *value)
Set an output value on a specific device.
Definition xrt_io_cache.h:241
xrt_result_t(* read)(struct xrt_io_cache *xic, uint64_t generation_id, uint32_t input_count, struct xrt_input *inputs, uint32_t output_count, struct xrt_output *outputs, bool *out_stale)
Read the current input and output values into caller-provided arrays.
Definition xrt_io_cache.h:140
xrt_result_t(* set_output)(struct xrt_io_cache *xic, struct xrt_device_id id, enum xrt_output_name name, const struct xrt_output_value *value)
Set an output value on a specific device.
Definition xrt_io_cache.h:169
Output limits of a particular device.
Definition xrt_device.h:314
A union of all output types.
Definition xrt_defines.h:2413
A single named output, that sits on a xrt_device.
Definition xrt_device.h:254
Object that oversees and manages spaces, one created for each XR system.
Definition xrt_space.h:97
A space very similar to a OpenXR XrSpace but not a full one-to-one mapping, but used to power XrSpace...
Definition xrt_space.h:32
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:758
Header defining an xrt display or controller device.
Header for limits of the XRT interfaces.
Internal result type for XRT.