Monado OpenXR Runtime
Loading...
Searching...
No Matches
ipc_protocol.h
Go to the documentation of this file.
1// Copyright 2020-2024 Collabora, Ltd.
2// Copyright 2025-2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Common protocol definition.
7 * @author Pete Black <pblack@collabora.com>
8 * @author Jakob Bornecrantz <jakob@collabora.com>
9 * @author Korcan Hussein <korcan.hussein@collabora.com>
10 * @ingroup ipc_shared
11 */
12
13#pragma once
14
15#include "xrt/xrt_limits.h"
16#include "xrt/xrt_compiler.h"
17#include "xrt/xrt_compositor.h"
18#include "xrt/xrt_results.h"
19#include "xrt/xrt_defines.h"
20#include "xrt/xrt_future.h"
21#include "xrt/xrt_system.h"
22#include "xrt/xrt_session.h"
23#include "xrt/xrt_instance.h"
24#include "xrt/xrt_compositor.h"
25#include "xrt/xrt_device.h"
26#include "xrt/xrt_space.h"
27#include "xrt/xrt_tracking.h"
28#include "xrt/xrt_config_build.h"
29
30#include <assert.h>
31#include <sys/types.h>
32
33
34#define IPC_CRED_SIZE 1 // auth not implemented
35#define IPC_BUF_SIZE 2048 // must be >= largest message length in bytes
36#define IPC_MAX_VIEWS 8 // max views we will return configs for
37#define IPC_MAX_FORMATS 32 // max formats our server-side compositor supports
38#define IPC_MAX_DEVICES 8 // max number of devices we will map using shared mem
39#define IPC_MAX_LAYERS XRT_MAX_LAYERS
40#define IPC_MAX_SLOTS 128
41#define IPC_MAX_CLIENTS 32
42#define IPC_MAX_RAW_VIEWS 32 // Max views that we can get, artificial limit.
43#define IPC_EVENT_QUEUE_SIZE 32
44
45
46// example: v21.0.0-560-g586d33b5
47#define IPC_VERSION_NAME_LEN 64
48
49#if defined(XRT_OS_WINDOWS) && !defined(XRT_ENV_MINGW)
50typedef int pid_t;
51#endif
52
53// Define the format to use to print a pid type
54#if defined(XRT_ENV_MINGW)
55// On Mingw64, this is an int64, aka a signed long long
56#define PID_T_FMT "%lli"
57#else
58// On Linux and 'native' Windows, this is an int
59#define PID_T_FMT "%d"
60#endif
61
62/*
63 *
64 * Shared memory structs.
65 *
66 */
67
68/*!
69 * Information about a device in the device list.
70 *
71 * @ingroup ipc
72 */
74{
75 //! Tracking origin ID
76 uint32_t id;
77};
78
79/*!
80 * A list of the current tracking origins.
81 *
82 * @ingroup ipc
83 */
85{
86 //! Number of tracking origins.
87 uint32_t origin_count;
88
89 //! Compact list of tracking origins.
91};
92
93/*!
94 * A tracking in the shared memory area.
95 *
96 * @ingroup ipc
97 */
99{
100 //! For debugging.
101 char name[XRT_TRACKING_NAME_LEN];
102
103 //! What can the state tracker expect from this tracking system.
105
106 //! Initial offset of the tracking origin.
108};
109
110/*!
111 * Information about a device in the device list.
112 *
113 * @ingroup ipc
114 */
116{
117 //! Device ID
118 uint32_t id;
119
120 //! Device type
122};
123
124/*!
125 * List of devices available on the server.
126 *
127 * @ingroup ipc
128 */
130{
131 //! Number of devices
132 uint32_t device_count;
133
134 //! Device entries
136};
137
138/*!
139 * Device information sent over IPC.
140 *
141 * Followed by varlen data containing:
142 * - An array of input_count * enum xrt_input_name
143 * - An array of output_count * enum xrt_output_name
144 * - An array of binding_profile_count * struct ipc_binding_profile_info
145 * - An array of total_input_pair_count * struct xrt_binding_input_pair
146 * - An array of total_output_pair_count * struct xrt_binding_output_pair
147 *
148 * @ingroup ipc
149 */
151{
152 //! Enum identifier of the device.
154 enum xrt_device_type device_type;
155
156 /*!
157 * The service-side @ref xrt_device_id, synchronized to IPC clients so that
158 * @ref xrt_device::id matches across all clients connected to the same
159 * service. This is distinct from the per-client-connection @c uint32_t
160 * slot index used to look up devices in IPC messages.
161 */
163
164 //! Which tracking system origin is this device attached to.
165 XRT_ALIGNAS(8) uint32_t tracking_origin_id;
166
167 //! A string describing the device.
168 char str[XRT_DEVICE_NAME_LEN];
169
170 //! A unique identifier. Persistent across configurations, if possible.
171 char serial[XRT_DEVICE_NAME_LEN];
172
173 //! Number of binding profiles in varlen data.
175
176 //! Total number of input pairs in varlen data (across all binding profiles).
178
179 //! Total number of output pairs in varlen data (across all binding profiles).
181
182 //! Number of inputs.
183 uint32_t input_count;
184
185 //! Number of outputs.
186 uint32_t output_count;
187
188 //! The supported fields.
190};
191
192/*!
193 * A binding in the shared memory area.
194 *
195 * @ingroup ipc
196 */
198{
200
201 //! Offset into the array of pairs where this input bindings starts.
203 //! Number of inputs.
204 uint32_t input_count;
205
206 //! Offset into the array of pairs where this output bindings starts.
208 //! Number of outputs.
209 uint32_t output_count;
210};
211
212/*!
213 * Data for a single composition layer.
214 *
215 * Similar in function to @ref comp_layer
216 *
217 * @ingroup ipc
218 */
220{
221 //! @todo what is this used for?
222 uint32_t xdev_id;
223
224 /*!
225 * Up to two indices of swapchains to use.
226 *
227 * How many are actually used depends on the value of @p data.type
228 */
229 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
230
231 /*!
232 * All basic (trivially-serializable) data associated with a layer,
233 * aside from which swapchain(s) are used.
234 */
235 struct xrt_layer_data data;
236};
237
238/*!
239 * Render state for a single client, including all layers.
240 *
241 * @ingroup ipc
242 */
244{
245 struct xrt_layer_frame_data data;
246 uint32_t layer_count;
247 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
248};
249
250/*!
251 * A big struct that contains all data that is shared to a client, no pointers
252 * allowed in this. To get the inputs of a device you go:
253 *
254 * ```C++
255 * struct xrt_input *
256 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
257 * {
258 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
259 * return &ism->inputs[index];
260 * }
261 * ```
262 *
263 * @ingroup ipc
264 */
266{
267 /*!
268 * The git revision of the service, used by clients to detect version mismatches.
269 */
270 char u_git_tag[IPC_VERSION_NAME_LEN];
271
272 /*!
273 * Various roles for the devices.
274 */
275 struct
276 {
277 int32_t head;
278 int32_t eyes;
279 int32_t face;
280 int32_t body;
281
282 struct
283 {
284 struct
285 {
286 int32_t left;
287 int32_t right;
288 } unobstructed;
289
290 struct
291 {
292 int32_t left;
293 int32_t right;
294 } conforming;
295 } hand_tracking;
296 } roles;
297
298 struct
299 {
300 struct
301 {
302 /*!
303 * Pixel properties of this display, not in absolute
304 * screen coordinates that the compositor sees. So
305 * before any rotation is applied by xrt_view::rot.
306 *
307 * The xrt_view::display::w_pixels &
308 * xrt_view::display::h_pixels become the recommended
309 * image size for this view.
310 *
311 * @todo doesn't account for overfill for timewarp or
312 * distortion?
313 */
314 struct
315 {
316 uint32_t w_pixels;
317 uint32_t h_pixels;
318 } display;
319 } views[2];
320 // view count
321 uint32_t view_count;
322 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
323 uint32_t blend_mode_count;
324 } hmd;
325
326 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
327
328 uint64_t startup_timestamp;
329 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext;
330};
331
332/*!
333 * Pointer-free arguments for creating an @ref xrt_hand_tracker over IPC.
334 */
336{
337 enum xrt_hand hand;
338 enum xrt_input_name requested_sources[2];
339 uint32_t requested_source_count;
340 bool has_locked_xdev;
341 uint32_t locked_xdev_id;
342};
343
344/*!
345 * Initial info from a client when it connects.
346 */
348{
349 pid_t pid;
350 struct xrt_application_info info;
351};
352
354{
355 uint32_t ids[IPC_MAX_CLIENTS];
356 uint32_t id_count;
357};
358
359/*!
360 * Which types of IO to block for a client.
361 *
362 * @ingroup ipc
363 */
365{
366 bool block_poses;
367 bool block_hand_tracking;
368 bool block_inputs;
369 bool block_outputs;
370};
371
372/*!
373 * State for a connected application.
374 *
375 * @ingroup ipc
376 */
378{
379 // Stable and unique ID of the client, only unique within this instance.
380 uint32_t id;
381
382 bool primary_application;
383 bool session_active;
384 bool session_visible;
385 bool session_focused;
386 bool session_overlay;
387 struct ipc_client_io_blocks io_blocks;
388 uint32_t z_order;
389 pid_t pid;
390 struct xrt_application_info info;
391};
392
393/*!
394 * Arguments for creating swapchains from native images.
395 */
397{
398 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
399};
400
401/*!
402 * Arguments for xrt_device::get_view_poses with two views.
403 */
405{
406 struct xrt_fov fovs[XRT_MAX_VIEWS];
407 struct xrt_pose poses[XRT_MAX_VIEWS];
408 struct xrt_space_relation head_relation;
409};
410
412{
413 uint32_t num_samples;
414 float sample_rate;
415 bool append;
416};
xrt_hand
Enumeration for left and right hand.
Definition xrt_defines.h:1478
xrt_blend_mode
Blend mode that the device supports, exact mirror of XrEnvironmentBlendMode.
Definition xrt_defines.h:112
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition xrt_limits.h:26
#define XRT_MAX_SWAPCHAIN_IMAGES
Max swapchain images, artificial limit.
Definition xrt_limits.h:53
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:930
xrt_tracking_type
What kind of tracking system is this.
Definition xrt_tracking.h:46
xrt_device_type
How an xrt_device can be used.
Definition xrt_defines.h:827
State for a connected application.
Definition ipc_protocol.h:378
Arguments for creating swapchains from native images.
Definition ipc_protocol.h:397
A binding in the shared memory area.
Definition ipc_protocol.h:198
uint32_t first_output_index
Offset into the array of pairs where this output bindings starts.
Definition ipc_protocol.h:207
uint32_t output_count
Number of outputs.
Definition ipc_protocol.h:209
uint32_t first_input_index
Offset into the array of pairs where this input bindings starts.
Definition ipc_protocol.h:202
uint32_t input_count
Number of inputs.
Definition ipc_protocol.h:204
Initial info from a client when it connects.
Definition ipc_protocol.h:348
Which types of IO to block for a client.
Definition ipc_protocol.h:365
Definition ipc_protocol.h:354
Device information sent over IPC.
Definition ipc_protocol.h:151
char str[XRT_DEVICE_NAME_LEN]
A string describing the device.
Definition ipc_protocol.h:168
uint32_t total_output_pair_count
Total number of output pairs in varlen data (across all binding profiles).
Definition ipc_protocol.h:180
enum xrt_device_name name
Enum identifier of the device.
Definition ipc_protocol.h:153
uint32_t total_input_pair_count
Total number of input pairs in varlen data (across all binding profiles).
Definition ipc_protocol.h:177
XRT_ALIGNAS(8) uint32_t tracking_origin_id
Which tracking system origin is this device attached to.
uint32_t binding_profile_count
Number of binding profiles in varlen data.
Definition ipc_protocol.h:174
char serial[XRT_DEVICE_NAME_LEN]
A unique identifier. Persistent across configurations, if possible.
Definition ipc_protocol.h:171
uint64_t xrt_device_id_val
The service-side xrt_device_id, synchronized to IPC clients so that xrt_device::id matches across all...
Definition ipc_protocol.h:162
struct xrt_device_supported supported
The supported fields.
Definition ipc_protocol.h:189
uint32_t input_count
Number of inputs.
Definition ipc_protocol.h:183
uint32_t output_count
Number of outputs.
Definition ipc_protocol.h:186
Information about a device in the device list.
Definition ipc_protocol.h:116
uint32_t id
Device ID.
Definition ipc_protocol.h:118
enum xrt_device_type device_type
Device type.
Definition ipc_protocol.h:121
List of devices available on the server.
Definition ipc_protocol.h:130
uint32_t device_count
Number of devices.
Definition ipc_protocol.h:132
Pointer-free arguments for creating an xrt_hand_tracker over IPC.
Definition ipc_protocol.h:336
Arguments for xrt_device::get_view_poses with two views.
Definition ipc_protocol.h:405
Data for a single composition layer.
Definition ipc_protocol.h:220
uint32_t xdev_id
Definition ipc_protocol.h:222
Render state for a single client, including all layers.
Definition ipc_protocol.h:244
Definition ipc_protocol.h:412
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition ipc_protocol.h:266
A tracking in the shared memory area.
Definition ipc_protocol.h:99
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition ipc_protocol.h:104
struct xrt_pose offset
Initial offset of the tracking origin.
Definition ipc_protocol.h:107
Information about a device in the device list.
Definition ipc_protocol.h:74
uint32_t id
Tracking origin ID.
Definition ipc_protocol.h:76
A list of the current tracking origins.
Definition ipc_protocol.h:85
uint32_t origin_count
Number of tracking origins.
Definition ipc_protocol.h:87
struct ipc_tracking_origin_list_entry origins[XRT_SYSTEM_MAX_DEVICES]
Compact list of tracking origins.
Definition ipc_protocol.h:90
Non-process-specific information provided by the application at instance create time.
Definition xrt_instance.h:73
Static data of supported features of the xrt_device this struct sits on.
Definition xrt_device.h:302
Describes a projection matrix fov.
Definition xrt_defines.h:512
All the pure data values associated with a composition layer.
Definition xrt_compositor.h:441
Per frame data for the layer submission calls, used in xrt_compositor::layer_begin.
Definition xrt_compositor.h:527
A query for a plane.
Definition xrt_plane_detector.h:97
A pose composed of a position and orientation.
Definition xrt_defines.h:492
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:683
Header holding common defines.
Header declaring XRT graphics interfaces.
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.
Interface for creating futures.
Header for xrt_instance object.
Header for limits of the XRT interfaces.
Internal result type for XRT.
Header for session object.
Header defining xrt space and space overseer.
Header for system objects.
Header defining the tracking system integration in Monado.