<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 14, 2016 at 11:57 PM, Jordan Justen <span dir="ltr"><<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Jordan Justen <<a href="mailto:jordan.l.justen@intel.com">jordan.l.justen@intel.com</a>><br>
---<br>
 src/compiler/nir/nir_lower_io.c | 86 ++++++++++++++++++++++++++++++++++++++++-<br>
 1 file changed, 84 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c<br>
index f844947..a869eb2 100644<br>
--- a/src/compiler/nir/nir_lower_io.c<br>
+++ b/src/compiler/nir/nir_lower_io.c<br>
@@ -189,6 +189,27 @@ store_op(struct lower_io_state *state,<br>
    return op;<br>
 }<br>
<br>
+static nir_intrinsic_op<br>
+atomic_op(nir_intrinsic_op opcode)<br>
+{<br>
+   switch (opcode) {<br>
+#define OP(O) case nir_intrinsic_var_##O: return nir_intrinsic_shared_##O;<br>
+   OP(atomic_exchange)<br>
+   OP(atomic_comp_swap)<br>
+   OP(atomic_add)<br>
+   OP(atomic_imin)<br>
+   OP(atomic_umin)<br>
+   OP(atomic_imax)<br>
+   OP(atomic_umax)<br>
+   OP(atomic_and)<br>
+   OP(atomic_or)<br>
+   OP(atomic_xor)<br>
+#undef OP<br>
+   default:<br>
+      unreachable("Invalid atomic");<br>
+   }<br>
+}<br>
+<br>
 static bool<br>
 nir_lower_io_block(nir_block *block, void *void_state)<br>
 {<br>
@@ -202,9 +223,25 @@ nir_lower_io_block(nir_block *block, void *void_state)<br>
<br>
       nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);<br>
<br>
-      if (intrin->intrinsic != nir_intrinsic_load_var &&<br>
-          intrin->intrinsic != nir_intrinsic_store_var)<br>
+      switch (intrin->intrinsic) {<br>
+      case nir_intrinsic_load_var:<br>
+      case nir_intrinsic_store_var:<br>
+      case nir_intrinsic_var_atomic_add:<br>
+      case nir_intrinsic_var_atomic_imin:<br>
+      case nir_intrinsic_var_atomic_umin:<br>
+      case nir_intrinsic_var_atomic_imax:<br>
+      case nir_intrinsic_var_atomic_umax:<br>
+      case nir_intrinsic_var_atomic_and:<br>
+      case nir_intrinsic_var_atomic_or:<br>
+      case nir_intrinsic_var_atomic_xor:<br>
+      case nir_intrinsic_var_atomic_exchange:<br>
+      case nir_intrinsic_var_atomic_comp_swap:<br>
+         /* We can lower the io for this nir instrinsic */<br>
+         break;<br>
+      default:<br>
+         /* We can't lower the io for this nir instrinsic, so skip it */<br>
          continue;<br>
+      }<br>
<br>
       nir_variable_mode mode = intrin->variables[0]->var->data.mode;<br>
<br>
@@ -293,6 +330,51 @@ nir_lower_io_block(nir_block *block, void *void_state)<br>
          break;<br>
       }<br>
<br>
+      case nir_intrinsic_var_atomic_add:<br>
+      case nir_intrinsic_var_atomic_imin:<br>
+      case nir_intrinsic_var_atomic_umin:<br>
+      case nir_intrinsic_var_atomic_imax:<br>
+      case nir_intrinsic_var_atomic_umax:<br>
+      case nir_intrinsic_var_atomic_and:<br>
+      case nir_intrinsic_var_atomic_or:<br>
+      case nir_intrinsic_var_atomic_xor:<br>
+      case nir_intrinsic_var_atomic_exchange:<br>
+      case nir_intrinsic_var_atomic_comp_swap: {<br>
+         assert(mode == nir_var_shared);<br>
+<br>
+         nir_ssa_def *offset;<br>
+<br>
+         offset = get_io_offset(b, intrin->variables[0],<br>
+                                NULL, state->type_size);<br>
+<br>
+         nir_intrinsic_instr *atomic =<br>
+            nir_intrinsic_instr_create(state->mem_ctx,<br>
+                                       atomic_op(intrin->intrinsic));<br>
+<br>
+         atomic->src[0] = nir_src_for_ssa(offset);<br>
+<br>
+         atomic->const_index[0] =<br>
+            intrin->variables[0]->var->data.driver_location;<br>
+<br>
+         nir_src_copy(&atomic->src[1], &intrin->src[0], atomic);<br>
+<br>
+         if (intrin->intrinsic == nir_intrinsic_var_atomic_comp_swap)<br>
+            nir_src_copy(&atomic->src[2], &intrin->src[1], atomic);<br></blockquote><div><br></div><div>Would looking in nir_intrinsic_infos for num_inputs be better?  Perhaps even a for loop?  If you don't want to change it, that's ok. I'm fine with it either way.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+         if (intrin->dest.is_ssa) {<br>
+            nir_ssa_dest_init(&atomic->instr, &atomic->dest,<br>
+                              intrin->dest.ssa.num_components, NULL);<br>
+            nir_ssa_def_rewrite_uses(&intrin->dest.ssa,<br>
+                                     nir_src_for_ssa(&atomic->dest.ssa));<br>
+         } else {<br>
+            nir_dest_copy(&atomic->dest, &intrin->dest, state->mem_ctx);<br>
+         }<br>
+<br>
+         nir_instr_insert_before(&intrin->instr, &atomic->instr);<br>
+         nir_instr_remove(&intrin->instr);<br>
+         break;<br>
+      }<br>
+<br>
       default:<br>
          break;<br>
       }<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.0<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>