Monado OpenXR Runtime
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 * Argument struct for @ref vk_cmd_copy_image_locked.
42 *
43 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
44 *
45 * @ingroup aux_vk
46 */
48{
49 struct
50 {
51 VkImageLayout old_layout;
52 VkAccessFlags src_access_mask;
53 VkPipelineStageFlags src_stage_mask;
54 struct vk_cmd_first_mip_image fm_image;
55 } src;
56 struct
57 {
58 VkImageLayout old_layout;
59 VkAccessFlags src_access_mask;
60 VkPipelineStageFlags src_stage_mask;
61 struct vk_cmd_first_mip_image fm_image;
62 } dst;
63 struct xrt_size size;
64};
65
66/*!
67 * Argument struct for @ref vk_cmd_blit_image_locked.
68 *
69 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
70 *
71 * @ingroup aux_vk
72 */
74{
75 struct
76 {
77 VkImageLayout old_layout;
78 VkAccessFlags src_access_mask;
79 VkPipelineStageFlags src_stage_mask;
80 struct xrt_rect rect;
81 struct vk_cmd_first_mip_image fm_image;
82 } src;
83 struct
84 {
85 VkImageLayout old_layout;
86 VkAccessFlags src_access_mask;
87 VkPipelineStageFlags src_stage_mask;
88 struct xrt_rect rect;
89 struct vk_cmd_first_mip_image fm_image;
90 } dst;
91};
92
93/*!
94 * Argument struct for @ref vk_cmd_blit_images_side_by_side_locked.
95 *
96 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
97 *
98 * @ingroup aux_vk
99 */
101{
102 struct
103 {
104 VkImageLayout old_layout;
105 VkAccessFlags src_access_mask;
106 VkPipelineStageFlags src_stage_mask;
107 struct xrt_rect rect;
108 struct vk_cmd_first_mip_image fm_image;
109 } src[2];
110 struct
111 {
112 VkImageLayout old_layout;
113 VkAccessFlags src_access_mask;
114 VkPipelineStageFlags src_stage_mask;
115 struct xrt_size size;
116 struct vk_cmd_first_mip_image fm_image;
117 } dst;
118};
119
120
121/*
122 *
123 * Command buffer functions.
124 *
125 */
126
127/*!
128 * Create a command buffer, the pool must be locked or ensured that only this
129 * thread is accessing it.
130 *
131 * @pre The look for the command pool must be held, or the code must
132 * ensure that only the calling thread is accessing the command pool.
133 *
134 * @ingroup aux_vk
135 */
136XRT_CHECK_RESULT VkResult
137vk_cmd_create_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer *out_cmd_buffer);
138
139/*!
140 * Create and begin a command buffer, the pool must be locked or ensured that
141 * only this thread is accessing it.
142 *
143 * @pre The look for the command pool must be held, or the code must
144 * ensure that only the calling thread is accessing the command pool.
145 *
146 * @ingroup aux_vk
147 */
148XRT_CHECK_RESULT VkResult
150 VkCommandPool pool,
151 VkCommandBufferUsageFlags flags,
152 VkCommandBuffer *out_cmd_buffer);
153
154/*!
155 * Very small helper to submit a command buffer, the `_locked` suffix refers to
156 * the command pool not the queue, the queue lock will be taken during the queue
157 * submit call, then released. The pool must be locked or ensured that only this
158 * thread is accessing it.
159 *
160 * @pre The look for the command pool must be held, or the code must
161 * ensure that only the calling thread is accessing the command pool.
162 *
163 * @ingroup aux_vk
164 */
165XRT_CHECK_RESULT VkResult
166vk_cmd_submit_locked(struct vk_bundle *vk, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
167
168/*!
169 * A do everything command buffer submission function, the `_locked` suffix
170 * refers to the command pool not the queue, the queue lock will be taken during
171 * the queue submit call, then released. The pool must be locked or ensured that
172 * only this thread is accessing it.
173 *
174 * @pre The look for the command pool must be held, or the code must
175 * ensure that only the calling thread is accessing the command pool.
176 *
177 * * Creates a new fence.
178 * * Takes queue lock.
179 * * Submits @p cmd_buffer to the queue, along with the fence.
180 * * Release queue lock.
181 * * Waits for the fence to complete.
182 * * Destroys the fence.
183 * * Destroy @p cmd_buffer.
184 *
185 * @ingroup aux_vk
186 */
187XRT_CHECK_RESULT VkResult
188vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer cmd_buffer);
189
190
191/*
192 *
193 * Copy and blit helpers.
194 *
195 */
196
197/*!
198 * Performs a copy of a image into a destination image, also does needed barrier
199 * operation needed to get images ready for transfer operations. Images will be
200 * left in the layout and pipeline needed for transfers.
201 *
202 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
203 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
204 *
205 * @ingroup aux_vk
206 */
207void
208vk_cmd_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_copy_image_info *info);
209
210/*!
211 * Performs a blit of a image into a destination image, also does needed barrier
212 * operation needed to get images ready for transfer operations. Images will be
213 * left in the layout and pipeline needed for transfers.
214 *
215 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
216 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
217 *
218 * @ingroup aux_vk
219 */
220void
221vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_image_info *info);
222
223/*!
224 * Performs a blit of two images to side by side on a destination image, also
225 * does needed barrier operation needed to get images ready for transfer
226 * operations. Images will be left in the layout and pipeline needed for
227 * transfers.
228 *
229 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
230 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
231 *
232 * @ingroup aux_vk
233 */
234void
236 VkCommandBuffer cmd_buffer,
237 const struct vk_cmd_blit_images_side_by_side_info *info);
238
239
240#ifdef __cplusplus
241}
242#endif
XRT_CHECK_RESULT VkResult vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, 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:97
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:356
XRT_CHECK_RESULT VkResult vk_cmd_submit_locked(struct vk_bundle *vk, 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_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
void vk_cmd_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_copy_image_info *info)
Performs a copy of a image into a destination image, also does needed barrier operation needed to get...
Definition: vk_cmd.c:162
void vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_image_info *info)
Performs a blit of a image into a destination image, also does needed barrier operation needed to get...
Definition: vk_cmd.c:256
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:49
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:49
Argument struct for vk_cmd_blit_image_locked.
Definition: vk_cmd.h:74
Argument struct for vk_cmd_blit_images_side_by_side_locked.
Definition: vk_cmd.h:101
Argument struct for vk_cmd_copy_image_locked.
Definition: vk_cmd.h:48
A similar struct to VkImageSubresourceRange and VkImageSubresourceLayers expect for this it's implied...
Definition: vk_cmd.h:34
Image rectangle.
Definition: xrt_defines.h:430
Image size.
Definition: xrt_defines.h:409
Common Vulkan code header.