anv: Use blorp for ClearColorImage
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 30 Aug 2016 23:56:25 +0000 (16:56 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 13 Sep 2016 19:40:13 +0000 (12:40 -0700)
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/intel/vulkan/anv_blorp.c
src/intel/vulkan/anv_meta_clear.c

index 72d7bea7fb71625c51208711aea253a8b7eb5765..d056fcfa213601e0ba64d74f061c6cebec001d39 100644 (file)
@@ -666,3 +666,59 @@ 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);
+         }
+
+         blorp_clear(&batch, &surf,
+                     src_format.isl_format, src_format.swizzle,
+                     level, base_layer, layer_count,
+                     0, 0, level_width, level_height,
+                     clear_color, color_write_disable);
+      }
+   }
+
+   blorp_batch_finish(&batch);
+}
index dddad34cc313bec9f9c80912af206b13d41990f7..ed4d1db9d450cf25f48665c0850867a44e45effd 100644 (file)
@@ -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,