From c68cd39eb3797eb34a049950cb34acfd0719cde7 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 31 Jan 2020 09:22:50 +0100 Subject: [PATCH] pan/midgard: Make sure we pass the right RT id to emit_fragment_store() nir_intrinsic_base() is assigned nir_variable.data.driver_location, which is assigned a unique ID based on the variable position in the shader variable list. There's no guarantee that this position will match the RT id we want to pass to emit_fragment_store(). Add a search_var() helper to retrieve a nir_variable based on its driver location, so we can pass the right RT value to emit_fragment_store(). We also make sure the shader output is color, since emit_fragment_store() is not ready for depth/stencil stores yet. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig Part-of: --- src/panfrost/midgard/midgard_compile.c | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 604b7bf5f2a..76294c4c81a 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -1404,6 +1404,17 @@ emit_vertex_builtin(compiler_context *ctx, nir_intrinsic_instr *instr) emit_attr_read(ctx, reg, vertex_builtin_arg(instr->intrinsic), 1, nir_type_int); } +static const nir_variable * +search_var(struct exec_list *vars, unsigned driver_loc) +{ + nir_foreach_variable(var, vars) { + if (var->data.driver_location == driver_loc) + return var; + } + + return NULL; +} + static void emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr) { @@ -1556,7 +1567,21 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr) reg = nir_src_index(ctx, &instr->src[0]); if (ctx->stage == MESA_SHADER_FRAGMENT) { - emit_fragment_store(ctx, reg, offset); + const nir_variable *var; + enum midgard_rt_id rt; + + var = search_var(&ctx->nir->outputs, + nir_intrinsic_base(instr)); + assert(var); + if (var->data.location == FRAG_RESULT_COLOR) + rt = MIDGARD_COLOR_RT0; + else if (var->data.location >= FRAG_RESULT_DATA0) + rt = MIDGARD_COLOR_RT0 + var->data.location - + FRAG_RESULT_DATA0; + else + assert(0); + + emit_fragment_store(ctx, reg, rt); } else if (ctx->stage == MESA_SHADER_VERTEX) { /* We should have been vectorized, though we don't * currently check that st_vary is emitted only once -- 2.30.2