1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2019 Google LLC
3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * based in part on anv and radv which are:
6bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation
7bf215546Sopenharmony_ci * Copyright © 2016 Red Hat.
8bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen
9bf215546Sopenharmony_ci */
10bf215546Sopenharmony_ci
11bf215546Sopenharmony_ci#include "vn_command_buffer.h"
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_ci#include "venus-protocol/vn_protocol_driver_command_buffer.h"
14bf215546Sopenharmony_ci#include "venus-protocol/vn_protocol_driver_command_pool.h"
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_ci#include "vn_device.h"
17bf215546Sopenharmony_ci#include "vn_image.h"
18bf215546Sopenharmony_ci#include "vn_render_pass.h"
19bf215546Sopenharmony_ci
20bf215546Sopenharmony_ci#define VN_CMD_ENQUEUE(cmd_name, commandBuffer, ...)                         \
21bf215546Sopenharmony_ci   do {                                                                      \
22bf215546Sopenharmony_ci      struct vn_command_buffer *_cmd =                                       \
23bf215546Sopenharmony_ci         vn_command_buffer_from_handle(commandBuffer);                       \
24bf215546Sopenharmony_ci      size_t _cmd_size = vn_sizeof_##cmd_name(commandBuffer, ##__VA_ARGS__); \
25bf215546Sopenharmony_ci                                                                             \
26bf215546Sopenharmony_ci      if (vn_cs_encoder_reserve(&_cmd->cs, _cmd_size))                       \
27bf215546Sopenharmony_ci         vn_encode_##cmd_name(&_cmd->cs, 0, commandBuffer, ##__VA_ARGS__);   \
28bf215546Sopenharmony_ci      else                                                                   \
29bf215546Sopenharmony_ci         _cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;                      \
30bf215546Sopenharmony_ci   } while (0)
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_cistatic bool
33bf215546Sopenharmony_civn_image_memory_barrier_has_present_src(
34bf215546Sopenharmony_ci   const VkImageMemoryBarrier *img_barriers, uint32_t count)
35bf215546Sopenharmony_ci{
36bf215546Sopenharmony_ci   for (uint32_t i = 0; i < count; i++) {
37bf215546Sopenharmony_ci      if (img_barriers[i].oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
38bf215546Sopenharmony_ci          img_barriers[i].newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
39bf215546Sopenharmony_ci         return true;
40bf215546Sopenharmony_ci   }
41bf215546Sopenharmony_ci   return false;
42bf215546Sopenharmony_ci}
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_cistatic VkImageMemoryBarrier *
45bf215546Sopenharmony_civn_cmd_get_image_memory_barriers(struct vn_command_buffer *cmd,
46bf215546Sopenharmony_ci                                 uint32_t count)
47bf215546Sopenharmony_ci{
48bf215546Sopenharmony_ci   /* avoid shrinking in case of non efficient reallocation implementation */
49bf215546Sopenharmony_ci   if (count > cmd->builder.image_barrier_count) {
50bf215546Sopenharmony_ci      size_t size = sizeof(VkImageMemoryBarrier) * count;
51bf215546Sopenharmony_ci      VkImageMemoryBarrier *img_barriers =
52bf215546Sopenharmony_ci         vk_realloc(&cmd->allocator, cmd->builder.image_barriers, size,
53bf215546Sopenharmony_ci                    VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
54bf215546Sopenharmony_ci      if (!img_barriers)
55bf215546Sopenharmony_ci         return NULL;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci      /* update upon successful reallocation */
58bf215546Sopenharmony_ci      cmd->builder.image_barrier_count = count;
59bf215546Sopenharmony_ci      cmd->builder.image_barriers = img_barriers;
60bf215546Sopenharmony_ci   }
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   return cmd->builder.image_barriers;
63bf215546Sopenharmony_ci}
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/* About VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, the spec says
66bf215546Sopenharmony_ci *
67bf215546Sopenharmony_ci *    VK_IMAGE_LAYOUT_PRESENT_SRC_KHR must only be used for presenting a
68bf215546Sopenharmony_ci *    presentable image for display. A swapchain's image must be transitioned
69bf215546Sopenharmony_ci *    to this layout before calling vkQueuePresentKHR, and must be
70bf215546Sopenharmony_ci *    transitioned away from this layout after calling vkAcquireNextImageKHR.
71bf215546Sopenharmony_ci *
72bf215546Sopenharmony_ci * That allows us to treat the layout internally as
73bf215546Sopenharmony_ci *
74bf215546Sopenharmony_ci *  - VK_IMAGE_LAYOUT_GENERAL
75bf215546Sopenharmony_ci *  - VK_QUEUE_FAMILY_FOREIGN_EXT has the ownership, if the image is not a
76bf215546Sopenharmony_ci *    prime blit source
77bf215546Sopenharmony_ci *
78bf215546Sopenharmony_ci * while staying performant.
79bf215546Sopenharmony_ci *
80bf215546Sopenharmony_ci * About queue family ownerships, the spec says
81bf215546Sopenharmony_ci *
82bf215546Sopenharmony_ci *    A queue family can take ownership of an image subresource or buffer
83bf215546Sopenharmony_ci *    range of a resource created with VK_SHARING_MODE_EXCLUSIVE, without an
84bf215546Sopenharmony_ci *    ownership transfer, in the same way as for a resource that was just
85bf215546Sopenharmony_ci *    created; however, taking ownership in this way has the effect that the
86bf215546Sopenharmony_ci *    contents of the image subresource or buffer range are undefined.
87bf215546Sopenharmony_ci *
88bf215546Sopenharmony_ci * It is unclear if that is applicable to external resources, which supposedly
89bf215546Sopenharmony_ci * have the same semantics
90bf215546Sopenharmony_ci *
91bf215546Sopenharmony_ci *    Binding a resource to a memory object shared between multiple Vulkan
92bf215546Sopenharmony_ci *    instances or other APIs does not change the ownership of the underlying
93bf215546Sopenharmony_ci *    memory. The first entity to access the resource implicitly acquires
94bf215546Sopenharmony_ci *    ownership. Accessing a resource backed by memory that is owned by a
95bf215546Sopenharmony_ci *    particular instance or API has the same semantics as accessing a
96bf215546Sopenharmony_ci *    VK_SHARING_MODE_EXCLUSIVE resource[...]
97bf215546Sopenharmony_ci *
98bf215546Sopenharmony_ci * We should get the spec clarified, or get rid of this completely broken code
99bf215546Sopenharmony_ci * (TODO).
100bf215546Sopenharmony_ci *
101bf215546Sopenharmony_ci * Assuming a queue family can acquire the ownership implicitly when the
102bf215546Sopenharmony_ci * contents are not needed, we do not need to worry about
103bf215546Sopenharmony_ci * VK_IMAGE_LAYOUT_UNDEFINED.  We can use VK_IMAGE_LAYOUT_PRESENT_SRC_KHR as
104bf215546Sopenharmony_ci * the sole signal to trigger queue family ownership transfers.
105bf215546Sopenharmony_ci *
106bf215546Sopenharmony_ci * When the image has VK_SHARING_MODE_CONCURRENT, we can, and are required to,
107bf215546Sopenharmony_ci * use VK_QUEUE_FAMILY_IGNORED as the other queue family whether we are
108bf215546Sopenharmony_ci * transitioning to or from VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
109bf215546Sopenharmony_ci *
110bf215546Sopenharmony_ci * When the image has VK_SHARING_MODE_EXCLUSIVE, we have to work out who the
111bf215546Sopenharmony_ci * other queue family is.  It is easier when the barrier does not also define
112bf215546Sopenharmony_ci * a queue family ownership transfer (i.e., srcQueueFamilyIndex equals to
113bf215546Sopenharmony_ci * dstQueueFamilyIndex).  The other queue family must be the queue family the
114bf215546Sopenharmony_ci * command buffer was allocated for.
115bf215546Sopenharmony_ci *
116bf215546Sopenharmony_ci * When the barrier also defines a queue family ownership transfer, it is
117bf215546Sopenharmony_ci * submitted both to the source queue family to release the ownership and to
118bf215546Sopenharmony_ci * the destination queue family to acquire the ownership.  Depending on
119bf215546Sopenharmony_ci * whether the barrier transitions to or from VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
120bf215546Sopenharmony_ci * we are only interested in the ownership release or acquire respectively and
121bf215546Sopenharmony_ci * should be careful to avoid double releases/acquires.
122bf215546Sopenharmony_ci *
123bf215546Sopenharmony_ci * I haven't followed all transition paths mentally to verify the correctness.
124bf215546Sopenharmony_ci * I likely also violate some VUs or miss some cases below.  They are
125bf215546Sopenharmony_ci * hopefully fixable and are left as TODOs.
126bf215546Sopenharmony_ci */
127bf215546Sopenharmony_cistatic void
128bf215546Sopenharmony_civn_cmd_fix_image_memory_barrier(const struct vn_command_buffer *cmd,
129bf215546Sopenharmony_ci                                const VkImageMemoryBarrier *src_barrier,
130bf215546Sopenharmony_ci                                VkImageMemoryBarrier *out_barrier)
131bf215546Sopenharmony_ci{
132bf215546Sopenharmony_ci   const struct vn_image *img = vn_image_from_handle(src_barrier->image);
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_ci   *out_barrier = *src_barrier;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci   /* no fix needed */
137bf215546Sopenharmony_ci   if (out_barrier->oldLayout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR &&
138bf215546Sopenharmony_ci       out_barrier->newLayout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
139bf215546Sopenharmony_ci      return;
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci   assert(img->wsi.is_wsi);
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci   if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
144bf215546Sopenharmony_ci      return;
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci   /* prime blit src or no layout transition */
147bf215546Sopenharmony_ci   if (img->wsi.is_prime_blit_src ||
148bf215546Sopenharmony_ci       out_barrier->oldLayout == out_barrier->newLayout) {
149bf215546Sopenharmony_ci      if (out_barrier->oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
150bf215546Sopenharmony_ci         out_barrier->oldLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
151bf215546Sopenharmony_ci      if (out_barrier->newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
152bf215546Sopenharmony_ci         out_barrier->newLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
153bf215546Sopenharmony_ci      return;
154bf215546Sopenharmony_ci   }
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   if (out_barrier->oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
157bf215546Sopenharmony_ci      out_barrier->oldLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci      /* no availability operation needed */
160bf215546Sopenharmony_ci      out_barrier->srcAccessMask = 0;
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci      const uint32_t dst_qfi = out_barrier->dstQueueFamilyIndex;
163bf215546Sopenharmony_ci      if (img->sharing_mode == VK_SHARING_MODE_CONCURRENT) {
164bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
165bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
166bf215546Sopenharmony_ci      } else if (dst_qfi == out_barrier->srcQueueFamilyIndex ||
167bf215546Sopenharmony_ci                 dst_qfi == cmd->queue_family_index) {
168bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
169bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = cmd->queue_family_index;
170bf215546Sopenharmony_ci      } else {
171bf215546Sopenharmony_ci         /* The barrier also defines a queue family ownership transfer, and
172bf215546Sopenharmony_ci          * this is the one that gets submitted to the source queue family to
173bf215546Sopenharmony_ci          * release the ownership.  Skip both the transfer and the transition.
174bf215546Sopenharmony_ci          */
175bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
176bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
177bf215546Sopenharmony_ci         out_barrier->newLayout = out_barrier->oldLayout;
178bf215546Sopenharmony_ci      }
179bf215546Sopenharmony_ci   } else {
180bf215546Sopenharmony_ci      out_barrier->newLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci      /* no visibility operation needed */
183bf215546Sopenharmony_ci      out_barrier->dstAccessMask = 0;
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci      const uint32_t src_qfi = out_barrier->srcQueueFamilyIndex;
186bf215546Sopenharmony_ci      if (img->sharing_mode == VK_SHARING_MODE_CONCURRENT) {
187bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
188bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
189bf215546Sopenharmony_ci      } else if (src_qfi == out_barrier->dstQueueFamilyIndex ||
190bf215546Sopenharmony_ci                 src_qfi == cmd->queue_family_index) {
191bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = cmd->queue_family_index;
192bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
193bf215546Sopenharmony_ci      } else {
194bf215546Sopenharmony_ci         /* The barrier also defines a queue family ownership transfer, and
195bf215546Sopenharmony_ci          * this is the one that gets submitted to the destination queue
196bf215546Sopenharmony_ci          * family to acquire the ownership.  Skip both the transfer and the
197bf215546Sopenharmony_ci          * transition.
198bf215546Sopenharmony_ci          */
199bf215546Sopenharmony_ci         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
200bf215546Sopenharmony_ci         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
201bf215546Sopenharmony_ci         out_barrier->oldLayout = out_barrier->newLayout;
202bf215546Sopenharmony_ci      }
203bf215546Sopenharmony_ci   }
204bf215546Sopenharmony_ci}
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_cistatic const VkImageMemoryBarrier *
207bf215546Sopenharmony_civn_cmd_wait_events_fix_image_memory_barriers(
208bf215546Sopenharmony_ci   struct vn_command_buffer *cmd,
209bf215546Sopenharmony_ci   const VkImageMemoryBarrier *src_barriers,
210bf215546Sopenharmony_ci   uint32_t count,
211bf215546Sopenharmony_ci   uint32_t *out_transfer_count)
212bf215546Sopenharmony_ci{
213bf215546Sopenharmony_ci   *out_transfer_count = 0;
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   if (cmd->builder.render_pass ||
216bf215546Sopenharmony_ci       !vn_image_memory_barrier_has_present_src(src_barriers, count))
217bf215546Sopenharmony_ci      return src_barriers;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   VkImageMemoryBarrier *img_barriers =
220bf215546Sopenharmony_ci      vn_cmd_get_image_memory_barriers(cmd, count * 2);
221bf215546Sopenharmony_ci   if (!img_barriers) {
222bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
223bf215546Sopenharmony_ci      return src_barriers;
224bf215546Sopenharmony_ci   }
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci   /* vkCmdWaitEvents cannot be used for queue family ownership transfers.
227bf215546Sopenharmony_ci    * Nothing appears to be said about the submission order of image memory
228bf215546Sopenharmony_ci    * barriers in the same array.  We take the liberty to move queue family
229bf215546Sopenharmony_ci    * ownership transfers to the tail.
230bf215546Sopenharmony_ci    */
231bf215546Sopenharmony_ci   VkImageMemoryBarrier *transfer_barriers = img_barriers + count;
232bf215546Sopenharmony_ci   uint32_t transfer_count = 0;
233bf215546Sopenharmony_ci   uint32_t valid_count = 0;
234bf215546Sopenharmony_ci   for (uint32_t i = 0; i < count; i++) {
235bf215546Sopenharmony_ci      VkImageMemoryBarrier *img_barrier = &img_barriers[valid_count];
236bf215546Sopenharmony_ci      vn_cmd_fix_image_memory_barrier(cmd, &src_barriers[i], img_barrier);
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ci      if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
239bf215546Sopenharmony_ci         valid_count++;
240bf215546Sopenharmony_ci         continue;
241bf215546Sopenharmony_ci      }
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci      if (img_barrier->srcQueueFamilyIndex ==
244bf215546Sopenharmony_ci          img_barrier->dstQueueFamilyIndex) {
245bf215546Sopenharmony_ci         valid_count++;
246bf215546Sopenharmony_ci      } else {
247bf215546Sopenharmony_ci         transfer_barriers[transfer_count++] = *img_barrier;
248bf215546Sopenharmony_ci      }
249bf215546Sopenharmony_ci   }
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci   assert(valid_count + transfer_count == count);
252bf215546Sopenharmony_ci   if (transfer_count) {
253bf215546Sopenharmony_ci      /* copy back to the tail */
254bf215546Sopenharmony_ci      memcpy(&img_barriers[valid_count], transfer_barriers,
255bf215546Sopenharmony_ci             sizeof(*transfer_barriers) * transfer_count);
256bf215546Sopenharmony_ci      *out_transfer_count = transfer_count;
257bf215546Sopenharmony_ci   }
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci   return img_barriers;
260bf215546Sopenharmony_ci}
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_cistatic const VkImageMemoryBarrier *
263bf215546Sopenharmony_civn_cmd_pipeline_barrier_fix_image_memory_barriers(
264bf215546Sopenharmony_ci   struct vn_command_buffer *cmd,
265bf215546Sopenharmony_ci   const VkImageMemoryBarrier *src_barriers,
266bf215546Sopenharmony_ci   uint32_t count)
267bf215546Sopenharmony_ci{
268bf215546Sopenharmony_ci   if (cmd->builder.render_pass ||
269bf215546Sopenharmony_ci       !vn_image_memory_barrier_has_present_src(src_barriers, count))
270bf215546Sopenharmony_ci      return src_barriers;
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_ci   VkImageMemoryBarrier *img_barriers =
273bf215546Sopenharmony_ci      vn_cmd_get_image_memory_barriers(cmd, count);
274bf215546Sopenharmony_ci   if (!img_barriers) {
275bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
276bf215546Sopenharmony_ci      return src_barriers;
277bf215546Sopenharmony_ci   }
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci   for (uint32_t i = 0; i < count; i++) {
280bf215546Sopenharmony_ci      vn_cmd_fix_image_memory_barrier(cmd, &src_barriers[i],
281bf215546Sopenharmony_ci                                      &img_barriers[i]);
282bf215546Sopenharmony_ci   }
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_ci   return img_barriers;
285bf215546Sopenharmony_ci}
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_cistatic void
288bf215546Sopenharmony_civn_cmd_encode_memory_barriers(struct vn_command_buffer *cmd,
289bf215546Sopenharmony_ci                              VkPipelineStageFlags src_stage_mask,
290bf215546Sopenharmony_ci                              VkPipelineStageFlags dst_stage_mask,
291bf215546Sopenharmony_ci                              uint32_t buf_barrier_count,
292bf215546Sopenharmony_ci                              const VkBufferMemoryBarrier *buf_barriers,
293bf215546Sopenharmony_ci                              uint32_t img_barrier_count,
294bf215546Sopenharmony_ci                              const VkImageMemoryBarrier *img_barriers)
295bf215546Sopenharmony_ci{
296bf215546Sopenharmony_ci   const VkCommandBuffer cmd_handle = vn_command_buffer_to_handle(cmd);
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdPipelineBarrier, cmd_handle, src_stage_mask,
299bf215546Sopenharmony_ci                  dst_stage_mask, 0, 0, NULL, buf_barrier_count, buf_barriers,
300bf215546Sopenharmony_ci                  img_barrier_count, img_barriers);
301bf215546Sopenharmony_ci}
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_cistatic void
304bf215546Sopenharmony_civn_present_src_attachment_to_image_memory_barrier(
305bf215546Sopenharmony_ci   const struct vn_image *img,
306bf215546Sopenharmony_ci   const struct vn_present_src_attachment *att,
307bf215546Sopenharmony_ci   VkImageMemoryBarrier *img_barrier)
308bf215546Sopenharmony_ci{
309bf215546Sopenharmony_ci   *img_barrier = (VkImageMemoryBarrier)
310bf215546Sopenharmony_ci   {
311bf215546Sopenharmony_ci      .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
312bf215546Sopenharmony_ci      .srcAccessMask = att->src_access_mask,
313bf215546Sopenharmony_ci      .dstAccessMask = att->dst_access_mask,
314bf215546Sopenharmony_ci      .oldLayout = att->acquire ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
315bf215546Sopenharmony_ci                                : VN_PRESENT_SRC_INTERNAL_LAYOUT,
316bf215546Sopenharmony_ci      .newLayout = att->acquire ? VN_PRESENT_SRC_INTERNAL_LAYOUT
317bf215546Sopenharmony_ci                                : VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
318bf215546Sopenharmony_ci      .image = vn_image_to_handle((struct vn_image *)img),
319bf215546Sopenharmony_ci      .subresourceRange = {
320bf215546Sopenharmony_ci         .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
321bf215546Sopenharmony_ci         .levelCount = 1,
322bf215546Sopenharmony_ci         .layerCount = 1,
323bf215546Sopenharmony_ci      },
324bf215546Sopenharmony_ci   };
325bf215546Sopenharmony_ci}
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_cistatic void
328bf215546Sopenharmony_civn_cmd_transfer_present_src_images(
329bf215546Sopenharmony_ci   struct vn_command_buffer *cmd,
330bf215546Sopenharmony_ci   const struct vn_image *const *images,
331bf215546Sopenharmony_ci   const struct vn_present_src_attachment *atts,
332bf215546Sopenharmony_ci   uint32_t count)
333bf215546Sopenharmony_ci{
334bf215546Sopenharmony_ci   VkImageMemoryBarrier *img_barriers =
335bf215546Sopenharmony_ci      vn_cmd_get_image_memory_barriers(cmd, count);
336bf215546Sopenharmony_ci   if (!img_barriers) {
337bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
338bf215546Sopenharmony_ci      return;
339bf215546Sopenharmony_ci   }
340bf215546Sopenharmony_ci
341bf215546Sopenharmony_ci   VkPipelineStageFlags src_stage_mask = 0;
342bf215546Sopenharmony_ci   VkPipelineStageFlags dst_stage_mask = 0;
343bf215546Sopenharmony_ci   for (uint32_t i = 0; i < count; i++) {
344bf215546Sopenharmony_ci      src_stage_mask |= atts[i].src_stage_mask;
345bf215546Sopenharmony_ci      dst_stage_mask |= atts[i].dst_stage_mask;
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci      vn_present_src_attachment_to_image_memory_barrier(images[i], &atts[i],
348bf215546Sopenharmony_ci                                                        &img_barriers[i]);
349bf215546Sopenharmony_ci      vn_cmd_fix_image_memory_barrier(cmd, &img_barriers[i],
350bf215546Sopenharmony_ci                                      &img_barriers[i]);
351bf215546Sopenharmony_ci   }
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_ci   if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
354bf215546Sopenharmony_ci      return;
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   vn_cmd_encode_memory_barriers(cmd, src_stage_mask, dst_stage_mask, 0, NULL,
357bf215546Sopenharmony_ci                                 count, img_barriers);
358bf215546Sopenharmony_ci}
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_cistatic void
361bf215546Sopenharmony_civn_cmd_begin_render_pass(struct vn_command_buffer *cmd,
362bf215546Sopenharmony_ci                         const struct vn_render_pass *pass,
363bf215546Sopenharmony_ci                         const struct vn_framebuffer *fb,
364bf215546Sopenharmony_ci                         const VkRenderPassBeginInfo *begin_info)
365bf215546Sopenharmony_ci{
366bf215546Sopenharmony_ci   cmd->builder.render_pass = pass;
367bf215546Sopenharmony_ci   cmd->builder.framebuffer = fb;
368bf215546Sopenharmony_ci
369bf215546Sopenharmony_ci   if (!pass->present_src_count ||
370bf215546Sopenharmony_ci       cmd->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY)
371bf215546Sopenharmony_ci      return;
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci   /* find fb attachments */
374bf215546Sopenharmony_ci   const VkImageView *views;
375bf215546Sopenharmony_ci   ASSERTED uint32_t view_count;
376bf215546Sopenharmony_ci   if (fb->image_view_count) {
377bf215546Sopenharmony_ci      views = fb->image_views;
378bf215546Sopenharmony_ci      view_count = fb->image_view_count;
379bf215546Sopenharmony_ci   } else {
380bf215546Sopenharmony_ci      const VkRenderPassAttachmentBeginInfo *imageless_info =
381bf215546Sopenharmony_ci         vk_find_struct_const(begin_info->pNext,
382bf215546Sopenharmony_ci                              RENDER_PASS_ATTACHMENT_BEGIN_INFO);
383bf215546Sopenharmony_ci      assert(imageless_info);
384bf215546Sopenharmony_ci      views = imageless_info->pAttachments;
385bf215546Sopenharmony_ci      view_count = imageless_info->attachmentCount;
386bf215546Sopenharmony_ci   }
387bf215546Sopenharmony_ci
388bf215546Sopenharmony_ci   const struct vn_image **images =
389bf215546Sopenharmony_ci      vk_alloc(&cmd->allocator, sizeof(*images) * pass->present_src_count,
390bf215546Sopenharmony_ci               VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
391bf215546Sopenharmony_ci   if (!images) {
392bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
393bf215546Sopenharmony_ci      return;
394bf215546Sopenharmony_ci   }
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci   for (uint32_t i = 0; i < pass->present_src_count; i++) {
397bf215546Sopenharmony_ci      const uint32_t index = pass->present_src_attachments[i].index;
398bf215546Sopenharmony_ci      assert(index < view_count);
399bf215546Sopenharmony_ci      images[i] = vn_image_view_from_handle(views[index])->image;
400bf215546Sopenharmony_ci   }
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci   if (pass->acquire_count) {
403bf215546Sopenharmony_ci      vn_cmd_transfer_present_src_images(
404bf215546Sopenharmony_ci         cmd, images, pass->present_src_attachments, pass->acquire_count);
405bf215546Sopenharmony_ci   }
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_ci   cmd->builder.present_src_images = images;
408bf215546Sopenharmony_ci}
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_cistatic void
411bf215546Sopenharmony_civn_cmd_end_render_pass(struct vn_command_buffer *cmd)
412bf215546Sopenharmony_ci{
413bf215546Sopenharmony_ci   const struct vn_render_pass *pass = cmd->builder.render_pass;
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci   cmd->builder.render_pass = NULL;
416bf215546Sopenharmony_ci   cmd->builder.framebuffer = NULL;
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci   if (!pass->present_src_count || !cmd->builder.present_src_images)
419bf215546Sopenharmony_ci      return;
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   const struct vn_image **images = cmd->builder.present_src_images;
422bf215546Sopenharmony_ci   cmd->builder.present_src_images = NULL;
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci   if (pass->release_count) {
425bf215546Sopenharmony_ci      vn_cmd_transfer_present_src_images(
426bf215546Sopenharmony_ci         cmd, images + pass->acquire_count,
427bf215546Sopenharmony_ci         pass->present_src_attachments + pass->acquire_count,
428bf215546Sopenharmony_ci         pass->release_count);
429bf215546Sopenharmony_ci   }
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   vk_free(&cmd->allocator, images);
432bf215546Sopenharmony_ci}
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci/* command pool commands */
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ciVkResult
437bf215546Sopenharmony_civn_CreateCommandPool(VkDevice device,
438bf215546Sopenharmony_ci                     const VkCommandPoolCreateInfo *pCreateInfo,
439bf215546Sopenharmony_ci                     const VkAllocationCallbacks *pAllocator,
440bf215546Sopenharmony_ci                     VkCommandPool *pCommandPool)
441bf215546Sopenharmony_ci{
442bf215546Sopenharmony_ci   VN_TRACE_FUNC();
443bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
444bf215546Sopenharmony_ci   const VkAllocationCallbacks *alloc =
445bf215546Sopenharmony_ci      pAllocator ? pAllocator : &dev->base.base.alloc;
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_ci   struct vn_command_pool *pool =
448bf215546Sopenharmony_ci      vk_zalloc(alloc, sizeof(*pool), VN_DEFAULT_ALIGN,
449bf215546Sopenharmony_ci                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
450bf215546Sopenharmony_ci   if (!pool)
451bf215546Sopenharmony_ci      return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   vn_object_base_init(&pool->base, VK_OBJECT_TYPE_COMMAND_POOL, &dev->base);
454bf215546Sopenharmony_ci
455bf215546Sopenharmony_ci   pool->allocator = *alloc;
456bf215546Sopenharmony_ci   pool->queue_family_index = pCreateInfo->queueFamilyIndex;
457bf215546Sopenharmony_ci   list_inithead(&pool->command_buffers);
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci   VkCommandPool pool_handle = vn_command_pool_to_handle(pool);
460bf215546Sopenharmony_ci   vn_async_vkCreateCommandPool(dev->instance, device, pCreateInfo, NULL,
461bf215546Sopenharmony_ci                                &pool_handle);
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci   *pCommandPool = pool_handle;
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   return VK_SUCCESS;
466bf215546Sopenharmony_ci}
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_civoid
469bf215546Sopenharmony_civn_DestroyCommandPool(VkDevice device,
470bf215546Sopenharmony_ci                      VkCommandPool commandPool,
471bf215546Sopenharmony_ci                      const VkAllocationCallbacks *pAllocator)
472bf215546Sopenharmony_ci{
473bf215546Sopenharmony_ci   VN_TRACE_FUNC();
474bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
475bf215546Sopenharmony_ci   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
476bf215546Sopenharmony_ci   const VkAllocationCallbacks *alloc;
477bf215546Sopenharmony_ci
478bf215546Sopenharmony_ci   if (!pool)
479bf215546Sopenharmony_ci      return;
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci   alloc = pAllocator ? pAllocator : &pool->allocator;
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_ci   /* We must emit vkDestroyCommandPool before freeing the command buffers in
484bf215546Sopenharmony_ci    * pool->command_buffers.  Otherwise, another thread might reuse their
485bf215546Sopenharmony_ci    * object ids while they still refer to the command buffers in the
486bf215546Sopenharmony_ci    * renderer.
487bf215546Sopenharmony_ci    */
488bf215546Sopenharmony_ci   vn_async_vkDestroyCommandPool(dev->instance, device, commandPool, NULL);
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci   list_for_each_entry_safe(struct vn_command_buffer, cmd,
491bf215546Sopenharmony_ci                            &pool->command_buffers, head) {
492bf215546Sopenharmony_ci      vn_cs_encoder_fini(&cmd->cs);
493bf215546Sopenharmony_ci      vn_object_base_fini(&cmd->base);
494bf215546Sopenharmony_ci      vk_free(alloc, cmd);
495bf215546Sopenharmony_ci   }
496bf215546Sopenharmony_ci
497bf215546Sopenharmony_ci   vn_object_base_fini(&pool->base);
498bf215546Sopenharmony_ci   vk_free(alloc, pool);
499bf215546Sopenharmony_ci}
500bf215546Sopenharmony_ci
501bf215546Sopenharmony_ciVkResult
502bf215546Sopenharmony_civn_ResetCommandPool(VkDevice device,
503bf215546Sopenharmony_ci                    VkCommandPool commandPool,
504bf215546Sopenharmony_ci                    VkCommandPoolResetFlags flags)
505bf215546Sopenharmony_ci{
506bf215546Sopenharmony_ci   VN_TRACE_FUNC();
507bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
508bf215546Sopenharmony_ci   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
509bf215546Sopenharmony_ci
510bf215546Sopenharmony_ci   list_for_each_entry_safe(struct vn_command_buffer, cmd,
511bf215546Sopenharmony_ci                            &pool->command_buffers, head) {
512bf215546Sopenharmony_ci      vn_cs_encoder_reset(&cmd->cs);
513bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
514bf215546Sopenharmony_ci   }
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci   vn_async_vkResetCommandPool(dev->instance, device, commandPool, flags);
517bf215546Sopenharmony_ci
518bf215546Sopenharmony_ci   return VK_SUCCESS;
519bf215546Sopenharmony_ci}
520bf215546Sopenharmony_ci
521bf215546Sopenharmony_civoid
522bf215546Sopenharmony_civn_TrimCommandPool(VkDevice device,
523bf215546Sopenharmony_ci                   VkCommandPool commandPool,
524bf215546Sopenharmony_ci                   VkCommandPoolTrimFlags flags)
525bf215546Sopenharmony_ci{
526bf215546Sopenharmony_ci   VN_TRACE_FUNC();
527bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
528bf215546Sopenharmony_ci
529bf215546Sopenharmony_ci   vn_async_vkTrimCommandPool(dev->instance, device, commandPool, flags);
530bf215546Sopenharmony_ci}
531bf215546Sopenharmony_ci
532bf215546Sopenharmony_ci/* command buffer commands */
533bf215546Sopenharmony_ci
534bf215546Sopenharmony_ciVkResult
535bf215546Sopenharmony_civn_AllocateCommandBuffers(VkDevice device,
536bf215546Sopenharmony_ci                          const VkCommandBufferAllocateInfo *pAllocateInfo,
537bf215546Sopenharmony_ci                          VkCommandBuffer *pCommandBuffers)
538bf215546Sopenharmony_ci{
539bf215546Sopenharmony_ci   VN_TRACE_FUNC();
540bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
541bf215546Sopenharmony_ci   struct vn_command_pool *pool =
542bf215546Sopenharmony_ci      vn_command_pool_from_handle(pAllocateInfo->commandPool);
543bf215546Sopenharmony_ci   const VkAllocationCallbacks *alloc = &pool->allocator;
544bf215546Sopenharmony_ci
545bf215546Sopenharmony_ci   for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
546bf215546Sopenharmony_ci      struct vn_command_buffer *cmd =
547bf215546Sopenharmony_ci         vk_zalloc(alloc, sizeof(*cmd), VN_DEFAULT_ALIGN,
548bf215546Sopenharmony_ci                   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
549bf215546Sopenharmony_ci      if (!cmd) {
550bf215546Sopenharmony_ci         for (uint32_t j = 0; j < i; j++) {
551bf215546Sopenharmony_ci            cmd = vn_command_buffer_from_handle(pCommandBuffers[j]);
552bf215546Sopenharmony_ci            vn_cs_encoder_fini(&cmd->cs);
553bf215546Sopenharmony_ci            list_del(&cmd->head);
554bf215546Sopenharmony_ci            vn_object_base_fini(&cmd->base);
555bf215546Sopenharmony_ci            vk_free(alloc, cmd);
556bf215546Sopenharmony_ci         }
557bf215546Sopenharmony_ci         memset(pCommandBuffers, 0,
558bf215546Sopenharmony_ci                sizeof(*pCommandBuffers) * pAllocateInfo->commandBufferCount);
559bf215546Sopenharmony_ci         return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
560bf215546Sopenharmony_ci      }
561bf215546Sopenharmony_ci
562bf215546Sopenharmony_ci      vn_object_base_init(&cmd->base, VK_OBJECT_TYPE_COMMAND_BUFFER,
563bf215546Sopenharmony_ci                          &dev->base);
564bf215546Sopenharmony_ci      cmd->device = dev;
565bf215546Sopenharmony_ci      cmd->allocator = pool->allocator;
566bf215546Sopenharmony_ci      cmd->level = pAllocateInfo->level;
567bf215546Sopenharmony_ci      cmd->queue_family_index = pool->queue_family_index;
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ci      list_addtail(&cmd->head, &pool->command_buffers);
570bf215546Sopenharmony_ci
571bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
572bf215546Sopenharmony_ci      vn_cs_encoder_init(&cmd->cs, dev->instance,
573bf215546Sopenharmony_ci                         VN_CS_ENCODER_STORAGE_SHMEM_POOL, 16 * 1024);
574bf215546Sopenharmony_ci
575bf215546Sopenharmony_ci      VkCommandBuffer cmd_handle = vn_command_buffer_to_handle(cmd);
576bf215546Sopenharmony_ci      pCommandBuffers[i] = cmd_handle;
577bf215546Sopenharmony_ci   }
578bf215546Sopenharmony_ci
579bf215546Sopenharmony_ci   vn_async_vkAllocateCommandBuffers(dev->instance, device, pAllocateInfo,
580bf215546Sopenharmony_ci                                     pCommandBuffers);
581bf215546Sopenharmony_ci
582bf215546Sopenharmony_ci   return VK_SUCCESS;
583bf215546Sopenharmony_ci}
584bf215546Sopenharmony_ci
585bf215546Sopenharmony_civoid
586bf215546Sopenharmony_civn_FreeCommandBuffers(VkDevice device,
587bf215546Sopenharmony_ci                      VkCommandPool commandPool,
588bf215546Sopenharmony_ci                      uint32_t commandBufferCount,
589bf215546Sopenharmony_ci                      const VkCommandBuffer *pCommandBuffers)
590bf215546Sopenharmony_ci{
591bf215546Sopenharmony_ci   VN_TRACE_FUNC();
592bf215546Sopenharmony_ci   struct vn_device *dev = vn_device_from_handle(device);
593bf215546Sopenharmony_ci   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
594bf215546Sopenharmony_ci   const VkAllocationCallbacks *alloc = &pool->allocator;
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci   vn_async_vkFreeCommandBuffers(dev->instance, device, commandPool,
597bf215546Sopenharmony_ci                                 commandBufferCount, pCommandBuffers);
598bf215546Sopenharmony_ci
599bf215546Sopenharmony_ci   for (uint32_t i = 0; i < commandBufferCount; i++) {
600bf215546Sopenharmony_ci      struct vn_command_buffer *cmd =
601bf215546Sopenharmony_ci         vn_command_buffer_from_handle(pCommandBuffers[i]);
602bf215546Sopenharmony_ci
603bf215546Sopenharmony_ci      if (!cmd)
604bf215546Sopenharmony_ci         continue;
605bf215546Sopenharmony_ci
606bf215546Sopenharmony_ci      if (cmd->builder.image_barriers)
607bf215546Sopenharmony_ci         vk_free(alloc, cmd->builder.image_barriers);
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci      vn_cs_encoder_fini(&cmd->cs);
610bf215546Sopenharmony_ci      list_del(&cmd->head);
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_ci      vn_object_base_fini(&cmd->base);
613bf215546Sopenharmony_ci      vk_free(alloc, cmd);
614bf215546Sopenharmony_ci   }
615bf215546Sopenharmony_ci}
616bf215546Sopenharmony_ci
617bf215546Sopenharmony_ciVkResult
618bf215546Sopenharmony_civn_ResetCommandBuffer(VkCommandBuffer commandBuffer,
619bf215546Sopenharmony_ci                      VkCommandBufferResetFlags flags)
620bf215546Sopenharmony_ci{
621bf215546Sopenharmony_ci   VN_TRACE_FUNC();
622bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
623bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
624bf215546Sopenharmony_ci
625bf215546Sopenharmony_ci   vn_cs_encoder_reset(&cmd->cs);
626bf215546Sopenharmony_ci   cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
627bf215546Sopenharmony_ci   cmd->draw_cmd_batched = 0;
628bf215546Sopenharmony_ci
629bf215546Sopenharmony_ci   vn_async_vkResetCommandBuffer(cmd->device->instance, commandBuffer, flags);
630bf215546Sopenharmony_ci
631bf215546Sopenharmony_ci   return VK_SUCCESS;
632bf215546Sopenharmony_ci}
633bf215546Sopenharmony_ci
634bf215546Sopenharmony_cistruct vn_command_buffer_begin_info {
635bf215546Sopenharmony_ci   VkCommandBufferBeginInfo begin;
636bf215546Sopenharmony_ci   VkCommandBufferInheritanceInfo inheritance;
637bf215546Sopenharmony_ci   VkCommandBufferInheritanceConditionalRenderingInfoEXT conditional_rendering;
638bf215546Sopenharmony_ci
639bf215546Sopenharmony_ci   bool has_inherited_pass;
640bf215546Sopenharmony_ci};
641bf215546Sopenharmony_ci
642bf215546Sopenharmony_cistatic const VkCommandBufferBeginInfo *
643bf215546Sopenharmony_civn_fix_command_buffer_begin_info(struct vn_command_buffer *cmd,
644bf215546Sopenharmony_ci                                 const VkCommandBufferBeginInfo *begin_info,
645bf215546Sopenharmony_ci                                 struct vn_command_buffer_begin_info *local)
646bf215546Sopenharmony_ci{
647bf215546Sopenharmony_ci   local->has_inherited_pass = false;
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_ci   if (!begin_info->pInheritanceInfo)
650bf215546Sopenharmony_ci      return begin_info;
651bf215546Sopenharmony_ci
652bf215546Sopenharmony_ci   const bool is_cmd_secondary =
653bf215546Sopenharmony_ci      cmd->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY;
654bf215546Sopenharmony_ci   const bool has_continue =
655bf215546Sopenharmony_ci      begin_info->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
656bf215546Sopenharmony_ci   const bool has_renderpass =
657bf215546Sopenharmony_ci      is_cmd_secondary &&
658bf215546Sopenharmony_ci      begin_info->pInheritanceInfo->renderPass != VK_NULL_HANDLE;
659bf215546Sopenharmony_ci
660bf215546Sopenharmony_ci   /* Can early-return if dynamic rendering is used and no structures need to
661bf215546Sopenharmony_ci    * be dropped from the pNext chain of VkCommandBufferInheritanceInfo.
662bf215546Sopenharmony_ci    */
663bf215546Sopenharmony_ci   if (is_cmd_secondary && has_continue && !has_renderpass)
664bf215546Sopenharmony_ci      return begin_info;
665bf215546Sopenharmony_ci
666bf215546Sopenharmony_ci   local->begin = *begin_info;
667bf215546Sopenharmony_ci
668bf215546Sopenharmony_ci   if (!is_cmd_secondary) {
669bf215546Sopenharmony_ci      local->begin.pInheritanceInfo = NULL;
670bf215546Sopenharmony_ci      return &local->begin;
671bf215546Sopenharmony_ci   }
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_ci   local->inheritance = *begin_info->pInheritanceInfo;
674bf215546Sopenharmony_ci   local->begin.pInheritanceInfo = &local->inheritance;
675bf215546Sopenharmony_ci
676bf215546Sopenharmony_ci   if (!has_continue) {
677bf215546Sopenharmony_ci      local->inheritance.framebuffer = VK_NULL_HANDLE;
678bf215546Sopenharmony_ci      local->inheritance.renderPass = VK_NULL_HANDLE;
679bf215546Sopenharmony_ci      local->inheritance.subpass = 0;
680bf215546Sopenharmony_ci   } else {
681bf215546Sopenharmony_ci      /* With early-returns above, it must be an inherited pass. */
682bf215546Sopenharmony_ci      local->has_inherited_pass = true;
683bf215546Sopenharmony_ci   }
684bf215546Sopenharmony_ci
685bf215546Sopenharmony_ci   /* Per spec, about VkCommandBufferInheritanceRenderingInfo:
686bf215546Sopenharmony_ci    *
687bf215546Sopenharmony_ci    * If VkCommandBufferInheritanceInfo::renderPass is not VK_NULL_HANDLE, or
688bf215546Sopenharmony_ci    * VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT is not specified in
689bf215546Sopenharmony_ci    * VkCommandBufferBeginInfo::flags, parameters of this structure are
690bf215546Sopenharmony_ci    * ignored.
691bf215546Sopenharmony_ci    */
692bf215546Sopenharmony_ci   VkBaseOutStructure *head = NULL;
693bf215546Sopenharmony_ci   VkBaseOutStructure *tail = NULL;
694bf215546Sopenharmony_ci   vk_foreach_struct_const(src, local->inheritance.pNext) {
695bf215546Sopenharmony_ci      void *pnext = NULL;
696bf215546Sopenharmony_ci      switch (src->sType) {
697bf215546Sopenharmony_ci      case VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_CONDITIONAL_RENDERING_INFO_EXT:
698bf215546Sopenharmony_ci         memcpy(
699bf215546Sopenharmony_ci            &local->conditional_rendering, src,
700bf215546Sopenharmony_ci            sizeof(VkCommandBufferInheritanceConditionalRenderingInfoEXT));
701bf215546Sopenharmony_ci         pnext = &local->conditional_rendering;
702bf215546Sopenharmony_ci         break;
703bf215546Sopenharmony_ci      case VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_RENDERING_INFO:
704bf215546Sopenharmony_ci      default:
705bf215546Sopenharmony_ci         break;
706bf215546Sopenharmony_ci      }
707bf215546Sopenharmony_ci
708bf215546Sopenharmony_ci      if (pnext) {
709bf215546Sopenharmony_ci         if (!head)
710bf215546Sopenharmony_ci            head = pnext;
711bf215546Sopenharmony_ci         else
712bf215546Sopenharmony_ci            tail->pNext = pnext;
713bf215546Sopenharmony_ci
714bf215546Sopenharmony_ci         tail = pnext;
715bf215546Sopenharmony_ci      }
716bf215546Sopenharmony_ci   }
717bf215546Sopenharmony_ci   local->inheritance.pNext = head;
718bf215546Sopenharmony_ci
719bf215546Sopenharmony_ci   return &local->begin;
720bf215546Sopenharmony_ci}
721bf215546Sopenharmony_ci
722bf215546Sopenharmony_ciVkResult
723bf215546Sopenharmony_civn_BeginCommandBuffer(VkCommandBuffer commandBuffer,
724bf215546Sopenharmony_ci                      const VkCommandBufferBeginInfo *pBeginInfo)
725bf215546Sopenharmony_ci{
726bf215546Sopenharmony_ci   VN_TRACE_FUNC();
727bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
728bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
729bf215546Sopenharmony_ci   struct vn_instance *instance = cmd->device->instance;
730bf215546Sopenharmony_ci   size_t cmd_size;
731bf215546Sopenharmony_ci
732bf215546Sopenharmony_ci   vn_cs_encoder_reset(&cmd->cs);
733bf215546Sopenharmony_ci   cmd->draw_cmd_batched = 0;
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_ci   struct vn_command_buffer_begin_info local_begin_info;
736bf215546Sopenharmony_ci   pBeginInfo =
737bf215546Sopenharmony_ci      vn_fix_command_buffer_begin_info(cmd, pBeginInfo, &local_begin_info);
738bf215546Sopenharmony_ci
739bf215546Sopenharmony_ci   cmd_size = vn_sizeof_vkBeginCommandBuffer(commandBuffer, pBeginInfo);
740bf215546Sopenharmony_ci   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size)) {
741bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
742bf215546Sopenharmony_ci      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
743bf215546Sopenharmony_ci   }
744bf215546Sopenharmony_ci
745bf215546Sopenharmony_ci   vn_encode_vkBeginCommandBuffer(&cmd->cs, 0, commandBuffer, pBeginInfo);
746bf215546Sopenharmony_ci
747bf215546Sopenharmony_ci   cmd->state = VN_COMMAND_BUFFER_STATE_RECORDING;
748bf215546Sopenharmony_ci
749bf215546Sopenharmony_ci   if (local_begin_info.has_inherited_pass) {
750bf215546Sopenharmony_ci      const VkCommandBufferInheritanceInfo *inheritance_info =
751bf215546Sopenharmony_ci         pBeginInfo->pInheritanceInfo;
752bf215546Sopenharmony_ci      vn_cmd_begin_render_pass(
753bf215546Sopenharmony_ci         cmd, vn_render_pass_from_handle(inheritance_info->renderPass),
754bf215546Sopenharmony_ci         vn_framebuffer_from_handle(inheritance_info->framebuffer), NULL);
755bf215546Sopenharmony_ci   }
756bf215546Sopenharmony_ci
757bf215546Sopenharmony_ci   return VK_SUCCESS;
758bf215546Sopenharmony_ci}
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_cistatic void
761bf215546Sopenharmony_civn_cmd_submit(struct vn_command_buffer *cmd)
762bf215546Sopenharmony_ci{
763bf215546Sopenharmony_ci   struct vn_instance *instance = cmd->device->instance;
764bf215546Sopenharmony_ci
765bf215546Sopenharmony_ci   if (cmd->state != VN_COMMAND_BUFFER_STATE_RECORDING)
766bf215546Sopenharmony_ci      return;
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci   vn_cs_encoder_commit(&cmd->cs);
769bf215546Sopenharmony_ci   if (vn_cs_encoder_get_fatal(&cmd->cs)) {
770bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
771bf215546Sopenharmony_ci      vn_cs_encoder_reset(&cmd->cs);
772bf215546Sopenharmony_ci      return;
773bf215546Sopenharmony_ci   }
774bf215546Sopenharmony_ci
775bf215546Sopenharmony_ci   if (unlikely(!instance->renderer->info.supports_blob_id_0))
776bf215546Sopenharmony_ci      vn_instance_wait_roundtrip(instance, cmd->cs.current_buffer_roundtrip);
777bf215546Sopenharmony_ci
778bf215546Sopenharmony_ci   if (vn_instance_ring_submit(instance, &cmd->cs) != VK_SUCCESS) {
779bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
780bf215546Sopenharmony_ci      return;
781bf215546Sopenharmony_ci   }
782bf215546Sopenharmony_ci
783bf215546Sopenharmony_ci   vn_cs_encoder_reset(&cmd->cs);
784bf215546Sopenharmony_ci   cmd->draw_cmd_batched = 0;
785bf215546Sopenharmony_ci}
786bf215546Sopenharmony_ci
787bf215546Sopenharmony_cistatic inline void
788bf215546Sopenharmony_civn_cmd_count_draw_and_submit_on_batch_limit(struct vn_command_buffer *cmd)
789bf215546Sopenharmony_ci{
790bf215546Sopenharmony_ci   if (++cmd->draw_cmd_batched >= vn_env.draw_cmd_batch_limit)
791bf215546Sopenharmony_ci      vn_cmd_submit(cmd);
792bf215546Sopenharmony_ci}
793bf215546Sopenharmony_ci
794bf215546Sopenharmony_ciVkResult
795bf215546Sopenharmony_civn_EndCommandBuffer(VkCommandBuffer commandBuffer)
796bf215546Sopenharmony_ci{
797bf215546Sopenharmony_ci   VN_TRACE_FUNC();
798bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
799bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
800bf215546Sopenharmony_ci   struct vn_instance *instance = cmd->device->instance;
801bf215546Sopenharmony_ci   size_t cmd_size;
802bf215546Sopenharmony_ci
803bf215546Sopenharmony_ci   if (cmd->state != VN_COMMAND_BUFFER_STATE_RECORDING)
804bf215546Sopenharmony_ci      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
805bf215546Sopenharmony_ci
806bf215546Sopenharmony_ci   cmd_size = vn_sizeof_vkEndCommandBuffer(commandBuffer);
807bf215546Sopenharmony_ci   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size)) {
808bf215546Sopenharmony_ci      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
809bf215546Sopenharmony_ci      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
810bf215546Sopenharmony_ci   }
811bf215546Sopenharmony_ci
812bf215546Sopenharmony_ci   vn_encode_vkEndCommandBuffer(&cmd->cs, 0, commandBuffer);
813bf215546Sopenharmony_ci
814bf215546Sopenharmony_ci   vn_cmd_submit(cmd);
815bf215546Sopenharmony_ci   if (cmd->state == VN_COMMAND_BUFFER_STATE_INVALID)
816bf215546Sopenharmony_ci      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_ci   cmd->state = VN_COMMAND_BUFFER_STATE_EXECUTABLE;
819bf215546Sopenharmony_ci
820bf215546Sopenharmony_ci   return VK_SUCCESS;
821bf215546Sopenharmony_ci}
822bf215546Sopenharmony_ci
823bf215546Sopenharmony_civoid
824bf215546Sopenharmony_civn_CmdBindPipeline(VkCommandBuffer commandBuffer,
825bf215546Sopenharmony_ci                   VkPipelineBindPoint pipelineBindPoint,
826bf215546Sopenharmony_ci                   VkPipeline pipeline)
827bf215546Sopenharmony_ci{
828bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindPipeline, commandBuffer, pipelineBindPoint,
829bf215546Sopenharmony_ci                  pipeline);
830bf215546Sopenharmony_ci}
831bf215546Sopenharmony_ci
832bf215546Sopenharmony_civoid
833bf215546Sopenharmony_civn_CmdSetViewport(VkCommandBuffer commandBuffer,
834bf215546Sopenharmony_ci                  uint32_t firstViewport,
835bf215546Sopenharmony_ci                  uint32_t viewportCount,
836bf215546Sopenharmony_ci                  const VkViewport *pViewports)
837bf215546Sopenharmony_ci{
838bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetViewport, commandBuffer, firstViewport,
839bf215546Sopenharmony_ci                  viewportCount, pViewports);
840bf215546Sopenharmony_ci}
841bf215546Sopenharmony_ci
842bf215546Sopenharmony_civoid
843bf215546Sopenharmony_civn_CmdSetScissor(VkCommandBuffer commandBuffer,
844bf215546Sopenharmony_ci                 uint32_t firstScissor,
845bf215546Sopenharmony_ci                 uint32_t scissorCount,
846bf215546Sopenharmony_ci                 const VkRect2D *pScissors)
847bf215546Sopenharmony_ci{
848bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetScissor, commandBuffer, firstScissor, scissorCount,
849bf215546Sopenharmony_ci                  pScissors);
850bf215546Sopenharmony_ci}
851bf215546Sopenharmony_ci
852bf215546Sopenharmony_civoid
853bf215546Sopenharmony_civn_CmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
854bf215546Sopenharmony_ci{
855bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetLineWidth, commandBuffer, lineWidth);
856bf215546Sopenharmony_ci}
857bf215546Sopenharmony_ci
858bf215546Sopenharmony_civoid
859bf215546Sopenharmony_civn_CmdSetDepthBias(VkCommandBuffer commandBuffer,
860bf215546Sopenharmony_ci                   float depthBiasConstantFactor,
861bf215546Sopenharmony_ci                   float depthBiasClamp,
862bf215546Sopenharmony_ci                   float depthBiasSlopeFactor)
863bf215546Sopenharmony_ci{
864bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthBias, commandBuffer, depthBiasConstantFactor,
865bf215546Sopenharmony_ci                  depthBiasClamp, depthBiasSlopeFactor);
866bf215546Sopenharmony_ci}
867bf215546Sopenharmony_ci
868bf215546Sopenharmony_civoid
869bf215546Sopenharmony_civn_CmdSetBlendConstants(VkCommandBuffer commandBuffer,
870bf215546Sopenharmony_ci                        const float blendConstants[4])
871bf215546Sopenharmony_ci{
872bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetBlendConstants, commandBuffer, blendConstants);
873bf215546Sopenharmony_ci}
874bf215546Sopenharmony_ci
875bf215546Sopenharmony_civoid
876bf215546Sopenharmony_civn_CmdSetDepthBounds(VkCommandBuffer commandBuffer,
877bf215546Sopenharmony_ci                     float minDepthBounds,
878bf215546Sopenharmony_ci                     float maxDepthBounds)
879bf215546Sopenharmony_ci{
880bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthBounds, commandBuffer, minDepthBounds,
881bf215546Sopenharmony_ci                  maxDepthBounds);
882bf215546Sopenharmony_ci}
883bf215546Sopenharmony_ci
884bf215546Sopenharmony_civoid
885bf215546Sopenharmony_civn_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer,
886bf215546Sopenharmony_ci                            VkStencilFaceFlags faceMask,
887bf215546Sopenharmony_ci                            uint32_t compareMask)
888bf215546Sopenharmony_ci{
889bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetStencilCompareMask, commandBuffer, faceMask,
890bf215546Sopenharmony_ci                  compareMask);
891bf215546Sopenharmony_ci}
892bf215546Sopenharmony_ci
893bf215546Sopenharmony_civoid
894bf215546Sopenharmony_civn_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer,
895bf215546Sopenharmony_ci                          VkStencilFaceFlags faceMask,
896bf215546Sopenharmony_ci                          uint32_t writeMask)
897bf215546Sopenharmony_ci{
898bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetStencilWriteMask, commandBuffer, faceMask,
899bf215546Sopenharmony_ci                  writeMask);
900bf215546Sopenharmony_ci}
901bf215546Sopenharmony_ci
902bf215546Sopenharmony_civoid
903bf215546Sopenharmony_civn_CmdSetStencilReference(VkCommandBuffer commandBuffer,
904bf215546Sopenharmony_ci                          VkStencilFaceFlags faceMask,
905bf215546Sopenharmony_ci                          uint32_t reference)
906bf215546Sopenharmony_ci{
907bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetStencilReference, commandBuffer, faceMask,
908bf215546Sopenharmony_ci                  reference);
909bf215546Sopenharmony_ci}
910bf215546Sopenharmony_ci
911bf215546Sopenharmony_civoid
912bf215546Sopenharmony_civn_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
913bf215546Sopenharmony_ci                         VkPipelineBindPoint pipelineBindPoint,
914bf215546Sopenharmony_ci                         VkPipelineLayout layout,
915bf215546Sopenharmony_ci                         uint32_t firstSet,
916bf215546Sopenharmony_ci                         uint32_t descriptorSetCount,
917bf215546Sopenharmony_ci                         const VkDescriptorSet *pDescriptorSets,
918bf215546Sopenharmony_ci                         uint32_t dynamicOffsetCount,
919bf215546Sopenharmony_ci                         const uint32_t *pDynamicOffsets)
920bf215546Sopenharmony_ci{
921bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindDescriptorSets, commandBuffer, pipelineBindPoint,
922bf215546Sopenharmony_ci                  layout, firstSet, descriptorSetCount, pDescriptorSets,
923bf215546Sopenharmony_ci                  dynamicOffsetCount, pDynamicOffsets);
924bf215546Sopenharmony_ci}
925bf215546Sopenharmony_ci
926bf215546Sopenharmony_civoid
927bf215546Sopenharmony_civn_CmdBindIndexBuffer(VkCommandBuffer commandBuffer,
928bf215546Sopenharmony_ci                      VkBuffer buffer,
929bf215546Sopenharmony_ci                      VkDeviceSize offset,
930bf215546Sopenharmony_ci                      VkIndexType indexType)
931bf215546Sopenharmony_ci{
932bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindIndexBuffer, commandBuffer, buffer, offset,
933bf215546Sopenharmony_ci                  indexType);
934bf215546Sopenharmony_ci}
935bf215546Sopenharmony_ci
936bf215546Sopenharmony_civoid
937bf215546Sopenharmony_civn_CmdBindVertexBuffers(VkCommandBuffer commandBuffer,
938bf215546Sopenharmony_ci                        uint32_t firstBinding,
939bf215546Sopenharmony_ci                        uint32_t bindingCount,
940bf215546Sopenharmony_ci                        const VkBuffer *pBuffers,
941bf215546Sopenharmony_ci                        const VkDeviceSize *pOffsets)
942bf215546Sopenharmony_ci{
943bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindVertexBuffers, commandBuffer, firstBinding,
944bf215546Sopenharmony_ci                  bindingCount, pBuffers, pOffsets);
945bf215546Sopenharmony_ci}
946bf215546Sopenharmony_ci
947bf215546Sopenharmony_civoid
948bf215546Sopenharmony_civn_CmdDraw(VkCommandBuffer commandBuffer,
949bf215546Sopenharmony_ci           uint32_t vertexCount,
950bf215546Sopenharmony_ci           uint32_t instanceCount,
951bf215546Sopenharmony_ci           uint32_t firstVertex,
952bf215546Sopenharmony_ci           uint32_t firstInstance)
953bf215546Sopenharmony_ci{
954bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDraw, commandBuffer, vertexCount, instanceCount,
955bf215546Sopenharmony_ci                  firstVertex, firstInstance);
956bf215546Sopenharmony_ci
957bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
958bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
959bf215546Sopenharmony_ci}
960bf215546Sopenharmony_ci
961bf215546Sopenharmony_civoid
962bf215546Sopenharmony_civn_CmdBeginRendering(VkCommandBuffer commandBuffer,
963bf215546Sopenharmony_ci                     const VkRenderingInfo *pRenderingInfo)
964bf215546Sopenharmony_ci{
965bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginRendering, commandBuffer, pRenderingInfo);
966bf215546Sopenharmony_ci}
967bf215546Sopenharmony_ci
968bf215546Sopenharmony_civoid
969bf215546Sopenharmony_civn_CmdEndRendering(VkCommandBuffer commandBuffer)
970bf215546Sopenharmony_ci{
971bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndRendering, commandBuffer);
972bf215546Sopenharmony_ci}
973bf215546Sopenharmony_ci
974bf215546Sopenharmony_civoid
975bf215546Sopenharmony_civn_CmdDrawIndexed(VkCommandBuffer commandBuffer,
976bf215546Sopenharmony_ci                  uint32_t indexCount,
977bf215546Sopenharmony_ci                  uint32_t instanceCount,
978bf215546Sopenharmony_ci                  uint32_t firstIndex,
979bf215546Sopenharmony_ci                  int32_t vertexOffset,
980bf215546Sopenharmony_ci                  uint32_t firstInstance)
981bf215546Sopenharmony_ci{
982bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndexed, commandBuffer, indexCount, instanceCount,
983bf215546Sopenharmony_ci                  firstIndex, vertexOffset, firstInstance);
984bf215546Sopenharmony_ci
985bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
986bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
987bf215546Sopenharmony_ci}
988bf215546Sopenharmony_ci
989bf215546Sopenharmony_civoid
990bf215546Sopenharmony_civn_CmdDrawIndirect(VkCommandBuffer commandBuffer,
991bf215546Sopenharmony_ci                   VkBuffer buffer,
992bf215546Sopenharmony_ci                   VkDeviceSize offset,
993bf215546Sopenharmony_ci                   uint32_t drawCount,
994bf215546Sopenharmony_ci                   uint32_t stride)
995bf215546Sopenharmony_ci{
996bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndirect, commandBuffer, buffer, offset, drawCount,
997bf215546Sopenharmony_ci                  stride);
998bf215546Sopenharmony_ci
999bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
1000bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
1001bf215546Sopenharmony_ci}
1002bf215546Sopenharmony_ci
1003bf215546Sopenharmony_civoid
1004bf215546Sopenharmony_civn_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer,
1005bf215546Sopenharmony_ci                          VkBuffer buffer,
1006bf215546Sopenharmony_ci                          VkDeviceSize offset,
1007bf215546Sopenharmony_ci                          uint32_t drawCount,
1008bf215546Sopenharmony_ci                          uint32_t stride)
1009bf215546Sopenharmony_ci{
1010bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndexedIndirect, commandBuffer, buffer, offset,
1011bf215546Sopenharmony_ci                  drawCount, stride);
1012bf215546Sopenharmony_ci
1013bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
1014bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
1015bf215546Sopenharmony_ci}
1016bf215546Sopenharmony_ci
1017bf215546Sopenharmony_civoid
1018bf215546Sopenharmony_civn_CmdDrawIndirectCount(VkCommandBuffer commandBuffer,
1019bf215546Sopenharmony_ci                        VkBuffer buffer,
1020bf215546Sopenharmony_ci                        VkDeviceSize offset,
1021bf215546Sopenharmony_ci                        VkBuffer countBuffer,
1022bf215546Sopenharmony_ci                        VkDeviceSize countBufferOffset,
1023bf215546Sopenharmony_ci                        uint32_t maxDrawCount,
1024bf215546Sopenharmony_ci                        uint32_t stride)
1025bf215546Sopenharmony_ci{
1026bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndirectCount, commandBuffer, buffer, offset,
1027bf215546Sopenharmony_ci                  countBuffer, countBufferOffset, maxDrawCount, stride);
1028bf215546Sopenharmony_ci
1029bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
1030bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
1031bf215546Sopenharmony_ci}
1032bf215546Sopenharmony_ci
1033bf215546Sopenharmony_civoid
1034bf215546Sopenharmony_civn_CmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer,
1035bf215546Sopenharmony_ci                               VkBuffer buffer,
1036bf215546Sopenharmony_ci                               VkDeviceSize offset,
1037bf215546Sopenharmony_ci                               VkBuffer countBuffer,
1038bf215546Sopenharmony_ci                               VkDeviceSize countBufferOffset,
1039bf215546Sopenharmony_ci                               uint32_t maxDrawCount,
1040bf215546Sopenharmony_ci                               uint32_t stride)
1041bf215546Sopenharmony_ci{
1042bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndexedIndirectCount, commandBuffer, buffer,
1043bf215546Sopenharmony_ci                  offset, countBuffer, countBufferOffset, maxDrawCount,
1044bf215546Sopenharmony_ci                  stride);
1045bf215546Sopenharmony_ci
1046bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
1047bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
1048bf215546Sopenharmony_ci}
1049bf215546Sopenharmony_ci
1050bf215546Sopenharmony_civoid
1051bf215546Sopenharmony_civn_CmdDispatch(VkCommandBuffer commandBuffer,
1052bf215546Sopenharmony_ci               uint32_t groupCountX,
1053bf215546Sopenharmony_ci               uint32_t groupCountY,
1054bf215546Sopenharmony_ci               uint32_t groupCountZ)
1055bf215546Sopenharmony_ci{
1056bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDispatch, commandBuffer, groupCountX, groupCountY,
1057bf215546Sopenharmony_ci                  groupCountZ);
1058bf215546Sopenharmony_ci}
1059bf215546Sopenharmony_ci
1060bf215546Sopenharmony_civoid
1061bf215546Sopenharmony_civn_CmdDispatchIndirect(VkCommandBuffer commandBuffer,
1062bf215546Sopenharmony_ci                       VkBuffer buffer,
1063bf215546Sopenharmony_ci                       VkDeviceSize offset)
1064bf215546Sopenharmony_ci{
1065bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDispatchIndirect, commandBuffer, buffer, offset);
1066bf215546Sopenharmony_ci}
1067bf215546Sopenharmony_ci
1068bf215546Sopenharmony_civoid
1069bf215546Sopenharmony_civn_CmdCopyBuffer(VkCommandBuffer commandBuffer,
1070bf215546Sopenharmony_ci                 VkBuffer srcBuffer,
1071bf215546Sopenharmony_ci                 VkBuffer dstBuffer,
1072bf215546Sopenharmony_ci                 uint32_t regionCount,
1073bf215546Sopenharmony_ci                 const VkBufferCopy *pRegions)
1074bf215546Sopenharmony_ci{
1075bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyBuffer, commandBuffer, srcBuffer, dstBuffer,
1076bf215546Sopenharmony_ci                  regionCount, pRegions);
1077bf215546Sopenharmony_ci}
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_civoid
1080bf215546Sopenharmony_civn_CmdCopyBuffer2(VkCommandBuffer commandBuffer,
1081bf215546Sopenharmony_ci                  const VkCopyBufferInfo2 *pCopyBufferInfo)
1082bf215546Sopenharmony_ci{
1083bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyBuffer2, commandBuffer, pCopyBufferInfo);
1084bf215546Sopenharmony_ci}
1085bf215546Sopenharmony_ci
1086bf215546Sopenharmony_civoid
1087bf215546Sopenharmony_civn_CmdCopyImage(VkCommandBuffer commandBuffer,
1088bf215546Sopenharmony_ci                VkImage srcImage,
1089bf215546Sopenharmony_ci                VkImageLayout srcImageLayout,
1090bf215546Sopenharmony_ci                VkImage dstImage,
1091bf215546Sopenharmony_ci                VkImageLayout dstImageLayout,
1092bf215546Sopenharmony_ci                uint32_t regionCount,
1093bf215546Sopenharmony_ci                const VkImageCopy *pRegions)
1094bf215546Sopenharmony_ci{
1095bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyImage, commandBuffer, srcImage, srcImageLayout,
1096bf215546Sopenharmony_ci                  dstImage, dstImageLayout, regionCount, pRegions);
1097bf215546Sopenharmony_ci}
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_civoid
1100bf215546Sopenharmony_civn_CmdCopyImage2(VkCommandBuffer commandBuffer,
1101bf215546Sopenharmony_ci                 const VkCopyImageInfo2 *pCopyImageInfo)
1102bf215546Sopenharmony_ci{
1103bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyImage2, commandBuffer, pCopyImageInfo);
1104bf215546Sopenharmony_ci}
1105bf215546Sopenharmony_ci
1106bf215546Sopenharmony_civoid
1107bf215546Sopenharmony_civn_CmdBlitImage(VkCommandBuffer commandBuffer,
1108bf215546Sopenharmony_ci                VkImage srcImage,
1109bf215546Sopenharmony_ci                VkImageLayout srcImageLayout,
1110bf215546Sopenharmony_ci                VkImage dstImage,
1111bf215546Sopenharmony_ci                VkImageLayout dstImageLayout,
1112bf215546Sopenharmony_ci                uint32_t regionCount,
1113bf215546Sopenharmony_ci                const VkImageBlit *pRegions,
1114bf215546Sopenharmony_ci                VkFilter filter)
1115bf215546Sopenharmony_ci{
1116bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBlitImage, commandBuffer, srcImage, srcImageLayout,
1117bf215546Sopenharmony_ci                  dstImage, dstImageLayout, regionCount, pRegions, filter);
1118bf215546Sopenharmony_ci}
1119bf215546Sopenharmony_ci
1120bf215546Sopenharmony_civoid
1121bf215546Sopenharmony_civn_CmdBlitImage2(VkCommandBuffer commandBuffer,
1122bf215546Sopenharmony_ci                 const VkBlitImageInfo2 *pBlitImageInfo)
1123bf215546Sopenharmony_ci{
1124bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBlitImage2, commandBuffer, pBlitImageInfo);
1125bf215546Sopenharmony_ci}
1126bf215546Sopenharmony_ci
1127bf215546Sopenharmony_civoid
1128bf215546Sopenharmony_civn_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,
1129bf215546Sopenharmony_ci                        VkBuffer srcBuffer,
1130bf215546Sopenharmony_ci                        VkImage dstImage,
1131bf215546Sopenharmony_ci                        VkImageLayout dstImageLayout,
1132bf215546Sopenharmony_ci                        uint32_t regionCount,
1133bf215546Sopenharmony_ci                        const VkBufferImageCopy *pRegions)
1134bf215546Sopenharmony_ci{
1135bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyBufferToImage, commandBuffer, srcBuffer, dstImage,
1136bf215546Sopenharmony_ci                  dstImageLayout, regionCount, pRegions);
1137bf215546Sopenharmony_ci}
1138bf215546Sopenharmony_ci
1139bf215546Sopenharmony_civoid
1140bf215546Sopenharmony_civn_CmdCopyBufferToImage2(
1141bf215546Sopenharmony_ci   VkCommandBuffer commandBuffer,
1142bf215546Sopenharmony_ci   const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo)
1143bf215546Sopenharmony_ci{
1144bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyBufferToImage2, commandBuffer,
1145bf215546Sopenharmony_ci                  pCopyBufferToImageInfo);
1146bf215546Sopenharmony_ci}
1147bf215546Sopenharmony_ci
1148bf215546Sopenharmony_cistatic bool
1149bf215546Sopenharmony_civn_needs_prime_blit(VkImage src_image, VkImageLayout src_image_layout)
1150bf215546Sopenharmony_ci{
1151bf215546Sopenharmony_ci   if (src_image_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR &&
1152bf215546Sopenharmony_ci       VN_PRESENT_SRC_INTERNAL_LAYOUT != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
1153bf215546Sopenharmony_ci
1154bf215546Sopenharmony_ci      /* sanity check */
1155bf215546Sopenharmony_ci      ASSERTED const struct vn_image *img = vn_image_from_handle(src_image);
1156bf215546Sopenharmony_ci      assert(img->wsi.is_wsi && img->wsi.is_prime_blit_src);
1157bf215546Sopenharmony_ci      return true;
1158bf215546Sopenharmony_ci   }
1159bf215546Sopenharmony_ci
1160bf215546Sopenharmony_ci   return false;
1161bf215546Sopenharmony_ci}
1162bf215546Sopenharmony_ci
1163bf215546Sopenharmony_cistatic void
1164bf215546Sopenharmony_civn_transition_prime_layout(struct vn_command_buffer *cmd, VkBuffer dst_buffer)
1165bf215546Sopenharmony_ci{
1166bf215546Sopenharmony_ci   const VkBufferMemoryBarrier buf_barrier = {
1167bf215546Sopenharmony_ci      .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
1168bf215546Sopenharmony_ci      .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1169bf215546Sopenharmony_ci      .srcQueueFamilyIndex = cmd->queue_family_index,
1170bf215546Sopenharmony_ci      .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT,
1171bf215546Sopenharmony_ci      .buffer = dst_buffer,
1172bf215546Sopenharmony_ci      .size = VK_WHOLE_SIZE,
1173bf215546Sopenharmony_ci   };
1174bf215546Sopenharmony_ci   vn_cmd_encode_memory_barriers(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT,
1175bf215546Sopenharmony_ci                                 VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 1,
1176bf215546Sopenharmony_ci                                 &buf_barrier, 0, NULL);
1177bf215546Sopenharmony_ci}
1178bf215546Sopenharmony_ci
1179bf215546Sopenharmony_civoid
1180bf215546Sopenharmony_civn_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
1181bf215546Sopenharmony_ci                        VkImage srcImage,
1182bf215546Sopenharmony_ci                        VkImageLayout srcImageLayout,
1183bf215546Sopenharmony_ci                        VkBuffer dstBuffer,
1184bf215546Sopenharmony_ci                        uint32_t regionCount,
1185bf215546Sopenharmony_ci                        const VkBufferImageCopy *pRegions)
1186bf215546Sopenharmony_ci{
1187bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1188bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1189bf215546Sopenharmony_ci
1190bf215546Sopenharmony_ci   bool prime_blit = vn_needs_prime_blit(srcImage, srcImageLayout);
1191bf215546Sopenharmony_ci   if (prime_blit)
1192bf215546Sopenharmony_ci      srcImageLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1193bf215546Sopenharmony_ci
1194bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyImageToBuffer, commandBuffer, srcImage,
1195bf215546Sopenharmony_ci                  srcImageLayout, dstBuffer, regionCount, pRegions);
1196bf215546Sopenharmony_ci
1197bf215546Sopenharmony_ci   if (prime_blit)
1198bf215546Sopenharmony_ci      vn_transition_prime_layout(cmd, dstBuffer);
1199bf215546Sopenharmony_ci}
1200bf215546Sopenharmony_ci
1201bf215546Sopenharmony_civoid
1202bf215546Sopenharmony_civn_CmdCopyImageToBuffer2(
1203bf215546Sopenharmony_ci   VkCommandBuffer commandBuffer,
1204bf215546Sopenharmony_ci   const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo)
1205bf215546Sopenharmony_ci{
1206bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1207bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1208bf215546Sopenharmony_ci   struct VkCopyImageToBufferInfo2 copy_info = *pCopyImageToBufferInfo;
1209bf215546Sopenharmony_ci
1210bf215546Sopenharmony_ci   bool prime_blit =
1211bf215546Sopenharmony_ci      vn_needs_prime_blit(copy_info.srcImage, copy_info.srcImageLayout);
1212bf215546Sopenharmony_ci   if (prime_blit)
1213bf215546Sopenharmony_ci      copy_info.srcImageLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1214bf215546Sopenharmony_ci
1215bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyImageToBuffer2, commandBuffer, &copy_info);
1216bf215546Sopenharmony_ci
1217bf215546Sopenharmony_ci   if (prime_blit)
1218bf215546Sopenharmony_ci      vn_transition_prime_layout(cmd, copy_info.dstBuffer);
1219bf215546Sopenharmony_ci}
1220bf215546Sopenharmony_ci
1221bf215546Sopenharmony_civoid
1222bf215546Sopenharmony_civn_CmdUpdateBuffer(VkCommandBuffer commandBuffer,
1223bf215546Sopenharmony_ci                   VkBuffer dstBuffer,
1224bf215546Sopenharmony_ci                   VkDeviceSize dstOffset,
1225bf215546Sopenharmony_ci                   VkDeviceSize dataSize,
1226bf215546Sopenharmony_ci                   const void *pData)
1227bf215546Sopenharmony_ci{
1228bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdUpdateBuffer, commandBuffer, dstBuffer, dstOffset,
1229bf215546Sopenharmony_ci                  dataSize, pData);
1230bf215546Sopenharmony_ci}
1231bf215546Sopenharmony_ci
1232bf215546Sopenharmony_civoid
1233bf215546Sopenharmony_civn_CmdFillBuffer(VkCommandBuffer commandBuffer,
1234bf215546Sopenharmony_ci                 VkBuffer dstBuffer,
1235bf215546Sopenharmony_ci                 VkDeviceSize dstOffset,
1236bf215546Sopenharmony_ci                 VkDeviceSize size,
1237bf215546Sopenharmony_ci                 uint32_t data)
1238bf215546Sopenharmony_ci{
1239bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdFillBuffer, commandBuffer, dstBuffer, dstOffset, size,
1240bf215546Sopenharmony_ci                  data);
1241bf215546Sopenharmony_ci}
1242bf215546Sopenharmony_ci
1243bf215546Sopenharmony_civoid
1244bf215546Sopenharmony_civn_CmdClearColorImage(VkCommandBuffer commandBuffer,
1245bf215546Sopenharmony_ci                      VkImage image,
1246bf215546Sopenharmony_ci                      VkImageLayout imageLayout,
1247bf215546Sopenharmony_ci                      const VkClearColorValue *pColor,
1248bf215546Sopenharmony_ci                      uint32_t rangeCount,
1249bf215546Sopenharmony_ci                      const VkImageSubresourceRange *pRanges)
1250bf215546Sopenharmony_ci{
1251bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdClearColorImage, commandBuffer, image, imageLayout,
1252bf215546Sopenharmony_ci                  pColor, rangeCount, pRanges);
1253bf215546Sopenharmony_ci}
1254bf215546Sopenharmony_ci
1255bf215546Sopenharmony_civoid
1256bf215546Sopenharmony_civn_CmdClearDepthStencilImage(VkCommandBuffer commandBuffer,
1257bf215546Sopenharmony_ci                             VkImage image,
1258bf215546Sopenharmony_ci                             VkImageLayout imageLayout,
1259bf215546Sopenharmony_ci                             const VkClearDepthStencilValue *pDepthStencil,
1260bf215546Sopenharmony_ci                             uint32_t rangeCount,
1261bf215546Sopenharmony_ci                             const VkImageSubresourceRange *pRanges)
1262bf215546Sopenharmony_ci{
1263bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdClearDepthStencilImage, commandBuffer, image,
1264bf215546Sopenharmony_ci                  imageLayout, pDepthStencil, rangeCount, pRanges);
1265bf215546Sopenharmony_ci}
1266bf215546Sopenharmony_ci
1267bf215546Sopenharmony_civoid
1268bf215546Sopenharmony_civn_CmdClearAttachments(VkCommandBuffer commandBuffer,
1269bf215546Sopenharmony_ci                       uint32_t attachmentCount,
1270bf215546Sopenharmony_ci                       const VkClearAttachment *pAttachments,
1271bf215546Sopenharmony_ci                       uint32_t rectCount,
1272bf215546Sopenharmony_ci                       const VkClearRect *pRects)
1273bf215546Sopenharmony_ci{
1274bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdClearAttachments, commandBuffer, attachmentCount,
1275bf215546Sopenharmony_ci                  pAttachments, rectCount, pRects);
1276bf215546Sopenharmony_ci}
1277bf215546Sopenharmony_ci
1278bf215546Sopenharmony_civoid
1279bf215546Sopenharmony_civn_CmdResolveImage(VkCommandBuffer commandBuffer,
1280bf215546Sopenharmony_ci                   VkImage srcImage,
1281bf215546Sopenharmony_ci                   VkImageLayout srcImageLayout,
1282bf215546Sopenharmony_ci                   VkImage dstImage,
1283bf215546Sopenharmony_ci                   VkImageLayout dstImageLayout,
1284bf215546Sopenharmony_ci                   uint32_t regionCount,
1285bf215546Sopenharmony_ci                   const VkImageResolve *pRegions)
1286bf215546Sopenharmony_ci{
1287bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdResolveImage, commandBuffer, srcImage, srcImageLayout,
1288bf215546Sopenharmony_ci                  dstImage, dstImageLayout, regionCount, pRegions);
1289bf215546Sopenharmony_ci}
1290bf215546Sopenharmony_ci
1291bf215546Sopenharmony_civoid
1292bf215546Sopenharmony_civn_CmdResolveImage2(VkCommandBuffer commandBuffer,
1293bf215546Sopenharmony_ci                    const VkResolveImageInfo2 *pResolveImageInfo)
1294bf215546Sopenharmony_ci{
1295bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdResolveImage2, commandBuffer, pResolveImageInfo);
1296bf215546Sopenharmony_ci}
1297bf215546Sopenharmony_ci
1298bf215546Sopenharmony_civoid
1299bf215546Sopenharmony_civn_CmdSetEvent(VkCommandBuffer commandBuffer,
1300bf215546Sopenharmony_ci               VkEvent event,
1301bf215546Sopenharmony_ci               VkPipelineStageFlags stageMask)
1302bf215546Sopenharmony_ci{
1303bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetEvent, commandBuffer, event, stageMask);
1304bf215546Sopenharmony_ci
1305bf215546Sopenharmony_ci   vn_feedback_event_cmd_record(commandBuffer, event, stageMask,
1306bf215546Sopenharmony_ci                                VK_EVENT_SET);
1307bf215546Sopenharmony_ci}
1308bf215546Sopenharmony_ci
1309bf215546Sopenharmony_civoid
1310bf215546Sopenharmony_civn_CmdResetEvent(VkCommandBuffer commandBuffer,
1311bf215546Sopenharmony_ci                 VkEvent event,
1312bf215546Sopenharmony_ci                 VkPipelineStageFlags stageMask)
1313bf215546Sopenharmony_ci{
1314bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdResetEvent, commandBuffer, event, stageMask);
1315bf215546Sopenharmony_ci
1316bf215546Sopenharmony_ci   vn_feedback_event_cmd_record(commandBuffer, event, stageMask,
1317bf215546Sopenharmony_ci                                VK_EVENT_RESET);
1318bf215546Sopenharmony_ci}
1319bf215546Sopenharmony_ci
1320bf215546Sopenharmony_civoid
1321bf215546Sopenharmony_civn_CmdWaitEvents(VkCommandBuffer commandBuffer,
1322bf215546Sopenharmony_ci                 uint32_t eventCount,
1323bf215546Sopenharmony_ci                 const VkEvent *pEvents,
1324bf215546Sopenharmony_ci                 VkPipelineStageFlags srcStageMask,
1325bf215546Sopenharmony_ci                 VkPipelineStageFlags dstStageMask,
1326bf215546Sopenharmony_ci                 uint32_t memoryBarrierCount,
1327bf215546Sopenharmony_ci                 const VkMemoryBarrier *pMemoryBarriers,
1328bf215546Sopenharmony_ci                 uint32_t bufferMemoryBarrierCount,
1329bf215546Sopenharmony_ci                 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
1330bf215546Sopenharmony_ci                 uint32_t imageMemoryBarrierCount,
1331bf215546Sopenharmony_ci                 const VkImageMemoryBarrier *pImageMemoryBarriers)
1332bf215546Sopenharmony_ci{
1333bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1334bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1335bf215546Sopenharmony_ci   uint32_t transfer_count;
1336bf215546Sopenharmony_ci
1337bf215546Sopenharmony_ci   pImageMemoryBarriers = vn_cmd_wait_events_fix_image_memory_barriers(
1338bf215546Sopenharmony_ci      cmd, pImageMemoryBarriers, imageMemoryBarrierCount, &transfer_count);
1339bf215546Sopenharmony_ci   imageMemoryBarrierCount -= transfer_count;
1340bf215546Sopenharmony_ci
1341bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdWaitEvents, commandBuffer, eventCount, pEvents,
1342bf215546Sopenharmony_ci                  srcStageMask, dstStageMask, memoryBarrierCount,
1343bf215546Sopenharmony_ci                  pMemoryBarriers, bufferMemoryBarrierCount,
1344bf215546Sopenharmony_ci                  pBufferMemoryBarriers, imageMemoryBarrierCount,
1345bf215546Sopenharmony_ci                  pImageMemoryBarriers);
1346bf215546Sopenharmony_ci
1347bf215546Sopenharmony_ci   if (transfer_count) {
1348bf215546Sopenharmony_ci      pImageMemoryBarriers += imageMemoryBarrierCount;
1349bf215546Sopenharmony_ci      vn_cmd_encode_memory_barriers(cmd, srcStageMask, dstStageMask, 0, NULL,
1350bf215546Sopenharmony_ci                                    transfer_count, pImageMemoryBarriers);
1351bf215546Sopenharmony_ci   }
1352bf215546Sopenharmony_ci}
1353bf215546Sopenharmony_ci
1354bf215546Sopenharmony_civoid
1355bf215546Sopenharmony_civn_CmdPipelineBarrier(VkCommandBuffer commandBuffer,
1356bf215546Sopenharmony_ci                      VkPipelineStageFlags srcStageMask,
1357bf215546Sopenharmony_ci                      VkPipelineStageFlags dstStageMask,
1358bf215546Sopenharmony_ci                      VkDependencyFlags dependencyFlags,
1359bf215546Sopenharmony_ci                      uint32_t memoryBarrierCount,
1360bf215546Sopenharmony_ci                      const VkMemoryBarrier *pMemoryBarriers,
1361bf215546Sopenharmony_ci                      uint32_t bufferMemoryBarrierCount,
1362bf215546Sopenharmony_ci                      const VkBufferMemoryBarrier *pBufferMemoryBarriers,
1363bf215546Sopenharmony_ci                      uint32_t imageMemoryBarrierCount,
1364bf215546Sopenharmony_ci                      const VkImageMemoryBarrier *pImageMemoryBarriers)
1365bf215546Sopenharmony_ci{
1366bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1367bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1368bf215546Sopenharmony_ci
1369bf215546Sopenharmony_ci   pImageMemoryBarriers = vn_cmd_pipeline_barrier_fix_image_memory_barriers(
1370bf215546Sopenharmony_ci      cmd, pImageMemoryBarriers, imageMemoryBarrierCount);
1371bf215546Sopenharmony_ci
1372bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdPipelineBarrier, commandBuffer, srcStageMask,
1373bf215546Sopenharmony_ci                  dstStageMask, dependencyFlags, memoryBarrierCount,
1374bf215546Sopenharmony_ci                  pMemoryBarriers, bufferMemoryBarrierCount,
1375bf215546Sopenharmony_ci                  pBufferMemoryBarriers, imageMemoryBarrierCount,
1376bf215546Sopenharmony_ci                  pImageMemoryBarriers);
1377bf215546Sopenharmony_ci}
1378bf215546Sopenharmony_ci
1379bf215546Sopenharmony_civoid
1380bf215546Sopenharmony_civn_CmdBeginQuery(VkCommandBuffer commandBuffer,
1381bf215546Sopenharmony_ci                 VkQueryPool queryPool,
1382bf215546Sopenharmony_ci                 uint32_t query,
1383bf215546Sopenharmony_ci                 VkQueryControlFlags flags)
1384bf215546Sopenharmony_ci{
1385bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginQuery, commandBuffer, queryPool, query, flags);
1386bf215546Sopenharmony_ci}
1387bf215546Sopenharmony_ci
1388bf215546Sopenharmony_civoid
1389bf215546Sopenharmony_civn_CmdEndQuery(VkCommandBuffer commandBuffer,
1390bf215546Sopenharmony_ci               VkQueryPool queryPool,
1391bf215546Sopenharmony_ci               uint32_t query)
1392bf215546Sopenharmony_ci{
1393bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndQuery, commandBuffer, queryPool, query);
1394bf215546Sopenharmony_ci}
1395bf215546Sopenharmony_ci
1396bf215546Sopenharmony_civoid
1397bf215546Sopenharmony_civn_CmdResetQueryPool(VkCommandBuffer commandBuffer,
1398bf215546Sopenharmony_ci                     VkQueryPool queryPool,
1399bf215546Sopenharmony_ci                     uint32_t firstQuery,
1400bf215546Sopenharmony_ci                     uint32_t queryCount)
1401bf215546Sopenharmony_ci{
1402bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdResetQueryPool, commandBuffer, queryPool, firstQuery,
1403bf215546Sopenharmony_ci                  queryCount);
1404bf215546Sopenharmony_ci}
1405bf215546Sopenharmony_ci
1406bf215546Sopenharmony_civoid
1407bf215546Sopenharmony_civn_CmdWriteTimestamp(VkCommandBuffer commandBuffer,
1408bf215546Sopenharmony_ci                     VkPipelineStageFlagBits pipelineStage,
1409bf215546Sopenharmony_ci                     VkQueryPool queryPool,
1410bf215546Sopenharmony_ci                     uint32_t query)
1411bf215546Sopenharmony_ci{
1412bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdWriteTimestamp, commandBuffer, pipelineStage,
1413bf215546Sopenharmony_ci                  queryPool, query);
1414bf215546Sopenharmony_ci}
1415bf215546Sopenharmony_ci
1416bf215546Sopenharmony_civoid
1417bf215546Sopenharmony_civn_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer,
1418bf215546Sopenharmony_ci                           VkQueryPool queryPool,
1419bf215546Sopenharmony_ci                           uint32_t firstQuery,
1420bf215546Sopenharmony_ci                           uint32_t queryCount,
1421bf215546Sopenharmony_ci                           VkBuffer dstBuffer,
1422bf215546Sopenharmony_ci                           VkDeviceSize dstOffset,
1423bf215546Sopenharmony_ci                           VkDeviceSize stride,
1424bf215546Sopenharmony_ci                           VkQueryResultFlags flags)
1425bf215546Sopenharmony_ci{
1426bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdCopyQueryPoolResults, commandBuffer, queryPool,
1427bf215546Sopenharmony_ci                  firstQuery, queryCount, dstBuffer, dstOffset, stride,
1428bf215546Sopenharmony_ci                  flags);
1429bf215546Sopenharmony_ci}
1430bf215546Sopenharmony_ci
1431bf215546Sopenharmony_civoid
1432bf215546Sopenharmony_civn_CmdPushConstants(VkCommandBuffer commandBuffer,
1433bf215546Sopenharmony_ci                    VkPipelineLayout layout,
1434bf215546Sopenharmony_ci                    VkShaderStageFlags stageFlags,
1435bf215546Sopenharmony_ci                    uint32_t offset,
1436bf215546Sopenharmony_ci                    uint32_t size,
1437bf215546Sopenharmony_ci                    const void *pValues)
1438bf215546Sopenharmony_ci{
1439bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdPushConstants, commandBuffer, layout, stageFlags,
1440bf215546Sopenharmony_ci                  offset, size, pValues);
1441bf215546Sopenharmony_ci}
1442bf215546Sopenharmony_ci
1443bf215546Sopenharmony_civoid
1444bf215546Sopenharmony_civn_CmdBeginRenderPass(VkCommandBuffer commandBuffer,
1445bf215546Sopenharmony_ci                      const VkRenderPassBeginInfo *pRenderPassBegin,
1446bf215546Sopenharmony_ci                      VkSubpassContents contents)
1447bf215546Sopenharmony_ci{
1448bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1449bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1450bf215546Sopenharmony_ci
1451bf215546Sopenharmony_ci   vn_cmd_begin_render_pass(
1452bf215546Sopenharmony_ci      cmd, vn_render_pass_from_handle(pRenderPassBegin->renderPass),
1453bf215546Sopenharmony_ci      vn_framebuffer_from_handle(pRenderPassBegin->framebuffer),
1454bf215546Sopenharmony_ci      pRenderPassBegin);
1455bf215546Sopenharmony_ci
1456bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginRenderPass, commandBuffer, pRenderPassBegin,
1457bf215546Sopenharmony_ci                  contents);
1458bf215546Sopenharmony_ci}
1459bf215546Sopenharmony_ci
1460bf215546Sopenharmony_civoid
1461bf215546Sopenharmony_civn_CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
1462bf215546Sopenharmony_ci{
1463bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdNextSubpass, commandBuffer, contents);
1464bf215546Sopenharmony_ci}
1465bf215546Sopenharmony_ci
1466bf215546Sopenharmony_civoid
1467bf215546Sopenharmony_civn_CmdEndRenderPass(VkCommandBuffer commandBuffer)
1468bf215546Sopenharmony_ci{
1469bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1470bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1471bf215546Sopenharmony_ci
1472bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndRenderPass, commandBuffer);
1473bf215546Sopenharmony_ci
1474bf215546Sopenharmony_ci   vn_cmd_end_render_pass(cmd);
1475bf215546Sopenharmony_ci}
1476bf215546Sopenharmony_ci
1477bf215546Sopenharmony_civoid
1478bf215546Sopenharmony_civn_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
1479bf215546Sopenharmony_ci                       const VkRenderPassBeginInfo *pRenderPassBegin,
1480bf215546Sopenharmony_ci                       const VkSubpassBeginInfo *pSubpassBeginInfo)
1481bf215546Sopenharmony_ci{
1482bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1483bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1484bf215546Sopenharmony_ci
1485bf215546Sopenharmony_ci   vn_cmd_begin_render_pass(
1486bf215546Sopenharmony_ci      cmd, vn_render_pass_from_handle(pRenderPassBegin->renderPass),
1487bf215546Sopenharmony_ci      vn_framebuffer_from_handle(pRenderPassBegin->framebuffer),
1488bf215546Sopenharmony_ci      pRenderPassBegin);
1489bf215546Sopenharmony_ci
1490bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginRenderPass2, commandBuffer, pRenderPassBegin,
1491bf215546Sopenharmony_ci                  pSubpassBeginInfo);
1492bf215546Sopenharmony_ci}
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_civoid
1495bf215546Sopenharmony_civn_CmdNextSubpass2(VkCommandBuffer commandBuffer,
1496bf215546Sopenharmony_ci                   const VkSubpassBeginInfo *pSubpassBeginInfo,
1497bf215546Sopenharmony_ci                   const VkSubpassEndInfo *pSubpassEndInfo)
1498bf215546Sopenharmony_ci{
1499bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdNextSubpass2, commandBuffer, pSubpassBeginInfo,
1500bf215546Sopenharmony_ci                  pSubpassEndInfo);
1501bf215546Sopenharmony_ci}
1502bf215546Sopenharmony_ci
1503bf215546Sopenharmony_civoid
1504bf215546Sopenharmony_civn_CmdEndRenderPass2(VkCommandBuffer commandBuffer,
1505bf215546Sopenharmony_ci                     const VkSubpassEndInfo *pSubpassEndInfo)
1506bf215546Sopenharmony_ci{
1507bf215546Sopenharmony_ci   struct vn_command_buffer *cmd =
1508bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer);
1509bf215546Sopenharmony_ci
1510bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndRenderPass2, commandBuffer, pSubpassEndInfo);
1511bf215546Sopenharmony_ci
1512bf215546Sopenharmony_ci   vn_cmd_end_render_pass(cmd);
1513bf215546Sopenharmony_ci}
1514bf215546Sopenharmony_ci
1515bf215546Sopenharmony_civoid
1516bf215546Sopenharmony_civn_CmdExecuteCommands(VkCommandBuffer commandBuffer,
1517bf215546Sopenharmony_ci                      uint32_t commandBufferCount,
1518bf215546Sopenharmony_ci                      const VkCommandBuffer *pCommandBuffers)
1519bf215546Sopenharmony_ci{
1520bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdExecuteCommands, commandBuffer, commandBufferCount,
1521bf215546Sopenharmony_ci                  pCommandBuffers);
1522bf215546Sopenharmony_ci}
1523bf215546Sopenharmony_ci
1524bf215546Sopenharmony_civoid
1525bf215546Sopenharmony_civn_CmdSetDeviceMask(VkCommandBuffer commandBuffer, uint32_t deviceMask)
1526bf215546Sopenharmony_ci{
1527bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDeviceMask, commandBuffer, deviceMask);
1528bf215546Sopenharmony_ci}
1529bf215546Sopenharmony_ci
1530bf215546Sopenharmony_civoid
1531bf215546Sopenharmony_civn_CmdDispatchBase(VkCommandBuffer commandBuffer,
1532bf215546Sopenharmony_ci                   uint32_t baseGroupX,
1533bf215546Sopenharmony_ci                   uint32_t baseGroupY,
1534bf215546Sopenharmony_ci                   uint32_t baseGroupZ,
1535bf215546Sopenharmony_ci                   uint32_t groupCountX,
1536bf215546Sopenharmony_ci                   uint32_t groupCountY,
1537bf215546Sopenharmony_ci                   uint32_t groupCountZ)
1538bf215546Sopenharmony_ci{
1539bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDispatchBase, commandBuffer, baseGroupX, baseGroupY,
1540bf215546Sopenharmony_ci                  baseGroupZ, groupCountX, groupCountY, groupCountZ);
1541bf215546Sopenharmony_ci}
1542bf215546Sopenharmony_ci
1543bf215546Sopenharmony_civoid
1544bf215546Sopenharmony_civn_CmdSetLineStippleEXT(VkCommandBuffer commandBuffer,
1545bf215546Sopenharmony_ci                        uint32_t lineStippleFactor,
1546bf215546Sopenharmony_ci                        uint16_t lineStipplePattern)
1547bf215546Sopenharmony_ci{
1548bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetLineStippleEXT, commandBuffer, lineStippleFactor,
1549bf215546Sopenharmony_ci                  lineStipplePattern);
1550bf215546Sopenharmony_ci}
1551bf215546Sopenharmony_ci
1552bf215546Sopenharmony_civoid
1553bf215546Sopenharmony_civn_CmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer,
1554bf215546Sopenharmony_ci                           VkQueryPool queryPool,
1555bf215546Sopenharmony_ci                           uint32_t query,
1556bf215546Sopenharmony_ci                           VkQueryControlFlags flags,
1557bf215546Sopenharmony_ci                           uint32_t index)
1558bf215546Sopenharmony_ci{
1559bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginQueryIndexedEXT, commandBuffer, queryPool, query,
1560bf215546Sopenharmony_ci                  flags, index);
1561bf215546Sopenharmony_ci}
1562bf215546Sopenharmony_ci
1563bf215546Sopenharmony_civoid
1564bf215546Sopenharmony_civn_CmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer,
1565bf215546Sopenharmony_ci                         VkQueryPool queryPool,
1566bf215546Sopenharmony_ci                         uint32_t query,
1567bf215546Sopenharmony_ci                         uint32_t index)
1568bf215546Sopenharmony_ci{
1569bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndQueryIndexedEXT, commandBuffer, queryPool, query,
1570bf215546Sopenharmony_ci                  index);
1571bf215546Sopenharmony_ci}
1572bf215546Sopenharmony_ci
1573bf215546Sopenharmony_civoid
1574bf215546Sopenharmony_civn_CmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer,
1575bf215546Sopenharmony_ci                                      uint32_t firstBinding,
1576bf215546Sopenharmony_ci                                      uint32_t bindingCount,
1577bf215546Sopenharmony_ci                                      const VkBuffer *pBuffers,
1578bf215546Sopenharmony_ci                                      const VkDeviceSize *pOffsets,
1579bf215546Sopenharmony_ci                                      const VkDeviceSize *pSizes)
1580bf215546Sopenharmony_ci{
1581bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindTransformFeedbackBuffersEXT, commandBuffer,
1582bf215546Sopenharmony_ci                  firstBinding, bindingCount, pBuffers, pOffsets, pSizes);
1583bf215546Sopenharmony_ci}
1584bf215546Sopenharmony_ci
1585bf215546Sopenharmony_civoid
1586bf215546Sopenharmony_civn_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer,
1587bf215546Sopenharmony_ci                                uint32_t firstCounterBuffer,
1588bf215546Sopenharmony_ci                                uint32_t counterBufferCount,
1589bf215546Sopenharmony_ci                                const VkBuffer *pCounterBuffers,
1590bf215546Sopenharmony_ci                                const VkDeviceSize *pCounterBufferOffsets)
1591bf215546Sopenharmony_ci{
1592bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginTransformFeedbackEXT, commandBuffer,
1593bf215546Sopenharmony_ci                  firstCounterBuffer, counterBufferCount, pCounterBuffers,
1594bf215546Sopenharmony_ci                  pCounterBufferOffsets);
1595bf215546Sopenharmony_ci}
1596bf215546Sopenharmony_ci
1597bf215546Sopenharmony_civoid
1598bf215546Sopenharmony_civn_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer,
1599bf215546Sopenharmony_ci                              uint32_t firstCounterBuffer,
1600bf215546Sopenharmony_ci                              uint32_t counterBufferCount,
1601bf215546Sopenharmony_ci                              const VkBuffer *pCounterBuffers,
1602bf215546Sopenharmony_ci                              const VkDeviceSize *pCounterBufferOffsets)
1603bf215546Sopenharmony_ci{
1604bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndTransformFeedbackEXT, commandBuffer,
1605bf215546Sopenharmony_ci                  firstCounterBuffer, counterBufferCount, pCounterBuffers,
1606bf215546Sopenharmony_ci                  pCounterBufferOffsets);
1607bf215546Sopenharmony_ci}
1608bf215546Sopenharmony_ci
1609bf215546Sopenharmony_civoid
1610bf215546Sopenharmony_civn_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer,
1611bf215546Sopenharmony_ci                               uint32_t instanceCount,
1612bf215546Sopenharmony_ci                               uint32_t firstInstance,
1613bf215546Sopenharmony_ci                               VkBuffer counterBuffer,
1614bf215546Sopenharmony_ci                               VkDeviceSize counterBufferOffset,
1615bf215546Sopenharmony_ci                               uint32_t counterOffset,
1616bf215546Sopenharmony_ci                               uint32_t vertexStride)
1617bf215546Sopenharmony_ci{
1618bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdDrawIndirectByteCountEXT, commandBuffer, instanceCount,
1619bf215546Sopenharmony_ci                  firstInstance, counterBuffer, counterBufferOffset,
1620bf215546Sopenharmony_ci                  counterOffset, vertexStride);
1621bf215546Sopenharmony_ci
1622bf215546Sopenharmony_ci   vn_cmd_count_draw_and_submit_on_batch_limit(
1623bf215546Sopenharmony_ci      vn_command_buffer_from_handle(commandBuffer));
1624bf215546Sopenharmony_ci}
1625bf215546Sopenharmony_ci
1626bf215546Sopenharmony_civoid
1627bf215546Sopenharmony_civn_CmdBindVertexBuffers2(VkCommandBuffer commandBuffer,
1628bf215546Sopenharmony_ci                         uint32_t firstBinding,
1629bf215546Sopenharmony_ci                         uint32_t bindingCount,
1630bf215546Sopenharmony_ci                         const VkBuffer *pBuffers,
1631bf215546Sopenharmony_ci                         const VkDeviceSize *pOffsets,
1632bf215546Sopenharmony_ci                         const VkDeviceSize *pSizes,
1633bf215546Sopenharmony_ci                         const VkDeviceSize *pStrides)
1634bf215546Sopenharmony_ci{
1635bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBindVertexBuffers2, commandBuffer, firstBinding,
1636bf215546Sopenharmony_ci                  bindingCount, pBuffers, pOffsets, pSizes, pStrides);
1637bf215546Sopenharmony_ci}
1638bf215546Sopenharmony_ci
1639bf215546Sopenharmony_civoid
1640bf215546Sopenharmony_civn_CmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode)
1641bf215546Sopenharmony_ci{
1642bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetCullMode, commandBuffer, cullMode);
1643bf215546Sopenharmony_ci}
1644bf215546Sopenharmony_ci
1645bf215546Sopenharmony_civoid
1646bf215546Sopenharmony_civn_CmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
1647bf215546Sopenharmony_ci                               VkBool32 depthBoundsTestEnable)
1648bf215546Sopenharmony_ci{
1649bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthBoundsTestEnable, commandBuffer,
1650bf215546Sopenharmony_ci                  depthBoundsTestEnable);
1651bf215546Sopenharmony_ci}
1652bf215546Sopenharmony_ci
1653bf215546Sopenharmony_civoid
1654bf215546Sopenharmony_civn_CmdSetDepthCompareOp(VkCommandBuffer commandBuffer,
1655bf215546Sopenharmony_ci                        VkCompareOp depthCompareOp)
1656bf215546Sopenharmony_ci{
1657bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthCompareOp, commandBuffer, depthCompareOp);
1658bf215546Sopenharmony_ci}
1659bf215546Sopenharmony_ci
1660bf215546Sopenharmony_civoid
1661bf215546Sopenharmony_civn_CmdSetDepthTestEnable(VkCommandBuffer commandBuffer,
1662bf215546Sopenharmony_ci                         VkBool32 depthTestEnable)
1663bf215546Sopenharmony_ci{
1664bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthTestEnable, commandBuffer, depthTestEnable);
1665bf215546Sopenharmony_ci}
1666bf215546Sopenharmony_ci
1667bf215546Sopenharmony_civoid
1668bf215546Sopenharmony_civn_CmdSetDepthWriteEnable(VkCommandBuffer commandBuffer,
1669bf215546Sopenharmony_ci                          VkBool32 depthWriteEnable)
1670bf215546Sopenharmony_ci{
1671bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthWriteEnable, commandBuffer, depthWriteEnable);
1672bf215546Sopenharmony_ci}
1673bf215546Sopenharmony_ci
1674bf215546Sopenharmony_civoid
1675bf215546Sopenharmony_civn_CmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace)
1676bf215546Sopenharmony_ci{
1677bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetFrontFace, commandBuffer, frontFace);
1678bf215546Sopenharmony_ci}
1679bf215546Sopenharmony_ci
1680bf215546Sopenharmony_civoid
1681bf215546Sopenharmony_civn_CmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
1682bf215546Sopenharmony_ci                           VkPrimitiveTopology primitiveTopology)
1683bf215546Sopenharmony_ci{
1684bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetPrimitiveTopology, commandBuffer,
1685bf215546Sopenharmony_ci                  primitiveTopology);
1686bf215546Sopenharmony_ci}
1687bf215546Sopenharmony_ci
1688bf215546Sopenharmony_civoid
1689bf215546Sopenharmony_civn_CmdSetScissorWithCount(VkCommandBuffer commandBuffer,
1690bf215546Sopenharmony_ci                          uint32_t scissorCount,
1691bf215546Sopenharmony_ci                          const VkRect2D *pScissors)
1692bf215546Sopenharmony_ci{
1693bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetScissorWithCount, commandBuffer, scissorCount,
1694bf215546Sopenharmony_ci                  pScissors);
1695bf215546Sopenharmony_ci}
1696bf215546Sopenharmony_ci
1697bf215546Sopenharmony_civoid
1698bf215546Sopenharmony_civn_CmdSetStencilOp(VkCommandBuffer commandBuffer,
1699bf215546Sopenharmony_ci                   VkStencilFaceFlags faceMask,
1700bf215546Sopenharmony_ci                   VkStencilOp failOp,
1701bf215546Sopenharmony_ci                   VkStencilOp passOp,
1702bf215546Sopenharmony_ci                   VkStencilOp depthFailOp,
1703bf215546Sopenharmony_ci                   VkCompareOp compareOp)
1704bf215546Sopenharmony_ci{
1705bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetStencilOp, commandBuffer, faceMask, failOp, passOp,
1706bf215546Sopenharmony_ci                  depthFailOp, compareOp);
1707bf215546Sopenharmony_ci}
1708bf215546Sopenharmony_ci
1709bf215546Sopenharmony_civoid
1710bf215546Sopenharmony_civn_CmdSetStencilTestEnable(VkCommandBuffer commandBuffer,
1711bf215546Sopenharmony_ci                           VkBool32 stencilTestEnable)
1712bf215546Sopenharmony_ci{
1713bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetStencilTestEnable, commandBuffer,
1714bf215546Sopenharmony_ci                  stencilTestEnable);
1715bf215546Sopenharmony_ci}
1716bf215546Sopenharmony_ci
1717bf215546Sopenharmony_civoid
1718bf215546Sopenharmony_civn_CmdSetViewportWithCount(VkCommandBuffer commandBuffer,
1719bf215546Sopenharmony_ci                           uint32_t viewportCount,
1720bf215546Sopenharmony_ci                           const VkViewport *pViewports)
1721bf215546Sopenharmony_ci{
1722bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetViewportWithCount, commandBuffer, viewportCount,
1723bf215546Sopenharmony_ci                  pViewports);
1724bf215546Sopenharmony_ci}
1725bf215546Sopenharmony_ci
1726bf215546Sopenharmony_civoid
1727bf215546Sopenharmony_civn_CmdSetDepthBiasEnable(VkCommandBuffer commandBuffer,
1728bf215546Sopenharmony_ci                         VkBool32 depthBiasEnable)
1729bf215546Sopenharmony_ci{
1730bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetDepthBiasEnable, commandBuffer, depthBiasEnable);
1731bf215546Sopenharmony_ci}
1732bf215546Sopenharmony_ci
1733bf215546Sopenharmony_civoid
1734bf215546Sopenharmony_civn_CmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp)
1735bf215546Sopenharmony_ci{
1736bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetLogicOpEXT, commandBuffer, logicOp);
1737bf215546Sopenharmony_ci}
1738bf215546Sopenharmony_ci
1739bf215546Sopenharmony_civoid
1740bf215546Sopenharmony_civn_CmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer,
1741bf215546Sopenharmony_ci                               uint32_t patchControlPoints)
1742bf215546Sopenharmony_ci{
1743bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetPatchControlPointsEXT, commandBuffer,
1744bf215546Sopenharmony_ci                  patchControlPoints);
1745bf215546Sopenharmony_ci}
1746bf215546Sopenharmony_ci
1747bf215546Sopenharmony_civoid
1748bf215546Sopenharmony_civn_CmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
1749bf215546Sopenharmony_ci                                VkBool32 primitiveRestartEnable)
1750bf215546Sopenharmony_ci{
1751bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetPrimitiveRestartEnable, commandBuffer,
1752bf215546Sopenharmony_ci                  primitiveRestartEnable);
1753bf215546Sopenharmony_ci}
1754bf215546Sopenharmony_ci
1755bf215546Sopenharmony_civoid
1756bf215546Sopenharmony_civn_CmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
1757bf215546Sopenharmony_ci                                 VkBool32 rasterizerDiscardEnable)
1758bf215546Sopenharmony_ci{
1759bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdSetRasterizerDiscardEnable, commandBuffer,
1760bf215546Sopenharmony_ci                  rasterizerDiscardEnable);
1761bf215546Sopenharmony_ci}
1762bf215546Sopenharmony_ci
1763bf215546Sopenharmony_civoid
1764bf215546Sopenharmony_civn_CmdBeginConditionalRenderingEXT(
1765bf215546Sopenharmony_ci   VkCommandBuffer commandBuffer,
1766bf215546Sopenharmony_ci   const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin)
1767bf215546Sopenharmony_ci{
1768bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdBeginConditionalRenderingEXT, commandBuffer,
1769bf215546Sopenharmony_ci                  pConditionalRenderingBegin);
1770bf215546Sopenharmony_ci}
1771bf215546Sopenharmony_ci
1772bf215546Sopenharmony_civoid
1773bf215546Sopenharmony_civn_CmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer)
1774bf215546Sopenharmony_ci{
1775bf215546Sopenharmony_ci   VN_CMD_ENQUEUE(vkCmdEndConditionalRenderingEXT, commandBuffer);
1776bf215546Sopenharmony_ci}
1777