Monado OpenXR Runtime
oxr_objects.h
Go to the documentation of this file.
1 // Copyright 2018-2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Contains the instance struct that a lot of things hang from.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup oxr_main
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_device.h"
13 #include "xrt/xrt_tracking.h"
14 #include "xrt/xrt_compositor.h"
17 #include "util/u_hashset.h"
18 #include "util/u_hashmap.h"
19 
20 #include "oxr_extension_support.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 /*!
28  * @defgroup oxr OpenXR state tracker
29  *
30  * Client application facing code.
31  *
32  * @ingroup xrt
33  */
34 
35 /*!
36  * @defgroup oxr_main OpenXR main code
37  *
38  * Gets called from @ref oxr_api functions and talks to devices and
39  * @ref comp using @ref xrt_iface.
40  *
41  * @ingroup oxr
42  * @{
43  */
44 
45 // For corruption and layer checking.
46 // clang-format off
47 #define OXR_XR_DEBUG_INSTANCE (*(uint64_t *)"oxrinst\0")
48 #define OXR_XR_DEBUG_SESSION (*(uint64_t *)"oxrsess\0")
49 #define OXR_XR_DEBUG_SPACE (*(uint64_t *)"oxrspac\0")
50 #define OXR_XR_DEBUG_PATH (*(uint64_t *)"oxrpath\0")
51 #define OXR_XR_DEBUG_ACTION (*(uint64_t *)"oxracti\0")
52 #define OXR_XR_DEBUG_SWAPCHAIN (*(uint64_t *)"oxrswap\0")
53 #define OXR_XR_DEBUG_ACTIONSET (*(uint64_t *)"oxraset\0")
54 #define OXR_XR_DEBUG_MESSENGER (*(uint64_t *)"oxrmess\0")
55 #define OXR_XR_DEBUG_SOURCESET (*(uint64_t *)"oxrsrcs\0")
56 #define OXR_XR_DEBUG_SOURCE (*(uint64_t *)"oxrsrc_\0")
57 // clang-format on
58 
59 
60 /*
61  *
62  * Forward declare structs.
63  *
64  */
65 
66 struct oxr_logger;
67 struct oxr_instance;
68 struct oxr_system;
69 struct oxr_session;
70 struct oxr_event;
71 struct oxr_swapchain;
72 struct oxr_space;
73 struct oxr_action_set;
74 struct oxr_action;
75 struct oxr_debug_messenger;
76 struct oxr_handle_base;
77 struct oxr_sub_paths;
78 struct oxr_source;
79 struct oxr_source_set;
80 struct oxr_source_input;
81 struct oxr_source_output;
82 struct oxr_binding;
84 
85 #define XRT_MAX_HANDLE_CHILDREN 256
86 
87 struct time_state;
88 
89 typedef XrResult (*oxr_handle_destroyer)(struct oxr_logger *log,
90  struct oxr_handle_base *hb);
91 
92 /*!
93  * State of a handle base, to reduce likelihood of going "boom" on
94  * out-of-order destruction or other unsavory behavior.
95  */
97 {
98  /*! State during/before oxr_handle_init, or after failure */
100 
101  /*! State after successful oxr_handle_init */
103 
104  /*! State after successful oxr_handle_destroy */
106 };
107 
108 /*!
109  * Sub action paths.
110  */
112 {
113  OXR_SUB_ACTION_PATH_USER,
114  OXR_SUB_ACTION_PATH_HEAD,
115  OXR_SUB_ACTION_PATH_LEFT,
116  OXR_SUB_ACTION_PATH_RIGHT,
117  OXR_SUB_ACTION_PATH_GAMEPAD,
118 };
119 
120 
121 /*
122  *
123  * oxr_handle_base.c
124  *
125  */
126 
127 /*!
128  * Destroy the handle's object, as well as all child handles recursively.
129  *
130  * This should be how all handle-associated objects are destroyed.
131  */
132 XrResult
133 oxr_handle_destroy(struct oxr_logger *log, struct oxr_handle_base *hb);
134 
135 /*!
136  * Returns a human-readable label for a handle state.
137  */
138 const char *
140 
141 /*
142  *
143  * oxr_instance.c
144  *
145  */
146 
147 /*!
148  * To go back to a OpenXR object.
149  */
150 static inline XrInstance
151 oxr_instance_to_openxr(struct oxr_instance *inst)
152 {
153  return (XrInstance)inst;
154 }
155 
156 XrResult
157 oxr_instance_create(struct oxr_logger *log,
158  const XrInstanceCreateInfo *createInfo,
159  struct oxr_instance **out_inst);
160 
161 XrResult
162 oxr_instance_get_properties(struct oxr_logger *log,
163  struct oxr_instance *inst,
164  XrInstanceProperties *instanceProperties);
165 
166 #if XR_USE_TIMESPEC
167 
168 XrResult
169 oxr_instance_convert_time_to_timespec(struct oxr_logger *log,
170  struct oxr_instance *inst,
171  XrTime time,
172  struct timespec *timespecTime);
173 XrResult
174 oxr_instance_convert_timespec_to_time(struct oxr_logger *log,
175  struct oxr_instance *inst,
176  const struct timespec *timespecTime,
177  XrTime *time);
178 #endif // XR_USE_TIMESPEC
179 
180 
181 /*
182  *
183  * oxr_path.c
184  *
185  */
186 
187 void *
188 oxr_path_get_attached(struct oxr_logger *log,
189  struct oxr_instance *inst,
190  XrPath path);
191 
192 /*!
193  * Get the path for the given string if it exists, or create it if it does not.
194  */
195 XrResult
197  struct oxr_instance *inst,
198  const char *str,
199  size_t length,
200  XrPath *out_path);
201 
202 /*!
203  * Only get the path for the given string if it exists.
204  */
205 XrResult
206 oxr_path_only_get(struct oxr_logger *log,
207  struct oxr_instance *inst,
208  const char *str,
209  size_t length,
210  XrPath *out_path);
211 
212 /*!
213  * Get a pointer and length of the internal string.
214  *
215  * The pointer has the same life time as the instance. The length is the number
216  * of valid characters, not including the null termination character (but a
217  * extra null byte is always reserved at the end so can strings can be given
218  * to functions expecting null terminated strings).
219  */
220 XrResult
221 oxr_path_get_string(struct oxr_logger *log,
222  struct oxr_instance *inst,
223  XrPath path,
224  const char **out_str,
225  size_t *out_length);
226 
227 /*!
228  * Destroy all paths that the instance has created.
229  */
230 void
231 oxr_path_destroy_all(struct oxr_logger *log, struct oxr_instance *inst);
232 
233 
234 /*
235  *
236  * oxr_input.c
237  *
238  */
239 
240 /*!
241  * Helper function to classify sub_paths.
242  */
243 void
245  struct oxr_instance *inst,
246  uint32_t num_subaction_paths,
247  const XrPath *subaction_paths,
248  struct oxr_sub_paths *sub_paths);
249 
250 /*!
251  * Find the pose input for the set of sub_paths
252  */
253 XrResult
255  struct oxr_session *sess,
256  uint32_t key,
257  const struct oxr_sub_paths *sub_paths,
258  struct oxr_source_input **out_input);
259 
260 /*!
261  * To go back to a OpenXR object.
262  */
263 static inline XrActionSet
264 oxr_action_set_to_openxr(struct oxr_action_set *act_set)
265 {
266  return (XrActionSet)act_set;
267 }
268 
269 XrResult
271  struct oxr_instance *inst,
272  const XrActionSetCreateInfo *createInfo,
273  struct oxr_action_set **out_act_set);
274 
275 /*!
276  * To go back to a OpenXR object.
277  */
278 static inline XrAction
279 oxr_action_to_openxr(struct oxr_action *act)
280 {
281  return (XrAction)act;
282 }
283 
284 XrResult
285 oxr_action_create(struct oxr_logger *log,
286  struct oxr_action_set *act_set,
287  const XrActionCreateInfo *createInfo,
288  struct oxr_action **out_act);
289 
290 XrResult
291 oxr_session_attach_action_sets(struct oxr_logger *log,
292  struct oxr_session *sess,
293  const XrSessionActionSetsAttachInfo *bindInfo);
294 
295 XrResult
296 oxr_action_sync_data(struct oxr_logger *log,
297  struct oxr_session *sess,
298  uint32_t countActionSets,
299  const XrActiveActionSet *actionSets);
300 
301 XrResult
302 oxr_action_get_boolean(struct oxr_logger *log,
303  struct oxr_session *sess,
304  uint64_t key,
305  struct oxr_sub_paths sub_paths,
306  XrActionStateBoolean *data);
307 
308 XrResult
309 oxr_action_get_vector1f(struct oxr_logger *log,
310  struct oxr_session *sess,
311  uint64_t key,
312  struct oxr_sub_paths sub_paths,
313  XrActionStateFloat *data);
314 
315 
316 XrResult
317 oxr_action_get_vector2f(struct oxr_logger *log,
318  struct oxr_session *sess,
319  uint64_t key,
320  struct oxr_sub_paths sub_paths,
321  XrActionStateVector2f *data);
322 
323 XrResult
324 oxr_action_get_pose(struct oxr_logger *log,
325  struct oxr_session *sess,
326  uint64_t key,
327  struct oxr_sub_paths sub_paths,
328  XrActionStatePose *data);
329 
330 XrResult
331 oxr_action_apply_haptic_feedback(struct oxr_logger *log,
332  struct oxr_session *sess,
333  uint64_t key,
334  struct oxr_sub_paths sub_paths,
335  const XrHapticBaseHeader *hapticEvent);
336 
337 XrResult
338 oxr_action_stop_haptic_feedback(struct oxr_logger *log,
339  struct oxr_session *sess,
340  uint64_t key,
341  struct oxr_sub_paths sub_paths);
342 
343 
344 /*
345  *
346  * oxr_binding.c
347  *
348  */
349 
350 /*!
351  * Find the best matching profile for the given @ref xrt_device.
352  *
353  * @param log Logger.
354  * @param inst Instance.
355  * @param xdev Can be null.
356  * @param[out] out_p Returned interaction profile.
357  */
358 void
360  struct oxr_instance *inst,
361  struct xrt_device *xdev,
362  struct oxr_interaction_profile **out_p);
363 
364 /*!
365  * Free all memory allocated by the binding system.
366  */
367 void
368 oxr_binding_destroy_all(struct oxr_logger *log, struct oxr_instance *inst);
369 
370 /*!
371  * Find all bindings that is the given action key is bound to.
372  */
373 void
375  struct oxr_interaction_profile *profile,
376  uint32_t key,
377  struct oxr_binding *bindings[32],
378  size_t *num_bindings);
379 
380 XrResult
382  struct oxr_logger *log,
383  struct oxr_instance *inst,
384  const XrInteractionProfileSuggestedBinding *suggestedBindings);
385 
386 XrResult
387 oxr_action_get_current_interaction_profile(
388  struct oxr_logger *log,
389  struct oxr_session *sess,
390  XrPath topLevelUserPath,
391  XrInteractionProfileState *interactionProfile);
392 
393 XrResult
395  struct oxr_logger *log,
396  struct oxr_session *sess,
397  const XrInputSourceLocalizedNameGetInfo *getInfo,
398  uint32_t bufferCapacityInput,
399  uint32_t *bufferCountOutput,
400  char *buffer);
401 
402 XrResult
404  struct oxr_session *sess,
405  uint64_t key,
406  uint32_t sourceCapacityInput,
407  uint32_t *sourceCountOutput,
408  XrPath *sources);
409 
410 
411 /*
412  *
413  * oxr_session.c
414  *
415  */
416 
417 /*!
418  * To go back to a OpenXR object.
419  */
420 static inline XrSession
421 oxr_session_to_openxr(struct oxr_session *sess)
422 {
423  return (XrSession)sess;
424 }
425 
426 XrResult
427 oxr_session_create(struct oxr_logger *log,
428  struct oxr_system *sys,
429  const XrSessionCreateInfo *createInfo,
430  struct oxr_session **out_session);
431 
432 XrResult
433 oxr_session_enumerate_formats(struct oxr_logger *log,
434  struct oxr_session *sess,
435  uint32_t formatCapacityInput,
436  uint32_t *formatCountOutput,
437  int64_t *formats);
438 
439 XrResult
440 oxr_session_begin(struct oxr_logger *log,
441  struct oxr_session *sess,
442  const XrSessionBeginInfo *beginInfo);
443 
444 XrResult
445 oxr_session_end(struct oxr_logger *log, struct oxr_session *sess);
446 
447 XrResult
448 oxr_session_request_exit(struct oxr_logger *log, struct oxr_session *sess);
449 
450 void
451 oxr_session_poll(struct oxr_session *sess);
452 
453 /*!
454  * Get the view space position at the given time in relation to the
455  * local or stage space.
456  */
457 XrResult
459  struct oxr_session *sess,
460  XrTime at_time,
461  struct xrt_pose *);
462 
463 XrResult
464 oxr_session_views(struct oxr_logger *log,
465  struct oxr_session *sess,
466  const XrViewLocateInfo *viewLocateInfo,
467  XrViewState *viewState,
468  uint32_t viewCapacityInput,
469  uint32_t *viewCountOutput,
470  XrView *views);
471 
472 XrResult
474  struct oxr_session *sess,
475  XrFrameState *frameState);
476 
477 XrResult
478 oxr_session_frame_begin(struct oxr_logger *log, struct oxr_session *sess);
479 
480 XrResult
482  struct oxr_session *sess,
483  const XrFrameEndInfo *frameEndInfo);
484 
485 
486 /*
487  *
488  * oxr_space.c
489  *
490  */
491 
492 /*!
493  * To go back to a OpenXR object.
494  */
495 static inline XrSpace
496 oxr_space_to_openxr(struct oxr_space *spc)
497 {
498  return (XrSpace)spc;
499 }
500 
501 XrResult
502 oxr_space_action_create(struct oxr_logger *log,
503  struct oxr_session *sess,
504  uint64_t key,
505  const XrActionSpaceCreateInfo *createInfo,
506  struct oxr_space **out_space);
507 
508 XrResult
509 oxr_space_reference_create(struct oxr_logger *log,
510  struct oxr_session *sess,
511  const XrReferenceSpaceCreateInfo *createInfo,
512  struct oxr_space **out_space);
513 
514 XrResult
515 oxr_space_locate(struct oxr_logger *log,
516  struct oxr_space *spc,
517  struct oxr_space *baseSpc,
518  XrTime time,
519  XrSpaceLocation *location);
520 
521 XrResult
523  struct oxr_session *sess,
524  XrReferenceSpaceType space,
525  XrReferenceSpaceType baseSpc,
526  XrTime time,
527  struct xrt_space_relation *out_relation);
528 
529 
530 /*
531  *
532  * oxr_swapchain.c
533  *
534  */
535 
536 /*!
537  * To go back to a OpenXR object.
538  */
539 static inline XrSwapchain
540 oxr_swapchain_to_openxr(struct oxr_swapchain *sc)
541 {
542  return (XrSwapchain)sc;
543 }
544 
545 XrResult
546 oxr_create_swapchain(struct oxr_logger *,
547  struct oxr_session *sess,
548  const XrSwapchainCreateInfo *,
549  struct oxr_swapchain **out_swapchain);
550 
551 
552 /*
553  *
554  * oxr_messenger.c
555  *
556  */
557 
558 /*!
559  * To go back to a OpenXR object.
560  */
561 static inline XrDebugUtilsMessengerEXT
562 oxr_messenger_to_openxr(struct oxr_debug_messenger *mssngr)
563 {
564  return (XrDebugUtilsMessengerEXT)mssngr;
565 }
566 
567 XrResult
569  struct oxr_instance *inst,
570  const XrDebugUtilsMessengerCreateInfoEXT *,
571  struct oxr_debug_messenger **out_mssngr);
572 XrResult
573 oxr_destroy_messenger(struct oxr_logger *log,
574  struct oxr_debug_messenger *mssngr);
575 
576 
577 /*
578  *
579  * oxr_system.c
580  *
581  */
582 
583 XrResult
584 oxr_system_select(struct oxr_logger *log,
585  struct oxr_system **systems,
586  uint32_t num_systems,
587  XrFormFactor form_factor,
588  struct oxr_system **out_selected);
589 
590 XrResult
591 oxr_system_fill_in(struct oxr_logger *log,
592  struct oxr_instance *inst,
593  XrSystemId systemId,
594  struct oxr_system *sys,
595  struct xrt_device **xdevs,
596  size_t num_xdevs);
597 
598 XrResult
599 oxr_system_verify_id(struct oxr_logger *log,
600  const struct oxr_instance *inst,
601  XrSystemId systemId);
602 
603 XrResult
604 oxr_system_get_by_id(struct oxr_logger *log,
605  struct oxr_instance *inst,
606  XrSystemId systemId,
607  struct oxr_system **system);
608 
609 XrResult
611  struct oxr_system *sys,
612  XrSystemProperties *properties);
613 
614 XrResult
615 oxr_system_enumerate_view_confs(
616  struct oxr_logger *log,
617  struct oxr_system *sys,
618  uint32_t viewConfigurationTypeCapacityInput,
619  uint32_t *viewConfigurationTypeCountOutput,
620  XrViewConfigurationType *viewConfigurationTypes);
621 
622 XrResult
624  struct oxr_system *sys,
625  XrViewConfigurationType viewConfigurationType,
626  uint32_t environmentBlendModeCapacityInput,
627  uint32_t *environmentBlendModeCountOutput,
628  XrEnvironmentBlendMode *environmentBlendModes);
629 
630 XrResult
631 oxr_system_get_view_conf_properties(
632  struct oxr_logger *log,
633  struct oxr_system *sys,
634  XrViewConfigurationType viewConfigurationType,
635  XrViewConfigurationProperties *configurationProperties);
636 
637 XrResult
638 oxr_system_enumerate_view_conf_views(
639  struct oxr_logger *log,
640  struct oxr_system *sys,
641  XrViewConfigurationType viewConfigurationType,
642  uint32_t viewCapacityInput,
643  uint32_t *viewCountOutput,
644  XrViewConfigurationView *views);
645 
646 
647 /*
648  *
649  * oxr_event.cpp
650  *
651  */
652 
653 XrResult
654 oxr_poll_event(struct oxr_logger *log,
655  struct oxr_instance *inst,
656  XrEventDataBuffer *eventData);
657 
658 XrResult
659 oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
660  struct oxr_session *sess,
661  XrSessionState state,
662  XrTime time);
663 
664 
665 /*
666  *
667  * oxr_xdev.c
668  *
669  */
670 
671 void
672 oxr_xdev_destroy(struct xrt_device **xdev_ptr);
673 
674 void
675 oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping);
676 
677 /*!
678  * Return true if it finds an input of that name on this device.
679  */
680 bool
681 oxr_xdev_find_input(struct xrt_device *xdev,
682  enum xrt_input_name name,
683  struct xrt_input **out_input);
684 
685 /*!
686  * Return true if it finds an output of that name on this device.
687  */
688 bool
689 oxr_xdev_find_output(struct xrt_device *xdev,
690  enum xrt_output_name name,
691  struct xrt_output **out_output);
692 
693 void
694 oxr_xdev_get_pose_at(struct oxr_logger *log,
695  struct oxr_instance *inst,
696  struct xrt_device *xdev,
697  enum xrt_input_name name,
698  struct xrt_pose *pose,
699  int64_t *timestamp);
700 
701 
702 /*
703  *
704  * OpenGL, located in various files.
705  *
706  */
707 
708 #ifdef XR_USE_GRAPHICS_API_OPENGL
709 #ifdef XR_USE_PLATFORM_XLIB
710 
711 XrResult
712 oxr_session_populate_gl_xlib(struct oxr_logger *log,
713  struct oxr_system *sys,
714  XrGraphicsBindingOpenGLXlibKHR const *next,
715  struct oxr_session *sess);
716 #endif // XR_USE_PLATFORM_XLIB
717 
718 XrResult
719 oxr_swapchain_gl_create(struct oxr_logger *,
720  struct oxr_session *sess,
721  const XrSwapchainCreateInfo *,
722  struct oxr_swapchain **out_swapchain);
723 
724 #endif // XR_USE_GRAPHICS_API_OPENGL
725 
726 
727 /*
728  *
729  * Vulkan, located in various files.
730  *
731  */
732 
733 #ifdef XR_USE_GRAPHICS_API_VULKAN
734 
735 XrResult
736 oxr_vk_get_instance_exts(struct oxr_logger *log,
737  struct oxr_system *sys,
738  uint32_t namesCapacityInput,
739  uint32_t *namesCountOutput,
740  char *namesString);
741 
742 XrResult
743 oxr_vk_get_device_exts(struct oxr_logger *log,
744  struct oxr_system *sys,
745  uint32_t namesCapacityInput,
746  uint32_t *namesCountOutput,
747  char *namesString);
748 
749 XrResult
750 oxr_vk_get_requirements(struct oxr_logger *log,
751  struct oxr_system *sys,
752  XrGraphicsRequirementsVulkanKHR *graphicsRequirements);
753 
754 XrResult
755 oxr_vk_get_physical_device(struct oxr_logger *log,
756  struct oxr_instance *inst,
757  struct oxr_system *sys,
758  VkInstance vkInstance,
759  PFN_vkGetInstanceProcAddr getProc,
760  VkPhysicalDevice *vkPhysicalDevice);
761 
762 XrResult
763 oxr_session_populate_vk(struct oxr_logger *log,
764  struct oxr_system *sys,
765  XrGraphicsBindingVulkanKHR const *next,
766  struct oxr_session *sess);
767 
768 XrResult
769 oxr_swapchain_vk_create(struct oxr_logger *,
770  struct oxr_session *sess,
771  const XrSwapchainCreateInfo *,
772  struct oxr_swapchain **out_swapchain);
773 
774 #endif
775 
776 
777 /*
778  *
779  * EGL, located in various files.
780  *
781  */
782 
783 #ifdef XR_USE_PLATFORM_EGL
784 
785 XrResult
786 oxr_session_populate_egl(struct oxr_logger *log,
787  struct oxr_system *sys,
788  XrGraphicsBindingEGLMND const *next,
789  struct oxr_session *sess);
790 
791 #endif
792 
793 
794 /*
795  *
796  * Structs
797  *
798  */
799 
800 
801 /*!
802  * Used to hold diverse child handles and ensure orderly destruction.
803  *
804  * Each object referenced by an OpenXR handle should have one of these as its
805  * first element.
806  */
808 {
809  //! Magic (per-handle-type) value for debugging.
810  uint64_t debug;
811 
812  /*!
813  * Pointer to this object's parent handle holder, if any.
814  */
816 
817  /*!
818  * Array of children, if any.
819  */
820  struct oxr_handle_base *children[XRT_MAX_HANDLE_CHILDREN];
821 
822  /*!
823  * Current handle state.
824  */
826 
827  /*!
828  * Destroy the object this handle refers to.
829  */
830  oxr_handle_destroyer destroy;
831 };
832 
833 /*!
834  * Single or multiple devices grouped together to form a system that sessions
835  * can be created from. Might need to open devices in order to get all
836  * properties from it, but shouldn't.
837  *
838  * @obj{XrSystemId}
839  */
841 {
842  struct oxr_instance *inst;
843 
844  union {
845  struct
846  {
847  struct xrt_device *head;
848  struct xrt_device *left;
849  struct xrt_device *right;
850  };
851  struct xrt_device *xdevs[16];
852  };
853  size_t num_xdevs;
854 
855  XrSystemId systemId;
856 
857  XrFormFactor form_factor;
858  XrViewConfigurationType view_config_type;
859  XrViewConfigurationView views[2];
860  uint32_t num_blend_modes;
861  XrEnvironmentBlendMode blend_modes[3];
862 };
863 
864 #define MAKE_EXT_STATUS(mixed_case, all_caps) bool mixed_case;
865 /*!
866  * Structure tracking which extensions are enabled for a given instance.
867  *
868  * Names are systematic: the extension name with the XR_ prefix removed.
869  */
871 {
872  OXR_EXTENSION_SUPPORT_GENERATE(MAKE_EXT_STATUS)
873 };
874 
875 /*!
876  * Main object that ties everything together.
877  *
878  * @obj{XrInstance}
879  */
881 {
882  //! Common structure for things referred to by OpenXR handles.
883  struct oxr_handle_base handle;
884 
885  /* ---- HACK ---- */
886  void *hack;
887  /* ---- HACK ---- */
888 
889  struct xrt_prober *prober;
890 
891  //! Enabled extensions
892  struct oxr_extension_status extensions;
893 
894  // Hardcoded single system.
895  struct oxr_system system;
896 
897  struct time_state *timekeeping;
898 
899  //! Path store, for looking up paths.
901 
902  // Event queue.
903  struct oxr_event *last_event;
904  struct oxr_event *next_event;
905 
906  struct oxr_interaction_profile **profiles;
907  size_t num_profiles;
908 
909  struct oxr_session *sessions;
910 
911  struct
912  {
913  XrPath user;
914  XrPath head;
915  XrPath left;
916  XrPath right;
917  XrPath gamepad;
918 
919  XrPath khr_simple_controller;
920  XrPath google_daydream_controller;
921  XrPath htc_vive_controller;
922  XrPath htc_vive_pro;
923  XrPath microsoft_motion_controller;
924  XrPath microsoft_xbox_controller;
925  XrPath oculus_go_controller;
926  XrPath oculus_touch_controller;
927  XrPath valve_index_controller;
928  XrPath mnd_ball_on_stick_controller;
929  } path_cache;
930 
931  //! Debug messengers
932  struct oxr_debug_messenger *messengers[XRT_MAX_HANDLE_CHILDREN];
933 
934  bool lifecycle_verbose;
935  bool debug_views;
936  bool debug_spaces;
937  bool debug_bindings;
938 };
939 
940 /*!
941  * Object that client program interact with.
942  *
943  * @obj{XrSession}
944  */
946 {
947  //! Common structure for things referred to by OpenXR handles.
948  struct oxr_handle_base handle;
949  struct oxr_system *sys;
950  struct xrt_compositor *compositor;
951 
952  struct oxr_session *next;
953 
954  XrSessionState state;
955  bool frame_started;
956  bool exiting;
957 
958  struct u_hashmap_int *act_sets;
959  struct u_hashmap_int *sources;
960 
961  //! List of created source sets.
963 
964  //! Has xrAttachSessionActionSets been called?
966 
967  /*!
968  * Currently bound interaction profile.
969  * @{
970  */
971  XrPath left;
972  XrPath right;
973  XrPath head;
974  XrPath gamepad;
975  /*!
976  * @}
977  */
978 
979  /*!
980  * IPD, to be expanded to a proper 3D relation.
981  */
982  float ipd_meters;
983 
984  float static_prediction_s;
985 
986  /*!
987  * To pipe swapchain creation to right code.
988  */
989  XrResult (*create_swapchain)(struct oxr_logger *,
990  struct oxr_session *sess,
991  const XrSwapchainCreateInfo *,
992  struct oxr_swapchain **);
993 };
994 
995 /*!
996  * Returns XR_SUCCESS or XR_SESSION_LOSS_PENDING as appropriate.
997  */
998 static inline XrResult
999 oxr_session_success_result(struct oxr_session *session)
1000 {
1001  switch (session->state) {
1002  case XR_SESSION_STATE_LOSS_PENDING: return XR_SESSION_LOSS_PENDING;
1003  default: return XR_SUCCESS;
1004  }
1005 }
1006 
1007 /*!
1008  * Returns XR_SUCCESS, XR_SESSION_LOSS_PENDING, or XR_SESSION_NOT_FOCUSED, as
1009  * appropriate.
1010  */
1011 static inline XrResult
1012 oxr_session_success_focused_result(struct oxr_session *session)
1013 {
1014  switch (session->state) {
1015  case XR_SESSION_STATE_LOSS_PENDING: return XR_SESSION_LOSS_PENDING;
1016  case XR_SESSION_STATE_FOCUSED: return XR_SUCCESS;
1017  default: return XR_SESSION_NOT_FOCUSED;
1018  }
1019 }
1020 
1021 /*!
1022  * A single interaction profile.
1023  */
1025 {
1026  XrPath path;
1027  struct oxr_binding *bindings;
1028  size_t num_bindings;
1029 };
1030 
1031 /*!
1032  * Interaction profile binding state.
1033  */
1035 {
1036  XrPath *paths;
1037  size_t num_paths;
1038 
1039  enum oxr_sub_action_path sub_path;
1040 
1041  uint32_t *keys;
1042  size_t num_keys;
1043 
1044  enum xrt_input_name *inputs;
1045  size_t num_inputs;
1046 
1047  enum xrt_output_name *outputs;
1048  size_t num_outputs;
1049 };
1050 
1051 /*!
1052  * To carry around a sementic selection of sub action paths.
1053  */
1055 {
1056  bool any;
1057  bool user;
1058  bool head;
1059  bool left;
1060  bool right;
1061  bool gamepad;
1062 };
1063 
1064 /*!
1065  * Session input source.
1066  *
1067  * @see oxr_action_set
1068  */
1070 {
1071  //! Common structure for things referred to by OpenXR handles.
1072  struct oxr_handle_base handle;
1073 
1074  //! Owning session.
1076 
1077  //! Which sub-action paths are requested on the latest sync.
1078  struct oxr_sub_paths requested_sub_paths;
1079 
1080  //! Next source set on this session.
1082 };
1083 
1084 /*!
1085  * The state of a action input source.
1086  *
1087  * @see oxr_source
1088  */
1090 {
1091  union {
1092  struct
1093  {
1094  float x;
1095  } vec1;
1096 
1097  struct
1098  {
1099  float x;
1100  float y;
1101  } vec2;
1102 
1103  bool boolean;
1104  };
1105 
1106  bool active;
1107 
1108  // Was this changed.
1109  bool changed;
1110 
1111  //! When was this last changed.
1112  XrTime timestamp;
1113 };
1114 
1115 /*!
1116  * A input source pair of a @ref xrt_input and a @ref xrt_device.
1117  *
1118  * @see xrt_device
1119  * @see xrt_input
1120  */
1122 {
1123  struct xrt_device *xdev;
1124  struct xrt_input *input;
1125 };
1126 
1127 /*!
1128  * A output source pair of a @ref xrt_output_name and a @ref xrt_device.
1129  *
1130  * @see xrt_device
1131  * @see xrt_output_name
1132  */
1134 {
1135  struct xrt_device *xdev;
1136  enum xrt_output_name name;
1137 };
1138 
1139 /*!
1140  * A set of inputs for a single sub action path.
1141  *
1142  * @see oxr_source
1143  */
1145 {
1146  struct oxr_source_state current;
1147 
1148  size_t num_inputs;
1149  struct oxr_source_input *inputs;
1150 
1151  int64_t stop_output_time;
1152  size_t num_outputs;
1153  struct oxr_source_output *outputs;
1154 };
1155 
1156 /*!
1157  * Session input source.
1158  *
1159  * @see oxr_action
1160  */
1162 {
1163  //! Common structure for things referred to by OpenXR handles.
1164  struct oxr_handle_base handle;
1165 
1166  //! Type the action this source was created from is.
1167  XrActionType action_type;
1168 
1169  struct oxr_source_state any_state;
1170 
1171  struct oxr_source_cache user;
1172  struct oxr_source_cache head;
1173  struct oxr_source_cache left;
1174  struct oxr_source_cache right;
1175  struct oxr_source_cache gamepad;
1176 };
1177 
1178 /*!
1179  * Can be one of 3 references or a space that are bound to actions.
1180  *
1181  * @obj{XrSpace}
1182  */
1184 {
1185  //! Common structure for things referred to by OpenXR handles.
1186  struct oxr_handle_base handle;
1187 
1188  //! Onwer of this space.
1190 
1191  //! Pose that was given during creation.
1192  struct xrt_pose pose;
1193 
1194  //! What kind of reference space is this, if any.
1195  XrReferenceSpaceType type;
1196 
1197  //! Action key from which action this space was created from.
1198  uint32_t act_key;
1199 
1200  //! Is this a reference space?
1202 
1203  //! Which sub action path is this?
1204  struct oxr_sub_paths sub_paths;
1205 };
1206 
1207 /*!
1208  * A set of images used for rendering.
1209  *
1210  * @obj{XrSwapchain}
1211  */
1213 {
1214  //! Common structure for things referred to by OpenXR handles.
1215  struct oxr_handle_base handle;
1216 
1217  //! Onwer of this swapchain.
1219 
1220  //! Compositor swapchain.
1222 
1223  //! Actual state tracked! :D
1225  int released_index;
1226 
1227  XrResult (*destroy)(struct oxr_logger *, struct oxr_swapchain *);
1228 
1229  XrResult (*enumerate_images)(struct oxr_logger *,
1230  struct oxr_swapchain *,
1231  uint32_t,
1232  XrSwapchainImageBaseHeader *);
1233 
1234  XrResult (*acquire_image)(struct oxr_logger *,
1235  struct oxr_swapchain *,
1236  const XrSwapchainImageAcquireInfo *,
1237  uint32_t *);
1238 
1239  XrResult (*wait_image)(struct oxr_logger *,
1240  struct oxr_swapchain *,
1241  const XrSwapchainImageWaitInfo *);
1242 
1243  XrResult (*release_image)(struct oxr_logger *,
1244  struct oxr_swapchain *,
1245  const XrSwapchainImageReleaseInfo *);
1246 };
1247 
1248 /*!
1249  * A group of actions.
1250  *
1251  * @obj{XrActionSet}
1252  */
1254 {
1255  //! Common structure for things referred to by OpenXR handles.
1256  struct oxr_handle_base handle;
1257 
1258  //! Onwer of this messenger.
1260 
1261  //! Application supplied name of this action.
1262  char name[XR_MAX_ACTION_SET_NAME_SIZE];
1263 
1264  //! Has this action set been attached.
1265  bool attached;
1266 
1267  //! Unique key for the session hashmap.
1268  uint32_t key;
1269 };
1270 
1271 /*!
1272  * A single action.
1273  *
1274  * @obj{XrAction}
1275  */
1277 {
1278  //! Common structure for things referred to by OpenXR handles.
1279  struct oxr_handle_base handle;
1280 
1281  //! Onwer of this messenger.
1283 
1284  //! Application supplied name of this action.
1285  char name[XR_MAX_ACTION_NAME_SIZE];
1286 
1287  //! Unique key for the session hashmap.
1288  uint32_t key;
1289 
1290  //! Type this action was created with.
1291  XrActionType action_type;
1292 
1293  //! Which sub action paths that this action was created with.
1294  struct oxr_sub_paths sub_paths;
1295 };
1296 
1297 /*!
1298  * Debug object created by the client program.
1299  *
1300  * @obj{XrDebugUtilsMessengerEXT}
1301  */
1303 {
1304  //! Common structure for things referred to by OpenXR handles.
1305  struct oxr_handle_base handle;
1306 
1307  //! Onwer of this messenger.
1309 
1310  //! Severities to submit to this messenger
1311  XrDebugUtilsMessageSeverityFlagsEXT message_severities;
1312 
1313  //! Types to submit to this messenger
1314  XrDebugUtilsMessageTypeFlagsEXT message_types;
1315 
1316  //! Callback function
1317  PFN_xrDebugUtilsMessengerCallbackEXT user_callback;
1318 
1319  //! Opaque user data
1320  void *XR_MAY_ALIAS user_data;
1321 };
1322 
1323 /*!
1324  * @}
1325  */
1326 
1327 
1328 #ifdef __cplusplus
1329 }
1330 #endif
float ipd_meters
IPD, to be expanded to a proper 3D relation.
Definition: oxr_objects.h:982
XrResult oxr_action_enumerate_bound_sources(struct oxr_logger *log, struct oxr_session *sess, uint64_t key, uint32_t sourceCapacityInput, uint32_t *sourceCountOutput, XrPath *sources)
Definition: oxr_binding.c:432
A simple uint64_t key to a void pointer hashmap.
Definition: u_hashmap.cpp:22
Can be one of 3 references or a space that are bound to actions.
Definition: oxr_objects.h:1183
XrResult oxr_source_get_pose_input(struct oxr_logger *log, struct oxr_session *sess, uint32_t key, const struct oxr_sub_paths *sub_paths, struct oxr_source_input **out_input)
Find the pose input for the set of sub_paths.
Definition: oxr_input.c:221
uint32_t act_key
Action key from which action this space was created from.
Definition: oxr_objects.h:1198
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:171
Include all of the Vulkan headers in one place.
Hashmap for integer values header.
Session input source.
Definition: oxr_objects.h:1069
XrResult oxr_session_get_view_pose_at(struct oxr_logger *, struct oxr_session *sess, XrTime at_time, struct xrt_pose *)
Get the view space position at the given time in relation to the local or stage space.
Definition: oxr_session.c:186
A pose composed of a position and orientation.
Definition: xrt_defines.h:229
XrResult oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSessionBeginInfo *beginInfo)
Definition: oxr_session.c:93
enum xrt_device_name name
Enum identifier of the device.
Definition: xrt_device.h:206
void oxr_binding_find_bindings_from_key(struct oxr_logger *log, struct oxr_interaction_profile *profile, uint32_t key, struct oxr_binding *bindings[32], size_t *num_bindings)
Find all bindings that is the given action key is bound to.
Definition: oxr_binding.c:261
A output source pair of a xrt_output_name and a xrt_device.
Definition: oxr_objects.h:1133
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:419
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:59
Object that client program interact with.
Definition: oxr_objects.h:945
State after successful oxr_handle_init.
Definition: oxr_objects.h:102
XrResult oxr_action_suggest_interaction_profile_bindings(struct oxr_logger *log, struct oxr_instance *inst, const XrInteractionProfileSuggestedBinding *suggestedBindings)
Definition: oxr_binding.c:337
void *XR_MAY_ALIAS user_data
Opaque user data.
Definition: oxr_objects.h:1320
struct oxr_handle_base * children[XRT_MAX_HANDLE_CHILDREN]
Array of children, if any.
Definition: oxr_objects.h:820
XrResult oxr_action_set_create(struct oxr_logger *log, struct oxr_instance *inst, const XrActionSetCreateInfo *createInfo, struct oxr_action_set **out_act_set)
Definition: oxr_input.c:98
struct oxr_source_set * next
Next source set on this session.
Definition: oxr_objects.h:1081
A group of actions.
Definition: oxr_objects.h:1253
struct oxr_instance * inst
Onwer of this messenger.
Definition: oxr_objects.h:1308
XrResult oxr_create_messenger(struct oxr_logger *, struct oxr_instance *inst, const XrDebugUtilsMessengerCreateInfoEXT *, struct oxr_debug_messenger **out_mssngr)
Definition: oxr_messenger.c:42
XrResult oxr_handle_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
Destroy the handle&#39;s object, as well as all child handles recursively.
Definition: oxr_handle_base.c:211
uint32_t key
Unique key for the session hashmap.
Definition: oxr_objects.h:1268
Header defining a xrt HMD device.
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:334
Macros for generating extension-related tables and code and inspecting Monado&#39;s extension support...
A set of images used for rendering.
Definition: oxr_objects.h:1212
Hashset struct header.
State after successful oxr_handle_destroy.
Definition: oxr_objects.h:105
Logger struct that lives on the stack, one for each call client call.
Definition: oxr_logger.h:36
State during/before oxr_handle_init, or after failure.
Definition: oxr_objects.h:99
Kind of bespoke hashset implementation, where the user is responsible for allocating and freeing the ...
Definition: u_hashset.cpp:24
bool attached
Has this action set been attached.
Definition: oxr_objects.h:1265
XrResult oxr_space_locate(struct oxr_logger *log, struct oxr_space *spc, struct oxr_space *baseSpc, XrTime time, XrSpaceLocation *location)
Definition: oxr_space.c:327
uint64_t debug
Magic (per-handle-type) value for debugging.
Definition: oxr_objects.h:810
uint32_t key
Unique key for the session hashmap.
Definition: oxr_objects.h:1288
XrResult oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo, struct oxr_instance **out_inst)
Definition: oxr_instance.c:100
oxr_handle_state
State of a handle base, to reduce likelihood of going "boom" on out-of-order destruction or other uns...
Definition: oxr_objects.h:96
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:141
XrDebugUtilsMessageSeverityFlagsEXT message_severities
Severities to submit to this messenger.
Definition: oxr_objects.h:1311
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:494
To carry around a sementic selection of sub action paths.
Definition: oxr_objects.h:1054
XrResult oxr_session_views(struct oxr_logger *log, struct oxr_session *sess, const XrViewLocateInfo *viewLocateInfo, XrViewState *viewState, uint32_t viewCapacityInput, uint32_t *viewCountOutput, XrView *views)
Definition: oxr_session.c:299
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:147
XrReferenceSpaceType type
What kind of reference space is this, if any.
Definition: oxr_objects.h:1195
Common swapchain base.
Definition: xrt_compositor.h:75
struct oxr_session * sess
Onwer of this space.
Definition: oxr_objects.h:1189
XrResult oxr_space_ref_relation(struct oxr_logger *log, struct oxr_session *sess, XrReferenceSpaceType space, XrReferenceSpaceType baseSpc, XrTime time, struct xrt_space_relation *out_relation)
This returns only the relation between two spaces without any of the app given relations applied...
Definition: oxr_space.c:135
XrResult oxr_path_get_string(struct oxr_logger *log, 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:192
The state of a action input source.
Definition: oxr_objects.h:1089
Time-keeping state structure.
Definition: u_time.cpp:46
Header defining a XRT graphics provider.
bool actionsAttached
Has xrAttachSessionActionSets been called?
Definition: oxr_objects.h:965
XrPath left
Currently bound interaction profile.
Definition: oxr_objects.h:971
struct xrt_swapchain * swapchain
Compositor swapchain.
Definition: oxr_objects.h:1221
XrTime timestamp
When was this last changed.
Definition: oxr_objects.h:1112
struct oxr_source_set * src_set_list
List of created source sets.
Definition: oxr_objects.h:962
struct oxr_session * sess
Onwer of this swapchain.
Definition: oxr_objects.h:1218
int acquired_index
Actual state tracked! :D.
Definition: oxr_objects.h:1224
Header defining the tracking system integration in Monado.
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:246
Common compositor base.
Definition: xrt_compositor.h:116
A single action.
Definition: oxr_objects.h:1276
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:43
oxr_sub_action_path
Sub action paths.
Definition: oxr_objects.h:111
XrResult oxr_session_frame_wait(struct oxr_logger *log, struct oxr_session *sess, XrFrameState *frameState)
Definition: oxr_session.c:386
XrResult oxr_session_request_exit(struct oxr_logger *log, struct oxr_session *sess)
Definition: oxr_session.c:158
struct oxr_handle_base * parent
Pointer to this object&#39;s parent handle holder, if any.
Definition: oxr_objects.h:815
Definition: oxr_event.c:21
struct oxr_session * sess
Owning session.
Definition: oxr_objects.h:1075
Session input source.
Definition: oxr_objects.h:1161
void oxr_classify_sub_action_paths(struct oxr_logger *log, struct oxr_instance *inst, uint32_t num_subaction_paths, const XrPath *subaction_paths, struct oxr_sub_paths *sub_paths)
Helper function to classify sub_paths.
Definition: oxr_input.c:179
Single or multiple devices grouped together to form a system that sessions can be created from...
Definition: oxr_objects.h:840
Structure tracking which extensions are enabled for a given instance.
Definition: oxr_objects.h:870
Definition: xrt_device.h:193
Definition: p_prober.h:127
Include all of the openxr headers in one place.
Used to hold diverse child handles and ensure orderly destruction.
Definition: oxr_objects.h:807
Main object that ties everything together.
Definition: oxr_objects.h:880
A single named input, that sits on a xrt_device.
Definition: xrt_device.h:181
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:38
XrDebugUtilsMessageTypeFlagsEXT message_types
Types to submit to this messenger.
Definition: oxr_objects.h:1314
Debug object created by the client program.
Definition: oxr_objects.h:1302
struct u_hashset * path_store
Path store, for looking up paths.
Definition: oxr_objects.h:900
struct oxr_action_set * act_set
Onwer of this messenger.
Definition: oxr_objects.h:1282
A single interaction profile.
Definition: oxr_objects.h:1024
PFN_xrDebugUtilsMessengerCallbackEXT user_callback
Callback function.
Definition: oxr_objects.h:1317
bool is_reference
Is this a reference space?
Definition: oxr_objects.h:1201
void oxr_find_profile_for_device(struct oxr_logger *log, struct oxr_instance *inst, struct xrt_device *xdev, struct oxr_interaction_profile **out_p)
Find the best matching profile for the given xrt_device.
Definition: oxr_binding.c:228
XrResult oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const XrFrameEndInfo *frameEndInfo)
Definition: oxr_session.c:459
A single HMD or input device.
Definition: xrt_device.h:203
XrResult oxr_system_get_properties(struct oxr_logger *log, struct oxr_system *sys, XrSystemProperties *properties)
Definition: oxr_system.c:208
XrActionType action_type
Type the action this source was created from is.
Definition: oxr_objects.h:1167
oxr_handle_destroyer destroy
Destroy the object this handle refers to.
Definition: oxr_objects.h:830
#define OXR_EXTENSION_SUPPORT_GENERATE(_)
Call this, passing a macro taking two parameters, to generate tables, code, etc.
Definition: oxr_extension_support.h:127
void oxr_path_destroy_all(struct oxr_logger *log, struct oxr_instance *inst)
Destroy all paths that the instance has created.
Definition: oxr_path.c:215
xrt_input_name
Name of a input with a baked in type.
Definition: xrt_defines.h:417
A input source pair of a xrt_input and a xrt_device.
Definition: oxr_objects.h:1121
enum oxr_handle_state state
Current handle state.
Definition: oxr_objects.h:825
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:296
struct oxr_instance * inst
Onwer of this messenger.
Definition: oxr_objects.h:1259
XrActionType action_type
Type this action was created with.
Definition: oxr_objects.h:1291
Interaction profile binding state.
Definition: oxr_objects.h:1034
A set of inputs for a single sub action path.
Definition: oxr_objects.h:1144