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 <sys/types.h>
29
30
31#define IPC_CRED_SIZE 1 // auth not implemented
32#define IPC_BUF_SIZE 512 // must be >= largest message length in bytes
33#define IPC_MAX_VIEWS 8 // max views we will return configs for
34#define IPC_MAX_FORMATS 32 // max formats our server-side compositor supports
35#define IPC_MAX_DEVICES 8 // max number of devices we will map using shared mem
36#define IPC_MAX_LAYERS XRT_MAX_LAYERS
37#define IPC_MAX_SLOTS 128
38#define IPC_MAX_CLIENTS 8
39#define IPC_MAX_RAW_VIEWS 32 // Max views that we can get, artificial limit.
40#define IPC_EVENT_QUEUE_SIZE 32
41
42#define IPC_SHARED_MAX_INPUTS 1024
43#define IPC_SHARED_MAX_OUTPUTS 128
44#define IPC_SHARED_MAX_BINDINGS 64
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/*
54 *
55 * Shared memory structs.
56 *
57 */
58
59/*!
60 * A tracking in the shared memory area.
61 *
62 * @ingroup ipc
63 */
65{
66 //! For debugging.
67 char name[XRT_TRACKING_NAME_LEN];
68
69 //! What can the state tracker expect from this tracking system.
71
72 //! Initial offset of the tracking origin.
74};
75
76/*!
77 * A binding in the shared memory area.
78 *
79 * @ingroup ipc
80 */
82{
83 enum xrt_device_name name;
84
85 //! Number of inputs.
86 uint32_t input_count;
87 //! Offset into the array of pairs where this input bindings starts.
89
90 //! Number of outputs.
91 uint32_t output_count;
92 //! Offset into the array of pairs where this output bindings starts.
94};
95
96/*!
97 * A device in the shared memory area.
98 *
99 * @ingroup ipc
100 */
102{
103 //! Enum identifier of the device.
105 enum xrt_device_type device_type;
106
107 //! Which tracking system origin is this device attached to.
109
110 //! A string describing the device.
111 char str[XRT_DEVICE_NAME_LEN];
112
113 //! A unique identifier. Persistent across configurations, if possible.
114 char serial[XRT_DEVICE_NAME_LEN];
115
116 //! Number of bindings.
118 //! 'Offset' into the array of bindings where the bindings starts.
120
121 //! Number of inputs.
122 uint32_t input_count;
123 //! 'Offset' into the array of inputs where the inputs starts.
125
126 //! Number of outputs.
127 uint32_t output_count;
128 //! 'Offset' into the array of outputs where the outputs starts.
130
131 bool orientation_tracking_supported;
132 bool position_tracking_supported;
133 bool hand_tracking_supported;
134 bool eye_gaze_supported;
135 bool face_tracking_supported;
136 bool body_tracking_supported;
137 bool force_feedback_supported;
138 bool form_factor_check_supported;
139 bool stage_supported;
140 bool battery_status_supported;
141};
142
143/*!
144 * Data for a single composition layer.
145 *
146 * Similar in function to @ref comp_layer
147 *
148 * @ingroup ipc
149 */
151{
152 //! @todo what is this used for?
153 uint32_t xdev_id;
154
155 /*!
156 * Up to two indices of swapchains to use.
157 *
158 * How many are actually used depends on the value of @p data.type
159 */
160 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
161
162 /*!
163 * All basic (trivially-serializable) data associated with a layer,
164 * aside from which swapchain(s) are used.
165 */
167};
168
169/*!
170 * Render state for a single client, including all layers.
171 *
172 * @ingroup ipc
173 */
175{
176 struct xrt_layer_frame_data data;
177 uint32_t layer_count;
178 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
179};
180
181/*!
182 * A big struct that contains all data that is shared to a client, no pointers
183 * allowed in this. To get the inputs of a device you go:
184 *
185 * ```C++
186 * struct xrt_input *
187 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
188 * {
189 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
190 * return &ism->inputs[index];
191 * }
192 * ```
193 *
194 * @ingroup ipc
195 */
197{
198 /*!
199 * The git revision of the service, used by clients to detect version mismatches.
200 */
201 char u_git_tag[IPC_VERSION_NAME_LEN];
202
203 /*!
204 * Number of elements in @ref itracks that are populated/valid.
205 */
206 uint32_t itrack_count;
207
208 /*!
209 * @brief Array of shared tracking origin data.
210 *
211 * Only @ref itrack_count elements are populated/valid.
212 */
214
215 /*!
216 * Number of elements in @ref isdevs that are populated/valid.
217 */
218 uint32_t isdev_count;
219
220 /*!
221 * @brief Array of shared data per device.
222 *
223 * Only @ref isdev_count elements are populated/valid.
224 */
226
227 /*!
228 * Various roles for the devices.
229 */
230 struct
231 {
232 int32_t head;
233 int32_t eyes;
234 int32_t face;
235 int32_t body;
236
237 struct
238 {
239 int32_t left;
240 int32_t right;
241 } hand_tracking;
243
244 struct
245 {
246 struct
247 {
248 /*!
249 * Pixel properties of this display, not in absolute
250 * screen coordinates that the compositor sees. So
251 * before any rotation is applied by xrt_view::rot.
252 *
253 * The xrt_view::display::w_pixels &
254 * xrt_view::display::h_pixels become the recommended
255 * image size for this view.
256 *
257 * @todo doesn't account for overfill for timewarp or
258 * distortion?
259 */
260 struct
261 {
262 uint32_t w_pixels;
263 uint32_t h_pixels;
265 } views[2];
266 // view count
267 uint32_t view_count;
268 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
269 uint32_t blend_mode_count;
270 } hmd;
271
272 struct xrt_input inputs[IPC_SHARED_MAX_INPUTS];
273
274 struct xrt_output outputs[IPC_SHARED_MAX_OUTPUTS];
275
276 struct ipc_shared_binding_profile binding_profiles[IPC_SHARED_MAX_BINDINGS];
277 struct xrt_binding_input_pair input_pairs[IPC_SHARED_MAX_INPUTS];
278 struct xrt_binding_output_pair output_pairs[IPC_SHARED_MAX_OUTPUTS];
279
280 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
281
282 uint64_t startup_timestamp;
283};
284
285/*!
286 * Initial info from a client when it connects.
287 */
289{
290 pid_t pid;
291 struct xrt_application_info info;
292};
293
295{
296 uint32_t ids[IPC_MAX_CLIENTS];
297 uint32_t id_count;
298};
299
300/*!
301 * State for a connected application.
302 *
303 * @ingroup ipc
304 */
306{
307 // Stable and unique ID of the client, only unique within this instance.
308 uint32_t id;
309
310 bool primary_application;
311 bool session_active;
312 bool session_visible;
313 bool session_focused;
314 bool session_overlay;
315 bool io_active;
316 uint32_t z_order;
317 pid_t pid;
318 struct xrt_application_info info;
319};
320
321
322/*!
323 * Arguments for creating swapchains from native images.
324 */
326{
327 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
328};
329
330/*!
331 * Arguments for xrt_device::get_view_poses with two views.
332 */
334{
335 struct xrt_fov fovs[XRT_MAX_VIEWS];
336 struct xrt_pose poses[XRT_MAX_VIEWS];
337 struct xrt_space_relation head_relation;
338};
xrt_blend_mode
Blend mode that the device supports, exact mirror of XrEnvironmentBlendMode.
Definition: xrt_defines.h:109
#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:783
State for a connected application.
Definition: ipc_protocol.h:306
Arguments for creating swapchains from native images.
Definition: ipc_protocol.h:326
Initial info from a client when it connects.
Definition: ipc_protocol.h:289
Definition: ipc_protocol.h:295
Arguments for xrt_device::get_view_poses with two views.
Definition: ipc_protocol.h:334
Data for a single composition layer.
Definition: ipc_protocol.h:151
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:166
uint32_t swapchain_ids[XRT_MAX_VIEWS *2]
Up to two indices of swapchains to use.
Definition: ipc_protocol.h:160
uint32_t xdev_id
Definition: ipc_protocol.h:153
Render state for a single client, including all layers.
Definition: ipc_protocol.h:175
A binding in the shared memory area.
Definition: ipc_protocol.h:82
uint32_t output_count
Number of outputs.
Definition: ipc_protocol.h:91
uint32_t input_count
Number of inputs.
Definition: ipc_protocol.h:86
uint32_t first_input_index
Offset into the array of pairs where this input bindings starts.
Definition: ipc_protocol.h:88
uint32_t first_output_index
Offset into the array of pairs where this output bindings starts.
Definition: ipc_protocol.h:93
A device in the shared memory area.
Definition: ipc_protocol.h:102
uint32_t first_input_index
'Offset' into the array of inputs where the inputs starts.
Definition: ipc_protocol.h:124
uint32_t binding_profile_count
Number of bindings.
Definition: ipc_protocol.h:117
uint32_t first_binding_profile_index
'Offset' into the array of bindings where the bindings starts.
Definition: ipc_protocol.h:119
uint32_t input_count
Number of inputs.
Definition: ipc_protocol.h:122
uint32_t output_count
Number of outputs.
Definition: ipc_protocol.h:127
uint32_t first_output_index
'Offset' into the array of outputs where the outputs starts.
Definition: ipc_protocol.h:129
char str[XRT_DEVICE_NAME_LEN]
A string describing the device.
Definition: ipc_protocol.h:111
uint32_t tracking_origin_index
Which tracking system origin is this device attached to.
Definition: ipc_protocol.h:108
char serial[XRT_DEVICE_NAME_LEN]
A unique identifier. Persistent across configurations, if possible.
Definition: ipc_protocol.h:114
enum xrt_device_name name
Enum identifier of the device.
Definition: ipc_protocol.h:104
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition: ipc_protocol.h:197
struct ipc_shared_memory::@245::@247::@248 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:206
char u_git_tag[64]
The git revision of the service, used by clients to detect version mismatches.
Definition: ipc_protocol.h:201
struct ipc_shared_memory::@244 roles
Various roles for the devices.
struct ipc_shared_tracking_origin itracks[XRT_SYSTEM_MAX_DEVICES]
Array of shared tracking origin data.
Definition: ipc_protocol.h:213
struct ipc_shared_device isdevs[XRT_SYSTEM_MAX_DEVICES]
Array of shared data per device.
Definition: ipc_protocol.h:225
uint32_t isdev_count
Number of elements in isdevs that are populated/valid.
Definition: ipc_protocol.h:218
A tracking in the shared memory area.
Definition: ipc_protocol.h:65
char name[XRT_TRACKING_NAME_LEN]
For debugging.
Definition: ipc_protocol.h:67
enum xrt_tracking_type type
What can the state tracker expect from this tracking system.
Definition: ipc_protocol.h:70
struct xrt_pose offset
Initial offset of the tracking origin.
Definition: ipc_protocol.h:73
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:189
A binding pair, going from a binding point to a device output.
Definition: xrt_device.h:200
Describes a projection matrix fov.
Definition: xrt_defines.h:486
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:161
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:478
A single named output, that sits on a xrt_device.
Definition: xrt_device.h:178
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:657
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:712
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.