The open source OpenXR runtime
at prediction-2 139 lines 3.2 kB view raw
1// Copyright 2019-2024, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Helper implementation for native compositors. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 8 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 9 * @ingroup comp_util 10 */ 11 12#pragma once 13 14#include "util/comp_swapchain.h" 15#include "util/comp_layer_accum.h" 16 17 18#ifdef __cplusplus 19extern "C" { 20#endif 21 22/*! 23 * Additional per-frame parameters. 24 * 25 * Independent of graphics API, swapchain implementation, etc. 26 * 27 * @ingroup comp_util 28 */ 29struct comp_frame_params 30{ 31 //! Special case one layer projection/projection-depth fast-path. 32 bool one_projection_layer_fast_path; 33 34 //! fov as reported by device for the current submit. 35 struct xrt_fov fovs[XRT_MAX_VIEWS]; 36 //! absolute pose as reported by device for the current submit. 37 struct xrt_pose poses[XRT_MAX_VIEWS]; 38}; 39 40/*! 41 * A simple compositor base that handles a lot of things for you. 42 * 43 * Things it handles for you: 44 * 45 * - App swapchains 46 * - App fences 47 * - Vulkan bundle (needed for swapchains and fences) 48 * - Layer tracking, not @ref xrt_compositor::layer_commit 49 * - Wait function, not @ref xrt_compositor::predict_frame 50 * 51 * Functions it does not implement: 52 * 53 * - @ref xrt_compositor::begin_session 54 * - @ref xrt_compositor::end_session 55 * - @ref xrt_compositor::predict_frame 56 * - @ref xrt_compositor::mark_frame 57 * - @ref xrt_compositor::begin_frame 58 * - @ref xrt_compositor::discard_frame 59 * - @ref xrt_compositor::layer_commit 60 * - @ref xrt_compositor::destroy 61 * 62 * Partially implements @ref xrt_compositor_native, meant to serve as 63 * the base of a main compositor implementation. 64 * 65 * @implements xrt_compositor_native 66 * @ingroup comp_util 67 */ 68struct comp_base 69{ 70 //! Base native compositor. 71 struct xrt_compositor_native base; 72 73 //! Vulkan bundle of useful things, used by swapchain and fence. 74 struct vk_bundle vk; 75 76 //! For default @ref xrt_compositor::wait_frame. 77 struct os_precise_sleeper sleeper; 78 79 //! Swapchain garbage collector, used by swapchain, child class needs to call. 80 struct comp_swapchain_shared cscs; 81 82 //! Collect layers for a single frame. 83 struct comp_layer_accum layer_accum; 84 85 //! Parameters for a single frame. 86 struct comp_frame_params frame_params; 87}; 88 89 90/* 91 * 92 * Helper functions. 93 * 94 */ 95 96/*! 97 * Convenience function to convert an xrt_compositor to a comp_base. 98 * 99 * @private @memberof comp_base 100 */ 101static inline struct comp_base * 102comp_base(struct xrt_compositor *xc) 103{ 104 return (struct comp_base *)xc; 105} 106 107 108/* 109 * 110 * 'Exported' functions. 111 * 112 */ 113 114/*! 115 * Inits all of the supported functions and structs, except @ref vk_bundle. 116 * 117 * The bundle needs to be initialised before any of the implemented functions 118 * are call, but is not required to be initialised before this function is 119 * called. 120 * 121 * @protected @memberof comp_base 122 */ 123void 124comp_base_init(struct comp_base *cb); 125 126/*! 127 * De-initialises all structs, except @ref vk_bundle. 128 * 129 * The bundle needs to be de-initialised by the sub-class. 130 * 131 * @private @memberof comp_base 132 */ 133void 134comp_base_fini(struct comp_base *cb); 135 136 137#ifdef __cplusplus 138} 139#endif