asahi: Add perf debug for generate_mipmap
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 11 Mar 2023 21:46:45 +0000 (16:46 -0500)
committerMarge Bot <emma+marge@anholt.net>
Fri, 7 Apr 2023 03:23:03 +0000 (03:23 +0000)
The current implementation leaves a lot of perf on the table, so call it out on
ASAHI_MESA_DEBUG=perf to help debugging perf problems, especially if this
ever happens in a real application (i.e. not a benchmark).

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22353>

src/gallium/drivers/asahi/agx_pipe.c

index d503625..1f06edd 100644 (file)
@@ -28,6 +28,7 @@
 #include "util/format/u_format.h"
 #include "util/half_float.h"
 #include "util/u_drm.h"
+#include "util/u_gen_mipmap.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_screen.h"
@@ -872,6 +873,27 @@ agx_transfer_unmap(struct pipe_context *pctx, struct pipe_transfer *transfer)
    FREE(transfer);
 }
 
+static bool
+agx_generate_mipmap(struct pipe_context *pctx, struct pipe_resource *prsrc,
+                    enum pipe_format format, unsigned base_level,
+                    unsigned last_level, unsigned first_layer,
+                    unsigned last_layer)
+{
+   struct agx_resource *rsrc = agx_resource(prsrc);
+
+   /* Generating a mipmap invalidates the written levels. Make that
+    * explicit so we don't reload the previous contents.
+    */
+   for (unsigned l = base_level + 1; l <= last_level; ++l)
+      BITSET_CLEAR(rsrc->data_valid, l);
+
+   /* For now we use util_gen_mipmap, but this has way too much overhead */
+   perf_debug_ctx(agx_context(pctx), "Unoptimized mipmap generation");
+
+   return util_gen_mipmap(pctx, prsrc, format, base_level, last_level,
+                          first_layer, last_layer, PIPE_TEX_FILTER_LINEAR);
+}
+
 /*
  * clear/copy
  */
@@ -1206,6 +1228,7 @@ agx_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
    pctx->clear = agx_clear;
    pctx->resource_copy_region = util_resource_copy_region;
    pctx->blit = agx_blit;
+   pctx->generate_mipmap = agx_generate_mipmap;
    pctx->flush_resource = agx_flush_resource;
 
    pctx->buffer_map = u_transfer_helper_transfer_map;
@@ -1335,6 +1358,7 @@ agx_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
       return 1;
 
    case PIPE_CAP_OCCLUSION_QUERY:
+   case PIPE_CAP_GENERATE_MIPMAP:
    case PIPE_CAP_PRIMITIVE_RESTART:
    case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
    case PIPE_CAP_ANISOTROPIC_FILTER: