Improve and fix quad randomization in vertex array test
authorAri Suonpaa <ari.suonpaa@siru.fi>
Fri, 3 Dec 2021 09:21:46 +0000 (11:21 +0200)
committerAri Suonpaa <ari.suonpaa@siru.fi>
Fri, 10 Dec 2021 05:41:49 +0000 (07:41 +0200)
Minimum quad size for fixed point format was larger
than the maximum value range, causing only extremely
large quads to be used. Also the quad randomization
relied on a loop with fixed number of attempts to
produce proper quads. Now the randomization ranges
are selected so that the quads can be accepted without
multiple attempts.

VK-GL-CTS Issue: 3376

Affects:

dEQP-GLES3.functional.vertex_arrays.*

Components: OpenGL ES
Change-Id: I648f2218aa9b661969c7b78c2f81b5e120ae9275

modules/glshared/glsVertexArrayTests.cpp
modules/glshared/glsVertexArrayTests.hpp

index 8cff9f5..75364f0 100644 (file)
@@ -1524,6 +1524,7 @@ char* RandomArrayGenerator::createQuads (int seed, int count, int componentCount
                        const T minDiff         = minValue<T>() > minQuadSize
                                                                ? minValue<T>()
                                                                : minQuadSize;
+                       const T maxRounded      = roundTo(minDiff, max);
 
                        for (int quadNdx = 0; quadNdx < count; ++quadNdx)
                        {
@@ -1531,33 +1532,22 @@ char* RandomArrayGenerator::createQuads (int seed, int count, int componentCount
                                T y1, y2;
                                T z, w;
 
-                               // attempt to find a good (i.e not extremely small) quad
-                               for (int attemptNdx = 0; attemptNdx < 4; ++attemptNdx)
-                               {
-                                       x1 = roundTo(minDiff, getRandom<T>(rnd, min, max - minDiff));
-                                       x2 = roundTo(minDiff, getRandom<T>(rnd, x1 + minDiff, max));
-
-                                       y1 = roundTo(minDiff, getRandom<T>(rnd, min, max - minDiff));
-                                       y2 = roundTo(minDiff, getRandom<T>(rnd, y1 + minDiff, max));
+                               x1 = roundTo(minDiff, getRandom<T>(rnd, min, maxRounded - minDiff));
+                               x2 = roundTo(minDiff, getRandom<T>(rnd, x1 + minDiff, maxRounded));
 
-                                       z = (componentCount > 2) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(0));
-                                       w = (componentCount > 3) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(1));
+                               y1 = roundTo(minDiff, getRandom<T>(rnd, min, maxRounded - minDiff));
+                               y2 = roundTo(minDiff, getRandom<T>(rnd, y1 + minDiff, maxRounded));
 
-                                       // no additional components, all is good
-                                       if (componentCount <= 2)
-                                               break;
+                               // Make sure the rounding doesn't drop the result below the original range of the random function.
+                               if (x2 < x1 + minDiff) x2 = x1 + minDiff;
+                               if (y2 < y1 + minDiff) y2 = y1 + minDiff;
 
-                                       // The result quad is too thin?
-                                       if ((deFloatAbs(x2.template to<float>() - x1.template to<float>()) < minDiff.template to<float>()) ||
-                                               (deFloatAbs(y2.template to<float>() - y1.template to<float>()) < minDiff.template to<float>()))
-                                       {
-                                               DE_ASSERT(attemptNdx < 3);
-                                               continue;
-                                       }
+                               z = (componentCount > 2) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(0));
+                               w = (componentCount > 3) ? roundTo(minDiff, (getRandom<T>(rnd, min, max))) : (T::create(1));
 
-                                       // all ok
-                                       break;
-                               }
+                               // Make sure the quad is not too thin.
+                               DE_ASSERT((deFloatAbs(x2.template to<float>() - x1.template to<float>()) >= minDiff.template to<float>() * 0.8f) &&
+                                       (deFloatAbs(y2.template to<float>() - y1.template to<float>()) >= minDiff.template to<float>() * 0.8f));
 
                                alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride]), x1);
                                alignmentSafeAssignment<T>(&(resultData[quadNdx * quadStride + componentStride]), y1);
index 3fd9fa9..11e1b3a 100644 (file)
@@ -353,7 +353,7 @@ public:
        {
        public:
                static Fixed            create                  (deInt32 value)                         { Fixed v; v.m_value = value; return v; }
-               static Fixed            fromFloat               (float value)                           { Fixed v; v.m_value = (deInt32)(value * 32768.0f); return v; }
+               static Fixed            fromFloat               (float value)                           { Fixed v; v.m_value = (deInt32)value; return v; }
                inline deInt32          getValue                (void) const                            { return m_value; }
 
                inline Fixed            operator+               (const Fixed& other) const      { return create(m_value + other.getValue()); }