Module: Mesa
Branch: master
Commit: 6941cd5c9860dc2eb67023e9307abe4ecd80b990
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6941cd5c9860dc2eb67023e9307abe4ecd80b990

Author: Eric Anholt <[email protected]>
Date:   Thu Mar 18 12:01:05 2021 -0700

freedreno: Move the ir3 linked shader cache to the context.

The other ir3 backends would love to have it to reduce lookups and to be
able to cache linked-program state.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9698>

---

 src/gallium/drivers/freedreno/a6xx/fd6_context.c  |  2 --
 src/gallium/drivers/freedreno/a6xx/fd6_context.h  |  5 ----
 src/gallium/drivers/freedreno/a6xx/fd6_emit.h     |  3 +-
 src/gallium/drivers/freedreno/a6xx/fd6_program.c  | 34 ++---------------------
 src/gallium/drivers/freedreno/freedreno_context.c |  3 ++
 src/gallium/drivers/freedreno/freedreno_context.h |  5 ++++
 src/gallium/drivers/freedreno/ir3/ir3_cache.c     |  6 ++++
 src/gallium/drivers/freedreno/ir3/ir3_gallium.c   |  6 +++-
 8 files changed, 22 insertions(+), 42 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_context.c 
b/src/gallium/drivers/freedreno/a6xx/fd6_context.c
index 27982549195..7b088ff6acb 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_context.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_context.c
@@ -60,8 +60,6 @@ fd6_context_destroy(struct pipe_context *pctx)
 
        fd_context_cleanup_common_vbos(&fd6_ctx->base);
 
