Monado OpenXR Runtime
Loading...
Searching...
No Matches
vk_cmd.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Command buffer helpers.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
8 * @ingroup aux_vk
9 */
10
11#pragma once
12
13#include "vk/vk_helpers.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19
20/*
21 *
22 * Struct(s).
23 *
24 */
25
26/*!
27 * A similar struct to VkImageSubresourceRange and VkImageSubresourceLayers
28 * expect for this it's implied that it's only the first mip-level and only one
29 * array layer used for the operation.
30 *
31 * @ingroup aux_vk
32 */
34{
35 uint32_t base_array_layer;
36 VkAccessFlags aspect_mask;
37 VkImage image;
38};
39
40/*!
41 * Structure defining the parameters for a blit operation, sans the image itself.
42 *
43 * See @ref vk_cmd_blit_image_info for usage.
44 *
45 * @ingroup aux_vk
46 */
48{
49 VkImageLayout layout;
50 VkAccessFlags access_mask;
51 VkPipelineStageFlags stage_mask;
52 struct xrt_rect rect;
53};
54
55/*!
56 * Argument struct for @ref vk_cmd_blit_image_locked and @ref vk_cmd_copy_image_locked.
57 *
58 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
59 *
60 * @ingroup aux_vk
61 */
63{
64 struct
65 {
66 struct vk_cmd_blit_image_params params;
67 struct vk_cmd_first_mip_image fm_image;
68 } src;
69 struct
70 {
71 struct vk_cmd_blit_image_params params;
72 struct vk_cmd_first_mip_image fm_image;
73 } dst;
74};
75
76/*!
77 * Argument struct for @ref vk_cmd_blit_images_side_by_side_locked.
78 *
79 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
80 *
81 * @ingroup aux_vk
82 */
84{
85 /// One each for left and right eyes/views.
86 /// Populate from the swapchain view data and the swapchain image itself
87 struct
88 {
89 VkImageLayout old_layout;
90 VkAccessFlags src_access_mask;
91 /// Depends on preceding compositor stage
92 VkPipelineStageFlags src_stage_mask;
93
94 struct xrt_rect rect;
95 struct vk_cmd_first_mip_image fm_image;
96 } src[2];
97 struct
98 {
99 VkImageLayout old_layout;
100 VkAccessFlags src_access_mask;
101 VkPipelineStageFlags src_stage_mask;
102 struct xrt_size size;
103 struct vk_cmd_first_mip_image fm_image;
104 } dst;
105};
106
107
108/*
109 *
110 * Command buffer functions.
111 *
112 */
113
114/*!
115 * Create a command buffer, the pool must be locked or ensured that only this
116 * thread is accessing it.
117 *
118 * @pre The look for the command pool must be held, or the code must
119 * ensure that only the calling thread is accessing the command pool.
120 *
121 * @ingroup aux_vk
122 */
123XRT_CHECK_RESULT VkResult
124vk_cmd_create_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer *out_cmd_buffer);
125
126/*!
127 * Create and begin a command buffer, the pool must be locked or ensured that
128 * only this thread is accessing it.
129 *
130 * @pre The look for the command pool must be held, or the code must
131 * ensure that only the calling thread is accessing the command pool.
132 *
133 * @ingroup aux_vk
134 */
135XRT_CHECK_RESULT VkResult
137 VkCommandPool pool,
138 VkCommandBufferUsageFlags flags,
139 VkCommandBuffer *out_cmd_buffer);
140
141/*!
142 * Very small helper to submit a command buffer, the `_locked` suffix refers to
143 * the command pool not the queue, the queue lock will be taken during the queue
144 * submit call, then released. The pool must be locked or ensured that only this
145 * thread is accessing it.
146 *
147 * @pre The look for the command pool must be held, or the code must
148 * ensure that only the calling thread is accessing the command pool.
149 *
150 * @ingroup aux_vk
151 */
152XRT_CHECK_RESULT VkResult
154 struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
155
156/*!
157 * A do everything command buffer submission function, the `_locked` suffix
158 * refers to the command pool not the queue, the queue lock will be taken during
159 * the queue submit call, then released. The pool must be locked or ensured that
160 * only this thread is accessing it.
161 *
162 * @pre The look for the command pool must be held, or the code must
163 * ensure that only the calling thread is accessing the command pool.
164 *
165 * * Creates a new fence.
166 * * Takes queue lock.
167 * * Submits @p cmd_buffer to the queue, along with the fence.
168 * * Release queue lock.
169 * * Waits for the fence to complete.
170 * * Destroys the fence.
171 * * Destroy @p cmd_buffer.
172 *
173 * @ingroup aux_vk
174 */
175XRT_CHECK_RESULT VkResult
177 struct vk_bundle_queue *queue,
178 VkCommandPool pool,
179 VkCommandBuffer cmd_buffer);
180
181
182/*
183 *
184 * Copy and blit helpers.
185 *
186 */
187
188/*!
189 * Performs a copy of a image into a destination image, also does needed barrier
190 * operation needed to get images ready for transfer operations. Images will be
191 * left in the layout and pipeline needed for transfers. Extents of the source
192 * and destination must be equal.
193 *
194 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
195 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
196 *
197 * @ingroup aux_vk
198 */
199void
201 VkCommandBuffer cmd_buffer,
202 const struct vk_cmd_image_transfer_info *info);
203
204/*!
205 * Performs a blit of a image into a destination image, also does needed barrier
206 * operation needed to get images ready for transfer operations. Images will be
207 * left in the layout and pipeline needed for transfers.
208 *
209 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
210 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
211 *
212 * @ingroup aux_vk
213 */
214void
216 VkCommandBuffer cmd_buffer,
217 const struct vk_cmd_image_transfer_info *info);
218
219/*!
220 * Performs a resolve of a image into a destination image, also does needed barrier
221 * operation needed to get images ready for transfer operations. Images will be
222 * left in the layout and pipeline needed for transfers.
223 *
224 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
225 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
226 *
227 * @ingroup aux_vk
228 */
229void
231 VkCommandBuffer cmd_buffer,
232 const struct vk_cmd_image_transfer_info *info);
233
234/*!
235 * Performs a blit of two images to side by side on a destination image, also
236 * does needed barrier operation needed to get images ready for transfer
237 * operations. Images will be left in the layout and pipeline needed for
238 * transfers.
239 *
240 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
241 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
242 *
243 * @ingroup aux_vk
244 */
245void
247 VkCommandBuffer cmd_buffer,
248 const struct vk_cmd_blit_images_side_by_side_info *info);
249
250
251#ifdef __cplusplus
252}
253#endif
void vk_cmd_resolve_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_image_transfer_info *info)
Performs a resolve of a image into a destination image, also does needed barrier operation needed to ...
Definition vk_cmd.c:383
XRT_CHECK_RESULT VkResult vk_cmd_submit_locked(struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence)
Very small helper to submit a command buffer, the _locked suffix refers to the command pool not the q...
Definition vk_cmd.c:81
XRT_CHECK_RESULT VkResult vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, struct vk_bundle_queue *queue, VkCommandPool pool, VkCommandBuffer cmd_buffer)
A do everything command buffer submission function, the _locked suffix refers to the command pool not...
Definition vk_cmd.c:98
void vk_cmd_blit_images_side_by_side_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_images_side_by_side_info *info)
Performs a blit of two images to side by side on a destination image, also does needed barrier operat...
Definition vk_cmd.c:488
void vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_image_transfer_info *info)
Performs a blit of a image into a destination image, also does needed barrier operation needed to get...
Definition vk_cmd.c:281
void vk_cmd_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_image_transfer_info *info)
Performs a copy of a image into a destination image, also does needed barrier operation needed to get...
Definition vk_cmd.c:176
XRT_CHECK_RESULT VkResult vk_cmd_create_and_begin_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBufferUsageFlags flags, VkCommandBuffer *out_cmd_buffer)
Create and begin a command buffer, the pool must be locked or ensured that only this thread is access...
Definition vk_cmd.c:41
XRT_CHECK_RESULT VkResult vk_cmd_create_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer *out_cmd_buffer)
Create a command buffer, the pool must be locked or ensured that only this thread is accessing it.
Definition vk_cmd.c:15
A very simple implementation of a fence primitive.
Definition comp_sync.c:36
Definition m_space.cpp:87
Definition u_worker.c:50
Definition vk_helpers.h:62
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition vk_helpers.h:81
Structure defining the parameters for a blit operation, sans the image itself.
Definition vk_cmd.h:48
Argument struct for vk_cmd_blit_images_side_by_side_locked.
Definition vk_cmd.h:84
VkPipelineStageFlags src_stage_mask
Depends on preceding compositor stage.
Definition vk_cmd.h:92
struct vk_cmd_blit_images_side_by_side_info::@71 src[2]
One each for left and right eyes/views.
A similar struct to VkImageSubresourceRange and VkImageSubresourceLayers expect for this it's implied...
Definition vk_cmd.h:34
Argument struct for vk_cmd_blit_image_locked and vk_cmd_copy_image_locked.
Definition vk_cmd.h:63
Image rectangle.
Definition xrt_defines.h:457
Image size.
Definition xrt_defines.h:436
Common Vulkan code header.