1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
5 * Copyright (c) 2015-2016 The Khronos Group Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 */ /*-------------------------------------------------------------------*/
26 * \file gl3cCullDistanceTests.cpp
27 * \brief Cull Distance Test Suite Implementation
28 */ /*-------------------------------------------------------------------*/
30 #include "gl3cCullDistanceTests.hpp"
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuRenderTarget.hpp"
37 #include "tcuTestLog.hpp"
44 #ifndef GL_MAX_CULL_DISTANCES
45 #define GL_MAX_CULL_DISTANCES (0x82F9)
47 #ifndef GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES
48 #define GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES (0x82FA)
53 /** @brief Build OpenGL program
55 * @param [in] gl OpenGL function bindings
56 * @param [in] testCtx Context
57 * @param [in] cs_body Compute shader source code
58 * @param [in] fs_body Fragment shader source code
59 * @param [in] gs_body Geometric shader source code
60 * @param [in] tc_body Tessellation control shader source code
61 * @param [in] te_body Tessellation evaluation shader source code
62 * @param [in] vs_body Vertex shader source code
63 * @param [in] n_tf_varyings Number of transform feedback varyings
64 * @param [in] tf_varyings Transform feedback varyings names
66 * @param [out] out_program If succeeded output program GL handle, 0 otherwise.
68 void CullDistance::Utilities::buildProgram(const glw::Functions& gl, tcu::TestContext& testCtx,
69 const glw::GLchar* cs_body, const glw::GLchar* fs_body,
70 const glw::GLchar* gs_body, const glw::GLchar* tc_body,
71 const glw::GLchar* te_body, const glw::GLchar* vs_body,
72 const glw::GLuint& n_tf_varyings, const glw::GLchar** tf_varyings,
73 glw::GLuint* out_program)
75 glw::GLuint po_id = 0;
77 struct _shaders_configuration
80 const glw::GLchar* body;
82 } shaders_configuration[] = { { GL_COMPUTE_SHADER, cs_body, 0 }, { GL_FRAGMENT_SHADER, fs_body, 0 },
83 { GL_GEOMETRY_SHADER, gs_body, 0 }, { GL_TESS_CONTROL_SHADER, tc_body, 0 },
84 { GL_TESS_EVALUATION_SHADER, te_body, 0 }, { GL_VERTEX_SHADER, vs_body, 0 } };
86 const glw::GLuint n_shaders_configuration = sizeof(shaders_configuration) / sizeof(shaders_configuration[0]);
88 /* Guard allocated OpenGL resources */
91 /* Create needed programs */
92 po_id = gl.createProgram();
93 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram() call failed.");
95 for (glw::GLuint n_shader_index = 0; n_shader_index < n_shaders_configuration; n_shader_index++)
97 if (shaders_configuration[n_shader_index].body != DE_NULL)
99 /* Generate shader object */
100 shaders_configuration[n_shader_index].id = gl.createShader(shaders_configuration[n_shader_index].type);
101 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader() call failed");
103 glw::GLint compile_status = GL_FALSE;
104 const glw::GLuint so_id = shaders_configuration[n_shader_index].id;
106 /* Assign shader source code */
107 gl.shaderSource(shaders_configuration[n_shader_index].id, 1, /* count */
108 &shaders_configuration[n_shader_index].body, DE_NULL); /* length */
109 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource() call failed");
111 gl.compileShader(so_id);
112 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader() call failed.");
114 gl.getShaderiv(so_id, GL_COMPILE_STATUS, &compile_status);
115 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
117 if (compile_status == GL_FALSE)
119 std::vector<glw::GLchar> log_array(1);
120 glw::GLint log_length = 0;
121 std::string log_string("Failed to retrieve log");
123 /* Retrive compilation log length */
124 gl.getShaderiv(so_id, GL_INFO_LOG_LENGTH, &log_length);
125 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
127 log_array.resize(log_length + 1, 0);
129 gl.getShaderInfoLog(so_id, log_length, DE_NULL, &log_array[0]);
130 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog() call failed.");
132 log_string = std::string(&log_array[0]);
134 testCtx.getLog() << tcu::TestLog::Message << "Shader compilation has failed.\n"
135 << "Shader type: " << shaders_configuration[n_shader_index].type << "\n"
136 << "Shader compilation error log:\n"
137 << log_string << "\n"
138 << "Shader source code:\n"
139 << shaders_configuration[n_shader_index].body << "\n"
140 << tcu::TestLog::EndMessage;
142 TCU_FAIL("Shader compilation has failed.");
145 /* Also attach the shader to the corresponding program object */
146 gl.attachShader(po_id, so_id);
148 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader() call failed");
149 } /* if (shaders_configuration[n_shader_index].body != DE_NULL) */
150 } /* for (all shader object IDs) */
152 /* Set transform feedback if requested */
153 if (n_tf_varyings > 0)
155 gl.transformFeedbackVaryings(po_id, n_tf_varyings, tf_varyings, GL_INTERLEAVED_ATTRIBS);
156 GLU_EXPECT_NO_ERROR(gl.getError(), "glTransformFeedbackVaryings() call failed");
159 /* Try to link the program objects */
162 glw::GLint link_status = GL_FALSE;
164 gl.linkProgram(po_id);
165 GLU_EXPECT_NO_ERROR(gl.getError(), "glLinkProgram() call failed");
167 gl.getProgramiv(po_id, GL_LINK_STATUS, &link_status);
168 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv() call failed");
170 if (link_status == GL_FALSE)
172 std::vector<glw::GLchar> log_array(1);
173 glw::GLsizei log_length = 0;
174 std::string log_string;
176 /* Retreive compilation log length */
177 gl.getProgramiv(po_id, GL_INFO_LOG_LENGTH, &log_length);
178 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv() call failed.");
180 log_array.resize(log_length + 1, 0);
182 /* Retreive compilation log */
183 gl.getProgramInfoLog(po_id, log_length, DE_NULL, &log_array[0]);
184 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog() call failed.");
186 log_string = std::string(&log_array[0]);
188 /* Log linking error message */
189 testCtx.getLog() << tcu::TestLog::Message << "Program linking has failed.\n"
190 << "Linking error log:\n"
191 << log_string << "\n"
192 << tcu::TestLog::EndMessage;
194 /* Log shader source code of shaders involved */
195 for (glw::GLuint n_shader_index = 0; n_shader_index < n_shaders_configuration; n_shader_index++)
197 if (shaders_configuration[n_shader_index].body != DE_NULL)
199 testCtx.getLog() << tcu::TestLog::Message << "Shader source code of type "
200 << shaders_configuration[n_shader_index].type << " follows:\n"
201 << shaders_configuration[n_shader_index].body << "\n"
202 << tcu::TestLog::EndMessage;
206 TCU_FAIL("Program linking failed");
208 } /* if (po_id != 0) */
210 /* Delete all shaders we've created */
211 for (glw::GLuint n_shader_index = 0; n_shader_index < n_shaders_configuration; n_shader_index++)
213 const glw::GLuint so_id = shaders_configuration[n_shader_index].id;
217 gl.deleteShader(so_id);
219 shaders_configuration[n_shader_index].id = 0;
221 GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteShader() call failed.");
225 /* Store the result progrtam IDs */
226 *out_program = po_id;
230 /* Delete all shaders we've created */
231 for (glw::GLuint n_shader_index = 0; n_shader_index < n_shaders_configuration; n_shader_index++)
233 const glw::GLuint so_id = shaders_configuration[n_shader_index].id;
237 gl.deleteShader(so_id);
239 shaders_configuration[n_shader_index].id = 0;
243 /* Delete the program object */
246 gl.deleteProgram(po_id);
256 /** @brief Replace all occurences of a substring in a string by a substring
258 * @param [in,out] str string to be edited
259 * @param [in] from substring to be replaced
260 * @param [out] to new substring
262 void CullDistance::Utilities::replaceAll(std::string& str, const std::string& from, const std::string& to)
264 for (size_t start_pos = str.find(from, 0); start_pos != std::string::npos; start_pos = str.find(from, start_pos))
266 str.replace(start_pos, from.length(), to);
268 start_pos += to.length();
274 /** @brief Convert integer to string representation
276 * @param [in] integer input integer to be converted
278 * @return String representation of integer
280 std::string CullDistance::Utilities::intToString(glw::GLint integer)
282 std::stringstream temp_sstream;
284 temp_sstream << integer;
286 return temp_sstream.str();
291 * @param context Rendering context handle.
293 CullDistance::APICoverageTest::APICoverageTest(deqp::Context& context)
294 : TestCase(context, "coverage", "Cull Distance API Coverage Test")
299 , m_fbo_draw_to_id(0)
309 /* Left blank on purpose */
312 /** @brief Cull Distance API Coverage Test deinitialization */
313 void CullDistance::APICoverageTest::deinit()
315 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
319 gl.deleteBuffers(1, &m_bo_id);
326 gl.deleteShader(m_cs_id);
333 gl.deleteTextures(1, &m_cs_to_id);
338 if (m_fbo_draw_id != 0)
340 gl.deleteFramebuffers(1, &m_fbo_draw_id);
345 if (m_fbo_draw_to_id != 0)
347 gl.deleteTextures(1, &m_fbo_draw_to_id);
349 m_fbo_draw_to_id = 0;
352 if (m_fbo_read_id != 0)
354 gl.deleteFramebuffers(1, &m_fbo_read_id);
361 gl.deleteShader(m_fs_id);
368 gl.deleteShader(m_gs_id);
375 gl.deleteProgram(m_po_id);
382 gl.deleteShader(m_tc_id);
389 gl.deleteShader(m_te_id);
396 gl.deleteVertexArrays(1, &m_vao_id);
403 gl.deleteShader(m_vs_id);
408 /* Restore default pack alignment value */
409 gl.pixelStorei(GL_PACK_ALIGNMENT, 4);
412 /** Executes test iteration.
414 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
416 tcu::TestNode::IterateResult CullDistance::APICoverageTest::iterate()
418 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
420 /* This test should only be executed if ARB_cull_distance is supported, or if
421 * we're running a GL4.5 context
423 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_cull_distance") &&
424 !glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)))
426 throw tcu::NotSupportedError("GL_ARB_cull_distance is not supported");
429 /* Check that calling GetIntegerv with MAX_CULL_DISTANCES doesn't generate
430 * any errors and returns a value at least 8.
432 * Check that calling GetIntegerv with MAX_COMBINED_CLIP_AND_CULL_DISTANCES
433 * doesn't generate any errors and returns a value at least 8.
436 glw::GLint error_code = GL_NO_ERROR;
437 glw::GLint gl_max_cull_distances_value = 0;
438 glw::GLint gl_max_combined_clip_and_cull_distances_value = 0;
440 gl.getIntegerv(GL_MAX_CULL_DISTANCES, &gl_max_cull_distances_value);
442 error_code = gl.getError();
443 if (error_code != GL_NO_ERROR)
445 m_testCtx.getLog() << tcu::TestLog::Message << "glGetIntegerv() returned error code "
446 << "[" << glu::getErrorStr(error_code) << "] for GL_MAX_CULL_DISTANCES"
447 " query instead of GL_NO_ERROR"
448 << tcu::TestLog::EndMessage;
450 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
455 gl.getIntegerv(GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES, &gl_max_combined_clip_and_cull_distances_value);
457 error_code = gl.getError();
458 if (error_code != GL_NO_ERROR)
460 m_testCtx.getLog() << tcu::TestLog::Message << "glGetIntegerv() returned error code "
461 << "[" << glu::getErrorStr(error_code) << "] for "
462 "GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES query "
463 "instead of GL_NO_ERROR"
464 << tcu::TestLog::EndMessage;
466 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
471 /* Before we proceed with the two other tests, initialize a buffer & a texture
472 * object we will need to capture data from the programs */
473 static const glw::GLuint bo_size = sizeof(int) * 4 /* components */ * 4 /* result points */;
475 gl.genBuffers(1, &m_bo_id);
476 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers() call failed.");
478 gl.genFramebuffers(1, &m_fbo_draw_id);
479 gl.genFramebuffers(1, &m_fbo_read_id);
480 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers() call(s) failed.");
482 gl.genTextures(1, &m_cs_to_id);
483 gl.genTextures(1, &m_fbo_draw_to_id);
484 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() call failed.");
486 gl.genVertexArrays(1, &m_vao_id);
487 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays() call failed.");
489 gl.bindVertexArray(m_vao_id);
490 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray() call failed.");
492 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_bo_id);
493 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, /* index */
495 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer() or glBindBufferBase() call(s) failed.");
497 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, bo_size, DE_NULL, GL_STATIC_DRAW);
498 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData() call failed.");
500 for (glw::GLuint n_to_id = 0; n_to_id < 2; /* CS, FBO */ ++n_to_id)
502 gl.bindTexture(GL_TEXTURE_2D, (n_to_id == 0) ? m_cs_to_id : m_fbo_draw_to_id);
503 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() call failed.");
505 gl.texStorage2D(GL_TEXTURE_2D, 1, /* levels */
506 GL_R32I, 1, /* width */
508 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage2D() call failed.");
511 gl.bindImageTexture(0, /* unit */
512 m_cs_to_id, 0, /* level */
513 GL_FALSE, /* layered */
515 GL_WRITE_ONLY, GL_R32I);
516 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindImageTexture() call failed.");
518 gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo_draw_id);
519 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer() call failed.");
521 gl.framebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fbo_draw_to_id, 0); /* level */
522 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D() call failed.");
524 gl.bindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo_read_id);
525 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer() call failed.");
527 gl.viewport(0, /* x */
531 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport() call failed.");
533 gl.pixelStorei(GL_PACK_ALIGNMENT, 1);
534 GLU_EXPECT_NO_ERROR(gl.getError(), "glPixelStorei() call failed.");
536 /* There are two new GL constants, where value we need to verify */
539 const glw::GLchar* essl_token_value;
542 glw::GLint min_value;
543 const glw::GLchar* name;
544 } runs[] = { { "gl_MaxCullDistances", GL_MAX_CULL_DISTANCES, gl_max_cull_distances_value, 8 /*minimum required */,
545 "GL_MAX_CULL_DISTANCES" },
546 { "gl_MaxCombinedClipAndCullDistances", GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES,
547 gl_max_combined_clip_and_cull_distances_value, 8 /*minimum required */,
548 "GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES" } };
550 static const glw::GLuint n_runs = sizeof(runs) / sizeof(runs[0]);
552 for (glw::GLuint n_run = 0; n_run < n_runs; ++n_run)
554 _run& current_run = runs[n_run];
556 static const struct _stage
565 const glw::GLchar* fs_input;
566 const glw::GLchar* gs_input;
567 const glw::GLchar* tc_input;
568 const glw::GLchar* te_input;
570 const glw::GLchar* tf_output_name;
571 const glw::GLenum tf_mode;
573 glw::GLenum draw_call_mode;
574 glw::GLuint n_draw_call_vertices;
575 } stages[] = { /* CS only test */
577 /* use_cs|use_fs|use_gs|use_tc|use_te|use_vs */
578 true, false, false, false, false, false,
584 NULL, /* tf_output_name */
585 GL_NONE, /* tf_mode */
586 GL_NONE, /* draw_call_mode */
587 0, /* n_draw_call_vertices */
589 /* VS+GS+TC+TE+FS test */
591 /* use_cs|use_fs|use_gs|use_tc|use_te|use_vs */
592 false, true, true, true, true, true,
594 "out_gs", /* fs_input */
595 "out_te", /* gs_input */
596 "out_vs", /* tc_input */
597 "out_tc", /* te_input */
598 "out_gs", /* tf_output_name */
599 GL_TRIANGLES, /* tf_mode */
600 GL_PATCHES, /* draw_call_mode */
601 3, /* n_draw_call_vertices */
605 /* use_cs|use_fs|use_gs|use_tc|use_te|use_vs */
606 false, true, true, false, false, true,
608 "out_gs", /* fs_input */
609 "out_vs", /* gs_input */
612 "out_gs", /* tf_output_name */
613 GL_TRIANGLES, /* tf_mode */
614 GL_POINTS, /* draw_call_mode */
615 1, /* n_draw_call_vertices */
617 /* VS+TC+TE+FS test */
619 /* use_cs|use_fs|use_gs|use_tc|use_te|use_vs */
620 false, true, false, true, true, true,
622 "out_te", /* fs_input */
624 "out_vs", /* tc_input */
625 "out_tc", /* te_input */
626 "out_te", /* tf_output_name */
627 GL_POINTS, /* tf_mode */
628 GL_PATCHES, /* draw_call_mode */
629 3 /* n_draw_call_vertices */
633 /* use_cs|use_fs|use_gs|use_tc|use_te|use_vs */
634 false, false, false, false, false, true,
636 "out_vs", /* fs_input */
640 "out_vs", /* tf_output_name */
641 GL_POINTS, /* tf_mode */
642 GL_POINTS, /* draw_call_mode */
643 1 /* n_draw_call_vertices */
646 const glw::GLuint n_stages = sizeof(stages) / sizeof(stages[0]);
648 /* Run through all test stages */
649 for (glw::GLuint n_stage = 0; n_stage < n_stages; ++n_stage)
651 /* Check for OpenGL feature support */
652 if (stages[n_stage].use_cs)
654 if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 3)) &&
655 !m_context.getContextInfo().isExtensionSupported("GL_ARB_compute_shader"))
657 continue; // no compute shader support
660 if (stages[n_stage].use_tc || stages[n_stage].use_te)
662 if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 0)) &&
663 !m_context.getContextInfo().isExtensionSupported("GL_ARB_tessellation_shader"))
665 continue; // no tessellation shader support
669 /* Check that use of the GLSL built-in constant gl_MaxCullDistance in any
670 * shader stage (including compute shader) does not affect the shader
671 * compilation & program linking process.
673 static const glw::GLchar* cs_body_template =
676 "#extension GL_ARB_compute_shader : require\n"
677 "#extension GL_ARB_cull_distance : require\n"
678 "#extension GL_ARB_shader_image_load_store : require\n"
680 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
682 "layout(r32i) uniform writeonly iimage2D result;\n"
686 " imageStore(result, ivec2(0),ivec4(TOKEN) );\n"
688 std::string cs_body = cs_body_template;
690 static const glw::GLchar* fs_body_template = "#version 150\n"
692 "#extension GL_ARB_cull_distance : require\n"
694 "flat in int INPUT_FS_NAME;\n"
699 " if (INPUT_FS_NAME == TOKEN)\n"
708 std::string fs_body = fs_body_template;
710 static const glw::GLchar* gs_body_template =
713 "#extension GL_ARB_cull_distance : require\n"
715 "flat in int INPUT_GS_NAME[];\n"
716 "flat out int out_gs;\n"
718 "layout(points) in;\n"
719 "layout(triangle_strip, max_vertices = 4) out;\n"
723 " int result_value = (INPUT_GS_NAME[0] == TOKEN) ? TOKEN : -1;\n"
725 /* Draw a full-screen quad */
726 " gl_Position = vec4(-1.0, 1.0, 0.0, 0.0);\n"
727 " out_gs = result_value;\n"
730 " gl_Position = vec4(-1.0, -1.0, 0.0, 0.0);\n"
731 " out_gs = result_value;\n"
734 " gl_Position = vec4(1.0, 1.0, 0.0, 0.0);\n"
735 " out_gs = result_value;\n"
738 " gl_Position = vec4(1.0, -1.0, 0.0, 0.0);\n"
739 " out_gs = result_value;\n"
743 std::string gs_body = gs_body_template;
745 static const glw::GLchar* tc_body_template =
748 "#extension GL_ARB_cull_distance : require\n"
750 "layout(vertices = 1) out;\n"
752 "flat in int INPUT_TC_NAME[];\n"
753 "flat out int out_tc [];\n"
757 " int result_value = (INPUT_TC_NAME[0] == TOKEN) ? TOKEN : -1;\n"
759 " out_tc[gl_InvocationID] = result_value;\n"
760 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
761 " gl_TessLevelInner[0] = 1.0;\n"
762 " gl_TessLevelInner[1] = 1.0;\n"
763 " gl_TessLevelOuter[0] = 1.0;\n"
764 " gl_TessLevelOuter[1] = 1.0;\n"
765 " gl_TessLevelOuter[2] = 1.0;\n"
766 " gl_TessLevelOuter[3] = 1.0;\n"
768 std::string tc_body = tc_body_template;
770 static const glw::GLchar* te_body_template =
773 "#extension GL_ARB_cull_distance : require\n"
775 "flat in int INPUT_TE_NAME[];\n"
776 "flat out int out_te;\n"
778 "layout(isolines, point_mode) in;\n"
782 " int result_value = (INPUT_TE_NAME[0] == TOKEN) ? TOKEN : 0;\n"
784 " out_te = result_value;\n"
786 std::string te_body = te_body_template;
788 static const glw::GLchar* vs_body_template = "#version 150\n"
790 "#extension GL_ARB_cull_distance : require\n"
792 "flat out int out_vs;\n"
796 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
799 std::string vs_body = vs_body_template;
801 const _stage& current_stage = stages[n_stage];
803 /* Build shader bodies */
806 std::string* body_ptr;
808 } shader_bodies[] = { { &cs_body, GL_COMPUTE_SHADER }, { &fs_body, GL_FRAGMENT_SHADER },
809 { &gs_body, GL_GEOMETRY_SHADER }, { &tc_body, GL_TESS_CONTROL_SHADER },
810 { &te_body, GL_TESS_EVALUATION_SHADER }, { &vs_body, GL_VERTEX_SHADER } };
811 static const glw::GLchar* input_fs_token_string = "INPUT_FS_NAME";
812 static const glw::GLchar* input_gs_token_string = "INPUT_GS_NAME";
813 static const glw::GLchar* input_te_token_string = "INPUT_TE_NAME";
814 static const glw::GLchar* input_tc_token_string = "INPUT_TC_NAME";
815 static const glw::GLuint n_shader_bodies = sizeof(shader_bodies) / sizeof(shader_bodies[0]);
817 std::size_t token_position = std::string::npos;
818 static const glw::GLchar* token_string = "TOKEN";
820 for (glw::GLuint n_shader_body = 0; n_shader_body < n_shader_bodies; ++n_shader_body)
822 _shader_body& current_body = shader_bodies[n_shader_body];
824 /* Is this stage actually used? */
825 if (((current_body.gl_type == GL_COMPUTE_SHADER) && (!current_stage.use_cs)) ||
826 ((current_body.gl_type == GL_FRAGMENT_SHADER) && (!current_stage.use_fs)) ||
827 ((current_body.gl_type == GL_TESS_CONTROL_SHADER) && (!current_stage.use_tc)) ||
828 ((current_body.gl_type == GL_TESS_EVALUATION_SHADER) && (!current_stage.use_te)) ||
829 ((current_body.gl_type == GL_VERTEX_SHADER) && (!current_stage.use_vs)))
831 /* Skip the iteration. */
835 /* Iterate over all token and replace them with stage-specific values */
836 struct _token_value_pair
838 const glw::GLchar* token;
839 const glw::GLchar* value;
840 } token_value_pairs[] = {
841 /* NOTE: The last entry is filled by the switch() block below */
842 { token_string, current_run.essl_token_value },
846 const size_t n_token_value_pairs = sizeof(token_value_pairs) / sizeof(token_value_pairs[0]);
848 switch (current_body.gl_type)
850 case GL_COMPUTE_SHADER:
851 case GL_VERTEX_SHADER:
854 case GL_FRAGMENT_SHADER:
856 token_value_pairs[1].token = input_fs_token_string;
857 token_value_pairs[1].value = current_stage.fs_input;
862 case GL_GEOMETRY_SHADER:
864 token_value_pairs[1].token = input_gs_token_string;
865 token_value_pairs[1].value = current_stage.gs_input;
870 case GL_TESS_CONTROL_SHADER:
872 token_value_pairs[1].token = input_tc_token_string;
873 token_value_pairs[1].value = current_stage.tc_input;
878 case GL_TESS_EVALUATION_SHADER:
880 token_value_pairs[1].token = input_te_token_string;
881 token_value_pairs[1].value = current_stage.te_input;
887 TCU_FAIL("Unrecognized shader body type");
890 for (glw::GLuint n_pair = 0; n_pair < n_token_value_pairs; ++n_pair)
892 const _token_value_pair& current_pair = token_value_pairs[n_pair];
894 if (current_pair.token == NULL || current_pair.value == NULL)
899 while ((token_position = current_body.body_ptr->find(current_pair.token)) != std::string::npos)
901 current_body.body_ptr->replace(token_position, strlen(current_pair.token), current_pair.value);
903 } /* for (all token+value pairs) */
904 } /* for (all sader bodies) */
906 /* Build the test program */
907 CullDistance::Utilities::buildProgram(
908 gl, m_testCtx, current_stage.use_cs ? cs_body.c_str() : DE_NULL,
909 current_stage.use_fs ? fs_body.c_str() : DE_NULL, current_stage.use_gs ? gs_body.c_str() : DE_NULL,
910 current_stage.use_tc ? tc_body.c_str() : DE_NULL, current_stage.use_te ? te_body.c_str() : DE_NULL,
911 current_stage.use_vs ? vs_body.c_str() : DE_NULL, (current_stage.tf_output_name != NULL) ? 1 : 0,
912 (const glw::GLchar**)¤t_stage.tf_output_name, &m_po_id);
914 /* Bind the test program */
915 DE_ASSERT(m_po_id != 0);
917 gl.useProgram(m_po_id);
918 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram() call failed.");
920 /* Execute the draw call. Transform Feed-back should be enabled for all iterations
921 * par the CS one, since we use a different tool to capture the result data in the
924 if (!current_stage.use_cs)
926 gl.beginTransformFeedback(current_stage.tf_mode);
927 GLU_EXPECT_NO_ERROR(gl.getError(), "glBeginTransformFeedback() call failed.");
929 gl.drawArrays(current_stage.draw_call_mode, 0, /* first */
930 current_stage.n_draw_call_vertices); /* count */
931 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays() call failed.");
933 gl.endTransformFeedback();
934 GLU_EXPECT_NO_ERROR(gl.getError(), "glEndTransformFeedback() call failed.");
938 gl.dispatchCompute(1, /* num_groups_x */
939 1, /* num_groups_y */
940 1); /* num_groups_z */
941 GLU_EXPECT_NO_ERROR(gl.getError(), "glDispatchCompute() call failed.");
944 /* Verify the result values */
945 if (!current_stage.use_cs)
947 glw::GLint* result_data_ptr = DE_NULL;
949 /* Retrieve the data captured by Transform Feedback */
950 result_data_ptr = (glw::GLint*)gl.mapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, /* offset */
951 sizeof(unsigned int) * 1, GL_MAP_READ_BIT);
952 GLU_EXPECT_NO_ERROR(gl.getError(), "glMapBufferRange() call failed.");
954 if (*result_data_ptr != current_run.gl_value)
956 m_testCtx.getLog() << tcu::TestLog::Message << current_run.name << " value "
958 << *result_data_ptr << "]"
959 " does not match the one reported by glGetIntegerv() "
961 << current_run.gl_value << "]" << tcu::TestLog::EndMessage;
963 TCU_FAIL("GL constant value does not match the ES SL equivalent");
966 if (*result_data_ptr < current_run.min_value)
968 m_testCtx.getLog() << tcu::TestLog::Message << current_run.name << " value "
970 << *result_data_ptr << "]"
971 " does not meet the minimum specification requirements "
973 << current_run.min_value << "]" << tcu::TestLog::EndMessage;
975 TCU_FAIL("GL constant value does not meet minimum specification requirements");
978 gl.unmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
979 GLU_EXPECT_NO_ERROR(gl.getError(), "glUnmapBuffer() call failed.");
982 for (glw::GLuint n_stage_internal = 0; n_stage_internal < 2; /* CS, FS write to separate textures */
985 glw::GLuint to_id = (n_stage_internal == 0) ? m_cs_to_id : m_fbo_draw_to_id;
987 if (((n_stage_internal == 0) && (!current_stage.use_cs)) ||
988 ((n_stage_internal == 1) && (!current_stage.use_fs)))
990 /* Skip the iteration */
994 /* Check the image data the test CS / FS should have written */
995 glw::GLint result_value = 0;
997 gl.framebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, to_id, 0); /* level */
998 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D() call failed.");
1000 /* NOTE: We're using our custom read framebuffer here, so we'll be reading
1001 * from the texture, that the writes have been issued to earlier. */
1003 GLU_EXPECT_NO_ERROR(gl.getError(), "glMemoryBarrier() call failed.");
1005 gl.readPixels(0, /* x */
1009 GL_RED_INTEGER, GL_INT, &result_value);
1010 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() call failed.");
1012 if (result_value != current_run.gl_value)
1014 m_testCtx.getLog() << tcu::TestLog::Message << current_run.name
1015 << " value accessible to the compute / fragment shader "
1017 << result_value << "]"
1018 " does not match the one reported by glGetIntegerv() "
1020 << current_run.gl_value << "]" << tcu::TestLog::EndMessage;
1022 TCU_FAIL("GL constant value does not match the ES SL equivalent");
1025 if (result_value < current_run.min_value)
1027 m_testCtx.getLog() << tcu::TestLog::Message << current_run.name
1028 << " value accessible to the compute / fragment shader "
1030 << result_value << "]"
1031 " does not meet the minimum specification requirements "
1033 << current_run.min_value << "]" << tcu::TestLog::EndMessage;
1035 TCU_FAIL("GL constant value does not meet minimum specification requirements");
1039 /* Clear the data buffer before we continue */
1040 static const glw::GLubyte bo_clear_data[bo_size] = { 0 };
1042 gl.bufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, /* offset */
1043 bo_size, bo_clear_data);
1044 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferSubData() call failed.");
1046 /* Clear the texture mip-map before we continue */
1047 glw::GLint clear_values[4] = { 0, 0, 0, 0 };
1049 gl.clearBufferiv(GL_COLOR, 0, /* drawbuffer */
1051 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearBufferiv() call failed.");
1053 /* Release program before we move on to the next iteration */
1056 gl.deleteProgram(m_po_id);
1060 } /* for (all stages) */
1061 } /* for (both runs) */
1064 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1071 * @param context Rendering context handle.
1073 CullDistance::FunctionalTest::FunctionalTest(deqp::Context& context)
1074 : TestCase(context, "functional", "Cull Distance Functional Test")
1079 , m_render_primitives(0)
1080 , m_render_vertices(0)
1081 , m_sub_grid_cell_size(0)
1086 , m_to_pixel_data_cache()
1088 /* Left blank on purpose */
1091 /** @brief Build OpenGL program for functional tests
1093 * @param [in] clipdistances_array_size use size of gl_ClipDistance array
1094 * @param [in] culldistances_array_size use size of gl_CullDistance array
1095 * @param [in] dynamic_index_writes use dunamic indexing for setting the gl_ClipDistance and gl_CullDistance arrays
1096 * @param [in] primitive_mode primitive_mode will be used for rendering
1097 * @param [in] redeclare_clipdistances redeclare gl_ClipDistance
1098 * @param [in] redeclare_culldistances redeclare gl_CullDistance
1099 * @param [in] use_core_functionality use core OpenGL functionality
1100 * @param [in] use_gs use geometry shader
1101 * @param [in] use_ts use tessellation shader
1102 * @param [in] fetch_culldistance_from_fs fetch check sum of gl_ClipDistance and gl_CullDistance from fragment shader
1104 void CullDistance::FunctionalTest::buildPO(glw::GLuint clipdistances_array_size, glw::GLuint culldistances_array_size,
1105 bool dynamic_index_writes, _primitive_mode primitive_mode,
1106 bool redeclare_clipdistances, bool redeclare_culldistances,
1107 bool use_core_functionality, bool use_gs, bool use_ts,
1108 bool fetch_culldistance_from_fs)
1112 /* Form the vertex shader */
1113 glw::GLuint clipdistances_input_size =
1114 clipdistances_array_size > 0 ? clipdistances_array_size : 1; /* Avoid zero-sized array compilation error */
1115 glw::GLuint culldistances_input_size =
1116 culldistances_array_size > 0 ? culldistances_array_size : 1; /* Avoid zero-sized array compilation error */
1117 static const glw::GLchar* dynamic_array_setters =
1119 "#if TEMPLATE_N_GL_CLIPDISTANCE_ENTRIES\n"
1120 " for (int n_clipdistance_entry = 0;\n"
1121 " n_clipdistance_entry < TEMPLATE_N_GL_CLIPDISTANCE_ENTRIES;\n"
1122 " ++n_clipdistance_entry)\n"
1124 " ASSIGN_CLIP_DISTANCE(n_clipdistance_entry);\n"
1128 "#if TEMPLATE_N_GL_CULLDISTANCE_ENTRIES \n"
1129 " for (int n_culldistance_entry = 0;\n"
1130 " n_culldistance_entry < TEMPLATE_N_GL_CULLDISTANCE_ENTRIES;\n"
1131 " ++n_culldistance_entry)\n"
1133 " ASSIGN_CULL_DISTANCE(n_culldistance_entry);\n"
1137 static const glw::GLchar* core_functionality = "#version 450\n";
1139 static const glw::GLchar* extention_functionality = "#version 440\n"
1141 "#extension GL_ARB_cull_distance : require\n"
1143 "#ifndef GL_ARB_cull_distance\n"
1144 " #error GL_ARB_cull_distance is undefined\n"
1147 static const glw::GLchar* fetch_function = "highp float fetch()\n"
1149 " highp float sum = 0.0;\n"
1151 "TEMPLATE_SUM_SETTER"
1153 " return sum / TEMPLATE_SUM_DIVIDER;\n"
1156 "#define ASSIGN_RETURN_VALUE fetch()";
1158 static const glw::GLchar* fs_template = "TEMPLATE_HEADER_DECLARATION\n"
1160 "TEMPLATE_REDECLARE_CLIPDISTANCE\n"
1161 "TEMPLATE_REDECLARE_CULLDISTANCE\n"
1163 "TEMPLATE_ASSIGN_RETURN_VALUE\n"
1165 "out vec4 out_fs;\n"
1167 "/* Fragment shader main function */\n"
1170 " out_fs = vec4(ASSIGN_RETURN_VALUE, 1.0, 1.0, 1.0);\n"
1173 static const glw::GLchar* gs_template = "TEMPLATE_HEADER_DECLARATION\n"
1175 "TEMPLATE_LAYOUT_IN\n"
1176 "TEMPLATE_LAYOUT_OUT\n"
1178 "TEMPLATE_REDECLARE_CLIPDISTANCE\n"
1179 "TEMPLATE_REDECLARE_CULLDISTANCE\n"
1181 "#define ASSIGN_CLIP_DISTANCE(IDX) TEMPLATE_ASSIGN_CLIP_DISTANCE\n"
1182 "#define ASSIGN_CULL_DISTANCE(IDX) TEMPLATE_ASSIGN_CULL_DISTANCE\n"
1184 "/* Geometry shader (passthrough) main function */\n"
1187 " for (int n_vertex_index = 0;\n"
1188 " n_vertex_index < gl_in.length();\n"
1189 " n_vertex_index ++)\n"
1191 " gl_Position = gl_in[n_vertex_index].gl_Position;\n"
1193 " TEMPLATE_ARRAY_SETTERS\n"
1198 " EndPrimitive();\n"
1201 static const glw::GLchar* tc_template =
1202 "TEMPLATE_HEADER_DECLARATION\n"
1204 "TEMPLATE_LAYOUT_OUT\n"
1206 "out gl_PerVertex {\n"
1207 "TEMPLATE_REDECLARE_CLIPDISTANCE\n"
1208 "TEMPLATE_REDECLARE_CULLDISTANCE\n"
1209 "vec4 gl_Position;\n"
1212 "#define ASSIGN_CLIP_DISTANCE(IDX) TEMPLATE_ASSIGN_CLIP_DISTANCE\n"
1213 "#define ASSIGN_CULL_DISTANCE(IDX) TEMPLATE_ASSIGN_CULL_DISTANCE\n"
1215 "/* Tesselation control shader main function */\n"
1218 " gl_TessLevelInner[0] = 1.0;\n"
1219 " gl_TessLevelInner[1] = 1.0;\n"
1220 " gl_TessLevelOuter[0] = 1.0;\n"
1221 " gl_TessLevelOuter[1] = 1.0;\n"
1222 " gl_TessLevelOuter[2] = 1.0;\n"
1223 " gl_TessLevelOuter[3] = 1.0;\n"
1224 " /* Clipdistance and culldistance array setters */\n"
1226 " TEMPLATE_ARRAY_SETTERS\n"
1228 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
1231 static const glw::GLchar* te_template = "TEMPLATE_HEADER_DECLARATION\n"
1233 "TEMPLATE_LAYOUT_IN\n"
1235 "in gl_PerVertex {\n"
1236 "TEMPLATE_REDECLARE_IN_CLIPDISTANCE\n"
1237 "TEMPLATE_REDECLARE_IN_CULLDISTANCE\n"
1238 "vec4 gl_Position;\n"
1241 "TEMPLATE_REDECLARE_CLIPDISTANCE\n"
1242 "TEMPLATE_REDECLARE_CULLDISTANCE\n"
1244 "#define ASSIGN_CLIP_DISTANCE(IDX) TEMPLATE_ASSIGN_CLIP_DISTANCE\n"
1245 "#define ASSIGN_CULL_DISTANCE(IDX) TEMPLATE_ASSIGN_CULL_DISTANCE\n"
1247 "/* Tesselation evaluation shader main function */\n"
1250 " /* Clipdistance and culldistance array setters */\n"
1252 " TEMPLATE_ARRAY_SETTERS\n"
1254 " gl_Position = TEMPLATE_OUT_FORMULA;\n"
1257 static const glw::GLchar* vs_template =
1258 "TEMPLATE_HEADER_DECLARATION\n"
1260 "in float clipdistance_data[TEMPLATE_CLIPDISTANCE_INPUT_SIZE];\n"
1261 "in float culldistance_data[TEMPLATE_CULLDISTANCE_INPUT_SIZE];\n"
1262 "in vec2 position;\n"
1264 "TEMPLATE_REDECLARE_CLIPDISTANCE\n"
1265 "TEMPLATE_REDECLARE_CULLDISTANCE\n"
1267 "#define ASSIGN_CLIP_DISTANCE(IDX) TEMPLATE_ASSIGN_CLIP_DISTANCE\n"
1268 "#define ASSIGN_CULL_DISTANCE(IDX) TEMPLATE_ASSIGN_CULL_DISTANCE\n"
1270 "/* Vertex shader main function */\n"
1273 " /* Clipdistance and culldistance array setters */\n"
1275 " TEMPLATE_ARRAY_SETTERS\n"
1277 " gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, 0.0, 1.0);\n"
1280 std::string* shader_body_string_fs = DE_NULL;
1281 std::string* shader_body_string_gs = DE_NULL;
1282 std::string* shader_body_string_tc = DE_NULL;
1283 std::string* shader_body_string_te = DE_NULL;
1284 std::string* shader_body_string_vs = DE_NULL;
1285 std::string shader_header_declaration = use_core_functionality ? core_functionality : extention_functionality;
1287 struct _shaders_configuration
1290 const glw::GLchar* shader_template;
1293 } shaders_configuration[] = { {
1294 GL_FRAGMENT_SHADER, fs_template, std::string(), true,
1297 GL_GEOMETRY_SHADER, gs_template, std::string(), use_gs,
1300 GL_TESS_CONTROL_SHADER, tc_template, std::string(), use_ts,
1303 GL_TESS_EVALUATION_SHADER, te_template, std::string(), use_ts,
1306 GL_VERTEX_SHADER, vs_template, std::string(), true,
1309 const glw::GLuint n_shaders_configuration = sizeof(shaders_configuration) / sizeof(shaders_configuration[0]);
1311 /* Construct shader bodies out of templates */
1312 for (glw::GLuint n_shader_index = 0; n_shader_index < n_shaders_configuration; n_shader_index++)
1314 if (shaders_configuration[n_shader_index].use)
1316 std::string array_setters;
1317 std::string clipdistance_array_declaration;
1318 std::string culldistance_array_declaration;
1319 std::string clipdistance_in_array_declaration;
1320 std::string culldistance_in_array_declaration;
1321 std::string& shader_source = shaders_configuration[n_shader_index].body;
1323 /* Copy template into shader body source */
1324 shader_source = shaders_configuration[n_shader_index].shader_template;
1326 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_HEADER_DECLARATION"),
1327 shader_header_declaration);
1329 /* Shader-specific actions */
1330 switch (shaders_configuration[n_shader_index].type)
1332 case GL_FRAGMENT_SHADER:
1334 shader_body_string_fs = &shaders_configuration[n_shader_index].body;
1336 if (fetch_culldistance_from_fs)
1338 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_ASSIGN_RETURN_VALUE"),
1339 std::string(fetch_function));
1341 std::string fetch_sum_setters = "";
1342 for (glw::GLuint i = 0; i < clipdistances_array_size; ++i)
1344 fetch_sum_setters.append(" sum += abs(gl_ClipDistance[");
1345 fetch_sum_setters.append(CullDistance::Utilities::intToString(i));
1346 fetch_sum_setters.append("]) * ");
1347 fetch_sum_setters.append(CullDistance::Utilities::intToString(i + 1));
1348 fetch_sum_setters.append(".0;\n");
1351 fetch_sum_setters.append("\n");
1353 for (glw::GLuint i = 0; i < culldistances_array_size; ++i)
1355 fetch_sum_setters.append(" sum += abs(gl_CullDistance[");
1356 fetch_sum_setters.append(CullDistance::Utilities::intToString(i));
1357 fetch_sum_setters.append("]) * ");
1358 fetch_sum_setters.append(
1359 CullDistance::Utilities::intToString(i + 1 + clipdistances_array_size));
1360 fetch_sum_setters.append(".0;\n");
1363 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_SUM_SETTER"),
1364 std::string(fetch_sum_setters));
1365 CullDistance::Utilities::replaceAll(
1366 shader_source, std::string("TEMPLATE_SUM_DIVIDER"),
1367 std::string(CullDistance::Utilities::intToString(
1368 (clipdistances_array_size + culldistances_array_size) *
1369 ((clipdistances_array_size + culldistances_array_size + 1))))
1374 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_ASSIGN_RETURN_VALUE"),
1375 std::string("#define ASSIGN_RETURN_VALUE 1.0"));
1381 case GL_GEOMETRY_SHADER:
1383 shader_body_string_gs = &shaders_configuration[n_shader_index].body;
1385 CullDistance::Utilities::replaceAll(
1386 shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1387 std::string("gl_ClipDistance[IDX] = gl_in[n_vertex_index].gl_ClipDistance[IDX]"));
1388 CullDistance::Utilities::replaceAll(
1389 shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1390 std::string("gl_CullDistance[IDX] = gl_in[n_vertex_index].gl_CullDistance[IDX]"));
1392 switch (primitive_mode)
1394 case PRIMITIVE_MODE_LINES:
1396 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1397 std::string("layout(lines) in;"));
1398 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1399 std::string("layout(line_strip, max_vertices = 2) out;"));
1403 case PRIMITIVE_MODE_POINTS:
1405 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1406 std::string("layout(points) in;"));
1407 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1408 std::string("layout(points, max_vertices = 1) out;"));
1412 case PRIMITIVE_MODE_TRIANGLES:
1414 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1415 std::string("layout(triangles) in;"));
1416 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1417 std::string("layout(triangle_strip, max_vertices = 3) out;"));
1422 TCU_FAIL("Unknown primitive mode");
1428 case GL_TESS_CONTROL_SHADER:
1430 shader_body_string_tc = &shaders_configuration[n_shader_index].body;
1432 CullDistance::Utilities::replaceAll(
1433 shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1435 "gl_out[gl_InvocationID].gl_ClipDistance[IDX] = gl_in[gl_InvocationID].gl_ClipDistance[IDX]"));
1436 CullDistance::Utilities::replaceAll(
1437 shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1439 "gl_out[gl_InvocationID].gl_CullDistance[IDX] = gl_in[gl_InvocationID].gl_CullDistance[IDX]"));
1441 switch (primitive_mode)
1443 case PRIMITIVE_MODE_LINES:
1445 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1446 std::string("layout(vertices = 2) out;"));
1450 case PRIMITIVE_MODE_POINTS:
1452 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1453 std::string("layout(vertices = 1) out;"));
1457 case PRIMITIVE_MODE_TRIANGLES:
1459 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_OUT"),
1460 std::string("layout(vertices = 3) out;"));
1465 TCU_FAIL("Unknown primitive mode");
1471 case GL_TESS_EVALUATION_SHADER:
1473 shader_body_string_te = &shaders_configuration[n_shader_index].body;
1475 switch (primitive_mode)
1477 case PRIMITIVE_MODE_LINES:
1479 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1480 std::string("layout(isolines) in;"));
1481 CullDistance::Utilities::replaceAll(
1482 shader_source, std::string("TEMPLATE_OUT_FORMULA"),
1483 std::string("mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x)"));
1484 CullDistance::Utilities::replaceAll(
1485 shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1486 std::string("gl_ClipDistance[IDX] = mix(gl_in[0].gl_ClipDistance[IDX], "
1487 "gl_in[1].gl_ClipDistance[IDX], gl_TessCoord.x)"));
1488 CullDistance::Utilities::replaceAll(
1489 shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1490 std::string("gl_CullDistance[IDX] = mix(gl_in[0].gl_CullDistance[IDX], "
1491 "gl_in[1].gl_CullDistance[IDX], gl_TessCoord.x)"));
1495 case PRIMITIVE_MODE_POINTS:
1497 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1498 std::string("layout(isolines, point_mode) in;"));
1499 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_OUT_FORMULA"),
1500 std::string("gl_in[0].gl_Position"));
1501 CullDistance::Utilities::replaceAll(
1502 shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1503 std::string("gl_ClipDistance[IDX] = gl_in[0].gl_ClipDistance[IDX]"));
1504 CullDistance::Utilities::replaceAll(
1505 shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1506 std::string("gl_CullDistance[IDX] = gl_in[0].gl_CullDistance[IDX]"));
1510 case PRIMITIVE_MODE_TRIANGLES:
1512 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_LAYOUT_IN"),
1513 std::string("layout(triangles) in;"));
1514 CullDistance::Utilities::replaceAll(
1515 shader_source, std::string("TEMPLATE_OUT_FORMULA"),
1516 std::string("vec4(mat3(gl_in[0].gl_Position.xyz, gl_in[1].gl_Position.xyz, "
1517 "gl_in[2].gl_Position.xyz) * gl_TessCoord, 1.0)"));
1518 CullDistance::Utilities::replaceAll(
1519 shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1520 std::string("gl_ClipDistance[IDX] = dot(vec3(gl_in[0].gl_ClipDistance[IDX], "
1521 "gl_in[1].gl_ClipDistance[IDX], gl_in[2].gl_ClipDistance[IDX]), gl_TessCoord)"));
1522 CullDistance::Utilities::replaceAll(
1523 shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1524 std::string("gl_CullDistance[IDX] = dot(vec3(gl_in[0].gl_CullDistance[IDX], "
1525 "gl_in[1].gl_CullDistance[IDX], gl_in[2].gl_CullDistance[IDX]), gl_TessCoord)"));
1530 TCU_FAIL("Unknown primitive mode");
1536 case GL_VERTEX_SHADER:
1538 shader_body_string_vs = &shaders_configuration[n_shader_index].body;
1540 /* Specify input data size for clipdistances data */
1541 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_CLIPDISTANCE_INPUT_SIZE"),
1542 CullDistance::Utilities::intToString(clipdistances_input_size));
1544 /* Specify input data size for culldistances data */
1545 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_CULLDISTANCE_INPUT_SIZE"),
1546 CullDistance::Utilities::intToString(culldistances_input_size));
1548 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_ASSIGN_CLIP_DISTANCE"),
1549 std::string("gl_ClipDistance[IDX] = clipdistance_data[IDX]"));
1550 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_ASSIGN_CULL_DISTANCE"),
1551 std::string("gl_CullDistance[IDX] = culldistance_data[IDX]"));
1557 TCU_FAIL("Unknown shader type");
1560 /* Adjust clipdistances declaration */
1561 if (redeclare_clipdistances && clipdistances_array_size > 0)
1563 if (shaders_configuration[n_shader_index].type == GL_FRAGMENT_SHADER)
1565 if (fetch_culldistance_from_fs)
1567 clipdistance_array_declaration =
1568 std::string("in float gl_ClipDistance[") +
1569 CullDistance::Utilities::intToString(clipdistances_array_size) + std::string("];");
1572 else if (shaders_configuration[n_shader_index].type == GL_TESS_CONTROL_SHADER)
1574 clipdistance_array_declaration = std::string("float gl_ClipDistance[") +
1575 CullDistance::Utilities::intToString(clipdistances_array_size) +
1580 clipdistance_array_declaration = std::string("out float gl_ClipDistance[") +
1581 CullDistance::Utilities::intToString(clipdistances_array_size) +
1583 clipdistance_in_array_declaration = std::string("in float gl_ClipDistance[") +
1584 CullDistance::Utilities::intToString(clipdistances_array_size) +
1588 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_REDECLARE_CLIPDISTANCE"),
1589 clipdistance_array_declaration);
1590 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_REDECLARE_IN_CLIPDISTANCE"),
1591 clipdistance_in_array_declaration);
1593 /* Adjust culldistances declaration */
1594 if (redeclare_culldistances && culldistances_array_size > 0)
1596 if (shaders_configuration[n_shader_index].type == GL_FRAGMENT_SHADER)
1598 if (fetch_culldistance_from_fs)
1600 culldistance_array_declaration =
1601 std::string("in float gl_CullDistance[") +
1602 CullDistance::Utilities::intToString(culldistances_array_size) + std::string("];");
1605 else if (shaders_configuration[n_shader_index].type == GL_TESS_CONTROL_SHADER)
1607 culldistance_array_declaration = std::string("float gl_CullDistance[") +
1608 CullDistance::Utilities::intToString(culldistances_array_size) +
1613 culldistance_array_declaration = std::string("out float gl_CullDistance[") +
1614 CullDistance::Utilities::intToString(culldistances_array_size) +
1616 culldistance_in_array_declaration = std::string("in float gl_CullDistance[") +
1617 CullDistance::Utilities::intToString(culldistances_array_size) +
1621 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_REDECLARE_CULLDISTANCE"),
1622 culldistance_array_declaration);
1623 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_REDECLARE_IN_CULLDISTANCE"),
1624 culldistance_in_array_declaration);
1626 /* Adjust clip/cull distances setters */
1627 if (dynamic_index_writes)
1629 array_setters = dynamic_array_setters;
1631 CullDistance::Utilities::replaceAll(array_setters, std::string("TEMPLATE_N_GL_CLIPDISTANCE_ENTRIES"),
1632 CullDistance::Utilities::intToString(clipdistances_array_size));
1633 CullDistance::Utilities::replaceAll(array_setters, std::string("TEMPLATE_N_GL_CULLDISTANCE_ENTRIES"),
1634 CullDistance::Utilities::intToString(culldistances_array_size));
1638 std::stringstream static_array_setters_sstream;
1640 static_array_setters_sstream << "\n";
1642 for (glw::GLuint clipdistances_array_entry = 0; clipdistances_array_entry < clipdistances_array_size;
1643 ++clipdistances_array_entry)
1645 static_array_setters_sstream << " ASSIGN_CLIP_DISTANCE(" << clipdistances_array_entry
1649 static_array_setters_sstream << "\n";
1651 for (glw::GLuint culldistances_array_entry = 0; culldistances_array_entry < culldistances_array_size;
1652 ++culldistances_array_entry)
1654 static_array_setters_sstream << " ASSIGN_CULL_DISTANCE(" << culldistances_array_entry
1658 array_setters = static_array_setters_sstream.str();
1661 CullDistance::Utilities::replaceAll(shader_source, std::string("TEMPLATE_ARRAY_SETTERS"), array_setters);
1665 /* Build the geometry shader */
1666 CullDistance::Utilities::buildProgram(
1667 m_context.getRenderContext().getFunctions(), m_testCtx, DE_NULL, /* Compute shader */
1668 shader_body_string_fs != DE_NULL ? shader_body_string_fs->c_str() :
1669 DE_NULL, /* Fragment shader */
1670 shader_body_string_gs != DE_NULL ? shader_body_string_gs->c_str() :
1671 DE_NULL, /* Geometry shader */
1672 shader_body_string_tc != DE_NULL ? shader_body_string_tc->c_str() :
1673 DE_NULL, /* Tesselation control shader */
1674 shader_body_string_te != DE_NULL ? shader_body_string_te->c_str() :
1675 DE_NULL, /* Tesselation evaluation shader */
1676 shader_body_string_vs != DE_NULL ? shader_body_string_vs->c_str() :
1677 DE_NULL, /* Vertex shader */
1678 0, /* Transform feedback varyings count */
1679 DE_NULL, /* Transform feedback varyings */
1680 &m_po_id /* Program object id */
1684 /** Generates primitive data required to test a case with specified
1685 * gl_ClipDistance and glCullDistance array sizes for specified
1686 * primitive mode. Generated primitive data is stored in m_bo_data
1687 * as well uploaded into buffer specified in m_bo_id buffer.
1688 * Also the procedure binds vertex attribute locations to
1689 * program object m_po_id.
1691 * @param clipdistances_array_size gl_ClipDistance array size. Can be 0.
1692 * @param culldistances_array_size gl_CullDistance array size. Can be 0.
1693 * @param _primitive_mode Primitives to be generated. Can be:
1694 * PRIMITIVE_MODE_POINTS,
1695 * PRIMITIVE_MODE_LINES,
1696 * PRIMITIVE_MODE_TRIANGLES.
1698 void CullDistance::FunctionalTest::configureVAO(glw::GLuint clipdistances_array_size,
1699 glw::GLuint culldistances_array_size, _primitive_mode primitive_mode)
1701 /* Detailed test description.
1703 * configureVAO() generates primitives layouted in grid. Primitve
1704 * consists of up to 3 vertices and each vertex is accompanied by:
1705 * - array of clipdistances (clipdistances_array_size floats);
1706 * - array of culldistances (culldistances_array_size floats);
1707 * - rendering position coordinates (x and y);
1708 * - check position coordinates (x and y).
1710 * The grid has following layout:
1712 * Grid | gl_CullDistance[x] |
1713 * | 0 .. culldistances_array_size - 1 |
1714 * | 0th | 1st | 2nd | .......... |
1715 * ---------------------------+-------+-------+-------+------------+
1716 * 0th gl_ClipDistance |Subgrid|Subgrid|Subgrid| .......... |
1717 * 1st gl_ClipDistance |Subgrid|Subgrid|Subgrid| .......... |
1718 * ... | ... | ... | ... | .......... |
1719 * y-th gl_ClipDistance |Subgrid|Subgrid|Subgrid| .......... |
1720 * ... | ... | ... | ... | .......... |
1721 * clipdistances_array_size-1 |Subgrid|Subgrid|Subgrid| .......... |
1723 * Each grid cell contains subgrid of 3*3 items in size with following
1726 * Subgrid | x-th gl_CullDistance test |
1728 * y-th | all vertices | 0th vertex | all vertices |
1729 * gl_ClipDistance| in primitive | in primitive | in primitive |
1730 * tests | dist[x] > 0 | dist[x] < 0 | dist[x] < 0 |
1731 * ---------------+--------------+--------------+--------------+
1732 * all vertices| primitive #0 | primitive #1 | primitive #2 |
1733 * in primitive| | | |
1734 * dist[y] > 0 | visible | visible | culled |
1735 * ---------------+--------------+--------------+--------------+
1736 * 0th vertex | primitive #3 | primitive #4 | primitive #5 |
1737 * in primitive| 0th vertex | 0th vertex | |
1738 * dist[y] < 0 | clipped | clipped | culled |
1739 * ---------------+--------------+--------------+--------------+
1740 * all vertices| primitive #6 | primitive #7 | primitive #8 |
1741 * in primitive| | | |
1742 * dist[y] < 0 | clipped | clipped | culled |
1743 * ---------------+--------------+--------------+--------------+
1745 * Expected rendering result is specified in cell bottom.
1746 * It can be one of the following:
1747 * - "visible" means the primitive is not affected neither by gl_CullDistance
1748 * nor by gl_ClipDistance and rendered as a whole;
1749 * - "clipped" for the vertex means the vertex is not rendered, while other
1750 * primitive vertices and some filling fragments are rendered;
1751 * - "clipped" for primitive means none of primitive vertices and fragments
1752 * are rendered and thus primitive is not rendered and is invisible;
1753 * - "culled" means, that neither primitive vertices, nor primitive filling
1754 * fragments are rendered (primitive is invisible).
1756 * All subgrid items contain same primitive rendered. Depending on
1757 * test case running it would be either triangle, or line, or point:
1759 * triangle line point
1760 * 8x8 box 8x8 box 3x3 box
1761 * ........ ........ ...
1762 * .0----2. .0...... .0.
1763 * ..\@@@|. ..\..... ...
1770 * where 0 - is a 0th vertex primitive
1771 * 1 - is a 1st vertex primitive
1772 * 2 - is a 2nd vertex primitive
1774 * The culldistances_array_size can be 0. In that case, grid height
1775 * is assumed equal to 1, but 0 glCullDistances is specified.
1776 * Similar handled clipdistances_array_size.
1778 * The data generated is used and checked in executeRenderTest().
1779 * After rendering each primitive vertex is tested:
1780 * - if it is rendered, if it have to be rendered (according distance);
1781 * - if it is not rendered, if it have to be not rendered (according distance).
1782 * Due to "top-left" rasterization rule check position is
1783 * different from rendering vertex position.
1785 * Also one pixel width guarding box is checked to be clear.
1788 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1789 const glw::GLuint n_sub_grid_cells = 3; /* Tested distance is positive for all vertices in the primitive;
1790 * Tested distance is negative for 0th vertex in the primitive;
1791 * Tested distance is negative for all vertices in the primitive;
1793 const glw::GLuint sub_grid_cell_size =
1794 ((primitive_mode == PRIMITIVE_MODE_LINES) ? 8 : (primitive_mode == PRIMITIVE_MODE_POINTS) ? 3 : 8);
1796 const glw::GLuint grid_cell_size = n_sub_grid_cells * sub_grid_cell_size;
1797 const glw::GLuint n_primitive_vertices =
1798 ((primitive_mode == PRIMITIVE_MODE_LINES) ? 2 : (primitive_mode == PRIMITIVE_MODE_POINTS) ? 1 : 3);
1800 const glw::GLuint n_grid_cells_x = culldistances_array_size != 0 ? culldistances_array_size : 1;
1801 const glw::GLuint n_grid_cells_y = clipdistances_array_size != 0 ? clipdistances_array_size : 1;
1802 const glw::GLuint n_pervertex_float_attributes = clipdistances_array_size + culldistances_array_size +
1803 2 /* vertex' draw x, y */ + 2 /* vertex' checkpoint x, y */;
1804 const glw::GLuint n_primitives_total = n_grid_cells_x * n_sub_grid_cells * n_grid_cells_y * n_sub_grid_cells;
1805 const glw::GLuint n_vertices_total = n_primitives_total * n_primitive_vertices;
1806 const glw::GLuint offsets_line_draw_x[2] = {
1807 1, sub_grid_cell_size - 1
1808 }; /* vertex x offsets to subgrid cell origin for line primitive */
1809 const glw::GLuint offsets_line_draw_y[2] = {
1810 1, sub_grid_cell_size - 1
1811 }; /* vertex y offsets to subgrid cell origin for line primitive */
1812 const glw::GLuint offsets_line_checkpoint_x[2] = {
1813 1, sub_grid_cell_size - 2
1814 }; /* pixel x offsets to subgrid cell origin for line primitive */
1815 const glw::GLuint offsets_line_checkpoint_y[2] = {
1816 1, sub_grid_cell_size - 2
1817 }; /* pixel y offsets to subgrid cell origin for line primitive */
1818 const glw::GLuint offsets_point_draw_x[1] = {
1820 }; /* vertex x offsets to subgrid cell origin for point primitive */
1821 const glw::GLuint offsets_point_draw_y[1] = {
1823 }; /* vertex y offsets to subgrid cell origin for point primitive */
1824 const glw::GLuint offsets_point_checkpoint_x[1] = {
1826 }; /* pixel x offsets to subgrid cell origin for point primitive */
1827 const glw::GLuint offsets_point_checkpoint_y[1] = {
1829 }; /* pixel y offsets to subgrid cell origin for point primitive */
1830 const glw::GLuint offsets_triangle_draw_x[3] = {
1831 1, sub_grid_cell_size - 1, sub_grid_cell_size - 1
1832 }; /* vertex x offsets to subgrid cell origin for triangle primitive */
1833 const glw::GLuint offsets_triangle_draw_y[3] = {
1834 1, sub_grid_cell_size - 1, 1
1835 }; /* vertex y offsets to subgrid cell origin for triangle primitive */
1836 const glw::GLuint offsets_triangle_checkpoint_x[3] = {
1837 1, sub_grid_cell_size - 2, sub_grid_cell_size - 2
1838 }; /* pixel x offsets to subgrid cell origin for triangle primitive */
1839 const glw::GLuint offsets_triangle_checkpoint_y[3] = {
1840 1, sub_grid_cell_size - 2, 1
1841 }; /* pixel y offsets to subgrid cell origin for triangle primitive */
1843 /* Clear data left from previous tests. */
1846 /* No data to render */
1847 m_render_primitives = 0;
1848 m_render_vertices = 0;
1850 /* Preallocate space for bo_points_count */
1851 m_bo_data.reserve(n_vertices_total * n_pervertex_float_attributes);
1853 /* Generate test data for cell_y-th clip distance */
1854 for (glw::GLuint cell_y = 0; cell_y < n_grid_cells_y; cell_y++)
1856 /* Generate test data for cell_x-th cull distance */
1857 for (glw::GLuint cell_x = 0; cell_x < n_grid_cells_x; cell_x++)
1859 /* Check clip distance sub cases:
1860 * 0. Tested distance is positive for all vertices in the primitive;
1861 * 1. Tested distance is negative for 0th vertex in the primitive;
1862 * 2. Tested distance is negative for all vertices in the primitive;
1864 for (glw::GLuint n_sub_cell_y = 0; n_sub_cell_y < n_sub_grid_cells; n_sub_cell_y++)
1866 /* Check cull distance sub cases:
1867 * 0. Tested distance is positive for all vertices in the primitive;
1868 * 1. Tested distance is negative for 0th vertex in the primitive;
1869 * 2. Tested distance is negative for all vertices in the primitive;
1871 for (glw::GLuint n_sub_cell_x = 0; n_sub_cell_x < n_sub_grid_cells; n_sub_cell_x++)
1873 /* Generate vertices in primitive */
1874 for (glw::GLuint n_primitive_vertex = 0; n_primitive_vertex < n_primitive_vertices;
1875 n_primitive_vertex++)
1877 /* Fill in clipdistance array for the n_primitive_vertex vertex in primitive */
1878 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size;
1879 n_clipdistance_entry++)
1881 glw::GLfloat distance_value = 0.0f;
1882 bool negative = true;
1884 /* Special approach to tested clipdistance entry. */
1885 if (n_clipdistance_entry == cell_y)
1887 /* The primitive vertex should be affected by the clip distance */
1888 switch (n_sub_cell_y)
1892 /* subgrid row 0: all primitive vertices have tested distance value positive */
1899 /* subgrid row 1: tested distance value for 0th primitive vertex is negative,
1900 all other primitive vertices have tested distance value positive */
1901 negative = (n_primitive_vertex == 0) ? true : false;
1907 /* subgrid row 2: tested distance value is negative for all primitive vertices */
1913 TCU_FAIL("Invalid subgrid cell index");
1916 distance_value = (negative ? -1.0f : 1.0f) * glw::GLfloat(n_clipdistance_entry + 1);
1920 /* For clip distances other than tested: assign positive value to avoid its influence. */
1921 distance_value = glw::GLfloat(clipdistances_array_size + n_clipdistance_entry + 1);
1924 m_bo_data.push_back(distance_value / glw::GLfloat(clipdistances_array_size));
1925 } /* for (all gl_ClipDistance[] array values) */
1927 /* Fill in culldistance array for the n_primitive_vertex vertex in primitive */
1928 for (glw::GLuint n_culldistance_entry = 0; n_culldistance_entry < culldistances_array_size;
1929 n_culldistance_entry++)
1931 glw::GLfloat distance_value = 0.0f;
1932 bool negative = true;
1934 /* Special approach to tested culldistance entry. */
1935 if (n_culldistance_entry == cell_x)
1937 /* The primitive vertex should be affected by the cull distance */
1938 switch (n_sub_cell_x)
1942 /* subgrid column 0: all primitive vertices have tested distance value positive */
1949 /* subgrid column 1: tested distance value for 0th primitive vertex is negative,
1950 all other primitive vertices have tested distance value positive */
1951 negative = (n_primitive_vertex == 0) ? true : false;
1957 /* subgrid column 2: tested distance value is negative for all primitive vertices */
1963 TCU_FAIL("Invalid subgrid cell index");
1966 distance_value = (negative ? -1.0f : 1.0f) * glw::GLfloat(n_culldistance_entry + 1);
1970 /* For cull distances other than tested: assign 0th vertex negative value,
1971 to check absence of between-distances influence. */
1972 if (n_primitive_vertices > 1 && n_primitive_vertex == 0)
1974 distance_value = -glw::GLfloat(culldistances_array_size + n_culldistance_entry + 1);
1978 /* This culldistance is out of interest: assign positive value. */
1979 distance_value = glw::GLfloat(culldistances_array_size + n_culldistance_entry + 1);
1983 m_bo_data.push_back(distance_value / glw::GLfloat(culldistances_array_size));
1984 } /* for (all gl_CullDistance[] array values) */
1986 /* Generate primitve vertex draw and checkpoint coordinates */
1987 glw::GLint vertex_draw_pixel_offset_x = 0;
1988 glw::GLint vertex_draw_pixel_offset_y = 0;
1989 glw::GLint vertex_checkpoint_pixel_offset_x = 0;
1990 glw::GLint vertex_checkpoint_pixel_offset_y = 0;
1992 switch (primitive_mode)
1994 case PRIMITIVE_MODE_LINES:
1996 vertex_draw_pixel_offset_x = offsets_line_draw_x[n_primitive_vertex];
1997 vertex_draw_pixel_offset_y = offsets_line_draw_y[n_primitive_vertex];
1998 vertex_checkpoint_pixel_offset_x = offsets_line_checkpoint_x[n_primitive_vertex];
1999 vertex_checkpoint_pixel_offset_y = offsets_line_checkpoint_y[n_primitive_vertex];
2004 case PRIMITIVE_MODE_POINTS:
2006 vertex_draw_pixel_offset_x = offsets_point_draw_x[n_primitive_vertex];
2007 vertex_draw_pixel_offset_y = offsets_point_draw_y[n_primitive_vertex];
2008 vertex_checkpoint_pixel_offset_x = offsets_point_checkpoint_x[n_primitive_vertex];
2009 vertex_checkpoint_pixel_offset_y = offsets_point_checkpoint_y[n_primitive_vertex];
2014 case PRIMITIVE_MODE_TRIANGLES:
2016 vertex_draw_pixel_offset_x = offsets_triangle_draw_x[n_primitive_vertex];
2017 vertex_draw_pixel_offset_y = offsets_triangle_draw_y[n_primitive_vertex];
2018 vertex_checkpoint_pixel_offset_x = offsets_triangle_checkpoint_x[n_primitive_vertex];
2019 vertex_checkpoint_pixel_offset_y = offsets_triangle_checkpoint_y[n_primitive_vertex];
2025 TCU_FAIL("Unknown primitive mode");
2028 /* Origin of sub_cell */
2029 glw::GLint sub_cell_origin_x = cell_x * grid_cell_size + n_sub_cell_x * sub_grid_cell_size;
2030 glw::GLint sub_cell_origin_y = cell_y * grid_cell_size + n_sub_cell_y * sub_grid_cell_size;
2031 /* Normalized texture coordinates of vertex draw position. */
2033 glw::GLfloat(sub_cell_origin_x + vertex_draw_pixel_offset_x) / glw::GLfloat(m_to_width);
2035 glw::GLfloat(sub_cell_origin_y + vertex_draw_pixel_offset_y) / glw::GLfloat(m_to_height);
2036 /* Normalized texture coordinates of vertex checkpoint position. */
2037 glw::GLfloat checkpoint_x = glw::GLfloat(sub_cell_origin_x + vertex_checkpoint_pixel_offset_x) /
2038 glw::GLfloat(m_to_width);
2039 glw::GLfloat checkpoint_y = glw::GLfloat(sub_cell_origin_y + vertex_checkpoint_pixel_offset_y) /
2040 glw::GLfloat(m_to_height);
2042 /* Add vertex draw coordinates into buffer. */
2043 m_bo_data.push_back(x);
2044 m_bo_data.push_back(y);
2046 /* Add vertex checkpoint coordinates into buffer. */
2047 m_bo_data.push_back(checkpoint_x);
2048 m_bo_data.push_back(checkpoint_y);
2049 } /* for (all vertices in primitive) */
2050 } /* for (all horizontal sub cells) */
2051 } /* for (all vertical sub cells) */
2052 } /* for (all horizontal cells) */
2053 } /* for (all vertical cells) */
2055 /* Sanity check: make sure we pushed required amount of data */
2056 DE_ASSERT(m_bo_data.size() == n_vertices_total * n_pervertex_float_attributes);
2058 /* Save number of primitives to render */
2059 m_render_primitives = n_primitives_total;
2060 m_render_vertices = n_vertices_total;
2061 m_sub_grid_cell_size = sub_grid_cell_size;
2063 /* Copy the data to the buffer object */
2064 gl.bindBuffer(GL_ARRAY_BUFFER, m_bo_id);
2065 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindBuffer() call failed.");
2067 gl.bufferData(GL_ARRAY_BUFFER, m_bo_data.size() * sizeof(glw::GLfloat), &m_bo_data[0], GL_STATIC_DRAW);
2068 GLU_EXPECT_NO_ERROR(gl.getError(), "glBufferData() call failed.");
2070 DE_ASSERT(m_po_id != 0);
2072 /* Bind VAO data to program */
2073 glw::GLint po_clipdistance_array_location = -1;
2074 glw::GLint po_culldistance_array_location = -1;
2075 glw::GLint po_position_location = -1;
2077 /* Retrieve clipdistance and culldistance attribute locations */
2078 gl.bindVertexArray(m_vao_id);
2079 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray() call failed.");
2081 po_clipdistance_array_location = gl.getAttribLocation(m_po_id, "clipdistance_data[0]");
2082 po_culldistance_array_location = gl.getAttribLocation(m_po_id, "culldistance_data[0]");
2083 po_position_location = gl.getAttribLocation(m_po_id, "position");
2085 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetAttribLocation() call(s) failed.");
2087 if (clipdistances_array_size > 0)
2089 DE_ASSERT(po_clipdistance_array_location != -1);
2092 if (culldistances_array_size > 0)
2094 DE_ASSERT(po_culldistance_array_location != -1);
2097 DE_ASSERT(po_position_location != -1);
2099 glw::GLintptr current_offset = 0;
2100 const glw::GLint stride = static_cast<glw::GLint>(n_pervertex_float_attributes * sizeof(glw::GLfloat));
2102 gl.bindVertexArray(m_vao_id);
2103 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray() call failed.");
2105 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size; ++n_clipdistance_entry)
2107 gl.vertexAttribPointer(po_clipdistance_array_location + n_clipdistance_entry, 1, /* size */
2108 GL_FLOAT, GL_FALSE, /* normalized */
2109 stride, (const glw::GLvoid*)current_offset);
2110 GLU_EXPECT_NO_ERROR(gl.getError(), "glVertexAttribPointer() call failed.");
2112 gl.enableVertexAttribArray(po_clipdistance_array_location + n_clipdistance_entry);
2113 GLU_EXPECT_NO_ERROR(gl.getError(), "glEnableVertexAttribArray() call failed.");
2115 current_offset += sizeof(glw::GLfloat);
2116 } /* for (all clip distance array value attributes) */
2118 for (glw::GLuint n_culldistance_entry = 0; n_culldistance_entry < culldistances_array_size; ++n_culldistance_entry)
2120 gl.vertexAttribPointer(po_culldistance_array_location + n_culldistance_entry, 1, /* size */
2121 GL_FLOAT, GL_FALSE, /* normalized */
2122 stride, (const glw::GLvoid*)current_offset);
2123 GLU_EXPECT_NO_ERROR(gl.getError(), "glVertexAttribPointer() call failed.");
2125 gl.enableVertexAttribArray(po_culldistance_array_location + n_culldistance_entry);
2126 GLU_EXPECT_NO_ERROR(gl.getError(), "glEnableVertexAttribArray() call failed.");
2128 current_offset += sizeof(glw::GLfloat);
2129 } /* for (all cull distance array value attributes) */
2131 gl.vertexAttribPointer(po_position_location, 2, /* size */
2132 GL_FLOAT, GL_FALSE, /* normalized */
2133 stride, (const glw::GLvoid*)current_offset);
2134 GLU_EXPECT_NO_ERROR(gl.getError(), "glVertexAttribPointer() call failed");
2136 gl.enableVertexAttribArray(po_position_location);
2137 GLU_EXPECT_NO_ERROR(gl.getError(), "glEnableVertexAttribArray() call failed");
2140 /** @brief Cull Distance Functional Test deinitialization */
2141 void CullDistance::FunctionalTest::deinit()
2143 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2147 gl.deleteFramebuffers(1, &m_fbo_id);
2154 gl.deleteTextures(1, &m_to_id);
2161 gl.deleteVertexArrays(1, &m_vao_id);
2169 /** @brief Cull Distance Functional Test deinitialization of OpenGL programs */
2170 void CullDistance::FunctionalTest::deinitPO()
2172 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2176 gl.deleteProgram(m_po_id);
2182 /** @brief Executes single render test case
2184 * @param [in] clipdistances_array_size Size of gl_ClipDistance[] array
2185 * @param [in] culldistances_array_size Size of gl_CullDistance[] array
2186 * @param [in] primitive_mode Type of primitives to be rendered (see enum _primitive_mode)
2187 * @param [in] use_tesselation Indicate whether to use tessellation shader
2188 * @param [in] fetch_culldistance_from_fs Indicate whether to fetch gl_CullDistance and gl_ClipDistance values from the fragment shader
2190 void CullDistance::FunctionalTest::executeRenderTest(glw::GLuint clipdistances_array_size,
2191 glw::GLuint culldistances_array_size,
2192 _primitive_mode primitive_mode, bool use_tesselation,
2193 bool fetch_culldistance_from_fs)
2195 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2196 glw::GLenum mode = GL_NONE;
2197 glw::GLuint n_clipped_vertices_real = 0;
2198 glw::GLuint n_culled_primitives_real = 0;
2199 glw::GLuint n_not_clipped_vertices_real = 0;
2200 const glw::GLuint primitive_vertices_count =
2201 ((primitive_mode == PRIMITIVE_MODE_LINES) ? 2 : (primitive_mode == PRIMITIVE_MODE_POINTS) ? 1 : 3);
2202 const glw::GLuint stride_in_floats =
2203 clipdistances_array_size + culldistances_array_size + 2 /* position's x, y*/ + 2 /* checkpoint x,y */;
2205 switch (primitive_mode)
2207 case PRIMITIVE_MODE_LINES:
2213 case PRIMITIVE_MODE_POINTS:
2219 case PRIMITIVE_MODE_TRIANGLES:
2221 mode = GL_TRIANGLES;
2226 TCU_FAIL("Unknown primitive mode");
2229 if (use_tesselation)
2233 gl.patchParameteri(GL_PATCH_VERTICES, primitive_vertices_count);
2234 GLU_EXPECT_NO_ERROR(gl.getError(), "glPatchParameteri() call failed.");
2237 gl.clear(GL_COLOR_BUFFER_BIT);
2238 GLU_EXPECT_NO_ERROR(gl.getError(), "glClear() call failed.");
2240 gl.useProgram(m_po_id);
2241 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram() call failed.");
2243 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size; n_clipdistance_entry++)
2245 gl.enable(GL_CLIP_DISTANCE0 + n_clipdistance_entry);
2246 GLU_EXPECT_NO_ERROR(gl.getError(), "gl.enable(GL_CLIP_DISTANCE)() call failed.");
2247 } /* for (all clip distance array value attributes) */
2249 gl.drawArrays(mode, 0, m_render_vertices);
2250 GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArray() call(s) failed.");
2252 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size; n_clipdistance_entry++)
2254 gl.disable(GL_CLIP_DISTANCE0 + n_clipdistance_entry);
2255 GLU_EXPECT_NO_ERROR(gl.getError(), "gl.disable(GL_CLIP_DISTANCE)() call failed.");
2256 } /* for (all clip distance array value attributes) */
2259 GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram() call failed.");
2261 /* Read generated texture into m_to_pixel_data_cache */
2262 readTexturePixels();
2264 for (glw::GLint n_primitive_index = 0; n_primitive_index < m_render_primitives; n_primitive_index++)
2266 glw::GLuint base_index_of_primitive = n_primitive_index * primitive_vertices_count * stride_in_floats;
2267 bool primitive_culled = false;
2268 glw::GLint primitive_culled_by_distance = -1;
2270 /* Check the bounding box is clear */
2271 glw::GLuint base_index_of_vertex = base_index_of_primitive;
2272 glw::GLuint checkpoint_position_index = base_index_of_vertex + clipdistances_array_size +
2273 culldistances_array_size + 2 /* ignore vertex coordinates */;
2274 glw::GLint checkpoint_x = glw::GLint(glw::GLfloat(m_to_width) * m_bo_data[checkpoint_position_index]);
2275 glw::GLint checkpoint_y = glw::GLint(glw::GLfloat(m_to_height) * m_bo_data[checkpoint_position_index + 1]);
2276 glw::GLint origin_x = checkpoint_x - 1;
2277 glw::GLint origin_y = checkpoint_y - 1;
2278 for (glw::GLint pixel_offset = 0; pixel_offset < m_sub_grid_cell_size; pixel_offset++)
2280 if (readRedPixelValue(origin_x + pixel_offset, origin_y) != 0)
2282 TCU_FAIL("Top edge of bounding box is overwritten");
2285 if (readRedPixelValue(origin_x + m_sub_grid_cell_size - 1, origin_y + pixel_offset) != 0)
2287 TCU_FAIL("Right edge of bounding box is overwritten");
2290 if (readRedPixelValue(origin_x + m_sub_grid_cell_size - 1 - pixel_offset,
2291 origin_y + m_sub_grid_cell_size - 1) != 0)
2293 TCU_FAIL("Bottom edge of bounding box is overwritten");
2296 if (readRedPixelValue(origin_x, origin_y + m_sub_grid_cell_size - 1 - pixel_offset) != 0)
2298 TCU_FAIL("Left edge of bounding box is overwritten");
2302 /* Determine if primitive has been culled */
2303 for (glw::GLuint n_culldistance_entry = 0; n_culldistance_entry < culldistances_array_size;
2304 n_culldistance_entry++)
2306 bool distance_negative_in_all_primitive_vertices = true;
2308 for (glw::GLuint n_primitive_vertex = 0; n_primitive_vertex < primitive_vertices_count;
2309 n_primitive_vertex++)
2311 glw::GLint base_index_of_vertex_internal =
2312 base_index_of_primitive + n_primitive_vertex * stride_in_floats;
2313 glw::GLint culldistance_array_offset = base_index_of_vertex_internal + clipdistances_array_size;
2314 glw::GLfloat* vertex_culldistance_array = &m_bo_data[culldistance_array_offset];
2316 if (vertex_culldistance_array[n_culldistance_entry] >= 0)
2318 /* Primitive is not culled, due to one of its distances is not negative */
2319 distance_negative_in_all_primitive_vertices = false;
2321 /* Skip left vertices for this distance */
2326 /* The distance is negative in all primitive vertices, so this distance culls the primitive */
2327 if (distance_negative_in_all_primitive_vertices)
2329 primitive_culled = true;
2330 primitive_culled_by_distance = n_culldistance_entry;
2332 n_culled_primitives_real++;
2334 /* Skip left distances from check */
2339 /* Validate culling */
2340 if (primitive_culled)
2342 /* Check whether primitive was culled and all its vertices are invisible */
2343 for (glw::GLuint n_primitive_vertex = 0; n_primitive_vertex < primitive_vertices_count;
2344 n_primitive_vertex++)
2346 glw::GLint base_index_of_vertex_internal =
2347 base_index_of_primitive + n_primitive_vertex * stride_in_floats;
2348 glw::GLint checkpoint_position_index_internal = base_index_of_vertex_internal +
2349 clipdistances_array_size + culldistances_array_size +
2350 2 /* ignore vertex coordinates */;
2351 glw::GLint checkpoint_x_internal =
2352 glw::GLint(glw::GLfloat(m_to_width) * m_bo_data[checkpoint_position_index_internal]);
2353 glw::GLint checkpoint_y_internal =
2354 glw::GLint(glw::GLfloat(m_to_height) * m_bo_data[checkpoint_position_index_internal + 1]);
2355 glw::GLint vertex_color_red_value = readRedPixelValue(checkpoint_x_internal, checkpoint_y_internal);
2357 /* Make sure vertex is invisible */
2358 if (vertex_color_red_value != 0)
2360 m_testCtx.getLog() << tcu::TestLog::Message << "Primitive number [" << n_primitive_index << "] "
2361 << "should be culled by distance [" << primitive_culled_by_distance << "]"
2362 << "but primitive vertex at (" << checkpoint_x << "," << checkpoint_y
2363 << ") is visible." << tcu::TestLog::EndMessage;
2365 TCU_FAIL("Primitive is expected to be culled, but one of its vertices is visible.");
2369 /* Primitive is culled, no reason to check clipping */
2373 bool all_vertices_are_clipped = true;
2375 for (glw::GLuint n_primitive_vertex = 0; n_primitive_vertex < primitive_vertices_count; n_primitive_vertex++)
2377 glw::GLuint base_index_of_vertex_internal = base_index_of_primitive + n_primitive_vertex * stride_in_floats;
2378 glw::GLuint clipdistance_array_index = base_index_of_vertex_internal;
2379 glw::GLuint checkpoint_position_index_internal = base_index_of_vertex_internal + clipdistances_array_size +
2380 culldistances_array_size +
2381 2 /* ignore vertex coordinates */;
2382 glw::GLint checkpoint_x_internal =
2383 glw::GLint(glw::GLfloat(m_to_width) * m_bo_data[checkpoint_position_index_internal]);
2384 glw::GLint checkpoint_y_internal =
2385 glw::GLint(glw::GLfloat(m_to_height) * m_bo_data[checkpoint_position_index_internal + 1]);
2386 glw::GLfloat* vertex_clipdistance_array = &m_bo_data[clipdistance_array_index];
2387 bool vertex_clipped = false;
2388 glw::GLint vertex_clipped_by_distance = 0;
2389 glw::GLint vertex_color_red_value = readRedPixelValue(checkpoint_x_internal, checkpoint_y_internal);
2391 /* Check whether pixel should be clipped */
2392 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size;
2393 n_clipdistance_entry++)
2395 if (vertex_clipdistance_array[n_clipdistance_entry] < 0)
2397 vertex_clipped = true;
2398 vertex_clipped_by_distance = n_clipdistance_entry;
2404 all_vertices_are_clipped &= vertex_clipped;
2406 /* Validate whether real data same as expected */
2409 if (vertex_color_red_value != 0)
2411 m_testCtx.getLog() << tcu::TestLog::Message << "In primitive number [" << n_primitive_index << "] "
2412 << "vertex at (" << checkpoint_x << "," << checkpoint_y << ") "
2413 << "should be clipped by distance [" << vertex_clipped_by_distance << "] "
2414 << "(distance value [" << vertex_clipdistance_array[vertex_clipped_by_distance]
2415 << "])" << tcu::TestLog::EndMessage;
2417 TCU_FAIL("Vertex is expected to be clipped and invisible, while it is visible.");
2421 n_clipped_vertices_real++;
2426 if (vertex_color_red_value == 0)
2428 m_testCtx.getLog() << tcu::TestLog::Message << "In primitive number [" << n_primitive_index << "] "
2429 << "vertex at (" << checkpoint_x << "," << checkpoint_y << ") "
2430 << "should not be clipped." << tcu::TestLog::EndMessage;
2432 TCU_FAIL("Vertex is unexpectedly clipped or invisible");
2436 n_not_clipped_vertices_real++;
2441 if (!all_vertices_are_clipped)
2443 /* Check fetched values from the shader (Point 2 of Basic Outline : "Use program that...") */
2444 if (fetch_culldistance_from_fs)
2446 for (glw::GLuint n_primitive_vertex = 0; n_primitive_vertex < primitive_vertices_count;
2447 n_primitive_vertex++)
2449 /* Get shader output value */
2450 glw::GLuint base_index_of_vertex_internal =
2451 base_index_of_primitive + n_primitive_vertex * stride_in_floats;
2452 glw::GLuint checkpoint_position_index_internal =
2453 base_index_of_vertex_internal + clipdistances_array_size + culldistances_array_size +
2454 2 /* ignore vertex coordinates */;
2455 glw::GLuint culldistances_index = base_index_of_vertex_internal + clipdistances_array_size;
2456 glw::GLint checkpoint_x_internal =
2457 glw::GLint(glw::GLfloat(m_to_width) * m_bo_data[checkpoint_position_index_internal]);
2458 glw::GLint checkpoint_y_internal =
2459 glw::GLint(glw::GLfloat(m_to_height) * m_bo_data[checkpoint_position_index_internal + 1]);
2460 glw::GLint vertex_color_red_value = readRedPixelValue(checkpoint_x_internal, checkpoint_y_internal);
2462 /* Calculate culldistances check sum hash */
2465 for (glw::GLuint n_clipdistance_entry = 0; n_clipdistance_entry < clipdistances_array_size;
2466 ++n_clipdistance_entry)
2468 sum += de::abs(m_bo_data[base_index_of_vertex_internal + n_clipdistance_entry]) *
2469 float(n_clipdistance_entry + 1);
2472 for (glw::GLuint n_culldistance_entry = 0; n_culldistance_entry < culldistances_array_size;
2473 ++n_culldistance_entry)
2475 sum += de::abs(m_bo_data[culldistances_index + n_culldistance_entry]) *
2476 float(n_culldistance_entry + 1 + clipdistances_array_size);
2479 /* limit sum and return */
2480 glw::GLint sum_hash =
2481 glw::GLint(sum / glw::GLfloat((clipdistances_array_size + culldistances_array_size) *
2482 (clipdistances_array_size + culldistances_array_size + 1)) *
2483 65535.f /* normalizing to short */);
2484 sum_hash = (sum_hash < 65536) ? sum_hash : 65535; /* clamping to short */
2486 /* Compare against setup value */
2487 if (std::abs(vertex_color_red_value - sum_hash) > 4 /* precision 4/65536 */)
2489 m_testCtx.getLog() << tcu::TestLog::Message << "Primitive number [" << n_primitive_index << "] "
2490 << "should have culldistance hash sum " << sum_hash
2491 << "but primitive vertex at (" << checkpoint_x << "," << checkpoint_y
2492 << ") has sum hash equal to " << vertex_color_red_value
2493 << tcu::TestLog::EndMessage;
2495 TCU_FAIL("Culled distances returned from fragment shader dose not match expected values.");
2502 /* sub_grid cell size is 3*3 */
2503 DE_ASSERT(m_render_primitives % 9 == 0);
2506 switch (primitive_mode)
2508 case PRIMITIVE_MODE_LINES:
2509 case PRIMITIVE_MODE_TRIANGLES:
2511 /* Validate culled primitives */
2512 if (culldistances_array_size == 0)
2514 DE_ASSERT(n_culled_primitives_real == 0);
2518 /* Each 3rd line or triangle should be culled by test design */
2519 DE_ASSERT(glw::GLsizei(n_culled_primitives_real) == m_render_primitives / 3);
2522 /* Validate clipped vertices */
2523 if (clipdistances_array_size == 0)
2525 DE_ASSERT(n_clipped_vertices_real == 0);
2529 #if defined(DE_DEBUG) && !defined(DE_COVERAGE_BUILD)
2530 glw::GLint one_third_of_rendered_primitives = (m_render_primitives - n_culled_primitives_real) / 3;
2531 glw::GLint n_clipped_vertices_expected = /* One third of primitives has 0th vertex clipped */
2532 one_third_of_rendered_primitives +
2533 /* One third of primitives clipped completely */
2534 one_third_of_rendered_primitives * primitive_vertices_count;
2536 DE_ASSERT(glw::GLint(n_clipped_vertices_real) == n_clipped_vertices_expected);
2542 case PRIMITIVE_MODE_POINTS:
2544 /* Validate culled primitives */
2545 if (culldistances_array_size == 0)
2547 DE_ASSERT(n_culled_primitives_real == 0);
2551 /* 2/3 points should be culled by test design */
2552 DE_ASSERT(glw::GLsizei(n_culled_primitives_real) == m_render_primitives * 2 / 3);
2555 /* Validate clipped vertices */
2556 if (clipdistances_array_size == 0)
2558 DE_ASSERT(n_clipped_vertices_real == 0);
2562 #if defined(DE_DEBUG) && !defined(DE_COVERAGE_BUILD)
2563 glw::GLint one_third_of_rendered_primitives = (m_render_primitives - n_culled_primitives_real) / 3;
2565 /* 2/3 of rendered points should be clipped by test design */
2566 DE_ASSERT(glw::GLint(n_clipped_vertices_real) == 2 * one_third_of_rendered_primitives);
2573 TCU_FAIL("Unknown primitive mode");
2577 /** Executes test iteration.
2579 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
2581 tcu::TestNode::IterateResult CullDistance::FunctionalTest::iterate()
2583 /* This test should only be executed if ARB_cull_distance is supported, or if
2584 * we're running a GL4.5 context
2586 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_cull_distance") &&
2587 !glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)))
2589 throw tcu::NotSupportedError("GL_ARB_cull_distance is not supported");
2592 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2593 bool has_succeeded = true;
2594 bool is_core = glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5));
2596 /* Retrieve important GL constant values */
2597 glw::GLint gl_max_clip_distances_value = 0;
2598 glw::GLint gl_max_combined_clip_and_cull_distances_value = 0;
2599 glw::GLint gl_max_cull_distances_value = 0;
2601 gl.getIntegerv(GL_MAX_CLIP_DISTANCES, &gl_max_clip_distances_value);
2602 gl.getIntegerv(GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES, &gl_max_combined_clip_and_cull_distances_value);
2603 gl.getIntegerv(GL_MAX_CULL_DISTANCES, &gl_max_cull_distances_value);
2604 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv() call(s) failed.");
2606 gl.genTextures(1, &m_to_id);
2607 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() call failed.");
2609 gl.bindTexture(GL_TEXTURE_2D, m_to_id);
2610 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() call failed.");
2612 gl.texStorage2D(GL_TEXTURE_2D, 1, /* levels */
2613 GL_R32F, m_to_width, m_to_height);
2614 GLU_EXPECT_NO_ERROR(gl.getError(), "glTexStorage2D() call failed.");
2616 /* Set up the draw/read FBO */
2617 gl.genFramebuffers(1, &m_fbo_id);
2618 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers() call failed.");
2620 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_id);
2621 GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer() call failed.");
2623 gl.framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_to_id, 0); /* level */
2624 GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferTexture2D() call failed.");
2626 /* Prepare a buffer object */
2627 gl.genBuffers(1, &m_bo_id);
2628 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers() call failed.");
2630 /* Prepare a VAO. We will configure separately for each iteration. */
2631 gl.genVertexArrays(1, &m_vao_id);
2632 GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays() call failed.");
2634 /* Iterate over all functional tests */
2637 bool redeclare_clipdistances_array;
2638 bool redeclare_culldistances_array;
2639 bool dynamic_index_writes;
2640 bool use_passthrough_gs;
2641 bool use_passthrough_ts;
2642 bool use_core_functionality;
2643 bool fetch_culldistances;
2644 } test_items[] = { /* Use the basic outline to test the basic functionality of cull distances. */
2646 true, /* redeclare_clipdistances_array */
2647 true, /* redeclare_culldistances_array */
2648 false, /* dynamic_index_writes */
2649 false, /* use_passthrough_gs */
2650 false, /* use_passthrough_ts */
2651 is_core, /* use_core_functionality */
2652 false /* fetch_culldistances */
2654 /* Use the basic outline but don't redeclare gl_ClipDistance with a size. */
2656 false, /* redeclare_clipdistances_array */
2657 true, /* redeclare_culldistances_array */
2658 false, /* dynamic_index_writes */
2659 false, /* use_passthrough_gs */
2660 false, /* use_passthrough_ts */
2661 is_core, /* use_core_functionality */
2662 false /* fetch_culldistances */
2664 /* Use the basic outline but don't redeclare gl_CullDistance with a size. */
2666 true, /* redeclare_clipdistances_array */
2667 false, /* redeclare_culldistances_array */
2668 false, /* dynamic_index_writes */
2669 false, /* use_passthrough_gs */
2670 false, /* use_passthrough_ts */
2671 is_core, /* use_core_functionality */
2672 false /* fetch_culldistances */
2674 /* Use the basic outline but don't redeclare either gl_ClipDistance or
2675 * gl_CullDistance with a size.
2678 false, /* redeclare_clipdistances_array */
2679 false, /* redeclare_culldistances_array */
2680 false, /* dynamic_index_writes */
2681 false, /* use_passthrough_gs */
2682 false, /* use_passthrough_ts */
2683 is_core, /* use_core_functionality */
2684 false /* fetch_culldistances */
2686 /* Use the basic outline but use dynamic indexing when writing the elements
2687 * of the gl_ClipDistance and gl_CullDistance arrays.
2690 true, /* redeclare_clipdistances_array */
2691 true, /* redeclare_culldistances_array */
2692 true, /* dynamic_index_writes */
2693 false, /* use_passthrough_gs */
2694 false, /* use_passthrough_ts */
2695 is_core, /* use_core_functionality */
2696 false /* fetch_culldistances */
2698 /* Use the basic outline but add a geometry shader to the program that
2699 * simply passes through all written clip and cull distances.
2702 true, /* redeclare_clipdistances_array */
2703 true, /* redeclare_culldistances_array */
2704 false, /* dynamic_index_writes */
2705 true, /* use_passthrough_gs */
2706 false, /* use_passthrough_ts */
2707 is_core, /* use_core_functionality */
2708 false /* fetch_culldistances */
2710 /* Use the basic outline but add a tessellation control and tessellation
2711 * evaluation shader to the program which simply pass through all written
2712 * clip and cull distances.
2715 true, /* redeclare_clipdistances_array */
2716 true, /* redeclare_culldistances_array */
2717 false, /* dynamic_index_writes */
2718 false, /* use_passthrough_gs */
2719 true, /* use_passthrough_ts */
2720 is_core, /* use_core_functionality */
2721 false /* fetch_culldistances */
2723 /* Test that using #extension with GL_ARB_cull_distance allows using the
2724 * feature even with an earlier version of GLSL. Also test that the
2725 * extension name is available as preprocessor #define.
2728 true, /* redeclare_clipdistances_array */
2729 true, /* redeclare_culldistances_array */
2730 false, /* dynamic_index_writes */
2731 false, /* use_passthrough_gs */
2732 false, /* use_passthrough_ts */
2733 false, /* use_core_functionality */
2734 false /* fetch_culldistances */
2736 /* Use a program that has only a vertex shader and a fragment shader.
2737 * The vertex shader should redeclare gl_ClipDistance with a size that
2738 * fits all enabled cull distances. Also redeclare gl_CullDistance with a
2739 * size. The sum of the two sizes should not be more than MAX_COMBINED_-
2740 * CLIP_AND_CULL_DISTANCES. The fragment shader should output the cull
2741 * distances written by the vertex shader by reading them from the built-in
2742 * array gl_CullDistance.
2745 true, /* redeclare_clipdistances_array */
2746 true, /* redeclare_culldistances_array */
2747 false, /* dynamic_index_writes */
2748 false, /* use_passthrough_gs */
2749 false, /* use_passthrough_ts */
2750 false, /* use_core_functionality */
2751 true /* fetch_culldistances */
2754 const glw::GLuint n_test_items = sizeof(test_items) / sizeof(test_items[0]);
2756 gl.viewport(0, 0, m_to_width, m_to_height);
2757 GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport() call failed.");
2759 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
2760 GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor() call failed.");
2762 for (glw::GLuint n_test_item = 0; n_test_item < n_test_items; ++n_test_item)
2764 /* Check for OpenGL feature support */
2765 if (test_items[n_test_item].use_passthrough_ts)
2767 if (!glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 0)) &&
2768 !m_context.getContextInfo().isExtensionSupported("GL_ARB_tessellation_shader"))
2770 continue; // no tessellation shader support
2774 const _test_item& current_test_item = test_items[n_test_item];
2775 const _primitive_mode primitive_modes[PRIMITIVE_MODE_COUNT] = { PRIMITIVE_MODE_LINES, PRIMITIVE_MODE_POINTS,
2776 PRIMITIVE_MODE_TRIANGLES };
2778 for (glw::GLuint primitive_mode_index = 0; primitive_mode_index < PRIMITIVE_MODE_COUNT; ++primitive_mode_index)
2780 _primitive_mode primitive_mode = primitive_modes[primitive_mode_index];
2782 /* Iterate over a set of gl_ClipDistances[] and gl_CullDistances[] array sizes */
2783 for (glw::GLint n_iteration = 0; n_iteration <= gl_max_combined_clip_and_cull_distances_value;
2786 glw::GLuint clipdistances_array_size = 0;
2787 glw::GLuint culldistances_array_size = 0;
2789 if (n_iteration != 0 && n_iteration <= gl_max_clip_distances_value)
2791 clipdistances_array_size = n_iteration;
2794 if ((gl_max_combined_clip_and_cull_distances_value - n_iteration) < gl_max_cull_distances_value)
2796 culldistances_array_size = gl_max_combined_clip_and_cull_distances_value - n_iteration;
2800 culldistances_array_size = gl_max_cull_distances_value;
2803 if (clipdistances_array_size == 0 && culldistances_array_size == 0)
2805 /* Skip the dummy iteration */
2809 if (current_test_item.fetch_culldistances && (primitive_mode != PRIMITIVE_MODE_POINTS))
2814 /* Create a program to run */
2815 buildPO(clipdistances_array_size, culldistances_array_size, current_test_item.dynamic_index_writes,
2816 primitive_mode, current_test_item.redeclare_clipdistances_array,
2817 current_test_item.redeclare_culldistances_array, current_test_item.use_core_functionality,
2818 current_test_item.use_passthrough_gs, current_test_item.use_passthrough_ts,
2819 current_test_item.fetch_culldistances);
2821 /* Initialize VAO data */
2822 configureVAO(clipdistances_array_size, culldistances_array_size, primitive_mode);
2824 /* Run GLSL program and check results */
2825 executeRenderTest(clipdistances_array_size, culldistances_array_size, primitive_mode,
2826 current_test_item.use_passthrough_ts, current_test_item.fetch_culldistances);
2828 } /* for (all iterations) */
2829 } /* for (all test modes) */
2830 } /* for (all test items) */
2835 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2839 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
2845 /** Returns pixel red component read from texture at position x, y.
2847 * @param x x-coordinate to read pixel color component from
2848 * @param y y-coordinate to read pixel color component from
2850 glw::GLint CullDistance::FunctionalTest::readRedPixelValue(glw::GLint x, glw::GLint y)
2852 glw::GLint result = -1;
2854 DE_ASSERT(x >= 0 && (glw::GLuint)x < m_to_width);
2855 DE_ASSERT(y >= 0 && (glw::GLuint)y < m_to_height);
2857 result = m_to_pixel_data_cache[(m_to_width * y + x) * m_to_pixel_data_cache_color_components];
2862 /** Reads texture into m_to_pixel_data_cache.
2863 * Texture size determined by fields m_to_width, m_to_height
2865 void CullDistance::FunctionalTest::readTexturePixels()
2867 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2869 m_to_pixel_data_cache.clear();
2871 m_to_pixel_data_cache.resize(m_to_width * m_to_height * m_to_pixel_data_cache_color_components);
2873 /* Read vertex from texture */
2874 gl.readPixels(0, /* x */
2876 m_to_width, /* width */
2877 m_to_height, /* height */
2878 GL_RGBA, GL_UNSIGNED_SHORT, &m_to_pixel_data_cache[0]);
2879 GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() call failed.");
2884 * @param context Rendering context handle.
2886 CullDistance::NegativeTest::NegativeTest(deqp::Context& context)
2887 : TestCase(context, "negative", "Cull Distance Negative Test")
2890 , m_temp_buffer(DE_NULL)
2893 /* Left blank on purpose */
2896 /** @brief Cull Distance Negative Test deinitialization */
2897 void CullDistance::NegativeTest::deinit()
2899 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2903 gl.deleteShader(m_fs_id);
2910 gl.deleteProgram(m_po_id);
2917 gl.deleteShader(m_vs_id);
2922 if (m_temp_buffer != DE_NULL)
2924 delete[] m_temp_buffer;
2926 m_temp_buffer = DE_NULL;
2930 /** @brief Get string description of test with given parameters
2932 * @param [in] n_test_iteration Test iteration number
2933 * @param [in] should_redeclare_output_variables Indicate whether test redeclared gl_ClipDistance and gl_CullDistance
2934 * @param [in] use_dynamic_index_based_writes Indicate whether test used dynamic index-based setters
2936 * @return String containing description.
2938 std::string CullDistance::NegativeTest::getTestDescription(int n_test_iteration, bool should_redeclare_output_variables,
2939 bool use_dynamic_index_based_writes)
2941 std::stringstream stream;
2943 stream << "Test iteration [" << n_test_iteration << "] which uses a vertex shader that:\n\n"
2944 << ((should_redeclare_output_variables) ?
2945 "* redeclares gl_ClipDistance and gl_CullDistance arrays\n" :
2946 "* does not redeclare gl_ClipDistance and gl_CullDistance arrays\n")
2947 << ((use_dynamic_index_based_writes) ? "* uses dynamic index-based writes\n" : "* uses static writes\n");
2949 return stream.str();
2952 /** Executes test iteration.
2954 * @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
2956 tcu::TestNode::IterateResult CullDistance::NegativeTest::iterate()
2958 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2960 /* Build the test shaders. */
2961 const glw::GLchar* token_dynamic_index_based_writes = "DYNAMIC_INDEX_BASED_WRITES";
2962 const glw::GLchar* token_insert_static_writes = "INSERT_STATIC_WRITES";
2963 const glw::GLchar* token_n_gl_clipdistance_entries = "N_GL_CLIPDISTANCE_ENTRIES";
2964 const glw::GLchar* token_n_gl_culldistance_entries = "N_GL_CULLDISTANCE_ENTRIES";
2965 const glw::GLchar* token_redeclare_output_variables = "REDECLARE_OUTPUT_VARIABLES";
2967 const glw::GLchar* fs_body = "#version 130\n"
2973 const glw::GLchar* vs_body_preamble = "#version 130\n"
2975 " #extension GL_ARB_cull_distance : require\n"
2978 const glw::GLchar* vs_body_main = "#ifdef REDECLARE_OUTPUT_VARIABLES\n"
2979 " out float gl_ClipDistance[N_GL_CLIPDISTANCE_ENTRIES];\n"
2980 " out float gl_CullDistance[N_GL_CULLDISTANCE_ENTRIES];\n"
2985 "#ifdef DYNAMIC_INDEX_BASED_WRITES\n"
2986 " for (int n_clipdistance_entry = 0;\n"
2987 " n_clipdistance_entry < N_GL_CLIPDISTANCE_ENTRIES;\n"
2988 " ++n_clipdistance_entry)\n"
2990 " gl_ClipDistance[n_clipdistance_entry] = float(n_clipdistance_entry) / "
2991 "float(N_GL_CLIPDISTANCE_ENTRIES);\n"
2994 " for (int n_culldistance_entry = 0;\n"
2995 " n_culldistance_entry < N_GL_CULLDISTANCE_ENTRIES;\n"
2996 " ++n_culldistance_entry)\n"
2998 " gl_CullDistance[n_culldistance_entry] = float(n_culldistance_entry) / "
2999 "float(N_GL_CULLDISTANCE_ENTRIES);\n"
3002 " INSERT_STATIC_WRITES\n"
3006 /* This test should only be executed if ARB_cull_distance is supported, or if
3007 * we're running a GL4.5 context
3009 if (!m_context.getContextInfo().isExtensionSupported("GL_ARB_cull_distance") &&
3010 !glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)))
3012 throw tcu::NotSupportedError("GL_ARB_cull_distance is not supported");
3015 /* It only makes sense to run this test if GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES
3016 * is lower than a sum of GL_MAX_CLIP_DISTANCES and GL_MAX_CLIP_CULL_DISTANCES.
3018 glw::GLint gl_max_clip_distances_value = 0;
3019 glw::GLint gl_max_combined_clip_and_cull_distances_value = 0;
3020 glw::GLint gl_max_cull_distances_value = 0;
3021 glw::GLuint n_gl_clipdistance_array_items = 0;
3022 std::string n_gl_clipdistance_array_items_string;
3023 glw::GLuint n_gl_culldistance_array_items = 0;
3024 std::string n_gl_culldistance_array_items_string;
3025 std::string static_write_shader_body_part;
3027 gl.getIntegerv(GL_MAX_CLIP_DISTANCES, &gl_max_clip_distances_value);
3028 gl.getIntegerv(GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES, &gl_max_combined_clip_and_cull_distances_value);
3029 gl.getIntegerv(GL_MAX_CULL_DISTANCES, &gl_max_cull_distances_value);
3031 if (gl_max_clip_distances_value + gl_max_cull_distances_value < gl_max_combined_clip_and_cull_distances_value)
3033 m_testCtx.getLog() << tcu::TestLog::Message
3034 << "GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES is larger than or equal to "
3035 "the sum of GL_MAX_CLIP_DISTANCES and GL_MAX_CULL_DISTANCES. Skipping."
3036 << tcu::TestLog::EndMessage;
3038 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3043 n_gl_clipdistance_array_items = gl_max_clip_distances_value;
3044 n_gl_culldistance_array_items = gl_max_combined_clip_and_cull_distances_value - gl_max_clip_distances_value + 1;
3046 /* Determine the number of items we will want the gl_ClipDistance and gl_CullDistance arrays
3047 * to hold for test iterations that will re-declare the built-in output variables.
3050 std::stringstream temp_sstream;
3052 temp_sstream << n_gl_clipdistance_array_items;
3054 n_gl_clipdistance_array_items_string = temp_sstream.str();
3058 std::stringstream temp_sstream;
3060 temp_sstream << n_gl_culldistance_array_items;
3062 n_gl_culldistance_array_items_string = temp_sstream.str();
3065 /* Form the "static write" shader body part. */
3067 std::stringstream temp_sstream;
3069 temp_sstream << "gl_ClipDistance[" << n_gl_clipdistance_array_items_string.c_str() << "] = 0.0f;\n"
3070 << "gl_CullDistance[" << n_gl_culldistance_array_items_string.c_str() << "] = 0.0f;\n";
3072 static_write_shader_body_part = temp_sstream.str();
3075 /* Prepare GL objects before we continue */
3076 glw::GLint compile_status = GL_FALSE;
3078 m_fs_id = gl.createShader(GL_FRAGMENT_SHADER);
3079 m_po_id = gl.createProgram();
3080 m_vs_id = gl.createShader(GL_VERTEX_SHADER);
3082 GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram() / glCreateShader() calls failed.");
3084 gl.attachShader(m_po_id, m_fs_id);
3085 gl.attachShader(m_po_id, m_vs_id);
3087 GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader() call(s) failed.");
3089 gl.shaderSource(m_fs_id, 1, /* count */
3090 &fs_body, DE_NULL); /* length */
3091 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource() call failed.");
3093 gl.compileShader(m_fs_id);
3094 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader() call failed.");
3096 gl.getShaderiv(m_fs_id, GL_COMPILE_STATUS, &compile_status);
3097 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
3099 if (compile_status == GL_FALSE)
3101 TCU_FAIL("Fragment shader failed to compile.");
3104 /* Run three separate test iterations. */
3107 bool should_redeclare_output_variables;
3108 bool use_dynamic_index_based_writes;
3109 } test_items[] = { /* Negative Test 1 */
3112 /* Negative Test 2 */
3115 /* Negative Test 3 */
3118 const unsigned int n_test_items = sizeof(test_items) / sizeof(test_items[0]);
3120 for (unsigned int n_test_item = 0; n_test_item < n_test_items; ++n_test_item)
3122 const _test_item& current_test_item = test_items[n_test_item];
3124 /* Prepare vertex shader body */
3125 std::size_t token_position = std::string::npos;
3126 std::stringstream vs_body_sstream;
3127 std::string vs_body_string;
3129 vs_body_sstream << vs_body_preamble << "\n";
3131 if (current_test_item.should_redeclare_output_variables)
3133 vs_body_sstream << "#define " << token_redeclare_output_variables << "\n";
3136 if (current_test_item.use_dynamic_index_based_writes)
3138 vs_body_sstream << "#define " << token_dynamic_index_based_writes << "\n";
3141 vs_body_sstream << vs_body_main;
3143 /* Replace tokens with meaningful values */
3144 vs_body_string = vs_body_sstream.str();
3146 while ((token_position = vs_body_string.find(token_n_gl_clipdistance_entries)) != std::string::npos)
3148 vs_body_string = vs_body_string.replace(token_position, strlen(token_n_gl_clipdistance_entries),
3149 n_gl_clipdistance_array_items_string);
3152 while ((token_position = vs_body_string.find(token_n_gl_culldistance_entries)) != std::string::npos)
3154 vs_body_string = vs_body_string.replace(token_position, strlen(token_n_gl_clipdistance_entries),
3155 n_gl_culldistance_array_items_string);
3158 while ((token_position = vs_body_string.find(token_insert_static_writes)) != std::string::npos)
3160 vs_body_string = vs_body_string.replace(token_position, strlen(token_insert_static_writes),
3161 static_write_shader_body_part);
3164 /* Try to compile the vertex shader */
3165 glw::GLint compile_status_internal = GL_FALSE;
3166 const char* vs_body_raw_ptr = vs_body_string.c_str();
3168 gl.shaderSource(m_vs_id, 1, /* count */
3169 &vs_body_raw_ptr, DE_NULL); /* length */
3170 GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource() call failed.");
3172 gl.compileShader(m_vs_id);
3173 GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader() call failed.");
3175 gl.getShaderiv(m_vs_id, GL_COMPILE_STATUS, &compile_status_internal);
3176 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
3178 if (compile_status_internal == GL_FALSE)
3180 glw::GLint buffer_size = 0;
3182 /* Log the compilation error */
3183 m_testCtx.getLog() << tcu::TestLog::Message
3184 << getTestDescription(n_test_item, current_test_item.should_redeclare_output_variables,
3185 current_test_item.use_dynamic_index_based_writes)
3186 << "has failed (as expected) to compile with the following info log:\n\n"
3187 << tcu::TestLog::EndMessage;
3189 gl.getShaderiv(m_vs_id, GL_INFO_LOG_LENGTH, &buffer_size);
3190 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
3192 m_temp_buffer = new glw::GLchar[buffer_size + 1];
3194 memset(m_temp_buffer, 0, buffer_size + 1);
3196 gl.getShaderInfoLog(m_vs_id, buffer_size, DE_NULL, /* length */
3198 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog() call failed.");
3200 m_testCtx.getLog() << tcu::TestLog::Message << m_temp_buffer << tcu::TestLog::EndMessage;
3202 delete[] m_temp_buffer;
3203 m_temp_buffer = DE_NULL;
3205 /* Move on to the next iteration */
3209 /* Try to link the program object */
3210 glw::GLint link_status = GL_FALSE;
3212 gl.linkProgram(m_po_id);
3213 GLU_EXPECT_NO_ERROR(gl.getError(), "glLinkProgram() call failed.");
3215 gl.getProgramiv(m_po_id, GL_LINK_STATUS, &link_status);
3216 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv() call failed.");
3218 if (link_status == GL_TRUE)
3220 m_testCtx.getLog() << tcu::TestLog::Message
3221 << getTestDescription(n_test_item, current_test_item.should_redeclare_output_variables,
3222 current_test_item.use_dynamic_index_based_writes)
3223 << "has linked successfully which is invalid!" << tcu::TestLog::EndMessage;
3225 TCU_FAIL("Program object has linked successfully, even though the process should have failed.");
3229 glw::GLint buffer_size = 0;
3231 m_testCtx.getLog() << tcu::TestLog::Message
3232 << getTestDescription(n_test_item, current_test_item.should_redeclare_output_variables,
3233 current_test_item.use_dynamic_index_based_writes)
3234 << "has failed (as expected) to link with the following info log:\n\n"
3235 << tcu::TestLog::EndMessage;
3237 gl.getProgramiv(m_po_id, GL_INFO_LOG_LENGTH, &buffer_size);
3238 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv() call failed.");
3240 m_temp_buffer = new glw::GLchar[buffer_size + 1];
3242 memset(m_temp_buffer, 0, buffer_size + 1);
3244 gl.getProgramInfoLog(m_po_id, buffer_size, DE_NULL, /* length */
3246 GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramInfoLog() call failed.");
3248 m_testCtx.getLog() << tcu::TestLog::Message << m_temp_buffer << tcu::TestLog::EndMessage;
3250 delete[] m_temp_buffer;
3251 m_temp_buffer = DE_NULL;
3253 } /* for (all test items) */
3256 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3263 * @param context Rendering context.
3265 CullDistance::Tests::Tests(deqp::Context& context) : TestCaseGroup(context, "cull_distance", "Cull Distance Test Suite")
3269 /** Initializes the test group contents. */
3270 void CullDistance::Tests::init()
3272 addChild(new CullDistance::APICoverageTest(m_context));
3273 addChild(new CullDistance::FunctionalTest(m_context));
3274 addChild(new CullDistance::NegativeTest(m_context));
3276 } /* glcts namespace */