From 56d7dad19cf286ef43aa066e31a71e91954481dc Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 18 Mar 2024 09:14:07 -0400 Subject: [PATCH] nir/lower_clamp_color_outputs: fix use with lowered io MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if io is lowered, variables cannot be used cc: mesa-stable Acked-by: Marek Olšák Part-of: --- .../nir/nir_lower_clamp_color_outputs.c | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/compiler/nir/nir_lower_clamp_color_outputs.c b/src/compiler/nir/nir_lower_clamp_color_outputs.c index c13e90705d7..37e40f89a28 100644 --- a/src/compiler/nir/nir_lower_clamp_color_outputs.c +++ b/src/compiler/nir/nir_lower_clamp_color_outputs.c @@ -25,13 +25,13 @@ #include "nir_builder.h" static bool -is_color_output(nir_shader *shader, nir_variable *out) +is_color_output(nir_shader *shader, int location) { switch (shader->info.stage) { case MESA_SHADER_VERTEX: case MESA_SHADER_GEOMETRY: case MESA_SHADER_TESS_EVAL: - switch (out->data.location) { + switch (location) { case VARYING_SLOT_COL0: case VARYING_SLOT_COL1: case VARYING_SLOT_BFC0: @@ -42,8 +42,8 @@ is_color_output(nir_shader *shader, nir_variable *out) } break; case MESA_SHADER_FRAGMENT: - return (out->data.location == FRAG_RESULT_COLOR || - out->data.location >= FRAG_RESULT_DATA0); + return (location == FRAG_RESULT_COLOR || + location >= FRAG_RESULT_DATA0); default: return false; } @@ -54,30 +54,23 @@ lower_intrinsic(nir_builder *b, nir_intrinsic_instr *intr, nir_shader *shader) { nir_variable *out = NULL; nir_def *s; + int loc = -1; switch (intr->intrinsic) { case nir_intrinsic_store_deref: out = nir_intrinsic_get_var(intr, 0); + if (out->data.mode != nir_var_shader_out) + return false; + loc = out->data.location; break; case nir_intrinsic_store_output: - /* already had i/o lowered.. lookup the matching output var: */ - nir_foreach_shader_out_variable(var, shader) { - int drvloc = var->data.driver_location; - if (nir_intrinsic_base(intr) == drvloc) { - out = var; - break; - } - } - assume(out); + loc = nir_intrinsic_io_semantics(intr).location; break; default: return false; } - if (out->data.mode != nir_var_shader_out) - return false; - - if (is_color_output(shader, out)) { + if (is_color_output(shader, loc)) { b->cursor = nir_before_instr(&intr->instr); int src = intr->intrinsic == nir_intrinsic_store_deref ? 1 : 0; s = intr->src[src].ssa;