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