Monado OpenXR Runtime
Loading...
Searching...
No Matches
oxr_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 Per-session snapshot wrapper around @ref xrt_io_cache.
6 * @ingroup oxr_main
7 */
8
9#pragma once
10
11#include "xrt/xrt_defines.h"
12#include "xrt/xrt_io_cache.h"
13
14#include "oxr_defines.h"
15#include "oxr_extension_support.h"
17
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
25
26/*!
27 * Per session-action-context snapshot of all device inputs and outputs, wrapping
28 * an @ref xrt_io_cache.
29 *
30 * One of these lives on every @ref oxr_session_action_context. It is the seam
31 * that hides the underlying @ref xrt_device instances from the OpenXR action
32 * code: resolved action bindings (@ref oxr_action_input / @ref oxr_action_output)
33 * point directly into the @ref inputs / @ref outputs arrays here, and those
34 * arrays are refreshed once per xrSyncActions from the backing devices in a
35 * single call.
36 *
37 * The @ref inputs and @ref outputs arrays are owned here and sized to match the
38 * device layout described by @ref info. Because action bindings hold raw
39 * pointers into these arrays, the arrays must not move while bindings are live:
40 * when the device set changes the arrays are reallocated (see
41 * @ref oxr_io_cache_recreate) as an explicit step, bracketed by tearing down and
42 * re-resolving the bindings. The backing @ref xic stays alive across that.
43 */
45{
46 //! Backing cache object that reads from / writes to the devices.
48
49 //! Layout (device table, counts and generation) of the current snapshot.
51
52 //! Snapshot arrays, owned here and sized per @ref info; bindings point into these.
54 struct xrt_output *outputs;
55};
56
57/*!
58 * Create the cache. Call once, when the owning session action context is
59 * created.
60 *
61 * @public @memberof oxr_io_cache
62 */
63XRT_CHECK_RESULT XrResult
64oxr_io_cache_init(struct oxr_io_cache *cache, struct xrt_system_devices *xsysd, struct xrt_space_overseer *xso);
65
66/*!
67 * Destroy the cache. Call once, when the owning session action context is
68 * destroyed.
69 *
70 * @public @memberof oxr_io_cache
71 */
72void
73oxr_io_cache_fini(struct oxr_io_cache *cache);
74
75/*!
76 * Recreate the snapshot for the current device layout: re-query @ref info and
77 * reallocate the @ref inputs / @ref outputs arrays. The backing @ref xic is
78 * kept alive.
79 *
80 * Call this as an explicit step after @ref oxr_io_cache_sync reports the cache
81 * is stale, and only after the action bindings that point into the old arrays
82 * have been torn down; rebind afterwards so bindings point into the new arrays.
83 *
84 * @public @memberof oxr_io_cache
85 */
86XRT_CHECK_RESULT XrResult
87oxr_io_cache_recreate(struct oxr_logger *log, struct oxr_io_cache *cache);
88
89/*!
90 * Refresh the snapshot: read all device inputs and outputs into @ref inputs /
91 * @ref outputs with a single call. Call once per xrSyncActions.
92 *
93 * This never reallocates. If the device layout changed since the arrays were
94 * sized the read cannot be satisfied, @p out_stale is set to true and the
95 * caller must tear down the bindings, @ref oxr_io_cache_recreate, rebind, and
96 * sync again. On a normal refresh @p out_stale is set to false.
97 *
98 * @public @memberof oxr_io_cache
99 */
100XRT_CHECK_RESULT XrResult
101oxr_io_cache_sync(struct oxr_logger *log, struct oxr_io_cache *cache, bool *out_stale);
102
103/*!
104 * Find the layout entry of the device with @p id in the current snapshot,
105 * returns NULL if the device is not part of it.
106 *
107 * @public @memberof oxr_io_cache
108 */
109XRT_NONNULL_ALL const struct xrt_io_cache_device *
110oxr_io_cache_find_device(const struct oxr_io_cache *cache, struct xrt_device_id id);
111
112/*!
113 * The inputs of @p dev in @ref oxr_io_cache::inputs, @p dev must be an entry
114 * in the layout of @p cache.
115 *
116 * @public @memberof oxr_io_cache
117 */
118XRT_NONNULL_ALL static inline struct xrt_input *
119oxr_io_cache_device_inputs(const struct oxr_io_cache *cache, const struct xrt_io_cache_device *dev)
120{
121 return cache->inputs + dev->first_input;
122}
123
124/*!
125 * The outputs of @p dev in @ref oxr_io_cache::outputs, @p dev must be an entry
126 * in the layout of @p cache.
127 *
128 * @public @memberof oxr_io_cache
129 */
130XRT_NONNULL_ALL static inline struct xrt_output *
131oxr_io_cache_device_outputs(const struct oxr_io_cache *cache, const struct xrt_io_cache_device *dev)
132{
133 return cache->outputs + dev->first_output;
134}
135
136/*!
137 * Find the input called @p name on @p dev in the current snapshot. The snapshot
138 * names are primed by @ref oxr_io_cache_recreate, so this works for both
139 * statically-backed devices and cache-only devices (controllers).
140 *
141 * @public @memberof oxr_io_cache
142 */
143XRT_NONNULL_ALL struct xrt_input *
144oxr_io_cache_find_input(const struct oxr_io_cache *cache,
145 const struct xrt_io_cache_device *dev,
146 enum xrt_input_name name);
147
148/*!
149 * Whether @p dev exposes an output called @p name in the current snapshot.
150 *
151 * @public @memberof oxr_io_cache
152 */
153XRT_NONNULL_ALL bool
154oxr_io_cache_has_output(const struct oxr_io_cache *cache,
155 const struct xrt_io_cache_device *dev,
156 enum xrt_output_name name);
157
158
159#ifdef __cplusplus
160}
161#endif
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:952
xrt_output_name
Name of a output with a baked in type.
Definition xrt_defines.h:1636
Shared internal defines and enums in the state tracker.
Forward declarations for OpenXR state tracker structs.
Per session-action-context snapshot of all device inputs and outputs, wrapping an xrt_io_cache.
Definition oxr_io_cache.h:45
struct xrt_input * inputs
Snapshot arrays, owned here and sized per info; bindings point into these.
Definition oxr_io_cache.h:53
struct xrt_io_cache_info info
Layout (device table, counts and generation) of the current snapshot.
Definition oxr_io_cache.h:50
static XRT_NONNULL_ALL struct xrt_input * oxr_io_cache_device_inputs(const struct oxr_io_cache *cache, const struct xrt_io_cache_device *dev)
The inputs of dev in oxr_io_cache::inputs, dev must be an entry in the layout of cache.
Definition oxr_io_cache.h:119
struct xrt_io_cache * xic
Backing cache object that reads from / writes to the devices.
Definition oxr_io_cache.h:47
static XRT_NONNULL_ALL struct xrt_output * oxr_io_cache_device_outputs(const struct oxr_io_cache *cache, const struct xrt_io_cache_device *dev)
The outputs of dev in oxr_io_cache::outputs, dev must be an entry in the layout of cache.
Definition oxr_io_cache.h:131
Logger struct that lives on the stack, one for each call client call.
Definition oxr_logger.h:44
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 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
Snapshot of the cache layout.
Definition xrt_io_cache.h:75
A cache of flattened device inputs and outputs.
Definition xrt_io_cache.h:116
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 collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:218
Common defines and enums for XRT.
Header defining xrt input/output cache.