[Mesa-dev] [PATCH 10/22] anv/cmd_buffer: Disable fast clears in the GENERAL layout

Nanley Chery nanleychery at gmail.com
Thu Apr 27 18:32:09 UTC 2017


Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
---
 src/intel/vulkan/anv_pass.c        | 22 ++++++++++++++++++++++
 src/intel/vulkan/anv_private.h     |  1 +
 src/intel/vulkan/genX_cmd_buffer.c | 20 ++++++++++++++------
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c
index dcd9aafc64..02b8f03fa5 100644
--- a/src/intel/vulkan/anv_pass.c
+++ b/src/intel/vulkan/anv_pass.c
@@ -32,6 +32,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,
@@ -90,6 +100,7 @@ VkResult anv_CreateRenderPass(
       att->initial_layout = pCreateInfo->pAttachments[i].initialLayout;
       att->final_layout = pCreateInfo->pAttachments[i].finalLayout;
       att->subpass_usage = subpass_usages;
+      assert(att->first_subpass_layout == VK_IMAGE_LAYOUT_UNDEFINED);
       subpass_usages += pass->subpass_count;
    }
 
@@ -116,6 +127,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;
@@ -135,6 +148,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]);
             }
          }
       }
@@ -159,6 +175,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]);
             }
          }
       }
@@ -173,6 +192,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;
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 12531264d5..b49a5a0009 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2216,6 +2216,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;
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index a981b00f67..e3b1687121 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -217,11 +217,13 @@ color_is_zero_one(VkClearColorValue value, enum isl_format format)
 
 static void
 color_attachment_compute_aux_usage(struct anv_cmd_buffer * const cmd_buffer,
-                                   struct anv_attachment_state *att_state,
-                                   struct anv_image_view *iview,
-                                   VkRect2D render_area,
+                                   const uint32_t att, VkRect2D render_area,
                                    union isl_color_value *fast_clear_color)
 {
+  struct anv_attachment_state *att_state = &cmd_buffer->state.attachments[att];
+  struct anv_image_view *iview =
+     cmd_buffer->state.framebuffer->attachments[att];
+
    if (iview->image->aux_surface.isl.size == 0) {
       att_state->aux_usage = ISL_AUX_USAGE_NONE;
       att_state->input_aux_usage = ISL_AUX_USAGE_NONE;
@@ -317,6 +319,13 @@ color_attachment_compute_aux_usage(struct anv_cmd_buffer * const cmd_buffer,
          att_state->fast_clear = false;
       }
 
+      /* We only allow fast clears for the COLOR_ATTACHMENT_OPTIMAL layout.
+       * See add_clear_values() for more information.
+       */
+      if (cmd_buffer->state.pass->attachments[att].first_subpass_layout !=
+          VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
+         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));
@@ -510,9 +519,8 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
 
          union isl_color_value clear_color = { .u32 = { 0, } };
          if (att_aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
-            color_attachment_compute_aux_usage(cmd_buffer,
-                                               &state->attachments[i],
-                                               iview, begin->renderArea,
+            color_attachment_compute_aux_usage(cmd_buffer, i,
+                                               begin->renderArea,
                                                &clear_color);
 
             struct isl_view view = iview->isl;
-- 
2.12.2



More information about the mesa-dev mailing list