Monado OpenXR Runtime
Loading...
Searching...
No Matches
comp_target_swapchain.h
Go to the documentation of this file.
1// Copyright 2019-2020, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Target Vulkan swapchain code header.
6 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup comp_main
9 */
10
11#pragma once
12
13#include "vk/vk_helpers.h"
14
15#include "main/comp_target.h"
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23/*
24 *
25 * Structs.
26 *
27 */
28
30
31/*!
32 * Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by @ref comp code.
33 *
34 * @ingroup comp_main
35 */
37{
38 //! Base target.
40
41 //! Compositor frame pacing helper
43
44 //! If we should use display timing.
46
47 //! Also works as a frame index.
49
50 struct
51 {
52 /*!
53 * Should we ignore the compositor's preferred extents. Some
54 * targets, like the direct mode ones, requires a particular
55 * set of dimensions.
56 */
58
59 /*!
60 * The extents that a sub-class wants us to use,
61 * see @p ignore_compositor_extent above.
62 */
63 VkExtent2D extent;
64 } override;
65
66 struct
67 {
68 VkSwapchainKHR handle;
69 } swapchain;
70
71 struct
72 {
73 VkSurfaceKHR handle;
74 VkSurfaceFormatKHR format;
75#ifdef VK_EXT_display_surface_counter
76 VkSurfaceCounterFlagsEXT surface_counter_flags;
77#endif
78
79 //! Whether VK_KHR_present_id2 is supported for the surface.
81
82 //! Whether VK_KHR_present_wait2 is supported for the surface.
84 } surface;
85
86 struct
87 {
88 VkFormat color_format;
89 VkColorSpaceKHR color_space;
90 } preferred;
91
92 //! Present mode that the system must support.
93 VkPresentModeKHR present_mode;
94
95 //! The current display used for direct mode, VK_NULL_HANDLE else.
96 VkDisplayKHR display;
97
98 struct
99 {
100 //! Must only be accessed from main compositor thread.
102
103 //! Protected by event_thread lock.
105
106 //! Protected by event_thread lock.
108
109 //! Thread waiting on vblank_event_fence (first pixel out).
111
112 //! Skipping the event on the first vblank avoids a spurious VK_ERROR_OUT_OF_HOST_MEMORY error.
114 } vblank;
115
116 /*!
117 * We print swapchain info as INFO the first time we create a
118 * VkSWapchain, this keeps track if we have done it.
119 */
121
122#ifdef VK_KHR_shared_presentable_image
123 /*!
124 * Only relevant when using present modes from VK_KHR_shared_presentable_image,
125 *
126 * Shared presentable images for front buffer rendering we only acquire the image once,
127 * and then reuse it. This will be set the first time we acquire an image.
128 */
129 bool shared_present_acquired;
130#endif
131};
132
133
134/*
135 *
136 * Functions.
137 *
138 */
139
140/*!
141 * @brief Pre Vulkan initialisation, sets function pointers.
142 *
143 * Call from the creation function for your "subclass", after allocating.
144 *
145 * Initializes these function pointers, all other methods of @ref comp_target are the responsibility of the caller (the
146 * "subclass"):
147 *
148 * - comp_target::check_ready
149 * - comp_target::create_images
150 * - comp_target::has_images
151 * - comp_target::acquire
152 * - comp_target::present
153 * - comp_target::calc_frame_pacing
154 * - comp_target::mark_timing_point
155 * - comp_target::update_timings
156 *
157 * Also sets comp_target_swapchain::timing_usage to the provided value.
158 *
159 * @protected @memberof comp_target_swapchain
160 *
161 * @ingroup comp_main
162 */
163void
164comp_target_swapchain_init_and_set_fnptrs(struct comp_target_swapchain *cts,
165 enum comp_target_display_timing_usage timing_usage);
166
167/*!
168 * Set that any size from the compositor should be ignored and that given size
169 * must be used for the @p VkSwapchain the helper code creates.
170 *
171 * @protected @memberof comp_target_swapchain
172 *
173 * @ingroup comp_main
174 */
175void
176comp_target_swapchain_override_extents(struct comp_target_swapchain *cts, VkExtent2D extent);
177
178/*!
179 * Free all managed resources on the given @ref comp_target_swapchain,
180 * does not free the struct itself.
181 *
182 * @protected @memberof comp_target_swapchain
183 *
184 * @ingroup comp_main
185 */
186void
187comp_target_swapchain_cleanup(struct comp_target_swapchain *cts);
188
189
190#ifdef __cplusplus
191}
192#endif
Abstracted compositor rendering target.
comp_target_display_timing_usage
If the target should use the display timing information.
Definition comp_target.h:52
Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code.
Definition comp_target_swapchain.h:37
VkPresentModeKHR present_mode
Present mode that the system must support.
Definition comp_target_swapchain.h:93
VkDisplayKHR display
The current display used for direct mode, VK_NULL_HANDLE else.
Definition comp_target_swapchain.h:96
int64_t current_frame_id
Also works as a frame index.
Definition comp_target_swapchain.h:48
uint64_t last_vblank_ns
Protected by event_thread lock.
Definition comp_target_swapchain.h:107
bool present_wait2_supported
Whether VK_KHR_present_wait2 is supported for the surface.
Definition comp_target_swapchain.h:83
struct os_thread_helper event_thread
Thread waiting on vblank_event_fence (first pixel out).
Definition comp_target_swapchain.h:110
bool present_id2_supported
Whether VK_KHR_present_id2 is supported for the surface.
Definition comp_target_swapchain.h:80
bool should_wait
Protected by event_thread lock.
Definition comp_target_swapchain.h:104
VkExtent2D extent
The extents that a sub-class wants us to use, see ignore_compositor_extent above.
Definition comp_target_swapchain.h:63
struct comp_target base
Base target.
Definition comp_target_swapchain.h:39
bool has_logged_info
We print swapchain info as INFO the first time we create a VkSWapchain, this keeps track if we have d...
Definition comp_target_swapchain.h:120
bool thread_running
Must only be accessed from main compositor thread.
Definition comp_target_swapchain.h:101
bool compositor_extent
Should we ignore the compositor's preferred extents.
Definition comp_target_swapchain.h:57
bool event_active
Skipping the event on the first vblank avoids a spurious VK_ERROR_OUT_OF_HOST_MEMORY error.
Definition comp_target_swapchain.h:113
struct u_pacing_compositor * upc
Compositor frame pacing helper.
Definition comp_target_swapchain.h:42
enum comp_target_display_timing_usage timing_usage
If we should use display timing.
Definition comp_target_swapchain.h:45
A compositor target: where the compositor renders to.
Definition comp_target.h:133
Definition t_rift_blobwatch.c:112
All in one helper that handles locking, waiting for change and starting a thread.
Definition os_threading.h:499
Compositor pacing helper interface.
Definition u_pacing.h:68
Common Vulkan code header.