nir: Allow internal changes to the instr in nir_shader_lower_instructions().
authorEric Anholt <eric@anholt.net>
Tue, 16 Jul 2019 17:52:25 +0000 (10:52 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 18 Jul 2019 18:28:56 +0000 (11:28 -0700)
v3d's NIR txf_ms lowering wants to swizzle around the input coordinates in
NIR, but doesn't generate a new txf_ms instructions as replacement.  It's
pretty easy to allow that in nir_shader_lower_instructions, and it may be
common in lowering passes.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir.c
src/compiler/nir/nir.h

index bf7a5fa0b7e6bc799ed2f2379fdfe8a346b42835..e09cb71bb35f3e76880a296f55c1a5ca17c1345c 100644 (file)
@@ -1876,7 +1876,7 @@ nir_function_impl_lower_instructions(nir_function_impl *impl,
 
       b.cursor = nir_after_instr(instr);
       nir_ssa_def *new_def = lower(&b, instr, cb_data);
-      if (new_def) {
+      if (new_def && new_def != NIR_LOWER_INSTR_PROGRESS) {
          assert(old_def != NULL);
          if (new_def->parent_instr->block != instr->block)
             preserved = nir_metadata_none;
@@ -1901,6 +1901,9 @@ nir_function_impl_lower_instructions(nir_function_impl *impl,
             list_replace(&old_if_uses, &old_def->if_uses);
          }
          iter = nir_after_instr(instr);
+
+         if (new_def == NIR_LOWER_INSTR_PROGRESS)
+            progress = true;
       }
    }
 
index 99fa4baa16a3a6c5243505458a0ed0c909a0cc6e..c94da19668e45c1dc274c2e99bae1125f9532cf6 100644 (file)
@@ -3299,6 +3299,13 @@ typedef bool (*nir_instr_filter_cb)(const nir_instr *, const void *);
 typedef nir_ssa_def *(*nir_lower_instr_cb)(struct nir_builder *,
                                            nir_instr *, void *);
 
+/**
+ * Special return value for nir_lower_instr_cb when some progress occurred
+ * (like changing an input to the instr) that didn't result in a replacement
+ * SSA def being generated.
+ */
+#define NIR_LOWER_INSTR_PROGRESS ((nir_ssa_def *)(uintptr_t)1)
+
 /** Iterate over all the instructions in a nir_function_impl and lower them
  *  using the provided callbacks
  *