[Mesa-dev] [PATCH] i965: Work around SIN/COS output range problem.

Kenneth Graunke kenneth at whitecape.org
Thu Mar 17 18:50:41 UTC 2016


On Thursday, March 17, 2016 6:18:39 PM PDT Martin Peres wrote:
> On 16/03/16 19:33, Kenneth Graunke wrote:
> > The SIN and COS instructions on Intel hardware can produce values
> > slightly outside of the [-1.0, 1.0] range for a small set of values.
> > Obviously, this can break everyone's expectations about trig functions.
> >
> > According to an internal presentation, the COS instruction can produce
> > a value up to 1.000027 for inputs in the range (0.08296, 0.09888).  One
> > suggested workaround is to multiply by 0.99997, scaling down the
> > amplitude slightly.  Apparently this also minimizes the error function,
> > reducing the maximum error from 0.00006 to about 0.00003.
> >
> > I chose to apply this only when not saturating, as saturate already
> > clamps to 1.0.  This may or may not be a good idea.
> >
> > Fixes 16 dEQP precision tests
> >
> >     dEQP-GLES31.functional.shaders.builtin_functions.precision.
> >     {cos,sin}.{highp,mediump}_compute.{scalar,vec2,vec4,vec4}.
> >
> > at the cost of making every sin and cos call more expensive.
> >
> > Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> > ---
> >   src/mesa/drivers/dri/i965/brw_fs_nir.cpp   | 26 +++++++++++++++++++
+------
> >   src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 26 +++++++++++++++++++
+------
> >   2 files changed, 40 insertions(+), 12 deletions(-)
> >
> > This has been in the Vulkan tree for a while - we needed it to pass the
> > Vulkan CTS, as it contains these same dEQP tests.
> >
> > I haven't run shader-db yet, but I don't expect we'll like the results.
> >
> > The patch is pretty sketchy, too.  I'm sort of tempted to hide it behind
> > an INTEL_STRICT_CONFORMANCE=1 option, like we had way back in the day...
> 
> FYI, a quick run on hsw_gt2 shows -10.45% on Gputest:voplosion.

Thanks!  It sounds like we probably should hide this behind some kind of
INTEL_STRICT_CONFORMANCE option or build time flag.  sin and cos are
really common, and making them cost effectively twice as much is really
painful.

I'll come up with a v2 at some point, let's NAK this for now.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160317/b78a0bb3/attachment.sig>


More information about the mesa-dev mailing list