<div dir="ltr">On 15 September 2013 00:10, 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">---<br>
 src/mesa/drivers/dri/i965/brw_defines.h     |  2 +<br>
 src/mesa/drivers/dri/i965/brw_eu.h          |  9 +++++<br>
 src/mesa/drivers/dri/i965/brw_eu_emit.c     | 62 +++++++++++++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/brw_fs.cpp        |  2 +<br>
 src/mesa/drivers/dri/i965/brw_fs.h          |  5 +++<br>
 src/mesa/drivers/dri/i965/brw_fs_emit.cpp   | 21 ++++++++++<br>
 src/mesa/drivers/dri/i965/brw_vec4.cpp      |  2 +<br>
 src/mesa/drivers/dri/i965/brw_vec4.h        |  5 +++<br>
 src/mesa/drivers/dri/i965/brw_vec4_emit.cpp | 22 ++++++++++<br>
 9 files changed, 130 insertions(+)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h<br>
index e9e0c4a..ccb4ce4 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
@@ -770,6 +770,8 @@ enum opcode {<br>
<br>
    SHADER_OPCODE_SHADER_TIME_ADD,<br>
<br>
+   SHADER_OPCODE_UNTYPED_ATOMIC,<br>
+<br>
    FS_OPCODE_DDX,<br>
    FS_OPCODE_DDY,<br>
    FS_OPCODE_PIXEL_X,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h<br>
index 720bc74..212d916 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_eu.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_eu.h<br>
@@ -422,6 +422,15 @@ void brw_CMP(struct brw_compile *p,<br>
             struct brw_reg src0,<br>
             struct brw_reg src1);<br>
<br>
+void<br>
+brw_untyped_atomic(struct brw_compile *p,<br>
+                   struct brw_reg dest,<br>
+                   struct brw_reg mrf,<br>
+                   GLuint atomic_op,<br>
+                   GLuint bind_table_index,<br>
+                   GLuint msg_length,<br>
+                   GLuint response_length);<br>
+<br>
 /***********************************************************************<br>
  * brw_eu_util.c:<br>
  */<br>
diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c<br>
index cce8752..f39bf99 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c<br>
@@ -2465,6 +2465,68 @@ brw_svb_write(struct brw_compile *p,<br>
                             send_commit_msg); /* send_commit_msg */<br>
 }<br>
