<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 12:33 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 | 124 ++++++++++++++-----------<br>
 1 file changed, 72 insertions(+), 52 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 bf16aec..9df2ba0 100644<br>
--- a/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
+++ b/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
@@ -31,29 +31,89 @@<br>
<br>
 struct lower_io_state {<br>
    nir_shader *shader;<br>
+   nir_function *entrypoint;<br>
    struct exec_list old_outputs;<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></blockquote><div><br></div><div>I question whether or not this is useful.  I'm inclined to say not.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+static void<br>
+emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl)<br>
+{<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(block, impl) {<br>
+         nir_foreach_instr(instr, block) {<br>
+            if (instr->type != nir_instr_type_intrinsic)<br>
+               continue;<br>
+<br>
+            nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);<br>
+            if (intrin->intrinsic == nir_intrinsic_emit_vertex) {<br>
+               emit_output_copies(nir_before_instr(&intrin->instr), state);<br>
+            }<br>
+         }<br>
+      }<br>
+   } else if (impl->function == state->entrypoint) {<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>
+   /* Reparent the constant initializer (if any) */<br>
+   ralloc_steal(nvar, nvar->constant_initializer);<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, nir_function *entrypoint)<br>
 {<br>
@@ -63,29 +123,14 @@ nir_lower_io_to_temporaries(nir_shader *shader, nir_function *entrypoint)<br>
       return;<br>
<br>
    state.shader = shader;<br>
+   state.entrypoint = entrypoint;<br>
    exec_list_move_nodes_to(&shader->outputs, &state.old_outputs);<br>
<br>
    /* Walk over all of the outputs turn each output into a temporary and<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>
-      /* Reparent the constant initializer (if any) */<br>
-      ralloc_steal(output, output->constant_initializer);<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>
@@ -93,32 +138,7 @@ nir_lower_io_to_temporaries(nir_shader *shader, nir_function *entrypoint)<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(block, function->impl) {<br>
-            nir_foreach_instr(instr, block) {<br>
-               if (instr->type != nir_instr_type_intrinsic)<br>
-                  continue;<br>
-<br>
-               nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);<br>
-               if (intrin->intrinsic == nir_intrinsic_emit_vertex) {<br>
-                  emit_output_copies(nir_before_instr(&intrin->instr),<br>
-                                     &state);<br>
-               }<br>
-            }<br>
-         }<br>
-      } else if (function == entrypoint) {<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(&state, function->impl);<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>
</font></span></blockquote></div><br></div></div>