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 //! Which tracking system origin is this device attached to.
158
159 //! A string describing the device.
160 char str[XRT_DEVICE_NAME_LEN];
161
162 //! A unique identifier. Persistent across configurations, if possible.
163 char serial[XRT_DEVICE_NAME_LEN];
164
165 //! Number of binding profiles in varlen data.
167
168 //! Total number of input pairs in varlen data (across all binding profiles).
170
171 //! Total number of output pairs in varlen data (across all binding profiles).
173
174 //! Number of inputs.
175 uint32_t input_count;
176
177 //! Number of outputs.
178 uint32_t output_count;
179
180 //! The supported fields.
182};
183
184/*!
185 * A binding in the shared memory area.
186 *
187 * @ingroup ipc
188 */
190{
191 enum xrt_device_name name;
192
193 //! Offset into the array of pairs where this input bindings starts.
195 //! Number of inputs.
196 uint32_t input_count;
197
198 //! Offset into the array of pairs where this output bindings starts.
200 //! Number of outputs.
201 uint32_t output_count;
202};
203
204/*!
205 * Data for a single composition layer.
206 *
207 * Similar in function to @ref comp_layer
208 *
209 * @ingroup ipc
210 */
212{
213 //! @todo what is this used for?
214 uint32_t xdev_id;
215
216 /*!
217 * Up to two indices of swapchains to use.
218 *
219 * How many are actually used depends on the value of @p data.type
220 */
221 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
222
223 /*!
224 * All basic (trivially-serializable) data associated with a layer,
225 * aside from which swapchain(s) are used.
226 */
228};
229
230/*!
231 * Render state for a single client, including all layers.
232 *
233 * @ingroup ipc
234 */
236{
237 struct xrt_layer_frame_data data;
238 uint32_t layer_count;
239 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
240};
241
242/*!
243 * A big struct that contains all data that is shared to a client, no pointers
244 * allowed in this. To get the inputs of a device you go:
245 *
246 * ```C++
247 * struct xrt_input *
248 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
249 * {
250 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
251 * return &ism->inputs[index];
252 * }
253 * ```
254 *
255 * @ingroup ipc
256 */
258{
259 /*!
260 * The git revision of the service, used by clients to detect version mismatches.
261 */
262 char u_git_tag[IPC_VERSION_NAME_LEN];
263
264 /*!
265 * Various roles for the devices.
266 */
267 struct
268 {
269 int32_t head;
270 int32_t eyes;
271 int32_t face;
272 int32_t body;
273
274 struct
275 {
276 struct
277 {
278 int32_t left;
279 int32_t right;
280 } unobstructed;
281
282 struct
283 {
284 int32_t left;
285 int32_t right;
286 } conforming;
287 } hand_tracking;
289
290 struct
291 {
292 struct
293 {
294 /*!
295 * Pixel properties of this display, not in absolute
296 * screen coordinates that the compositor sees. So
297 * before any rotation is applied by xrt_view::rot.
298 *
299 * The xrt_view::display::w_pixels &
300 * xrt_view::display::h_pixels become the recommended
301 * image size for this view.
302 *
303 * @todo doesn't account for overfill for timewarp or
304 * distortion?
305 */
306 struct
307 {
308 uint32_t w_pixels;
309 uint32_t h_pixels;
311 } views[2];
312 // view count
313 uint32_t view_count;
314 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
315 uint32_t blend_mode_count;
316 } hmd;
317
318 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
319
320 uint64_t startup_timestamp;
321 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext;
322};
323
324/*!
325 * Initial info from a client when it connects.
326 */
328{
329 pid_t pid;
330 struct xrt_application_info info;
331};
332
334{
335 uint32_t ids[IPC_MAX_CLIENTS];
336 uint32_t id_count;
337};
338
339/*!
340 * Which types of IO to block for a client.
341 *
342 * @ingroup ipc
343 */
345{
346 bool block_poses;
347 bool block_hand_tracking;
348 bool block_inputs;
349 bool block_outputs;
350};
351
352/*!
353 * State for a connected application.
354 *
355 * @ingroup ipc
356 */
358{
359 // Stable and unique ID of the client, only unique within this instance.
360 uint32_t id;
361
362 bool primary_application;
363 bool session_active;
364 bool session_visible;
365 bool session_focused;
366 bool session_overlay;
367 struct ipc_client_io_blocks io_blocks;
368 uint32_t z_order;
369 pid_t pid;
370 struct xrt_application_info info;
371};
372
373
374/*!
375 * Arguments for creating swapchains from native images.
376 */
378{
379 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
380};
381
382/*!
383 * Arguments for xrt_device::get_view_poses with two views.
384 */
386{
387 struct xrt_fov fovs[XRT_MAX_VIEWS];
388 struct xrt_pose poses[XRT_MAX_VIEWS];
389 struct xrt_space_relation head_relation;
390};
391
393{
394 uint32_t num_samples;
395 float sample_rate;
396 bool append;
397};
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_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:812
State for a connected application.
Definition ipc_protocol.h:358
Arguments for creating swapchains from native images.
Definition ipc_protocol.h:378
A binding in the shared memory area.
Definition ipc_protocol.h:190
uint32_t first_output_index
Offset into the array of pairs where this output bindings starts.
Definition ipc_protocol.h:199
uint32_t output_count
Number of outputs.
Definition ipc_protocol.h:201
uint32_t first_input_index
Offset into the array of pairs where this input bindings starts.
Definition ipc_protocol.h:194
uint32_t input_count
Number of inputs.
Definition ipc_protocol.h:196
Initial info from a client when it connects.
Definition ipc_protocol.h:328
Which types of IO to block for a client.
Definition ipc_protocol.h:345
Definition ipc_protocol.h:334
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:160
uint32_t total_output_pair_count
Total number of output pairs in varlen data (across all binding profiles).
Definition ipc_protocol.h:172
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:169
uint32_t binding_profile_count
Number of binding profiles in varlen data.
Definition ipc_protocol.h:166
char serial[XRT_DEVICE_NAME_LEN]
A unique identifier. Persistent across configurations, if possible.
Definition ipc_protocol.h:163
uint32_t tracking_origin_id
Which tracking system origin is this device attached to.
Definition ipc_protocol.h:157
struct xrt_device_supported supported
The supported fields.
Definition ipc_protocol.h:181
uint32_t input_count
Number of inputs.
Definition ipc_protocol.h:175
uint32_t output_count
Number of outputs.
Definition ipc_protocol.h:178
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
struct ipc_device_list_entry devices[XRT_SYSTEM_MAX_DEVICES]
Device entries.
Definition ipc_protocol.h:135
uint32_t device_count
Number of devices.
Definition ipc_protocol.h:132
Arguments for xrt_device::get_view_poses with two views.
Definition ipc_protocol.h:386
Data for a single composition layer.
Definition ipc_protocol.h:212
struct xrt_layer_data data
All basic (trivially-serializable) data associated with a layer, aside from which swapchain(s) are us...
Definition ipc_protocol.h:227
uint32_t swapchain_ids[XRT_MAX_VIEWS *2]
Up to two indices of swapchains to use.
Definition ipc_protocol.h:221
uint32_t xdev_id
Definition ipc_protocol.h:214
Render state for a single client, including all layers.
Definition ipc_protocol.h:236
Definition ipc_protocol.h:393
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition ipc_protocol.h:258
struct ipc_shared_memory::@268::@272::@273 display
Pixel properties of this display, not in absolute screen coordinates that the compositor sees.
char u_git_tag[64]
The git revision of the service, used by clients to detect version mismatches.
Definition ipc_protocol.h:262
struct ipc_shared_memory::@267 roles
Various roles for the devices.
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
char name[XRT_TRACKING_NAME_LEN]
For debugging.
Definition ipc_protocol.h:101
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:280
Describes a projection matrix fov.
Definition xrt_defines.h:499
All the pure data values associated with a composition layer.
Definition xrt_compositor.h:395
Per frame data for the layer submission calls, used in xrt_compositor::layer_begin.
Definition xrt_compositor.h:481
A query for a plane.
Definition xrt_plane_detector.h:97
A pose composed of a position and orientation.
Definition xrt_defines.h:479
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:670
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:724
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.