vk: Cache each render pass's number of clear ops
authorChad Versace <chad.versace@intel.com>
Thu, 20 Aug 2015 17:03:58 +0000 (10:03 -0700)
committerChad Versace <chad.versace@intel.com>
Thu, 20 Aug 2015 17:25:04 +0000 (10:25 -0700)
During vkCreateRenderPass, count the number of clear ops and store them
in new members of anv_render_pass:

    uint32_t num_color_clear_attachments
    bool has_depth_clear_attachment
    bool has_stencil_clear_attachment

Cacheing these 8 bytes (including padding) reduces the number of times
that anv_cmd_buffer_clear_attachments needs to loop over the pass's
attachments.

src/vulkan/anv_device.c
src/vulkan/anv_meta.c
src/vulkan/anv_private.h

index 5805ffab193e3e9dbaf4213d125b14b274af4b94..eaeae3b0a4ffe2021ebbfe7a42976c5397895a98 100644 (file)
@@ -2238,6 +2238,17 @@ VkResult anv_CreateRenderPass(
       att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
       // att->store_op = pCreateInfo->pAttachments[i].storeOp;
       // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
+
+      if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+         if (anv_format_is_color(att->format)) {
+            ++pass->num_color_clear_attachments;
+         } else if (att->format->depth_format) {
+            pass->has_depth_clear_attachment = true;
+         }
+      } else if (att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+         assert(att->format->has_stencil);
+         pass->has_stencil_clear_attachment = true;
+      }
    }
 
    for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
index add5f7d6d9be8d082ef108ef76e0995a26144f8b..b1f3fe7191b2dc7014aec9406eee8054fd209338 100644 (file)
@@ -272,22 +272,17 @@ anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
 {
    struct anv_saved_state saved_state;
 
-   int num_clear_layers = 0;
-   for (uint32_t i = 0; i < pass->attachment_count; i++) {
-      if (pass->attachments[i].load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
-         if (anv_format_is_depth_or_stencil(pass->attachments[i].format)) {
-            anv_finishme("Can't clear depth-stencil yet");
-            continue;
-         }
-         num_clear_layers++;
-      }
-   }
+   if (pass->has_depth_clear_attachment)
+      anv_finishme("depth clear");
+
+   if (pass->has_stencil_clear_attachment)
+      anv_finishme("stencil clear");
 
-   if (num_clear_layers == 0)
+   if (pass->num_color_clear_attachments == 0)
       return;
 
-   struct clear_instance_data instance_data[num_clear_layers];
-   uint32_t color_attachments[num_clear_layers];
+   struct clear_instance_data instance_data[pass->num_color_clear_attachments];
+   uint32_t color_attachments[pass->num_color_clear_attachments];
 
    int layer = 0;
    for (uint32_t i = 0; i < pass->attachment_count; i++) {
@@ -310,14 +305,15 @@ anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
 
    struct anv_subpass subpass = {
       .input_count = 0,
-      .color_count = num_clear_layers,
+      .color_count = pass->num_color_clear_attachments,
       .color_attachments = color_attachments,
       .depth_stencil_attachment = VK_ATTACHMENT_UNUSED,
    };
 
    anv_cmd_buffer_begin_subpass(cmd_buffer, &subpass);
 
-   meta_emit_clear(cmd_buffer, num_clear_layers, instance_data);
+   meta_emit_clear(cmd_buffer, pass->num_color_clear_attachments,
+                   instance_data);
 
    /* Restore API state */
    anv_cmd_buffer_restore(cmd_buffer, &saved_state);
index 73bcd85e41108b044bc7ef31d517acd86c2c9787..1de97fda83a37449ac7ec9170311d87b64a3f205 100644 (file)
@@ -1063,6 +1063,10 @@ struct anv_render_pass {
    uint32_t                                     attachment_count;
    uint32_t                                     subpass_count;
 
+   uint32_t                                     num_color_clear_attachments;
+   bool                                         has_depth_clear_attachment;
+   bool                                         has_stencil_clear_attachment;
+
    struct anv_render_pass_attachment *          attachments;
    struct anv_subpass                           subpasses[0];
 };