Monado OpenXR Runtime
comp_compositor.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Main compositor written using Vulkan header.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
8 * @ingroup comp_main
9 */
10
11#pragma once
12
13#include "xrt/xrt_gfx_vk.h"
14#include "xrt/xrt_config_build.h"
15
16#include "util/u_threading.h"
17#include "util/u_index_fifo.h"
18#include "util/u_logging.h"
21
22#include "util/comp_base.h"
23#include "util/comp_sync.h"
24#include "util/comp_scratch.h"
25#include "util/comp_swapchain.h"
26
28
29#include "main/comp_target.h"
30#include "main/comp_window.h"
31#include "main/comp_settings.h"
32#include "main/comp_renderer.h"
33
34struct comp_window_peek;
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41
42/*
43 *
44 * Defines
45 *
46 */
47
48// clang-format off
49#define COMP_INSTANCE_EXTENSIONS_COMMON \
50 VK_EXT_DEBUG_REPORT_EXTENSION_NAME, \
51 VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, \
52 VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, \
53 VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, \
54 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, \
55 VK_KHR_SURFACE_EXTENSION_NAME
56// clang-format on
57
58
59/*
60 *
61 * Structs
62 *
63 */
64
65/*!
66 * Tracking frame state.
67 */
69{
70 int64_t id;
71 uint64_t predicted_display_time_ns;
72 uint64_t desired_present_time_ns;
73 uint64_t present_slop_ns;
74};
75
76/*!
77 * Main compositor struct tying everything in the compositor together.
78 *
79 *
80 * This ultimately implements @ref xrt_compositor_native but does so by
81 * extending @ref comp_base. Yes, it looks like a little bit of "code reuse
82 * through inheritance," but it is useful here to avoid lots of boilerplate
83 * due to the use of C.
84 *
85 * @ingroup comp_main
86 * @extends comp_base
87 */
89{
90 struct comp_base base;
91
92 //! The settings.
94
95 //! The device we are displaying to.
97
98 //! Vulkan shaders that the compositor (renderer) uses.
100
101 //! Vulkan resources that the compositor (renderer) uses.
103
104 //! The selected target factory that we create our target from.
106
107 //! The target we are displaying to.
109
110 //! Renderer helper.
112
113 //! Duration of a frame at current refresh rate.
115
116 //! Timestamp of last-rendered (immersive) frame.
118
119 // Extents of one view, in pixels.
120 VkExtent2D view_extents;
121
122 //! Are we mirroring any of the views to the debug gui? If so, turn off the fast path.
124
125 //! On screen window to display the content of the HMD.
127
128 /*!
129 * @brief Data exclusive to the begin_frame/end_frame for computing an
130 * estimate of the app's needs.
131 */
132 struct
133 {
134 int64_t last_begin;
135 int64_t last_end;
137
138 struct u_frame_times_widget compositor_frame_times;
139
140 struct
141 {
142 struct comp_frame waited;
143 struct comp_frame rendering;
144 } frame;
145
146 struct
147 {
148 // Per-view scratch images.
149 struct comp_scratch_single_images views[2];
150 } scratch;
151
152 struct
153 {
154 //! Temporarily disable ATW
156
157 //! Should the fast path be disabled.
159
160 struct u_swapchain_debug sc;
161 } debug;
162
163 //! If true, part of the compositor startup will be delayed until a session is started
165};
166
167
168/*
169 *
170 * Functions and helpers.
171 *
172 */
173
174/*!
175 * Convenience function to convert an xrt_compositor to a comp_compositor.
176 *
177 * @private @memberof comp_compositor
178 */
179static inline struct comp_compositor *
181{
182 return (struct comp_compositor *)xc;
183}
184
185/*!
186 * Helper define for printing Vulkan errors.
187 *
188 * @relates comp_compositor
189 */
190#define CVK_ERROR(C, FUNC, MSG, RET) COMP_ERROR(C, FUNC ": %s\n\t" MSG, vk_result_string(RET));
191
192/*!
193 * Spew level logging.
194 *
195 * @relates comp_compositor
196 */
197#define COMP_SPEW(c, ...) U_LOG_IFL_T(c->settings.log_level, __VA_ARGS__);
198
199/*!
200 * Debug level logging.
201 *
202 * @relates comp_compositor
203 */
204#define COMP_DEBUG(c, ...) U_LOG_IFL_D(c->settings.log_level, __VA_ARGS__);
205
206/*!
207 * Info level logging.
208 *
209 * @relates comp_compositor
210 */
211#define COMP_INFO(c, ...) U_LOG_IFL_I(c->settings.log_level, __VA_ARGS__);
212
213/*!
214 * Warn level logging.
215 *
216 * @relates comp_compositor
217 */
218#define COMP_WARN(c, ...) U_LOG_IFL_W(c->settings.log_level, __VA_ARGS__);
219
220/*!
221 * Error level logging.
222 *
223 * @relates comp_compositor
224 */
225#define COMP_ERROR(c, ...) U_LOG_IFL_E(c->settings.log_level, __VA_ARGS__);
226
227/*!
228 * Mode printing.
229 *
230 * @relates comp_compositor
231 */
232#define COMP_PRINT_MODE(c, ...) \
233 if (c->settings.print_modes) { \
234 U_LOG_I(__VA_ARGS__); \
235 }
236
237
238#ifdef __cplusplus
239}
240#endif
Helper implementation for native compositors.
Compositor rendering code header.
Helper implementation for native compositors.
Settings struct for compositor header.
Independent swapchain implementation.
Independent xrt_compositor_fence implementation.
Abstracted compositor rendering target.
Compositor window header.
The NEW compositor rendering code header.
A simple compositor base that handles a lot of things for you.
Definition: comp_base.h:69
struct xrt_compositor_native base
Base native compositor.
Definition: comp_base.h:71
Main compositor struct tying everything in the compositor together.
Definition: comp_compositor.h:89
bool deferred_surface
If true, part of the compositor startup will be delayed until a session is started.
Definition: comp_compositor.h:164
struct comp_settings settings
The settings.
Definition: comp_compositor.h:93
struct xrt_device * xdev
The device we are displaying to.
Definition: comp_compositor.h:96
struct comp_window_peek * peek
On screen window to display the content of the HMD.
Definition: comp_compositor.h:126
const struct comp_target_factory * target_factory
The selected target factory that we create our target from.
Definition: comp_compositor.h:105
bool atw_off
Temporarily disable ATW.
Definition: comp_compositor.h:155
bool mirroring_to_debug_gui
Are we mirroring any of the views to the debug gui? If so, turn off the fast path.
Definition: comp_compositor.h:123
struct comp_renderer * r
Renderer helper.
Definition: comp_compositor.h:111
struct render_shaders shaders
Vulkan shaders that the compositor (renderer) uses.
Definition: comp_compositor.h:99
int64_t frame_interval_ns
Duration of a frame at current refresh rate.
Definition: comp_compositor.h:114
bool disable_fast_path
Should the fast path be disabled.
Definition: comp_compositor.h:158
int64_t last_frame_time_ns
Timestamp of last-rendered (immersive) frame.
Definition: comp_compositor.h:117
struct render_resources nr
Vulkan resources that the compositor (renderer) uses.
Definition: comp_compositor.h:102
struct comp_compositor::@62 app_profiling
Data exclusive to the begin_frame/end_frame for computing an estimate of the app's needs.
struct comp_target * target
The target we are displaying to.
Definition: comp_compositor.h:108
Tracking frame state.
Definition: comp_compositor.h:69
Holds associated vulkan objects and state to render with a distortion.
Definition: comp_renderer.c:96
Holds scratch images for a single view, designed to work with render code.
Definition: comp_scratch.h:68
Settings for the compositor.
Definition: comp_settings.h:47
A factory of targets.
Definition: comp_target.h:651
A compositor target: where the compositor renders to.
Definition: comp_target.h:132
Definition: comp_window_peek.c:30
Definition: u_pacing_compositor.c:54
Holds all pools and static resources for rendering.
Definition: render_interface.h:352
Holds all shaders.
Definition: render_interface.h:136
Definition: u_frame_times_widget.h:24
Allows to debug image that is in GPU memory.
Definition: u_native_images_debug.h:197
Common compositor client interface/base.
Definition: xrt_compositor.h:988
A single HMD or input device.
Definition: xrt_device.h:241
Shared code for visualizing frametimes.
A FIFO for indices.
Basic logging functionality.
Special code for managing a variable tracked swapchain.
Slightly higher level thread safe helpers.
Header defining an XRT graphics provider.