Mesa (main): panfrost: Call tgsi_to_nir earlier

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 2 14:14:35 UTC 2022


Module: Mesa
Branch: main
Commit: b834dea8896c2f55457c98a7cd2ef2459df891e1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b834dea8896c2f55457c98a7cd2ef2459df891e1

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Tue Apr 26 13:58:19 2022 -0400

panfrost: Call tgsi_to_nir earlier

This ensures we always have NIR available in the shader state. It also saves a
(trivial) amount of recomputation if multiple TGSI variants are needed.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16173>

---

 src/gallium/drivers/panfrost/pan_assemble.c | 15 ++-------------
 src/gallium/drivers/panfrost/pan_compute.c  |  5 +++--
 src/gallium/drivers/panfrost/pan_context.c  | 27 +++++++++++----------------
 src/gallium/drivers/panfrost/pan_context.h  |  7 ++++---
 4 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c
index ea9d7be0dab..82b8bb3ca00 100644
--- a/src/gallium/drivers/panfrost/pan_assemble.c
+++ b/src/gallium/drivers/panfrost/pan_assemble.c
@@ -32,32 +32,21 @@
 #include "pan_util.h"
 
 #include "compiler/nir/nir.h"
-#include "nir/tgsi_to_nir.h"
 #include "util/u_dynarray.h"
 #include "util/u_upload_mgr.h"
 
-#include "tgsi/tgsi_dump.h"
-
 void
 panfrost_shader_compile(struct pipe_screen *pscreen,
                         struct panfrost_pool *shader_pool,
                         struct panfrost_pool *desc_pool,
-                        enum pipe_shader_ir ir_type,
-                        const void *ir,
+                        const nir_shader *ir,
                         gl_shader_stage stage,
                         struct panfrost_shader_state *state)
 {
         struct panfrost_screen *screen = pan_screen(pscreen);
         struct panfrost_device *dev = pan_device(pscreen);
 
-        nir_shader *s;
-
-        if (ir_type == PIPE_SHADER_IR_NIR) {
-                s = nir_shader_clone(NULL, ir);
-        } else {
-                assert (ir_type == PIPE_SHADER_IR_TGSI);
-                s = tgsi_to_nir(ir, pscreen, false);
-        }
+        nir_shader *s = nir_shader_clone(NULL, ir);
 
         /* Lower this early so the backends don't have to worry about it */
         if (stage == MESA_SHADER_FRAGMENT)
diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c
index 844016ee948..1f473b52563 100644
--- a/src/gallium/drivers/panfrost/pan_compute.c
+++ b/src/gallium/drivers/panfrost/pan_compute.c
@@ -68,9 +68,10 @@ panfrost_create_compute_state(
                 so->cbase.ir_type = PIPE_SHADER_IR_NIR;
         }
 
+        assert(so->cbase.ir_type == PIPE_SHADER_IR_NIR && "TGSI kernels unsupported");
+
         panfrost_shader_compile(pctx->screen, &ctx->shaders, &ctx->descs,
-                        so->cbase.ir_type, so->cbase.prog, MESA_SHADER_COMPUTE,
-                        v);
+                        so->cbase.prog, MESA_SHADER_COMPUTE, v);
 
         /* There are no variants so we won't need the NIR again */
         ralloc_free((void *)so->cbase.prog);
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 9bdb220429a..f93656e43f6 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -45,6 +45,7 @@
 #include "util/u_prim_restart.h"
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_from_mesa.h"
+#include "nir/tgsi_to_nir.h"
 #include "util/u_math.h"
 
 #include "pan_screen.h"
@@ -297,25 +298,25 @@ panfrost_create_shader_state(
 {
         struct panfrost_shader_variants *so = CALLOC_STRUCT(panfrost_shader_variants);
         struct panfrost_device *dev = pan_device(pctx->screen);
-        so->base = *cso;
 
         simple_mtx_init(&so->lock, mtx_plain);
 
-        /* Token deep copy to prevent memory corruption */
+        so->stream_output = cso->stream_output;
 
         if (cso->type == PIPE_SHADER_IR_TGSI)
-                so->base.tokens = tgsi_dup_tokens(so->base.tokens);
+                so->nir = tgsi_to_nir(cso->tokens, pctx->screen, false);
+        else
+                so->nir = cso->ir.nir;
 
         /* Precompile for shader-db if we need to */
-        if (unlikely((dev->debug & PAN_DBG_PRECOMPILE) && cso->type == PIPE_SHADER_IR_NIR)) {
+        if (unlikely(dev->debug & PAN_DBG_PRECOMPILE)) {
                 struct panfrost_context *ctx = pan_context(pctx);
 
                 struct panfrost_shader_state state = { 0 };
 
                 panfrost_shader_compile(pctx->screen,
                                         &ctx->shaders, &ctx->descs,
-                                        PIPE_SHADER_IR_NIR,
-                                        so->base.ir.nir,
+                                        so->nir,
                                         tgsi_processor_to_shader_stage(stage),
                                         &state);
         }
@@ -330,11 +331,8 @@ panfrost_delete_shader_state(
 {
         struct panfrost_shader_variants *cso = (struct panfrost_shader_variants *) so;
 
-        if (!cso->is_compute && cso->base.type == PIPE_SHADER_IR_NIR)
-                ralloc_free(cso->base.ir.nir);
-
-        if (cso->base.type == PIPE_SHADER_IR_TGSI)
-                tgsi_free_tokens(cso->base.tokens);
+        if (!cso->is_compute)
+                ralloc_free(cso->nir);
 
         for (unsigned i = 0; i < cso->variant_count; ++i) {
                 struct panfrost_shader_state *shader_state = &cso->variants[i];
@@ -521,17 +519,14 @@ panfrost_bind_shader_state(
         if (!shader_state->compiled) {
                 panfrost_shader_compile(ctx->base.screen,
                                         &ctx->shaders, &ctx->descs,
-                                        variants->base.type,
-                                        variants->base.type == PIPE_SHADER_IR_NIR ?
-                                        variants->base.ir.nir :
-                                        variants->base.tokens,
+                                        variants->nir,
                                         tgsi_processor_to_shader_stage(type),
                                         shader_state);
 
                 shader_state->compiled = true;
 
                 /* Fixup the stream out information */
-                shader_state->stream_output = variants->base.stream_output;
+                shader_state->stream_output = variants->stream_output;
                 shader_state->so_mask =
                         update_so_info(&shader_state->stream_output,
                                        shader_state->info.outputs_written);
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index 9dfea147aa9..54db73ebfb6 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -289,10 +289,12 @@ struct panfrost_shader_variants {
         bool is_compute;
 
         union {
-                struct pipe_shader_state base;
                 struct pipe_compute_state cbase;
         };
 
+        nir_shader *nir;
+        struct pipe_stream_output_info stream_output;
+
         /** Lock for the variants array */
         simple_mtx_t lock;
 
@@ -370,8 +372,7 @@ void
 panfrost_shader_compile(struct pipe_screen *pscreen,
                         struct panfrost_pool *shader_pool,
                         struct panfrost_pool *desc_pool,
-                        enum pipe_shader_ir ir_type,
-                        const void *ir,
+                        const nir_shader *ir,
                         gl_shader_stage stage,
                         struct panfrost_shader_state *state);
 



More information about the mesa-commit mailing list