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 * 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 * Structure defining the parameters for a blit operation, sans the image itself.
68 *
69 * See @ref vk_cmd_blit_image_info for usage.
70 *
71 * @ingroup aux_vk
72 */
74{
75 VkImageLayout layout;
76 VkAccessFlags access_mask;
77 VkPipelineStageFlags stage_mask;
78 struct xrt_rect rect;
79};
80
81/*!
82 * Argument struct for @ref vk_cmd_blit_image_locked.
83 *
84 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
85 *
86 * @ingroup aux_vk
87 */
89{
90 struct
91 {
92 struct vk_cmd_blit_image_params params;
93 struct vk_cmd_first_mip_image fm_image;
94 } src;
95 struct
96 {
97 struct vk_cmd_blit_image_params params;
98 struct vk_cmd_first_mip_image fm_image;
99 } dst;
100};
101
102/*!
103 * Argument struct for @ref vk_cmd_blit_images_side_by_side_locked.
104 *
105 * See @ref vk_cmd_first_mip_image for array and mip selection rules.
106 *
107 * @ingroup aux_vk
108 */
110{
111 /// One each for left and right eyes/views.
112 /// Populate from the swapchain view data and the swapchain image itself
113 struct
114 {
115 VkImageLayout old_layout;
116 VkAccessFlags src_access_mask;
117 /// Depends on preceding compositor stage
118 VkPipelineStageFlags src_stage_mask;
119
120 struct xrt_rect rect;
121 struct vk_cmd_first_mip_image fm_image;
122 } src[2];
123 struct
124 {
125 VkImageLayout old_layout;
126 VkAccessFlags src_access_mask;
127 VkPipelineStageFlags src_stage_mask;
128 struct xrt_size size;
129 struct vk_cmd_first_mip_image fm_image;
130 } dst;
131};
132
133
134/*
135 *
136 * Command buffer functions.
137 *
138 */
139
140/*!
141 * Create a command buffer, the pool must be locked or ensured that only this
142 * thread is accessing it.
143 *
144 * @pre The look for the command pool must be held, or the code must
145 * ensure that only the calling thread is accessing the command pool.
146 *
147 * @ingroup aux_vk
148 */
149XRT_CHECK_RESULT VkResult
150vk_cmd_create_cmd_buffer_locked(struct vk_bundle *vk, VkCommandPool pool, VkCommandBuffer *out_cmd_buffer);
151
152/*!
153 * Create and begin a command buffer, the pool must be locked or ensured that
154 * only this thread is accessing it.
155 *
156 * @pre The look for the command pool must be held, or the code must
157 * ensure that only the calling thread is accessing the command pool.
158 *
159 * @ingroup aux_vk
160 */
161XRT_CHECK_RESULT VkResult
163 VkCommandPool pool,
164 VkCommandBufferUsageFlags flags,
165 VkCommandBuffer *out_cmd_buffer);
166
167/*!
168 * Very small helper to submit a command buffer, the `_locked` suffix refers to
169 * the command pool not the queue, the queue lock will be taken during the queue
170 * submit call, then released. The pool must be locked or ensured that only this
171 * thread is accessing it.
172 *
173 * @pre The look for the command pool must be held, or the code must
174 * ensure that only the calling thread is accessing the command pool.
175 *
176 * @ingroup aux_vk
177 */
178XRT_CHECK_RESULT VkResult
180 struct vk_bundle *vk, struct vk_bundle_queue *queue, uint32_t count, const VkSubmitInfo *infos, VkFence fence);
181
182/*!
183 * A do everything command buffer submission function, the `_locked` suffix
184 * refers to the command pool not the queue, the queue lock will be taken during
185 * the queue submit call, then released. The pool must be locked or ensured that
186 * only this thread is accessing it.
187 *
188 * @pre The look for the command pool must be held, or the code must
189 * ensure that only the calling thread is accessing the command pool.
190 *
191 * * Creates a new fence.
192 * * Takes queue lock.
193 * * Submits @p cmd_buffer to the queue, along with the fence.
194 * * Release queue lock.
195 * * Waits for the fence to complete.
196 * * Destroys the fence.
197 * * Destroy @p cmd_buffer.
198 *
199 * @ingroup aux_vk
200 */
201XRT_CHECK_RESULT VkResult
203 struct vk_bundle_queue *queue,
204 VkCommandPool pool,
205 VkCommandBuffer cmd_buffer);
206
207
208/*
209 *
210 * Copy and blit helpers.
211 *
212 */
213
214/*!
215 * Performs a copy 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_copy_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_copy_image_info *info);
226
227/*!
228 * Performs a blit of a image into a destination image, also does needed barrier
229 * operation needed to get images ready for transfer operations. Images will be
230 * left in the layout and pipeline needed for transfers.
231 *
232 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
233 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
234 *
235 * @ingroup aux_vk
236 */
237void
238vk_cmd_blit_image_locked(struct vk_bundle *vk, VkCommandBuffer cmd_buffer, const struct vk_cmd_blit_image_info *info);
239
240/*!
241 * Performs a blit of two images to side by side on a destination image, also
242 * does needed barrier operation needed to get images ready for transfer
243 * operations. Images will be left in the layout and pipeline needed for
244 * transfers.
245 *
246 * * Src image(s): VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
247 * * Dst image(s): VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
248 *
249 * @ingroup aux_vk
250 */
251void
253 VkCommandBuffer cmd_buffer,
254 const struct vk_cmd_blit_images_side_by_side_info *info);
255
256
257#ifdef __cplusplus
258}
259#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: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
Argument struct for vk_cmd_blit_image_locked.
Definition vk_cmd.h:89
Structure defining the parameters for a blit operation, sans the image itself.
Definition vk_cmd.h:74
Argument struct for vk_cmd_blit_images_side_by_side_locked.
Definition vk_cmd.h:110
struct vk_cmd_blit_images_side_by_side_info::@50 src[2]
One each for left and right eyes/views.
VkPipelineStageFlags src_stage_mask
Depends on preceding compositor stage.
Definition vk_cmd.h:118
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:457
Image size.
Definition xrt_defines.h:436
Common Vulkan code header.