<div dir="ltr">I don't know that I like the lower-io prefix.  Maybe nir/io-to-temp?  Doesn't really matter<br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 26, 2016 at 2:02 PM, Rob Clark <span dir="ltr"><<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
<br>
Prep work to reduce the noise in the next patch.<br>
<br>
Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
---<br>
 src/compiler/nir/nir_lower_io_to_temporaries.c | 95 +++++++++++++++-----------<br>
 1 file changed, 57 insertions(+), 38 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_lower_io_to_temporaries.c b/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
index 0db436b..8e9df99 100644<br>
--- a/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
+++ b/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
@@ -35,25 +35,30 @@ struct lower_io_state {<br>
 };<br>
<br>
 static void<br>
-emit_output_copies(nir_cursor cursor, struct lower_io_state *state)<br>
+emit_copies(nir_cursor cursor, nir_shader *shader, struct exec_list *new_vars,<br>
+          struct exec_list *old_vars)<br>
 {<br>
-   assert(exec_list_length(&state->shader->outputs) ==<br>
-          exec_list_length(&state->old_outputs));<br>
+   assert(exec_list_length(new_vars) == exec_list_length(old_vars));<br>
<br>
-   foreach_two_lists(out_node, &state->shader->outputs,<br>
-                     temp_node, &state->old_outputs) {<br>
-      nir_variable *output = exec_node_data(nir_variable, out_node, node);<br>
-      nir_variable *temp = exec_node_data(nir_variable, temp_node, node);<br>
+   foreach_two_lists(new_node, new_vars, old_node, old_vars) {<br>
+      nir_variable *newv = exec_node_data(nir_variable, new_node, node);<br>
+      nir_variable *temp = exec_node_data(nir_variable, old_node, node);<br>
<br>
       nir_intrinsic_instr *copy =<br>
-         nir_intrinsic_instr_create(state->shader, nir_intrinsic_copy_var);<br>
-      copy->variables[0] = nir_deref_var_create(copy, output);<br>
+         nir_intrinsic_instr_create(shader, nir_intrinsic_copy_var);<br>
+      copy->variables[0] = nir_deref_var_create(copy, newv);<br>
       copy->variables[1] = nir_deref_var_create(copy, temp);<br>
<br>
       nir_instr_insert(cursor, &copy->instr);<br>
    }<br>
 }<br>
<br>
+static void<br>
+emit_output_copies(nir_cursor cursor, struct lower_io_state *state)<br>
+{<br>
+   emit_copies(cursor, state->shader, &state->shader->outputs, &state->old_outputs);<br>
+}<br>
+<br>
 static bool<br>
 emit_output_copies_block(nir_block *block, void *state)<br>
 {<br>
@@ -69,6 +74,47 @@ emit_output_copies_block(nir_block *block, void *state)<br>
    return true;<br>
 }<br>
<br>
+static void<br>
+emit_output_copies_impl(nir_function_impl *impl, struct lower_io_state *state)<br></blockquote><div><br></div><div>In light of the change to make lower_io_to_temporaries take a nir_function, this will have to be reworked a bit.  Perhaps we want an emit_gs_output_copies and emit_output_copies?  The GS version would walk the entire shader and the non-GS version would take a function impl and just put the copies at the end of it.<br><br></div><div>In any case, I like the direction this is going.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+   if (state->shader->stage == MESA_SHADER_GEOMETRY) {<br>
+      /* For geometry shaders, we have to emit the output copies right<br>
+       * before each EmitVertex call.<br>
+       */<br>
+      nir_foreach_block(impl, emit_output_copies_block, state);<br>
+   } else if (strcmp(impl->function->name, "main") == 0) {<br>
+      /* For all other shader types, we need to do the copies right before<br>
+       * the jumps to the end block.<br>
+       */<br>
+      struct set_entry *block_entry;<br>
+      set_foreach(impl->end_block->predecessors, block_entry) {<br>
+         struct nir_block *block = (void *)block_entry->key;<br>
+         emit_output_copies(nir_after_block_before_jump(block), state);<br>
+      }<br>
+   }<br>
+}<br>
+<br>
+static nir_variable *<br>
+create_shadow_temp(struct lower_io_state *state, nir_variable *var)<br>
+{<br>
+   nir_variable *nvar = ralloc(state->shader, nir_variable);<br>
+   memcpy(nvar, var, sizeof *nvar);<br>
+<br>
+   /* The original is now the temporary */<br>
+   nir_variable *temp = var;<br>
+<br>
+   /* Reparent the name to the new variable */<br>
+   ralloc_steal(nvar, nvar->name);<br>
+<br>
+   /* Give the output a new name with @out-temp appended */<br>
+   const char *mode = "out";<br>
+   temp->name = ralloc_asprintf(var, "%s@%s-temp", mode, nvar->name);<br>
+   temp->data.mode = nir_var_global;<br>
+   temp->constant_initializer = NULL;<br>
+<br>
+   return nvar;<br>
+}<br>
+<br>
 void<br>
 nir_lower_io_to_temporaries(nir_shader *shader)<br>
 {<br>
@@ -84,20 +130,7 @@ nir_lower_io_to_temporaries(nir_shader *shader)<br>
     * make a new variable for the actual output.<br>
     */<br>
    nir_foreach_variable(var, &state.old_outputs) {<br>
-      nir_variable *output = ralloc(shader, nir_variable);<br>
-      memcpy(output, var, sizeof *output);<br>
-<br>
-      /* The orignal is now the temporary */<br>
-      nir_variable *temp = var;<br>
-<br>
-      /* Reparent the name to the new variable */<br>
-      ralloc_steal(output, output->name);<br>
-<br>
-      /* Give the output a new name with @out-temp appended */<br>
-      temp->name = ralloc_asprintf(var, "%s@out-temp", output->name);<br>
-      temp->data.mode = nir_var_global;<br>
-      temp->constant_initializer = NULL;<br>
-<br>
+      nir_variable *output = create_shadow_temp(&state, var);<br>
       exec_list_push_tail(&shader->outputs, &output->node);<br>
    }<br>
<br>
@@ -105,21 +138,7 @@ nir_lower_io_to_temporaries(nir_shader *shader)<br>
       if (function->impl == NULL)<br>
          continue;<br>
<br>
-      if (shader->stage == MESA_SHADER_GEOMETRY) {<br>
-         /* For geometry shaders, we have to emit the output copies right<br>
-          * before each EmitVertex call.<br>
-          */<br>
-         nir_foreach_block(function->impl, emit_output_copies_block, &state);<br>
-      } else if (strcmp(function->name, "main") == 0) {<br>
-         /* For all other shader types, we need to do the copies right before<br>
-          * the jumps to the end block.<br>
-          */<br>
-         struct set_entry *block_entry;<br>
-         set_foreach(function->impl->end_block->predecessors, block_entry) {<br>
-            struct nir_block *block = (void *)block_entry->key;<br>
-            emit_output_copies(nir_after_block_before_jump(block), &state);<br>
-         }<br>
-      }<br>
+      emit_output_copies_impl(function->impl, &state);<br>
<br>
       nir_metadata_preserve(function->impl, nir_metadata_block_index |<br>
                                             nir_metadata_dominance);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.5<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>