freedreno/a6xx: Add a way to assert valid format
authorRob Clark <robdclark@chromium.org>
Wed, 15 Feb 2023 19:48:44 +0000 (11:48 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 22 Feb 2023 21:26:27 +0000 (21:26 +0000)
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 <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21408>

src/gallium/drivers/freedreno/a6xx/fd6_image.c
src/gallium/drivers/freedreno/a6xx/fd6_resource.c
src/gallium/drivers/freedreno/a6xx/fd6_resource.h

index e875570..562af55 100644 (file)
@@ -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",
index 24f87c2..ace89ee 100644 (file)
@@ -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
index 33d24eb..56a9bd9 100644 (file)
 
 #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);