From bd49c8f0ebaed08b06feadcdb7dadf6b7b64f21f Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 14 Jun 2019 09:59:20 +0200 Subject: [PATCH] panfrost: Make the sysval logic more generic We are about to add support for nir_texop_txs which requires adding a sysval/uniform containing the texture size. Let's change the emit_sysval_read() prototype to take a nir_instr object instead of a nir_intrinsic_instr one so we can re-use this function when emitting a sysval for a txs instruction. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig --- .../panfrost/midgard/midgard_compile.c | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c index cd65da8b23e..0abecb90f3c 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c +++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c @@ -297,16 +297,46 @@ midgard_nir_sysval_for_intrinsic(nir_intrinsic_instr *instr) } } -static void -midgard_nir_assign_sysval_body(compiler_context *ctx, nir_instr *instr) +static unsigned +nir_dest_index(compiler_context *ctx, nir_dest *dst) { + if (dst->is_ssa) + return dst->ssa.index; + else { + assert(!dst->reg.indirect); + return ctx->func->impl->ssa_alloc + dst->reg.reg->index; + } +} + +static int sysval_for_instr(compiler_context *ctx, nir_instr *instr, + unsigned *dest) +{ + nir_intrinsic_instr *intr; + nir_dest *dst = NULL; int sysval = -1; - if (instr->type == nir_instr_type_intrinsic) { - nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr); + switch (instr->type) { + case nir_instr_type_intrinsic: + intr = nir_instr_as_intrinsic(instr); sysval = midgard_nir_sysval_for_intrinsic(intr); + dst = &intr->dest; + break; + default: + break; } + if (dest && dst) + *dest = nir_dest_index(ctx, dst); + + return sysval; +} + +static void +midgard_nir_assign_sysval_body(compiler_context *ctx, nir_instr *instr) +{ + int sysval; + + sysval = sysval_for_instr(ctx, instr, NULL); if (sysval < 0) return; @@ -514,17 +544,6 @@ nir_src_index(compiler_context *ctx, nir_src *src) } } -static unsigned -nir_dest_index(compiler_context *ctx, nir_dest *dst) -{ - if (dst->is_ssa) - return dst->ssa.index; - else { - assert(!dst->reg.indirect); - return ctx->func->impl->ssa_alloc + dst->reg.reg->index; - } -} - static unsigned nir_alu_src_index(compiler_context *ctx, nir_alu_src *src) { @@ -1079,13 +1098,11 @@ emit_varying_read( } static void -emit_sysval_read(compiler_context *ctx, nir_intrinsic_instr *instr) +emit_sysval_read(compiler_context *ctx, nir_instr *instr) { - /* First, pull out the destination */ - unsigned dest = nir_dest_index(ctx, &instr->dest); - - /* Now, figure out which uniform this is */ - int sysval = midgard_nir_sysval_for_intrinsic(instr); + unsigned dest; + /* Figure out which uniform this is */ + int sysval = sysval_for_instr(ctx, instr, &dest); void *val = _mesa_hash_table_u64_search(ctx->sysval_to_id, sysval); /* Sysvals are prefix uniforms */ @@ -1318,7 +1335,7 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr) case nir_intrinsic_load_viewport_scale: case nir_intrinsic_load_viewport_offset: - emit_sysval_read(ctx, instr); + emit_sysval_read(ctx, &instr->instr); break; default: -- 2.30.2