Fix negative shift in bitfieldExtract tests
authorAri Suonpaa <ari.suonpaa@siru.fi>
Mon, 13 Dec 2021 12:10:09 +0000 (14:10 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 6 Jan 2022 22:46:34 +0000 (22:46 +0000)
Reference calculation was using a negative shift when the
number of bits for bitfieldExtract was zero. This is
undefined behavior so now the bits = 0 case is handled
separately.

VK-GL-CTS Issue: 3333

Affects:

dEQP-GLES31.functional.shaders.builtin_functions.integer.bitfieldextract.*

Components: OpenGL ES
Change-Id: I7691962d7ffd8ceed4dc1267d6730f1a6cb3e564

modules/gles31/functional/es31fShaderIntegerFunctionTests.cpp

index 19f44be..1ab5120 100644 (file)
@@ -741,11 +741,21 @@ public:
 
                for (int compNdx = 0; compNdx < scalarSize; compNdx++)
                {
-                       const deUint32  value   = ((const deUint32*)inputs[0])[compNdx];
-                       const deUint32  out             = ((const deUint32*)outputs[0])[compNdx];
-                       const deUint32  valMask = (bits == 32 ? ~0u : ((1u<<bits)-1u));
-                       const deUint32  baseVal = (offset == 32) ? (0) : ((value >> offset) & valMask);
-                       const deUint32  ref             = baseVal | ((isSigned && (baseVal & (1<<(bits-1)))) ? ~valMask : 0u);
+                       const deUint32  out     = ((const deUint32*)outputs[0])[compNdx];
+                       deUint32                ref;
+
+                       // From the bitfieldExtract spec: "If bits is zero, the result will be zero.".
+                       if (bits == 0)
+                       {
+                               ref = 0u;
+                       }
+                       else
+                       {
+                               const deUint32  value   = ((const deUint32*)inputs[0])[compNdx];
+                               const deUint32  valMask = (bits == 32 ? ~0u : ((1u<<bits)-1u));
+                               const deUint32  baseVal = (offset == 32) ? (0) : ((value >> offset) & valMask);
+                               ref = baseVal | ((isSigned && (baseVal & (1 << (bits - 1)))) ? ~valMask : 0u);
+                       }
 
                        if (out != ref)
                        {