xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fDrawTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.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 "es3fDrawTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsDrawTest.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "deSTLUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker 
34*35238bceSAndroid Build Coastguard Worker #include <set>
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker namespace deqp
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker namespace gles3
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker namespace Functional
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker namespace
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker enum TestIterationType
46*35238bceSAndroid Build Coastguard Worker {
47*35238bceSAndroid Build Coastguard Worker     TYPE_DRAW_COUNT,     // !< test with 1, 5, and 25 primitives
48*35238bceSAndroid Build Coastguard Worker     TYPE_INSTANCE_COUNT, // !< test with 1, 4, and 11 instances
49*35238bceSAndroid Build Coastguard Worker     TYPE_INDEX_RANGE,    // !< test with index range of [0, 23], [23, 40], and [5, 5]
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker     TYPE_LAST
52*35238bceSAndroid Build Coastguard Worker };
53*35238bceSAndroid Build Coastguard Worker 
addTestIterations(gls::DrawTest * test,const gls::DrawTestSpec & baseSpec,TestIterationType type)54*35238bceSAndroid Build Coastguard Worker static void addTestIterations(gls::DrawTest *test, const gls::DrawTestSpec &baseSpec, TestIterationType type)
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec(baseSpec);
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker     if (type == TYPE_DRAW_COUNT)
59*35238bceSAndroid Build Coastguard Worker     {
60*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 1;
61*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 1");
62*35238bceSAndroid Build Coastguard Worker 
63*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 5;
64*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 5");
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = 25;
67*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "draw count = 25");
68*35238bceSAndroid Build Coastguard Worker     }
69*35238bceSAndroid Build Coastguard Worker     else if (type == TYPE_INSTANCE_COUNT)
70*35238bceSAndroid Build Coastguard Worker     {
71*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 1;
72*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 1");
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 4;
75*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 4");
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 11;
78*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "instance count = 11");
79*35238bceSAndroid Build Coastguard Worker     }
80*35238bceSAndroid Build Coastguard Worker     else if (type == TYPE_INDEX_RANGE)
81*35238bceSAndroid Build Coastguard Worker     {
82*35238bceSAndroid Build Coastguard Worker         spec.indexMin = 0;
83*35238bceSAndroid Build Coastguard Worker         spec.indexMax = 23;
84*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "index range = [0, 23]");
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker         spec.indexMin = 23;
87*35238bceSAndroid Build Coastguard Worker         spec.indexMax = 40;
88*35238bceSAndroid Build Coastguard Worker         test->addIteration(spec, "index range = [23, 40]");
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker         // Only makes sense with points
91*35238bceSAndroid Build Coastguard Worker         if (spec.primitive == gls::DrawTestSpec::PRIMITIVE_POINTS)
92*35238bceSAndroid Build Coastguard Worker         {
93*35238bceSAndroid Build Coastguard Worker             spec.indexMin = 5;
94*35238bceSAndroid Build Coastguard Worker             spec.indexMax = 5;
95*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, "index range = [5, 5]");
96*35238bceSAndroid Build Coastguard Worker         }
97*35238bceSAndroid Build Coastguard Worker     }
98*35238bceSAndroid Build Coastguard Worker     else
99*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
100*35238bceSAndroid Build Coastguard Worker }
101*35238bceSAndroid Build Coastguard Worker 
genBasicSpec(gls::DrawTestSpec & spec,gls::DrawTestSpec::DrawMethod method)102*35238bceSAndroid Build Coastguard Worker static void genBasicSpec(gls::DrawTestSpec &spec, gls::DrawTestSpec::DrawMethod method)
103*35238bceSAndroid Build Coastguard Worker {
104*35238bceSAndroid Build Coastguard Worker     spec.apiType            = glu::ApiType::es(3, 0);
105*35238bceSAndroid Build Coastguard Worker     spec.primitive          = gls::DrawTestSpec::PRIMITIVE_TRIANGLES;
106*35238bceSAndroid Build Coastguard Worker     spec.primitiveCount     = 5;
107*35238bceSAndroid Build Coastguard Worker     spec.drawMethod         = method;
108*35238bceSAndroid Build Coastguard Worker     spec.indexType          = gls::DrawTestSpec::INDEXTYPE_LAST;
109*35238bceSAndroid Build Coastguard Worker     spec.indexPointerOffset = 0;
110*35238bceSAndroid Build Coastguard Worker     spec.indexStorage       = gls::DrawTestSpec::STORAGE_LAST;
111*35238bceSAndroid Build Coastguard Worker     spec.first              = 0;
112*35238bceSAndroid Build Coastguard Worker     spec.indexMin           = 0;
113*35238bceSAndroid Build Coastguard Worker     spec.indexMax           = 0;
114*35238bceSAndroid Build Coastguard Worker     spec.instanceCount      = 1;
115*35238bceSAndroid Build Coastguard Worker 
116*35238bceSAndroid Build Coastguard Worker     spec.attribs.resize(2);
117*35238bceSAndroid Build Coastguard Worker 
118*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
119*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
120*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
121*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
122*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].componentCount      = 4;
123*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].offset              = 0;
124*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].stride              = 0;
125*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].normalize           = false;
126*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].instanceDivisor     = 0;
127*35238bceSAndroid Build Coastguard Worker     spec.attribs[0].useDefaultAttribute = false;
128*35238bceSAndroid Build Coastguard Worker 
129*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
130*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
131*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
132*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
133*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].componentCount      = 2;
134*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].offset              = 0;
135*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].stride              = 0;
136*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].normalize           = false;
137*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].instanceDivisor     = 0;
138*35238bceSAndroid Build Coastguard Worker     spec.attribs[1].useDefaultAttribute = false;
139*35238bceSAndroid Build Coastguard Worker }
140*35238bceSAndroid Build Coastguard Worker 
141*35238bceSAndroid Build Coastguard Worker class AttributeGroup : public TestCaseGroup
142*35238bceSAndroid Build Coastguard Worker {
143*35238bceSAndroid Build Coastguard Worker public:
144*35238bceSAndroid Build Coastguard Worker     AttributeGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod,
145*35238bceSAndroid Build Coastguard Worker                    gls::DrawTestSpec::Primitive primitive, gls::DrawTestSpec::IndexType indexType,
146*35238bceSAndroid Build Coastguard Worker                    gls::DrawTestSpec::Storage indexStorage);
147*35238bceSAndroid Build Coastguard Worker     ~AttributeGroup(void);
148*35238bceSAndroid Build Coastguard Worker 
149*35238bceSAndroid Build Coastguard Worker     void init(void);
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker private:
152*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
153*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Primitive m_primitive;
154*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::IndexType m_indexType;
155*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::Storage m_indexStorage;
156*35238bceSAndroid Build Coastguard Worker };
157*35238bceSAndroid Build Coastguard Worker 
AttributeGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod,gls::DrawTestSpec::Primitive primitive,gls::DrawTestSpec::IndexType indexType,gls::DrawTestSpec::Storage indexStorage)158*35238bceSAndroid Build Coastguard Worker AttributeGroup::AttributeGroup(Context &context, const char *name, const char *descr,
159*35238bceSAndroid Build Coastguard Worker                                gls::DrawTestSpec::DrawMethod drawMethod, gls::DrawTestSpec::Primitive primitive,
160*35238bceSAndroid Build Coastguard Worker                                gls::DrawTestSpec::IndexType indexType, gls::DrawTestSpec::Storage indexStorage)
161*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
162*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
163*35238bceSAndroid Build Coastguard Worker     , m_primitive(primitive)
164*35238bceSAndroid Build Coastguard Worker     , m_indexType(indexType)
165*35238bceSAndroid Build Coastguard Worker     , m_indexStorage(indexStorage)
166*35238bceSAndroid Build Coastguard Worker {
167*35238bceSAndroid Build Coastguard Worker }
168*35238bceSAndroid Build Coastguard Worker 
~AttributeGroup(void)169*35238bceSAndroid Build Coastguard Worker AttributeGroup::~AttributeGroup(void)
170*35238bceSAndroid Build Coastguard Worker {
171*35238bceSAndroid Build Coastguard Worker }
172*35238bceSAndroid Build Coastguard Worker 
init(void)173*35238bceSAndroid Build Coastguard Worker void AttributeGroup::init(void)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker     // select test type
176*35238bceSAndroid Build Coastguard Worker     const bool instanced = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED) ||
177*35238bceSAndroid Build Coastguard Worker                            (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED);
178*35238bceSAndroid Build Coastguard Worker     const bool ranged = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED);
179*35238bceSAndroid Build Coastguard Worker     const TestIterationType testType =
180*35238bceSAndroid Build Coastguard Worker         (instanced) ? (TYPE_INSTANCE_COUNT) : ((ranged) ? (TYPE_INDEX_RANGE) : (TYPE_DRAW_COUNT));
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker     // Single attribute
183*35238bceSAndroid Build Coastguard Worker     {
184*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test =
185*35238bceSAndroid Build Coastguard Worker             new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "single_attribute", "Single attribute array.");
186*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
187*35238bceSAndroid Build Coastguard Worker 
188*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::ApiType::es(3, 0);
189*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
190*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
191*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
192*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
193*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
194*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
195*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
196*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
197*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
198*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
199*35238bceSAndroid Build Coastguard Worker 
200*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(1);
201*35238bceSAndroid Build Coastguard Worker 
202*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
203*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
204*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
205*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
206*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 2;
207*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
208*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
209*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
210*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
211*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
212*35238bceSAndroid Build Coastguard Worker 
213*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, testType);
214*35238bceSAndroid Build Coastguard Worker 
215*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
216*35238bceSAndroid Build Coastguard Worker     }
217*35238bceSAndroid Build Coastguard Worker 
218*35238bceSAndroid Build Coastguard Worker     // Multiple attribute
219*35238bceSAndroid Build Coastguard Worker     {
220*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "multiple_attributes",
221*35238bceSAndroid Build Coastguard Worker                                                 "Multiple attribute arrays.");
222*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
223*35238bceSAndroid Build Coastguard Worker 
224*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::ApiType::es(3, 0);
225*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
226*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
227*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
228*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
229*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
230*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
231*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
232*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
233*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
234*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(2);
237*35238bceSAndroid Build Coastguard Worker 
238*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
239*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
240*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
241*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
242*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 4;
243*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
244*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
245*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
246*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
247*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
248*35238bceSAndroid Build Coastguard Worker 
249*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
250*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
251*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
252*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
253*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].componentCount      = 2;
254*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].offset              = 0;
255*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].stride              = 0;
256*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].normalize           = false;
257*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].instanceDivisor     = 0;
258*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].useDefaultAttribute = false;
259*35238bceSAndroid Build Coastguard Worker 
260*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, testType);
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
263*35238bceSAndroid Build Coastguard Worker     }
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker     // Multiple attribute, second one divided
266*35238bceSAndroid Build Coastguard Worker     {
267*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "instanced_attributes",
268*35238bceSAndroid Build Coastguard Worker                                                 "Instanced attribute array.");
269*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
270*35238bceSAndroid Build Coastguard Worker 
271*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::ApiType::es(3, 0);
272*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
273*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
274*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
275*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
276*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
277*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
278*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
279*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
280*35238bceSAndroid Build Coastguard Worker         spec.indexMax           = 0;
281*35238bceSAndroid Build Coastguard Worker         spec.instanceCount      = 1;
282*35238bceSAndroid Build Coastguard Worker 
283*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(3);
284*35238bceSAndroid Build Coastguard Worker 
285*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
286*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
287*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
288*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
289*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 4;
290*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
291*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
292*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
293*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
294*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
295*35238bceSAndroid Build Coastguard Worker 
296*35238bceSAndroid Build Coastguard Worker         // Add another position component so the instances wont be drawn on each other
297*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].inputType                   = gls::DrawTestSpec::INPUTTYPE_FLOAT;
298*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].outputType                  = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
299*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].storage                     = gls::DrawTestSpec::STORAGE_BUFFER;
300*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].usage                       = gls::DrawTestSpec::USAGE_STATIC_DRAW;
301*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].componentCount              = 2;
302*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].offset                      = 0;
303*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].stride                      = 0;
304*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].normalize                   = false;
305*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].instanceDivisor             = 1;
306*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].useDefaultAttribute         = false;
307*35238bceSAndroid Build Coastguard Worker         spec.attribs[1].additionalPositionAttribute = true;
308*35238bceSAndroid Build Coastguard Worker 
309*35238bceSAndroid Build Coastguard Worker         // Instanced color
310*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
311*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
312*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
313*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
314*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].componentCount      = 3;
315*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].offset              = 0;
316*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].stride              = 0;
317*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].normalize           = false;
318*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].instanceDivisor     = 1;
319*35238bceSAndroid Build Coastguard Worker         spec.attribs[2].useDefaultAttribute = false;
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, testType);
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
324*35238bceSAndroid Build Coastguard Worker     }
325*35238bceSAndroid Build Coastguard Worker 
326*35238bceSAndroid Build Coastguard Worker     // Multiple attribute, second one default
327*35238bceSAndroid Build Coastguard Worker     {
328*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), "default_attribute",
329*35238bceSAndroid Build Coastguard Worker                                                 "Attribute specified with glVertexAttrib*.");
330*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
331*35238bceSAndroid Build Coastguard Worker 
332*35238bceSAndroid Build Coastguard Worker         spec.apiType            = glu::ApiType::es(3, 0);
333*35238bceSAndroid Build Coastguard Worker         spec.primitive          = m_primitive;
334*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount     = 5;
335*35238bceSAndroid Build Coastguard Worker         spec.drawMethod         = m_method;
336*35238bceSAndroid Build Coastguard Worker         spec.indexType          = m_indexType;
337*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = 0;
338*35238bceSAndroid Build Coastguard Worker         spec.indexStorage       = m_indexStorage;
339*35238bceSAndroid Build Coastguard Worker         spec.first              = 0;
340*35238bceSAndroid Build Coastguard Worker         spec.indexMin           = 0;
341*35238bceSAndroid Build Coastguard Worker         spec.indexMax =
342*35238bceSAndroid Build Coastguard Worker             20; // \note addTestIterations is not called for the spec, so we must ensure [indexMin, indexMax] is a good range
343*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = 1;
344*35238bceSAndroid Build Coastguard Worker 
345*35238bceSAndroid Build Coastguard Worker         spec.attribs.resize(2);
346*35238bceSAndroid Build Coastguard Worker 
347*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].inputType           = gls::DrawTestSpec::INPUTTYPE_FLOAT;
348*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].outputType          = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
349*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
350*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
351*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].componentCount      = 2;
352*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].offset              = 0;
353*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].stride              = 0;
354*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].normalize           = false;
355*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].instanceDivisor     = 0;
356*35238bceSAndroid Build Coastguard Worker         spec.attribs[0].useDefaultAttribute = false;
357*35238bceSAndroid Build Coastguard Worker 
358*35238bceSAndroid Build Coastguard Worker         struct IOPair
359*35238bceSAndroid Build Coastguard Worker         {
360*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::InputType input;
361*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::OutputType output;
362*35238bceSAndroid Build Coastguard Worker             int componentCount;
363*35238bceSAndroid Build Coastguard Worker         } iopairs[] = {
364*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC2, 4},
365*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC4, 2},
366*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_INT, gls::DrawTestSpec::OUTPUTTYPE_IVEC3, 4},
367*35238bceSAndroid Build Coastguard Worker             {gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT, gls::DrawTestSpec::OUTPUTTYPE_UVEC2, 4},
368*35238bceSAndroid Build Coastguard Worker         };
369*35238bceSAndroid Build Coastguard Worker 
370*35238bceSAndroid Build Coastguard Worker         for (int ioNdx = 0; ioNdx < DE_LENGTH_OF_ARRAY(iopairs); ++ioNdx)
371*35238bceSAndroid Build Coastguard Worker         {
372*35238bceSAndroid Build Coastguard Worker             const std::string desc = gls::DrawTestSpec::inputTypeToString(iopairs[ioNdx].input) +
373*35238bceSAndroid Build Coastguard Worker                                      de::toString(iopairs[ioNdx].componentCount) + " to " +
374*35238bceSAndroid Build Coastguard Worker                                      gls::DrawTestSpec::outputTypeToString(iopairs[ioNdx].output);
375*35238bceSAndroid Build Coastguard Worker 
376*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].inputType           = iopairs[ioNdx].input;
377*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].outputType          = iopairs[ioNdx].output;
378*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].storage             = gls::DrawTestSpec::STORAGE_BUFFER;
379*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].usage               = gls::DrawTestSpec::USAGE_STATIC_DRAW;
380*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].componentCount      = iopairs[ioNdx].componentCount;
381*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].offset              = 0;
382*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].stride              = 0;
383*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].normalize           = false;
384*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].instanceDivisor     = 0;
385*35238bceSAndroid Build Coastguard Worker             spec.attribs[1].useDefaultAttribute = true;
386*35238bceSAndroid Build Coastguard Worker 
387*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, desc.c_str());
388*35238bceSAndroid Build Coastguard Worker         }
389*35238bceSAndroid Build Coastguard Worker 
390*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
391*35238bceSAndroid Build Coastguard Worker     }
392*35238bceSAndroid Build Coastguard Worker }
393*35238bceSAndroid Build Coastguard Worker 
394*35238bceSAndroid Build Coastguard Worker class IndexGroup : public TestCaseGroup
395*35238bceSAndroid Build Coastguard Worker {
396*35238bceSAndroid Build Coastguard Worker public:
397*35238bceSAndroid Build Coastguard Worker     IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
398*35238bceSAndroid Build Coastguard Worker     ~IndexGroup(void);
399*35238bceSAndroid Build Coastguard Worker 
400*35238bceSAndroid Build Coastguard Worker     void init(void);
401*35238bceSAndroid Build Coastguard Worker 
402*35238bceSAndroid Build Coastguard Worker private:
403*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
404*35238bceSAndroid Build Coastguard Worker };
405*35238bceSAndroid Build Coastguard Worker 
IndexGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)406*35238bceSAndroid Build Coastguard Worker IndexGroup::IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod)
407*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
408*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
409*35238bceSAndroid Build Coastguard Worker {
410*35238bceSAndroid Build Coastguard Worker }
411*35238bceSAndroid Build Coastguard Worker 
~IndexGroup(void)412*35238bceSAndroid Build Coastguard Worker IndexGroup::~IndexGroup(void)
413*35238bceSAndroid Build Coastguard Worker {
414*35238bceSAndroid Build Coastguard Worker }
415*35238bceSAndroid Build Coastguard Worker 
init(void)416*35238bceSAndroid Build Coastguard Worker void IndexGroup::init(void)
417*35238bceSAndroid Build Coastguard Worker {
418*35238bceSAndroid Build Coastguard Worker     struct IndexTest
419*35238bceSAndroid Build Coastguard Worker     {
420*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::Storage storage;
421*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::IndexType type;
422*35238bceSAndroid Build Coastguard Worker         bool aligned;
423*35238bceSAndroid Build Coastguard Worker         int offsets[3];
424*35238bceSAndroid Build Coastguard Worker     };
425*35238bceSAndroid Build Coastguard Worker 
426*35238bceSAndroid Build Coastguard Worker     const IndexTest tests[] = {
427*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_USER, gls::DrawTestSpec::INDEXTYPE_BYTE, true, {0, 1, -1}},
428*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_USER, gls::DrawTestSpec::INDEXTYPE_SHORT, true, {0, 2, -1}},
429*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_USER, gls::DrawTestSpec::INDEXTYPE_INT, true, {0, 4, -1}},
430*35238bceSAndroid Build Coastguard Worker 
431*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_USER, gls::DrawTestSpec::INDEXTYPE_SHORT, false, {1, 3, -1}},
432*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_USER, gls::DrawTestSpec::INDEXTYPE_INT, false, {2, 3, -1}},
433*35238bceSAndroid Build Coastguard Worker 
434*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_BYTE, true, {0, 1, -1}},
435*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_SHORT, true, {0, 2, -1}},
436*35238bceSAndroid Build Coastguard Worker         {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_INT, true, {0, 4, -1}},
437*35238bceSAndroid Build Coastguard Worker     };
438*35238bceSAndroid Build Coastguard Worker 
439*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec;
440*35238bceSAndroid Build Coastguard Worker 
441*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *userPtrGroup = new tcu::TestCaseGroup(m_testCtx, "user_ptr", "user pointer");
442*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *unalignedUserPtrGroup =
443*35238bceSAndroid Build Coastguard Worker         new tcu::TestCaseGroup(m_testCtx, "unaligned_user_ptr", "unaligned user pointer");
444*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *bufferGroup = new tcu::TestCaseGroup(m_testCtx, "buffer", "buffer");
445*35238bceSAndroid Build Coastguard Worker 
446*35238bceSAndroid Build Coastguard Worker     genBasicSpec(spec, m_method);
447*35238bceSAndroid Build Coastguard Worker 
448*35238bceSAndroid Build Coastguard Worker     this->addChild(userPtrGroup);
449*35238bceSAndroid Build Coastguard Worker     this->addChild(unalignedUserPtrGroup);
450*35238bceSAndroid Build Coastguard Worker     this->addChild(bufferGroup);
451*35238bceSAndroid Build Coastguard Worker 
452*35238bceSAndroid Build Coastguard Worker     for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
453*35238bceSAndroid Build Coastguard Worker     {
454*35238bceSAndroid Build Coastguard Worker         const IndexTest &indexTest = tests[testNdx];
455*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *group  = (indexTest.storage == gls::DrawTestSpec::STORAGE_USER) ?
456*35238bceSAndroid Build Coastguard Worker                                          ((indexTest.aligned) ? (userPtrGroup) : (unalignedUserPtrGroup)) :
457*35238bceSAndroid Build Coastguard Worker                                          ((indexTest.aligned) ? (bufferGroup) : (DE_NULL));
458*35238bceSAndroid Build Coastguard Worker 
459*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("index_") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
460*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type) + " in " +
461*35238bceSAndroid Build Coastguard Worker                                  gls::DrawTestSpec::storageToString(indexTest.storage);
462*35238bceSAndroid Build Coastguard Worker         de::MovePtr<gls::DrawTest> test(
463*35238bceSAndroid Build Coastguard Worker             new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()));
464*35238bceSAndroid Build Coastguard Worker 
465*35238bceSAndroid Build Coastguard Worker         spec.indexType    = indexTest.type;
466*35238bceSAndroid Build Coastguard Worker         spec.indexStorage = indexTest.storage;
467*35238bceSAndroid Build Coastguard Worker 
468*35238bceSAndroid Build Coastguard Worker         for (int iterationNdx = 0;
469*35238bceSAndroid Build Coastguard Worker              iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.offsets) && indexTest.offsets[iterationNdx] != -1;
470*35238bceSAndroid Build Coastguard Worker              ++iterationNdx)
471*35238bceSAndroid Build Coastguard Worker         {
472*35238bceSAndroid Build Coastguard Worker             const std::string iterationDesc = std::string("offset ") + de::toString(indexTest.offsets[iterationNdx]);
473*35238bceSAndroid Build Coastguard Worker             spec.indexPointerOffset         = indexTest.offsets[iterationNdx];
474*35238bceSAndroid Build Coastguard Worker             test->addIteration(spec, iterationDesc.c_str());
475*35238bceSAndroid Build Coastguard Worker         }
476*35238bceSAndroid Build Coastguard Worker 
477*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET);
478*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE);
479*35238bceSAndroid Build Coastguard Worker         group->addChild(test.release());
480*35238bceSAndroid Build Coastguard Worker     }
481*35238bceSAndroid Build Coastguard Worker }
482*35238bceSAndroid Build Coastguard Worker 
483*35238bceSAndroid Build Coastguard Worker class FirstGroup : public TestCaseGroup
484*35238bceSAndroid Build Coastguard Worker {
485*35238bceSAndroid Build Coastguard Worker public:
486*35238bceSAndroid Build Coastguard Worker     FirstGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
487*35238bceSAndroid Build Coastguard Worker     ~FirstGroup(void);
488*35238bceSAndroid Build Coastguard Worker 
489*35238bceSAndroid Build Coastguard Worker     void init(void);
490*35238bceSAndroid Build Coastguard Worker 
491*35238bceSAndroid Build Coastguard Worker private:
492*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
493*35238bceSAndroid Build Coastguard Worker };
494*35238bceSAndroid Build Coastguard Worker 
FirstGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)495*35238bceSAndroid Build Coastguard Worker FirstGroup::FirstGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod)
496*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
497*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
498*35238bceSAndroid Build Coastguard Worker {
499*35238bceSAndroid Build Coastguard Worker }
500*35238bceSAndroid Build Coastguard Worker 
~FirstGroup(void)501*35238bceSAndroid Build Coastguard Worker FirstGroup::~FirstGroup(void)
502*35238bceSAndroid Build Coastguard Worker {
503*35238bceSAndroid Build Coastguard Worker }
504*35238bceSAndroid Build Coastguard Worker 
init(void)505*35238bceSAndroid Build Coastguard Worker void FirstGroup::init(void)
506*35238bceSAndroid Build Coastguard Worker {
507*35238bceSAndroid Build Coastguard Worker     const int firsts[] = {1, 3, 17};
508*35238bceSAndroid Build Coastguard Worker 
509*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec spec;
510*35238bceSAndroid Build Coastguard Worker     genBasicSpec(spec, m_method);
511*35238bceSAndroid Build Coastguard Worker 
512*35238bceSAndroid Build Coastguard Worker     for (int firstNdx = 0; firstNdx < DE_LENGTH_OF_ARRAY(firsts); ++firstNdx)
513*35238bceSAndroid Build Coastguard Worker     {
514*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("first_") + de::toString(firsts[firstNdx]);
515*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("first ") + de::toString(firsts[firstNdx]);
516*35238bceSAndroid Build Coastguard Worker         gls::DrawTest *test    = new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str());
517*35238bceSAndroid Build Coastguard Worker 
518*35238bceSAndroid Build Coastguard Worker         spec.first = firsts[firstNdx];
519*35238bceSAndroid Build Coastguard Worker 
520*35238bceSAndroid Build Coastguard Worker         addTestIterations(test, spec, TYPE_DRAW_COUNT);
521*35238bceSAndroid Build Coastguard Worker 
522*35238bceSAndroid Build Coastguard Worker         this->addChild(test);
523*35238bceSAndroid Build Coastguard Worker     }
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker 
526*35238bceSAndroid Build Coastguard Worker class MethodGroup : public TestCaseGroup
527*35238bceSAndroid Build Coastguard Worker {
528*35238bceSAndroid Build Coastguard Worker public:
529*35238bceSAndroid Build Coastguard Worker     MethodGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
530*35238bceSAndroid Build Coastguard Worker     ~MethodGroup(void);
531*35238bceSAndroid Build Coastguard Worker 
532*35238bceSAndroid Build Coastguard Worker     void init(void);
533*35238bceSAndroid Build Coastguard Worker 
534*35238bceSAndroid Build Coastguard Worker private:
535*35238bceSAndroid Build Coastguard Worker     gls::DrawTestSpec::DrawMethod m_method;
536*35238bceSAndroid Build Coastguard Worker };
537*35238bceSAndroid Build Coastguard Worker 
MethodGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)538*35238bceSAndroid Build Coastguard Worker MethodGroup::MethodGroup(Context &context, const char *name, const char *descr,
539*35238bceSAndroid Build Coastguard Worker                          gls::DrawTestSpec::DrawMethod drawMethod)
540*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
541*35238bceSAndroid Build Coastguard Worker     , m_method(drawMethod)
542*35238bceSAndroid Build Coastguard Worker {
543*35238bceSAndroid Build Coastguard Worker }
544*35238bceSAndroid Build Coastguard Worker 
~MethodGroup(void)545*35238bceSAndroid Build Coastguard Worker MethodGroup::~MethodGroup(void)
546*35238bceSAndroid Build Coastguard Worker {
547*35238bceSAndroid Build Coastguard Worker }
548*35238bceSAndroid Build Coastguard Worker 
init(void)549*35238bceSAndroid Build Coastguard Worker void MethodGroup::init(void)
550*35238bceSAndroid Build Coastguard Worker {
551*35238bceSAndroid Build Coastguard Worker     const bool indexed = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS) ||
552*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED) ||
553*35238bceSAndroid Build Coastguard Worker                          (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED);
554*35238bceSAndroid Build Coastguard Worker     const bool hasFirst = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS) ||
555*35238bceSAndroid Build Coastguard Worker                           (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED);
556*35238bceSAndroid Build Coastguard Worker 
557*35238bceSAndroid Build Coastguard Worker     const gls::DrawTestSpec::Primitive primitive[] = {
558*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_POINTS,       gls::DrawTestSpec::PRIMITIVE_TRIANGLES,
559*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP,
560*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINES,        gls::DrawTestSpec::PRIMITIVE_LINE_STRIP,
561*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINE_LOOP};
562*35238bceSAndroid Build Coastguard Worker 
563*35238bceSAndroid Build Coastguard Worker     if (hasFirst)
564*35238bceSAndroid Build Coastguard Worker     {
565*35238bceSAndroid Build Coastguard Worker         // First-tests
566*35238bceSAndroid Build Coastguard Worker         this->addChild(new FirstGroup(m_context, "first", "First tests", m_method));
567*35238bceSAndroid Build Coastguard Worker     }
568*35238bceSAndroid Build Coastguard Worker 
569*35238bceSAndroid Build Coastguard Worker     if (indexed)
570*35238bceSAndroid Build Coastguard Worker     {
571*35238bceSAndroid Build Coastguard Worker         // Index-tests
572*35238bceSAndroid Build Coastguard Worker         if (m_method != gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED)
573*35238bceSAndroid Build Coastguard Worker             this->addChild(new IndexGroup(m_context, "indices", "Index tests", m_method));
574*35238bceSAndroid Build Coastguard Worker     }
575*35238bceSAndroid Build Coastguard Worker 
576*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(primitive); ++ndx)
577*35238bceSAndroid Build Coastguard Worker     {
578*35238bceSAndroid Build Coastguard Worker         const std::string name = gls::DrawTestSpec::primitiveToString(primitive[ndx]);
579*35238bceSAndroid Build Coastguard Worker         const std::string desc = gls::DrawTestSpec::primitiveToString(primitive[ndx]);
580*35238bceSAndroid Build Coastguard Worker 
581*35238bceSAndroid Build Coastguard Worker         this->addChild(new AttributeGroup(m_context, name.c_str(), desc.c_str(), m_method, primitive[ndx],
582*35238bceSAndroid Build Coastguard Worker                                           gls::DrawTestSpec::INDEXTYPE_SHORT, gls::DrawTestSpec::STORAGE_BUFFER));
583*35238bceSAndroid Build Coastguard Worker     }
584*35238bceSAndroid Build Coastguard Worker }
585*35238bceSAndroid Build Coastguard Worker 
586*35238bceSAndroid Build Coastguard Worker class GridProgram : public sglr::ShaderProgram
587*35238bceSAndroid Build Coastguard Worker {
588*35238bceSAndroid Build Coastguard Worker public:
589*35238bceSAndroid Build Coastguard Worker     GridProgram(void);
590*35238bceSAndroid Build Coastguard Worker 
591*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
592*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
593*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const;
594*35238bceSAndroid Build Coastguard Worker };
595*35238bceSAndroid Build Coastguard Worker 
GridProgram(void)596*35238bceSAndroid Build Coastguard Worker GridProgram::GridProgram(void)
597*35238bceSAndroid Build Coastguard Worker     : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
598*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
599*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_offset", rr::GENERICVECTYPE_FLOAT)
600*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
601*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
602*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
603*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::VertexSource("#version 300 es\n"
604*35238bceSAndroid Build Coastguard Worker                                                       "in highp vec4 a_position;\n"
605*35238bceSAndroid Build Coastguard Worker                                                       "in highp vec4 a_offset;\n"
606*35238bceSAndroid Build Coastguard Worker                                                       "in highp vec4 a_color;\n"
607*35238bceSAndroid Build Coastguard Worker                                                       "out mediump vec4 v_color;\n"
608*35238bceSAndroid Build Coastguard Worker                                                       "void main(void)\n"
609*35238bceSAndroid Build Coastguard Worker                                                       "{\n"
610*35238bceSAndroid Build Coastguard Worker                                                       "    gl_Position = a_position + a_offset;\n"
611*35238bceSAndroid Build Coastguard Worker                                                       "    v_color = a_color;\n"
612*35238bceSAndroid Build Coastguard Worker                                                       "}\n")
613*35238bceSAndroid Build Coastguard Worker                           << sglr::pdec::FragmentSource("#version 300 es\n"
614*35238bceSAndroid Build Coastguard Worker                                                         "layout(location = 0) out mediump vec4 dEQP_FragColor;\n"
615*35238bceSAndroid Build Coastguard Worker                                                         "in mediump vec4 v_color;\n"
616*35238bceSAndroid Build Coastguard Worker                                                         "void main(void)\n"
617*35238bceSAndroid Build Coastguard Worker                                                         "{\n"
618*35238bceSAndroid Build Coastguard Worker                                                         "    dEQP_FragColor = v_color;\n"
619*35238bceSAndroid Build Coastguard Worker                                                         "}\n"))
620*35238bceSAndroid Build Coastguard Worker {
621*35238bceSAndroid Build Coastguard Worker }
622*35238bceSAndroid Build Coastguard Worker 
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const623*35238bceSAndroid Build Coastguard Worker void GridProgram::shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets,
624*35238bceSAndroid Build Coastguard Worker                                 const int numPackets) const
625*35238bceSAndroid Build Coastguard Worker {
626*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < numPackets; ++ndx)
627*35238bceSAndroid Build Coastguard Worker     {
628*35238bceSAndroid Build Coastguard Worker         packets[ndx]->position =
629*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx) +
630*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
631*35238bceSAndroid Build Coastguard Worker         packets[ndx]->outputs[0] =
632*35238bceSAndroid Build Coastguard Worker             rr::readVertexAttribFloat(inputs[2], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
633*35238bceSAndroid Build Coastguard Worker     }
634*35238bceSAndroid Build Coastguard Worker }
635*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const636*35238bceSAndroid Build Coastguard Worker void GridProgram::shadeFragments(rr::FragmentPacket *packets, const int numPackets,
637*35238bceSAndroid Build Coastguard Worker                                  const rr::FragmentShadingContext &context) const
638*35238bceSAndroid Build Coastguard Worker {
639*35238bceSAndroid Build Coastguard Worker     for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
640*35238bceSAndroid Build Coastguard Worker         for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
641*35238bceSAndroid Build Coastguard Worker             rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
642*35238bceSAndroid Build Coastguard Worker                                     rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx));
643*35238bceSAndroid Build Coastguard Worker }
644*35238bceSAndroid Build Coastguard Worker 
645*35238bceSAndroid Build Coastguard Worker class InstancedGridRenderTest : public TestCase
646*35238bceSAndroid Build Coastguard Worker {
647*35238bceSAndroid Build Coastguard Worker public:
648*35238bceSAndroid Build Coastguard Worker     InstancedGridRenderTest(Context &context, const char *name, const char *desc, int gridSide, bool useIndices);
649*35238bceSAndroid Build Coastguard Worker     ~InstancedGridRenderTest(void);
650*35238bceSAndroid Build Coastguard Worker 
651*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
652*35238bceSAndroid Build Coastguard Worker 
653*35238bceSAndroid Build Coastguard Worker private:
654*35238bceSAndroid Build Coastguard Worker     void renderTo(sglr::Context &ctx, sglr::ShaderProgram &program, tcu::Surface &dst);
655*35238bceSAndroid Build Coastguard Worker     bool verifyImage(const tcu::Surface &image);
656*35238bceSAndroid Build Coastguard Worker 
657*35238bceSAndroid Build Coastguard Worker     const int m_gridSide;
658*35238bceSAndroid Build Coastguard Worker     const bool m_useIndices;
659*35238bceSAndroid Build Coastguard Worker };
660*35238bceSAndroid Build Coastguard Worker 
InstancedGridRenderTest(Context & context,const char * name,const char * desc,int gridSide,bool useIndices)661*35238bceSAndroid Build Coastguard Worker InstancedGridRenderTest::InstancedGridRenderTest(Context &context, const char *name, const char *desc, int gridSide,
662*35238bceSAndroid Build Coastguard Worker                                                  bool useIndices)
663*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, desc)
664*35238bceSAndroid Build Coastguard Worker     , m_gridSide(gridSide)
665*35238bceSAndroid Build Coastguard Worker     , m_useIndices(useIndices)
666*35238bceSAndroid Build Coastguard Worker {
667*35238bceSAndroid Build Coastguard Worker }
668*35238bceSAndroid Build Coastguard Worker 
~InstancedGridRenderTest(void)669*35238bceSAndroid Build Coastguard Worker InstancedGridRenderTest::~InstancedGridRenderTest(void)
670*35238bceSAndroid Build Coastguard Worker {
671*35238bceSAndroid Build Coastguard Worker }
672*35238bceSAndroid Build Coastguard Worker 
iterate(void)673*35238bceSAndroid Build Coastguard Worker InstancedGridRenderTest::IterateResult InstancedGridRenderTest::iterate(void)
674*35238bceSAndroid Build Coastguard Worker {
675*35238bceSAndroid Build Coastguard Worker     const int renderTargetWidth  = de::min(1024, m_context.getRenderTarget().getWidth());
676*35238bceSAndroid Build Coastguard Worker     const int renderTargetHeight = de::min(1024, m_context.getRenderTarget().getHeight());
677*35238bceSAndroid Build Coastguard Worker 
678*35238bceSAndroid Build Coastguard Worker     sglr::GLContext ctx(m_context.getRenderContext(), m_testCtx.getLog(),
679*35238bceSAndroid Build Coastguard Worker                         sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS,
680*35238bceSAndroid Build Coastguard Worker                         tcu::IVec4(0, 0, renderTargetWidth, renderTargetHeight));
681*35238bceSAndroid Build Coastguard Worker     tcu::Surface surface(renderTargetWidth, renderTargetHeight);
682*35238bceSAndroid Build Coastguard Worker     GridProgram program;
683*35238bceSAndroid Build Coastguard Worker 
684*35238bceSAndroid Build Coastguard Worker     // render
685*35238bceSAndroid Build Coastguard Worker 
686*35238bceSAndroid Build Coastguard Worker     renderTo(ctx, program, surface);
687*35238bceSAndroid Build Coastguard Worker 
688*35238bceSAndroid Build Coastguard Worker     // verify image
689*35238bceSAndroid Build Coastguard Worker 
690*35238bceSAndroid Build Coastguard Worker     if (verifyImage(surface))
691*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
692*35238bceSAndroid Build Coastguard Worker     else
693*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Incorrect rendering result");
694*35238bceSAndroid Build Coastguard Worker     return STOP;
695*35238bceSAndroid Build Coastguard Worker }
696*35238bceSAndroid Build Coastguard Worker 
renderTo(sglr::Context & ctx,sglr::ShaderProgram & program,tcu::Surface & dst)697*35238bceSAndroid Build Coastguard Worker void InstancedGridRenderTest::renderTo(sglr::Context &ctx, sglr::ShaderProgram &program, tcu::Surface &dst)
698*35238bceSAndroid Build Coastguard Worker {
699*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 green(0, 1, 0, 1);
700*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 yellow(1, 1, 0, 1);
701*35238bceSAndroid Build Coastguard Worker 
702*35238bceSAndroid Build Coastguard Worker     uint32_t positionBuf   = 0;
703*35238bceSAndroid Build Coastguard Worker     uint32_t offsetBuf     = 0;
704*35238bceSAndroid Build Coastguard Worker     uint32_t colorBuf      = 0;
705*35238bceSAndroid Build Coastguard Worker     uint32_t indexBuf      = 0;
706*35238bceSAndroid Build Coastguard Worker     uint32_t programID     = ctx.createProgram(&program);
707*35238bceSAndroid Build Coastguard Worker     int32_t posLocation    = ctx.getAttribLocation(programID, "a_position");
708*35238bceSAndroid Build Coastguard Worker     int32_t offsetLocation = ctx.getAttribLocation(programID, "a_offset");
709*35238bceSAndroid Build Coastguard Worker     int32_t colorLocation  = ctx.getAttribLocation(programID, "a_color");
710*35238bceSAndroid Build Coastguard Worker 
711*35238bceSAndroid Build Coastguard Worker     float cellW                       = 2.0f / (float)m_gridSide;
712*35238bceSAndroid Build Coastguard Worker     float cellH                       = 2.0f / (float)m_gridSide;
713*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 vertexPositions[] = {
714*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0, 0, 0, 1),     tcu::Vec4(cellW, 0, 0, 1), tcu::Vec4(0, cellH, 0, 1),
715*35238bceSAndroid Build Coastguard Worker 
716*35238bceSAndroid Build Coastguard Worker         tcu::Vec4(0, cellH, 0, 1), tcu::Vec4(cellW, 0, 0, 1), tcu::Vec4(cellW, cellH, 0, 1),
717*35238bceSAndroid Build Coastguard Worker     };
718*35238bceSAndroid Build Coastguard Worker 
719*35238bceSAndroid Build Coastguard Worker     const uint16_t indices[] = {0, 4, 3, 2, 1, 5};
720*35238bceSAndroid Build Coastguard Worker 
721*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> offsets;
722*35238bceSAndroid Build Coastguard Worker     for (int x = 0; x < m_gridSide; ++x)
723*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < m_gridSide; ++y)
724*35238bceSAndroid Build Coastguard Worker             offsets.push_back(tcu::Vec4((float)x * cellW - 1.0f, (float)y * cellW - 1.0f, 0, 0));
725*35238bceSAndroid Build Coastguard Worker 
726*35238bceSAndroid Build Coastguard Worker     std::vector<tcu::Vec4> colors;
727*35238bceSAndroid Build Coastguard Worker     for (int x = 0; x < m_gridSide; ++x)
728*35238bceSAndroid Build Coastguard Worker         for (int y = 0; y < m_gridSide; ++y)
729*35238bceSAndroid Build Coastguard Worker             colors.push_back(((x + y) % 2 == 0) ? (green) : (yellow));
730*35238bceSAndroid Build Coastguard Worker 
731*35238bceSAndroid Build Coastguard Worker     ctx.genBuffers(1, &positionBuf);
732*35238bceSAndroid Build Coastguard Worker     ctx.bindBuffer(GL_ARRAY_BUFFER, positionBuf);
733*35238bceSAndroid Build Coastguard Worker     ctx.bufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
734*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
735*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribDivisor(posLocation, 0);
736*35238bceSAndroid Build Coastguard Worker     ctx.enableVertexAttribArray(posLocation);
737*35238bceSAndroid Build Coastguard Worker 
738*35238bceSAndroid Build Coastguard Worker     ctx.genBuffers(1, &offsetBuf);
739*35238bceSAndroid Build Coastguard Worker     ctx.bindBuffer(GL_ARRAY_BUFFER, offsetBuf);
740*35238bceSAndroid Build Coastguard Worker     ctx.bufferData(GL_ARRAY_BUFFER, offsets.size() * sizeof(tcu::Vec4), &offsets[0], GL_STATIC_DRAW);
741*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribPointer(offsetLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
742*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribDivisor(offsetLocation, 1);
743*35238bceSAndroid Build Coastguard Worker     ctx.enableVertexAttribArray(offsetLocation);
744*35238bceSAndroid Build Coastguard Worker 
745*35238bceSAndroid Build Coastguard Worker     ctx.genBuffers(1, &colorBuf);
746*35238bceSAndroid Build Coastguard Worker     ctx.bindBuffer(GL_ARRAY_BUFFER, colorBuf);
747*35238bceSAndroid Build Coastguard Worker     ctx.bufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(tcu::Vec4), &colors[0], GL_STATIC_DRAW);
748*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
749*35238bceSAndroid Build Coastguard Worker     ctx.vertexAttribDivisor(colorLocation, 1);
750*35238bceSAndroid Build Coastguard Worker     ctx.enableVertexAttribArray(colorLocation);
751*35238bceSAndroid Build Coastguard Worker 
752*35238bceSAndroid Build Coastguard Worker     if (m_useIndices)
753*35238bceSAndroid Build Coastguard Worker     {
754*35238bceSAndroid Build Coastguard Worker         ctx.genBuffers(1, &indexBuf);
755*35238bceSAndroid Build Coastguard Worker         ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf);
756*35238bceSAndroid Build Coastguard Worker         ctx.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
757*35238bceSAndroid Build Coastguard Worker     }
758*35238bceSAndroid Build Coastguard Worker 
759*35238bceSAndroid Build Coastguard Worker     ctx.clearColor(0, 0, 0, 1);
760*35238bceSAndroid Build Coastguard Worker     ctx.clear(GL_COLOR_BUFFER_BIT);
761*35238bceSAndroid Build Coastguard Worker 
762*35238bceSAndroid Build Coastguard Worker     ctx.viewport(0, 0, dst.getWidth(), dst.getHeight());
763*35238bceSAndroid Build Coastguard Worker 
764*35238bceSAndroid Build Coastguard Worker     ctx.useProgram(programID);
765*35238bceSAndroid Build Coastguard Worker     if (m_useIndices)
766*35238bceSAndroid Build Coastguard Worker         ctx.drawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL, m_gridSide * m_gridSide);
767*35238bceSAndroid Build Coastguard Worker     else
768*35238bceSAndroid Build Coastguard Worker         ctx.drawArraysInstanced(GL_TRIANGLES, 0, 6, m_gridSide * m_gridSide);
769*35238bceSAndroid Build Coastguard Worker     ctx.useProgram(0);
770*35238bceSAndroid Build Coastguard Worker 
771*35238bceSAndroid Build Coastguard Worker     if (m_useIndices)
772*35238bceSAndroid Build Coastguard Worker         ctx.deleteBuffers(1, &indexBuf);
773*35238bceSAndroid Build Coastguard Worker     ctx.deleteBuffers(1, &colorBuf);
774*35238bceSAndroid Build Coastguard Worker     ctx.deleteBuffers(1, &offsetBuf);
775*35238bceSAndroid Build Coastguard Worker     ctx.deleteBuffers(1, &positionBuf);
776*35238bceSAndroid Build Coastguard Worker     ctx.deleteProgram(programID);
777*35238bceSAndroid Build Coastguard Worker 
778*35238bceSAndroid Build Coastguard Worker     ctx.finish();
779*35238bceSAndroid Build Coastguard Worker     ctx.readPixels(dst, 0, 0, dst.getWidth(), dst.getHeight());
780*35238bceSAndroid Build Coastguard Worker 
781*35238bceSAndroid Build Coastguard Worker     glu::checkError(ctx.getError(), "", __FILE__, __LINE__);
782*35238bceSAndroid Build Coastguard Worker }
783*35238bceSAndroid Build Coastguard Worker 
verifyImage(const tcu::Surface & image)784*35238bceSAndroid Build Coastguard Worker bool InstancedGridRenderTest::verifyImage(const tcu::Surface &image)
785*35238bceSAndroid Build Coastguard Worker {
786*35238bceSAndroid Build Coastguard Worker     // \note the green/yellow pattern is only for clarity. The test will only verify that all instances were drawn by looking for anything non-green/yellow.
787*35238bceSAndroid Build Coastguard Worker     using tcu::TestLog;
788*35238bceSAndroid Build Coastguard Worker 
789*35238bceSAndroid Build Coastguard Worker     const int colorThreshold = 20;
790*35238bceSAndroid Build Coastguard Worker 
791*35238bceSAndroid Build Coastguard Worker     tcu::Surface error(image.getWidth(), image.getHeight());
792*35238bceSAndroid Build Coastguard Worker     bool isOk = true;
793*35238bceSAndroid Build Coastguard Worker 
794*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < image.getHeight(); y++)
795*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < image.getWidth(); x++)
796*35238bceSAndroid Build Coastguard Worker         {
797*35238bceSAndroid Build Coastguard Worker             if (x == 0 || y == 0 || y + 1 == image.getHeight() || x + 1 == image.getWidth())
798*35238bceSAndroid Build Coastguard Worker             {
799*35238bceSAndroid Build Coastguard Worker                 // Background color might bleed in at the borders with msaa
800*35238bceSAndroid Build Coastguard Worker                 error.setPixel(x, y, tcu::RGBA(0, 255, 0, 255));
801*35238bceSAndroid Build Coastguard Worker             }
802*35238bceSAndroid Build Coastguard Worker             else
803*35238bceSAndroid Build Coastguard Worker             {
804*35238bceSAndroid Build Coastguard Worker                 const tcu::RGBA pixel = image.getPixel(x, y);
805*35238bceSAndroid Build Coastguard Worker                 bool pixelOk          = true;
806*35238bceSAndroid Build Coastguard Worker 
807*35238bceSAndroid Build Coastguard Worker                 // Any pixel with !(G ~= 255) is faulty (not a linear combinations of green and yellow)
808*35238bceSAndroid Build Coastguard Worker                 if (de::abs(pixel.getGreen() - 255) > colorThreshold)
809*35238bceSAndroid Build Coastguard Worker                     pixelOk = false;
810*35238bceSAndroid Build Coastguard Worker 
811*35238bceSAndroid Build Coastguard Worker                 // Any pixel with !(B ~= 0) is faulty (not a linear combinations of green and yellow)
812*35238bceSAndroid Build Coastguard Worker                 if (de::abs(pixel.getBlue() - 0) > colorThreshold)
813*35238bceSAndroid Build Coastguard Worker                     pixelOk = false;
814*35238bceSAndroid Build Coastguard Worker 
815*35238bceSAndroid Build Coastguard Worker                 error.setPixel(x, y, (pixelOk) ? (tcu::RGBA(0, 255, 0, 255)) : (tcu::RGBA(255, 0, 0, 255)));
816*35238bceSAndroid Build Coastguard Worker                 isOk = isOk && pixelOk;
817*35238bceSAndroid Build Coastguard Worker             }
818*35238bceSAndroid Build Coastguard Worker         }
819*35238bceSAndroid Build Coastguard Worker 
820*35238bceSAndroid Build Coastguard Worker     if (!isOk)
821*35238bceSAndroid Build Coastguard Worker     {
822*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = m_testCtx.getLog();
823*35238bceSAndroid Build Coastguard Worker 
824*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Image verification failed." << TestLog::EndMessage;
825*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Verfication result", "Result of rendering")
826*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Result", "Result", image) << TestLog::Image("ErrorMask", "Error mask", error)
827*35238bceSAndroid Build Coastguard Worker             << TestLog::EndImageSet;
828*35238bceSAndroid Build Coastguard Worker     }
829*35238bceSAndroid Build Coastguard Worker     else
830*35238bceSAndroid Build Coastguard Worker     {
831*35238bceSAndroid Build Coastguard Worker         tcu::TestLog &log = m_testCtx.getLog();
832*35238bceSAndroid Build Coastguard Worker 
833*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Verfication result", "Result of rendering")
834*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Result", "Result", image) << TestLog::EndImageSet;
835*35238bceSAndroid Build Coastguard Worker     }
836*35238bceSAndroid Build Coastguard Worker 
837*35238bceSAndroid Build Coastguard Worker     return isOk;
838*35238bceSAndroid Build Coastguard Worker }
839*35238bceSAndroid Build Coastguard Worker 
840*35238bceSAndroid Build Coastguard Worker class InstancingGroup : public TestCaseGroup
841*35238bceSAndroid Build Coastguard Worker {
842*35238bceSAndroid Build Coastguard Worker public:
843*35238bceSAndroid Build Coastguard Worker     InstancingGroup(Context &context, const char *name, const char *descr);
844*35238bceSAndroid Build Coastguard Worker     ~InstancingGroup(void);
845*35238bceSAndroid Build Coastguard Worker 
846*35238bceSAndroid Build Coastguard Worker     void init(void);
847*35238bceSAndroid Build Coastguard Worker };
848*35238bceSAndroid Build Coastguard Worker 
InstancingGroup(Context & context,const char * name,const char * descr)849*35238bceSAndroid Build Coastguard Worker InstancingGroup::InstancingGroup(Context &context, const char *name, const char *descr)
850*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, descr)
851*35238bceSAndroid Build Coastguard Worker {
852*35238bceSAndroid Build Coastguard Worker }
853*35238bceSAndroid Build Coastguard Worker 
~InstancingGroup(void)854*35238bceSAndroid Build Coastguard Worker InstancingGroup::~InstancingGroup(void)
855*35238bceSAndroid Build Coastguard Worker {
856*35238bceSAndroid Build Coastguard Worker }
857*35238bceSAndroid Build Coastguard Worker 
init(void)858*35238bceSAndroid Build Coastguard Worker void InstancingGroup::init(void)
859*35238bceSAndroid Build Coastguard Worker {
860*35238bceSAndroid Build Coastguard Worker     const int gridWidths[] = {
861*35238bceSAndroid Build Coastguard Worker         2, 5, 10, 32, 100,
862*35238bceSAndroid Build Coastguard Worker     };
863*35238bceSAndroid Build Coastguard Worker 
864*35238bceSAndroid Build Coastguard Worker     // drawArrays
865*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(gridWidths); ++ndx)
866*35238bceSAndroid Build Coastguard Worker     {
867*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("draw_arrays_instanced_grid_") + de::toString(gridWidths[ndx]) + "x" +
868*35238bceSAndroid Build Coastguard Worker                                  de::toString(gridWidths[ndx]);
869*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("DrawArraysInstanced, Grid size ") + de::toString(gridWidths[ndx]) + "x" +
870*35238bceSAndroid Build Coastguard Worker                                  de::toString(gridWidths[ndx]);
871*35238bceSAndroid Build Coastguard Worker 
872*35238bceSAndroid Build Coastguard Worker         this->addChild(new InstancedGridRenderTest(m_context, name.c_str(), desc.c_str(), gridWidths[ndx], false));
873*35238bceSAndroid Build Coastguard Worker     }
874*35238bceSAndroid Build Coastguard Worker 
875*35238bceSAndroid Build Coastguard Worker     // drawElements
876*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(gridWidths); ++ndx)
877*35238bceSAndroid Build Coastguard Worker     {
878*35238bceSAndroid Build Coastguard Worker         const std::string name = std::string("draw_elements_instanced_grid_") + de::toString(gridWidths[ndx]) + "x" +
879*35238bceSAndroid Build Coastguard Worker                                  de::toString(gridWidths[ndx]);
880*35238bceSAndroid Build Coastguard Worker         const std::string desc = std::string("DrawElementsInstanced, Grid size ") + de::toString(gridWidths[ndx]) +
881*35238bceSAndroid Build Coastguard Worker                                  "x" + de::toString(gridWidths[ndx]);
882*35238bceSAndroid Build Coastguard Worker 
883*35238bceSAndroid Build Coastguard Worker         this->addChild(new InstancedGridRenderTest(m_context, name.c_str(), desc.c_str(), gridWidths[ndx], true));
884*35238bceSAndroid Build Coastguard Worker     }
885*35238bceSAndroid Build Coastguard Worker }
886*35238bceSAndroid Build Coastguard Worker 
887*35238bceSAndroid Build Coastguard Worker class RandomGroup : public TestCaseGroup
888*35238bceSAndroid Build Coastguard Worker {
889*35238bceSAndroid Build Coastguard Worker public:
890*35238bceSAndroid Build Coastguard Worker     RandomGroup(Context &context, const char *name, const char *descr);
891*35238bceSAndroid Build Coastguard Worker     ~RandomGroup(void);
892*35238bceSAndroid Build Coastguard Worker 
893*35238bceSAndroid Build Coastguard Worker     void init(void);
894*35238bceSAndroid Build Coastguard Worker };
895*35238bceSAndroid Build Coastguard Worker 
896*35238bceSAndroid Build Coastguard Worker template <int SIZE>
897*35238bceSAndroid Build Coastguard Worker struct UniformWeightArray
898*35238bceSAndroid Build Coastguard Worker {
899*35238bceSAndroid Build Coastguard Worker     float weights[SIZE];
900*35238bceSAndroid Build Coastguard Worker 
UniformWeightArraydeqp::gles3::Functional::__anon99d5a21a0111::UniformWeightArray901*35238bceSAndroid Build Coastguard Worker     UniformWeightArray(void)
902*35238bceSAndroid Build Coastguard Worker     {
903*35238bceSAndroid Build Coastguard Worker         for (int i = 0; i < SIZE; ++i)
904*35238bceSAndroid Build Coastguard Worker             weights[i] = 1.0f;
905*35238bceSAndroid Build Coastguard Worker     }
906*35238bceSAndroid Build Coastguard Worker };
907*35238bceSAndroid Build Coastguard Worker 
RandomGroup(Context & context,const char * name,const char * descr)908*35238bceSAndroid Build Coastguard Worker RandomGroup::RandomGroup(Context &context, const char *name, const char *descr) : TestCaseGroup(context, name, descr)
909*35238bceSAndroid Build Coastguard Worker {
910*35238bceSAndroid Build Coastguard Worker }
911*35238bceSAndroid Build Coastguard Worker 
~RandomGroup(void)912*35238bceSAndroid Build Coastguard Worker RandomGroup::~RandomGroup(void)
913*35238bceSAndroid Build Coastguard Worker {
914*35238bceSAndroid Build Coastguard Worker }
915*35238bceSAndroid Build Coastguard Worker 
init(void)916*35238bceSAndroid Build Coastguard Worker void RandomGroup::init(void)
917*35238bceSAndroid Build Coastguard Worker {
918*35238bceSAndroid Build Coastguard Worker     const int numAttempts = 300;
919*35238bceSAndroid Build Coastguard Worker 
920*35238bceSAndroid Build Coastguard Worker     static const int attribCounts[]             = {1, 2, 5};
921*35238bceSAndroid Build Coastguard Worker     static const float attribWeights[]          = {30, 10, 1};
922*35238bceSAndroid Build Coastguard Worker     static const int primitiveCounts[]          = {1, 5, 64};
923*35238bceSAndroid Build Coastguard Worker     static const float primitiveCountWeights[]  = {20, 10, 1};
924*35238bceSAndroid Build Coastguard Worker     static const int indexOffsets[]             = {0, 7, 13};
925*35238bceSAndroid Build Coastguard Worker     static const float indexOffsetWeights[]     = {20, 20, 1};
926*35238bceSAndroid Build Coastguard Worker     static const int firsts[]                   = {0, 7, 13};
927*35238bceSAndroid Build Coastguard Worker     static const float firstWeights[]           = {20, 20, 1};
928*35238bceSAndroid Build Coastguard Worker     static const int instanceCounts[]           = {1, 2, 16, 17};
929*35238bceSAndroid Build Coastguard Worker     static const float instanceWeights[]        = {20, 10, 5, 1};
930*35238bceSAndroid Build Coastguard Worker     static const int indexMins[]                = {0, 1, 3, 8};
931*35238bceSAndroid Build Coastguard Worker     static const int indexMaxs[]                = {4, 8, 128, 257};
932*35238bceSAndroid Build Coastguard Worker     static const float indexWeights[]           = {50, 50, 50, 50};
933*35238bceSAndroid Build Coastguard Worker     static const int offsets[]                  = {0, 1, 5, 12};
934*35238bceSAndroid Build Coastguard Worker     static const float offsetWeights[]          = {50, 10, 10, 10};
935*35238bceSAndroid Build Coastguard Worker     static const int strides[]                  = {0, 7, 16, 17};
936*35238bceSAndroid Build Coastguard Worker     static const float strideWeights[]          = {50, 10, 10, 10};
937*35238bceSAndroid Build Coastguard Worker     static const int instanceDivisors[]         = {0, 1, 3, 129};
938*35238bceSAndroid Build Coastguard Worker     static const float instanceDivisorWeights[] = {70, 30, 10, 10};
939*35238bceSAndroid Build Coastguard Worker 
940*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::Primitive primitives[] = {
941*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_POINTS,       gls::DrawTestSpec::PRIMITIVE_TRIANGLES,
942*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP,
943*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINES,        gls::DrawTestSpec::PRIMITIVE_LINE_STRIP,
944*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::PRIMITIVE_LINE_LOOP};
945*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(primitives)> primitiveWeights;
946*35238bceSAndroid Build Coastguard Worker 
947*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::DrawMethod drawMethods[] = {
948*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS, gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED,
949*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS, gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED,
950*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED};
951*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(drawMethods)> drawMethodWeights;
952*35238bceSAndroid Build Coastguard Worker 
953*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::IndexType indexTypes[] = {
954*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INDEXTYPE_BYTE,
955*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INDEXTYPE_SHORT,
956*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INDEXTYPE_INT,
957*35238bceSAndroid Build Coastguard Worker     };
958*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(indexTypes)> indexTypeWeights;
959*35238bceSAndroid Build Coastguard Worker 
960*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::Storage storages[] = {
961*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::STORAGE_USER,
962*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::STORAGE_BUFFER,
963*35238bceSAndroid Build Coastguard Worker     };
964*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(storages)> storageWeights;
965*35238bceSAndroid Build Coastguard Worker 
966*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::InputType inputTypes[] = {
967*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_FLOAT,
968*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_FIXED,
969*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_BYTE,
970*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_SHORT,
971*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_UNSIGNED_BYTE,
972*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_UNSIGNED_SHORT,
973*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_INT,
974*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT,
975*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_HALF,
976*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT_2_10_10_10,
977*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::INPUTTYPE_INT_2_10_10_10,
978*35238bceSAndroid Build Coastguard Worker     };
979*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(inputTypes)> inputTypeWeights;
980*35238bceSAndroid Build Coastguard Worker 
981*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::OutputType outputTypes[] = {
982*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC2,  gls::DrawTestSpec::OUTPUTTYPE_VEC3,
983*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_VEC4,  gls::DrawTestSpec::OUTPUTTYPE_INT,   gls::DrawTestSpec::OUTPUTTYPE_UINT,
984*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_IVEC2, gls::DrawTestSpec::OUTPUTTYPE_IVEC3, gls::DrawTestSpec::OUTPUTTYPE_IVEC4,
985*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::OUTPUTTYPE_UVEC2, gls::DrawTestSpec::OUTPUTTYPE_UVEC3, gls::DrawTestSpec::OUTPUTTYPE_UVEC4,
986*35238bceSAndroid Build Coastguard Worker     };
987*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(outputTypes)> outputTypeWeights;
988*35238bceSAndroid Build Coastguard Worker 
989*35238bceSAndroid Build Coastguard Worker     static const gls::DrawTestSpec::Usage usages[] = {
990*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_DYNAMIC_DRAW, gls::DrawTestSpec::USAGE_STATIC_DRAW,
991*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_STREAM_DRAW,  gls::DrawTestSpec::USAGE_STREAM_READ,
992*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_STREAM_COPY,  gls::DrawTestSpec::USAGE_STATIC_READ,
993*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_STATIC_COPY,  gls::DrawTestSpec::USAGE_DYNAMIC_READ,
994*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec::USAGE_DYNAMIC_COPY,
995*35238bceSAndroid Build Coastguard Worker     };
996*35238bceSAndroid Build Coastguard Worker     const UniformWeightArray<DE_LENGTH_OF_ARRAY(usages)> usageWeights;
997*35238bceSAndroid Build Coastguard Worker 
998*35238bceSAndroid Build Coastguard Worker     static const uint32_t disallowedCases[] = {
999*35238bceSAndroid Build Coastguard Worker         544, //!< extremely narrow triangle
1000*35238bceSAndroid Build Coastguard Worker     };
1001*35238bceSAndroid Build Coastguard Worker 
1002*35238bceSAndroid Build Coastguard Worker     std::set<uint32_t> insertedHashes;
1003*35238bceSAndroid Build Coastguard Worker     size_t insertedCount = 0;
1004*35238bceSAndroid Build Coastguard Worker 
1005*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < numAttempts; ++ndx)
1006*35238bceSAndroid Build Coastguard Worker     {
1007*35238bceSAndroid Build Coastguard Worker         de::Random random(0xc551393 + ndx); // random does not depend on previous cases
1008*35238bceSAndroid Build Coastguard Worker 
1009*35238bceSAndroid Build Coastguard Worker         int attributeCount = random.chooseWeighted<int, const int *, const float *>(
1010*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(attribCounts), DE_ARRAY_END(attribCounts), attribWeights);
1011*35238bceSAndroid Build Coastguard Worker         gls::DrawTestSpec spec;
1012*35238bceSAndroid Build Coastguard Worker 
1013*35238bceSAndroid Build Coastguard Worker         spec.apiType   = glu::ApiType::es(3, 0);
1014*35238bceSAndroid Build Coastguard Worker         spec.primitive = random.chooseWeighted<gls::DrawTestSpec::Primitive>(
1015*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(primitives), DE_ARRAY_END(primitives), primitiveWeights.weights);
1016*35238bceSAndroid Build Coastguard Worker         spec.primitiveCount = random.chooseWeighted<int, const int *, const float *>(
1017*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(primitiveCounts), DE_ARRAY_END(primitiveCounts), primitiveCountWeights);
1018*35238bceSAndroid Build Coastguard Worker         spec.drawMethod = random.chooseWeighted<gls::DrawTestSpec::DrawMethod>(
1019*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(drawMethods), DE_ARRAY_END(drawMethods), drawMethodWeights.weights);
1020*35238bceSAndroid Build Coastguard Worker         spec.indexType = random.chooseWeighted<gls::DrawTestSpec::IndexType>(
1021*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(indexTypes), DE_ARRAY_END(indexTypes), indexTypeWeights.weights);
1022*35238bceSAndroid Build Coastguard Worker         spec.indexPointerOffset = random.chooseWeighted<int, const int *, const float *>(
1023*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(indexOffsets), DE_ARRAY_END(indexOffsets), indexOffsetWeights);
1024*35238bceSAndroid Build Coastguard Worker         spec.indexStorage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
1025*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
1026*35238bceSAndroid Build Coastguard Worker         spec.first         = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(firsts),
1027*35238bceSAndroid Build Coastguard Worker                                                                             DE_ARRAY_END(firsts), firstWeights);
1028*35238bceSAndroid Build Coastguard Worker         spec.indexMin      = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(indexMins),
1029*35238bceSAndroid Build Coastguard Worker                                                                                DE_ARRAY_END(indexMins), indexWeights);
1030*35238bceSAndroid Build Coastguard Worker         spec.indexMax      = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(indexMaxs),
1031*35238bceSAndroid Build Coastguard Worker                                                                                DE_ARRAY_END(indexMaxs), indexWeights);
1032*35238bceSAndroid Build Coastguard Worker         spec.instanceCount = random.chooseWeighted<int, const int *, const float *>(
1033*35238bceSAndroid Build Coastguard Worker             DE_ARRAY_BEGIN(instanceCounts), DE_ARRAY_END(instanceCounts), instanceWeights);
1034*35238bceSAndroid Build Coastguard Worker 
1035*35238bceSAndroid Build Coastguard Worker         // check spec is legal
1036*35238bceSAndroid Build Coastguard Worker         if (!spec.valid())
1037*35238bceSAndroid Build Coastguard Worker             continue;
1038*35238bceSAndroid Build Coastguard Worker 
1039*35238bceSAndroid Build Coastguard Worker         for (int attrNdx = 0; attrNdx < attributeCount;)
1040*35238bceSAndroid Build Coastguard Worker         {
1041*35238bceSAndroid Build Coastguard Worker             bool valid;
1042*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::AttributeSpec attribSpec;
1043*35238bceSAndroid Build Coastguard Worker 
1044*35238bceSAndroid Build Coastguard Worker             attribSpec.inputType = random.chooseWeighted<gls::DrawTestSpec::InputType>(
1045*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(inputTypes), DE_ARRAY_END(inputTypes), inputTypeWeights.weights);
1046*35238bceSAndroid Build Coastguard Worker             attribSpec.outputType = random.chooseWeighted<gls::DrawTestSpec::OutputType>(
1047*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(outputTypes), DE_ARRAY_END(outputTypes), outputTypeWeights.weights);
1048*35238bceSAndroid Build Coastguard Worker             attribSpec.storage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
1049*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
1050*35238bceSAndroid Build Coastguard Worker             attribSpec.usage = random.chooseWeighted<gls::DrawTestSpec::Usage>(
1051*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(usages), DE_ARRAY_END(usages), usageWeights.weights);
1052*35238bceSAndroid Build Coastguard Worker             attribSpec.componentCount = random.getInt(1, 4);
1053*35238bceSAndroid Build Coastguard Worker             attribSpec.offset         = random.chooseWeighted<int, const int *, const float *>(
1054*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(offsets), DE_ARRAY_END(offsets), offsetWeights);
1055*35238bceSAndroid Build Coastguard Worker             attribSpec.stride = random.chooseWeighted<int, const int *, const float *>(
1056*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(strides), DE_ARRAY_END(strides), strideWeights);
1057*35238bceSAndroid Build Coastguard Worker             attribSpec.normalize       = random.getBool();
1058*35238bceSAndroid Build Coastguard Worker             attribSpec.instanceDivisor = random.chooseWeighted<int, const int *, const float *>(
1059*35238bceSAndroid Build Coastguard Worker                 DE_ARRAY_BEGIN(instanceDivisors), DE_ARRAY_END(instanceDivisors), instanceDivisorWeights);
1060*35238bceSAndroid Build Coastguard Worker             attribSpec.useDefaultAttribute = random.getBool();
1061*35238bceSAndroid Build Coastguard Worker 
1062*35238bceSAndroid Build Coastguard Worker             // check spec is legal
1063*35238bceSAndroid Build Coastguard Worker             valid = attribSpec.valid(spec.apiType);
1064*35238bceSAndroid Build Coastguard Worker 
1065*35238bceSAndroid Build Coastguard Worker             // we do not want interleaved elements. (Might result in some weird floating point values)
1066*35238bceSAndroid Build Coastguard Worker             if (attribSpec.stride &&
1067*35238bceSAndroid Build Coastguard Worker                 attribSpec.componentCount * gls::DrawTestSpec::inputTypeSize(attribSpec.inputType) > attribSpec.stride)
1068*35238bceSAndroid Build Coastguard Worker                 valid = false;
1069*35238bceSAndroid Build Coastguard Worker 
1070*35238bceSAndroid Build Coastguard Worker             // try again if not valid
1071*35238bceSAndroid Build Coastguard Worker             if (valid)
1072*35238bceSAndroid Build Coastguard Worker             {
1073*35238bceSAndroid Build Coastguard Worker                 spec.attribs.push_back(attribSpec);
1074*35238bceSAndroid Build Coastguard Worker                 ++attrNdx;
1075*35238bceSAndroid Build Coastguard Worker             }
1076*35238bceSAndroid Build Coastguard Worker         }
1077*35238bceSAndroid Build Coastguard Worker 
1078*35238bceSAndroid Build Coastguard Worker         // Do not collapse all vertex positions to a single positions
1079*35238bceSAndroid Build Coastguard Worker         if (spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
1080*35238bceSAndroid Build Coastguard Worker             spec.attribs[0].instanceDivisor = 0;
1081*35238bceSAndroid Build Coastguard Worker 
1082*35238bceSAndroid Build Coastguard Worker         // Is render result meaningful?
1083*35238bceSAndroid Build Coastguard Worker         {
1084*35238bceSAndroid Build Coastguard Worker             // Only one vertex
1085*35238bceSAndroid Build Coastguard Worker             if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
1086*35238bceSAndroid Build Coastguard Worker                 spec.indexMin == spec.indexMax && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
1087*35238bceSAndroid Build Coastguard Worker                 continue;
1088*35238bceSAndroid Build Coastguard Worker             if (spec.attribs[0].useDefaultAttribute && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
1089*35238bceSAndroid Build Coastguard Worker                 continue;
1090*35238bceSAndroid Build Coastguard Worker 
1091*35238bceSAndroid Build Coastguard Worker             // Triangle only on one axis
1092*35238bceSAndroid Build Coastguard Worker             if (spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLES ||
1093*35238bceSAndroid Build Coastguard Worker                 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN ||
1094*35238bceSAndroid Build Coastguard Worker                 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP)
1095*35238bceSAndroid Build Coastguard Worker             {
1096*35238bceSAndroid Build Coastguard Worker                 if (spec.attribs[0].componentCount == 1)
1097*35238bceSAndroid Build Coastguard Worker                     continue;
1098*35238bceSAndroid Build Coastguard Worker                 if (spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_FLOAT ||
1099*35238bceSAndroid Build Coastguard Worker                     spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_INT ||
1100*35238bceSAndroid Build Coastguard Worker                     spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_UINT)
1101*35238bceSAndroid Build Coastguard Worker                     continue;
1102*35238bceSAndroid Build Coastguard Worker                 if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
1103*35238bceSAndroid Build Coastguard Worker                     (spec.indexMax - spec.indexMin) < 2)
1104*35238bceSAndroid Build Coastguard Worker                     continue;
1105*35238bceSAndroid Build Coastguard Worker             }
1106*35238bceSAndroid Build Coastguard Worker         }
1107*35238bceSAndroid Build Coastguard Worker 
1108*35238bceSAndroid Build Coastguard Worker         // Add case
1109*35238bceSAndroid Build Coastguard Worker         {
1110*35238bceSAndroid Build Coastguard Worker             uint32_t hash = spec.hash();
1111*35238bceSAndroid Build Coastguard Worker             for (int attrNdx = 0; attrNdx < attributeCount; ++attrNdx)
1112*35238bceSAndroid Build Coastguard Worker                 hash = (hash << 2) ^ (uint32_t)spec.attribs[attrNdx].hash();
1113*35238bceSAndroid Build Coastguard Worker 
1114*35238bceSAndroid Build Coastguard Worker             if (insertedHashes.find(hash) == insertedHashes.end())
1115*35238bceSAndroid Build Coastguard Worker             {
1116*35238bceSAndroid Build Coastguard Worker                 // Only properly aligned and not disallowed cases
1117*35238bceSAndroid Build Coastguard Worker                 if (spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET &&
1118*35238bceSAndroid Build Coastguard Worker                     spec.isCompatibilityTest() != gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE &&
1119*35238bceSAndroid Build Coastguard Worker                     !de::contains(DE_ARRAY_BEGIN(disallowedCases), DE_ARRAY_END(disallowedCases), hash))
1120*35238bceSAndroid Build Coastguard Worker                 {
1121*35238bceSAndroid Build Coastguard Worker                     this->addChild(new gls::DrawTest(m_testCtx, m_context.getRenderContext(), spec,
1122*35238bceSAndroid Build Coastguard Worker                                                      de::toString(insertedCount).c_str(), spec.getDesc().c_str()));
1123*35238bceSAndroid Build Coastguard Worker                 }
1124*35238bceSAndroid Build Coastguard Worker                 insertedHashes.insert(hash);
1125*35238bceSAndroid Build Coastguard Worker 
1126*35238bceSAndroid Build Coastguard Worker                 ++insertedCount;
1127*35238bceSAndroid Build Coastguard Worker             }
1128*35238bceSAndroid Build Coastguard Worker         }
1129*35238bceSAndroid Build Coastguard Worker     }
1130*35238bceSAndroid Build Coastguard Worker }
1131*35238bceSAndroid Build Coastguard Worker 
1132*35238bceSAndroid Build Coastguard Worker } // namespace
1133*35238bceSAndroid Build Coastguard Worker 
DrawTests(Context & context)1134*35238bceSAndroid Build Coastguard Worker DrawTests::DrawTests(Context &context) : TestCaseGroup(context, "draw", "Drawing tests")
1135*35238bceSAndroid Build Coastguard Worker {
1136*35238bceSAndroid Build Coastguard Worker }
1137*35238bceSAndroid Build Coastguard Worker 
~DrawTests(void)1138*35238bceSAndroid Build Coastguard Worker DrawTests::~DrawTests(void)
1139*35238bceSAndroid Build Coastguard Worker {
1140*35238bceSAndroid Build Coastguard Worker }
1141*35238bceSAndroid Build Coastguard Worker 
init(void)1142*35238bceSAndroid Build Coastguard Worker void DrawTests::init(void)
1143*35238bceSAndroid Build Coastguard Worker {
1144*35238bceSAndroid Build Coastguard Worker     // Basic
1145*35238bceSAndroid Build Coastguard Worker     {
1146*35238bceSAndroid Build Coastguard Worker         const gls::DrawTestSpec::DrawMethod basicMethods[] = {
1147*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS,           gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS,
1148*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED, gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED,
1149*35238bceSAndroid Build Coastguard Worker             gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED,
1150*35238bceSAndroid Build Coastguard Worker         };
1151*35238bceSAndroid Build Coastguard Worker 
1152*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(basicMethods); ++ndx)
1153*35238bceSAndroid Build Coastguard Worker         {
1154*35238bceSAndroid Build Coastguard Worker             const std::string name = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
1155*35238bceSAndroid Build Coastguard Worker             const std::string desc = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
1156*35238bceSAndroid Build Coastguard Worker 
1157*35238bceSAndroid Build Coastguard Worker             this->addChild(new MethodGroup(m_context, name.c_str(), desc.c_str(), basicMethods[ndx]));
1158*35238bceSAndroid Build Coastguard Worker         }
1159*35238bceSAndroid Build Coastguard Worker     }
1160*35238bceSAndroid Build Coastguard Worker 
1161*35238bceSAndroid Build Coastguard Worker     // extreme instancing
1162*35238bceSAndroid Build Coastguard Worker 
1163*35238bceSAndroid Build Coastguard Worker     this->addChild(new InstancingGroup(m_context, "instancing", "draw tests with a large instance count."));
1164*35238bceSAndroid Build Coastguard Worker 
1165*35238bceSAndroid Build Coastguard Worker     // Random
1166*35238bceSAndroid Build Coastguard Worker 
1167*35238bceSAndroid Build Coastguard Worker     this->addChild(new RandomGroup(m_context, "random", "random draw commands."));
1168*35238bceSAndroid Build Coastguard Worker }
1169*35238bceSAndroid Build Coastguard Worker 
1170*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1171*35238bceSAndroid Build Coastguard Worker } // namespace gles3
1172*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1173