<br>
+static void<br>
+brw_set_dp_untyped_atomic_message(struct brw_compile *p,<br>
+                                  struct brw_instruction *insn,<br>
+                                  GLuint atomic_op,<br>
+                                  GLuint bind_table_index,<br>
+                                  GLuint msg_length,<br>
+                                  GLuint response_length,<br>
+                                  bool header_present)<br>
+{<br>
+   if (p->brw->is_haswell) {<br>
+      brw_set_message_descriptor(p, insn, HSW_SFID_DATAPORT_DATA_CACHE_1,<br>
+                                 msg_length, response_length,<br>
+                                 header_present, false);<br>
+<br>
+<br>
+      if (insn->header.access_mode == BRW_ALIGN_1) {<br>
+         if (insn->header.execution_size != BRW_EXECUTE_16)<br>
+            insn->bits3.ud |= 1 << 12; /* SIMD8 mode */<br>
+<br>
+         insn->bits3.gen7_dp.msg_type =<br>
+            HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP;<br>
+      } else {<br>
+         insn->bits3.gen7_dp.msg_type =<br>
+            HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2;<br>
+      }<br>
+<br>
+   } else {<br></blockquote><div><br></div><div>It would be nice to have a comment somewhere in the else block explaining that on IVB, SIMD4x2 atomic operations aren't available, so we implement them using SIMD8 messages, and we rely on the shader compiler to set the execution mask accordingly.<br>
<br></div><div>With that comment added, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      brw_set_message_descriptor(p, insn, GEN7_SFID_DATAPORT_DATA_CACHE,<br>
+                                 msg_length, response_length,<br>
+                                 header_present, false);<br>
+<br>
+      insn->bits3.gen7_dp.msg_type = GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP;<br>
+<br>
+      if (insn->header.execution_size != BRW_EXECUTE_16)<br>
+         insn->bits3.ud |= 1 << 12; /* SIMD8 mode */<br>
+   }<br>
+<br>
+   if (response_length)<br>
+      insn->bits3.ud |= 1 << 13; /* Return data expected */<br>
+<br>
+   insn->bits3.gen7_dp.binding_table_index = bind_table_index;<br>
+   insn->bits3.ud |= atomic_op << 8;<br>
+}<br>
+<br>
+void<br>
+brw_untyped_atomic(struct brw_compile *p,<br>
+                   struct brw_reg dest,<br>
+                   struct brw_reg mrf,<br>
+                   GLuint atomic_op,<br>
+                   GLuint bind_table_index,<br>
+                   GLuint msg_length,<br>
+                   GLuint response_length) {<br>
+   struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);<br>
+<br>
+   brw_set_dest(p, insn, retype(dest, BRW_REGISTER_TYPE_UD));<br>
+   brw_set_src0(p, insn, retype(mrf, BRW_REGISTER_TYPE_UD));<br>
+   brw_set_src1(p, insn, brw_imm_d(0));<br>
+   brw_set_dp_untyped_atomic_message(<br>
+      p, insn, atomic_op, bind_table_index, msg_length, response_length,<br>
+      insn->header.access_mode == BRW_ALIGN_1);<br>
+}<br>
+<br>
 /**<br>
  * This instruction is generated as a single-channel align1 instruction by<br>
  * both the VS and FS stages when using INTEL_DEBUG=shader_time.<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
index a98e7c7..4f1a665 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
@@ -738,6 +738,8 @@ fs_visitor::implied_mrf_writes(fs_inst *inst)<br>
       return inst->mlen;<br>
    case FS_OPCODE_SPILL:<br>
       return 2;<br>
+   case SHADER_OPCODE_UNTYPED_ATOMIC:<br>
+      return 0;<br>
    default:<br>
       assert(!"not reached");<br>
       return inst->mlen;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h<br>
index e78267e..27a47fa 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.h<br>
@@ -556,6 +556,11 @@ private:<br>
                                  struct brw_reg offset,<br>
                                  struct brw_reg value);<br>
<br>
+   void generate_untyped_atomic(fs_inst *inst,<br>
+                                struct brw_reg dst,<br>
+                                struct brw_reg atomic_op,<br>
+                                struct brw_reg surf_index);<br>
+<br>
    void mark_surface_used(unsigned surf_index);<br>
<br>
    void patch_discard_jumps_to_fb_writes();<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_emit.cpp b/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
index bfb3d33..cf30fcb 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_emit.cpp<br>
@@ -1066,6 +1066,23 @@ fs_generator::generate_shader_time_add(fs_inst *inst,<br>
 }<br>
<br>
 void<br>
+fs_generator::generate_untyped_atomic(fs_inst *inst, struct brw_reg dst,<br>
+                                      struct brw_reg atomic_op,<br>
+                                      struct brw_reg surf_index)<br>
+{<br>
+   assert(atomic_op.file == BRW_IMMEDIATE_VALUE &&<br>
+          atomic_op.type == BRW_REGISTER_TYPE_UD &&<br>
+          surf_index.file == BRW_IMMEDIATE_VALUE &&<br>
+         surf_index.type == BRW_REGISTER_TYPE_UD);<br>
+<br>
+   brw_untyped_atomic(p, dst, brw_message_reg(inst->base_mrf),<br>
+                      atomic_op.dw1.ud, surf_index.dw1.ud,<br>
+                      inst->mlen, dispatch_width / 8);<br>
+<br>
+   mark_surface_used(surf_index.dw1.ud);<br>
+}<br>
+<br>
+void<br>
 fs_generator::generate_code(exec_list *instructions)<br>
 {<br>
    int last_native_insn_offset = p->next_insn_offset;<br>
@@ -1439,6 +1456,10 @@ fs_generator::generate_code(exec_list *instructions)<br>
          generate_shader_time_add(inst, src[0], src[1], src[2]);<br>
          break;<br>
<br>
+      case SHADER_OPCODE_UNTYPED_ATOMIC:<br>
+         generate_untyped_atomic(inst, dst, src[0], src[1]);<br>
+         break;<br>
+<br>
       case FS_OPCODE_SET_SIMD4X2_OFFSET:<br>
          generate_set_simd4x2_offset(inst, dst, src[0]);<br>
          break;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
index 2c1f541..590c0a5 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
@@ -271,6 +271,8 @@ vec4_visitor::implied_mrf_writes(vec4_instruction *inst)<br>
    case SHADER_OPCODE_TXF_MS:<br>
    case SHADER_OPCODE_TXS:<br>
       return inst->header_present ? 1 : 0;<br>
+   case SHADER_OPCODE_UNTYPED_ATOMIC:<br>
+      return 0;<br>
    default:<br>
       assert(!"not reached");<br>
       return inst->mlen;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
index 13c9166..233f233 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h<br>
@@ -620,6 +620,11 @@ private:<br>
    void generate_unpack_flags(vec4_instruction *inst,<br>
                               struct brw_reg dst);<br>
<br>
+   void generate_untyped_atomic(vec4_instruction *inst,<br>
+                                struct brw_reg dst,<br>
+                                struct brw_reg atomic_op,<br>
+                                struct brw_reg surf_index);<br>
+<br>
    void mark_surface_used(unsigned surf_index);<br>
<br>
    struct brw_context *brw;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
index 6916134..05c5806 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp<br>
@@ -835,6 +835,24 @@ vec4_generator::generate_pull_constant_load_gen7(vec4_instruction *inst,<br>
    mark_surface_used(surf_index.dw1.ud);<br>
 }<br>
<br>
+void<br>
+vec4_generator::generate_untyped_atomic(vec4_instruction *inst,<br>
+                                        struct brw_reg dst,<br>
+                                        struct brw_reg atomic_op,<br>
+                                        struct brw_reg surf_index)<br>
+{<br>
+   assert(atomic_op.file == BRW_IMMEDIATE_VALUE &&<br>
+          atomic_op.type == BRW_REGISTER_TYPE_UD &&<br>
+          surf_index.file == BRW_IMMEDIATE_VALUE &&<br>
+         surf_index.type == BRW_REGISTER_TYPE_UD);<br>
+<br>
+   brw_untyped_atomic(p, dst, brw_message_reg(inst->base_mrf),<br>
+                      atomic_op.dw1.ud, surf_index.dw1.ud,<br>
+                      inst->mlen, 1);<br>
+<br>
+   mark_surface_used(surf_index.dw1.ud);<br>
+}<br>
+<br>
 /**<br>
  * Generate assembly for a Vec4 IR instruction.<br>
  *<br>
@@ -1096,6 +1114,10 @@ vec4_generator::generate_vec4_instruction(vec4_instruction *instruction,<br>
       mark_surface_used(SURF_INDEX_VEC4_SHADER_TIME);<br>
       break;<br>
<br>
+   case SHADER_OPCODE_UNTYPED_ATOMIC:<br>
+      generate_untyped_atomic(inst, dst, src[0], src[1]);<br>
+      break;<br>
+<br>
    case VS_OPCODE_UNPACK_FLAGS_SIMD4X2:<br>
       generate_unpack_flags(inst, dst);<br>
       break;<br>
<span><font color="#888888">--<br>
1.8.3.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">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>