Fix division by zero
authorAri Suonpaa <ari.suonpaa@siru.fi>
Mon, 16 May 2022 12:17:47 +0000 (15:17 +0300)
committerAri Suonpaa <ari.suonpaa@siru.fi>
Mon, 16 May 2022 12:17:47 +0000 (15:17 +0300)
Fixed format threshold calculation caused division by zero
whenever less than four channels were used by the format.
This change uses threshold zero for the empty channels.

VK-GL-CTS Issue: 3332

Affects:

dEQP-GLES31.functional.draw_buffers_indexed.random.max_implementation_draw_buffers.*

Components: OpenGL ES
Change-Id: Ib6c8ee6ee0fa82d1f0514b639938c61ed7762381

modules/gles31/functional/es31fDrawBuffersIndexedTests.cpp

index d190461..a934b5d 100644 (file)
@@ -446,7 +446,19 @@ Vec4 getFixedPointFormatThreshold (const tcu::TextureFormat& sourceFormat, const
        const tcu::IVec4        srcBits         = tcu::getTextureFormatBitDepth(sourceFormat);
        const tcu::IVec4        readBits        = tcu::getTextureFormatBitDepth(readPixelsFormat);
 
-       return Vec4(3.0f) / ((tcu::Vector<deUint64, 4>(1) << (tcu::min(srcBits, readBits).cast<deUint64>())) - tcu::Vector<deUint64, 4>(1)).cast<float>();
+       Vec4                            threshold       = Vec4(0.0f);
+
+       for (int i = 0; i < 4; i++)
+       {
+               const int bits = de::min(srcBits[i], readBits[i]);
+
+               if (bits > 0)
+               {
+                       threshold[i] = 3.0f / static_cast<float>(((1ul << bits) - 1ul));
+               }
+       }
+
+       return threshold;
 }
 
 UVec4 getFloatULPThreshold (const tcu::TextureFormat& sourceFormat, const tcu::TextureFormat& readPixelsFormat)