<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 11, 2016 at 12:26 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">There are actually two contradicting pieces in the bspec:<br>
<br>
>From the BSpec: 3D-Media-GPGPU Engine - 3D Pipeline Stages - Pixel -<br>
Pixel Backend [IVB+] - MCS Buffer for Render Target(s)<br>
<br>
BDW:  Mip-mapped and arrayed surfaces are supported with MCS buffer<br>
      layout with these alignments in the RT space:<br>
      Horizontal Alignment = 256 and Vertical Alignment = 128.<br>
SKL+: Mip-mapped and arrayed surfaces are supported with MCS buffer<br>
      layout with these alignments in the RT space: Horizontal<br>
      Alignment = 128 and Vertical Alignment = 64.<br>
<br>
and<br>
<br>
>From the BSpec: GT - Shared Functions - vol5c Shared Functions -<br>
RENDER_SURFACE_STATE [BDW+] Issues Info 2:<br>
<br>
PRE-SKL<br>
For non-multisampled render target's auxiliary surface, MCS, QPitch<br>
must be computed with Horizontal Alignment = 256 and Surface Vertical<br>
Alignment = 128. These alignments are only for MCS buffer and not for<br>
associated render target.<br>
<br>
SKL+<br>
For non-multisampled render target's CCS auxiliary surface, QPitch<br>
must be computed with Horizontal Alignment = 128 and Surface Vertical<br>
Alignment = 256. These alignments are only for CCS buffer and not for<br>
associated render target.<br>
<br>
The former seems to hold for individual mip-levels and the latter<br>
for qpitch.<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       | 68 +++++++++++++++++++-----<br>
 src/mesa/drivers/dri/i965/brw_<wbr>wm_surface_state.c |  2 +-<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c    | 31 ++++++++++-<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h    |  4 +-<br>
 4 files changed, 89 insertions(+), 16 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 94ded33..9c28500 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>
@@ -199,8 +199,24 @@ tr_mode_vertical_texture_<wbr>alignment(const struct intel_mipmap_tree *mt)<br>
<br>
 static unsigned int<br>
 intel_vertical_texture_<wbr>alignment_unit(struct brw_context *brw,<br>
-                                      const struct intel_mipmap_tree *mt)<br>
+                                      const struct intel_mipmap_tree *mt,<br>
+                                      uint32_t layout_flags)<br>
 {<br>
+   /* From the BSpec: 3D-Media-GPGPU Engine - 3D Pipeline Stages - Pixel -<br>
+    * Pixel Backend [IVB+] - MCS Buffer for Render Target(s)<br>
+    *<br>
+    * BDW:  Mip-mapped and arrayed surfaces are supported with MCS buffer<br>
+    *       layout with these alignments in the RT space:<br>
+    *       Horizontal Alignment = 256 and Vertical Alignment = 128.<br>
+    * SKL+: Mip-mapped and arrayed surfaces are supported with MCS buffer<br>
+    *       layout with these alignments in the RT space: Horizontal<br>
+    *       Alignment = 128 and Vertical Alignment = 64.<br>
+    */<br>
+   if (brw->gen >= 8 && mt->num_samples <= 1 &&<br>
+       layout_flags & MIPTREE_LAYOUT_FOR_MCS) {<br>
+      return brw->gen == 8 ? 128 : 64;<br>
+   }<br>
+<br>
    /**<br>
     * +-----------------------------<wbr>------------------------------<wbr>-----------+<br>
     * |                                        | alignment unit height ("j") |<br>
@@ -380,7 +396,7 @@ brw_miptree_get_horizontal_<wbr>slice_pitch(const struct brw_context *brw,<br>
 unsigned<br>
 brw_miptree_get_vertical_<wbr>slice_pitch(const struct brw_context *brw,<br>
                                      const struct intel_mipmap_tree *mt,<br>
-                                     unsigned level)<br>
+                                     unsigned level, uint32_t layout_flags)<br>
 {<br>
    unsigned qpitch;<br>
<br>
@@ -420,6 +436,26 @@ brw_miptree_get_vertical_<wbr>slice_pitch(const struct brw_context *brw,<br>
       qpitch = h0 + h1 + (brw->gen >= 7 ? 12 : 11) * mt->valign;<br>
    }<br>
<br>
+   /* From the BSpec: GT - Shared Functions - vol5c Shared Functions -<br>
+    * RENDER_SURFACE_STATE [BDW+] Issues Info 2:<br>
+    *<br>
+    * PRE-SKL<br>
+    * For non-multisampled render target's auxiliary surface, MCS, QPitch<br>
+    * must be computed with Horizontal Alignment = 256 and Surface Vertical<br>
+    * Alignment = 128. These alignments are only for MCS buffer and not for<br>
+    * associated render target.<br>
+    *<br>
+    * SKL+<br>
+    * For non-multisampled render target's CCS auxiliary surface, QPitch<br>
+    * must be computed with Horizontal Alignment = 128 and Surface Vertical<br>
+    * Alignment = 256. These alignments are only for CCS buffer and not for<br>
+    * associated render target.<br>
+    */<br>
+   if (brw->gen >= 8 && (layout_flags & MIPTREE_LAYOUT_FOR_MCS) &&<br>
+       (mt->last_level || mt->logical_depth0 > 1)) {<br>
+      qpitch = ALIGN(qpitch, brw->gen == 8 ? 128 : 256);<br>
+   }<br>
+<br>
    return qpitch;<br>
 }<br>
