<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 19, 2017 at 1:37 PM, Pohjolainen, Topi <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"><div class="HOEnZb"><div class="h5">On Wed, Jul 19, 2017 at 01:27:16PM -0700, Jason Ekstrand wrote:<br>
> On Wed, Jul 19, 2017 at 12:51 PM, Topi Pohjolainen <<br>
> <a href="mailto:topi.pohjolainen@gmail.com">topi.pohjolainen@gmail.com</a>> wrote:<br>
><br>
> > This makes intel_mipmap_tree::pitch and isl_surf::row_pitch<br>
> > semantically equivalent.<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/<wbr>gen7_misc_state.c   | 12 +------<br>
> >  src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c  | 16 +--------<br>
> >  src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c | 50<br>
> > ++++++++++-----------------<br>
> >  3 files changed, 20 insertions(+), 58 deletions(-)<br>
> ><br>
> > diff --git a/src/mesa/drivers/dri/i965/<wbr>gen7_misc_state.c<br>
> > b/src/mesa/drivers/dri/i965/<wbr>gen7_misc_state.c<br>
> > index 6c69fa8ba5..e189788a88 100644<br>
> > --- a/src/mesa/drivers/dri/i965/<wbr>gen7_misc_state.c<br>
> > +++ b/src/mesa/drivers/dri/i965/<wbr>gen7_misc_state.c<br>
> > @@ -170,19 +170,9 @@ gen7_emit_depth_stencil_hiz(<wbr>struct brw_context *brw,<br>
> ><br>
> >        BEGIN_BATCH(3);<br>
> >        OUT_BATCH(GEN7_3DSTATE_<wbr>STENCIL_BUFFER << 16 | (3 - 2));<br>
> > -      /* The stencil buffer has quirky pitch requirements.  From the<br>
> > -       * Sandybridge PRM, Volume 2 Part 1, page 329<br>
> > (3DSTATE_STENCIL_BUFFER<br>
> > -       * dword 1 bits 16:0 - Surface Pitch):<br>
> > -       *<br>
> > -       *    The pitch must be set to 2x the value computed based on<br>
> > width, as<br>
> > -       *    the stencil buffer is stored with two rows interleaved.<br>
> > -       *<br>
> > -       * While the Ivybridge PRM lacks this comment, the BSpec contains<br>
> > the<br>
> > -       * same text, and experiments indicate that this is necessary.<br>
> > -       */<br>
> >        OUT_BATCH(enabled |<br>
> >                  mocs << 25 |<br>
> > -               (2 * stencil_mt->pitch - 1));<br>
> > +               (stencil_mt->pitch - 1));<br>
> >        OUT_RELOC(stencil_mt->bo,<br>
> >                 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,<br>
> >                 0);<br>
> > diff --git a/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c<br>
> > b/src/mesa/drivers/dri/i965/<wbr>gen8_depth_state.c<br>
> > index 52c6dd0787..d05e1ba32e 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>
> > @@ -111,22 +111,8 @@ emit_depth_packets(struct brw_context *brw,<br>
> >     } else {<br>
> >        BEGIN_BATCH(5);<br>
> >        OUT_BATCH(GEN7_3DSTATE_<wbr>STENCIL_BUFFER << 16 | (5 - 2));<br>
> > -      /* The stencil buffer has quirky pitch requirements.  From the<br>
> > Graphics<br>
> > -       * BSpec: vol2a.11 3D Pipeline Windower > Early Depth/Stencil<br>
> > Processing<br>
> > -       * > Depth/Stencil Buffer State > 3DSTATE_STENCIL_BUFFER [DevIVB+],<br>
> > -       * field "Surface Pitch":<br>
> > -       *<br>
> > -       *    The pitch must be set to 2x the value computed based on<br>
> > width, as<br>
> > -       *    the stencil buffer is stored with two rows interleaved.<br>
> > -       *<br>
> > -       * (Note that it is not 100% clear whether this intended to apply to<br>
> > -       * Gen7; the BSpec flags this comment as "DevILK,DevSNB" (which<br>
> > would<br>
> > -       * imply that it doesn't), however the comment appears on a<br>
> > "DevIVB+"<br>
> > -       * page (which would imply that it does).  Experiments with the<br>
> > hardware<br>
> > -       * indicate that it does.<br>
> > -       */<br>
> >        OUT_BATCH(HSW_STENCIL_ENABLED | mocs_wb << 22 |<br>
> > -                (2 * stencil_mt->pitch - 1));<br>
> > +                (stencil_mt->pitch - 1));<br>
> >        OUT_RELOC64(stencil_mt->bo,<br>
> >                    I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);<br>
> >        OUT_BATCH(stencil_mt ? stencil_mt->qpitch >> 2 : 0);<br>
> > diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
> > b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
> > index 925c67fc50..9244a35d4f 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>
> > @@ -858,6 +858,18 @@ miptree_create(struct brw_context *brw,<br>
> >                                          mt->surf.tiling),<br>
> >                                       &mt->pitch,<br>
> >                                       alloc_flags);<br>
> > +<br>
> > +      /* The stencil buffer has quirky pitch requirements.  From the<br>
> > +       * Sandybridge PRM, Volume 2 Part 1, page 329<br>
> > (3DSTATE_STENCIL_BUFFER<br>
> > +       * dword 1 bits 16:0 - Surface Pitch):<br>
> > +       *<br>
> > +       *    The pitch must be set to 2x the value computed based on<br>
> > width, as<br>
> > +       *    the stencil buffer is stored with two rows interleaved.<br>
> > +       *<br>
> > +       * While the Ivybridge PRM lacks this comment, the BSpec contains<br>
> > the<br>
> > +       * same text, and experiments indicate that this is necessary.<br>
> > +       */<br>
> > +      mt->pitch *= 2;<br>
<br>
</div></div>Here we make it to what gpu wants.<br>
<span class=""><br>
> >     } else {<br>
> >        mt->bo = brw_bo_alloc_tiled_2d(brw-><wbr>bufmgr, "miptree",<br>
> >                                       mt->total_width, mt->total_height,<br>
> > @@ -2819,7 +2831,7 @@ intel_offset_S8(uint32_t stride, uint32_t x,<br>
> > uint32_t y, bool swizzled)<br>
> >     uint32_t tile_size = 4096;<br>
> >     uint32_t tile_width = 64;<br>
> >     uint32_t tile_height = 64;<br>
> > -   uint32_t row_size = 64 * stride;<br>
> > +   uint32_t row_size = 64 * stride / 2; /* Two rows are interleaved. */<br>
<br>
</span>And here we take into account the "pitch-for-two-interleaved rows" for<br>
byte offset calculation.<br>
<span class=""><br>
> ><br>
> >     uint32_t tile_x = x / tile_width;<br>
> >     uint32_t tile_y = y / tile_height;<br>
> > @@ -3197,12 +3209,8 @@ intel_miptree_map_s8(struct brw_context *brw,<br>
> >      * temporary buffer back out.<br>
> >      */<br>
> >     if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {<br>
> > -      /* ISL uses a stencil pitch value that is expected by hardware<br>
> > whereas<br>
> > -       * traditional miptree uses half of that. Below the value gets<br>
> > supplied<br>
> > -       * to intel_offset_S8() which expects the legacy interpretation.<br>
> > -       */<br>
> >        const unsigned pitch = mt->surf.size > 0 ?<br>
> > -                             mt->surf.row_pitch / 2 : mt->pitch;<br>
> > +                             mt->surf.row_pitch : mt->pitch;<br>
> ><br>
><br>
> Wait, don't you want to add a "/ 2" to mt->pitch not remove it from<br>
> surf.row_pitch?<br>
<br>
</span>It needs to get removed. See above.<br><div class="HOEnZb"><div class="h5"></div></div></blockquote><div><br></div><div>Ok, I missed the interaction with offset_S8.  This looks good<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
><br>
><br>
> >        uint8_t *untiled_s8_map = map->ptr;<br>
> >        uint8_t *tiled_s8_map = intel_miptree_map_raw(brw, mt,<br>
> > GL_MAP_READ_BIT);<br>
> >        unsigned int image_x, image_y;<br>
> > @@ -3239,12 +3247,8 @@ intel_miptree_unmap_s8(struct brw_context *brw,<br>
> >                        unsigned int slice)<br>
> >  {<br>
> >     if (map->mode & GL_MAP_WRITE_BIT) {<br>
> > -      /* ISL uses a stencil pitch value that is expected by hardware<br>
> > whereas<br>
> > -       * traditional miptree uses half of that. Below the value gets<br>
> > supplied<br>
> > -       * to intel_offset_S8() which expects the legacy interpretation.<br>
> > -       */<br>
> >        const unsigned pitch = mt->surf.size > 0 ?<br>
> > -                             mt->surf.row_pitch / 2: mt->pitch;<br>
> > +                             mt->surf.row_pitch : mt->pitch;<br>
> ><br>
><br>
> Same here.<br>
><br>
><br>
> >        unsigned int image_x, image_y;<br>
> >        uint8_t *untiled_s8_map = map->ptr;<br>
> >        uint8_t *tiled_s8_map = intel_miptree_map_raw(brw, mt,<br>
> > GL_MAP_WRITE_BIT);<br>
> > @@ -3352,12 +3356,8 @@ intel_miptree_map_<wbr>depthstencil(struct brw_context<br>
> > *brw,<br>
> >      * temporary buffer back out.<br>
> >      */<br>
> >     if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {<br>
> > -      /* ISL uses a stencil pitch value that is expected by hardware<br>
> > whereas<br>
> > -       * traditional miptree uses half of that. Below the value gets<br>
> > supplied<br>
> > -       * to intel_offset_S8() which expects the legacy interpretation.<br>
> > -       */<br>
> >        const unsigned s_pitch = s_mt->surf.size > 0 ?<br>
> > -                               s_mt->surf.row_pitch / 2 : s_mt->pitch;<br>
> > +                               s_mt->surf.row_pitch : s_mt->pitch;<br>
> ><br>
><br>
> And here.<br>
><br>
><br>
> >        uint32_t *packed_map = map->ptr;<br>
> >        uint8_t *s_map = intel_miptree_map_raw(brw, s_mt, GL_MAP_READ_BIT);<br>
> >        uint32_t *z_map = intel_miptree_map_raw(brw, z_mt, GL_MAP_READ_BIT);<br>
> > @@ -3419,12 +3419,8 @@ intel_miptree_unmap_<wbr>depthstencil(struct<br>
> > brw_context *brw,<br>
> >     bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z_FLOAT32;<br>
> ><br>
> >     if (map->mode & GL_MAP_WRITE_BIT) {<br>
> > -      /* ISL uses a stencil pitch value that is expected by hardware<br>
> > whereas<br>
> > -       * traditional miptree uses half of that. Below the value gets<br>
> > supplied<br>
> > -       * to intel_offset_S8() which expects the legacy interpretation.<br>
> > -       */<br>
> >        const unsigned s_pitch = s_mt->surf.size > 0 ?<br>
> > -                               s_mt->surf.row_pitch / 2 : s_mt->pitch;<br>
> > +                               s_mt->surf.row_pitch : s_mt->pitch;<br>
> ><br>
><br>
> And here.<br>
><br>
><br>
> >        uint32_t *packed_map = map->ptr;<br>
> >        uint8_t *s_map = intel_miptree_map_raw(brw, s_mt, GL_MAP_WRITE_BIT);<br>
> >        uint32_t *z_map = intel_miptree_map_raw(brw, z_mt,<br>
> > GL_MAP_WRITE_BIT);<br>
> > @@ -3738,17 +3734,7 @@ intel_miptree_get_isl_surf(<wbr>struct brw_context *brw,<br>
> >                                           mt->array_layout);<br>
> >     surf->msaa_layout = mt->surf.msaa_layout;<br>
> >     surf->tiling = intel_miptree_get_isl_tiling(<wbr>mt);<br>
> > -<br>
> > -   if (mt->format == MESA_FORMAT_S_UINT8) {<br>
> > -      /* The ISL definition of row_pitch matches the surface state pitch<br>
> > field<br>
> > -       * a bit better than intel_mipmap_tree.  In particular, ISL<br>
> > incorporates<br>
> > -       * the factor of 2 for W-tiling in row_pitch.<br>
> > -       */<br>
> > -      surf->row_pitch = 2 * mt->pitch;<br>
> > -   } else {<br>
> > -      surf->row_pitch = mt->pitch;<br>
> > -   }<br>
> > -<br>
> > +   surf->row_pitch = mt->pitch;<br>
> >     surf->format = translate_tex_format(brw, mt->format, false);<br>
> ><br>
> >     if (brw->gen >= 9) {<br>
> > --<br>
> > 2.11.0<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>
> ><br>
</div></div></blockquote></div><br></div></div>