1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 2.0 Module
3*35238bceSAndroid Build Coastguard Worker * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Uniform API tests.
22*35238bceSAndroid Build Coastguard Worker *
23*35238bceSAndroid Build Coastguard Worker * \todo [2013-02-26 nuutti] Much duplication between this and ES3.
24*35238bceSAndroid Build Coastguard Worker * Utilities to glshared?
25*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
26*35238bceSAndroid Build Coastguard Worker
27*35238bceSAndroid Build Coastguard Worker #include "es2fUniformApiTests.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluCallLogWrapper.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "gluVarType.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "tcuCommandLine.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "deSharedPtr.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "deString.h"
42*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
43*35238bceSAndroid Build Coastguard Worker
44*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
45*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
46*35238bceSAndroid Build Coastguard Worker
47*35238bceSAndroid Build Coastguard Worker #include <set>
48*35238bceSAndroid Build Coastguard Worker #include <cstring>
49*35238bceSAndroid Build Coastguard Worker
50*35238bceSAndroid Build Coastguard Worker using namespace glw;
51*35238bceSAndroid Build Coastguard Worker
52*35238bceSAndroid Build Coastguard Worker namespace deqp
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker namespace gles2
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker namespace Functional
57*35238bceSAndroid Build Coastguard Worker {
58*35238bceSAndroid Build Coastguard Worker
59*35238bceSAndroid Build Coastguard Worker using de::Random;
60*35238bceSAndroid Build Coastguard Worker using de::SharedPtr;
61*35238bceSAndroid Build Coastguard Worker using glu::ShaderProgram;
62*35238bceSAndroid Build Coastguard Worker using glu::StructType;
63*35238bceSAndroid Build Coastguard Worker using std::string;
64*35238bceSAndroid Build Coastguard Worker using std::vector;
65*35238bceSAndroid Build Coastguard Worker using tcu::ScopedLogSection;
66*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
67*35238bceSAndroid Build Coastguard Worker
68*35238bceSAndroid Build Coastguard Worker typedef bool (*dataTypePredicate)(glu::DataType);
69*35238bceSAndroid Build Coastguard Worker
70*35238bceSAndroid Build Coastguard Worker static const int MAX_RENDER_WIDTH = 32;
71*35238bceSAndroid Build Coastguard Worker static const int MAX_RENDER_HEIGHT = 32;
72*35238bceSAndroid Build Coastguard Worker static const int MAX_NUM_SAMPLER_UNIFORMS = 16;
73*35238bceSAndroid Build Coastguard Worker
74*35238bceSAndroid Build Coastguard Worker static const glu::DataType s_testDataTypes[] = {
75*35238bceSAndroid Build Coastguard Worker glu::TYPE_FLOAT, glu::TYPE_FLOAT_VEC2, glu::TYPE_FLOAT_VEC3, glu::TYPE_FLOAT_VEC4,
76*35238bceSAndroid Build Coastguard Worker glu::TYPE_FLOAT_MAT2, glu::TYPE_FLOAT_MAT3, glu::TYPE_FLOAT_MAT4,
77*35238bceSAndroid Build Coastguard Worker
78*35238bceSAndroid Build Coastguard Worker glu::TYPE_INT, glu::TYPE_INT_VEC2, glu::TYPE_INT_VEC3, glu::TYPE_INT_VEC4,
79*35238bceSAndroid Build Coastguard Worker
80*35238bceSAndroid Build Coastguard Worker glu::TYPE_BOOL, glu::TYPE_BOOL_VEC2, glu::TYPE_BOOL_VEC3, glu::TYPE_BOOL_VEC4,
81*35238bceSAndroid Build Coastguard Worker
82*35238bceSAndroid Build Coastguard Worker glu::TYPE_SAMPLER_2D, glu::TYPE_SAMPLER_CUBE};
83*35238bceSAndroid Build Coastguard Worker
getGLInt(const glw::Functions & funcs,const uint32_t name)84*35238bceSAndroid Build Coastguard Worker static inline int getGLInt(const glw::Functions &funcs, const uint32_t name)
85*35238bceSAndroid Build Coastguard Worker {
86*35238bceSAndroid Build Coastguard Worker int val = -1;
87*35238bceSAndroid Build Coastguard Worker funcs.getIntegerv(name, &val);
88*35238bceSAndroid Build Coastguard Worker return val;
89*35238bceSAndroid Build Coastguard Worker }
90*35238bceSAndroid Build Coastguard Worker
vec4FromPtr(const float * const ptr)91*35238bceSAndroid Build Coastguard Worker static inline tcu::Vec4 vec4FromPtr(const float *const ptr)
92*35238bceSAndroid Build Coastguard Worker {
93*35238bceSAndroid Build Coastguard Worker tcu::Vec4 result;
94*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++)
95*35238bceSAndroid Build Coastguard Worker result[i] = ptr[i];
96*35238bceSAndroid Build Coastguard Worker return result;
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker
beforeLast(const string & str,const char c)99*35238bceSAndroid Build Coastguard Worker static inline string beforeLast(const string &str, const char c)
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker return str.substr(0, str.find_last_of(c));
102*35238bceSAndroid Build Coastguard Worker }
103*35238bceSAndroid Build Coastguard Worker
fillWithColor(const tcu::PixelBufferAccess & access,const tcu::Vec4 & color)104*35238bceSAndroid Build Coastguard Worker static inline void fillWithColor(const tcu::PixelBufferAccess &access, const tcu::Vec4 &color)
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker for (int z = 0; z < access.getDepth(); z++)
107*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < access.getHeight(); y++)
108*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < access.getWidth(); x++)
109*35238bceSAndroid Build Coastguard Worker access.setPixel(color, x, y, z);
110*35238bceSAndroid Build Coastguard Worker }
111*35238bceSAndroid Build Coastguard Worker
getSamplerNumLookupDimensions(const glu::DataType type)112*35238bceSAndroid Build Coastguard Worker static inline int getSamplerNumLookupDimensions(const glu::DataType type)
113*35238bceSAndroid Build Coastguard Worker {
114*35238bceSAndroid Build Coastguard Worker switch (type)
115*35238bceSAndroid Build Coastguard Worker {
116*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_2D:
117*35238bceSAndroid Build Coastguard Worker return 2;
118*35238bceSAndroid Build Coastguard Worker
119*35238bceSAndroid Build Coastguard Worker case glu::TYPE_SAMPLER_CUBE:
120*35238bceSAndroid Build Coastguard Worker return 3;
121*35238bceSAndroid Build Coastguard Worker
122*35238bceSAndroid Build Coastguard Worker default: // \note All others than 2d and cube are gles3-only types.
123*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
124*35238bceSAndroid Build Coastguard Worker return 0;
125*35238bceSAndroid Build Coastguard Worker }
126*35238bceSAndroid Build Coastguard Worker }
127*35238bceSAndroid Build Coastguard Worker
128*35238bceSAndroid Build Coastguard Worker template <glu::DataType T>
dataTypeEquals(const glu::DataType t)129*35238bceSAndroid Build Coastguard Worker static bool dataTypeEquals(const glu::DataType t)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker return t == T;
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker
134*35238bceSAndroid Build Coastguard Worker template <int N>
dataTypeIsMatrixWithNRows(const glu::DataType t)135*35238bceSAndroid Build Coastguard Worker static bool dataTypeIsMatrixWithNRows(const glu::DataType t)
136*35238bceSAndroid Build Coastguard Worker {
137*35238bceSAndroid Build Coastguard Worker return glu::isDataTypeMatrix(t) && glu::getDataTypeMatrixNumRows(t) == N;
138*35238bceSAndroid Build Coastguard Worker }
139*35238bceSAndroid Build Coastguard Worker
typeContainsMatchingBasicType(const glu::VarType & type,const dataTypePredicate predicate)140*35238bceSAndroid Build Coastguard Worker static bool typeContainsMatchingBasicType(const glu::VarType &type, const dataTypePredicate predicate)
141*35238bceSAndroid Build Coastguard Worker {
142*35238bceSAndroid Build Coastguard Worker if (type.isBasicType())
143*35238bceSAndroid Build Coastguard Worker return predicate(type.getBasicType());
144*35238bceSAndroid Build Coastguard Worker else if (type.isArrayType())
145*35238bceSAndroid Build Coastguard Worker return typeContainsMatchingBasicType(type.getElementType(), predicate);
146*35238bceSAndroid Build Coastguard Worker else
147*35238bceSAndroid Build Coastguard Worker {
148*35238bceSAndroid Build Coastguard Worker DE_ASSERT(type.isStructType());
149*35238bceSAndroid Build Coastguard Worker const StructType &structType = *type.getStructPtr();
150*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < structType.getNumMembers(); i++)
151*35238bceSAndroid Build Coastguard Worker if (typeContainsMatchingBasicType(structType.getMember(i).getType(), predicate))
152*35238bceSAndroid Build Coastguard Worker return true;
153*35238bceSAndroid Build Coastguard Worker return false;
154*35238bceSAndroid Build Coastguard Worker }
155*35238bceSAndroid Build Coastguard Worker }
156*35238bceSAndroid Build Coastguard Worker
getDistinctSamplerTypes(vector<glu::DataType> & dst,const glu::VarType & type)157*35238bceSAndroid Build Coastguard Worker static void getDistinctSamplerTypes(vector<glu::DataType> &dst, const glu::VarType &type)
158*35238bceSAndroid Build Coastguard Worker {
159*35238bceSAndroid Build Coastguard Worker if (type.isBasicType())
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker const glu::DataType basicType = type.getBasicType();
162*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeSampler(basicType) && std::find(dst.begin(), dst.end(), basicType) == dst.end())
163*35238bceSAndroid Build Coastguard Worker dst.push_back(basicType);
164*35238bceSAndroid Build Coastguard Worker }
165*35238bceSAndroid Build Coastguard Worker else if (type.isArrayType())
166*35238bceSAndroid Build Coastguard Worker getDistinctSamplerTypes(dst, type.getElementType());
167*35238bceSAndroid Build Coastguard Worker else
168*35238bceSAndroid Build Coastguard Worker {
169*35238bceSAndroid Build Coastguard Worker DE_ASSERT(type.isStructType());
170*35238bceSAndroid Build Coastguard Worker const StructType &structType = *type.getStructPtr();
171*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < structType.getNumMembers(); i++)
172*35238bceSAndroid Build Coastguard Worker getDistinctSamplerTypes(dst, structType.getMember(i).getType());
173*35238bceSAndroid Build Coastguard Worker }
174*35238bceSAndroid Build Coastguard Worker }
175*35238bceSAndroid Build Coastguard Worker
getNumSamplersInType(const glu::VarType & type)176*35238bceSAndroid Build Coastguard Worker static int getNumSamplersInType(const glu::VarType &type)
177*35238bceSAndroid Build Coastguard Worker {
178*35238bceSAndroid Build Coastguard Worker if (type.isBasicType())
179*35238bceSAndroid Build Coastguard Worker return glu::isDataTypeSampler(type.getBasicType()) ? 1 : 0;
180*35238bceSAndroid Build Coastguard Worker else if (type.isArrayType())
181*35238bceSAndroid Build Coastguard Worker return getNumSamplersInType(type.getElementType()) * type.getArraySize();
182*35238bceSAndroid Build Coastguard Worker else
183*35238bceSAndroid Build Coastguard Worker {
184*35238bceSAndroid Build Coastguard Worker DE_ASSERT(type.isStructType());
185*35238bceSAndroid Build Coastguard Worker const StructType &structType = *type.getStructPtr();
186*35238bceSAndroid Build Coastguard Worker int sum = 0;
187*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < structType.getNumMembers(); i++)
188*35238bceSAndroid Build Coastguard Worker sum += getNumSamplersInType(structType.getMember(i).getType());
189*35238bceSAndroid Build Coastguard Worker return sum;
190*35238bceSAndroid Build Coastguard Worker }
191*35238bceSAndroid Build Coastguard Worker }
192*35238bceSAndroid Build Coastguard Worker
generateRandomType(const int maxDepth,int & curStructIdx,vector<const StructType * > & structTypesDst,Random & rnd)193*35238bceSAndroid Build Coastguard Worker static glu::VarType generateRandomType(const int maxDepth, int &curStructIdx,
194*35238bceSAndroid Build Coastguard Worker vector<const StructType *> &structTypesDst, Random &rnd)
195*35238bceSAndroid Build Coastguard Worker {
196*35238bceSAndroid Build Coastguard Worker const bool isStruct = maxDepth > 0 && rnd.getFloat() < 0.2f;
197*35238bceSAndroid Build Coastguard Worker const bool isArray = rnd.getFloat() < 0.3f;
198*35238bceSAndroid Build Coastguard Worker
199*35238bceSAndroid Build Coastguard Worker if (isStruct)
200*35238bceSAndroid Build Coastguard Worker {
201*35238bceSAndroid Build Coastguard Worker const int numMembers = rnd.getInt(1, 5);
202*35238bceSAndroid Build Coastguard Worker StructType *const structType = new StructType(("structType" + de::toString(curStructIdx++)).c_str());
203*35238bceSAndroid Build Coastguard Worker
204*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numMembers; i++)
205*35238bceSAndroid Build Coastguard Worker structType->addMember(("m" + de::toString(i)).c_str(),
206*35238bceSAndroid Build Coastguard Worker generateRandomType(maxDepth - 1, curStructIdx, structTypesDst, rnd));
207*35238bceSAndroid Build Coastguard Worker
208*35238bceSAndroid Build Coastguard Worker structTypesDst.push_back(structType);
209*35238bceSAndroid Build Coastguard Worker return isArray ? glu::VarType(glu::VarType(structType), rnd.getInt(1, 5)) : glu::VarType(structType);
210*35238bceSAndroid Build Coastguard Worker }
211*35238bceSAndroid Build Coastguard Worker else
212*35238bceSAndroid Build Coastguard Worker {
213*35238bceSAndroid Build Coastguard Worker const glu::DataType basicType =
214*35238bceSAndroid Build Coastguard Worker (glu::DataType)s_testDataTypes[rnd.getInt(0, DE_LENGTH_OF_ARRAY(s_testDataTypes) - 1)];
215*35238bceSAndroid Build Coastguard Worker const glu::Precision precision =
216*35238bceSAndroid Build Coastguard Worker glu::isDataTypeBoolOrBVec(basicType) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
217*35238bceSAndroid Build Coastguard Worker return isArray ? glu::VarType(glu::VarType(basicType, precision), rnd.getInt(1, 5)) :
218*35238bceSAndroid Build Coastguard Worker glu::VarType(basicType, precision);
219*35238bceSAndroid Build Coastguard Worker }
220*35238bceSAndroid Build Coastguard Worker }
221*35238bceSAndroid Build Coastguard Worker
222*35238bceSAndroid Build Coastguard Worker namespace
223*35238bceSAndroid Build Coastguard Worker {
224*35238bceSAndroid Build Coastguard Worker
225*35238bceSAndroid Build Coastguard Worker struct VarValue
226*35238bceSAndroid Build Coastguard Worker {
227*35238bceSAndroid Build Coastguard Worker glu::DataType type;
228*35238bceSAndroid Build Coastguard Worker
229*35238bceSAndroid Build Coastguard Worker union
230*35238bceSAndroid Build Coastguard Worker {
231*35238bceSAndroid Build Coastguard Worker float floatV[4 * 4]; // At most mat4. \note Matrices here are column-major.
232*35238bceSAndroid Build Coastguard Worker int32_t intV[4];
233*35238bceSAndroid Build Coastguard Worker bool boolV[4];
234*35238bceSAndroid Build Coastguard Worker struct
235*35238bceSAndroid Build Coastguard Worker {
236*35238bceSAndroid Build Coastguard Worker int unit;
237*35238bceSAndroid Build Coastguard Worker float fillColor[4];
238*35238bceSAndroid Build Coastguard Worker } samplerV;
239*35238bceSAndroid Build Coastguard Worker } val;
240*35238bceSAndroid Build Coastguard Worker };
241*35238bceSAndroid Build Coastguard Worker
242*35238bceSAndroid Build Coastguard Worker enum CaseShaderType
243*35238bceSAndroid Build Coastguard Worker {
244*35238bceSAndroid Build Coastguard Worker CASESHADERTYPE_VERTEX = 0,
245*35238bceSAndroid Build Coastguard Worker CASESHADERTYPE_FRAGMENT,
246*35238bceSAndroid Build Coastguard Worker CASESHADERTYPE_BOTH,
247*35238bceSAndroid Build Coastguard Worker
248*35238bceSAndroid Build Coastguard Worker CASESHADERTYPE_LAST
249*35238bceSAndroid Build Coastguard Worker };
250*35238bceSAndroid Build Coastguard Worker
251*35238bceSAndroid Build Coastguard Worker struct Uniform
252*35238bceSAndroid Build Coastguard Worker {
253*35238bceSAndroid Build Coastguard Worker string name;
254*35238bceSAndroid Build Coastguard Worker glu::VarType type;
255*35238bceSAndroid Build Coastguard Worker
Uniformdeqp::gles2::Functional::__anon88939a840111::Uniform256*35238bceSAndroid Build Coastguard Worker Uniform(const char *const name_, const glu::VarType &type_) : name(name_), type(type_)
257*35238bceSAndroid Build Coastguard Worker {
258*35238bceSAndroid Build Coastguard Worker }
259*35238bceSAndroid Build Coastguard Worker };
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker // A set of uniforms, along with related struct types.
262*35238bceSAndroid Build Coastguard Worker class UniformCollection
263*35238bceSAndroid Build Coastguard Worker {
264*35238bceSAndroid Build Coastguard Worker public:
getNumUniforms(void) const265*35238bceSAndroid Build Coastguard Worker int getNumUniforms(void) const
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker return (int)m_uniforms.size();
268*35238bceSAndroid Build Coastguard Worker }
getNumStructTypes(void) const269*35238bceSAndroid Build Coastguard Worker int getNumStructTypes(void) const
270*35238bceSAndroid Build Coastguard Worker {
271*35238bceSAndroid Build Coastguard Worker return (int)m_structTypes.size();
272*35238bceSAndroid Build Coastguard Worker }
getUniform(const int ndx)273*35238bceSAndroid Build Coastguard Worker Uniform &getUniform(const int ndx)
274*35238bceSAndroid Build Coastguard Worker {
275*35238bceSAndroid Build Coastguard Worker return m_uniforms[ndx];
276*35238bceSAndroid Build Coastguard Worker }
getUniform(const int ndx) const277*35238bceSAndroid Build Coastguard Worker const Uniform &getUniform(const int ndx) const
278*35238bceSAndroid Build Coastguard Worker {
279*35238bceSAndroid Build Coastguard Worker return m_uniforms[ndx];
280*35238bceSAndroid Build Coastguard Worker }
getStructType(const int ndx) const281*35238bceSAndroid Build Coastguard Worker const StructType *getStructType(const int ndx) const
282*35238bceSAndroid Build Coastguard Worker {
283*35238bceSAndroid Build Coastguard Worker return m_structTypes[ndx];
284*35238bceSAndroid Build Coastguard Worker }
addUniform(const Uniform & uniform)285*35238bceSAndroid Build Coastguard Worker void addUniform(const Uniform &uniform)
286*35238bceSAndroid Build Coastguard Worker {
287*35238bceSAndroid Build Coastguard Worker m_uniforms.push_back(uniform);
288*35238bceSAndroid Build Coastguard Worker }
addStructType(const StructType * const type)289*35238bceSAndroid Build Coastguard Worker void addStructType(const StructType *const type)
290*35238bceSAndroid Build Coastguard Worker {
291*35238bceSAndroid Build Coastguard Worker m_structTypes.push_back(type);
292*35238bceSAndroid Build Coastguard Worker }
293*35238bceSAndroid Build Coastguard Worker
UniformCollection(void)294*35238bceSAndroid Build Coastguard Worker UniformCollection(void)
295*35238bceSAndroid Build Coastguard Worker {
296*35238bceSAndroid Build Coastguard Worker }
~UniformCollection(void)297*35238bceSAndroid Build Coastguard Worker ~UniformCollection(void)
298*35238bceSAndroid Build Coastguard Worker {
299*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_structTypes.size(); i++)
300*35238bceSAndroid Build Coastguard Worker delete m_structTypes[i];
301*35238bceSAndroid Build Coastguard Worker }
302*35238bceSAndroid Build Coastguard Worker
303*35238bceSAndroid Build Coastguard Worker // Add the contents of m_uniforms and m_structTypes to receiver, and remove them from this one.
304*35238bceSAndroid Build Coastguard Worker // \note receiver takes ownership of the struct types.
moveContents(UniformCollection & receiver)305*35238bceSAndroid Build Coastguard Worker void moveContents(UniformCollection &receiver)
306*35238bceSAndroid Build Coastguard Worker {
307*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniforms.size(); i++)
308*35238bceSAndroid Build Coastguard Worker receiver.addUniform(m_uniforms[i]);
309*35238bceSAndroid Build Coastguard Worker m_uniforms.clear();
310*35238bceSAndroid Build Coastguard Worker
311*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_structTypes.size(); i++)
312*35238bceSAndroid Build Coastguard Worker receiver.addStructType(m_structTypes[i]);
313*35238bceSAndroid Build Coastguard Worker m_structTypes.clear();
314*35238bceSAndroid Build Coastguard Worker }
315*35238bceSAndroid Build Coastguard Worker
containsMatchingBasicType(const dataTypePredicate predicate) const316*35238bceSAndroid Build Coastguard Worker bool containsMatchingBasicType(const dataTypePredicate predicate) const
317*35238bceSAndroid Build Coastguard Worker {
318*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniforms.size(); i++)
319*35238bceSAndroid Build Coastguard Worker if (typeContainsMatchingBasicType(m_uniforms[i].type, predicate))
320*35238bceSAndroid Build Coastguard Worker return true;
321*35238bceSAndroid Build Coastguard Worker return false;
322*35238bceSAndroid Build Coastguard Worker }
323*35238bceSAndroid Build Coastguard Worker
getSamplerTypes(void) const324*35238bceSAndroid Build Coastguard Worker vector<glu::DataType> getSamplerTypes(void) const
325*35238bceSAndroid Build Coastguard Worker {
326*35238bceSAndroid Build Coastguard Worker vector<glu::DataType> samplerTypes;
327*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniforms.size(); i++)
328*35238bceSAndroid Build Coastguard Worker getDistinctSamplerTypes(samplerTypes, m_uniforms[i].type);
329*35238bceSAndroid Build Coastguard Worker return samplerTypes;
330*35238bceSAndroid Build Coastguard Worker }
331*35238bceSAndroid Build Coastguard Worker
containsSeveralSamplerTypes(void) const332*35238bceSAndroid Build Coastguard Worker bool containsSeveralSamplerTypes(void) const
333*35238bceSAndroid Build Coastguard Worker {
334*35238bceSAndroid Build Coastguard Worker return getSamplerTypes().size() > 1;
335*35238bceSAndroid Build Coastguard Worker }
336*35238bceSAndroid Build Coastguard Worker
getNumSamplers(void) const337*35238bceSAndroid Build Coastguard Worker int getNumSamplers(void) const
338*35238bceSAndroid Build Coastguard Worker {
339*35238bceSAndroid Build Coastguard Worker int sum = 0;
340*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniforms.size(); i++)
341*35238bceSAndroid Build Coastguard Worker sum += getNumSamplersInType(m_uniforms[i].type);
342*35238bceSAndroid Build Coastguard Worker return sum;
343*35238bceSAndroid Build Coastguard Worker }
344*35238bceSAndroid Build Coastguard Worker
basic(const glu::DataType type,const char * const nameSuffix="")345*35238bceSAndroid Build Coastguard Worker static UniformCollection *basic(const glu::DataType type, const char *const nameSuffix = "")
346*35238bceSAndroid Build Coastguard Worker {
347*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
348*35238bceSAndroid Build Coastguard Worker const glu::Precision prec = glu::isDataTypeBoolOrBVec(type) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
349*35238bceSAndroid Build Coastguard Worker res->m_uniforms.push_back(Uniform((string("u_var") + nameSuffix).c_str(), glu::VarType(type, prec)));
350*35238bceSAndroid Build Coastguard Worker return res;
351*35238bceSAndroid Build Coastguard Worker }
352*35238bceSAndroid Build Coastguard Worker
basicArray(const glu::DataType type,const char * const nameSuffix="")353*35238bceSAndroid Build Coastguard Worker static UniformCollection *basicArray(const glu::DataType type, const char *const nameSuffix = "")
354*35238bceSAndroid Build Coastguard Worker {
355*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
356*35238bceSAndroid Build Coastguard Worker const glu::Precision prec = glu::isDataTypeBoolOrBVec(type) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
357*35238bceSAndroid Build Coastguard Worker res->m_uniforms.push_back(
358*35238bceSAndroid Build Coastguard Worker Uniform((string("u_var") + nameSuffix).c_str(), glu::VarType(glu::VarType(type, prec), 3)));
359*35238bceSAndroid Build Coastguard Worker return res;
360*35238bceSAndroid Build Coastguard Worker }
361*35238bceSAndroid Build Coastguard Worker
basicStruct(const glu::DataType type0,const glu::DataType type1,const bool containsArrays,const char * const nameSuffix="")362*35238bceSAndroid Build Coastguard Worker static UniformCollection *basicStruct(const glu::DataType type0, const glu::DataType type1,
363*35238bceSAndroid Build Coastguard Worker const bool containsArrays, const char *const nameSuffix = "")
364*35238bceSAndroid Build Coastguard Worker {
365*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
366*35238bceSAndroid Build Coastguard Worker const glu::Precision prec0 = glu::isDataTypeBoolOrBVec(type0) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
367*35238bceSAndroid Build Coastguard Worker const glu::Precision prec1 = glu::isDataTypeBoolOrBVec(type1) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
368*35238bceSAndroid Build Coastguard Worker
369*35238bceSAndroid Build Coastguard Worker StructType *const structType = new StructType((string("structType") + nameSuffix).c_str());
370*35238bceSAndroid Build Coastguard Worker structType->addMember("m0", glu::VarType(type0, prec0));
371*35238bceSAndroid Build Coastguard Worker structType->addMember("m1", glu::VarType(type1, prec1));
372*35238bceSAndroid Build Coastguard Worker if (containsArrays)
373*35238bceSAndroid Build Coastguard Worker {
374*35238bceSAndroid Build Coastguard Worker structType->addMember("m2", glu::VarType(glu::VarType(type0, prec0), 3));
375*35238bceSAndroid Build Coastguard Worker structType->addMember("m3", glu::VarType(glu::VarType(type1, prec1), 3));
376*35238bceSAndroid Build Coastguard Worker }
377*35238bceSAndroid Build Coastguard Worker
378*35238bceSAndroid Build Coastguard Worker res->addStructType(structType);
379*35238bceSAndroid Build Coastguard Worker res->addUniform(Uniform((string("u_var") + nameSuffix).c_str(), glu::VarType(structType)));
380*35238bceSAndroid Build Coastguard Worker
381*35238bceSAndroid Build Coastguard Worker return res;
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker
structInArray(const glu::DataType type0,const glu::DataType type1,const bool containsArrays,const char * const nameSuffix="")384*35238bceSAndroid Build Coastguard Worker static UniformCollection *structInArray(const glu::DataType type0, const glu::DataType type1,
385*35238bceSAndroid Build Coastguard Worker const bool containsArrays, const char *const nameSuffix = "")
386*35238bceSAndroid Build Coastguard Worker {
387*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = basicStruct(type0, type1, containsArrays, nameSuffix);
388*35238bceSAndroid Build Coastguard Worker res->getUniform(0).type = glu::VarType(res->getUniform(0).type, 3);
389*35238bceSAndroid Build Coastguard Worker return res;
390*35238bceSAndroid Build Coastguard Worker }
391*35238bceSAndroid Build Coastguard Worker
nestedArraysStructs(const glu::DataType type0,const glu::DataType type1,const char * const nameSuffix="")392*35238bceSAndroid Build Coastguard Worker static UniformCollection *nestedArraysStructs(const glu::DataType type0, const glu::DataType type1,
393*35238bceSAndroid Build Coastguard Worker const char *const nameSuffix = "")
394*35238bceSAndroid Build Coastguard Worker {
395*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
396*35238bceSAndroid Build Coastguard Worker const glu::Precision prec0 = glu::isDataTypeBoolOrBVec(type0) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
397*35238bceSAndroid Build Coastguard Worker const glu::Precision prec1 = glu::isDataTypeBoolOrBVec(type1) ? glu::PRECISION_LAST : glu::PRECISION_MEDIUMP;
398*35238bceSAndroid Build Coastguard Worker StructType *const structType = new StructType((string("structType") + nameSuffix).c_str());
399*35238bceSAndroid Build Coastguard Worker StructType *const subStructType = new StructType((string("subStructType") + nameSuffix).c_str());
400*35238bceSAndroid Build Coastguard Worker StructType *const subSubStructType = new StructType((string("subSubStructType") + nameSuffix).c_str());
401*35238bceSAndroid Build Coastguard Worker
402*35238bceSAndroid Build Coastguard Worker subSubStructType->addMember("mss0", glu::VarType(type0, prec0));
403*35238bceSAndroid Build Coastguard Worker subSubStructType->addMember("mss1", glu::VarType(type1, prec1));
404*35238bceSAndroid Build Coastguard Worker
405*35238bceSAndroid Build Coastguard Worker subStructType->addMember("ms0", glu::VarType(type1, prec1));
406*35238bceSAndroid Build Coastguard Worker subStructType->addMember("ms1", glu::VarType(glu::VarType(type0, prec0), 2));
407*35238bceSAndroid Build Coastguard Worker subStructType->addMember("ms2", glu::VarType(glu::VarType(subSubStructType), 2));
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker structType->addMember("m0", glu::VarType(type0, prec0));
410*35238bceSAndroid Build Coastguard Worker structType->addMember("m1", glu::VarType(subStructType));
411*35238bceSAndroid Build Coastguard Worker structType->addMember("m2", glu::VarType(type1, prec1));
412*35238bceSAndroid Build Coastguard Worker
413*35238bceSAndroid Build Coastguard Worker res->addStructType(subSubStructType);
414*35238bceSAndroid Build Coastguard Worker res->addStructType(subStructType);
415*35238bceSAndroid Build Coastguard Worker res->addStructType(structType);
416*35238bceSAndroid Build Coastguard Worker
417*35238bceSAndroid Build Coastguard Worker res->addUniform(Uniform((string("u_var") + nameSuffix).c_str(), glu::VarType(structType)));
418*35238bceSAndroid Build Coastguard Worker
419*35238bceSAndroid Build Coastguard Worker return res;
420*35238bceSAndroid Build Coastguard Worker }
421*35238bceSAndroid Build Coastguard Worker
multipleBasic(const char * const nameSuffix="")422*35238bceSAndroid Build Coastguard Worker static UniformCollection *multipleBasic(const char *const nameSuffix = "")
423*35238bceSAndroid Build Coastguard Worker {
424*35238bceSAndroid Build Coastguard Worker static const glu::DataType types[] = {glu::TYPE_FLOAT, glu::TYPE_INT_VEC3, glu::TYPE_FLOAT_MAT3,
425*35238bceSAndroid Build Coastguard Worker glu::TYPE_BOOL_VEC2};
426*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
427*35238bceSAndroid Build Coastguard Worker
428*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < DE_LENGTH_OF_ARRAY(types); i++)
429*35238bceSAndroid Build Coastguard Worker {
430*35238bceSAndroid Build Coastguard Worker UniformCollection *const sub = basic(types[i], ("_" + de::toString(i) + nameSuffix).c_str());
431*35238bceSAndroid Build Coastguard Worker sub->moveContents(*res);
432*35238bceSAndroid Build Coastguard Worker delete sub;
433*35238bceSAndroid Build Coastguard Worker }
434*35238bceSAndroid Build Coastguard Worker
435*35238bceSAndroid Build Coastguard Worker return res;
436*35238bceSAndroid Build Coastguard Worker }
437*35238bceSAndroid Build Coastguard Worker
multipleBasicArray(const char * const nameSuffix="")438*35238bceSAndroid Build Coastguard Worker static UniformCollection *multipleBasicArray(const char *const nameSuffix = "")
439*35238bceSAndroid Build Coastguard Worker {
440*35238bceSAndroid Build Coastguard Worker static const glu::DataType types[] = {glu::TYPE_FLOAT, glu::TYPE_INT_VEC3, glu::TYPE_BOOL_VEC2};
441*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
442*35238bceSAndroid Build Coastguard Worker
443*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < DE_LENGTH_OF_ARRAY(types); i++)
444*35238bceSAndroid Build Coastguard Worker {
445*35238bceSAndroid Build Coastguard Worker UniformCollection *const sub = basicArray(types[i], ("_" + de::toString(i) + nameSuffix).c_str());
446*35238bceSAndroid Build Coastguard Worker sub->moveContents(*res);
447*35238bceSAndroid Build Coastguard Worker delete sub;
448*35238bceSAndroid Build Coastguard Worker }
449*35238bceSAndroid Build Coastguard Worker
450*35238bceSAndroid Build Coastguard Worker return res;
451*35238bceSAndroid Build Coastguard Worker }
452*35238bceSAndroid Build Coastguard Worker
multipleNestedArraysStructs(const char * const nameSuffix="")453*35238bceSAndroid Build Coastguard Worker static UniformCollection *multipleNestedArraysStructs(const char *const nameSuffix = "")
454*35238bceSAndroid Build Coastguard Worker {
455*35238bceSAndroid Build Coastguard Worker static const glu::DataType types0[] = {glu::TYPE_FLOAT, glu::TYPE_INT, glu::TYPE_BOOL_VEC4};
456*35238bceSAndroid Build Coastguard Worker static const glu::DataType types1[] = {glu::TYPE_FLOAT_VEC4, glu::TYPE_INT_VEC4, glu::TYPE_BOOL};
457*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
458*35238bceSAndroid Build Coastguard Worker
459*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(types0) == DE_LENGTH_OF_ARRAY(types1));
460*35238bceSAndroid Build Coastguard Worker
461*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < DE_LENGTH_OF_ARRAY(types0); i++)
462*35238bceSAndroid Build Coastguard Worker {
463*35238bceSAndroid Build Coastguard Worker UniformCollection *const sub =
464*35238bceSAndroid Build Coastguard Worker nestedArraysStructs(types0[i], types1[i], ("_" + de::toString(i) + nameSuffix).c_str());
465*35238bceSAndroid Build Coastguard Worker sub->moveContents(*res);
466*35238bceSAndroid Build Coastguard Worker delete sub;
467*35238bceSAndroid Build Coastguard Worker }
468*35238bceSAndroid Build Coastguard Worker
469*35238bceSAndroid Build Coastguard Worker return res;
470*35238bceSAndroid Build Coastguard Worker }
471*35238bceSAndroid Build Coastguard Worker
random(const uint32_t seed)472*35238bceSAndroid Build Coastguard Worker static UniformCollection *random(const uint32_t seed)
473*35238bceSAndroid Build Coastguard Worker {
474*35238bceSAndroid Build Coastguard Worker Random rnd(seed);
475*35238bceSAndroid Build Coastguard Worker const int numUniforms = rnd.getInt(1, 5);
476*35238bceSAndroid Build Coastguard Worker int structIdx = 0;
477*35238bceSAndroid Build Coastguard Worker UniformCollection *const res = new UniformCollection;
478*35238bceSAndroid Build Coastguard Worker
479*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numUniforms; i++)
480*35238bceSAndroid Build Coastguard Worker {
481*35238bceSAndroid Build Coastguard Worker vector<const StructType *> structTypes;
482*35238bceSAndroid Build Coastguard Worker Uniform uniform(("u_var" + de::toString(i)).c_str(), glu::VarType());
483*35238bceSAndroid Build Coastguard Worker
484*35238bceSAndroid Build Coastguard Worker // \note Discard uniforms that would cause number of samplers to exceed MAX_NUM_SAMPLER_UNIFORMS.
485*35238bceSAndroid Build Coastguard Worker do
486*35238bceSAndroid Build Coastguard Worker {
487*35238bceSAndroid Build Coastguard Worker for (int j = 0; j < (int)structTypes.size(); j++)
488*35238bceSAndroid Build Coastguard Worker delete structTypes[j];
489*35238bceSAndroid Build Coastguard Worker structTypes.clear();
490*35238bceSAndroid Build Coastguard Worker uniform.type = generateRandomType(3, structIdx, structTypes, rnd);
491*35238bceSAndroid Build Coastguard Worker } while (res->getNumSamplers() + getNumSamplersInType(uniform.type) > MAX_NUM_SAMPLER_UNIFORMS);
492*35238bceSAndroid Build Coastguard Worker
493*35238bceSAndroid Build Coastguard Worker res->addUniform(uniform);
494*35238bceSAndroid Build Coastguard Worker for (int j = 0; j < (int)structTypes.size(); j++)
495*35238bceSAndroid Build Coastguard Worker res->addStructType(structTypes[j]);
496*35238bceSAndroid Build Coastguard Worker }
497*35238bceSAndroid Build Coastguard Worker
498*35238bceSAndroid Build Coastguard Worker return res;
499*35238bceSAndroid Build Coastguard Worker }
500*35238bceSAndroid Build Coastguard Worker
501*35238bceSAndroid Build Coastguard Worker private:
502*35238bceSAndroid Build Coastguard Worker // \note Copying these would be cumbersome, since deep-copying both m_uniforms and m_structTypes
503*35238bceSAndroid Build Coastguard Worker // would mean that we'd need to update pointers from uniforms to point to the new structTypes.
504*35238bceSAndroid Build Coastguard Worker // When the same UniformCollection is needed in several places, a SharedPtr is used instead.
505*35238bceSAndroid Build Coastguard Worker UniformCollection(const UniformCollection &); // Not allowed.
506*35238bceSAndroid Build Coastguard Worker UniformCollection &operator=(const UniformCollection &); // Not allowed.
507*35238bceSAndroid Build Coastguard Worker
508*35238bceSAndroid Build Coastguard Worker vector<Uniform> m_uniforms;
509*35238bceSAndroid Build Coastguard Worker vector<const StructType *> m_structTypes;
510*35238bceSAndroid Build Coastguard Worker };
511*35238bceSAndroid Build Coastguard Worker
512*35238bceSAndroid Build Coastguard Worker } // namespace
513*35238bceSAndroid Build Coastguard Worker
getSamplerFillValue(const VarValue & sampler)514*35238bceSAndroid Build Coastguard Worker static VarValue getSamplerFillValue(const VarValue &sampler)
515*35238bceSAndroid Build Coastguard Worker {
516*35238bceSAndroid Build Coastguard Worker DE_ASSERT(glu::isDataTypeSampler(sampler.type));
517*35238bceSAndroid Build Coastguard Worker
518*35238bceSAndroid Build Coastguard Worker VarValue result;
519*35238bceSAndroid Build Coastguard Worker result.type = glu::TYPE_FLOAT_VEC4;
520*35238bceSAndroid Build Coastguard Worker
521*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++)
522*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = sampler.val.samplerV.fillColor[i];
523*35238bceSAndroid Build Coastguard Worker
524*35238bceSAndroid Build Coastguard Worker return result;
525*35238bceSAndroid Build Coastguard Worker }
526*35238bceSAndroid Build Coastguard Worker
getSamplerUnitValue(const VarValue & sampler)527*35238bceSAndroid Build Coastguard Worker static VarValue getSamplerUnitValue(const VarValue &sampler)
528*35238bceSAndroid Build Coastguard Worker {
529*35238bceSAndroid Build Coastguard Worker DE_ASSERT(glu::isDataTypeSampler(sampler.type));
530*35238bceSAndroid Build Coastguard Worker
531*35238bceSAndroid Build Coastguard Worker VarValue result;
532*35238bceSAndroid Build Coastguard Worker result.type = glu::TYPE_INT;
533*35238bceSAndroid Build Coastguard Worker result.val.intV[0] = sampler.val.samplerV.unit;
534*35238bceSAndroid Build Coastguard Worker
535*35238bceSAndroid Build Coastguard Worker return result;
536*35238bceSAndroid Build Coastguard Worker }
537*35238bceSAndroid Build Coastguard Worker
shaderVarValueStr(const VarValue & value)538*35238bceSAndroid Build Coastguard Worker static string shaderVarValueStr(const VarValue &value)
539*35238bceSAndroid Build Coastguard Worker {
540*35238bceSAndroid Build Coastguard Worker const int numElems = glu::getDataTypeScalarSize(value.type);
541*35238bceSAndroid Build Coastguard Worker std::ostringstream result;
542*35238bceSAndroid Build Coastguard Worker
543*35238bceSAndroid Build Coastguard Worker if (numElems > 1)
544*35238bceSAndroid Build Coastguard Worker result << glu::getDataTypeName(value.type) << "(";
545*35238bceSAndroid Build Coastguard Worker
546*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
547*35238bceSAndroid Build Coastguard Worker {
548*35238bceSAndroid Build Coastguard Worker if (i > 0)
549*35238bceSAndroid Build Coastguard Worker result << ", ";
550*35238bceSAndroid Build Coastguard Worker
551*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(value.type) || glu::isDataTypeMatrix(value.type))
552*35238bceSAndroid Build Coastguard Worker result << de::floatToString(value.val.floatV[i], 2);
553*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec((value.type)))
554*35238bceSAndroid Build Coastguard Worker result << de::toString(value.val.intV[i]);
555*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec((value.type)))
556*35238bceSAndroid Build Coastguard Worker result << (value.val.boolV[i] ? "true" : "false");
557*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler((value.type)))
558*35238bceSAndroid Build Coastguard Worker result << shaderVarValueStr(getSamplerFillValue(value));
559*35238bceSAndroid Build Coastguard Worker else
560*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
561*35238bceSAndroid Build Coastguard Worker }
562*35238bceSAndroid Build Coastguard Worker
563*35238bceSAndroid Build Coastguard Worker if (numElems > 1)
564*35238bceSAndroid Build Coastguard Worker result << ")";
565*35238bceSAndroid Build Coastguard Worker
566*35238bceSAndroid Build Coastguard Worker return result.str();
567*35238bceSAndroid Build Coastguard Worker }
568*35238bceSAndroid Build Coastguard Worker
apiVarValueStr(const VarValue & value)569*35238bceSAndroid Build Coastguard Worker static string apiVarValueStr(const VarValue &value)
570*35238bceSAndroid Build Coastguard Worker {
571*35238bceSAndroid Build Coastguard Worker const int numElems = glu::getDataTypeScalarSize(value.type);
572*35238bceSAndroid Build Coastguard Worker std::ostringstream result;
573*35238bceSAndroid Build Coastguard Worker
574*35238bceSAndroid Build Coastguard Worker if (numElems > 1)
575*35238bceSAndroid Build Coastguard Worker result << "(";
576*35238bceSAndroid Build Coastguard Worker
577*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
578*35238bceSAndroid Build Coastguard Worker {
579*35238bceSAndroid Build Coastguard Worker if (i > 0)
580*35238bceSAndroid Build Coastguard Worker result << ", ";
581*35238bceSAndroid Build Coastguard Worker
582*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(value.type) || glu::isDataTypeMatrix(value.type))
583*35238bceSAndroid Build Coastguard Worker result << de::floatToString(value.val.floatV[i], 2);
584*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec((value.type)))
585*35238bceSAndroid Build Coastguard Worker result << de::toString(value.val.intV[i]);
586*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec((value.type)))
587*35238bceSAndroid Build Coastguard Worker result << (value.val.boolV[i] ? "true" : "false");
588*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler((value.type)))
589*35238bceSAndroid Build Coastguard Worker result << value.val.samplerV.unit;
590*35238bceSAndroid Build Coastguard Worker else
591*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
592*35238bceSAndroid Build Coastguard Worker }
593*35238bceSAndroid Build Coastguard Worker
594*35238bceSAndroid Build Coastguard Worker if (numElems > 1)
595*35238bceSAndroid Build Coastguard Worker result << ")";
596*35238bceSAndroid Build Coastguard Worker
597*35238bceSAndroid Build Coastguard Worker return result.str();
598*35238bceSAndroid Build Coastguard Worker }
599*35238bceSAndroid Build Coastguard Worker
generateRandomVarValue(const glu::DataType type,Random & rnd,int samplerUnit=-1)600*35238bceSAndroid Build Coastguard Worker static VarValue generateRandomVarValue(
601*35238bceSAndroid Build Coastguard Worker const glu::DataType type, Random &rnd,
602*35238bceSAndroid Build Coastguard Worker int samplerUnit = -1 /* Used if type is a sampler type. \note Samplers' unit numbers are not randomized. */)
603*35238bceSAndroid Build Coastguard Worker {
604*35238bceSAndroid Build Coastguard Worker const int numElems = glu::getDataTypeScalarSize(type);
605*35238bceSAndroid Build Coastguard Worker VarValue result;
606*35238bceSAndroid Build Coastguard Worker result.type = type;
607*35238bceSAndroid Build Coastguard Worker
608*35238bceSAndroid Build Coastguard Worker DE_ASSERT((samplerUnit >= 0) == (glu::isDataTypeSampler(type)));
609*35238bceSAndroid Build Coastguard Worker
610*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(type) || glu::isDataTypeMatrix(type))
611*35238bceSAndroid Build Coastguard Worker {
612*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
613*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = rnd.getFloat(-10.0f, 10.0f);
614*35238bceSAndroid Build Coastguard Worker }
615*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(type))
616*35238bceSAndroid Build Coastguard Worker {
617*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
618*35238bceSAndroid Build Coastguard Worker result.val.intV[i] = rnd.getInt(-10, 10);
619*35238bceSAndroid Build Coastguard Worker }
620*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec(type))
621*35238bceSAndroid Build Coastguard Worker {
622*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
623*35238bceSAndroid Build Coastguard Worker result.val.boolV[i] = rnd.getBool();
624*35238bceSAndroid Build Coastguard Worker }
625*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(type))
626*35238bceSAndroid Build Coastguard Worker {
627*35238bceSAndroid Build Coastguard Worker result.val.samplerV.unit = samplerUnit;
628*35238bceSAndroid Build Coastguard Worker
629*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++)
630*35238bceSAndroid Build Coastguard Worker result.val.samplerV.fillColor[i] = rnd.getFloat(0.0f, 1.0f);
631*35238bceSAndroid Build Coastguard Worker }
632*35238bceSAndroid Build Coastguard Worker else
633*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
634*35238bceSAndroid Build Coastguard Worker
635*35238bceSAndroid Build Coastguard Worker return result;
636*35238bceSAndroid Build Coastguard Worker }
637*35238bceSAndroid Build Coastguard Worker
generateZeroVarValue(const glu::DataType type)638*35238bceSAndroid Build Coastguard Worker static VarValue generateZeroVarValue(const glu::DataType type)
639*35238bceSAndroid Build Coastguard Worker {
640*35238bceSAndroid Build Coastguard Worker const int numElems = glu::getDataTypeScalarSize(type);
641*35238bceSAndroid Build Coastguard Worker VarValue result;
642*35238bceSAndroid Build Coastguard Worker result.type = type;
643*35238bceSAndroid Build Coastguard Worker
644*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(type) || glu::isDataTypeMatrix(type))
645*35238bceSAndroid Build Coastguard Worker {
646*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
647*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = 0.0f;
648*35238bceSAndroid Build Coastguard Worker }
649*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(type))
650*35238bceSAndroid Build Coastguard Worker {
651*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
652*35238bceSAndroid Build Coastguard Worker result.val.intV[i] = 0;
653*35238bceSAndroid Build Coastguard Worker }
654*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec(type))
655*35238bceSAndroid Build Coastguard Worker {
656*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numElems; i++)
657*35238bceSAndroid Build Coastguard Worker result.val.boolV[i] = false;
658*35238bceSAndroid Build Coastguard Worker }
659*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(type))
660*35238bceSAndroid Build Coastguard Worker {
661*35238bceSAndroid Build Coastguard Worker result.val.samplerV.unit = 0;
662*35238bceSAndroid Build Coastguard Worker
663*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++)
664*35238bceSAndroid Build Coastguard Worker result.val.samplerV.fillColor[i] = 0.12f * (float)i;
665*35238bceSAndroid Build Coastguard Worker }
666*35238bceSAndroid Build Coastguard Worker else
667*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
668*35238bceSAndroid Build Coastguard Worker
669*35238bceSAndroid Build Coastguard Worker return result;
670*35238bceSAndroid Build Coastguard Worker }
671*35238bceSAndroid Build Coastguard Worker
apiVarValueEquals(const VarValue & a,const VarValue & b)672*35238bceSAndroid Build Coastguard Worker static bool apiVarValueEquals(const VarValue &a, const VarValue &b)
673*35238bceSAndroid Build Coastguard Worker {
674*35238bceSAndroid Build Coastguard Worker const int size = glu::getDataTypeScalarSize(a.type);
675*35238bceSAndroid Build Coastguard Worker const float floatThreshold = 0.05f;
676*35238bceSAndroid Build Coastguard Worker
677*35238bceSAndroid Build Coastguard Worker DE_ASSERT(a.type == b.type);
678*35238bceSAndroid Build Coastguard Worker
679*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(a.type) || glu::isDataTypeMatrix(a.type))
680*35238bceSAndroid Build Coastguard Worker {
681*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
682*35238bceSAndroid Build Coastguard Worker if (de::abs(a.val.floatV[i] - b.val.floatV[i]) >= floatThreshold)
683*35238bceSAndroid Build Coastguard Worker return false;
684*35238bceSAndroid Build Coastguard Worker }
685*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(a.type))
686*35238bceSAndroid Build Coastguard Worker {
687*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
688*35238bceSAndroid Build Coastguard Worker if (a.val.intV[i] != b.val.intV[i])
689*35238bceSAndroid Build Coastguard Worker return false;
690*35238bceSAndroid Build Coastguard Worker }
691*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec(a.type))
692*35238bceSAndroid Build Coastguard Worker {
693*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
694*35238bceSAndroid Build Coastguard Worker if (a.val.boolV[i] != b.val.boolV[i])
695*35238bceSAndroid Build Coastguard Worker return false;
696*35238bceSAndroid Build Coastguard Worker }
697*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(a.type))
698*35238bceSAndroid Build Coastguard Worker {
699*35238bceSAndroid Build Coastguard Worker if (a.val.samplerV.unit != b.val.samplerV.unit)
700*35238bceSAndroid Build Coastguard Worker return false;
701*35238bceSAndroid Build Coastguard Worker }
702*35238bceSAndroid Build Coastguard Worker else
703*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
704*35238bceSAndroid Build Coastguard Worker
705*35238bceSAndroid Build Coastguard Worker return true;
706*35238bceSAndroid Build Coastguard Worker }
707*35238bceSAndroid Build Coastguard Worker
getRandomBoolRepresentation(const VarValue & boolValue,const glu::DataType targetScalarType,Random & rnd)708*35238bceSAndroid Build Coastguard Worker static VarValue getRandomBoolRepresentation(const VarValue &boolValue, const glu::DataType targetScalarType,
709*35238bceSAndroid Build Coastguard Worker Random &rnd)
710*35238bceSAndroid Build Coastguard Worker {
711*35238bceSAndroid Build Coastguard Worker DE_ASSERT(glu::isDataTypeBoolOrBVec(boolValue.type));
712*35238bceSAndroid Build Coastguard Worker
713*35238bceSAndroid Build Coastguard Worker const int size = glu::getDataTypeScalarSize(boolValue.type);
714*35238bceSAndroid Build Coastguard Worker const glu::DataType targetType = size == 1 ? targetScalarType : glu::getDataTypeVector(targetScalarType, size);
715*35238bceSAndroid Build Coastguard Worker VarValue result;
716*35238bceSAndroid Build Coastguard Worker result.type = targetType;
717*35238bceSAndroid Build Coastguard Worker
718*35238bceSAndroid Build Coastguard Worker switch (targetScalarType)
719*35238bceSAndroid Build Coastguard Worker {
720*35238bceSAndroid Build Coastguard Worker case glu::TYPE_INT:
721*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
722*35238bceSAndroid Build Coastguard Worker {
723*35238bceSAndroid Build Coastguard Worker if (boolValue.val.boolV[i])
724*35238bceSAndroid Build Coastguard Worker {
725*35238bceSAndroid Build Coastguard Worker result.val.intV[i] = rnd.getInt(-10, 10);
726*35238bceSAndroid Build Coastguard Worker if (result.val.intV[i] == 0)
727*35238bceSAndroid Build Coastguard Worker result.val.intV[i] = 1;
728*35238bceSAndroid Build Coastguard Worker }
729*35238bceSAndroid Build Coastguard Worker else
730*35238bceSAndroid Build Coastguard Worker result.val.intV[i] = 0;
731*35238bceSAndroid Build Coastguard Worker }
732*35238bceSAndroid Build Coastguard Worker break;
733*35238bceSAndroid Build Coastguard Worker
734*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT:
735*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
736*35238bceSAndroid Build Coastguard Worker {
737*35238bceSAndroid Build Coastguard Worker if (boolValue.val.boolV[i])
738*35238bceSAndroid Build Coastguard Worker {
739*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = rnd.getFloat(-10.0f, 10.0f);
740*35238bceSAndroid Build Coastguard Worker if (result.val.floatV[i] == 0.0f)
741*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = 1.0f;
742*35238bceSAndroid Build Coastguard Worker }
743*35238bceSAndroid Build Coastguard Worker else
744*35238bceSAndroid Build Coastguard Worker result.val.floatV[i] = 0;
745*35238bceSAndroid Build Coastguard Worker }
746*35238bceSAndroid Build Coastguard Worker break;
747*35238bceSAndroid Build Coastguard Worker
748*35238bceSAndroid Build Coastguard Worker default:
749*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
750*35238bceSAndroid Build Coastguard Worker }
751*35238bceSAndroid Build Coastguard Worker
752*35238bceSAndroid Build Coastguard Worker return result;
753*35238bceSAndroid Build Coastguard Worker }
754*35238bceSAndroid Build Coastguard Worker
getCaseShaderTypeName(const CaseShaderType type)755*35238bceSAndroid Build Coastguard Worker static const char *getCaseShaderTypeName(const CaseShaderType type)
756*35238bceSAndroid Build Coastguard Worker {
757*35238bceSAndroid Build Coastguard Worker switch (type)
758*35238bceSAndroid Build Coastguard Worker {
759*35238bceSAndroid Build Coastguard Worker case CASESHADERTYPE_VERTEX:
760*35238bceSAndroid Build Coastguard Worker return "vertex";
761*35238bceSAndroid Build Coastguard Worker case CASESHADERTYPE_FRAGMENT:
762*35238bceSAndroid Build Coastguard Worker return "fragment";
763*35238bceSAndroid Build Coastguard Worker case CASESHADERTYPE_BOTH:
764*35238bceSAndroid Build Coastguard Worker return "both";
765*35238bceSAndroid Build Coastguard Worker default:
766*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
767*35238bceSAndroid Build Coastguard Worker return DE_NULL;
768*35238bceSAndroid Build Coastguard Worker }
769*35238bceSAndroid Build Coastguard Worker }
770*35238bceSAndroid Build Coastguard Worker
randomCaseShaderType(const uint32_t seed)771*35238bceSAndroid Build Coastguard Worker static CaseShaderType randomCaseShaderType(const uint32_t seed)
772*35238bceSAndroid Build Coastguard Worker {
773*35238bceSAndroid Build Coastguard Worker return (CaseShaderType)Random(seed).getInt(0, CASESHADERTYPE_LAST - 1);
774*35238bceSAndroid Build Coastguard Worker }
775*35238bceSAndroid Build Coastguard Worker
776*35238bceSAndroid Build Coastguard Worker class UniformCase : public TestCase, protected glu::CallLogWrapper
777*35238bceSAndroid Build Coastguard Worker {
778*35238bceSAndroid Build Coastguard Worker public:
779*35238bceSAndroid Build Coastguard Worker enum Feature
780*35238bceSAndroid Build Coastguard Worker {
781*35238bceSAndroid Build Coastguard Worker // ARRAYUSAGE_ONLY_MIDDLE_INDEX: only middle index of each array is used in shader. If not given, use all indices.
782*35238bceSAndroid Build Coastguard Worker FEATURE_ARRAYUSAGE_ONLY_MIDDLE_INDEX = 1 << 0,
783*35238bceSAndroid Build Coastguard Worker
784*35238bceSAndroid Build Coastguard Worker // UNIFORMFUNC_VALUE: use pass-by-value versions of uniform assignment funcs, e.g. glUniform1f(), where possible. If not given, use pass-by-pointer versions.
785*35238bceSAndroid Build Coastguard Worker FEATURE_UNIFORMFUNC_VALUE = 1 << 1,
786*35238bceSAndroid Build Coastguard Worker
787*35238bceSAndroid Build Coastguard Worker // ARRAYASSIGN: how basic-type arrays are assigned with glUniform*(). If none given, assign each element of an array separately.
788*35238bceSAndroid Build Coastguard Worker FEATURE_ARRAYASSIGN_FULL = 1 << 2, //!< Assign all elements of an array with one glUniform*().
789*35238bceSAndroid Build Coastguard Worker FEATURE_ARRAYASSIGN_BLOCKS_OF_TWO = 1 << 3, //!< Assign two elements per one glUniform*().
790*35238bceSAndroid Build Coastguard Worker
791*35238bceSAndroid Build Coastguard Worker // UNIFORMUSAGE_EVERY_OTHER: use about half of the uniforms. If not given, use all uniforms (except that some array indices may be omitted according to ARRAYUSAGE).
792*35238bceSAndroid Build Coastguard Worker FEATURE_UNIFORMUSAGE_EVERY_OTHER = 1 << 4,
793*35238bceSAndroid Build Coastguard Worker
794*35238bceSAndroid Build Coastguard Worker // BOOLEANAPITYPE: type used to pass booleans to and from GL api. If none given, use float.
795*35238bceSAndroid Build Coastguard Worker FEATURE_BOOLEANAPITYPE_INT = 1 << 5,
796*35238bceSAndroid Build Coastguard Worker
797*35238bceSAndroid Build Coastguard Worker // UNIFORMVALUE_ZERO: use zero-valued uniforms. If not given, use random uniform values.
798*35238bceSAndroid Build Coastguard Worker FEATURE_UNIFORMVALUE_ZERO = 1 << 6,
799*35238bceSAndroid Build Coastguard Worker
800*35238bceSAndroid Build Coastguard Worker // ARRAY_FIRST_ELEM_NAME_NO_INDEX: in certain API functions, when referring to the first element of an array, use just the array name without [0] at the end.
801*35238bceSAndroid Build Coastguard Worker FEATURE_ARRAY_FIRST_ELEM_NAME_NO_INDEX = 1 << 7
802*35238bceSAndroid Build Coastguard Worker };
803*35238bceSAndroid Build Coastguard Worker
804*35238bceSAndroid Build Coastguard Worker UniformCase(Context &context, const char *name, const char *description, CaseShaderType caseType,
805*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection, uint32_t features);
806*35238bceSAndroid Build Coastguard Worker UniformCase(Context &context, const char *name, const char *description,
807*35238bceSAndroid Build Coastguard Worker uint32_t seed); // \note Randomizes caseType, uniformCollection and features.
808*35238bceSAndroid Build Coastguard Worker virtual ~UniformCase(void);
809*35238bceSAndroid Build Coastguard Worker
810*35238bceSAndroid Build Coastguard Worker virtual void init(void);
811*35238bceSAndroid Build Coastguard Worker virtual void deinit(void);
812*35238bceSAndroid Build Coastguard Worker
813*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
814*35238bceSAndroid Build Coastguard Worker
815*35238bceSAndroid Build Coastguard Worker protected:
816*35238bceSAndroid Build Coastguard Worker // A basic uniform is a uniform (possibly struct or array member) whose type is a basic type (e.g. float, ivec4, sampler2d).
817*35238bceSAndroid Build Coastguard Worker struct BasicUniform
818*35238bceSAndroid Build Coastguard Worker {
819*35238bceSAndroid Build Coastguard Worker string name;
820*35238bceSAndroid Build Coastguard Worker glu::DataType type;
821*35238bceSAndroid Build Coastguard Worker bool isUsedInShader;
822*35238bceSAndroid Build Coastguard Worker VarValue finalValue; //!< The value we ultimately want to set for this uniform.
823*35238bceSAndroid Build Coastguard Worker
824*35238bceSAndroid Build Coastguard Worker string
825*35238bceSAndroid Build Coastguard Worker rootName; //!< If this is a member of a basic-typed array, rootName is the name of that array with "[0]" appended. Otherwise it equals name.
826*35238bceSAndroid Build Coastguard Worker int elemNdx; //!< If this is a member of a basic-typed array, elemNdx is the index in that array. Otherwise -1.
827*35238bceSAndroid Build Coastguard Worker int rootSize; //!< If this is a member of a basic-typed array, rootSize is the size of that array. Otherwise 1.
828*35238bceSAndroid Build Coastguard Worker
BasicUniformdeqp::gles2::Functional::UniformCase::BasicUniform829*35238bceSAndroid Build Coastguard Worker BasicUniform(const char *const name_, const glu::DataType type_, const bool isUsedInShader_,
830*35238bceSAndroid Build Coastguard Worker const VarValue &finalValue_, const char *const rootName_ = DE_NULL, const int elemNdx_ = -1,
831*35238bceSAndroid Build Coastguard Worker const int rootSize_ = 1)
832*35238bceSAndroid Build Coastguard Worker : name(name_)
833*35238bceSAndroid Build Coastguard Worker , type(type_)
834*35238bceSAndroid Build Coastguard Worker , isUsedInShader(isUsedInShader_)
835*35238bceSAndroid Build Coastguard Worker , finalValue(finalValue_)
836*35238bceSAndroid Build Coastguard Worker , rootName(rootName_ == DE_NULL ? name_ : rootName_)
837*35238bceSAndroid Build Coastguard Worker , elemNdx(elemNdx_)
838*35238bceSAndroid Build Coastguard Worker , rootSize(rootSize_)
839*35238bceSAndroid Build Coastguard Worker {
840*35238bceSAndroid Build Coastguard Worker }
841*35238bceSAndroid Build Coastguard Worker
findWithNamedeqp::gles2::Functional::UniformCase::BasicUniform842*35238bceSAndroid Build Coastguard Worker static vector<BasicUniform>::const_iterator findWithName(const vector<BasicUniform> &vec,
843*35238bceSAndroid Build Coastguard Worker const char *const name)
844*35238bceSAndroid Build Coastguard Worker {
845*35238bceSAndroid Build Coastguard Worker for (vector<BasicUniform>::const_iterator it = vec.begin(); it != vec.end(); it++)
846*35238bceSAndroid Build Coastguard Worker {
847*35238bceSAndroid Build Coastguard Worker if (it->name == name)
848*35238bceSAndroid Build Coastguard Worker return it;
849*35238bceSAndroid Build Coastguard Worker }
850*35238bceSAndroid Build Coastguard Worker return vec.end();
851*35238bceSAndroid Build Coastguard Worker }
852*35238bceSAndroid Build Coastguard Worker };
853*35238bceSAndroid Build Coastguard Worker
854*35238bceSAndroid Build Coastguard Worker // Reference values for info that is expected to be reported by glGetActiveUniform().
855*35238bceSAndroid Build Coastguard Worker struct BasicUniformReportRef
856*35238bceSAndroid Build Coastguard Worker {
857*35238bceSAndroid Build Coastguard Worker string name;
858*35238bceSAndroid Build Coastguard Worker // \note minSize and maxSize are for arrays and can be distinct since implementations are allowed, but not required, to trim the inactive end indices of arrays.
859*35238bceSAndroid Build Coastguard Worker int minSize;
860*35238bceSAndroid Build Coastguard Worker int maxSize;
861*35238bceSAndroid Build Coastguard Worker glu::DataType type;
862*35238bceSAndroid Build Coastguard Worker bool isUsedInShader;
863*35238bceSAndroid Build Coastguard Worker
BasicUniformReportRefdeqp::gles2::Functional::UniformCase::BasicUniformReportRef864*35238bceSAndroid Build Coastguard Worker BasicUniformReportRef(const char *const name_, const int minS, const int maxS, const glu::DataType type_,
865*35238bceSAndroid Build Coastguard Worker const bool used)
866*35238bceSAndroid Build Coastguard Worker : name(name_)
867*35238bceSAndroid Build Coastguard Worker , minSize(minS)
868*35238bceSAndroid Build Coastguard Worker , maxSize(maxS)
869*35238bceSAndroid Build Coastguard Worker , type(type_)
870*35238bceSAndroid Build Coastguard Worker , isUsedInShader(used)
871*35238bceSAndroid Build Coastguard Worker {
872*35238bceSAndroid Build Coastguard Worker DE_ASSERT(minSize <= maxSize);
873*35238bceSAndroid Build Coastguard Worker }
BasicUniformReportRefdeqp::gles2::Functional::UniformCase::BasicUniformReportRef874*35238bceSAndroid Build Coastguard Worker BasicUniformReportRef(const char *const name_, const glu::DataType type_, const bool used)
875*35238bceSAndroid Build Coastguard Worker : name(name_)
876*35238bceSAndroid Build Coastguard Worker , minSize(1)
877*35238bceSAndroid Build Coastguard Worker , maxSize(1)
878*35238bceSAndroid Build Coastguard Worker , type(type_)
879*35238bceSAndroid Build Coastguard Worker , isUsedInShader(used)
880*35238bceSAndroid Build Coastguard Worker {
881*35238bceSAndroid Build Coastguard Worker }
882*35238bceSAndroid Build Coastguard Worker };
883*35238bceSAndroid Build Coastguard Worker
884*35238bceSAndroid Build Coastguard Worker // Info that is actually reported by glGetActiveUniform().
885*35238bceSAndroid Build Coastguard Worker struct BasicUniformReportGL
886*35238bceSAndroid Build Coastguard Worker {
887*35238bceSAndroid Build Coastguard Worker string name;
888*35238bceSAndroid Build Coastguard Worker int nameLength;
889*35238bceSAndroid Build Coastguard Worker int size;
890*35238bceSAndroid Build Coastguard Worker glu::DataType type;
891*35238bceSAndroid Build Coastguard Worker
892*35238bceSAndroid Build Coastguard Worker int index;
893*35238bceSAndroid Build Coastguard Worker
BasicUniformReportGLdeqp::gles2::Functional::UniformCase::BasicUniformReportGL894*35238bceSAndroid Build Coastguard Worker BasicUniformReportGL(const char *const name_, const int nameLength_, const int size_, const glu::DataType type_,
895*35238bceSAndroid Build Coastguard Worker const int index_)
896*35238bceSAndroid Build Coastguard Worker : name(name_)
897*35238bceSAndroid Build Coastguard Worker , nameLength(nameLength_)
898*35238bceSAndroid Build Coastguard Worker , size(size_)
899*35238bceSAndroid Build Coastguard Worker , type(type_)
900*35238bceSAndroid Build Coastguard Worker , index(index_)
901*35238bceSAndroid Build Coastguard Worker {
902*35238bceSAndroid Build Coastguard Worker }
903*35238bceSAndroid Build Coastguard Worker
findWithNamedeqp::gles2::Functional::UniformCase::BasicUniformReportGL904*35238bceSAndroid Build Coastguard Worker static vector<BasicUniformReportGL>::const_iterator findWithName(const vector<BasicUniformReportGL> &vec,
905*35238bceSAndroid Build Coastguard Worker const char *const name)
906*35238bceSAndroid Build Coastguard Worker {
907*35238bceSAndroid Build Coastguard Worker for (vector<BasicUniformReportGL>::const_iterator it = vec.begin(); it != vec.end(); it++)
908*35238bceSAndroid Build Coastguard Worker {
909*35238bceSAndroid Build Coastguard Worker if (it->name == name)
910*35238bceSAndroid Build Coastguard Worker return it;
911*35238bceSAndroid Build Coastguard Worker }
912*35238bceSAndroid Build Coastguard Worker return vec.end();
913*35238bceSAndroid Build Coastguard Worker }
914*35238bceSAndroid Build Coastguard Worker };
915*35238bceSAndroid Build Coastguard Worker
916*35238bceSAndroid Build Coastguard Worker // Query info with glGetActiveUniform() and check validity.
917*35238bceSAndroid Build Coastguard Worker bool getActiveUniforms(vector<BasicUniformReportGL> &dst, const vector<BasicUniformReportRef> &ref,
918*35238bceSAndroid Build Coastguard Worker uint32_t programGL);
919*35238bceSAndroid Build Coastguard Worker // Get uniform values with glGetUniform*() and put to valuesDst. Uniforms that get -1 from glGetUniformLocation() get glu::TYPE_INVALID.
920*35238bceSAndroid Build Coastguard Worker bool getUniforms(vector<VarValue> &valuesDst, const vector<BasicUniform> &basicUniforms, uint32_t programGL);
921*35238bceSAndroid Build Coastguard Worker // Check that every uniform has the default (zero) value.
922*35238bceSAndroid Build Coastguard Worker bool checkUniformDefaultValues(const vector<VarValue> &values, const vector<BasicUniform> &basicUniforms);
923*35238bceSAndroid Build Coastguard Worker // Assign the basicUniforms[].finalValue values for uniforms. \note rnd parameter is for booleans (true can be any nonzero value).
924*35238bceSAndroid Build Coastguard Worker void assignUniforms(const vector<BasicUniform> &basicUniforms, uint32_t programGL, Random &rnd);
925*35238bceSAndroid Build Coastguard Worker // Compare the uniform values given in values (obtained with glGetUniform*()) with the basicUniform.finalValue values.
926*35238bceSAndroid Build Coastguard Worker bool compareUniformValues(const vector<VarValue> &values, const vector<BasicUniform> &basicUniforms);
927*35238bceSAndroid Build Coastguard Worker // Render and check that all pixels are white (i.e. all uniform comparisons passed).
928*35238bceSAndroid Build Coastguard Worker bool renderTest(const vector<BasicUniform> &basicUniforms, const ShaderProgram &program, Random &rnd);
929*35238bceSAndroid Build Coastguard Worker
930*35238bceSAndroid Build Coastguard Worker virtual bool test(const vector<BasicUniform> &basicUniforms,
931*35238bceSAndroid Build Coastguard Worker const vector<BasicUniformReportRef> &basicUniformReportsRef, const ShaderProgram &program,
932*35238bceSAndroid Build Coastguard Worker Random &rnd) = 0;
933*35238bceSAndroid Build Coastguard Worker
934*35238bceSAndroid Build Coastguard Worker const uint32_t m_features;
935*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> m_uniformCollection;
936*35238bceSAndroid Build Coastguard Worker
937*35238bceSAndroid Build Coastguard Worker private:
938*35238bceSAndroid Build Coastguard Worker static uint32_t randomFeatures(uint32_t seed);
939*35238bceSAndroid Build Coastguard Worker
940*35238bceSAndroid Build Coastguard Worker // Generates the basic uniforms, based on the uniform with name varName and type varType, in the same manner as are expected
941*35238bceSAndroid Build Coastguard Worker // to be returned by glGetActiveUniform(), e.g. generates a name like var[0] for arrays, and recursively generates struct member names.
942*35238bceSAndroid Build Coastguard Worker void generateBasicUniforms(vector<BasicUniform> &basicUniformsDst,
943*35238bceSAndroid Build Coastguard Worker vector<BasicUniformReportRef> &basicUniformReportsDst, const glu::VarType &varType,
944*35238bceSAndroid Build Coastguard Worker const char *varName, bool isParentActive, int &samplerUnitCounter, Random &rnd) const;
945*35238bceSAndroid Build Coastguard Worker
946*35238bceSAndroid Build Coastguard Worker void writeUniformDefinitions(std::ostringstream &dst) const;
947*35238bceSAndroid Build Coastguard Worker void writeUniformCompareExpr(std::ostringstream &dst, const BasicUniform &uniform) const;
948*35238bceSAndroid Build Coastguard Worker void writeUniformComparisons(std::ostringstream &dst, const vector<BasicUniform> &basicUniforms,
949*35238bceSAndroid Build Coastguard Worker const char *variableName) const;
950*35238bceSAndroid Build Coastguard Worker
951*35238bceSAndroid Build Coastguard Worker string generateVertexSource(const vector<BasicUniform> &basicUniforms) const;
952*35238bceSAndroid Build Coastguard Worker string generateFragmentSource(const vector<BasicUniform> &basicUniforms) const;
953*35238bceSAndroid Build Coastguard Worker
954*35238bceSAndroid Build Coastguard Worker void setupTexture(const VarValue &value);
955*35238bceSAndroid Build Coastguard Worker
956*35238bceSAndroid Build Coastguard Worker const CaseShaderType m_caseShaderType;
957*35238bceSAndroid Build Coastguard Worker
958*35238bceSAndroid Build Coastguard Worker vector<glu::Texture2D *> m_textures2d;
959*35238bceSAndroid Build Coastguard Worker vector<glu::TextureCube *> m_texturesCube;
960*35238bceSAndroid Build Coastguard Worker vector<uint32_t> m_filledTextureUnits;
961*35238bceSAndroid Build Coastguard Worker };
962*35238bceSAndroid Build Coastguard Worker
randomFeatures(const uint32_t seed)963*35238bceSAndroid Build Coastguard Worker uint32_t UniformCase::randomFeatures(const uint32_t seed)
964*35238bceSAndroid Build Coastguard Worker {
965*35238bceSAndroid Build Coastguard Worker static const uint32_t arrayUsageChoices[] = {0, FEATURE_ARRAYUSAGE_ONLY_MIDDLE_INDEX};
966*35238bceSAndroid Build Coastguard Worker static const uint32_t uniformFuncChoices[] = {0, FEATURE_UNIFORMFUNC_VALUE};
967*35238bceSAndroid Build Coastguard Worker static const uint32_t arrayAssignChoices[] = {0, FEATURE_ARRAYASSIGN_FULL, FEATURE_ARRAYASSIGN_BLOCKS_OF_TWO};
968*35238bceSAndroid Build Coastguard Worker static const uint32_t uniformUsageChoices[] = {0, FEATURE_UNIFORMUSAGE_EVERY_OTHER};
969*35238bceSAndroid Build Coastguard Worker static const uint32_t booleanApiTypeChoices[] = {0, FEATURE_BOOLEANAPITYPE_INT};
970*35238bceSAndroid Build Coastguard Worker static const uint32_t uniformValueChoices[] = {0, FEATURE_UNIFORMVALUE_ZERO};
971*35238bceSAndroid Build Coastguard Worker
972*35238bceSAndroid Build Coastguard Worker Random rnd(seed);
973*35238bceSAndroid Build Coastguard Worker
974*35238bceSAndroid Build Coastguard Worker uint32_t result = 0;
975*35238bceSAndroid Build Coastguard Worker
976*35238bceSAndroid Build Coastguard Worker #define ARRAY_CHOICE(ARR) ((ARR)[rnd.getInt(0, DE_LENGTH_OF_ARRAY(ARR) - 1)])
977*35238bceSAndroid Build Coastguard Worker
978*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(arrayUsageChoices);
979*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(uniformFuncChoices);
980*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(arrayAssignChoices);
981*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(uniformUsageChoices);
982*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(booleanApiTypeChoices);
983*35238bceSAndroid Build Coastguard Worker result |= ARRAY_CHOICE(uniformValueChoices);
984*35238bceSAndroid Build Coastguard Worker
985*35238bceSAndroid Build Coastguard Worker #undef ARRAY_CHOICE
986*35238bceSAndroid Build Coastguard Worker
987*35238bceSAndroid Build Coastguard Worker return result;
988*35238bceSAndroid Build Coastguard Worker }
989*35238bceSAndroid Build Coastguard Worker
UniformCase(Context & context,const char * const name,const char * const description,const CaseShaderType caseShaderType,const SharedPtr<const UniformCollection> & uniformCollection,const uint32_t features)990*35238bceSAndroid Build Coastguard Worker UniformCase::UniformCase(Context &context, const char *const name, const char *const description,
991*35238bceSAndroid Build Coastguard Worker const CaseShaderType caseShaderType,
992*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection, const uint32_t features)
993*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
994*35238bceSAndroid Build Coastguard Worker , CallLogWrapper(context.getRenderContext().getFunctions(), m_testCtx.getLog())
995*35238bceSAndroid Build Coastguard Worker , m_features(features)
996*35238bceSAndroid Build Coastguard Worker , m_uniformCollection(uniformCollection)
997*35238bceSAndroid Build Coastguard Worker , m_caseShaderType(caseShaderType)
998*35238bceSAndroid Build Coastguard Worker {
999*35238bceSAndroid Build Coastguard Worker }
1000*35238bceSAndroid Build Coastguard Worker
UniformCase(Context & context,const char * name,const char * description,const uint32_t seed)1001*35238bceSAndroid Build Coastguard Worker UniformCase::UniformCase(Context &context, const char *name, const char *description, const uint32_t seed)
1002*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
1003*35238bceSAndroid Build Coastguard Worker , CallLogWrapper(context.getRenderContext().getFunctions(), m_testCtx.getLog())
1004*35238bceSAndroid Build Coastguard Worker , m_features(randomFeatures(seed))
1005*35238bceSAndroid Build Coastguard Worker , m_uniformCollection(UniformCollection::random(seed))
1006*35238bceSAndroid Build Coastguard Worker , m_caseShaderType(randomCaseShaderType(seed))
1007*35238bceSAndroid Build Coastguard Worker {
1008*35238bceSAndroid Build Coastguard Worker }
1009*35238bceSAndroid Build Coastguard Worker
init(void)1010*35238bceSAndroid Build Coastguard Worker void UniformCase::init(void)
1011*35238bceSAndroid Build Coastguard Worker {
1012*35238bceSAndroid Build Coastguard Worker {
1013*35238bceSAndroid Build Coastguard Worker const glw::Functions &funcs = m_context.getRenderContext().getFunctions();
1014*35238bceSAndroid Build Coastguard Worker const int numSamplerUniforms = m_uniformCollection->getNumSamplers();
1015*35238bceSAndroid Build Coastguard Worker const int vertexTexUnitsRequired = m_caseShaderType != CASESHADERTYPE_FRAGMENT ? numSamplerUniforms : 0;
1016*35238bceSAndroid Build Coastguard Worker const int fragmentTexUnitsRequired = m_caseShaderType != CASESHADERTYPE_VERTEX ? numSamplerUniforms : 0;
1017*35238bceSAndroid Build Coastguard Worker const int combinedTexUnitsRequired = vertexTexUnitsRequired + fragmentTexUnitsRequired;
1018*35238bceSAndroid Build Coastguard Worker const int vertexTexUnitsSupported = getGLInt(funcs, GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
1019*35238bceSAndroid Build Coastguard Worker const int fragmentTexUnitsSupported = getGLInt(funcs, GL_MAX_TEXTURE_IMAGE_UNITS);
1020*35238bceSAndroid Build Coastguard Worker const int combinedTexUnitsSupported = getGLInt(funcs, GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
1021*35238bceSAndroid Build Coastguard Worker
1022*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numSamplerUniforms <= MAX_NUM_SAMPLER_UNIFORMS);
1023*35238bceSAndroid Build Coastguard Worker
1024*35238bceSAndroid Build Coastguard Worker if (vertexTexUnitsRequired > vertexTexUnitsSupported)
1025*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(de::toString(vertexTexUnitsRequired) + " vertex texture units required, " +
1026*35238bceSAndroid Build Coastguard Worker de::toString(vertexTexUnitsSupported) + " supported");
1027*35238bceSAndroid Build Coastguard Worker if (fragmentTexUnitsRequired > fragmentTexUnitsSupported)
1028*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(de::toString(fragmentTexUnitsRequired) + " fragment texture units required, " +
1029*35238bceSAndroid Build Coastguard Worker de::toString(fragmentTexUnitsSupported) + " supported");
1030*35238bceSAndroid Build Coastguard Worker if (combinedTexUnitsRequired > combinedTexUnitsSupported)
1031*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(de::toString(combinedTexUnitsRequired) + " combined texture units required, " +
1032*35238bceSAndroid Build Coastguard Worker de::toString(combinedTexUnitsSupported) + " supported");
1033*35238bceSAndroid Build Coastguard Worker }
1034*35238bceSAndroid Build Coastguard Worker
1035*35238bceSAndroid Build Coastguard Worker enableLogging(true);
1036*35238bceSAndroid Build Coastguard Worker }
1037*35238bceSAndroid Build Coastguard Worker
deinit(void)1038*35238bceSAndroid Build Coastguard Worker void UniformCase::deinit(void)
1039*35238bceSAndroid Build Coastguard Worker {
1040*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_textures2d.size(); i++)
1041*35238bceSAndroid Build Coastguard Worker delete m_textures2d[i];
1042*35238bceSAndroid Build Coastguard Worker m_textures2d.clear();
1043*35238bceSAndroid Build Coastguard Worker
1044*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_texturesCube.size(); i++)
1045*35238bceSAndroid Build Coastguard Worker delete m_texturesCube[i];
1046*35238bceSAndroid Build Coastguard Worker m_texturesCube.clear();
1047*35238bceSAndroid Build Coastguard Worker
1048*35238bceSAndroid Build Coastguard Worker m_filledTextureUnits.clear();
1049*35238bceSAndroid Build Coastguard Worker }
1050*35238bceSAndroid Build Coastguard Worker
~UniformCase(void)1051*35238bceSAndroid Build Coastguard Worker UniformCase::~UniformCase(void)
1052*35238bceSAndroid Build Coastguard Worker {
1053*35238bceSAndroid Build Coastguard Worker UniformCase::deinit();
1054*35238bceSAndroid Build Coastguard Worker }
1055*35238bceSAndroid Build Coastguard Worker
generateBasicUniforms(vector<BasicUniform> & basicUniformsDst,vector<BasicUniformReportRef> & basicUniformReportsDst,const glu::VarType & varType,const char * const varName,const bool isParentActive,int & samplerUnitCounter,Random & rnd) const1056*35238bceSAndroid Build Coastguard Worker void UniformCase::generateBasicUniforms(vector<BasicUniform> &basicUniformsDst,
1057*35238bceSAndroid Build Coastguard Worker vector<BasicUniformReportRef> &basicUniformReportsDst,
1058*35238bceSAndroid Build Coastguard Worker const glu::VarType &varType, const char *const varName,
1059*35238bceSAndroid Build Coastguard Worker const bool isParentActive, int &samplerUnitCounter, Random &rnd) const
1060*35238bceSAndroid Build Coastguard Worker {
1061*35238bceSAndroid Build Coastguard Worker if (varType.isBasicType())
1062*35238bceSAndroid Build Coastguard Worker {
1063*35238bceSAndroid Build Coastguard Worker const bool isActive =
1064*35238bceSAndroid Build Coastguard Worker isParentActive && (m_features & FEATURE_UNIFORMUSAGE_EVERY_OTHER ? basicUniformsDst.size() % 2 == 0 : true);
1065*35238bceSAndroid Build Coastguard Worker const glu::DataType type = varType.getBasicType();
1066*35238bceSAndroid Build Coastguard Worker const VarValue value = m_features & FEATURE_UNIFORMVALUE_ZERO ? generateZeroVarValue(type) :
1067*35238bceSAndroid Build Coastguard Worker glu::isDataTypeSampler(type) ? generateRandomVarValue(type, rnd, samplerUnitCounter++) :
1068*35238bceSAndroid Build Coastguard Worker generateRandomVarValue(varType.getBasicType(), rnd);
1069*35238bceSAndroid Build Coastguard Worker
1070*35238bceSAndroid Build Coastguard Worker basicUniformsDst.push_back(BasicUniform(varName, varType.getBasicType(), isActive, value));
1071*35238bceSAndroid Build Coastguard Worker basicUniformReportsDst.push_back(BasicUniformReportRef(varName, varType.getBasicType(), isActive));
1072*35238bceSAndroid Build Coastguard Worker }
1073*35238bceSAndroid Build Coastguard Worker else if (varType.isArrayType())
1074*35238bceSAndroid Build Coastguard Worker {
1075*35238bceSAndroid Build Coastguard Worker const int size = varType.getArraySize();
1076*35238bceSAndroid Build Coastguard Worker const string arrayRootName = string("") + varName + "[0]";
1077*35238bceSAndroid Build Coastguard Worker vector<bool> isElemActive;
1078*35238bceSAndroid Build Coastguard Worker
1079*35238bceSAndroid Build Coastguard Worker for (int elemNdx = 0; elemNdx < varType.getArraySize(); elemNdx++)
1080*35238bceSAndroid Build Coastguard Worker {
1081*35238bceSAndroid Build Coastguard Worker const string indexedName = string("") + varName + "[" + de::toString(elemNdx) + "]";
1082*35238bceSAndroid Build Coastguard Worker const bool isCurElemActive =
1083*35238bceSAndroid Build Coastguard Worker isParentActive &&
1084*35238bceSAndroid Build Coastguard Worker (m_features & FEATURE_UNIFORMUSAGE_EVERY_OTHER ? basicUniformsDst.size() % 2 == 0 : true) &&
1085*35238bceSAndroid Build Coastguard Worker (m_features & FEATURE_ARRAYUSAGE_ONLY_MIDDLE_INDEX ? elemNdx == size / 2 : true);
1086*35238bceSAndroid Build Coastguard Worker
1087*35238bceSAndroid Build Coastguard Worker isElemActive.push_back(isCurElemActive);
1088*35238bceSAndroid Build Coastguard Worker
1089*35238bceSAndroid Build Coastguard Worker if (varType.getElementType().isBasicType())
1090*35238bceSAndroid Build Coastguard Worker {
1091*35238bceSAndroid Build Coastguard Worker // \note We don't want separate entries in basicUniformReportsDst for elements of basic-type arrays.
1092*35238bceSAndroid Build Coastguard Worker const glu::DataType elemBasicType = varType.getElementType().getBasicType();
1093*35238bceSAndroid Build Coastguard Worker const VarValue value = m_features & FEATURE_UNIFORMVALUE_ZERO ?
1094*35238bceSAndroid Build Coastguard Worker generateZeroVarValue(elemBasicType) :
1095*35238bceSAndroid Build Coastguard Worker glu::isDataTypeSampler(elemBasicType) ?
1096*35238bceSAndroid Build Coastguard Worker generateRandomVarValue(elemBasicType, rnd, samplerUnitCounter++) :
1097*35238bceSAndroid Build Coastguard Worker generateRandomVarValue(elemBasicType, rnd);
1098*35238bceSAndroid Build Coastguard Worker
1099*35238bceSAndroid Build Coastguard Worker basicUniformsDst.push_back(BasicUniform(indexedName.c_str(), elemBasicType, isCurElemActive, value,
1100*35238bceSAndroid Build Coastguard Worker arrayRootName.c_str(), elemNdx, size));
1101*35238bceSAndroid Build Coastguard Worker }
1102*35238bceSAndroid Build Coastguard Worker else
1103*35238bceSAndroid Build Coastguard Worker generateBasicUniforms(basicUniformsDst, basicUniformReportsDst, varType.getElementType(),
1104*35238bceSAndroid Build Coastguard Worker indexedName.c_str(), isCurElemActive, samplerUnitCounter, rnd);
1105*35238bceSAndroid Build Coastguard Worker }
1106*35238bceSAndroid Build Coastguard Worker
1107*35238bceSAndroid Build Coastguard Worker if (varType.getElementType().isBasicType())
1108*35238bceSAndroid Build Coastguard Worker {
1109*35238bceSAndroid Build Coastguard Worker int minSize;
1110*35238bceSAndroid Build Coastguard Worker for (minSize = varType.getArraySize(); minSize > 0 && !isElemActive[minSize - 1]; minSize--)
1111*35238bceSAndroid Build Coastguard Worker ;
1112*35238bceSAndroid Build Coastguard Worker
1113*35238bceSAndroid Build Coastguard Worker basicUniformReportsDst.push_back(BasicUniformReportRef(arrayRootName.c_str(), minSize, size,
1114*35238bceSAndroid Build Coastguard Worker varType.getElementType().getBasicType(),
1115*35238bceSAndroid Build Coastguard Worker isParentActive && minSize > 0));
1116*35238bceSAndroid Build Coastguard Worker }
1117*35238bceSAndroid Build Coastguard Worker }
1118*35238bceSAndroid Build Coastguard Worker else
1119*35238bceSAndroid Build Coastguard Worker {
1120*35238bceSAndroid Build Coastguard Worker DE_ASSERT(varType.isStructType());
1121*35238bceSAndroid Build Coastguard Worker
1122*35238bceSAndroid Build Coastguard Worker const StructType &structType = *varType.getStructPtr();
1123*35238bceSAndroid Build Coastguard Worker
1124*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < structType.getNumMembers(); i++)
1125*35238bceSAndroid Build Coastguard Worker {
1126*35238bceSAndroid Build Coastguard Worker const glu::StructMember &member = structType.getMember(i);
1127*35238bceSAndroid Build Coastguard Worker const string memberFullName = string("") + varName + "." + member.getName();
1128*35238bceSAndroid Build Coastguard Worker
1129*35238bceSAndroid Build Coastguard Worker generateBasicUniforms(basicUniformsDst, basicUniformReportsDst, member.getType(), memberFullName.c_str(),
1130*35238bceSAndroid Build Coastguard Worker isParentActive, samplerUnitCounter, rnd);
1131*35238bceSAndroid Build Coastguard Worker }
1132*35238bceSAndroid Build Coastguard Worker }
1133*35238bceSAndroid Build Coastguard Worker }
1134*35238bceSAndroid Build Coastguard Worker
writeUniformDefinitions(std::ostringstream & dst) const1135*35238bceSAndroid Build Coastguard Worker void UniformCase::writeUniformDefinitions(std::ostringstream &dst) const
1136*35238bceSAndroid Build Coastguard Worker {
1137*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniformCollection->getNumStructTypes(); i++)
1138*35238bceSAndroid Build Coastguard Worker dst << glu::declare(m_uniformCollection->getStructType(i)) << ";\n";
1139*35238bceSAndroid Build Coastguard Worker
1140*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniformCollection->getNumUniforms(); i++)
1141*35238bceSAndroid Build Coastguard Worker dst << "uniform "
1142*35238bceSAndroid Build Coastguard Worker << glu::declare(m_uniformCollection->getUniform(i).type, m_uniformCollection->getUniform(i).name.c_str())
1143*35238bceSAndroid Build Coastguard Worker << ";\n";
1144*35238bceSAndroid Build Coastguard Worker
1145*35238bceSAndroid Build Coastguard Worker dst << "\n";
1146*35238bceSAndroid Build Coastguard Worker
1147*35238bceSAndroid Build Coastguard Worker {
1148*35238bceSAndroid Build Coastguard Worker static const struct
1149*35238bceSAndroid Build Coastguard Worker {
1150*35238bceSAndroid Build Coastguard Worker dataTypePredicate requiringTypes[2];
1151*35238bceSAndroid Build Coastguard Worker const char *definition;
1152*35238bceSAndroid Build Coastguard Worker } compareFuncs[] = {
1153*35238bceSAndroid Build Coastguard Worker {{glu::isDataTypeFloatOrVec, glu::isDataTypeMatrix},
1154*35238bceSAndroid Build Coastguard Worker "mediump float compare_float (mediump float a, mediump float b) { return abs(a - b) < 0.05 ? 1.0 : "
1155*35238bceSAndroid Build Coastguard Worker "0.0; }"},
1156*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_VEC2>, dataTypeIsMatrixWithNRows<2>},
1157*35238bceSAndroid Build Coastguard Worker "mediump float compare_vec2 (mediump vec2 a, mediump vec2 b) { return compare_float(a.x, "
1158*35238bceSAndroid Build Coastguard Worker "b.x)*compare_float(a.y, b.y); }"},
1159*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_VEC3>, dataTypeIsMatrixWithNRows<3>},
1160*35238bceSAndroid Build Coastguard Worker "mediump float compare_vec3 (mediump vec3 a, mediump vec3 b) { return compare_float(a.x, "
1161*35238bceSAndroid Build Coastguard Worker "b.x)*compare_float(a.y, b.y)*compare_float(a.z, b.z); }"},
1162*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_VEC4>, dataTypeIsMatrixWithNRows<4>},
1163*35238bceSAndroid Build Coastguard Worker "mediump float compare_vec4 (mediump vec4 a, mediump vec4 b) { return compare_float(a.x, "
1164*35238bceSAndroid Build Coastguard Worker "b.x)*compare_float(a.y, b.y)*compare_float(a.z, b.z)*compare_float(a.w, b.w); }"},
1165*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_MAT2>, dataTypeEquals<glu::TYPE_INVALID>},
1166*35238bceSAndroid Build Coastguard Worker "mediump float compare_mat2 (mediump mat2 a, mediump mat2 b) { return compare_vec2(a[0], "
1167*35238bceSAndroid Build Coastguard Worker "b[0])*compare_vec2(a[1], b[1]); }"},
1168*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_MAT3>, dataTypeEquals<glu::TYPE_INVALID>},
1169*35238bceSAndroid Build Coastguard Worker "mediump float compare_mat3 (mediump mat3 a, mediump mat3 b) { return compare_vec3(a[0], "
1170*35238bceSAndroid Build Coastguard Worker "b[0])*compare_vec3(a[1], b[1])*compare_vec3(a[2], b[2]); }"},
1171*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_FLOAT_MAT4>, dataTypeEquals<glu::TYPE_INVALID>},
1172*35238bceSAndroid Build Coastguard Worker "mediump float compare_mat4 (mediump mat4 a, mediump mat4 b) { return compare_vec4(a[0], "
1173*35238bceSAndroid Build Coastguard Worker "b[0])*compare_vec4(a[1], b[1])*compare_vec4(a[2], b[2])*compare_vec4(a[3], b[3]); }"},
1174*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_INT>, dataTypeEquals<glu::TYPE_INVALID>},
1175*35238bceSAndroid Build Coastguard Worker "mediump float compare_int (mediump int a, mediump int b) { return a == b ? 1.0 : 0.0; }"},
1176*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_INT_VEC2>, dataTypeEquals<glu::TYPE_INVALID>},
1177*35238bceSAndroid Build Coastguard Worker "mediump float compare_ivec2 (mediump ivec2 a, mediump ivec2 b) { return a == b ? 1.0 : 0.0; }"},
1178*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_INT_VEC3>, dataTypeEquals<glu::TYPE_INVALID>},
1179*35238bceSAndroid Build Coastguard Worker "mediump float compare_ivec3 (mediump ivec3 a, mediump ivec3 b) { return a == b ? 1.0 : 0.0; }"},
1180*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_INT_VEC4>, dataTypeEquals<glu::TYPE_INVALID>},
1181*35238bceSAndroid Build Coastguard Worker "mediump float compare_ivec4 (mediump ivec4 a, mediump ivec4 b) { return a == b ? 1.0 : 0.0; }"},
1182*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_BOOL>, dataTypeEquals<glu::TYPE_INVALID>},
1183*35238bceSAndroid Build Coastguard Worker "mediump float compare_bool (bool a, bool b) { return a == b ? 1.0 : 0.0; }"},
1184*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_BOOL_VEC2>, dataTypeEquals<glu::TYPE_INVALID>},
1185*35238bceSAndroid Build Coastguard Worker "mediump float compare_bvec2 (bvec2 a, bvec2 b) { return a == b ? 1.0 : 0.0; }"},
1186*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_BOOL_VEC3>, dataTypeEquals<glu::TYPE_INVALID>},
1187*35238bceSAndroid Build Coastguard Worker "mediump float compare_bvec3 (bvec3 a, bvec3 b) { return a == b ? 1.0 : 0.0; }"},
1188*35238bceSAndroid Build Coastguard Worker {{dataTypeEquals<glu::TYPE_BOOL_VEC4>, dataTypeEquals<glu::TYPE_INVALID>},
1189*35238bceSAndroid Build Coastguard Worker "mediump float compare_bvec4 (bvec4 a, bvec4 b) { return a == b ? 1.0 : 0.0; }"}};
1190*35238bceSAndroid Build Coastguard Worker
1191*35238bceSAndroid Build Coastguard Worker const bool containsSamplers = !m_uniformCollection->getSamplerTypes().empty();
1192*35238bceSAndroid Build Coastguard Worker
1193*35238bceSAndroid Build Coastguard Worker for (int compFuncNdx = 0; compFuncNdx < DE_LENGTH_OF_ARRAY(compareFuncs); compFuncNdx++)
1194*35238bceSAndroid Build Coastguard Worker {
1195*35238bceSAndroid Build Coastguard Worker const dataTypePredicate(&typeReq)[2] = compareFuncs[compFuncNdx].requiringTypes;
1196*35238bceSAndroid Build Coastguard Worker const bool containsTypeSampler =
1197*35238bceSAndroid Build Coastguard Worker containsSamplers && (typeReq[0](glu::TYPE_FLOAT_VEC4) || typeReq[1](glu::TYPE_FLOAT_VEC4));
1198*35238bceSAndroid Build Coastguard Worker
1199*35238bceSAndroid Build Coastguard Worker if (containsTypeSampler || m_uniformCollection->containsMatchingBasicType(typeReq[0]) ||
1200*35238bceSAndroid Build Coastguard Worker m_uniformCollection->containsMatchingBasicType(typeReq[1]))
1201*35238bceSAndroid Build Coastguard Worker dst << compareFuncs[compFuncNdx].definition << "\n";
1202*35238bceSAndroid Build Coastguard Worker }
1203*35238bceSAndroid Build Coastguard Worker }
1204*35238bceSAndroid Build Coastguard Worker }
1205*35238bceSAndroid Build Coastguard Worker
writeUniformCompareExpr(std::ostringstream & dst,const BasicUniform & uniform) const1206*35238bceSAndroid Build Coastguard Worker void UniformCase::writeUniformCompareExpr(std::ostringstream &dst, const BasicUniform &uniform) const
1207*35238bceSAndroid Build Coastguard Worker {
1208*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeSampler(uniform.type))
1209*35238bceSAndroid Build Coastguard Worker {
1210*35238bceSAndroid Build Coastguard Worker dst << "compare_vec4(" << (uniform.type == glu::TYPE_SAMPLER_2D ? "texture2D" : "textureCube") << "("
1211*35238bceSAndroid Build Coastguard Worker << uniform.name << ", vec" << getSamplerNumLookupDimensions(uniform.type) << "(0.0))";
1212*35238bceSAndroid Build Coastguard Worker }
1213*35238bceSAndroid Build Coastguard Worker else
1214*35238bceSAndroid Build Coastguard Worker dst << "compare_" << glu::getDataTypeName(uniform.type) << "(" << uniform.name;
1215*35238bceSAndroid Build Coastguard Worker
1216*35238bceSAndroid Build Coastguard Worker dst << ", " << shaderVarValueStr(uniform.finalValue) << ")";
1217*35238bceSAndroid Build Coastguard Worker }
1218*35238bceSAndroid Build Coastguard Worker
writeUniformComparisons(std::ostringstream & dst,const vector<BasicUniform> & basicUniforms,const char * const variableName) const1219*35238bceSAndroid Build Coastguard Worker void UniformCase::writeUniformComparisons(std::ostringstream &dst, const vector<BasicUniform> &basicUniforms,
1220*35238bceSAndroid Build Coastguard Worker const char *const variableName) const
1221*35238bceSAndroid Build Coastguard Worker {
1222*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)basicUniforms.size(); i++)
1223*35238bceSAndroid Build Coastguard Worker {
1224*35238bceSAndroid Build Coastguard Worker const BasicUniform &unif = basicUniforms[i];
1225*35238bceSAndroid Build Coastguard Worker
1226*35238bceSAndroid Build Coastguard Worker if (unif.isUsedInShader)
1227*35238bceSAndroid Build Coastguard Worker {
1228*35238bceSAndroid Build Coastguard Worker dst << "\t" << variableName << " *= ";
1229*35238bceSAndroid Build Coastguard Worker writeUniformCompareExpr(dst, basicUniforms[i]);
1230*35238bceSAndroid Build Coastguard Worker dst << ";\n";
1231*35238bceSAndroid Build Coastguard Worker }
1232*35238bceSAndroid Build Coastguard Worker else
1233*35238bceSAndroid Build Coastguard Worker dst << "\t// UNUSED: " << basicUniforms[i].name << "\n";
1234*35238bceSAndroid Build Coastguard Worker }
1235*35238bceSAndroid Build Coastguard Worker }
1236*35238bceSAndroid Build Coastguard Worker
generateVertexSource(const vector<BasicUniform> & basicUniforms) const1237*35238bceSAndroid Build Coastguard Worker string UniformCase::generateVertexSource(const vector<BasicUniform> &basicUniforms) const
1238*35238bceSAndroid Build Coastguard Worker {
1239*35238bceSAndroid Build Coastguard Worker const bool isVertexCase = m_caseShaderType == CASESHADERTYPE_VERTEX || m_caseShaderType == CASESHADERTYPE_BOTH;
1240*35238bceSAndroid Build Coastguard Worker std::ostringstream result;
1241*35238bceSAndroid Build Coastguard Worker
1242*35238bceSAndroid Build Coastguard Worker result << "attribute highp vec4 a_position;\n"
1243*35238bceSAndroid Build Coastguard Worker "varying mediump float v_vtxOut;\n"
1244*35238bceSAndroid Build Coastguard Worker "\n";
1245*35238bceSAndroid Build Coastguard Worker
1246*35238bceSAndroid Build Coastguard Worker if (isVertexCase)
1247*35238bceSAndroid Build Coastguard Worker writeUniformDefinitions(result);
1248*35238bceSAndroid Build Coastguard Worker
1249*35238bceSAndroid Build Coastguard Worker result << "\n"
1250*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1251*35238bceSAndroid Build Coastguard Worker "{\n"
1252*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
1253*35238bceSAndroid Build Coastguard Worker " v_vtxOut = 1.0;\n";
1254*35238bceSAndroid Build Coastguard Worker
1255*35238bceSAndroid Build Coastguard Worker if (isVertexCase)
1256*35238bceSAndroid Build Coastguard Worker writeUniformComparisons(result, basicUniforms, "v_vtxOut");
1257*35238bceSAndroid Build Coastguard Worker
1258*35238bceSAndroid Build Coastguard Worker result << "}\n";
1259*35238bceSAndroid Build Coastguard Worker
1260*35238bceSAndroid Build Coastguard Worker return result.str();
1261*35238bceSAndroid Build Coastguard Worker }
1262*35238bceSAndroid Build Coastguard Worker
generateFragmentSource(const vector<BasicUniform> & basicUniforms) const1263*35238bceSAndroid Build Coastguard Worker string UniformCase::generateFragmentSource(const vector<BasicUniform> &basicUniforms) const
1264*35238bceSAndroid Build Coastguard Worker {
1265*35238bceSAndroid Build Coastguard Worker const bool isFragmentCase = m_caseShaderType == CASESHADERTYPE_FRAGMENT || m_caseShaderType == CASESHADERTYPE_BOTH;
1266*35238bceSAndroid Build Coastguard Worker std::ostringstream result;
1267*35238bceSAndroid Build Coastguard Worker
1268*35238bceSAndroid Build Coastguard Worker result << "varying mediump float v_vtxOut;\n"
1269*35238bceSAndroid Build Coastguard Worker "\n";
1270*35238bceSAndroid Build Coastguard Worker
1271*35238bceSAndroid Build Coastguard Worker if (isFragmentCase)
1272*35238bceSAndroid Build Coastguard Worker writeUniformDefinitions(result);
1273*35238bceSAndroid Build Coastguard Worker
1274*35238bceSAndroid Build Coastguard Worker result << "\n"
1275*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1276*35238bceSAndroid Build Coastguard Worker "{\n"
1277*35238bceSAndroid Build Coastguard Worker " mediump float result = v_vtxOut;\n";
1278*35238bceSAndroid Build Coastguard Worker
1279*35238bceSAndroid Build Coastguard Worker if (isFragmentCase)
1280*35238bceSAndroid Build Coastguard Worker writeUniformComparisons(result, basicUniforms, "result");
1281*35238bceSAndroid Build Coastguard Worker
1282*35238bceSAndroid Build Coastguard Worker result << " gl_FragColor = vec4(result, result, result, 1.0);\n"
1283*35238bceSAndroid Build Coastguard Worker "}\n";
1284*35238bceSAndroid Build Coastguard Worker
1285*35238bceSAndroid Build Coastguard Worker return result.str();
1286*35238bceSAndroid Build Coastguard Worker }
1287*35238bceSAndroid Build Coastguard Worker
setupTexture(const VarValue & value)1288*35238bceSAndroid Build Coastguard Worker void UniformCase::setupTexture(const VarValue &value)
1289*35238bceSAndroid Build Coastguard Worker {
1290*35238bceSAndroid Build Coastguard Worker enableLogging(false);
1291*35238bceSAndroid Build Coastguard Worker
1292*35238bceSAndroid Build Coastguard Worker const int width = 32;
1293*35238bceSAndroid Build Coastguard Worker const int height = 32;
1294*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 color = vec4FromPtr(&value.val.samplerV.fillColor[0]);
1295*35238bceSAndroid Build Coastguard Worker
1296*35238bceSAndroid Build Coastguard Worker if (value.type == glu::TYPE_SAMPLER_2D)
1297*35238bceSAndroid Build Coastguard Worker {
1298*35238bceSAndroid Build Coastguard Worker glu::Texture2D *texture =
1299*35238bceSAndroid Build Coastguard Worker new glu::Texture2D(m_context.getRenderContext(), GL_RGBA, GL_UNSIGNED_BYTE, width, height);
1300*35238bceSAndroid Build Coastguard Worker tcu::Texture2D &refTexture = texture->getRefTexture();
1301*35238bceSAndroid Build Coastguard Worker m_textures2d.push_back(texture);
1302*35238bceSAndroid Build Coastguard Worker
1303*35238bceSAndroid Build Coastguard Worker refTexture.allocLevel(0);
1304*35238bceSAndroid Build Coastguard Worker fillWithColor(refTexture.getLevel(0), color);
1305*35238bceSAndroid Build Coastguard Worker
1306*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glActiveTexture(GL_TEXTURE0 + value.val.samplerV.unit));
1307*35238bceSAndroid Build Coastguard Worker m_filledTextureUnits.push_back(value.val.samplerV.unit);
1308*35238bceSAndroid Build Coastguard Worker texture->upload();
1309*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1310*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1311*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1312*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
1313*35238bceSAndroid Build Coastguard Worker }
1314*35238bceSAndroid Build Coastguard Worker else if (value.type == glu::TYPE_SAMPLER_CUBE)
1315*35238bceSAndroid Build Coastguard Worker {
1316*35238bceSAndroid Build Coastguard Worker DE_ASSERT(width == height);
1317*35238bceSAndroid Build Coastguard Worker
1318*35238bceSAndroid Build Coastguard Worker glu::TextureCube *texture =
1319*35238bceSAndroid Build Coastguard Worker new glu::TextureCube(m_context.getRenderContext(), GL_RGBA, GL_UNSIGNED_BYTE, width);
1320*35238bceSAndroid Build Coastguard Worker tcu::TextureCube &refTexture = texture->getRefTexture();
1321*35238bceSAndroid Build Coastguard Worker m_texturesCube.push_back(texture);
1322*35238bceSAndroid Build Coastguard Worker
1323*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < (int)tcu::CUBEFACE_LAST; face++)
1324*35238bceSAndroid Build Coastguard Worker {
1325*35238bceSAndroid Build Coastguard Worker refTexture.allocLevel((tcu::CubeFace)face, 0);
1326*35238bceSAndroid Build Coastguard Worker fillWithColor(refTexture.getLevelFace(0, (tcu::CubeFace)face), color);
1327*35238bceSAndroid Build Coastguard Worker }
1328*35238bceSAndroid Build Coastguard Worker
1329*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glActiveTexture(GL_TEXTURE0 + value.val.samplerV.unit));
1330*35238bceSAndroid Build Coastguard Worker m_filledTextureUnits.push_back(value.val.samplerV.unit);
1331*35238bceSAndroid Build Coastguard Worker texture->upload();
1332*35238bceSAndroid Build Coastguard Worker
1333*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1334*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1335*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1336*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
1337*35238bceSAndroid Build Coastguard Worker }
1338*35238bceSAndroid Build Coastguard Worker else
1339*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1340*35238bceSAndroid Build Coastguard Worker
1341*35238bceSAndroid Build Coastguard Worker enableLogging(true);
1342*35238bceSAndroid Build Coastguard Worker }
1343*35238bceSAndroid Build Coastguard Worker
getActiveUniforms(vector<BasicUniformReportGL> & basicUniformReportsDst,const vector<BasicUniformReportRef> & basicUniformReportsRef,const uint32_t programGL)1344*35238bceSAndroid Build Coastguard Worker bool UniformCase::getActiveUniforms(vector<BasicUniformReportGL> &basicUniformReportsDst,
1345*35238bceSAndroid Build Coastguard Worker const vector<BasicUniformReportRef> &basicUniformReportsRef,
1346*35238bceSAndroid Build Coastguard Worker const uint32_t programGL)
1347*35238bceSAndroid Build Coastguard Worker {
1348*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1349*35238bceSAndroid Build Coastguard Worker GLint numActiveUniforms = 0;
1350*35238bceSAndroid Build Coastguard Worker GLint uniformMaxNameLength = 0;
1351*35238bceSAndroid Build Coastguard Worker vector<char> nameBuffer;
1352*35238bceSAndroid Build Coastguard Worker bool success = true;
1353*35238bceSAndroid Build Coastguard Worker
1354*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetProgramiv(programGL, GL_ACTIVE_UNIFORMS, &numActiveUniforms));
1355*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Number of active uniforms reported: " << numActiveUniforms << TestLog::EndMessage;
1356*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetProgramiv(programGL, GL_ACTIVE_UNIFORM_MAX_LENGTH, &uniformMaxNameLength));
1357*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Maximum uniform name length reported: " << uniformMaxNameLength
1358*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1359*35238bceSAndroid Build Coastguard Worker nameBuffer.resize(uniformMaxNameLength);
1360*35238bceSAndroid Build Coastguard Worker
1361*35238bceSAndroid Build Coastguard Worker for (int unifNdx = 0; unifNdx < numActiveUniforms; unifNdx++)
1362*35238bceSAndroid Build Coastguard Worker {
1363*35238bceSAndroid Build Coastguard Worker GLsizei reportedNameLength = 0;
1364*35238bceSAndroid Build Coastguard Worker GLint reportedSize = -1;
1365*35238bceSAndroid Build Coastguard Worker GLenum reportedTypeGL = GL_NONE;
1366*35238bceSAndroid Build Coastguard Worker
1367*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetActiveUniform(programGL, (GLuint)unifNdx, (GLsizei)uniformMaxNameLength,
1368*35238bceSAndroid Build Coastguard Worker &reportedNameLength, &reportedSize, &reportedTypeGL, &nameBuffer[0]));
1369*35238bceSAndroid Build Coastguard Worker
1370*35238bceSAndroid Build Coastguard Worker const glu::DataType reportedType = glu::getDataTypeFromGLType(reportedTypeGL);
1371*35238bceSAndroid Build Coastguard Worker const string reportedNameStr(&nameBuffer[0]);
1372*35238bceSAndroid Build Coastguard Worker
1373*35238bceSAndroid Build Coastguard Worker TCU_CHECK_MSG(reportedType != glu::TYPE_LAST, "Invalid uniform type");
1374*35238bceSAndroid Build Coastguard Worker
1375*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Got name = " << reportedNameStr << ", name length = " << reportedNameLength
1376*35238bceSAndroid Build Coastguard Worker << ", size = " << reportedSize << ", type = " << glu::getDataTypeName(reportedType) << TestLog::EndMessage;
1377*35238bceSAndroid Build Coastguard Worker
1378*35238bceSAndroid Build Coastguard Worker if ((GLsizei)reportedNameStr.length() != reportedNameLength)
1379*35238bceSAndroid Build Coastguard Worker {
1380*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: wrong name length reported, should be " << reportedNameStr.length()
1381*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1382*35238bceSAndroid Build Coastguard Worker success = false;
1383*35238bceSAndroid Build Coastguard Worker }
1384*35238bceSAndroid Build Coastguard Worker
1385*35238bceSAndroid Build Coastguard Worker if (!deStringBeginsWith(reportedNameStr.c_str(), "gl_")) // Ignore built-in uniforms.
1386*35238bceSAndroid Build Coastguard Worker {
1387*35238bceSAndroid Build Coastguard Worker int referenceNdx;
1388*35238bceSAndroid Build Coastguard Worker for (referenceNdx = 0; referenceNdx < (int)basicUniformReportsRef.size(); referenceNdx++)
1389*35238bceSAndroid Build Coastguard Worker {
1390*35238bceSAndroid Build Coastguard Worker if (basicUniformReportsRef[referenceNdx].name == reportedNameStr)
1391*35238bceSAndroid Build Coastguard Worker break;
1392*35238bceSAndroid Build Coastguard Worker }
1393*35238bceSAndroid Build Coastguard Worker
1394*35238bceSAndroid Build Coastguard Worker if (referenceNdx >= (int)basicUniformReportsRef.size())
1395*35238bceSAndroid Build Coastguard Worker {
1396*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: invalid non-built-in uniform name reported"
1397*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1398*35238bceSAndroid Build Coastguard Worker success = false;
1399*35238bceSAndroid Build Coastguard Worker }
1400*35238bceSAndroid Build Coastguard Worker else
1401*35238bceSAndroid Build Coastguard Worker {
1402*35238bceSAndroid Build Coastguard Worker const BasicUniformReportRef &reference = basicUniformReportsRef[referenceNdx];
1403*35238bceSAndroid Build Coastguard Worker
1404*35238bceSAndroid Build Coastguard Worker DE_ASSERT(reference.type != glu::TYPE_LAST);
1405*35238bceSAndroid Build Coastguard Worker DE_ASSERT(reference.minSize >= 1 || (reference.minSize == 0 && !reference.isUsedInShader));
1406*35238bceSAndroid Build Coastguard Worker DE_ASSERT(reference.minSize <= reference.maxSize);
1407*35238bceSAndroid Build Coastguard Worker
1408*35238bceSAndroid Build Coastguard Worker if (BasicUniformReportGL::findWithName(basicUniformReportsDst, reportedNameStr.c_str()) !=
1409*35238bceSAndroid Build Coastguard Worker basicUniformReportsDst.end())
1410*35238bceSAndroid Build Coastguard Worker {
1411*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: same uniform name reported twice" << TestLog::EndMessage;
1412*35238bceSAndroid Build Coastguard Worker success = false;
1413*35238bceSAndroid Build Coastguard Worker }
1414*35238bceSAndroid Build Coastguard Worker
1415*35238bceSAndroid Build Coastguard Worker basicUniformReportsDst.push_back(BasicUniformReportGL(reportedNameStr.c_str(), reportedNameLength,
1416*35238bceSAndroid Build Coastguard Worker reportedSize, reportedType, unifNdx));
1417*35238bceSAndroid Build Coastguard Worker
1418*35238bceSAndroid Build Coastguard Worker if (reportedType != reference.type)
1419*35238bceSAndroid Build Coastguard Worker {
1420*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: wrong type reported, should be "
1421*35238bceSAndroid Build Coastguard Worker << glu::getDataTypeName(reference.type) << TestLog::EndMessage;
1422*35238bceSAndroid Build Coastguard Worker success = false;
1423*35238bceSAndroid Build Coastguard Worker }
1424*35238bceSAndroid Build Coastguard Worker if (reportedSize < reference.minSize || reportedSize > reference.maxSize)
1425*35238bceSAndroid Build Coastguard Worker {
1426*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: wrong size reported, should be "
1427*35238bceSAndroid Build Coastguard Worker << (reference.minSize == reference.maxSize ?
1428*35238bceSAndroid Build Coastguard Worker de::toString(reference.minSize) :
1429*35238bceSAndroid Build Coastguard Worker "in the range [" + de::toString(reference.minSize) + ", " +
1430*35238bceSAndroid Build Coastguard Worker de::toString(reference.maxSize) + "]")
1431*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1432*35238bceSAndroid Build Coastguard Worker
1433*35238bceSAndroid Build Coastguard Worker success = false;
1434*35238bceSAndroid Build Coastguard Worker }
1435*35238bceSAndroid Build Coastguard Worker }
1436*35238bceSAndroid Build Coastguard Worker }
1437*35238bceSAndroid Build Coastguard Worker }
1438*35238bceSAndroid Build Coastguard Worker
1439*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)basicUniformReportsRef.size(); i++)
1440*35238bceSAndroid Build Coastguard Worker {
1441*35238bceSAndroid Build Coastguard Worker const BasicUniformReportRef &expected = basicUniformReportsRef[i];
1442*35238bceSAndroid Build Coastguard Worker if (expected.isUsedInShader &&
1443*35238bceSAndroid Build Coastguard Worker BasicUniformReportGL::findWithName(basicUniformReportsDst, expected.name.c_str()) ==
1444*35238bceSAndroid Build Coastguard Worker basicUniformReportsDst.end())
1445*35238bceSAndroid Build Coastguard Worker {
1446*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: uniform with name " << expected.name << " was not reported by GL"
1447*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1448*35238bceSAndroid Build Coastguard Worker success = false;
1449*35238bceSAndroid Build Coastguard Worker }
1450*35238bceSAndroid Build Coastguard Worker }
1451*35238bceSAndroid Build Coastguard Worker
1452*35238bceSAndroid Build Coastguard Worker return success;
1453*35238bceSAndroid Build Coastguard Worker }
1454*35238bceSAndroid Build Coastguard Worker
getUniforms(vector<VarValue> & valuesDst,const vector<BasicUniform> & basicUniforms,const uint32_t programGL)1455*35238bceSAndroid Build Coastguard Worker bool UniformCase::getUniforms(vector<VarValue> &valuesDst, const vector<BasicUniform> &basicUniforms,
1456*35238bceSAndroid Build Coastguard Worker const uint32_t programGL)
1457*35238bceSAndroid Build Coastguard Worker {
1458*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1459*35238bceSAndroid Build Coastguard Worker bool success = true;
1460*35238bceSAndroid Build Coastguard Worker
1461*35238bceSAndroid Build Coastguard Worker for (int unifNdx = 0; unifNdx < (int)basicUniforms.size(); unifNdx++)
1462*35238bceSAndroid Build Coastguard Worker {
1463*35238bceSAndroid Build Coastguard Worker const BasicUniform &uniform = basicUniforms[unifNdx];
1464*35238bceSAndroid Build Coastguard Worker const string queryName = m_features & FEATURE_ARRAY_FIRST_ELEM_NAME_NO_INDEX && uniform.elemNdx == 0 ?
1465*35238bceSAndroid Build Coastguard Worker beforeLast(uniform.name, '[') :
1466*35238bceSAndroid Build Coastguard Worker uniform.name;
1467*35238bceSAndroid Build Coastguard Worker const int location = glGetUniformLocation(programGL, queryName.c_str());
1468*35238bceSAndroid Build Coastguard Worker const int size = glu::getDataTypeScalarSize(uniform.type);
1469*35238bceSAndroid Build Coastguard Worker VarValue value;
1470*35238bceSAndroid Build Coastguard Worker
1471*35238bceSAndroid Build Coastguard Worker deMemset(&value, 0xcd, sizeof(value)); // Initialize to known garbage.
1472*35238bceSAndroid Build Coastguard Worker
1473*35238bceSAndroid Build Coastguard Worker if (location == -1)
1474*35238bceSAndroid Build Coastguard Worker {
1475*35238bceSAndroid Build Coastguard Worker value.type = glu::TYPE_INVALID;
1476*35238bceSAndroid Build Coastguard Worker valuesDst.push_back(value);
1477*35238bceSAndroid Build Coastguard Worker if (uniform.isUsedInShader)
1478*35238bceSAndroid Build Coastguard Worker {
1479*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: " << uniform.name << " was used in shader, but has location -1"
1480*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1481*35238bceSAndroid Build Coastguard Worker success = false;
1482*35238bceSAndroid Build Coastguard Worker }
1483*35238bceSAndroid Build Coastguard Worker continue;
1484*35238bceSAndroid Build Coastguard Worker }
1485*35238bceSAndroid Build Coastguard Worker
1486*35238bceSAndroid Build Coastguard Worker value.type = uniform.type;
1487*35238bceSAndroid Build Coastguard Worker
1488*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(sizeof(GLint) == sizeof(value.val.intV[0]));
1489*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(sizeof(GLfloat) == sizeof(value.val.floatV[0]));
1490*35238bceSAndroid Build Coastguard Worker
1491*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(uniform.type) || glu::isDataTypeMatrix(uniform.type))
1492*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetUniformfv(programGL, location, &value.val.floatV[0]));
1493*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(uniform.type))
1494*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetUniformiv(programGL, location, &value.val.intV[0]));
1495*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec(uniform.type))
1496*35238bceSAndroid Build Coastguard Worker {
1497*35238bceSAndroid Build Coastguard Worker if (m_features & FEATURE_BOOLEANAPITYPE_INT)
1498*35238bceSAndroid Build Coastguard Worker {
1499*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetUniformiv(programGL, location, &value.val.intV[0]));
1500*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
1501*35238bceSAndroid Build Coastguard Worker value.val.boolV[i] = value.val.intV[i] != 0;
1502*35238bceSAndroid Build Coastguard Worker }
1503*35238bceSAndroid Build Coastguard Worker else // Default: use float.
1504*35238bceSAndroid Build Coastguard Worker {
1505*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetUniformfv(programGL, location, &value.val.floatV[0]));
1506*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < size; i++)
1507*35238bceSAndroid Build Coastguard Worker value.val.boolV[i] = value.val.floatV[i] != 0.0f;
1508*35238bceSAndroid Build Coastguard Worker }
1509*35238bceSAndroid Build Coastguard Worker }
1510*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(uniform.type))
1511*35238bceSAndroid Build Coastguard Worker {
1512*35238bceSAndroid Build Coastguard Worker GLint unit = -1;
1513*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glGetUniformiv(programGL, location, &unit));
1514*35238bceSAndroid Build Coastguard Worker value.val.samplerV.unit = unit;
1515*35238bceSAndroid Build Coastguard Worker }
1516*35238bceSAndroid Build Coastguard Worker else
1517*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1518*35238bceSAndroid Build Coastguard Worker
1519*35238bceSAndroid Build Coastguard Worker valuesDst.push_back(value);
1520*35238bceSAndroid Build Coastguard Worker
1521*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Got " << uniform.name << " value " << apiVarValueStr(value)
1522*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1523*35238bceSAndroid Build Coastguard Worker }
1524*35238bceSAndroid Build Coastguard Worker
1525*35238bceSAndroid Build Coastguard Worker return success;
1526*35238bceSAndroid Build Coastguard Worker }
1527*35238bceSAndroid Build Coastguard Worker
checkUniformDefaultValues(const vector<VarValue> & values,const vector<BasicUniform> & basicUniforms)1528*35238bceSAndroid Build Coastguard Worker bool UniformCase::checkUniformDefaultValues(const vector<VarValue> &values, const vector<BasicUniform> &basicUniforms)
1529*35238bceSAndroid Build Coastguard Worker {
1530*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1531*35238bceSAndroid Build Coastguard Worker bool success = true;
1532*35238bceSAndroid Build Coastguard Worker
1533*35238bceSAndroid Build Coastguard Worker DE_ASSERT(values.size() == basicUniforms.size());
1534*35238bceSAndroid Build Coastguard Worker
1535*35238bceSAndroid Build Coastguard Worker for (int unifNdx = 0; unifNdx < (int)basicUniforms.size(); unifNdx++)
1536*35238bceSAndroid Build Coastguard Worker {
1537*35238bceSAndroid Build Coastguard Worker const BasicUniform &uniform = basicUniforms[unifNdx];
1538*35238bceSAndroid Build Coastguard Worker const VarValue &unifValue = values[unifNdx];
1539*35238bceSAndroid Build Coastguard Worker const int valSize = glu::getDataTypeScalarSize(uniform.type);
1540*35238bceSAndroid Build Coastguard Worker
1541*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Checking uniform " << uniform.name << TestLog::EndMessage;
1542*35238bceSAndroid Build Coastguard Worker
1543*35238bceSAndroid Build Coastguard Worker if (unifValue.type == glu::TYPE_INVALID) // This happens when glGetUniformLocation() returned -1.
1544*35238bceSAndroid Build Coastguard Worker continue;
1545*35238bceSAndroid Build Coastguard Worker
1546*35238bceSAndroid Build Coastguard Worker #define CHECK_UNIFORM(VAR_VALUE_MEMBER, ZERO) \
1547*35238bceSAndroid Build Coastguard Worker do \
1548*35238bceSAndroid Build Coastguard Worker { \
1549*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < valSize; i++) \
1550*35238bceSAndroid Build Coastguard Worker { \
1551*35238bceSAndroid Build Coastguard Worker if (unifValue.val.VAR_VALUE_MEMBER[i] != (ZERO)) \
1552*35238bceSAndroid Build Coastguard Worker { \
1553*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: uniform " << uniform.name << " has non-zero initial value" \
1554*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage; \
1555*35238bceSAndroid Build Coastguard Worker success = false; \
1556*35238bceSAndroid Build Coastguard Worker } \
1557*35238bceSAndroid Build Coastguard Worker } \
1558*35238bceSAndroid Build Coastguard Worker } while (false)
1559*35238bceSAndroid Build Coastguard Worker
1560*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(uniform.type) || glu::isDataTypeMatrix(uniform.type))
1561*35238bceSAndroid Build Coastguard Worker CHECK_UNIFORM(floatV, 0.0f);
1562*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(uniform.type))
1563*35238bceSAndroid Build Coastguard Worker CHECK_UNIFORM(intV, 0);
1564*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeBoolOrBVec(uniform.type))
1565*35238bceSAndroid Build Coastguard Worker CHECK_UNIFORM(boolV, false);
1566*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(uniform.type))
1567*35238bceSAndroid Build Coastguard Worker {
1568*35238bceSAndroid Build Coastguard Worker if (unifValue.val.samplerV.unit != 0)
1569*35238bceSAndroid Build Coastguard Worker {
1570*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: uniform " << uniform.name << " has non-zero initial value"
1571*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1572*35238bceSAndroid Build Coastguard Worker success = false;
1573*35238bceSAndroid Build Coastguard Worker }
1574*35238bceSAndroid Build Coastguard Worker }
1575*35238bceSAndroid Build Coastguard Worker else
1576*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1577*35238bceSAndroid Build Coastguard Worker
1578*35238bceSAndroid Build Coastguard Worker #undef CHECK_UNIFORM
1579*35238bceSAndroid Build Coastguard Worker }
1580*35238bceSAndroid Build Coastguard Worker
1581*35238bceSAndroid Build Coastguard Worker return success;
1582*35238bceSAndroid Build Coastguard Worker }
1583*35238bceSAndroid Build Coastguard Worker
assignUniforms(const vector<BasicUniform> & basicUniforms,uint32_t programGL,Random & rnd)1584*35238bceSAndroid Build Coastguard Worker void UniformCase::assignUniforms(const vector<BasicUniform> &basicUniforms, uint32_t programGL, Random &rnd)
1585*35238bceSAndroid Build Coastguard Worker {
1586*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1587*35238bceSAndroid Build Coastguard Worker const glu::DataType boolApiType = m_features & FEATURE_BOOLEANAPITYPE_INT ? glu::TYPE_INT : glu::TYPE_FLOAT;
1588*35238bceSAndroid Build Coastguard Worker
1589*35238bceSAndroid Build Coastguard Worker for (int unifNdx = 0; unifNdx < (int)basicUniforms.size(); unifNdx++)
1590*35238bceSAndroid Build Coastguard Worker {
1591*35238bceSAndroid Build Coastguard Worker const BasicUniform &uniform = basicUniforms[unifNdx];
1592*35238bceSAndroid Build Coastguard Worker const bool isArrayMember = uniform.elemNdx >= 0;
1593*35238bceSAndroid Build Coastguard Worker const string queryName = m_features & FEATURE_ARRAY_FIRST_ELEM_NAME_NO_INDEX && uniform.elemNdx == 0 ?
1594*35238bceSAndroid Build Coastguard Worker beforeLast(uniform.name, '[') :
1595*35238bceSAndroid Build Coastguard Worker uniform.name;
1596*35238bceSAndroid Build Coastguard Worker const int numValuesToAssign =
1597*35238bceSAndroid Build Coastguard Worker !isArrayMember ? 1 :
1598*35238bceSAndroid Build Coastguard Worker m_features & FEATURE_ARRAYASSIGN_FULL ? (uniform.elemNdx == 0 ? uniform.rootSize : 0) :
1599*35238bceSAndroid Build Coastguard Worker m_features & FEATURE_ARRAYASSIGN_BLOCKS_OF_TWO ? (uniform.elemNdx % 2 == 0 ? 2 : 0) :
1600*35238bceSAndroid Build Coastguard Worker /* Default: assign array elements separately */ 1;
1601*35238bceSAndroid Build Coastguard Worker
1602*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numValuesToAssign >= 0);
1603*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numValuesToAssign == 1 || isArrayMember);
1604*35238bceSAndroid Build Coastguard Worker
1605*35238bceSAndroid Build Coastguard Worker if (numValuesToAssign == 0)
1606*35238bceSAndroid Build Coastguard Worker {
1607*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Uniform " << uniform.name
1608*35238bceSAndroid Build Coastguard Worker << " is covered by another glUniform*v() call to the same array" << TestLog::EndMessage;
1609*35238bceSAndroid Build Coastguard Worker continue;
1610*35238bceSAndroid Build Coastguard Worker }
1611*35238bceSAndroid Build Coastguard Worker
1612*35238bceSAndroid Build Coastguard Worker const int location = glGetUniformLocation(programGL, queryName.c_str());
1613*35238bceSAndroid Build Coastguard Worker const int typeSize = glu::getDataTypeScalarSize(uniform.type);
1614*35238bceSAndroid Build Coastguard Worker const bool assignByValue =
1615*35238bceSAndroid Build Coastguard Worker m_features & FEATURE_UNIFORMFUNC_VALUE && !glu::isDataTypeMatrix(uniform.type) && numValuesToAssign == 1;
1616*35238bceSAndroid Build Coastguard Worker vector<VarValue> valuesToAssign;
1617*35238bceSAndroid Build Coastguard Worker
1618*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < numValuesToAssign; i++)
1619*35238bceSAndroid Build Coastguard Worker {
1620*35238bceSAndroid Build Coastguard Worker const string curName =
1621*35238bceSAndroid Build Coastguard Worker isArrayMember ? beforeLast(uniform.rootName, '[') + "[" + de::toString(uniform.elemNdx + i) + "]" :
1622*35238bceSAndroid Build Coastguard Worker uniform.name;
1623*35238bceSAndroid Build Coastguard Worker VarValue unifValue;
1624*35238bceSAndroid Build Coastguard Worker
1625*35238bceSAndroid Build Coastguard Worker if (isArrayMember)
1626*35238bceSAndroid Build Coastguard Worker {
1627*35238bceSAndroid Build Coastguard Worker const vector<BasicUniform>::const_iterator elemUnif =
1628*35238bceSAndroid Build Coastguard Worker BasicUniform::findWithName(basicUniforms, curName.c_str());
1629*35238bceSAndroid Build Coastguard Worker if (elemUnif == basicUniforms.end())
1630*35238bceSAndroid Build Coastguard Worker continue;
1631*35238bceSAndroid Build Coastguard Worker unifValue = elemUnif->finalValue;
1632*35238bceSAndroid Build Coastguard Worker }
1633*35238bceSAndroid Build Coastguard Worker else
1634*35238bceSAndroid Build Coastguard Worker unifValue = uniform.finalValue;
1635*35238bceSAndroid Build Coastguard Worker
1636*35238bceSAndroid Build Coastguard Worker const VarValue apiValue = glu::isDataTypeBoolOrBVec(unifValue.type) ?
1637*35238bceSAndroid Build Coastguard Worker getRandomBoolRepresentation(unifValue, boolApiType, rnd) :
1638*35238bceSAndroid Build Coastguard Worker glu::isDataTypeSampler(unifValue.type) ? getSamplerUnitValue(unifValue) :
1639*35238bceSAndroid Build Coastguard Worker unifValue;
1640*35238bceSAndroid Build Coastguard Worker
1641*35238bceSAndroid Build Coastguard Worker valuesToAssign.push_back(apiValue);
1642*35238bceSAndroid Build Coastguard Worker
1643*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeBoolOrBVec(uniform.type))
1644*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Using type " << glu::getDataTypeName(boolApiType)
1645*35238bceSAndroid Build Coastguard Worker << " to set boolean value " << apiVarValueStr(unifValue) << " for " << curName
1646*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1647*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(uniform.type))
1648*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Texture for the sampler uniform " << curName
1649*35238bceSAndroid Build Coastguard Worker << " will be filled with color " << apiVarValueStr(getSamplerFillValue(uniform.finalValue))
1650*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1651*35238bceSAndroid Build Coastguard Worker }
1652*35238bceSAndroid Build Coastguard Worker
1653*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!valuesToAssign.empty());
1654*35238bceSAndroid Build Coastguard Worker
1655*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeFloatOrVec(valuesToAssign[0].type))
1656*35238bceSAndroid Build Coastguard Worker {
1657*35238bceSAndroid Build Coastguard Worker if (assignByValue)
1658*35238bceSAndroid Build Coastguard Worker {
1659*35238bceSAndroid Build Coastguard Worker const float *const ptr = &valuesToAssign[0].val.floatV[0];
1660*35238bceSAndroid Build Coastguard Worker
1661*35238bceSAndroid Build Coastguard Worker switch (typeSize)
1662*35238bceSAndroid Build Coastguard Worker {
1663*35238bceSAndroid Build Coastguard Worker case 1:
1664*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1f(location, ptr[0]));
1665*35238bceSAndroid Build Coastguard Worker break;
1666*35238bceSAndroid Build Coastguard Worker case 2:
1667*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform2f(location, ptr[0], ptr[1]));
1668*35238bceSAndroid Build Coastguard Worker break;
1669*35238bceSAndroid Build Coastguard Worker case 3:
1670*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform3f(location, ptr[0], ptr[1], ptr[2]));
1671*35238bceSAndroid Build Coastguard Worker break;
1672*35238bceSAndroid Build Coastguard Worker case 4:
1673*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform4f(location, ptr[0], ptr[1], ptr[2], ptr[3]));
1674*35238bceSAndroid Build Coastguard Worker break;
1675*35238bceSAndroid Build Coastguard Worker default:
1676*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1677*35238bceSAndroid Build Coastguard Worker }
1678*35238bceSAndroid Build Coastguard Worker }
1679*35238bceSAndroid Build Coastguard Worker else
1680*35238bceSAndroid Build Coastguard Worker {
1681*35238bceSAndroid Build Coastguard Worker vector<float> buffer(valuesToAssign.size() * typeSize);
1682*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)buffer.size(); i++)
1683*35238bceSAndroid Build Coastguard Worker buffer[i] = valuesToAssign[i / typeSize].val.floatV[i % typeSize];
1684*35238bceSAndroid Build Coastguard Worker
1685*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(sizeof(GLfloat) == sizeof(buffer[0]));
1686*35238bceSAndroid Build Coastguard Worker switch (typeSize)
1687*35238bceSAndroid Build Coastguard Worker {
1688*35238bceSAndroid Build Coastguard Worker case 1:
1689*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1fv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1690*35238bceSAndroid Build Coastguard Worker break;
1691*35238bceSAndroid Build Coastguard Worker case 2:
1692*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform2fv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1693*35238bceSAndroid Build Coastguard Worker break;
1694*35238bceSAndroid Build Coastguard Worker case 3:
1695*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform3fv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1696*35238bceSAndroid Build Coastguard Worker break;
1697*35238bceSAndroid Build Coastguard Worker case 4:
1698*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform4fv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1699*35238bceSAndroid Build Coastguard Worker break;
1700*35238bceSAndroid Build Coastguard Worker default:
1701*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1702*35238bceSAndroid Build Coastguard Worker }
1703*35238bceSAndroid Build Coastguard Worker }
1704*35238bceSAndroid Build Coastguard Worker }
1705*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeMatrix(valuesToAssign[0].type))
1706*35238bceSAndroid Build Coastguard Worker {
1707*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!assignByValue);
1708*35238bceSAndroid Build Coastguard Worker
1709*35238bceSAndroid Build Coastguard Worker vector<float> buffer(valuesToAssign.size() * typeSize);
1710*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)buffer.size(); i++)
1711*35238bceSAndroid Build Coastguard Worker buffer[i] = valuesToAssign[i / typeSize].val.floatV[i % typeSize];
1712*35238bceSAndroid Build Coastguard Worker
1713*35238bceSAndroid Build Coastguard Worker switch (uniform.type)
1714*35238bceSAndroid Build Coastguard Worker {
1715*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT_MAT2:
1716*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniformMatrix2fv(location, (GLsizei)valuesToAssign.size(), GL_FALSE, &buffer[0]));
1717*35238bceSAndroid Build Coastguard Worker break;
1718*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT_MAT3:
1719*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniformMatrix3fv(location, (GLsizei)valuesToAssign.size(), GL_FALSE, &buffer[0]));
1720*35238bceSAndroid Build Coastguard Worker break;
1721*35238bceSAndroid Build Coastguard Worker case glu::TYPE_FLOAT_MAT4:
1722*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniformMatrix4fv(location, (GLsizei)valuesToAssign.size(), GL_FALSE, &buffer[0]));
1723*35238bceSAndroid Build Coastguard Worker break;
1724*35238bceSAndroid Build Coastguard Worker default:
1725*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1726*35238bceSAndroid Build Coastguard Worker }
1727*35238bceSAndroid Build Coastguard Worker }
1728*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeIntOrIVec(valuesToAssign[0].type))
1729*35238bceSAndroid Build Coastguard Worker {
1730*35238bceSAndroid Build Coastguard Worker if (assignByValue)
1731*35238bceSAndroid Build Coastguard Worker {
1732*35238bceSAndroid Build Coastguard Worker const int32_t *const ptr = &valuesToAssign[0].val.intV[0];
1733*35238bceSAndroid Build Coastguard Worker
1734*35238bceSAndroid Build Coastguard Worker switch (typeSize)
1735*35238bceSAndroid Build Coastguard Worker {
1736*35238bceSAndroid Build Coastguard Worker case 1:
1737*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1i(location, ptr[0]));
1738*35238bceSAndroid Build Coastguard Worker break;
1739*35238bceSAndroid Build Coastguard Worker case 2:
1740*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform2i(location, ptr[0], ptr[1]));
1741*35238bceSAndroid Build Coastguard Worker break;
1742*35238bceSAndroid Build Coastguard Worker case 3:
1743*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform3i(location, ptr[0], ptr[1], ptr[2]));
1744*35238bceSAndroid Build Coastguard Worker break;
1745*35238bceSAndroid Build Coastguard Worker case 4:
1746*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform4i(location, ptr[0], ptr[1], ptr[2], ptr[3]));
1747*35238bceSAndroid Build Coastguard Worker break;
1748*35238bceSAndroid Build Coastguard Worker default:
1749*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1750*35238bceSAndroid Build Coastguard Worker }
1751*35238bceSAndroid Build Coastguard Worker }
1752*35238bceSAndroid Build Coastguard Worker else
1753*35238bceSAndroid Build Coastguard Worker {
1754*35238bceSAndroid Build Coastguard Worker vector<int32_t> buffer(valuesToAssign.size() * typeSize);
1755*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)buffer.size(); i++)
1756*35238bceSAndroid Build Coastguard Worker buffer[i] = valuesToAssign[i / typeSize].val.intV[i % typeSize];
1757*35238bceSAndroid Build Coastguard Worker
1758*35238bceSAndroid Build Coastguard Worker DE_STATIC_ASSERT(sizeof(GLint) == sizeof(buffer[0]));
1759*35238bceSAndroid Build Coastguard Worker switch (typeSize)
1760*35238bceSAndroid Build Coastguard Worker {
1761*35238bceSAndroid Build Coastguard Worker case 1:
1762*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1iv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1763*35238bceSAndroid Build Coastguard Worker break;
1764*35238bceSAndroid Build Coastguard Worker case 2:
1765*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform2iv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1766*35238bceSAndroid Build Coastguard Worker break;
1767*35238bceSAndroid Build Coastguard Worker case 3:
1768*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform3iv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1769*35238bceSAndroid Build Coastguard Worker break;
1770*35238bceSAndroid Build Coastguard Worker case 4:
1771*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform4iv(location, (GLsizei)valuesToAssign.size(), &buffer[0]));
1772*35238bceSAndroid Build Coastguard Worker break;
1773*35238bceSAndroid Build Coastguard Worker default:
1774*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1775*35238bceSAndroid Build Coastguard Worker }
1776*35238bceSAndroid Build Coastguard Worker }
1777*35238bceSAndroid Build Coastguard Worker }
1778*35238bceSAndroid Build Coastguard Worker else if (glu::isDataTypeSampler(valuesToAssign[0].type))
1779*35238bceSAndroid Build Coastguard Worker {
1780*35238bceSAndroid Build Coastguard Worker if (assignByValue)
1781*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1i(location, uniform.finalValue.val.samplerV.unit));
1782*35238bceSAndroid Build Coastguard Worker else
1783*35238bceSAndroid Build Coastguard Worker {
1784*35238bceSAndroid Build Coastguard Worker const GLint unit = uniform.finalValue.val.samplerV.unit;
1785*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUniform1iv(location, (GLsizei)valuesToAssign.size(), &unit));
1786*35238bceSAndroid Build Coastguard Worker }
1787*35238bceSAndroid Build Coastguard Worker }
1788*35238bceSAndroid Build Coastguard Worker else
1789*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1790*35238bceSAndroid Build Coastguard Worker }
1791*35238bceSAndroid Build Coastguard Worker }
1792*35238bceSAndroid Build Coastguard Worker
compareUniformValues(const vector<VarValue> & values,const vector<BasicUniform> & basicUniforms)1793*35238bceSAndroid Build Coastguard Worker bool UniformCase::compareUniformValues(const vector<VarValue> &values, const vector<BasicUniform> &basicUniforms)
1794*35238bceSAndroid Build Coastguard Worker {
1795*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1796*35238bceSAndroid Build Coastguard Worker bool success = true;
1797*35238bceSAndroid Build Coastguard Worker
1798*35238bceSAndroid Build Coastguard Worker for (int unifNdx = 0; unifNdx < (int)basicUniforms.size(); unifNdx++)
1799*35238bceSAndroid Build Coastguard Worker {
1800*35238bceSAndroid Build Coastguard Worker const BasicUniform &uniform = basicUniforms[unifNdx];
1801*35238bceSAndroid Build Coastguard Worker const VarValue &unifValue = values[unifNdx];
1802*35238bceSAndroid Build Coastguard Worker
1803*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Checking uniform " << uniform.name << TestLog::EndMessage;
1804*35238bceSAndroid Build Coastguard Worker
1805*35238bceSAndroid Build Coastguard Worker if (unifValue.type == glu::TYPE_INVALID) // This happens when glGetUniformLocation() returned -1.
1806*35238bceSAndroid Build Coastguard Worker continue;
1807*35238bceSAndroid Build Coastguard Worker
1808*35238bceSAndroid Build Coastguard Worker if (!apiVarValueEquals(unifValue, uniform.finalValue))
1809*35238bceSAndroid Build Coastguard Worker {
1810*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// FAILURE: value obtained with glGetUniform*() for uniform " << uniform.name
1811*35238bceSAndroid Build Coastguard Worker << " differs from value set with glUniform*()" << TestLog::EndMessage;
1812*35238bceSAndroid Build Coastguard Worker success = false;
1813*35238bceSAndroid Build Coastguard Worker }
1814*35238bceSAndroid Build Coastguard Worker }
1815*35238bceSAndroid Build Coastguard Worker
1816*35238bceSAndroid Build Coastguard Worker return success;
1817*35238bceSAndroid Build Coastguard Worker }
1818*35238bceSAndroid Build Coastguard Worker
renderTest(const vector<BasicUniform> & basicUniforms,const ShaderProgram & program,Random & rnd)1819*35238bceSAndroid Build Coastguard Worker bool UniformCase::renderTest(const vector<BasicUniform> &basicUniforms, const ShaderProgram &program, Random &rnd)
1820*35238bceSAndroid Build Coastguard Worker {
1821*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1822*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
1823*35238bceSAndroid Build Coastguard Worker const int viewportW = de::min(renderTarget.getWidth(), MAX_RENDER_WIDTH);
1824*35238bceSAndroid Build Coastguard Worker const int viewportH = de::min(renderTarget.getHeight(), MAX_RENDER_HEIGHT);
1825*35238bceSAndroid Build Coastguard Worker const int viewportX = rnd.getInt(0, renderTarget.getWidth() - viewportW);
1826*35238bceSAndroid Build Coastguard Worker const int viewportY = rnd.getInt(0, renderTarget.getHeight() - viewportH);
1827*35238bceSAndroid Build Coastguard Worker tcu::Surface renderedImg(viewportW, viewportH);
1828*35238bceSAndroid Build Coastguard Worker
1829*35238bceSAndroid Build Coastguard Worker // Assert that no two samplers of different types have the same texture unit - this is an error in GL.
1830*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)basicUniforms.size(); i++)
1831*35238bceSAndroid Build Coastguard Worker {
1832*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeSampler(basicUniforms[i].type))
1833*35238bceSAndroid Build Coastguard Worker {
1834*35238bceSAndroid Build Coastguard Worker for (int j = 0; j < i; j++)
1835*35238bceSAndroid Build Coastguard Worker {
1836*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeSampler(basicUniforms[j].type) && basicUniforms[i].type != basicUniforms[j].type)
1837*35238bceSAndroid Build Coastguard Worker DE_ASSERT(basicUniforms[i].finalValue.val.samplerV.unit !=
1838*35238bceSAndroid Build Coastguard Worker basicUniforms[j].finalValue.val.samplerV.unit);
1839*35238bceSAndroid Build Coastguard Worker }
1840*35238bceSAndroid Build Coastguard Worker }
1841*35238bceSAndroid Build Coastguard Worker }
1842*35238bceSAndroid Build Coastguard Worker
1843*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)basicUniforms.size(); i++)
1844*35238bceSAndroid Build Coastguard Worker {
1845*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeSampler(basicUniforms[i].type) &&
1846*35238bceSAndroid Build Coastguard Worker std::find(m_filledTextureUnits.begin(), m_filledTextureUnits.end(),
1847*35238bceSAndroid Build Coastguard Worker basicUniforms[i].finalValue.val.samplerV.unit) == m_filledTextureUnits.end())
1848*35238bceSAndroid Build Coastguard Worker {
1849*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "// Filling texture at unit " << apiVarValueStr(basicUniforms[i].finalValue)
1850*35238bceSAndroid Build Coastguard Worker << " with color " << shaderVarValueStr(basicUniforms[i].finalValue) << TestLog::EndMessage;
1851*35238bceSAndroid Build Coastguard Worker setupTexture(basicUniforms[i].finalValue);
1852*35238bceSAndroid Build Coastguard Worker }
1853*35238bceSAndroid Build Coastguard Worker }
1854*35238bceSAndroid Build Coastguard Worker
1855*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glViewport(viewportX, viewportY, viewportW, viewportH));
1856*35238bceSAndroid Build Coastguard Worker
1857*35238bceSAndroid Build Coastguard Worker {
1858*35238bceSAndroid Build Coastguard Worker static const float position[] = {-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, +1.0f, 0.0f, 1.0f,
1859*35238bceSAndroid Build Coastguard Worker +1.0f, -1.0f, 0.0f, 1.0f, +1.0f, +1.0f, 0.0f, 1.0f};
1860*35238bceSAndroid Build Coastguard Worker static const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
1861*35238bceSAndroid Build Coastguard Worker
1862*35238bceSAndroid Build Coastguard Worker const int posLoc = glGetAttribLocation(program.getProgram(), "a_position");
1863*35238bceSAndroid Build Coastguard Worker
1864*35238bceSAndroid Build Coastguard Worker glEnableVertexAttribArray(posLoc);
1865*35238bceSAndroid Build Coastguard Worker glVertexAttribPointer(posLoc, 4, GL_FLOAT, GL_FALSE, 0, &position[0]);
1866*35238bceSAndroid Build Coastguard Worker
1867*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glDrawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_SHORT, &indices[0]));
1868*35238bceSAndroid Build Coastguard Worker }
1869*35238bceSAndroid Build Coastguard Worker
1870*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedImg.getAccess());
1871*35238bceSAndroid Build Coastguard Worker
1872*35238bceSAndroid Build Coastguard Worker int numFailedPixels = 0;
1873*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < renderedImg.getHeight(); y++)
1874*35238bceSAndroid Build Coastguard Worker {
1875*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < renderedImg.getWidth(); x++)
1876*35238bceSAndroid Build Coastguard Worker {
1877*35238bceSAndroid Build Coastguard Worker if (renderedImg.getPixel(x, y) != tcu::RGBA::white())
1878*35238bceSAndroid Build Coastguard Worker numFailedPixels += 1;
1879*35238bceSAndroid Build Coastguard Worker }
1880*35238bceSAndroid Build Coastguard Worker }
1881*35238bceSAndroid Build Coastguard Worker
1882*35238bceSAndroid Build Coastguard Worker if (numFailedPixels > 0)
1883*35238bceSAndroid Build Coastguard Worker {
1884*35238bceSAndroid Build Coastguard Worker log << TestLog::Image("RenderedImage", "Rendered image", renderedImg);
1885*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "FAILURE: image comparison failed, got " << numFailedPixels << " non-white pixels"
1886*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1887*35238bceSAndroid Build Coastguard Worker return false;
1888*35238bceSAndroid Build Coastguard Worker }
1889*35238bceSAndroid Build Coastguard Worker else
1890*35238bceSAndroid Build Coastguard Worker {
1891*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Success: got all-white pixels (all uniforms have correct values)"
1892*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
1893*35238bceSAndroid Build Coastguard Worker return true;
1894*35238bceSAndroid Build Coastguard Worker }
1895*35238bceSAndroid Build Coastguard Worker }
1896*35238bceSAndroid Build Coastguard Worker
iterate(void)1897*35238bceSAndroid Build Coastguard Worker UniformCase::IterateResult UniformCase::iterate(void)
1898*35238bceSAndroid Build Coastguard Worker {
1899*35238bceSAndroid Build Coastguard Worker Random rnd(deStringHash(getName()) ^ (uint32_t)m_context.getTestContext().getCommandLine().getBaseSeed());
1900*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1901*35238bceSAndroid Build Coastguard Worker vector<BasicUniform> basicUniforms;
1902*35238bceSAndroid Build Coastguard Worker vector<BasicUniformReportRef> basicUniformReportsRef;
1903*35238bceSAndroid Build Coastguard Worker
1904*35238bceSAndroid Build Coastguard Worker {
1905*35238bceSAndroid Build Coastguard Worker int samplerUnitCounter = 0;
1906*35238bceSAndroid Build Coastguard Worker for (int i = 0; i < (int)m_uniformCollection->getNumUniforms(); i++)
1907*35238bceSAndroid Build Coastguard Worker generateBasicUniforms(basicUniforms, basicUniformReportsRef, m_uniformCollection->getUniform(i).type,
1908*35238bceSAndroid Build Coastguard Worker m_uniformCollection->getUniform(i).name.c_str(), true, samplerUnitCounter, rnd);
1909*35238bceSAndroid Build Coastguard Worker }
1910*35238bceSAndroid Build Coastguard Worker
1911*35238bceSAndroid Build Coastguard Worker const string vertexSource = generateVertexSource(basicUniforms);
1912*35238bceSAndroid Build Coastguard Worker const string fragmentSource = generateFragmentSource(basicUniforms);
1913*35238bceSAndroid Build Coastguard Worker const ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexSource, fragmentSource));
1914*35238bceSAndroid Build Coastguard Worker
1915*35238bceSAndroid Build Coastguard Worker log << program;
1916*35238bceSAndroid Build Coastguard Worker
1917*35238bceSAndroid Build Coastguard Worker if (!program.isOk())
1918*35238bceSAndroid Build Coastguard Worker {
1919*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Compile failed");
1920*35238bceSAndroid Build Coastguard Worker return STOP;
1921*35238bceSAndroid Build Coastguard Worker }
1922*35238bceSAndroid Build Coastguard Worker
1923*35238bceSAndroid Build Coastguard Worker GLU_CHECK_CALL(glUseProgram(program.getProgram()));
1924*35238bceSAndroid Build Coastguard Worker
1925*35238bceSAndroid Build Coastguard Worker const bool success = test(basicUniforms, basicUniformReportsRef, program, rnd);
1926*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Passed" : "Failed");
1927*35238bceSAndroid Build Coastguard Worker
1928*35238bceSAndroid Build Coastguard Worker return STOP;
1929*35238bceSAndroid Build Coastguard Worker }
1930*35238bceSAndroid Build Coastguard Worker
1931*35238bceSAndroid Build Coastguard Worker class UniformInfoQueryCase : public UniformCase
1932*35238bceSAndroid Build Coastguard Worker {
1933*35238bceSAndroid Build Coastguard Worker public:
1934*35238bceSAndroid Build Coastguard Worker UniformInfoQueryCase(Context &context, const char *name, const char *description, CaseShaderType shaderType,
1935*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection, uint32_t additionalFeatures = 0);
1936*35238bceSAndroid Build Coastguard Worker bool test(const vector<BasicUniform> &basicUniforms, const vector<BasicUniformReportRef> &basicUniformReportsRef,
1937*35238bceSAndroid Build Coastguard Worker const ShaderProgram &program, Random &rnd);
1938*35238bceSAndroid Build Coastguard Worker };
1939*35238bceSAndroid Build Coastguard Worker
UniformInfoQueryCase(Context & context,const char * const name,const char * const description,const CaseShaderType shaderType,const SharedPtr<const UniformCollection> & uniformCollection,const uint32_t additionalFeatures)1940*35238bceSAndroid Build Coastguard Worker UniformInfoQueryCase::UniformInfoQueryCase(Context &context, const char *const name, const char *const description,
1941*35238bceSAndroid Build Coastguard Worker const CaseShaderType shaderType,
1942*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection,
1943*35238bceSAndroid Build Coastguard Worker const uint32_t additionalFeatures)
1944*35238bceSAndroid Build Coastguard Worker : UniformCase(context, name, description, shaderType, uniformCollection, additionalFeatures)
1945*35238bceSAndroid Build Coastguard Worker {
1946*35238bceSAndroid Build Coastguard Worker }
1947*35238bceSAndroid Build Coastguard Worker
test(const vector<BasicUniform> & basicUniforms,const vector<BasicUniformReportRef> & basicUniformReportsRef,const ShaderProgram & program,Random & rnd)1948*35238bceSAndroid Build Coastguard Worker bool UniformInfoQueryCase::test(const vector<BasicUniform> &basicUniforms,
1949*35238bceSAndroid Build Coastguard Worker const vector<BasicUniformReportRef> &basicUniformReportsRef,
1950*35238bceSAndroid Build Coastguard Worker const ShaderProgram &program, Random &rnd)
1951*35238bceSAndroid Build Coastguard Worker {
1952*35238bceSAndroid Build Coastguard Worker DE_UNREF(basicUniforms);
1953*35238bceSAndroid Build Coastguard Worker DE_UNREF(rnd);
1954*35238bceSAndroid Build Coastguard Worker
1955*35238bceSAndroid Build Coastguard Worker const uint32_t programGL = program.getProgram();
1956*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
1957*35238bceSAndroid Build Coastguard Worker vector<BasicUniformReportGL> basicUniformReportsUniform;
1958*35238bceSAndroid Build Coastguard Worker
1959*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "InfoGetActiveUniform",
1960*35238bceSAndroid Build Coastguard Worker "Uniform information queries with glGetActiveUniform()");
1961*35238bceSAndroid Build Coastguard Worker const bool success = getActiveUniforms(basicUniformReportsUniform, basicUniformReportsRef, programGL);
1962*35238bceSAndroid Build Coastguard Worker
1963*35238bceSAndroid Build Coastguard Worker if (!success)
1964*35238bceSAndroid Build Coastguard Worker return false;
1965*35238bceSAndroid Build Coastguard Worker
1966*35238bceSAndroid Build Coastguard Worker return true;
1967*35238bceSAndroid Build Coastguard Worker }
1968*35238bceSAndroid Build Coastguard Worker
1969*35238bceSAndroid Build Coastguard Worker class UniformValueCase : public UniformCase
1970*35238bceSAndroid Build Coastguard Worker {
1971*35238bceSAndroid Build Coastguard Worker public:
1972*35238bceSAndroid Build Coastguard Worker enum ValueToCheck
1973*35238bceSAndroid Build Coastguard Worker {
1974*35238bceSAndroid Build Coastguard Worker VALUETOCHECK_INITIAL = 0, //!< Verify the initial values of the uniforms (i.e. check that they're zero).
1975*35238bceSAndroid Build Coastguard Worker VALUETOCHECK_ASSIGNED, //!< Assign values to uniforms with glUniform*(), and check those.
1976*35238bceSAndroid Build Coastguard Worker
1977*35238bceSAndroid Build Coastguard Worker VALUETOCHECK_LAST
1978*35238bceSAndroid Build Coastguard Worker };
1979*35238bceSAndroid Build Coastguard Worker enum CheckMethod
1980*35238bceSAndroid Build Coastguard Worker {
1981*35238bceSAndroid Build Coastguard Worker CHECKMETHOD_GET_UNIFORM = 0, //!< Check values with glGetUniform*().
1982*35238bceSAndroid Build Coastguard Worker CHECKMETHOD_RENDER, //!< Check values by rendering with the value-checking shader.
1983*35238bceSAndroid Build Coastguard Worker
1984*35238bceSAndroid Build Coastguard Worker CHECKMETHOD_LAST
1985*35238bceSAndroid Build Coastguard Worker };
1986*35238bceSAndroid Build Coastguard Worker enum AssignMethod
1987*35238bceSAndroid Build Coastguard Worker {
1988*35238bceSAndroid Build Coastguard Worker ASSIGNMETHOD_POINTER = 0,
1989*35238bceSAndroid Build Coastguard Worker ASSIGNMETHOD_VALUE,
1990*35238bceSAndroid Build Coastguard Worker
1991*35238bceSAndroid Build Coastguard Worker ASSIGNMETHOD_LAST
1992*35238bceSAndroid Build Coastguard Worker };
1993*35238bceSAndroid Build Coastguard Worker
1994*35238bceSAndroid Build Coastguard Worker UniformValueCase(Context &context, const char *name, const char *description, CaseShaderType shaderType,
1995*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection, ValueToCheck valueToCheck,
1996*35238bceSAndroid Build Coastguard Worker CheckMethod checkMethod, AssignMethod assignMethod, uint32_t additionalFeatures = 0);
1997*35238bceSAndroid Build Coastguard Worker
1998*35238bceSAndroid Build Coastguard Worker bool test(const vector<BasicUniform> &basicUniforms, const vector<BasicUniformReportRef> &basicUniformReportsRef,
1999*35238bceSAndroid Build Coastguard Worker const ShaderProgram &program, Random &rnd);
2000*35238bceSAndroid Build Coastguard Worker
2001*35238bceSAndroid Build Coastguard Worker static const char *getValueToCheckName(ValueToCheck valueToCheck);
2002*35238bceSAndroid Build Coastguard Worker static const char *getValueToCheckDescription(ValueToCheck valueToCheck);
2003*35238bceSAndroid Build Coastguard Worker static const char *getCheckMethodName(CheckMethod checkMethod);
2004*35238bceSAndroid Build Coastguard Worker static const char *getCheckMethodDescription(CheckMethod checkMethod);
2005*35238bceSAndroid Build Coastguard Worker static const char *getAssignMethodName(AssignMethod checkMethod);
2006*35238bceSAndroid Build Coastguard Worker static const char *getAssignMethodDescription(AssignMethod checkMethod);
2007*35238bceSAndroid Build Coastguard Worker
2008*35238bceSAndroid Build Coastguard Worker private:
2009*35238bceSAndroid Build Coastguard Worker const ValueToCheck m_valueToCheck;
2010*35238bceSAndroid Build Coastguard Worker const CheckMethod m_checkMethod;
2011*35238bceSAndroid Build Coastguard Worker };
2012*35238bceSAndroid Build Coastguard Worker
getValueToCheckName(const ValueToCheck valueToCheck)2013*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getValueToCheckName(const ValueToCheck valueToCheck)
2014*35238bceSAndroid Build Coastguard Worker {
2015*35238bceSAndroid Build Coastguard Worker switch (valueToCheck)
2016*35238bceSAndroid Build Coastguard Worker {
2017*35238bceSAndroid Build Coastguard Worker case VALUETOCHECK_INITIAL:
2018*35238bceSAndroid Build Coastguard Worker return "initial";
2019*35238bceSAndroid Build Coastguard Worker case VALUETOCHECK_ASSIGNED:
2020*35238bceSAndroid Build Coastguard Worker return "assigned";
2021*35238bceSAndroid Build Coastguard Worker default:
2022*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2023*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2024*35238bceSAndroid Build Coastguard Worker }
2025*35238bceSAndroid Build Coastguard Worker }
2026*35238bceSAndroid Build Coastguard Worker
getValueToCheckDescription(const ValueToCheck valueToCheck)2027*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getValueToCheckDescription(const ValueToCheck valueToCheck)
2028*35238bceSAndroid Build Coastguard Worker {
2029*35238bceSAndroid Build Coastguard Worker switch (valueToCheck)
2030*35238bceSAndroid Build Coastguard Worker {
2031*35238bceSAndroid Build Coastguard Worker case VALUETOCHECK_INITIAL:
2032*35238bceSAndroid Build Coastguard Worker return "Check initial uniform values (zeros)";
2033*35238bceSAndroid Build Coastguard Worker case VALUETOCHECK_ASSIGNED:
2034*35238bceSAndroid Build Coastguard Worker return "Check assigned uniform values";
2035*35238bceSAndroid Build Coastguard Worker default:
2036*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2037*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2038*35238bceSAndroid Build Coastguard Worker }
2039*35238bceSAndroid Build Coastguard Worker }
2040*35238bceSAndroid Build Coastguard Worker
getCheckMethodName(const CheckMethod checkMethod)2041*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getCheckMethodName(const CheckMethod checkMethod)
2042*35238bceSAndroid Build Coastguard Worker {
2043*35238bceSAndroid Build Coastguard Worker switch (checkMethod)
2044*35238bceSAndroid Build Coastguard Worker {
2045*35238bceSAndroid Build Coastguard Worker case CHECKMETHOD_GET_UNIFORM:
2046*35238bceSAndroid Build Coastguard Worker return "get_uniform";
2047*35238bceSAndroid Build Coastguard Worker case CHECKMETHOD_RENDER:
2048*35238bceSAndroid Build Coastguard Worker return "render";
2049*35238bceSAndroid Build Coastguard Worker default:
2050*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2051*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2052*35238bceSAndroid Build Coastguard Worker }
2053*35238bceSAndroid Build Coastguard Worker }
2054*35238bceSAndroid Build Coastguard Worker
getCheckMethodDescription(const CheckMethod checkMethod)2055*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getCheckMethodDescription(const CheckMethod checkMethod)
2056*35238bceSAndroid Build Coastguard Worker {
2057*35238bceSAndroid Build Coastguard Worker switch (checkMethod)
2058*35238bceSAndroid Build Coastguard Worker {
2059*35238bceSAndroid Build Coastguard Worker case CHECKMETHOD_GET_UNIFORM:
2060*35238bceSAndroid Build Coastguard Worker return "Verify values with glGetUniform*()";
2061*35238bceSAndroid Build Coastguard Worker case CHECKMETHOD_RENDER:
2062*35238bceSAndroid Build Coastguard Worker return "Verify values by rendering";
2063*35238bceSAndroid Build Coastguard Worker default:
2064*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2065*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2066*35238bceSAndroid Build Coastguard Worker }
2067*35238bceSAndroid Build Coastguard Worker }
2068*35238bceSAndroid Build Coastguard Worker
getAssignMethodName(const AssignMethod assignMethod)2069*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getAssignMethodName(const AssignMethod assignMethod)
2070*35238bceSAndroid Build Coastguard Worker {
2071*35238bceSAndroid Build Coastguard Worker switch (assignMethod)
2072*35238bceSAndroid Build Coastguard Worker {
2073*35238bceSAndroid Build Coastguard Worker case ASSIGNMETHOD_POINTER:
2074*35238bceSAndroid Build Coastguard Worker return "by_pointer";
2075*35238bceSAndroid Build Coastguard Worker case ASSIGNMETHOD_VALUE:
2076*35238bceSAndroid Build Coastguard Worker return "by_value";
2077*35238bceSAndroid Build Coastguard Worker default:
2078*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2079*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2080*35238bceSAndroid Build Coastguard Worker }
2081*35238bceSAndroid Build Coastguard Worker }
2082*35238bceSAndroid Build Coastguard Worker
getAssignMethodDescription(const AssignMethod assignMethod)2083*35238bceSAndroid Build Coastguard Worker const char *UniformValueCase::getAssignMethodDescription(const AssignMethod assignMethod)
2084*35238bceSAndroid Build Coastguard Worker {
2085*35238bceSAndroid Build Coastguard Worker switch (assignMethod)
2086*35238bceSAndroid Build Coastguard Worker {
2087*35238bceSAndroid Build Coastguard Worker case ASSIGNMETHOD_POINTER:
2088*35238bceSAndroid Build Coastguard Worker return "Assign values by-pointer";
2089*35238bceSAndroid Build Coastguard Worker case ASSIGNMETHOD_VALUE:
2090*35238bceSAndroid Build Coastguard Worker return "Assign values by-value";
2091*35238bceSAndroid Build Coastguard Worker default:
2092*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
2093*35238bceSAndroid Build Coastguard Worker return DE_NULL;
2094*35238bceSAndroid Build Coastguard Worker }
2095*35238bceSAndroid Build Coastguard Worker }
2096*35238bceSAndroid Build Coastguard Worker
UniformValueCase(Context & context,const char * const name,const char * const description,const CaseShaderType shaderType,const SharedPtr<const UniformCollection> & uniformCollection,const ValueToCheck valueToCheck,const CheckMethod checkMethod,const AssignMethod assignMethod,const uint32_t additionalFeatures)2097*35238bceSAndroid Build Coastguard Worker UniformValueCase::UniformValueCase(Context &context, const char *const name, const char *const description,
2098*35238bceSAndroid Build Coastguard Worker const CaseShaderType shaderType,
2099*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection,
2100*35238bceSAndroid Build Coastguard Worker const ValueToCheck valueToCheck, const CheckMethod checkMethod,
2101*35238bceSAndroid Build Coastguard Worker const AssignMethod assignMethod, const uint32_t additionalFeatures)
2102*35238bceSAndroid Build Coastguard Worker : UniformCase(context, name, description, shaderType, uniformCollection,
2103*35238bceSAndroid Build Coastguard Worker (valueToCheck == VALUETOCHECK_INITIAL ? FEATURE_UNIFORMVALUE_ZERO : 0) |
2104*35238bceSAndroid Build Coastguard Worker (assignMethod == ASSIGNMETHOD_VALUE ? FEATURE_UNIFORMFUNC_VALUE : 0) | additionalFeatures)
2105*35238bceSAndroid Build Coastguard Worker , m_valueToCheck(valueToCheck)
2106*35238bceSAndroid Build Coastguard Worker , m_checkMethod(checkMethod)
2107*35238bceSAndroid Build Coastguard Worker {
2108*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!(assignMethod == ASSIGNMETHOD_LAST && valueToCheck == VALUETOCHECK_ASSIGNED));
2109*35238bceSAndroid Build Coastguard Worker }
2110*35238bceSAndroid Build Coastguard Worker
test(const vector<BasicUniform> & basicUniforms,const vector<BasicUniformReportRef> & basicUniformReportsRef,const ShaderProgram & program,Random & rnd)2111*35238bceSAndroid Build Coastguard Worker bool UniformValueCase::test(const vector<BasicUniform> &basicUniforms,
2112*35238bceSAndroid Build Coastguard Worker const vector<BasicUniformReportRef> &basicUniformReportsRef, const ShaderProgram &program,
2113*35238bceSAndroid Build Coastguard Worker Random &rnd)
2114*35238bceSAndroid Build Coastguard Worker {
2115*35238bceSAndroid Build Coastguard Worker DE_UNREF(basicUniformReportsRef);
2116*35238bceSAndroid Build Coastguard Worker
2117*35238bceSAndroid Build Coastguard Worker const uint32_t programGL = program.getProgram();
2118*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
2119*35238bceSAndroid Build Coastguard Worker
2120*35238bceSAndroid Build Coastguard Worker if (m_valueToCheck == VALUETOCHECK_ASSIGNED)
2121*35238bceSAndroid Build Coastguard Worker {
2122*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "UniformAssign", "Uniform value assignments");
2123*35238bceSAndroid Build Coastguard Worker assignUniforms(basicUniforms, programGL, rnd);
2124*35238bceSAndroid Build Coastguard Worker }
2125*35238bceSAndroid Build Coastguard Worker else
2126*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_valueToCheck == VALUETOCHECK_INITIAL);
2127*35238bceSAndroid Build Coastguard Worker
2128*35238bceSAndroid Build Coastguard Worker if (m_checkMethod == CHECKMETHOD_GET_UNIFORM)
2129*35238bceSAndroid Build Coastguard Worker {
2130*35238bceSAndroid Build Coastguard Worker vector<VarValue> values;
2131*35238bceSAndroid Build Coastguard Worker
2132*35238bceSAndroid Build Coastguard Worker {
2133*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "GetUniforms", "Uniform value query");
2134*35238bceSAndroid Build Coastguard Worker const bool success = getUniforms(values, basicUniforms, program.getProgram());
2135*35238bceSAndroid Build Coastguard Worker
2136*35238bceSAndroid Build Coastguard Worker if (!success)
2137*35238bceSAndroid Build Coastguard Worker return false;
2138*35238bceSAndroid Build Coastguard Worker }
2139*35238bceSAndroid Build Coastguard Worker
2140*35238bceSAndroid Build Coastguard Worker if (m_valueToCheck == VALUETOCHECK_ASSIGNED)
2141*35238bceSAndroid Build Coastguard Worker {
2142*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "ValueCheck",
2143*35238bceSAndroid Build Coastguard Worker "Verify that the reported values match the assigned values");
2144*35238bceSAndroid Build Coastguard Worker const bool success = compareUniformValues(values, basicUniforms);
2145*35238bceSAndroid Build Coastguard Worker
2146*35238bceSAndroid Build Coastguard Worker if (!success)
2147*35238bceSAndroid Build Coastguard Worker return false;
2148*35238bceSAndroid Build Coastguard Worker }
2149*35238bceSAndroid Build Coastguard Worker else
2150*35238bceSAndroid Build Coastguard Worker {
2151*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_valueToCheck == VALUETOCHECK_INITIAL);
2152*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "ValueCheck",
2153*35238bceSAndroid Build Coastguard Worker "Verify that the uniforms have correct initial values (zeros)");
2154*35238bceSAndroid Build Coastguard Worker const bool success = checkUniformDefaultValues(values, basicUniforms);
2155*35238bceSAndroid Build Coastguard Worker
2156*35238bceSAndroid Build Coastguard Worker if (!success)
2157*35238bceSAndroid Build Coastguard Worker return false;
2158*35238bceSAndroid Build Coastguard Worker }
2159*35238bceSAndroid Build Coastguard Worker }
2160*35238bceSAndroid Build Coastguard Worker else
2161*35238bceSAndroid Build Coastguard Worker {
2162*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_checkMethod == CHECKMETHOD_RENDER);
2163*35238bceSAndroid Build Coastguard Worker
2164*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "RenderTest", "Render test");
2165*35238bceSAndroid Build Coastguard Worker const bool success = renderTest(basicUniforms, program, rnd);
2166*35238bceSAndroid Build Coastguard Worker
2167*35238bceSAndroid Build Coastguard Worker if (!success)
2168*35238bceSAndroid Build Coastguard Worker return false;
2169*35238bceSAndroid Build Coastguard Worker }
2170*35238bceSAndroid Build Coastguard Worker
2171*35238bceSAndroid Build Coastguard Worker return true;
2172*35238bceSAndroid Build Coastguard Worker }
2173*35238bceSAndroid Build Coastguard Worker
2174*35238bceSAndroid Build Coastguard Worker class RandomUniformCase : public UniformCase
2175*35238bceSAndroid Build Coastguard Worker {
2176*35238bceSAndroid Build Coastguard Worker public:
2177*35238bceSAndroid Build Coastguard Worker RandomUniformCase(Context &m_context, const char *name, const char *description, uint32_t seed);
2178*35238bceSAndroid Build Coastguard Worker
2179*35238bceSAndroid Build Coastguard Worker bool test(const vector<BasicUniform> &basicUniforms, const vector<BasicUniformReportRef> &basicUniformReportsRef,
2180*35238bceSAndroid Build Coastguard Worker const ShaderProgram &program, Random &rnd);
2181*35238bceSAndroid Build Coastguard Worker };
2182*35238bceSAndroid Build Coastguard Worker
RandomUniformCase(Context & context,const char * const name,const char * const description,const uint32_t seed)2183*35238bceSAndroid Build Coastguard Worker RandomUniformCase::RandomUniformCase(Context &context, const char *const name, const char *const description,
2184*35238bceSAndroid Build Coastguard Worker const uint32_t seed)
2185*35238bceSAndroid Build Coastguard Worker : UniformCase(context, name, description, seed ^ (uint32_t)context.getTestContext().getCommandLine().getBaseSeed())
2186*35238bceSAndroid Build Coastguard Worker {
2187*35238bceSAndroid Build Coastguard Worker }
2188*35238bceSAndroid Build Coastguard Worker
test(const vector<BasicUniform> & basicUniforms,const vector<BasicUniformReportRef> & basicUniformReportsRef,const ShaderProgram & program,Random & rnd)2189*35238bceSAndroid Build Coastguard Worker bool RandomUniformCase::test(const vector<BasicUniform> &basicUniforms,
2190*35238bceSAndroid Build Coastguard Worker const vector<BasicUniformReportRef> &basicUniformReportsRef, const ShaderProgram &program,
2191*35238bceSAndroid Build Coastguard Worker Random &rnd)
2192*35238bceSAndroid Build Coastguard Worker {
2193*35238bceSAndroid Build Coastguard Worker // \note Different sampler types may not be bound to same unit when rendering.
2194*35238bceSAndroid Build Coastguard Worker const bool renderingPossible =
2195*35238bceSAndroid Build Coastguard Worker (m_features & FEATURE_UNIFORMVALUE_ZERO) == 0 || !m_uniformCollection->containsSeveralSamplerTypes();
2196*35238bceSAndroid Build Coastguard Worker
2197*35238bceSAndroid Build Coastguard Worker bool performGetActiveUniforms = rnd.getBool();
2198*35238bceSAndroid Build Coastguard Worker const bool performGetUniforms = rnd.getBool();
2199*35238bceSAndroid Build Coastguard Worker const bool performCheckUniformDefaultValues = performGetUniforms && rnd.getBool();
2200*35238bceSAndroid Build Coastguard Worker const bool performAssignUniforms = rnd.getBool();
2201*35238bceSAndroid Build Coastguard Worker const bool performCompareUniformValues = performGetUniforms && performAssignUniforms && rnd.getBool();
2202*35238bceSAndroid Build Coastguard Worker const bool performRenderTest = renderingPossible && performAssignUniforms && rnd.getBool();
2203*35238bceSAndroid Build Coastguard Worker const uint32_t programGL = program.getProgram();
2204*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
2205*35238bceSAndroid Build Coastguard Worker
2206*35238bceSAndroid Build Coastguard Worker if (!(performGetActiveUniforms || performGetUniforms || performCheckUniformDefaultValues || performAssignUniforms ||
2207*35238bceSAndroid Build Coastguard Worker performCompareUniformValues || performRenderTest))
2208*35238bceSAndroid Build Coastguard Worker performGetActiveUniforms = true; // Do something at least.
2209*35238bceSAndroid Build Coastguard Worker
2210*35238bceSAndroid Build Coastguard Worker #define PERFORM_AND_CHECK(CALL, SECTION_NAME, SECTION_DESCRIPTION) \
2211*35238bceSAndroid Build Coastguard Worker do \
2212*35238bceSAndroid Build Coastguard Worker { \
2213*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, (SECTION_NAME), (SECTION_DESCRIPTION)); \
2214*35238bceSAndroid Build Coastguard Worker const bool success = (CALL); \
2215*35238bceSAndroid Build Coastguard Worker if (!success) \
2216*35238bceSAndroid Build Coastguard Worker return false; \
2217*35238bceSAndroid Build Coastguard Worker } while (false)
2218*35238bceSAndroid Build Coastguard Worker
2219*35238bceSAndroid Build Coastguard Worker if (performGetActiveUniforms)
2220*35238bceSAndroid Build Coastguard Worker {
2221*35238bceSAndroid Build Coastguard Worker vector<BasicUniformReportGL> reportsUniform;
2222*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(getActiveUniforms(reportsUniform, basicUniformReportsRef, programGL), "InfoGetActiveUniform",
2223*35238bceSAndroid Build Coastguard Worker "Uniform information queries with glGetActiveUniform()");
2224*35238bceSAndroid Build Coastguard Worker }
2225*35238bceSAndroid Build Coastguard Worker
2226*35238bceSAndroid Build Coastguard Worker {
2227*35238bceSAndroid Build Coastguard Worker vector<VarValue> uniformDefaultValues;
2228*35238bceSAndroid Build Coastguard Worker
2229*35238bceSAndroid Build Coastguard Worker if (performGetUniforms)
2230*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(getUniforms(uniformDefaultValues, basicUniforms, programGL), "GetUniformDefaults",
2231*35238bceSAndroid Build Coastguard Worker "Uniform default value query");
2232*35238bceSAndroid Build Coastguard Worker if (performCheckUniformDefaultValues)
2233*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(checkUniformDefaultValues(uniformDefaultValues, basicUniforms), "DefaultValueCheck",
2234*35238bceSAndroid Build Coastguard Worker "Verify that the uniforms have correct initial values (zeros)");
2235*35238bceSAndroid Build Coastguard Worker }
2236*35238bceSAndroid Build Coastguard Worker
2237*35238bceSAndroid Build Coastguard Worker {
2238*35238bceSAndroid Build Coastguard Worker vector<VarValue> uniformValues;
2239*35238bceSAndroid Build Coastguard Worker
2240*35238bceSAndroid Build Coastguard Worker if (performAssignUniforms)
2241*35238bceSAndroid Build Coastguard Worker {
2242*35238bceSAndroid Build Coastguard Worker const ScopedLogSection section(log, "UniformAssign", "Uniform value assignments");
2243*35238bceSAndroid Build Coastguard Worker assignUniforms(basicUniforms, programGL, rnd);
2244*35238bceSAndroid Build Coastguard Worker }
2245*35238bceSAndroid Build Coastguard Worker if (performCompareUniformValues)
2246*35238bceSAndroid Build Coastguard Worker {
2247*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(getUniforms(uniformValues, basicUniforms, programGL), "GetUniforms",
2248*35238bceSAndroid Build Coastguard Worker "Uniform value query");
2249*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(compareUniformValues(uniformValues, basicUniforms), "ValueCheck",
2250*35238bceSAndroid Build Coastguard Worker "Verify that the reported values match the assigned values");
2251*35238bceSAndroid Build Coastguard Worker }
2252*35238bceSAndroid Build Coastguard Worker }
2253*35238bceSAndroid Build Coastguard Worker
2254*35238bceSAndroid Build Coastguard Worker if (performRenderTest)
2255*35238bceSAndroid Build Coastguard Worker PERFORM_AND_CHECK(renderTest(basicUniforms, program, rnd), "RenderTest", "Render test");
2256*35238bceSAndroid Build Coastguard Worker
2257*35238bceSAndroid Build Coastguard Worker #undef PERFORM_AND_CHECK
2258*35238bceSAndroid Build Coastguard Worker
2259*35238bceSAndroid Build Coastguard Worker return true;
2260*35238bceSAndroid Build Coastguard Worker }
2261*35238bceSAndroid Build Coastguard Worker
UniformApiTests(Context & context)2262*35238bceSAndroid Build Coastguard Worker UniformApiTests::UniformApiTests(Context &context) : TestCaseGroup(context, "uniform_api", "Uniform API Tests")
2263*35238bceSAndroid Build Coastguard Worker {
2264*35238bceSAndroid Build Coastguard Worker }
2265*35238bceSAndroid Build Coastguard Worker
~UniformApiTests(void)2266*35238bceSAndroid Build Coastguard Worker UniformApiTests::~UniformApiTests(void)
2267*35238bceSAndroid Build Coastguard Worker {
2268*35238bceSAndroid Build Coastguard Worker }
2269*35238bceSAndroid Build Coastguard Worker
2270*35238bceSAndroid Build Coastguard Worker namespace
2271*35238bceSAndroid Build Coastguard Worker {
2272*35238bceSAndroid Build Coastguard Worker
2273*35238bceSAndroid Build Coastguard Worker // \note Although this is only used in UniformApiTest::init, it needs to be defined here as it's used as a template argument.
2274*35238bceSAndroid Build Coastguard Worker struct UniformCollectionCase
2275*35238bceSAndroid Build Coastguard Worker {
2276*35238bceSAndroid Build Coastguard Worker string namePrefix;
2277*35238bceSAndroid Build Coastguard Worker SharedPtr<const UniformCollection> uniformCollection;
2278*35238bceSAndroid Build Coastguard Worker
UniformCollectionCasedeqp::gles2::Functional::__anon88939a840511::UniformCollectionCase2279*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(const char *const name, const UniformCollection *uniformCollection_)
2280*35238bceSAndroid Build Coastguard Worker : namePrefix(name ? name + string("_") : "")
2281*35238bceSAndroid Build Coastguard Worker , uniformCollection(uniformCollection_)
2282*35238bceSAndroid Build Coastguard Worker {
2283*35238bceSAndroid Build Coastguard Worker }
2284*35238bceSAndroid Build Coastguard Worker };
2285*35238bceSAndroid Build Coastguard Worker
2286*35238bceSAndroid Build Coastguard Worker } // namespace
2287*35238bceSAndroid Build Coastguard Worker
init(void)2288*35238bceSAndroid Build Coastguard Worker void UniformApiTests::init(void)
2289*35238bceSAndroid Build Coastguard Worker {
2290*35238bceSAndroid Build Coastguard Worker // Generate sets of UniformCollections that are used by several cases.
2291*35238bceSAndroid Build Coastguard Worker
2292*35238bceSAndroid Build Coastguard Worker enum
2293*35238bceSAndroid Build Coastguard Worker {
2294*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_BASIC = 0,
2295*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_BASIC_ARRAY,
2296*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_BASIC_STRUCT,
2297*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_STRUCT_IN_ARRAY,
2298*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT,
2299*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_NESTED_STRUCTS_ARRAYS,
2300*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_MULTIPLE_BASIC,
2301*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_MULTIPLE_BASIC_ARRAY,
2302*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_MULTIPLE_NESTED_STRUCTS_ARRAYS,
2303*35238bceSAndroid Build Coastguard Worker
2304*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_LAST
2305*35238bceSAndroid Build Coastguard Worker };
2306*35238bceSAndroid Build Coastguard Worker
2307*35238bceSAndroid Build Coastguard Worker struct UniformCollectionGroup
2308*35238bceSAndroid Build Coastguard Worker {
2309*35238bceSAndroid Build Coastguard Worker string name;
2310*35238bceSAndroid Build Coastguard Worker vector<UniformCollectionCase> cases;
2311*35238bceSAndroid Build Coastguard Worker } defaultUniformCollections[UNIFORMCOLLECTIONS_LAST];
2312*35238bceSAndroid Build Coastguard Worker
2313*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC].name = "basic";
2314*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC_ARRAY].name = "basic_array";
2315*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC_STRUCT].name = "basic_struct";
2316*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_STRUCT_IN_ARRAY].name = "struct_in_array";
2317*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT].name = "array_in_struct";
2318*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_NESTED_STRUCTS_ARRAYS].name = "nested_structs_arrays";
2319*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_BASIC].name = "multiple_basic";
2320*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_BASIC_ARRAY].name = "multiple_basic_array";
2321*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_NESTED_STRUCTS_ARRAYS].name =
2322*35238bceSAndroid Build Coastguard Worker "multiple_nested_structs_arrays";
2323*35238bceSAndroid Build Coastguard Worker
2324*35238bceSAndroid Build Coastguard Worker for (int dataTypeNdx = 0; dataTypeNdx < DE_LENGTH_OF_ARRAY(s_testDataTypes); dataTypeNdx++)
2325*35238bceSAndroid Build Coastguard Worker {
2326*35238bceSAndroid Build Coastguard Worker const glu::DataType dataType = s_testDataTypes[dataTypeNdx];
2327*35238bceSAndroid Build Coastguard Worker const char *const typeName = glu::getDataTypeName(dataType);
2328*35238bceSAndroid Build Coastguard Worker
2329*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC].cases.push_back(
2330*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(typeName, UniformCollection::basic(dataType)));
2331*35238bceSAndroid Build Coastguard Worker
2332*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeScalar(dataType) ||
2333*35238bceSAndroid Build Coastguard Worker (glu::isDataTypeVector(dataType) && glu::getDataTypeScalarSize(dataType) == 4) ||
2334*35238bceSAndroid Build Coastguard Worker dataType == glu::TYPE_FLOAT_MAT4 || dataType == glu::TYPE_SAMPLER_2D)
2335*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC_ARRAY].cases.push_back(
2336*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(typeName, UniformCollection::basicArray(dataType)));
2337*35238bceSAndroid Build Coastguard Worker
2338*35238bceSAndroid Build Coastguard Worker if (glu::isDataTypeScalar(dataType) || dataType == glu::TYPE_FLOAT_MAT4 || dataType == glu::TYPE_SAMPLER_2D)
2339*35238bceSAndroid Build Coastguard Worker {
2340*35238bceSAndroid Build Coastguard Worker const glu::DataType secondDataType = glu::isDataTypeScalar(dataType) ? glu::getDataTypeVector(dataType, 4) :
2341*35238bceSAndroid Build Coastguard Worker dataType == glu::TYPE_FLOAT_MAT4 ? glu::TYPE_FLOAT_MAT2 :
2342*35238bceSAndroid Build Coastguard Worker dataType == glu::TYPE_SAMPLER_2D ? glu::TYPE_SAMPLER_CUBE :
2343*35238bceSAndroid Build Coastguard Worker glu::TYPE_LAST;
2344*35238bceSAndroid Build Coastguard Worker DE_ASSERT(secondDataType != glu::TYPE_LAST);
2345*35238bceSAndroid Build Coastguard Worker const char *const secondTypeName = glu::getDataTypeName(secondDataType);
2346*35238bceSAndroid Build Coastguard Worker const string name = string("") + typeName + "_" + secondTypeName;
2347*35238bceSAndroid Build Coastguard Worker
2348*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_BASIC_STRUCT].cases.push_back(
2349*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(name.c_str(), UniformCollection::basicStruct(dataType, secondDataType, false)));
2350*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT].cases.push_back(
2351*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(name.c_str(), UniformCollection::basicStruct(dataType, secondDataType, true)));
2352*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_STRUCT_IN_ARRAY].cases.push_back(
2353*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(name.c_str(), UniformCollection::structInArray(dataType, secondDataType, false)));
2354*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_NESTED_STRUCTS_ARRAYS].cases.push_back(
2355*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(name.c_str(), UniformCollection::nestedArraysStructs(dataType, secondDataType)));
2356*35238bceSAndroid Build Coastguard Worker }
2357*35238bceSAndroid Build Coastguard Worker }
2358*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_BASIC].cases.push_back(
2359*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(DE_NULL, UniformCollection::multipleBasic()));
2360*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_BASIC_ARRAY].cases.push_back(
2361*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(DE_NULL, UniformCollection::multipleBasicArray()));
2362*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_MULTIPLE_NESTED_STRUCTS_ARRAYS].cases.push_back(
2363*35238bceSAndroid Build Coastguard Worker UniformCollectionCase(DE_NULL, UniformCollection::multipleNestedArraysStructs()));
2364*35238bceSAndroid Build Coastguard Worker
2365*35238bceSAndroid Build Coastguard Worker // Info-query cases (check info returned by e.g. glGetActiveUniforms()).
2366*35238bceSAndroid Build Coastguard Worker
2367*35238bceSAndroid Build Coastguard Worker {
2368*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const infoQueryGroup = new TestCaseGroup(m_context, "info_query", "Test glGetActiveUniform()");
2369*35238bceSAndroid Build Coastguard Worker addChild(infoQueryGroup);
2370*35238bceSAndroid Build Coastguard Worker
2371*35238bceSAndroid Build Coastguard Worker for (int collectionGroupNdx = 0; collectionGroupNdx < (int)UNIFORMCOLLECTIONS_LAST; collectionGroupNdx++)
2372*35238bceSAndroid Build Coastguard Worker {
2373*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup = defaultUniformCollections[collectionGroupNdx];
2374*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const collectionTestGroup = new TestCaseGroup(m_context, collectionGroup.name.c_str(), "");
2375*35238bceSAndroid Build Coastguard Worker infoQueryGroup->addChild(collectionTestGroup);
2376*35238bceSAndroid Build Coastguard Worker
2377*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size(); collectionNdx++)
2378*35238bceSAndroid Build Coastguard Worker {
2379*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2380*35238bceSAndroid Build Coastguard Worker
2381*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2382*35238bceSAndroid Build Coastguard Worker {
2383*35238bceSAndroid Build Coastguard Worker const string name = collectionCase.namePrefix + getCaseShaderTypeName((CaseShaderType)shaderType);
2384*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection = collectionCase.uniformCollection;
2385*35238bceSAndroid Build Coastguard Worker
2386*35238bceSAndroid Build Coastguard Worker collectionTestGroup->addChild(new UniformInfoQueryCase(
2387*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection));
2388*35238bceSAndroid Build Coastguard Worker }
2389*35238bceSAndroid Build Coastguard Worker }
2390*35238bceSAndroid Build Coastguard Worker }
2391*35238bceSAndroid Build Coastguard Worker
2392*35238bceSAndroid Build Coastguard Worker // Info-querying cases when unused uniforms are present.
2393*35238bceSAndroid Build Coastguard Worker
2394*35238bceSAndroid Build Coastguard Worker {
2395*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const unusedUniformsGroup =
2396*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, "unused_uniforms", "Test with unused uniforms");
2397*35238bceSAndroid Build Coastguard Worker infoQueryGroup->addChild(unusedUniformsGroup);
2398*35238bceSAndroid Build Coastguard Worker
2399*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup =
2400*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT];
2401*35238bceSAndroid Build Coastguard Worker
2402*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size(); collectionNdx++)
2403*35238bceSAndroid Build Coastguard Worker {
2404*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2405*35238bceSAndroid Build Coastguard Worker const string collName = collectionCase.namePrefix;
2406*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection = collectionCase.uniformCollection;
2407*35238bceSAndroid Build Coastguard Worker
2408*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2409*35238bceSAndroid Build Coastguard Worker {
2410*35238bceSAndroid Build Coastguard Worker const string name = collName + getCaseShaderTypeName((CaseShaderType)shaderType);
2411*35238bceSAndroid Build Coastguard Worker unusedUniformsGroup->addChild(new UniformInfoQueryCase(
2412*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection,
2413*35238bceSAndroid Build Coastguard Worker UniformCase::FEATURE_UNIFORMUSAGE_EVERY_OTHER |
2414*35238bceSAndroid Build Coastguard Worker UniformCase::FEATURE_ARRAYUSAGE_ONLY_MIDDLE_INDEX));
2415*35238bceSAndroid Build Coastguard Worker }
2416*35238bceSAndroid Build Coastguard Worker }
2417*35238bceSAndroid Build Coastguard Worker }
2418*35238bceSAndroid Build Coastguard Worker }
2419*35238bceSAndroid Build Coastguard Worker
2420*35238bceSAndroid Build Coastguard Worker // Cases testing uniform values.
2421*35238bceSAndroid Build Coastguard Worker
2422*35238bceSAndroid Build Coastguard Worker {
2423*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const valueGroup = new TestCaseGroup(m_context, "value", "Uniform value tests");
2424*35238bceSAndroid Build Coastguard Worker addChild(valueGroup);
2425*35238bceSAndroid Build Coastguard Worker
2426*35238bceSAndroid Build Coastguard Worker // Cases checking uniforms' initial values (all must be zeros), with glGetUniform*() or by rendering.
2427*35238bceSAndroid Build Coastguard Worker
2428*35238bceSAndroid Build Coastguard Worker {
2429*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const initialValuesGroup = new TestCaseGroup(
2430*35238bceSAndroid Build Coastguard Worker m_context, UniformValueCase::getValueToCheckName(UniformValueCase::VALUETOCHECK_INITIAL),
2431*35238bceSAndroid Build Coastguard Worker UniformValueCase::getValueToCheckDescription(UniformValueCase::VALUETOCHECK_INITIAL));
2432*35238bceSAndroid Build Coastguard Worker valueGroup->addChild(initialValuesGroup);
2433*35238bceSAndroid Build Coastguard Worker
2434*35238bceSAndroid Build Coastguard Worker for (int checkMethodI = 0; checkMethodI < (int)UniformValueCase::CHECKMETHOD_LAST; checkMethodI++)
2435*35238bceSAndroid Build Coastguard Worker {
2436*35238bceSAndroid Build Coastguard Worker const UniformValueCase::CheckMethod checkMethod = (UniformValueCase::CheckMethod)checkMethodI;
2437*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const checkMethodGroup =
2438*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, UniformValueCase::getCheckMethodName(checkMethod),
2439*35238bceSAndroid Build Coastguard Worker UniformValueCase::getCheckMethodDescription(checkMethod));
2440*35238bceSAndroid Build Coastguard Worker initialValuesGroup->addChild(checkMethodGroup);
2441*35238bceSAndroid Build Coastguard Worker
2442*35238bceSAndroid Build Coastguard Worker for (int collectionGroupNdx = 0; collectionGroupNdx < (int)UNIFORMCOLLECTIONS_LAST;
2443*35238bceSAndroid Build Coastguard Worker collectionGroupNdx++)
2444*35238bceSAndroid Build Coastguard Worker {
2445*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup = defaultUniformCollections[collectionGroupNdx];
2446*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const collectionTestGroup =
2447*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, collectionGroup.name.c_str(), "");
2448*35238bceSAndroid Build Coastguard Worker checkMethodGroup->addChild(collectionTestGroup);
2449*35238bceSAndroid Build Coastguard Worker
2450*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size(); collectionNdx++)
2451*35238bceSAndroid Build Coastguard Worker {
2452*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2453*35238bceSAndroid Build Coastguard Worker const string collName = collectionCase.namePrefix;
2454*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection = collectionCase.uniformCollection;
2455*35238bceSAndroid Build Coastguard Worker const bool containsBooleans =
2456*35238bceSAndroid Build Coastguard Worker uniformCollection->containsMatchingBasicType(glu::isDataTypeBoolOrBVec);
2457*35238bceSAndroid Build Coastguard Worker const bool varyBoolApiType = checkMethod == UniformValueCase::CHECKMETHOD_GET_UNIFORM &&
2458*35238bceSAndroid Build Coastguard Worker containsBooleans &&
2459*35238bceSAndroid Build Coastguard Worker (collectionGroupNdx == UNIFORMCOLLECTIONS_BASIC ||
2460*35238bceSAndroid Build Coastguard Worker collectionGroupNdx == UNIFORMCOLLECTIONS_BASIC_ARRAY);
2461*35238bceSAndroid Build Coastguard Worker const int numBoolVariations = varyBoolApiType ? 2 : 1;
2462*35238bceSAndroid Build Coastguard Worker
2463*35238bceSAndroid Build Coastguard Worker if (checkMethod == UniformValueCase::CHECKMETHOD_RENDER &&
2464*35238bceSAndroid Build Coastguard Worker uniformCollection->containsSeveralSamplerTypes())
2465*35238bceSAndroid Build Coastguard Worker continue; // \note Samplers' initial API values (i.e. their texture units) are 0, and no two samplers of different types shall have same unit when rendering.
2466*35238bceSAndroid Build Coastguard Worker
2467*35238bceSAndroid Build Coastguard Worker for (int booleanTypeI = 0; booleanTypeI < numBoolVariations; booleanTypeI++)
2468*35238bceSAndroid Build Coastguard Worker {
2469*35238bceSAndroid Build Coastguard Worker const uint32_t booleanTypeFeat =
2470*35238bceSAndroid Build Coastguard Worker booleanTypeI == 1 ? UniformCase::FEATURE_BOOLEANAPITYPE_INT : 0;
2471*35238bceSAndroid Build Coastguard Worker const char *const booleanTypeName = booleanTypeI == 1 ? "int" : "float";
2472*35238bceSAndroid Build Coastguard Worker const string nameWithApiType =
2473*35238bceSAndroid Build Coastguard Worker varyBoolApiType ? collName + "api_" + booleanTypeName + "_" : collName;
2474*35238bceSAndroid Build Coastguard Worker
2475*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2476*35238bceSAndroid Build Coastguard Worker {
2477*35238bceSAndroid Build Coastguard Worker const string name = nameWithApiType + getCaseShaderTypeName((CaseShaderType)shaderType);
2478*35238bceSAndroid Build Coastguard Worker collectionTestGroup->addChild(new UniformValueCase(
2479*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection,
2480*35238bceSAndroid Build Coastguard Worker UniformValueCase::VALUETOCHECK_INITIAL, checkMethod,
2481*35238bceSAndroid Build Coastguard Worker UniformValueCase::ASSIGNMETHOD_LAST, booleanTypeFeat));
2482*35238bceSAndroid Build Coastguard Worker }
2483*35238bceSAndroid Build Coastguard Worker }
2484*35238bceSAndroid Build Coastguard Worker }
2485*35238bceSAndroid Build Coastguard Worker }
2486*35238bceSAndroid Build Coastguard Worker }
2487*35238bceSAndroid Build Coastguard Worker }
2488*35238bceSAndroid Build Coastguard Worker
2489*35238bceSAndroid Build Coastguard Worker // Cases that first assign values to each uniform, then check the values with glGetUniform*() or by rendering.
2490*35238bceSAndroid Build Coastguard Worker
2491*35238bceSAndroid Build Coastguard Worker {
2492*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const assignedValuesGroup = new TestCaseGroup(
2493*35238bceSAndroid Build Coastguard Worker m_context, UniformValueCase::getValueToCheckName(UniformValueCase::VALUETOCHECK_ASSIGNED),
2494*35238bceSAndroid Build Coastguard Worker UniformValueCase::getValueToCheckDescription(UniformValueCase::VALUETOCHECK_ASSIGNED));
2495*35238bceSAndroid Build Coastguard Worker valueGroup->addChild(assignedValuesGroup);
2496*35238bceSAndroid Build Coastguard Worker
2497*35238bceSAndroid Build Coastguard Worker for (int assignMethodI = 0; assignMethodI < (int)UniformValueCase::ASSIGNMETHOD_LAST; assignMethodI++)
2498*35238bceSAndroid Build Coastguard Worker {
2499*35238bceSAndroid Build Coastguard Worker const UniformValueCase::AssignMethod assignMethod = (UniformValueCase::AssignMethod)assignMethodI;
2500*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const assignMethodGroup =
2501*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, UniformValueCase::getAssignMethodName(assignMethod),
2502*35238bceSAndroid Build Coastguard Worker UniformValueCase::getAssignMethodDescription(assignMethod));
2503*35238bceSAndroid Build Coastguard Worker assignedValuesGroup->addChild(assignMethodGroup);
2504*35238bceSAndroid Build Coastguard Worker
2505*35238bceSAndroid Build Coastguard Worker for (int checkMethodI = 0; checkMethodI < (int)UniformValueCase::CHECKMETHOD_LAST; checkMethodI++)
2506*35238bceSAndroid Build Coastguard Worker {
2507*35238bceSAndroid Build Coastguard Worker const UniformValueCase::CheckMethod checkMethod = (UniformValueCase::CheckMethod)checkMethodI;
2508*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const checkMethodGroup =
2509*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, UniformValueCase::getCheckMethodName(checkMethod),
2510*35238bceSAndroid Build Coastguard Worker UniformValueCase::getCheckMethodDescription(checkMethod));
2511*35238bceSAndroid Build Coastguard Worker assignMethodGroup->addChild(checkMethodGroup);
2512*35238bceSAndroid Build Coastguard Worker
2513*35238bceSAndroid Build Coastguard Worker for (int collectionGroupNdx = 0; collectionGroupNdx < (int)UNIFORMCOLLECTIONS_LAST;
2514*35238bceSAndroid Build Coastguard Worker collectionGroupNdx++)
2515*35238bceSAndroid Build Coastguard Worker {
2516*35238bceSAndroid Build Coastguard Worker const int numArrayFirstElemNameCases =
2517*35238bceSAndroid Build Coastguard Worker checkMethod == UniformValueCase::CHECKMETHOD_GET_UNIFORM &&
2518*35238bceSAndroid Build Coastguard Worker collectionGroupNdx == UNIFORMCOLLECTIONS_BASIC_ARRAY ?
2519*35238bceSAndroid Build Coastguard Worker 2 :
2520*35238bceSAndroid Build Coastguard Worker 1;
2521*35238bceSAndroid Build Coastguard Worker
2522*35238bceSAndroid Build Coastguard Worker for (int referToFirstArrayElemWithoutIndexI = 0;
2523*35238bceSAndroid Build Coastguard Worker referToFirstArrayElemWithoutIndexI < numArrayFirstElemNameCases;
2524*35238bceSAndroid Build Coastguard Worker referToFirstArrayElemWithoutIndexI++)
2525*35238bceSAndroid Build Coastguard Worker {
2526*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup =
2527*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[collectionGroupNdx];
2528*35238bceSAndroid Build Coastguard Worker const string collectionGroupName =
2529*35238bceSAndroid Build Coastguard Worker collectionGroup.name +
2530*35238bceSAndroid Build Coastguard Worker (referToFirstArrayElemWithoutIndexI == 0 ? "" : "_first_elem_without_brackets");
2531*35238bceSAndroid Build Coastguard Worker TestCaseGroup *collectionTestGroup = DE_NULL;
2532*35238bceSAndroid Build Coastguard Worker
2533*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size();
2534*35238bceSAndroid Build Coastguard Worker collectionNdx++)
2535*35238bceSAndroid Build Coastguard Worker {
2536*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2537*35238bceSAndroid Build Coastguard Worker const string collName = collectionCase.namePrefix;
2538*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection =
2539*35238bceSAndroid Build Coastguard Worker collectionCase.uniformCollection;
2540*35238bceSAndroid Build Coastguard Worker const bool containsBooleans =
2541*35238bceSAndroid Build Coastguard Worker uniformCollection->containsMatchingBasicType(glu::isDataTypeBoolOrBVec);
2542*35238bceSAndroid Build Coastguard Worker const bool varyBoolApiType = checkMethod == UniformValueCase::CHECKMETHOD_GET_UNIFORM &&
2543*35238bceSAndroid Build Coastguard Worker containsBooleans &&
2544*35238bceSAndroid Build Coastguard Worker (collectionGroupNdx == UNIFORMCOLLECTIONS_BASIC ||
2545*35238bceSAndroid Build Coastguard Worker collectionGroupNdx == UNIFORMCOLLECTIONS_BASIC_ARRAY);
2546*35238bceSAndroid Build Coastguard Worker const int numBoolVariations = varyBoolApiType ? 2 : 1;
2547*35238bceSAndroid Build Coastguard Worker const bool containsMatrices =
2548*35238bceSAndroid Build Coastguard Worker uniformCollection->containsMatchingBasicType(glu::isDataTypeMatrix);
2549*35238bceSAndroid Build Coastguard Worker
2550*35238bceSAndroid Build Coastguard Worker if (containsMatrices && assignMethod != UniformValueCase::ASSIGNMETHOD_POINTER)
2551*35238bceSAndroid Build Coastguard Worker continue;
2552*35238bceSAndroid Build Coastguard Worker
2553*35238bceSAndroid Build Coastguard Worker for (int booleanTypeI = 0; booleanTypeI < numBoolVariations; booleanTypeI++)
2554*35238bceSAndroid Build Coastguard Worker {
2555*35238bceSAndroid Build Coastguard Worker const uint32_t booleanTypeFeat =
2556*35238bceSAndroid Build Coastguard Worker booleanTypeI == 1 ? UniformCase::FEATURE_BOOLEANAPITYPE_INT : 0;
2557*35238bceSAndroid Build Coastguard Worker const char *const booleanTypeName = booleanTypeI == 1 ? "int" : "float";
2558*35238bceSAndroid Build Coastguard Worker const string nameWithBoolType =
2559*35238bceSAndroid Build Coastguard Worker varyBoolApiType ? collName + "api_" + booleanTypeName + "_" : collName;
2560*35238bceSAndroid Build Coastguard Worker const string nameWithMatrixType = nameWithBoolType;
2561*35238bceSAndroid Build Coastguard Worker
2562*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2563*35238bceSAndroid Build Coastguard Worker {
2564*35238bceSAndroid Build Coastguard Worker const string name =
2565*35238bceSAndroid Build Coastguard Worker nameWithMatrixType + getCaseShaderTypeName((CaseShaderType)shaderType);
2566*35238bceSAndroid Build Coastguard Worker const uint32_t arrayFirstElemNameNoIndexFeat =
2567*35238bceSAndroid Build Coastguard Worker referToFirstArrayElemWithoutIndexI == 0 ?
2568*35238bceSAndroid Build Coastguard Worker 0 :
2569*35238bceSAndroid Build Coastguard Worker UniformCase::FEATURE_ARRAY_FIRST_ELEM_NAME_NO_INDEX;
2570*35238bceSAndroid Build Coastguard Worker
2571*35238bceSAndroid Build Coastguard Worker // skip empty groups by creating groups on demand
2572*35238bceSAndroid Build Coastguard Worker if (!collectionTestGroup)
2573*35238bceSAndroid Build Coastguard Worker {
2574*35238bceSAndroid Build Coastguard Worker collectionTestGroup =
2575*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, collectionGroupName.c_str(), "");
2576*35238bceSAndroid Build Coastguard Worker checkMethodGroup->addChild(collectionTestGroup);
2577*35238bceSAndroid Build Coastguard Worker }
2578*35238bceSAndroid Build Coastguard Worker
2579*35238bceSAndroid Build Coastguard Worker collectionTestGroup->addChild(new UniformValueCase(
2580*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection,
2581*35238bceSAndroid Build Coastguard Worker UniformValueCase::VALUETOCHECK_ASSIGNED, checkMethod, assignMethod,
2582*35238bceSAndroid Build Coastguard Worker booleanTypeFeat | arrayFirstElemNameNoIndexFeat));
2583*35238bceSAndroid Build Coastguard Worker }
2584*35238bceSAndroid Build Coastguard Worker }
2585*35238bceSAndroid Build Coastguard Worker }
2586*35238bceSAndroid Build Coastguard Worker }
2587*35238bceSAndroid Build Coastguard Worker }
2588*35238bceSAndroid Build Coastguard Worker }
2589*35238bceSAndroid Build Coastguard Worker }
2590*35238bceSAndroid Build Coastguard Worker
2591*35238bceSAndroid Build Coastguard Worker // Cases assign multiple basic-array elements with one glUniform*v() (i.e. the count parameter is bigger than 1).
2592*35238bceSAndroid Build Coastguard Worker
2593*35238bceSAndroid Build Coastguard Worker {
2594*35238bceSAndroid Build Coastguard Worker static const struct
2595*35238bceSAndroid Build Coastguard Worker {
2596*35238bceSAndroid Build Coastguard Worker UniformCase::Feature arrayAssignMode;
2597*35238bceSAndroid Build Coastguard Worker const char *name;
2598*35238bceSAndroid Build Coastguard Worker const char *description;
2599*35238bceSAndroid Build Coastguard Worker } arrayAssignGroups[] = {{UniformCase::FEATURE_ARRAYASSIGN_FULL, "basic_array_assign_full",
2600*35238bceSAndroid Build Coastguard Worker "Assign entire basic-type arrays per glUniform*v() call"},
2601*35238bceSAndroid Build Coastguard Worker {UniformCase::FEATURE_ARRAYASSIGN_BLOCKS_OF_TWO, "basic_array_assign_partial",
2602*35238bceSAndroid Build Coastguard Worker "Assign two elements of a basic-type array per glUniform*v() call"}};
2603*35238bceSAndroid Build Coastguard Worker
2604*35238bceSAndroid Build Coastguard Worker for (int arrayAssignGroupNdx = 0; arrayAssignGroupNdx < DE_LENGTH_OF_ARRAY(arrayAssignGroups);
2605*35238bceSAndroid Build Coastguard Worker arrayAssignGroupNdx++)
2606*35238bceSAndroid Build Coastguard Worker {
2607*35238bceSAndroid Build Coastguard Worker UniformCase::Feature arrayAssignMode = arrayAssignGroups[arrayAssignGroupNdx].arrayAssignMode;
2608*35238bceSAndroid Build Coastguard Worker const char *const groupName = arrayAssignGroups[arrayAssignGroupNdx].name;
2609*35238bceSAndroid Build Coastguard Worker const char *const groupDesc = arrayAssignGroups[arrayAssignGroupNdx].description;
2610*35238bceSAndroid Build Coastguard Worker
2611*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const curArrayAssignGroup = new TestCaseGroup(m_context, groupName, groupDesc);
2612*35238bceSAndroid Build Coastguard Worker assignedValuesGroup->addChild(curArrayAssignGroup);
2613*35238bceSAndroid Build Coastguard Worker
2614*35238bceSAndroid Build Coastguard Worker static const int basicArrayCollectionGroups[] = {UNIFORMCOLLECTIONS_BASIC_ARRAY,
2615*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT,
2616*35238bceSAndroid Build Coastguard Worker UNIFORMCOLLECTIONS_MULTIPLE_BASIC_ARRAY};
2617*35238bceSAndroid Build Coastguard Worker
2618*35238bceSAndroid Build Coastguard Worker for (int collectionGroupNdx = 0;
2619*35238bceSAndroid Build Coastguard Worker collectionGroupNdx < DE_LENGTH_OF_ARRAY(basicArrayCollectionGroups); collectionGroupNdx++)
2620*35238bceSAndroid Build Coastguard Worker {
2621*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup =
2622*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[basicArrayCollectionGroups[collectionGroupNdx]];
2623*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const collectionTestGroup =
2624*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, collectionGroup.name.c_str(), "");
2625*35238bceSAndroid Build Coastguard Worker curArrayAssignGroup->addChild(collectionTestGroup);
2626*35238bceSAndroid Build Coastguard Worker
2627*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size(); collectionNdx++)
2628*35238bceSAndroid Build Coastguard Worker {
2629*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2630*35238bceSAndroid Build Coastguard Worker const string collName = collectionCase.namePrefix;
2631*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection =
2632*35238bceSAndroid Build Coastguard Worker collectionCase.uniformCollection;
2633*35238bceSAndroid Build Coastguard Worker
2634*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2635*35238bceSAndroid Build Coastguard Worker {
2636*35238bceSAndroid Build Coastguard Worker const string name = collName + getCaseShaderTypeName((CaseShaderType)shaderType);
2637*35238bceSAndroid Build Coastguard Worker collectionTestGroup->addChild(new UniformValueCase(
2638*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection,
2639*35238bceSAndroid Build Coastguard Worker UniformValueCase::VALUETOCHECK_ASSIGNED, UniformValueCase::CHECKMETHOD_GET_UNIFORM,
2640*35238bceSAndroid Build Coastguard Worker UniformValueCase::ASSIGNMETHOD_POINTER, arrayAssignMode));
2641*35238bceSAndroid Build Coastguard Worker }
2642*35238bceSAndroid Build Coastguard Worker }
2643*35238bceSAndroid Build Coastguard Worker }
2644*35238bceSAndroid Build Coastguard Worker }
2645*35238bceSAndroid Build Coastguard Worker }
2646*35238bceSAndroid Build Coastguard Worker
2647*35238bceSAndroid Build Coastguard Worker // Value checking cases when unused uniforms are present.
2648*35238bceSAndroid Build Coastguard Worker
2649*35238bceSAndroid Build Coastguard Worker {
2650*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const unusedUniformsGroup =
2651*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_context, "unused_uniforms", "Test with unused uniforms");
2652*35238bceSAndroid Build Coastguard Worker assignedValuesGroup->addChild(unusedUniformsGroup);
2653*35238bceSAndroid Build Coastguard Worker
2654*35238bceSAndroid Build Coastguard Worker const UniformCollectionGroup &collectionGroup =
2655*35238bceSAndroid Build Coastguard Worker defaultUniformCollections[UNIFORMCOLLECTIONS_ARRAY_IN_STRUCT];
2656*35238bceSAndroid Build Coastguard Worker
2657*35238bceSAndroid Build Coastguard Worker for (int collectionNdx = 0; collectionNdx < (int)collectionGroup.cases.size(); collectionNdx++)
2658*35238bceSAndroid Build Coastguard Worker {
2659*35238bceSAndroid Build Coastguard Worker const UniformCollectionCase &collectionCase = collectionGroup.cases[collectionNdx];
2660*35238bceSAndroid Build Coastguard Worker const string collName = collectionCase.namePrefix;
2661*35238bceSAndroid Build Coastguard Worker const SharedPtr<const UniformCollection> &uniformCollection = collectionCase.uniformCollection;
2662*35238bceSAndroid Build Coastguard Worker
2663*35238bceSAndroid Build Coastguard Worker for (int shaderType = 0; shaderType < (int)CASESHADERTYPE_LAST; shaderType++)
2664*35238bceSAndroid Build Coastguard Worker {
2665*35238bceSAndroid Build Coastguard Worker const string name = collName + getCaseShaderTypeName((CaseShaderType)shaderType);
2666*35238bceSAndroid Build Coastguard Worker unusedUniformsGroup->addChild(new UniformValueCase(
2667*35238bceSAndroid Build Coastguard Worker m_context, name.c_str(), "", (CaseShaderType)shaderType, uniformCollection,
2668*35238bceSAndroid Build Coastguard Worker UniformValueCase::VALUETOCHECK_ASSIGNED, UniformValueCase::CHECKMETHOD_GET_UNIFORM,
2669*35238bceSAndroid Build Coastguard Worker UniformValueCase::ASSIGNMETHOD_POINTER,
2670*35238bceSAndroid Build Coastguard Worker UniformCase::FEATURE_ARRAYUSAGE_ONLY_MIDDLE_INDEX |
2671*35238bceSAndroid Build Coastguard Worker UniformCase::FEATURE_UNIFORMUSAGE_EVERY_OTHER));
2672*35238bceSAndroid Build Coastguard Worker }
2673*35238bceSAndroid Build Coastguard Worker }
2674*35238bceSAndroid Build Coastguard Worker }
2675*35238bceSAndroid Build Coastguard Worker }
2676*35238bceSAndroid Build Coastguard Worker }
2677*35238bceSAndroid Build Coastguard Worker
2678*35238bceSAndroid Build Coastguard Worker // Random cases.
2679*35238bceSAndroid Build Coastguard Worker
2680*35238bceSAndroid Build Coastguard Worker {
2681*35238bceSAndroid Build Coastguard Worker const int numRandomCases = 100;
2682*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const randomGroup = new TestCaseGroup(m_context, "random", "Random cases");
2683*35238bceSAndroid Build Coastguard Worker addChild(randomGroup);
2684*35238bceSAndroid Build Coastguard Worker
2685*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numRandomCases; ndx++)
2686*35238bceSAndroid Build Coastguard Worker randomGroup->addChild(new RandomUniformCase(m_context, de::toString(ndx).c_str(), "", (uint32_t)ndx));
2687*35238bceSAndroid Build Coastguard Worker }
2688*35238bceSAndroid Build Coastguard Worker }
2689*35238bceSAndroid Build Coastguard Worker
2690*35238bceSAndroid Build Coastguard Worker } // namespace Functional
2691*35238bceSAndroid Build Coastguard Worker } // namespace gles2
2692*35238bceSAndroid Build Coastguard Worker } // namespace deqp
2693