17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2019 Google LLC
37ec681f3Smrg * SPDX-License-Identifier: MIT
47ec681f3Smrg *
57ec681f3Smrg * based in part on anv and radv which are:
67ec681f3Smrg * Copyright © 2015 Intel Corporation
77ec681f3Smrg * Copyright © 2016 Red Hat.
87ec681f3Smrg * Copyright © 2016 Bas Nieuwenhuizen
97ec681f3Smrg */
107ec681f3Smrg
117ec681f3Smrg#include "vn_command_buffer.h"
127ec681f3Smrg
137ec681f3Smrg#include "venus-protocol/vn_protocol_driver_command_buffer.h"
147ec681f3Smrg#include "venus-protocol/vn_protocol_driver_command_pool.h"
157ec681f3Smrg
167ec681f3Smrg#include "vn_device.h"
177ec681f3Smrg#include "vn_image.h"
187ec681f3Smrg#include "vn_render_pass.h"
197ec681f3Smrg
207ec681f3Smrgstatic bool
217ec681f3Smrgvn_image_memory_barrier_has_present_src(
227ec681f3Smrg   const VkImageMemoryBarrier *img_barriers, uint32_t count)
237ec681f3Smrg{
247ec681f3Smrg   for (uint32_t i = 0; i < count; i++) {
257ec681f3Smrg      if (img_barriers[i].oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
267ec681f3Smrg          img_barriers[i].newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
277ec681f3Smrg         return true;
287ec681f3Smrg   }
297ec681f3Smrg   return false;
307ec681f3Smrg}
317ec681f3Smrg
327ec681f3Smrgstatic VkImageMemoryBarrier *
337ec681f3Smrgvn_cmd_get_image_memory_barriers(struct vn_command_buffer *cmd,
347ec681f3Smrg                                 uint32_t count)
357ec681f3Smrg{
367ec681f3Smrg   /* avoid shrinking in case of non efficient reallocation implementation */
377ec681f3Smrg   if (count > cmd->builder.image_barrier_count) {
387ec681f3Smrg      size_t size = sizeof(VkImageMemoryBarrier) * count;
397ec681f3Smrg      VkImageMemoryBarrier *img_barriers =
407ec681f3Smrg         vk_realloc(&cmd->allocator, cmd->builder.image_barriers, size,
417ec681f3Smrg                    VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
427ec681f3Smrg      if (!img_barriers)
437ec681f3Smrg         return NULL;
447ec681f3Smrg
457ec681f3Smrg      /* update upon successful reallocation */
467ec681f3Smrg      cmd->builder.image_barrier_count = count;
477ec681f3Smrg      cmd->builder.image_barriers = img_barriers;
487ec681f3Smrg   }
497ec681f3Smrg
507ec681f3Smrg   return cmd->builder.image_barriers;
517ec681f3Smrg}
527ec681f3Smrg
537ec681f3Smrg/* About VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, the spec says
547ec681f3Smrg *
557ec681f3Smrg *    VK_IMAGE_LAYOUT_PRESENT_SRC_KHR must only be used for presenting a
567ec681f3Smrg *    presentable image for display. A swapchain's image must be transitioned
577ec681f3Smrg *    to this layout before calling vkQueuePresentKHR, and must be
587ec681f3Smrg *    transitioned away from this layout after calling vkAcquireNextImageKHR.
597ec681f3Smrg *
607ec681f3Smrg * That allows us to treat the layout internally as
617ec681f3Smrg *
627ec681f3Smrg *  - VK_IMAGE_LAYOUT_GENERAL
637ec681f3Smrg *  - VK_QUEUE_FAMILY_FOREIGN_EXT has the ownership, if the image is not a
647ec681f3Smrg *    prime blit source
657ec681f3Smrg *
667ec681f3Smrg * while staying performant.
677ec681f3Smrg *
687ec681f3Smrg * About queue family ownerships, the spec says
697ec681f3Smrg *
707ec681f3Smrg *    A queue family can take ownership of an image subresource or buffer
717ec681f3Smrg *    range of a resource created with VK_SHARING_MODE_EXCLUSIVE, without an
727ec681f3Smrg *    ownership transfer, in the same way as for a resource that was just
737ec681f3Smrg *    created; however, taking ownership in this way has the effect that the
747ec681f3Smrg *    contents of the image subresource or buffer range are undefined.
757ec681f3Smrg *
767ec681f3Smrg * It is unclear if that is applicable to external resources, which supposedly
777ec681f3Smrg * have the same semantics
787ec681f3Smrg *
797ec681f3Smrg *    Binding a resource to a memory object shared between multiple Vulkan
807ec681f3Smrg *    instances or other APIs does not change the ownership of the underlying
817ec681f3Smrg *    memory. The first entity to access the resource implicitly acquires
827ec681f3Smrg *    ownership. Accessing a resource backed by memory that is owned by a
837ec681f3Smrg *    particular instance or API has the same semantics as accessing a
847ec681f3Smrg *    VK_SHARING_MODE_EXCLUSIVE resource[...]
857ec681f3Smrg *
867ec681f3Smrg * We should get the spec clarified, or get rid of this completely broken code
877ec681f3Smrg * (TODO).
887ec681f3Smrg *
897ec681f3Smrg * Assuming a queue family can acquire the ownership implicitly when the
907ec681f3Smrg * contents are not needed, we do not need to worry about
917ec681f3Smrg * VK_IMAGE_LAYOUT_UNDEFINED.  We can use VK_IMAGE_LAYOUT_PRESENT_SRC_KHR as
927ec681f3Smrg * the sole signal to trigger queue family ownership transfers.
937ec681f3Smrg *
947ec681f3Smrg * When the image has VK_SHARING_MODE_CONCURRENT, we can, and are required to,
957ec681f3Smrg * use VK_QUEUE_FAMILY_IGNORED as the other queue family whether we are
967ec681f3Smrg * transitioning to or from VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
977ec681f3Smrg *
987ec681f3Smrg * When the image has VK_SHARING_MODE_EXCLUSIVE, we have to work out who the
997ec681f3Smrg * other queue family is.  It is easier when the barrier does not also define
1007ec681f3Smrg * a queue family ownership transfer (i.e., srcQueueFamilyIndex equals to
1017ec681f3Smrg * dstQueueFamilyIndex).  The other queue family must be the queue family the
1027ec681f3Smrg * command buffer was allocated for.
1037ec681f3Smrg *
1047ec681f3Smrg * When the barrier also defines a queue family ownership transfer, it is
1057ec681f3Smrg * submitted both to the source queue family to release the ownership and to
1067ec681f3Smrg * the destination queue family to acquire the ownership.  Depending on
1077ec681f3Smrg * whether the barrier transitions to or from VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
1087ec681f3Smrg * we are only interested in the ownership release or acquire respectively and
1097ec681f3Smrg * should be careful to avoid double releases/acquires.
1107ec681f3Smrg *
1117ec681f3Smrg * I haven't followed all transition paths mentally to verify the correctness.
1127ec681f3Smrg * I likely also violate some VUs or miss some cases below.  They are
1137ec681f3Smrg * hopefully fixable and are left as TODOs.
1147ec681f3Smrg */
1157ec681f3Smrgstatic void
1167ec681f3Smrgvn_cmd_fix_image_memory_barrier(const struct vn_command_buffer *cmd,
1177ec681f3Smrg                                const VkImageMemoryBarrier *src_barrier,
1187ec681f3Smrg                                VkImageMemoryBarrier *out_barrier)
1197ec681f3Smrg{
1207ec681f3Smrg   const struct vn_image *img = vn_image_from_handle(src_barrier->image);
1217ec681f3Smrg
1227ec681f3Smrg   *out_barrier = *src_barrier;
1237ec681f3Smrg
1247ec681f3Smrg   /* no fix needed */
1257ec681f3Smrg   if (out_barrier->oldLayout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR &&
1267ec681f3Smrg       out_barrier->newLayout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
1277ec681f3Smrg      return;
1287ec681f3Smrg
1297ec681f3Smrg   assert(img->is_wsi);
1307ec681f3Smrg
1317ec681f3Smrg   if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
1327ec681f3Smrg      return;
1337ec681f3Smrg
1347ec681f3Smrg   /* prime blit src or no layout transition */
1357ec681f3Smrg   if (img->is_prime_blit_src ||
1367ec681f3Smrg       out_barrier->oldLayout == out_barrier->newLayout) {
1377ec681f3Smrg      if (out_barrier->oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
1387ec681f3Smrg         out_barrier->oldLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1397ec681f3Smrg      if (out_barrier->newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
1407ec681f3Smrg         out_barrier->newLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1417ec681f3Smrg      return;
1427ec681f3Smrg   }
1437ec681f3Smrg
1447ec681f3Smrg   if (out_barrier->oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
1457ec681f3Smrg      out_barrier->oldLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1467ec681f3Smrg
1477ec681f3Smrg      /* no availability operation needed */
1487ec681f3Smrg      out_barrier->srcAccessMask = 0;
1497ec681f3Smrg
1507ec681f3Smrg      const uint32_t dst_qfi = out_barrier->dstQueueFamilyIndex;
1517ec681f3Smrg      if (img->sharing_mode == VK_SHARING_MODE_CONCURRENT) {
1527ec681f3Smrg         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
1537ec681f3Smrg         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1547ec681f3Smrg      } else if (dst_qfi == out_barrier->srcQueueFamilyIndex ||
1557ec681f3Smrg                 dst_qfi == cmd->queue_family_index) {
1567ec681f3Smrg         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
1577ec681f3Smrg         out_barrier->dstQueueFamilyIndex = cmd->queue_family_index;
1587ec681f3Smrg      } else {
1597ec681f3Smrg         /* The barrier also defines a queue family ownership transfer, and
1607ec681f3Smrg          * this is the one that gets submitted to the source queue family to
1617ec681f3Smrg          * release the ownership.  Skip both the transfer and the transition.
1627ec681f3Smrg          */
1637ec681f3Smrg         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1647ec681f3Smrg         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1657ec681f3Smrg         out_barrier->newLayout = out_barrier->oldLayout;
1667ec681f3Smrg      }
1677ec681f3Smrg   } else {
1687ec681f3Smrg      out_barrier->newLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
1697ec681f3Smrg
1707ec681f3Smrg      /* no visibility operation needed */
1717ec681f3Smrg      out_barrier->dstAccessMask = 0;
1727ec681f3Smrg
1737ec681f3Smrg      const uint32_t src_qfi = out_barrier->srcQueueFamilyIndex;
1747ec681f3Smrg      if (img->sharing_mode == VK_SHARING_MODE_CONCURRENT) {
1757ec681f3Smrg         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1767ec681f3Smrg         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
1777ec681f3Smrg      } else if (src_qfi == out_barrier->dstQueueFamilyIndex ||
1787ec681f3Smrg                 src_qfi == cmd->queue_family_index) {
1797ec681f3Smrg         out_barrier->srcQueueFamilyIndex = cmd->queue_family_index;
1807ec681f3Smrg         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
1817ec681f3Smrg      } else {
1827ec681f3Smrg         /* The barrier also defines a queue family ownership transfer, and
1837ec681f3Smrg          * this is the one that gets submitted to the destination queue
1847ec681f3Smrg          * family to acquire the ownership.  Skip both the transfer and the
1857ec681f3Smrg          * transition.
1867ec681f3Smrg          */
1877ec681f3Smrg         out_barrier->srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1887ec681f3Smrg         out_barrier->dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1897ec681f3Smrg         out_barrier->oldLayout = out_barrier->newLayout;
1907ec681f3Smrg      }
1917ec681f3Smrg   }
1927ec681f3Smrg}
1937ec681f3Smrg
1947ec681f3Smrgstatic const VkImageMemoryBarrier *
1957ec681f3Smrgvn_cmd_wait_events_fix_image_memory_barriers(
1967ec681f3Smrg   struct vn_command_buffer *cmd,
1977ec681f3Smrg   const VkImageMemoryBarrier *src_barriers,
1987ec681f3Smrg   uint32_t count,
1997ec681f3Smrg   uint32_t *out_transfer_count)
2007ec681f3Smrg{
2017ec681f3Smrg   *out_transfer_count = 0;
2027ec681f3Smrg
2037ec681f3Smrg   if (cmd->builder.render_pass ||
2047ec681f3Smrg       !vn_image_memory_barrier_has_present_src(src_barriers, count))
2057ec681f3Smrg      return src_barriers;
2067ec681f3Smrg
2077ec681f3Smrg   VkImageMemoryBarrier *img_barriers =
2087ec681f3Smrg      vn_cmd_get_image_memory_barriers(cmd, count * 2);
2097ec681f3Smrg   if (!img_barriers) {
2107ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
2117ec681f3Smrg      return src_barriers;
2127ec681f3Smrg   }
2137ec681f3Smrg
2147ec681f3Smrg   /* vkCmdWaitEvents cannot be used for queue family ownership transfers.
2157ec681f3Smrg    * Nothing appears to be said about the submission order of image memory
2167ec681f3Smrg    * barriers in the same array.  We take the liberty to move queue family
2177ec681f3Smrg    * ownership transfers to the tail.
2187ec681f3Smrg    */
2197ec681f3Smrg   VkImageMemoryBarrier *transfer_barriers = img_barriers + count;
2207ec681f3Smrg   uint32_t transfer_count = 0;
2217ec681f3Smrg   uint32_t valid_count = 0;
2227ec681f3Smrg   for (uint32_t i = 0; i < count; i++) {
2237ec681f3Smrg      VkImageMemoryBarrier *img_barrier = &img_barriers[valid_count];
2247ec681f3Smrg      vn_cmd_fix_image_memory_barrier(cmd, &src_barriers[i], img_barrier);
2257ec681f3Smrg
2267ec681f3Smrg      if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
2277ec681f3Smrg         valid_count++;
2287ec681f3Smrg         continue;
2297ec681f3Smrg      }
2307ec681f3Smrg
2317ec681f3Smrg      if (img_barrier->srcQueueFamilyIndex ==
2327ec681f3Smrg          img_barrier->dstQueueFamilyIndex) {
2337ec681f3Smrg         valid_count++;
2347ec681f3Smrg      } else {
2357ec681f3Smrg         transfer_barriers[transfer_count++] = *img_barrier;
2367ec681f3Smrg      }
2377ec681f3Smrg   }
2387ec681f3Smrg
2397ec681f3Smrg   assert(valid_count + transfer_count == count);
2407ec681f3Smrg   if (transfer_count) {
2417ec681f3Smrg      /* copy back to the tail */
2427ec681f3Smrg      memcpy(&img_barriers[valid_count], transfer_barriers,
2437ec681f3Smrg             sizeof(*transfer_barriers) * transfer_count);
2447ec681f3Smrg      *out_transfer_count = transfer_count;
2457ec681f3Smrg   }
2467ec681f3Smrg
2477ec681f3Smrg   return img_barriers;
2487ec681f3Smrg}
2497ec681f3Smrg
2507ec681f3Smrgstatic const VkImageMemoryBarrier *
2517ec681f3Smrgvn_cmd_pipeline_barrier_fix_image_memory_barriers(
2527ec681f3Smrg   struct vn_command_buffer *cmd,
2537ec681f3Smrg   const VkImageMemoryBarrier *src_barriers,
2547ec681f3Smrg   uint32_t count)
2557ec681f3Smrg{
2567ec681f3Smrg   if (cmd->builder.render_pass ||
2577ec681f3Smrg       !vn_image_memory_barrier_has_present_src(src_barriers, count))
2587ec681f3Smrg      return src_barriers;
2597ec681f3Smrg
2607ec681f3Smrg   VkImageMemoryBarrier *img_barriers =
2617ec681f3Smrg      vn_cmd_get_image_memory_barriers(cmd, count);
2627ec681f3Smrg   if (!img_barriers) {
2637ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
2647ec681f3Smrg      return src_barriers;
2657ec681f3Smrg   }
2667ec681f3Smrg
2677ec681f3Smrg   for (uint32_t i = 0; i < count; i++) {
2687ec681f3Smrg      vn_cmd_fix_image_memory_barrier(cmd, &src_barriers[i],
2697ec681f3Smrg                                      &img_barriers[i]);
2707ec681f3Smrg   }
2717ec681f3Smrg
2727ec681f3Smrg   return img_barriers;
2737ec681f3Smrg}
2747ec681f3Smrg
2757ec681f3Smrgstatic void
2767ec681f3Smrgvn_cmd_encode_memory_barriers(struct vn_command_buffer *cmd,
2777ec681f3Smrg                              VkPipelineStageFlags src_stage_mask,
2787ec681f3Smrg                              VkPipelineStageFlags dst_stage_mask,
2797ec681f3Smrg                              uint32_t buf_barrier_count,
2807ec681f3Smrg                              const VkBufferMemoryBarrier *buf_barriers,
2817ec681f3Smrg                              uint32_t img_barrier_count,
2827ec681f3Smrg                              const VkImageMemoryBarrier *img_barriers)
2837ec681f3Smrg{
2847ec681f3Smrg   const VkCommandBuffer cmd_handle = vn_command_buffer_to_handle(cmd);
2857ec681f3Smrg
2867ec681f3Smrg   const size_t cmd_size = vn_sizeof_vkCmdPipelineBarrier(
2877ec681f3Smrg      cmd_handle, src_stage_mask, dst_stage_mask, 0, 0, NULL,
2887ec681f3Smrg      buf_barrier_count, buf_barriers, img_barrier_count, img_barriers);
2897ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size)) {
2907ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
2917ec681f3Smrg      return;
2927ec681f3Smrg   }
2937ec681f3Smrg
2947ec681f3Smrg   vn_encode_vkCmdPipelineBarrier(
2957ec681f3Smrg      &cmd->cs, 0, cmd_handle, src_stage_mask, dst_stage_mask, 0, 0, NULL,
2967ec681f3Smrg      buf_barrier_count, buf_barriers, img_barrier_count, img_barriers);
2977ec681f3Smrg}
2987ec681f3Smrg
2997ec681f3Smrgstatic void
3007ec681f3Smrgvn_present_src_attachment_to_image_memory_barrier(
3017ec681f3Smrg   const struct vn_image *img,
3027ec681f3Smrg   const struct vn_present_src_attachment *att,
3037ec681f3Smrg   VkImageMemoryBarrier *img_barrier)
3047ec681f3Smrg{
3057ec681f3Smrg   *img_barrier = (VkImageMemoryBarrier)
3067ec681f3Smrg   {
3077ec681f3Smrg      .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
3087ec681f3Smrg      .srcAccessMask = att->src_access_mask,
3097ec681f3Smrg      .dstAccessMask = att->dst_access_mask,
3107ec681f3Smrg      .oldLayout = att->acquire ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
3117ec681f3Smrg                                : VN_PRESENT_SRC_INTERNAL_LAYOUT,
3127ec681f3Smrg      .newLayout = att->acquire ? VN_PRESENT_SRC_INTERNAL_LAYOUT
3137ec681f3Smrg                                : VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
3147ec681f3Smrg      .image = vn_image_to_handle((struct vn_image *)img),
3157ec681f3Smrg      .subresourceRange = {
3167ec681f3Smrg         .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
3177ec681f3Smrg         .levelCount = 1,
3187ec681f3Smrg         .layerCount = 1,
3197ec681f3Smrg      },
3207ec681f3Smrg   };
3217ec681f3Smrg}
3227ec681f3Smrg
3237ec681f3Smrgstatic void
3247ec681f3Smrgvn_cmd_transfer_present_src_images(
3257ec681f3Smrg   struct vn_command_buffer *cmd,
3267ec681f3Smrg   const struct vn_image *const *images,
3277ec681f3Smrg   const struct vn_present_src_attachment *atts,
3287ec681f3Smrg   uint32_t count)
3297ec681f3Smrg{
3307ec681f3Smrg   VkImageMemoryBarrier *img_barriers =
3317ec681f3Smrg      vn_cmd_get_image_memory_barriers(cmd, count);
3327ec681f3Smrg   if (!img_barriers) {
3337ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
3347ec681f3Smrg      return;
3357ec681f3Smrg   }
3367ec681f3Smrg
3377ec681f3Smrg   VkPipelineStageFlags src_stage_mask = 0;
3387ec681f3Smrg   VkPipelineStageFlags dst_stage_mask = 0;
3397ec681f3Smrg   for (uint32_t i = 0; i < count; i++) {
3407ec681f3Smrg      src_stage_mask |= atts[i].src_stage_mask;
3417ec681f3Smrg      dst_stage_mask |= atts[i].dst_stage_mask;
3427ec681f3Smrg
3437ec681f3Smrg      vn_present_src_attachment_to_image_memory_barrier(images[i], &atts[i],
3447ec681f3Smrg                                                        &img_barriers[i]);
3457ec681f3Smrg      vn_cmd_fix_image_memory_barrier(cmd, &img_barriers[i],
3467ec681f3Smrg                                      &img_barriers[i]);
3477ec681f3Smrg   }
3487ec681f3Smrg
3497ec681f3Smrg   if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
3507ec681f3Smrg      return;
3517ec681f3Smrg
3527ec681f3Smrg   vn_cmd_encode_memory_barriers(cmd, src_stage_mask, dst_stage_mask, 0, NULL,
3537ec681f3Smrg                                 count, img_barriers);
3547ec681f3Smrg}
3557ec681f3Smrg
3567ec681f3Smrgstatic void
3577ec681f3Smrgvn_cmd_begin_render_pass(struct vn_command_buffer *cmd,
3587ec681f3Smrg                         const struct vn_render_pass *pass,
3597ec681f3Smrg                         const struct vn_framebuffer *fb,
3607ec681f3Smrg                         const VkRenderPassBeginInfo *begin_info)
3617ec681f3Smrg{
3627ec681f3Smrg   cmd->builder.render_pass = pass;
3637ec681f3Smrg   cmd->builder.framebuffer = fb;
3647ec681f3Smrg
3657ec681f3Smrg   if (!pass->present_src_count ||
3667ec681f3Smrg       cmd->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY)
3677ec681f3Smrg      return;
3687ec681f3Smrg
3697ec681f3Smrg   /* find fb attachments */
3707ec681f3Smrg   const VkImageView *views;
3717ec681f3Smrg   ASSERTED uint32_t view_count;
3727ec681f3Smrg   if (fb->image_view_count) {
3737ec681f3Smrg      views = fb->image_views;
3747ec681f3Smrg      view_count = fb->image_view_count;
3757ec681f3Smrg   } else {
3767ec681f3Smrg      const VkRenderPassAttachmentBeginInfo *imageless_info =
3777ec681f3Smrg         vk_find_struct_const(begin_info->pNext,
3787ec681f3Smrg                              RENDER_PASS_ATTACHMENT_BEGIN_INFO);
3797ec681f3Smrg      assert(imageless_info);
3807ec681f3Smrg      views = imageless_info->pAttachments;
3817ec681f3Smrg      view_count = imageless_info->attachmentCount;
3827ec681f3Smrg   }
3837ec681f3Smrg
3847ec681f3Smrg   const struct vn_image **images =
3857ec681f3Smrg      vk_alloc(&cmd->allocator, sizeof(*images) * pass->present_src_count,
3867ec681f3Smrg               VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
3877ec681f3Smrg   if (!images) {
3887ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
3897ec681f3Smrg      return;
3907ec681f3Smrg   }
3917ec681f3Smrg
3927ec681f3Smrg   for (uint32_t i = 0; i < pass->present_src_count; i++) {
3937ec681f3Smrg      const uint32_t index = pass->present_src_attachments[i].index;
3947ec681f3Smrg      assert(index < view_count);
3957ec681f3Smrg      images[i] = vn_image_view_from_handle(views[index])->image;
3967ec681f3Smrg   }
3977ec681f3Smrg
3987ec681f3Smrg   if (pass->acquire_count) {
3997ec681f3Smrg      vn_cmd_transfer_present_src_images(
4007ec681f3Smrg         cmd, images, pass->present_src_attachments, pass->acquire_count);
4017ec681f3Smrg   }
4027ec681f3Smrg
4037ec681f3Smrg   cmd->builder.present_src_images = images;
4047ec681f3Smrg}
4057ec681f3Smrg
4067ec681f3Smrgstatic void
4077ec681f3Smrgvn_cmd_end_render_pass(struct vn_command_buffer *cmd)
4087ec681f3Smrg{
4097ec681f3Smrg   const struct vn_render_pass *pass = cmd->builder.render_pass;
4107ec681f3Smrg
4117ec681f3Smrg   cmd->builder.render_pass = NULL;
4127ec681f3Smrg   cmd->builder.framebuffer = NULL;
4137ec681f3Smrg
4147ec681f3Smrg   if (!pass->present_src_count || !cmd->builder.present_src_images)
4157ec681f3Smrg      return;
4167ec681f3Smrg
4177ec681f3Smrg   const struct vn_image **images = cmd->builder.present_src_images;
4187ec681f3Smrg   cmd->builder.present_src_images = NULL;
4197ec681f3Smrg
4207ec681f3Smrg   if (pass->release_count) {
4217ec681f3Smrg      vn_cmd_transfer_present_src_images(
4227ec681f3Smrg         cmd, images + pass->acquire_count,
4237ec681f3Smrg         pass->present_src_attachments + pass->acquire_count,
4247ec681f3Smrg         pass->release_count);
4257ec681f3Smrg   }
4267ec681f3Smrg
4277ec681f3Smrg   vk_free(&cmd->allocator, images);
4287ec681f3Smrg}
4297ec681f3Smrg
4307ec681f3Smrg/* command pool commands */
4317ec681f3Smrg
4327ec681f3SmrgVkResult
4337ec681f3Smrgvn_CreateCommandPool(VkDevice device,
4347ec681f3Smrg                     const VkCommandPoolCreateInfo *pCreateInfo,
4357ec681f3Smrg                     const VkAllocationCallbacks *pAllocator,
4367ec681f3Smrg                     VkCommandPool *pCommandPool)
4377ec681f3Smrg{
4387ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
4397ec681f3Smrg   const VkAllocationCallbacks *alloc =
4407ec681f3Smrg      pAllocator ? pAllocator : &dev->base.base.alloc;
4417ec681f3Smrg
4427ec681f3Smrg   struct vn_command_pool *pool =
4437ec681f3Smrg      vk_zalloc(alloc, sizeof(*pool), VN_DEFAULT_ALIGN,
4447ec681f3Smrg                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
4457ec681f3Smrg   if (!pool)
4467ec681f3Smrg      return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
4477ec681f3Smrg
4487ec681f3Smrg   vn_object_base_init(&pool->base, VK_OBJECT_TYPE_COMMAND_POOL, &dev->base);
4497ec681f3Smrg
4507ec681f3Smrg   pool->allocator = *alloc;
4517ec681f3Smrg   pool->queue_family_index = pCreateInfo->queueFamilyIndex;
4527ec681f3Smrg   list_inithead(&pool->command_buffers);
4537ec681f3Smrg
4547ec681f3Smrg   VkCommandPool pool_handle = vn_command_pool_to_handle(pool);
4557ec681f3Smrg   vn_async_vkCreateCommandPool(dev->instance, device, pCreateInfo, NULL,
4567ec681f3Smrg                                &pool_handle);
4577ec681f3Smrg
4587ec681f3Smrg   *pCommandPool = pool_handle;
4597ec681f3Smrg
4607ec681f3Smrg   return VK_SUCCESS;
4617ec681f3Smrg}
4627ec681f3Smrg
4637ec681f3Smrgvoid
4647ec681f3Smrgvn_DestroyCommandPool(VkDevice device,
4657ec681f3Smrg                      VkCommandPool commandPool,
4667ec681f3Smrg                      const VkAllocationCallbacks *pAllocator)
4677ec681f3Smrg{
4687ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
4697ec681f3Smrg   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
4707ec681f3Smrg   const VkAllocationCallbacks *alloc;
4717ec681f3Smrg
4727ec681f3Smrg   if (!pool)
4737ec681f3Smrg      return;
4747ec681f3Smrg
4757ec681f3Smrg   alloc = pAllocator ? pAllocator : &pool->allocator;
4767ec681f3Smrg
4777ec681f3Smrg   /* We must emit vkDestroyCommandPool before freeing the command buffers in
4787ec681f3Smrg    * pool->command_buffers.  Otherwise, another thread might reuse their
4797ec681f3Smrg    * object ids while they still refer to the command buffers in the
4807ec681f3Smrg    * renderer.
4817ec681f3Smrg    */
4827ec681f3Smrg   vn_async_vkDestroyCommandPool(dev->instance, device, commandPool, NULL);
4837ec681f3Smrg
4847ec681f3Smrg   list_for_each_entry_safe(struct vn_command_buffer, cmd,
4857ec681f3Smrg                            &pool->command_buffers, head) {
4867ec681f3Smrg      vn_cs_encoder_fini(&cmd->cs);
4877ec681f3Smrg      vn_object_base_fini(&cmd->base);
4887ec681f3Smrg      vk_free(alloc, cmd);
4897ec681f3Smrg   }
4907ec681f3Smrg
4917ec681f3Smrg   vn_object_base_fini(&pool->base);
4927ec681f3Smrg   vk_free(alloc, pool);
4937ec681f3Smrg}
4947ec681f3Smrg
4957ec681f3SmrgVkResult
4967ec681f3Smrgvn_ResetCommandPool(VkDevice device,
4977ec681f3Smrg                    VkCommandPool commandPool,
4987ec681f3Smrg                    VkCommandPoolResetFlags flags)
4997ec681f3Smrg{
5007ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
5017ec681f3Smrg   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
5027ec681f3Smrg
5037ec681f3Smrg   list_for_each_entry_safe(struct vn_command_buffer, cmd,
5047ec681f3Smrg                            &pool->command_buffers, head) {
5057ec681f3Smrg      vn_cs_encoder_reset(&cmd->cs);
5067ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
5077ec681f3Smrg   }
5087ec681f3Smrg
5097ec681f3Smrg   vn_async_vkResetCommandPool(dev->instance, device, commandPool, flags);
5107ec681f3Smrg
5117ec681f3Smrg   return VK_SUCCESS;
5127ec681f3Smrg}
5137ec681f3Smrg
5147ec681f3Smrgvoid
5157ec681f3Smrgvn_TrimCommandPool(VkDevice device,
5167ec681f3Smrg                   VkCommandPool commandPool,
5177ec681f3Smrg                   VkCommandPoolTrimFlags flags)
5187ec681f3Smrg{
5197ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
5207ec681f3Smrg
5217ec681f3Smrg   vn_async_vkTrimCommandPool(dev->instance, device, commandPool, flags);
5227ec681f3Smrg}
5237ec681f3Smrg
5247ec681f3Smrg/* command buffer commands */
5257ec681f3Smrg
5267ec681f3SmrgVkResult
5277ec681f3Smrgvn_AllocateCommandBuffers(VkDevice device,
5287ec681f3Smrg                          const VkCommandBufferAllocateInfo *pAllocateInfo,
5297ec681f3Smrg                          VkCommandBuffer *pCommandBuffers)
5307ec681f3Smrg{
5317ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
5327ec681f3Smrg   struct vn_command_pool *pool =
5337ec681f3Smrg      vn_command_pool_from_handle(pAllocateInfo->commandPool);
5347ec681f3Smrg   const VkAllocationCallbacks *alloc = &pool->allocator;
5357ec681f3Smrg
5367ec681f3Smrg   for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
5377ec681f3Smrg      struct vn_command_buffer *cmd =
5387ec681f3Smrg         vk_zalloc(alloc, sizeof(*cmd), VN_DEFAULT_ALIGN,
5397ec681f3Smrg                   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
5407ec681f3Smrg      if (!cmd) {
5417ec681f3Smrg         for (uint32_t j = 0; j < i; j++) {
5427ec681f3Smrg            cmd = vn_command_buffer_from_handle(pCommandBuffers[j]);
5437ec681f3Smrg            vn_cs_encoder_fini(&cmd->cs);
5447ec681f3Smrg            list_del(&cmd->head);
5457ec681f3Smrg            vn_object_base_fini(&cmd->base);
5467ec681f3Smrg            vk_free(alloc, cmd);
5477ec681f3Smrg         }
5487ec681f3Smrg         memset(pCommandBuffers, 0,
5497ec681f3Smrg                sizeof(*pCommandBuffers) * pAllocateInfo->commandBufferCount);
5507ec681f3Smrg         return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
5517ec681f3Smrg      }
5527ec681f3Smrg
5537ec681f3Smrg      vn_object_base_init(&cmd->base, VK_OBJECT_TYPE_COMMAND_BUFFER,
5547ec681f3Smrg                          &dev->base);
5557ec681f3Smrg      cmd->device = dev;
5567ec681f3Smrg      cmd->allocator = pool->allocator;
5577ec681f3Smrg      cmd->level = pAllocateInfo->level;
5587ec681f3Smrg      cmd->queue_family_index = pool->queue_family_index;
5597ec681f3Smrg
5607ec681f3Smrg      list_addtail(&cmd->head, &pool->command_buffers);
5617ec681f3Smrg
5627ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
5637ec681f3Smrg      vn_cs_encoder_init_indirect(&cmd->cs, dev->instance, 16 * 1024);
5647ec681f3Smrg
5657ec681f3Smrg      VkCommandBuffer cmd_handle = vn_command_buffer_to_handle(cmd);
5667ec681f3Smrg      pCommandBuffers[i] = cmd_handle;
5677ec681f3Smrg   }
5687ec681f3Smrg
5697ec681f3Smrg   vn_async_vkAllocateCommandBuffers(dev->instance, device, pAllocateInfo,
5707ec681f3Smrg                                     pCommandBuffers);
5717ec681f3Smrg
5727ec681f3Smrg   return VK_SUCCESS;
5737ec681f3Smrg}
5747ec681f3Smrg
5757ec681f3Smrgvoid
5767ec681f3Smrgvn_FreeCommandBuffers(VkDevice device,
5777ec681f3Smrg                      VkCommandPool commandPool,
5787ec681f3Smrg                      uint32_t commandBufferCount,
5797ec681f3Smrg                      const VkCommandBuffer *pCommandBuffers)
5807ec681f3Smrg{
5817ec681f3Smrg   struct vn_device *dev = vn_device_from_handle(device);
5827ec681f3Smrg   struct vn_command_pool *pool = vn_command_pool_from_handle(commandPool);
5837ec681f3Smrg   const VkAllocationCallbacks *alloc = &pool->allocator;
5847ec681f3Smrg
5857ec681f3Smrg   vn_async_vkFreeCommandBuffers(dev->instance, device, commandPool,
5867ec681f3Smrg                                 commandBufferCount, pCommandBuffers);
5877ec681f3Smrg
5887ec681f3Smrg   for (uint32_t i = 0; i < commandBufferCount; i++) {
5897ec681f3Smrg      struct vn_command_buffer *cmd =
5907ec681f3Smrg         vn_command_buffer_from_handle(pCommandBuffers[i]);
5917ec681f3Smrg
5927ec681f3Smrg      if (!cmd)
5937ec681f3Smrg         continue;
5947ec681f3Smrg
5957ec681f3Smrg      if (cmd->builder.image_barriers)
5967ec681f3Smrg         vk_free(alloc, cmd->builder.image_barriers);
5977ec681f3Smrg
5987ec681f3Smrg      vn_cs_encoder_fini(&cmd->cs);
5997ec681f3Smrg      list_del(&cmd->head);
6007ec681f3Smrg
6017ec681f3Smrg      vn_object_base_fini(&cmd->base);
6027ec681f3Smrg      vk_free(alloc, cmd);
6037ec681f3Smrg   }
6047ec681f3Smrg}
6057ec681f3Smrg
6067ec681f3SmrgVkResult
6077ec681f3Smrgvn_ResetCommandBuffer(VkCommandBuffer commandBuffer,
6087ec681f3Smrg                      VkCommandBufferResetFlags flags)
6097ec681f3Smrg{
6107ec681f3Smrg   struct vn_command_buffer *cmd =
6117ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
6127ec681f3Smrg
6137ec681f3Smrg   vn_cs_encoder_reset(&cmd->cs);
6147ec681f3Smrg   cmd->state = VN_COMMAND_BUFFER_STATE_INITIAL;
6157ec681f3Smrg
6167ec681f3Smrg   vn_async_vkResetCommandBuffer(cmd->device->instance, commandBuffer, flags);
6177ec681f3Smrg
6187ec681f3Smrg   return VK_SUCCESS;
6197ec681f3Smrg}
6207ec681f3Smrg
6217ec681f3SmrgVkResult
6227ec681f3Smrgvn_BeginCommandBuffer(VkCommandBuffer commandBuffer,
6237ec681f3Smrg                      const VkCommandBufferBeginInfo *pBeginInfo)
6247ec681f3Smrg{
6257ec681f3Smrg   struct vn_command_buffer *cmd =
6267ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
6277ec681f3Smrg   struct vn_instance *instance = cmd->device->instance;
6287ec681f3Smrg   size_t cmd_size;
6297ec681f3Smrg
6307ec681f3Smrg   vn_cs_encoder_reset(&cmd->cs);
6317ec681f3Smrg
6327ec681f3Smrg   VkCommandBufferBeginInfo local_begin_info;
6337ec681f3Smrg   if (pBeginInfo->pInheritanceInfo &&
6347ec681f3Smrg       cmd->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
6357ec681f3Smrg      local_begin_info = *pBeginInfo;
6367ec681f3Smrg      local_begin_info.pInheritanceInfo = NULL;
6377ec681f3Smrg      pBeginInfo = &local_begin_info;
6387ec681f3Smrg   }
6397ec681f3Smrg
6407ec681f3Smrg   cmd_size = vn_sizeof_vkBeginCommandBuffer(commandBuffer, pBeginInfo);
6417ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size)) {
6427ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
6437ec681f3Smrg      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
6447ec681f3Smrg   }
6457ec681f3Smrg
6467ec681f3Smrg   vn_encode_vkBeginCommandBuffer(&cmd->cs, 0, commandBuffer, pBeginInfo);
6477ec681f3Smrg
6487ec681f3Smrg   cmd->state = VN_COMMAND_BUFFER_STATE_RECORDING;
6497ec681f3Smrg
6507ec681f3Smrg   if (cmd->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY &&
6517ec681f3Smrg       (pBeginInfo->flags &
6527ec681f3Smrg        VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
6537ec681f3Smrg      const VkCommandBufferInheritanceInfo *inheritance_info =
6547ec681f3Smrg         pBeginInfo->pInheritanceInfo;
6557ec681f3Smrg      vn_cmd_begin_render_pass(
6567ec681f3Smrg         cmd, vn_render_pass_from_handle(inheritance_info->renderPass),
6577ec681f3Smrg         vn_framebuffer_from_handle(inheritance_info->framebuffer), NULL);
6587ec681f3Smrg   }
6597ec681f3Smrg
6607ec681f3Smrg   return VK_SUCCESS;
6617ec681f3Smrg}
6627ec681f3Smrg
6637ec681f3Smrgstatic VkResult
6647ec681f3Smrgvn_cmd_submit(struct vn_command_buffer *cmd)
6657ec681f3Smrg{
6667ec681f3Smrg   struct vn_instance *instance = cmd->device->instance;
6677ec681f3Smrg
6687ec681f3Smrg   if (cmd->state != VN_COMMAND_BUFFER_STATE_RECORDING)
6697ec681f3Smrg      return VK_ERROR_OUT_OF_HOST_MEMORY;
6707ec681f3Smrg
6717ec681f3Smrg   vn_cs_encoder_commit(&cmd->cs);
6727ec681f3Smrg   if (vn_cs_encoder_get_fatal(&cmd->cs)) {
6737ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
6747ec681f3Smrg      vn_cs_encoder_reset(&cmd->cs);
6757ec681f3Smrg      return VK_ERROR_OUT_OF_HOST_MEMORY;
6767ec681f3Smrg   }
6777ec681f3Smrg
6787ec681f3Smrg   vn_instance_wait_roundtrip(instance, cmd->cs.current_buffer_roundtrip);
6797ec681f3Smrg   VkResult result = vn_instance_ring_submit(instance, &cmd->cs);
6807ec681f3Smrg   if (result != VK_SUCCESS) {
6817ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
6827ec681f3Smrg      return result;
6837ec681f3Smrg   }
6847ec681f3Smrg
6857ec681f3Smrg   vn_cs_encoder_reset(&cmd->cs);
6867ec681f3Smrg
6877ec681f3Smrg   return VK_SUCCESS;
6887ec681f3Smrg}
6897ec681f3Smrg
6907ec681f3SmrgVkResult
6917ec681f3Smrgvn_EndCommandBuffer(VkCommandBuffer commandBuffer)
6927ec681f3Smrg{
6937ec681f3Smrg   struct vn_command_buffer *cmd =
6947ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
6957ec681f3Smrg   struct vn_instance *instance = cmd->device->instance;
6967ec681f3Smrg   size_t cmd_size;
6977ec681f3Smrg
6987ec681f3Smrg   cmd_size = vn_sizeof_vkEndCommandBuffer(commandBuffer);
6997ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size)) {
7007ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
7017ec681f3Smrg      return vn_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
7027ec681f3Smrg   }
7037ec681f3Smrg
7047ec681f3Smrg   vn_encode_vkEndCommandBuffer(&cmd->cs, 0, commandBuffer);
7057ec681f3Smrg
7067ec681f3Smrg   VkResult result = vn_cmd_submit(cmd);
7077ec681f3Smrg   if (result != VK_SUCCESS) {
7087ec681f3Smrg      cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
7097ec681f3Smrg      return vn_error(instance, result);
7107ec681f3Smrg   }
7117ec681f3Smrg
7127ec681f3Smrg   cmd->state = VN_COMMAND_BUFFER_STATE_EXECUTABLE;
7137ec681f3Smrg
7147ec681f3Smrg   return VK_SUCCESS;
7157ec681f3Smrg}
7167ec681f3Smrg
7177ec681f3Smrgvoid
7187ec681f3Smrgvn_CmdBindPipeline(VkCommandBuffer commandBuffer,
7197ec681f3Smrg                   VkPipelineBindPoint pipelineBindPoint,
7207ec681f3Smrg                   VkPipeline pipeline)
7217ec681f3Smrg{
7227ec681f3Smrg   struct vn_command_buffer *cmd =
7237ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
7247ec681f3Smrg   size_t cmd_size;
7257ec681f3Smrg
7267ec681f3Smrg   cmd_size =
7277ec681f3Smrg      vn_sizeof_vkCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
7287ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
7297ec681f3Smrg      return;
7307ec681f3Smrg
7317ec681f3Smrg   vn_encode_vkCmdBindPipeline(&cmd->cs, 0, commandBuffer, pipelineBindPoint,
7327ec681f3Smrg                               pipeline);
7337ec681f3Smrg}
7347ec681f3Smrg
7357ec681f3Smrgvoid
7367ec681f3Smrgvn_CmdSetViewport(VkCommandBuffer commandBuffer,
7377ec681f3Smrg                  uint32_t firstViewport,
7387ec681f3Smrg                  uint32_t viewportCount,
7397ec681f3Smrg                  const VkViewport *pViewports)
7407ec681f3Smrg{
7417ec681f3Smrg   struct vn_command_buffer *cmd =
7427ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
7437ec681f3Smrg   size_t cmd_size;
7447ec681f3Smrg
7457ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetViewport(commandBuffer, firstViewport,
7467ec681f3Smrg                                         viewportCount, pViewports);
7477ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
7487ec681f3Smrg      return;
7497ec681f3Smrg
7507ec681f3Smrg   vn_encode_vkCmdSetViewport(&cmd->cs, 0, commandBuffer, firstViewport,
7517ec681f3Smrg                              viewportCount, pViewports);
7527ec681f3Smrg}
7537ec681f3Smrg
7547ec681f3Smrgvoid
7557ec681f3Smrgvn_CmdSetScissor(VkCommandBuffer commandBuffer,
7567ec681f3Smrg                 uint32_t firstScissor,
7577ec681f3Smrg                 uint32_t scissorCount,
7587ec681f3Smrg                 const VkRect2D *pScissors)
7597ec681f3Smrg{
7607ec681f3Smrg   struct vn_command_buffer *cmd =
7617ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
7627ec681f3Smrg   size_t cmd_size;
7637ec681f3Smrg
7647ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetScissor(commandBuffer, firstScissor,
7657ec681f3Smrg                                        scissorCount, pScissors);
7667ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
7677ec681f3Smrg      return;
7687ec681f3Smrg
7697ec681f3Smrg   vn_encode_vkCmdSetScissor(&cmd->cs, 0, commandBuffer, firstScissor,
7707ec681f3Smrg                             scissorCount, pScissors);
7717ec681f3Smrg}
7727ec681f3Smrg
7737ec681f3Smrgvoid
7747ec681f3Smrgvn_CmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
7757ec681f3Smrg{
7767ec681f3Smrg   struct vn_command_buffer *cmd =
7777ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
7787ec681f3Smrg   size_t cmd_size;
7797ec681f3Smrg
7807ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetLineWidth(commandBuffer, lineWidth);
7817ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
7827ec681f3Smrg      return;
7837ec681f3Smrg
7847ec681f3Smrg   vn_encode_vkCmdSetLineWidth(&cmd->cs, 0, commandBuffer, lineWidth);
7857ec681f3Smrg}
7867ec681f3Smrg
7877ec681f3Smrgvoid
7887ec681f3Smrgvn_CmdSetDepthBias(VkCommandBuffer commandBuffer,
7897ec681f3Smrg                   float depthBiasConstantFactor,
7907ec681f3Smrg                   float depthBiasClamp,
7917ec681f3Smrg                   float depthBiasSlopeFactor)
7927ec681f3Smrg{
7937ec681f3Smrg   struct vn_command_buffer *cmd =
7947ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
7957ec681f3Smrg   size_t cmd_size;
7967ec681f3Smrg
7977ec681f3Smrg   cmd_size =
7987ec681f3Smrg      vn_sizeof_vkCmdSetDepthBias(commandBuffer, depthBiasConstantFactor,
7997ec681f3Smrg                                  depthBiasClamp, depthBiasSlopeFactor);
8007ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8017ec681f3Smrg      return;
8027ec681f3Smrg
8037ec681f3Smrg   vn_encode_vkCmdSetDepthBias(&cmd->cs, 0, commandBuffer,
8047ec681f3Smrg                               depthBiasConstantFactor, depthBiasClamp,
8057ec681f3Smrg                               depthBiasSlopeFactor);
8067ec681f3Smrg}
8077ec681f3Smrg
8087ec681f3Smrgvoid
8097ec681f3Smrgvn_CmdSetBlendConstants(VkCommandBuffer commandBuffer,
8107ec681f3Smrg                        const float blendConstants[4])
8117ec681f3Smrg{
8127ec681f3Smrg   struct vn_command_buffer *cmd =
8137ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
8147ec681f3Smrg   size_t cmd_size;
8157ec681f3Smrg
8167ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetBlendConstants(commandBuffer, blendConstants);
8177ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8187ec681f3Smrg      return;
8197ec681f3Smrg
8207ec681f3Smrg   vn_encode_vkCmdSetBlendConstants(&cmd->cs, 0, commandBuffer,
8217ec681f3Smrg                                    blendConstants);
8227ec681f3Smrg}
8237ec681f3Smrg
8247ec681f3Smrgvoid
8257ec681f3Smrgvn_CmdSetDepthBounds(VkCommandBuffer commandBuffer,
8267ec681f3Smrg                     float minDepthBounds,
8277ec681f3Smrg                     float maxDepthBounds)
8287ec681f3Smrg{
8297ec681f3Smrg   struct vn_command_buffer *cmd =
8307ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
8317ec681f3Smrg   size_t cmd_size;
8327ec681f3Smrg
8337ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetDepthBounds(commandBuffer, minDepthBounds,
8347ec681f3Smrg                                            maxDepthBounds);
8357ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8367ec681f3Smrg      return;
8377ec681f3Smrg
8387ec681f3Smrg   vn_encode_vkCmdSetDepthBounds(&cmd->cs, 0, commandBuffer, minDepthBounds,
8397ec681f3Smrg                                 maxDepthBounds);
8407ec681f3Smrg}
8417ec681f3Smrg
8427ec681f3Smrgvoid
8437ec681f3Smrgvn_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer,
8447ec681f3Smrg                            VkStencilFaceFlags faceMask,
8457ec681f3Smrg                            uint32_t compareMask)
8467ec681f3Smrg{
8477ec681f3Smrg   struct vn_command_buffer *cmd =
8487ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
8497ec681f3Smrg   size_t cmd_size;
8507ec681f3Smrg
8517ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetStencilCompareMask(commandBuffer, faceMask,
8527ec681f3Smrg                                                   compareMask);
8537ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8547ec681f3Smrg      return;
8557ec681f3Smrg
8567ec681f3Smrg   vn_encode_vkCmdSetStencilCompareMask(&cmd->cs, 0, commandBuffer, faceMask,
8577ec681f3Smrg                                        compareMask);
8587ec681f3Smrg}
8597ec681f3Smrg
8607ec681f3Smrgvoid
8617ec681f3Smrgvn_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer,
8627ec681f3Smrg                          VkStencilFaceFlags faceMask,
8637ec681f3Smrg                          uint32_t writeMask)
8647ec681f3Smrg{
8657ec681f3Smrg   struct vn_command_buffer *cmd =
8667ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
8677ec681f3Smrg   size_t cmd_size;
8687ec681f3Smrg
8697ec681f3Smrg   cmd_size =
8707ec681f3Smrg      vn_sizeof_vkCmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
8717ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8727ec681f3Smrg      return;
8737ec681f3Smrg
8747ec681f3Smrg   vn_encode_vkCmdSetStencilWriteMask(&cmd->cs, 0, commandBuffer, faceMask,
8757ec681f3Smrg                                      writeMask);
8767ec681f3Smrg}
8777ec681f3Smrg
8787ec681f3Smrgvoid
8797ec681f3Smrgvn_CmdSetStencilReference(VkCommandBuffer commandBuffer,
8807ec681f3Smrg                          VkStencilFaceFlags faceMask,
8817ec681f3Smrg                          uint32_t reference)
8827ec681f3Smrg{
8837ec681f3Smrg   struct vn_command_buffer *cmd =
8847ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
8857ec681f3Smrg   size_t cmd_size;
8867ec681f3Smrg
8877ec681f3Smrg   cmd_size =
8887ec681f3Smrg      vn_sizeof_vkCmdSetStencilReference(commandBuffer, faceMask, reference);
8897ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
8907ec681f3Smrg      return;
8917ec681f3Smrg
8927ec681f3Smrg   vn_encode_vkCmdSetStencilReference(&cmd->cs, 0, commandBuffer, faceMask,
8937ec681f3Smrg                                      reference);
8947ec681f3Smrg}
8957ec681f3Smrg
8967ec681f3Smrgvoid
8977ec681f3Smrgvn_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
8987ec681f3Smrg                         VkPipelineBindPoint pipelineBindPoint,
8997ec681f3Smrg                         VkPipelineLayout layout,
9007ec681f3Smrg                         uint32_t firstSet,
9017ec681f3Smrg                         uint32_t descriptorSetCount,
9027ec681f3Smrg                         const VkDescriptorSet *pDescriptorSets,
9037ec681f3Smrg                         uint32_t dynamicOffsetCount,
9047ec681f3Smrg                         const uint32_t *pDynamicOffsets)
9057ec681f3Smrg{
9067ec681f3Smrg   struct vn_command_buffer *cmd =
9077ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
9087ec681f3Smrg   size_t cmd_size;
9097ec681f3Smrg
9107ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBindDescriptorSets(
9117ec681f3Smrg      commandBuffer, pipelineBindPoint, layout, firstSet, descriptorSetCount,
9127ec681f3Smrg      pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
9137ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
9147ec681f3Smrg      return;
9157ec681f3Smrg
9167ec681f3Smrg   vn_encode_vkCmdBindDescriptorSets(&cmd->cs, 0, commandBuffer,
9177ec681f3Smrg                                     pipelineBindPoint, layout, firstSet,
9187ec681f3Smrg                                     descriptorSetCount, pDescriptorSets,
9197ec681f3Smrg                                     dynamicOffsetCount, pDynamicOffsets);
9207ec681f3Smrg}
9217ec681f3Smrg
9227ec681f3Smrgvoid
9237ec681f3Smrgvn_CmdBindIndexBuffer(VkCommandBuffer commandBuffer,
9247ec681f3Smrg                      VkBuffer buffer,
9257ec681f3Smrg                      VkDeviceSize offset,
9267ec681f3Smrg                      VkIndexType indexType)
9277ec681f3Smrg{
9287ec681f3Smrg   struct vn_command_buffer *cmd =
9297ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
9307ec681f3Smrg   size_t cmd_size;
9317ec681f3Smrg
9327ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBindIndexBuffer(commandBuffer, buffer, offset,
9337ec681f3Smrg                                             indexType);
9347ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
9357ec681f3Smrg      return;
9367ec681f3Smrg
9377ec681f3Smrg   vn_encode_vkCmdBindIndexBuffer(&cmd->cs, 0, commandBuffer, buffer, offset,
9387ec681f3Smrg                                  indexType);
9397ec681f3Smrg}
9407ec681f3Smrg
9417ec681f3Smrgvoid
9427ec681f3Smrgvn_CmdBindVertexBuffers(VkCommandBuffer commandBuffer,
9437ec681f3Smrg                        uint32_t firstBinding,
9447ec681f3Smrg                        uint32_t bindingCount,
9457ec681f3Smrg                        const VkBuffer *pBuffers,
9467ec681f3Smrg                        const VkDeviceSize *pOffsets)
9477ec681f3Smrg{
9487ec681f3Smrg   struct vn_command_buffer *cmd =
9497ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
9507ec681f3Smrg   size_t cmd_size;
9517ec681f3Smrg
9527ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBindVertexBuffers(
9537ec681f3Smrg      commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
9547ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
9557ec681f3Smrg      return;
9567ec681f3Smrg
9577ec681f3Smrg   vn_encode_vkCmdBindVertexBuffers(&cmd->cs, 0, commandBuffer, firstBinding,
9587ec681f3Smrg                                    bindingCount, pBuffers, pOffsets);
9597ec681f3Smrg}
9607ec681f3Smrg
9617ec681f3Smrgvoid
9627ec681f3Smrgvn_CmdDraw(VkCommandBuffer commandBuffer,
9637ec681f3Smrg           uint32_t vertexCount,
9647ec681f3Smrg           uint32_t instanceCount,
9657ec681f3Smrg           uint32_t firstVertex,
9667ec681f3Smrg           uint32_t firstInstance)
9677ec681f3Smrg{
9687ec681f3Smrg   struct vn_command_buffer *cmd =
9697ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
9707ec681f3Smrg   size_t cmd_size;
9717ec681f3Smrg
9727ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDraw(commandBuffer, vertexCount, instanceCount,
9737ec681f3Smrg                                  firstVertex, firstInstance);
9747ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
9757ec681f3Smrg      return;
9767ec681f3Smrg
9777ec681f3Smrg   vn_encode_vkCmdDraw(&cmd->cs, 0, commandBuffer, vertexCount, instanceCount,
9787ec681f3Smrg                       firstVertex, firstInstance);
9797ec681f3Smrg}
9807ec681f3Smrg
9817ec681f3Smrgvoid
9827ec681f3Smrgvn_CmdDrawIndexed(VkCommandBuffer commandBuffer,
9837ec681f3Smrg                  uint32_t indexCount,
9847ec681f3Smrg                  uint32_t instanceCount,
9857ec681f3Smrg                  uint32_t firstIndex,
9867ec681f3Smrg                  int32_t vertexOffset,
9877ec681f3Smrg                  uint32_t firstInstance)
9887ec681f3Smrg{
9897ec681f3Smrg   struct vn_command_buffer *cmd =
9907ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
9917ec681f3Smrg   size_t cmd_size;
9927ec681f3Smrg
9937ec681f3Smrg   cmd_size =
9947ec681f3Smrg      vn_sizeof_vkCmdDrawIndexed(commandBuffer, indexCount, instanceCount,
9957ec681f3Smrg                                 firstIndex, vertexOffset, firstInstance);
9967ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
9977ec681f3Smrg      return;
9987ec681f3Smrg
9997ec681f3Smrg   vn_encode_vkCmdDrawIndexed(&cmd->cs, 0, commandBuffer, indexCount,
10007ec681f3Smrg                              instanceCount, firstIndex, vertexOffset,
10017ec681f3Smrg                              firstInstance);
10027ec681f3Smrg}
10037ec681f3Smrg
10047ec681f3Smrgvoid
10057ec681f3Smrgvn_CmdDrawIndirect(VkCommandBuffer commandBuffer,
10067ec681f3Smrg                   VkBuffer buffer,
10077ec681f3Smrg                   VkDeviceSize offset,
10087ec681f3Smrg                   uint32_t drawCount,
10097ec681f3Smrg                   uint32_t stride)
10107ec681f3Smrg{
10117ec681f3Smrg   struct vn_command_buffer *cmd =
10127ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
10137ec681f3Smrg   size_t cmd_size;
10147ec681f3Smrg
10157ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDrawIndirect(commandBuffer, buffer, offset,
10167ec681f3Smrg                                          drawCount, stride);
10177ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
10187ec681f3Smrg      return;
10197ec681f3Smrg
10207ec681f3Smrg   vn_encode_vkCmdDrawIndirect(&cmd->cs, 0, commandBuffer, buffer, offset,
10217ec681f3Smrg                               drawCount, stride);
10227ec681f3Smrg}
10237ec681f3Smrg
10247ec681f3Smrgvoid
10257ec681f3Smrgvn_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer,
10267ec681f3Smrg                          VkBuffer buffer,
10277ec681f3Smrg                          VkDeviceSize offset,
10287ec681f3Smrg                          uint32_t drawCount,
10297ec681f3Smrg                          uint32_t stride)
10307ec681f3Smrg{
10317ec681f3Smrg   struct vn_command_buffer *cmd =
10327ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
10337ec681f3Smrg   size_t cmd_size;
10347ec681f3Smrg
10357ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDrawIndexedIndirect(commandBuffer, buffer,
10367ec681f3Smrg                                                 offset, drawCount, stride);
10377ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
10387ec681f3Smrg      return;
10397ec681f3Smrg
10407ec681f3Smrg   vn_encode_vkCmdDrawIndexedIndirect(&cmd->cs, 0, commandBuffer, buffer,
10417ec681f3Smrg                                      offset, drawCount, stride);
10427ec681f3Smrg}
10437ec681f3Smrg
10447ec681f3Smrgvoid
10457ec681f3Smrgvn_CmdDrawIndirectCount(VkCommandBuffer commandBuffer,
10467ec681f3Smrg                        VkBuffer buffer,
10477ec681f3Smrg                        VkDeviceSize offset,
10487ec681f3Smrg                        VkBuffer countBuffer,
10497ec681f3Smrg                        VkDeviceSize countBufferOffset,
10507ec681f3Smrg                        uint32_t maxDrawCount,
10517ec681f3Smrg                        uint32_t stride)
10527ec681f3Smrg{
10537ec681f3Smrg   struct vn_command_buffer *cmd =
10547ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
10557ec681f3Smrg   size_t cmd_size;
10567ec681f3Smrg
10577ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDrawIndirectCount(commandBuffer, buffer, offset,
10587ec681f3Smrg                                               countBuffer, countBufferOffset,
10597ec681f3Smrg                                               maxDrawCount, stride);
10607ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
10617ec681f3Smrg      return;
10627ec681f3Smrg
10637ec681f3Smrg   vn_encode_vkCmdDrawIndirectCount(&cmd->cs, 0, commandBuffer, buffer,
10647ec681f3Smrg                                    offset, countBuffer, countBufferOffset,
10657ec681f3Smrg                                    maxDrawCount, stride);
10667ec681f3Smrg}
10677ec681f3Smrg
10687ec681f3Smrgvoid
10697ec681f3Smrgvn_CmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer,
10707ec681f3Smrg                               VkBuffer buffer,
10717ec681f3Smrg                               VkDeviceSize offset,
10727ec681f3Smrg                               VkBuffer countBuffer,
10737ec681f3Smrg                               VkDeviceSize countBufferOffset,
10747ec681f3Smrg                               uint32_t maxDrawCount,
10757ec681f3Smrg                               uint32_t stride)
10767ec681f3Smrg{
10777ec681f3Smrg   struct vn_command_buffer *cmd =
10787ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
10797ec681f3Smrg   size_t cmd_size;
10807ec681f3Smrg
10817ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDrawIndexedIndirectCount(
10827ec681f3Smrg      commandBuffer, buffer, offset, countBuffer, countBufferOffset,
10837ec681f3Smrg      maxDrawCount, stride);
10847ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
10857ec681f3Smrg      return;
10867ec681f3Smrg
10877ec681f3Smrg   vn_encode_vkCmdDrawIndexedIndirectCount(
10887ec681f3Smrg      &cmd->cs, 0, commandBuffer, buffer, offset, countBuffer,
10897ec681f3Smrg      countBufferOffset, maxDrawCount, stride);
10907ec681f3Smrg}
10917ec681f3Smrg
10927ec681f3Smrgvoid
10937ec681f3Smrgvn_CmdDispatch(VkCommandBuffer commandBuffer,
10947ec681f3Smrg               uint32_t groupCountX,
10957ec681f3Smrg               uint32_t groupCountY,
10967ec681f3Smrg               uint32_t groupCountZ)
10977ec681f3Smrg{
10987ec681f3Smrg   struct vn_command_buffer *cmd =
10997ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
11007ec681f3Smrg   size_t cmd_size;
11017ec681f3Smrg
11027ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDispatch(commandBuffer, groupCountX, groupCountY,
11037ec681f3Smrg                                      groupCountZ);
11047ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
11057ec681f3Smrg      return;
11067ec681f3Smrg
11077ec681f3Smrg   vn_encode_vkCmdDispatch(&cmd->cs, 0, commandBuffer, groupCountX,
11087ec681f3Smrg                           groupCountY, groupCountZ);
11097ec681f3Smrg}
11107ec681f3Smrg
11117ec681f3Smrgvoid
11127ec681f3Smrgvn_CmdDispatchIndirect(VkCommandBuffer commandBuffer,
11137ec681f3Smrg                       VkBuffer buffer,
11147ec681f3Smrg                       VkDeviceSize offset)
11157ec681f3Smrg{
11167ec681f3Smrg   struct vn_command_buffer *cmd =
11177ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
11187ec681f3Smrg   size_t cmd_size;
11197ec681f3Smrg
11207ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDispatchIndirect(commandBuffer, buffer, offset);
11217ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
11227ec681f3Smrg      return;
11237ec681f3Smrg
11247ec681f3Smrg   vn_encode_vkCmdDispatchIndirect(&cmd->cs, 0, commandBuffer, buffer,
11257ec681f3Smrg                                   offset);
11267ec681f3Smrg}
11277ec681f3Smrg
11287ec681f3Smrgvoid
11297ec681f3Smrgvn_CmdCopyBuffer(VkCommandBuffer commandBuffer,
11307ec681f3Smrg                 VkBuffer srcBuffer,
11317ec681f3Smrg                 VkBuffer dstBuffer,
11327ec681f3Smrg                 uint32_t regionCount,
11337ec681f3Smrg                 const VkBufferCopy *pRegions)
11347ec681f3Smrg{
11357ec681f3Smrg   struct vn_command_buffer *cmd =
11367ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
11377ec681f3Smrg   size_t cmd_size;
11387ec681f3Smrg
11397ec681f3Smrg   cmd_size = vn_sizeof_vkCmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer,
11407ec681f3Smrg                                        regionCount, pRegions);
11417ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
11427ec681f3Smrg      return;
11437ec681f3Smrg
11447ec681f3Smrg   vn_encode_vkCmdCopyBuffer(&cmd->cs, 0, commandBuffer, srcBuffer, dstBuffer,
11457ec681f3Smrg                             regionCount, pRegions);
11467ec681f3Smrg}
11477ec681f3Smrg
11487ec681f3Smrgvoid
11497ec681f3Smrgvn_CmdCopyImage(VkCommandBuffer commandBuffer,
11507ec681f3Smrg                VkImage srcImage,
11517ec681f3Smrg                VkImageLayout srcImageLayout,
11527ec681f3Smrg                VkImage dstImage,
11537ec681f3Smrg                VkImageLayout dstImageLayout,
11547ec681f3Smrg                uint32_t regionCount,
11557ec681f3Smrg                const VkImageCopy *pRegions)
11567ec681f3Smrg{
11577ec681f3Smrg   struct vn_command_buffer *cmd =
11587ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
11597ec681f3Smrg   size_t cmd_size;
11607ec681f3Smrg
11617ec681f3Smrg   cmd_size = vn_sizeof_vkCmdCopyImage(commandBuffer, srcImage,
11627ec681f3Smrg                                       srcImageLayout, dstImage,
11637ec681f3Smrg                                       dstImageLayout, regionCount, pRegions);
11647ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
11657ec681f3Smrg      return;
11667ec681f3Smrg
11677ec681f3Smrg   vn_encode_vkCmdCopyImage(&cmd->cs, 0, commandBuffer, srcImage,
11687ec681f3Smrg                            srcImageLayout, dstImage, dstImageLayout,
11697ec681f3Smrg                            regionCount, pRegions);
11707ec681f3Smrg}
11717ec681f3Smrg
11727ec681f3Smrgvoid
11737ec681f3Smrgvn_CmdBlitImage(VkCommandBuffer commandBuffer,
11747ec681f3Smrg                VkImage srcImage,
11757ec681f3Smrg                VkImageLayout srcImageLayout,
11767ec681f3Smrg                VkImage dstImage,
11777ec681f3Smrg                VkImageLayout dstImageLayout,
11787ec681f3Smrg                uint32_t regionCount,
11797ec681f3Smrg                const VkImageBlit *pRegions,
11807ec681f3Smrg                VkFilter filter)
11817ec681f3Smrg{
11827ec681f3Smrg   struct vn_command_buffer *cmd =
11837ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
11847ec681f3Smrg   size_t cmd_size;
11857ec681f3Smrg
11867ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBlitImage(
11877ec681f3Smrg      commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout,
11887ec681f3Smrg      regionCount, pRegions, filter);
11897ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
11907ec681f3Smrg      return;
11917ec681f3Smrg
11927ec681f3Smrg   vn_encode_vkCmdBlitImage(&cmd->cs, 0, commandBuffer, srcImage,
11937ec681f3Smrg                            srcImageLayout, dstImage, dstImageLayout,
11947ec681f3Smrg                            regionCount, pRegions, filter);
11957ec681f3Smrg}
11967ec681f3Smrg
11977ec681f3Smrgvoid
11987ec681f3Smrgvn_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,
11997ec681f3Smrg                        VkBuffer srcBuffer,
12007ec681f3Smrg                        VkImage dstImage,
12017ec681f3Smrg                        VkImageLayout dstImageLayout,
12027ec681f3Smrg                        uint32_t regionCount,
12037ec681f3Smrg                        const VkBufferImageCopy *pRegions)
12047ec681f3Smrg{
12057ec681f3Smrg   struct vn_command_buffer *cmd =
12067ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
12077ec681f3Smrg   size_t cmd_size;
12087ec681f3Smrg
12097ec681f3Smrg   cmd_size =
12107ec681f3Smrg      vn_sizeof_vkCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage,
12117ec681f3Smrg                                       dstImageLayout, regionCount, pRegions);
12127ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
12137ec681f3Smrg      return;
12147ec681f3Smrg
12157ec681f3Smrg   vn_encode_vkCmdCopyBufferToImage(&cmd->cs, 0, commandBuffer, srcBuffer,
12167ec681f3Smrg                                    dstImage, dstImageLayout, regionCount,
12177ec681f3Smrg                                    pRegions);
12187ec681f3Smrg}
12197ec681f3Smrg
12207ec681f3Smrgvoid
12217ec681f3Smrgvn_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
12227ec681f3Smrg                        VkImage srcImage,
12237ec681f3Smrg                        VkImageLayout srcImageLayout,
12247ec681f3Smrg                        VkBuffer dstBuffer,
12257ec681f3Smrg                        uint32_t regionCount,
12267ec681f3Smrg                        const VkBufferImageCopy *pRegions)
12277ec681f3Smrg{
12287ec681f3Smrg   struct vn_command_buffer *cmd =
12297ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
12307ec681f3Smrg   size_t cmd_size;
12317ec681f3Smrg
12327ec681f3Smrg   bool prime_blit = false;
12337ec681f3Smrg   if (srcImageLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR &&
12347ec681f3Smrg       VN_PRESENT_SRC_INTERNAL_LAYOUT != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
12357ec681f3Smrg      srcImageLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
12367ec681f3Smrg
12377ec681f3Smrg      /* sanity check */
12387ec681f3Smrg      const struct vn_image *img = vn_image_from_handle(srcImage);
12397ec681f3Smrg      prime_blit = img->is_wsi && img->is_prime_blit_src;
12407ec681f3Smrg      assert(prime_blit);
12417ec681f3Smrg   }
12427ec681f3Smrg
12437ec681f3Smrg   cmd_size = vn_sizeof_vkCmdCopyImageToBuffer(commandBuffer, srcImage,
12447ec681f3Smrg                                               srcImageLayout, dstBuffer,
12457ec681f3Smrg                                               regionCount, pRegions);
12467ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
12477ec681f3Smrg      return;
12487ec681f3Smrg
12497ec681f3Smrg   vn_encode_vkCmdCopyImageToBuffer(&cmd->cs, 0, commandBuffer, srcImage,
12507ec681f3Smrg                                    srcImageLayout, dstBuffer, regionCount,
12517ec681f3Smrg                                    pRegions);
12527ec681f3Smrg
12537ec681f3Smrg   if (prime_blit) {
12547ec681f3Smrg      const VkBufferMemoryBarrier buf_barrier = {
12557ec681f3Smrg         .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
12567ec681f3Smrg         .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
12577ec681f3Smrg         .srcQueueFamilyIndex = cmd->queue_family_index,
12587ec681f3Smrg         .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT,
12597ec681f3Smrg         .buffer = dstBuffer,
12607ec681f3Smrg         .size = VK_WHOLE_SIZE,
12617ec681f3Smrg      };
12627ec681f3Smrg      vn_cmd_encode_memory_barriers(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT,
12637ec681f3Smrg                                    VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 1,
12647ec681f3Smrg                                    &buf_barrier, 0, NULL);
12657ec681f3Smrg   }
12667ec681f3Smrg}
12677ec681f3Smrg
12687ec681f3Smrgvoid
12697ec681f3Smrgvn_CmdUpdateBuffer(VkCommandBuffer commandBuffer,
12707ec681f3Smrg                   VkBuffer dstBuffer,
12717ec681f3Smrg                   VkDeviceSize dstOffset,
12727ec681f3Smrg                   VkDeviceSize dataSize,
12737ec681f3Smrg                   const void *pData)
12747ec681f3Smrg{
12757ec681f3Smrg   struct vn_command_buffer *cmd =
12767ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
12777ec681f3Smrg   size_t cmd_size;
12787ec681f3Smrg
12797ec681f3Smrg   cmd_size = vn_sizeof_vkCmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset,
12807ec681f3Smrg                                          dataSize, pData);
12817ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
12827ec681f3Smrg      return;
12837ec681f3Smrg
12847ec681f3Smrg   vn_encode_vkCmdUpdateBuffer(&cmd->cs, 0, commandBuffer, dstBuffer,
12857ec681f3Smrg                               dstOffset, dataSize, pData);
12867ec681f3Smrg}
12877ec681f3Smrg
12887ec681f3Smrgvoid
12897ec681f3Smrgvn_CmdFillBuffer(VkCommandBuffer commandBuffer,
12907ec681f3Smrg                 VkBuffer dstBuffer,
12917ec681f3Smrg                 VkDeviceSize dstOffset,
12927ec681f3Smrg                 VkDeviceSize size,
12937ec681f3Smrg                 uint32_t data)
12947ec681f3Smrg{
12957ec681f3Smrg   struct vn_command_buffer *cmd =
12967ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
12977ec681f3Smrg   size_t cmd_size;
12987ec681f3Smrg
12997ec681f3Smrg   cmd_size = vn_sizeof_vkCmdFillBuffer(commandBuffer, dstBuffer, dstOffset,
13007ec681f3Smrg                                        size, data);
13017ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
13027ec681f3Smrg      return;
13037ec681f3Smrg
13047ec681f3Smrg   vn_encode_vkCmdFillBuffer(&cmd->cs, 0, commandBuffer, dstBuffer, dstOffset,
13057ec681f3Smrg                             size, data);
13067ec681f3Smrg}
13077ec681f3Smrg
13087ec681f3Smrgvoid
13097ec681f3Smrgvn_CmdClearColorImage(VkCommandBuffer commandBuffer,
13107ec681f3Smrg                      VkImage image,
13117ec681f3Smrg                      VkImageLayout imageLayout,
13127ec681f3Smrg                      const VkClearColorValue *pColor,
13137ec681f3Smrg                      uint32_t rangeCount,
13147ec681f3Smrg                      const VkImageSubresourceRange *pRanges)
13157ec681f3Smrg{
13167ec681f3Smrg   struct vn_command_buffer *cmd =
13177ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
13187ec681f3Smrg   size_t cmd_size;
13197ec681f3Smrg
13207ec681f3Smrg   cmd_size = vn_sizeof_vkCmdClearColorImage(
13217ec681f3Smrg      commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
13227ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
13237ec681f3Smrg      return;
13247ec681f3Smrg
13257ec681f3Smrg   vn_encode_vkCmdClearColorImage(&cmd->cs, 0, commandBuffer, image,
13267ec681f3Smrg                                  imageLayout, pColor, rangeCount, pRanges);
13277ec681f3Smrg}
13287ec681f3Smrg
13297ec681f3Smrgvoid
13307ec681f3Smrgvn_CmdClearDepthStencilImage(VkCommandBuffer commandBuffer,
13317ec681f3Smrg                             VkImage image,
13327ec681f3Smrg                             VkImageLayout imageLayout,
13337ec681f3Smrg                             const VkClearDepthStencilValue *pDepthStencil,
13347ec681f3Smrg                             uint32_t rangeCount,
13357ec681f3Smrg                             const VkImageSubresourceRange *pRanges)
13367ec681f3Smrg{
13377ec681f3Smrg   struct vn_command_buffer *cmd =
13387ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
13397ec681f3Smrg   size_t cmd_size;
13407ec681f3Smrg
13417ec681f3Smrg   cmd_size = vn_sizeof_vkCmdClearDepthStencilImage(
13427ec681f3Smrg      commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
13437ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
13447ec681f3Smrg      return;
13457ec681f3Smrg
13467ec681f3Smrg   vn_encode_vkCmdClearDepthStencilImage(&cmd->cs, 0, commandBuffer, image,
13477ec681f3Smrg                                         imageLayout, pDepthStencil,
13487ec681f3Smrg                                         rangeCount, pRanges);
13497ec681f3Smrg}
13507ec681f3Smrg
13517ec681f3Smrgvoid
13527ec681f3Smrgvn_CmdClearAttachments(VkCommandBuffer commandBuffer,
13537ec681f3Smrg                       uint32_t attachmentCount,
13547ec681f3Smrg                       const VkClearAttachment *pAttachments,
13557ec681f3Smrg                       uint32_t rectCount,
13567ec681f3Smrg                       const VkClearRect *pRects)
13577ec681f3Smrg{
13587ec681f3Smrg   struct vn_command_buffer *cmd =
13597ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
13607ec681f3Smrg   size_t cmd_size;
13617ec681f3Smrg
13627ec681f3Smrg   cmd_size = vn_sizeof_vkCmdClearAttachments(
13637ec681f3Smrg      commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
13647ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
13657ec681f3Smrg      return;
13667ec681f3Smrg
13677ec681f3Smrg   vn_encode_vkCmdClearAttachments(&cmd->cs, 0, commandBuffer,
13687ec681f3Smrg                                   attachmentCount, pAttachments, rectCount,
13697ec681f3Smrg                                   pRects);
13707ec681f3Smrg}
13717ec681f3Smrg
13727ec681f3Smrgvoid
13737ec681f3Smrgvn_CmdResolveImage(VkCommandBuffer commandBuffer,
13747ec681f3Smrg                   VkImage srcImage,
13757ec681f3Smrg                   VkImageLayout srcImageLayout,
13767ec681f3Smrg                   VkImage dstImage,
13777ec681f3Smrg                   VkImageLayout dstImageLayout,
13787ec681f3Smrg                   uint32_t regionCount,
13797ec681f3Smrg                   const VkImageResolve *pRegions)
13807ec681f3Smrg{
13817ec681f3Smrg   struct vn_command_buffer *cmd =
13827ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
13837ec681f3Smrg   size_t cmd_size;
13847ec681f3Smrg
13857ec681f3Smrg   cmd_size = vn_sizeof_vkCmdResolveImage(
13867ec681f3Smrg      commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout,
13877ec681f3Smrg      regionCount, pRegions);
13887ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
13897ec681f3Smrg      return;
13907ec681f3Smrg
13917ec681f3Smrg   vn_encode_vkCmdResolveImage(&cmd->cs, 0, commandBuffer, srcImage,
13927ec681f3Smrg                               srcImageLayout, dstImage, dstImageLayout,
13937ec681f3Smrg                               regionCount, pRegions);
13947ec681f3Smrg}
13957ec681f3Smrg
13967ec681f3Smrgvoid
13977ec681f3Smrgvn_CmdSetEvent(VkCommandBuffer commandBuffer,
13987ec681f3Smrg               VkEvent event,
13997ec681f3Smrg               VkPipelineStageFlags stageMask)
14007ec681f3Smrg{
14017ec681f3Smrg   struct vn_command_buffer *cmd =
14027ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
14037ec681f3Smrg   size_t cmd_size;
14047ec681f3Smrg
14057ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetEvent(commandBuffer, event, stageMask);
14067ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
14077ec681f3Smrg      return;
14087ec681f3Smrg
14097ec681f3Smrg   vn_encode_vkCmdSetEvent(&cmd->cs, 0, commandBuffer, event, stageMask);
14107ec681f3Smrg}
14117ec681f3Smrg
14127ec681f3Smrgvoid
14137ec681f3Smrgvn_CmdResetEvent(VkCommandBuffer commandBuffer,
14147ec681f3Smrg                 VkEvent event,
14157ec681f3Smrg                 VkPipelineStageFlags stageMask)
14167ec681f3Smrg{
14177ec681f3Smrg   struct vn_command_buffer *cmd =
14187ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
14197ec681f3Smrg   size_t cmd_size;
14207ec681f3Smrg
14217ec681f3Smrg   cmd_size = vn_sizeof_vkCmdResetEvent(commandBuffer, event, stageMask);
14227ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
14237ec681f3Smrg      return;
14247ec681f3Smrg
14257ec681f3Smrg   vn_encode_vkCmdResetEvent(&cmd->cs, 0, commandBuffer, event, stageMask);
14267ec681f3Smrg}
14277ec681f3Smrg
14287ec681f3Smrgvoid
14297ec681f3Smrgvn_CmdWaitEvents(VkCommandBuffer commandBuffer,
14307ec681f3Smrg                 uint32_t eventCount,
14317ec681f3Smrg                 const VkEvent *pEvents,
14327ec681f3Smrg                 VkPipelineStageFlags srcStageMask,
14337ec681f3Smrg                 VkPipelineStageFlags dstStageMask,
14347ec681f3Smrg                 uint32_t memoryBarrierCount,
14357ec681f3Smrg                 const VkMemoryBarrier *pMemoryBarriers,
14367ec681f3Smrg                 uint32_t bufferMemoryBarrierCount,
14377ec681f3Smrg                 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
14387ec681f3Smrg                 uint32_t imageMemoryBarrierCount,
14397ec681f3Smrg                 const VkImageMemoryBarrier *pImageMemoryBarriers)
14407ec681f3Smrg{
14417ec681f3Smrg   struct vn_command_buffer *cmd =
14427ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
14437ec681f3Smrg   size_t cmd_size;
14447ec681f3Smrg
14457ec681f3Smrg   uint32_t transfer_count;
14467ec681f3Smrg   pImageMemoryBarriers = vn_cmd_wait_events_fix_image_memory_barriers(
14477ec681f3Smrg      cmd, pImageMemoryBarriers, imageMemoryBarrierCount, &transfer_count);
14487ec681f3Smrg   imageMemoryBarrierCount -= transfer_count;
14497ec681f3Smrg
14507ec681f3Smrg   cmd_size = vn_sizeof_vkCmdWaitEvents(
14517ec681f3Smrg      commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask,
14527ec681f3Smrg      memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount,
14537ec681f3Smrg      pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
14547ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
14557ec681f3Smrg      return;
14567ec681f3Smrg
14577ec681f3Smrg   vn_encode_vkCmdWaitEvents(&cmd->cs, 0, commandBuffer, eventCount, pEvents,
14587ec681f3Smrg                             srcStageMask, dstStageMask, memoryBarrierCount,
14597ec681f3Smrg                             pMemoryBarriers, bufferMemoryBarrierCount,
14607ec681f3Smrg                             pBufferMemoryBarriers, imageMemoryBarrierCount,
14617ec681f3Smrg                             pImageMemoryBarriers);
14627ec681f3Smrg
14637ec681f3Smrg   if (transfer_count) {
14647ec681f3Smrg      pImageMemoryBarriers += imageMemoryBarrierCount;
14657ec681f3Smrg      vn_cmd_encode_memory_barriers(cmd, srcStageMask, dstStageMask, 0, NULL,
14667ec681f3Smrg                                    transfer_count, pImageMemoryBarriers);
14677ec681f3Smrg   }
14687ec681f3Smrg}
14697ec681f3Smrg
14707ec681f3Smrgvoid
14717ec681f3Smrgvn_CmdPipelineBarrier(VkCommandBuffer commandBuffer,
14727ec681f3Smrg                      VkPipelineStageFlags srcStageMask,
14737ec681f3Smrg                      VkPipelineStageFlags dstStageMask,
14747ec681f3Smrg                      VkDependencyFlags dependencyFlags,
14757ec681f3Smrg                      uint32_t memoryBarrierCount,
14767ec681f3Smrg                      const VkMemoryBarrier *pMemoryBarriers,
14777ec681f3Smrg                      uint32_t bufferMemoryBarrierCount,
14787ec681f3Smrg                      const VkBufferMemoryBarrier *pBufferMemoryBarriers,
14797ec681f3Smrg                      uint32_t imageMemoryBarrierCount,
14807ec681f3Smrg                      const VkImageMemoryBarrier *pImageMemoryBarriers)
14817ec681f3Smrg{
14827ec681f3Smrg   struct vn_command_buffer *cmd =
14837ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
14847ec681f3Smrg   size_t cmd_size;
14857ec681f3Smrg
14867ec681f3Smrg   pImageMemoryBarriers = vn_cmd_pipeline_barrier_fix_image_memory_barriers(
14877ec681f3Smrg      cmd, pImageMemoryBarriers, imageMemoryBarrierCount);
14887ec681f3Smrg
14897ec681f3Smrg   cmd_size = vn_sizeof_vkCmdPipelineBarrier(
14907ec681f3Smrg      commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
14917ec681f3Smrg      memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount,
14927ec681f3Smrg      pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
14937ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
14947ec681f3Smrg      return;
14957ec681f3Smrg
14967ec681f3Smrg   vn_encode_vkCmdPipelineBarrier(
14977ec681f3Smrg      &cmd->cs, 0, commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
14987ec681f3Smrg      memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount,
14997ec681f3Smrg      pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
15007ec681f3Smrg}
15017ec681f3Smrg
15027ec681f3Smrgvoid
15037ec681f3Smrgvn_CmdBeginQuery(VkCommandBuffer commandBuffer,
15047ec681f3Smrg                 VkQueryPool queryPool,
15057ec681f3Smrg                 uint32_t query,
15067ec681f3Smrg                 VkQueryControlFlags flags)
15077ec681f3Smrg{
15087ec681f3Smrg   struct vn_command_buffer *cmd =
15097ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
15107ec681f3Smrg   size_t cmd_size;
15117ec681f3Smrg
15127ec681f3Smrg   cmd_size =
15137ec681f3Smrg      vn_sizeof_vkCmdBeginQuery(commandBuffer, queryPool, query, flags);
15147ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
15157ec681f3Smrg      return;
15167ec681f3Smrg
15177ec681f3Smrg   vn_encode_vkCmdBeginQuery(&cmd->cs, 0, commandBuffer, queryPool, query,
15187ec681f3Smrg                             flags);
15197ec681f3Smrg}
15207ec681f3Smrg
15217ec681f3Smrgvoid
15227ec681f3Smrgvn_CmdEndQuery(VkCommandBuffer commandBuffer,
15237ec681f3Smrg               VkQueryPool queryPool,
15247ec681f3Smrg               uint32_t query)
15257ec681f3Smrg{
15267ec681f3Smrg   struct vn_command_buffer *cmd =
15277ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
15287ec681f3Smrg   size_t cmd_size;
15297ec681f3Smrg
15307ec681f3Smrg   cmd_size = vn_sizeof_vkCmdEndQuery(commandBuffer, queryPool, query);
15317ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
15327ec681f3Smrg      return;
15337ec681f3Smrg
15347ec681f3Smrg   vn_encode_vkCmdEndQuery(&cmd->cs, 0, commandBuffer, queryPool, query);
15357ec681f3Smrg}
15367ec681f3Smrg
15377ec681f3Smrgvoid
15387ec681f3Smrgvn_CmdResetQueryPool(VkCommandBuffer commandBuffer,
15397ec681f3Smrg                     VkQueryPool queryPool,
15407ec681f3Smrg                     uint32_t firstQuery,
15417ec681f3Smrg                     uint32_t queryCount)
15427ec681f3Smrg{
15437ec681f3Smrg   struct vn_command_buffer *cmd =
15447ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
15457ec681f3Smrg   size_t cmd_size;
15467ec681f3Smrg
15477ec681f3Smrg   cmd_size = vn_sizeof_vkCmdResetQueryPool(commandBuffer, queryPool,
15487ec681f3Smrg                                            firstQuery, queryCount);
15497ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
15507ec681f3Smrg      return;
15517ec681f3Smrg
15527ec681f3Smrg   vn_encode_vkCmdResetQueryPool(&cmd->cs, 0, commandBuffer, queryPool,
15537ec681f3Smrg                                 firstQuery, queryCount);
15547ec681f3Smrg}
15557ec681f3Smrg
15567ec681f3Smrgvoid
15577ec681f3Smrgvn_CmdWriteTimestamp(VkCommandBuffer commandBuffer,
15587ec681f3Smrg                     VkPipelineStageFlagBits pipelineStage,
15597ec681f3Smrg                     VkQueryPool queryPool,
15607ec681f3Smrg                     uint32_t query)
15617ec681f3Smrg{
15627ec681f3Smrg   struct vn_command_buffer *cmd =
15637ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
15647ec681f3Smrg   size_t cmd_size;
15657ec681f3Smrg
15667ec681f3Smrg   cmd_size = vn_sizeof_vkCmdWriteTimestamp(commandBuffer, pipelineStage,
15677ec681f3Smrg                                            queryPool, query);
15687ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
15697ec681f3Smrg      return;
15707ec681f3Smrg
15717ec681f3Smrg   vn_encode_vkCmdWriteTimestamp(&cmd->cs, 0, commandBuffer, pipelineStage,
15727ec681f3Smrg                                 queryPool, query);
15737ec681f3Smrg}
15747ec681f3Smrg
15757ec681f3Smrgvoid
15767ec681f3Smrgvn_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer,
15777ec681f3Smrg                           VkQueryPool queryPool,
15787ec681f3Smrg                           uint32_t firstQuery,
15797ec681f3Smrg                           uint32_t queryCount,
15807ec681f3Smrg                           VkBuffer dstBuffer,
15817ec681f3Smrg                           VkDeviceSize dstOffset,
15827ec681f3Smrg                           VkDeviceSize stride,
15837ec681f3Smrg                           VkQueryResultFlags flags)
15847ec681f3Smrg{
15857ec681f3Smrg   struct vn_command_buffer *cmd =
15867ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
15877ec681f3Smrg   size_t cmd_size;
15887ec681f3Smrg
15897ec681f3Smrg   cmd_size = vn_sizeof_vkCmdCopyQueryPoolResults(
15907ec681f3Smrg      commandBuffer, queryPool, firstQuery, queryCount, dstBuffer, dstOffset,
15917ec681f3Smrg      stride, flags);
15927ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
15937ec681f3Smrg      return;
15947ec681f3Smrg
15957ec681f3Smrg   vn_encode_vkCmdCopyQueryPoolResults(&cmd->cs, 0, commandBuffer, queryPool,
15967ec681f3Smrg                                       firstQuery, queryCount, dstBuffer,
15977ec681f3Smrg                                       dstOffset, stride, flags);
15987ec681f3Smrg}
15997ec681f3Smrg
16007ec681f3Smrgvoid
16017ec681f3Smrgvn_CmdPushConstants(VkCommandBuffer commandBuffer,
16027ec681f3Smrg                    VkPipelineLayout layout,
16037ec681f3Smrg                    VkShaderStageFlags stageFlags,
16047ec681f3Smrg                    uint32_t offset,
16057ec681f3Smrg                    uint32_t size,
16067ec681f3Smrg                    const void *pValues)
16077ec681f3Smrg{
16087ec681f3Smrg   struct vn_command_buffer *cmd =
16097ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
16107ec681f3Smrg   size_t cmd_size;
16117ec681f3Smrg
16127ec681f3Smrg   cmd_size = vn_sizeof_vkCmdPushConstants(commandBuffer, layout, stageFlags,
16137ec681f3Smrg                                           offset, size, pValues);
16147ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
16157ec681f3Smrg      return;
16167ec681f3Smrg
16177ec681f3Smrg   vn_encode_vkCmdPushConstants(&cmd->cs, 0, commandBuffer, layout,
16187ec681f3Smrg                                stageFlags, offset, size, pValues);
16197ec681f3Smrg}
16207ec681f3Smrg
16217ec681f3Smrgvoid
16227ec681f3Smrgvn_CmdBeginRenderPass(VkCommandBuffer commandBuffer,
16237ec681f3Smrg                      const VkRenderPassBeginInfo *pRenderPassBegin,
16247ec681f3Smrg                      VkSubpassContents contents)
16257ec681f3Smrg{
16267ec681f3Smrg   struct vn_command_buffer *cmd =
16277ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
16287ec681f3Smrg   size_t cmd_size;
16297ec681f3Smrg
16307ec681f3Smrg   vn_cmd_begin_render_pass(
16317ec681f3Smrg      cmd, vn_render_pass_from_handle(pRenderPassBegin->renderPass),
16327ec681f3Smrg      vn_framebuffer_from_handle(pRenderPassBegin->framebuffer),
16337ec681f3Smrg      pRenderPassBegin);
16347ec681f3Smrg
16357ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBeginRenderPass(commandBuffer, pRenderPassBegin,
16367ec681f3Smrg                                             contents);
16377ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
16387ec681f3Smrg      return;
16397ec681f3Smrg
16407ec681f3Smrg   vn_encode_vkCmdBeginRenderPass(&cmd->cs, 0, commandBuffer,
16417ec681f3Smrg                                  pRenderPassBegin, contents);
16427ec681f3Smrg}
16437ec681f3Smrg
16447ec681f3Smrgvoid
16457ec681f3Smrgvn_CmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
16467ec681f3Smrg{
16477ec681f3Smrg   struct vn_command_buffer *cmd =
16487ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
16497ec681f3Smrg   size_t cmd_size;
16507ec681f3Smrg
16517ec681f3Smrg   cmd_size = vn_sizeof_vkCmdNextSubpass(commandBuffer, contents);
16527ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
16537ec681f3Smrg      return;
16547ec681f3Smrg
16557ec681f3Smrg   vn_encode_vkCmdNextSubpass(&cmd->cs, 0, commandBuffer, contents);
16567ec681f3Smrg}
16577ec681f3Smrg
16587ec681f3Smrgvoid
16597ec681f3Smrgvn_CmdEndRenderPass(VkCommandBuffer commandBuffer)
16607ec681f3Smrg{
16617ec681f3Smrg   struct vn_command_buffer *cmd =
16627ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
16637ec681f3Smrg   size_t cmd_size;
16647ec681f3Smrg
16657ec681f3Smrg   cmd_size = vn_sizeof_vkCmdEndRenderPass(commandBuffer);
16667ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
16677ec681f3Smrg      return;
16687ec681f3Smrg
16697ec681f3Smrg   vn_encode_vkCmdEndRenderPass(&cmd->cs, 0, commandBuffer);
16707ec681f3Smrg
16717ec681f3Smrg   vn_cmd_end_render_pass(cmd);
16727ec681f3Smrg}
16737ec681f3Smrg
16747ec681f3Smrgvoid
16757ec681f3Smrgvn_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
16767ec681f3Smrg                       const VkRenderPassBeginInfo *pRenderPassBegin,
16777ec681f3Smrg                       const VkSubpassBeginInfo *pSubpassBeginInfo)
16787ec681f3Smrg{
16797ec681f3Smrg   struct vn_command_buffer *cmd =
16807ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
16817ec681f3Smrg   size_t cmd_size;
16827ec681f3Smrg
16837ec681f3Smrg   vn_cmd_begin_render_pass(
16847ec681f3Smrg      cmd, vn_render_pass_from_handle(pRenderPassBegin->renderPass),
16857ec681f3Smrg      vn_framebuffer_from_handle(pRenderPassBegin->framebuffer),
16867ec681f3Smrg      pRenderPassBegin);
16877ec681f3Smrg
16887ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBeginRenderPass2(commandBuffer, pRenderPassBegin,
16897ec681f3Smrg                                              pSubpassBeginInfo);
16907ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
16917ec681f3Smrg      return;
16927ec681f3Smrg
16937ec681f3Smrg   vn_encode_vkCmdBeginRenderPass2(&cmd->cs, 0, commandBuffer,
16947ec681f3Smrg                                   pRenderPassBegin, pSubpassBeginInfo);
16957ec681f3Smrg}
16967ec681f3Smrg
16977ec681f3Smrgvoid
16987ec681f3Smrgvn_CmdNextSubpass2(VkCommandBuffer commandBuffer,
16997ec681f3Smrg                   const VkSubpassBeginInfo *pSubpassBeginInfo,
17007ec681f3Smrg                   const VkSubpassEndInfo *pSubpassEndInfo)
17017ec681f3Smrg{
17027ec681f3Smrg   struct vn_command_buffer *cmd =
17037ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17047ec681f3Smrg   size_t cmd_size;
17057ec681f3Smrg
17067ec681f3Smrg   cmd_size = vn_sizeof_vkCmdNextSubpass2(commandBuffer, pSubpassBeginInfo,
17077ec681f3Smrg                                          pSubpassEndInfo);
17087ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
17097ec681f3Smrg      return;
17107ec681f3Smrg
17117ec681f3Smrg   vn_encode_vkCmdNextSubpass2(&cmd->cs, 0, commandBuffer, pSubpassBeginInfo,
17127ec681f3Smrg                               pSubpassEndInfo);
17137ec681f3Smrg}
17147ec681f3Smrg
17157ec681f3Smrgvoid
17167ec681f3Smrgvn_CmdEndRenderPass2(VkCommandBuffer commandBuffer,
17177ec681f3Smrg                     const VkSubpassEndInfo *pSubpassEndInfo)
17187ec681f3Smrg{
17197ec681f3Smrg   struct vn_command_buffer *cmd =
17207ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17217ec681f3Smrg   size_t cmd_size;
17227ec681f3Smrg
17237ec681f3Smrg   cmd_size = vn_sizeof_vkCmdEndRenderPass2(commandBuffer, pSubpassEndInfo);
17247ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
17257ec681f3Smrg      return;
17267ec681f3Smrg
17277ec681f3Smrg   vn_encode_vkCmdEndRenderPass2(&cmd->cs, 0, commandBuffer, pSubpassEndInfo);
17287ec681f3Smrg
17297ec681f3Smrg   vn_cmd_end_render_pass(cmd);
17307ec681f3Smrg}
17317ec681f3Smrg
17327ec681f3Smrgvoid
17337ec681f3Smrgvn_CmdExecuteCommands(VkCommandBuffer commandBuffer,
17347ec681f3Smrg                      uint32_t commandBufferCount,
17357ec681f3Smrg                      const VkCommandBuffer *pCommandBuffers)
17367ec681f3Smrg{
17377ec681f3Smrg   struct vn_command_buffer *cmd =
17387ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17397ec681f3Smrg   size_t cmd_size;
17407ec681f3Smrg
17417ec681f3Smrg   cmd_size = vn_sizeof_vkCmdExecuteCommands(
17427ec681f3Smrg      commandBuffer, commandBufferCount, pCommandBuffers);
17437ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
17447ec681f3Smrg      return;
17457ec681f3Smrg
17467ec681f3Smrg   vn_encode_vkCmdExecuteCommands(&cmd->cs, 0, commandBuffer,
17477ec681f3Smrg                                  commandBufferCount, pCommandBuffers);
17487ec681f3Smrg}
17497ec681f3Smrg
17507ec681f3Smrgvoid
17517ec681f3Smrgvn_CmdSetDeviceMask(VkCommandBuffer commandBuffer, uint32_t deviceMask)
17527ec681f3Smrg{
17537ec681f3Smrg   struct vn_command_buffer *cmd =
17547ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17557ec681f3Smrg   size_t cmd_size;
17567ec681f3Smrg
17577ec681f3Smrg   cmd_size = vn_sizeof_vkCmdSetDeviceMask(commandBuffer, deviceMask);
17587ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
17597ec681f3Smrg      return;
17607ec681f3Smrg
17617ec681f3Smrg   vn_encode_vkCmdSetDeviceMask(&cmd->cs, 0, commandBuffer, deviceMask);
17627ec681f3Smrg}
17637ec681f3Smrg
17647ec681f3Smrgvoid
17657ec681f3Smrgvn_CmdDispatchBase(VkCommandBuffer commandBuffer,
17667ec681f3Smrg                   uint32_t baseGroupX,
17677ec681f3Smrg                   uint32_t baseGroupY,
17687ec681f3Smrg                   uint32_t baseGroupZ,
17697ec681f3Smrg                   uint32_t groupCountX,
17707ec681f3Smrg                   uint32_t groupCountY,
17717ec681f3Smrg                   uint32_t groupCountZ)
17727ec681f3Smrg{
17737ec681f3Smrg   struct vn_command_buffer *cmd =
17747ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17757ec681f3Smrg   size_t cmd_size;
17767ec681f3Smrg
17777ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDispatchBase(commandBuffer, baseGroupX,
17787ec681f3Smrg                                          baseGroupY, baseGroupZ, groupCountX,
17797ec681f3Smrg                                          groupCountY, groupCountZ);
17807ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
17817ec681f3Smrg      return;
17827ec681f3Smrg
17837ec681f3Smrg   vn_encode_vkCmdDispatchBase(&cmd->cs, 0, commandBuffer, baseGroupX,
17847ec681f3Smrg                               baseGroupY, baseGroupZ, groupCountX,
17857ec681f3Smrg                               groupCountY, groupCountZ);
17867ec681f3Smrg}
17877ec681f3Smrg
17887ec681f3Smrgvoid
17897ec681f3Smrgvn_CmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer,
17907ec681f3Smrg                           VkQueryPool queryPool,
17917ec681f3Smrg                           uint32_t query,
17927ec681f3Smrg                           VkQueryControlFlags flags,
17937ec681f3Smrg                           uint32_t index)
17947ec681f3Smrg{
17957ec681f3Smrg   struct vn_command_buffer *cmd =
17967ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
17977ec681f3Smrg   size_t cmd_size;
17987ec681f3Smrg
17997ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBeginQueryIndexedEXT(commandBuffer, queryPool,
18007ec681f3Smrg                                                  query, flags, index);
18017ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
18027ec681f3Smrg      return;
18037ec681f3Smrg
18047ec681f3Smrg   vn_encode_vkCmdBeginQueryIndexedEXT(&cmd->cs, 0, commandBuffer, queryPool,
18057ec681f3Smrg                                       query, flags, index);
18067ec681f3Smrg}
18077ec681f3Smrg
18087ec681f3Smrgvoid
18097ec681f3Smrgvn_CmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer,
18107ec681f3Smrg                         VkQueryPool queryPool,
18117ec681f3Smrg                         uint32_t query,
18127ec681f3Smrg                         uint32_t index)
18137ec681f3Smrg{
18147ec681f3Smrg   struct vn_command_buffer *cmd =
18157ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
18167ec681f3Smrg   size_t cmd_size;
18177ec681f3Smrg
18187ec681f3Smrg   cmd_size = vn_sizeof_vkCmdEndQueryIndexedEXT(commandBuffer, queryPool,
18197ec681f3Smrg                                                query, index);
18207ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
18217ec681f3Smrg      return;
18227ec681f3Smrg
18237ec681f3Smrg   vn_encode_vkCmdEndQueryIndexedEXT(&cmd->cs, 0, commandBuffer, queryPool,
18247ec681f3Smrg                                     query, index);
18257ec681f3Smrg}
18267ec681f3Smrg
18277ec681f3Smrgvoid
18287ec681f3Smrgvn_CmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer,
18297ec681f3Smrg                                      uint32_t firstBinding,
18307ec681f3Smrg                                      uint32_t bindingCount,
18317ec681f3Smrg                                      const VkBuffer *pBuffers,
18327ec681f3Smrg                                      const VkDeviceSize *pOffsets,
18337ec681f3Smrg                                      const VkDeviceSize *pSizes)
18347ec681f3Smrg{
18357ec681f3Smrg   struct vn_command_buffer *cmd =
18367ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
18377ec681f3Smrg   size_t cmd_size;
18387ec681f3Smrg
18397ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBindTransformFeedbackBuffersEXT(
18407ec681f3Smrg      commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes);
18417ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
18427ec681f3Smrg      return;
18437ec681f3Smrg
18447ec681f3Smrg   vn_encode_vkCmdBindTransformFeedbackBuffersEXT(&cmd->cs, 0, commandBuffer,
18457ec681f3Smrg                                                  firstBinding, bindingCount,
18467ec681f3Smrg                                                  pBuffers, pOffsets, pSizes);
18477ec681f3Smrg}
18487ec681f3Smrg
18497ec681f3Smrgvoid
18507ec681f3Smrgvn_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer,
18517ec681f3Smrg                                uint32_t firstCounterBuffer,
18527ec681f3Smrg                                uint32_t counterBufferCount,
18537ec681f3Smrg                                const VkBuffer *pCounterBuffers,
18547ec681f3Smrg                                const VkDeviceSize *pCounterBufferOffsets)
18557ec681f3Smrg{
18567ec681f3Smrg   struct vn_command_buffer *cmd =
18577ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
18587ec681f3Smrg   size_t cmd_size;
18597ec681f3Smrg
18607ec681f3Smrg   cmd_size = vn_sizeof_vkCmdBeginTransformFeedbackEXT(
18617ec681f3Smrg      commandBuffer, firstCounterBuffer, counterBufferCount, pCounterBuffers,
18627ec681f3Smrg      pCounterBufferOffsets);
18637ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
18647ec681f3Smrg      return;
18657ec681f3Smrg
18667ec681f3Smrg   vn_encode_vkCmdBeginTransformFeedbackEXT(
18677ec681f3Smrg      &cmd->cs, 0, commandBuffer, firstCounterBuffer, counterBufferCount,
18687ec681f3Smrg      pCounterBuffers, pCounterBufferOffsets);
18697ec681f3Smrg}
18707ec681f3Smrg
18717ec681f3Smrgvoid
18727ec681f3Smrgvn_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer,
18737ec681f3Smrg                              uint32_t firstCounterBuffer,
18747ec681f3Smrg                              uint32_t counterBufferCount,
18757ec681f3Smrg                              const VkBuffer *pCounterBuffers,
18767ec681f3Smrg                              const VkDeviceSize *pCounterBufferOffsets)
18777ec681f3Smrg{
18787ec681f3Smrg   struct vn_command_buffer *cmd =
18797ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
18807ec681f3Smrg   size_t cmd_size;
18817ec681f3Smrg
18827ec681f3Smrg   cmd_size = vn_sizeof_vkCmdEndTransformFeedbackEXT(
18837ec681f3Smrg      commandBuffer, firstCounterBuffer, counterBufferCount, pCounterBuffers,
18847ec681f3Smrg      pCounterBufferOffsets);
18857ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
18867ec681f3Smrg      return;
18877ec681f3Smrg
18887ec681f3Smrg   vn_encode_vkCmdEndTransformFeedbackEXT(
18897ec681f3Smrg      &cmd->cs, 0, commandBuffer, firstCounterBuffer, counterBufferCount,
18907ec681f3Smrg      pCounterBuffers, pCounterBufferOffsets);
18917ec681f3Smrg}
18927ec681f3Smrg
18937ec681f3Smrgvoid
18947ec681f3Smrgvn_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer,
18957ec681f3Smrg                               uint32_t instanceCount,
18967ec681f3Smrg                               uint32_t firstInstance,
18977ec681f3Smrg                               VkBuffer counterBuffer,
18987ec681f3Smrg                               VkDeviceSize counterBufferOffset,
18997ec681f3Smrg                               uint32_t counterOffset,
19007ec681f3Smrg                               uint32_t vertexStride)
19017ec681f3Smrg{
19027ec681f3Smrg   struct vn_command_buffer *cmd =
19037ec681f3Smrg      vn_command_buffer_from_handle(commandBuffer);
19047ec681f3Smrg   size_t cmd_size;
19057ec681f3Smrg
19067ec681f3Smrg   cmd_size = vn_sizeof_vkCmdDrawIndirectByteCountEXT(
19077ec681f3Smrg      commandBuffer, instanceCount, firstInstance, counterBuffer,
19087ec681f3Smrg      counterBufferOffset, counterOffset, vertexStride);
19097ec681f3Smrg   if (!vn_cs_encoder_reserve(&cmd->cs, cmd_size))
19107ec681f3Smrg      return;
19117ec681f3Smrg
19127ec681f3Smrg   vn_encode_vkCmdDrawIndirectByteCountEXT(
19137ec681f3Smrg      &cmd->cs, 0, commandBuffer, instanceCount, firstInstance, counterBuffer,
19147ec681f3Smrg      counterBufferOffset, counterOffset, vertexStride);
19157ec681f3Smrg}
1916