<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 24, 2014 at 9:17 AM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send patches with git-send-email and no other method.  Save this message<br>
and apply it to origin/master using git-am to see why.<br>
<br>
Hopefully Matt or Ken can review this...<br>
<div class=""><br>
On 06/12/2014 12:35 PM, Cody Northrop wrote:<br>
> Commit 17c7ead7 exposed a bug in how uniform loading happens in the<br>
> presence of discard.  It manifested itself in an application as randomly<br>
> incorrect pixels on the borders of conditional areas.<br>
><br>
> We believe it is due to how discards jump to the end of the shader<br>
> incorrectly for some channels.  The current implementation checks each<br>
> 2x2 subspan to preserve derivatives.  When uniform loading via samplers<br>
> was turned on, it uses a full execution mask, as stated in<br>
> lower_uniform_pull_constant_loads(), and only populates four channels of<br>
> the destination (see generate_uniform_pull_constant_load_gen7()).  We<br>
> think that is happening incorrectly when the first subspan has been<br>
> jumped over.<br>
><br>
> A possible fix is to only jump to the end of the shader if all relevant<br>
> channels are disabled, i.e. all 8 or 16, depending on dispatch.  This<br>
> preserves the original speedup noted in commit beafced2.  There are<br>
> other more heavyweight fixes (i.e. don't use sampler for uniforms if<br>
> discard in use), but this seems like a good fix.  I've appended it below<br>
> as a patch.  It changes the shader accordingly:<br>
><br>
> before    : 0x000000d0: (-f0.1.any4h) halt(8) 17 2<br>
> null                            { align1 WE_all 1Q };<br>
> after(8)  : 0x000000d0: (-f0.1.any8h) halt(8) 17 2<br>
> null                            { align1 WE_all 1Q };<br>
> after(16) : 0x00000250: (-f0.1.any16h) halt(16) 17 2<br>
> null                            { align1 WE_all 1H };<br>
<br>
</div>All of this information should go in the commit message.<br></blockquote><div><br></div><div>Will do.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
> I attached a test case to the bugzilla entry below.<br>
<br>
</div>Was the test also sent to the piglit mailing list for inclusion in the<br>
the test suite?<br></blockquote><div><br></div><div>No, it wasn't a full featured test.  I'll invest the time in creating a better example.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class=""><br>
> Thanks for any review or feedback.  Curious if anyone sees a better fix.<br>
><br>
> -C<br>
><br>
><br>
> From 871671c4ab8ff00e85b434865e8855fc356efa8f Mon Sep 17 00:00:00 2001<br>
</div>> From: Cody Northrop <<a href="mailto:cody@lunarg.com">cody@lunarg.com</a> <mailto:<a href="mailto:cody@lunarg.com">cody@lunarg.com</a>>><br>
<div class="">> Date: Thu, 12 Jun 2014 09:07:18 -0600<br>
> Subject: [PATCH] i965/fs: Update discard jump to preserve uniform loads via<br>
>  sampler.<br>
><br>
> The series that implemented this optimization was done before<br>
> the changes to use samplers for uniform loads.  Uniform sampler<br>
> loads use special execution masks and only populate four<br>
> channels, so we can't jump over those or corruption ensues.<br>
> Use a more conservative jump mask which only jumps to the end<br>
> if all relevant channels are disabled.<br>
><br>
> No change was observed in GLbenchmark 2.7, so the optimization<br>
> is preserved.<br>
><br>
</div>> Signed-off-by: Cody Northrop <<a href="mailto:cody@lunarg.com">cody@lunarg.com</a> <mailto:<a href="mailto:cody@lunarg.com">cody@lunarg.com</a>>><br>
> Reviewed-by: Mike Stroyan <<a href="mailto:mike@lunarg.com">mike@lunarg.com</a> <mailto:<a href="mailto:mike@lunarg.com">mike@lunarg.com</a>>><br>
<div><div class="h5">> Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=79948" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=79948</a><br>
> ---<br>
>  src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 10 +++++++++-<br>
>  1 file changed, 9 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> index 8858852..fe05715 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
> @@ -1907,7 +1907,15 @@ fs_visitor::visit(ir_discard *ir)<br>
>         */<br>
>        fs_inst *discard_jump = emit(FS_OPCODE_DISCARD_JUMP);<br>
>        discard_jump->flag_subreg = 1;<br>
> -      discard_jump->predicate = BRW_PREDICATE_ALIGN1_ANY4H;<br>
> +<br>
> +      /* Uniforms are now loaded using samplers with a routine that has<br>
> +       * its own execution mask, so we can only jump if all relevant<br>
> +       * channels are dead.  This is more conservative than the previous<br>
> +       * four channel checking, but still preserves speedups.<br>
> +       */<br>
> +      discard_jump->predicate = (8 == dispatch_width)<br>
> +                                ? BRW_PREDICATE_ALIGN1_ANY8H<br>
> +                                : BRW_PREDICATE_ALIGN1_ANY16H;<br>
>        discard_jump->predicate_inverse = true;<br>
>     }<br>
>  }<br>
> --<br>
> 1.8.3.2<br>
><br>
</div></div>> _______________________________________________<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>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div><font color="#999999"><font face="trebuchet ms, sans-serif"> Cody Northrop<br> Graphics Software Engineer<br> LunarG, Inc.- 3D Driver Innovations</font><font style="font-size:small" face="trebuchet ms, sans-serif"><br>
 Email: <a href="mailto:cody@lunarg.com" target="_blank">cody@lunarg.com</a><br> Website: <a href="http://www.lunarg.com/" target="_blank">http://www.lunarg.com</a></font></font></div></div>
</div></div>