From 72d14f8b6f76b34b2d40d33d672337d1e5ab8f47 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 12 Feb 2021 17:49:23 +0100 Subject: [PATCH] panfrost: Move sysval_to_id out of panfrost_sysvals 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 Acked-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 6 ++++-- src/panfrost/bifrost/compiler.h | 1 + src/panfrost/midgard/compiler.h | 1 + src/panfrost/midgard/midgard_compile.c | 5 +++-- src/panfrost/util/pan_ir.h | 9 +++++---- src/panfrost/util/pan_sysval.c | 20 +++++++++++--------- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index a1492a7ec53..6340cb81e2a 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -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; diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 24536b8d2a8..35e260cddad 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -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; diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index bc2c687d58d..a4e7991af69 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -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; diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index d459af4b32b..ab9cfd68c25 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -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; diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h index 67e2ad1ce1f..a48b3e92c97 100644 --- a/src/panfrost/util/pan_ir.h +++ b/src/panfrost/util/pan_ir.h @@ -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); diff --git a/src/panfrost/util/pan_sysval.c b/src/panfrost/util/pan_sysval.c index 8171df10467..f1e3daaff72 100644 --- a/src/panfrost/util/pan_sysval.c +++ b/src/panfrost/util/pan_sysval.c @@ -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); }