[Mesa-dev] [PATCH 22/22] anv: Avoid some resolves for samplable HiZ buffers

Nanley Chery nanleychery at gmail.com
Thu Jan 12 01:55:08 UTC 2017


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

diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index 447baa08b2..11745f8b9e 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -311,11 +311,21 @@ need_input_attachment_state(const struct anv_render_pass_attachment *att)
 }
 
 static enum isl_aux_usage
-layout_to_hiz_usage(VkImageLayout layout)
+layout_to_hiz_usage(VkImageLayout layout, uint8_t samples)
 {
    switch (layout) {
    case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
       return ISL_AUX_USAGE_HIZ;
+   case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
+   case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
+      if (anv_can_sample_with_hiz(GEN_GEN, samples))
+         return ISL_AUX_USAGE_HIZ;
+      /* Fall-through */
+   case VK_IMAGE_LAYOUT_GENERAL:
+      /* This buffer could be used as a source or destination in a transfer
+       * operation. Transfer operations current don't perform HiZ-enabled reads
+       * and writes.
+       */
    default:
       return ISL_AUX_USAGE_NONE;
    }
@@ -336,26 +346,43 @@ transition_depth_buffer(struct anv_cmd_buffer *cmd_buffer,
    if (image->aux_usage != ISL_AUX_USAGE_HIZ)
       return;
 
-   const bool hiz_enabled = layout_to_hiz_usage(initial_layout) ==
+   const bool hiz_enabled = layout_to_hiz_usage(initial_layout, image->samples) ==
                             ISL_AUX_USAGE_HIZ;
-   const bool enable_hiz = layout_to_hiz_usage(final_layout) ==
+   const bool enable_hiz = layout_to_hiz_usage(final_layout, image->samples) ==
                            ISL_AUX_USAGE_HIZ;
 
+   /* Images that have sampling with HiZ enabled cause all shader sampling to
+    * load data with the HiZ buffer. Therefore, in the case of transitioning to
+    * the general layout - which currently routes all writes to the depth
+    * buffer - we must ensure that the HiZ buffer remains consistent with the
+    * depth buffer by performing a HIZ resolve after performing the resolve
+    * required by this transition (if not already HiZ).
+    */
+   const bool needs_hiz_resolve = final_layout == VK_IMAGE_LAYOUT_GENERAL &&
+      (hiz_enabled || initial_layout == VK_IMAGE_LAYOUT_UNDEFINED) &&
+      anv_can_sample_with_hiz(GEN_GEN, image->samples);
+
    /* We've already initialized the aux HiZ buffer at BindImageMemory time,
     * so there's no need to perform a HIZ resolve or clear to avoid GPU hangs.
     * This initial layout indicates that the user doesn't care about the data
-    * that's currently in the buffer, so no resolves are necessary.
+    * that's currently in the buffer, so resolves are not necessary except for
+    * the case mentioned above.
     */
-   if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED)
+   if (!needs_hiz_resolve && initial_layout == VK_IMAGE_LAYOUT_UNDEFINED)
       return;
 
-   if (hiz_enabled == enable_hiz) {
-      /* The same buffer will be used, no resolves are necessary */
-   } else if (hiz_enabled && !enable_hiz) {
-      anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_DEPTH_RESOLVE);
+   if (!hiz_enabled && enable_hiz) {
+         anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);
    } else {
-      assert(!hiz_enabled && enable_hiz);
-      anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);
+      if (hiz_enabled == enable_hiz) {
+         /* If the same buffer will be used, no resolves are necessary except
+          * for the special case noted above.
+          */
+      } else if (hiz_enabled && !enable_hiz) {
+         anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_DEPTH_RESOLVE);
+      }
+      if (needs_hiz_resolve)
+         anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);
    }
 }
 
@@ -513,7 +540,7 @@ genX(cmd_buffer_setup_attachments)(struct anv_cmd_buffer *cmd_buffer,
             if (iview->image->aux_usage == ISL_AUX_USAGE_HIZ &&
                 iview->aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
                state->attachments[i].aux_usage =
-                  layout_to_hiz_usage(att->initial_layout);
+                  layout_to_hiz_usage(att->initial_layout, iview->image->samples);
             } else {
                state->attachments[i].aux_usage = ISL_AUX_USAGE_NONE;
             }
@@ -2319,7 +2346,8 @@ genX(cmd_buffer_set_subpass)(struct anv_cmd_buffer *cmd_buffer,
       cmd_buffer->state.attachments[ds].current_layout =
          cmd_buffer->state.subpass->depth_stencil_layout;
       cmd_buffer->state.attachments[ds].aux_usage =
-         layout_to_hiz_usage(cmd_buffer->state.subpass->depth_stencil_layout);
+         layout_to_hiz_usage(cmd_buffer->state.subpass->depth_stencil_layout,
+                             iview->image->samples);
    }
 
    cmd_buffer_emit_depth_stencil(cmd_buffer);
-- 
2.11.0



More information about the mesa-dev mailing list