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