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 <boris.brezillon@collabora.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8963>
This commit is contained in:
Boris Brezillon 2021-02-12 17:49:23 +01:00 committed by Marge Bot
parent 8d7eda9c95
commit 72d14f8b6f
6 changed files with 25 additions and 17 deletions

View 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;

View 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;

View 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;

View 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;

View 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);

View 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);
}