<div dir="ltr"><div>Good work!  Series is<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 12, 2017 at 5:34 PM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2: Simplify nested ifs (Jason Ekstrand)<br>
<span class=""><br>
Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
---<br>
</span> src/intel/vulkan/genX_cmd_<wbr>buffer.c | 67 ++++++++++++++++++++++++++++--<wbr>--------<br>
 1 file changed, 49 insertions(+), 18 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
index 59041f0458..f7894a0574 100644<br>
<span class="">--- a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
+++ b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
@@ -311,11 +311,21 @@ need_input_attachment_state(<wbr>const struct anv_render_pass_attachment *att)<br>
 }<br>
<br>
 static enum isl_aux_usage<br>
-layout_to_hiz_usage(<wbr>VkImageLayout layout)<br>
+layout_to_hiz_usage(<wbr>VkImageLayout layout, uint8_t samples)<br>
 {<br>
    switch (layout) {<br>
    case VK_IMAGE_LAYOUT_DEPTH_STENCIL_<wbr>ATTACHMENT_OPTIMAL:<br>
       return ISL_AUX_USAGE_HIZ;<br>
+   case VK_IMAGE_LAYOUT_DEPTH_STENCIL_<wbr>READ_ONLY_OPTIMAL:<br>
+   case VK_IMAGE_LAYOUT_SHADER_READ_<wbr>ONLY_OPTIMAL:<br>
+      if (anv_can_sample_with_hiz(GEN_<wbr>GEN, samples))<br>
+         return ISL_AUX_USAGE_HIZ;<br>
+      /* Fall-through */<br>
+   case VK_IMAGE_LAYOUT_GENERAL:<br>
+      /* This buffer could be used as a source or destination in a transfer<br>
+       * operation. Transfer operations current don't perform HiZ-enabled reads<br>
+       * and writes.<br>
+       */<br>
    default:<br>
       return ISL_AUX_USAGE_NONE;<br>
    }<br>
</span>@@ -333,28 +343,48 @@ transition_depth_buffer(struct anv_cmd_buffer *cmd_buffer,<br>
 {<br>
    assert(image);<br>
<br>
-   if (image->aux_usage != ISL_AUX_USAGE_HIZ)<br>
+   if (image->aux_usage != ISL_AUX_USAGE_HIZ || final_layout == initial_layout)<br>
<span class="">       return;<br>
<br>
-   const bool hiz_enabled = layout_to_hiz_usage(initial_<wbr>layout) ==<br>
+   const bool hiz_enabled = layout_to_hiz_usage(initial_<wbr>layout, image->samples) ==<br>
                             ISL_AUX_USAGE_HIZ;<br>
-   const bool enable_hiz = layout_to_hiz_usage(final_<wbr>layout) ==<br>
+   const bool enable_hiz = layout_to_hiz_usage(final_<wbr>layout, image->samples) ==<br>
                            ISL_AUX_USAGE_HIZ;<br>
<br>
</span>-   /* We've already initialized the aux HiZ buffer at BindImageMemory time,<br>
-    * so there's no need to perform a HIZ resolve or clear to avoid GPU hangs.<br>
-    * This initial layout indicates that the user doesn't care about the data<br>
<span class="">-    * that's currently in the buffer, so no resolves are necessary.<br>
</span>-    */<br>
<span class="">-   if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED)<br>
</span>-      return;<br>
-<br>
<span class="">-   if (hiz_enabled == enable_hiz) {<br>
-      /* The same buffer will be used, no resolves are necessary */<br>
</span>+   enum blorp_hiz_op hiz_op;<br>
+   if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED) {<br>
+      /* We've already initialized the aux HiZ buffer at BindImageMemory time,<br>
+       * so there's no need to perform a HIZ resolve or clear to avoid GPU hangs.<br>
+       * This initial layout indicates that the user doesn't care about the data<br>
<span class="">+       * that's currently in the buffer, so resolves are not necessary except<br>
</span>+       * for the special case noted below.<br>
+       */<br>
+      hiz_op = BLORP_HIZ_OP_NONE;<br>
<span class="">    } else if (hiz_enabled && !enable_hiz) {<br>
</span>-      anv_gen8_hiz_op_resolve(cmd_<wbr>buffer, image, BLORP_HIZ_OP_DEPTH_RESOLVE);<br>
+      hiz_op = BLORP_HIZ_OP_DEPTH_RESOLVE;<br>
+   } else if (!hiz_enabled && enable_hiz) {<br>
+      hiz_op = BLORP_HIZ_OP_HIZ_RESOLVE;<br>
<span class="">    } else {<br>
-      assert(!hiz_enabled && enable_hiz);<br>
</span>+      assert(hiz_enabled == enable_hiz);<br>
+      /* If the same buffer will be used, no resolves are necessary except for<br>
+       * the special case noted below.<br>
+       */<br>
+      hiz_op = BLORP_HIZ_OP_NONE;<br>
+   }<br>
+<br>
+   if (hiz_op != BLORP_HIZ_OP_NONE)<br>
+      anv_gen8_hiz_op_resolve(cmd_<wbr>buffer, image, hiz_op);<br>
+<br>
<span class="">+   /* Images that have sampling with HiZ enabled cause all shader sampling to<br>
+    * load data with the HiZ buffer. Therefore, in the case of transitioning to<br>
+    * the general layout - which currently routes all writes to the depth<br>
+    * buffer - we must ensure that the HiZ buffer remains consistent with the<br>
</span>+    * depth buffer by performing an additional HIZ resolve if the operation<br>
+    * required by this transition was not already a HiZ resolve.<br>
+    */<br>
+   if (final_layout == VK_IMAGE_LAYOUT_GENERAL &&<br>
+       anv_can_sample_with_hiz(GEN_<wbr>GEN, image->samples) &&<br>
+       hiz_op != BLORP_HIZ_OP_HIZ_RESOLVE) {<br>
       anv_gen8_hiz_op_resolve(cmd_<wbr>buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);<br>
    }<br>
 }<br>
@@ -512,7 +542,7 @@ genX(cmd_buffer_setup_<wbr>attachments)(struct anv_cmd_buffer *cmd_buffer,<br>
          } else {<br>
             if (iview->image->aux_usage == ISL_AUX_USAGE_HIZ) {<br>
<span class="">                state->attachments[i].aux_<wbr>usage =<br>
-                  layout_to_hiz_usage(att-><wbr>initial_layout);<br>
+                  layout_to_hiz_usage(att-><wbr>initial_layout, iview->image->samples);<br>
             } else {<br>
                state->attachments[i].aux_<wbr>usage = ISL_AUX_USAGE_NONE;<br>
             }<br>
</span>@@ -2312,7 +2342,8 @@ genX(cmd_buffer_set_subpass)(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
<div class="HOEnZb"><div class="h5">       cmd_buffer->state.attachments[<wbr>ds].current_layout =<br>
          cmd_buffer->state.subpass-><wbr>depth_stencil_layout;<br>
       cmd_buffer->state.attachments[<wbr>ds].aux_usage =<br>
-         layout_to_hiz_usage(cmd_<wbr>buffer->state.subpass->depth_<wbr>stencil_layout);<br>
+         layout_to_hiz_usage(cmd_<wbr>buffer->state.subpass->depth_<wbr>stencil_layout,<br>
+                             iview->image->samples);<br>
    }<br>
<br>
    cmd_buffer_emit_depth_stencil(<wbr>cmd_buffer);<br>
--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>