Monado OpenXR Runtime
ipc_protocol.h
Go to the documentation of this file.
1// Copyright 2020-2024 Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Common protocol definition.
6 * @author Pete Black <pblack@collabora.com>
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Korcan Hussein <korcan.hussein@collabora.com>
9 * @ingroup ipc_shared
10 */
11
12#pragma once
13
14#include "xrt/xrt_limits.h"
15#include "xrt/xrt_compiler.h"
16#include "xrt/xrt_compositor.h"
17#include "xrt/xrt_results.h"
18#include "xrt/xrt_defines.h"
19#include "xrt/xrt_system.h"
20#include "xrt/xrt_session.h"
21#include "xrt/xrt_instance.h"
22#include "xrt/xrt_compositor.h"
23#include "xrt/xrt_device.h"
24#include "xrt/xrt_space.h"
25#include "xrt/xrt_tracking.h"
26#include "xrt/xrt_config_build.h"
27
28#include <assert.h>
29#include <sys/types.h>
30
31
32#define IPC_CRED_SIZE 1 // auth not implemented
33#define IPC_BUF_SIZE 512 // must be >= largest message length in bytes
34#define IPC_MAX_VIEWS 8 // max views we will return configs for
35#define IPC_MAX_FORMATS 32 // max formats our server-side compositor supports
36#define IPC_MAX_DEVICES 8 // max number of devices we will map using shared mem
37#define IPC_MAX_LAYERS XRT_MAX_LAYERS
38#define IPC_MAX_SLOTS 128
39#define IPC_MAX_CLIENTS 8
40#define IPC_MAX_RAW_VIEWS 32 // Max views that we can get, artificial limit.
41#define IPC_EVENT_QUEUE_SIZE 32
42
43#define IPC_SHARED_MAX_INPUTS 1024
44#define IPC_SHARED_MAX_OUTPUTS 128
45#define IPC_SHARED_MAX_BINDINGS 64
46
47// example: v21.0.0-560-g586d33b5
48#define IPC_VERSION_NAME_LEN 64
49
50#if defined(XRT_OS_WINDOWS) && !defined(XRT_ENV_MINGW)
51typedef int pid_t;
52#endif
53
54/*
55 *
56 * Shared memory structs.
57 *
58 */
59
60/*!
61 * A tracking in the shared memory area.
62 *
63 * @ingroup ipc
64 */
66{
67 //! For debugging.
68 char name[XRT_TRACKING_NAME_LEN];
69
70 //! What can the state tracker expect from this tracking system.
72
73 //! Initial offset of the tracking origin.
75};
76
77/*!
78 * A binding in the shared memory area.
79 *
80 * @ingroup ipc
81 */
83{
84 enum xrt_device_name name;
85
86 //! Number of inputs.
87 uint32_t input_count;
88 //! Offset into the array of pairs where this input bindings starts.
90
91 //! Number of outputs.
92 uint32_t output_count;
93 //! Offset into the array of pairs where this output bindings starts.
95};
96
97/*!
98 * A device in the shared memory area.
99 *
100 * @ingroup ipc
101 */
103{
104 //! Enum identifier of the device.
106 enum xrt_device_type device_type;
107
108 //! Which tracking system origin is this device attached to.
110
111 //! A string describing the device.
112 char str[XRT_DEVICE_NAME_LEN];
113
114 //! A unique identifier. Persistent across configurations, if possible.
115 char serial[XRT_DEVICE_NAME_LEN];
116
117 //! Number of bindings.
119 //! 'Offset' into the array of bindings where the bindings starts.
121
122 //! Number of inputs.
123 uint32_t input_count;
124 //! 'Offset' into the array of inputs where the inputs starts.
126
127 //! Number of outputs.
128 uint32_t output_count;
129 //! 'Offset' into the array of outputs where the outputs starts.
131
132 //! The supported fields.
134};
135
136/*!
137 * Data for a single composition layer.
138 *
139 * Similar in function to @ref comp_layer
140 *
141 * @ingroup ipc
142 */
144{
145 //! @todo what is this used for?
146 uint32_t xdev_id;
147
148 /*!
149 * Up to two indices of swapchains to use.
150 *
151 * How many are actually used depends on the value of @p data.type
152 */
153 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
154
155 /*!
156 * All basic (trivially-serializable) data associated with a layer,
157 * aside from which swapchain(s) are used.
158 */
160};
161
162/*!
163 * Render state for a single client, including all layers.
164 *
165 * @ingroup ipc
166 */
168{
169 struct xrt_layer_frame_data data;
170 uint32_t layer_count;
171 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
172};
173
174/*!
175 * A big struct that contains all data that is shared to a client, no pointers
176 * allowed in this. To get the inputs of a device you go:
177 *
178 * ```C++
179 * struct xrt_input *
180 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
181 * {
182 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
183 * return &ism->inputs[index];
184 * }
185 * ```
186 *
187 * @ingroup ipc
188 */
190{
191 /*!
192 * The git revision of the service, used by clients to detect version mismatches.
193 */
194 char u_git_tag[IPC_VERSION_NAME_LEN];
195
196 /*!
197 * Number of elements in @ref itracks that are populated/valid.
198 */
199 uint32_t itrack_count;
200
201 /*!
202 * @brief Array of shared tracking origin data.
203 *
204 * Only @ref itrack_count elements are populated/valid.
205 */
207
208 /*!
209 * Number of elements in @ref isdevs that are populated/valid.
210 */
211 uint32_t isdev_count;
212
213 /*!
214 * @brief Array of shared data per device.
215 *
216 * Only @ref isdev_count elements are populated/valid.
217 */
219
220 /*!
221 * Various roles for the devices.
222 */
223 struct
224 {
225 int32_t head;
226 int32_t eyes;
227 int32_t face;
228 int32_t body;
229
230 struct
231 {
232 struct
233 {
234 int32_t left;
235 int32_t right;
236 } unobstructed;
237
238 struct
239 {
240 int32_t left;
241 int32_t right;
242 } conforming;
243 } hand_tracking;
245
246 struct
247 {
248 struct
249 {
250 /*!
251 * Pixel properties of this display, not in absolute
252 * screen coordinates that the compositor sees. So
253 * before any rotation is applied by xrt_view::rot.
254 *
255 * The xrt_view::display::w_pixels &
256 * xrt_view::display::h_pixels become the recommended
257 * image size for this view.
258 *
259 * @todo doesn't account for overfill for timewarp or
260 * distortion?
261 */
262 struct
263 {
264 uint32_t w_pixels;
265 uint32_t h_pixels;
267 } views[2];
268 // view count
269 uint32_t view_count;
270 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
271 uint32_t blend_mode_count;
272 } hmd;
273
274 struct xrt_input inputs[IPC_SHARED_MAX_INPUTS];
275
276 struct xrt_output outputs[IPC_SHARED_MAX_OUTPUTS];
277
278 struct ipc_shared_binding_profile binding_profiles[IPC_SHARED_MAX_BINDINGS];
279 struct xrt_binding_input_pair input_pairs[IPC_SHARED_MAX_INPUTS];
280 struct xrt_binding_output_pair output_pairs[IPC_SHARED_MAX_OUTPUTS];
281
282 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
283
284 uint64_t startup_timestamp;
285 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext;
286};
287
288/*!
289 * Initial info from a client when it connects.
290 */
292{
293 pid_t pid;
294 struct xrt_application_info info;
295};
296
298{
299 uint32_t ids[IPC_MAX_CLIENTS];
300 uint32_t id_count;
301};
302
303/*!
304 * State for a connected application.
305 *
306 * @ingroup ipc
307 */
309{
310 // Stable and unique ID of the client, only unique within this instance.
311 uint32_t id;
312
313 bool primary_application;
314 bool session_active;
315 bool session_visible;
316 bool session_focused;
317 bool session_overlay;
318 bool io_active;
319 uint32_t z_order;
320 pid_t pid;
321 struct xrt_application_info info;
322};
323
324
325/*!
326 * Arguments for creating swapchains from native images.
327 */
329{
330 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
331};
332
333/*!
334 * Arguments for xrt_device::get_view_poses with two views.
335 */
337{
338 struct xrt_fov fovs[XRT_MAX_VIEWS];
339 struct xrt_pose poses[XRT_MAX_VIEWS];
340 struct xrt_space_relation head_relation;
341};
342
344{
345 uint32_t num_samples;
346 float sample_rate;
347 bool append;
348};
xrt_blend_mode
Blend mode that the device supports, exact mirror of XrEnvironmentBlendMode.
Definition: xrt_defines.h:111
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition: xrt_system.h:141
#define XRT_MAX_SWAPCHAIN_IMAGES
Max swapchain images, artificial limit.
Definition: xrt_limits.h:34
xrt_tracking_type
What kind of tracking system is this.
Definition: xrt_tracking.h:45
xrt_device_type
How an xrt_device can be used.
Definition: xrt_defines.h:785
State for a connected application.
Definition: ipc_protocol.h:309
Arguments for creating swapchains from native images.
Definition: ipc_protocol.h:329
Initial info from a client when it connects.
Definition: ipc_protocol.h:292
Definition: ipc_protocol.h:298
Arguments for xrt_device::get_view_poses with two views.
Definition: ipc_protocol.h:337
Data for a single composition layer.
Definition: ipc_protocol.h:144
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:159
uint32_t swapchain_ids[XRT_MAX_VIEWS *2]
Up to two indices of swapchains to use.
Definition: ipc_protocol.h:153
uint32_t xdev_id
Definition: ipc_protocol.h:146
Render state for a single client, including all layers.
Definition: ipc_protocol.h:168
Definition: ipc_protocol.h:344
A binding in the shared memory area.
Definition: ipc_protocol.h:83
uint32_t output_count
Number of outputs.
Definition: ipc_protocol.h:92
uint32_t input_count
Number of inputs.
Definition: ipc_protocol.h:87
uint32_t first_input_index
Offset into the array of pairs where this input bindings starts.
Definition: ipc_protocol.h:89
uint32_t first_output_index
Offset into the array of pairs where this output bindings starts.
Definition: ipc_protocol.h:94
A device in the shared memory area.
Definition: ipc_protocol.h:103
uint32_t first_input_index
'Offset' into the array of inputs where the inputs starts.
Definition: ipc_protocol.h:125
uint32_t binding_profile_count
Number of bindings.
Definition: ipc_protocol.h:118
uint32_t first_binding_profile_index
'Offset' into the array of bindings where the bindings starts.
Definition: ipc_protocol.h:120
uint32_t input_count
Number of inputs.
Definition: ipc_protocol.h:123
uint32_t output_count
Number of outputs.
Definition: ipc_protocol.h:128
uint32_t first_output_index
'Offset' into the array of outputs where the outputs starts.
Definition: ipc_protocol.h:130
char str[XRT_DEVICE_NAME_LEN]
A string describing the device.
Definition: ipc_protocol.h:112
struct xrt_device_supported supported
The supported fields.
Definition: ipc_protocol.h:133
uint32_t tracking_origin_index
Which tracking system origin is this device attached to.
Definition: ipc_protocol.h:109
char serial[XRT_DEVICE_NAME_LEN]
A unique identifier. Persistent across configurations, if possible.
Definition: ipc_protocol.h:115
enum xrt_device_name name
Enum identifier of the device.
Definition: ipc_protocol.h:105
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition: ipc_protocol.h:190
struct ipc_shared_memory::@256 roles
Various roles for the devices.
struct ipc_shared_memory::@257::@261::@262 display
Pixel properties of this display, not in absolute screen coordinates that the compositor sees.
uint32_t itrack_count
Number of elements in itracks that are populated/valid.
Definition: ipc_protocol.h:199
char u_git_tag[64]
The git revision of the service, used by clients to detect version mismatches.
Definition: ipc_protocol.h:194
struct ipc_shared_tracking_origin itracks[XRT_SYSTEM_MAX_DEVICES]
Array of shared tracking origin data.
Definition: ipc_protocol.h:206
struct ipc_shared_device isdevs[XRT_SYSTEM_MAX_DEVICES]
Array of shared data per device.
Definition: ipc_protocol.h:218
uint32_t isdev_count
Number of elements in isdevs that are populated/valid.
Definition: ipc_protocol.h:211
A tracking in the shared memory area.
Definition: ipc_protocol.h:66
char name[XRT_TRACKING_NAME_LEN]
For debugging.
Definition: ipc_protocol.h:68
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition: ipc_protocol.h:71
struct xrt_pose offset
Initial offset of the tracking origin.
Definition: ipc_protocol.h:74
Non-process-specific information provided by the application at instance create time.
Definition: xrt_instance.h:72
A binding pair, going from a binding point to a device input.
Definition: xrt_device.h:192
A binding pair, going from a binding point to a device output.
Definition: xrt_device.h:203
Static data of supported features of the xrt_device this struct sits on.
Definition: xrt_device.h:254
Describes a projection matrix fov.
Definition: xrt_defines.h:484
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:163
All the pure data values associated with a composition layer.
Definition: xrt_compositor.h:394
Per frame data for the layer submission calls, used in xrt_compositor::layer_begin.
Definition: xrt_compositor.h:480
A single named output, that sits on a xrt_device.
Definition: xrt_device.h:181
A query for a plane.
Definition: xrt_plane_detector.h:97
A pose composed of a position and orientation.
Definition: xrt_defines.h:464
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:655
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:709
Header defining an xrt display or controller device.
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.