anv/cmd_buffer: Restrict fast clears in the GENERAL layout
authorNanley Chery <nanley.g.chery@intel.com>
Fri, 31 Mar 2017 20:52:53 +0000 (13:52 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sun, 23 Jul 2017 03:12:09 +0000 (20:12 -0700)
v2: Remove ::first_subpass_layout assertion (Jason Ekstrand).
v3: Allow some fast clears in the GENERAL layout.
v4: Remove extra '||' and adjust line break (Jason Ekstrand).

Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_pass.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c

index 1b30c1409d980a1a1bc5b4301f9b8d815fea2c13..ab0733fc103252da7aaa91898b7b640f590baa7e 100644 (file)
@@ -34,6 +34,16 @@ num_subpass_attachments(const VkSubpassDescription *desc)
           (desc->pDepthStencilAttachment != NULL);
 }
 
+static void
+init_first_subpass_layout(struct anv_render_pass_attachment * const att,
+                          const VkAttachmentReference att_ref)
+{
+   if (att->first_subpass_layout == VK_IMAGE_LAYOUT_UNDEFINED) {
+      att->first_subpass_layout = att_ref.layout;
+      assert(att->first_subpass_layout != VK_IMAGE_LAYOUT_UNDEFINED);
+   }
+}
+
 VkResult anv_CreateRenderPass(
     VkDevice                                    _device,
     const VkRenderPassCreateInfo*               pCreateInfo,
@@ -91,6 +101,7 @@ VkResult anv_CreateRenderPass(
       att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
       att->initial_layout = pCreateInfo->pAttachments[i].initialLayout;
       att->final_layout = pCreateInfo->pAttachments[i].finalLayout;
+      att->first_subpass_layout = VK_IMAGE_LAYOUT_UNDEFINED;
       att->subpass_usage = subpass_usages;
       subpass_usages += pass->subpass_count;
    }
@@ -119,6 +130,8 @@ VkResult anv_CreateRenderPass(
                pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_INPUT;
                pass->attachments[a].last_subpass_idx = i;
 
+               init_first_subpass_layout(&pass->attachments[a],
+                                         desc->pInputAttachments[j]);
                if (desc->pDepthStencilAttachment &&
                    a == desc->pDepthStencilAttachment->attachment)
                   subpass->has_ds_self_dep = true;
@@ -138,6 +151,9 @@ VkResult anv_CreateRenderPass(
                pass->attachments[a].usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
                pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_DRAW;
                pass->attachments[a].last_subpass_idx = i;
+
+               init_first_subpass_layout(&pass->attachments[a],
+                                         desc->pColorAttachments[j]);
             }
          }
       }
@@ -162,6 +178,9 @@ VkResult anv_CreateRenderPass(
                pass->attachments[a].subpass_usage[i] |=
                   ANV_SUBPASS_USAGE_RESOLVE_DST;
                pass->attachments[a].last_subpass_idx = i;
+
+               init_first_subpass_layout(&pass->attachments[a],
+                                         desc->pResolveAttachments[j]);
             }
          }
       }
@@ -176,6 +195,9 @@ VkResult anv_CreateRenderPass(
                VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
             pass->attachments[a].subpass_usage[i] |= ANV_SUBPASS_USAGE_DRAW;
             pass->attachments[a].last_subpass_idx = i;
+
+            init_first_subpass_layout(&pass->attachments[a],
+                                      *desc->pDepthStencilAttachment);
          }
       } else {
          subpass->depth_stencil_attachment.attachment = VK_ATTACHMENT_UNUSED;
index 3635bc8a1a571f8cad0c3ffc5aae703ce18e4047..70eb3d87604f1fc008126d67412c158855b2e19c 100644 (file)
@@ -1490,6 +1490,7 @@ struct anv_attachment_state {
    bool                                         fast_clear;
    VkClearValue                                 clear_value;
    bool                                         clear_color_is_zero_one;
+   bool                                         clear_color_is_zero;
 };
 
 /** State required while building cmd buffer */
@@ -2308,6 +2309,7 @@ struct anv_render_pass_attachment {
    VkAttachmentLoadOp                           stencil_load_op;
    VkImageLayout                                initial_layout;
    VkImageLayout                                final_layout;
+   VkImageLayout                                first_subpass_layout;
 
    /* An array, indexed by subpass id, of how the attachment will be used. */
    enum anv_subpass_usage *                     subpass_usage;
index 9ffe1ee3aa324fa948353ae14ac0db3e11ca6926..f81d58de8443ed29c06f67769ec22e1ac0346117 100644 (file)
@@ -255,6 +255,11 @@ color_attachment_compute_aux_usage(struct anv_device * device,
 
    att_state->clear_color_is_zero_one =
       color_is_zero_one(att_state->clear_value.color, iview->isl.format);
+   att_state->clear_color_is_zero =
+      att_state->clear_value.color.uint32[0] == 0 &&
+      att_state->clear_value.color.uint32[1] == 0 &&
+      att_state->clear_value.color.uint32[2] == 0 &&
+      att_state->clear_value.color.uint32[3] == 0;
 
    if (att_state->pending_clear_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
       /* Start off assuming fast clears are possible */
@@ -299,6 +304,17 @@ color_attachment_compute_aux_usage(struct anv_device * device,
          }
       }
 
+      /* We only allow fast clears in the GENERAL layout if the auxiliary
+       * buffer is always enabled and the fast-clear value is all 0's. See
+       * add_fast_clear_state_buffer() for more information.
+       */
+      if (cmd_state->pass->attachments[att].first_subpass_layout ==
+          VK_IMAGE_LAYOUT_GENERAL &&
+          (!att_state->clear_color_is_zero ||
+           iview->image->aux_usage == ISL_AUX_USAGE_NONE)) {
+         att_state->fast_clear = false;
+      }
+
       if (att_state->fast_clear) {
          memcpy(fast_clear_color->u32, att_state->clear_value.color.uint32,
                 sizeof(fast_clear_color->u32));