From b6778995d7cffada31afe8c3783814125256981a Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 15 Feb 2023 11:48:44 -0800 Subject: [PATCH] freedreno/a6xx: Add a way to assert valid format Layout transitions caused by access as a various format must happen at state bind time, before batch_draw_tracking(). Add a helper to assert this fact. Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/a6xx/fd6_image.c | 3 +- src/gallium/drivers/freedreno/a6xx/fd6_resource.c | 46 +++++++++++------------ src/gallium/drivers/freedreno/a6xx/fd6_resource.h | 17 ++++++++- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_image.c b/src/gallium/drivers/freedreno/a6xx/fd6_image.c index e875570..562af55 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_image.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_image.c @@ -410,7 +410,8 @@ fd6_set_shader_images(struct pipe_context *pctx, enum pipe_shader_type shader, * due to the extra caching (CCU) involved: */ if (rsc->layout.ubwc) { - bool linear = fd6_valid_tiling(rsc, buf->format); + bool linear = + fd6_check_valid_format(rsc, buf->format) == DEMOTE_TO_LINEAR; perf_debug_ctx(ctx, "%" PRSC_FMT ": demoted to %suncompressed due to coherent/volatile use as %s", diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c index 24f87c2..ace89ee 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_resource.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_resource.c @@ -161,21 +161,28 @@ is_r8g8(enum pipe_format format) } /** - * Can a rsc be accessed tiled with the specified format, or does it need to - * be linearized? + * Can a rsc as it is currently laid out be accessed as the specified format. + * Returns whether the access is ok or whether the rsc needs to be demoted + * to uncompressed tiled or linear. */ -bool -fd6_valid_tiling(struct fd_resource *rsc, enum pipe_format format) +enum fd6_format_status +fd6_check_valid_format(struct fd_resource *rsc, enum pipe_format format) { enum pipe_format orig_format = rsc->b.b.format; if (orig_format == format) - return true; + return FORMAT_OK; if (rsc->layout.tile_mode && (is_r8g8(orig_format) != is_r8g8(format))) - return false; + return DEMOTE_TO_LINEAR; - return true; + if (!rsc->layout.ubwc) + return FORMAT_OK; + + if (ok_ubwc_format(rsc->b.b.screen, format) && valid_format_cast(rsc, format)) + return FORMAT_OK; + + return DEMOTE_TO_TILED; } /** @@ -187,33 +194,26 @@ void fd6_validate_format(struct fd_context *ctx, struct fd_resource *rsc, enum pipe_format format) { - enum pipe_format orig_format = rsc->b.b.format; - tc_assert_driver_thread(ctx->tc); - if (orig_format == format) + switch (fd6_check_valid_format(rsc, format)) { + case FORMAT_OK: return; - - if (!fd6_valid_tiling(rsc, format)) { + case DEMOTE_TO_LINEAR: perf_debug_ctx(ctx, "%" PRSC_FMT ": demoted to linear+uncompressed due to use as %s", PRSC_ARGS(&rsc->b.b), util_format_short_name(format)); fd_resource_uncompress(ctx, rsc, true); return; - } - - if (!rsc->layout.ubwc) - return; + case DEMOTE_TO_TILED: + perf_debug_ctx(ctx, + "%" PRSC_FMT ": demoted to uncompressed due to use as %s", + PRSC_ARGS(&rsc->b.b), util_format_short_name(format)); - if (ok_ubwc_format(rsc->b.b.screen, format) && valid_format_cast(rsc, format)) + fd_resource_uncompress(ctx, rsc, false); return; - - perf_debug_ctx(ctx, - "%" PRSC_FMT ": demoted to uncompressed due to use as %s", - PRSC_ARGS(&rsc->b.b), util_format_short_name(format)); - - fd_resource_uncompress(ctx, rsc, false); + } } static void diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_resource.h b/src/gallium/drivers/freedreno/a6xx/fd6_resource.h index 33d24eb..56a9bd9 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_resource.h +++ b/src/gallium/drivers/freedreno/a6xx/fd6_resource.h @@ -30,9 +30,24 @@ #include "freedreno_resource.h" -bool fd6_valid_tiling(struct fd_resource *rsc, enum pipe_format format); + +enum fd6_format_status { + FORMAT_OK, + DEMOTE_TO_LINEAR, + DEMOTE_TO_TILED, +}; + +enum fd6_format_status fd6_check_valid_format(struct fd_resource *rsc, + enum pipe_format format); void fd6_validate_format(struct fd_context *ctx, struct fd_resource *rsc, enum pipe_format format) assert_dt; + +static inline void +fd6_assert_valid_format(struct fd_resource *rsc, enum pipe_format format) +{ + assert(fd6_check_valid_format(rsc, format) == FORMAT_OK); +} + void fd6_emit_flag_reference(struct fd_ringbuffer *ring, struct fd_resource *rsc, int level, int layer); void fd6_resource_screen_init(struct pipe_screen *pscreen); -- 2.7.4