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