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 /// One each for left and right eyes/views.
103 /// Populate from the swapchain view data and the swapchain image itself
104 struct
105 {
106 VkImageLayout old_layout;
107 VkAccessFlags src_access_mask;
108 /// Depends on preceding compositor stage
109 VkPipelineStageFlags src_stage_mask;
110
111 struct xrt_rect rect;
112 struct vk_cmd_first_mip_image fm_image;
113 } src[2];
114 struct
115 {
116 VkImageLayout old_layout;
117 VkAccessFlags src_access_mask;
118 VkPipelineStageFlags src_stage_mask;
119 struct xrt_size size;
120 struct vk_cmd_first_mip_image fm_image;
121 } dst;
122};
123
124
125/*
126 *
127 * Command buffer functions.
128 *
129 */
130
131/*!
132 * Create a command buffer, the pool must be locked or ensured that only this
133 * thread is accessing it.
134 *
135 * @pre The look for the command pool must be held, or the code must
136 * ensure that only the calling thread is accessing the command pool.
137 *
138 * @ingroup aux_vk
139 */
140XRT_CHECK_RESULT VkResult
141vk_cmd_create_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer *out_cmd_buffer);
142
143/*!
144 * Create and begin a command buffer, the pool must be locked or ensured that
145 * only this 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 VkCommandPool pool,
155 VkCommandBufferUsageFlags flags,
156 VkCommandBuffer *out_cmd_buffer);
157
158/*!
159 * Very small helper to submit a command buffer, the `_locked` suffix refers to
160 * the command pool not the queue, the queue lock will be taken during the queue
161 * submit call, then released. The pool must be locked or ensured that only this
162 * thread is accessing it.
163 *
164 * @pre The look for the command pool must be held, or the code must
165 * ensure that only the calling thread is accessing the command pool.
166 *
167 * @ingroup aux_vk
168 */
169XRT_CHECK_RESULT VkResult
170vk_cmd_submit_locked(struct vk_bundle *vk, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
171
172/*!
173 * A do everything command buffer submission function, the `_locked` suffix
174 * refers to the command pool not the queue, the queue lock will be taken during
175 * the queue submit call, then released. The pool must be locked or ensured that
176 * only this thread is accessing it.
177 *
178 * @pre The look for the command pool must be held, or the code must
179 * ensure that only the calling thread is accessing the command pool.
180 *
181 * * Creates a new fence.
182 * * Takes queue lock.
183 * * Submits @p cmd_buffer to the queue, along with the fence.
184 * * Release queue lock.
185 * * Waits for the fence to complete.
186 * * Destroys the fence.
187 * * Destroy @p cmd_buffer.
188 *
189 * @ingroup aux_vk
190 */
191XRT_CHECK_RESULT VkResult
192vk_cmd_end_submit_wait_and_free_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer cmd_buffer);
193
194
195/*
196 *
197 * Copy and blit helpers.
198 *
199 */
200
201/*!
202 * Performs a copy of a image into a destination image, also does needed barrier
203 * operation needed to get images ready for transfer operations. Images will be
204 * left in the layout and pipeline needed for transfers.
205 *
206 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
207 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
208 *
209 * @ingroup aux_vk
210 */
211void
212vk_cmd_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_copy_image_info *info);
213
214/*!
215 * Performs a blit of a image into a destination image, also does needed barrier
216 * operation needed to get images ready for transfer operations. Images will be
217 * left in the layout and pipeline needed for transfers.
218 *
219 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
220 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
221 *
222 * @ingroup aux_vk
223 */
224void
225vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_image_info *info);
226
227/*!
228 * Performs a blit of two images to side by side on a destination image, also
229 * does needed barrier operation needed to get images ready for transfer
230 * operations. Images will be left in the layout and pipeline needed for
231 * transfers.
232 *
233 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
234 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
235 *
236 * @ingroup aux_vk
237 */
238void
240 VkCommandBuffer cmd_buffer,
241 const struct vk_cmd_blit_images_side_by_side_info *info);
242
243
244#ifdef __cplusplus
245}
246#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:366
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:172
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:266
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:50
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
struct vk_cmd_blit_images_side_by_side_info::@57 src[2]
One each for left and right eyes/views.
VkPipelineStageFlags src_stage_mask
Depends on preceding compositor stage.
Definition: vk_cmd.h:109
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.