[Mesa-dev] [PATCH 20/24] anv/cmd_buffer: Perform color buffer layout transitions

Nanley Chery nanleychery at gmail.com
Thu May 11 19:05:27 UTC 2017


Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
---
 src/intel/vulkan/genX_cmd_buffer.c | 65 ++++++++++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 13 deletions(-)

diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index 5adf08b798..b49b80e6c9 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -1172,12 +1172,24 @@ void genX(CmdPipelineBarrier)(
    for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) {
       src_flags |= pImageMemoryBarriers[i].srcAccessMask;
       dst_flags |= pImageMemoryBarriers[i].dstAccessMask;
+      /* Perform layout transitions. */
       ANV_FROM_HANDLE(anv_image, image, pImageMemoryBarriers[i].image);
-      if (pImageMemoryBarriers[i].subresourceRange.aspectMask &
-          VK_IMAGE_ASPECT_DEPTH_BIT) {
+      const struct VkImageSubresourceRange * const range =
+         &pImageMemoryBarriers[i].subresourceRange;
+      if (range->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
          transition_depth_buffer(cmd_buffer, image,
                                  pImageMemoryBarriers[i].oldLayout,
                                  pImageMemoryBarriers[i].newLayout);
+      } else if (range->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT) {
+         const uint32_t layers = image->type == VK_IMAGE_TYPE_3D ?
+                                 image->extent.depth :
+                                 anv_get_layerCount(image, range);
+         transition_color_buffer(cmd_buffer, image,
+                                 range->baseMipLevel,
+                                 anv_get_levelCount(image, range),
+                                 range->baseArrayLayer, layers,
+                                 pImageMemoryBarriers[i].oldLayout,
+                                 pImageMemoryBarriers[i].newLayout);
       }
    }
 
@@ -2640,29 +2652,56 @@ cmd_buffer_subpass_transition_layouts(struct anv_cmd_buffer * const cmd_buffer,
           * this is not the last use of the buffer. The layout should not have
           * changed from the first call and no transition is necessary.
           */
-         assert(att_ref->layout == att_state->current_layout);
+         assert(att_state->current_layout == att_ref->layout ||
+                att_state->current_layout ==
+                VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
          continue;
       }
 
-      /* Get the appropriate target layout for this attachment. */
-      const VkImageLayout target_layout = subpass_end ?
-         att_desc->final_layout : att_ref->layout;
-
       /* The attachment index must be less than the number of attachments
        * within the framebuffer.
        */
       assert(att_ref->attachment < cmd_state->framebuffer->attachment_count);
 
-      const struct anv_image * const image =
-         cmd_state->framebuffer->attachments[att_ref->attachment]->image;
+      const struct anv_image_view * const iview =
+         cmd_state->framebuffer->attachments[att_ref->attachment];
+
+      /* Get the appropriate target layout for this attachment. */
+      VkImageLayout target_layout;
+
+      /* A resolve is necessary before use as an input attachment if the clear
+       * color or auxiliary buffer usage isn't supported by the sampler.
+       */
+      const bool input_needs_resolve =
+            (att_state->fast_clear && !att_state->clear_color_is_zero_one) ||
+            att_state->input_aux_usage != att_state->aux_usage;
+      if (subpass_end) {
+         target_layout = att_desc->final_layout;
+      } else if (iview->aspect_mask == VK_IMAGE_ASPECT_COLOR_BIT &&
+                 !input_needs_resolve) {
+         /* Layout transitions before the final only help to enable sampling as
+          * an input attachment. If the input attachment supports sampling
+          * using the auxiliary surface, we can skip such transitions by making
+          * the target layout one that is CCS-aware.
+          */
+         target_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+      } else {
+         target_layout = att_ref->layout;
+      }
 
       /* Perform the layout transition. */
-      if (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
-         transition_depth_buffer(cmd_buffer, image,
+      if (iview->image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
+         transition_depth_buffer(cmd_buffer, iview->image,
                                  att_state->current_layout, target_layout);
          att_state->aux_usage =
-            anv_layout_to_aux_usage(&cmd_buffer->device->info, image,
-                                    image->aspects, target_layout);
+            anv_layout_to_aux_usage(&cmd_buffer->device->info, iview->image,
+                                    iview->image->aspects, target_layout);
+      } else if (iview->image->aspects == VK_IMAGE_ASPECT_COLOR_BIT) {
+         transition_color_buffer(cmd_buffer, iview->image,
+                                 iview->isl.base_level, 1,
+                                 iview->isl.base_array_layer,
+                                 cmd_state->framebuffer->layers,
+                                 att_state->current_layout, target_layout);
       }
 
       att_state->current_layout = target_layout;
-- 
2.12.2



More information about the mesa-dev mailing list