xref: /aosp_15_r20/external/deqp/external/openglcts/modules/gl/gl4cShaderDrawParametersTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
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  gl4cShaderDrawParametersTests.cpp
21  * \brief Conformance tests for the GL_ARB_shader_draw_parameters functionality.
22  */ /*-------------------------------------------------------------------*/
23 
24 #include "gl4cShaderDrawParametersTests.hpp"
25 #include "gluContextInfo.hpp"
26 #include "gluDefs.hpp"
27 #include "gluDrawUtil.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "glwEnums.hpp"
30 #include "glwFunctions.hpp"
31 #include "tcuRenderTarget.hpp"
32 #include "tcuStringTemplate.hpp"
33 #include "tcuTestLog.hpp"
34 
35 using namespace glw;
36 using namespace glu;
37 
38 namespace gl4cts
39 {
40 
41 const char *sdp_compute_extensionCheck = "#version 450 core\n"
42                                          "\n"
43                                          "#extension GL_ARB_shader_draw_parameters : require\n"
44                                          "\n"
45                                          "#ifndef GL_ARB_shader_draw_parameters\n"
46                                          "  #error GL_ARB_shader_draw_parameters not defined\n"
47                                          "#else\n"
48                                          "  #if (GL_ARB_shader_draw_parameters != 1)\n"
49                                          "    #error GL_ARB_shader_draw_parameters wrong value\n"
50                                          "  #endif\n"
51                                          "#endif // GL_ARB_shader_draw_parameters\n"
52                                          "\n"
53                                          "layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
54                                          "\n"
55                                          "void main()\n"
56                                          "{\n"
57                                          "}\n";
58 
59 static const char *sdp_vertShader = "${VERSION}\n"
60                                     "\n"
61                                     "${DRAW_PARAMETERS_EXTENSION}\n"
62                                     "\n"
63                                     "in vec3 vertex;\n"
64                                     "out vec3 color;\n"
65                                     "\n"
66                                     "void main()\n"
67                                     "{\n"
68                                     "    float hOffset = float(${GL_BASE_VERTEX}) / 5.0;\n"
69                                     "    float vOffset = float(${GL_BASE_INSTANCE}) / 5.0;\n"
70                                     "    color = vec3(0.0);\n"
71                                     "    if (${GL_DRAW_ID} % 3 == 0) color.r = 1;\n"
72                                     "    else if (${GL_DRAW_ID} % 3 == 1) color.g = 1;\n"
73                                     "    else if (${GL_DRAW_ID} % 3 == 2) color.b = 1;\n"
74                                     "    gl_Position = vec4(vertex + vec3(hOffset, vOffset, 0), 1);\n"
75                                     "}\n";
76 
77 static const char *sdp_fragShader = "${VERSION}\n"
78                                     "\n"
79                                     "${DRAW_PARAMETERS_EXTENSION}\n"
80                                     "\n"
81                                     "in vec3 color;\n"
82                                     "out vec4 fragColor;\n"
83                                     "\n"
84                                     "void main()\n"
85                                     "{\n"
86                                     "    fragColor = vec4(color, 1.0);\n"
87                                     "}\n";
88 
89 /** Constructor.
90  *
91  *  @param context     Rendering context
92  */
ShaderDrawParametersExtensionTestCase(deqp::Context & context)93 ShaderDrawParametersExtensionTestCase::ShaderDrawParametersExtensionTestCase(deqp::Context &context)
94     : TestCase(context, "ShaderDrawParametersExtension",
95                "Verifies if GL_ARB_shader_draw_parameters extension is available for GLSL")
96 {
97     /* Left blank intentionally */
98 }
99 
100 /** Executes test iteration.
101  *
102  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
103  */
iterate()104 tcu::TestNode::IterateResult ShaderDrawParametersExtensionTestCase::iterate()
105 {
106     if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_draw_parameters"))
107     {
108         m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "Not Supported");
109         return STOP;
110     }
111 
112     const Functions &gl = m_context.getRenderContext().getFunctions();
113 
114     std::string shader = sdp_compute_extensionCheck;
115 
116     ProgramSources sources;
117     sources << ComputeSource(shader);
118     ShaderProgram program(gl, sources);
119 
120     if (!program.isOk())
121     {
122         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
123         m_testCtx.getLog() << tcu::TestLog::Message << "Checking shader preprocessor directives failed. Source:\n"
124                            << shader.c_str() << "InfoLog:\n"
125                            << program.getShaderInfo(SHADERTYPE_COMPUTE).infoLog << "\n"
126                            << tcu::TestLog::EndMessage;
127         return STOP;
128     }
129 
130     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
131     return STOP;
132 }
133 
134 /** Constructor.
135  *
136  *  @param context      Rendering context
137  *  @param name         Test case name
138  *  @param description  Test case description
139  */
ShaderDrawParametersTestBase(deqp::Context & context,const char * name,const char * description)140 ShaderDrawParametersTestBase::ShaderDrawParametersTestBase(deqp::Context &context, const char *name,
141                                                            const char *description)
142     : TestCase(context, name, description)
143     , m_vao(0)
144     , m_arrayBuffer(0)
145     , m_elementBuffer(0)
146     , m_drawIndirectBuffer(0)
147     , m_parameterBuffer(0)
148 {
149     /* Left blank intentionally */
150 }
151 
152 /** Stub init method */
init()153 void ShaderDrawParametersTestBase::init()
154 {
155     glu::ContextType contextType = m_context.getRenderContext().getType();
156     if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
157         !m_context.getContextInfo().isExtensionSupported("GL_ARB_shader_draw_parameters"))
158     {
159         TCU_THROW(NotSupportedError, "shader_draw_parameters functionality not supported");
160     }
161 
162     initChild();
163 
164     const Functions &gl = m_context.getRenderContext().getFunctions();
165 
166     const GLfloat vertices[] = {
167         -1.0f, -1.0f, 0.0f, -1.0f, -0.8f, 0.0f, -0.9f, -1.0f, 0.0f,
168         -0.9f, -0.8f, 0.0f, -0.8f, -1.0f, 0.0f, -0.8f, -0.8f, 0.0f,
169     };
170 
171     const GLushort elements[] = {0, 1, 2, 3, 4, 5};
172 
173     // Generate vertex array object
174     gl.genVertexArrays(1, &m_vao);
175     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays");
176 
177     gl.bindVertexArray(m_vao);
178     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray");
179 
180     // Setup vertex array buffer
181     gl.genBuffers(1, &m_arrayBuffer);
182     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
183 
184     gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuffer);
185     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
186 
187     gl.bufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
188     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
189 
190     // Setup element array buffer
191     gl.genBuffers(1, &m_elementBuffer);
192     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
193 
194     gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
195     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
196 
197     gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(GLushort), elements, GL_STATIC_DRAW);
198     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
199 }
200 
201 /** Stub deinit method */
deinit()202 void ShaderDrawParametersTestBase::deinit()
203 {
204     const Functions &gl = m_context.getRenderContext().getFunctions();
205 
206     if (m_vao)
207         gl.deleteVertexArrays(1, &m_vao);
208     if (m_arrayBuffer)
209         gl.deleteBuffers(1, &m_arrayBuffer);
210     if (m_elementBuffer)
211         gl.deleteBuffers(1, &m_elementBuffer);
212 
213     deinitChild();
214 }
215 
216 /** Executes test iteration.
217  *
218  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
219  */
iterate()220 tcu::TestNode::IterateResult ShaderDrawParametersTestBase::iterate()
221 {
222     if (draw() && verify())
223         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
224     else
225         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
226 
227     return STOP;
228 }
229 
230 /** Draws scene using specific case parameters.
231  *
232  *  @return Returns true if no error occurred, false otherwise.
233  */
draw()234 bool ShaderDrawParametersTestBase::draw()
235 {
236     const Functions &gl          = m_context.getRenderContext().getFunctions();
237     glu::ContextType contextType = m_context.getRenderContext().getType();
238     std::map<std::string, std::string> specializationMap;
239 
240     if (glu::contextSupports(contextType, glu::ApiType::core(4, 6)))
241     {
242         specializationMap["VERSION"]                   = "#version 460";
243         specializationMap["DRAW_PARAMETERS_EXTENSION"] = "";
244         specializationMap["GL_BASE_VERTEX"]            = "gl_BaseVertex";
245         specializationMap["GL_BASE_INSTANCE"]          = "gl_BaseInstance";
246         specializationMap["GL_DRAW_ID"]                = "gl_DrawID";
247     }
248     else
249     {
250         specializationMap["VERSION"]                   = "#version 450";
251         specializationMap["DRAW_PARAMETERS_EXTENSION"] = "#extension GL_ARB_shader_draw_parameters : enable";
252         specializationMap["GL_BASE_VERTEX"]            = "gl_BaseVertexARB";
253         specializationMap["GL_BASE_INSTANCE"]          = "gl_BaseInstanceARB";
254         specializationMap["GL_DRAW_ID"]                = "gl_DrawIDARB";
255     }
256 
257     std::string vs = tcu::StringTemplate(sdp_vertShader).specialize(specializationMap);
258     std::string fs = tcu::StringTemplate(sdp_fragShader).specialize(specializationMap);
259 
260     ProgramSources sources = makeVtxFragSources(vs, fs);
261     ShaderProgram program(gl, sources);
262 
263     if (!program.isOk())
264     {
265         m_testCtx.getLog() << tcu::TestLog::Message << "Shader build failed.\n"
266                            << "Vertex: " << program.getShaderInfo(SHADERTYPE_VERTEX).infoLog << "\n"
267                            << "Fragment: " << program.getShaderInfo(SHADERTYPE_FRAGMENT).infoLog << "\n"
268                            << "Program: " << program.getProgramInfo().infoLog << tcu::TestLog::EndMessage;
269         return false;
270     }
271 
272     gl.useProgram(program.getProgram());
273     GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram");
274 
275     gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
276     gl.clear(GL_COLOR_BUFFER_BIT);
277 
278     gl.enable(GL_BLEND);
279     gl.blendFunc(GL_ONE, GL_ONE);
280 
281     gl.enableVertexAttribArray(0);
282     GLU_EXPECT_NO_ERROR(gl.getError(), "glEnableVertexAttribArray");
283     gl.vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
284     GLU_EXPECT_NO_ERROR(gl.getError(), "glVertexAttribPointer");
285 
286     drawCommand();
287 
288     gl.disableVertexAttribArray(0);
289     GLU_EXPECT_NO_ERROR(gl.getError(), "glDisableVertexAttribArray");
290 
291     gl.disable(GL_BLEND);
292 
293     return true;
294 }
295 
296 /** Verifies if drawing result is as expected.
297  *
298  *  @return Returns true if verifying process has been successfully completed, false otherwise.
299  */
verify()300 bool ShaderDrawParametersTestBase::verify()
301 {
302     const Functions &gl         = m_context.getRenderContext().getFunctions();
303     const tcu::RenderTarget &rt = m_context.getRenderContext().getRenderTarget();
304 
305     const int width  = rt.getWidth();
306     const int height = rt.getHeight();
307 
308     std::vector<GLubyte> pixels;
309     pixels.resize(width * height * 3);
310 
311     gl.pixelStorei(GL_PACK_ALIGNMENT, 1);
312     gl.readPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
313     gl.pixelStorei(GL_PACK_ALIGNMENT, 4);
314 
315     std::vector<ResultPoint>::iterator it;
316     for (it = m_resultPoints.begin(); it != m_resultPoints.end(); ++it)
317     {
318         int x     = (int)(((it->x + 1.0f) / 2) * width);
319         int y     = (int)(((it->y + 1.0f) / 2) * height);
320         int red   = (int)(it->red * 255);
321         int green = (int)(it->green * 255);
322         int blue  = (int)(it->blue * 255);
323 
324         if (pixels[(x + y * width) * 3 + 0] != red || pixels[(x + y * width) * 3 + 1] != green ||
325             pixels[(x + y * width) * 3 + 2] != blue)
326         {
327             m_testCtx.getLog() << tcu::TestLog::Message << "Verification failed (" << x << "/" << y << ")\n"
328                                << "Expected point: (" << red << "," << green << "," << blue << ")\n"
329                                << "Result point: (" << (int)pixels[(x + y * width) * 3 + 0] << ","
330                                << (int)pixels[(x + y * width) * 3 + 1] << "," << (int)pixels[(x + y * width) * 3 + 2]
331                                << ")\n"
332                                << tcu::TestLog::EndMessage;
333             return false;
334         }
335     }
336 
337     return true;
338 }
339 
340 /** Child case initialization method.
341  */
initChild()342 void ShaderDrawParametersTestBase::initChild()
343 {
344     /* Do nothing */
345 }
346 
347 /** Child case deinitialization method.
348  */
deinitChild()349 void ShaderDrawParametersTestBase::deinitChild()
350 {
351     /* Do nothing */
352 }
353 
354 /** Child case drawing command invocation.
355  */
drawCommand()356 void ShaderDrawParametersTestBase::drawCommand()
357 {
358     /* Do nothing */
359 }
360 
361 /* ShaderDrawArraysParametersTestCase */
362 
initChild()363 void ShaderDrawArraysParametersTestCase::initChild()
364 {
365     // Set expected result vector [x, y, red, green, blue]
366     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
367     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
368     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
369     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
370 }
371 
deinitChild()372 void ShaderDrawArraysParametersTestCase::deinitChild()
373 {
374     /* Do nothing */
375 }
376 
drawCommand()377 void ShaderDrawArraysParametersTestCase::drawCommand()
378 {
379     const Functions &gl = m_context.getRenderContext().getFunctions();
380 
381     gl.drawArrays(GL_TRIANGLE_STRIP, 1, 4);
382     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays");
383 }
384 
385 /* ---------------------------------- */
386 
387 /* ShaderDrawElementsParametersTestCase */
388 
initChild()389 void ShaderDrawElementsParametersTestCase::initChild()
390 {
391     // Set expected result vector [x, y, red, green, blue]
392     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
393     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
394     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
395     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
396 }
397 
deinitChild()398 void ShaderDrawElementsParametersTestCase::deinitChild()
399 {
400     /* Do nothing */
401 }
402 
drawCommand()403 void ShaderDrawElementsParametersTestCase::drawCommand()
404 {
405     const Functions &gl = m_context.getRenderContext().getFunctions();
406 
407     gl.drawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (GLvoid *)(2 * sizeof(GLushort)));
408     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElements");
409 }
410 
411 /* ---------------------------------- */
412 
413 /* ShaderDrawArraysIndirectParametersTestCase */
414 
initChild()415 void ShaderDrawArraysIndirectParametersTestCase::initChild()
416 {
417     const Functions &gl = m_context.getRenderContext().getFunctions();
418 
419     // Set expected result vector [x, y, red, green, blue]
420     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
421     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
422     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
423     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
424 
425     const SDPDrawArraysIndirectCommand indirect[] = {
426         {5, 1, 0, 0},
427     };
428 
429     // Setup indirect command buffer
430     gl.genBuffers(1, &m_drawIndirectBuffer);
431     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
432 
433     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
434     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
435 
436     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 1 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
437     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
438 }
439 
deinitChild()440 void ShaderDrawArraysIndirectParametersTestCase::deinitChild()
441 {
442     const Functions &gl = m_context.getRenderContext().getFunctions();
443 
444     if (m_drawIndirectBuffer)
445         gl.deleteBuffers(1, &m_drawIndirectBuffer);
446 }
447 
drawCommand()448 void ShaderDrawArraysIndirectParametersTestCase::drawCommand()
449 {
450     const Functions &gl = m_context.getRenderContext().getFunctions();
451 
452     gl.drawArraysIndirect(GL_TRIANGLE_STRIP, (GLvoid *)0);
453     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArraysIndirect");
454 }
455 
456 /* ---------------------------------- */
457 
458 /* ShaderDrawElementsIndirectParametersTestCase */
459 
initChild()460 void ShaderDrawElementsIndirectParametersTestCase::initChild()
461 {
462     const Functions &gl = m_context.getRenderContext().getFunctions();
463 
464     // Set expected result vector [x, y, red, green, blue]
465     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
466     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
467     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
468     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
469 
470     const SDPDrawElementsIndirectCommand indirect[] = {
471         {5, 1, 1, 0, 0},
472     };
473 
474     // Setup indirect command buffer
475     gl.genBuffers(1, &m_drawIndirectBuffer);
476     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
477 
478     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
479     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
480 
481     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 1 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
482     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
483 }
484 
deinitChild()485 void ShaderDrawElementsIndirectParametersTestCase::deinitChild()
486 {
487     const Functions &gl = m_context.getRenderContext().getFunctions();
488 
489     if (m_drawIndirectBuffer)
490         gl.deleteBuffers(1, &m_drawIndirectBuffer);
491 }
492 
drawCommand()493 void ShaderDrawElementsIndirectParametersTestCase::drawCommand()
494 {
495     const Functions &gl = m_context.getRenderContext().getFunctions();
496 
497     gl.drawElementsIndirect(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, (GLvoid *)0);
498     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElementsIndirect");
499 }
500 
501 /* ---------------------------------- */
502 
503 /* ShaderDrawArraysInstancedParametersTestCase */
504 
initChild()505 void ShaderDrawArraysInstancedParametersTestCase::initChild()
506 {
507     // Set expected result vector [x, y, red, green, blue]
508     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
509     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
510     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
511     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
512 }
513 
deinitChild()514 void ShaderDrawArraysInstancedParametersTestCase::deinitChild()
515 {
516     /* Do nothing */
517 }
518 
drawCommand()519 void ShaderDrawArraysInstancedParametersTestCase::drawCommand()
520 {
521     const Functions &gl = m_context.getRenderContext().getFunctions();
522 
523     gl.drawArraysInstanced(GL_TRIANGLE_STRIP, 2, 4, 2);
524     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArraysInstanced");
525 }
526 
527 /* ---------------------------------- */
528 
529 /* ShaderDrawElementsInstancedParametersTestCase */
530 
initChild()531 void ShaderDrawElementsInstancedParametersTestCase::initChild()
532 {
533     // Set expected result vector [x, y, red, green, blue]
534     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
535     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
536     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
537     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
538 }
539 
deinitChild()540 void ShaderDrawElementsInstancedParametersTestCase::deinitChild()
541 {
542     /* Do nothing */
543 }
544 
drawCommand()545 void ShaderDrawElementsInstancedParametersTestCase::drawCommand()
546 {
547     const Functions &gl = m_context.getRenderContext().getFunctions();
548 
549     gl.drawElementsInstanced(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_SHORT, (GLvoid *)0, 3);
550     GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawElementsInstanced");
551 }
552 
553 /* ---------------------------------- */
554 
555 /* ShaderMultiDrawArraysParametersTestCase */
556 
initChild()557 void ShaderMultiDrawArraysParametersTestCase::initChild()
558 {
559     // Set expected result vector [x, y, red, green, blue]
560     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
561     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
562     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 1.0f, 0.0f));
563     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
564 }
565 
deinitChild()566 void ShaderMultiDrawArraysParametersTestCase::deinitChild()
567 {
568     /* Do nothing */
569 }
570 
drawCommand()571 void ShaderMultiDrawArraysParametersTestCase::drawCommand()
572 {
573     const Functions &gl = m_context.getRenderContext().getFunctions();
574 
575     const GLint dFirst[]   = {0, 1};
576     const GLsizei dCount[] = {4, 4};
577 
578     gl.multiDrawArrays(GL_TRIANGLE_STRIP, dFirst, dCount, 2);
579     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArrays");
580 }
581 
582 /* ---------------------------------- */
583 
584 /* ShaderMultiDrawElementsParametersTestCase */
585 
initChild()586 void ShaderMultiDrawElementsParametersTestCase::initChild()
587 {
588     // Set expected result vector [x, y, red, green, blue]
589     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
590     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
591     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 1.0f, 0.0f));
592     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
593 }
594 
deinitChild()595 void ShaderMultiDrawElementsParametersTestCase::deinitChild()
596 {
597     /* Do nothing */
598 }
599 
drawCommand()600 void ShaderMultiDrawElementsParametersTestCase::drawCommand()
601 {
602     const Functions &gl = m_context.getRenderContext().getFunctions();
603 
604     const GLsizei dCount[]   = {5, 4};
605     const GLvoid *dIndices[] = {(GLvoid *)(1 * sizeof(GLushort)), (GLvoid *)(1 * sizeof(GLushort))};
606 
607     gl.multiDrawElements(GL_TRIANGLE_STRIP, dCount, GL_UNSIGNED_SHORT, dIndices, 2);
608     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElements");
609 }
610 
611 /* ---------------------------------- */
612 
613 /* ShaderMultiDrawArraysIndirectParametersTestCase */
614 
initChild()615 void ShaderMultiDrawArraysIndirectParametersTestCase::initChild()
616 {
617     const Functions &gl = m_context.getRenderContext().getFunctions();
618 
619     // Set expected result vector [x, y, red, green, blue]
620     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 1.0f, 0.0f));
621     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 1.0f, 0.0f));
622     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
623     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
624     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 1.0f));
625     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
626     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
627     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
628 
629     const SDPDrawArraysIndirectCommand indirect[] = {
630         {5, 1, 1, 0},
631         {4, 1, 0, 0},
632         {3, 1, 0, 1},
633     };
634 
635     // Setup indirect command buffer
636     gl.genBuffers(1, &m_drawIndirectBuffer);
637     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
638 
639     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
640     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
641 
642     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
643     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
644 }
645 
deinitChild()646 void ShaderMultiDrawArraysIndirectParametersTestCase::deinitChild()
647 {
648     const Functions &gl = m_context.getRenderContext().getFunctions();
649 
650     if (m_drawIndirectBuffer)
651         gl.deleteBuffers(1, &m_drawIndirectBuffer);
652 }
653 
drawCommand()654 void ShaderMultiDrawArraysIndirectParametersTestCase::drawCommand()
655 {
656     const Functions &gl = m_context.getRenderContext().getFunctions();
657 
658     gl.multiDrawArraysIndirect(GL_TRIANGLE_STRIP, (GLvoid *)0, 3, sizeof(SDPDrawArraysIndirectCommand));
659     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArraysIndirect");
660 }
661 
662 /* ---------------------------------- */
663 
664 /* ShaderMultiDrawElementsIndirectParametersTestCase */
665 
initChild()666 void ShaderMultiDrawElementsIndirectParametersTestCase::initChild()
667 {
668     const Functions &gl = m_context.getRenderContext().getFunctions();
669 
670     // Set expected result vector [x, y, red, green, blue]
671     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
672     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
673     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
674     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
675     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
676     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
677     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
678     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
679     m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
680     m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 1.0f));
681     m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
682     m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
683 
684     const SDPDrawElementsIndirectCommand indirect[] = {
685         {4, 1, 0, 0, 0},
686         {3, 1, 3, 0, 1},
687         {3, 1, 0, 1, 0},
688     };
689 
690     // Setup indirect command buffer
691     gl.genBuffers(1, &m_drawIndirectBuffer);
692     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
693 
694     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
695     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
696 
697     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
698     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
699 }
700 
deinitChild()701 void ShaderMultiDrawElementsIndirectParametersTestCase::deinitChild()
702 {
703     const Functions &gl = m_context.getRenderContext().getFunctions();
704 
705     if (m_drawIndirectBuffer)
706         gl.deleteBuffers(1, &m_drawIndirectBuffer);
707 }
708 
drawCommand()709 void ShaderMultiDrawElementsIndirectParametersTestCase::drawCommand()
710 {
711     const Functions &gl = m_context.getRenderContext().getFunctions();
712 
713     gl.multiDrawElementsIndirect(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, (GLvoid *)0, 3,
714                                  sizeof(SDPDrawElementsIndirectCommand));
715     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElementsIndirect");
716 }
717 
718 /* ---------------------------------- */
719 
720 /* ShaderMultiDrawArraysIndirectCountParametersTestCase */
721 
initChild()722 void ShaderMultiDrawArraysIndirectCountParametersTestCase::initChild()
723 {
724     glu::ContextType contextType = m_context.getRenderContext().getType();
725     if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
726         !m_context.getContextInfo().isExtensionSupported("GL_ARB_indirect_parameters"))
727     {
728         TCU_THROW(NotSupportedError, "indirect_parameters functionality not supported");
729     }
730 
731     const Functions &gl = m_context.getRenderContext().getFunctions();
732 
733     // Set expected result vector [x, y, red, green, blue]
734     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
735     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
736     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
737     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 1.0f, 0.0f, 0.0f));
738     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.05f, 0.0f, 1.0f, 0.0f));
739     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
740     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.05f, 0.0f, 1.0f, 0.0f));
741     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.8f + 0.15f, 0.0f, 1.0f, 0.0f));
742     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.6f + 0.05f, 0.0f, 0.0f, 0.0f));
743     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -0.6f + 0.15f, 0.0f, 0.0f, 0.0f));
744     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.6f + 0.05f, 0.0f, 0.0f, 1.0f));
745     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -0.6f + 0.15f, 0.0f, 0.0f, 1.0f));
746 
747     const SDPDrawArraysIndirectCommand indirect[] = {
748         {5, 1, 1, 0},
749         {6, 1, 0, 1},
750         {4, 1, 2, 2},
751     };
752 
753     const GLushort parameters[] = {1, 1, 1};
754 
755     // Setup indirect command buffer
756     gl.genBuffers(1, &m_drawIndirectBuffer);
757     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
758 
759     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
760     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
761 
762     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 4 * sizeof(SDPDrawArraysIndirectCommand), indirect, GL_STATIC_DRAW);
763     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
764 
765     // Setup indirect command buffer
766     gl.genBuffers(1, &m_parameterBuffer);
767     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
768 
769     gl.bindBuffer(GL_PARAMETER_BUFFER_ARB, m_parameterBuffer);
770     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
771 
772     gl.bufferData(GL_PARAMETER_BUFFER_ARB, 3 * sizeof(GLushort), parameters, GL_STATIC_DRAW);
773     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
774 }
775 
deinitChild()776 void ShaderMultiDrawArraysIndirectCountParametersTestCase::deinitChild()
777 {
778     const Functions &gl = m_context.getRenderContext().getFunctions();
779 
780     if (m_drawIndirectBuffer)
781         gl.deleteBuffers(1, &m_drawIndirectBuffer);
782     if (m_parameterBuffer)
783         gl.deleteBuffers(1, &m_parameterBuffer);
784 }
785 
drawCommand()786 void ShaderMultiDrawArraysIndirectCountParametersTestCase::drawCommand()
787 {
788     const Functions &gl = m_context.getRenderContext().getFunctions();
789 
790     gl.multiDrawArraysIndirectCount(GL_TRIANGLE_STRIP, 0, 0, 3, sizeof(SDPDrawArraysIndirectCommand));
791     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawArraysIndirect");
792 }
793 
794 /* ---------------------------------- */
795 
796 /* ShaderMultiDrawElementsIndirectCountParametersTestCase */
797 
initChild()798 void ShaderMultiDrawElementsIndirectCountParametersTestCase::initChild()
799 {
800     glu::ContextType contextType = m_context.getRenderContext().getType();
801     if (!glu::contextSupports(contextType, glu::ApiType::core(4, 6)) &&
802         !m_context.getContextInfo().isExtensionSupported("GL_ARB_indirect_parameters"))
803     {
804         TCU_THROW(NotSupportedError, "indirect_parameters functionality not supported");
805     }
806 
807     const Functions &gl = m_context.getRenderContext().getFunctions();
808 
809     // Set expected result vector [x, y, red, green, blue]
810     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.05f, 1.0f, 0.0f, 0.0f));
811     m_resultPoints.push_back(ResultPoint(-1.0f + 0.05f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
812     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.05f, 0.0f, 0.0f, 0.0f));
813     m_resultPoints.push_back(ResultPoint(-1.0f + 0.15f, -1.0f + 0.15f, 0.0f, 0.0f, 0.0f));
814     m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -0.8f + 0.05f, 0.0f, 0.0f, 0.0f));
815     m_resultPoints.push_back(ResultPoint(-0.8f + 0.05f, -0.8f + 0.15f, 0.0f, 1.0f, 1.0f));
816     m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -0.8f + 0.05f, 0.0f, 0.0f, 1.0f));
817     m_resultPoints.push_back(ResultPoint(-0.8f + 0.15f, -0.8f + 0.15f, 0.0f, 0.0f, 0.0f));
818 
819     const SDPDrawElementsIndirectCommand indirect[] = {
820         {3, 1, 0, 0, 0},
821         {3, 1, 0, 1, 1},
822         {4, 1, 0, 1, 1},
823     };
824 
825     const GLushort parameters[] = {1, 1, 1};
826 
827     // Setup indirect command buffer
828     gl.genBuffers(1, &m_drawIndirectBuffer);
829     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
830 
831     gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_drawIndirectBuffer);
832     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
833 
834     gl.bufferData(GL_DRAW_INDIRECT_BUFFER, 3 * sizeof(SDPDrawElementsIndirectCommand), indirect, GL_STATIC_DRAW);
835     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
836 
837     // Setup indirect command buffer
838     gl.genBuffers(1, &m_parameterBuffer);
839     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers");
840 
841     gl.bindBuffer(GL_PARAMETER_BUFFER_ARB, m_parameterBuffer);
842     GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer");
843 
844     gl.bufferData(GL_PARAMETER_BUFFER_ARB, 3 * sizeof(GLushort), parameters, GL_STATIC_DRAW);
845     GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData");
846 }
847 
deinitChild()848 void ShaderMultiDrawElementsIndirectCountParametersTestCase::deinitChild()
849 {
850     const Functions &gl = m_context.getRenderContext().getFunctions();
851 
852     if (m_drawIndirectBuffer)
853         gl.deleteBuffers(1, &m_drawIndirectBuffer);
854     if (m_parameterBuffer)
855         gl.deleteBuffers(1, &m_parameterBuffer);
856 }
857 
drawCommand()858 void ShaderMultiDrawElementsIndirectCountParametersTestCase::drawCommand()
859 {
860     const Functions &gl = m_context.getRenderContext().getFunctions();
861 
862     gl.multiDrawElementsIndirectCount(GL_TRIANGLE_STRIP, GL_UNSIGNED_SHORT, 0, 0, 3,
863                                       sizeof(SDPDrawElementsIndirectCommand));
864     GLU_EXPECT_NO_ERROR(gl.getError(), "glMultiDrawElementsIndirect");
865 }
866 
867 /* ---------------------------------- */
868 
869 /** Constructor.
870  *
871  *  @param context Rendering context.
872  */
ShaderDrawParametersTests(deqp::Context & context)873 ShaderDrawParametersTests::ShaderDrawParametersTests(deqp::Context &context)
874     : TestCaseGroup(context, "shader_draw_parameters_tests",
875                     "Verify conformance of GL_ARB_shader_draw_parameters implementation")
876 {
877 }
878 
879 /** Initializes the test group contents. */
init()880 void ShaderDrawParametersTests::init()
881 {
882     addChild(new ShaderDrawParametersExtensionTestCase(m_context));
883     addChild(new ShaderDrawArraysParametersTestCase(m_context));
884     addChild(new ShaderDrawElementsParametersTestCase(m_context));
885     addChild(new ShaderDrawArraysIndirectParametersTestCase(m_context));
886     addChild(new ShaderDrawElementsIndirectParametersTestCase(m_context));
887     addChild(new ShaderDrawArraysInstancedParametersTestCase(m_context));
888     addChild(new ShaderDrawElementsInstancedParametersTestCase(m_context));
889     addChild(new ShaderMultiDrawArraysParametersTestCase(m_context));
890     addChild(new ShaderMultiDrawElementsParametersTestCase(m_context));
891     addChild(new ShaderMultiDrawArraysIndirectParametersTestCase(m_context));
892     addChild(new ShaderMultiDrawElementsIndirectParametersTestCase(m_context));
893     addChild(new ShaderMultiDrawArraysIndirectCountParametersTestCase(m_context));
894     addChild(new ShaderMultiDrawElementsIndirectCountParametersTestCase(m_context));
895 }
896 
897 } // namespace gl4cts
898