<br>
@@ -459,7 +495,8 @@ gen9_use_linear_1d_layout(<wbr>const struct brw_context *brw,<br>
<br>
 static void<br>
 brw_miptree_layout_texture_<wbr>array(struct brw_context *brw,<br>
-                                struct intel_mipmap_tree *mt)<br>
+                                 struct intel_mipmap_tree *mt,<br>
+                                 uint32_t layout_flags)<br>
 {<br>
    unsigned height = mt->physical_height0;<br>
    bool layout_1d = gen9_use_linear_1d_layout(brw, mt);<br>
@@ -479,7 +516,9 @@ brw_miptree_layout_texture_<wbr>array(struct brw_context *brw,<br>
        */<br>
       mt->qpitch = mt->total_width;<br>
    } else {<br>
-      mt->qpitch = brw_miptree_get_vertical_<wbr>slice_pitch(brw, mt, 0);<br>
+      mt->qpitch = brw_miptree_get_vertical_<wbr>slice_pitch(brw, mt, 0,<br>
+                                                        layout_flags);<br>
+<br>
       /* Unlike previous generations the qpitch is a multiple of the<br>
        * compressed block size on Gen9 so physical_qpitch matches mt->qpitch.<br>
        */<br>
@@ -653,7 +692,8 @@ brw_miptree_choose_tiling(<wbr>struct brw_context *brw,<br>
<br>
 static void<br>
 intel_miptree_set_total_width_<wbr>height(struct brw_context *brw,<br>
-                                     struct intel_mipmap_tree *mt)<br>
+                                     struct intel_mipmap_tree *mt,<br>
+                                     uint32_t layout_flags)<br>
 {<br>
    switch (mt->target) {<br>
    case GL_TEXTURE_CUBE_MAP:<br>
@@ -663,29 +703,30 @@ intel_miptree_set_total_width_<wbr>height(struct brw_context *brw,<br>
          brw_miptree_layout_texture_3d(<wbr>brw, mt);<br>
       } else {<br>
          /* All other hardware stores cube maps as 2D arrays. */<br>
-        brw_miptree_layout_texture_<wbr>array(brw, mt);<br>
+         brw_miptree_layout_texture_<wbr>array(brw, mt, layout_flags);<br>
       }<br>
       break;<br>
<br>
    case GL_TEXTURE_3D:<br>
-      if (brw->gen >= 9)<br>
-         brw_miptree_layout_texture_<wbr>array(brw, mt);<br>
-      else<br>
+      if (brw->gen >= 9) {<br>
+         brw_miptree_layout_texture_<wbr>array(brw, mt, layout_flags);<br>
+      } else {<br>
          brw_miptree_layout_texture_3d(<wbr>brw, mt);<br>
+      }<br>
       break;<br>
<br>
    case GL_TEXTURE_1D_ARRAY:<br>
    case GL_TEXTURE_2D_ARRAY:<br>
    case GL_TEXTURE_2D_MULTISAMPLE_<wbr>ARRAY:<br>
    case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
-      brw_miptree_layout_texture_<wbr>array(brw, mt);<br>
+      brw_miptree_layout_texture_<wbr>array(brw, mt, layout_flags);<br>
       break;<br>
<br>
    default:<br>
       switch (mt->msaa_layout) {<br>
       case INTEL_MSAA_LAYOUT_UMS:<br>
       case INTEL_MSAA_LAYOUT_CMS:<br>
-         brw_miptree_layout_texture_<wbr>array(brw, mt);<br>
+         brw_miptree_layout_texture_<wbr>array(brw, mt, layout_flags);<br>
          break;<br>
       case INTEL_MSAA_LAYOUT_NONE:<br>
       case INTEL_MSAA_LAYOUT_IMS:<br>
@@ -769,7 +810,8 @@ intel_miptree_set_alignment(<wbr>struct brw_context *brw,<br>
    } else {<br>
       mt->halign =<br>
          intel_horizontal_texture_<wbr>alignment_unit(brw, mt, layout_flags);<br>
-      mt->valign = intel_vertical_texture_<wbr>alignment_unit(brw, mt);<br>
+      mt->valign = intel_vertical_texture_<wbr>alignment_unit(brw, mt,<br>
+                                                         layout_flags);<br>
    }<br>
 }<br>
<br>
@@ -781,7 +823,7 @@ brw_miptree_layout(struct brw_context *brw,<br>
    mt->tr_mode = INTEL_MIPTREE_TRMODE_NONE;<br>
<br>
    intel_miptree_set_alignment(<wbr>brw, mt, layout_flags);<br>
-   intel_miptree_set_total_width_<wbr>height(brw, mt);<br>
+   intel_miptree_set_total_width_<wbr>height(brw, mt, layout_flags);<br>
<br>
    if (!mt->total_width || !mt->total_height) {<br>
       intel_miptree_release(&mt);<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
index 7ee9486..482a034 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
@@ -1669,7 +1669,7 @@ update_texture_image_param(<wbr>struct brw_context *brw,<br>
    param->stride[2] =<br>
       brw_miptree_get_horizontal_<wbr>slice_pitch(brw, mt, u->Level);<br>
    param->stride[3] =<br>
-      brw_miptree_get_vertical_<wbr>slice_pitch(brw, mt, u->Level);<br>
+      brw_miptree_get_vertical_<wbr>slice_pitch(brw, mt, u->Level, 0);<br>
<br>
    if (mt->tiling == I915_TILING_X) {<br>
       /* An X tile is a rectangular block of 512x8 bytes. */<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 0fed0ee..f51392f 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>
@@ -1624,7 +1624,8 @@ intel_miptree_alloc_non_msrt_<wbr>mcs(struct brw_context *brw,<br>
    uint32_t layout_flags = MIPTREE_LAYOUT_TILING_Y;<br>
<br>
    if (brw->gen >= 8) {<br>
-      layout_flags |= MIPTREE_LAYOUT_FORCE_HALIGN16;<br>
+      layout_flags |= (MIPTREE_LAYOUT_FORCE_HALIGN16 |<br>
+                       MIPTREE_LAYOUT_FOR_MCS);<br>
    }<br>
<br>
    /* In case of compression mcs buffer needs to be initialised requiring the<br>
@@ -1664,6 +1665,34 @@ intel_miptree_alloc_non_msrt_<wbr>mcs(struct brw_context *brw,<br>
       mt->msaa_layout = INTEL_MSAA_LAYOUT_CMS;<br>
    }<br>
<br>
+   /* From the BSpec: GT - Shared Functions - vol5c Shared Functions -<br>
+    * RENDER_SURFACE_STATE [BDW+] Issues Info 2:<br>
+    *<br>
+    * PRE-SKL<br>
+    * For non-multisampled render target's auxiliary surface, MCS, QPitch<br>
+    * must be computed with Horizontal Alignment = 256 and Surface Vertical<br>
+    * Alignment = 128. These alignments are only for MCS buffer and not for<br>
+    * associated render target.<br>
+    *<br>
+    * SKL+<br>
+    * For non-multisampled render target's CCS auxiliary surface, QPitch<br>
+    * must be computed with Horizontal Alignment = 128 and Surface Vertical<br>
+    * Alignment = 256. These alignments are only for CCS buffer and not for<br>
+    * associated render target.<br>
+    */<br>
+   if ((mt->last_level || mt->logical_depth0 > 1)) {<br>
+      if (brw->gen >= 9) {<br>
+         assert(mt->pitch % 128 == 0);<br>
+      } else if (brw->gen == 8) {<br>
+         /* TODO: In practise, alignment of 256 causes hangs - fall back to<br>
+          * 128.<br>
+          */<br>
+         assert(mt->pitch % 128 == 0);<br></blockquote><div><br></div><div>Are you sure you want pitch here?  The pitch is in terms of bytes not pixels in the primary surface.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      } else {<br>
+         unreachable("mipmapped or/and arrayed are only supported for gen8+");<br>
+      }<br>
+   }<br>
+<br>
    return mt->mcs_mt;<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 079fb4a..1ba2fb9 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>
@@ -667,6 +667,8 @@ enum {<br>
                                              MIPTREE_LAYOUT_TILING_NONE,<br>
<br>
    MIPTREE_LAYOUT_FOR_SCANOUT              = 1 << 7,<br>
+<br>
+   MIPTREE_LAYOUT_FOR_MCS                  = 1 << 8,<br>
 };<br>
<br>
 struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,<br>
@@ -964,7 +966,7 @@ brw_miptree_get_horizontal_<wbr>slice_pitch(const struct brw_context *brw,<br>
 unsigned<br>
 brw_miptree_get_vertical_<wbr>slice_pitch(const struct brw_context *brw,<br>
                                      const struct intel_mipmap_tree *mt,<br>
-                                     unsigned level);<br>
+                                     unsigned level, uint32_t layout_flags);<br>
<br>
 void<br>
 brw_miptree_layout(struct brw_context *brw,<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>