etnaviv: nir: Move pre-halti5 tex lowering

Let's have all the texture lowerings in one place.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35696>
This commit is contained in:
Christian Gmeiner 2025-06-18 12:00:42 +02:00 committed by Marge Bot
parent 84cb568150
commit e64390a056
4 changed files with 44 additions and 59 deletions

View file

@ -1247,7 +1247,7 @@ etna_compile_shader(struct etna_shader_variant *v)
NIR_PASS(_, s, nir_lower_vars_to_ssa);
NIR_PASS(_, s, nir_lower_indirect_derefs, nir_var_all, UINT32_MAX);
NIR_PASS(_, s, etna_nir_lower_texture, &v->key);
NIR_PASS(_, s, etna_nir_lower_texture, &v->key, v->shader->info);
NIR_PASS(_, s, nir_lower_alu_width, NULL, NULL);
NIR_PASS(_, s, nir_lower_alu_to_scalar, etna_alu_to_scalar_filter_cb, c->info);

View file

@ -107,62 +107,6 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v)
break;
}
}
if (instr->type != nir_instr_type_tex)
continue;
nir_tex_instr *tex = nir_instr_as_tex(instr);
nir_src *coord = NULL;
nir_src *src1 = NULL;
unsigned src1_idx;
assert(tex->sampler_index == tex->texture_index);
for (unsigned i = 0; i < tex->num_srcs; i++) {
switch (tex->src[i].src_type) {
case nir_tex_src_coord:
coord = &tex->src[i].src;
break;
case nir_tex_src_bias:
case nir_tex_src_lod:
assert(!src1);
src1 = &tex->src[i].src;
src1_idx = i;
break;
case nir_tex_src_ddx:
case nir_tex_src_ddy:
case nir_tex_src_comparator:
break;
default:
assert(0);
break;
}
}
/* pre HALTI5 needs texture sources in a single source */
if (!src1 || v->shader->info->halti >= 5)
continue;
assert(coord && src1 && tex->coord_components < 4);
nir_alu_instr *vec = nir_alu_instr_create(shader, nir_op_vec4);
for (unsigned i = 0; i < tex->coord_components; i++) {
vec->src[i].src = nir_src_for_ssa(coord->ssa);
vec->src[i].swizzle[0] = i;
}
for (unsigned i = tex->coord_components; i < 4; i++)
vec->src[i].src = nir_src_for_ssa(src1->ssa);
nir_def_init(&vec->instr, &vec->def, 4, 32);
nir_tex_instr_remove_src(tex, src1_idx);
nir_src_rewrite(coord, &vec->def);
tex->coord_components = 4;
nir_instr_insert_before(&tex->instr, &vec->instr);
func_progress = true;
}
}

View file

@ -35,7 +35,7 @@ bool
etna_lower_alu(nir_shader *shader, bool has_new_transcendentals);
bool
etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key);
etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key, const struct etna_core_info *info);
bool
etna_nir_lower_to_source_mods(nir_shader *shader);

View file

@ -108,6 +108,42 @@ legalize_txd_comparator(nir_builder *b, nir_tex_instr *tex, UNUSED void *data)
return true;
}
static bool
legalize_src(nir_builder *b, nir_tex_instr *tex, UNUSED void *data)
{
int bias_index = nir_tex_instr_src_index(tex, nir_tex_src_bias);
int lod_index = nir_tex_instr_src_index(tex, nir_tex_src_lod);
if (bias_index < 0 && lod_index < 0)
return false;
b->cursor = nir_before_instr(&tex->instr);
nir_def *src1 = NULL;
if (bias_index >= 0)
src1 = nir_steal_tex_src(tex, nir_tex_src_bias);
if (lod_index >= 0) {
assert(!src1);
src1 = nir_steal_tex_src(tex, nir_tex_src_lod);
}
int coord_index = nir_tex_instr_src_index(tex, nir_tex_src_coord);
assert(coord_index >= 0);
nir_def *coord = tex->src[coord_index].src.ssa;
assert(src1->num_components == 1);
assert(tex->coord_components < 4);
coord = nir_pad_vec4(b, coord);
coord = nir_vector_insert_imm(b, coord, src1, 3);
tex->coord_components = 4;
nir_src_rewrite(&tex->src[coord_index].src, coord);
return true;
}
static bool
lower_offset_filter(const nir_instr *instr, const void *data)
{
@ -126,7 +162,7 @@ lower_offset_filter(const nir_instr *instr, const void *data)
}
bool
etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key, const struct etna_core_info *info)
{
bool progress = false;
@ -158,5 +194,10 @@ etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
NIR_PASS(progress, s, nir_shader_tex_pass, legalize_txd_comparator,
nir_metadata_control_flow, NULL);
if (info->halti < 5) {
NIR_PASS(progress, s, nir_shader_tex_pass, legalize_src,
nir_metadata_control_flow, NULL);
}
return progress;
}