From 9f55657366da24626449606a5fcf3f9c38db2f74 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 29 Jan 2021 17:16:07 -0500 Subject: [PATCH] panfrost: Overhaul sysval handling Don't preassign. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 7 +++--- src/panfrost/midgard/midgard_compile.c | 16 +++++-------- src/panfrost/util/pan_ir.h | 5 ++++- src/panfrost/util/pan_sysval.c | 31 +++++++++----------------- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 949aa51b5db..4a5382c4363 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2460,6 +2460,8 @@ 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->nir = nir; ctx->stage = nir->info.stage; ctx->quirks = bifrost_get_quirks(inputs->gpu_id); @@ -2505,9 +2507,6 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir, nir_print_shader(nir, stdout); } - panfrost_nir_assign_sysvals(&ctx->sysvals, ctx, nir); - program->sysval_count = ctx->sysvals.sysval_count; - memcpy(program->sysvals, ctx->sysvals.sysvals, sizeof(ctx->sysvals.sysvals[0]) * ctx->sysvals.sysval_count); ctx->blend_types = program->blend_types; ctx->tls_size = nir->scratch_size; @@ -2570,6 +2569,8 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir, program->wait_7 = (first_deps & (1 << 7)); memcpy(program->blend_ret_offsets, ctx->blend_ret_offsets, sizeof(program->blend_ret_offsets)); + program->sysval_count = ctx->sysvals.sysval_count; + memcpy(program->sysvals, ctx->sysvals.sysvals, sizeof(ctx->sysvals.sysvals[0]) * ctx->sysvals.sysval_count); if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) { disassemble_bifrost(stdout, program->compiled.data, diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index aa42e4ca161..f543e44b0c5 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -1442,12 +1442,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); - void *val = _mesa_hash_table_u64_search(ctx->sysvals.sysval_to_id, sysval); - unsigned dest = nir_dest_index(&nir_dest); - - /* Sysvals are prefix uniforms */ - unsigned uniform = ((uintptr_t) val) - 1; + unsigned uniform = pan_lookup_sysval(&ctx->sysvals, sysval); /* Emit the read itself -- this is never indirect */ midgard_instruction *ins = @@ -2981,6 +2977,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->nir = nir; ctx->stage = nir->info.stage; @@ -3051,12 +3048,6 @@ midgard_compile_shader_nir(void *mem_ctx, nir_shader *nir, nir_print_shader(nir, stdout); } - /* Assign sysvals and counts, now that we're sure - * (post-optimisation) */ - - panfrost_nir_assign_sysvals(&ctx->sysvals, ctx, nir); - program->sysval_count = ctx->sysvals.sysval_count; - memcpy(program->sysvals, ctx->sysvals.sysvals, sizeof(ctx->sysvals.sysvals[0]) * ctx->sysvals.sysval_count); ctx->tls_size = nir->scratch_size; nir_foreach_function(func, nir) { @@ -3181,6 +3172,9 @@ midgard_compile_shader_nir(void *mem_ctx, nir_shader *nir, program->tls_size = ctx->tls_size; + program->sysval_count = ctx->sysvals.sysval_count; + memcpy(program->sysvals, ctx->sysvals.sysvals, sizeof(ctx->sysvals.sysvals[0]) * ctx->sysvals.sysval_count); + if ((midgard_debug & MIDGARD_DBG_SHADERS) && !nir->info.internal) { disassemble_midgard(stdout, program->compiled.data, program->compiled.size, inputs->gpu_id); diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h index afcb2ed6bf8..c6e1bcf7d12 100644 --- a/src/panfrost/util/pan_ir.h +++ b/src/panfrost/util/pan_ir.h @@ -105,7 +105,10 @@ unsigned pan_lookup_pushed_ubo(struct panfrost_ubo_push *push, unsigned ubo, unsigned offs); void -panfrost_nir_assign_sysvals(struct panfrost_sysvals *ctx, void *memctx, nir_shader *shader); +panfrost_init_sysvals(struct panfrost_sysvals *ctx, void *memctx); + +unsigned +pan_lookup_sysval(struct panfrost_sysvals *ctx, 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 996041dc2ad..8171df10467 100644 --- a/src/panfrost/util/pan_sysval.c +++ b/src/panfrost/util/pan_sysval.c @@ -25,6 +25,7 @@ */ #include "pan_ir.h" +#include "compiler/nir/nir_builder.h" /* TODO: ssbo_size */ static int @@ -125,39 +126,29 @@ panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest) return sysval; } -static void -panfrost_nir_assign_sysval_body(struct panfrost_sysvals *ctx, nir_instr *instr) +unsigned +pan_lookup_sysval(struct panfrost_sysvals *ctx, int sysval) { - int sysval = panfrost_sysval_for_instr(instr, NULL); - if (sysval < 0) - return; + /* Try to lookup */ - /* We have a sysval load; check if it's already been assigned */ + void *cached = _mesa_hash_table_u64_search(ctx->sysval_to_id, sysval); - if (_mesa_hash_table_u64_search(ctx->sysval_to_id, sysval)) - return; + if (cached) + return ((uintptr_t) cached) - 1; - /* It hasn't -- so assign it now! */ + /* Else assign */ unsigned id = ctx->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; + + return id; } void -panfrost_nir_assign_sysvals(struct panfrost_sysvals *ctx, void *memctx, nir_shader *shader) +panfrost_init_sysvals(struct panfrost_sysvals *ctx, void *memctx) { ctx->sysval_count = 0; ctx->sysval_to_id = _mesa_hash_table_u64_create(memctx); - - nir_foreach_function(function, shader) { - if (!function->impl) continue; - - nir_foreach_block(block, function->impl) { - nir_foreach_instr_safe(instr, block) { - panfrost_nir_assign_sysval_body(ctx, instr); - } - } - } }