[Mesa-dev] [PATCH 1/3] etnaviv: support tile aligned RS blits

Wladimir J. van der Laan laanwj at gmail.com
Tue Sep 19 14:24:24 UTC 2017


On Fri, Sep 15, 2017 at 06:00:52PM +0200, Lucas Stach wrote:
> The RS can blit abitrary tile aligned subregions of a resource by
> adjusting the buffer offset.

Thanks for doing this.

Comments inline,

> Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
> ---
>  src/gallium/drivers/etnaviv/etnaviv_clear_blit.c | 75 +++++++++++++++++++++---
>  1 file changed, 67 insertions(+), 8 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> index 92c91073434a..6734968ee4ed 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> @@ -358,6 +358,38 @@ etna_manual_blit(struct etna_resource *dst, struct etna_resource_level *dst_lev,
>     return true;
>  }
>  
> +static inline size_t
> +etna_compute_tileoffset(const struct pipe_box *box, enum pipe_format format,
> +                        size_t stride, enum etna_surface_layout layout)
> +{
> +   size_t offset;
> +   unsigned x = box->x, y = box->y;
> +
> +   switch (layout) {
> +   case ETNA_LAYOUT_LINEAR:
> +      offset = y * stride + x * util_format_get_blocksize(format);
> +      break;
> +   case ETNA_LAYOUT_MULTI_TILED:
> +      y >>= 1;
> +      /* fall-through */
> +   case ETNA_LAYOUT_TILED:
> +      offset = (y & ~0x03) * stride +
> +               util_format_get_blocksize(format) * ((x & ~0x03) << 2);
> +      break;
> +   case ETNA_LAYOUT_MULTI_SUPERTILED:
> +      y >>= 1;
> +      /* fall-through */
> +   case ETNA_LAYOUT_SUPER_TILED:
> +      offset = (y & ~0x3f) * stride +
> +               util_format_get_blocksize(format) * ((x & ~0x3f) << 6);
> +      break;
> +   default:
> +      unreachable("invalid resource layout");
> +   }
> +
> +   return offset;

Maybe add assertions that the passed-in coordinates are really tile-aligned
for the layout type, this could catch some bugs.

> +}
> +
>  static bool
>  etna_try_rs_blit(struct pipe_context *pctx,
>                   const struct pipe_blit_info *blit_info)
> @@ -399,14 +431,32 @@ etna_try_rs_blit(struct pipe_context *pctx,
>     unsigned dst_format = etna_compatible_rs_format(blit_info->dst.format);
>     if (translate_rs_format(src_format) == ETNA_NO_MATCH ||
>         translate_rs_format(dst_format) == ETNA_NO_MATCH ||
> -       blit_info->scissor_enable || blit_info->src.box.x != 0 ||
> -       blit_info->src.box.y != 0 || blit_info->dst.box.x != 0 ||
> -       blit_info->dst.box.y != 0 ||
> +       blit_info->scissor_enable ||
>         blit_info->dst.box.depth != blit_info->src.box.depth ||
>         blit_info->dst.box.depth != 1) {
>        return FALSE;
>     }
>  
> +   unsigned w_mask, h_mask;
> +
> +   if (src->layout & ETNA_LAYOUT_BIT_SUPER) {
> +      w_mask = h_mask = 0x3f;
> +   } else {
> +      w_mask = ETNA_RS_WIDTH_MASK;
> +      h_mask = ((ETNA_RS_HEIGHT_MASK + 1) * ctx->screen->specs.pixel_pipes - 1);
> +   }
> +   if ((blit_info->src.box.x & w_mask) || (blit_info->src.box.y & h_mask))
> +      return FALSE;
> +
> +   if (dst->layout & ETNA_LAYOUT_BIT_SUPER) {
> +      w_mask = h_mask = 0x3f;
> +   } else {
> +      w_mask = ETNA_RS_WIDTH_MASK;
> +      h_mask = ((ETNA_RS_HEIGHT_MASK + 1) * ctx->screen->specs.pixel_pipes - 1);
> +   }
> +   if ((blit_info->dst.box.x & w_mask) || (blit_info->dst.box.y & h_mask))
> +      return FALSE;
> +
>     /* Ensure that the Z coordinate is sane */
>     if (dst->base.target != PIPE_TEXTURE_CUBE)
>        assert(blit_info->dst.box.z == 0);
> @@ -426,10 +476,18 @@ etna_try_rs_blit(struct pipe_context *pctx,
>     assert(blit_info->dst.box.x + blit_info->dst.box.width <= dst_lev->padded_width);
>     assert(blit_info->dst.box.y + blit_info->dst.box.height <= dst_lev->padded_height);
>  
> -   unsigned src_offset =
> -      src_lev->offset + blit_info->src.box.z * src_lev->layer_stride;
> -   unsigned dst_offset =
> -      dst_lev->offset + blit_info->dst.box.z * dst_lev->layer_stride;
> +   unsigned src_offset = src_lev->offset +
> +                         blit_info->src.box.z * src_lev->layer_stride +
> +                         etna_compute_tileoffset(&blit_info->src.box,
> +                                                 blit_info->src.format,
> +                                                 src_lev->stride,
> +                                                 src->layout);

Maybe include the z-computation in etna_compute_tileoffset as
well - this would be future-compatible with formats have 3D tiles instead of 
a stack of 2D ones (thinking of ASTC).

> +   unsigned dst_offset = dst_lev->offset +
> +                         blit_info->dst.box.z * dst_lev->layer_stride +
> +                         etna_compute_tileoffset(&blit_info->dst.box,
> +                                                 blit_info->dst.format,
> +                                                 dst_lev->stride,
> +                                                 dst->layout);
>  
>     if (src_lev->padded_width <= ETNA_RS_WIDTH_MASK ||
>         dst_lev->padded_width <= ETNA_RS_WIDTH_MASK ||
> @@ -503,7 +561,8 @@ etna_try_rs_blit(struct pipe_context *pctx,
>  
>        memset(&reloc, 0, sizeof(struct etna_reloc));
>        reloc.bo = src->bo;
> -      reloc.offset = src_offset;
> +      reloc.offset = src_lev->offset +
> +                     blit_info->src.box.z * src_lev->layer_stride;
>        reloc.flags = ETNA_RELOC_READ;
>        etna_set_state_reloc(ctx->stream, VIVS_TS_COLOR_SURFACE_BASE, &reloc);
>  
> -- 
> 2.11.0


More information about the mesa-dev mailing list