Fix division by zero in glsBuiltinPrecisionTests
authorAntto Mäkinen <antto.makinen@siru.fi>
Fri, 17 Jun 2022 10:52:15 +0000 (13:52 +0300)
committerziga-lunarg <ziga@lunarg.com>
Wed, 24 Aug 2022 20:05:31 +0000 (22:05 +0200)
GLSL precision tests were using 1 / InverseSqrt(x) to calculate
reference values for square root. This is problematic when x = 0,
as it causes a division by zero.

VK-GL-CTS Issue: 3330

Affects:

dEQP-GLES3*.functional.shaders.builtin_functions.precision.*

Components: OpenGL ES
Change-Id: I199f16b2eeb66ab042f0bb1ab6b588246efeb6d5

modules/glshared/glsBuiltinPrecisionTests.cpp

index 2af7126..98564dc 100644 (file)
@@ -2276,7 +2276,7 @@ ExprP<TRET> NAME (const ExprP<T0>& arg0, const ExprP<T1>& arg1,                   \
        return app<CLASS>(arg0, arg1, arg2, arg3);                                                      \
 }
 
-DEFINE_DERIVED_FLOAT1(Sqrt,            sqrt,           x,              constant(1.0f) / app<InverseSqrt>(x));
+DEFINE_DERIVED_FLOAT1(Sqrt,            sqrt,           x,              (x == 0.0f ? constant(1.0f) : (constant(1.0f) / app<InverseSqrt>(x))));
 DEFINE_DERIVED_FLOAT2(Pow,             pow,            x,      y,      exp2(y * log2(x)));
 DEFINE_DERIVED_FLOAT1(Radians, radians,        d,              (constant(DE_PI) / constant(180.0f)) * d);
 DEFINE_DERIVED_FLOAT1(Degrees, degrees,        r,              (constant(180.0f) / constant(DE_PI)) * r);