Fix gles3 transform feedback uint cases always using zeroed buffers.
authorJarkko Pöyry <jpoyry@google.com>
Thu, 12 Mar 2015 00:30:45 +0000 (17:30 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Thu, 12 Mar 2015 00:32:19 +0000 (17:32 -0700)
- Generate random values for uint cases.
- Do not rely on implementation-specific behavior on int cases.

Bug: 19699456
Change-Id: I66afa29731215636b240b856f3d416b9700c3b75

modules/gles3/functional/es3fTransformFeedbackTests.cpp

index 9967e4e..6ddd9c8 100644 (file)
@@ -520,14 +520,25 @@ static void computeTransformFeedbackOutputs (vector<Output>& transformFeedbackOu
        }
 }
 
+static deUint32 signExtend (deUint32 value, deUint32 numBits)
+{
+       DE_ASSERT(numBits >= 1u && numBits <= 32u);
+       if (numBits == 32u)
+               return value;
+       else if ((value & (1u << (numBits-1u))) == 0u)
+               return value;
+       else
+               return value | ~((1u << numBits) - 1u);
+}
+
 static void genAttributeData (const Attribute& attrib, deUint8* basePtr, int stride, int numElements, de::Random& rnd)
 {
-       const int               elementSize     = (int)sizeof(deUint32);
-       bool                    isFloat         = glu::isDataTypeFloatOrVec(attrib.type.getBasicType());
-       bool                    isInt           = glu::isDataTypeIntOrIVec(attrib.type.getBasicType());
-       bool                    isUint          = glu::isDataTypeIntOrIVec(attrib.type.getBasicType());
-       glu::Precision  precision       = attrib.type.getPrecision();
-       int                             numComps        = glu::getDataTypeScalarSize(attrib.type.getBasicType());
+       const int                               elementSize     = (int)sizeof(deUint32);
+       const bool                              isFloat         = glu::isDataTypeFloatOrVec(attrib.type.getBasicType());
+       const bool                              isInt           = glu::isDataTypeIntOrIVec(attrib.type.getBasicType());
+       const bool                              isUint          = glu::isDataTypeUintOrUVec(attrib.type.getBasicType());
+       const glu::Precision    precision       = attrib.type.getPrecision();
+       const int                               numComps        = glu::getDataTypeScalarSize(attrib.type.getBasicType());
 
        for (int elemNdx = 0; elemNdx < numElements; elemNdx++)
        {
@@ -551,9 +562,9 @@ static void genAttributeData (const Attribute& attrib, deUint8* basePtr, int str
                                int* comp = (int*)(basePtr+offset);
                                switch (precision)
                                {
-                                       case glu::PRECISION_LOWP:               *comp = (int)(rnd.getUint32()&0xff) << 24 >> 24;        break;
-                                       case glu::PRECISION_MEDIUMP:    *comp = (int)(rnd.getUint32()&0xffff) << 16 >> 16;      break;
-                                       case glu::PRECISION_HIGHP:              *comp = (int)rnd.getUint32();                                           break;
+                                       case glu::PRECISION_LOWP:               *comp = (int)signExtend(rnd.getUint32()&0xff, 8);               break;
+                                       case glu::PRECISION_MEDIUMP:    *comp = (int)signExtend(rnd.getUint32()&0xffff, 16);    break;
+                                       case glu::PRECISION_HIGHP:              *comp = (int)rnd.getUint32();                                                   break;
                                        default:
                                                DE_ASSERT(false);
                                }
@@ -570,6 +581,8 @@ static void genAttributeData (const Attribute& attrib, deUint8* basePtr, int str
                                                DE_ASSERT(false);
                                }
                        }
+                       else
+                               DE_ASSERT(false);
                }
        }
 }