-       ir3_cache_destroy(fd6_ctx->shader_cache);
-
        fd6_texture_fini(pctx);
 
        free(fd6_ctx);
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_context.h 
b/src/gallium/drivers/freedreno/a6xx/fd6_context.h
index 1a1102f95a8..8fbc2da6b07 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_context.h
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_context.h
@@ -79,11 +79,6 @@ struct fd6_context {
        /* number of active samples-passed queries: */
        int samples_passed_queries;
 
-       /* maps per-shader-stage state plus variant key to hw
-        * program stateobj:
-        */
-       struct ir3_cache *shader_cache;
-
        /* cached stateobjs to avoid hashtable lookup when not dirty: */
        const struct fd6_program_state *prog;
 
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.h 
b/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
index c3f14fc4532..21d9d8997ce 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.h
@@ -118,9 +118,8 @@ static inline const struct fd6_program_state *
 fd6_emit_get_prog(struct fd6_emit *emit)
 {
        if (!emit->prog) {
-               struct fd6_context *fd6_ctx = fd6_context(emit->ctx);
                struct ir3_program_state *s =
-                               ir3_cache_lookup(fd6_ctx->shader_cache, 
&emit->key, &emit->ctx->debug);
+                               ir3_cache_lookup(emit->ctx->shader_cache, 
&emit->key, &emit->ctx->debug);
                emit->prog = fd6_program_state(s);
        }
        return emit->prog;
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_program.c 
b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
index 00b4f66acda..f581e2f0852 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_program.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_program.c
@@ -1119,44 +1119,14 @@ static const struct ir3_cache_funcs cache_funcs = {
        .destroy_state = fd6_program_destroy,
 };
 
-static void *
-fd6_shader_state_create(struct pipe_context *pctx, const struct 
pipe_shader_state *cso)
-{
-       return ir3_shader_state_create(pctx, cso);
-}
-
-static void
-fd6_shader_state_delete(struct pipe_context *pctx, void *hwcso)
-{
-       struct fd_context *ctx = fd_context(pctx);
-       ir3_cache_invalidate(fd6_context(ctx)->shader_cache, hwcso);
-       ir3_shader_state_delete(pctx, hwcso);
-}
-
 void
 fd6_prog_init(struct pipe_context *pctx)
 {
        struct fd_context *ctx = fd_context(pctx);
 
-       fd6_context(ctx)->shader_cache = ir3_cache_create(&cache_funcs, ctx);
-
-       pctx->create_vs_state = fd6_shader_state_create;
-       pctx->delete_vs_state = fd6_shader_state_delete;
-
-       pctx->create_tcs_state = fd6_shader_state_create;
-       pctx->delete_tcs_state = fd6_shader_state_delete;
-
-       pctx->create_tes_state = fd6_shader_state_create;
-       pctx->delete_tes_state = fd6_shader_state_delete;
-
-       pctx->create_gs_state = fd6_shader_state_create;
-       pctx->delete_gs_state = fd6_shader_state_delete;
-
-       pctx->create_gs_state = fd6_shader_state_create;
-       pctx->delete_gs_state = fd6_shader_state_delete;
+       ctx->shader_cache = ir3_cache_create(&cache_funcs, ctx);
 
-       pctx->create_fs_state = fd6_shader_state_create;
-       pctx->delete_fs_state = fd6_shader_state_delete;
+       ir3_prog_init(pctx);
 
        fd_prog_init(pctx);
 }
diff --git a/src/gallium/drivers/freedreno/freedreno_context.c 
b/src/gallium/drivers/freedreno/freedreno_context.c
index f7de932cc33..73f1f7f1f1d 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.c
+++ b/src/gallium/drivers/freedreno/freedreno_context.c
@@ -36,6 +36,7 @@
 #include "freedreno_query.h"
 #include "freedreno_query_hw.h"
 #include "freedreno_util.h"
+#include "ir3/ir3_cache.h"
 #include "util/u_upload_mgr.h"
 
 static void
@@ -373,6 +374,8 @@ fd_context_destroy(struct pipe_context *pctx)
 
        fd_autotune_fini(&ctx->autotune);
 
+       ir3_cache_destroy(ctx->shader_cache);
+
        if (FD_DBG(BSTAT) || FD_DBG(MSGS)) {
                mesa_logi("batch_total=%u, batch_sysmem=%u, batch_gmem=%u, 
batch_nondraw=%u, batch_restore=%u\n",
                        (uint32_t)ctx->stats.batch_total, 
(uint32_t)ctx->stats.batch_sysmem,
diff --git a/src/gallium/drivers/freedreno/freedreno_context.h 
b/src/gallium/drivers/freedreno/freedreno_context.h
index 36ac6246569..0f5948f6050 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.h
+++ b/src/gallium/drivers/freedreno/freedreno_context.h
@@ -416,6 +416,11 @@ struct fd_context {
                uint32_t per_fiber_size;
        } pvtmem[2] dt;
 
+       /* maps per-shader-stage state plus variant key to hw
+        * program stateobj:
+        */
+       struct ir3_cache *shader_cache;
+
        struct pipe_debug_callback debug;
 
        struct u_trace_context trace_context dt;
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cache.c 
b/src/gallium/drivers/freedreno/ir3/ir3_cache.c
index 3d9ebf7a793..dddcbb97540 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_cache.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_cache.c
@@ -73,6 +73,9 @@ struct ir3_cache * ir3_cache_create(const struct 
ir3_cache_funcs *funcs, void *d
 
 void ir3_cache_destroy(struct ir3_cache *cache)
 {
+       if (!cache)
+               return;
+
        /* _mesa_hash_table_destroy is so *almost* useful.. */
        hash_table_foreach(cache->ht, entry) {
                cache->funcs->destroy_state(cache->data, entry->data);
@@ -167,6 +170,9 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct 
ir3_cache_key *key,
  */
 void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj)
 {
+       if (!cache)
+               return;
+
        hash_table_foreach(cache->ht, entry) {
                const struct ir3_cache_key *key = entry->key;
                if ((key->fs == stobj) || (key->vs == stobj) ||
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c 
b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
index 971dd079c35..1dee9edcdcd 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_gallium.c
@@ -38,6 +38,7 @@
 #include "freedreno_context.h"
 #include "freedreno_util.h"
 
+#include "ir3/ir3_cache.h"
 #include "ir3/ir3_shader.h"
 #include "ir3/ir3_gallium.h"
 #include "ir3/ir3_compiler.h"
@@ -389,10 +390,13 @@ ir3_shader_state_create(struct pipe_context *pctx, const 
struct pipe_shader_stat
 void
 ir3_shader_state_delete(struct pipe_context *pctx, void *_hwcso)
 {
-       struct fd_screen *screen = fd_context(pctx)->screen;
+       struct fd_context *ctx = fd_context(pctx);
+       struct fd_screen *screen = ctx->screen;
        struct ir3_shader_state *hwcso = _hwcso;
        struct ir3_shader *so = hwcso->shader;
 
+       ir3_cache_invalidate(ctx->shader_cache, hwcso);
+
        /* util_queue_drop_job() guarantees that either:
         *  1) job did not execute
         *  2) job completed

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to