xref: /aosp_15_r20/external/deqp/modules/gles2/stress/es2sDrawTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 Drawing tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2sDrawTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsDrawTest.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker #include <set>
34*35238bceSAndroid Build Coastguard Worker 
35*35238bceSAndroid Build Coastguard Worker namespace deqp
36*35238bceSAndroid Build Coastguard Worker {
37*35238bceSAndroid Build Coastguard Worker namespace gles2
38*35238bceSAndroid Build Coastguard Worker {
39*35238bceSAndroid Build Coastguard Worker namespace Stress
40*35238bceSAndroid Build Coastguard Worker {
41*35238bceSAndroid Build Coastguard Worker namespace
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker 
genBasicSpec(gls::DrawTestSpec & spec,gls::DrawTestSpec::DrawMethod method)44*35238bceSAndroid Build Coastguard Worker static void genBasicSpec(gls::DrawTestSpec &spec, gls::DrawTestSpec::DrawMethod method)
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker     spec.apiType            = glu::ApiType::es(2, 0);
47*35238bceSAndroid Build Coastguard Worker     spec.primitive          = gls::DrawTestSpec::PRIMITIVE_TRIANGLES;
48*35238bceSAndroid Build Coastguard Worker     spec.primitiveCount     = 5;
49*35238bceSAndroid Build Coastguard Worker     spec.drawMethod         = method;
50*35238bceSAndroid Build Coastguard Worker     spec.indexType          = gls::DrawTestSpec::INDEXTYPE_LAST;
51*35238bceSAndroid Build Coastguard Worker     spec.indexPointerOffset = 0;
52*35238bceSAndroid Build Coastguard Worker     spec.indexStorage       = gls::DrawTestSpec::STORAGE_LAST;
53*35238bceSAndroid Build Coastguard Worker     spec.first              = 0;
54*35238bceSAndroid Build Coastguard Worker     spec.indexMin           = 0;
55*35238bceSAndroid Build Coastguard Worker     spec.indexMax           = 0;
56*35238bceSAndroid Build Coastguard Worker     spec.instanceCount      = 1;
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker     spec.attribs.resize(2);
59*35238bceSAndroid Build Coastguard Worker 
60*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
61*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
62*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
63*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
64*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].componentCount      = 4;
65*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].offset              = 0;
66*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].stride              = 0;
67*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].normalize           = false;
68*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].instanceDivisor     = 0;
69*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].useDefaultAttribute = false;
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
72*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
73*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
74*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
75*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].componentCount      = 2;
76*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].offset              = 0;
77*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].stride              = 0;
78*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].normalize           = false;
79*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].instanceDivisor     = 0;
80*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].useDefaultAttribute = false;
81*35238bceSAndroid Build Coastguard Worker }
82*35238bceSAndroid Build Coastguard Worker 
83*35238bceSAndroid Build Coastguard Worker class IndexGroup : public TestCaseGroup
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker public:
86*35238bceSAndroid Build Coastguard Worker     IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
87*35238bceSAndroid Build Coastguard Worker     ~IndexGroup(void);
88*35238bceSAndroid Build Coastguard Worker 
89*35238bceSAndroid Build Coastguard Worker     void init(void);
90*35238bceSAndroid Build Coastguard Worker 
91*35238bceSAndroid Build Coastguard Worker private:
92*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
93*35238bceSAndroid Build Coastguard Worker };
94*35238bceSAndroid Build Coastguard Worker 
IndexGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)95*35238bceSAndroid Build Coastguard Worker IndexGroup::IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod)
96*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
97*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
98*35238bceSAndroid Build Coastguard Worker {
99*35238bceSAndroid Build Coastguard Worker }
100*35238bceSAndroid Build Coastguard Worker 
~IndexGroup(void)101*35238bceSAndroid Build Coastguard Worker IndexGroup::~IndexGroup(void)
102*35238bceSAndroid Build Coastguard Worker {
103*35238bceSAndroid Build Coastguard Worker }
104*35238bceSAndroid Build Coastguard Worker 
init(void)105*35238bceSAndroid Build Coastguard Worker void IndexGroup::init(void)
106*35238bceSAndroid Build Coastguard Worker {
107*35238bceSAndroid Build Coastguard Worker     struct IndexTest
108*35238bceSAndroid Build Coastguard Worker     {
109*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::Storage storage;
110*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::IndexType type;
111*35238bceSAndroid Build Coastguard Worker         bool aligned;
112*35238bceSAndroid Build Coastguard Worker         int offsets[3];
113*35238bceSAndroid Build Coastguard Worker     };
114*35238bceSAndroid Build Coastguard Worker 
115*35238bceSAndroid Build Coastguard Worker     const IndexTest tests[] = {
116*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_SHORT, false, {1, 3, -1}},
117*35238bceSAndroid Build Coastguard Worker     };
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec;
120*35238bceSAndroid Build Coastguard Worker 
121*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *unalignedBufferGroup =
122*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "unaligned_buffer", "unaligned buffer");
123*35238bceSAndroid Build Coastguard Worker 
124*35238bceSAndroid Build Coastguard Worker     genBasicSpec(spec, m_method);
125*35238bceSAndroid Build Coastguard Worker 
126*35238bceSAndroid Build Coastguard Worker     this->addChild(unalignedBufferGroup);
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker     for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
129*35238bceSAndroid Build Coastguard Worker     {
130*35238bceSAndroid Build Coastguard Worker         const IndexTest &indexTest = tests[testNdx];
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(indexTest.storage != gls::DrawTestSpec::STORAGE_USER);
133*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(!indexTest.aligned);
134*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *group = unalignedBufferGroup;
135*35238bceSAndroid Build Coastguard Worker 
136*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("index_") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
137*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type) + " in " +
138*35238bceSAndroid Build Coastguard Worker                                  gls::DrawTestSpec::storageToString(indexTest.storage);
139*35238bceSAndroid Build Coastguard Worker         de::MovePtr<gls::DrawTest> test(
140*35238bceSAndroid Build Coastguard Worker             new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()));
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker         spec.indexType    = indexTest.type;
143*35238bceSAndroid Build Coastguard Worker         spec.indexStorage = indexTest.storage;
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker         for (int iterationNdx = 0;
146*35238bceSAndroid Build Coastguard Worker              iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.offsets) && indexTest.offsets[iterationNdx] != -1;
147*35238bceSAndroid Build Coastguard Worker              ++iterationNdx)
148*35238bceSAndroid Build Coastguard Worker         {
149*35238bceSAndroid Build Coastguard Worker             const std::string iterationDesc = std::string("offset ") + de::toString(indexTest.offsets[iterationNdx]);
150*35238bceSAndroid Build Coastguard Worker             spec.indexPointerOffset         = indexTest.offsets[iterationNdx];
151*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, iterationDesc.c_str());
152*35238bceSAndroid Build Coastguard Worker         }
153*35238bceSAndroid Build Coastguard Worker 
154*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET ||
155*35238bceSAndroid Build Coastguard Worker                   spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE);
156*35238bceSAndroid Build Coastguard Worker         group->addChild(test.release());
157*35238bceSAndroid Build Coastguard Worker     }
158*35238bceSAndroid Build Coastguard Worker }
159*35238bceSAndroid Build Coastguard Worker 
160*35238bceSAndroid Build Coastguard Worker class MethodGroup : public TestCaseGroup
161*35238bceSAndroid Build Coastguard Worker {
162*35238bceSAndroid Build Coastguard Worker public:
163*35238bceSAndroid Build Coastguard Worker     MethodGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
164*35238bceSAndroid Build Coastguard Worker     ~MethodGroup(void);
165*35238bceSAndroid Build Coastguard Worker 
166*35238bceSAndroid Build Coastguard Worker     void init(void);
167*35238bceSAndroid Build Coastguard Worker 
168*35238bceSAndroid Build Coastguard Worker private:
169*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
170*35238bceSAndroid Build Coastguard Worker };
171*35238bceSAndroid Build Coastguard Worker 
MethodGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)172*35238bceSAndroid Build Coastguard Worker MethodGroup::MethodGroup(Context &context, const char *name, const char *descr,
173*35238bceSAndroid Build Coastguard Worker                          gls::DrawTestSpec::DrawMethod drawMethod)
174*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
175*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
176*35238bceSAndroid Build Coastguard Worker {
177*35238bceSAndroid Build Coastguard Worker }
178*35238bceSAndroid Build Coastguard Worker 
~MethodGroup(void)179*35238bceSAndroid Build Coastguard Worker MethodGroup::~MethodGroup(void)
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker }
182*35238bceSAndroid Build Coastguard Worker 
init(void)183*35238bceSAndroid Build Coastguard Worker void MethodGroup::init(void)
184*35238bceSAndroid Build Coastguard Worker {
185*35238bceSAndroid Build Coastguard Worker     const bool indexed = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS) ||
186*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED) ||
187*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED);
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(indexed);
190*35238bceSAndroid Build Coastguard Worker     DE_UNREF(indexed);
191*35238bceSAndroid Build Coastguard Worker 
192*35238bceSAndroid Build Coastguard Worker     this->addChild(new IndexGroup(m_context, "indices", "Index tests", m_method));
193*35238bceSAndroid Build Coastguard Worker }
194*35238bceSAndroid Build Coastguard Worker 
195*35238bceSAndroid Build Coastguard Worker class RandomGroup : public TestCaseGroup
196*35238bceSAndroid Build Coastguard Worker {
197*35238bceSAndroid Build Coastguard Worker public:
198*35238bceSAndroid Build Coastguard Worker     RandomGroup(Context &context, const char *name, const char *descr);
199*35238bceSAndroid Build Coastguard Worker     ~RandomGroup(void);
200*35238bceSAndroid Build Coastguard Worker 
201*35238bceSAndroid Build Coastguard Worker     void init(void);
202*35238bceSAndroid Build Coastguard Worker };
203*35238bceSAndroid Build Coastguard Worker 
204*35238bceSAndroid Build Coastguard Worker template <int SIZE>
205*35238bceSAndroid Build Coastguard Worker struct UniformWeightArray
206*35238bceSAndroid Build Coastguard Worker {
207*35238bceSAndroid Build Coastguard Worker     float weights[SIZE];
208*35238bceSAndroid Build Coastguard Worker 
UniformWeightArraydeqp::gles2::Stress::__anon970e44560111::UniformWeightArray209*35238bceSAndroid Build Coastguard Worker     UniformWeightArray(void)
210*35238bceSAndroid Build Coastguard Worker     {
211*35238bceSAndroid Build Coastguard Worker         for (int i = 0; i < SIZE; ++i)
212*35238bceSAndroid Build Coastguard Worker             weights[i] = 1.0f;
213*35238bceSAndroid Build Coastguard Worker     }
214*35238bceSAndroid Build Coastguard Worker };
215*35238bceSAndroid Build Coastguard Worker 
RandomGroup(Context & context,const char * name,const char * descr)216*35238bceSAndroid Build Coastguard Worker RandomGroup::RandomGroup(Context &context, const char *name, const char *descr) : TestCaseGroup(context, name, descr)
217*35238bceSAndroid Build Coastguard Worker {
218*35238bceSAndroid Build Coastguard Worker }
219*35238bceSAndroid Build Coastguard Worker 
~RandomGroup(void)220*35238bceSAndroid Build Coastguard Worker RandomGroup::~RandomGroup(void)
221*35238bceSAndroid Build Coastguard Worker {
222*35238bceSAndroid Build Coastguard Worker }
223*35238bceSAndroid Build Coastguard Worker 
init(void)224*35238bceSAndroid Build Coastguard Worker void RandomGroup::init(void)
225*35238bceSAndroid Build Coastguard Worker {
226*35238bceSAndroid Build Coastguard Worker     const int numAttempts = 100;
227*35238bceSAndroid Build Coastguard Worker 
228*35238bceSAndroid Build Coastguard Worker     const int attribCounts[]            = {1, 2, 5};
229*35238bceSAndroid Build Coastguard Worker     const float attribWeights[]         = {30, 10, 1};
230*35238bceSAndroid Build Coastguard Worker     const int primitiveCounts[]         = {1, 5, 64};
231*35238bceSAndroid Build Coastguard Worker     const float primitiveCountWeights[] = {20, 10, 1};
232*35238bceSAndroid Build Coastguard Worker     const int indexOffsets[]            = {0, 7, 13};
233*35238bceSAndroid Build Coastguard Worker     const float indexOffsetWeights[]    = {20, 20, 1};
234*35238bceSAndroid Build Coastguard Worker     const int firsts[]                  = {0, 7, 13};
235*35238bceSAndroid Build Coastguard Worker     const float firstWeights[]          = {20, 20, 1};
236*35238bceSAndroid Build Coastguard Worker     const int offsets[]                 = {0, 1, 5, 12};
237*35238bceSAndroid Build Coastguard Worker     const float offsetWeights[]         = {50, 10, 10, 10};
238*35238bceSAndroid Build Coastguard Worker     const int strides[]                 = {0, 7, 16, 17};
239*35238bceSAndroid Build Coastguard Worker     const float strideWeights[]         = {50, 10, 10, 10};
240*35238bceSAndroid Build Coastguard Worker 
241*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Primitive primitives[] = {
242*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_POINTS,       gls::DrawTestSpec::PRIMITIVE_TRIANGLES,
243*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP,
244*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINES,        gls::DrawTestSpec::PRIMITIVE_LINE_STRIP,
245*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINE_LOOP};
246*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(primitives)> primitiveWeights;
247*35238bceSAndroid Build Coastguard Worker 
248*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod drawMethods[] = {
249*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS,
250*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS,
251*35238bceSAndroid Build Coastguard Worker     };
252*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(drawMethods)> drawMethodWeights;
253*35238bceSAndroid Build Coastguard Worker 
254*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::IndexType indexTypes[] = {
255*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INDEXTYPE_BYTE,
256*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INDEXTYPE_SHORT,
257*35238bceSAndroid Build Coastguard Worker     };
258*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(indexTypes)> indexTypeWeights;
259*35238bceSAndroid Build Coastguard Worker 
260*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Storage storages[] = {
261*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::STORAGE_USER,
262*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::STORAGE_BUFFER,
263*35238bceSAndroid Build Coastguard Worker     };
264*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(storages)> storageWeights;
265*35238bceSAndroid Build Coastguard Worker 
266*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::InputType inputTypes[] = {
267*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_FLOAT,         gls::DrawTestSpec::INPUTTYPE_FIXED,
268*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_BYTE,          gls::DrawTestSpec::INPUTTYPE_SHORT,
269*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_UNSIGNED_BYTE, gls::DrawTestSpec::INPUTTYPE_UNSIGNED_SHORT};
270*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(inputTypes)> inputTypeWeights;
271*35238bceSAndroid Build Coastguard Worker 
272*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::OutputType outputTypes[] = {
273*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_FLOAT,
274*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_VEC2,
275*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_VEC3,
276*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_VEC4,
277*35238bceSAndroid Build Coastguard Worker     };
278*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(outputTypes)> outputTypeWeights;
279*35238bceSAndroid Build Coastguard Worker 
280*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Usage usages[] = {
281*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_STATIC_DRAW,
282*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_DYNAMIC_DRAW,
283*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_STREAM_DRAW,
284*35238bceSAndroid Build Coastguard Worker     };
285*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(usages)> usageWeights;
286*35238bceSAndroid Build Coastguard Worker 
287*35238bceSAndroid Build Coastguard Worker     const uint32_t disallowedCases[] = {
288*35238bceSAndroid Build Coastguard Worker         3153, //!< extremely narrow triangle, results depend on sample positions
289*35238bceSAndroid Build Coastguard Worker     };
290*35238bceSAndroid Build Coastguard Worker 
291*35238bceSAndroid Build Coastguard Worker     std::set<uint32_t> insertedHashes;
292*35238bceSAndroid Build Coastguard Worker     size_t insertedCount = 0;
293*35238bceSAndroid Build Coastguard Worker 
294*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < numAttempts; ++ndx)
295*35238bceSAndroid Build Coastguard Worker     {
296*35238bceSAndroid Build Coastguard Worker         de::Random random(0xc551393 + ndx); // random does not depend on previous cases
297*35238bceSAndroid Build Coastguard Worker 
298*35238bceSAndroid Build Coastguard Worker         int attributeCount = random.chooseWeighted<int, const int *, const float *>(
299*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(attribCounts), DE_ARRAY_END(attribCounts), attribWeights);
300*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
301*35238bceSAndroid Build Coastguard Worker 
302*35238bceSAndroid Build Coastguard Worker         spec.apiType   = glu::ApiType::es(2, 0);
303*35238bceSAndroid Build Coastguard Worker         spec.primitive = random.chooseWeighted<gls::DrawTestSpec::Primitive>(
304*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(primitives), DE_ARRAY_END(primitives), primitiveWeights.weights);
305*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = random.chooseWeighted<int, const int *, const float *>(
306*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(primitiveCounts), DE_ARRAY_END(primitiveCounts), primitiveCountWeights);
307*35238bceSAndroid Build Coastguard Worker         spec.drawMethod = random.chooseWeighted<gls::DrawTestSpec::DrawMethod>(
308*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(drawMethods), DE_ARRAY_END(drawMethods), drawMethodWeights.weights);
309*35238bceSAndroid Build Coastguard Worker         spec.indexType = random.chooseWeighted<gls::DrawTestSpec::IndexType>(
310*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(indexTypes), DE_ARRAY_END(indexTypes), indexTypeWeights.weights);
311*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = random.chooseWeighted<int, const int *, const float *>(
312*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(indexOffsets), DE_ARRAY_END(indexOffsets), indexOffsetWeights);
313*35238bceSAndroid Build Coastguard Worker         spec.indexStorage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
314*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
315*35238bceSAndroid Build Coastguard Worker         spec.first         = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(firsts),
316*35238bceSAndroid Build Coastguard Worker                                                                             DE_ARRAY_END(firsts), firstWeights);
317*35238bceSAndroid Build Coastguard Worker         spec.indexMin      = 0;
318*35238bceSAndroid Build Coastguard Worker         spec.indexMax      = 0;
319*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 0;
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker         // check spec is legal
322*35238bceSAndroid Build Coastguard Worker         if (!spec.valid())
323*35238bceSAndroid Build Coastguard Worker             continue;
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker         for (int attrNdx = 0; attrNdx < attributeCount;)
326*35238bceSAndroid Build Coastguard Worker         {
327*35238bceSAndroid Build Coastguard Worker             bool valid;
328*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::AttributeSpec attribSpec;
329*35238bceSAndroid Build Coastguard Worker 
330*35238bceSAndroid Build Coastguard Worker             attribSpec.inputType = random.chooseWeighted<gls::DrawTestSpec::InputType>(
331*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(inputTypes), DE_ARRAY_END(inputTypes), inputTypeWeights.weights);
332*35238bceSAndroid Build Coastguard Worker             attribSpec.outputType = random.chooseWeighted<gls::DrawTestSpec::OutputType>(
333*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(outputTypes), DE_ARRAY_END(outputTypes), outputTypeWeights.weights);
334*35238bceSAndroid Build Coastguard Worker             attribSpec.storage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
335*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
336*35238bceSAndroid Build Coastguard Worker             attribSpec.usage = random.chooseWeighted<gls::DrawTestSpec::Usage>(
337*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(usages), DE_ARRAY_END(usages), usageWeights.weights);
338*35238bceSAndroid Build Coastguard Worker             attribSpec.componentCount = random.getInt(1, 4);
339*35238bceSAndroid Build Coastguard Worker             attribSpec.offset         = random.chooseWeighted<int, const int *, const float *>(
340*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(offsets), DE_ARRAY_END(offsets), offsetWeights);
341*35238bceSAndroid Build Coastguard Worker             attribSpec.stride = random.chooseWeighted<int, const int *, const float *>(
342*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(strides), DE_ARRAY_END(strides), strideWeights);
343*35238bceSAndroid Build Coastguard Worker             attribSpec.normalize           = random.getBool();
344*35238bceSAndroid Build Coastguard Worker             attribSpec.instanceDivisor     = 0;
345*35238bceSAndroid Build Coastguard Worker             attribSpec.useDefaultAttribute = random.getBool();
346*35238bceSAndroid Build Coastguard Worker 
347*35238bceSAndroid Build Coastguard Worker             // check spec is legal
348*35238bceSAndroid Build Coastguard Worker             valid = attribSpec.valid(spec.apiType);
349*35238bceSAndroid Build Coastguard Worker 
350*35238bceSAndroid Build Coastguard Worker             // we do not want interleaved elements. (Might result in some weird floating point values)
351*35238bceSAndroid Build Coastguard Worker             if (attribSpec.stride &&
352*35238bceSAndroid Build Coastguard Worker                 attribSpec.componentCount * gls::DrawTestSpec::inputTypeSize(attribSpec.inputType) > attribSpec.stride)
353*35238bceSAndroid Build Coastguard Worker                 valid = false;
354*35238bceSAndroid Build Coastguard Worker 
355*35238bceSAndroid Build Coastguard Worker             // try again if not valid
356*35238bceSAndroid Build Coastguard Worker             if (valid)
357*35238bceSAndroid Build Coastguard Worker             {
358*35238bceSAndroid Build Coastguard Worker                 spec.attribs.push_back(attribSpec);
359*35238bceSAndroid Build Coastguard Worker                 ++attrNdx;
360*35238bceSAndroid Build Coastguard Worker             }
361*35238bceSAndroid Build Coastguard Worker         }
362*35238bceSAndroid Build Coastguard Worker 
363*35238bceSAndroid Build Coastguard Worker         // Do not collapse all vertex positions to a single positions
364*35238bceSAndroid Build Coastguard Worker         if (spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
365*35238bceSAndroid Build Coastguard Worker             spec.attribs[0].instanceDivisor = 0;
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker         // Is render result meaningful?
368*35238bceSAndroid Build Coastguard Worker         {
369*35238bceSAndroid Build Coastguard Worker             // Only one vertex
370*35238bceSAndroid Build Coastguard Worker             if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
371*35238bceSAndroid Build Coastguard Worker                 spec.indexMin == spec.indexMax && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
372*35238bceSAndroid Build Coastguard Worker                 continue;
373*35238bceSAndroid Build Coastguard Worker             if (spec.attribs[0].useDefaultAttribute && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
374*35238bceSAndroid Build Coastguard Worker                 continue;
375*35238bceSAndroid Build Coastguard Worker 
376*35238bceSAndroid Build Coastguard Worker             // Triangle only on one axis
377*35238bceSAndroid Build Coastguard Worker             if (spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLES ||
378*35238bceSAndroid Build Coastguard Worker                 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN ||
379*35238bceSAndroid Build Coastguard Worker                 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP)
380*35238bceSAndroid Build Coastguard Worker             {
381*35238bceSAndroid Build Coastguard Worker                 if (spec.attribs[0].componentCount == 1)
382*35238bceSAndroid Build Coastguard Worker                     continue;
383*35238bceSAndroid Build Coastguard Worker                 if (spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_FLOAT ||
384*35238bceSAndroid Build Coastguard Worker                     spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_INT ||
385*35238bceSAndroid Build Coastguard Worker                     spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_UINT)
386*35238bceSAndroid Build Coastguard Worker                     continue;
387*35238bceSAndroid Build Coastguard Worker                 if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
388*35238bceSAndroid Build Coastguard Worker                     (spec.indexMax - spec.indexMin) < 2)
389*35238bceSAndroid Build Coastguard Worker                     continue;
390*35238bceSAndroid Build Coastguard Worker             }
391*35238bceSAndroid Build Coastguard Worker         }
392*35238bceSAndroid Build Coastguard Worker 
393*35238bceSAndroid Build Coastguard Worker         // Add case
394*35238bceSAndroid Build Coastguard Worker         {
395*35238bceSAndroid Build Coastguard Worker             uint32_t hash = spec.hash();
396*35238bceSAndroid Build Coastguard Worker             for (int attrNdx = 0; attrNdx < attributeCount; ++attrNdx)
397*35238bceSAndroid Build Coastguard Worker                 hash = (hash << 2) ^ (uint32_t)spec.attribs[attrNdx].hash();
398*35238bceSAndroid Build Coastguard Worker 
399*35238bceSAndroid Build Coastguard Worker             if (insertedHashes.find(hash) == insertedHashes.end() &&
400*35238bceSAndroid Build Coastguard Worker                 std::find(DE_ARRAY_BEGIN(disallowedCases), DE_ARRAY_END(disallowedCases), hash) ==
401*35238bceSAndroid Build Coastguard Worker                     DE_ARRAY_END(disallowedCases))
402*35238bceSAndroid Build Coastguard Worker             {
403*35238bceSAndroid Build Coastguard Worker                 // Only unaligned cases
404*35238bceSAndroid Build Coastguard Worker                 if (spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET ||
405*35238bceSAndroid Build Coastguard Worker                     spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE)
406*35238bceSAndroid Build Coastguard Worker                     this->addChild(new gls::DrawTest(m_testCtx, m_context.getRenderContext(), spec,
407*35238bceSAndroid Build Coastguard Worker                                                      de::toString(insertedCount).c_str(), spec.getDesc().c_str()));
408*35238bceSAndroid Build Coastguard Worker                 insertedHashes.insert(hash);
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker                 ++insertedCount;
411*35238bceSAndroid Build Coastguard Worker             }
412*35238bceSAndroid Build Coastguard Worker         }
413*35238bceSAndroid Build Coastguard Worker     }
414*35238bceSAndroid Build Coastguard Worker }
415*35238bceSAndroid Build Coastguard Worker 
416*35238bceSAndroid Build Coastguard Worker } // namespace
417*35238bceSAndroid Build Coastguard Worker 
DrawTests(Context & context)418*35238bceSAndroid Build Coastguard Worker DrawTests::DrawTests(Context &context) : TestCaseGroup(context, "draw", "Drawing tests")
419*35238bceSAndroid Build Coastguard Worker {
420*35238bceSAndroid Build Coastguard Worker }
421*35238bceSAndroid Build Coastguard Worker 
~DrawTests(void)422*35238bceSAndroid Build Coastguard Worker DrawTests::~DrawTests(void)
423*35238bceSAndroid Build Coastguard Worker {
424*35238bceSAndroid Build Coastguard Worker }
425*35238bceSAndroid Build Coastguard Worker 
init(void)426*35238bceSAndroid Build Coastguard Worker void DrawTests::init(void)
427*35238bceSAndroid Build Coastguard Worker {
428*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *const unalignedGroup =
429*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "unaligned_data", "Test with unaligned data");
430*35238bceSAndroid Build Coastguard Worker 
431*35238bceSAndroid Build Coastguard Worker     addChild(unalignedGroup);
432*35238bceSAndroid Build Coastguard Worker 
433*35238bceSAndroid Build Coastguard Worker     // .unaligned_data
434*35238bceSAndroid Build Coastguard Worker     {
435*35238bceSAndroid Build Coastguard Worker         const gls::DrawTestSpec::DrawMethod basicMethods[] = {
436*35238bceSAndroid Build Coastguard Worker             // gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS,
437*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS,
438*35238bceSAndroid Build Coastguard Worker         };
439*35238bceSAndroid Build Coastguard Worker 
440*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(basicMethods); ++ndx)
441*35238bceSAndroid Build Coastguard Worker         {
442*35238bceSAndroid Build Coastguard Worker             std::string name = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
443*35238bceSAndroid Build Coastguard Worker             std::string desc = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
444*35238bceSAndroid Build Coastguard Worker 
445*35238bceSAndroid Build Coastguard Worker             unalignedGroup->addChild(new MethodGroup(m_context, name.c_str(), desc.c_str(), basicMethods[ndx]));
446*35238bceSAndroid Build Coastguard Worker         }
447*35238bceSAndroid Build Coastguard Worker 
448*35238bceSAndroid Build Coastguard Worker         // Random
449*35238bceSAndroid Build Coastguard Worker 
450*35238bceSAndroid Build Coastguard Worker         unalignedGroup->addChild(new RandomGroup(m_context, "random", "random draw commands."));
451*35238bceSAndroid Build Coastguard Worker     }
452*35238bceSAndroid Build Coastguard Worker }
453*35238bceSAndroid Build Coastguard Worker 
454*35238bceSAndroid Build Coastguard Worker } // namespace Stress
455*35238bceSAndroid Build Coastguard Worker } // namespace gles2
456*35238bceSAndroid Build Coastguard Worker } // namespace deqp
457