<div dir="ltr">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 Wed, Jul 19, 2017 at 1:07 PM, Topi Pohjolainen <span dir="ltr"><<a href="mailto:topi.pohjolainen@gmail.com" target="_blank">topi.pohjolainen@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 (Jason):<br>
   - s/separate_stencil_surface/<wbr>make_separate_stencil_surface/<br>
   - drop the check for separate stencil when wrapping an<br>
     existing buffer object with miptree. This is dead code as<br>
     the first thing needs_separate_stencil() checks is<br>
     MIPTREE_LAYOUT_FOR_BO-flag and says no.<br>
<br>
CC: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
<span class="">Signed-off-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>><br>
---<br>
 src/mesa/drivers/dri/i965/brw_<wbr>clear.c         |   5 +-<br>
 src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c  |   3 +-<br>
</span> src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c | 130 +++++++++++++++++---------<br>
 3 files changed, 91 insertions(+), 47 deletions(-)<br>
<div><div class="h5"><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 7fbaa3a47d..c310d2547a 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_clear.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_clear.c<br>
@@ -121,7 +121,8 @@ brw_fast_clear_depth(struct gl_context *ctx)<br>
    if ((ctx->Scissor.EnableFlags & 1) && !noop_scissor(fb)) {<br>
       perf_debug("Failed to fast clear %dx%d depth because of scissors.  "<br>
                  "Possible 5%% performance win if avoided.\n",<br>
-                 mt->logical_width0, mt->logical_height0);<br>
+                 mt->surf.logical_level0_px.<wbr>width,<br>
+                 mt->surf.logical_level0_px.<wbr>height);<br>
       return false;<br>
    }<br>
<br>
@@ -149,7 +150,7 @@ brw_fast_clear_depth(struct gl_context *ctx)<br>
        *        optimization must be disabled.<br>
        */<br>
       if (brw->gen == 6 &&<br>
-          (minify(mt->physical_width0,<br>
+          (minify(mt->surf.phys_level0_<wbr>sa.width,<br>
                   depth_irb->mt_level - mt->first_level) % 16) != 0)<br>
         return false;<br>
       break;<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c b/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c<br>
index c934d0d21a..5cee93ade0 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c<br>
@@ -78,7 +78,8 @@ emit_depth_packets(struct brw_context *brw,<br>
    OUT_BATCH(((width - 1) << 4) | ((height - 1) << 18) | lod);<br>
    OUT_BATCH(((depth - 1) << 21) | (min_array_element << 10) | mocs_wb);<br>
    OUT_BATCH(0);<br>
-   OUT_BATCH(((depth - 1) << 21) | (depth_mt ? depth_mt->qpitch >> 2 : 0));<br>
+   OUT_BATCH(((depth - 1) << 21) |<br>
+              (depth_mt ? depth_mt->surf.array_pitch_el_<wbr>rows >> 2 : 0));<br>
    ADVANCE_BATCH();<br>
<br>
    if (!hiz) {<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>
</div></div>index 0776cd1bab..9fad722d90 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>
@@ -522,43 +522,7 @@ intel_miptree_create_layout(<wbr>struct brw_context *brw,<br>
<div><div class="h5">    mt->physical_height0 = height0;<br>
    mt->physical_depth0 = depth0;<br>
<br>
-   if (needs_separate_stencil(brw, mt, format, layout_flags)) {<br>
-      uint32_t stencil_flags = MIPTREE_LAYOUT_ACCELERATED_<wbr>UPLOAD;<br>
-      if (brw->gen == 6) {<br>
-         stencil_flags |= MIPTREE_LAYOUT_TILING_ANY;<br>
-      }<br>
-<br>
-      mt->stencil_mt = intel_miptree_create(brw,<br>
-                                            mt->target,<br>
-                                            MESA_FORMAT_S_UINT8,<br>
-                                            mt->first_level,<br>
-                                            mt->last_level,<br>
-                                            mt->logical_width0,<br>
-                                            mt->logical_height0,<br>
-                                            mt->logical_depth0,<br>
-                                            num_samples,<br>
-                                            stencil_flags);<br>
-<br>
-      if (!mt->stencil_mt) {<br>
-        intel_miptree_release(&mt);<br>
-        return NULL;<br>
-      }<br>
-      mt->stencil_mt->r8stencil_<wbr>needs_update = true;<br>
-<br>
-      /* Fix up the Z miptree format for how we're splitting out separate<br>
-       * stencil.  Gen7 expects there to be no stencil bits in its depth buffer.<br>
-       */<br>
-      mt->format = intel_depth_format_for_<wbr>depthstencil_format(mt-><wbr>format);<br>
-      mt->cpp = 4;<br>
-<br>
-      if (format == mt->format) {<br>
-         _mesa_problem(NULL, "Unknown format %s in separate stencil mt\n",<br>
-                       _mesa_get_format_name(mt-><wbr>format));<br>
-      }<br>
-   }<br>
-<br>
-   if (layout_flags & MIPTREE_LAYOUT_GEN6_HIZ_<wbr>STENCIL)<br>
-      mt->array_layout = GEN6_HIZ_STENCIL;<br>
+   assert(!needs_separate_<wbr>stencil(brw, mt, format, layout_flags));<br>
<br>
    /*<br>
     * Obey HALIGN_16 constraints for Gen8 and Gen9 buffers which are<br>
</div></div>@@ -831,6 +795,40 @@ fail:<br>
    return NULL;<br>
 }<br>
<br>
+static bool<br>
+make_separate_stencil_<wbr>surface(struct brw_context *brw,<br>
<div><div class="h5">+                              struct intel_mipmap_tree *mt)<br>
+{<br>
+   mt->stencil_mt = make_surface(brw, mt->target, MESA_FORMAT_S_UINT8,<br>
+                                 0, mt->surf.levels - 1,<br>
+                                 mt->surf.logical_level0_px.<wbr>width,<br>
+                                 mt->surf.logical_level0_px.<wbr>height,<br>
+                                 mt->surf.dim == ISL_SURF_DIM_3D ?<br>
+                                    mt->surf.logical_level0_px.<wbr>depth :<br>
+                                    mt->surf.logical_level0_px.<wbr>array_len,<br>
+                                 mt->surf.samples, ISL_TILING_W_BIT,<br>
+                                 ISL_SURF_USAGE_STENCIL_BIT |<br>
+                                 ISL_SURF_USAGE_TEXTURE_BIT,<br>
+                                 BO_ALLOC_FOR_RENDER, 0, NULL);<br>
+<br>
+   if (!mt->stencil_mt)<br>
+      return false;<br>
+<br>
+   mt->stencil_mt->r8stencil_<wbr>needs_update = true;<br>
+<br>
+   return true;<br>
+}<br>
+<br>
+static bool<br>
+force_linear_tiling(uint32_t layout_flags)<br>
+{<br>
+   /* ANY includes NONE and Y bit. */<br>
+   if (layout_flags & MIPTREE_LAYOUT_TILING_Y)<br>
+      return false;<br>
+<br>
+   return layout_flags & MIPTREE_LAYOUT_TILING_NONE;<br>
+}<br>
+<br>
 static struct intel_mipmap_tree *<br>
 miptree_create(struct brw_context *brw,<br>
                GLenum target,<br>
</div></div>@@ -851,6 +849,34 @@ miptree_create(struct brw_context *brw,<br>
<span class="">                           ISL_SURF_USAGE_TEXTURE_BIT,<br>
                           BO_ALLOC_FOR_RENDER, 0, NULL);<br>
<br>
+   const GLenum base_format = _mesa_get_format_base_format(<wbr>format);<br>
+   if ((base_format == GL_DEPTH_COMPONENT ||<br>
+        base_format == GL_DEPTH_STENCIL) &&<br>
+       !force_linear_tiling(layout_<wbr>flags)) {<br>
+      /* Fix up the Z miptree format for how we're splitting out separate<br>
+       * stencil.  Gen7 expects there to be no stencil bits in its depth buffer.<br>
+       */<br>
+      const mesa_format depth_only_format =<br>
+         intel_depth_format_for_<wbr>depthstencil_format(format);<br>
+      struct intel_mipmap_tree *mt = make_surface(<br>
+         brw, target, brw->gen >= 6 ? depth_only_format : format,<br>
+         first_level, last_level,<br>
+         width0, height0, depth0, num_samples, ISL_TILING_Y0_BIT,<br>
+         ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_TEXTURE_BIT,<br>
+         BO_ALLOC_FOR_RENDER, 0, NULL);<br>
+<br>
+      if (needs_separate_stencil(brw, mt, format, layout_flags) &&<br>
</span>+          !make_separate_stencil_<wbr>surface(brw, mt)) {<br>
<span class="">+         intel_miptree_release(&mt);<br>
+         return NULL;<br>
+      }<br>
+<br>
+      if (!(layout_flags & MIPTREE_LAYOUT_DISABLE_AUX))<br>
+         intel_miptree_choose_aux_<wbr>usage(brw, mt);<br>
+<br>
+      return mt;<br>
+   }<br>
+<br>
    struct intel_mipmap_tree *mt;<br>
    mesa_format tex_format = format;<br>
    mesa_format etc_format = MESA_FORMAT_NONE;<br>
</span>@@ -986,8 +1012,25 @@ intel_miptree_create_for_bo(<wbr>struct brw_context *brw,<br>
<span class="">    struct intel_mipmap_tree *mt;<br>
    uint32_t tiling, swizzle;<br>
    const GLenum target = depth > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;<br>
+   const GLenum base_format = _mesa_get_format_base_format(<wbr>format);<br>
+<br>
+   if ((base_format == GL_DEPTH_COMPONENT ||<br>
+        base_format == GL_DEPTH_STENCIL)) {<br>
+      const mesa_format depth_only_format =<br>
+         intel_depth_format_for_<wbr>depthstencil_format(format);<br>
+      mt = make_surface(brw, target,<br>
+                        brw->gen >= 6 ? depth_only_format : format,<br>
+                        0, 0, width, height, depth, 1, ISL_TILING_Y0_BIT,<br>
+                        ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_TEXTURE_BIT,<br>
+                        BO_ALLOC_FOR_RENDER, pitch, bo);<br>
<br>
-   if (format == MESA_FORMAT_S_UINT8) {<br>
</span><span class="">+      brw_bo_reference(bo);<br>
+<br>
+      if (!(layout_flags & MIPTREE_LAYOUT_DISABLE_AUX))<br>
+         intel_miptree_choose_aux_<wbr>usage(brw, mt);<br>
+<br>
+      return mt;<br>
+   } else if (format == MESA_FORMAT_S_UINT8) {<br>
       mt = make_surface(brw, target, MESA_FORMAT_S_UINT8,<br>
                         0, 0, width, height, depth, 1,<br>
                         ISL_TILING_W_BIT,<br>
</span>@@ -1975,10 +2018,11 @@ intel_miptree_level_enable_<wbr>hiz(struct brw_context *brw,<br>
<span class="">                                uint32_t level)<br>
 {<br>
    assert(mt->hiz_buf);<br>
+   assert(mt->surf.size > 0);<br>
<br>
    if (brw->gen >= 8 || brw->is_haswell) {<br>
-      uint32_t width = minify(mt->physical_width0, level);<br>
-      uint32_t height = minify(mt->physical_height0, level);<br>
+      uint32_t width = minify(mt->surf.phys_level0_<wbr>sa.width, level);<br>
+      uint32_t height = minify(mt->surf.phys_level0_<wbr>sa.height, level);<br>
<br>
       /* Disable HiZ for LOD > 0 unless the width is 8 aligned<br>
        * and the height is 4 aligned. This allows our HiZ support<br>
</span>@@ -2009,12 +2053,10 @@ intel_miptree_alloc_hiz(struct brw_context *brw,<br>
<span class="">    if (!aux_state)<br>
       return false;<br>
<br>
-   struct isl_surf temp_main_surf;<br>
    struct isl_surf temp_hiz_surf;<br>
<br>
-   intel_miptree_get_isl_surf(<wbr>brw, mt, &temp_main_surf);<br>
    MAYBE_UNUSED bool ok =<br>
-      isl_surf_get_hiz_surf(&brw-><wbr>isl_dev, &temp_main_surf, &temp_hiz_surf);<br>
+      isl_surf_get_hiz_surf(&brw-><wbr>isl_dev, &mt->surf, &temp_hiz_surf);<br>
    assert(ok);<br>
<br>
    const uint32_t alloc_flags = BO_ALLOC_FOR_RENDER;<br>
</span>@@ -2103,7 +2145,7 @@ intel_miptree_sample_with_hiz(<wbr>struct brw_context *brw,<br>
<div class="HOEnZb"><div class="h5">     * mipmap levels aren't available in the HiZ buffer. So we need all levels<br>
     * of the texture to be HiZ enabled.<br>
     */<br>
-   for (unsigned level = mt->first_level; level <= mt->last_level; ++level) {<br>
+   for (unsigned level = 0; level < mt->surf.levels; ++level) {<br>
       if (!intel_miptree_level_has_hiz(<wbr>mt, level))<br>
          return false;<br>
    }<br>
--<br>
2.11.0<br>
<br>
</div></div></blockquote></div><br></div>