1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.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 Draw stress tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "es3sDrawTests.hpp"
25 #include "tcuVector.hpp"
26 #include "tcuTestLog.hpp"
27 #include "tcuRenderTarget.hpp"
28 #include "tcuSurface.hpp"
29 #include "gluCallLogWrapper.hpp"
30 #include "gluObjectWrapper.hpp"
31 #include "gluPixelTransfer.hpp"
32 #include "gluRenderContext.hpp"
33 #include "gluShaderProgram.hpp"
34 #include "gluStrUtil.hpp"
35 #include "glsDrawTest.hpp"
36 #include "glwFunctions.hpp"
37 #include "glwEnums.hpp"
38 #include "deRandom.hpp"
39 #include "deStringUtil.hpp"
40 #include "deUniquePtr.hpp"
41
42 #include <set>
43
44 namespace deqp
45 {
46 namespace gles3
47 {
48 namespace Stress
49 {
50 namespace
51 {
52
53 static const char *const s_vertexSource = "#version 300 es\n"
54 "in highp vec4 a_position;\n"
55 "void main (void)\n"
56 "{\n"
57 " gl_Position = a_position;\n"
58 "}\n";
59 static const char *const s_fragmentSource = "#version 300 es\n"
60 "layout(location = 0) out mediump vec4 fragColor;\n"
61 "void main (void)\n"
62 "{\n"
63 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
64 "}\n";
65
66 class DrawInvalidRangeCase : public TestCase
67 {
68 public:
69 DrawInvalidRangeCase(Context &ctx, const char *name, const char *desc, uint32_t min, uint32_t max,
70 bool useLimitMin = false, bool useLimitMax = false);
71 ~DrawInvalidRangeCase(void);
72
73 void init(void);
74 void deinit(void);
75 IterateResult iterate(void);
76
77 private:
78 const int m_min;
79 const int m_max;
80 const int m_bufferedElements;
81 const int m_numIndices;
82 const bool m_useLimitMin;
83 const bool m_useLimitMax;
84
85 uint32_t m_buffer;
86 uint32_t m_indexBuffer;
87 glu::ShaderProgram *m_program;
88 };
89
DrawInvalidRangeCase(Context & ctx,const char * name,const char * desc,uint32_t min,uint32_t max,bool useLimitMin,bool useLimitMax)90 DrawInvalidRangeCase::DrawInvalidRangeCase(Context &ctx, const char *name, const char *desc, uint32_t min, uint32_t max,
91 bool useLimitMin, bool useLimitMax)
92 : TestCase(ctx, name, desc)
93 , m_min(min)
94 , m_max(max)
95 , m_bufferedElements(128)
96 , m_numIndices(64)
97 , m_useLimitMin(useLimitMin)
98 , m_useLimitMax(useLimitMax)
99 , m_buffer(0)
100 , m_indexBuffer(0)
101 , m_program(DE_NULL)
102 {
103 }
104
~DrawInvalidRangeCase(void)105 DrawInvalidRangeCase::~DrawInvalidRangeCase(void)
106 {
107 deinit();
108 }
109
init(void)110 void DrawInvalidRangeCase::init(void)
111 {
112 const glw::Functions &gl = m_context.getRenderContext().getFunctions();
113 std::vector<tcu::Vec4> data(m_bufferedElements); // !< some junk data to make sure buffer is really allocated
114 std::vector<uint32_t> indices(m_numIndices);
115
116 for (int ndx = 0; ndx < m_numIndices; ++ndx)
117 indices[ndx] = ndx;
118
119 gl.genBuffers(1, &m_buffer);
120 gl.bindBuffer(GL_ARRAY_BUFFER, m_buffer);
121 gl.bufferData(GL_ARRAY_BUFFER, int(m_bufferedElements * sizeof(tcu::Vec4)), &data[0], GL_STATIC_DRAW);
122 GLU_EXPECT_NO_ERROR(gl.getError(), "buffer gen");
123
124 gl.genBuffers(1, &m_indexBuffer);
125 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
126 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, int(m_numIndices * sizeof(uint32_t)), &indices[0], GL_STATIC_DRAW);
127 GLU_EXPECT_NO_ERROR(gl.getError(), "buffer gen");
128
129 m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
130 << glu::VertexSource(s_vertexSource)
131 << glu::FragmentSource(s_fragmentSource));
132 if (!m_program->isOk())
133 {
134 m_testCtx.getLog() << *m_program;
135 throw tcu::TestError("could not build program");
136 }
137 }
138
deinit(void)139 void DrawInvalidRangeCase::deinit(void)
140 {
141 if (m_buffer)
142 {
143 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_buffer);
144 m_buffer = 0;
145 }
146
147 if (m_indexBuffer)
148 {
149 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indexBuffer);
150 m_indexBuffer = 0;
151 }
152
153 delete m_program;
154 m_program = DE_NULL;
155 }
156
iterate(void)157 DrawInvalidRangeCase::IterateResult DrawInvalidRangeCase::iterate(void)
158 {
159 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
160 const int32_t positionLoc = gl.glGetAttribLocation(m_program->getProgram(), "a_position");
161 tcu::Surface dst(m_context.getRenderTarget().getWidth(), m_context.getRenderTarget().getHeight());
162 glu::VertexArray vao(m_context.getRenderContext());
163
164 int64_t indexLimit = 0;
165 uint32_t min = m_min;
166 uint32_t max = m_max;
167
168 gl.enableLogging(true);
169
170 if (m_useLimitMin || m_useLimitMax)
171 {
172 gl.glGetInteger64v(GL_MAX_ELEMENT_INDEX, &indexLimit);
173 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query limit");
174 }
175
176 if (m_useLimitMin)
177 {
178 if ((uint64_t)indexLimit > 0xFFFFFFFFULL)
179 min = 0xFFFFFFF0;
180 else
181 min = (uint32_t)(indexLimit - 16);
182 }
183
184 if (m_useLimitMax)
185 {
186 if ((uint64_t)indexLimit > 0xFFFFFFFFULL)
187 max = 0xFFFFFFFF;
188 else
189 max = (uint32_t)indexLimit;
190 }
191
192 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
193 gl.glClear(GL_COLOR_BUFFER_BIT);
194 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup");
195
196 gl.glUseProgram(m_program->getProgram());
197 GLU_EXPECT_NO_ERROR(gl.glGetError(), "use program");
198
199 gl.glBindVertexArray(*vao);
200 gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
201
202 gl.glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
203 gl.glEnableVertexAttribArray(positionLoc);
204 gl.glVertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
205 GLU_EXPECT_NO_ERROR(gl.glGetError(), "set buffer");
206
207 gl.glDrawRangeElements(GL_POINTS, min, max, m_numIndices, GL_UNSIGNED_INT, DE_NULL);
208
209 // Indexing outside range is an error, but it doesnt need to be checked. Causes implementation-dependent behavior.
210 // Even if the indices are in range (m_min = 0), the specification allows partial processing of vertices in the range,
211 // which might cause access over buffer bounds. Causes implementation-dependent behavior.
212
213 // allow errors
214 {
215 const uint32_t error = gl.glGetError();
216
217 if (error != GL_NO_ERROR)
218 m_testCtx.getLog() << tcu::TestLog::Message << "Got error: " << glu::getErrorStr(error) << ", ignoring..."
219 << tcu::TestLog::EndMessage;
220 }
221
222 // read pixels to wait for rendering
223 gl.glFinish();
224 glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
225
226 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
227 return STOP;
228 }
229
genBasicSpec(gls::DrawTestSpec & spec,gls::DrawTestSpec::DrawMethod method)230 static void genBasicSpec(gls::DrawTestSpec &spec, gls::DrawTestSpec::DrawMethod method)
231 {
232 spec.apiType = glu::ApiType::es(3, 0);
233 spec.primitive = gls::DrawTestSpec::PRIMITIVE_TRIANGLES;
234 spec.primitiveCount = 5;
235 spec.drawMethod = method;
236 spec.indexType = gls::DrawTestSpec::INDEXTYPE_LAST;
237 spec.indexPointerOffset = 0;
238 spec.indexStorage = gls::DrawTestSpec::STORAGE_LAST;
239 spec.first = 0;
240 spec.indexMin = 0;
241 spec.indexMax = 0;
242 spec.instanceCount = 1;
243
244 spec.attribs.resize(2);
245
246 spec.attribs[0].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT;
247 spec.attribs[0].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
248 spec.attribs[0].storage = gls::DrawTestSpec::STORAGE_BUFFER;
249 spec.attribs[0].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW;
250 spec.attribs[0].componentCount = 4;
251 spec.attribs[0].offset = 0;
252 spec.attribs[0].stride = 0;
253 spec.attribs[0].normalize = false;
254 spec.attribs[0].instanceDivisor = 0;
255 spec.attribs[0].useDefaultAttribute = false;
256
257 spec.attribs[1].inputType = gls::DrawTestSpec::INPUTTYPE_FLOAT;
258 spec.attribs[1].outputType = gls::DrawTestSpec::OUTPUTTYPE_VEC2;
259 spec.attribs[1].storage = gls::DrawTestSpec::STORAGE_BUFFER;
260 spec.attribs[1].usage = gls::DrawTestSpec::USAGE_STATIC_DRAW;
261 spec.attribs[1].componentCount = 2;
262 spec.attribs[1].offset = 0;
263 spec.attribs[1].stride = 0;
264 spec.attribs[1].normalize = false;
265 spec.attribs[1].instanceDivisor = 0;
266 spec.attribs[1].useDefaultAttribute = false;
267 }
268
269 class IndexGroup : public TestCaseGroup
270 {
271 public:
272 IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
273 ~IndexGroup(void);
274
275 void init(void);
276
277 private:
278 gls::DrawTestSpec::DrawMethod m_method;
279 };
280
IndexGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)281 IndexGroup::IndexGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod)
282 : TestCaseGroup(context, name, descr)
283 , m_method(drawMethod)
284 {
285 }
286
~IndexGroup(void)287 IndexGroup::~IndexGroup(void)
288 {
289 }
290
init(void)291 void IndexGroup::init(void)
292 {
293 struct IndexTest
294 {
295 gls::DrawTestSpec::Storage storage;
296 gls::DrawTestSpec::IndexType type;
297 bool aligned;
298 int offsets[3];
299 };
300
301 const IndexTest tests[] = {
302 {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_SHORT, false, {1, 3, -1}},
303 {gls::DrawTestSpec::STORAGE_BUFFER, gls::DrawTestSpec::INDEXTYPE_INT, false, {2, 3, -1}},
304 };
305
306 gls::DrawTestSpec spec;
307
308 tcu::TestCaseGroup *const unalignedBufferGroup =
309 new tcu::TestCaseGroup(m_testCtx, "unaligned_buffer", "unaligned buffer");
310 const bool isRangedMethod = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED ||
311 m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX);
312
313 genBasicSpec(spec, m_method);
314
315 this->addChild(unalignedBufferGroup);
316
317 for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
318 {
319 const IndexTest &indexTest = tests[testNdx];
320
321 DE_ASSERT(indexTest.storage != gls::DrawTestSpec::STORAGE_USER);
322 DE_ASSERT(!indexTest.aligned);
323 tcu::TestCaseGroup *group = unalignedBufferGroup;
324
325 const std::string name = std::string("index_") + gls::DrawTestSpec::indexTypeToString(indexTest.type);
326 const std::string desc = std::string("index ") + gls::DrawTestSpec::indexTypeToString(indexTest.type) + " in " +
327 gls::DrawTestSpec::storageToString(indexTest.storage);
328 de::MovePtr<gls::DrawTest> test(
329 new gls::DrawTest(m_testCtx, m_context.getRenderContext(), name.c_str(), desc.c_str()));
330
331 spec.indexType = indexTest.type;
332 spec.indexStorage = indexTest.storage;
333
334 if (isRangedMethod)
335 {
336 spec.indexMin = 0;
337 spec.indexMax = 55;
338 }
339
340 for (int iterationNdx = 0;
341 iterationNdx < DE_LENGTH_OF_ARRAY(indexTest.offsets) && indexTest.offsets[iterationNdx] != -1;
342 ++iterationNdx)
343 {
344 const std::string iterationDesc = std::string("offset ") + de::toString(indexTest.offsets[iterationNdx]);
345 spec.indexPointerOffset = indexTest.offsets[iterationNdx];
346 test->addIteration(spec, iterationDesc.c_str());
347 }
348
349 DE_ASSERT(spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET ||
350 spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE);
351 group->addChild(test.release());
352 }
353 }
354
355 class MethodGroup : public TestCaseGroup
356 {
357 public:
358 MethodGroup(Context &context, const char *name, const char *descr, gls::DrawTestSpec::DrawMethod drawMethod);
359 ~MethodGroup(void);
360
361 void init(void);
362
363 private:
364 gls::DrawTestSpec::DrawMethod m_method;
365 };
366
MethodGroup(Context & context,const char * name,const char * descr,gls::DrawTestSpec::DrawMethod drawMethod)367 MethodGroup::MethodGroup(Context &context, const char *name, const char *descr,
368 gls::DrawTestSpec::DrawMethod drawMethod)
369 : TestCaseGroup(context, name, descr)
370 , m_method(drawMethod)
371 {
372 }
373
~MethodGroup(void)374 MethodGroup::~MethodGroup(void)
375 {
376 }
377
init(void)378 void MethodGroup::init(void)
379 {
380 const bool indexed = (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS) ||
381 (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED) ||
382 (m_method == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED);
383
384 DE_ASSERT(indexed);
385 DE_UNREF(indexed);
386
387 this->addChild(new IndexGroup(m_context, "indices", "Index tests", m_method));
388 }
389
390 class RandomGroup : public TestCaseGroup
391 {
392 public:
393 RandomGroup(Context &context, const char *name, const char *descr);
394 ~RandomGroup(void);
395
396 void init(void);
397 };
398
399 template <int SIZE>
400 struct UniformWeightArray
401 {
402 float weights[SIZE];
403
UniformWeightArraydeqp::gles3::Stress::__anon697865380111::UniformWeightArray404 UniformWeightArray(void)
405 {
406 for (int i = 0; i < SIZE; ++i)
407 weights[i] = 1.0f;
408 }
409 };
410
RandomGroup(Context & context,const char * name,const char * descr)411 RandomGroup::RandomGroup(Context &context, const char *name, const char *descr) : TestCaseGroup(context, name, descr)
412 {
413 }
414
~RandomGroup(void)415 RandomGroup::~RandomGroup(void)
416 {
417 }
418
init(void)419 void RandomGroup::init(void)
420 {
421 const int numAttempts = 300;
422
423 const int attribCounts[] = {1, 2, 5};
424 const float attribWeights[] = {30, 10, 1};
425 const int primitiveCounts[] = {1, 5, 64};
426 const float primitiveCountWeights[] = {20, 10, 1};
427 const int indexOffsets[] = {0, 7, 13};
428 const float indexOffsetWeights[] = {20, 20, 1};
429 const int firsts[] = {0, 7, 13};
430 const float firstWeights[] = {20, 20, 1};
431 const int instanceCounts[] = {1, 2, 16, 17};
432 const float instanceWeights[] = {20, 10, 5, 1};
433 const int indexMins[] = {0, 1, 3, 8};
434 const int indexMaxs[] = {4, 8, 128, 257};
435 const float indexWeights[] = {50, 50, 50, 50};
436 const int offsets[] = {0, 1, 5, 12};
437 const float offsetWeights[] = {50, 10, 10, 10};
438 const int strides[] = {0, 7, 16, 17};
439 const float strideWeights[] = {50, 10, 10, 10};
440 const int instanceDivisors[] = {0, 1, 3, 129};
441 const float instanceDivisorWeights[] = {70, 30, 10, 10};
442
443 gls::DrawTestSpec::Primitive primitives[] = {
444 gls::DrawTestSpec::PRIMITIVE_POINTS, gls::DrawTestSpec::PRIMITIVE_TRIANGLES,
445 gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN, gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP,
446 gls::DrawTestSpec::PRIMITIVE_LINES, gls::DrawTestSpec::PRIMITIVE_LINE_STRIP,
447 gls::DrawTestSpec::PRIMITIVE_LINE_LOOP};
448 const UniformWeightArray<DE_LENGTH_OF_ARRAY(primitives)> primitiveWeights;
449
450 gls::DrawTestSpec::DrawMethod drawMethods[] = {
451 gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS, gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED,
452 gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS, gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED,
453 gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED};
454 const UniformWeightArray<DE_LENGTH_OF_ARRAY(drawMethods)> drawMethodWeights;
455
456 gls::DrawTestSpec::IndexType indexTypes[] = {
457 gls::DrawTestSpec::INDEXTYPE_BYTE,
458 gls::DrawTestSpec::INDEXTYPE_SHORT,
459 gls::DrawTestSpec::INDEXTYPE_INT,
460 };
461 const UniformWeightArray<DE_LENGTH_OF_ARRAY(indexTypes)> indexTypeWeights;
462
463 gls::DrawTestSpec::Storage storages[] = {
464 gls::DrawTestSpec::STORAGE_USER,
465 gls::DrawTestSpec::STORAGE_BUFFER,
466 };
467 const UniformWeightArray<DE_LENGTH_OF_ARRAY(storages)> storageWeights;
468
469 gls::DrawTestSpec::InputType inputTypes[] = {
470 gls::DrawTestSpec::INPUTTYPE_FLOAT,
471 gls::DrawTestSpec::INPUTTYPE_FIXED,
472 gls::DrawTestSpec::INPUTTYPE_BYTE,
473 gls::DrawTestSpec::INPUTTYPE_SHORT,
474 gls::DrawTestSpec::INPUTTYPE_UNSIGNED_BYTE,
475 gls::DrawTestSpec::INPUTTYPE_UNSIGNED_SHORT,
476 gls::DrawTestSpec::INPUTTYPE_INT,
477 gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT,
478 gls::DrawTestSpec::INPUTTYPE_HALF,
479 gls::DrawTestSpec::INPUTTYPE_UNSIGNED_INT_2_10_10_10,
480 gls::DrawTestSpec::INPUTTYPE_INT_2_10_10_10,
481 };
482 const UniformWeightArray<DE_LENGTH_OF_ARRAY(inputTypes)> inputTypeWeights;
483
484 gls::DrawTestSpec::OutputType outputTypes[] = {
485 gls::DrawTestSpec::OUTPUTTYPE_FLOAT, gls::DrawTestSpec::OUTPUTTYPE_VEC2, gls::DrawTestSpec::OUTPUTTYPE_VEC3,
486 gls::DrawTestSpec::OUTPUTTYPE_VEC4, gls::DrawTestSpec::OUTPUTTYPE_INT, gls::DrawTestSpec::OUTPUTTYPE_UINT,
487 gls::DrawTestSpec::OUTPUTTYPE_IVEC2, gls::DrawTestSpec::OUTPUTTYPE_IVEC3, gls::DrawTestSpec::OUTPUTTYPE_IVEC4,
488 gls::DrawTestSpec::OUTPUTTYPE_UVEC2, gls::DrawTestSpec::OUTPUTTYPE_UVEC3, gls::DrawTestSpec::OUTPUTTYPE_UVEC4,
489 };
490 const UniformWeightArray<DE_LENGTH_OF_ARRAY(outputTypes)> outputTypeWeights;
491
492 gls::DrawTestSpec::Usage usages[] = {
493 gls::DrawTestSpec::USAGE_DYNAMIC_DRAW, gls::DrawTestSpec::USAGE_STATIC_DRAW,
494 gls::DrawTestSpec::USAGE_STREAM_DRAW, gls::DrawTestSpec::USAGE_STREAM_READ,
495 gls::DrawTestSpec::USAGE_STREAM_COPY, gls::DrawTestSpec::USAGE_STATIC_READ,
496 gls::DrawTestSpec::USAGE_STATIC_COPY, gls::DrawTestSpec::USAGE_DYNAMIC_READ,
497 gls::DrawTestSpec::USAGE_DYNAMIC_COPY,
498 };
499 const UniformWeightArray<DE_LENGTH_OF_ARRAY(usages)> usageWeights;
500
501 std::set<uint32_t> insertedHashes;
502 size_t insertedCount = 0;
503
504 for (int ndx = 0; ndx < numAttempts; ++ndx)
505 {
506 de::Random random(0xc551393 + ndx); // random does not depend on previous cases
507
508 int attributeCount = random.chooseWeighted<int, const int *, const float *>(
509 DE_ARRAY_BEGIN(attribCounts), DE_ARRAY_END(attribCounts), attribWeights);
510 gls::DrawTestSpec spec;
511
512 spec.apiType = glu::ApiType::es(3, 0);
513 spec.primitive = random.chooseWeighted<gls::DrawTestSpec::Primitive>(
514 DE_ARRAY_BEGIN(primitives), DE_ARRAY_END(primitives), primitiveWeights.weights);
515 spec.primitiveCount = random.chooseWeighted<int, const int *, const float *>(
516 DE_ARRAY_BEGIN(primitiveCounts), DE_ARRAY_END(primitiveCounts), primitiveCountWeights);
517 spec.drawMethod = random.chooseWeighted<gls::DrawTestSpec::DrawMethod>(
518 DE_ARRAY_BEGIN(drawMethods), DE_ARRAY_END(drawMethods), drawMethodWeights.weights);
519 spec.indexType = random.chooseWeighted<gls::DrawTestSpec::IndexType>(
520 DE_ARRAY_BEGIN(indexTypes), DE_ARRAY_END(indexTypes), indexTypeWeights.weights);
521 spec.indexPointerOffset = random.chooseWeighted<int, const int *, const float *>(
522 DE_ARRAY_BEGIN(indexOffsets), DE_ARRAY_END(indexOffsets), indexOffsetWeights);
523 spec.indexStorage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
524 DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
525 spec.first = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(firsts),
526 DE_ARRAY_END(firsts), firstWeights);
527 spec.indexMin = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(indexMins),
528 DE_ARRAY_END(indexMins), indexWeights);
529 spec.indexMax = random.chooseWeighted<int, const int *, const float *>(DE_ARRAY_BEGIN(indexMaxs),
530 DE_ARRAY_END(indexMaxs), indexWeights);
531 spec.instanceCount = random.chooseWeighted<int, const int *, const float *>(
532 DE_ARRAY_BEGIN(instanceCounts), DE_ARRAY_END(instanceCounts), instanceWeights);
533
534 // check spec is legal
535 if (!spec.valid())
536 continue;
537
538 for (int attrNdx = 0; attrNdx < attributeCount;)
539 {
540 bool valid;
541 gls::DrawTestSpec::AttributeSpec attribSpec;
542
543 attribSpec.inputType = random.chooseWeighted<gls::DrawTestSpec::InputType>(
544 DE_ARRAY_BEGIN(inputTypes), DE_ARRAY_END(inputTypes), inputTypeWeights.weights);
545 attribSpec.outputType = random.chooseWeighted<gls::DrawTestSpec::OutputType>(
546 DE_ARRAY_BEGIN(outputTypes), DE_ARRAY_END(outputTypes), outputTypeWeights.weights);
547 attribSpec.storage = random.chooseWeighted<gls::DrawTestSpec::Storage>(
548 DE_ARRAY_BEGIN(storages), DE_ARRAY_END(storages), storageWeights.weights);
549 attribSpec.usage = random.chooseWeighted<gls::DrawTestSpec::Usage>(
550 DE_ARRAY_BEGIN(usages), DE_ARRAY_END(usages), usageWeights.weights);
551 attribSpec.componentCount = random.getInt(1, 4);
552 attribSpec.offset = random.chooseWeighted<int, const int *, const float *>(
553 DE_ARRAY_BEGIN(offsets), DE_ARRAY_END(offsets), offsetWeights);
554 attribSpec.stride = random.chooseWeighted<int, const int *, const float *>(
555 DE_ARRAY_BEGIN(strides), DE_ARRAY_END(strides), strideWeights);
556 attribSpec.normalize = random.getBool();
557 attribSpec.instanceDivisor = random.chooseWeighted<int, const int *, const float *>(
558 DE_ARRAY_BEGIN(instanceDivisors), DE_ARRAY_END(instanceDivisors), instanceDivisorWeights);
559 attribSpec.useDefaultAttribute = random.getBool();
560
561 // check spec is legal
562 valid = attribSpec.valid(spec.apiType);
563
564 // we do not want interleaved elements. (Might result in some weird floating point values)
565 if (attribSpec.stride &&
566 attribSpec.componentCount * gls::DrawTestSpec::inputTypeSize(attribSpec.inputType) > attribSpec.stride)
567 valid = false;
568
569 // try again if not valid
570 if (valid)
571 {
572 spec.attribs.push_back(attribSpec);
573 ++attrNdx;
574 }
575 }
576
577 // Do not collapse all vertex positions to a single positions
578 if (spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
579 spec.attribs[0].instanceDivisor = 0;
580
581 // Is render result meaningful?
582 {
583 // Only one vertex
584 if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
585 spec.indexMin == spec.indexMax && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
586 continue;
587 if (spec.attribs[0].useDefaultAttribute && spec.primitive != gls::DrawTestSpec::PRIMITIVE_POINTS)
588 continue;
589
590 // Triangle only on one axis
591 if (spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLES ||
592 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_FAN ||
593 spec.primitive == gls::DrawTestSpec::PRIMITIVE_TRIANGLE_STRIP)
594 {
595 if (spec.attribs[0].componentCount == 1)
596 continue;
597 if (spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_FLOAT ||
598 spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_INT ||
599 spec.attribs[0].outputType == gls::DrawTestSpec::OUTPUTTYPE_UINT)
600 continue;
601 if (spec.drawMethod == gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED &&
602 (spec.indexMax - spec.indexMin) < 2)
603 continue;
604 }
605 }
606
607 // Add case
608 {
609 uint32_t hash = spec.hash();
610 for (int attrNdx = 0; attrNdx < attributeCount; ++attrNdx)
611 hash = (hash << 2) ^ (uint32_t)spec.attribs[attrNdx].hash();
612
613 if (insertedHashes.find(hash) == insertedHashes.end())
614 {
615 // Only unaligned cases
616 if (spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_OFFSET ||
617 spec.isCompatibilityTest() == gls::DrawTestSpec::COMPATIBILITY_UNALIGNED_STRIDE)
618 this->addChild(new gls::DrawTest(m_testCtx, m_context.getRenderContext(), spec,
619 de::toString(insertedCount).c_str(), spec.getDesc().c_str()));
620 insertedHashes.insert(hash);
621
622 ++insertedCount;
623 }
624 }
625 }
626 }
627
628 } // namespace
629
DrawTests(Context & context)630 DrawTests::DrawTests(Context &context) : TestCaseGroup(context, "draw", "Draw stress tests")
631 {
632 }
633
~DrawTests(void)634 DrawTests::~DrawTests(void)
635 {
636 }
637
init(void)638 void DrawTests::init(void)
639 {
640 tcu::TestCaseGroup *const unalignedGroup =
641 new tcu::TestCaseGroup(m_testCtx, "unaligned_data", "Test with unaligned data");
642 tcu::TestCaseGroup *const drawRangeGroup =
643 new tcu::TestCaseGroup(m_testCtx, "draw_range_elements", "Test drawRangeElements");
644
645 addChild(unalignedGroup);
646 addChild(drawRangeGroup);
647
648 // .unaligned_data
649 {
650 const gls::DrawTestSpec::DrawMethod basicMethods[] = {
651 // gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS,
652 gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS,
653 // gls::DrawTestSpec::DRAWMETHOD_DRAWARRAYS_INSTANCED,
654 gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_INSTANCED,
655 gls::DrawTestSpec::DRAWMETHOD_DRAWELEMENTS_RANGED,
656 };
657
658 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(basicMethods); ++ndx)
659 {
660 const std::string name = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
661 const std::string desc = gls::DrawTestSpec::drawMethodToString(basicMethods[ndx]);
662
663 unalignedGroup->addChild(new MethodGroup(m_context, name.c_str(), desc.c_str(), basicMethods[ndx]));
664 }
665
666 // Random
667
668 unalignedGroup->addChild(new RandomGroup(m_context, "random", "random draw commands."));
669 }
670
671 // .draw_range_elements
672 {
673 // use a larger range than the buffer size is
674 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_max_over_bounds",
675 "Range over buffer bounds", 0x00000000, 0x00210000));
676 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_max_over_bounds_near_signed_wrap",
677 "Range over buffer bounds", 0x00000000, 0x7FFFFFFF));
678 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_max_over_bounds_near_unsigned_wrap",
679 "Range over buffer bounds", 0x00000000, 0xFFFFFFFF));
680 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_max_over_bounds_near_max",
681 "Range over buffer bounds", 0x00000000, 0x00000000, false,
682 true));
683
684 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_min_max_over_bounds",
685 "Range over buffer bounds", 0x00200000, 0x00210000));
686 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_min_max_over_bounds_near_signed_wrap",
687 "Range over buffer bounds", 0x7FFFFFF0, 0x7FFFFFFF));
688 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_min_max_over_bounds_near_unsigned_wrap",
689 "Range over buffer bounds", 0xFFFFFFF0, 0xFFFFFFFF));
690 drawRangeGroup->addChild(new DrawInvalidRangeCase(m_context, "range_min_max_over_bounds_near_max",
691 "Range over buffer bounds", 0x00000000, 0x00000000, true,
692 true));
693 }
694 }
695
696 } // namespace Stress
697 } // namespace gles3
698 } // namespace deqp
699