<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jun 1, 2017 at 3:17 AM, 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 Tue, May 30, 2017 at 05:55:20PM -0700, Jason Ekstrand wrote:<br>
> ---<br>
>  src/intel/blorp/blorp_genX_<wbr>exec.h                | 32 ++++++++++++-<br>
>  src/intel/isl/isl_emit_depth_<wbr>stencil.c           |  1 +<br>
>  src/mesa/drivers/dri/i965/brw_<wbr>blorp.c            | 61 ------------------------<br>
>  src/mesa/drivers/dri/i965/brw_<wbr>wm_surface_state.c |  3 +-<br>
>  src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c    | 17 ++++---<br>
>  src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h    |  2 +-<br>
>  6 files changed, 42 insertions(+), 74 deletions(-)<br>
><br>
> diff --git a/src/intel/blorp/blorp_genX_<wbr>exec.h b/src/intel/blorp/blorp_genX_<wbr>exec.h<br>
> index 8b9b8d2..59c1d36 100644<br>
> --- a/src/intel/blorp/blorp_genX_<wbr>exec.h<br>
> +++ b/src/intel/blorp/blorp_genX_<wbr>exec.h<br>
> @@ -1384,9 +1384,23 @@ blorp_emit_depth_stencil_<wbr>config(struct blorp_batch *batch,<br>
>        if (info.hiz_usage == ISL_AUX_USAGE_HIZ) {<br>
>           info.hiz_surf = &params->depth.aux_surf;<br>
><br>
> +         struct blorp_address hiz_address = params->depth.aux_addr;<br>
> +#if GEN_GEN == 6<br>
> +         /* Sandy bridge hardware does not technically support mipmapped HiZ.<br>
> +          * However, we have a special layout that allows us to make it work<br>
> +          * anyway by manually offsetting to the specified miplevel.<br>
> +          */<br>
> +         assert(info.hiz_surf->dim_<wbr>layout == ISL_DIM_LAYOUT_GEN6_STENCIL_<wbr>HIZ);<br>
> +         uint32_t offset_B;<br>
> +         isl_surf_get_image_offset_B_<wbr>tile_sa(info.hiz_surf,<br>
> +                                             info.view->base_level, 0, 0,<br>
> +                                             &offset_B, NULL, NULL);<br>
> +         hiz_address.offset += offset_B;<br>
> +#endif<br>
> +<br>
>           info.hiz_address =<br>
>              blorp_emit_reloc(batch, dw + isl_dev->ds.hiz_offset / 4,<br>
> -                             params->depth.aux_addr, 0);<br>
> +                             hiz_address, 0);<br>
><br>
>           info.depth_clear_value = params->depth.clear_color.u32[<wbr>0];<br>
>        }<br>
> @@ -1395,9 +1409,23 @@ blorp_emit_depth_stencil_<wbr>config(struct blorp_batch *batch,<br>
>     if (params->stencil.enabled) {<br>
>        info.stencil_surf = &params->stencil.surf;<br>
><br>
> +      struct blorp_address stencil_address = params->stencil.addr;<br>
> +#if GEN_GEN == 6<br>
> +      /* Sandy bridge hardware does not technically support mipmapped stencil.<br>
> +       * However, we have a special layout that allows us to make it work<br>
> +       * anyway by manually offsetting to the specified miplevel.<br>
> +       */<br>
> +      assert(info.stencil_surf->dim_<wbr>layout == ISL_DIM_LAYOUT_GEN6_STENCIL_<wbr>HIZ);<br>
> +      uint32_t offset_B;<br>
> +      isl_surf_get_image_offset_B_<wbr>tile_sa(info.stencil_surf,<br>
> +                                          info.view->base_level, 0, 0,<br>
> +                                          &offset_B, NULL, NULL);<br>
> +      stencil_address.offset += offset_B;<br>
> +#endif<br>
> +<br>
>        info.stencil_address =<br>
>           blorp_emit_reloc(batch, dw + isl_dev->ds.stencil_offset / 4,<br>
> -                          params->stencil.addr, 0);<br>
> +                          stencil_address, 0);<br>
>     }<br>
><br>
>     isl_emit_depth_stencil_hiz_s(<wbr>isl_dev, dw, &info);<br>
> diff --git a/src/intel/isl/isl_emit_<wbr>depth_stencil.c b/src/intel/isl/isl_emit_<wbr>depth_stencil.c<br>
> index 41a01be..04bed07 100644<br>
> --- a/src/intel/isl/isl_emit_<wbr>depth_stencil.c<br>
> +++ b/src/intel/isl/isl_emit_<wbr>depth_stencil.c<br>
> @@ -158,6 +158,7 @@ isl_genX(emit_depth_stencil_<wbr>hiz_s)(const struct isl_device *dev, void *batch,<br>
>        hiz.SurfaceBaseAddress = info->hiz_address;<br>
>        hiz.<wbr>HierarchicalDepthBufferMOCS = info->mocs;<br>
>        hiz.SurfacePitch = info->hiz_surf->row_pitch - 1;<br>
> +<br>
<br>
</div></div>Leftover?<br><div><div class="h5"></div></div></blockquote><div><br></div><div>Yup.  Fixed.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
>  #if GEN_GEN >= 8<br>
>        /* From the SKL PRM Vol2a:<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 61c6bda..28be620 100644<br>
> --- a/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
> +++ b/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
> @@ -118,36 +118,6 @@ brw_blorp_init(struct brw_context *brw)<br>
>  }<br>
><br>
>  static void<br>
> -apply_gen6_stencil_hiz_<wbr>offset(struct isl_surf *surf,<br>
> -                              struct intel_mipmap_tree *mt,<br>
> -                              uint32_t lod,<br>
> -                              uint32_t *offset)<br>
> -{<br>
> -   assert(mt->array_layout == GEN6_HIZ_STENCIL);<br>
> -<br>
> -   if (mt->format == MESA_FORMAT_S_UINT8) {<br>
> -      /* Note: we can't compute the stencil offset using<br>
> -       * intel_miptree_get_aligned_<wbr>offset(), because the miptree<br>
> -       * claims that the region is untiled even though it's W tiled.<br>
> -       */<br>
> -      *offset = mt->level[lod].level_y * mt->pitch +<br>
> -                mt->level[lod].level_x * 64;<br>
> -   } else {<br>
> -      *offset = intel_miptree_get_aligned_<wbr>offset(mt,<br>
> -                                                 mt->level[lod].level_x,<br>
> -                                                 mt->level[lod].level_y);<br>
> -   }<br>
> -<br>
> -   surf->logical_level0_px.width = minify(surf->logical_level0_<wbr>px.width, lod);<br>
> -   surf->logical_level0_px.height = minify(surf->logical_level0_<wbr>px.height, lod);<br>
> -   surf->phys_level0_sa.width = minify(surf->phys_level0_sa.<wbr>width, lod);<br>
> -   surf->phys_level0_sa.height = minify(surf->phys_level0_sa.<wbr>height, lod);<br>
> -   surf->levels = 1;<br>
> -   surf->array_pitch_el_rows =<br>
> -      ALIGN(surf->phys_level0_sa.<wbr>height, surf->image_alignment_el.<wbr>height);<br>
> -}<br>
> -<br>
> -static void<br>
>  blorp_surf_for_miptree(struct brw_context *brw,<br>
>                         struct blorp_surf *surf,<br>
>                         struct intel_mipmap_tree *mt,<br>
> @@ -181,24 +151,6 @@ 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 == GEN6_HIZ_STENCIL) {<br>
> -      /* Sandy bridge stencil and HiZ use this GEN6_HIZ_STENCIL 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>
> -       * offset into the surface.  Since ISL doesn't know how to deal with the<br>
> -       * crazy GEN6_HIZ_STENCIL layout and since we have to do a manual<br>
> -       * offset of it anyway, we might as well do the offset here and keep the<br>
> -       * hacks inside the i965 driver.<br>
> -       *<br>
> -       * See also gen6_depth_stencil_state.c<br>
> -       */<br>
> -      uint32_t offset;<br>
> -      apply_gen6_stencil_hiz_offset(<wbr>&tmp_surfs[0], mt, *level, &offset);<br>
> -      surf->addr.offset += offset;<br>
> -      *level = 0;<br>
> -   }<br>
> -<br>
>     struct isl_surf *aux_surf = &tmp_surfs[1];<br>
>     intel_miptree_get_aux_isl_<wbr>surf(brw, mt, aux_surf, &surf->aux_usage);<br>
><br>
> @@ -258,19 +210,6 @@ blorp_surf_for_miptree(struct brw_context *brw,<br>
><br>
>           surf->aux_addr.buffer = mt->hiz_buf-><a href="http://aux_base.bo" rel="noreferrer" target="_blank">aux_base.bo</a>;<br>
>           surf->aux_addr.offset = mt->hiz_buf->aux_base.offset;<br>
> -<br>
> -         struct intel_mipmap_tree *hiz_mt = mt->hiz_buf->mt;<br>
> -         if (hiz_mt) {<br>
> -            assert(brw->gen == 6 && hiz_mt->array_layout == GEN6_HIZ_STENCIL);<br>
> -<br>
> -            /* gen6 requires the HiZ buffer to be manually offset to the<br>
> -             * right location.  We could fixup the surf but it doesn't<br>
> -             * matter since most of those fields don't matter.<br>
> -             */<br>
> -            apply_gen6_stencil_hiz_offset(<wbr>aux_surf, hiz_mt, *level,<br>
> -                                          &surf->aux_addr.offset);<br>
> -            assert(hiz_mt->pitch == aux_surf->row_pitch);<br>
> -         }<br>
>        }<br>
>     } else {<br>
>        surf->aux_addr = (struct blorp_address) {<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 e019adc..ddfb4f9 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>
> @@ -89,7 +89,8 @@ brw_emit_surface_state(struct brw_context *brw,<br>
>     surf.dim = get_isl_surf_dim(target);<br>
><br>
>     const enum isl_dim_layout dim_layout =<br>
> -      get_isl_dim_layout(&brw-><wbr>screen->devinfo, mt->tiling, target);<br>
> +      get_isl_dim_layout(&brw-><wbr>screen->devinfo, mt->tiling, target,<br>
> +                         mt->array_layout);<br>
><br>
>     if (surf.dim_layout != dim_layout) {<br>
>        /* The layout of the specified texture target is not compatible with the<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 c0eaab0..55b760b 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>
> @@ -1813,13 +1813,7 @@ intel_hiz_miptree_buf_create(<wbr>struct brw_context *brw,<br>
>     buf-><a href="http://aux_base.bo" rel="noreferrer" target="_blank">aux_base.bo</a> = buf->mt->bo;<br>
>     buf->aux_base.size = buf->mt->total_height * buf->mt->pitch;<br>
>     buf->aux_base.pitch = buf->mt->pitch;<br>
> -<br>
> -   /* On gen6 hiz is unconditionally laid out packing all slices<br>
> -    * at each level-of-detail (LOD). This means there is no valid qpitch<br>
> -    * setting. In fact, this is ignored when hardware is setup - there is no<br>
> -    * hardware qpitch setting of hiz on gen6.<br>
> -    */<br>
> -   buf->aux_base.qpitch = 0;<br>
> +   buf->aux_base.qpitch = buf->mt->qpitch * 2;<br>
<br>
</div></div>Is this really needed? I also didn't get the multiply by two.<br><div><div class="h5"></div></div></blockquote><div><br></div><div>I did this entirely for sanity-checking purposes.  Checking the qpitch is a quick and easy sanity check that ISL and brw_tex_layout calculated the same thing.  It's not necessary (so long as we remove an assert from ISL) but I like the safety.  You'll be deleting it soon enough anyway. :-)<br><br></div><div>Why multiply by 2?  because brw_tex_layout thinks it's Y-tiled while ISL has a concept of HiZ-tiled.  In order to get the right calculation in brw_tex_layout, we use a scale-down factor of 16x2 (a HiZ block is actually 8x4, see also Y vs. HiZ tiling).  Since all other qpitch values in intel_mipmap_tree are in terms of samples (not surface elements), we need to undo the scale-down.  Make sense?  It's really easy to get lost in all the calculations.  Just take comfort in the fact that this code will soon be gone. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
><br>
>     return buf;<br>
>  }<br>
> @@ -3133,8 +3127,11 @@ get_isl_surf_dim(GLenum target)<br>
><br>
>  enum isl_dim_layout<br>
>  get_isl_dim_layout(const struct gen_device_info *devinfo, uint32_t tiling,<br>
> -                   GLenum target)<br>
> +                   GLenum target, enum miptree_array_layout array_layout)<br>
>  {<br>
> +   if (array_layout == GEN6_HIZ_STENCIL)<br>
> +      return ISL_DIM_LAYOUT_GEN6_STENCIL_<wbr>HIZ;<br>
> +<br>
>     switch (target) {<br>
>     case GL_TEXTURE_1D:<br>
>     case GL_TEXTURE_1D_ARRAY:<br>
> @@ -3188,7 +3185,8 @@ intel_miptree_get_isl_surf(<wbr>struct brw_context *brw,<br>
>  {<br>
>     surf->dim = get_isl_surf_dim(mt->target);<br>
>     surf->dim_layout = get_isl_dim_layout(&brw-><wbr>screen->devinfo,<br>
> -                                         mt->tiling, mt->target);<br>
> +                                         mt->tiling, mt->target,<br>
> +                                         mt->array_layout);<br>
><br>
>     if (mt->num_samples > 1) {<br>
>        switch (mt->msaa_layout) {<br>
> @@ -3267,6 +3265,7 @@ intel_miptree_get_isl_surf(<wbr>struct brw_context *brw,<br>
>     switch (surf->dim_layout) {<br>
>     case ISL_DIM_LAYOUT_GEN4_2D:<br>
>     case ISL_DIM_LAYOUT_GEN4_3D:<br>
> +   case ISL_DIM_LAYOUT_GEN6_STENCIL_<wbr>HIZ:<br>
>        if (brw->gen >= 9) {<br>
>           surf->array_pitch_el_rows = mt->qpitch;<br>
>        } else {<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 be460f3..6096cab 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>
> @@ -804,7 +804,7 @@ get_isl_surf_dim(GLenum target);<br>
><br>
>  enum isl_dim_layout<br>
>  get_isl_dim_layout(const struct gen_device_info *devinfo, uint32_t tiling,<br>
> -                   GLenum target);<br>
> +                   GLenum target, enum miptree_array_layout array_layout);<br>
><br>
>  enum isl_tiling<br>
>  intel_miptree_get_isl_tiling(<wbr>const struct intel_mipmap_tree *mt);<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<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>
</blockquote></div><br></div></div>