Monado OpenXR Runtime
u_device.h
Go to the documentation of this file.
1// Copyright 2019-2025, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Misc helpers for device drivers.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @author Moshi Turner <moshiturner@protonmail.com>
9 * @author Simon Zeni <simon.zeni@collabora.com>
10 * @ingroup aux_util
11 */
12
13#pragma once
14
15#include "xrt/xrt_compiler.h"
16#include "xrt/xrt_device.h"
17#include "xrt/xrt_tracking.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24extern const struct xrt_matrix_2x2 u_device_rotation_right;
25extern const struct xrt_matrix_2x2 u_device_rotation_left;
26extern const struct xrt_matrix_2x2 u_device_rotation_ident;
27extern const struct xrt_matrix_2x2 u_device_rotation_180;
28
29enum u_device_alloc_flags
30{
31 // clang-format off
32 U_DEVICE_ALLOC_NO_FLAGS = 0,
33 U_DEVICE_ALLOC_HMD = 1u << 0u,
34 U_DEVICE_ALLOC_TRACKING_NONE = 1u << 1u,
35 // clang-format on
36};
37
38/*!
39 *
40 * Info to describe 2D extents of a device's screen
41 *
42 */
44{
45 uint32_t w_pixels; // Width of entire screen in pixels
46 uint32_t h_pixels; // Height of entire screen
47};
48
49/*!
50 *
51 * Info to describe a very simple headset with diffractive lens optics.
52 *
53 */
55{
56 struct
57 {
58 uint32_t w_pixels;
59 uint32_t h_pixels;
60 float w_meters;
61 float h_meters;
62 } display;
63
64 float lens_horizontal_separation_meters;
65 float lens_vertical_position_meters;
66
67 float fov[XRT_MAX_VIEWS];
68};
69
70/*!
71 * Setup the device information given a very simple info struct.
72 *
73 * @return true on success.
74 * @ingroup aux_util
75 */
76bool
77u_device_setup_one_eye(struct xrt_device *xdev, const struct u_device_simple_info *info);
78
79/*!
80 * Setup the device information given a very simple info struct.
81 *
82 * @return true on success.
83 * @ingroup aux_util
84 */
85bool
87
88/*!
89 * Setup the device's display's 2D extents.
90 * Good for headsets without traditional VR optics.
91 *
92 * @return true on success.
93 * @ingroup aux_util
94 */
95bool
96u_extents_2d_split_side_by_side(struct xrt_device *xdev, const struct u_extents_2d *extents);
97
98
99/*!
100 * Dump the device config to stderr.
101 *
102 * @ingroup aux_util
103 */
104void
105u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod);
106
107#define U_DEVICE_ALLOCATE(type, flags, input_count, output_count) \
108 ((type *)u_device_allocate(flags, sizeof(type), input_count, output_count))
109
110
111/*!
112 * Helper function to allocate a device plus inputs in the same allocation
113 * placed after the device in memory.
114 *
115 * Will setup any pointers and num values.
116 *
117 * @ingroup aux_util
118 */
119void *
120u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t input_count, size_t output_count);
121
122/*!
123 * Helper function to free a device and any data hanging of it.
124 *
125 * @ingroup aux_util
126 */
127void
128u_device_free(struct xrt_device *xdev);
129
130
131#define XRT_DEVICE_ROLE_UNASSIGNED (-1)
132
133/*!
134 * Helper function to assign head, left hand, right hand, and gamepad roles.
135 *
136 * @ingroup aux_util
137 */
138void
140 struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right, int *gamepad);
141
142/*!
143 * Helper function for `get_view_pose` in an HMD driver.
144 *
145 * Takes in a translation from the left to right eye, and returns a center to left or right eye transform that assumes
146 * the eye relation is symmetrical around the tracked point ("center eye"). Knowing IPD is a subset of this: If you know
147 * IPD better than the overall Monado system, copy @p eye_relation and put your known IPD in @p real_eye_relation->x
148 *
149 * If you have rotation, apply it after calling this function.
150 *
151 * @param eye_relation 3D translation from left eye to right eye.
152 * @param view_index 0 for left, 1 for right.
153 * @param out_pose The output pose to populate. Will receive translation, with an identity rotation.
154 */
155void
156u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose);
157
158
159/*
160 *
161 * Default implementation of functions.
162 *
163 */
164
165/*!
166 * Helper function to implement @ref xrt_device::get_view_poses in a HMD driver.
167 *
168 * The field @ref xrt_device::hmd needs to be set and valid.
169 */
172 const struct xrt_vec3 *default_eye_relation,
173 int64_t at_timestamp_ns,
174 enum xrt_view_type view_type,
175 uint32_t view_count,
176 struct xrt_space_relation *out_head_relation,
177 struct xrt_fov *out_fovs,
178 struct xrt_pose *out_poses);
179
180/*!
181 * Helper function to implement @ref xrt_device::get_visibility_mask in a HMD driver.
182 *
183 * The field @ref xrt_device::hmd needs to be set and valid.
184 */
187 enum xrt_visibility_mask_type type,
188 uint32_t view_index,
189 struct xrt_visibility_mask **out_mask);
190
191/*
192 *
193 * No-op implementation of functions.
194 *
195 */
196
197/*!
198 * Noop function for @ref xrt_device::update_inputs,
199 * should only be used from a device with any inputs.
200 *
201 * @ingroup aux_util
202 */
205
206
207/*
208 *
209 * Not implemented function helpers.
210 *
211 */
212
213/*!
214 * Not implemented function for @ref xrt_device::get_hand_tracking.
215 *
216 * @ingroup aux_util
217 */
220 enum xrt_input_name name,
221 int64_t desired_timestamp_ns,
222 struct xrt_hand_joint_set *out_value,
223 int64_t *out_timestamp_ns);
224
225/*!
226 * Not implemented function for @ref xrt_device::get_face_tracking.
227 *
228 * @ingroup aux_util
229 */
232 enum xrt_input_name facial_expression_type,
233 int64_t at_timestamp_ns,
234 struct xrt_facial_expression_set *out_value);
235
236/*!
237 * Not implemented function for @ref xrt_device::get_body_skeleton.
238 *
239 * @ingroup aux_util
240 */
243 enum xrt_input_name body_tracking_type,
244 struct xrt_body_skeleton *out_value);
245
246/*!
247 * Not implemented function for @ref xrt_device::get_body_joints.
248 *
249 * @ingroup aux_util
250 */
253 enum xrt_input_name body_tracking_type,
254 int64_t desired_timestamp_ns,
255 struct xrt_body_joint_set *out_value);
256
257/*!
258 * Not implemented function for @ref xrt_device::reset_body_tracking_calibration_meta.
259 *
260 * @ingroup aux_util
261 */
264
265/*!
266 * Not implemented function for @ref xrt_device::set_body_tracking_calibration_override_meta.
267 *
268 * @ingroup aux_util
269 */
272
273/*!
274 * Not implemented function for @ref xrt_device::set_output.
275 *
276 * @ingroup aux_util
277 */
279u_device_ni_set_output(struct xrt_device *xdev, enum xrt_output_name name, const struct xrt_output_value *value);
280
281/*!
282 * Not implemented function for @ref xrt_device::get_output_limits.
283 *
284 * @ingroup aux_util
285 */
288
289/*!
290 * Not implemented function for @ref xrt_device::get_presence.
291 *
292 * @ingroup aux_util
293 */
295u_device_ni_get_presence(struct xrt_device *xdev, bool *presence);
296
297/*!
298 * Not implemented function for @ref xrt_device::begin_plane_detection_ext.
299 *
300 * @ingroup aux_util
301 */
304 const struct xrt_plane_detector_begin_info_ext *begin_info,
305 uint64_t plane_detection_id,
306 uint64_t *out_plane_detection_id);
307
308/*!
309 * Not implemented function for @ref xrt_device::destroy_plane_detection_ext.
310 *
311 * @ingroup aux_util
312 */
314u_device_ni_destroy_plane_detection_ext(struct xrt_device *xdev, uint64_t plane_detection_id);
315
316/*!
317 * Not implemented function for @ref xrt_device::get_plane_detection_state_ext.
318 *
319 * @ingroup aux_util
320 */
323 uint64_t plane_detection_id,
324 enum xrt_plane_detector_state_ext *out_state);
325
326/*!
327 * Not implemented function for @ref xrt_device::get_plane_detections_ext.
328 *
329 * @ingroup aux_util
330 */
333 uint64_t plane_detection_id,
334 struct xrt_plane_detections_ext *out_detections);
335
336/*!
337 * Not implemented function for @ref xrt_device::get_view_poses.
338 *
339 * @ingroup aux_util
340 */
343 const struct xrt_vec3 *default_eye_relation,
344 int64_t at_timestamp_ns,
345 enum xrt_view_type view_type,
346 uint32_t view_count,
347 struct xrt_space_relation *out_head_relation,
348 struct xrt_fov *out_fovs,
349 struct xrt_pose *out_poses);
350
351/*!
352 * Not implemented function for @ref xrt_device::compute_distortion.
353 *
354 * @ingroup aux_util
355 */
358 struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result);
359
360/*!
361 * Not implemented function for @ref xrt_device::get_visibility_mask.
362 *
363 * @ingroup aux_util
364 */
367 enum xrt_visibility_mask_type type,
368 uint32_t view_index,
369 struct xrt_visibility_mask **out_mask);
370
371/*!
372 * Not implemented function for @ref xrt_device::ref_space_usage.
373 *
374 * @ingroup aux_util
375 */
378 enum xrt_reference_space_type type,
379 enum xrt_input_name name,
380 bool used);
381
382/*!
383 * Not implemented function for @ref xrt_device::is_form_factor_available.
384 *
385 * @ingroup aux_util
386 */
387bool
389
390/*!
391 * Not implemented function for @ref xrt_device::get_battery_status.
392 *
393 * @ingroup aux_util
394 */
396u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge);
397
398/*!
399 * Not implemented function for @ref xrt_device::get_brightness.
400 *
401 * @ingroup aux_util
402 */
404u_device_ni_get_brightness(struct xrt_device *xdev, float *out_brightness);
405
406/*!
407 * Not implemented function for @ref xrt_device::set_brightness.
408 *
409 * @ingroup aux_util
410 */
412u_device_ni_set_brightness(struct xrt_device *xdev, float brightness, bool relative);
413
414/*!
415 * Not implemented function for @ref xrt_device::begin_feature.
416 *
417 * @ingroup aux_util
418 */
421
422/*!
423 * Not implemented function for @ref xrt_device::end_feature.
424 *
425 * @ingroup aux_util
426 */
429
430
431#ifdef __cplusplus
432}
433#endif
xrt_result_t u_device_ni_get_body_joints(struct xrt_device *xdev, enum xrt_input_name body_tracking_type, int64_t desired_timestamp_ns, struct xrt_body_joint_set *out_value)
Not implemented function for xrt_device::get_body_joints.
Definition: u_device.c:551
xrt_result_t u_device_ni_get_output_limits(struct xrt_device *xdev, struct xrt_output_limits *limits)
Not implemented function for xrt_device::get_output_limits.
Definition: u_device.c:582
xrt_result_t u_device_ni_reset_body_tracking_calibration_meta(struct xrt_device *xdev)
Not implemented function for xrt_device::reset_body_tracking_calibration_meta.
Definition: u_device.c:561
bool u_device_setup_split_side_by_side(struct xrt_device *xdev, const struct u_device_simple_info *info)
Setup the device information given a very simple info struct.
Definition: u_device.c:206
xrt_result_t u_device_ni_get_view_poses(struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, enum xrt_view_type view_type, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
Not implemented function for xrt_device::get_view_poses.
Definition: u_device.c:631
xrt_result_t u_device_ni_set_body_tracking_calibration_override_meta(struct xrt_device *xdev, float new_body_height)
Not implemented function for xrt_device::set_body_tracking_calibration_override_meta.
Definition: u_device.c:568
void u_device_free(struct xrt_device *xdev)
Helper function to free a device and any data hanging of it.
Definition: u_device.c:333
bool u_extents_2d_split_side_by_side(struct xrt_device *xdev, const struct u_extents_2d *extents)
Setup the device's display's 2D extents.
Definition: u_device.c:133
xrt_result_t u_device_ni_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge)
Not implemented function for xrt_device::get_battery_status.
Definition: u_device.c:680
xrt_result_t u_device_ni_get_body_skeleton(struct xrt_device *xdev, enum xrt_input_name body_tracking_type, struct xrt_body_skeleton *out_value)
Not implemented function for xrt_device::get_body_skeleton.
Definition: u_device.c:542
void u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod)
Dump the device config to stderr.
Definition: u_device.c:89
xrt_result_t u_device_ni_get_plane_detections_ext(struct xrt_device *xdev, uint64_t plane_detection_id, struct xrt_plane_detections_ext *out_detections)
Not implemented function for xrt_device::get_plane_detections_ext.
Definition: u_device.c:622
xrt_result_t u_device_ni_compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result)
Not implemented function for xrt_device::compute_distortion.
Definition: u_device.c:645
xrt_result_t u_device_ni_ref_space_usage(struct xrt_device *xdev, enum xrt_reference_space_type type, enum xrt_input_name name, bool used)
Not implemented function for xrt_device::ref_space_usage.
Definition: u_device.c:663
xrt_result_t u_device_ni_get_plane_detection_state_ext(struct xrt_device *xdev, uint64_t plane_detection_id, enum xrt_plane_detector_state_ext *out_state)
Not implemented function for xrt_device::get_plane_detection_state_ext.
Definition: u_device.c:613
bool u_device_setup_one_eye(struct xrt_device *xdev, const struct u_device_simple_info *info)
Setup the device information given a very simple info struct.
Definition: u_device.c:162
void u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right, int *gamepad)
Helper function to assign head, left hand, right hand, and gamepad roles.
Definition: u_device.c:363
xrt_result_t u_device_ni_end_feature(struct xrt_device *xdev, enum xrt_device_feature_type type)
Not implemented function for xrt_device::end_feature.
Definition: u_device.c:708
xrt_result_t u_device_ni_get_visibility_mask(struct xrt_device *xdev, enum xrt_visibility_mask_type type, uint32_t view_index, struct xrt_visibility_mask **out_mask)
Not implemented function for xrt_device::get_visibility_mask.
Definition: u_device.c:653
xrt_result_t u_device_ni_get_hand_tracking(struct xrt_device *xdev, enum xrt_input_name name, int64_t desired_timestamp_ns, struct xrt_hand_joint_set *out_value, int64_t *out_timestamp_ns)
Not implemented function for xrt_device::get_hand_tracking.
Definition: u_device.c:521
xrt_result_t u_device_ni_get_presence(struct xrt_device *xdev, bool *presence)
Not implemented function for xrt_device::get_presence.
Definition: u_device.c:589
xrt_result_t u_device_ni_set_output(struct xrt_device *xdev, enum xrt_output_name name, const struct xrt_output_value *value)
Not implemented function for xrt_device::set_output.
Definition: u_device.c:575
xrt_result_t u_device_ni_get_brightness(struct xrt_device *xdev, float *out_brightness)
Not implemented function for xrt_device::get_brightness.
Definition: u_device.c:687
xrt_result_t u_device_ni_set_brightness(struct xrt_device *xdev, float brightness, bool relative)
Not implemented function for xrt_device::set_brightness.
Definition: u_device.c:694
xrt_result_t u_device_ni_begin_plane_detection_ext(struct xrt_device *xdev, const struct xrt_plane_detector_begin_info_ext *begin_info, uint64_t plane_detection_id, uint64_t *out_plane_detection_id)
Not implemented function for xrt_device::begin_plane_detection_ext.
Definition: u_device.c:596
xrt_result_t u_device_ni_begin_feature(struct xrt_device *xdev, enum xrt_device_feature_type type)
Not implemented function for xrt_device::begin_feature.
Definition: u_device.c:701
bool u_device_ni_is_form_factor_available(struct xrt_device *xdev, enum xrt_form_factor form_factor)
Not implemented function for xrt_device::is_form_factor_available.
Definition: u_device.c:673
xrt_result_t u_device_ni_destroy_plane_detection_ext(struct xrt_device *xdev, uint64_t plane_detection_id)
Not implemented function for xrt_device::destroy_plane_detection_ext.
Definition: u_device.c:606
void * u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t input_count, size_t output_count)
Helper function to allocate a device plus inputs in the same allocation placed after the device in me...
Definition: u_device.c:274
xrt_result_t u_device_noop_update_inputs(struct xrt_device *xdev)
Noop function for xrt_device::update_inputs, should only be used from a device with any inputs.
Definition: u_device.c:505
xrt_result_t u_device_ni_get_face_tracking(struct xrt_device *xdev, enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set *out_value)
Not implemented function for xrt_device::get_face_tracking.
Definition: u_device.c:532
xrt_visibility_mask_type
Visibility mask, mirror of XrVisibilityMaskKHR.
Definition: xrt_defines.h:2173
xrt_form_factor
What form factor is this device, mostly maps onto OpenXR's XrFormFactor.
Definition: xrt_defines.h:2114
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1344
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_reference_space_type
Type of a OpenXR mapped reference space, maps to the semantic spaces on the xrt_space_overseer struct...
Definition: xrt_defines.h:612
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:1974
xrt_plane_detector_state_ext
State of a plane detector, see xrt_device.
Definition: xrt_plane_detector.h:83
Definition: m_space.cpp:87
Info to describe a very simple headset with diffractive lens optics.
Definition: u_device.h:55
Info to describe 2D extents of a device's screen.
Definition: u_device.h:44
Definition: xrt_defines.h:1957
Definition: xrt_defines.h:1914
A single HMD or input device.
Definition: xrt_device.h:284
Definition: xrt_defines.h:1692
Describes a projection matrix fov.
Definition: xrt_defines.h:499
Joint set type used for hand tracking.
Definition: xrt_defines.h:1443
A tightly packed 2x2 matrix of floats.
Definition: xrt_defines.h:526
Output limits of a particular device.
Definition: xrt_device.h:242
A union of all output types.
Definition: xrt_defines.h:2092
Each plane has n polygons; ultimately plane metadata from locations and vetices is reconstructed.
Definition: xrt_plane_detector.h:171
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
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition: xrt_defines.h:279
A 3 element vector with single floats.
Definition: xrt_defines.h:289
Visibility mask helper, the indices and vertices are tightly packed after this struct.
Definition: xrt_visibility_mask.h:25
xrt_result_t u_device_get_visibility_mask(struct xrt_device *xdev, enum xrt_visibility_mask_type type, uint32_t view_index, struct xrt_visibility_mask **out_mask)
Helper function to implement xrt_device::get_visibility_mask in a HMD driver.
Definition: u_device.c:488
xrt_result_t u_device_get_view_poses(struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, int64_t at_timestamp_ns, enum xrt_view_type view_type, uint32_t view_count, struct xrt_space_relation *out_head_relation, struct xrt_fov *out_fovs, struct xrt_pose *out_poses)
Helper function to implement xrt_device::get_view_poses in a HMD driver.
Definition: u_device.c:461
void u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose)
Helper function for get_view_pose in an HMD driver.
Definition: u_device.c:430
Header holding common defines.
xrt_view_type
View type to be rendered to by the compositor.
Definition: xrt_defines.h:2123
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition: xrt_device.h:231
Header defining the tracking system integration in Monado.