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 tracking origin in the tracking origin list.
70 *
71 * @ingroup ipc
72 */
74{
75 //! Tracking origin IPC ID, not @ref xrt_tracking_origin::id.
76 uint32_t ipc_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 /*!
101 * The service-side @ref xrt_tracking_origin_id, synchronized to IPC
102 * clients so that @ref xrt_tracking_origin::id matches across all
103 * clients connected to the same service. This is distinct from the
104 * tracking origin IPC ID used to look up tracking origins in IPC
105 * messages.
106 */
107 XRT_ALIGNAS(8) uint64_t xrt_tracking_origin_id_val;
108
109 //! For debugging.
110 char name[XRT_TRACKING_NAME_LEN];
111
112 //! What can the state tracker expect from this tracking system.
114
115 //! Initial offset of the tracking origin.
117};
118
119/*!
120 * Information about a device in the device list.
121 *
122 * @ingroup ipc
123 */
125{
126 //! Device ID
127 uint32_t id;
128
129 //! Device type
131};
132
133/*!
134 * List of devices available on the server.
135 *
136 * @ingroup ipc
137 */
139{
140 //! Number of devices
141 uint32_t device_count;
142
143 //! Device entries
145};
146
147/*!
148 * Device information sent over IPC.
149 *
150 * Followed by varlen data containing:
151 * - An array of input_count * enum xrt_input_name
152 * - An array of output_count * enum xrt_output_name
153 *
154 * @ingroup ipc
155 */
157{
158 //! Enum identifier of the device.
160 enum xrt_device_type device_type;
161
162 /*!
163 * The service-side @ref xrt_device_id, synchronized to IPC clients so that
164 * @ref xrt_device::id matches across all clients connected to the same
165 * service. This is distinct from the per-client-connection @c uint32_t
166 * slot index used to look up devices in IPC messages.
167 */
169
170 /*!
171 * IPC ID of the tracking origin this device is attached to, not the
172 * same as @ref xrt_tracking_origin::id.
173 */
174 XRT_ALIGNAS(8) uint32_t tracking_origin_ipc_id;
175
176 //! A string describing the device.
177 char str[XRT_DEVICE_NAME_LEN];
178
179 //! A unique identifier. Persistent across configurations, if possible.
180 char serial[XRT_DEVICE_NAME_LEN];
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.
189 struct xrt_device_supported supported;
190};
191
192/*!
193 * Data for a single composition layer.
194 *
195 * Similar in function to @ref comp_layer
196 *
197 * @ingroup ipc
198 */
200{
201 //! @todo what is this used for?
202 uint32_t xdev_id;
203
204 /*!
205 * Up to two indices of swapchains to use.
206 *
207 * How many are actually used depends on the value of @p data.type
208 */
209 uint32_t swapchain_ids[XRT_MAX_VIEWS * 2];
210
211 /*!
212 * All basic (trivially-serializable) data associated with a layer,
213 * aside from which swapchain(s) are used.
214 */
215 struct xrt_layer_data data;
216};
217
218/*!
219 * Render state for a single client, including all layers.
220 *
221 * @ingroup ipc
222 */
224{
225 struct xrt_layer_frame_data data;
226 uint32_t layer_count;
227 struct ipc_layer_entry layers[IPC_MAX_LAYERS];
228};
229
230/*!
231 * A big struct that contains all data that is shared to a client, no pointers
232 * allowed in this. To get the inputs of a device you go:
233 *
234 * ```C++
235 * struct xrt_input *
236 * helper(struct ipc_shared_memory *ism, uint32_t device_id, uint32_t input)
237 * {
238 * uint32_t index = ism->isdevs[device_id]->first_input_index + input;
239 * return &ism->inputs[index];
240 * }
241 * ```
242 *
243 * @ingroup ipc
244 */
246{
247 /*!
248 * The git revision of the service, used by clients to detect version mismatches.
249 */
250 char u_git_tag[IPC_VERSION_NAME_LEN];
251
252 /*!
253 * Various roles for the devices.
254 */
255 struct
256 {
257 int32_t head;
258 int32_t eyes;
259 int32_t face;
260 int32_t body;
261
262 struct
263 {
264 struct
265 {
266 int32_t left;
267 int32_t right;
268 } unobstructed;
269
270 struct
271 {
272 int32_t left;
273 int32_t right;
274 } conforming;
275 } hand_tracking;
276 } roles;
277
278 /*!
279 * Features supported by the service's system devices, see
280 * @ref xrt_system_devices::supported.
281 */
283
284 struct
285 {
286 struct
287 {
288 /*!
289 * Pixel properties of this display, not in absolute
290 * screen coordinates that the compositor sees. So
291 * before any rotation is applied by xrt_view::rot.
292 *
293 * The xrt_view::display::w_pixels &
294 * xrt_view::display::h_pixels become the recommended
295 * image size for this view.
296 *
297 * @todo doesn't account for overfill for timewarp or
298 * distortion?
299 */
300 struct
301 {
302 uint32_t w_pixels;
303 uint32_t h_pixels;
304 } display;
305 } views[2];
306 // view count
307 uint32_t view_count;
308 enum xrt_blend_mode blend_modes[XRT_MAX_DEVICE_BLEND_MODES];
309 uint32_t blend_mode_count;
310 } hmd;
311
312 struct ipc_layer_slot slots[IPC_MAX_SLOTS];
313
314 uint64_t startup_timestamp;
315 struct xrt_plane_detector_begin_info_ext plane_begin_info_ext;
316};
317
318/*!
319 * Pointer-free arguments for creating an @ref xrt_hand_tracker over IPC.
320 */
322{
323 enum xrt_hand hand;
324 enum xrt_input_name requested_sources[2];
325 uint32_t requested_source_count;
326 bool has_locked_xdev;
327 uint32_t locked_xdev_id;
328};
329
330/*!
331 * Pointer-free arguments for creating an @ref xrt_body_tracker over IPC.
332 */
334{
335 enum xrt_input_name body_tracking_type;
336 bool has_locked_xdev;
337 uint32_t locked_xdev_id;
338};
339
340/*!
341 * Initial info from a client when it connects.
342 */
344{
345 pid_t pid;
346 struct xrt_application_info info;
347};
348
350{
351 uint32_t ids[IPC_MAX_CLIENTS];
352 uint32_t id_count;
353};
354
355/*!
356 * Which types of IO to block for a client.
357 *
358 * @ingroup ipc
359 */
361{
362 bool block_poses;
363 bool block_hand_tracking;
364 bool block_inputs;
365 bool block_outputs;
366};
367
368/*!
369 * State for a connected application.
370 *
371 * @ingroup ipc
372 */
374{
375 // Stable and unique ID of the client, only unique within this instance.
376 uint32_t id;
377
378 bool primary_application;
379 bool session_active;
380 bool session_visible;
381 bool session_focused;
382 bool session_overlay;
383 struct ipc_client_io_blocks io_blocks;
384 uint32_t z_order;
385 pid_t pid;
386 struct xrt_application_info info;
387};
388
389/*!
390 * Arguments for creating swapchains from native images.
391 */
393{
394 uint32_t sizes[XRT_MAX_SWAPCHAIN_IMAGES];
395};
396
397/*!
398 * Arguments for xrt_device::get_view_poses with two views.
399 */
401{
402 struct xrt_fov fovs[XRT_MAX_VIEWS];
403 struct xrt_pose poses[XRT_MAX_VIEWS];
404 struct xrt_space_relation head_relation;
405};
406
407/*!
408 * Max number of samples in one @ref ipc_pcm_haptic_buffer.
409 *
410 * @note The value comes from `XR_MAX_HAPTIC_PCM_BUFFER_SIZE_FB` in the
411 * `XR_FB_haptic_pcm` extension.
412 *
413 * @warning The spec defines `XR_MAX_HAPTIC_PCM_BUFFER_SIZE_FB` as the maximum
414 * size of the runtime's internal sample buffer, not as a per-call limit. We
415 * don't keep such a buffer literally, but the only observable effect of one is
416 * that no more than this many samples can be consumed per call, so going above
417 * this value would violate the spec.
418 */
419#define IPC_MAX_PCM_HAPTIC_SAMPLES 4000
420
422{
423 uint32_t num_samples;
424 float sample_rate;
425 bool append;
426};
xrt_hand
Enumeration for left and right hand.
Definition xrt_defines.h:1581
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:1031
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:928
State for a connected application.
Definition ipc_protocol.h:374
Arguments for creating swapchains from native images.
Definition ipc_protocol.h:393
Pointer-free arguments for creating an xrt_body_tracker over IPC.
Definition ipc_protocol.h:334
Initial info from a client when it connects.
Definition ipc_protocol.h:344
Which types of IO to block for a client.
Definition ipc_protocol.h:361
Definition ipc_protocol.h:350
Device information sent over IPC.
Definition ipc_protocol.h:157
XRT_ALIGNAS(8) uint32_t tracking_origin_ipc_id
IPC ID of the tracking origin this device is attached to, not the same as xrt_tracking_origin::id.
enum xrt_device_name name
Enum identifier of the device.
Definition ipc_protocol.h:159
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:168
Information about a device in the device list.
Definition ipc_protocol.h:125
uint32_t id
Device ID.
Definition ipc_protocol.h:127
enum xrt_device_type device_type
Device type.
Definition ipc_protocol.h:130
List of devices available on the server.
Definition ipc_protocol.h:139
uint32_t device_count
Number of devices.
Definition ipc_protocol.h:141
Pointer-free arguments for creating an xrt_hand_tracker over IPC.
Definition ipc_protocol.h:322
Arguments for xrt_device::get_view_poses with two views.
Definition ipc_protocol.h:401
Data for a single composition layer.
Definition ipc_protocol.h:200
uint32_t xdev_id
Definition ipc_protocol.h:202
Render state for a single client, including all layers.
Definition ipc_protocol.h:224
Definition ipc_protocol.h:422
A big struct that contains all data that is shared to a client, no pointers allowed in this.
Definition ipc_protocol.h:246
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:113
struct xrt_pose offset
Initial offset of the tracking origin.
Definition ipc_protocol.h:116
XRT_ALIGNAS(8) uint64_t xrt_tracking_origin_id_val
The service-side xrt_tracking_origin_id, synchronized to IPC clients so that xrt_tracking_origin::id ...
Information about a tracking origin in the tracking origin list.
Definition ipc_protocol.h:74
uint32_t ipc_id
Tracking origin IPC ID, not xrt_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:306
Describes a projection matrix fov.
Definition xrt_defines.h:555
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:535
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:726
Features supported by a xrt_system_devices as a whole, modeled after xrt_device_supported.
Definition xrt_system.h:221
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:837
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.