panfrost: Overhaul sysval handling
Don't preassign. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8774>
This commit is contained in:
parent
4086b8980d
commit
9f55657366
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue