From 55f4f6882fc815aac1cfe89946ada047e16794e5 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 22 Jan 2021 09:16:58 -0800 Subject: [PATCH] freedreno/a6xx: Add helper to check if UBWC is supported Signed-off-by: Rob Clark Part-of: --- .../drivers/freedreno/a6xx/fd6_resource.c | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c index d289d32bc85..751a0880bb4 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c @@ -37,7 +37,7 @@ * it can be tiled doesn't mean it can be compressed. */ static bool -ok_ubwc_format(struct fd_resource *rsc, enum pipe_format pfmt) +ok_ubwc_format(struct pipe_screen *pscreen, enum pipe_format pfmt) { switch (pfmt) { case PIPE_FORMAT_X24S8_UINT: @@ -47,7 +47,7 @@ ok_ubwc_format(struct fd_resource *rsc, enum pipe_format pfmt) * fd_resource_uncompress() at the point of stencil sampling because * that itself uses stencil sampling in the fd_blitter_blit path. */ - return fd_screen(rsc->base.screen)->info.a6xx.has_z24uint_s8uint; + return fd_screen(pscreen)->info.a6xx.has_z24uint_s8uint; case PIPE_FORMAT_R8_G8B8_420_UNORM: return true; @@ -90,6 +90,19 @@ ok_ubwc_format(struct fd_resource *rsc, enum pipe_format pfmt) } } +static bool +can_do_ubwc(struct pipe_resource *prsc) +{ + /* limit things to simple single level 2d for now: */ + if ((prsc->depth0 != 1) || (prsc->array_size != 1) || (prsc->last_level != 0)) + return false; + if (prsc->target != PIPE_TEXTURE_2D) + return false; + if (!ok_ubwc_format(prsc->screen, prsc->format)) + return false; + return true; +} + /** * Ensure the rsc is in an ok state to be used with the specified format. * This handles the case of UBWC buffers used with non-UBWC compatible @@ -102,7 +115,7 @@ fd6_validate_format(struct fd_context *ctx, struct fd_resource *rsc, if (!rsc->layout.ubwc) return; - if (ok_ubwc_format(rsc, format)) + if (ok_ubwc_format(rsc->base.screen, format)) return; fd_resource_uncompress(ctx, rsc); @@ -145,7 +158,7 @@ fd6_setup_slices(struct fd_resource *rsc) if (!(fd_mesa_debug & FD_DBG_NOLRZ) && has_depth(rsc->base.format)) setup_lrz(rsc); - if (rsc->layout.ubwc && !ok_ubwc_format(rsc, rsc->base.format)) + if (rsc->layout.ubwc && !ok_ubwc_format(rsc->base.screen, rsc->base.format)) rsc->layout.ubwc = false; fdl6_layout(&rsc->layout, prsc->format, fd_resource_nr_samples(prsc), @@ -166,12 +179,7 @@ fill_ubwc_buffer_sizes(struct fd_resource *rsc) .pitch = rsc->layout.pitch0, }; - /* limit things to simple single level 2d for now: */ - if ((prsc->depth0 != 1) || (prsc->array_size != 1) || (prsc->last_level != 0)) - return -1; - if (prsc->target != PIPE_TEXTURE_2D) - return -1; - if (!ok_ubwc_format(rsc, prsc->format)) + if (!can_do_ubwc(prsc)) return -1; rsc->layout.ubwc = true;