<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 26, 2017 at 4:30 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is similar to the previous commit only for HiZ.  For HiZ, apart<br>
from everything looking different, there is really only one functional<br>
change:  We now track the ISL_AUX_STATE_COMPRESSED_NO_<wbr>CLEAR state.<br>
Previously, if you rendered to a resolved slice of the miptree and then<br>
did a fast-clear with a different clear color, that slice would get<br>
resolved even though it hadn't been fast-cleared.  Now that we can track<br>
COMPRESSED_NO_CLEAR, we know that it doesn't have any blocks in the<br>
"clear" state so we can skip the resolve.<br>
---<br>
 src/mesa/drivers/dri/i965/brw_<wbr>clear.c         |   3 +-<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c | 222 ++++++++++++++------------<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h |  24 ---<br>
 3 files changed, 124 insertions(+), 125 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_clear.c b/src/mesa/drivers/dri/i965/<wbr>brw_clear.c<br>
index aa2e994..be72d67 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_clear.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_clear.c<br>
@@ -162,7 +162,8 @@ brw_fast_clear_depth(struct gl_context *ctx)<br>
     * flags out of the HiZ buffer into the real depth buffer.<br>
     */<br>
    if (mt->fast_clear_color.f32[0] != ctx->Depth.Clear) {<br>
-      intel_miptree_all_slices_<wbr>resolve_depth(brw, mt);<br>
+      intel_miptree_prepare_access(<wbr>brw, mt, 0, INTEL_REMAINING_LEVELS,<br>
+                                   0, INTEL_REMAINING_LAYERS, true, false);<br>
       mt->fast_clear_color.f32[0] = ctx->Depth.Clear;<br>
    }<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
index 3e30b2a..a1a8177 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
@@ -325,7 +325,6 @@ intel_miptree_create_layout(<wbr>struct brw_context *brw,<br>
       INTEL_AUX_DISABLE_ALL : INTEL_AUX_DISABLE_NONE;<br>
    mt->aux_disable |= INTEL_AUX_DISABLE_CCS;<br>
    mt->is_scanout = (layout_flags & MIPTREE_LAYOUT_FOR_SCANOUT) != 0;<br>
-   exec_list_make_empty(&mt->hiz_<wbr>map);<br>
    mt->aux_state = NULL;<br>
    mt->cpp = _mesa_get_format_bytes(format)<wbr>;<br>
    mt->num_samples = num_samples;<br>
@@ -974,7 +973,6 @@ intel_miptree_release(struct intel_mipmap_tree **mt)<br>
          brw_bo_unreference((*mt)->mcs_<wbr>buf->bo);<br>
          free((*mt)->mcs_buf);<br>
       }<br>
-      intel_resolve_map_clear(&(*mt)<wbr>->hiz_map);<br>
       free_aux_state_map((*mt)->aux_<wbr>state);<br>
<br>
       intel_miptree_release(&(*mt)-><wbr>plane[0]);<br>
