On 14 August 2012 16:58, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@linux.intel.com" target="_blank">chad.versace@linux.intel.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On creating a hiz miptree, we conservatively marked that each miptree<br>
slice needed a hiz resolve. But the resolves are unneeded when creating<br>
a non-texture miptree, so this patch removes them.<br>
<br>
This eliminates one hiz resolve per each creation of a non-texture depth<br>
miptree.  Hence, this eliminates many resolves when resizing a window.<br></blockquote><div><br>So, with this change, are the contents of the HiZ buffer uninitialized for a newly created (or resized) non-texture miptree?  The HW docs don't specify the exact format of the HiZ buffer, so it's possible that there may be some possible states of the HiZ buffer that are invalid.  If there are, and the hardware doesn't deal with those invalid states well, then we run the risk of sporadic incorrect results (if subsequent rendering fails to bring the HiZ buffer into a valid state) or possibly sporadic GPU hangs (if the hardware is unable to cope with the invalid states).<br>
<br>Alternatively, perhaps we could initialize non-texture HiZ buffers to a state that indicates that they need a fast depth clear rather than a HiZ resolve.  Clears are likely to be much faster than HiZ resolves, because they don't require reading from the depth buffer.  So we would still get most of the benefit of avoiding the HiZ resolve, and no risk of undefined behaviour.  In fact, we might conceivably get even more benefit, since after a fast depth clear, the HiZ buffer is in a state where future rendering is very efficient (since the depth buffer doesn't need to be read).<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Signed-off-by: Chad Versace <<a href="mailto:chad.versace@linux.intel.com">chad.versace@linux.intel.com</a>><br>
---<br>
 src/mesa/drivers/dri/intel/intel_fbo.c         |  4 ++-<br>
 src/mesa/drivers/dri/intel/intel_mipmap_tree.c | 39 +++++++++++++++++---------<br>
 src/mesa/drivers/dri/intel/intel_mipmap_tree.h |  3 +-<br>
 3 files changed, 30 insertions(+), 16 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c<br>
index 3a610c2..ada0f69 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_fbo.c<br>
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c<br>
@@ -538,7 +538,9 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,<br>
<br>
    if (mt->hiz_mt == NULL &&<br>
        intel->vtbl.is_hiz_depth_format(intel, rb->Format)) {<br>
-      intel_miptree_alloc_hiz(intel, mt, 0 /* num_samples */);<br>
+      intel_miptree_alloc_hiz(intel, mt,<br>
+                              0 /*num_samples*/,<br>
+                              true /*for_texture*/);<br>
       if (!mt->hiz_mt)<br>
         return false;<br>
    }<br>
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c<br>
index 24cd9e9..143f2e3 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c<br>
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c<br>
@@ -467,7 +467,8 @@ intel_miptree_create_for_renderbuffer(struct intel_context *intel,<br>
       goto fail;<br>
<br>
    if (intel->vtbl.is_hiz_depth_format(intel, format)) {<br>
-      ok = intel_miptree_alloc_hiz(intel, mt, num_samples);<br>
+      ok = intel_miptree_alloc_hiz(intel, mt, num_samples,<br>
+                                   false /*for_texture*/);<br>
       if (!ok)<br>
          goto fail;<br>
    }<br>
@@ -825,7 +826,8 @@ intel_miptree_alloc_mcs(struct intel_context *intel,<br>
 bool<br>
 intel_miptree_alloc_hiz(struct intel_context *intel,<br>
                        struct intel_mipmap_tree *mt,<br>
-                        GLuint num_samples)<br>
+                        GLuint num_samples,<br>
+                        bool for_texture)<br>
 {<br>
    assert(mt->hiz_mt == NULL);<br>
    /* MSAA HiZ surfaces always use IMS layout. */<br>
@@ -844,18 +846,27 @@ intel_miptree_alloc_hiz(struct intel_context *intel,<br>
    if (!mt->hiz_mt)<br>
       return false;<br>
<br>
-   /* Mark that all slices need a HiZ resolve. */<br>
-   struct intel_resolve_map *head = &mt->hiz_map;<br>
-   for (int level = mt->first_level; level <= mt->last_level; ++level) {<br>
-      for (int layer = 0; layer < mt->level[level].depth; ++layer) {<br>
-        head->next = malloc(sizeof(*head->next));<br>
-        head->next->prev = head;<br>
-        head->next->next = NULL;<br>
-        head = head->next;<br>
-<br>
-        head->level = level;<br>
-        head->layer = layer;<br>
-        head->need = GEN6_HIZ_OP_HIZ_RESOLVE;<br>
+   if (for_texture) {<br>
+      /* Mark that all slices need a HiZ resolve. This is necessary for<br>
+       * renderbuffers that wrap textures because the user may have previously<br>
+       * uploaded texture data into the parent depth miptree.<br>
+       *<br>
+       * This is skipped for non-texture miptrees. In the non-texture case,<br>
+       * the depth miptree and the hiz miptree are created together, and hence<br>
+       * the content of each is undefined here.<br>
+       */<br>
+      struct intel_resolve_map *head = &mt->hiz_map;<br>
+      for (int level = mt->first_level; level <= mt->last_level; ++level) {<br>
+         for (int layer = 0; layer < mt->level[level].depth; ++layer) {<br>
+            head->next = malloc(sizeof(*head->next));<br>
+            head->next->prev = head;<br>
+            head->next->next = NULL;<br>
+            head = head->next;<br>
+<br>
+            head->level = level;<br>
+            head->layer = layer;<br>
+            head->need = GEN6_HIZ_OP_HIZ_RESOLVE;<br>
+         }<br>
       }<br>
    }<br>
<br>
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h<br>
index 0d0e757..65743fd 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h<br>
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h<br>
@@ -503,7 +503,8 @@ intel_miptree_alloc_mcs(struct intel_context *intel,<br>
 bool<br>
 intel_miptree_alloc_hiz(struct intel_context *intel,<br>
                        struct intel_mipmap_tree *mt,<br>
-                        GLuint num_samples);<br>
+                        GLuint num_samples,<br>
+                        bool for_texture);<br>
<br>
 void<br>
 intel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt,<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.11.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br>