<div dir="ltr">On 15 September 2013 00:19, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This can deal with all the 15 32-bit untyped atomic operations the<br>
hardware supports, but only INC and PREDEC are going to be exposed<br>
through the API for now.<br>
---<br>
 src/mesa/drivers/dri/i965/brw_vec4.h           |  7 +++<br>
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 64 ++++++++++++++++++++++++++<br>
 2 files changed, 71 insertions(+)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
index 37e1da0..7678925 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
@@ -499,6 +499,13 @@ public:<br>
    void emit_shader_time_write(enum shader_time_shader_type type,<br>
                                src_reg value);<br>
<br>
+   void emit_untyped_atomic(unsigned atomic_op, unsigned surf_index,<br>
+                            unsigned offset, dst_reg dst, src_reg src0,<br>
+                            src_reg src1);<br>
+<br>
+   void emit_untyped_surface_read(unsigned surf_index, unsigned offset,<br>
+                                  dst_reg dst);<br>
+<br>
    src_reg get_scratch_offset(vec4_instruction *inst,<br>
                              src_reg *reladdr, int reg_offset);<br>
    src_reg get_pull_constant_offset(vec4_instruction *inst,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
index a19686b..c3d4506 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
@@ -2464,8 +2464,72 @@ vec4_visitor::visit(ir_end_primitive *)<br>
 }<br>
<br>
 void<br>
+vec4_visitor::emit_untyped_atomic(unsigned atomic_op, unsigned surf_index,<br>
+                                  unsigned offset, dst_reg dst,<br>
+                                  src_reg src0, src_reg src1)<br>
+{<br>
+   unsigned mlen = 0;<br>
+<br>
+   /* Set the atomic operation offset. */<br>
+   emit(MOV(brw_writemask(brw_uvec_mrf(8, mlen, 0), WRITEMASK_X),<br>
+            src_reg(offset)));<br>
+   mlen++;<br>
+<br>
+   /* Set the atomic operation arguments. */<br>
+   if (src0.file != BAD_FILE) {<br>
+      emit(MOV(brw_writemask(brw_uvec_mrf(8, mlen, 0), WRITEMASK_X), src0));<br>
+      mlen++;<br>
+   }<br>
+<br>
+   if (src1.file != BAD_FILE) {<br>
+      emit(MOV(brw_writemask(brw_uvec_mrf(8, mlen, 0), WRITEMASK_X), src1));<br>
+      mlen++;<br>
+   }<br>
+<br>
+   /* Emit the instruction. */<br>
+   vec4_instruction *inst = emit(SHADER_OPCODE_UNTYPED_ATOMIC, dst,<br>
+                                 src_reg(atomic_op), src_reg(surf_index));<br></blockquote><div><br></div><div>It's probably worth putting in a comment here to note that pre-Haswell, this uses the SIMD8 atomic message (since there is no SIMD4x2 atomic message).  But that's ok because the dst register is a float, so the instruction will be emitted with WRITEMASK_X, meaning that the operation will be appropriately masked down to operate on just 2 vertices.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   inst->base_mrf = 0;<br>
+   inst->mlen = mlen;<br>
+}<br>
+<br>
+void<br>
+vec4_visitor::emit_untyped_surface_read(unsigned surf_index,<br>
+                                        unsigned offset, dst_reg dst)<br>
+{<br>
+   /* Set the surface read offset. */<br>
+   emit(MOV(brw_writemask(brw_uvec_mrf(8, 0, 0), WRITEMASK_X),<br>
+            src_reg(offset)));<br>
+<br>
+   /* Emit the instruction. */<br>
+   vec4_instruction *inst = emit(SHADER_OPCODE_UNTYPED_SURFACE_READ,<br>
+                                 dst, src_reg(surf_index));<br></blockquote><div><br></div><div>A similar coment about masking would be nice here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+   inst->base_mrf = 0;<br>
+   inst->mlen = 1;<br>
+}<br>
+<br>
+void<br>
 vec4_visitor::visit(ir_atomic *ir)<br>
 {<br>
+   ir_variable *loc = ir->location->variable_referenced();<br>
+   unsigned surf_index = SURF_INDEX_VEC4_ABO(loc->atomic.buffer_index);<br>
+<br>
+   result = src_reg(this, ir->type);<br>
+<br>
+   switch (ir->op) {<br>
+   case ir_atomic_read:<br>
+      emit_untyped_surface_read(surf_index, loc->atomic.offset,<br>
+                                dst_reg(result));<br>
+      break;<br>
+   case ir_atomic_inc:<br>
+      emit_untyped_atomic(BRW_AOP_INC, surf_index, loc->atomic.offset,<br>
+                          dst_reg(result), src_reg(), src_reg());<br>
+      break;<br>
+   case ir_atomic_dec:<br>
+      emit_untyped_atomic(BRW_AOP_PREDEC, surf_index, loc->atomic.offset,<br>
+                          dst_reg(result), src_reg(), src_reg());<br></blockquote><div><br></div><div>My questions about fs_reg() in the last patch apply here too.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+      break;<br>
+   }<br>
 }<br>
<br>
 void<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<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="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>