etnaviv: nir: lower nir_texop_txs
authorChristian Gmeiner <cgmeiner@igalia.com>
Tue, 11 Jul 2023 13:46:55 +0000 (15:46 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 21 Jul 2023 08:52:03 +0000 (08:52 +0000)
Non of the GPU models know at this time have hardware support to
retrieve the dimensions of a level of a texture. Do almost the
same as the binary blob and store the needed values as uniforms.

Passes dEQP-GLES3.functional.shaders.texture_functions.texturesize.*

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24217>

src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c

index 4348e9e..3e15fa3 100644 (file)
@@ -5,6 +5,27 @@
 
 #include "etnaviv_nir.h"
 
+static bool
+lower_txs(nir_builder *b, nir_instr *instr, UNUSED void *data)
+{
+   if (instr->type != nir_instr_type_tex)
+      return false;
+
+   nir_tex_instr *tex = nir_instr_as_tex(instr);
+
+   if (tex->op != nir_texop_txs)
+      return false;
+
+   b->cursor = nir_instr_remove(instr);
+
+   nir_ssa_def *idx = nir_imm_int(b, tex->texture_index);
+   nir_ssa_def *sizes = nir_load_texture_size_etna(b, 32, idx);
+
+   nir_ssa_def_rewrite_uses(&tex->dest.ssa, sizes);
+
+   return true;
+}
+
 bool
 etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
 {
@@ -12,6 +33,7 @@ etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
 
    nir_lower_tex_options lower_tex_options = {
       .lower_txp = ~0u,
+      .lower_txs_lod = true,
       .lower_invalid_implicit_lod = true,
    };
 
@@ -22,5 +44,8 @@ etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key)
                                                   key->tex_compare_func,
                                                   key->tex_swizzle);
 
+   NIR_PASS(progress, s, nir_shader_instructions_pass, lower_txs,
+         nir_metadata_block_index | nir_metadata_dominance, NULL);
+
    return progress;
 }