[Mesa-dev] [PATCH 32/33] anv: Use blorp for ClearColorImage

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


---
 src/intel/vulkan/anv_blorp.c      | 60 +++++++++++++++++++++++++++++++++++++++
 src/intel/vulkan/anv_meta_clear.c | 21 --------------
 2 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index e2b6672..bd4638d 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -663,3 +663,63 @@ void anv_CmdUpdateBuffer(
 
    blorp_batch_finish(&batch);
 }
+
+void anv_CmdClearColorImage(
+    VkCommandBuffer                             commandBuffer,
+    VkImage                                     _image,
+    VkImageLayout                               imageLayout,
+    const VkClearColorValue*                    pColor,
+    uint32_t                                    rangeCount,
+    const VkImageSubresourceRange*              pRanges)
+{
+   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
+   ANV_FROM_HANDLE(anv_image, image, _image);
+
+   static const bool color_write_disable[4] = { false, false, false, false };
+
+   struct blorp_batch batch;
+   blorp_batch_init(&cmd_buffer->device->blorp, &batch, cmd_buffer);
+
+   union isl_color_value clear_color;
+   memcpy(clear_color.u32, pColor->uint32, sizeof(pColor->uint32));
+
+   struct blorp_surf surf;
+   get_blorp_surf_for_anv_image(image, VK_IMAGE_ASPECT_COLOR_BIT, &surf);
+
+   for (unsigned r = 0; r < rangeCount; r++) {
+      if (pRanges[r].aspectMask == 0)
+         continue;
+
+      assert(pRanges[r].aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
+
+      struct anv_format src_format =
+         anv_get_format(&cmd_buffer->device->info, image->vk_format,
+                        VK_IMAGE_ASPECT_COLOR_BIT, image->tiling);
+
+      unsigned base_layer = pRanges[r].baseArrayLayer;
+      unsigned layer_count = pRanges[r].layerCount;
+
+      for (unsigned i = 0; i < pRanges[r].levelCount; i++) {
+         const unsigned level = pRanges[r].baseMipLevel + i;
+         const unsigned level_width = anv_minify(image->extent.width, level);
+         const unsigned level_height = anv_minify(image->extent.height, level);
+
+         if (image->type == VK_IMAGE_TYPE_3D) {
+            base_layer = 0;
+            layer_count = anv_minify(image->extent.depth, level);
+         }
+
+         for (unsigned j = 0; j < layer_count; j++) {
+            const unsigned layer = base_layer + j;
+
+            blorp_clear(&batch, &surf,
+                        src_format.isl_format, src_format.swizzle,
+                        level, layer,
+                        0, 0, level_width, level_height,
+                        clear_color, color_write_disable);
+         }
+      }
+   }
+
+   blorp_batch_finish(&batch);
+}
diff --git a/src/intel/vulkan/anv_meta_clear.c b/src/intel/vulkan/anv_meta_clear.c
index dddad34..ed4d1db 100644
--- a/src/intel/vulkan/anv_meta_clear.c
+++ b/src/intel/vulkan/anv_meta_clear.c
@@ -900,27 +900,6 @@ anv_cmd_clear_image(struct anv_cmd_buffer *cmd_buffer,
    }
 }
 
-void anv_CmdClearColorImage(
-    VkCommandBuffer                             commandBuffer,
-    VkImage                                     image_h,
-    VkImageLayout                               imageLayout,
-    const VkClearColorValue*                    pColor,
-    uint32_t                                    rangeCount,
-    const VkImageSubresourceRange*              pRanges)
-{
-   ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
-   ANV_FROM_HANDLE(anv_image, image, image_h);
-   struct anv_meta_saved_state saved_state;
-
-   meta_clear_begin(&saved_state, cmd_buffer);
-
-   anv_cmd_clear_image(cmd_buffer, image, imageLayout,
-                       (VkClearValue) { .color = *pColor },
-                       rangeCount, pRanges);
-
-   meta_clear_end(&saved_state, cmd_buffer);
-}
-
 void anv_CmdClearDepthStencilImage(
     VkCommandBuffer                             commandBuffer,
     VkImage                                     image_h,
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list