panfrost: Add PAN_MESA_DEBUG=precompile for shader-db
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 13 Dec 2019 20:13:02 +0000 (15:13 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 17 Dec 2019 17:42:57 +0000 (17:42 +0000)
We would like to use run.c for shader-db runs (rather than capturing in
real-time, which is limiting).

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3125>

src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_screen.c
src/gallium/drivers/panfrost/pan_util.h

index b446a4afb011b674812322d4916b061e5c76a843..ea87bbbdbd53a9561512b6d3d92d61a329ed1cdc 100644 (file)
@@ -1700,7 +1700,8 @@ panfrost_bind_vertex_elements_state(
 static void *
 panfrost_create_shader_state(
         struct pipe_context *pctx,
-        const struct pipe_shader_state *cso)
+        const struct pipe_shader_state *cso,
+        enum pipe_shader_type stage)
 {
         struct panfrost_shader_variants *so = CALLOC_STRUCT(panfrost_shader_variants);
         so->base = *cso;
@@ -1710,6 +1711,21 @@ panfrost_create_shader_state(
         if (cso->type == PIPE_SHADER_IR_TGSI)
                 so->base.tokens = tgsi_dup_tokens(so->base.tokens);
 
+        /* Precompile for shader-db if we need to */
+        if (unlikely((pan_debug & PAN_DBG_PRECOMPILE) && cso->type == PIPE_SHADER_IR_NIR)) {
+                struct panfrost_context *ctx = pan_context(pctx);
+
+                struct mali_shader_meta meta;
+                struct panfrost_shader_state state;
+                uint64_t outputs_written;
+
+                panfrost_shader_compile(ctx, &meta,
+                              PIPE_SHADER_IR_NIR,
+                                      so->base.ir.nir,
+                                        tgsi_processor_to_shader_stage(stage), &state,
+                                        &outputs_written);
+        }
+
         return so;
 }
 
@@ -1976,6 +1992,18 @@ panfrost_bind_shader_state(
         }
 }
 
+static void *
+panfrost_create_vs_state(struct pipe_context *pctx, const struct pipe_shader_state *hwcso)
+{
+        return panfrost_create_shader_state(pctx, hwcso, PIPE_SHADER_VERTEX);
+}
+
+static void *
+panfrost_create_fs_state(struct pipe_context *pctx, const struct pipe_shader_state *hwcso)
+{
+        return panfrost_create_shader_state(pctx, hwcso, PIPE_SHADER_FRAGMENT);
+}
+
 static void
 panfrost_bind_vs_state(struct pipe_context *pctx, void *hwcso)
 {
@@ -2595,11 +2623,11 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
         gallium->bind_vertex_elements_state = panfrost_bind_vertex_elements_state;
         gallium->delete_vertex_elements_state = panfrost_generic_cso_delete;
 
-        gallium->create_fs_state = panfrost_create_shader_state;
+        gallium->create_fs_state = panfrost_create_fs_state;
         gallium->delete_fs_state = panfrost_delete_shader_state;
         gallium->bind_fs_state = panfrost_bind_fs_state;
 
-        gallium->create_vs_state = panfrost_create_shader_state;
+        gallium->create_vs_state = panfrost_create_vs_state;
         gallium->delete_vs_state = panfrost_delete_shader_state;
         gallium->bind_vs_state = panfrost_bind_vs_state;
 
index e237f36e491d2a4ff3b9168d4a3df23a3fc2c6d8..ff71170524b7fd909ef13c9c27c24517700fad20 100644 (file)
@@ -60,6 +60,7 @@ static const struct debug_named_value debug_options[] = {
         {"deqp",      PAN_DBG_DEQP,     "Hacks for dEQP"},
         {"afbc",      PAN_DBG_AFBC,     "Enable non-conformant AFBC impl"},
         {"sync",      PAN_DBG_SYNC,     "Wait for each job's completion and check for any GPU fault"},
+        {"precompile", PAN_DBG_PRECOMPILE, "Precompile shaders for shader-db"},
         DEBUG_NAMED_VALUE_END
 };
 
index b51b88d2e1a2b3bf8702b7152a1abb607905d893..c74e0fb7fd37a718ad061cd15c75c1529061e1ad 100644 (file)
@@ -33,6 +33,7 @@
 #define PAN_DBG_DEQP            0x0004
 #define PAN_DBG_AFBC            0x0008
 #define PAN_DBG_SYNC            0x0010
+#define PAN_DBG_PRECOMPILE      0x0020
 
 extern int pan_debug;