<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 3, 2017 at 2:22 AM, 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">leaving y-tiled (r8stencil) copies still as they were.<br>
<br>
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>blorp.c         | 24 +++++++----<br>
 src/mesa/drivers/dri/i965/brw_<wbr>tex_layout.c    | 57 ---------------------------<br>
 src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c  | 31 +++++++--------<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c | 45 ++++++++++++++-------<br>
 4 files changed, 63 insertions(+), 94 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c b/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
index 158cf66..7b6c13d 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
@@ -146,8 +146,7 @@ blorp_surf_for_miptree(struct brw_context *brw,<br>
       .write_domain = is_render_target ? I915_GEM_DOMAIN_RENDER : 0,<br>
    };<br>
<br>
-   if (brw->gen == 6 && mt->format == MESA_FORMAT_S_UINT8 &&<br>
-       mt->array_layout == ALL_SLICES_AT_EACH_LOD) {<br>
+   if (brw->gen == 6 && mt->format == MESA_FORMAT_S_UINT8) {<br>
       /* Sandy bridge stencil and HiZ use this ALL_SLICES_AT_EACH_LOD hack in<br>
        * order to allow for layered rendering.  The hack makes each LOD of the<br>
        * stencil or HiZ buffer a single tightly packed array surface at some<br>
@@ -166,12 +165,23 @@ blorp_surf_for_miptree(struct brw_context *brw,<br>
        * consulted. Otherwise surf is ignored and there is no need to adjust<br>
        * it any further.  See blorp_emit_depth_stencil_<wbr>config().<br>
        */<br>
-      surf->addr.offset += brw_stencil_all_slices_at_<wbr>each_lod_offset(<br>
-                              surf->surf, *level);<br>
+      uint32_t x_offset_sa, y_offset_sa;<br>
+      get_image_offset_sa_gen6_back_<wbr>to_back(<br>
+         &mt->surf, *level, 0, 0, &x_offset_sa, &y_offset_sa);<br>
+      assert(x_offset_sa == 0);<br>
+<br>
+      /* The stencil buffer has quirky pitch requirements.  From Vol 2a,<br>
+       * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":<br>
+       *    The pitch must be set to 2x the value computed based on width, as<br>
+       *    the stencil buffer is stored with two rows interleaved.<br>
+       *<br>
+       * As ISL uses twice the width, byte offset calculation needs to use<br>
+       * half of that.<br>
+       */<br>
+      const uint32_t offset = y_offset_sa * mt->surf.row_pitch / 2;<br></blockquote><div><br></div>If you used isl_tiling_get_intratile_offset_sa, it would take care of this for you because it does a trip through logical tile sizes.<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      assert(offset % 4096 == 0);<br>
<br>
-      assert(brw_stencil_all_slices_<wbr>at_each_lod_offset(surf->surf, *level) ==<br>
-             mt->level[*level].level_y * mt->pitch +<br>
-             mt->level[*level].level_x * 64);<br>
+      surf->addr.offset += offset;<br>
<br>
       *level = 0;<br>
    }<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_tex_layout.c b/src/mesa/drivers/dri/i965/<wbr>brw_tex_layout.c<br>
index deac692..dec04d7 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_tex_layout.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_tex_layout.c<br>
@@ -163,63 +163,6 @@ gen9_miptree_layout_1d(struct intel_mipmap_tree *mt)<br>
    }<br>
 }<br>
