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 *
145 * @ingroup ipc
146 */
148{
149 //! Enum identifier of the device.
151 enum xrt_device_type device_type;
152
153 /*!
154 * The service-side @ref xrt_device_id, synchronized to IPC clients so that
155 * @ref xrt_device::id matches across all clients connected to the same
156 * service. This is distinct from the per-client-connection @c uint32_t
157 * slot index used to look up devices in IPC messages.
158 */
160
161 //! Which tracking system origin is this device attached to.
162 XRT_ALIGNAS(8) uint32_t tracking_origin_id;
163
164 //! A string describing the device.
165 char str[XRT_DEVICE_NAME_LEN];
166
167 //! A unique identifier. Persistent across configurations, if possible.
168 char serial[XRT_DEVICE_NAME_LEN];
169
170 //! Number of inputs.
171 uint32_t input_count;
172
173 //! Number of outputs.
174 uint32_t output_count;
175
176 //! The supported fields.
178};
179
180/*!
181 * Data for a single composition layer.
182 *
183 * Similar in function to @ref comp_layer
184 *
185 * @ingroup ipc
186 */
188{
189 //! @todo what is this used for?
190 uint32_t xdev_id;
191
192 /*!
193 * Up to two indices of swapchains to use.
194 *
195 * How many are actually used depends on the value of @p data.type
196 */
197 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
198
199 /*!
200 * All basic (trivially-serializable) data associated with a layer,
201 * aside from which swapchain(s) are used.
202 */
203 struct xrt_layer_data data;
204};
205
206/*!
207 * Render state for a single client, including all layers.
208 *
209 * @ingroup ipc
210 */
212{
213 struct xrt_layer_frame_data data;
214 uint32_t layer_count;
215 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
216};
217
218/*!
219 * A big struct that contains all data that is shared to a client, no pointers
220 * allowed in this. To get the inputs of a device you go:
221 *
222 * ```C++
223 * struct xrt_input *
224 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
225 * {
226 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
227 * return &ism->inputs[index];
228 * }
229 * ```
230 *
231 * @ingroup ipc
232 */
234{
235 /*!
236 * The git revision of the service, used by clients to detect version mismatches.
237 */
238 char u_git_tag[IPC_VERSION_NAME_LEN];
239
240 /*!
241 * Various roles for the devices.
242 */
243 struct
244 {
245 int32_t head;
246 int32_t eyes;
247 int32_t face;
248 int32_t body;
249
250 struct
251 {
252 struct
253 {
254 int32_t left;
255 int32_t right;
256 } unobstructed;
257
258 struct
259 {
260 int32_t left;
261 int32_t right;
262 } conforming;
263 } hand_tracking;
264 } roles;
265
266 struct
267 {
268 struct
269 {
270 /*!
271 * Pixel properties of this display, not in absolute
272 * screen coordinates that the compositor sees. So
273 * before any rotation is applied by xrt_view::rot.
274 *
275 * The xrt_view::display::w_pixels &
276 * xrt_view::display::h_pixels become the recommended
277 * image size for this view.
278 *
279 * @todo doesn't account for overfill for timewarp or
280 * distortion?
281 */
282 struct
283 {
284 uint32_t w_pixels;
285 uint32_t h_pixels;
286 } display;
287 } views[2];
288 // view count
289 uint32_t view_count;
290 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
291 uint32_t blend_mode_count;
292 } hmd;
293
294 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
295
296 uint64_t startup_timestamp;
297 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext;
298};
299
300/*!
301 * Pointer-free arguments for creating an @ref xrt_hand_tracker over IPC.
302 */
304{
305 enum xrt_hand hand;
306 enum xrt_input_name requested_sources[2];
307 uint32_t requested_source_count;
308 bool has_locked_xdev;
309 uint32_t locked_xdev_id;
310};
311
312/*!
313 * Pointer-free arguments for creating an @ref xrt_body_tracker over IPC.
314 */
316{
317 enum xrt_input_name body_tracking_type;
318 bool has_locked_xdev;
319 uint32_t locked_xdev_id;
320};
321
322/*!
323 * Initial info from a client when it connects.
324 */
326{
327 pid_t pid;
328 struct xrt_application_info info;
329};
330
332{
333 uint32_t ids[IPC_MAX_CLIENTS];
334 uint32_t id_count;
335};
336
337/*!
338 * Which types of IO to block for a client.
339 *
340 * @ingroup ipc
341 */
343{
344 bool block_poses;
345 bool block_hand_tracking;
346 bool block_inputs;
347 bool block_outputs;
348};
349
350/*!
351 * State for a connected application.
352 *
353 * @ingroup ipc
354 */
356{
357 // Stable and unique ID of the client, only unique within this instance.
358 uint32_t id;
359
360 bool primary_application;
361 bool session_active;
362 bool session_visible;
363 bool session_focused;
364 bool session_overlay;
365 struct ipc_client_io_blocks io_blocks;
366 uint32_t z_order;
367 pid_t pid;
368 struct xrt_application_info info;
369};
370
371/*!
372 * Arguments for creating swapchains from native images.
373 */
375{
376 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
377};
378
379/*!
380 * Arguments for xrt_device::get_view_poses with two views.
381 */
383{
384 struct xrt_fov fovs[XRT_MAX_VIEWS];
385 struct xrt_pose poses[XRT_MAX_VIEWS];
386 struct xrt_space_relation head_relation;
387};
388
390{
391 uint32_t num_samples;
392 float sample_rate;
393 bool append;
394};
xrt_hand
Enumeration for left and right hand.
Definition xrt_defines.h:1502
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:952
xrt_tracking_type
What kind of tracking system is this.
Definition xrt_tracking.h:55
xrt_device_type
How an xrt_device can be used.
Definition xrt_defines.h:849
State for a connected application.
Definition ipc_protocol.h:356
Arguments for creating swapchains from native images.
Definition ipc_protocol.h:375
Pointer-free arguments for creating an xrt_body_tracker over IPC.
Definition ipc_protocol.h:316
Initial info from a client when it connects.
Definition ipc_protocol.h:326
Which types of IO to block for a client.
Definition ipc_protocol.h:343
Definition ipc_protocol.h:332
Device information sent over IPC.
Definition ipc_protocol.h:148
char str[XRT_DEVICE_NAME_LEN]
A string describing the device.
Definition ipc_protocol.h:165
enum xrt_device_name name
Enum identifier of the device.
Definition ipc_protocol.h:150
XRT_ALIGNAS(8) uint32_t tracking_origin_id
Which tracking system origin is this device attached to.
char serial[XRT_DEVICE_NAME_LEN]
A unique identifier. Persistent across configurations, if possible.
Definition ipc_protocol.h:168
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:159
struct xrt_device_supported supported
The supported fields.
Definition ipc_protocol.h:177
uint32_t input_count
Number of inputs.
Definition ipc_protocol.h:171
uint32_t output_count
Number of outputs.
Definition ipc_protocol.h:174
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:304
Arguments for xrt_device::get_view_poses with two views.
Definition ipc_protocol.h:383
Data for a single composition layer.
Definition ipc_protocol.h:188
uint32_t xdev_id
Definition ipc_protocol.h:190
Render state for a single client, including all layers.
Definition ipc_protocol.h:212
Definition ipc_protocol.h:390
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition ipc_protocol.h:234
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:74
Static data of supported features of the xrt_device this struct sits on.
Definition xrt_device.h:289
Describes a projection matrix fov.
Definition xrt_defines.h:533
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:513
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:704
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:758
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.