panfrost: Move sysval_to_id out of panfrost_sysvals
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 12 Feb 2021 16:49:23 +0000 (17:49 +0100)
committerMarge Bot <eric+marge@anholt.net>
Mon, 15 Feb 2021 11:23:46 +0000 (11:23 +0000)
So we can re-use the panfrost_sysvals definition outside of the
compiler without dragging the sysval_to_id hash table.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8963>

src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/compiler.h
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_compile.c
src/panfrost/util/pan_ir.h
src/panfrost/util/pan_sysval.c

index a1492a7..6340cb8 100644 (file)
@@ -295,7 +295,9 @@ static bi_instr *
 bi_load_sysval_to(bi_builder *b, bi_index dest, int sysval,
                 unsigned nr_components, unsigned offset)
 {
-        unsigned uniform = pan_lookup_sysval(&b->shader->sysvals, sysval);
+        unsigned uniform =
+                pan_lookup_sysval(b->shader->sysval_to_id, &b->shader->sysvals,
+                                  sysval);
         unsigned idx = (uniform * 16) + offset;
 
         return bi_load_to(b, nr_components * 32, dest,
@@ -2515,7 +2517,7 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir,
         bifrost_debug = debug_get_option_bifrost_debug();
 
         bi_context *ctx = rzalloc(NULL, bi_context);
-        panfrost_init_sysvals(&ctx->sysvals, ctx);
+        ctx->sysval_to_id = panfrost_init_sysvals(&ctx->sysvals, ctx);
 
         ctx->nir = nir;
         ctx->stage = nir->info.stage;
index 24536b8..35e260c 100644 (file)
@@ -498,6 +498,7 @@ typedef struct {
        gl_shader_stage stage;
        struct list_head blocks; /* list of bi_block */
        struct panfrost_sysvals sysvals;
+       struct hash_table_u64 *sysval_to_id;
        struct panfrost_ubo_push *push;
        uint32_t quirks;
        unsigned arch;
index bc2c687..a4e7991 100644 (file)
@@ -321,6 +321,7 @@ typedef struct compiler_context {
         midgard_instruction *writeout_branch[MIDGARD_NUM_RTS][MIDGARD_MAX_SAMPLE_ITER];
 
         struct panfrost_sysvals sysvals;
+        struct hash_table_u64 *sysval_to_id;
         struct panfrost_ubo_push *push;
 } compiler_context;
 
index d459af4..ab9cfd6 100644 (file)
@@ -1447,7 +1447,8 @@ emit_sysval_read(compiler_context *ctx, nir_instr *instr,
         /* Figure out which uniform this is */
         int sysval = panfrost_sysval_for_instr(instr, &nir_dest);
         unsigned dest = nir_dest_index(&nir_dest);
-        unsigned uniform = pan_lookup_sysval(&ctx->sysvals, sysval);
+        unsigned uniform =
+                pan_lookup_sysval(ctx->sysval_to_id, &ctx->sysvals, sysval);
 
         /* Emit the read itself -- this is never indirect */
         midgard_instruction *ins =
@@ -2986,7 +2987,7 @@ midgard_compile_shader_nir(void *mem_ctx, nir_shader *nir,
 
         /* TODO: Bound against what? */
         compiler_context *ctx = rzalloc(NULL, compiler_context);
-        panfrost_init_sysvals(&ctx->sysvals, ctx);
+        ctx->sysval_to_id = panfrost_init_sysvals(&ctx->sysvals, ctx);
 
         ctx->nir = nir;
         ctx->stage = nir->info.stage;
index 67e2ad1..a48b3e9 100644 (file)
@@ -77,7 +77,6 @@ struct panfrost_sysvals {
         /* The mapping of sysvals to uniforms, the count, and the off-by-one inverse */
         unsigned sysvals[MAX_SYSVAL_COUNT];
         unsigned sysval_count;
-        struct hash_table_u64 *sysval_to_id;
 };
 
 /* Technically Midgard could go up to 92 in a pathological case but we don't
@@ -105,11 +104,13 @@ struct panfrost_ubo_push {
 unsigned
 pan_lookup_pushed_ubo(struct panfrost_ubo_push *push, unsigned ubo, unsigned offs);
 
-void
-panfrost_init_sysvals(struct panfrost_sysvals *ctx, void *memctx);
+struct hash_table_u64 *
+panfrost_init_sysvals(struct panfrost_sysvals *sysvals, void *memctx);
 
 unsigned
-pan_lookup_sysval(struct panfrost_sysvals *ctx, int sysval);
+pan_lookup_sysval(struct hash_table_u64 *sysval_to_id,
+                  struct panfrost_sysvals *sysvals,
+                  int sysval);
 
 int
 panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest);
index 8171df1..f1e3daa 100644 (file)
@@ -127,28 +127,30 @@ panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest)
 }
 
 unsigned
-pan_lookup_sysval(struct panfrost_sysvals *ctx, int sysval)
+pan_lookup_sysval(struct hash_table_u64 *sysval_to_id,
+                  struct panfrost_sysvals *sysvals,
+                  int sysval)
 {
         /* Try to lookup */
 
-        void *cached = _mesa_hash_table_u64_search(ctx->sysval_to_id, sysval);
+        void *cached = _mesa_hash_table_u64_search(sysval_to_id, sysval);
 
         if (cached)
                 return ((uintptr_t) cached) - 1;
 
         /* Else assign */
 
-        unsigned id = ctx->sysval_count++;
+        unsigned id = sysvals->sysval_count++;
         assert(id < MAX_SYSVAL_COUNT);
-        _mesa_hash_table_u64_insert(ctx->sysval_to_id, sysval, (void *) ((uintptr_t) id + 1));
-        ctx->sysvals[id] = sysval;
+        _mesa_hash_table_u64_insert(sysval_to_id, sysval, (void *) ((uintptr_t) id + 1));
+        sysvals->sysvals[id] = sysval;
 
         return id;
 }
 
-void
-panfrost_init_sysvals(struct panfrost_sysvals *ctx, void *memctx)
+struct hash_table_u64 *
+panfrost_init_sysvals(struct panfrost_sysvals *sysvals, void *memctx)
 {
-        ctx->sysval_count = 0;
-        ctx->sysval_to_id = _mesa_hash_table_u64_create(memctx);
+        sysvals->sysval_count = 0;
+        return _mesa_hash_table_u64_create(memctx);
 }