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
171 struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
172
173/*!
174 * A do everything command buffer submission function, the `_locked` suffix
175 * refers to the command pool not the queue, the queue lock will be taken during
176 * the queue submit call, then released. The pool must be locked or ensured that
177 * only this thread is accessing it.
178 *
179 * @pre The look for the command pool must be held, or the code must
180 * ensure that only the calling thread is accessing the command pool.
181 *
182 * * Creates a new fence.
183 * * Takes queue lock.
184 * * Submits @p cmd_buffer to the queue, along with the fence.
185 * * Release queue lock.
186 * * Waits for the fence to complete.
187 * * Destroys the fence.
188 * * Destroy @p cmd_buffer.
189 *
190 * @ingroup aux_vk
191 */
192XRT_CHECK_RESULT VkResult
194 struct vk_bundle_queue *queue,
195 VkCommandPool pool,
196 VkCommandBuffer cmd_buffer);
197
198
199/*
200 *
201 * Copy and blit helpers.
202 *
203 */
204
205/*!
206 * Performs a copy of a image into a destination image, also does needed barrier
207 * operation needed to get images ready for transfer operations. Images will be
208 * left in the layout and pipeline needed for transfers.
209 *
210 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
211 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
212 *
213 * @ingroup aux_vk
214 */
215void
216vk_cmd_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_copy_image_info *info);
217
218/*!
219 * Performs a blit of a image into a destination image, also does needed barrier
220 * operation needed to get images ready for transfer operations. Images will be
221 * left in the layout and pipeline needed for transfers.
222 *
223 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
224 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
225 *
226 * @ingroup aux_vk
227 */
228void
229vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_image_info *info);
230
231/*!
232 * Performs a blit of two images to side by side on a destination image, also
233 * does needed barrier operation needed to get images ready for transfer
234 * operations. Images will be left in the layout and pipeline needed for
235 * transfers.
236 *
237 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
238 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
239 *
240 * @ingroup aux_vk
241 */
242void
244 VkCommandBuffer cmd_buffer,
245 const struct vk_cmd_blit_images_side_by_side_info *info);
246
247
248#ifdef __cplusplus
249}
250#endif
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:370
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:176
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:270
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
Definition: vk_helpers.h:44
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code.
Definition: vk_helpers.h:67
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
VkPipelineStageFlags src_stage_mask
Depends on preceding compositor stage.
Definition: vk_cmd.h:109
struct vk_cmd_blit_images_side_by_side_info::@59 src[2]
One each for left and right eyes/views.
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:429
Image size.
Definition: xrt_defines.h:408
Common Vulkan code header.