Commit 3942f5cb by Antonio Maiorano

Clamp GLES sine/cosine to [-1,1]

Hack for minor precision issues with current implementation. Fixes 8 quality warnings from deqp-gles3 when run against SwiftShaderGL/Subzero. Bug: b/151461290 Change-Id: I4a3148add2c0987dcccca96e7c877ea4fb16ca89 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43470 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent acc90dc1
...@@ -276,6 +276,12 @@ namespace sw ...@@ -276,6 +276,12 @@ namespace sw
return sine_pi(y, pp); return sine_pi(y, pp);
} }
// Assumes x is a finite floating point value
static RValue<Float4> clamp(const Float4 &x, const Float4 &min, const Float4 &max)
{
return Min(Max(x, min), max);
}
Float4 sine(RValue<Float4> x, bool pp) Float4 sine(RValue<Float4> x, bool pp)
{ {
// Reduce to [-0.5, 0.5] range // Reduce to [-0.5, 0.5] range
...@@ -311,6 +317,9 @@ namespace sw ...@@ -311,6 +317,9 @@ namespace sw
sin = sin * (Abs(sin) * D + C); sin = sin * (Abs(sin) * D + C);
} }
// TODO(b/151461290): Fix precision loss instead of clamping.
sin = clamp(sin, Float4(-1.0f), Float4(1.0f));
return sin; return sin;
} }
...@@ -318,7 +327,12 @@ namespace sw ...@@ -318,7 +327,12 @@ namespace sw
{ {
// cos(x) = sin(x + pi/2) // cos(x) = sin(x + pi/2)
Float4 y = x + Float4(1.57079632e+0f); Float4 y = x + Float4(1.57079632e+0f);
return sine(y, pp); auto cos = sine(y, pp);
// TODO(b/151461290): Fix precision loss instead of clamping.
cos = clamp(cos, Float4(-1.0f), Float4(1.0f));
return cos;
} }
Float4 tangent(RValue<Float4> x, bool pp) Float4 tangent(RValue<Float4> x, bool pp)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment