Monado OpenXR Runtime
xrt_compositor.h
Go to the documentation of this file.
1 // Copyright 2019-2024, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Header declaring XRT graphics interfaces.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
8  * @author Rylie Pavlik <rylie.pavlik@collabora.com>
9  * @author Christoph Haag <christoph.haag@collabora.com>
10  * @author Korcan Hussein <korcan.hussein@collabora.com>
11  * @ingroup xrt_iface
12  */
13 
14 #pragma once
15 
16 #include "xrt/xrt_limits.h"
17 #include "xrt/xrt_defines.h"
18 #include "xrt/xrt_handles.h"
19 #include "xrt/xrt_config_os.h"
20 #include "xrt/xrt_config_have.h"
21 #include "xrt/xrt_windows.h"
22 
23 #if defined(XRT_HAVE_D3D11)
24 #include <d3d11.h>
25 #elif defined(XRT_DOXYGEN)
26 struct ID3D11Texture2D;
27 #endif
28 
29 #if defined(XRT_HAVE_D3D12)
30 #include <d3d12.h>
31 #elif defined(XRT_DOXYGEN)
32 struct ID3D12Resource;
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 
40 /*
41  *
42  * Pre-declare things, also they should not be in the xrt_iface group.
43  *
44  */
45 
46 struct xrt_device;
47 struct xrt_image_native;
48 struct xrt_compositor;
50 
51 typedef struct VkCommandBuffer_T *VkCommandBuffer;
52 #ifdef XRT_64_BIT
53 typedef struct VkImage_T *VkImage;
54 typedef struct VkDeviceMemory_T *VkDeviceMemory;
55 #else
56 typedef uint64_t VkImage;
57 typedef uint64_t VkDeviceMemory;
58 #endif
59 
60 
61 /*!
62  * @addtogroup xrt_iface
63  * @{
64  */
65 
66 
67 /*
68  *
69  * Layers.
70  *
71  */
72 
73 /*!
74  * Layer type.
75  */
77 {
78  XRT_LAYER_PROJECTION,
79  XRT_LAYER_PROJECTION_DEPTH,
80  XRT_LAYER_QUAD,
81  XRT_LAYER_CUBE,
82  XRT_LAYER_CYLINDER,
83  XRT_LAYER_EQUIRECT1,
84  XRT_LAYER_EQUIRECT2,
85  XRT_LAYER_PASSTHROUGH
86 };
87 
88 /*!
89  * Bit field for holding information about how a layer should be composited.
90  */
92 {
93  XRT_LAYER_COMPOSITION_CORRECT_CHROMATIC_ABERRATION_BIT = 1u << 0u,
94  XRT_LAYER_COMPOSITION_BLEND_TEXTURE_SOURCE_ALPHA_BIT = 1u << 1u,
95  XRT_LAYER_COMPOSITION_UNPREMULTIPLIED_ALPHA_BIT = 1u << 2u,
96  /*!
97  * The layer is locked to the device and the pose should only be
98  * adjusted for the IPD.
99  */
101 
102  /*!
103  * If this flag is set the compositor should use the scale and bias
104  * from the @ref xrt_layer_data struct.
105  */
107 
108  //! Normal super sampling, see XrCompositionLayerSettingsFlagsFB.
110 
111  //! Quality super sampling, see XrCompositionLayerSettingsFlagsFB.
113 
114  //! Normal sharpening, see XrCompositionLayerSettingsFlagsFB.
116 
117  //! Quality sharpening, see XrCompositionLayerSettingsFlagsFB.
119 
120  /*!
121  * This layer has advanced blending information, this bit
122  * supersedes the behavior of
123  * @ref XRT_LAYER_COMPOSITION_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
124  * see @p XrCompositionLayerAlphaBlendFB.
125  */
127 
128  /*!
129  * Depth testing is requested when composing this layer if this flag is set,
130  * see XrCompositionLayerDepthTestFB.
131  */
133 };
134 
135 /*!
136  * XrCompareOpFB
137  */
139 {
140  XRT_COMPARE_OP_NEVER_FB = 0,
141  XRT_COMPARE_OP_LESS_FB = 1,
142  XRT_COMPARE_OP_EQUAL_FB = 2,
143  XRT_COMPARE_OP_LESS_OR_EQUAL_FB = 3,
144  XRT_COMPARE_OP_GREATER_FB = 4,
145  XRT_COMPARE_OP_NOT_EQUAL_FB = 5,
146  XRT_COMPARE_OP_GREATER_OR_EQUAL_FB = 6,
147  XRT_COMPARE_OP_ALWAYS_FB = 7,
148  XRT_COMPARE_OP_MAX_ENUM_FB = 0x7FFFFFFF
149 };
150 
151 /*!
152  * Which view is the layer visible to?
153  *
154  * Used for quad layers.
155  *
156  * @note Doesn't have the same values as the OpenXR counterpart!
157  */
159 {
160  XRT_LAYER_EYE_VISIBILITY_NONE = 0x0,
161  XRT_LAYER_EYE_VISIBILITY_LEFT_BIT = 0x1,
162  XRT_LAYER_EYE_VISIBILITY_RIGHT_BIT = 0x2,
163  XRT_LAYER_EYE_VISIBILITY_BOTH = 0x3,
164 };
165 
166 /*!
167  * Blend factors.
168  */
170 {
171  XRT_BLEND_FACTOR_ZERO = 0,
172  XRT_BLEND_FACTOR_ONE = 1,
173  XRT_BLEND_FACTOR_SRC_ALPHA = 2,
174  XRT_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 3,
175  XRT_BLEND_FACTOR_DST_ALPHA = 4,
176  XRT_BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 5,
177  XRT_BLEND_FACTOR_MAX_ENUM_FB = 0x7FFFFFFF,
178 };
179 
180 /*!
181  * Advanced blend
182  * provides explicit control over source and destination blend factors,
183  * with separate controls for color and alpha
184  *
185  * See @ref XRT_LAYER_COMPOSITION_ADVANCED_BLENDING_BIT.
186  */
188 {
189  enum xrt_blend_factor src_factor_color;
190  enum xrt_blend_factor dst_factor_color;
191  enum xrt_blend_factor src_factor_alpha;
192  enum xrt_blend_factor dst_factor_alpha;
193 };
194 
195 /*!
196  * Specifies a sub-image in a layer.
197  */
199 {
200  //! Image index in the (implicit) swapchain
201  uint32_t image_index;
202  //! Index in image array (for array textures)
203  uint32_t array_index;
204  //! The rectangle in the image to use
205  struct xrt_rect rect;
206  //! Normalized sub image coordinates and size.
208 };
209 
210 /*!
211  * All of the pure data values associated with a single view in a projection
212  * layer.
213  *
214  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
215  * this struct.
216  */
218 {
219  struct xrt_sub_image sub;
220 
221  struct xrt_fov fov;
222  struct xrt_pose pose;
223 };
224 
225 /*!
226  * All the pure data values associated with a projection layer.
227  *
228  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
229  * this struct.
230  */
232 {
233  struct xrt_layer_projection_view_data v[XRT_MAX_VIEWS];
234 };
235 
236 /*!
237  * All the pure data values associated with a depth information attached
238  * to a layer.
239  *
240  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
241  * this struct.
242  */
244 {
245  struct xrt_sub_image sub;
246 
247  float min_depth;
248  float max_depth;
249  float near_z;
250  float far_z;
251 };
252 
254 {
255  bool depth_mask;
256  enum xrt_compare_op_fb compare_op;
257 };
258 
259 /*!
260  * All the pure data values associated with a projection layer with depth
261  * swapchain attached.
262  *
263  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
264  * this struct.
265  */
267 {
268  struct xrt_layer_projection_view_data v[XRT_MAX_VIEWS];
269 
270  struct xrt_layer_depth_data d[XRT_MAX_VIEWS];
271 };
272 
273 /*!
274  * All the pure data values associated with a quad layer.
275  *
276  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
277  * this struct.
278  */
280 {
281  enum xrt_layer_eye_visibility visibility;
282 
283  struct xrt_sub_image sub;
284 
285  struct xrt_pose pose;
286  struct xrt_vec2 size;
287 };
288 
289 /*!
290  * All the pure data values associated with a cube layer.
291  *
292  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
293  * this struct.
294  */
296 {
297  enum xrt_layer_eye_visibility visibility;
298 
299  struct xrt_sub_image sub;
300 
301  struct xrt_pose pose;
302 };
303 
304 /*!
305  * All the pure data values associated with a cylinder layer.
306  *
307  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
308  * this struct.
309  */
311 {
312  enum xrt_layer_eye_visibility visibility;
313 
314  struct xrt_sub_image sub;
315 
316  struct xrt_pose pose;
317  float radius;
318  float central_angle;
319  float aspect_ratio;
320 };
321 
322 /*!
323  * All the pure data values associated with a equirect1 layer.
324  *
325  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
326  * this struct.
327  */
329 {
330  enum xrt_layer_eye_visibility visibility;
331 
332  struct xrt_sub_image sub;
333 
334  struct xrt_pose pose;
335  float radius;
336  struct xrt_vec2 scale;
337  struct xrt_vec2 bias;
338 };
339 
340 /*!
341  * All the pure data values associated with a equirect2 layer.
342  *
343  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
344  * this struct.
345  */
347 {
348  enum xrt_layer_eye_visibility visibility;
349 
350  struct xrt_sub_image sub;
351 
352  struct xrt_pose pose;
353  float radius;
354  float central_horizontal_angle;
355  float upper_vertical_angle;
356  float lower_vertical_angle;
357 };
358 
359 /*!
360  * @interface xrt_passthrough
361  */
363 {
364  bool paused;
365 };
366 
367 /*!
368  * @interface xrt_passthrough_layer
369  */
371 {
372  bool paused;
373 };
374 
375 /*!
376  * All the pure data values associated with a passthrough layer.
377  *
378  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
379  * this struct.
380  */
382 {
383  struct xrt_passthrough xrt_pt;
384  struct xrt_passthrough_layer xrt_pl;
385 };
386 
387 /*!
388  * All the pure data values associated with a composition layer.
389  *
390  * The @ref xrt_swapchain references and @ref xrt_device are provided outside of
391  * this struct.
392  */
394 {
395  /*!
396  * Tag for compositor layer type.
397  */
398  enum xrt_layer_type type;
399 
400  /*!
401  * Often @ref XRT_INPUT_GENERIC_HEAD_POSE
402  */
403  enum xrt_input_name name;
404 
405  /*!
406  * "Display no-earlier-than" timestamp for this layer.
407  *
408  * The layer may be displayed after this point, but must never be
409  * displayed before.
410  */
411  uint64_t timestamp;
412 
413  /*!
414  * Composition flags
415  */
417 
418  /*!
419  * Depth test data
420  */
422 
423  /*!
424  * Whether the main compositor should flip the direction of y when
425  * rendering.
426  *
427  * This is actually an input only to the "main" compositor
428  * comp_compositor. It is overwritten by the various client
429  * implementations of the @ref xrt_compositor interface depending on the
430  * conventions of the associated graphics API. Other @ref
431  * xrt_compositor_native implementations that are not the main
432  * compositor just pass this field along unchanged to the "real"
433  * compositor.
434  */
435  bool flip_y;
436 
437  /*!
438  * Modulate the color sourced from the images.
439  */
441 
442  /*!
443  * Modulate the color sourced from the images.
444  */
446 
447  /*!
448  * Advanced blend factors
449  */
451 
452  /*!
453  * Union of data values for the various layer types.
454  *
455  * The initialized member of this union should match the value of
456  * xrt_layer_data::type. It also should be clear because of the layer
457  * function called between xrt_compositor::layer_begin and
458  * xrt_compositor::layer_commit where this data was passed.
459  */
460  union {
461  struct xrt_layer_projection_data proj;
462  struct xrt_layer_projection_depth_data depth;
463  struct xrt_layer_quad_data quad;
464  struct xrt_layer_cube_data cube;
465  struct xrt_layer_cylinder_data cylinder;
466  struct xrt_layer_equirect1_data equirect1;
467  struct xrt_layer_equirect2_data equirect2;
468  struct xrt_layer_passthrough_data passthrough;
469  };
470  uint32_t view_count;
471 };
472 
473 /*!
474  * Per frame data for the layer submission calls, used in
475  * @ref xrt_compositor::layer_begin.
476  */
478 {
479  int64_t frame_id;
480  uint64_t display_time_ns;
481  enum xrt_blend_mode env_blend_mode;
482 };
483 
484 
485 /*
486  *
487  * Swapchain.
488  *
489  */
490 
491 /*!
492  * Special flags for creating swapchain images.
493  */
495 {
496  //! Our compositor just ignores this bit.
498  //! Signals that the allocator should only allocate one image.
500 };
501 
502 /*!
503  * Usage of the swapchain images.
504  */
506 {
507  XRT_SWAPCHAIN_USAGE_COLOR = 0x00000001,
508  XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL = 0x00000002,
509  XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS = 0x00000004,
510  XRT_SWAPCHAIN_USAGE_TRANSFER_SRC = 0x00000008,
511  XRT_SWAPCHAIN_USAGE_TRANSFER_DST = 0x00000010,
512  XRT_SWAPCHAIN_USAGE_SAMPLED = 0x00000020,
513  XRT_SWAPCHAIN_USAGE_MUTABLE_FORMAT = 0x00000040,
514  XRT_SWAPCHAIN_USAGE_INPUT_ATTACHMENT = 0x00000080,
515 };
516 
517 /*!
518  * The direction of a transition.
519  */
521 {
522  XRT_BARRIER_TO_APP = 1,
523  XRT_BARRIER_TO_COMP = 2,
524 };
525 
526 /*!
527  * @interface xrt_swapchain
528  *
529  * Common swapchain interface/base.
530  *
531  * Swapchains are owned by the @ref xrt_compositor that they where created from,
532  * it's the state trackers job to ensure all swapchains are destroyed before
533  * destroying the @ref xrt_compositor.
534  */
536 {
537  /*!
538  * Reference helper.
539  */
540  struct xrt_reference reference;
541 
542  /*!
543  * Number of images.
544  *
545  * The images themselves are on the subclasses.
546  */
547  uint32_t image_count;
548 
549  /*!
550  * @ref dec_image_use must have been called as often as @ref inc_image_use.
551  */
552  void (*destroy)(struct xrt_swapchain *xsc);
553 
554  /*!
555  * Obtain the index of the next image to use, without blocking on being
556  * able to write to it.
557  *
558  * See xrAcquireSwapchainImage.
559  *
560  * Caller must make sure that no image is acquired before calling
561  * @ref xrt_swapchain_acquire_image.
562  *
563  * @param xsc Self pointer
564  * @param[out] out_index Image index to use next
565  *
566  * Call @ref xrt_swapchain_wait_image before writing to the image index output from this function.
567  */
568  xrt_result_t (*acquire_image)(struct xrt_swapchain *xsc, uint32_t *out_index);
569 
570  /*!
571  * @brief Increments the use counter of a swapchain image.
572  */
573  xrt_result_t (*inc_image_use)(struct xrt_swapchain *xsc, uint32_t index);
574 
575  /*!
576  * @brief Decrements the use counter of a swapchain image.
577  *
578  * @ref wait_image will return once the image use counter is 0.
579  */
580  xrt_result_t (*dec_image_use)(struct xrt_swapchain *xsc, uint32_t index);
581 
582  /*!
583  * Wait until image @p index is available for exclusive use, or until @p timeout_ns expires.
584  *
585  * See xrWaitSwapchainImage, which is the basis for this API.
586  * The state tracker needs to track image index, which should have come from @ref xrt_swapchain_acquire_image
587 
588  * @param xsc Self pointer
589  * @param timeout_ns Timeout in nanoseconds,
590  * @param index Image index to wait for.
591  */
592  xrt_result_t (*wait_image)(struct xrt_swapchain *xsc, uint64_t timeout_ns, uint32_t index);
593 
594  /*!
595  * Do any barrier transitions to and from the application.
596  *
597  * @param xsc Self pointer
598  * @param direction Direction of the barrier transition.
599  * @param index Image index to barrier transition.
600  */
601  xrt_result_t (*barrier_image)(struct xrt_swapchain *xsc, enum xrt_barrier_direction direction, uint32_t index);
602 
603  /*!
604  * See xrReleaseSwapchainImage, state tracker needs to track index.
605  */
606  xrt_result_t (*release_image)(struct xrt_swapchain *xsc, uint32_t index);
607 };
608 
609 /*!
610  * Update the reference counts on swapchain(s).
611  *
612  * @param[in,out] dst Pointer to a object reference: if the object reference is
613  * non-null will decrement its counter. The reference that
614  * @p dst points to will be set to @p src.
615  * @param[in] src New object for @p dst to refer to (may be null).
616  * If non-null, will have its refcount increased.
617  * @ingroup xrt_iface
618  * @relates xrt_swapchain
619  */
620 static inline void
622 {
623  struct xrt_swapchain *old_dst = *dst;
624 
625  if (old_dst == src) {
626  return;
627  }
628 
629  if (src) {
631  }
632 
633  *dst = src;
634 
635  if (old_dst) {
636  if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
637  old_dst->destroy(old_dst);
638  }
639  }
640 }
641 
642 /*!
643  * @copydoc xrt_swapchain::acquire_image
644  *
645  * Helper for calling through the function pointer.
646  *
647  * @public @memberof xrt_swapchain
648  */
649 static inline xrt_result_t
650 xrt_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *out_index)
651 {
652  return xsc->acquire_image(xsc, out_index);
653 }
654 
655 /*!
656  * @copydoc xrt_swapchain::inc_image_use
657  *
658  * Helper for calling through the function pointer.
659  *
660  * @public @memberof xrt_swapchain
661  */
662 static inline xrt_result_t
663 xrt_swapchain_inc_image_use(struct xrt_swapchain *xsc, uint32_t index)
664 {
665  return xsc->inc_image_use(xsc, index);
666 }
667 
668 /*!
669  * @copydoc xrt_swapchain::dec_image_use
670  *
671  * Helper for calling through the function pointer.
672  *
673  * @public @memberof xrt_swapchain
674  */
675 static inline xrt_result_t
676 xrt_swapchain_dec_image_use(struct xrt_swapchain *xsc, uint32_t index)
677 {
678  return xsc->dec_image_use(xsc, index);
679 }
680 
681 /*!
682  * @copydoc xrt_swapchain::wait_image
683  *
684  * Helper for calling through the function pointer.
685  *
686  * @public @memberof xrt_swapchain
687  */
688 static inline xrt_result_t
689 xrt_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout_ns, uint32_t index)
690 {
691  return xsc->wait_image(xsc, timeout_ns, index);
692 }
693 
694 /*!
695  * @copydoc xrt_swapchain::barrier_image
696  *
697  * Helper for calling through the function pointer.
698  *
699  * @public @memberof xrt_swapchain
700  */
701 static inline xrt_result_t
702 xrt_swapchain_barrier_image(struct xrt_swapchain *xsc, enum xrt_barrier_direction direction, uint32_t index)
703 {
704  return xsc->barrier_image(xsc, direction, index);
705 }
706 
707 /*!
708  * @copydoc xrt_swapchain::release_image
709  *
710  * Helper for calling through the function pointer.
711  *
712  * @public @memberof xrt_swapchain
713  */
714 static inline xrt_result_t
715 xrt_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index)
716 {
717  return xsc->release_image(xsc, index);
718 }
719 
720 
721 /*
722  *
723  * Fence.
724  *
725  */
726 
727 /*!
728  * Compositor fence used for syncornization.
729  */
731 {
732  /*!
733  * Waits on the fence with the given timeout.
734  */
735  xrt_result_t (*wait)(struct xrt_compositor_fence *xcf, uint64_t timeout);
736 
737  /*!
738  * Destroys the fence.
739  */
740  void (*destroy)(struct xrt_compositor_fence *xcf);
741 };
742 
743 /*!
744  * @copydoc xrt_compositor_fence::wait
745  *
746  * Helper for calling through the function pointer.
747  *
748  * @public @memberof xrt_compositor_fence
749  */
750 static inline xrt_result_t
751 xrt_compositor_fence_wait(struct xrt_compositor_fence *xcf, uint64_t timeout)
752 {
753  return xcf->wait(xcf, timeout);
754 }
755 
756 /*!
757  * @copydoc xrt_compositor_fence::destroy
758  *
759  * Helper for calling through the function pointer: does a null check and sets
760  * xcf_ptr to null if freed.
761  *
762  * @public @memberof xrt_compositor_fence
763  */
764 static inline void
766 {
767  struct xrt_compositor_fence *xcf = *xcf_ptr;
768  if (xcf == NULL) {
769  return;
770  }
771 
772  xcf->destroy(xcf);
773  *xcf_ptr = NULL;
774 }
775 
776 
777 /*
778  *
779  * Compositor semaphore.
780  *
781  */
782 
783 /*!
784  * Compositor semaphore used for synchronization, needs to be as capable as a
785  * Vulkan pipeline semaphore.
786  */
788 {
789  /*!
790  * Reference helper.
791  */
792  struct xrt_reference reference;
793 
794  /*!
795  * Does a CPU side wait on the semaphore to reach the given value.
796  */
797  xrt_result_t (*wait)(struct xrt_compositor_semaphore *xcsem, uint64_t value, uint64_t timeout_ns);
798 
799  /*!
800  * Destroys the semaphore.
801  */
802  void (*destroy)(struct xrt_compositor_semaphore *xcsem);
803 };
804 
805 /*!
806  * Update the reference counts on compositor semaphore(s).
807  *
808  * @param[in,out] dst Pointer to a object reference: if the object reference is
809  * non-null will decrement its counter. The reference that
810  * @p dst points to will be set to @p src.
811  * @param[in] src New object for @p dst to refer to (may be null).
812  * If non-null, will have its refcount increased.
813  * @ingroup xrt_iface
814  * @relates xrt_compositor_semaphore
815  */
816 static inline void
818 {
819  struct xrt_compositor_semaphore *old_dst = *dst;
820 
821  if (old_dst == src) {
822  return;
823  }
824 
825  if (src) {
827  }
828 
829  *dst = src;
830 
831  if (old_dst) {
832  if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
833  old_dst->destroy(old_dst);
834  }
835  }
836 }
837 
838 /*!
839  * @copydoc xrt_compositor_semaphore::wait
840  *
841  * Helper for calling through the function pointer.
842  *
843  * @public @memberof xrt_compositor_semaphore
844  */
845 static inline xrt_result_t
846 xrt_compositor_semaphore_wait(struct xrt_compositor_semaphore *xcsem, uint64_t value, uint64_t timeout)
847 {
848  return xcsem->wait(xcsem, value, timeout);
849 }
850 
851 
852 /*
853  *
854  * Compositor.
855  *
856  */
857 
858 /*!
859  * View type to be rendered to by the compositor.
860  */
862 {
863  XRT_VIEW_TYPE_MONO = 1,
864  XRT_VIEW_TYPE_STEREO = 2,
865 };
866 
868 {
869  XRT_COMPOSITOR_FRAME_POINT_WOKE, //!< The client woke up after waiting.
870 };
871 
872 /*!
873  * Swapchain creation info.
874  */
876 {
877  enum xrt_swapchain_create_flags create;
878  enum xrt_swapchain_usage_bits bits;
879  uint32_t format;
880  uint32_t sample_count;
881  uint32_t width;
882  uint32_t height;
883  uint32_t face_count;
884  uint32_t array_size;
885  uint32_t mip_count;
886 
887  /*
888  * List of formats that could be used when creating views of the swapchain images.
889  * See XR_KHR_vulkan_swapchain_format_list and VK_KHR_image_format_list
890  */
891  uint32_t format_count;
893 };
894 
895 /*!
896  * Passthrough creation info.
897  */
899 {
900  enum xrt_passthrough_create_flags create;
901 };
902 
903 /*!
904  * Passthrough layer creation info.
905  */
907 {
908  enum xrt_passthrough_create_flags create;
909  enum xrt_passthrough_purpose_flags purpose;
910 };
911 
912 /*!
913  * Struct used to negotiate properties of a swapchain that is created outside
914  * of the compositor. Often used by a client compositor or IPC layer to allocate
915  * the swapchain images and then pass them into the native compositor.
916  */
918 {
919  //! How many images the compositor want in the swapchain.
920  uint32_t image_count;
921 
922  //! New creation bits.
924 };
925 
926 /*!
927  * Session information, mostly overlay extension data.
928  */
930 {
931  bool is_overlay;
932  uint64_t flags;
933  uint32_t z_order;
934 };
935 
936 /*!
937  * Capabilities and information about the compositor and device together.
938  *
939  * For client compositors the formats of the native compositor are translated.
940  */
942 {
943  //! Number of formats, never changes.
944  uint32_t format_count;
945 
946  //! Supported formats, never changes.
948 
949  //! Max texture size that GPU supports (size of a single dimension), zero means any size.
951 };
952 
953 /*!
954  * Begin Session information not known until clients have created an xrt-instance such as which
955  * extensions are enabled, view type, etc.
956  */
958 {
959  enum xrt_view_type view_type;
960  bool ext_hand_tracking_enabled;
961  bool ext_eye_gaze_interaction_enabled;
962  bool ext_hand_interaction_enabled;
963  bool htc_facial_tracking_enabled;
964 };
965 
966 /*!
967  * Hints the XR runtime what type of task the thread is doing.
968  */
970 {
971  XRT_THREAD_HINT_APPLICATION_MAIN = 1,
972  XRT_THREAD_HINT_APPLICATION_WORKER = 2,
973  XRT_THREAD_HINT_RENDERER_MAIN = 3,
974  XRT_THREAD_HINT_RENDERER_WORKER = 4,
975 };
976 
977 /*!
978  * @interface xrt_compositor
979  *
980  * Common compositor client interface/base.
981  *
982  * A compositor is very much analogous to a `XrSession` but without any of the
983  * input functionality, and does have the same life time as a `XrSession`.
984  */
986 {
987  /*!
988  * Capabilities and recommended values information.
989  */
990  struct xrt_compositor_info info;
991 
992  /*!
993  * For a given @ref xrt_swapchain_create_info struct returns a filled
994  * out @ref xrt_swapchain_create_properties.
995  */
997  const struct xrt_swapchain_create_info *info,
998  struct xrt_swapchain_create_properties *xsccp);
999 
1000  /*!
1001  * @name Function pointers for swapchain and sync creation and import
1002  * @{
1003  */
1004  /*!
1005  * Create a swapchain with a set of images.
1006  *
1007  * The pointer pointed to by @p out_xsc has to either be NULL or a valid
1008  * @ref xrt_swapchain pointer. If there is a valid @ref xrt_swapchain
1009  * pointed by the pointed pointer it will have it reference decremented.
1010  */
1012  const struct xrt_swapchain_create_info *info,
1013  struct xrt_swapchain **out_xsc);
1014 
1015  /*!
1016  * Create a swapchain from a set of native images.
1017  *
1018  * The pointer pointed to by @p out_xsc has to either be NULL or a valid
1019  * @ref xrt_swapchain pointer. If there is a valid @ref xrt_swapchain
1020  * pointed by the pointed pointer it will have it reference decremented.
1021  */
1023  const struct xrt_swapchain_create_info *info,
1024  struct xrt_image_native *native_images,
1025  uint32_t image_count,
1026  struct xrt_swapchain **out_xsc);
1027 
1028  /*!
1029  * Create a compositor fence from a native sync handle.
1030  */
1033  struct xrt_compositor_fence **out_xcf);
1034 
1035  /*!
1036  * Create a compositor semaphore, also returns a native handle.
1037  */
1039  xrt_graphics_sync_handle_t *out_handle,
1040  struct xrt_compositor_semaphore **out_xcsem);
1041  /*! @} */
1042 
1043  /*!
1044  * Create a passthrough.
1045  */
1047 
1048 
1049  /*!
1050  * Create a passthrough layer.
1051  */
1053  const struct xrt_passthrough_layer_create_info *info);
1054  /*!
1055  * Destroy a passthrough.
1056  */
1058 
1059  /*!
1060  * @name Function pointers for session functions
1061  * @{
1062  */
1063  /*!
1064  * See xrBeginSession.
1065  */
1067 
1068  /*!
1069  * See xrEndSession, unlike the OpenXR one the state tracker is
1070  * responsible to call discard frame before calling this function. See
1071  * discard_frame.
1072  */
1074 
1075  /*! @} */
1076 
1077  /*!
1078  * @name Function pointers for frame functions
1079  * @{
1080  */
1081 
1082  /*!
1083  * This function and @ref mark_frame function calls are a alternative to
1084  * @ref wait_frame.
1085  *
1086  * The only requirement on the compositor for the @p frame_id
1087  * is that it is a positive number and larger then the last returned
1088  * frame_id.
1089  *
1090  * After a call to predict_frame, the state tracker is not allowed to
1091  * call this function until after a call to @ref mark_frame (with point
1092  * @ref XRT_COMPOSITOR_FRAME_POINT_WOKE), followed by either
1093  * @ref begin_frame or @ref discard_frame.
1094  *
1095  * @param[in] xc The compositor
1096  * @param[out] out_frame_id Frame id
1097  * @param[out] out_wake_time_ns When we want the client to be awoken to begin rendering.
1098  * @param[out] out_predicted_gpu_time_ns When we expect the client to finish the GPU work. If not
1099  * computed/available, set to 0.
1100  * @param[out] out_predicted_display_time_ns When the pixels turns into photons.
1101  * @param[out] out_predicted_display_period_ns The period for the frames.
1102  */
1104  int64_t *out_frame_id,
1105  uint64_t *out_wake_time_ns,
1106  uint64_t *out_predicted_gpu_time_ns,
1107  uint64_t *out_predicted_display_time_ns,
1108  uint64_t *out_predicted_display_period_ns);
1109 
1110  /*!
1111  * This function and @ref predict_frame function calls are a alternative to
1112  * @ref wait_frame.
1113  *
1114  * If point is @ref XRT_COMPOSITOR_FRAME_POINT_WOKE it is to mark that the
1115  * client woke up from waiting on a frame.
1116  *
1117  * @param[in] xc The compositor
1118  * @param[in] frame_id Frame id
1119  * @param[in] point What type of frame point to mark.
1120  * @param[in] when_ns When this point happened.
1121  */
1123  int64_t frame_id,
1124  enum xrt_compositor_frame_point point,
1125  uint64_t when_ns);
1126 
1127  /*!
1128  * See xrWaitFrame.
1129  *
1130  * This function has the same semantics as calling @ref predict_frame,
1131  * sleeping, and then calling @ref mark_frame with a point of
1132  * @ref XRT_COMPOSITOR_FRAME_POINT_WOKE.
1133  *
1134  * The only requirement on the compositor for the @p frame_id
1135  * is that it is a positive number and larger then the last returned
1136  * @p frame_id.
1137  *
1138  * After a call to wait_frame, the state tracker is not allowed to call
1139  * this function until after a call to either @ref begin_frame or
1140  * @ref discard_frame.
1141  *
1142  * If the caller can do its own blocking, use the pair of functions
1143  * xrt_compositor::predict_frame and xrt_compositor::mark_frame instead
1144  * of this single blocking function.
1145  */
1147  int64_t *out_frame_id,
1148  uint64_t *out_predicted_display_time,
1149  uint64_t *out_predicted_display_period);
1150 
1151  /*!
1152  * See xrBeginFrame.
1153  *
1154  * Must have made a call to either @ref predict_frame or @ref wait_frame
1155  * before calling this function. After this function is called you must
1156  * call layer_commit.
1157  *
1158  * @param[in] xc The compositor
1159  * @param[in] frame_id Frame id
1160  */
1161  xrt_result_t (*begin_frame)(struct xrt_compositor *xc, int64_t frame_id);
1162 
1163  /*!
1164  * @brief Explicitly discard a frame.
1165  *
1166  * This isn't in the OpenXR API but is explicit in the XRT interfaces.
1167  *
1168  * Two calls to xrBeginFrame without intervening xrEndFrame will cause
1169  * the state tracker to call:
1170  *
1171  * ```c
1172  * // first xrBeginFrame
1173  * xrt_comp_begin_frame(xc, frame_id);
1174  * // second xrBeginFrame
1175  * xrt_comp_discard_frame(xc, frame_id);
1176  * xrt_comp_begin_frame(xc, frame_id);
1177  * ```
1178  */
1179  xrt_result_t (*discard_frame)(struct xrt_compositor *xc, int64_t frame_id);
1180 
1181  /*! @} */
1182 
1183 
1184  /*!
1185  * @name Function pointers for layer submission
1186  * @{
1187  */
1188  /*!
1189  * @brief Begins layer submission.
1190  *
1191  * This and the other `layer_*` calls are equivalent to xrEndFrame,
1192  * except split over multiple calls. It's only after
1193  * xrt_compositor::layer_commit that layers will be displayed.
1194  * From the point of view of the swapchain, the image is used as
1195  * soon as it's given in a call.
1196  */
1197  xrt_result_t (*layer_begin)(struct xrt_compositor *xc, const struct xrt_layer_frame_data *data);
1198 
1199  /*!
1200  * @brief Adds a projection layer for submissions.
1201  *
1202  * Note that e.g. the same swapchain object may be passed as both
1203  * @p l_xsc and @p r_xsc - the parameters in @p data identify
1204  * the subrect and array texture index to use for each of the views.
1205  *
1206  * @param xc Self pointer
1207  * @param xdev The device the layer is relative to.
1208  * @param xsc Swapchain object containing eye RGB data.
1209  * @param data All of the pure data bits (not pointers/handles),
1210  * including what parts of the supplied swapchain
1211  * objects to use for each view.
1212  */
1214  struct xrt_device *xdev,
1215  struct xrt_swapchain *xsc[XRT_MAX_VIEWS],
1216  const struct xrt_layer_data *data);
1217 
1218  /*!
1219  * @brief Adds a projection layer for submission, has depth information.
1220  *
1221  * Note that e.g. the same swapchain object may be passed as both
1222  * @p l_xsc and @p r_xsc - the parameters in @p data identify
1223  * the subrect and array texture index to use for each of the views.
1224  * This flexibility is required by the OpenXR API and is passed through
1225  * to the compositor to preserve the maximum information
1226  *
1227  * @param xc Self pointer
1228  * @param xdev The device the layer is relative to.
1229  * @param l_xsc Swapchain object containing left eye RGB data.
1230  * @param r_xsc Swapchain object containing right eye RGB data.
1231  * @param l_d_xsc Swapchain object containing left eye depth data.
1232  * @param r_d_xsc Swapchain object containing right eye depth data.
1233  * @param data All of the pure data bits (not pointers/handles),
1234  * including what parts of the supplied swapchain
1235  * objects to use for each view.
1236  */
1238  struct xrt_device *xdev,
1239  struct xrt_swapchain *xsc[XRT_MAX_VIEWS],
1240  struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS],
1241  const struct xrt_layer_data *data);
1242 
1243  /*!
1244  * Adds a quad layer for submission, the center of the quad is specified
1245  * by the pose and extends outwards from it.
1246  *
1247  * @param xc Self pointer
1248  * @param xdev The device the layer is relative to.
1249  * @param xsc Swapchain.
1250  * @param data All of the pure data bits (not pointers/handles),
1251  * including what part of the supplied swapchain
1252  * object to use.
1253  */
1255  struct xrt_device *xdev,
1256  struct xrt_swapchain *xsc,
1257  const struct xrt_layer_data *data);
1258 
1259  /*!
1260  * Adds a cube layer for submission.
1261  *
1262  * @param xc Self pointer
1263  * @param xdev The device the layer is relative to.
1264  * @param xsc Swapchain.
1265  * @param data All of the pure data bits (not pointers/handles),
1266  * including what part of the supplied swapchain
1267  * object to use.
1268  */
1270  struct xrt_device *xdev,
1271  struct xrt_swapchain *xsc,
1272  const struct xrt_layer_data *data);
1273 
1274  /*!
1275  * Adds a cylinder layer for submission.
1276  *
1277  * @param xc Self pointer
1278  * @param xdev The device the layer is relative to.
1279  * @param xsc Swapchain.
1280  * @param data All of the pure data bits (not pointers/handles),
1281  * including what part of the supplied swapchain
1282  * object to use.
1283  */
1285  struct xrt_device *xdev,
1286  struct xrt_swapchain *xsc,
1287  const struct xrt_layer_data *data);
1288 
1289  /*!
1290  * Adds a equirect1 layer for submission.
1291  *
1292  * @param xc Self pointer
1293  * @param xdev The device the layer is relative to.
1294  * @param xsc Swapchain.
1295  * @param data All of the pure data bits (not pointers/handles),
1296  * including what part of the supplied swapchain
1297  * object to use.
1298  */
1300  struct xrt_device *xdev,
1301  struct xrt_swapchain *xsc,
1302  const struct xrt_layer_data *data);
1303 
1304 
1305  /*!
1306  * Adds a equirect2 layer for submission.
1307  *
1308  * @param xc Self pointer
1309  * @param xdev The device the layer is relative to.
1310  * @param xsc Swapchain.
1311  * @param data All of the pure data bits (not pointers/handles),
1312  * including what part of the supplied swapchain
1313  * object to use.
1314  */
1316  struct xrt_device *xdev,
1317  struct xrt_swapchain *xsc,
1318  const struct xrt_layer_data *data);
1319 
1320  /*!
1321  * Adds a passthrough layer for submission.
1322  *
1323  * @param xc Self pointer
1324  * @param xdev The device the layer is relative to.
1325  * @param data All of the pure data bits (not pointers/handles),
1326  * including what part of the supplied swapchain
1327  * object to use.
1328  */
1330  struct xrt_device *xdev,
1331  const struct xrt_layer_data *data);
1332 
1333  /*!
1334  * @brief Commits all of the submitted layers.
1335  *
1336  * Only after this call will the compositor actually use the layers.
1337  */
1339 
1340  /*!
1341  * @brief Commits all of the submitted layers, with a semaphore.
1342  *
1343  * Only after this call will the compositor actually use the layers.
1344  * @param xc Self pointer
1345  * @param frame_id The frame id this commit is for.
1346  * @param xcsem Semaphore that will be signalled when the app GPU
1347  * work has completed.
1348  * @param value Semaphore value upone completion of GPU work.
1349  */
1351  struct xrt_compositor_semaphore *xcsem,
1352  uint64_t value);
1353 
1354  /*! @} */
1355 
1356 
1357  /*!
1358  * @name Function pointers for XR_FB_display_refresh_rate.
1359  * @{
1360  */
1361 
1362  /*!
1363  * Get the current display refresh rate.
1364  *
1365  * @param xc Self pointer
1366  * @param out_display_refresh_rate_hz Current display refresh rate in Hertz.
1367  */
1368  xrt_result_t (*get_display_refresh_rate)(struct xrt_compositor *xc, float *out_display_refresh_rate_hz);
1369 
1370  /*!
1371  * Request system to change the display refresh rate to the requested value.
1372  *
1373  * @param xc Self pointer
1374  * @param display_refresh_rate_hz Requested display refresh rate in Hertz.
1375  */
1376  xrt_result_t (*request_display_refresh_rate)(struct xrt_compositor *xc, float display_refresh_rate_hz);
1377 
1378  /*! @} */
1379 
1380 
1381  /*!
1382  * @brief Set CPU/GPU performance level.
1383  */
1385  enum xrt_perf_domain domain,
1386  enum xrt_perf_set_level level);
1387 
1388  /*!
1389  * Teardown the compositor.
1390  *
1391  * The state tracker must have made sure that no frames or sessions are
1392  * currently pending.
1393  *
1394  * @see xrt_compositor::discard_frame or xrt_compositor::end_frame for a pending frame
1395  * @see xrt_compositor::end_session for an open session.
1396  */
1397  void (*destroy)(struct xrt_compositor *xc);
1398 
1399  /*!
1400  * @name Function pointers for extensions
1401  * @{
1402  */
1403 
1404  /*!
1405  * @brief Set thread attributes according to thread type
1406  */
1407  xrt_result_t (*set_thread_hint)(struct xrt_compositor *xc, enum xrt_thread_hint hint, uint32_t thread_id);
1408 
1409  /*! @} */
1410 };
1411 
1412 /*!
1413  * @copydoc xrt_compositor::get_swapchain_create_properties
1414  *
1415  * Helper for calling through the function pointer.
1416  *
1417  * @public @memberof xrt_compositor
1418  */
1419 static inline xrt_result_t
1421  const struct xrt_swapchain_create_info *info,
1422  struct xrt_swapchain_create_properties *xsccp)
1423 {
1424  return xc->get_swapchain_create_properties(xc, info, xsccp);
1425 }
1426 
1427 /*!
1428  * @name Swapchain and sync creation and import methods
1429  * @{
1430  */
1431 
1432 /*!
1433  * @copydoc xrt_compositor::create_swapchain
1434  *
1435  * Helper for calling through the function pointer.
1436  *
1437  * @public @memberof xrt_compositor
1438  */
1439 static inline xrt_result_t
1441  const struct xrt_swapchain_create_info *info,
1442  struct xrt_swapchain **out_xsc)
1443 {
1444  return xc->create_swapchain(xc, info, out_xsc);
1445 }
1446 
1447 /*!
1448  * @copydoc xrt_compositor::import_swapchain
1449  *
1450  * Helper for calling through the function pointer.
1451  *
1452  * @public @memberof xrt_compositor
1453  */
1454 static inline xrt_result_t
1456  const struct xrt_swapchain_create_info *info,
1457  struct xrt_image_native *native_images,
1458  uint32_t image_count,
1459  struct xrt_swapchain **out_xsc)
1460 {
1461  return xc->import_swapchain(xc, info, native_images, image_count, out_xsc);
1462 }
1463 
1464 /*!
1465  * @copydoc xrt_compositor::import_fence
1466  *
1467  * Helper for calling through the function pointer.
1468  *
1469  * @public @memberof xrt_compositor
1470  */
1471 static inline xrt_result_t
1474  struct xrt_compositor_fence **out_xcf)
1475 {
1476  return xc->import_fence(xc, handle, out_xcf);
1477 }
1478 
1479 /*!
1480  * @copydoc xrt_compositor::create_semaphore
1481  *
1482  * Helper for calling through the function pointer.
1483  *
1484  * @public @memberof xrt_compositor
1485  */
1486 static inline xrt_result_t
1488  xrt_graphics_sync_handle_t *out_handle,
1489  struct xrt_compositor_semaphore **out_xcsem)
1490 {
1491  return xc->create_semaphore(xc, out_handle, out_xcsem);
1492 }
1493 
1494 /*! @} */
1495 
1496 /*!
1497  * @copydoc xrt_compositor::create_passthrough
1498  *
1499  * Helper for calling through the function pointer.
1500  *
1501  * @public @memberof xrt_compositor
1502  */
1503 static inline xrt_result_t
1505 {
1506  return xc->create_passthrough(xc, info);
1507 }
1508 
1509 /*!
1510  * @copydoc xrt_compositor::create_passthrough_layer
1511  *
1512  * Helper for calling through the function pointer.
1513  *
1514  * @public @memberof xrt_compositor
1515  */
1516 static inline xrt_result_t
1518 {
1519  return xc->create_passthrough_layer(xc, info);
1520 }
1521 
1522 /*!
1523  * @copydoc xrt_compositor::destroy_passthrough
1524  *
1525  * Helper for calling through the function pointer.
1526  *
1527  * @public @memberof xrt_compositor
1528  */
1529 static inline xrt_result_t
1531 {
1532  return xc->destroy_passthrough(xc);
1533 }
1534 
1535 /*!
1536  * @name Session methods
1537  * @{
1538  */
1539 
1540 /*!
1541  * @copydoc xrt_compositor::begin_session
1542  *
1543  * Helper for calling through the function pointer.
1544  *
1545  * @public @memberof xrt_compositor
1546  */
1547 static inline xrt_result_t
1549 {
1550  return xc->begin_session(xc, info);
1551 }
1552 
1553 /*!
1554  * @copydoc xrt_compositor::end_session
1555  *
1556  * Helper for calling through the function pointer.
1557  *
1558  * @public @memberof xrt_compositor
1559  */
1560 static inline xrt_result_t
1562 {
1563  return xc->end_session(xc);
1564 }
1565 
1566 /*! @} */
1567 
1568 
1569 /*!
1570  * @name Frame-related methods
1571  * @brief Related to the OpenXR `xr*Frame` functions
1572  * @{
1573  */
1574 
1575 /*!
1576  * @copydoc xrt_compositor::predict_frame
1577  *
1578  * Helper for calling through the function pointer.
1579  *
1580  * @public @memberof xrt_compositor
1581  */
1582 static inline xrt_result_t
1584  int64_t *out_frame_id,
1585  uint64_t *out_wake_time_ns,
1586  uint64_t *out_predicted_gpu_time_ns,
1587  uint64_t *out_predicted_display_time_ns,
1588  uint64_t *out_predicted_display_period_ns)
1589 {
1590  return xc->predict_frame( //
1591  xc, //
1592  out_frame_id, //
1593  out_wake_time_ns, //
1594  out_predicted_gpu_time_ns, //
1595  out_predicted_display_time_ns, //
1596  out_predicted_display_period_ns); //
1597 }
1598 
1599 /*!
1600  * @copydoc xrt_compositor::mark_frame
1601  *
1602  * Helper for calling through the function pointer.
1603  *
1604  * @public @memberof xrt_compositor
1605  */
1606 static inline xrt_result_t
1608  int64_t frame_id,
1609  enum xrt_compositor_frame_point point,
1610  uint64_t when_ns)
1611 {
1612  return xc->mark_frame(xc, frame_id, point, when_ns);
1613 }
1614 
1615 /*!
1616  * @copydoc xrt_compositor::wait_frame
1617  *
1618  * Helper for calling through the function pointer.
1619  *
1620  * @public @memberof xrt_compositor
1621  */
1622 static inline xrt_result_t
1624  int64_t *out_frame_id,
1625  uint64_t *out_predicted_display_time,
1626  uint64_t *out_predicted_display_period)
1627 {
1628  return xc->wait_frame(xc, out_frame_id, out_predicted_display_time, out_predicted_display_period);
1629 }
1630 
1631 /*!
1632  * @copydoc xrt_compositor::begin_frame
1633  *
1634  * Helper for calling through the function pointer.
1635  *
1636  * @public @memberof xrt_compositor
1637  */
1638 static inline xrt_result_t
1639 xrt_comp_begin_frame(struct xrt_compositor *xc, int64_t frame_id)
1640 {
1641  return xc->begin_frame(xc, frame_id);
1642 }
1643 
1644 /*!
1645  * @copydoc xrt_compositor::discard_frame
1646  *
1647  * Helper for calling through the function pointer.
1648  *
1649  * @public @memberof xrt_compositor
1650  */
1651 static inline xrt_result_t
1652 xrt_comp_discard_frame(struct xrt_compositor *xc, int64_t frame_id)
1653 {
1654  return xc->discard_frame(xc, frame_id);
1655 }
1656 
1657 /*! @} */
1658 
1659 
1660 /*!
1661  * @name Layer submission methods
1662  * @brief Equivalent to `xrEndFrame`, but split across multiple calls.
1663  * @{
1664  */
1665 
1666 /*!
1667  * @copydoc xrt_compositor::layer_begin
1668  *
1669  * Helper for calling through the function pointer.
1670  *
1671  * @public @memberof xrt_compositor
1672  */
1673 static inline xrt_result_t
1675 {
1676  return xc->layer_begin(xc, data);
1677 }
1678 
1679 /*!
1680  * @copydoc xrt_compositor::layer_projection
1681  *
1682  * Helper for calling through the function pointer.
1683  *
1684  * @public @memberof xrt_compositor
1685  */
1686 static inline xrt_result_t
1688  struct xrt_device *xdev,
1689  struct xrt_swapchain *xsc[XRT_MAX_VIEWS],
1690  const struct xrt_layer_data *data)
1691 {
1692  return xc->layer_projection(xc, xdev, xsc, data);
1693 }
1694 
1695 /*!
1696  * @copydoc xrt_compositor::layer_projection_depth
1697  *
1698  * Helper for calling through the function pointer.
1699  *
1700  * @public @memberof xrt_compositor
1701  */
1702 static inline xrt_result_t
1704  struct xrt_device *xdev,
1705  struct xrt_swapchain *xsc[XRT_MAX_VIEWS],
1706  struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS],
1707  const struct xrt_layer_data *data)
1708 {
1709  return xc->layer_projection_depth(xc, xdev, xsc, d_xsc, data);
1710 }
1711 
1712 /*!
1713  * @copydoc xrt_compositor::layer_quad
1714  *
1715  * Helper for calling through the function pointer.
1716  *
1717  * @public @memberof xrt_compositor
1718  */
1719 static inline xrt_result_t
1721  struct xrt_device *xdev,
1722  struct xrt_swapchain *xsc,
1723  const struct xrt_layer_data *data)
1724 {
1725  return xc->layer_quad(xc, xdev, xsc, data);
1726 }
1727 
1728 /*!
1729  * @copydoc xrt_compositor::layer_cube
1730  *
1731  * Helper for calling through the function pointer.
1732  *
1733  * @public @memberof xrt_compositor
1734  */
1735 static inline xrt_result_t
1737  struct xrt_device *xdev,
1738  struct xrt_swapchain *xsc,
1739  const struct xrt_layer_data *data)
1740 {
1741  return xc->layer_cube(xc, xdev, xsc, data);
1742 }
1743 
1744 /*!
1745  * @copydoc xrt_compositor::layer_cylinder
1746  *
1747  * Helper for calling through the function pointer.
1748  *
1749  * @public @memberof xrt_compositor
1750  */
1751 static inline xrt_result_t
1753  struct xrt_device *xdev,
1754  struct xrt_swapchain *xsc,
1755  const struct xrt_layer_data *data)
1756 {
1757  return xc->layer_cylinder(xc, xdev, xsc, data);
1758 }
1759 
1760 
1761 /*!
1762  * @copydoc xrt_compositor::layer_equirect1
1763  *
1764  * Helper for calling through the function pointer.
1765  *
1766  * @public @memberof xrt_compositor
1767  */
1768 static inline xrt_result_t
1770  struct xrt_device *xdev,
1771  struct xrt_swapchain *xsc,
1772  const struct xrt_layer_data *data)
1773 {
1774  return xc->layer_equirect1(xc, xdev, xsc, data);
1775 }
1776 
1777 /*!
1778  * @copydoc xrt_compositor::layer_equirect2
1779  *
1780  * Helper for calling through the function pointer.
1781  *
1782  * @public @memberof xrt_compositor
1783  */
1784 static inline xrt_result_t
1786  struct xrt_device *xdev,
1787  struct xrt_swapchain *xsc,
1788  const struct xrt_layer_data *data)
1789 {
1790  return xc->layer_equirect2(xc, xdev, xsc, data);
1791 }
1792 
1793 /*!
1794  * @copydoc xrt_compositor::layer_passthrough
1795  *
1796  * Helper for calling through the function pointer.
1797  *
1798  * @public @memberof xrt_compositor
1799  */
1800 static inline xrt_result_t
1801 xrt_comp_layer_passthrough(struct xrt_compositor *xc, struct xrt_device *xdev, const struct xrt_layer_data *data)
1802 {
1803  return xc->layer_passthrough(xc, xdev, data);
1804 }
1805 
1806 /*!
1807  * @copydoc xrt_compositor::layer_commit
1808  *
1809  * Helper for calling through the function pointer.
1810  *
1811  * @public @memberof xrt_compositor
1812  */
1813 static inline xrt_result_t
1815 {
1816  return xc->layer_commit(xc, sync_handle);
1817 }
1818 
1819 /*!
1820  * @copydoc xrt_compositor::layer_commit_with_semaphore
1821  *
1822  * Helper for calling through the function pointer.
1823  *
1824  * @public @memberof xrt_compositor
1825  */
1826 static inline xrt_result_t
1828 {
1829  return xc->layer_commit_with_semaphore(xc, xcsem, value);
1830 }
1831 
1832 /*! @} */
1833 
1834 /*!
1835  * @copydoc xrt_compositor::get_display_refresh_rate
1836  *
1837  * Helper for calling through the function pointer.
1838  *
1839  * @public @memberof xrt_compositor
1840  */
1841 static inline xrt_result_t
1842 xrt_comp_get_display_refresh_rate(struct xrt_compositor *xc, float *out_display_refresh_rate_hz)
1843 {
1844  return xc->get_display_refresh_rate(xc, out_display_refresh_rate_hz);
1845 }
1846 
1847 /*!
1848  * @copydoc xrt_compositor::request_display_refresh_rate
1849  *
1850  * Helper for calling through the function pointer.
1851  *
1852  * @public @memberof xrt_compositor
1853  */
1854 static inline xrt_result_t
1855 xrt_comp_request_display_refresh_rate(struct xrt_compositor *xc, float display_refresh_rate_hz)
1856 {
1857  return xc->request_display_refresh_rate(xc, display_refresh_rate_hz);
1858 }
1859 
1860 
1861 /*!
1862  * @copydoc xrt_compositor::set_performance_level
1863  *
1864  * Helper for calling through the function pointer.
1865  *
1866  * @public @memberof xrt_compositor
1867  */
1868 static inline xrt_result_t
1870 {
1871  return xc->set_performance_level(xc, domain, level);
1872 }
1873 
1874 /*!
1875  * @copydoc xrt_compositor::destroy
1876  *
1877  * Helper for calling through the function pointer: does a null check and sets
1878  * xc_ptr to null if freed.
1879  *
1880  * @public @memberof xrt_compositor
1881  */
1882 static inline void
1884 {
1885  struct xrt_compositor *xc = *xc_ptr;
1886  if (xc == NULL) {
1887  return;
1888  }
1889 
1890  xc->destroy(xc);
1891  *xc_ptr = NULL;
1892 }
1893 
1894 /*!
1895  * @name Function pointers for extensions
1896  * @{
1897  */
1898 
1899 /*!
1900  * @brief Set thread attributes according to thread type
1901  */
1902 static inline xrt_result_t
1903 xrt_comp_set_thread_hint(struct xrt_compositor *xc, enum xrt_thread_hint hint, uint32_t thread_id)
1904 {
1905  return xc->set_thread_hint(xc, hint, thread_id);
1906 }
1907 
1908 /*! @} */
1909 
1910 /*
1911  *
1912  * OpenGL interface.
1913  *
1914  */
1915 
1916 /*!
1917  * Base class for an OpenGL (ES) client swapchain.
1918  *
1919  * @ingroup xrt_iface comp_client
1920  * @extends xrt_swapchain
1921  */
1923 {
1924  //! @public Base
1925  struct xrt_swapchain base;
1926 
1927  // GLuint
1928  unsigned int images[XRT_MAX_SWAPCHAIN_IMAGES];
1929 };
1930 
1931 /*!
1932  * Base class for an OpenGL (ES) client compositor.
1933  *
1934  * @ingroup xrt_iface comp_client
1935  * @extends xrt_compositor
1936  */
1938 {
1939  struct xrt_compositor base;
1940 };
1941 
1942 /*!
1943  * Down-cast helper.
1944  *
1945  * @private @memberof xrt_swapchain_gl
1946  *
1947  * @todo unused - remove?
1948  */
1949 static inline struct xrt_swapchain_gl *
1950 xrt_swapchain_gl(struct xrt_swapchain *xsc)
1951 {
1952  return (struct xrt_swapchain_gl *)xsc;
1953 }
1954 
1955 /*!
1956  * Down-cast helper.
1957  *
1958  * @private @memberof xrt_compositor_gl
1959  *
1960  * @todo unused - remove?
1961  */
1962 static inline struct xrt_compositor_gl *
1964 {
1965  return (struct xrt_compositor_gl *)xc;
1966 }
1967 
1968 
1969 /*
1970  *
1971  * Vulkan interface.
1972  *
1973  */
1974 
1975 /*!
1976  * Base class for a Vulkan client swapchain.
1977  *
1978  * @ingroup xrt_iface comp_client
1979  * @extends xrt_swapchain
1980  */
1982 {
1983  //! @public Base
1984  struct xrt_swapchain base;
1985 
1986  //! Images to be used by the caller.
1988 };
1989 
1990 /*!
1991  * Base class for a Vulkan client compositor.
1992  *
1993  * @ingroup xrt_iface comp_client
1994  * @extends xrt_compositor
1995  */
1997 {
1998  //! @public Base
1999  struct xrt_compositor base;
2000 };
2001 
2002 /*!
2003  * Down-cast helper.
2004  *
2005  * @private @memberof xrt_swapchain_vk
2006  *
2007  * @todo unused - remove?
2008  */
2009 static inline struct xrt_swapchain_vk *
2010 xrt_swapchain_vk(struct xrt_swapchain *xsc)
2011 {
2012  return (struct xrt_swapchain_vk *)xsc;
2013 }
2014 
2015 /*!
2016  * Down-cast helper.
2017  *
2018  * @private @memberof xrt_compositor_vk
2019  *
2020  * @todo unused - remove?
2021  */
2022 static inline struct xrt_compositor_vk *
2024 {
2025  return (struct xrt_compositor_vk *)xc;
2026 }
2027 
2028 #if defined(XRT_HAVE_D3D11) || defined(XRT_DOXYGEN)
2029 
2030 /*
2031  *
2032  * D3D11 interface.
2033  *
2034  */
2035 
2036 /*!
2037  * Base class for a D3D11 client swapchain.
2038  *
2039  * @ingroup xrt_iface comp_client
2040  * @extends xrt_swapchain
2041  */
2043 {
2044  //! @public Base
2045  struct xrt_swapchain base;
2046 
2047  //! Images to be used by the caller.
2049 };
2050 
2051 /*!
2052  * Base class for a D3D11 client compositor.
2053  *
2054  * @ingroup xrt_iface comp_client
2055  * @extends xrt_compositor
2056  */
2058 {
2059  //! @public Base
2060  struct xrt_compositor base;
2061 };
2062 
2063 /*!
2064  * Graphics usage requirements for D3D APIs.
2065  *
2066  * @ingroup xrt_iface
2067  */
2069 {
2070  LUID adapter_luid;
2071  D3D_FEATURE_LEVEL min_feature_level;
2072 };
2073 
2074 #endif // XRT_OS_WINDOWS
2075 
2076 
2077 #if defined(XRT_HAVE_D3D12) || defined(XRT_DOXYGEN)
2078 /*
2079  *
2080  * D3D12 interface.
2081  *
2082  */
2083 
2084 /*!
2085  * Base class for a D3D12 client swapchain.
2086  *
2087  * @ingroup xrt_iface comp_client
2088  * @extends xrt_swapchain
2089  */
2091 {
2092  //! @public Base
2093  struct xrt_swapchain base;
2094 
2095  //! Images to be used by the caller.
2097 };
2098 
2099 /*!
2100  * Base class for a D3D12 client compositor.
2101  *
2102  * @ingroup xrt_iface comp_client
2103  * @extends xrt_compositor
2104  */
2106 {
2107  //! @public Base
2108  struct xrt_compositor base;
2109 };
2110 #endif
2111 
2112 /*
2113  *
2114  * Native interface.
2115  *
2116  * These types are supported by underlying native buffers, which are DMABUF file
2117  * descriptors on Linux.
2118  *
2119  */
2120 
2121 /*!
2122  * A single image of a swapchain based on native buffer handles.
2123  *
2124  * @ingroup xrt_iface comp
2125  * @see xrt_swapchain_native, xrt_graphics_buffer_handle_t
2126  */
2128 {
2129  /*!
2130  * Native buffer handle.
2131  */
2133 
2134  /*!
2135  * @brief Buffer size in memory.
2136  *
2137  * Optional, set to 0 if unknown at allocation time.
2138  * If not zero, used for a max memory requirements check when importing
2139  * into Vulkan.
2140  */
2141  size_t size;
2142 
2143  /*!
2144  * Is the image created with a dedicated allocation or not.
2145  */
2147 
2148  /*!
2149  * Is the native buffer handle a DXGI handle?
2150  */
2152 };
2153 
2154 /*!
2155  * @interface xrt_swapchain_native
2156  * Base class for a swapchain that exposes a native buffer handle to be imported
2157  * into a client API.
2158  *
2159  * @ingroup xrt_iface comp
2160  * @extends xrt_swapchain
2161  */
2163 {
2164  //! @public Base
2165  struct xrt_swapchain base;
2166 
2167  /*!
2168  * Unique id for the swapchain, only unique for the current process, is
2169  * not synchronized between service and any apps via the IPC layer.
2170  */
2172 
2174 };
2175 
2176 /*!
2177  * @copydoc xrt_swapchain_reference
2178  *
2179  * @relates xrt_swapchain_native
2180  */
2181 static inline void
2183 {
2184  xrt_swapchain_reference((struct xrt_swapchain **)dst, (struct xrt_swapchain *)src);
2185 }
2186 
2187 /*!
2188  * @interface xrt_compositor_native
2189  *
2190  * Main compositor server interface.
2191  *
2192  * @ingroup xrt_iface comp
2193  * @extends xrt_compositor
2194  */
2196 {
2197  //! @public Base
2198  struct xrt_compositor base;
2199 };
2200 
2201 /*!
2202  * @brief Create a native swapchain with a set of images.
2203  *
2204  * A specialized version of @ref xrt_comp_create_swapchain, for use only on @ref
2205  * xrt_compositor_native.
2206  *
2207  * Helper for calling through the base's function pointer then performing the
2208  * known-safe downcast.
2209  *
2210  * The pointer pointed to by @p out_xsc has to either be NULL or a valid
2211  * @ref xrt_swapchain pointer. If there is a valid @ref xrt_swapchain
2212  * pointed by the pointed pointer it will have it reference decremented.
2213  *
2214  * @public @memberof xrt_compositor_native
2215  */
2216 static inline xrt_result_t
2218  const struct xrt_swapchain_create_info *info,
2219  struct xrt_swapchain_native **out_xscn)
2220 {
2221  struct xrt_swapchain *xsc = NULL; // Has to be NULL.
2222 
2223  xrt_result_t ret = xrt_comp_create_swapchain(&xcn->base, info, &xsc);
2224  if (ret == XRT_SUCCESS) {
2225  // Need to unref any swapchain already there first.
2226  xrt_swapchain_native_reference(out_xscn, NULL);
2227 
2228  // Already referenced.
2229  *out_xscn = (struct xrt_swapchain_native *)xsc;
2230  }
2231 
2232  return ret;
2233 }
2234 
2235 /*!
2236  * @copydoc xrt_compositor::destroy
2237  *
2238  * Helper for calling through the function pointer: does a null check and sets
2239  * xcn_ptr to null if freed.
2240  *
2241  * @public @memberof xrt_compositor_native
2242  */
2243 static inline void
2245 {
2246  struct xrt_compositor_native *xcn = *xcn_ptr;
2247  if (xcn == NULL) {
2248  return;
2249  }
2250 
2251  xcn->base.destroy(&xcn->base);
2252  *xcn_ptr = NULL;
2253 }
2254 
2255 
2256 /*
2257  *
2258  * System composition: how to composite on a system, either directly or by combining layers from multiple apps
2259  *
2260  */
2261 
2262 /*!
2263  * Capabilities and information about the system compositor (and its wrapped native compositor, if any),
2264  * and device together.
2265  */
2267 {
2268  struct
2269  {
2270  struct
2271  {
2272  uint32_t width_pixels;
2273  uint32_t height_pixels;
2274  uint32_t sample_count;
2275  } recommended; //!< Recommended for this view.
2276 
2277  struct
2278  {
2279  uint32_t width_pixels;
2280  uint32_t height_pixels;
2281  uint32_t sample_count;
2282  } max; //!< Maximums for this view.
2283  } views[XRT_MAX_VIEWS]; //!< View configuration information.
2284 
2285  //! Maximum number of composition layers supported, never changes.
2286  uint32_t max_layers;
2287 
2288  /*!
2289  * Blend modes supported by the system (the combination of the
2290  * compositor and the HMD capabilities), never changes.
2291  *
2292  * In preference order. Based on the modes reported by the device,
2293  * but the compositor has a chance to modify this.
2294  */
2295  enum xrt_blend_mode supported_blend_modes[XRT_BLEND_MODE_MAX_ENUM];
2296 
2297  //! Number of meaningful elements in xrt_system_compositor_info::supported_blend_modes
2299 
2300  uint32_t refresh_rate_count;
2301  float refresh_rates_hz[XRT_MAX_SUPPORTED_REFRESH_RATES];
2302 
2303  //! The vk device as used by the compositor, never changes.
2305 
2306  //! The vk device suggested for Vulkan clients, never changes.
2308 
2309  //! The (Windows) LUID for the GPU device suggested for D3D clients, never changes.
2311 
2312  //! Whether @ref client_d3d_deviceLUID is valid
2314 };
2315 
2316 struct xrt_system_compositor;
2317 
2318 /*!
2319  * @interface xrt_multi_compositor_control
2320  * Special functions to control multi session/clients.
2321  * Effectively an optional aspect of @ref xrt_system_compositor
2322  * exposed by implementations that can combine layers from multiple sessions/clients.
2323  */
2325 {
2326  /*!
2327  * Sets the state of the compositor, generating any events to the client
2328  * if the state is actually changed. Input focus is enforced/handled by
2329  * a different component but is still signaled by the compositor.
2330  */
2332  struct xrt_compositor *xc,
2333  bool visible,
2334  bool focused);
2335 
2336  /*!
2337  * Set the rendering Z order for rendering, visible has higher priority
2338  * then z_order but is still saved until visible again. This a signed
2339  * 64 bit integer compared to a unsigned 32 bit integer in OpenXR, so
2340  * that non-overlay clients can be handled like overlay ones.
2341  */
2342  xrt_result_t (*set_z_order)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, int64_t z_order);
2343 
2344  /*!
2345  * Tell this client/session if the main application is visible or not.
2346  */
2348  struct xrt_compositor *xc,
2349  bool visible);
2350 
2351  /*!
2352  * Notify this client/session if the compositor is going to lose the ability of rendering.
2353  *
2354  * @param loss_time_ns System monotonic timestamps, such as returned by os_monotonic_get_ns().
2355  */
2357  struct xrt_compositor *xc,
2358  uint64_t loss_time_ns);
2359 
2360  /*!
2361  * Notify this client/session if the compositor lost the ability of rendering.
2362  */
2364 
2365  /*!
2366  * Notify this client/session if the display refresh rate has been changed.
2367  */
2369  struct xrt_compositor *xc,
2370  float from_display_refresh_rate_hz,
2371  float to_display_refresh_rate_hz);
2372 };
2373 
2374 /*!
2375  * The system compositor handles composition for a system.
2376  * It is not itself a "compositor" (as in xrt_compositor), but it can create/own compositors.
2377  * - In a multi-app capable system, the system compositor may own an internal compositor, and
2378  * xrt_system_compositor::create_native_compositor will
2379  * create a compositor that submits layers to a merging mechanism.
2380  * - In a non-multi-app capable system, xrt_system_compositor::create_native_compositor
2381  * creates normal, native compositors, that do not wrap or feed into any other compositor.
2382  *
2383  * This is a long lived object: it has the same life time as an XrSystemID.
2384  */
2386 {
2387  /*!
2388  * An optional aspect/additional interface, providing multi-app control.
2389  * Populated if this system compositor supports multi client controls.
2390  */
2392 
2393  //! Info regarding the system.
2395 
2396  /*!
2397  * Create a new native compositor.
2398  *
2399  * This signals that you want to start XR, and as such implicitly brings
2400  * up a new session. Does not "call" `xrBeginSession`.
2401  *
2402  * Some system compositors might only support one `xrt_compositor`
2403  * active at a time, will return `XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED`
2404  * if this is the case.
2405  *
2406  * In a multi-session capable system compositor, this may return a "proxy"
2407  * for feeding a single client's layers to a compositor or a layer merging mechanism,
2408  * rather than a raw native compositor (not wrapping or forwarding) directly.
2409  */
2411  const struct xrt_session_info *xsi,
2412  struct xrt_session_event_sink *xses,
2413  struct xrt_compositor_native **out_xcn);
2414 
2415  /*!
2416  * Teardown the system compositor.
2417  *
2418  * The state tracker must make sure that no compositors are alive.
2419  */
2420  void (*destroy)(struct xrt_system_compositor *xsc);
2421 };
2422 
2423 /*!
2424  * @copydoc xrt_multi_compositor_control::set_state
2425  *
2426  * Helper for calling through the function pointer.
2427  *
2428  * If the system compositor @p xsc does not implement @ref xrt_multi_compositor_control,
2429  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2430  *
2431  * @public @memberof xrt_system_compositor
2432  */
2433 static inline xrt_result_t
2434 xrt_syscomp_set_state(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, bool visible, bool focused)
2435 {
2436  if (xsc->xmcc == NULL) {
2438  }
2439 
2440  return xsc->xmcc->set_state(xsc, xc, visible, focused);
2441 }
2442 
2443 /*!
2444  * @copydoc xrt_multi_compositor_control::set_z_order
2445  *
2446  * Helper for calling through the function pointer.
2447  *
2448  * If the system compositor @p xsc does not implement @ref xrt_multi_compositor_control,
2449  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2450  *
2451  * @public @memberof xrt_system_compositor
2452  */
2453 static inline xrt_result_t
2454 xrt_syscomp_set_z_order(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, int64_t z_order)
2455 {
2456  if (xsc->xmcc == NULL) {
2458  }
2459 
2460  return xsc->xmcc->set_z_order(xsc, xc, z_order);
2461 }
2462 
2463 
2464 /*!
2465  * @copydoc xrt_multi_compositor_control::set_main_app_visibility
2466  *
2467  * Helper for calling through the function pointer.
2468  *
2469  * If the system compositor @p xsc does not implement @ref xrt_multi_compositor_control,
2470  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2471  *
2472  * @public @memberof xrt_system_compositor
2473  */
2474 static inline xrt_result_t
2476 {
2477  if (xsc->xmcc == NULL) {
2479  }
2480 
2481  return xsc->xmcc->set_main_app_visibility(xsc, xc, visible);
2482 }
2483 
2484 /*!
2485  * @copydoc xrt_multi_compositor_control::notify_loss_pending
2486  *
2487  * Helper for calling through the function pointer.
2488  *
2489  * If the system compositor @p xsc does not implement @ref xrt_multi_compositor_control,
2490  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2491  *
2492  * @public @memberof xrt_system_compositor
2493  */
2494 static inline xrt_result_t
2495 xrt_syscomp_notify_loss_pending(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, uint64_t loss_time_ns)
2496 {
2497  if (xsc->xmcc == NULL) {
2499  }
2500 
2501  return xsc->xmcc->notify_loss_pending(xsc, xc, loss_time_ns);
2502 }
2503 
2504 /*!
2505  * @copydoc xrt_multi_compositor_control::notify_lost
2506  *
2507  * Helper for calling through the function pointer.
2508  *
2509  * If the system compositor @p xsc does not implement @ref xrt_multi_compositor_control,
2510  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2511  *
2512  * @public @memberof xrt_system_compositor
2513  */
2514 static inline xrt_result_t
2516 {
2517  if (xsc->xmcc == NULL) {
2519  }
2520 
2521  return xsc->xmcc->notify_lost(xsc, xc);
2522 }
2523 
2524 /*!
2525  * @copydoc xrt_multi_compositor_control::notify_display_refresh_changed
2526  *
2527  * Helper for calling through the function pointer.
2528  *
2529  * If the system compositor @p xsc does not implement @ref xrt_multi_composition_control,
2530  * this returns @ref XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED.
2531  *
2532  * @public @memberof xrt_system_compositor
2533  */
2534 static inline xrt_result_t
2536  struct xrt_compositor *xc,
2537  float from_display_refresh_rate_hz,
2538  float to_display_refresh_rate_hz)
2539 {
2540  if (xsc->xmcc == NULL) {
2542  }
2543 
2544  return xsc->xmcc->notify_display_refresh_changed(xsc, xc, from_display_refresh_rate_hz,
2545  to_display_refresh_rate_hz);
2546 }
2547 
2548 /*!
2549  * @copydoc xrt_system_compositor::create_native_compositor
2550  *
2551  * Helper for calling through the function pointer.
2552  *
2553  * @public @memberof xrt_system_compositor
2554  */
2555 static inline xrt_result_t
2557  const struct xrt_session_info *xsi,
2558  struct xrt_session_event_sink *xses,
2559  struct xrt_compositor_native **out_xcn)
2560 {
2561  return xsc->create_native_compositor(xsc, xsi, xses, out_xcn);
2562 }
2563 
2564 /*!
2565  * @copydoc xrt_system_compositor::destroy
2566  *
2567  * Helper for calling through the function pointer: does a null check and sets
2568  * xcn_ptr to null if freed.
2569  *
2570  * @public @memberof xrt_system_compositor
2571  */
2572 static inline void
2574 {
2575  struct xrt_system_compositor *xsc = *xsc_ptr;
2576  if (xsc == NULL) {
2577  return;
2578  }
2579 
2580  xsc->destroy(xsc);
2581  *xsc_ptr = NULL;
2582 }
2583 
2584 
2585 /*
2586  *
2587  * Image allocator.
2588  *
2589  */
2590 
2591 /*!
2592  * Allocator for system native images, in general you do not need to free the
2593  * images as they will be consumed by importing them to the graphics API.
2594  *
2595  * @see xrt_image_native
2596  */
2598 {
2599  /*!
2600  * Allocate a set of images suitable to be used to back a swapchain
2601  * with the given create info properties (@p xsci).
2602  */
2604  const struct xrt_swapchain_create_info *xsci,
2605  size_t image_count,
2606  struct xrt_image_native *out_images);
2607 
2608  /*!
2609  * Free the given images.
2610  */
2612  size_t image_count,
2613  struct xrt_image_native *images);
2614 
2615  /*!
2616  * Destroy the image allocator.
2617  */
2618  void (*destroy)(struct xrt_image_native_allocator *xina);
2619 };
2620 
2621 /*!
2622  * @copydoc xrt_image_native_allocator::xrt_images_allocate
2623  *
2624  * Helper for calling through the function pointer.
2625  *
2626  * @public @memberof xrt_image_native_allocate
2627  */
2628 static inline xrt_result_t
2629 xrt_images_allocate(struct xrt_image_native_allocator *xina,
2630  const struct xrt_swapchain_create_info *xsci,
2631  size_t image_count,
2632  struct xrt_image_native *out_images)
2633 {
2634  return xina->images_allocate(xina, xsci, image_count, out_images);
2635 }
2636 
2637 /*!
2638  * @copydoc xrt_image_native_allocator::images_free
2639  *
2640  * Helper for calling through the function pointer.
2641  *
2642  * @public @memberof xrt_image_native_allocate
2643  */
2644 static inline xrt_result_t
2645 xrt_images_free(struct xrt_image_native_allocator *xina, size_t image_count, struct xrt_image_native *images)
2646 {
2647  return xina->images_free(xina, image_count, images);
2648 }
2649 
2650 /*!
2651  * @copydoc xrt_image_native_allocator::destroy
2652  *
2653  * Helper for calling through the function pointer: does a null check and sets
2654  * xina_ptr to null if freed.
2655  *
2656  * @public @memberof xrt_image_native_allocator
2657  */
2658 static inline void
2660 {
2661  struct xrt_image_native_allocator *xina = *xina_ptr;
2662  if (xina == NULL) {
2663  return;
2664  }
2665 
2666  xina->destroy(xina);
2667  *xina_ptr = NULL;
2668 }
2669 
2670 
2671 /*!
2672  * @}
2673  */
2674 
2675 
2676 #ifdef __cplusplus
2677 }
2678 #endif
xrt_compare_op_fb
XrCompareOpFB.
Definition: xrt_compositor.h:139
static xrt_result_t xrt_comp_set_performance_level(struct xrt_compositor *xc, enum xrt_perf_domain domain, enum xrt_perf_set_level level)
Set CPU/GPU performance level.
Definition: xrt_compositor.h:1869
xrt_swapchain_usage_bits
Usage of the swapchain images.
Definition: xrt_compositor.h:506
static xrt_result_t xrt_comp_begin_frame(struct xrt_compositor *xc, int64_t frame_id)
See xrBeginFrame.
Definition: xrt_compositor.h:1639
static xrt_result_t xrt_comp_layer_quad(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a quad layer for submission, the center of the quad is specified by the pose and extends outward...
Definition: xrt_compositor.h:1720
static void xrt_syscomp_destroy(struct xrt_system_compositor **xsc_ptr)
Teardown the system compositor.
Definition: xrt_compositor.h:2573
static xrt_result_t xrt_comp_native_create_swapchain(struct xrt_compositor_native *xcn, const struct xrt_swapchain_create_info *info, struct xrt_swapchain_native **out_xscn)
Create a native swapchain with a set of images.
Definition: xrt_compositor.h:2217
static xrt_result_t xrt_swapchain_barrier_image(struct xrt_swapchain *xsc, enum xrt_barrier_direction direction, uint32_t index)
Do any barrier transitions to and from the application.
Definition: xrt_compositor.h:702
xrt_blend_mode
Blend mode that the device supports, exact mirror of XrEnvironmentBlendMode.
Definition: xrt_defines.h:109
static xrt_result_t xrt_comp_set_thread_hint(struct xrt_compositor *xc, enum xrt_thread_hint hint, uint32_t thread_id)
Set thread attributes according to thread type.
Definition: xrt_compositor.h:1903
static xrt_result_t xrt_comp_layer_commit_with_semaphore(struct xrt_compositor *xc, struct xrt_compositor_semaphore *xcsem, uint64_t value)
Commits all of the submitted layers, with a semaphore.
Definition: xrt_compositor.h:1827
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:1598
static xrt_result_t xrt_swapchain_dec_image_use(struct xrt_swapchain *xsc, uint32_t index)
Decrements the use counter of a swapchain image.
Definition: xrt_compositor.h:676
static xrt_result_t xrt_comp_layer_cube(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a cube layer for submission.
Definition: xrt_compositor.h:1736
static xrt_result_t xrt_comp_destroy_passthrough(struct xrt_compositor *xc)
Destroy a passthrough.
Definition: xrt_compositor.h:1530
static void xrt_comp_destroy(struct xrt_compositor **xc_ptr)
Teardown the compositor.
Definition: xrt_compositor.h:1883
static xrt_result_t xrt_comp_layer_projection_depth(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
Adds a projection layer for submission, has depth information.
Definition: xrt_compositor.h:1703
static xrt_result_t xrt_comp_wait_frame(struct xrt_compositor *xc, int64_t *out_frame_id, uint64_t *out_predicted_display_time, uint64_t *out_predicted_display_period)
See xrWaitFrame.
Definition: xrt_compositor.h:1623
static xrt_result_t xrt_syscomp_set_main_app_visibility(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, bool visible)
Tell this client/session if the main application is visible or not.
Definition: xrt_compositor.h:2475
static xrt_result_t xrt_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index)
See xrReleaseSwapchainImage, state tracker needs to track index.
Definition: xrt_compositor.h:715
static xrt_result_t xrt_comp_import_swapchain(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_image_native *native_images, uint32_t image_count, struct xrt_swapchain **out_xsc)
Create a swapchain from a set of native images.
Definition: xrt_compositor.h:1455
static xrt_result_t xrt_comp_begin_session(struct xrt_compositor *xc, const struct xrt_begin_session_info *info)
See xrBeginSession.
Definition: xrt_compositor.h:1548
static xrt_result_t xrt_comp_get_display_refresh_rate(struct xrt_compositor *xc, float *out_display_refresh_rate_hz)
Get the current display refresh rate.
Definition: xrt_compositor.h:1842
static xrt_result_t xrt_comp_create_semaphore(struct xrt_compositor *xc, xrt_graphics_sync_handle_t *out_handle, struct xrt_compositor_semaphore **out_xcsem)
Create a compositor semaphore, also returns a native handle.
Definition: xrt_compositor.h:1487
static xrt_result_t xrt_comp_predict_frame(struct xrt_compositor *xc, int64_t *out_frame_id, uint64_t *out_wake_time_ns, uint64_t *out_predicted_gpu_time_ns, uint64_t *out_predicted_display_time_ns, uint64_t *out_predicted_display_period_ns)
This function and mark_frame function calls are a alternative to wait_frame.
Definition: xrt_compositor.h:1583
#define XRT_MAX_SWAPCHAIN_IMAGES
Max swapchain images, artificial limit.
Definition: xrt_limits.h:34
static xrt_result_t xrt_comp_mark_frame(struct xrt_compositor *xc, int64_t frame_id, enum xrt_compositor_frame_point point, uint64_t when_ns)
This function and predict_frame function calls are a alternative to wait_frame.
Definition: xrt_compositor.h:1607
xrt_view_type
View type to be rendered to by the compositor.
Definition: xrt_compositor.h:862
static xrt_result_t xrt_comp_import_fence(struct xrt_compositor *xc, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf)
Create a compositor fence from a native sync handle.
Definition: xrt_compositor.h:1472
static xrt_result_t xrt_swapchain_inc_image_use(struct xrt_swapchain *xsc, uint32_t index)
Increments the use counter of a swapchain image.
Definition: xrt_compositor.h:663
static xrt_result_t xrt_comp_end_session(struct xrt_compositor *xc)
See xrEndSession, unlike the OpenXR one the state tracker is responsible to call discard frame before...
Definition: xrt_compositor.h:1561
static xrt_result_t xrt_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout_ns, uint32_t index)
Wait until image index is available for exclusive use, or until timeout_ns expires.
Definition: xrt_compositor.h:689
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1134
static xrt_result_t xrt_comp_layer_equirect1(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a equirect1 layer for submission.
Definition: xrt_compositor.h:1769
static xrt_result_t xrt_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *out_index)
Obtain the index of the next image to use, without blocking on being able to write to it.
Definition: xrt_compositor.h:650
static xrt_result_t xrt_syscomp_set_z_order(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, int64_t z_order)
Set the rendering Z order for rendering, visible has higher priority then z_order but is still saved ...
Definition: xrt_compositor.h:2454
static xrt_result_t xrt_comp_layer_projection(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
Adds a projection layer for submissions.
Definition: xrt_compositor.h:1687
#define XRT_MAX_SWAPCHAIN_CREATE_INFO_FORMAT_LIST_COUNT
Max formats in the swapchain creation info formats list, artificial limit.
Definition: xrt_limits.h:44
xrt_swapchain_create_flags
Special flags for creating swapchain images.
Definition: xrt_compositor.h:495
static void xrt_images_destroy(struct xrt_image_native_allocator **xina_ptr)
Destroy the image allocator.
Definition: xrt_compositor.h:2659
static xrt_result_t xrt_comp_discard_frame(struct xrt_compositor *xc, int64_t frame_id)
Explicitly discard a frame.
Definition: xrt_compositor.h:1652
static xrt_result_t xrt_comp_get_swapchain_create_properties(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain_create_properties *xsccp)
For a given xrt_swapchain_create_info struct returns a filled out xrt_swapchain_create_properties.
Definition: xrt_compositor.h:1420
static xrt_result_t xrt_compositor_fence_wait(struct xrt_compositor_fence *xcf, uint64_t timeout)
Waits on the fence with the given timeout.
Definition: xrt_compositor.h:751
enum xrt_result xrt_result_t
Result type used across Monado.
static void xrt_reference_inc(struct xrt_reference *xref)
Increment the reference, probably want xrt_reference_inc_and_was_zero.
Definition: xrt_defines.h:1561
static xrt_result_t xrt_comp_create_swapchain(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain **out_xsc)
Create a swapchain with a set of images.
Definition: xrt_compositor.h:1440
static void xrt_comp_native_destroy(struct xrt_compositor_native **xcn_ptr)
Teardown the compositor.
Definition: xrt_compositor.h:2244
xrt_compositor_frame_point
Definition: xrt_compositor.h:868
static xrt_result_t xrt_syscomp_set_state(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, bool visible, bool focused)
Sets the state of the compositor, generating any events to the client if the state is actually change...
Definition: xrt_compositor.h:2434
static void xrt_swapchain_native_reference(struct xrt_swapchain_native **dst, struct xrt_swapchain_native *src)
Update the reference counts on swapchain(s).
Definition: xrt_compositor.h:2182
static xrt_result_t xrt_comp_create_passthrough_layer(struct xrt_compositor *xc, const struct xrt_passthrough_layer_create_info *info)
Create a passthrough layer.
Definition: xrt_compositor.h:1517
static xrt_result_t xrt_comp_layer_begin(struct xrt_compositor *xc, const struct xrt_layer_frame_data *data)
Begins layer submission.
Definition: xrt_compositor.h:1674
static xrt_result_t xrt_syscomp_notify_loss_pending(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, uint64_t loss_time_ns)
Notify this client/session if the compositor is going to lose the ability of rendering.
Definition: xrt_compositor.h:2495
xrt_layer_composition_flags
Bit field for holding information about how a layer should be composited.
Definition: xrt_compositor.h:92
xrt_thread_hint
Hints the XR runtime what type of task the thread is doing.
Definition: xrt_compositor.h:970
static xrt_result_t xrt_syscomp_notify_display_refresh_changed(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, float from_display_refresh_rate_hz, float to_display_refresh_rate_hz)
Notify this client/session if the display refresh rate has been changed.
Definition: xrt_compositor.h:2535
static void xrt_compositor_fence_destroy(struct xrt_compositor_fence **xcf_ptr)
Destroys the fence.
Definition: xrt_compositor.h:765
static void xrt_compositor_semaphore_reference(struct xrt_compositor_semaphore **dst, struct xrt_compositor_semaphore *src)
Update the reference counts on compositor semaphore(s).
Definition: xrt_compositor.h:817
xrt_layer_eye_visibility
Which view is the layer visible to?
Definition: xrt_compositor.h:159
static xrt_result_t xrt_comp_layer_passthrough(struct xrt_compositor *xc, struct xrt_device *xdev, const struct xrt_layer_data *data)
Adds a passthrough layer for submission.
Definition: xrt_compositor.h:1801
static xrt_result_t xrt_syscomp_notify_lost(struct xrt_system_compositor *xsc, struct xrt_compositor *xc)
Notify this client/session if the compositor lost the ability of rendering.
Definition: xrt_compositor.h:2515
static void xrt_swapchain_reference(struct xrt_swapchain **dst, struct xrt_swapchain *src)
Update the reference counts on swapchain(s).
Definition: xrt_compositor.h:621
xrt_blend_factor
Blend factors.
Definition: xrt_compositor.h:170
#define XRT_MAX_SUPPORTED_REFRESH_RATES
Max number of supported display refresh rates, artificial limit.
Definition: xrt_limits.h:49
#define XRT_MAX_SWAPCHAIN_FORMATS
Max formats supported by a compositor, artificial limit.
Definition: xrt_limits.h:39
static xrt_result_t xrt_comp_create_passthrough(struct xrt_compositor *xc, const struct xrt_passthrough_create_info *info)
Create a passthrough.
Definition: xrt_compositor.h:1504
static xrt_result_t xrt_comp_request_display_refresh_rate(struct xrt_compositor *xc, float display_refresh_rate_hz)
Request system to change the display refresh rate to the requested value.
Definition: xrt_compositor.h:1855
static xrt_result_t xrt_comp_layer_commit(struct xrt_compositor *xc, xrt_graphics_sync_handle_t sync_handle)
Commits all of the submitted layers.
Definition: xrt_compositor.h:1814
xrt_barrier_direction
The direction of a transition.
Definition: xrt_compositor.h:521
static xrt_result_t xrt_comp_layer_cylinder(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a cylinder layer for submission.
Definition: xrt_compositor.h:1752
static xrt_result_t xrt_syscomp_create_native_compositor(struct xrt_system_compositor *xsc, const struct xrt_session_info *xsi, struct xrt_session_event_sink *xses, struct xrt_compositor_native **out_xcn)
Create a new native compositor.
Definition: xrt_compositor.h:2556
static xrt_result_t xrt_comp_layer_equirect2(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a equirect2 layer for submission.
Definition: xrt_compositor.h:1785
xrt_layer_type
Layer type.
Definition: xrt_compositor.h:77
static xrt_result_t xrt_compositor_semaphore_wait(struct xrt_compositor_semaphore *xcsem, uint64_t value, uint64_t timeout)
Does a CPU side wait on the semaphore to reach the given value.
Definition: xrt_compositor.h:846
@ XRT_SWAPCHAIN_CREATE_PROTECTED_CONTENT
Our compositor just ignores this bit.
Definition: xrt_compositor.h:497
@ XRT_SWAPCHAIN_CREATE_STATIC_IMAGE
Signals that the allocator should only allocate one image.
Definition: xrt_compositor.h:499
@ XRT_COMPOSITOR_FRAME_POINT_WOKE
The client woke up after waiting.
Definition: xrt_compositor.h:869
@ XRT_COMPOSITION_LAYER_PROCESSING_QUALITY_SUPER_SAMPLING_BIT_FB
Quality super sampling, see XrCompositionLayerSettingsFlagsFB.
Definition: xrt_compositor.h:112
@ XRT_LAYER_COMPOSITION_ADVANCED_BLENDING_BIT
This layer has advanced blending information, this bit supersedes the behavior of XRT_LAYER_COMPOSITI...
Definition: xrt_compositor.h:126
@ XRT_COMPOSITION_LAYER_PROCESSING_NORMAL_SUPER_SAMPLING_BIT_FB
Normal super sampling, see XrCompositionLayerSettingsFlagsFB.
Definition: xrt_compositor.h:109
@ XRT_LAYER_COMPOSITION_DEPTH_TEST
Depth testing is requested when composing this layer if this flag is set, see XrCompositionLayerDepth...
Definition: xrt_compositor.h:132
@ XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT
The layer is locked to the device and the pose should only be adjusted for the IPD.
Definition: xrt_compositor.h:100
@ XRT_COMPOSITION_LAYER_PROCESSING_QUALITY_SHARPENING_BIT_FB
Quality sharpening, see XrCompositionLayerSettingsFlagsFB.
Definition: xrt_compositor.h:118
@ XRT_COMPOSITION_LAYER_PROCESSING_NORMAL_SHARPENING_BIT_FB
Normal sharpening, see XrCompositionLayerSettingsFlagsFB.
Definition: xrt_compositor.h:115
@ XRT_LAYER_COMPOSITION_COLOR_BIAS_SCALE
If this flag is set the compositor should use the scale and bias from the xrt_layer_data struct.
Definition: xrt_compositor.h:106
@ XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED
Multiple not supported on this layer level (IPC, compositor).
Definition: xrt_results.h:97
@ XRT_SUCCESS
The operation succeeded.
Definition: xrt_results.h:26
Definition: m_space.cpp:87
Begin Session information not known until clients have created an xrt-instance such as which extensio...
Definition: xrt_compositor.h:958
A 4 element colour with floating point channels.
Definition: xrt_defines.h:396
Base class for a D3D11 client compositor.
Definition: xrt_compositor.h:2058
struct xrt_compositor base
Base.
Definition: xrt_compositor.h:2060
Base class for a D3D12 client compositor.
Definition: xrt_compositor.h:2106
struct xrt_compositor base
Base.
Definition: xrt_compositor.h:2108
Compositor fence used for syncornization.
Definition: xrt_compositor.h:731
xrt_result_t(* wait)(struct xrt_compositor_fence *xcf, uint64_t timeout)
Waits on the fence with the given timeout.
Definition: xrt_compositor.h:735
void(* destroy)(struct xrt_compositor_fence *xcf)
Destroys the fence.
Definition: xrt_compositor.h:740
Base class for an OpenGL (ES) client compositor.
Definition: xrt_compositor.h:1938
Capabilities and information about the compositor and device together.
Definition: xrt_compositor.h:942
uint32_t max_texture_size
Max texture size that GPU supports (size of a single dimension), zero means any size.
Definition: xrt_compositor.h:950
int64_t formats[XRT_MAX_SWAPCHAIN_FORMATS]
Supported formats, never changes.
Definition: xrt_compositor.h:947
uint32_t format_count
Number of formats, never changes.
Definition: xrt_compositor.h:944
Main compositor server interface.
Definition: xrt_compositor.h:2196
struct xrt_compositor base
Base.
Definition: xrt_compositor.h:2198
Compositor semaphore used for synchronization, needs to be as capable as a Vulkan pipeline semaphore.
Definition: xrt_compositor.h:788
struct xrt_reference reference
Reference helper.
Definition: xrt_compositor.h:792
void(* destroy)(struct xrt_compositor_semaphore *xcsem)
Destroys the semaphore.
Definition: xrt_compositor.h:802
xrt_result_t(* wait)(struct xrt_compositor_semaphore *xcsem, uint64_t value, uint64_t timeout_ns)
Does a CPU side wait on the semaphore to reach the given value.
Definition: xrt_compositor.h:797
Base class for a Vulkan client compositor.
Definition: xrt_compositor.h:1997
struct xrt_compositor base
Base.
Definition: xrt_compositor.h:1999
Common compositor client interface/base.
Definition: xrt_compositor.h:986
xrt_result_t(* layer_projection_depth)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
Adds a projection layer for submission, has depth information.
Definition: xrt_compositor.h:1237
void(* destroy)(struct xrt_compositor *xc)
Teardown the compositor.
Definition: xrt_compositor.h:1397
xrt_result_t(* layer_commit)(struct xrt_compositor *xc, xrt_graphics_sync_handle_t sync_handle)
Commits all of the submitted layers.
Definition: xrt_compositor.h:1338
xrt_result_t(* create_swapchain)(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain **out_xsc)
Create a swapchain with a set of images.
Definition: xrt_compositor.h:1011
xrt_result_t(* get_swapchain_create_properties)(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain_create_properties *xsccp)
For a given xrt_swapchain_create_info struct returns a filled out xrt_swapchain_create_properties.
Definition: xrt_compositor.h:996
xrt_result_t(* set_thread_hint)(struct xrt_compositor *xc, enum xrt_thread_hint hint, uint32_t thread_id)
Set thread attributes according to thread type.
Definition: xrt_compositor.h:1407
xrt_result_t(* layer_cylinder)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a cylinder layer for submission.
Definition: xrt_compositor.h:1284
xrt_result_t(* end_session)(struct xrt_compositor *xc)
See xrEndSession, unlike the OpenXR one the state tracker is responsible to call discard frame before...
Definition: xrt_compositor.h:1073
xrt_result_t(* discard_frame)(struct xrt_compositor *xc, int64_t frame_id)
Explicitly discard a frame.
Definition: xrt_compositor.h:1179
xrt_result_t(* destroy_passthrough)(struct xrt_compositor *xc)
Destroy a passthrough.
Definition: xrt_compositor.h:1057
xrt_result_t(* get_display_refresh_rate)(struct xrt_compositor *xc, float *out_display_refresh_rate_hz)
Get the current display refresh rate.
Definition: xrt_compositor.h:1368
xrt_result_t(* request_display_refresh_rate)(struct xrt_compositor *xc, float display_refresh_rate_hz)
Request system to change the display refresh rate to the requested value.
Definition: xrt_compositor.h:1376
xrt_result_t(* begin_frame)(struct xrt_compositor *xc, int64_t frame_id)
See xrBeginFrame.
Definition: xrt_compositor.h:1161
xrt_result_t(* predict_frame)(struct xrt_compositor *xc, int64_t *out_frame_id, uint64_t *out_wake_time_ns, uint64_t *out_predicted_gpu_time_ns, uint64_t *out_predicted_display_time_ns, uint64_t *out_predicted_display_period_ns)
This function and mark_frame function calls are a alternative to wait_frame.
Definition: xrt_compositor.h:1103
xrt_result_t(* layer_quad)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a quad layer for submission, the center of the quad is specified by the pose and extends outward...
Definition: xrt_compositor.h:1254
xrt_result_t(* wait_frame)(struct xrt_compositor *xc, int64_t *out_frame_id, uint64_t *out_predicted_display_time, uint64_t *out_predicted_display_period)
See xrWaitFrame.
Definition: xrt_compositor.h:1146
xrt_result_t(* mark_frame)(struct xrt_compositor *xc, int64_t frame_id, enum xrt_compositor_frame_point point, uint64_t when_ns)
This function and predict_frame function calls are a alternative to wait_frame.
Definition: xrt_compositor.h:1122
xrt_result_t(* layer_projection)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
Adds a projection layer for submissions.
Definition: xrt_compositor.h:1213
xrt_result_t(* layer_equirect1)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a equirect1 layer for submission.
Definition: xrt_compositor.h:1299
xrt_result_t(* import_swapchain)(struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_image_native *native_images, uint32_t image_count, struct xrt_swapchain **out_xsc)
Create a swapchain from a set of native images.
Definition: xrt_compositor.h:1022
xrt_result_t(* set_performance_level)(struct xrt_compositor *xc, enum xrt_perf_domain domain, enum xrt_perf_set_level level)
Set CPU/GPU performance level.
Definition: xrt_compositor.h:1384
xrt_result_t(* import_fence)(struct xrt_compositor *xc, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf)
Create a compositor fence from a native sync handle.
Definition: xrt_compositor.h:1031
xrt_result_t(* layer_begin)(struct xrt_compositor *xc, const struct xrt_layer_frame_data *data)
Begins layer submission.
Definition: xrt_compositor.h:1197
struct xrt_compositor_info info
Capabilities and recommended values information.
Definition: xrt_compositor.h:990
xrt_result_t(* begin_session)(struct xrt_compositor *xc, const struct xrt_begin_session_info *info)
See xrBeginSession.
Definition: xrt_compositor.h:1066
xrt_result_t(* create_passthrough)(struct xrt_compositor *xc, const struct xrt_passthrough_create_info *info)
Create a passthrough.
Definition: xrt_compositor.h:1046
xrt_result_t(* layer_equirect2)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a equirect2 layer for submission.
Definition: xrt_compositor.h:1315
xrt_result_t(* create_semaphore)(struct xrt_compositor *xc, xrt_graphics_sync_handle_t *out_handle, struct xrt_compositor_semaphore **out_xcsem)
Create a compositor semaphore, also returns a native handle.
Definition: xrt_compositor.h:1038
xrt_result_t(* layer_passthrough)(struct xrt_compositor *xc, struct xrt_device *xdev, const struct xrt_layer_data *data)
Adds a passthrough layer for submission.
Definition: xrt_compositor.h:1329
xrt_result_t(* layer_cube)(struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
Adds a cube layer for submission.
Definition: xrt_compositor.h:1269
xrt_result_t(* create_passthrough_layer)(struct xrt_compositor *xc, const struct xrt_passthrough_layer_create_info *info)
Create a passthrough layer.
Definition: xrt_compositor.h:1052
xrt_result_t(* layer_commit_with_semaphore)(struct xrt_compositor *xc, struct xrt_compositor_semaphore *xcsem, uint64_t value)
Commits all of the submitted layers, with a semaphore.
Definition: xrt_compositor.h:1350
Graphics usage requirements for D3D APIs.
Definition: xrt_compositor.h:2069
A single HMD or input device.
Definition: xrt_device.h:230
Describes a projection matrix fov.
Definition: xrt_defines.h:486
Allocator for system native images, in general you do not need to free the images as they will be con...
Definition: xrt_compositor.h:2598
void(* destroy)(struct xrt_image_native_allocator *xina)
Destroy the image allocator.
Definition: xrt_compositor.h:2618
xrt_result_t(* images_allocate)(struct xrt_image_native_allocator *xina, const struct xrt_swapchain_create_info *xsci, size_t image_count, struct xrt_image_native *out_images)
Allocate a set of images suitable to be used to back a swapchain with the given create info propertie...
Definition: xrt_compositor.h:2603
xrt_result_t(* images_free)(struct xrt_image_native_allocator *xina, size_t image_count, struct xrt_image_native *images)
Free the given images.
Definition: xrt_compositor.h:2611
A single image of a swapchain based on native buffer handles.
Definition: xrt_compositor.h:2128
bool use_dedicated_allocation
Is the image created with a dedicated allocation or not.
Definition: xrt_compositor.h:2146
size_t size
Buffer size in memory.
Definition: xrt_compositor.h:2141
xrt_graphics_buffer_handle_t handle
Native buffer handle.
Definition: xrt_compositor.h:2132
bool is_dxgi_handle
Is the native buffer handle a DXGI handle?
Definition: xrt_compositor.h:2151
Advanced blend provides explicit control over source and destination blend factors,...
Definition: xrt_compositor.h:188
All the pure data values associated with a cube layer.
Definition: xrt_compositor.h:296
All the pure data values associated with a cylinder layer.
Definition: xrt_compositor.h:311
All the pure data values associated with a composition layer.
Definition: xrt_compositor.h:394
struct xrt_colour_rgba_f32 color_scale
Modulate the color sourced from the images.
Definition: xrt_compositor.h:440
struct xrt_colour_rgba_f32 color_bias
Modulate the color sourced from the images.
Definition: xrt_compositor.h:445
enum xrt_input_name name
Often XRT_INPUT_GENERIC_HEAD_POSE.
Definition: xrt_compositor.h:403
enum xrt_layer_type type
Tag for compositor layer type.
Definition: xrt_compositor.h:398
enum xrt_layer_composition_flags flags
Composition flags.
Definition: xrt_compositor.h:416
uint64_t timestamp
"Display no-earlier-than" timestamp for this layer.
Definition: xrt_compositor.h:411
struct xrt_layer_depth_test_data depth_test
Depth test data.
Definition: xrt_compositor.h:421
bool flip_y
Whether the main compositor should flip the direction of y when rendering.
Definition: xrt_compositor.h:435
struct xrt_layer_advanced_blend_data advanced_blend
Advanced blend factors.
Definition: xrt_compositor.h:450
All the pure data values associated with a depth information attached to a layer.
Definition: xrt_compositor.h:244
Definition: xrt_compositor.h:254
All the pure data values associated with a equirect1 layer.
Definition: xrt_compositor.h:329
All the pure data values associated with a equirect2 layer.
Definition: xrt_compositor.h:347
Per frame data for the layer submission calls, used in xrt_compositor::layer_begin.
Definition: xrt_compositor.h:478
All the pure data values associated with a passthrough layer.
Definition: xrt_compositor.h:382
All the pure data values associated with a projection layer.
Definition: xrt_compositor.h:232
All the pure data values associated with a projection layer with depth swapchain attached.
Definition: xrt_compositor.h:267
All of the pure data values associated with a single view in a projection layer.
Definition: xrt_compositor.h:218
All the pure data values associated with a quad layer.
Definition: xrt_compositor.h:280
A limited unique id, it is only unique for the process it is in, so must not be used or synchronized ...
Definition: xrt_defines.h:79
To transport LUIDs between different APIs.
Definition: xrt_defines.h:60
Special functions to control multi session/clients.
Definition: xrt_compositor.h:2325
xrt_result_t(* set_main_app_visibility)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, bool visible)
Tell this client/session if the main application is visible or not.
Definition: xrt_compositor.h:2347
xrt_result_t(* notify_display_refresh_changed)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, float from_display_refresh_rate_hz, float to_display_refresh_rate_hz)
Notify this client/session if the display refresh rate has been changed.
Definition: xrt_compositor.h:2368
xrt_result_t(* set_z_order)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, int64_t z_order)
Set the rendering Z order for rendering, visible has higher priority then z_order but is still saved ...
Definition: xrt_compositor.h:2342
xrt_result_t(* set_state)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, bool visible, bool focused)
Sets the state of the compositor, generating any events to the client if the state is actually change...
Definition: xrt_compositor.h:2331
xrt_result_t(* notify_lost)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc)
Notify this client/session if the compositor lost the ability of rendering.
Definition: xrt_compositor.h:2363
xrt_result_t(* notify_loss_pending)(struct xrt_system_compositor *xsc, struct xrt_compositor *xc, uint64_t loss_time_ns)
Notify this client/session if the compositor is going to lose the ability of rendering.
Definition: xrt_compositor.h:2356
Normalized image rectangle, coordinates and size in 0 .
Definition: xrt_defines.h:453
Passthrough creation info.
Definition: xrt_compositor.h:899
Passthrough layer creation info.
Definition: xrt_compositor.h:907
Definition: xrt_compositor.h:371
Definition: xrt_compositor.h:363
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
Image rectangle.
Definition: xrt_defines.h:430
A base class for reference counted objects.
Definition: xrt_defines.h:96
Used internally from producers of events to push events into session, some sinks might mutliplex even...
Definition: xrt_session.h:193
Session information, mostly overlay extension data.
Definition: xrt_compositor.h:930
Specifies a sub-image in a layer.
Definition: xrt_compositor.h:199
struct xrt_normalized_rect norm_rect
Normalized sub image coordinates and size.
Definition: xrt_compositor.h:207
struct xrt_rect rect
The rectangle in the image to use.
Definition: xrt_compositor.h:205
uint32_t image_index
Image index in the (implicit) swapchain.
Definition: xrt_compositor.h:201
uint32_t array_index
Index in image array (for array textures)
Definition: xrt_compositor.h:203
Swapchain creation info.
Definition: xrt_compositor.h:876
Struct used to negotiate properties of a swapchain that is created outside of the compositor.
Definition: xrt_compositor.h:918
enum xrt_swapchain_usage_bits extra_bits
New creation bits.
Definition: xrt_compositor.h:923
uint32_t image_count
How many images the compositor want in the swapchain.
Definition: xrt_compositor.h:920
Base class for a D3D11 client swapchain.
Definition: xrt_compositor.h:2043
struct xrt_swapchain base
Base.
Definition: xrt_compositor.h:2045
ID3D11Texture2D * images[XRT_MAX_SWAPCHAIN_IMAGES]
Images to be used by the caller.
Definition: xrt_compositor.h:2048
Base class for a D3D12 client swapchain.
Definition: xrt_compositor.h:2091
ID3D12Resource * images[XRT_MAX_SWAPCHAIN_IMAGES]
Images to be used by the caller.
Definition: xrt_compositor.h:2096
struct xrt_swapchain base
Base.
Definition: xrt_compositor.h:2093
Base class for an OpenGL (ES) client swapchain.
Definition: xrt_compositor.h:1923
struct xrt_swapchain base
Base.
Definition: xrt_compositor.h:1925
Base class for a swapchain that exposes a native buffer handle to be imported into a client API.
Definition: xrt_compositor.h:2163
struct xrt_swapchain base
Base.
Definition: xrt_compositor.h:2165
xrt_limited_unique_id_t limited_unique_id
Unique id for the swapchain, only unique for the current process, is not synchronized between service...
Definition: xrt_compositor.h:2171
Base class for a Vulkan client swapchain.
Definition: xrt_compositor.h:1982
struct xrt_swapchain base
Base.
Definition: xrt_compositor.h:1984
VkImage images[XRT_MAX_SWAPCHAIN_IMAGES]
Images to be used by the caller.
Definition: xrt_compositor.h:1987
Common swapchain interface/base.
Definition: xrt_compositor.h:536
xrt_result_t(* barrier_image)(struct xrt_swapchain *xsc, enum xrt_barrier_direction direction, uint32_t index)
Do any barrier transitions to and from the application.
Definition: xrt_compositor.h:601
xrt_result_t(* dec_image_use)(struct xrt_swapchain *xsc, uint32_t index)
Decrements the use counter of a swapchain image.
Definition: xrt_compositor.h:580
xrt_result_t(* release_image)(struct xrt_swapchain *xsc, uint32_t index)
See xrReleaseSwapchainImage, state tracker needs to track index.
Definition: xrt_compositor.h:606
xrt_result_t(* acquire_image)(struct xrt_swapchain *xsc, uint32_t *out_index)
Obtain the index of the next image to use, without blocking on being able to write to it.
Definition: xrt_compositor.h:568
xrt_result_t(* wait_image)(struct xrt_swapchain *xsc, uint64_t timeout_ns, uint32_t index)
Wait until image index is available for exclusive use, or until timeout_ns expires.
Definition: xrt_compositor.h:592
struct xrt_reference reference
Reference helper.
Definition: xrt_compositor.h:540
xrt_result_t(* inc_image_use)(struct xrt_swapchain *xsc, uint32_t index)
Increments the use counter of a swapchain image.
Definition: xrt_compositor.h:573
void(* destroy)(struct xrt_swapchain *xsc)
dec_image_use must have been called as often as inc_image_use.
Definition: xrt_compositor.h:552
uint32_t image_count
Number of images.
Definition: xrt_compositor.h:547
Capabilities and information about the system compositor (and its wrapped native compositor,...
Definition: xrt_compositor.h:2267
struct xrt_system_compositor_info::@218::@219 recommended
Recommended for this view.
uint8_t supported_blend_mode_count
Number of meaningful elements in xrt_system_compositor_info::supported_blend_modes.
Definition: xrt_compositor.h:2298
struct xrt_system_compositor_info::@218::@220 max
Maximums for this view.
bool client_d3d_deviceLUID_valid
Whether client_d3d_deviceLUID is valid.
Definition: xrt_compositor.h:2313
enum xrt_blend_mode supported_blend_modes[XRT_BLEND_MODE_MAX_ENUM]
Blend modes supported by the system (the combination of the compositor and the HMD capabilities),...
Definition: xrt_compositor.h:2295
xrt_uuid_t client_vk_deviceUUID
The vk device suggested for Vulkan clients, never changes.
Definition: xrt_compositor.h:2307
struct xrt_system_compositor_info::@218 views[XRT_MAX_VIEWS]
View configuration information.
xrt_luid_t client_d3d_deviceLUID
The (Windows) LUID for the GPU device suggested for D3D clients, never changes.
Definition: xrt_compositor.h:2310
xrt_uuid_t compositor_vk_deviceUUID
The vk device as used by the compositor, never changes.
Definition: xrt_compositor.h:2304
uint32_t max_layers
Maximum number of composition layers supported, never changes.
Definition: xrt_compositor.h:2286
The system compositor handles composition for a system.
Definition: xrt_compositor.h:2386
struct xrt_system_compositor_info info
Info regarding the system.
Definition: xrt_compositor.h:2394
void(* destroy)(struct xrt_system_compositor *xsc)
Teardown the system compositor.
Definition: xrt_compositor.h:2420
struct xrt_multi_compositor_control * xmcc
An optional aspect/additional interface, providing multi-app control.
Definition: xrt_compositor.h:2391
xrt_result_t(* create_native_compositor)(struct xrt_system_compositor *xsc, const struct xrt_session_info *xsi, struct xrt_session_event_sink *xses, struct xrt_compositor_native **out_xcn)
Create a new native compositor.
Definition: xrt_compositor.h:2410
To transport UUIDs between different APIs.
Definition: xrt_defines.h:36
A 2 element vector with single floats.
Definition: xrt_defines.h:250
Auto detect OS and certain features.
Common defines and enums for XRT.
xrt_passthrough_purpose_flags
Specify the kind of passthrough behavior the layer provides.
Definition: xrt_defines.h:148
xrt_perf_domain
Domain type.
Definition: xrt_defines.h:1502
xrt_passthrough_create_flags
Special flags for creating passthrough.
Definition: xrt_defines.h:122
xrt_perf_set_level
Performance level.
Definition: xrt_defines.h:1518
Native handle types.
int xrt_graphics_buffer_handle_t
The type underlying buffers shared between compositor clients and the main compositor.
Definition: xrt_handles.h:246
int xrt_graphics_sync_handle_t
The type underlying synchronization primitives (semaphores, etc) shared between compositor clients an...
Definition: xrt_handles.h:348
Header for limits of the XRT interfaces.
A minimal way to include Windows.h.