From e64390a0561e8707277f45795ced5d783d00bba7 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Wed, 18 Jun 2025 12:00:42 +0200 Subject: [PATCH] etnaviv: nir: Move pre-halti5 tex lowering Let's have all the texture lowerings in one place. Signed-off-by: Christian Gmeiner Reviewed-by: Lucas Stach Part-of: --- .../drivers/etnaviv/etnaviv_compiler_nir.c | 2 +- src/gallium/drivers/etnaviv/etnaviv_nir.c | 56 ------------------- src/gallium/drivers/etnaviv/etnaviv_nir.h | 2 +- .../etnaviv/etnaviv_nir_lower_texture.c | 43 +++++++++++++- 4 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c index 3286533cf8e..338eab07224 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c @@ -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); diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.c b/src/gallium/drivers/etnaviv/etnaviv_nir.c index a1d06816275..753ea69a096 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir.c @@ -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; } } diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.h b/src/gallium/drivers/etnaviv/etnaviv_nir.h index 9b5c4ca1013..496f0600a2f 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir.h +++ b/src/gallium/drivers/etnaviv/etnaviv_nir.h @@ -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); diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c index 68e123648ec..2e5ccbb32b3 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c @@ -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; }