@@ -1909,6 +1907,11 @@ intel_miptree_alloc_hiz(struct brw_context *brw,<br>
    assert(mt->hiz_buf == NULL);<br>
    assert((mt->aux_disable & INTEL_AUX_DISABLE_HIZ) == 0);<br>
<br>
+   enum isl_aux_state **aux_state =<br>
+      create_aux_state_map(mt, ISL_AUX_STATE_AUX_INVALID);<br>
+   if (!aux_state)<br>
+      return false;<br>
+<br>
    if (brw->gen == 7) {<br>
       mt->hiz_buf = intel_gen7_hiz_buf_create(brw, mt);<br>
    } else if (brw->gen >= 8) {<br>
@@ -1917,24 +1920,15 @@ intel_miptree_alloc_hiz(struct brw_context *brw,<br>
       mt->hiz_buf = intel_hiz_miptree_buf_create(<wbr>brw, mt);<br>
    }<br>
<br>
-   if (!mt->hiz_buf)<br>
+   if (!mt->hiz_buf) {<br>
+      free(aux_state);<br>
       return false;<br>
+   }<br>
<br>
-   /* Mark that all slices need a HiZ resolve. */<br>
-   for (unsigned level = mt->first_level; level <= mt->last_level; ++level) {<br>
-      if (!intel_miptree_level_enable_<wbr>hiz(brw, mt, level))<br>
-         continue;<br>
-<br>
-      for (unsigned layer = 0; layer < mt->level[level].depth; ++layer) {<br>
-         struct intel_resolve_map *m = malloc(sizeof(struct intel_resolve_map));<br>
-         exec_node_init(&m->link);<br>
-         m->level = level;<br>
-         m->layer = layer;<br>
-         m->need = BLORP_HIZ_OP_HIZ_RESOLVE;<br>
+   for (unsigned level = mt->first_level; level <= mt->last_level; ++level)<br>
+      intel_miptree_level_enable_<wbr>hiz(brw, mt, level);<br>
<br>
-         exec_list_push_tail(&mt->hiz_<wbr>map, &m->link);<br>
-      }<br>
-   }<br>
+   mt->aux_state = aux_state;<br>
<br>
    return true;<br>
 }<br>
@@ -1993,41 +1987,6 @@ intel_miptree_level_has_hiz(<wbr>struct intel_mipmap_tree *mt, uint32_t level)<br>
    return mt->level[level].has_hiz;<br>
 }<br>
<br>
-static bool<br>
-intel_miptree_depth_hiz_<wbr>resolve(struct brw_context *brw,<br>
-                                struct intel_mipmap_tree *mt,<br>
-                                uint32_t start_level, uint32_t num_levels,<br>
-                                uint32_t start_layer, uint32_t num_layers,<br>
-                                enum blorp_hiz_op need)<br>
-{<br>
-   bool did_resolve = false;<br>
-<br>
-   foreach_list_typed_safe(struct intel_resolve_map, map, link, &mt->hiz_map) {<br>
-      if (map->level < start_level ||<br>
-          map->level >= (start_level + num_levels) ||<br>
-          map->layer < start_layer ||<br>
-          map->layer >= (start_layer + num_layers))<br>
-         continue;<br>
-<br>
-      if (map->need != need)<br>
-        continue;<br>
-<br>
-      intel_hiz_exec(brw, mt, map->level, map->layer, need);<br>
-      intel_resolve_map_remove(map);<br>
-      did_resolve = true;<br>
-   }<br>
-<br>
-   return did_resolve;<br>
-}<br>
-<br>
-bool<br>
-intel_miptree_all_slices_<wbr>resolve_depth(struct brw_context *brw,<br>
-                                      struct intel_mipmap_tree *mt)<br>
-{<br>
-   return intel_miptree_depth_hiz_<wbr>resolve(brw, mt, 0, UINT32_MAX, 0, UINT32_MAX,<br>
-                                          BLORP_HIZ_OP_DEPTH_RESOLVE);<br>
-}<br>
-<br>
 bool<br>
 intel_miptree_has_color_<wbr>unresolved(const struct intel_mipmap_tree *mt,<br>
                                    unsigned start_level, unsigned num_levels,<br>
@@ -2267,6 +2226,96 @@ intel_miptree_finish_mcs_<wbr>write(struct brw_context *brw,<br>
    }<br>
 }<br>
<br>
+static void<br>
+intel_miptree_prepare_hiz_<wbr>access(struct brw_context *brw,<br>
+                                 struct intel_mipmap_tree *mt,<br>
+                                 uint32_t level, uint32_t layer,<br>
+                                 bool hiz_supported, bool fast_clear_supported)<br>
+{<br>
+   enum blorp_hiz_op hiz_op = BLORP_HIZ_OP_NONE;<br>
+   switch (intel_miptree_get_aux_state(<wbr>mt, level, layer)) {<br>
+   case ISL_AUX_STATE_CLEAR:<br>
+   case ISL_AUX_STATE_COMPRESSED_<wbr>CLEAR:<br>
+      if (!hiz_supported || !fast_clear_supported)<br>
+         hiz_op = BLORP_HIZ_OP_DEPTH_RESOLVE;<br>
+      break;<br>
+<br>
+   case ISL_AUX_STATE_COMPRESSED_NO_<wbr>CLEAR:<br>
+      if (!hiz_supported)<br>
+         hiz_op = BLORP_HIZ_OP_DEPTH_RESOLVE;<br>
+      break;<br>
+<br>
+   case ISL_AUX_STATE_PASS_THROUGH:<br>
+   case ISL_AUX_STATE_RESOLVED:<br>
+      break;<br>
+<br>
+   case ISL_AUX_STATE_AUX_INVALID:<br>
+      if (hiz_supported)<br>
+         hiz_op = BLORP_HIZ_OP_HIZ_RESOLVE;<br>
+      break;<br>
+   }<br>
+<br>
+   if (hiz_op != BLORP_HIZ_OP_NONE) {<br>
+      intel_hiz_exec(brw, mt, level, layer, hiz_op);<br>
+<br>
+      switch (hiz_op) {<br>
+      case BLORP_HIZ_OP_DEPTH_RESOLVE:<br>
+         intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                     ISL_AUX_STATE_RESOLVED);<br>
+         break;<br>
+<br>
+      case BLORP_HIZ_OP_HIZ_RESOLVE:<br>
+         /* The HiZ resolve operation is actually an ambiguate */<br>
+         intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                     ISL_AUX_STATE_RESOLVED);<br></blockquote><div><br></div><div>This should be ISL_AUX_STATE_PASS_THROUGH.  I've fixed it locally.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         break;<br>
+<br>
+      default:<br>
+         unreachable("Invalid HiZ op");<br>
+      }<br>
+   }<br>
+}<br>
+<br>
+static void<br>
+intel_miptree_finish_hiz_<wbr>write(struct brw_context *brw,<br>
+                               struct intel_mipmap_tree *mt,<br>
+                               uint32_t level, uint32_t layer,<br>
+                               bool written_with_hiz)<br>
+{<br>
+   switch (intel_miptree_get_aux_state(<wbr>mt, level, layer)) {<br>
+   case ISL_AUX_STATE_CLEAR:<br>
+      assert(written_with_hiz);<br>
+      intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                  ISL_AUX_STATE_COMPRESSED_<wbr>CLEAR);<br>
+      break;<br>
+<br>
+   case ISL_AUX_STATE_COMPRESSED_NO_<wbr>CLEAR:<br>
+   case ISL_AUX_STATE_COMPRESSED_<wbr>CLEAR:<br>
+      assert(written_with_hiz);<br>
+      break; /* Nothing to do */<br>
+<br>
+   case ISL_AUX_STATE_RESOLVED:<br>
+      if (written_with_hiz) {<br>
+         intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                     ISL_AUX_STATE_COMPRESSED_NO_<wbr>CLEAR);<br>
+      } else {<br>
+         intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                     ISL_AUX_STATE_AUX_INVALID);<br>
+      }<br>
+<br>
+   case ISL_AUX_STATE_PASS_THROUGH:<br>
+      if (written_with_hiz) {<br>
+         intel_miptree_set_aux_state(<wbr>brw, mt, level, layer, 1,<br>
+                                     ISL_AUX_STATE_COMPRESSED_NO_<wbr>CLEAR);<br>
+      }<br>
+      break;<br>
+<br>
+   case ISL_AUX_STATE_AUX_INVALID:<br>
+      assert(!written_with_hiz);<br>
+      break;<br>
+   }<br>
+}<br>
+<br>
 void<br>
 intel_miptree_prepare_access(<wbr>struct brw_context *brw,<br>
                              struct intel_mipmap_tree *mt,<br>
@@ -2305,16 +2354,17 @@ intel_miptree_prepare_access(<wbr>struct brw_context *brw,<br>
       if (!mt->hiz_buf)<br>
          return;<br>
<br>
-      if (aux_supported) {<br>
-         assert(fast_clear_supported);<br>
-         intel_miptree_depth_hiz_<wbr>resolve(brw, mt, start_level, num_levels,<br>
-                                         start_layer, num_layers,<br>
-                                         BLORP_HIZ_OP_HIZ_RESOLVE);<br>
-      } else {<br>
-         assert(!fast_clear_supported);<br>
-         intel_miptree_depth_hiz_<wbr>resolve(brw, mt, start_level, num_levels,<br>
-                                         start_layer, num_layers,<br>
-                                         BLORP_HIZ_OP_DEPTH_RESOLVE);<br>
+      for (uint32_t level = start_level; level <= last_level; level++) {<br>
+         if (!intel_miptree_level_has_hiz(<wbr>mt, level))<br>
+            continue;<br>
+<br>
+         const uint32_t level_layers =<br>
+            MIN2(num_layers, mt->level[level].depth);<br>
+         for (uint32_t a = 0; a < level_layers; a++) {<br>
+            intel_miptree_prepare_hiz_<wbr>access(brw, mt, level, start_layer + a,<br>
+                                             aux_supported,<br>
+                                             fast_clear_supported);<br>
+         }<br>
       }<br>
    }<br>
 }<br>
@@ -2351,18 +2401,9 @@ intel_miptree_finish_write(<wbr>struct brw_context *brw,<br>
       if (!intel_miptree_level_has_hiz(<wbr>mt, level))<br>
          return;<br>
<br>
-      if (written_with_aux) {<br>
-         for (unsigned a = 0; a < num_layers; a++) {<br>
-            intel_miptree_check_level_<wbr>layer(mt, level, start_layer);<br>
-            intel_resolve_map_set(&mt-><wbr>hiz_map, level, start_layer + a,<br>
-                                  BLORP_HIZ_OP_DEPTH_RESOLVE);<br>
-         }<br>
-      } else {<br>
-         for (unsigned a = 0; a < num_layers; a++) {<br>
-            intel_miptree_check_level_<wbr>layer(mt, level, start_layer);<br>
-            intel_resolve_map_set(&mt-><wbr>hiz_map, level, start_layer + a,<br>
-                                  BLORP_HIZ_OP_HIZ_RESOLVE);<br>
-         }<br>
+      for (uint32_t a = 0; a < num_layers; a++) {<br>
+         intel_miptree_finish_hiz_<wbr>write(brw, mt, level, start_layer + a,<br>
+                                        written_with_aux);<br>
       }<br>
    }<br>
 }<br>
@@ -2376,24 +2417,13 @@ intel_miptree_get_aux_state(<wbr>const struct intel_mipmap_tree *mt,<br>
    if (_mesa_is_format_color_format(<wbr>mt->format)) {<br>
       assert(mt->mcs_buf != NULL);<br>
       assert(mt->num_samples <= 1 || mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS);<br>
-      return mt->aux_state[level][layer];<br>
    } else if (mt->format == MESA_FORMAT_S_UINT8) {<br>
       unreachable("Cannot get aux state for stencil");<br>
    } else {<br>
       assert(mt->hiz_buf != NULL);<br>
-      const struct intel_resolve_map *map =<br>
-         intel_resolve_map_const_get(&<wbr>mt->hiz_map, level, layer);<br>
-      if (!map)<br>
-         return ISL_AUX_STATE_RESOLVED;<br>
-      switch (map->need) {<br>
-      case BLORP_HIZ_OP_DEPTH_RESOLVE:<br>
-         return ISL_AUX_STATE_COMPRESSED_<wbr>CLEAR;<br>
-      case BLORP_HIZ_OP_HIZ_RESOLVE:<br>
-         return ISL_AUX_STATE_AUX_INVALID;<br>
-      default:<br>
-         unreachable("Invalid hiz op");<br>
-      }<br>
    }<br>
+<br>
+   return mt->aux_state[level][layer];<br>
 }<br>
<br>
 void<br>
@@ -2410,23 +2440,14 @@ intel_miptree_set_aux_state(<wbr>struct brw_context *brw,<br>
    if (_mesa_is_format_color_format(<wbr>mt->format)) {<br>
       assert(mt->mcs_buf != NULL);<br>
       assert(mt->num_samples <= 1 || mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS);<br>
-<br>
-      for (unsigned a = 0; a < num_layers; a++)<br>
-         mt->aux_state[level][start_<wbr>layer + a] = aux_state;<br>
    } else if (mt->format == MESA_FORMAT_S_UINT8) {<br>
       unreachable("Cannot get aux state for stencil");<br>
    } else {<br>
       assert(mt->hiz_buf != NULL);<br>
-<br>
-      /* Right now, this only applies to clears. */<br>
-      assert(aux_state == ISL_AUX_STATE_CLEAR);<br>
-<br>
-      for (unsigned a = 0; a < num_layers; a++) {<br>
-         intel_miptree_check_level_<wbr>layer(mt, level, start_layer);<br>
-         intel_resolve_map_set(&mt-><wbr>hiz_map, level, start_layer + a,<br>
-                               BLORP_HIZ_OP_DEPTH_RESOLVE);<br>
-      }<br>
    }<br>
+<br>
+   for (unsigned a = 0; a < num_layers; a++)<br>
+      mt->aux_state[level][start_<wbr>layer + a] = aux_state;<br>
 }<br>
<br>
 /* On Gen9 color buffers may be compressed by the hardware (lossless<br>
@@ -2647,7 +2668,8 @@ intel_miptree_make_shareable(<wbr>struct brw_context *brw,<br>
        * any will likely crash due to the missing aux buffer. So let's delete<br>
        * all pending ops.<br>
        */<br>
-      exec_list_make_empty(&mt->hiz_<wbr>map);<br>
+      free(mt->aux_state);<br>
+      mt->aux_state = NULL;<br>
    }<br>
 }<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
