mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 15:20:10 +01:00
zink: handle invalid gl_TexCoord reads
if a texcoord input is read in a fragment shader but not written in the previous stage, the texcoord variable must be preserved until nir_lower_texcoord_replace has (possibly) run, and only then can it be replaced with a 0000 read Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17775>
This commit is contained in:
parent
f60f246426
commit
2bbc2c49ec
1 changed files with 37 additions and 4 deletions
|
|
@ -1442,12 +1442,17 @@ assign_consumer_var_io(gl_shader_stage stage, nir_variable *var, unsigned *reser
|
|||
slot -= VARYING_SLOT_PATCH0;
|
||||
}
|
||||
if (slot_map[slot] == (unsigned char)-1) {
|
||||
if (stage != MESA_SHADER_TESS_CTRL && !is_texcoord(stage, var))
|
||||
/* texcoords can't be eliminated in fs due to GL_COORD_REPLACE,
|
||||
* so keep for now and eliminate later
|
||||
*/
|
||||
if (is_texcoord(stage, var)) {
|
||||
var->data.driver_location = -1;
|
||||
return true;
|
||||
}
|
||||
if (stage != MESA_SHADER_TESS_CTRL)
|
||||
/* dead io */
|
||||
return false;
|
||||
/* - texcoords can't be eliminated in fs due to GL_COORD_REPLACE
|
||||
* - patch variables may be read in the workgroup
|
||||
*/
|
||||
/* patch variables may be read in the workgroup */
|
||||
slot_map[slot] = (*reserved)++;
|
||||
}
|
||||
var->data.driver_location = slot_map[slot];
|
||||
|
|
@ -1456,6 +1461,25 @@ assign_consumer_var_io(gl_shader_stage stage, nir_variable *var, unsigned *reser
|
|||
}
|
||||
|
||||
|
||||
static bool
|
||||
rewrite_read_as_0(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
nir_variable *var = data;
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic != nir_intrinsic_load_deref)
|
||||
return false;
|
||||
nir_variable *deref_var = nir_intrinsic_get_var(intr, 0);
|
||||
if (deref_var != var)
|
||||
return false;
|
||||
b->cursor = nir_before_instr(instr);
|
||||
nir_ssa_def *zero = nir_imm_zero(b, nir_dest_num_components(intr->dest), nir_dest_bit_size(intr->dest));
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, zero);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
rewrite_and_discard_read(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
|
|
@ -2144,6 +2168,15 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shad
|
|||
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_temp, NULL);
|
||||
need_optimize = true;
|
||||
}
|
||||
nir_foreach_shader_in_variable_safe(var, nir) {
|
||||
if (!is_texcoord(MESA_SHADER_FRAGMENT, var) || var->data.driver_location != -1)
|
||||
continue;
|
||||
nir_shader_instructions_pass(nir, rewrite_read_as_0, nir_metadata_dominance, var);
|
||||
var->data.mode = nir_var_shader_temp;
|
||||
nir_fixup_deref_modes(nir);
|
||||
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_temp, NULL);
|
||||
need_optimize = true;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue