[Mesa-dev] [PATCH 17/21] etnaviv: nir: add texture fixup path before register assignment

Philipp Zabel p.zabel at pengutronix.de
Tue Jun 5 14:38:41 UTC 2018


The texture instructions expect the source register to have the correct number
of components. Since we only have vec4 hardware registers, rewrite the number
of components to 4 and insert a mov instruction to a new vec4 SSA right before
the texture load instruction.

TODO: To support destination registers with the correct num_components
we have to add additional virtual scalar, vec2, and vec3 register
classes that only allow to use the X, XY, and XYZ components.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter at pengutronix.de>
---
 src/gallium/drivers/etnaviv/etnaviv_nir.c | 27 +++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.c b/src/gallium/drivers/etnaviv/etnaviv_nir.c
index 7889adf473ab..af1684ed9091 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_nir.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_nir.c
@@ -373,6 +373,32 @@ etna_lower_store_intrinsics(nir_shader *shader)
    }
 }
 
+/* The hardware only has vec4 registers, so rewrite all texture load
+ * instructions to require vec4 sources.
+ */
+static void
+etna_fixup_tex(nir_shader *shader)
+{
+   nir_foreach_function(function, shader) {
+      nir_metadata_require(function->impl, nir_metadata_live_ssa_defs);
+      nir_foreach_block(block, function->impl) {
+         nir_foreach_instr(instr, block) {
+            if (instr->type != nir_instr_type_tex)
+               continue;
+
+            nir_tex_instr *tex = nir_instr_as_tex(instr);
+
+            if (tex->src[0].src_type == nir_tex_src_coord) {
+               tex->coord_components = 4;
+               insert_mov(&tex->instr, &tex->src[0].src, shader);
+            }
+         }
+      }
+      nir_metadata_preserve(function->impl,
+                            nir_metadata_block_index | nir_metadata_dominance);
+   }
+}
+
 /* Return the destination SSA if it should be replaced with a global register,
  * or NULL.
  */
@@ -957,6 +983,7 @@ etna_optimize_nir(struct etna_shader *shader,
    NIR_PASS_V(s, etna_lower_store_intrinsics);
 
    NIR_PASS_V(s, nir_convert_from_ssa, true);
+   NIR_PASS_V(s, etna_fixup_tex);
    NIR_PASS_V(s, etna_assign_registers);
    NIR_PASS_V(s, etna_remove_io_intrinsics);
 
-- 
2.17.1



More information about the mesa-dev mailing list