nir/lower_clamp_color_outputs: fix use with lowered io

if io is lowered, variables cannot be used

cc: mesa-stable

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28463>
This commit is contained in:
Mike Blumenkrantz 2024-03-18 09:14:07 -04:00 committed by Marge Bot
parent 056fe1dc6a
commit 56d7dad19c

View file

@ -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;