<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 16, 2017 at 1:13 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">This is kept on purpose in i965. It can be moved to ISL if it<br>
is needed in vulkan.<br>
<br>
Pointers to miptrees are given solely for verification purposes.<br>
These will be dropped in following patches.<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>tex_layout.c    | 65 +++++++++++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/<wbr>gen6_depth_state.c  | 14 +++---<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h |  5 +++<br>
 3 files changed, 78 insertions(+), 6 deletions(-)<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 768f8a8..80b341a 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>
@@ -288,6 +288,71 @@ 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>
+                                          const struct intel_mipmap_tree *mt,<br>
+                                          unsigned level)<br>
+{<br>
+   assert(mt->array_layout == ALL_SLICES_AT_EACH_LOD);<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>
+   assert(level_x == mt->level[level].level_x);<br>
+   assert(level_y == mt->level[level].level_y);<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>
+   assert(two_rows_interleaved_<wbr>pitch == mt->pitch);<br>
+<br>
+   return level_y * two_rows_interleaved_pitch + level_x * 64;<br>
+}<br></blockquote><div><br></div><div>There's really no good place in this series to make this comment but I think this is as good as I'm going to get...<br><br></div><div>I can't quite tell what your long-term plan is for gen6 stencil and HiZ.  Eventually, I'd like to kill the ALL_SLICES_AT_EACH_LOD stuff.  The only reason why Jordan and the Igalia people did that in the first place was so that they could re-use existing surface calculation code.  Really, the requirement is that gen6 doesn't support multiple miplevels with HiZ and Stencil even though it does support arrays.  The point of the ALL_SLICES_AT_EACH_LOD layout is to, instead of making it an array of miptrees, it lays it out into a bunch of single-LOD arrays.  The fact that they happen to be layed out like a miptree is immaterial.<br><br></div><div>When Nanley and I were talking about this in the office, he had a very good suggestion.  What he suggested was to just have an array of isl_surf's, one for each miplevel and lay the single-LOD arrays out linearly in memory.  To compute the size of the gen6 stencil or HiZ buffer you would do something like this;<br><br></div><div>uint32_t size = 0;<br></div><div>for (level = 0; level < num_levels; level++) {<br></div><div>   isl_surf_init(&mt->gen6_per_level[level].surf,<br></div><div>              .width = minify(width, level),<br></div><div>              .height = minify(height, level),<br></div><div>              .depth = 1,<br></div><div>              .levels = 1,<br></div><div>              .array_len = array_len,<br></div><div>              .format = ISL_FORMAT_HIZ,<br>              ...);<br></div><div>   mt->gen6_per_level[level].offset = size;<br></div><div>   size += mt->gen6_per_level[level].surf.size;<br></div><div>}<br><br></div><div>Then in the gen6 hiz and stencil setup code, you would just offset it by mt->gen6_per_level[level].offset and be done with it.  There's no real reason why we need to keep all this ALL_SLICES_AT_EACH_LOD calculation stuff indefinitely.  We just need some way of putting all of the per-LOD images in the same BO.  (Technically, they don't even need to go in the same BO but it's kind of nice to do it that way.)<br><br></div><div>Thoughts?<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
 static void<br>
 brw_miptree_layout_2d(struct intel_mipmap_tree *mt)<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 cda66e8..80cb890 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,15 +189,17 @@ gen6_emit_depth_stencil_hiz(<wbr>struct brw_context *brw,<br>
       if (separate_stencil) {<br>
          uint32_t offset = 0;<br>
<br>
+         struct isl_surf temp_surf;<br>
+         intel_miptree_get_isl_surf(<wbr>brw, stencil_mt, &temp_surf);<br>
+<br>
          if (stencil_mt->array_layout == ALL_SLICES_AT_EACH_LOD) {<br>
             assert(stencil_mt->format == MESA_FORMAT_S_UINT8);<br>
+            offset = brw_stencil_all_slices_at_<wbr>each_lod_offset(<br>
+                        &temp_surf, stencil_mt, lod);<br>
<br>
-            /* Note: we can't compute the stencil offset using<br>
-             * intel_region_get_aligned_<wbr>offset(), because stencil_region<br>
-             * claims that the region is untiled even though it's W tiled.<br>
-             */<br>
-            offset = stencil_mt->level[lod].level_y * stencil_mt->pitch +<br>
-                     stencil_mt->level[lod].level_x * 64;<br>
+            assert(offset ==<br>
+                   stencil_mt->level[lod].level_y * stencil_mt->pitch +<br>
+                   stencil_mt->level[lod].level_x * 64);<br>
          }<br>
<br>
         BEGIN_BATCH(3);<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 476c46b..e51872f 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>
@@ -983,6 +983,11 @@ brw_miptree_get_vertical_<wbr>slice_pitch(const struct brw_context *brw,<br>
                                      const struct intel_mipmap_tree *mt,<br>
                                      unsigned level);<br>
<br>
+uint32_t<br>
+brw_stencil_all_slices_at_<wbr>each_lod_offset(const struct isl_surf *surf,<br>
+                                          const struct intel_mipmap_tree *mt,<br>
+                                          uint32_t level);<br>
+<br>
 void<br>
 brw_miptree_layout(struct brw_context *brw,<br>
                    struct intel_mipmap_tree *mt,<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.5<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>