Monado OpenXR Runtime
oxr_objects.h
Go to the documentation of this file.
1// Copyright 2018-2024, Collabora, Ltd.
2// Copyright 2023, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief The objects representing OpenXR handles, and prototypes for internal functions used in the state tracker.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Korcan Hussein <korcan.hussein@collabora.com>
9 * @ingroup oxr_main
10 */
11
12#pragma once
13
14#include "xrt/xrt_space.h"
15#include "xrt/xrt_limits.h"
16#include "xrt/xrt_system.h"
17#include "xrt/xrt_device.h"
18#include "xrt/xrt_tracking.h"
19#include "xrt/xrt_compositor.h"
22#include "xrt/xrt_config_os.h"
23#include "xrt/xrt_config_have.h"
24
25#include "os/os_threading.h"
26
27#include "util/u_index_fifo.h"
28#include "util/u_hashset.h"
29#include "util/u_hashmap.h"
30#include "util/u_device.h"
31
33#include "oxr_subaction.h"
34#include "oxr_defines.h"
35#include "oxr_frame_sync.h"
36
37#if defined(XRT_HAVE_D3D11) || defined(XRT_HAVE_D3D12)
38#include <dxgi.h>
39#include <d3dcommon.h>
40#endif
41
42#ifdef XRT_FEATURE_RENDERDOC
43#include "renderdoc_app.h"
44#ifndef XRT_OS_WINDOWS
45#include <dlfcn.h>
46#endif // !XRT_OS_WINDOWS
47#endif // XRT_FEATURE_RENDERDOC
48
49#ifdef XRT_OS_ANDROID
50#include "xrt/xrt_android.h"
51#endif // #ifdef XRT_OS_ANDROID
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57
58/*!
59 * @defgroup oxr OpenXR state tracker
60 *
61 * Client application facing code.
62 *
63 * @ingroup xrt
64 */
65
66/*!
67 * @brief Cast a pointer to an OpenXR handle in such a way as to avoid warnings.
68 *
69 * Avoids -Wpointer-to-int-cast by first casting to the same size int, then
70 * promoting to the 64-bit int, then casting to the handle type. That's a lot of
71 * no-ops on 64-bit, but a widening conversion on 32-bit.
72 *
73 * @ingroup oxr
74 */
75#define XRT_CAST_PTR_TO_OXR_HANDLE(HANDLE_TYPE, PTR) ((HANDLE_TYPE)(uint64_t)(uintptr_t)(PTR))
76
77/*!
78 * @brief Cast an OpenXR handle to a pointer in such a way as to avoid warnings.
79 *
80 * Avoids -Wint-to-pointer-cast by first casting to a 64-bit int, then to a
81 * pointer-sized int, then to the desired pointer type. That's a lot of no-ops
82 * on 64-bit, but a narrowing (!) conversion on 32-bit.
83 *
84 * @ingroup oxr
85 */
86#define XRT_CAST_OXR_HANDLE_TO_PTR(PTR_TYPE, HANDLE) ((PTR_TYPE)(uintptr_t)(uint64_t)(HANDLE))
87
88/*!
89 * @defgroup oxr_main OpenXR main code
90 *
91 * Gets called from @ref oxr_api functions and talks to devices and
92 * @ref comp using @ref xrt_iface.
93 *
94 * @ingroup oxr
95 * @{
96 */
97
98
99/*
100 *
101 * Forward declare structs.
102 *
103 */
104
105struct xrt_instance;
106struct oxr_logger;
108struct oxr_instance;
109struct oxr_system;
110struct oxr_session;
111struct oxr_event;
112struct oxr_swapchain;
113struct oxr_space;
114struct oxr_action_set;
115struct oxr_action;
117struct oxr_handle_base;
121struct oxr_action_input;
122struct oxr_action_output;
123struct oxr_dpad_state;
124struct oxr_binding;
126struct oxr_action_set_ref;
127struct oxr_action_ref;
128struct oxr_hand_tracker;
129struct oxr_facial_tracker_htc;
130struct oxr_face_tracker2_fb;
131struct oxr_body_tracker_fb;
132struct oxr_xdev_list;
133struct oxr_plane_detector_ext;
134
135#define XRT_MAX_HANDLE_CHILDREN 256
136#define OXR_MAX_BINDINGS_PER_ACTION 32
137
138struct time_state;
139
140/*!
141 * Function pointer type for a handle destruction function.
142 *
143 * @relates oxr_handle_base
144 */
145typedef XrResult (*oxr_handle_destroyer)(struct oxr_logger *log, struct oxr_handle_base *hb);
146
147
148
149/*
150 *
151 * Helpers
152 *
153 */
154
155/*!
156 * Safely copy an xrt_pose to an XrPosef.
157 */
158#define OXR_XRT_POSE_TO_XRPOSEF(FROM, TO) \
159 do { \
160 union { \
161 struct xrt_pose xrt; \
162 XrPosef oxr; \
163 } safe_copy = {FROM}; \
164 TO = safe_copy.oxr; \
165 } while (false)
166
167/*!
168 * Safely copy an xrt_fov to an XrFovf.
169 */
170#define OXR_XRT_FOV_TO_XRFOVF(FROM, TO) \
171 do { \
172 union { \
173 struct xrt_fov xrt; \
174 XrFovf oxr; \
175 } safe_copy = {FROM}; \
176 TO = safe_copy.oxr; \
177 } while (false)
178
179
180/*
181 *
182 * oxr_handle_base.c
183 *
184 */
185
186/*!
187 * Destroy the handle's object, as well as all child handles recursively.
188 *
189 * This should be how all handle-associated objects are destroyed.
190 *
191 * @public @memberof oxr_handle_base
192 */
193XrResult
194oxr_handle_destroy(struct oxr_logger *log, struct oxr_handle_base *hb);
195
196/*!
197 * Returns a human-readable label for a handle state.
198 *
199 * @relates oxr_handle_base
200 */
201const char *
203
204/*!
205 *
206 * @name oxr_instance.c
207 * @{
208 *
209 */
210
211/*!
212 * To go back to a OpenXR object.
213 *
214 * @relates oxr_instance
215 */
216static inline XrInstance
218{
219 return XRT_CAST_PTR_TO_OXR_HANDLE(XrInstance, inst);
220}
221
222/*!
223 * Creates a instance, does minimal validation of @p createInfo.
224 *
225 * @param[in] log Logger
226 * @param[in] createInfo OpenXR creation info.
227 * @param[in] extensions Parsed extension list to be enabled.
228 * @param[out] out_inst Pointer to pointer to a instance, returned instance.
229 *
230 * @public @static @memberof oxr_instance
231 */
232XrResult
234 const XrInstanceCreateInfo *createInfo,
235 XrVersion major_minor,
236 const struct oxr_extension_status *extensions,
237 struct oxr_instance **out_inst);
238
239/*!
240 * @public @memberof oxr_instance
241 */
242XrResult
243oxr_instance_get_properties(struct oxr_logger *log,
244 struct oxr_instance *inst,
245 XrInstanceProperties *instanceProperties);
246
247#if XR_USE_TIMESPEC
248
249/*!
250 * @public @memberof oxr_instance
251 */
252XrResult
253oxr_instance_convert_time_to_timespec(struct oxr_logger *log,
254 struct oxr_instance *inst,
255 XrTime time,
256 struct timespec *timespecTime);
257
258/*!
259 * @public @memberof oxr_instance
260 */
261XrResult
262oxr_instance_convert_timespec_to_time(struct oxr_logger *log,
263 struct oxr_instance *inst,
264 const struct timespec *timespecTime,
265 XrTime *time);
266#endif // XR_USE_TIMESPEC
267
268#ifdef XR_USE_PLATFORM_WIN32
269
270/*!
271 * @public @memberof oxr_instance
272 */
273XrResult
274oxr_instance_convert_time_to_win32perfcounter(struct oxr_logger *log,
275 struct oxr_instance *inst,
276 XrTime time,
277 LARGE_INTEGER *win32perfcounterTime);
278
279/*!
280 * @public @memberof oxr_instance
281 */
282XrResult
283oxr_instance_convert_win32perfcounter_to_time(struct oxr_logger *log,
284 struct oxr_instance *inst,
285 const LARGE_INTEGER *win32perfcounterTime,
286 XrTime *time);
287
288#endif // XR_USE_PLATFORM_WIN32
289
290/*!
291 * @}
292 */
293
294/*!
295 *
296 * @name oxr_path.c
297 * @{
298 *
299 */
300
301/*!
302 * Initialize the path system.
303 * @private @memberof oxr_instance
304 */
305XrResult
306oxr_path_init(struct oxr_logger *log, struct oxr_instance *inst);
307
308/*!
309 * @public @memberof oxr_instance
310 */
311bool
312oxr_path_is_valid(struct oxr_logger *log, struct oxr_instance *inst, XrPath path);
313
314/*!
315 * @public @memberof oxr_instance
316 */
317void *
318oxr_path_get_attached(struct oxr_logger *log, struct oxr_instance *inst, XrPath path);
319
320/*!
321 * Get the path for the given string if it exists, or create it if it does not.
322 *
323 * @public @memberof oxr_instance
324 */
325XrResult
327 struct oxr_logger *log, struct oxr_instance *inst, const char *str, size_t length, XrPath *out_path);
328
329/*!
330 * Only get the path for the given string if it exists.
331 *
332 * @public @memberof oxr_instance
333 */
334XrResult
335oxr_path_only_get(struct oxr_logger *log, struct oxr_instance *inst, const char *str, size_t length, XrPath *out_path);
336
337/*!
338 * Get a pointer and length of the internal string.
339 *
340 * The pointer has the same life time as the instance. The length is the number
341 * of valid characters, not including the null termination character (but an
342 * extra null byte is always reserved at the end so can strings can be given
343 * to functions expecting null terminated strings).
344 *
345 * @public @memberof oxr_instance
346 */
347XrResult
349 struct oxr_logger *log, const struct oxr_instance *inst, XrPath path, const char **out_str, size_t *out_length);
350
351/*!
352 * Destroy the path system and all paths that the instance has created.
353 *
354 * @private @memberof oxr_instance
355 */
356void
357oxr_path_destroy(struct oxr_logger *log, struct oxr_instance *inst);
358
359/*!
360 * @}
361 */
362
363/*!
364 * To go back to a OpenXR object.
365 *
366 * @relates oxr_action_set
367 */
368static inline XrActionSet
370{
371 return XRT_CAST_PTR_TO_OXR_HANDLE(XrActionSet, act_set);
372}
373
374/*!
375 * To go back to a OpenXR object.
376 *
377 * @relates oxr_hand_tracker
378 */
379static inline XrHandTrackerEXT
381{
382 return XRT_CAST_PTR_TO_OXR_HANDLE(XrHandTrackerEXT, hand_tracker);
383}
384
385#ifdef OXR_HAVE_EXT_plane_detection
386/*!
387 * To go back to a OpenXR object.
388 *
389 * @relates oxr_plane_detector
390 */
391static inline XrPlaneDetectorEXT
392oxr_plane_detector_to_openxr(struct oxr_plane_detector_ext *plane_detector)
393{
394 return XRT_CAST_PTR_TO_OXR_HANDLE(XrPlaneDetectorEXT, plane_detector);
395}
396#endif // OXR_HAVE_EXT_plane_detection
397
398/*!
399 * To go back to a OpenXR object.
400 *
401 * @relates oxr_action
402 */
403static inline XrAction
405{
406 return XRT_CAST_PTR_TO_OXR_HANDLE(XrAction, act);
407}
408
409#ifdef OXR_HAVE_HTC_facial_tracking
410/*!
411 * To go back to a OpenXR object.
412 *
413 * @relates oxr_facial_tracker_htc
414 */
415static inline XrFacialTrackerHTC
416oxr_facial_tracker_htc_to_openxr(struct oxr_facial_tracker_htc *face_tracker_htc)
417{
418 return XRT_CAST_PTR_TO_OXR_HANDLE(XrFacialTrackerHTC, face_tracker_htc);
419}
420#endif
421
422#ifdef OXR_HAVE_FB_body_tracking
423/*!
424 * To go back to a OpenXR object.
425 *
426 * @relates oxr_facial_tracker_htc
427 */
428static inline XrBodyTrackerFB
429oxr_body_tracker_fb_to_openxr(struct oxr_body_tracker_fb *body_tracker_fb)
430{
431 return XRT_CAST_PTR_TO_OXR_HANDLE(XrBodyTrackerFB, body_tracker_fb);
432}
433#endif
434
435#ifdef OXR_HAVE_FB_face_tracking2
436/*!
437 * To go back to a OpenXR object.
438 *
439 * @relates oxr_face_tracker2_fb
440 */
441static inline XrFaceTracker2FB
442oxr_face_tracker2_fb_to_openxr(struct oxr_face_tracker2_fb *face_tracker2_fb)
443{
444 return XRT_CAST_PTR_TO_OXR_HANDLE(XrFaceTracker2FB, face_tracker2_fb);
445}
446#endif
447/*!
448 *
449 * @name oxr_input.c
450 * @{
451 *
452 */
453
454/*!
455 * Helper function to classify subaction_paths.
456 *
457 * Sets all members of @p subaction_paths ( @ref oxr_subaction_paths ) as
458 * appropriate based on the subaction paths found in the list.
459 *
460 * If no paths are provided, @p subaction_paths->any will be true.
461 *
462 * @return false if an invalid subaction path is provided.
463 *
464 * @public @memberof oxr_instance
465 * @see oxr_subaction_paths
466 */
467bool
469 const struct oxr_instance *inst,
470 uint32_t subaction_path_count,
471 const XrPath *subaction_paths,
472 struct oxr_subaction_paths *subaction_paths_out);
473
474/*!
475 * Find the pose input for the set of subaction_paths
476 *
477 * @public @memberof oxr_session
478 */
479XrResult
481 uint32_t act_key,
482 const struct oxr_subaction_paths *subaction_paths_ptr,
483 struct oxr_action_input **out_input);
484
485/*!
486 * @public @memberof oxr_instance
487 */
488XrResult
489oxr_action_set_create(struct oxr_logger *log,
490 struct oxr_instance *inst,
491 const XrActionSetCreateInfo *createInfo,
492 struct oxr_action_set **out_act_set);
493
494/*!
495 * @public @memberof oxr_action
496 */
497XrResult
498oxr_action_create(struct oxr_logger *log,
499 struct oxr_action_set *act_set,
500 const XrActionCreateInfo *createInfo,
501 struct oxr_action **out_act);
502
503/*!
504 * @public @memberof oxr_session
505 * @see oxr_action_set
506 */
507XrResult
509 struct oxr_session *sess,
510 const XrSessionActionSetsAttachInfo *bindInfo);
511
512
513XrResult
514oxr_session_update_action_bindings(struct oxr_logger *log, struct oxr_session *sess);
515
516/*!
517 * Given an action act_key, look up the @ref oxr_action_attachment of
518 * the associated action in the given Session.
519 *
520 * @private @memberof oxr_session
521 */
522void
523oxr_session_get_action_attachment(struct oxr_session *sess,
524 uint32_t act_key,
525 struct oxr_action_attachment **out_act_attached);
526
527/*!
528 * @public @memberof oxr_session
529 */
530XrResult
532 struct oxr_session *sess,
533 uint32_t countActionSets,
534 const XrActiveActionSet *actionSets,
535 const XrActiveActionSetPrioritiesEXT *activePriorities);
536
537/*!
538 * @public @memberof oxr_session
539 */
540XrResult
541oxr_action_enumerate_bound_sources(struct oxr_logger *log,
542 struct oxr_session *sess,
543 uint32_t act_key,
544 uint32_t sourceCapacityInput,
545 uint32_t *sourceCountOutput,
546 XrPath *sources);
547
548/*!
549 * @public @memberof oxr_session
550 */
551XrResult
552oxr_action_get_boolean(struct oxr_logger *log,
553 struct oxr_session *sess,
554 uint32_t act_key,
555 struct oxr_subaction_paths subaction_paths,
556 XrActionStateBoolean *data);
557
558/*!
559 * @public @memberof oxr_session
560 */
561XrResult
562oxr_action_get_vector1f(struct oxr_logger *log,
563 struct oxr_session *sess,
564 uint32_t act_key,
565 struct oxr_subaction_paths subaction_paths,
566 XrActionStateFloat *data);
567
568/*!
569 * @public @memberof oxr_session
570 */
571XrResult
572oxr_action_get_vector2f(struct oxr_logger *log,
573 struct oxr_session *sess,
574 uint32_t act_key,
575 struct oxr_subaction_paths subaction_paths,
576 XrActionStateVector2f *data);
577/*!
578 * @public @memberof oxr_session
579 */
580XrResult
581oxr_action_get_pose(struct oxr_logger *log,
582 struct oxr_session *sess,
583 uint32_t act_key,
584 struct oxr_subaction_paths subaction_paths,
585 XrActionStatePose *data);
586/*!
587 * @public @memberof oxr_session
588 */
589XrResult
590oxr_action_apply_haptic_feedback(struct oxr_logger *log,
591 struct oxr_session *sess,
592 uint32_t act_key,
593 struct oxr_subaction_paths subaction_paths,
594 const XrHapticBaseHeader *hapticEvent);
595/*!
596 * @public @memberof oxr_session
597 */
598XrResult
599oxr_action_stop_haptic_feedback(struct oxr_logger *log,
600 struct oxr_session *sess,
601 uint32_t act_key,
602 struct oxr_subaction_paths subaction_paths);
603
604/*!
605 * @public @memberof oxr_instance
606 */
607XrResult
608oxr_hand_tracker_create(struct oxr_logger *log,
609 struct oxr_session *sess,
610 const XrHandTrackerCreateInfoEXT *createInfo,
611 struct oxr_hand_tracker **out_hand_tracker);
612
613/*!
614 * @}
615 */
616
617/*!
618 *
619 * @name oxr_binding.c
620 * @{
621 *
622 */
623
624/*!
625 * Find the best matching profile for the given @ref xrt_device.
626 *
627 * @param log Logger.
628 * @param sess Session.
629 * @param xdev Can be null.
630 * @param[out] out_p Returned interaction profile.
631 *
632 * @public @memberof oxr_session
633 */
634void
636 struct oxr_session *sess,
637 struct xrt_device *xdev,
638 struct oxr_interaction_profile **out_p);
639
640void
641oxr_get_profile_for_device_name(struct oxr_logger *log,
642 struct oxr_session *sess,
643 enum xrt_device_name name,
644 struct oxr_interaction_profile **out_p);
645
647oxr_clone_profile(const struct oxr_interaction_profile *src_profile);
648
649/*!
650 * Free all memory allocated by the binding system.
651 *
652 * @public @memberof oxr_instance
653 */
654void
655oxr_binding_destroy_all(struct oxr_logger *log, struct oxr_instance *inst);
656
657/*!
658 * Free all memory allocated by the binding system.
659 *
660 * @public @memberof oxr_instance
661 */
662void
664
665/*!
666 * Find all bindings that is the given action key is bound to.
667 * @public @memberof oxr_interaction_profile
668 */
669void
671 struct oxr_interaction_profile *p,
672 uint32_t key,
673 size_t max_bounding_count,
674 struct oxr_binding **bindings,
675 size_t *out_binding_count);
676
677/*!
678 * @public @memberof oxr_instance
679 */
680XrResult
681oxr_action_suggest_interaction_profile_bindings(struct oxr_logger *log,
682 struct oxr_instance *inst,
683 const XrInteractionProfileSuggestedBinding *suggestedBindings,
684 struct oxr_dpad_state *state);
685
686/*!
687 * @public @memberof oxr_instance
688 */
689XrResult
690oxr_action_get_current_interaction_profile(struct oxr_logger *log,
691 struct oxr_session *sess,
692 XrPath topLevelUserPath,
693 XrInteractionProfileState *interactionProfile);
694
695/*!
696 * @public @memberof oxr_session
697 */
698XrResult
700 struct oxr_session *sess,
701 const XrInputSourceLocalizedNameGetInfo *getInfo,
702 uint32_t bufferCapacityInput,
703 uint32_t *bufferCountOutput,
704 char *buffer);
705
706/*!
707 * @}
708 */
709
710
711/*!
712 *
713 * @name oxr_dpad.c
714 * @{
715 *
716 */
717
718/*!
719 * Initialises a dpad state, has to be zero init before a call to this function.
720 *
721 * @public @memberof oxr_dpad_state_get
722 */
723bool
724oxr_dpad_state_init(struct oxr_dpad_state *state);
725
726/*!
727 * Look for a entry in the state for the given action set key,
728 * returns NULL if no entry has been made for that action set.
729 *
730 * @public @memberof oxr_dpad_state_get
731 */
732struct oxr_dpad_entry *
733oxr_dpad_state_get(struct oxr_dpad_state *state, uint64_t key);
734
735/*!
736 * Look for a entry in the state for the given action set key,
737 * allocates a new entry if none was found.
738 *
739 * @public @memberof oxr_dpad_state_get
740 */
741struct oxr_dpad_entry *
742oxr_dpad_state_get_or_add(struct oxr_dpad_state *state, uint64_t key);
743
744/*!
745 * Frees all state and entries attached to this dpad state.
746 *
747 * @public @memberof oxr_dpad_state_get
748 */
749void
750oxr_dpad_state_deinit(struct oxr_dpad_state *state);
751
752/*!
753 * Clones all oxr_dpad_state
754 * @param dst_dpad_state destination of cloning
755 * @param src_dpad_state source of cloning
756 * @public @memberof oxr_dpad_state_clone
757 */
758bool
759oxr_dpad_state_clone(struct oxr_dpad_state *dst_dpad_state, const struct oxr_dpad_state *src_dpad_state);
760
761
762/*!
763 * @}
764 */
765
766
767/*!
768 *
769 * @name oxr_session.c
770 * @{
771 *
772 */
773
774/*!
775 * To go back to a OpenXR object.
776 *
777 * @relates oxr_session
778 */
779static inline XrSession
781{
782 return XRT_CAST_PTR_TO_OXR_HANDLE(XrSession, sess);
783}
784
785XrResult
786oxr_session_create(struct oxr_logger *log,
787 struct oxr_system *sys,
788 const XrSessionCreateInfo *createInfo,
789 struct oxr_session **out_session);
790
791XrResult
792oxr_session_enumerate_formats(struct oxr_logger *log,
793 struct oxr_session *sess,
794 uint32_t formatCapacityInput,
795 uint32_t *formatCountOutput,
796 int64_t *formats);
797
798/*!
799 * Change the state of the session, queues a event.
800 */
801void
802oxr_session_change_state(struct oxr_logger *log, struct oxr_session *sess, XrSessionState state, XrTime time);
803
804XrResult
805oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSessionBeginInfo *beginInfo);
806
807XrResult
808oxr_session_end(struct oxr_logger *log, struct oxr_session *sess);
809
810XrResult
811oxr_session_request_exit(struct oxr_logger *log, struct oxr_session *sess);
812
813XRT_CHECK_RESULT XrResult
814oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess);
815
816XrResult
817oxr_session_locate_views(struct oxr_logger *log,
818 struct oxr_session *sess,
819 const XrViewLocateInfo *viewLocateInfo,
820 XrViewState *viewState,
821 uint32_t viewCapacityInput,
822 uint32_t *viewCountOutput,
823 XrView *views);
824
825XrResult
826oxr_session_frame_wait(struct oxr_logger *log, struct oxr_session *sess, XrFrameState *frameState);
827
828XrResult
829oxr_session_frame_begin(struct oxr_logger *log, struct oxr_session *sess);
830
831XrResult
832oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const XrFrameEndInfo *frameEndInfo);
833
834XrResult
835oxr_session_hand_joints(struct oxr_logger *log,
836 struct oxr_hand_tracker *hand_tracker,
837 const XrHandJointsLocateInfoEXT *locateInfo,
838 XrHandJointLocationsEXT *locations);
839
840/*
841 * Gets the body pose in the base space.
842 */
843XrResult
844oxr_get_base_body_pose(struct oxr_logger *log,
845 const struct xrt_body_joint_set *body_joint_set,
846 struct oxr_space *base_spc,
847 struct xrt_device *body_xdev,
848 XrTime at_time,
849 struct xrt_space_relation *out_base_body);
850
851XrResult
852oxr_session_apply_force_feedback(struct oxr_logger *log,
853 struct oxr_hand_tracker *hand_tracker,
854 const XrForceFeedbackCurlApplyLocationsMNDX *locations);
855
856#ifdef OXR_HAVE_KHR_android_thread_settings
857XrResult
858oxr_session_android_thread_settings(struct oxr_logger *log,
859 struct oxr_session *sess,
860 XrAndroidThreadTypeKHR threadType,
861 uint32_t threadId);
862#endif // OXR_HAVE_KHR_android_thread_settings
863
864#ifdef OXR_HAVE_KHR_visibility_mask
865XrResult
866oxr_session_get_visibility_mask(struct oxr_logger *log,
867 struct oxr_session *session,
868 XrVisibilityMaskTypeKHR visibilityMaskType,
869 uint32_t viewIndex,
870 XrVisibilityMaskKHR *visibilityMask);
871
872XrResult
873oxr_event_push_XrEventDataVisibilityMaskChangedKHR(struct oxr_logger *log,
874 struct oxr_session *sess,
875 XrViewConfigurationType viewConfigurationType,
876 uint32_t viewIndex);
877#endif // OXR_HAVE_KHR_visibility_mask
878
879#ifdef OXR_HAVE_EXT_performance_settings
880XrResult
881oxr_session_set_perf_level(struct oxr_logger *log,
882 struct oxr_session *sess,
883 XrPerfSettingsDomainEXT domain,
884 XrPerfSettingsLevelEXT level);
885#endif // OXR_HAVE_EXT_performance_settings
886
887/*
888 *
889 * oxr_space.c
890 *
891 */
892
893/*!
894 * To go back to a OpenXR object.
895 */
896static inline XrSpace
898{
899 return XRT_CAST_PTR_TO_OXR_HANDLE(XrSpace, spc);
900}
901
902XrResult
903oxr_space_action_create(struct oxr_logger *log,
904 struct oxr_session *sess,
905 uint32_t key,
906 const XrActionSpaceCreateInfo *createInfo,
907 struct oxr_space **out_space);
908
909XrResult
910oxr_space_get_reference_bounds_rect(struct oxr_logger *log,
911 struct oxr_session *sess,
912 XrReferenceSpaceType referenceSpaceType,
913 XrExtent2Df *bounds);
914
915XrResult
916oxr_space_reference_create(struct oxr_logger *log,
917 struct oxr_session *sess,
918 const XrReferenceSpaceCreateInfo *createInfo,
919 struct oxr_space **out_space);
920
921/*!
922 * Monado special space that always points to a specific @ref xrt_device and
923 * pose, useful when you want to bypass the action binding system for instance.
924 */
925XrResult
927 struct oxr_session *sess,
928 struct xrt_device *xdev,
929 enum xrt_input_name name,
930 const struct xrt_pose *pose,
931 struct oxr_space **out_space);
932
933XrResult
935 struct oxr_logger *log, struct oxr_space *spc, struct oxr_space *baseSpc, XrTime time, XrSpaceLocation *location);
936
937XrResult
938oxr_spaces_locate(struct oxr_logger *log,
939 struct oxr_space **spcs,
940 uint32_t spc_count,
941 struct oxr_space *baseSpc,
942 XrTime time,
943 XrSpaceLocations *locations);
944
945/*!
946 * Locate the @ref xrt_device in the given base space, useful for implementing
947 * hand tracking location look ups and the like.
948 *
949 * @param log Logging struct.
950 * @param xdev Device to locate in the base space.
951 * @param baseSpc Base space where the device is to be located.
952 * @param[in] time Time in OpenXR domain.
953 * @param[out] out_relation Returns T_base_xdev, aka xdev in base space.
954 *
955 * @return Any errors, XR_SUCCESS, pose might not be valid on XR_SUCCESS.
956 */
957XRT_CHECK_RESULT XrResult
959 struct xrt_device *xdev,
960 struct oxr_space *baseSpc,
961 XrTime time,
962 struct xrt_space_relation *out_relation);
963
964
965/*
966 *
967 * oxr_swapchain.c
968 *
969 */
970
971/*!
972 * To go back to a OpenXR object.
973 */
974static inline XrSwapchain
976{
977 return XRT_CAST_PTR_TO_OXR_HANDLE(XrSwapchain, sc);
978}
979
980
981/*
982 *
983 * oxr_messenger.c
984 *
985 */
986
987/*!
988 * To go back to a OpenXR object.
989 */
990static inline XrDebugUtilsMessengerEXT
992{
993 return XRT_CAST_PTR_TO_OXR_HANDLE(XrDebugUtilsMessengerEXT, mssngr);
994}
995
996XrResult
998 struct oxr_instance *inst,
999 const XrDebugUtilsMessengerCreateInfoEXT *,
1000 struct oxr_debug_messenger **out_mssngr);
1001XrResult
1002oxr_destroy_messenger(struct oxr_logger *log, struct oxr_debug_messenger *mssngr);
1003
1004
1005/*
1006 *
1007 * oxr_system.c
1008 *
1009 */
1010
1011XrResult
1012oxr_system_select(struct oxr_logger *log,
1013 struct oxr_system **systems,
1014 uint32_t system_count,
1015 XrFormFactor form_factor,
1016 struct oxr_system **out_selected);
1017
1018XrResult
1019oxr_system_fill_in(struct oxr_logger *log,
1020 struct oxr_instance *inst,
1021 XrSystemId systemId,
1022 uint32_t view_count,
1023 struct oxr_system *sys);
1024
1025XrResult
1026oxr_system_verify_id(struct oxr_logger *log, const struct oxr_instance *inst, XrSystemId systemId);
1027
1028XrResult
1029oxr_system_get_by_id(struct oxr_logger *log,
1030 struct oxr_instance *inst,
1031 XrSystemId systemId,
1032 struct oxr_system **system);
1033
1034XrResult
1035oxr_system_get_properties(struct oxr_logger *log, struct oxr_system *sys, XrSystemProperties *properties);
1036
1037XrResult
1038oxr_system_enumerate_view_confs(struct oxr_logger *log,
1039 struct oxr_system *sys,
1040 uint32_t viewConfigurationTypeCapacityInput,
1041 uint32_t *viewConfigurationTypeCountOutput,
1042 XrViewConfigurationType *viewConfigurationTypes);
1043
1044XrResult
1046 struct oxr_system *sys,
1047 XrViewConfigurationType viewConfigurationType,
1048 uint32_t environmentBlendModeCapacityInput,
1049 uint32_t *environmentBlendModeCountOutput,
1050 XrEnvironmentBlendMode *environmentBlendModes);
1051
1052XrResult
1053oxr_system_get_view_conf_properties(struct oxr_logger *log,
1054 struct oxr_system *sys,
1055 XrViewConfigurationType viewConfigurationType,
1056 XrViewConfigurationProperties *configurationProperties);
1057
1058XrResult
1059oxr_system_enumerate_view_conf_views(struct oxr_logger *log,
1060 struct oxr_system *sys,
1061 XrViewConfigurationType viewConfigurationType,
1062 uint32_t viewCapacityInput,
1063 uint32_t *viewCountOutput,
1064 XrViewConfigurationView *views);
1065
1066bool
1067oxr_system_get_hand_tracking_support(struct oxr_logger *log, struct oxr_instance *inst);
1068
1069bool
1070oxr_system_get_eye_gaze_support(struct oxr_logger *log, struct oxr_instance *inst);
1071
1072bool
1073oxr_system_get_force_feedback_support(struct oxr_logger *log, struct oxr_instance *inst);
1074
1075void
1076oxr_system_get_face_tracking_htc_support(struct oxr_logger *log,
1077 struct oxr_instance *inst,
1078 bool *supports_eye,
1079 bool *supports_lip);
1080
1081void
1082oxr_system_get_face_tracking2_fb_support(struct oxr_logger *log,
1083 struct oxr_instance *inst,
1084 bool *supports_audio,
1085 bool *supports_visual);
1086
1087bool
1088oxr_system_get_body_tracking_fb_support(struct oxr_logger *log, struct oxr_instance *inst);
1089
1090/*
1091 *
1092 * oxr_event.cpp
1093 *
1094 */
1095
1096XrResult
1097oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
1098 struct oxr_session *sess,
1099 XrSessionState state,
1100 XrTime time);
1101
1102XrResult
1103oxr_event_push_XrEventDataInteractionProfileChanged(struct oxr_logger *log, struct oxr_session *sess);
1104
1105XrResult
1106oxr_event_push_XrEventDataReferenceSpaceChangePending(struct oxr_logger *log,
1107 struct oxr_session *sess,
1108 XrReferenceSpaceType referenceSpaceType,
1109 XrTime changeTime,
1110 XrBool32 poseValid,
1111 const XrPosef *poseInPreviousSpace);
1112
1113#ifdef OXR_HAVE_FB_display_refresh_rate
1114XrResult
1115oxr_event_push_XrEventDataDisplayRefreshRateChangedFB(struct oxr_logger *log,
1116 struct oxr_session *sess,
1117 float fromDisplayRefreshRate,
1118 float toDisplayRefreshRate);
1119#endif // OXR_HAVE_FB_display_refresh_rate
1120
1121#ifdef OXR_HAVE_EXTX_overlay
1122XrResult
1123oxr_event_push_XrEventDataMainSessionVisibilityChangedEXTX(struct oxr_logger *log,
1124 struct oxr_session *sess,
1125 bool visible);
1126#endif // OXR_HAVE_EXTX_overlay
1127
1128#ifdef OXR_HAVE_EXT_performance_settings
1129XrResult
1130oxr_event_push_XrEventDataPerfSettingsEXTX(struct oxr_logger *log,
1131 struct oxr_session *sess,
1132 enum xrt_perf_domain domain,
1133 enum xrt_perf_sub_domain subDomain,
1134 enum xrt_perf_notify_level fromLevel,
1135 enum xrt_perf_notify_level toLevel);
1136#endif // OXR_HAVE_EXT_performance_settings
1137/*!
1138 * This clears all pending events refers to the given session.
1139 */
1140XrResult
1141oxr_event_remove_session_events(struct oxr_logger *log, struct oxr_session *sess);
1142
1143/*!
1144 * Will return one event if available, also drain the sessions event queues.
1145 */
1146XrResult
1147oxr_poll_event(struct oxr_logger *log, struct oxr_instance *inst, XrEventDataBuffer *eventData);
1148
1149
1150/*
1151 *
1152 * oxr_xdev.c
1153 *
1154 */
1155
1156void
1157oxr_xdev_destroy(struct xrt_device **xdev_ptr);
1158
1159/*!
1160 * Return true if it finds an input of that name on this device.
1161 */
1162bool
1163oxr_xdev_find_input(struct xrt_device *xdev, enum xrt_input_name name, struct xrt_input **out_input);
1164
1165/*!
1166 * Return true if it finds an output of that name on this device.
1167 */
1168bool
1169oxr_xdev_find_output(struct xrt_device *xdev, enum xrt_output_name name, struct xrt_output **out_output);
1170
1171/*!
1172 * Returns the hand tracking value of the named input from the device.
1173 * Does NOT apply tracking origin offset to each joint.
1174 */
1175void
1177 struct oxr_instance *inst,
1178 struct xrt_device *xdev,
1179 enum xrt_input_name name,
1180 XrTime at_time,
1181 struct xrt_hand_joint_set *out_value);
1182
1183#ifdef OXR_HAVE_MNDX_xdev_space
1184static inline XrXDevListMNDX
1185oxr_xdev_list_to_openxr(struct oxr_xdev_list *sc)
1186{
1187 return XRT_CAST_PTR_TO_OXR_HANDLE(XrXDevListMNDX, sc);
1188}
1189
1190XrResult
1191oxr_xdev_list_create(struct oxr_logger *log,
1192 struct oxr_session *sess,
1193 const XrCreateXDevListInfoMNDX *createInfo,
1194 struct oxr_xdev_list **out_xdl);
1195
1196XrResult
1197oxr_xdev_list_get_properties(struct oxr_logger *log,
1198 struct oxr_xdev_list *xdl,
1199 uint32_t index,
1200 XrXDevPropertiesMNDX *properties);
1201
1202XrResult
1203oxr_xdev_list_space_create(struct oxr_logger *log,
1204 struct oxr_xdev_list *xdl,
1205 const XrCreateXDevSpaceInfoMNDX *createInfo,
1206 uint32_t index,
1207 struct oxr_space **out_space);
1208
1209#endif // OXR_HAVE_MNDX_xdev_space
1210
1211
1212/*
1213 *
1214 * OpenGL, located in various files.
1215 *
1216 */
1217
1218#ifdef XR_USE_GRAPHICS_API_OPENGL
1219#ifdef XR_USE_PLATFORM_XLIB
1220
1221XrResult
1222oxr_session_populate_gl_xlib(struct oxr_logger *log,
1223 struct oxr_system *sys,
1224 XrGraphicsBindingOpenGLXlibKHR const *next,
1225 struct oxr_session *sess);
1226#endif // XR_USE_PLATFORM_XLIB
1227
1228#ifdef XR_USE_PLATFORM_WIN32
1229XrResult
1230oxr_session_populate_gl_win32(struct oxr_logger *log,
1231 struct oxr_system *sys,
1232 XrGraphicsBindingOpenGLWin32KHR const *next,
1233 struct oxr_session *sess);
1234#endif // XR_USE_PLATFORM_WIN32
1235#endif // XR_USE_GRAPHICS_API_OPENGL
1236
1237#if defined(XR_USE_GRAPHICS_API_OPENGL) || defined(XR_USE_GRAPHICS_API_OPENGL_ES)
1238XrResult
1239oxr_swapchain_gl_create(struct oxr_logger * /*log*/,
1240 struct oxr_session *sess,
1241 const XrSwapchainCreateInfo * /*createInfo*/,
1242 struct oxr_swapchain **out_swapchain);
1243
1244#endif // XR_USE_GRAPHICS_API_OPENGL || XR_USE_GRAPHICS_API_OPENGL_ES
1245
1246#if defined(XR_USE_GRAPHICS_API_OPENGL_ES)
1247#if defined(XR_USE_PLATFORM_ANDROID)
1248XrResult
1249oxr_session_populate_gles_android(struct oxr_logger *log,
1250 struct oxr_system *sys,
1251 XrGraphicsBindingOpenGLESAndroidKHR const *next,
1252 struct oxr_session *sess);
1253#endif // XR_USE_PLATFORM_ANDROID
1254#endif // XR_USE_GRAPHICS_API_OPENGL_ES
1255
1256
1257/*
1258 *
1259 * Vulkan, located in various files.
1260 *
1261 */
1262
1263#ifdef XR_USE_GRAPHICS_API_VULKAN
1264
1265XrResult
1266oxr_vk_get_instance_exts(struct oxr_logger *log,
1267 struct oxr_system *sys,
1268 uint32_t namesCapacityInput,
1269 uint32_t *namesCountOutput,
1270 char *namesString);
1271
1272XrResult
1273oxr_vk_get_device_exts(struct oxr_logger *log,
1274 struct oxr_system *sys,
1275 uint32_t namesCapacityInput,
1276 uint32_t *namesCountOutput,
1277 char *namesString);
1278
1279XrResult
1280oxr_vk_get_requirements(struct oxr_logger *log,
1281 struct oxr_system *sys,
1282 XrGraphicsRequirementsVulkanKHR *graphicsRequirements);
1283
1284XrResult
1286 struct oxr_system *sys,
1287 const XrVulkanInstanceCreateInfoKHR *createInfo,
1288 VkInstance *vulkanInstance,
1289 VkResult *vulkanResult);
1290
1291XrResult
1293 struct oxr_system *sys,
1294 const XrVulkanDeviceCreateInfoKHR *createInfo,
1295 VkDevice *vulkanDevice,
1296 VkResult *vulkanResult);
1297
1298XrResult
1299oxr_vk_get_physical_device(struct oxr_logger *log,
1300 struct oxr_instance *inst,
1301 struct oxr_system *sys,
1302 VkInstance vkInstance,
1303 PFN_vkGetInstanceProcAddr getProc,
1304 VkPhysicalDevice *vkPhysicalDevice);
1305
1306XrResult
1307oxr_session_populate_vk(struct oxr_logger *log,
1308 struct oxr_system *sys,
1309 XrGraphicsBindingVulkanKHR const *next,
1310 struct oxr_session *sess);
1311
1312XrResult
1313oxr_swapchain_vk_create(struct oxr_logger * /*log*/,
1314 struct oxr_session *sess,
1315 const XrSwapchainCreateInfo * /*createInfo*/,
1316 struct oxr_swapchain **out_swapchain);
1317
1318#endif
1319
1320
1321/*
1322 *
1323 * EGL, located in various files.
1324 *
1325 */
1326
1327#ifdef XR_USE_PLATFORM_EGL
1328
1329XrResult
1330oxr_session_populate_egl(struct oxr_logger *log,
1331 struct oxr_system *sys,
1332 XrGraphicsBindingEGLMNDX const *next,
1333 struct oxr_session *sess);
1334
1335#endif
1336
1337/*
1338 *
1339 * D3D version independent routines, located in oxr_d3d.cpp
1340 *
1341 */
1342
1343#if defined(XRT_HAVE_D3D11) || defined(XRT_HAVE_D3D12) || defined(XRT_DOXYGEN)
1344/// Common GetRequirements call for D3D11 and D3D12
1345XrResult
1347 struct oxr_system *sys,
1348 LUID *adapter_luid,
1349 D3D_FEATURE_LEVEL *min_feature_level);
1350
1351/// Verify the provided LUID matches the expected one in @p sys
1352XrResult
1353oxr_d3d_check_luid(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid);
1354#endif
1355
1356/*
1357 *
1358 * D3D11, located in various files.
1359 *
1360 */
1361
1362#ifdef XR_USE_GRAPHICS_API_D3D11
1363
1364XrResult
1365oxr_d3d11_get_requirements(struct oxr_logger *log,
1366 struct oxr_system *sys,
1367 XrGraphicsRequirementsD3D11KHR *graphicsRequirements);
1368
1369/**
1370 * @brief Check to ensure the device provided at session create matches the LUID we returned earlier.
1371 *
1372 * @return XR_SUCCESS if the device matches the LUID
1373 */
1374XrResult
1375oxr_d3d11_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D11Device *device);
1376
1377
1378XrResult
1379oxr_session_populate_d3d11(struct oxr_logger *log,
1380 struct oxr_system *sys,
1381 XrGraphicsBindingD3D11KHR const *next,
1382 struct oxr_session *sess);
1383
1384XrResult
1385oxr_swapchain_d3d11_create(struct oxr_logger *,
1386 struct oxr_session *sess,
1387 const XrSwapchainCreateInfo *,
1388 struct oxr_swapchain **out_swapchain);
1389
1390#endif
1391
1392/*
1393 *
1394 * D3D12, located in various files.
1395 *
1396 */
1397
1398#ifdef XR_USE_GRAPHICS_API_D3D12
1399
1400XrResult
1401oxr_d3d12_get_requirements(struct oxr_logger *log,
1402 struct oxr_system *sys,
1403 XrGraphicsRequirementsD3D12KHR *graphicsRequirements);
1404
1405/**
1406 * @brief Check to ensure the device provided at session create matches the LUID we returned earlier.
1407 *
1408 * @return XR_SUCCESS if the device matches the LUID
1409 */
1410XrResult
1411oxr_d3d12_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D12Device *device);
1412
1413
1414XrResult
1415oxr_session_populate_d3d12(struct oxr_logger *log,
1416 struct oxr_system *sys,
1417 XrGraphicsBindingD3D12KHR const *next,
1418 struct oxr_session *sess);
1419
1420XrResult
1421oxr_swapchain_d3d12_create(struct oxr_logger *,
1422 struct oxr_session *sess,
1423 const XrSwapchainCreateInfo *,
1424 struct oxr_swapchain **out_swapchain);
1425
1426#endif
1427
1428/*
1429 *
1430 * Structs
1431 *
1432 */
1433
1434
1435/*!
1436 * Used to hold diverse child handles and ensure orderly destruction.
1437 *
1438 * Each object referenced by an OpenXR handle should have one of these as its
1439 * first element, thus "extending" this class.
1440 */
1442{
1443 //! Magic (per-handle-type) value for debugging.
1444 uint64_t debug;
1445
1446 /*!
1447 * Pointer to this object's parent handle holder, if any.
1448 */
1450
1451 /*!
1452 * Array of children, if any.
1453 */
1454 struct oxr_handle_base *children[XRT_MAX_HANDLE_CHILDREN];
1455
1456 /*!
1457 * Current handle state.
1458 */
1460
1461 /*!
1462 * Destroy the object this handle refers to.
1463 */
1465};
1466
1467/*!
1468 * Single or multiple devices grouped together to form a system that sessions
1469 * can be created from. Might need to open devices to get all
1470 * properties from it, but shouldn't.
1471 *
1472 * Not strictly an object, but an atom.
1473 *
1474 * Valid only within an XrInstance (@ref oxr_instance)
1475 *
1476 * @obj{XrSystemId}
1477 */
1479{
1480 struct oxr_instance *inst;
1481
1482 //! The @ref xrt_iface level system.
1484
1485 //! System devices used in all session types.
1487
1488 //! Space overseer used in all session types.
1490
1491 //! System compositor, used to create session compositors.
1493
1494 XrSystemId systemId;
1495
1496 //! Have the client application called the gfx api requirements func?
1498
1499 XrFormFactor form_factor;
1500 XrViewConfigurationType view_config_type;
1501 XrViewConfigurationView views[2];
1502 uint32_t blend_mode_count;
1503 XrEnvironmentBlendMode blend_modes[3];
1504
1505 XrReferenceSpaceType reference_spaces[5];
1506 uint32_t reference_space_count;
1507
1508 //! Cache of the last known system roles, see @ref xrt_system_roles::generation_id
1510 struct os_mutex sync_actions_mutex;
1511
1512 struct xrt_visibility_mask *visibility_mask[2];
1513
1514#ifdef OXR_HAVE_MNDX_xdev_space
1515 bool supports_xdev_space;
1516#endif
1517
1518#ifdef XR_USE_GRAPHICS_API_VULKAN
1519 //! The instance/device we create when vulkan_enable2 is used
1521 //! The device returned with the last xrGetVulkanGraphicsDeviceKHR or xrGetVulkanGraphicsDevice2KHR call.
1522 //! XR_NULL_HANDLE if neither has been called.
1524
1525 struct
1526 {
1527 // No better place to keep this state.
1528 bool external_fence_fd_enabled;
1529 bool external_semaphore_fd_enabled;
1530 bool timeline_semaphore_enabled;
1531 bool debug_utils_enabled;
1532 bool image_format_list_enabled;
1533 } vk;
1534
1535#endif
1536
1537#if defined(XR_USE_GRAPHICS_API_D3D11) || defined(XR_USE_GRAPHICS_API_D3D12)
1538 LUID suggested_d3d_luid;
1539 bool suggested_d3d_luid_valid;
1540#endif
1541};
1542
1543
1544/*
1545 * Device roles helpers.
1546 */
1547
1548// static roles
1549// clang-format off
1550static inline struct xrt_device *get_role_head(struct oxr_system *sys) {return sys->xsysd->static_roles.head; }
1551static inline struct xrt_device *get_role_eyes(struct oxr_system *sys) {return sys->xsysd->static_roles.eyes; }
1552static inline struct xrt_device *get_role_face(struct oxr_system* sys) { return sys->xsysd->static_roles.face; }
1553static inline struct xrt_device *get_role_body(struct oxr_system* sys) { return sys->xsysd->static_roles.body; }
1554static inline struct xrt_device *get_role_hand_tracking_left(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.left; }
1555static inline struct xrt_device *get_role_hand_tracking_right(struct oxr_system* sys) { return sys->xsysd->static_roles.hand_tracking.right; }
1556// clang-format on
1557
1558// dynamic roles
1559#define MAKE_GET_DYN_ROLES_FN(ROLE) \
1560 static inline struct xrt_device *get_role_##ROLE(struct oxr_system *sys) \
1561 { \
1562 const bool is_locked = 0 == os_mutex_trylock(&sys->sync_actions_mutex); \
1563 const int32_t xdev_idx = sys->dynamic_roles_cache.ROLE; \
1564 if (is_locked) { \
1565 os_mutex_unlock(&sys->sync_actions_mutex); \
1566 } \
1567 if (xdev_idx < 0 || xdev_idx >= (int32_t)ARRAY_SIZE(sys->xsysd->xdevs)) \
1568 return NULL; \
1569 return sys->xsysd->xdevs[xdev_idx]; \
1570 }
1571MAKE_GET_DYN_ROLES_FN(left)
1572MAKE_GET_DYN_ROLES_FN(right)
1573MAKE_GET_DYN_ROLES_FN(gamepad)
1574#undef MAKE_GET_DYN_ROLES_FN
1575
1576#define GET_XDEV_BY_ROLE(SYS, ROLE) (get_role_##ROLE((SYS)))
1577
1578
1579static inline enum xrt_device_name
1580get_role_profile_head(struct oxr_system *sys)
1581{
1582 return XRT_DEVICE_INVALID;
1583}
1584static inline enum xrt_device_name
1585get_role_profile_eyes(struct oxr_system *sys)
1586{
1587 return XRT_DEVICE_INVALID;
1588}
1589static inline enum xrt_device_name
1590get_role_profile_face(struct oxr_system *sys)
1591{
1592 return XRT_DEVICE_INVALID;
1593}
1594static inline enum xrt_device_name
1595get_role_profile_body(struct oxr_system *sys)
1596{
1597 return XRT_DEVICE_INVALID;
1598}
1599static inline enum xrt_device_name
1600get_role_profile_hand_tracking_left(struct oxr_system *sys)
1601{
1602 return XRT_DEVICE_INVALID;
1603}
1604static inline enum xrt_device_name
1605get_role_profile_hand_tracking_right(struct oxr_system *sys)
1606{
1607 return XRT_DEVICE_INVALID;
1608}
1609
1610#define MAKE_GET_DYN_ROLE_PROFILE_FN(ROLE) \
1611 static inline enum xrt_device_name get_role_profile_##ROLE(struct oxr_system *sys) \
1612 { \
1613 const bool is_locked = 0 == os_mutex_trylock(&sys->sync_actions_mutex); \
1614 const enum xrt_device_name profile_name = sys->dynamic_roles_cache.ROLE##_profile; \
1615 if (is_locked) { \
1616 os_mutex_unlock(&sys->sync_actions_mutex); \
1617 } \
1618 return profile_name; \
1619 }
1620MAKE_GET_DYN_ROLE_PROFILE_FN(left)
1621MAKE_GET_DYN_ROLE_PROFILE_FN(right)
1622MAKE_GET_DYN_ROLE_PROFILE_FN(gamepad)
1623#undef MAKE_GET_DYN_ROLES_FN
1624
1625#define GET_PROFILE_NAME_BY_ROLE(SYS, ROLE) (get_role_profile_##ROLE((SYS)))
1626
1627/*
1628 * Extensions helpers.
1629 */
1630
1631#define MAKE_EXT_STATUS(mixed_case, all_caps) bool mixed_case;
1632/*!
1633 * Structure tracking which extensions are enabled for a given instance.
1634 *
1635 * Names are systematic: the extension name with the XR_ prefix removed.
1636 */
1638{
1639 OXR_EXTENSION_SUPPORT_GENERATE(MAKE_EXT_STATUS)
1640};
1641#undef MAKE_EXT_STATUS
1642
1643/*!
1644 * Main object that ties everything together.
1645 *
1646 * No parent type/handle: this is the root handle.
1647 *
1648 * @obj{XrInstance}
1649 * @extends oxr_handle_base
1651struct oxr_instance
1652{
1653 //! Common structure for things referred to by OpenXR handles.
1654 struct oxr_handle_base handle;
1655
1656 struct u_debug_gui *debug_ui;
1657
1658 struct xrt_instance *xinst;
1659
1660 //! Enabled extensions
1662
1663 //! The OpenXR version requested in the app info. It determines the instance's OpenXR version.
1664 struct
1665 {
1666 //! Stores only major.minor version. Simplifies comparisons for e.g. "at least OpenXR 1.1".
1667 XrVersion major_minor;
1669
1670 // Hardcoded single system.
1671 struct oxr_system system;
1672
1673 struct time_state *timekeeping;
1674
1675 struct
1676 {
1677 struct u_hashset *name_store;
1678 struct u_hashset *loc_store;
1679 } action_sets;
1680
1681 //! Path store, for looking up paths.
1682 struct u_hashset *path_store;
1683 //! Mapping from ID to path.
1684 struct oxr_path **path_array;
1685 //! Total length of path array.
1686 size_t path_array_length;
1687 //! Number of paths in the array (0 is always null).
1688 size_t path_num;
1689
1690 // Event queue.
1691 struct
1692 {
1693 struct os_mutex mutex;
1694 struct oxr_event *last;
1695 struct oxr_event *next;
1696 } event;
1697
1698 //! Interaction profile bindings that have been suggested by the client.
1700 size_t profile_count;
1701
1702 struct oxr_session *sessions;
1703
1704 struct
1705 {
1706
1707#define SUBACTION_PATH_MEMBER(X) XrPath X;
1708 OXR_FOR_EACH_SUBACTION_PATH(SUBACTION_PATH_MEMBER)
1709
1710#undef SUBACTION_PATH_MEMBER
1711 } path_cache;
1712
1713 struct
1714 {
1715 struct
1716 {
1717 struct
1718 {
1719 uint32_t major;
1720 uint32_t minor;
1721 uint32_t patch;
1722 const char *name; //< Engine name, not freed.
1723 } engine;
1724 } detected;
1725 } appinfo;
1726
1727 struct
1728 {
1729 //! Unreal has a bug in the VulkanRHI backend.
1731 //! Unreal 4 has a bug calling xrEndSession; the function should just exit
1732 bool skip_end_session;
1733
1734 /*!
1735 * Return XR_ERROR_REFERENCE_SPACE_UNSUPPORTED instead of
1736 * XR_ERROR_VALIDATION_FAILURE in xrCreateReferenceSpace.
1737 */
1739
1740 //! For applications that rely on views being parallel, notably some OpenVR games with OpenComposite.
1741 bool parallel_views;
1742 } quirks;
1743
1744 //! Debug messengers
1745 struct oxr_debug_messenger *messengers[XRT_MAX_HANDLE_CHILDREN];
1746
1747 bool lifecycle_verbose;
1748 bool debug_views;
1749 bool debug_spaces;
1750 bool debug_bindings;
1751
1752#ifdef XRT_FEATURE_RENDERDOC
1753 RENDERDOC_API_1_4_1 *rdoc_api;
1754#endif
1755
1756#ifdef XRT_OS_ANDROID
1757 enum xrt_android_lifecycle_event activity_state;
1758#endif // XRT_OS_ANDROID
1759};
1760
1761/*!
1762 * Object that client program interact with.
1763 *
1764 * Parent type/handle is @ref oxr_instance
1765 *
1766 * @obj{XrSession}
1767 * @extends oxr_handle_base
1768 */
1770{
1771 //! Common structure for things referred to by OpenXR handles.
1772 struct oxr_handle_base handle;
1773 struct oxr_system *sys;
1774
1775 //! What graphics type was this session created with.
1777
1778 //! The @ref xrt_session backing this session.
1780
1781 //! Native compositor that is wrapped by client compositors.
1782 struct xrt_compositor_native *xcn;
1783
1784 struct xrt_compositor *compositor;
1785
1786 struct oxr_session *next;
1787
1788 XrSessionState state;
1789
1790 /*!
1791 * There is a extra state between xrBeginSession has been called and
1792 * the first xrEndFrame has been called. These are to track this.
1793 */
1794 bool has_ended_once;
1795
1796 bool compositor_visible;
1797 bool compositor_focused;
1798
1799 // the number of xrWaitFrame calls that did not yet have a corresponding
1800 // xrEndFrame or xrBeginFrame (discarded frame) call
1801 int active_wait_frames;
1802 struct os_mutex active_wait_frames_lock;
1803
1804 bool frame_started;
1805 bool exiting;
1806
1807 struct
1808 {
1809 int64_t waited;
1810 int64_t begun;
1811 } frame_id;
1812
1813 struct oxr_frame_sync frame_sync;
1814
1815 /*!
1816 * Used to implement precise extra sleeping in wait frame.
1817 */
1819
1820 /*!
1821 * An array of action set attachments that this session owns.
1822 *
1823 * If non-null, this means action sets have been attached to this
1824 * session.
1825 */
1827
1828 /*!
1829 * Length of @ref oxr_session::act_set_attachments.
1830 */
1832
1833 /*!
1834 * A map of action set key to action set attachments.
1835 *
1836 * If non-null, this means action sets have been attached to this
1837 * session, since this map points to elements of
1838 * oxr_session::act_set_attachments
1839 */
1841
1842 /*!
1843 * A map of action key to action attachment.
1844 *
1845 * The action attachments are actually owned by the action set
1846 * attachments, but we own the action set attachments, so this is OK.
1847 *
1848 * If non-null, this means action sets have been attached to this
1849 * session, since this map points to @p oxr_action_attachment members of
1850 * @ref oxr_session::act_set_attachments elements.
1851 */
1853
1854 /*!
1855 * Clone of all suggested binding profiles at the point of action set/session attachment.
1856 * @ref oxr_session_attach_action_sets
1857 */
1859 struct oxr_interaction_profile **profiles_on_attachment;
1860
1861 /*!
1862 * Currently bound interaction profile.
1863 * @{
1864 */
1865
1866#define OXR_PATH_MEMBER(X) XrPath X;
1867
1869#undef OXR_PATH_MEMBER
1870 /*!
1871 * @}
1872 */
1874 /*!
1875 * IPD, to be expanded to a proper 3D relation.
1876 */
1877 float ipd_meters;
1879 /*!
1880 * Frame timing debug output.
1882 bool frame_timing_spew;
1883
1884 //! Extra sleep in wait frame.
1887 /*!
1888 * To pipe swapchain creation to right code.
1889 */
1890 XrResult (*create_swapchain)(struct oxr_logger *,
1891 struct oxr_session *sess,
1892 const XrSwapchainCreateInfo *,
1893 struct oxr_swapchain **);
1894
1895 /*! initial relation of head in "global" space.
1896 * Used as reference for local space. */
1898
1899 bool has_lost;
1900};
1901
1902/*!
1903 * Returns XR_SUCCESS or XR_SESSION_LOSS_PENDING as appropriate.
1905 * @public @memberof oxr_session
1906 */
1907static inline XrResult
1909{
1910 switch (session->state) {
1911 case XR_SESSION_STATE_LOSS_PENDING: return XR_SESSION_LOSS_PENDING;
1912 default: return XR_SUCCESS;
1913 }
1914}
1915
1916/*!
1917 * Returns XR_SUCCESS, XR_SESSION_LOSS_PENDING, or XR_SESSION_NOT_FOCUSED, as
1918 * appropriate.
1920 * @public @memberof oxr_session
1921 */
1922static inline XrResult
1924{
1925 switch (session->state) {
1926 case XR_SESSION_STATE_LOSS_PENDING: return XR_SESSION_LOSS_PENDING;
1927 case XR_SESSION_STATE_FOCUSED: return XR_SUCCESS;
1928 default: return XR_SESSION_NOT_FOCUSED;
1929 }
1930}
1931
1932#ifdef OXR_HAVE_FB_display_refresh_rate
1933XrResult
1934oxr_session_get_display_refresh_rate(struct oxr_logger *log, struct oxr_session *sess, float *displayRefreshRate);
1935
1936XrResult
1937oxr_session_request_display_refresh_rate(struct oxr_logger *log, struct oxr_session *sess, float displayRefreshRate);
1938#endif // OXR_HAVE_FB_display_refresh_rate
1939
1940/*!
1941 * dpad settings we need extracted from XrInteractionProfileDpadBindingEXT
1942 *
1943 * @ingroup oxr_input
1944 */
1945struct oxr_dpad_settings
1946{
1947 float forceThreshold;
1948 float forceThresholdReleased;
1949 float centerRegion;
1950 float wedgeAngle;
1951 bool isSticky;
1952};
1954/*!
1955 * dpad binding extracted from XrInteractionProfileDpadBindingEXT
1956 */
1958{
1959 XrPath binding;
1960 struct oxr_dpad_settings settings;
1961};
1962
1963/*!
1964 * A entry in the dpad state for one action set.
1965 *
1966 * @ingroup oxr_input
1967 */
1968struct oxr_dpad_entry
1969{
1970#ifdef XR_EXT_dpad_binding
1971 struct oxr_dpad_binding_modification dpads[4];
1972 uint32_t dpad_count;
1973#endif
1974
1975 uint64_t key;
1976};
1977
1978/*!
1979 * Holds dpad binding state for a single interaction profile.
1980 *
1981 * @ingroup oxr_input
1982 */
1983struct oxr_dpad_state
1984{
1985 struct u_hashmap_int *uhi;
1986};
1988/*!
1989 * dpad emulation settings from oxr_interaction_profile
1990 */
1991struct oxr_dpad_emulation
1992{
1993 enum oxr_subaction_path subaction_path;
1994 XrPath *paths;
1995 uint32_t path_count;
1996 enum xrt_input_name position;
1997 enum xrt_input_name activate; // Can be zero
1998};
2000/*!
2001 * A single interaction profile.
2002 */
2005 XrPath path;
2006
2007 //! Used to lookup @ref xrt_binding_profile for fallback.
2009
2010 //! Name presented to the user.
2011 const char *localized_name;
2012
2013 struct oxr_binding *bindings;
2014 size_t binding_count;
2015
2016 struct oxr_dpad_emulation *dpads;
2017 size_t dpad_count;
2018
2019 struct oxr_dpad_state dpad_state;
2020};
2022/*!
2023 * Interaction profile binding state.
2024 */
2025struct oxr_binding
2026{
2027 XrPath *paths;
2028 uint32_t path_count;
2029
2030 //! Name presented to the user.
2031 const char *localized_name;
2032
2033 enum oxr_subaction_path subaction_path;
2035 uint32_t key_count;
2036 uint32_t *keys;
2037 //! store which entry in paths was suggested, for each action key
2039
2040 enum xrt_input_name input;
2041 enum xrt_input_name dpad_activate;
2042
2043 enum xrt_output_name output;
2044};
2045
2046/*!
2047 * @defgroup oxr_input OpenXR input
2048 * @ingroup oxr_main
2049 *
2050 * @brief The action-set/action-based input subsystem of OpenXR.
2051 *
2052 *
2053 * Action sets are created as children of the Instance, but are primarily used
2054 * with one or more Sessions. They may be used with multiple sessions at a time,
2055 * so we can't just put the per-session information directly in the action set
2056 * or action. Instead, we have the `_attachment `structures, which mirror the
2057 * action sets and actions but are rooted under the Session:
2058 *
2059 * - For every action set attached to a session, that session owns a @ref
2060 * oxr_action_set_attachment.
2061 * - For each action in those attached action sets, the action set attachment
2062 * owns an @ref oxr_action_attachment.
2063 *
2064 * We go from the public handle to the `_attachment` structure by using a `key`
2065 * value and a hash map: specifically, we look up the
2066 * oxr_action_set::act_set_key and oxr_action::act_key in the session.
2067 *
2068 * ![](monado-input-class-relationships.drawio.svg)
2069 */
2070
2071/*!
2072 * A parsed equivalent of a list of sub-action paths.
2073 *
2074 * If @p any is true, then no paths were provided, which typically means any
2075 * input is acceptable.
2077 * @ingroup oxr_main
2078 * @ingroup oxr_input
2079 */
2081{
2082 bool any;
2083#define OXR_SUBPATH_MEMBER(X) bool X;
2084 OXR_FOR_EACH_SUBACTION_PATH(OXR_SUBPATH_MEMBER)
2085#undef OXR_SUBPATH_MEMBER
2086};
2087
2088/*!
2089 * Helper function to determine if the set of paths in @p a is a subset of the
2090 * paths in @p b.
2091 *
2092 * @public @memberof oxr_subaction_paths
2093 */
2094static inline bool
2096{
2097#define OXR_CHECK_SUBACTION_PATHS(X) \
2098 if (a->X && !b->X) { \
2099 return false; \
2100 }
2101 OXR_FOR_EACH_SUBACTION_PATH(OXR_CHECK_SUBACTION_PATHS)
2102#undef OXR_CHECK_SUBACTION_PATHS
2103 return true;
2104}
2105
2106/*!
2107 * The data associated with the attachment of an Action Set (@ref
2108 * oxr_action_set) to as Session (@ref oxr_session).
2109 *
2110 * This structure has no pointer to the @ref oxr_action_set that created it
2111 * because the application is allowed to destroy an action before the session,
2112 * which should change nothing except not allow the application to use the
2113 * corresponding data anymore.
2114 *
2115 * @ingroup oxr_input
2117 * @see oxr_action_set
2118 */
2120{
2121 //! Owning session.
2123
2124 //! Action set refcounted data
2126
2127 //! Unique key for the session hashmap.
2128 uint32_t act_set_key;
2129
2130 //! Which sub-action paths are requested on the latest sync.
2132
2133 //! An array of action attachments we own.
2135
2136 /*!
2137 * Length of @ref oxr_action_set_attachment::act_attachments.
2138 */
2140};
2141
2142/*!
2143 * De-initialize an action set attachment and its action attachments.
2144 *
2145 * Frees the action attachments, but does not de-allocate the action set
2146 * attachment.
2147 *
2148 * @public @memberof oxr_action_set_attachment
2149 */
2150void
2152
2153
2154/*!
2155 * The state of a action input.
2156 *
2157 * @ingroup oxr_input
2158 *
2159 * @see oxr_action_attachment
2161struct oxr_action_state
2162{
2163 /*!
2164 * The actual value - must interpret using action type
2165 */
2166 union xrt_input_value value;
2167
2168 //! Is this active (bound and providing input)?
2170
2171 // Was this changed.
2172 bool changed;
2173
2174 //! When was this last changed.
2175 XrTime timestamp;
2176};
2177
2178/*!
2179 * A input action pair of a @ref xrt_input and a @ref xrt_device, along with the
2180 * required transform.
2182 * @ingroup oxr_input
2183 *
2184 * @see xrt_device
2185 * @see xrt_input
2186 */
2187struct oxr_action_input
2188{
2189 struct xrt_device *xdev; // Used for poses and transform is null.
2190 struct xrt_input *input; // Ditto
2191 enum xrt_input_name dpad_activate_name; // used to activate dpad emulation if present
2192 struct xrt_input *dpad_activate; // used to activate dpad emulation if present
2193 struct oxr_input_transform *transforms;
2194 size_t transform_count;
2195 XrPath bound_path;
2196};
2197
2198/*!
2199 * A output action pair of a @ref xrt_output_name and a @ref xrt_device.
2201 * @ingroup oxr_input
2202 *
2203 * @see xrt_device
2204 * @see xrt_output_name
2205 */
2206struct oxr_action_output
2207{
2208 struct xrt_device *xdev;
2209 enum xrt_output_name name;
2210 XrPath bound_path;
2211};
2212
2213
2214/*!
2215 * The set of inputs/outputs for a single sub-action path for an action.
2216 *
2217 * Each @ref oxr_action_attachment has one of these for every known sub-action
2218 * path in the spec. Many, or even most, will be "empty".
2219 *
2220 * A single action will either be input or output, not both.
2221 *
2222 * @ingroup oxr_input
2223 *
2224 * @see oxr_action_attachment
2225 */
2226struct oxr_action_cache
2227{
2228 struct oxr_action_state current;
2229
2230 size_t input_count;
2231 struct oxr_action_input *inputs;
2232
2233 int64_t stop_output_time;
2234 size_t output_count;
2235 struct oxr_action_output *outputs;
2236};
2237
2238/*!
2239 * Data associated with an Action that has been attached to a Session.
2240 *
2241 * More information on the action vs action attachment and action set vs action
2242 * set attachment parallel is in the docs for @ref oxr_input
2243 *
2244 * @ingroup oxr_input
2246 * @see oxr_action
2247 */
2249{
2250 //! The owning action set attachment
2252
2253 //! This action's refcounted data
2254 struct oxr_action_ref *act_ref;
2255
2256 /*!
2257 * The corresponding session.
2258 *
2259 * This will always be valid: the session outlives this object because
2260 * it owns act_set_attached.
2261 */
2262 struct oxr_session *sess;
2263
2264 //! Unique key for the session hashmap.
2265 uint32_t act_key;
2266
2268 /*!
2269 * For pose actions any subaction paths are special treated, at bind
2270 * time we pick one subaction path and stick to it as long as the action
2271 * lives.
2272 */
2274
2275 struct oxr_action_state any_state;
2276
2277#define OXR_CACHE_MEMBER(X) struct oxr_action_cache X;
2278 OXR_FOR_EACH_SUBACTION_PATH(OXR_CACHE_MEMBER)
2279#undef OXR_CACHE_MEMBER
2280};
2281
2282/*!
2283 * @}
2284 */
2285
2286
2287static inline bool
2288oxr_space_type_is_reference(enum oxr_space_type space_type)
2289{
2290 switch (space_type) {
2291 case OXR_SPACE_TYPE_REFERENCE_VIEW:
2292 case OXR_SPACE_TYPE_REFERENCE_LOCAL:
2293 case OXR_SPACE_TYPE_REFERENCE_LOCAL_FLOOR:
2294 case OXR_SPACE_TYPE_REFERENCE_STAGE:
2295 case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT:
2296 case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO:
2297 case OXR_SPACE_TYPE_REFERENCE_LOCALIZATION_MAP_ML:
2298 // These are reference spaces.
2299 return true;
2300
2301 case OXR_SPACE_TYPE_ACTION:
2302 case OXR_SPACE_TYPE_XDEV_POSE:
2303 // These are not reference spaces.
2304 return false;
2305 }
2306
2307 // Handles invalid value.
2308 return false;
2309}
2310
2311
2312/*!
2313 * Can be one of several reference space types, or a space that is bound to an
2314 * action.
2315 *
2316 * Parent type/handle is @ref oxr_session
2318 * @obj{XrSpace}
2319 * @extends oxr_handle_base
2321struct oxr_space
2322{
2323 //! Common structure for things referred to by OpenXR handles.
2324 struct oxr_handle_base handle;
2325
2326 //! Owner of this space.
2327 struct oxr_session *sess;
2328
2329 //! Pose that was given during creation.
2330 struct xrt_pose pose;
2331
2332 //! Action key from which action this space was created from.
2333 uint32_t act_key;
2334
2335 //! What kind of space is this?
2337
2338 //! Which sub action path is this?
2340
2341 struct
2342 {
2343 struct xrt_space *xs;
2344 struct xrt_device *xdev;
2345 enum xrt_input_name name;
2346 } action;
2347
2348 struct
2349 {
2350 struct xrt_space *xs;
2351 } xdev_pose;
2352};
2353
2354/*!
2355 * A set of images used for rendering.
2356 *
2357 * Parent type/handle is @ref oxr_session
2359 * @obj{XrSwapchain}
2360 * @extends oxr_handle_base
2362struct oxr_swapchain
2363{
2364 //! Common structure for things referred to by OpenXR handles.
2365 struct oxr_handle_base handle;
2366
2367 //! Owner of this swapchain.
2368 struct oxr_session *sess;
2369
2370 //! Compositor swapchain.
2371 struct xrt_swapchain *swapchain;
2372
2373 //! Swapchain size.
2374 uint32_t width, height;
2375
2376 //! For 1 is 2D texture, greater then 1 2D array texture.
2377 uint32_t array_layer_count;
2378
2379 //! The number of cubemap faces. 6 for cubemaps, 1 otherwise.
2380 uint32_t face_count;
2381
2382 struct
2383 {
2384 enum oxr_image_state state;
2385 } images[XRT_MAX_SWAPCHAIN_IMAGES];
2386
2387 struct
2388 {
2389 size_t num;
2390 struct u_index_fifo fifo;
2391 } acquired;
2392
2393 struct
2394 {
2395 bool yes;
2396 int index;
2397 } inflight; // This is the image that the app is working on.
2398
2399 struct
2400 {
2401 bool yes;
2402 int index;
2403 } released;
2404
2405 // Is this a static swapchain, needed for acquire semantics.
2406 bool is_static;
2407
2408
2409 XrResult (*destroy)(struct oxr_logger *, struct oxr_swapchain *);
2410
2411 XrResult (*enumerate_images)(struct oxr_logger *,
2412 struct oxr_swapchain *,
2413 uint32_t,
2414 XrSwapchainImageBaseHeader *);
2415
2416 XrResult (*acquire_image)(struct oxr_logger *,
2417 struct oxr_swapchain *,
2418 const XrSwapchainImageAcquireInfo *,
2419 uint32_t *);
2420
2421 XrResult (*wait_image)(struct oxr_logger *, struct oxr_swapchain *, const XrSwapchainImageWaitInfo *);
2422
2423 XrResult (*release_image)(struct oxr_logger *, struct oxr_swapchain *, const XrSwapchainImageReleaseInfo *);
2424};
2425
2426struct oxr_refcounted
2427{
2428 struct xrt_reference base;
2429 //! Destruction callback
2430 void (*destroy)(struct oxr_refcounted *);
2431};
2432
2433/*!
2434 * Increase the reference count of @p orc.
2435 */
2436static inline void
2438{
2440}
2441
2442/*!
2443 * Decrease the reference count of @p orc, destroying it if it reaches 0.
2444 */
2445static inline void
2447{
2448 if (xrt_reference_dec_and_is_zero(&orc->base)) {
2449 orc->destroy(orc);
2450 }
2451}
2452
2453/*!
2454 * The reference-counted data of an action set.
2455 *
2456 * One or more sessions may still need this data after the application destroys
2457 * its XrActionSet handle, so this data is refcounted.
2458 *
2459 * @ingroup oxr_input
2460 *
2461 * @see oxr_action_set
2462 * @extends oxr_refcounted
2463 */
2464struct oxr_action_set_ref
2465{
2466 struct oxr_refcounted base;
2467
2468 //! Application supplied name of this action.
2469 char name[XR_MAX_ACTION_SET_NAME_SIZE];
2470
2471 /*!
2472 * Has this action set even been attached to any session, marking it as
2473 * immutable.
2475 bool ever_attached;
2476
2477 //! Unique key for the session hashmap.
2478 uint32_t act_set_key;
2479
2480 //! Application supplied action set priority.
2481 uint32_t priority;
2482
2483 struct
2484 {
2485 struct u_hashset *name_store;
2486 struct u_hashset *loc_store;
2487 } actions;
2488
2489 struct oxr_subaction_paths permitted_subaction_paths;
2490};
2491
2492/*!
2493 * A group of actions.
2494 *
2495 * Parent type/handle is @ref oxr_instance
2496 *
2497 * Note, however, that an action set must be "attached" to a session
2498 * ( @ref oxr_session ) to be used and not just configured.
2499 * The corresponding data is in @ref oxr_action_set_attachment.
2500 *
2501 * @ingroup oxr_input
2503 * @obj{XrActionSet}
2504 * @extends oxr_handle_base
2506struct oxr_action_set
2507{
2508 //! Common structure for things referred to by OpenXR handles.
2509 struct oxr_handle_base handle;
2510
2511 //! Owner of this action set.
2512 struct oxr_instance *inst;
2513
2514 /*!
2515 * The data for this action set that must live as long as any session we
2516 * are attached to.
2517 */
2518 struct oxr_action_set_ref *data;
2520
2521 /*!
2522 * Unique key for the session hashmap.
2523 *
2524 * Duplicated from oxr_action_set_ref::act_set_key for efficiency.
2526 uint32_t act_set_key;
2527
2528 //! The item in the name hashset.
2529 struct u_hashset_item *name_item;
2530
2531 //! The item in the localized hashset.
2532 struct u_hashset_item *loc_item;
2533};
2534
2535/*!
2536 * The reference-counted data of an action.
2537 *
2538 * One or more sessions may still need this data after the application destroys
2539 * its XrAction handle, so this data is refcounted.
2540 *
2541 * @ingroup oxr_input
2542 *
2543 * @see oxr_action
2544 * @extends oxr_refcounted
2545 */
2546struct oxr_action_ref
2548 struct oxr_refcounted base;
2549
2550 //! Application supplied name of this action.
2551 char name[XR_MAX_ACTION_NAME_SIZE];
2552
2553 //! Unique key for the session hashmap.
2554 uint32_t act_key;
2555
2556 //! Type this action was created with.
2557 XrActionType action_type;
2558
2559 //! Which sub action paths that this action was created with.
2561};
2562
2563/*!
2564 * A single action.
2565 *
2566 * Parent type/handle is @ref oxr_action_set
2567 *
2568 * For actual usage, an action is attached to a session: the corresponding data
2569 * is in @ref oxr_action_attachment
2570 *
2571 * @ingroup oxr_input
2573 * @obj{XrAction}
2574 * @extends oxr_handle_base
2576struct oxr_action
2577{
2578 //! Common structure for things referred to by OpenXR handles.
2580
2581 //! Owner of this action.
2582 struct oxr_action_set *act_set;
2583
2584 //! The data for this action that must live as long as any session we
2585 //! are attached to.
2587
2588 /*!
2589 * Unique key for the session hashmap.
2590 *
2591 * Duplicated from oxr_action_ref::act_key for efficiency.
2593 uint32_t act_key;
2594
2595 //! The item in the name hashset.
2596 struct u_hashset_item *name_item;
2597
2598 //! The item in the localized hashset.
2599 struct u_hashset_item *loc_item;
2600};
2601
2603 * Debug object created by the client program.
2604 *
2605 * Parent type/handle is @ref oxr_instance
2606 *
2607 * @obj{XrDebugUtilsMessengerEXT}
2610{
2611 //! Common structure for things referred to by OpenXR handles.
2612 struct oxr_handle_base handle;
2613
2614 //! Owner of this messenger.
2615 struct oxr_instance *inst;
2616
2617 //! Severities to submit to this messenger
2618 XrDebugUtilsMessageSeverityFlagsEXT message_severities;
2619
2620 //! Types to submit to this messenger
2621 XrDebugUtilsMessageTypeFlagsEXT message_types;
2622
2623 //! Callback function
2624 PFN_xrDebugUtilsMessengerCallbackEXT user_callback;
2625
2626 //! Opaque user data
2627 void *XR_MAY_ALIAS user_data;
2628};
2629
2630/*!
2631 * A hand tracker.
2633 * Parent type/handle is @ref oxr_instance
2634 *
2636 * @obj{XrHandTrackerEXT}
2637 * @extends oxr_handle_base
2639struct oxr_hand_tracker
2640{
2641 //! Common structure for things referred to by OpenXR handles.
2642 struct oxr_handle_base handle;
2643
2644 //! Owner of this hand tracker.
2645 struct oxr_session *sess;
2646
2647 //! xrt_device backing this hand tracker
2648 struct xrt_device *xdev;
2649
2650 //! the input name associated with this hand tracker
2652
2653 XrHandEXT hand;
2654 XrHandJointSetEXT hand_joint_set;
2655};
2656
2657#ifdef OXR_HAVE_FB_passthrough
2658
2659struct oxr_passthrough
2660{
2661 struct oxr_handle_base handle;
2662
2663 struct oxr_session *sess;
2664
2665 XrPassthroughFlagsFB flags;
2666
2667 bool paused;
2668};
2669
2670struct oxr_passthrough_layer
2671{
2672 struct oxr_handle_base handle;
2673
2674 struct oxr_session *sess;
2675
2676 XrPassthroughFB passthrough;
2677
2678 XrPassthroughFlagsFB flags;
2679
2680 XrPassthroughLayerPurposeFB purpose;
2681
2682 bool paused;
2683
2684 XrPassthroughStyleFB style;
2685 XrPassthroughColorMapMonoToRgbaFB monoToRgba;
2686 XrPassthroughColorMapMonoToMonoFB monoToMono;
2687 XrPassthroughBrightnessContrastSaturationFB brightnessContrastSaturation;
2688};
2689
2690XrResult
2691oxr_passthrough_create(struct oxr_logger *log,
2692 struct oxr_session *sess,
2693 const XrPassthroughCreateInfoFB *createInfo,
2694 struct oxr_passthrough **out_passthrough);
2695
2696XrResult
2697oxr_passthrough_layer_create(struct oxr_logger *log,
2698 struct oxr_session *sess,
2699 const XrPassthroughLayerCreateInfoFB *createInfo,
2700 struct oxr_passthrough_layer **out_layer);
2701
2702static inline XrPassthroughFB
2703oxr_passthrough_to_openxr(struct oxr_passthrough *passthrough)
2704{
2705 return XRT_CAST_PTR_TO_OXR_HANDLE(XrPassthroughFB, passthrough);
2706}
2707
2708static inline XrPassthroughLayerFB
2709oxr_passthrough_layer_to_openxr(struct oxr_passthrough_layer *passthroughLayer)
2710{
2711 return XRT_CAST_PTR_TO_OXR_HANDLE(XrPassthroughLayerFB, passthroughLayer);
2712}
2713
2714XrResult
2715oxr_event_push_XrEventDataPassthroughStateChangedFB(struct oxr_logger *log,
2716 struct oxr_session *sess,
2717 XrPassthroughStateChangedFlagsFB flags);
2718
2719#endif // OXR_HAVE_FB_passthrough
2720
2721#ifdef OXR_HAVE_HTC_facial_tracking
2722/*!
2723 * HTC specific Facial tracker.
2724 *
2725 * Parent type/handle is @ref oxr_instance
2726 *
2727 *
2728 * @obj{XrFacialTrackerHTC}
2729 * @extends oxr_handle_base
2730 */
2731struct oxr_facial_tracker_htc
2732{
2733 //! Common structure for things referred to by OpenXR handles.
2734 struct oxr_handle_base handle;
2735
2736 //! Owner of this face tracker.
2737 struct oxr_session *sess;
2738
2739 //! xrt_device backing this face tracker
2740 struct xrt_device *xdev;
2741
2742 //! Type of facial tracking, eyes or lips
2743 enum xrt_facial_tracking_type_htc facial_tracking_type;
2744};
2745
2746XrResult
2747oxr_facial_tracker_htc_create(struct oxr_logger *log,
2748 struct oxr_session *sess,
2749 const XrFacialTrackerCreateInfoHTC *createInfo,
2750 struct oxr_facial_tracker_htc **out_face_tracker_htc);
2751
2752XrResult
2753oxr_get_facial_expressions_htc(struct oxr_logger *log,
2754 struct oxr_facial_tracker_htc *facial_tracker_htc,
2755 XrFacialExpressionsHTC *facialExpressions);
2756#endif
2757
2758#ifdef OXR_HAVE_FB_body_tracking
2759/*!
2760 * FB specific Body tracker.
2761 *
2762 * Parent type/handle is @ref oxr_instance
2763 *
2764 * @obj{XrBodyTrackerFB}
2765 * @extends oxr_handle_base
2766 */
2767struct oxr_body_tracker_fb
2768{
2769 //! Common structure for things referred to by OpenXR handles.
2770 struct oxr_handle_base handle;
2771
2772 //! Owner of this face tracker.
2773 struct oxr_session *sess;
2774
2775 //! xrt_device backing this face tracker
2776 struct xrt_device *xdev;
2777
2778 //! Type of the body joint set e.g. XR_FB_body_tracking or XR_META_body_tracking_full_body
2779 enum xrt_body_joint_set_type_fb joint_set_type;
2780};
2781
2782XrResult
2783oxr_create_body_tracker_fb(struct oxr_logger *log,
2784 struct oxr_session *sess,
2785 const XrBodyTrackerCreateInfoFB *createInfo,
2786 struct oxr_body_tracker_fb **out_body_tracker_fb);
2787
2788XrResult
2789oxr_get_body_skeleton_fb(struct oxr_logger *log,
2790 struct oxr_body_tracker_fb *body_tracker_fb,
2791 XrBodySkeletonFB *skeleton);
2792
2793XrResult
2794oxr_locate_body_joints_fb(struct oxr_logger *log,
2795 struct oxr_body_tracker_fb *body_tracker_fb,
2796 struct oxr_space *base_spc,
2797 const XrBodyJointsLocateInfoFB *locateInfo,
2798 XrBodyJointLocationsFB *locations);
2799#endif
2800
2801#ifdef OXR_HAVE_FB_face_tracking2
2802/*!
2803 * FB specific Face tracker2.
2804 *
2805 * Parent type/handle is @ref oxr_instance
2806 *
2807 * @obj{XrFaceTracker2FB}
2808 * @extends oxr_handle_base
2809 */
2810struct oxr_face_tracker2_fb
2811{
2812 //! Common structure for things referred to by OpenXR handles.
2813 struct oxr_handle_base handle;
2814
2815 //! Owner of this face tracker.
2816 struct oxr_session *sess;
2817
2818 //! xrt_device backing this face tracker
2819 struct xrt_device *xdev;
2820
2821 bool audio_enabled;
2822 bool visual_enabled;
2823};
2824
2825XrResult
2826oxr_face_tracker2_fb_create(struct oxr_logger *log,
2827 struct oxr_session *sess,
2828 const XrFaceTrackerCreateInfo2FB *createInfo,
2829 struct oxr_face_tracker2_fb **out_face_tracker2_fb);
2830
2831XrResult
2832oxr_get_face_expression_weights2_fb(struct oxr_logger *log,
2833 struct oxr_face_tracker2_fb *face_tracker2_fb,
2834 const XrFaceExpressionInfo2FB *expression_info,
2835 XrFaceExpressionWeights2FB *expression_weights);
2836#endif
2837
2838#ifdef OXR_HAVE_MNDX_xdev_space
2839/*!
2840 * Object that holds a list of the current @ref xrt_devices.
2841 *
2842 * Parent type/handle is @ref oxr_session
2843 *
2844 * @obj{XrXDevList}
2845 * @extends oxr_handle_base
2846 */
2847struct oxr_xdev_list
2848{
2849 //! Common structure for things referred to by OpenXR handles.
2850 struct oxr_handle_base handle;
2851
2852 //! Owner of this @ref xrt_device list.
2853 struct oxr_session *sess;
2854
2855 //! Monotonically increasing number.
2856 uint64_t generation_number;
2857
2858 uint64_t ids[XRT_SYSTEM_MAX_DEVICES];
2859 struct xrt_device *xdevs[XRT_SYSTEM_MAX_DEVICES];
2861
2862 //! Counts ids, names and xdevs.
2863 uint32_t device_count;
2864};
2865#endif // OXR_HAVE_MNDX_xdev_space
2866
2867#ifdef OXR_HAVE_EXT_plane_detection
2868/*!
2869 * A Plane Detector.
2870 *
2871 * Parent type/handle is @ref oxr_session
2872 *
2873 *
2874 * @obj{XrPlaneDetectorEXT}
2875 * @extends oxr_handle_base
2876 */
2877struct oxr_plane_detector_ext
2878{
2879 //! Common structure for things referred to by OpenXR handles.
2880 struct oxr_handle_base handle;
2881
2882 //! Owner of this anchor.
2883 struct oxr_session *sess;
2884
2885 //! Plane detector flags.
2887
2888 //! The last known state of this plane detector.
2889 XrPlaneDetectionStateEXT state;
2890
2891 //! Whether the last DONE plane detection has been retrieved from the xdev.
2892 bool retrieved;
2893
2894 //! The device that this plane detector belongs to.
2895 struct xrt_device *xdev;
2896
2897 //! Detected planes. xrt_plane_detector_locations_ext::relation is kept in xdev space and not updated.
2898 struct xrt_plane_detections_ext detections;
2899
2900 //! Corresponds to xrt_plane_detections_ext::locations, but with OpenXR types and transformed into target space.
2901 //! Enables two call idiom.
2902 XrPlaneDetectorLocationEXT *xr_locations;
2903
2904 //! A globally unique id for the current plane detection or 0, generated by the xrt_device.
2905 uint64_t detection_id;
2906};
2907#endif // OXR_HAVE_EXT_plane_detection
2908
2909/*!
2910 * @}
2911 */
2912
2913
2914#ifdef __cplusplus
2915}
2916#endif
void oxr_action_set_attachment_teardown(struct oxr_action_set_attachment *act_set_attached)
De-initialize an action set attachment and its action attachments.
Definition: oxr_input.c:222
void oxr_binding_find_bindings_from_key(struct oxr_logger *log, struct oxr_interaction_profile *p, uint32_t key, size_t max_bounding_count, struct oxr_binding **bindings, size_t *out_binding_count)
Find all bindings that is the given action key is bound to.
Definition: oxr_binding.c:399
static void oxr_refcounted_unref(struct oxr_refcounted *orc)
Decrease the reference count of orc, destroying it if it reaches 0.
Definition: oxr_objects.h:2439
XrResult oxr_poll_event(struct oxr_logger *log, struct oxr_instance *inst, XrEventDataBuffer *eventData)
Will return one event if available, also drain the sessions event queues.
Definition: oxr_event.c:379
XrResult oxr_spaces_locate(struct oxr_logger *log, struct oxr_space **spcs, uint32_t spc_count, struct oxr_space *baseSpc, XrTime time, XrSpaceLocations *locations)
Definition: oxr_space.c:291
XrResult oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSessionBeginInfo *beginInfo)
Definition: oxr_session.c:207
static XrSwapchain oxr_swapchain_to_openxr(struct oxr_swapchain *sc)
To go back to a OpenXR object.
Definition: oxr_objects.h:975
oxr_image_state
Tracks the state of a image that belongs to a oxr_swapchain.
Definition: oxr_defines.h:92
XrResult oxr_path_get_or_create(struct oxr_logger *log, struct oxr_instance *inst, const char *str, size_t length, XrPath *out_path)
Get the path for the given string if it exists, or create it if it does not.
Definition: oxr_path.c:172
XrResult oxr_d3d_check_luid(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid)
Verify the provided LUID matches the expected one in sys.
Definition: oxr_d3d.cpp:80
XrResult oxr_system_enumerate_blend_modes(struct oxr_logger *log, struct oxr_system *sys, XrViewConfigurationType viewConfigurationType, uint32_t environmentBlendModeCapacityInput, uint32_t *environmentBlendModeCountOutput, XrEnvironmentBlendMode *environmentBlendModes)
Definition: oxr_system.c:540
XrResult oxr_handle_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
Destroy the handle's object, as well as all child handles recursively.
Definition: oxr_handle_base.c:197
XrResult oxr_event_remove_session_events(struct oxr_logger *log, struct oxr_session *sess)
This clears all pending events refers to the given session.
Definition: oxr_event.c:347
static XrResult oxr_session_success_result(struct oxr_session *session)
Returns XR_SUCCESS or XR_SESSION_LOSS_PENDING as appropriate.
Definition: oxr_objects.h:1904
XrResult oxr_action_get_pose_input(struct oxr_session *sess, uint32_t act_key, const struct oxr_subaction_paths *subaction_paths_ptr, struct oxr_action_input **out_input)
Find the pose input for the set of subaction_paths.
Definition: oxr_input.c:473
static XrResult oxr_session_success_focused_result(struct oxr_session *session)
Returns XR_SUCCESS, XR_SESSION_LOSS_PENDING, or XR_SESSION_NOT_FOCUSED, as appropriate.
Definition: oxr_objects.h:1919
XrResult oxr_path_only_get(struct oxr_logger *log, struct oxr_instance *inst, const char *str, size_t length, XrPath *out_path)
Only get the path for the given string if it exists.
Definition: oxr_path.c:199
XrResult oxr_space_xdev_pose_create(struct oxr_logger *log, struct oxr_session *sess, struct xrt_device *xdev, enum xrt_input_name name, const struct xrt_pose *pose, struct oxr_space **out_space)
Monado special space that always points to a specific xrt_device and pose, useful when you want to by...
Definition: oxr_space.c:238
void oxr_find_profile_for_device(struct oxr_logger *log, struct oxr_session *sess, struct xrt_device *xdev, struct oxr_interaction_profile **out_p)
Find the best matching profile for the given xrt_device.
Definition: oxr_binding.c:373
XrResult oxr_session_attach_action_sets(struct oxr_logger *log, struct oxr_session *sess, const XrSessionActionSetsAttachInfo *bindInfo)
Definition: oxr_input.c:1704
XRT_CHECK_RESULT XrResult oxr_space_locate_device(struct oxr_logger *log, struct xrt_device *xdev, struct oxr_space *baseSpc, XrTime time, struct xrt_space_relation *out_relation)
Locate the xrt_device in the given base space, useful for implementing hand tracking location look up...
Definition: oxr_space.c:581
static XrDebugUtilsMessengerEXT oxr_messenger_to_openxr(struct oxr_debug_messenger *mssngr)
To go back to a OpenXR object.
Definition: oxr_objects.h:991
XrResult oxr_space_locate(struct oxr_logger *log, struct oxr_space *spc, struct oxr_space *baseSpc, XrTime time, XrSpaceLocation *location)
Definition: oxr_space.c:448
XrResult oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const XrFrameEndInfo *frameEndInfo)
Definition: oxr_session_frame_end.c:1646
static XrInstance oxr_instance_to_openxr(struct oxr_instance *inst)
To go back to a OpenXR object.
Definition: oxr_objects.h:217
static XrHandTrackerEXT oxr_hand_tracker_to_openxr(struct oxr_hand_tracker *hand_tracker)
To go back to a OpenXR object.
Definition: oxr_objects.h:380
static XrActionSet oxr_action_set_to_openxr(struct oxr_action_set *act_set)
To go back to a OpenXR object.
Definition: oxr_objects.h:369
bool oxr_classify_subaction_paths(struct oxr_logger *log, const struct oxr_instance *inst, uint32_t subaction_path_count, const XrPath *subaction_paths, struct oxr_subaction_paths *subaction_paths_out)
Helper function to classify subaction_paths.
Definition: oxr_input.c:429
static bool oxr_subaction_paths_is_subset_of(const struct oxr_subaction_paths *a, const struct oxr_subaction_paths *b)
Helper function to determine if the set of paths in a is a subset of the paths in b.
Definition: oxr_objects.h:2090
static XrSession oxr_session_to_openxr(struct oxr_session *sess)
To go back to a OpenXR object.
Definition: oxr_objects.h:780
oxr_session_graphics_ext
What graphics API was this session created with.
Definition: oxr_defines.h:123
static XrAction oxr_action_to_openxr(struct oxr_action *act)
To go back to a OpenXR object.
Definition: oxr_objects.h:404
XrResult oxr_d3d_get_requirements(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid, D3D_FEATURE_LEVEL *min_feature_level)
Common GetRequirements call for D3D11 and D3D12.
Definition: oxr_d3d.cpp:42
bool oxr_xdev_find_input(struct xrt_device *xdev, enum xrt_input_name name, struct xrt_input **out_input)
Return true if it finds an input of that name on this device.
Definition: oxr_xdev.c:89
oxr_space_type
Internal enum for the type of space, lets us reason about action spaces.
Definition: oxr_defines.h:104
XrResult oxr_vk_create_vulkan_instance(struct oxr_logger *log, struct oxr_system *sys, const XrVulkanInstanceCreateInfoKHR *createInfo, VkInstance *vulkanInstance, VkResult *vulkanResult)
Definition: oxr_vulkan.c:231
static void oxr_refcounted_ref(struct oxr_refcounted *orc)
Increase the reference count of orc.
Definition: oxr_objects.h:2430
void oxr_xdev_get_hand_tracking_at(struct oxr_logger *log, struct oxr_instance *inst, struct xrt_device *xdev, enum xrt_input_name name, XrTime at_time, struct xrt_hand_joint_set *out_value)
Returns the hand tracking value of the named input from the device.
Definition: oxr_xdev.c:126
void oxr_binding_destroy_all(struct oxr_logger *log, struct oxr_instance *inst)
Free all memory allocated by the binding system.
Definition: oxr_binding.c:561
XrResult oxr_session_request_exit(struct oxr_logger *log, struct oxr_session *sess)
Definition: oxr_session.c:343
XrResult(* oxr_handle_destroyer)(struct oxr_logger *log, struct oxr_handle_base *hb)
Function pointer type for a handle destruction function.
Definition: oxr_objects.h:145
void oxr_session_change_state(struct oxr_logger *log, struct oxr_session *sess, XrSessionState state, XrTime time)
Change the state of the session, queues a event.
Definition: oxr_session.c:164
XrResult oxr_system_fill_in(struct oxr_logger *log, struct oxr_instance *inst, XrSystemId systemId, uint32_t view_count, struct oxr_system *sys)
Definition: oxr_system.c:110
XrResult oxr_create_messenger(struct oxr_logger *, struct oxr_instance *inst, const XrDebugUtilsMessengerCreateInfoEXT *, struct oxr_debug_messenger **out_mssngr)
Definition: oxr_messenger.c:41
void oxr_session_binding_destroy_all(struct oxr_logger *log, struct oxr_session *sess)
Free all memory allocated by the binding system.
Definition: oxr_binding.c:569
XrResult oxr_path_get_string(struct oxr_logger *log, const struct oxr_instance *inst, XrPath path, const char **out_str, size_t *out_length)
Get a pointer and length of the internal string.
Definition: oxr_path.c:216
XrResult oxr_session_frame_wait(struct oxr_logger *log, struct oxr_session *sess, XrFrameState *frameState)
Definition: oxr_session.c:778
oxr_handle_state
State of a handle base, to reduce likelihood of going "boom" on out-of-order destruction or other uns...
Definition: oxr_defines.h:46
XrResult oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo, XrVersion major_minor, const struct oxr_extension_status *extensions, struct oxr_instance **out_inst)
Creates a instance, does minimal validation of createInfo.
Definition: oxr_instance.c:220
static XrSpace oxr_space_to_openxr(struct oxr_space *spc)
To go back to a OpenXR object.
Definition: oxr_objects.h:897
oxr_subaction_path
Sub action paths.
Definition: oxr_defines.h:63
XrResult oxr_vk_create_vulkan_device(struct oxr_logger *log, struct oxr_system *sys, const XrVulkanDeviceCreateInfoKHR *createInfo, VkDevice *vulkanDevice, VkResult *vulkanResult)
Definition: oxr_vulkan.c:390
const char * oxr_handle_state_to_string(enum oxr_handle_state state)
Returns a human-readable label for a handle state.
Definition: oxr_handle_base.c:42
bool oxr_xdev_find_output(struct xrt_device *xdev, enum xrt_output_name name, struct xrt_output **out_output)
Return true if it finds an output of that name on this device.
Definition: oxr_xdev.c:108
#define XRT_CAST_PTR_TO_OXR_HANDLE(HANDLE_TYPE, PTR)
Cast a pointer to an OpenXR handle in such a way as to avoid warnings.
Definition: oxr_objects.h:75
static XRT_CHECK_RESULT bool xrt_reference_dec_and_is_zero(struct xrt_reference *xref)
Decrement the reference and return true if the value is now zero.
Definition: xrt_defines.h:2048
#define XRT_SYSTEM_MAX_DEVICES
Maximum number of devices simultaneously usable by an implementation of xrt_system_devices.
Definition: xrt_system.h:142
#define XRT_MAX_SWAPCHAIN_IMAGES
Max swapchain images, artificial limit.
Definition: xrt_limits.h:34
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1303
static void xrt_reference_inc(struct xrt_reference *xref)
Increment the reference, probably want xrt_reference_inc_and_was_zero.
Definition: xrt_defines.h:2011
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:1806
xrt_plane_detector_flags_ext
Flags used when running plane detection.
Definition: xrt_plane_detector.h:46
Wrapper around OS threading native functions.
XrResult oxr_action_get_input_source_localized_name(struct oxr_logger *log, struct oxr_session *sess, const XrInputSourceLocalizedNameGetInfo *getInfo, uint32_t bufferCapacityInput, uint32_t *bufferCountOutput, char *buffer)
Definition: oxr_binding.c:649
Shared internal defines and enums in the state tracker.
Macros for generating extension-related tables and code and inspecting Monado's extension support.
#define OXR_EXTENSION_SUPPORT_GENERATE(_)
Call this, passing a macro taking two parameters, to generate tables, code, etc.
Definition: oxr_extension_support.h:795
The objects that handle session running status and blocking of xrWaitFrame.
XrResult oxr_action_sync_data(struct oxr_logger *log, struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets, const XrActiveActionSetPrioritiesEXT *activePriorities)
Definition: oxr_input.c:1786
#define OXR_PATH_MEMBER(X)
Currently bound interaction profile.
Definition: oxr_objects.h:1863
Provides a utility macro for dealing with subaction paths.
#define OXR_FOR_EACH_SUBACTION_PATH(_)
Expansion macro (x-macro) that calls the macro you pass with the shorthand name of each subaction pat...
Definition: oxr_subaction.h:39
#define OXR_FOR_EACH_VALID_SUBACTION_PATH(_)
Expansion macro (x-macro) that calls the macro you pass with the shorthand name of each valid subacti...
Definition: oxr_subaction.h:23
Definition: m_space.cpp:87
A wrapper around a native mutex.
Definition: os_threading.h:55
Definition: os_time.h:208
Data associated with an Action that has been attached to a Session.
Definition: oxr_objects.h:2243
struct oxr_subaction_paths any_pose_subaction_path
For pose actions any subaction paths are special treated, at bind time we pick one subaction path and...
Definition: oxr_objects.h:2267
struct oxr_action_ref * act_ref
This action's refcounted data.
Definition: oxr_objects.h:2248
struct oxr_action_set_attachment * act_set_attached
The owning action set attachment.
Definition: oxr_objects.h:2245
uint32_t act_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2259
struct oxr_session * sess
The corresponding session.
Definition: oxr_objects.h:2256
The set of inputs/outputs for a single sub-action path for an action.
Definition: oxr_objects.h:2221
A input action pair of a xrt_input and a xrt_device, along with the required transform.
Definition: oxr_objects.h:2182
A output action pair of a xrt_output_name and a xrt_device.
Definition: oxr_objects.h:2201
The reference-counted data of an action.
Definition: oxr_objects.h:2540
char name[XR_MAX_ACTION_NAME_SIZE]
Application supplied name of this action.
Definition: oxr_objects.h:2544
struct oxr_subaction_paths subaction_paths
Which sub action paths that this action was created with.
Definition: oxr_objects.h:2553
XrActionType action_type
Type this action was created with.
Definition: oxr_objects.h:2550
uint32_t act_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2547
The data associated with the attachment of an Action Set (oxr_action_set) to as Session (oxr_session)...
Definition: oxr_objects.h:2114
struct oxr_action_attachment * act_attachments
An array of action attachments we own.
Definition: oxr_objects.h:2128
struct oxr_session * sess
Owning session.
Definition: oxr_objects.h:2116
struct oxr_action_set_ref * act_set_ref
Action set refcounted data.
Definition: oxr_objects.h:2119
uint32_t act_set_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2122
size_t action_attachment_count
Length of oxr_action_set_attachment::act_attachments.
Definition: oxr_objects.h:2133
struct oxr_subaction_paths requested_subaction_paths
Which sub-action paths are requested on the latest sync.
Definition: oxr_objects.h:2125
The reference-counted data of an action set.
Definition: oxr_objects.h:2458
uint32_t act_set_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2471
char name[XR_MAX_ACTION_SET_NAME_SIZE]
Application supplied name of this action.
Definition: oxr_objects.h:2462
bool ever_attached
Has this action set even been attached to any session, marking it as immutable.
Definition: oxr_objects.h:2468
uint32_t priority
Application supplied action set priority.
Definition: oxr_objects.h:2474
A group of actions.
Definition: oxr_objects.h:2500
struct u_hashset_item * name_item
The item in the name hashset.
Definition: oxr_objects.h:2522
struct u_hashset_item * loc_item
The item in the localized hashset.
Definition: oxr_objects.h:2525
struct oxr_action_set_ref * data
The data for this action set that must live as long as any session we are attached to.
Definition: oxr_objects.h:2511
uint32_t act_set_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2519
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2502
struct oxr_instance * inst
Owner of this action set.
Definition: oxr_objects.h:2505
The state of a action input.
Definition: oxr_objects.h:2156
bool active
Is this active (bound and providing input)?
Definition: oxr_objects.h:2163
XrTime timestamp
When was this last changed.
Definition: oxr_objects.h:2169
A single action.
Definition: oxr_objects.h:2570
struct oxr_action_set * act_set
Owner of this action.
Definition: oxr_objects.h:2575
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2572
struct u_hashset_item * loc_item
The item in the localized hashset.
Definition: oxr_objects.h:2592
uint32_t act_key
Unique key for the session hashmap.
Definition: oxr_objects.h:2586
struct u_hashset_item * name_item
The item in the name hashset.
Definition: oxr_objects.h:2589
struct oxr_action_ref * data
The data for this action that must live as long as any session we are attached to.
Definition: oxr_objects.h:2579
Interaction profile binding state.
Definition: oxr_objects.h:2022
uint32_t * preferred_binding_path_index
store which entry in paths was suggested, for each action key
Definition: oxr_objects.h:2034
const char * localized_name
Name presented to the user.
Definition: oxr_objects.h:2027
Debug object created by the client program.
Definition: oxr_objects.h:2603
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2605
XrDebugUtilsMessageTypeFlagsEXT message_types
Types to submit to this messenger.
Definition: oxr_objects.h:2614
PFN_xrDebugUtilsMessengerCallbackEXT user_callback
Callback function.
Definition: oxr_objects.h:2617
struct oxr_instance * inst
Owner of this messenger.
Definition: oxr_objects.h:2608
void *XR_MAY_ALIAS user_data
Opaque user data.
Definition: oxr_objects.h:2620
XrDebugUtilsMessageSeverityFlagsEXT message_severities
Severities to submit to this messenger.
Definition: oxr_objects.h:2611
dpad binding extracted from XrInteractionProfileDpadBindingEXT
Definition: oxr_objects.h:1954
dpad emulation settings from oxr_interaction_profile
Definition: oxr_objects.h:1988
A entry in the dpad state for one action set.
Definition: oxr_objects.h:1965
dpad settings we need extracted from XrInteractionProfileDpadBindingEXT
Definition: oxr_objects.h:1942
Holds dpad binding state for a single interaction profile.
Definition: oxr_objects.h:1980
Definition: oxr_event.c:30
Structure tracking which extensions are enabled for a given instance.
Definition: oxr_objects.h:1638
Helper that handles synchronizing the xr{Wait,Begin,End}Frame calls.
Definition: oxr_frame_sync.h:36
A hand tracker.
Definition: oxr_objects.h:2633
enum xrt_input_name input_name
the input name associated with this hand tracker
Definition: oxr_objects.h:2644
struct xrt_device * xdev
xrt_device backing this hand tracker
Definition: oxr_objects.h:2641
struct oxr_session * sess
Owner of this hand tracker.
Definition: oxr_objects.h:2638
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2635
Used to hold diverse child handles and ensure orderly destruction.
Definition: oxr_objects.h:1442
struct oxr_handle_base * parent
Pointer to this object's parent handle holder, if any.
Definition: oxr_objects.h:1449
uint64_t debug
Magic (per-handle-type) value for debugging.
Definition: oxr_objects.h:1444
struct oxr_handle_base * children[256]
Array of children, if any.
Definition: oxr_objects.h:1454
enum oxr_handle_state state
Current handle state.
Definition: oxr_objects.h:1459
oxr_handle_destroyer destroy
Destroy the object this handle refers to.
Definition: oxr_objects.h:1464
Variant type for input transforms.
Definition: oxr_input_transform.h:144
Main object that ties everything together.
Definition: oxr_objects.h:1651
struct oxr_instance::@263 openxr_version
The OpenXR version requested in the app info. It determines the instance's OpenXR version.
bool parallel_views
For applications that rely on views being parallel, notably some OpenVR games with OpenComposite.
Definition: oxr_objects.h:1738
size_t path_num
Number of paths in the array (0 is always null).
Definition: oxr_objects.h:1687
bool disable_vulkan_format_depth_stencil
Unreal has a bug in the VulkanRHI backend.
Definition: oxr_objects.h:1727
XrVersion major_minor
Stores only major.minor version. Simplifies comparisons for e.g. "at least OpenXR 1....
Definition: oxr_objects.h:1666
bool skip_end_session
Unreal 4 has a bug calling xrEndSession; the function should just exit.
Definition: oxr_objects.h:1729
struct oxr_path ** path_array
Mapping from ID to path.
Definition: oxr_objects.h:1683
bool no_validation_error_in_create_ref_space
Return XR_ERROR_REFERENCE_SPACE_UNSUPPORTED instead of XR_ERROR_VALIDATION_FAILURE in xrCreateReferen...
Definition: oxr_objects.h:1735
size_t path_array_length
Total length of path array.
Definition: oxr_objects.h:1685
struct oxr_extension_status extensions
Enabled extensions.
Definition: oxr_objects.h:1660
struct oxr_debug_messenger * messengers[256]
Debug messengers.
Definition: oxr_objects.h:1742
struct u_hashset * path_store
Path store, for looking up paths.
Definition: oxr_objects.h:1681
struct oxr_interaction_profile ** profiles
Interaction profile bindings that have been suggested by the client.
Definition: oxr_objects.h:1698
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:1653
A single interaction profile.
Definition: oxr_objects.h:2000
enum xrt_device_name xname
Used to lookup xrt_binding_profile for fallback.
Definition: oxr_objects.h:2004
const char * localized_name
Name presented to the user.
Definition: oxr_objects.h:2007
Logger struct that lives on the stack, one for each call client call.
Definition: oxr_logger.h:40
Internal representation of a path, item follows this struct in memory and that in turn is followed by...
Definition: oxr_path.c:28
Definition: oxr_objects.h:2420
void(* destroy)(struct oxr_refcounted *)
Destruction callback.
Definition: oxr_objects.h:2423
Object that client program interact with.
Definition: oxr_objects.h:1767
struct u_hashmap_int * act_attachments_by_key
A map of action key to action attachment.
Definition: oxr_objects.h:1849
XrResult(* create_swapchain)(struct oxr_logger *, struct oxr_session *sess, const XrSwapchainCreateInfo *, struct oxr_swapchain **)
To pipe swapchain creation to right code.
Definition: oxr_objects.h:1886
struct xrt_compositor_native * xcn
Native compositor that is wrapped by client compositors.
Definition: oxr_objects.h:1779
struct xrt_space_relation local_space_pure_relation
initial relation of head in "global" space.
Definition: oxr_objects.h:1893
struct xrt_session * xs
The xrt_session backing this session.
Definition: oxr_objects.h:1776
struct oxr_action_set_attachment * act_set_attachments
An array of action set attachments that this session owns.
Definition: oxr_objects.h:1823
uint32_t frame_timing_wait_sleep_ms
Extra sleep in wait frame.
Definition: oxr_objects.h:1881
struct os_precise_sleeper sleeper
Used to implement precise extra sleeping in wait frame.
Definition: oxr_objects.h:1815
enum oxr_session_graphics_ext gfx_ext
What graphics type was this session created with.
Definition: oxr_objects.h:1773
size_t profiles_on_attachment_size
Clone of all suggested binding profiles at the point of action set/session attachment.
Definition: oxr_objects.h:1855
bool has_ended_once
There is a extra state between xrBeginSession has been called and the first xrEndFrame has been calle...
Definition: oxr_objects.h:1791
struct u_hashmap_int * act_sets_attachments_by_key
A map of action set key to action set attachments.
Definition: oxr_objects.h:1837
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:1769
float ipd_meters
IPD, to be expanded to a proper 3D relation.
Definition: oxr_objects.h:1873
size_t action_set_attachment_count
Length of oxr_session::act_set_attachments.
Definition: oxr_objects.h:1828
bool frame_timing_spew
Frame timing debug output.
Definition: oxr_objects.h:1878
Can be one of several reference space types, or a space that is bound to an action.
Definition: oxr_objects.h:2315
struct oxr_subaction_paths subaction_paths
Which sub action path is this?
Definition: oxr_objects.h:2332
enum oxr_space_type space_type
What kind of space is this?
Definition: oxr_objects.h:2329
uint32_t act_key
Action key from which action this space was created from.
Definition: oxr_objects.h:2326
struct xrt_pose pose
Pose that was given during creation.
Definition: oxr_objects.h:2323
struct oxr_session * sess
Owner of this space.
Definition: oxr_objects.h:2320
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2317
A parsed equivalent of a list of sub-action paths.
Definition: oxr_objects.h:2077
A set of images used for rendering.
Definition: oxr_objects.h:2356
struct oxr_session * sess
Owner of this swapchain.
Definition: oxr_objects.h:2361
uint32_t face_count
The number of cubemap faces. 6 for cubemaps, 1 otherwise.
Definition: oxr_objects.h:2373
struct xrt_swapchain * swapchain
Compositor swapchain.
Definition: oxr_objects.h:2364
struct oxr_handle_base handle
Common structure for things referred to by OpenXR handles.
Definition: oxr_objects.h:2358
uint32_t width
Swapchain size.
Definition: oxr_objects.h:2367
uint32_t array_layer_count
For 1 is 2D texture, greater then 1 2D array texture.
Definition: oxr_objects.h:2370
Single or multiple devices grouped together to form a system that sessions can be created from.
Definition: oxr_objects.h:1479
struct xrt_system * xsys
The XRT interfaces level system.
Definition: oxr_objects.h:1483
VkPhysicalDevice suggested_vulkan_physical_device
The device returned with the last xrGetVulkanGraphicsDeviceKHR or xrGetVulkanGraphicsDevice2KHR call.
Definition: oxr_objects.h:1523
struct xrt_system_devices * xsysd
System devices used in all session types.
Definition: oxr_objects.h:1486
struct xrt_space_overseer * xso
Space overseer used in all session types.
Definition: oxr_objects.h:1489
VkInstance vulkan_enable2_instance
The instance/device we create when vulkan_enable2 is used.
Definition: oxr_objects.h:1520
bool gotten_requirements
Have the client application called the gfx api requirements func?
Definition: oxr_objects.h:1497
struct xrt_system_compositor * xsysc
System compositor, used to create session compositors.
Definition: oxr_objects.h:1492
struct xrt_system_roles dynamic_roles_cache
Cache of the last known system roles, see xrt_system_roles::generation_id.
Definition: oxr_objects.h:1509
Time-keeping state structure.
Definition: u_time.cpp:30
A simple uint64_t key to a void pointer hashmap.
Definition: u_hashmap.cpp:24
A embeddable hashset item, note that the string directly follows the u_hashset_item.
Definition: u_hashset.h:37
Kind of bespoke hashset implementation, where the user is responsible for allocating and freeing the ...
Definition: u_hashset.cpp:26
Definition: u_index_fifo.h:21
Definition: xrt_defines.h:1790
Main compositor server interface.
Definition: xrt_compositor.h:2233
Common compositor client interface/base.
Definition: xrt_compositor.h:997
A single HMD or input device.
Definition: xrt_device.h:254
enum xrt_device_name name
Enum identifier of the device.
Definition: xrt_device.h:256
Joint set type used for hand tracking.
Definition: xrt_defines.h:1402
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:164
This interface acts as a root object for Monado.
Definition: xrt_instance.h:114
A single named output, that sits on a xrt_device.
Definition: xrt_device.h:182
Each plane has n polygons; ultimately plane metadata from locations and vetices is reconstructed.
Definition: xrt_plane_detector.h:171
A pose composed of a position and orientation.
Definition: xrt_defines.h:467
A base class for reference counted objects.
Definition: xrt_defines.h:96
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:246
Object that oversees and manages spaces, one created for each XR system.
Definition: xrt_space.h:96
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:659
A space very similar to a OpenXR XrSpace but not a full one-to-one mapping, but used to power XrSpace...
Definition: xrt_space.h:31
Common swapchain interface/base.
Definition: xrt_compositor.h:541
The system compositor handles composition for a system.
Definition: xrt_compositor.h:2423
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition: xrt_system.h:222
struct xrt_device * head
An observing pointer to the device serving as the "head" (and HMD).
Definition: xrt_system.h:251
struct xrt_device * face
An observing pointer to the device providing face tracking (optional).
Definition: xrt_system.h:263
struct xrt_device * eyes
An observing pointer to the device providing eye tracking (optional).
Definition: xrt_system.h:257
struct xrt_system_devices::@242::@243 hand_tracking
Devices providing optical (or otherwise more directly measured than from controller estimation) hand ...
struct xrt_system_devices::@242 static_roles
Observing pointers for devices in some static (unchangeable) roles.
struct xrt_device * left
An observing pointer to the device providing hand tracking for the left hand (optional).
Definition: xrt_system.h:285
struct xrt_device * right
An observing pointer to the device providing hand tracking for the right hand (optional).
Definition: xrt_system.h:294
struct xrt_device * body
An observing pointer to the device providing body tracking (optional).
Definition: xrt_system.h:269
Data associating a device index (in xrt_system_devices::xdevs) with a given "role" for dynamic role s...
Definition: xrt_system.h:162
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:63
Visibility mask helper, the indices and vertices are tightly packed after this struct.
Definition: xrt_visibility_mask.h:25
Misc helpers for device drivers.
Hashmap for integer values header.
Hashset struct header.
A FIFO for indices.
A union of all input types.
Definition: xrt_defines.h:1418
Header holding Android-specific details.
xrt_android_lifecycle_event
Distinguishes the possible Android lifecycle events from each other.
Definition: xrt_android.h:32
Header declaring XRT graphics interfaces.
Auto detect OS and certain features.
xrt_perf_notify_level
Performance level.
Definition: xrt_defines.h:1979
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:714
xrt_perf_domain
Domain type.
Definition: xrt_defines.h:1952
Header defining an xrt display or controller device.
Header for limits of the XRT interfaces.
Include all of the openxr headers in one place.
Header defining xrt space and space overseer.
Header for system objects.
Header defining the tracking system integration in Monado.
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.