<div dir="ltr"><div>Assuming we get the previous patch sorted out,<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><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>
Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
---<br>
src/compiler/nir/nir.h | 2 +-<br>
src/compiler/nir/nir_lower_io_to_temporaries.c | 55 +++++++++++++++++++++-----<br>
src/mesa/drivers/dri/i965/brw_nir.c | 2 +-<br>
3 files changed, 48 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index ab73068..f12bc68 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2160,7 +2160,7 @@ bool nir_lower_indirect_derefs(nir_shader *shader, uint32_t mode_mask);<br>
<br>
bool nir_lower_locals_to_regs(nir_shader *shader);<br>
<br>
-void nir_lower_io_to_temporaries(nir_shader *shader);<br>
+void nir_lower_io_to_temporaries(nir_shader *shader, bool outputs, bool inputs);<br>
<br>
void nir_assign_var_locations(struct exec_list *var_list,<br>
unsigned *size,<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 8e9df99..c25b6e7 100644<br>
--- a/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
+++ b/src/compiler/nir/nir_lower_io_to_temporaries.c<br>
@@ -22,9 +22,12 @@<br>
*/<br>
<br>
/*<br>
- * Implements a pass that lowers output variables to a temporary plus an<br>
- * output variable with a single copy at each exit point of the shader.<br>
- * This way the output variable is only ever written.<br>
+ * Implements a pass that lowers output and/or input variables to a<br>
+ * temporary plus an output variable with a single copy at each exit<br>
+ * point of the shader and/or an input variable with a single copy<br>
+ * at the entrance point of the shader. This way the output variable<br>
+ * is only ever written once and/or input is only read once, and there<br>
+ * are no indirect outut/input accesses.<br>
*/<br>
<br>
#include "nir.h"<br>
@@ -32,6 +35,7 @@<br>
struct lower_io_state {<br>
nir_shader *shader;<br>
struct exec_list old_outputs;<br>
+ struct exec_list old_inputs;<br>
};<br>
<br>
static void<br>
@@ -48,7 +52,6 @@ emit_copies(nir_cursor cursor, nir_shader *shader, struct exec_list *new_vars,<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, ©->instr);<br>
}<br>
}<br>
@@ -94,6 +97,20 @@ emit_output_copies_impl(nir_function_impl *impl, struct lower_io_state *state)<br>
}<br>
}<br>
<br>
+static void<br>
+emit_input_copies(nir_cursor cursor, struct lower_io_state *state)<br>
+{<br>
+ emit_copies(cursor, state->shader, &state->old_inputs, &state->shader->inputs);<br>
+}<br>
+<br>
+static void<br>
+emit_input_copies_impl(nir_function_impl *impl, struct lower_io_state *state)<br>
+{<br>
+ if (strcmp(impl->function->name, "main") == 0) {<br>
+ emit_input_copies(nir_before_block(nir_start_block(impl)), state);<br>
+ }<br>
+}<br>
+<br>
static nir_variable *<br>
create_shadow_temp(struct lower_io_state *state, nir_variable *var)<br>
{<br>
@@ -106,8 +123,8 @@ create_shadow_temp(struct lower_io_state *state, nir_variable *var)<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>
+ /* Give the original a new name with @<mode>-temp appended */<br>
+ const char *mode = (temp->data.mode == nir_var_shader_in) ? "in" : "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>
@@ -116,7 +133,7 @@ create_shadow_temp(struct lower_io_state *state, nir_variable *var)<br>
}<br>
<br>
void<br>
-nir_lower_io_to_temporaries(nir_shader *shader)<br>
+nir_lower_io_to_temporaries(nir_shader *shader, bool outputs, bool inputs)<br>
{<br>
struct lower_io_state state;<br>
<br>
@@ -124,7 +141,16 @@ nir_lower_io_to_temporaries(nir_shader *shader)<br>
return;<br>
<br>
state.shader = shader;<br>
- exec_list_move_nodes_to(&shader->outputs, &state.old_outputs);<br>
+<br>
+ if (inputs)<br>
+ exec_list_move_nodes_to(&shader->inputs, &state.old_inputs);<br>
+ else<br>
+ exec_list_make_empty(&state.old_inputs);<br>
+<br>
+ if (outputs)<br>
+ exec_list_move_nodes_to(&shader->outputs, &state.old_outputs);<br>
+ else<br>
+ exec_list_make_empty(&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>
@@ -134,15 +160,26 @@ nir_lower_io_to_temporaries(nir_shader *shader)<br>
exec_list_push_tail(&shader->outputs, &output->node);<br>
}<br>
<br>
+ /* and same for inputs: */<br>
+ nir_foreach_variable(var, &state.old_inputs) {<br>
+ nir_variable *input = create_shadow_temp(&state, var);<br>
+ exec_list_push_tail(&shader->inputs, &input->node);<br>
+ }<br>
+<br>
nir_foreach_function(shader, function) {<br>
if (function->impl == NULL)<br>
continue;<br>
<br>
- emit_output_copies_impl(function->impl, &state);<br>
+ if (inputs)<br>
+ emit_input_copies_impl(function->impl, &state);<br>
+<br>
+ if (outputs)<br>
+ emit_output_copies_impl(function->impl, &state);<br>
<br>
nir_metadata_preserve(function->impl, nir_metadata_block_index |<br>
nir_metadata_dominance);<br>
}<br>
<br>
+ exec_list_append(&shader->globals, &state.old_inputs);<br>
exec_list_append(&shader->globals, &state.old_outputs);<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c<br>
index 10f4ae1..d7c9764 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_nir.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_nir.c<br>
@@ -560,7 +560,7 @@ brw_create_nir(struct brw_context *brw,<br>
/* First, lower the GLSL IR or Mesa IR to NIR */<br>
if (shader_prog) {<br>
nir = glsl_to_nir(shader_prog, stage, options);<br>
- nir_lower_io_to_temporaries(nir);<br>
+ nir_lower_io_to_temporaries(nir, true, false);<br>
} else {<br>
nir = prog_to_nir(prog, options);<br>
OPT_V(nir_convert_to_ssa); /* turn registers into SSA */<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>