<div dir="ltr">On 2 December 2013 11:39, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
src/mesa/drivers/dri/i965/brw_defines.h | 2 +<br>
src/mesa/drivers/dri/i965/brw_eu.h | 4 ++<br>
src/mesa/drivers/dri/i965/brw_eu_emit.c | 69 ++++++++++++++++++++++++<br>
src/mesa/drivers/dri/i965/brw_fs.cpp | 2 +<br>
src/mesa/drivers/dri/i965/brw_fs_generator.cpp | 4 ++<br>
src/mesa/drivers/dri/i965/brw_shader.cpp | 1 +<br>
src/mesa/drivers/dri/i965/brw_vec4.cpp | 2 +<br>
src/mesa/drivers/dri/i965/brw_vec4_generator.cpp | 4 ++<br>
8 files changed, 88 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 631473a..9e51e2c 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
@@ -784,6 +784,8 @@ enum opcode {<br>
SHADER_OPCODE_TYPED_SURFACE_READ,<br>
SHADER_OPCODE_TYPED_SURFACE_WRITE,<br>
<br>
+ SHADER_OPCODE_MEMORY_FENCE,<br>
+<br>
SHADER_OPCODE_GEN4_SCRATCH_READ,<br>
SHADER_OPCODE_GEN4_SCRATCH_WRITE,<br>
SHADER_OPCODE_GEN7_SCRATCH_READ,<br>
diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h<br>
index 17822ce..a47c730 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_eu.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_eu.h<br>
@@ -408,6 +408,10 @@ brw_typed_surface_write(struct brw_compile *p,<br>
unsigned msg_length,<br>
unsigned num_channels);<br>
<br>
+void<br>
+brw_memory_fence(struct brw_compile *p,<br>
+ struct brw_reg mrf);<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 772be7a..3ee86c6 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c<br>
@@ -2919,6 +2919,75 @@ brw_typed_surface_write(struct brw_compile *p,<br>
brw_send_indirect_message(p, sfid, dst, mrf, desc);<br>
}<br>
<br>
+static void<br>
+brw_set_memory_fence_message(struct brw_compile *p,<br>
+ struct brw_instruction *insn,<br>
+ enum brw_message_target sfid,<br>
+ bool commit_enable)<br>
+{<br>
+ brw_set_message_descriptor(p, insn, sfid,<br>
+ 1 /* message length */,<br>
+ (commit_enable ? 1 : 0) /* response length */,<br>
+ true /* header present */,<br>
+ false);<br>
+<br>
+ switch (sfid) {<br>
+ case GEN6_SFID_DATAPORT_RENDER_CACHE:<br>
+ insn->bits3.gen7_dp.msg_type = GEN7_DATAPORT_RC_MEMORY_FENCE;<br>
+ break;<br>
+ case GEN7_SFID_DATAPORT_DATA_CACHE:<br>
+ insn->bits3.gen7_dp.msg_type = GEN7_DATAPORT_DC_MEMORY_FENCE;<br>
+ break;<br>
+ default:<br>
+ unreachable();<br></blockquote><div><br></div><div>Change to an assert.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ }<br>
+<br>
+ if (commit_enable)<br>
+ insn->bits3.ud |= 1 << 13;<br>
+}<br>
+<br>
+void<br>
+brw_memory_fence(struct brw_compile *p,<br>
+ struct brw_reg mrf)<br>
+{<br>
+ const bool commit_enable = !p->brw->is_haswell;<br></blockquote><div><br></div><div>It would be nice to have a comment here with a pointer to Graphics BSpec: 3D-Media-GPGPU Engine > Shared Functions > Shared Functions – Data Port [Pre-SKL] > Messages > Memory Fence, which explains why the commit enable is needed on IVB and not HSW.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ struct brw_instruction *insn;<br>
+<br>
+ /* Set mrf as destination for dependency tracking, the MEMORY_FENCE<br>
+ * message doesn't write anything back.<br>
+ */<br></blockquote><div><br></div><div>I don't think this comment is correct. The MEMORY_FENCE message *does* write something back, if commit_enable is true. The particular value that it writes back is reserved, but that's different from not writing anything back at all. <br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ insn = next_insn(p, BRW_OPCODE_SEND);<br>
+ mrf = retype(mrf, BRW_REGISTER_TYPE_UD);<br>
+ brw_set_dest(p, insn, mrf);<br>
+ brw_set_src0(p, insn, mrf);<br>
+ brw_set_memory_fence_message(p, insn, GEN7_SFID_DATAPORT_DATA_CACHE,<br>
+ commit_enable);<br>
+<br>
+ if (!p->brw->is_haswell) {<br>
+ /* IVB does typed surface access through the render cache, so we<br>
+ * need to flush that too. Use a different register so both<br>
+ * flushes can be pipelined by the hardware.<br>
+ */<br>
+ insn = next_insn(p, BRW_OPCODE_SEND);<br>
+ brw_set_dest(p, insn, offset(mrf, 1));<br>
+ brw_set_src0(p, insn, offset(mrf, 1));<br>
+ brw_set_memory_fence_message(p, insn, GEN6_SFID_DATAPORT_RENDER_CACHE,<br>
+ commit_enable);<br>
+<br>
+ /* Now write the response of the second message into the<br>
+ * response of the first to trigger a pipeline stall -- This way<br>
+ * future render and data cache messages will be properly<br>
+ * ordered with respect to past data and render cache messages<br>
+ * respectively.<br>
+ */<br>
+ brw_push_insn_state(p);<br>
+ brw_set_compression_control(p, BRW_COMPRESSION_NONE);<br>
+ brw_set_mask_control(p, BRW_MASK_DISABLE);<br>
+ brw_MOV(p, mrf, offset(mrf, 1));<br>
+ brw_pop_insn_state(p);<br>
+ }<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 20cb4b9..cce6ed0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
@@ -786,6 +786,8 @@ fs_visitor::implied_mrf_writes(fs_inst *inst)<br>
case SHADER_OPCODE_TYPED_SURFACE_READ:<br>
case SHADER_OPCODE_TYPED_SURFACE_WRITE:<br>
return 0;<br>
+ case SHADER_OPCODE_MEMORY_FENCE:<br>
+ return 1;<br>
default:<br>
assert(!"not reached");<br>
return inst->mlen;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp<br>
index 9601183..5ead435 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp<br>
@@ -1714,6 +1714,10 @@ fs_generator::generate_code(exec_list *instructions)<br>
src[0], inst->mlen, src[1].dw1.ud);<br>
break;<br>
<br>
+ case SHADER_OPCODE_MEMORY_FENCE:<br>
+ brw_memory_fence(p, brw_message_reg(inst->base_mrf));<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_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
index fc8d0ff..26300a6 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
@@ -663,6 +663,7 @@ backend_instruction::has_side_effects() const<br>
case SHADER_OPCODE_UNTYPED_ATOMIC:<br>
case SHADER_OPCODE_TYPED_ATOMIC:<br>
case SHADER_OPCODE_TYPED_SURFACE_WRITE:<br>
+ case SHADER_OPCODE_MEMORY_FENCE:<br>
return true;<br>
default:<br>
return false;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
index 04054d5..e98fff5 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
@@ -298,6 +298,8 @@ vec4_visitor::implied_mrf_writes(vec4_instruction *inst)<br>
case SHADER_OPCODE_TYPED_SURFACE_READ:<br>
case SHADER_OPCODE_TYPED_SURFACE_WRITE:<br>
return 0;<br>
+ case SHADER_OPCODE_MEMORY_FENCE:<br>
+ return 1;<br></blockquote><div><br></div><div>It's 1 just for IVB, right? (Since IVB writes to mrf and mrf+1, whereas HSW just uses mrf).<br><br></div><div>With those issues fixed, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div></div></div></div>