[Mesa-dev] [PATCH v3 014/104] nir: Add a pass for fixing deref modes

Jason Ekstrand jason at jlekstrand.net
Tue Apr 3 18:32:41 UTC 2018


This will be needed by anything which changes variable modes without
rewriting derefs.
---
 src/compiler/nir/nir.h       |  2 ++
 src/compiler/nir/nir_deref.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index a02ab2a..405dc42 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2606,6 +2606,8 @@ bool nir_lower_deref_instrs(nir_shader *shader,
 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, nir_shader *shader);
 bool nir_lower_var_copies(nir_shader *shader);
 
+void nir_fixup_deref_modes(nir_shader *shader);
+
 bool nir_lower_global_vars_to_local(nir_shader *shader);
 
 bool nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes);
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 87a8192..af5d75f 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -299,3 +299,33 @@ nir_lower_deref_instrs(nir_shader *shader,
 
    return progress;
 }
+
+void
+nir_fixup_deref_modes(nir_shader *shader)
+{
+   nir_foreach_function(function, shader) {
+      if (!function->impl)
+         continue;
+
+      nir_foreach_block(block, function->impl) {
+         nir_foreach_instr(instr, block) {
+            if (instr->type != nir_instr_type_deref)
+               continue;
+
+            nir_deref_instr *deref = nir_instr_as_deref(instr);
+
+            nir_variable_mode parent_mode;
+            if (deref->deref_type == nir_deref_type_var) {
+               parent_mode = deref->var->data.mode;
+            } else {
+               assert(deref->parent.is_ssa);
+               nir_deref_instr *parent =
+                  nir_instr_as_deref(deref->parent.ssa->parent_instr);
+               parent_mode = parent->mode;
+            }
+
+            deref->mode = parent_mode;
+         }
+      }
+   }
+}
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list