Monado OpenXR Runtime
Loading...
Searching...
No Matches
comp_compositor.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2025-2026, 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"
21#include "util/comp_base.h"
22#include "util/comp_sync.h"
23#include "util/comp_scratch.h"
24#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 active view configurations
93 struct xrt_view_config view_configs[XRT_MAX_COMPOSITOR_VIEW_CONFIGS_COUNT];
94 //! The amount of view configs
96
97 //! The settings.
99
100 //! The device we are displaying to.
102
103 //! Vulkan shaders that the compositor (renderer) uses.
105
106 //! Vulkan resources that the compositor (renderer) uses.
108
109 //! The selected target factory that we create our target from.
111
112 //! The target we are displaying to.
114
115 //! Renderer helper.
117
118 //! Duration of a frame at current refresh rate.
120
121 //! Compositor mode passed to the device when querying it, kept in sync with @ref frame_interval_ns.
123
124 //! Timestamp of last-rendered (immersive) frame.
126
127 // Extents of one view, in pixels.
128 VkExtent2D view_extents;
129
130 //! Are we mirroring any of the views to the debug gui? If so, turn off the fast path.
132
133 //! On screen window to display the content of the HMD.
135
136 /*!
137 * @brief Data exclusive to the begin_frame/end_frame for computing an
138 * estimate of the app's needs.
139 */
140 struct
141 {
142 int64_t last_begin;
143 int64_t last_end;
145
146 struct u_frame_times_widget compositor_frame_times;
147
148 struct
149 {
150 struct comp_frame waited;
151 struct comp_frame rendering;
152 } frame;
153
154 // Scratch images for the renderer.
155 struct chl_scratch scratch;
156
157 struct
158 {
159 //! Temporarily disable ATW
161
162 //! Should the fast path be disabled.
164 } debug;
165
166 //! If true, part of the compositor startup will be delayed until a session is started
168};
169
170
171/*
172 *
173 * Functions and helpers.
174 *
175 */
176
177/*!
178 * Convenience function to convert an xrt_compositor to a comp_compositor.
179 *
180 * @private @memberof comp_compositor
181 */
182static inline struct comp_compositor *
184{
185 return (struct comp_compositor *)xc;
186}
187
188/*!
189 * Helper define for printing Vulkan errors.
190 *
191 * @relates comp_compositor
192 */
193#define CVK_ERROR(C, FUNC, MSG, RET) COMP_ERROR(C, FUNC ": %s\n\t" MSG, vk_str_result(RET));
194
195/*!
196 * Spew level logging.
197 *
198 * @relates comp_compositor
199 */
200#define COMP_SPEW(c, ...) U_LOG_IFL_T(c->settings.log_level, __VA_ARGS__);
201
202/*!
203 * Debug level logging.
204 *
205 * @relates comp_compositor
206 */
207#define COMP_DEBUG(c, ...) U_LOG_IFL_D(c->settings.log_level, __VA_ARGS__);
208
209/*!
210 * Info level logging.
211 *
212 * @relates comp_compositor
213 */
214#define COMP_INFO(c, ...) U_LOG_IFL_I(c->settings.log_level, __VA_ARGS__);
215
216/*!
217 * Warn level logging.
218 *
219 * @relates comp_compositor
220 */
221#define COMP_WARN(c, ...) U_LOG_IFL_W(c->settings.log_level, __VA_ARGS__);
222
223/*!
224 * Error level logging.
225 *
226 * @relates comp_compositor
227 */
228#define COMP_ERROR(c, ...) U_LOG_IFL_E(c->settings.log_level, __VA_ARGS__);
229
230/*!
231 * Mode printing.
232 *
233 * @relates comp_compositor
234 */
235#define COMP_PRINT_MODE(c, ...) \
236 if (c->settings.print_modes) { \
237 U_LOG_I(__VA_ARGS__); \
238 }
239
240
241#ifdef __cplusplus
242}
243#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
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:167
struct comp_settings settings
The settings.
Definition comp_compositor.h:98
struct xrt_device * xdev
The device we are displaying to.
Definition comp_compositor.h:101
struct comp_window_peek * peek
On screen window to display the content of the HMD.
Definition comp_compositor.h:134
const struct comp_target_factory * target_factory
The selected target factory that we create our target from.
Definition comp_compositor.h:110
uint32_t view_config_count
The amount of view configs.
Definition comp_compositor.h:95
bool atw_off
Temporarily disable ATW.
Definition comp_compositor.h:160
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:131
struct comp_renderer * r
Renderer helper.
Definition comp_compositor.h:116
struct render_shaders shaders
Vulkan shaders that the compositor (renderer) uses.
Definition comp_compositor.h:104
int64_t frame_interval_ns
Duration of a frame at current refresh rate.
Definition comp_compositor.h:119
bool disable_fast_path
Should the fast path be disabled.
Definition comp_compositor.h:163
struct comp_compositor::@84 app_profiling
Data exclusive to the begin_frame/end_frame for computing an estimate of the app's needs.
int64_t last_frame_time_ns
Timestamp of last-rendered (immersive) frame.
Definition comp_compositor.h:125
struct render_resources nr
Vulkan resources that the compositor (renderer) uses.
Definition comp_compositor.h:107
struct xrt_device_compositor_mode xdev_compositor_mode
Compositor mode passed to the device when querying it, kept in sync with frame_interval_ns.
Definition comp_compositor.h:122
struct comp_target * target
The target we are displaying to.
Definition comp_compositor.h:113
struct xrt_view_config view_configs[XRT_MAX_COMPOSITOR_VIEW_CONFIGS_COUNT]
The active view configurations.
Definition comp_compositor.h:93
Tracking frame state.
Definition comp_compositor.h:69
Holds associated vulkan objects and state to render with a distortion.
Definition comp_renderer.c:120
Settings for the compositor.
Definition comp_settings.h:48
A factory of targets.
Definition comp_target.h:791
A compositor target: where the compositor renders to.
Definition comp_target.h:133
Definition comp_window_peek.c:32
Definition u_pacing_compositor.c:59
Holds all pools and static resources for rendering.
Definition render_interface.h:348
Holds all shaders.
Definition render_shaders_interface.h:26
Definition u_frame_times_widget.h:24
Common compositor client interface/base.
Definition xrt_compositor.h:1004
Compositor mode information for a device.
Definition xrt_device.h:169
A single HMD or input device.
Definition xrt_device.h:345
Definition xrt_compositor.h:2256
Shared code for visualizing frametimes.
A FIFO for indices.
Basic logging functionality.
Slightly higher level thread safe helpers.
Header defining an XRT graphics provider.