[Mesa-dev] [PATCH 28/33] anv: Use blorp for CopyBufferToImage

Jason Ekstrand jason at jlekstrand.net
Wed Aug 31 21:22:47 UTC 2016


---
 src/intel/vulkan/anv_blorp.c     |  16 +++++
 src/intel/vulkan/anv_meta_copy.c | 125 ---------------------------------------
 2 files changed, 16 insertions(+), 125 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index a838b55..5fa6699 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -254,6 +254,22 @@ copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
    blorp_batch_finish(&batch);
 }
 
+void anv_CmdCopyBufferToImage(
+    VkCommandBuffer                             commandBuffer,
+    VkBuffer                                    srcBuffer,
+    VkImage                                     dstImage,
+    VkImageLayout                               dstImageLayout,
+    uint32_t                                    regionCount,
+    const VkBufferImageCopy*                    pRegions)
+{
+   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
+   ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
+   ANV_FROM_HANDLE(anv_image, dst_image, dstImage);
+
+   copy_buffer_to_image(cmd_buffer, src_buffer, dst_image,
+                        regionCount, pRegions, true);
+}
+
 void anv_CmdCopyImageToBuffer(
     VkCommandBuffer                             commandBuffer,
     VkImage                                     srcImage,
diff --git a/src/intel/vulkan/anv_meta_copy.c b/src/intel/vulkan/anv_meta_copy.c
index a17dd63..5df04e6 100644
--- a/src/intel/vulkan/anv_meta_copy.c
+++ b/src/intel/vulkan/anv_meta_copy.c
@@ -107,131 +107,6 @@ do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
    anv_meta_blit2d(cmd_buffer, &b_src, &b_dst, 1, &rect);
 }
 
-static void
-meta_copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
-                          struct anv_buffer* buffer,
-                          struct anv_image* image,
-                          uint32_t regionCount,
-                          const VkBufferImageCopy* pRegions,
-                          bool forward)
-{
-   struct anv_meta_saved_state saved_state;
-
-   /* The Vulkan 1.0 spec says "dstImage must have a sample count equal to
-    * VK_SAMPLE_COUNT_1_BIT."
-    */
-   assert(image->samples == 1);
-
-   anv_meta_begin_blit2d(cmd_buffer, &saved_state);
-
-   for (unsigned r = 0; r < regionCount; r++) {
-
-      /**
-       * From the Vulkan 1.0.6 spec: 18.3 Copying Data Between Images
-       *    extent is the size in texels of the source image to copy in width,
-       *    height and depth. 1D images use only x and width. 2D images use x, y,
-       *    width and height. 3D images use x, y, z, width, height and depth.
-       *
-       *
-       * Also, convert the offsets and extent from units of texels to units of
-       * blocks - which is the highest resolution accessible in this command.
-       */
-      const VkOffset3D img_offset_el =
-         meta_region_offset_el(image, &pRegions[r].imageOffset);
-      const VkExtent3D bufferExtent = {
-         .width  = pRegions[r].bufferRowLength ?
-                   pRegions[r].bufferRowLength : pRegions[r].imageExtent.width,
-         .height = pRegions[r].bufferImageHeight ?
-                   pRegions[r].bufferImageHeight : pRegions[r].imageExtent.height,
-      };
-      const VkExtent3D buf_extent_el =
-         meta_region_extent_el(image, &bufferExtent);
-
-      /* Start creating blit rect */
-      const VkExtent3D img_extent_el =
-         meta_region_extent_el(image, &pRegions[r].imageExtent);
-      struct anv_meta_blit2d_rect rect = {
-         .width = img_extent_el.width,
-         .height =  img_extent_el.height,
-      };
-
-      /* Create blit surfaces */
-      VkImageAspectFlags aspect = pRegions[r].imageSubresource.aspectMask;
-      const struct anv_surface *img_surf =
-         anv_image_get_surface_for_aspect_mask(image, aspect);
-      struct anv_meta_blit2d_surf img_bsurf =
-         blit_surf_for_image(image, img_surf);
-      enum isl_format buf_format = anv_get_isl_format(&cmd_buffer->device->info,
-                                                      image->vk_format, aspect,
-                                                      VK_IMAGE_TILING_LINEAR);
-      struct anv_meta_blit2d_surf buf_bsurf = {
-         .bo = buffer->bo,
-         .tiling = ISL_TILING_LINEAR,
-         .base_offset = buffer->offset + pRegions[r].bufferOffset,
-         .bs = isl_format_get_layout(buf_format)->bpb / 8,
-         .pitch = buf_extent_el.width * buf_bsurf.bs,
-      };
-
-      /* Set direction-dependent variables */
-      struct anv_meta_blit2d_surf *dst_bsurf = forward ? &img_bsurf : &buf_bsurf;
-      struct anv_meta_blit2d_surf *src_bsurf = forward ? &buf_bsurf : &img_bsurf;
-      uint32_t *x_offset = forward ? &rect.dst_x : &rect.src_x;
-      uint32_t *y_offset = forward ? &rect.dst_y : &rect.src_y;
-
-      /* Loop through each 3D or array slice */
-      unsigned num_slices_3d = img_extent_el.depth;
-      unsigned num_slices_array = pRegions[r].imageSubresource.layerCount;
-      unsigned slice_3d = 0;
-      unsigned slice_array = 0;
-      while (slice_3d < num_slices_3d && slice_array < num_slices_array) {
-
-         /* Finish creating blit rect */
-         isl_surf_get_image_offset_el(&img_surf->isl,
-                                    pRegions[r].imageSubresource.mipLevel,
-                                    pRegions[r].imageSubresource.baseArrayLayer
-                                       + slice_array,
-                                    img_offset_el.z + slice_3d,
-                                    x_offset,
-                                    y_offset);
-         *x_offset += img_offset_el.x;
-         *y_offset += img_offset_el.y;
-
-         /* Perform Blit */
-         anv_meta_blit2d(cmd_buffer, src_bsurf, dst_bsurf, 1, &rect);
-
-         /* Once we've done the blit, all of the actual information about
-          * the image is embedded in the command buffer so we can just
-          * increment the offset directly in the image effectively
-          * re-binding it to different backing memory.
-          */
-         buf_bsurf.base_offset += buf_extent_el.width *
-                                  buf_extent_el.height * buf_bsurf.bs;
-
-         if (image->type == VK_IMAGE_TYPE_3D)
-            slice_3d++;
-         else
-            slice_array++;
-      }
-   }
-   anv_meta_end_blit2d(cmd_buffer, &saved_state);
-}
-
-void anv_CmdCopyBufferToImage(
-    VkCommandBuffer                             commandBuffer,
-    VkBuffer                                    srcBuffer,
-    VkImage                                     destImage,
-    VkImageLayout                               destImageLayout,
-    uint32_t                                    regionCount,
-    const VkBufferImageCopy*                    pRegions)
-{
-   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
-   ANV_FROM_HANDLE(anv_image, dest_image, destImage);
-   ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
-
-   meta_copy_buffer_to_image(cmd_buffer, src_buffer, dest_image,
-                             regionCount, pRegions, true);
-}
-
 void anv_CmdCopyImage(
     VkCommandBuffer                             commandBuffer,
     VkImage                                     srcImage,
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list