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