index 528c32c..428c097 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
@@ -542,23 +542,6 @@ struct intel_mipmap_tree<br>
    struct intel_miptree_hiz_buffer *hiz_buf;<br>
<br>
    /**<br>
-    * \brief Maps of miptree slices to needed resolves.<br>
-    *<br>
-    * hiz_map is used only when the miptree has a child HiZ miptree.<br>
-    *<br>
-    * Let \c mt be a depth miptree with HiZ enabled. Then the resolve map is<br>
-    * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c<br>
-    * mt->hiz_mt->hiz_map, is unused.<br>
-    *<br>
-    *<br>
-    * color_resolve_map is used only when the miptree uses fast clear (Gen7+)<br>
-    * lossless compression (Gen9+). It should be noted that absence in the<br>
-    * map means implicitly RESOLVED state. If item is found it always<br>
-    * indicates state other than RESOLVED.<br>
-    */<br>
-   struct exec_list hiz_map; /* List of intel_resolve_map. */<br>
-<br>
-   /**<br>
     * \brief Maps miptree slices to their current aux state<br>
     *<br>
     * This two-dimensional array is indexed as [level][layer] and stores an<br>
@@ -825,13 +808,6 @@ intel_miptree_alloc_hiz(struct brw_context *brw,<br>
 bool<br>
 intel_miptree_level_has_hiz(<wbr>struct intel_mipmap_tree *mt, uint32_t level);<br>
<br>
-/**<br>
- * \return false if no resolve was needed<br>
- */<br>
-bool<br>
-intel_miptree_all_slices_<wbr>resolve_depth(struct brw_context *brw,<br>
-                                      struct intel_mipmap_tree *mt);<br>
-<br>
 /**\}*/<br>
<br>
 bool<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div></div>