<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 27, 2016 at 7:05 PM, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The sampler EOT optimization pass naively assumes that the texturing<br>
instruction provides all the data used by the FB write just because<br>
they're standing next to each other.  The least we should be checking<br>
is whether the source and destination regions of the FB write and<br>
texturing instructions match.  Without this the previous seemingly<br>
harmless commit would have caused opt_sampler_eot() to misoptimize a<br>
shader from dota-2 causing DCE to eliminate all of its 78 instructions<br>
except for the final sampler EOT message (!).<br></blockquote><div><br></div><div>Oh, well that's fun...<br></div><div> </div><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 |  1 +<br>
 src/mesa/drivers/dri/i965/brw_fs.cpp    | 14 ++++++++++++++<br>
 2 files changed, 15 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 8794d44..60b215d 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
@@ -1395,6 +1395,7 @@ enum fb_write_logical_srcs {<br>
    FB_WRITE_LOGICAL_SRC_SRC_STENCIL, /* gl_FragStencilRefARB */<br>
    FB_WRITE_LOGICAL_SRC_OMASK,       /* Sample Mask (gl_SampleMask) */<br>
    FB_WRITE_LOGICAL_SRC_COMPONENTS,  /* REQUIRED */<br>
+   FB_WRITE_LOGICAL_NUM_SRCS<br>
 };<br>
<br>
 enum tex_logical_srcs {<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
index 6abf776..1574cd9 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
@@ -2647,6 +2647,20 @@ fs_visitor::opt_sampler_eot()<br>
    if (tex_inst->prev->is_head_sentinel())<br>
       return false;<br>
<br>
+   /* Check that the FB write sources are fully initialized by the single<br>
+    * texturing instruction.<br>
+    */<br>
+   for (unsigned i = 0; i < FB_WRITE_LOGICAL_NUM_SRCS; i++) {<br>
+      if (i == FB_WRITE_LOGICAL_SRC_COLOR0) {<br>
+         if (!fb_write->src[i].equals(tex_inst->dst) ||<br>
+             fb_write->regs_read(i) != tex_inst->regs_written)<br>
+         return false;<br>
+      } else if (i != FB_WRITE_LOGICAL_SRC_COMPONENTS) {<br>
+         if (fb_write->src[i].file != BAD_FILE)<br>
+            return false;<br>
+      }<br>
+   }<br>
+<br>
    assert(!tex_inst->eot); /* We can't get here twice */<br>
    assert((tex_inst->offset & (0xff << 24)) == 0);<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.7.3<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>