<br>
-static unsigned<br>
-all_slices_at_each_lod_x_<wbr>offset(unsigned w0, unsigned align, unsigned level)<br>
-{<br>
-   const unsigned w = level >= 2 ? minify(w0, 1) : 0;<br>
-   return ALIGN(w, align);<br>
-}<br>
-<br>
-static unsigned<br>
-all_slices_at_each_lod_y_<wbr>offset(const struct isl_extent4d *phys_level0_sa,<br>
-                                enum isl_surf_dim dim, unsigned align,<br>
-                                unsigned level)<br>
-{<br>
-   unsigned y = 0;<br>
-<br>
-   /* Add vertical space taken by lower levels one by one. Levels one and two<br>
-    * are side-by-side just below level zero. Levels three and greater are<br>
-    * stacked one after another below level two.<br>
-    */<br>
-   for (unsigned i = 1; i <= level; ++i) {<br>
-      const unsigned d = dim == ISL_SURF_DIM_3D ?<br>
-                         minify(phys_level0_sa->depth, i - 1) :<br>
-                         phys_level0_sa->array_len;<br>
-<br>
-      /* Levels two and greater are stacked just below level zero. */<br>
-      if (i != 2) {<br>
-         const unsigned h = minify(phys_level0_sa->height, i - 1);<br>
-         y += d * ALIGN(h, align);<br>
-      }<br>
-   }<br>
-<br>
-   return y;<br>
-}<br>
-<br>
-uint32_t<br>
-brw_stencil_all_slices_at_<wbr>each_lod_offset(const struct isl_surf *surf,<br>
-                                          unsigned level)<br>
-{<br>
-   const unsigned halign = 64;<br>
-   const unsigned valign = 64;<br>
-   const unsigned level_x = all_slices_at_each_lod_x_<wbr>offset(<br>
-      surf->phys_level0_sa.width, halign, level);<br>
-   const unsigned level_y = all_slices_at_each_lod_y_<wbr>offset(<br>
-      &surf->phys_level0_sa, surf->dim, valign, level);<br>
-<br>
-   /* From Vol 2a, 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":<br>
-    *    The pitch must be set to 2x the value computed based on width, as<br>
-    *    the stencil buffer is stored with two rows interleaved.<br>
-    *<br>
-    * While ISL surface stores the pitch expected by hardware, the offset<br>
-    * into individual slices needs to be calculated as if rows are<br>
-    * interleaved.<br>
-    */<br>
-   const unsigned two_rows_interleaved_pitch = surf->row_pitch / 2;<br>
-<br>
-   return level_y * two_rows_interleaved_pitch + level_x * 64;<br>
-}<br>
-<br>
 uint32_t<br>
 brw_get_mipmap_total_width(<wbr>unsigned w0, unsigned num_levels, unsigned halign)<br>
 {<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c b/src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c<br>
index 16fb209..1850934 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c<br>
@@ -189,29 +189,28 @@ gen6_emit_depth_stencil_hiz(<wbr>struct brw_context *brw,<br>
<br>
       /* Emit stencil buffer. */<br>
       if (separate_stencil) {<br>
-         uint32_t offset = 0;<br>
+         assert(stencil_mt->format == MESA_FORMAT_S_UINT8);<br>
<br>
-         if (stencil_mt->array_layout == ALL_SLICES_AT_EACH_LOD) {<br>
-            assert(stencil_mt->format == MESA_FORMAT_S_UINT8);<br>
-<br>
-            struct isl_surf temp_surf;<br>
-            intel_miptree_get_isl_surf(<wbr>brw, stencil_mt, &temp_surf);<br>
-<br>
-            offset = brw_stencil_all_slices_at_<wbr>each_lod_offset(<br>
-                        &temp_surf, lod);<br>
-            assert(offset ==<br>
-                stencil_mt->level[lod].level_y * stencil_mt->pitch +<br>
-                stencil_mt->level[lod].level_x * 64);<br>
-         }<br>
+         uint32_t x_offset_sa, y_offset_sa;<br>
+         get_image_offset_sa_gen6_back_<wbr>to_back(&stencil_mt->surf,<br>
+                                               lod, 0, 0,<br>
+                                               &x_offset_sa, &y_offset_sa);<br></blockquote><div><br></div><div>Why are you calling this directly and not just using isl_surf_get_image_offset_sa?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         assert(x_offset_sa == 0);<br>
<br>
-        BEGIN_BATCH(3);<br>
-        OUT_BATCH((_3DSTATE_STENCIL_<wbr>BUFFER << 16) | (3 - 2));<br>
          /* The stencil buffer has quirky pitch requirements.  From Vol 2a,<br>
           * 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface Pitch":<br>
           *    The pitch must be set to 2x the value computed based on width, as<br>
           *    the stencil buffer is stored with two rows interleaved.<br>
+          *<br>
+          * As ISL uses twice the width, byte offset calculation needs to use<br>
+          * half of that.<br>
           */<br>
-        OUT_BATCH(2 * stencil_mt->pitch - 1);<br>
+         const uint32_t offset = y_offset_sa * stencil_mt->surf.row_pitch / 2;<br></blockquote><div><br></div><div>Again, use isl_tiling_get_intratile_offset_sa<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         assert(offset % 4096 == 0);<br>
+<br>
+        BEGIN_BATCH(3);<br>
+        OUT_BATCH((_3DSTATE_STENCIL_<wbr>BUFFER << 16) | (3 - 2));<br>
+        OUT_BATCH(stencil_mt->surf.<wbr>row_pitch - 1);<br>
         OUT_RELOC(stencil_mt->bo,<br>
                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,<br>
                   offset);<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 ced1e0e..febe880 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>
@@ -678,6 +678,14 @@ miptree_create(struct brw_context *brw,<br>
                GLuint num_samples,<br>
                uint32_t layout_flags)<br>
 {<br>
+   if (format == MESA_FORMAT_S_UINT8)<br>
+      return make_surface(brw, target, format, first_level, last_level,<br>
+                          width0, height0, depth0, num_samples,<br>
+                          ISL_TILING_W,<br>
+                          ISL_SURF_USAGE_STENCIL_BIT |<br>
+                          ISL_SURF_USAGE_TEXTURE_BIT,<br>
+                          BO_ALLOC_FOR_RENDER);<br>
+<br>
    struct intel_mipmap_tree *mt;<br>
    mesa_format tex_format = format;<br>
    mesa_format etc_format = MESA_FORMAT_NONE;<br>
@@ -2275,28 +2283,35 @@ intel_update_r8stencil(struct brw_context *brw,<br>
        !src->r8stencil_needs_update)<br>
       return;<br>
<br>
+   assert(src->surf.size > 0);<br>
+<br>
    if (!mt->r8stencil_mt) {<br>
       const uint32_t r8stencil_flags =<br>
          MIPTREE_LAYOUT_ACCELERATED_<wbr>UPLOAD | MIPTREE_LAYOUT_TILING_Y |<br>
          MIPTREE_LAYOUT_DISABLE_AUX;<br>
       assert(brw->gen > 6); /* Handle MIPTREE_LAYOUT_FORCE_ALL_<wbr>SLICE_AT_LOD */<br>
-      mt->r8stencil_mt = intel_miptree_create(brw,<br>
-                                              src->target,<br>
-                                              MESA_FORMAT_R_UINT8,<br>
-                                              src->first_level,<br>
-                                              src->last_level,<br>
-                                              src->logical_width0,<br>
-                                              src->logical_height0,<br>
-                                              src->logical_depth0,<br>
-                                              src->num_samples,<br>
-                                              r8stencil_flags);<br>
+      mt->r8stencil_mt = intel_miptree_create(<br>
+                            brw,<br>
+                            src->target,<br>
+                            MESA_FORMAT_R_UINT8,<br>
+                            0, src->surf.levels - 1,<br>
+                            src->surf.logical_level0_px.<wbr>width,<br>
+                            src->surf.logical_level0_px.<wbr>height,<br>
+                            src->surf.dim_layout == ISL_DIM_LAYOUT_GEN4_3D ?<br>
+                               src->surf.logical_level0_px.<wbr>depth :<br>
+                               src->surf.logical_level0_px.<wbr>array_len,<br>
+                            src->surf.samples,<br>
+                            r8stencil_flags);<br>
       assert(mt->r8stencil_mt);<br>
    }<br>
<br>
    struct intel_mipmap_tree *dst = mt->r8stencil_mt;<br>
<br>
-   for (int level = src->first_level; level <= src->last_level; level++) {<br>
-      const unsigned depth = src->level[level].depth;<br>
+   for (int level = 0; level < src->surf.levels; level++) {<br>
+      const unsigned depth = src->surf.dim_layout == ISL_DIM_LAYOUT_GEN4_3D ?<br></blockquote><div><br></div><div>ISL_SURF_DIM_3D<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         minify(src->surf.logical_<wbr>level0_px.depth, level) :<br>
+         src->surf.logical_level0_px.<wbr>array_len;<br>
+<br>
       const int layers_per_blit =<br>
          (dst->msaa_layout == INTEL_MSAA_LAYOUT_UMS ||<br>
           dst->msaa_layout == INTEL_MSAA_LAYOUT_CMS) ?<br>
@@ -2309,8 +2324,10 @@ intel_update_r8stencil(struct brw_context *brw,<br>
                                  dst, level, layers_per_blit * layer,<br>
                                  MESA_FORMAT_R_UNORM8,<br>
                                  0, 0,<br>
-                                 minify(src->logical_width0, level),<br>
-                                 minify(src->logical_height0, level),<br>
+                                 minify(src->surf.logical_<wbr>level0_px.width,<br>
+                                        level),<br>
+                                 minify(src->surf.logical_<wbr>level0_px.height,<br>
+                                        level),<br>
                                  0, 0,<br>
                                  minify(dst->logical_width0, level),<br>
                                  minify(dst->logical_height0, level),<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.3<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>
</font></span></blockquote></div><br></div></div>