1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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.
21 * \brief Geometry shader tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fGeometryShaderTests.hpp"
26 #include "gluRenderContext.hpp"
27 #include "gluTextureUtil.hpp"
28 #include "gluObjectWrapper.hpp"
29 #include "gluPixelTransfer.hpp"
30 #include "gluContextInfo.hpp"
31 #include "gluCallLogWrapper.hpp"
32 #include "tcuRenderTarget.hpp"
33 #include "tcuTestLog.hpp"
34 #include "tcuVectorUtil.hpp"
35 #include "tcuImageCompare.hpp"
36 #include "tcuTextureUtil.hpp"
37 #include "glsStateQueryUtil.hpp"
39 #include "gluStrUtil.hpp"
40 #include "deStringUtil.hpp"
41 #include "deUniquePtr.hpp"
44 #include "sglrContext.hpp"
45 #include "sglrReferenceContext.hpp"
46 #include "sglrGLContext.hpp"
47 #include "sglrReferenceUtils.hpp"
49 #include "glwDefs.hpp"
50 #include "glwEnums.hpp"
51 #include "glwFunctions.hpp"
66 using namespace gls::StateQueryUtil;
68 const int TEST_CANVAS_SIZE = 256;
70 static const char* const s_commonShaderSourceVertex = "#version 310 es\n"
71 "in highp vec4 a_position;\n"
72 "in highp vec4 a_color;\n"
73 "out highp vec4 v_geom_FragColor;\n"
76 " gl_Position = a_position;\n"
77 " gl_PointSize = 1.0;\n"
78 " v_geom_FragColor = a_color;\n"
80 static const char* const s_commonShaderSourceFragment = "#version 310 es\n"
81 "layout(location = 0) out mediump vec4 fragColor;\n"
82 "in mediump vec4 v_frag_FragColor;\n"
85 " fragColor = v_frag_FragColor;\n"
87 static const char* const s_expandShaderSourceGeometryBody = "in highp vec4 v_geom_FragColor[];\n"
88 "out highp vec4 v_frag_FragColor;\n"
92 " const highp vec4 offset0 = vec4(-0.07, -0.01, 0.0, 0.0);\n"
93 " const highp vec4 offset1 = vec4( 0.03, -0.03, 0.0, 0.0);\n"
94 " const highp vec4 offset2 = vec4(-0.01, 0.08, 0.0, 0.0);\n"
95 " highp vec4 yoffset = float(gl_PrimitiveIDIn) * vec4(0.02, 0.1, 0.0, 0.0);\n"
97 " for (highp int ndx = 0; ndx < gl_in.length(); ndx++)\n"
99 " gl_Position = gl_in[ndx].gl_Position + offset0 + yoffset;\n"
100 " gl_PrimitiveID = gl_PrimitiveIDIn;\n"
101 " v_frag_FragColor = v_geom_FragColor[ndx];\n"
104 " gl_Position = gl_in[ndx].gl_Position + offset1 + yoffset;\n"
105 " gl_PrimitiveID = gl_PrimitiveIDIn;\n"
106 " v_frag_FragColor = v_geom_FragColor[ndx];\n"
109 " gl_Position = gl_in[ndx].gl_Position + offset2 + yoffset;\n"
110 " gl_PrimitiveID = gl_PrimitiveIDIn;\n"
111 " v_frag_FragColor = v_geom_FragColor[ndx];\n"
117 std::string inputTypeToGLString (rr::GeometryShaderInputType inputType)
121 case rr::GEOMETRYSHADERINPUTTYPE_POINTS: return "points";
122 case rr::GEOMETRYSHADERINPUTTYPE_LINES: return "lines";
123 case rr::GEOMETRYSHADERINPUTTYPE_LINES_ADJACENCY: return "lines_adjacency";
124 case rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES: return "triangles";
125 case rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES_ADJACENCY: return "triangles_adjacency";
132 std::string outputTypeToGLString (rr::GeometryShaderOutputType outputType)
136 case rr::GEOMETRYSHADEROUTPUTTYPE_POINTS: return "points";
137 case rr::GEOMETRYSHADEROUTPUTTYPE_LINE_STRIP: return "line_strip";
138 case rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP: return "triangle_strip";
145 std::string primitiveTypeToString(GLenum primitive)
149 case GL_POINTS: return "points";
150 case GL_LINES: return "lines";
151 case GL_LINE_LOOP: return "line_loop";
152 case GL_LINE_STRIP: return "line_strip";
153 case GL_LINES_ADJACENCY: return "lines_adjacency";
154 case GL_LINE_STRIP_ADJACENCY: return "line_strip_adjacency";
155 case GL_TRIANGLES: return "triangles";
156 case GL_TRIANGLE_STRIP: return "triangle_strip";
157 case GL_TRIANGLE_FAN: return "triangle_fan";
158 case GL_TRIANGLES_ADJACENCY: return "triangles_adjacency";
159 case GL_TRIANGLE_STRIP_ADJACENCY: return "triangle_strip_adjacency";
166 struct OutputCountPatternSpec
168 OutputCountPatternSpec (int count);
169 OutputCountPatternSpec (int count0, int count1);
171 std::vector<int> pattern;
174 OutputCountPatternSpec::OutputCountPatternSpec (int count)
176 pattern.push_back(count);
179 OutputCountPatternSpec::OutputCountPatternSpec (int count0, int count1)
181 pattern.push_back(count0);
182 pattern.push_back(count1);
185 class VertexExpanderShader : public sglr::ShaderProgram
188 VertexExpanderShader (rr::GeometryShaderInputType inputType, rr::GeometryShaderOutputType outputType);
190 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
191 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
192 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
195 size_t calcOutputVertices (rr::GeometryShaderInputType inputType) const;
196 std::string genGeometrySource (rr::GeometryShaderInputType inputType, rr::GeometryShaderOutputType outputType) const;
199 VertexExpanderShader::VertexExpanderShader (rr::GeometryShaderInputType inputType, rr::GeometryShaderOutputType outputType)
200 : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
201 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
202 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
203 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
204 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
205 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
206 << sglr::pdec::VertexSource(s_commonShaderSourceVertex)
207 << sglr::pdec::FragmentSource(s_commonShaderSourceFragment)
208 << sglr::pdec::GeometryShaderDeclaration(inputType, outputType, calcOutputVertices(inputType))
209 << sglr::pdec::GeometrySource(genGeometrySource(inputType, outputType).c_str()))
213 void VertexExpanderShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
215 for (int ndx = 0; ndx < numPackets; ++ndx)
217 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
218 packets[ndx]->pointSize = 1.0f;
219 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
223 void VertexExpanderShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
225 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
226 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
227 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
230 void VertexExpanderShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
232 DE_UNREF(invocationID);
234 for (int ndx = 0; ndx < numPackets; ++ndx)
235 for (int verticeNdx = 0; verticeNdx < verticesIn; ++verticeNdx)
237 const tcu::Vec4 offsets[] =
239 tcu::Vec4(-0.07f, -0.01f, 0.0f, 0.0f),
240 tcu::Vec4( 0.03f, -0.03f, 0.0f, 0.0f),
241 tcu::Vec4(-0.01f, 0.08f, 0.0f, 0.0f)
243 const tcu::Vec4 yoffset = float(packets[ndx].primitiveIDIn) * tcu::Vec4(0.02f, 0.1f, 0, 0);
245 // Create new primitive at every input vertice
246 const rr::VertexPacket* vertex = packets[ndx].vertices[verticeNdx];
248 output.EmitVertex(vertex->position + offsets[0] + yoffset, vertex->pointSize, vertex->outputs, packets[ndx].primitiveIDIn);
249 output.EmitVertex(vertex->position + offsets[1] + yoffset, vertex->pointSize, vertex->outputs, packets[ndx].primitiveIDIn);
250 output.EmitVertex(vertex->position + offsets[2] + yoffset, vertex->pointSize, vertex->outputs, packets[ndx].primitiveIDIn);
251 output.EndPrimitive();
255 size_t VertexExpanderShader::calcOutputVertices (rr::GeometryShaderInputType inputType) const
259 case rr::GEOMETRYSHADERINPUTTYPE_POINTS: return 1 * 3;
260 case rr::GEOMETRYSHADERINPUTTYPE_LINES: return 2 * 3;
261 case rr::GEOMETRYSHADERINPUTTYPE_LINES_ADJACENCY: return 4 * 3;
262 case rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES: return 3 * 3;
263 case rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES_ADJACENCY: return 6 * 3;
270 std::string VertexExpanderShader::genGeometrySource (rr::GeometryShaderInputType inputType, rr::GeometryShaderOutputType outputType) const
272 std::ostringstream str;
274 str << "#version 310 es\n";
275 str << "#extension GL_EXT_geometry_shader : require\n";
276 str << "layout(" << inputTypeToGLString(inputType) << ") in;\n";
277 str << "layout(" << outputTypeToGLString(outputType) << ", max_vertices = " << calcOutputVertices(inputType) << ") out;";
279 str << s_expandShaderSourceGeometryBody;
284 class VertexEmitterShader : public sglr::ShaderProgram
287 VertexEmitterShader (int emitCountA, int endCountA, int emitCountB, int endCountB, rr::GeometryShaderOutputType outputType);
289 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
290 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
291 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
294 std::string genGeometrySource (int emitCountA, int endCountA, int emitCountB, int endCountB, rr::GeometryShaderOutputType outputType) const;
302 VertexEmitterShader::VertexEmitterShader (int emitCountA, int endCountA, int emitCountB, int endCountB, rr::GeometryShaderOutputType outputType)
303 : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
304 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
305 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
306 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
307 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
308 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
309 << sglr::pdec::VertexSource(s_commonShaderSourceVertex)
310 << sglr::pdec::FragmentSource(s_commonShaderSourceFragment)
311 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS, outputType, emitCountA + emitCountB)
312 << sglr::pdec::GeometrySource(genGeometrySource(emitCountA, endCountA, emitCountB, endCountB, outputType).c_str()))
313 , m_emitCountA (emitCountA)
314 , m_endCountA (endCountA)
315 , m_emitCountB (emitCountB)
316 , m_endCountB (endCountB)
320 void VertexEmitterShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
322 for (int ndx = 0; ndx < numPackets; ++ndx)
324 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
325 packets[ndx]->pointSize = 1.0f;
326 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
330 void VertexEmitterShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
332 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
333 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
334 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
337 void VertexEmitterShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
339 DE_UNREF(verticesIn);
340 DE_UNREF(invocationID);
342 for (int ndx = 0; ndx < numPackets; ++ndx)
344 const tcu::Vec4 positions[] =
346 tcu::Vec4(-0.5f, 0.5f, 0.0f, 0.0f),
347 tcu::Vec4( 0.0f, 0.1f, 0.0f, 0.0f),
348 tcu::Vec4( 0.5f, 0.5f, 0.0f, 0.0f),
349 tcu::Vec4( 0.7f, -0.2f, 0.0f, 0.0f),
350 tcu::Vec4( 0.2f, 0.2f, 0.0f, 0.0f),
351 tcu::Vec4( 0.4f, -0.3f, 0.0f, 0.0f),
354 // Create new primitive at this point
355 const rr::VertexPacket* vertex = packets[ndx].vertices[0];
357 for (int i = 0; i < m_emitCountA; ++i)
358 output.EmitVertex(vertex->position + positions[i], vertex->pointSize, vertex->outputs, packets[ndx].primitiveIDIn);
360 for (int i = 0; i < m_endCountA; ++i)
361 output.EndPrimitive();
363 for (int i = 0; i < m_emitCountB; ++i)
364 output.EmitVertex(vertex->position + positions[m_emitCountA + i], vertex->pointSize, vertex->outputs, packets[ndx].primitiveIDIn);
366 for (int i = 0; i < m_endCountB; ++i)
367 output.EndPrimitive();
371 std::string VertexEmitterShader::genGeometrySource (int emitCountA, int endCountA, int emitCountB, int endCountB, rr::GeometryShaderOutputType outputType) const
373 std::ostringstream str;
375 str << "#version 310 es\n";
376 str << "#extension GL_EXT_geometry_shader : require\n";
377 str << "layout(points) in;\n";
378 str << "layout(" << outputTypeToGLString(outputType) << ", max_vertices = " << (emitCountA+emitCountB) << ") out;";
381 str << "in highp vec4 v_geom_FragColor[];\n"
382 "out highp vec4 v_frag_FragColor;\n"
386 " const highp vec4 position0 = vec4(-0.5, 0.5, 0.0, 0.0);\n"
387 " const highp vec4 position1 = vec4( 0.0, 0.1, 0.0, 0.0);\n"
388 " const highp vec4 position2 = vec4( 0.5, 0.5, 0.0, 0.0);\n"
389 " const highp vec4 position3 = vec4( 0.7, -0.2, 0.0, 0.0);\n"
390 " const highp vec4 position4 = vec4( 0.2, 0.2, 0.0, 0.0);\n"
391 " const highp vec4 position5 = vec4( 0.4, -0.3, 0.0, 0.0);\n"
394 for (int i = 0; i < emitCountA; ++i)
395 str << " gl_Position = gl_in[0].gl_Position + position" << i << ";\n"
396 " gl_PrimitiveID = gl_PrimitiveIDIn;\n"
397 " v_frag_FragColor = v_geom_FragColor[0];\n"
401 for (int i = 0; i < endCountA; ++i)
402 str << " EndPrimitive();\n";
404 for (int i = 0; i < emitCountB; ++i)
405 str << " gl_Position = gl_in[0].gl_Position + position" << (emitCountA + i) << ";\n"
406 " gl_PrimitiveID = gl_PrimitiveIDIn;\n"
407 " v_frag_FragColor = v_geom_FragColor[0];\n"
411 for (int i = 0; i < endCountB; ++i)
412 str << " EndPrimitive();\n";
420 class VertexVaryingShader : public sglr::ShaderProgram
423 VertexVaryingShader (int vertexOut, int geometryOut);
425 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
426 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
427 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
430 static sglr::pdec::ShaderProgramDeclaration genProgramDeclaration (int vertexOut, int geometryOut);
432 const int m_vertexOut;
433 const int m_geometryOut;
436 VertexVaryingShader::VertexVaryingShader (int vertexOut, int geometryOut)
437 : sglr::ShaderProgram (genProgramDeclaration(vertexOut, geometryOut))
438 , m_vertexOut (vertexOut)
439 , m_geometryOut (geometryOut)
443 void VertexVaryingShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
445 // vertex shader is no-op
446 if (m_vertexOut == -1)
449 for (int ndx = 0; ndx < numPackets; ++ndx)
451 const tcu::Vec4 color = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
453 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
454 packets[ndx]->pointSize = 1.0f;
462 packets[ndx]->outputs[0] = color;
466 packets[ndx]->outputs[0] = color * 0.5f;
467 packets[ndx]->outputs[1] = color.swizzle(2,1,0,3) * 0.5f;
476 void VertexVaryingShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
478 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
480 switch (m_geometryOut)
483 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
484 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
488 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
489 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx));
493 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
494 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readTriangleVarying<float>(packets[packetNdx], context, 0, fragNdx)
495 + rr::readTriangleVarying<float>(packets[packetNdx], context, 1, fragNdx).swizzle(1, 0, 2, 3));
504 void VertexVaryingShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
506 DE_UNREF(invocationID);
508 const tcu::Vec4 vertexOffset(-0.2f, -0.2f, 0, 0);
510 if (m_vertexOut == -1)
513 const tcu::Vec4 inputColor = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
514 rr::GenericVec4 outputs[2];
517 switch (m_geometryOut)
523 outputs[0] = inputColor;
527 outputs[0] = inputColor * 0.5f;
528 outputs[1] = inputColor.swizzle(1, 0, 2, 3) * 0.5f;
535 for (int ndx = 0; ndx < numPackets; ++ndx)
537 output.EmitVertex(tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f) + vertexOffset, 1.0f, outputs, packets[ndx].primitiveIDIn);
538 output.EmitVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f) + vertexOffset, 1.0f, outputs, packets[ndx].primitiveIDIn);
539 output.EmitVertex(tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f) + vertexOffset, 1.0f, outputs, packets[ndx].primitiveIDIn);
540 output.EndPrimitive();
545 // vertex is not a no-op
546 for (int ndx = 0; ndx < numPackets; ++ndx)
548 for (int verticeNdx = 0; verticeNdx < verticesIn; ++verticeNdx)
550 tcu::Vec4 inputColor;
551 rr::GenericVec4 outputs[2];
557 inputColor = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
561 inputColor = packets[ndx].vertices[verticeNdx]->outputs[0].get<float>();
565 inputColor = (packets[ndx].vertices[verticeNdx]->outputs[0].get<float>() * 0.5f)
566 + (packets[ndx].vertices[verticeNdx]->outputs[1].get<float>().swizzle(2, 1, 0, 3) * 0.5f);
574 switch (m_geometryOut)
580 outputs[0] = inputColor;
584 outputs[0] = inputColor * 0.5f;
585 outputs[1] = inputColor.swizzle(1, 0, 2, 3) * 0.5f;
592 output.EmitVertex(packets[ndx].vertices[verticeNdx]->position + vertexOffset, packets[ndx].vertices[verticeNdx]->pointSize, outputs, packets[ndx].primitiveIDIn);
594 output.EndPrimitive();
599 sglr::pdec::ShaderProgramDeclaration VertexVaryingShader::genProgramDeclaration (int vertexOut, int geometryOut)
601 sglr::pdec::ShaderProgramDeclaration decl;
602 std::ostringstream vertexSource;
603 std::ostringstream fragmentSource;
604 std::ostringstream geometrySource;
607 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
608 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT);
610 for (int i = 0; i < vertexOut; ++i)
611 decl << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT);
612 for (int i = 0; i < geometryOut; ++i)
613 decl << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT);
616 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
617 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_TRIANGLES, rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP, 3);
621 vertexSource << "#version 310 es\n"
622 "in highp vec4 a_position;\n"
623 "in highp vec4 a_color;\n";
628 vertexSource << "void main (void)\n"
634 for (int i = 0; i < vertexOut; ++i)
635 vertexSource << "out highp vec4 v_geom_" << i << ";\n";
637 vertexSource << "void main (void)\n"
639 "\tgl_Position = a_position;\n"
640 "\tgl_PointSize = 1.0;\n";
647 vertexSource << "\tv_geom_0 = a_color;\n";
651 vertexSource << "\tv_geom_0 = a_color * 0.5;\n";
652 vertexSource << "\tv_geom_1 = a_color.zyxw * 0.5;\n";
658 vertexSource << "}\n";
663 fragmentSource << "#version 310 es\n"
664 "layout(location = 0) out mediump vec4 fragColor;\n";
666 for (int i = 0; i < geometryOut; ++i)
667 fragmentSource << "in mediump vec4 v_frag_" << i << ";\n";
669 fragmentSource << "void main (void)\n"
674 fragmentSource << "\tfragColor = vec4(1.0, 0.0, 0.0, 1.0);\n";
678 fragmentSource << "\tfragColor = v_frag_0;\n";
682 fragmentSource << "\tfragColor = v_frag_0 + v_frag_1.yxzw;\n";
688 fragmentSource << "}\n";
692 geometrySource << "#version 310 es\n"
693 "#extension GL_EXT_geometry_shader : require\n"
694 "layout(triangles) in;\n"
695 "layout(triangle_strip, max_vertices = 3) out;\n";
697 for (int i = 0; i < vertexOut; ++i)
698 geometrySource << "in highp vec4 v_geom_" << i << "[];\n";
699 for (int i = 0; i < geometryOut; ++i)
700 geometrySource << "out highp vec4 v_frag_" << i << ";\n";
702 geometrySource << "void main (void)\n"
704 "\thighp vec4 offset = vec4(-0.2, -0.2, 0.0, 0.0);\n"
705 "\thighp vec4 inputColor;\n\n";
707 for (int vertexNdx = 0; vertexNdx < 3; ++vertexNdx)
712 geometrySource << "\tinputColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
713 "\tgl_Position = vec4(" << ((vertexNdx==0) ? ("0.0, 0.0") : ((vertexNdx==1) ? ("1.0, 0.0") : ("1.0, 1.0"))) << ", 0.0, 1.0) + offset;\n"
714 "\tgl_PrimitiveID = gl_PrimitiveIDIn;\n";
721 geometrySource << "\tinputColor = vec4(1.0, 0.0, 0.0, 1.0);\n";
725 geometrySource << "\tinputColor = v_geom_0[" << vertexNdx << "];\n";
729 geometrySource << "\tinputColor = v_geom_0[" << vertexNdx << "] * 0.5 + v_geom_1[" << vertexNdx << "].zyxw * 0.5;\n";
735 geometrySource << "\tgl_Position = gl_in[" << vertexNdx << "].gl_Position + offset;\n"
736 "\tgl_PrimitiveID = gl_PrimitiveIDIn;\n";
745 geometrySource << "\tv_frag_0 = inputColor;\n";
749 geometrySource << "\tv_frag_0 = inputColor * 0.5;\n";
750 geometrySource << "\tv_frag_1 = inputColor.yxzw * 0.5;\n";
757 geometrySource << "\tEmitVertex();\n\n";
760 geometrySource << "\tEndPrimitive();\n"
764 << sglr::pdec::VertexSource(vertexSource.str().c_str())
765 << sglr::pdec::FragmentSource(fragmentSource.str().c_str())
766 << sglr::pdec::GeometrySource(geometrySource.str().c_str());
770 class OutputCountShader : public sglr::ShaderProgram
773 OutputCountShader (const OutputCountPatternSpec& spec);
775 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
776 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
777 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
780 std::string genGeometrySource (const OutputCountPatternSpec& spec) const;
781 size_t getPatternEmitCount (const OutputCountPatternSpec& spec) const;
783 const int m_patternLength;
784 const int m_patternMaxEmitCount;
785 const OutputCountPatternSpec m_spec;
788 OutputCountShader::OutputCountShader (const OutputCountPatternSpec& spec)
789 : sglr::ShaderProgram (sglr::pdec::ShaderProgramDeclaration()
790 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
791 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
792 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
793 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
794 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
795 << sglr::pdec::VertexSource(s_commonShaderSourceVertex)
796 << sglr::pdec::FragmentSource(s_commonShaderSourceFragment)
797 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS, rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP, getPatternEmitCount(spec))
798 << sglr::pdec::GeometrySource(genGeometrySource(spec).c_str()))
799 , m_patternLength ((int)spec.pattern.size())
800 , m_patternMaxEmitCount ((int)getPatternEmitCount(spec))
805 void OutputCountShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
807 for (int ndx = 0; ndx < numPackets; ++ndx)
809 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
810 packets[ndx]->pointSize = 1.0f;
811 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
815 void OutputCountShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
817 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
818 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
819 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
822 void OutputCountShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
824 DE_UNREF(verticesIn);
825 DE_UNREF(invocationID);
827 const float rowHeight = 2.0f / (float)m_patternLength;
828 const float colWidth = 2.0f / (float)m_patternMaxEmitCount;
830 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
832 // Create triangle strip at this point
833 const rr::VertexPacket* vertex = packets[packetNdx].vertices[0];
834 const int emitCount = m_spec.pattern[packets[packetNdx].primitiveIDIn];
836 for (int ndx = 0; ndx < emitCount / 2; ++ndx)
838 output.EmitVertex(vertex->position + tcu::Vec4(2 * ndx * colWidth, 0.0, 0.0, 0.0), vertex->pointSize, vertex->outputs, packets[packetNdx].primitiveIDIn);
839 output.EmitVertex(vertex->position + tcu::Vec4(2 * ndx * colWidth, rowHeight, 0.0, 0.0), vertex->pointSize, vertex->outputs, packets[packetNdx].primitiveIDIn);
841 output.EndPrimitive();
845 std::string OutputCountShader::genGeometrySource (const OutputCountPatternSpec& spec) const
847 std::ostringstream str;
849 // draw row with a triangle strip, always make rectangles
850 for (int ndx = 0; ndx < (int)spec.pattern.size(); ++ndx)
851 DE_ASSERT(spec.pattern[ndx] % 2 == 0);
853 str << "#version 310 es\n";
854 str << "#extension GL_EXT_geometry_shader : require\n";
855 str << "layout(points) in;\n";
856 str << "layout(triangle_strip, max_vertices = " << getPatternEmitCount(spec) << ") out;";
859 str << "in highp vec4 v_geom_FragColor[];\n"
860 "out highp vec4 v_frag_FragColor;\n"
864 " const highp float rowHeight = 2.0 / float(" << spec.pattern.size() << ");\n"
865 " const highp float colWidth = 2.0 / float(" << getPatternEmitCount(spec) << ");\n"
868 str << " highp int emitCount = ";
869 for (int ndx = 0; ndx < (int)spec.pattern.size() - 1; ++ndx)
870 str << "(gl_PrimitiveIDIn == " << ndx << ") ? (" << spec.pattern[ndx] << ") : (";
871 str << spec.pattern[(int)spec.pattern.size() - 1]
872 << ((spec.pattern.size() == 1) ? ("") : (")"))
875 str << " for (highp int ndx = 0; ndx < emitCount / 2; ndx++)\n"
877 " gl_Position = gl_in[0].gl_Position + vec4(float(ndx) * 2.0 * colWidth, 0.0, 0.0, 0.0);\n"
878 " v_frag_FragColor = v_geom_FragColor[0];\n"
881 " gl_Position = gl_in[0].gl_Position + vec4(float(ndx) * 2.0 * colWidth, rowHeight, 0.0, 0.0);\n"
882 " v_frag_FragColor = v_geom_FragColor[0];\n"
890 size_t OutputCountShader::getPatternEmitCount (const OutputCountPatternSpec& spec) const
892 return *std::max_element(spec.pattern.begin(), spec.pattern.end());
895 class BuiltinVariableShader : public sglr::ShaderProgram
901 TEST_PRIMITIVE_ID_IN,
907 BuiltinVariableShader (VariableTest test);
909 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
910 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
911 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
913 static const char* getTestAttributeName (VariableTest test);
916 std::string genGeometrySource (VariableTest test) const;
917 std::string genVertexSource (VariableTest test) const;
918 std::string genFragmentSource (VariableTest test) const;
920 const VariableTest m_test;
923 BuiltinVariableShader::BuiltinVariableShader (VariableTest test)
924 : sglr::ShaderProgram (sglr::pdec::ShaderProgramDeclaration()
925 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
926 << sglr::pdec::VertexAttribute(getTestAttributeName(test), rr::GENERICVECTYPE_FLOAT)
927 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
928 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
929 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
930 << sglr::pdec::VertexSource(genVertexSource(test))
931 << sglr::pdec::FragmentSource(genFragmentSource(test))
932 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS,
933 ((test == TEST_POINT_SIZE) ? (rr::GEOMETRYSHADEROUTPUTTYPE_POINTS) : (rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP)),
934 ((test == TEST_POINT_SIZE) ? (1) : (3)))
935 << sglr::pdec::GeometrySource(genGeometrySource(test).c_str()))
940 void BuiltinVariableShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
942 for (int ndx = 0; ndx < numPackets; ++ndx)
944 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
945 packets[ndx]->pointSize = 1.0f;
946 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
950 void BuiltinVariableShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
952 const tcu::Vec4 red = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
953 const tcu::Vec4 green = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
954 const tcu::Vec4 blue = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
955 const tcu::Vec4 yellow = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
956 const tcu::Vec4 colors[4] = { yellow, red, green, blue };
958 if (m_test == TEST_POINT_SIZE || m_test == TEST_PRIMITIVE_ID_IN)
960 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
961 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
962 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
964 else if (m_test == TEST_PRIMITIVE_ID)
966 const tcu::Vec4 color = colors[context.primitiveID % 4];
968 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
969 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
970 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
976 void BuiltinVariableShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
978 DE_UNREF(verticesIn);
979 DE_UNREF(invocationID);
981 const tcu::Vec4 red = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
982 const tcu::Vec4 green = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
983 const tcu::Vec4 blue = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
984 const tcu::Vec4 yellow = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
985 const tcu::Vec4 colors[4] = { red, green, blue, yellow };
987 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
989 const rr::VertexPacket* vertex = packets[packetNdx].vertices[0];
991 if (m_test == TEST_POINT_SIZE)
993 rr::GenericVec4 fragColor;
994 const float pointSize = vertex->outputs[0].get<float>().x() + 1.0f;
996 fragColor = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
997 output.EmitVertex(vertex->position, pointSize, &fragColor, packets[packetNdx].primitiveIDIn);
999 else if (m_test == TEST_PRIMITIVE_ID_IN)
1001 rr::GenericVec4 fragColor;
1002 fragColor = colors[packets[packetNdx].primitiveIDIn % 4];
1004 output.EmitVertex(vertex->position + tcu::Vec4(0.05f, 0.0f, 0.0f, 0.0f), 1.0f, &fragColor, packets[packetNdx].primitiveIDIn);
1005 output.EmitVertex(vertex->position - tcu::Vec4(0.05f, 0.0f, 0.0f, 0.0f), 1.0f, &fragColor, packets[packetNdx].primitiveIDIn);
1006 output.EmitVertex(vertex->position + tcu::Vec4(0.0f, 0.05f, 0.0f, 0.0f), 1.0f, &fragColor, packets[packetNdx].primitiveIDIn);
1008 else if (m_test == TEST_PRIMITIVE_ID)
1010 const int primitiveID = (int)deFloatFloor(vertex->outputs[0].get<float>().x()) + 3;
1012 output.EmitVertex(vertex->position + tcu::Vec4(0.05f, 0.0f, 0.0f, 0.0f), 1.0f, vertex->outputs, primitiveID);
1013 output.EmitVertex(vertex->position - tcu::Vec4(0.05f, 0.0f, 0.0f, 0.0f), 1.0f, vertex->outputs, primitiveID);
1014 output.EmitVertex(vertex->position + tcu::Vec4(0.0f, 0.05f, 0.0f, 0.0f), 1.0f, vertex->outputs, primitiveID);
1017 DE_ASSERT(DE_FALSE);
1019 output.EndPrimitive();
1023 const char* BuiltinVariableShader::getTestAttributeName (VariableTest test)
1027 case TEST_POINT_SIZE: return "a_pointSize";
1028 case TEST_PRIMITIVE_ID_IN: return "";
1029 case TEST_PRIMITIVE_ID: return "a_primitiveID";
1031 DE_ASSERT(DE_FALSE);
1036 std::string BuiltinVariableShader::genGeometrySource (VariableTest test) const
1038 std::ostringstream buf;
1040 buf << "#version 310 es\n"
1041 "#extension GL_EXT_geometry_shader : require\n";
1043 if (test == TEST_POINT_SIZE)
1044 buf << "#extension GL_EXT_geometry_point_size : require\n";
1046 buf << "layout(points) in;\n";
1048 if (test == TEST_POINT_SIZE)
1049 buf << "layout(points, max_vertices = 1) out;\n";
1051 buf << "layout(triangle_strip, max_vertices = 3) out;\n";
1053 if (test == TEST_POINT_SIZE)
1054 buf << "in highp vec4 v_geom_pointSize[];\n";
1055 else if (test == TEST_PRIMITIVE_ID)
1056 buf << "in highp vec4 v_geom_primitiveID[];\n";
1058 if (test != TEST_PRIMITIVE_ID)
1059 buf << "out highp vec4 v_frag_FragColor;\n";
1062 "void main (void)\n"
1065 if (test == TEST_POINT_SIZE)
1067 buf << " gl_Position = gl_in[0].gl_Position;\n"
1068 " gl_PointSize = v_geom_pointSize[0].x + 1.0;\n"
1069 " v_frag_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
1072 else if (test == TEST_PRIMITIVE_ID_IN)
1074 buf << " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
1075 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
1076 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
1077 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
1078 " const highp vec4 colors[4] = vec4[4](red, green, blue, yellow);\n"
1080 " gl_Position = gl_in[0].gl_Position + vec4(0.05, 0.0, 0.0, 0.0);\n"
1081 " v_frag_FragColor = colors[gl_PrimitiveIDIn % 4];\n"
1084 " gl_Position = gl_in[0].gl_Position - vec4(0.05, 0.0, 0.0, 0.0);\n"
1085 " v_frag_FragColor = colors[gl_PrimitiveIDIn % 4];\n"
1088 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.05, 0.0, 0.0);\n"
1089 " v_frag_FragColor = colors[gl_PrimitiveIDIn % 4];\n"
1092 else if (test == TEST_PRIMITIVE_ID)
1094 buf << " gl_Position = gl_in[0].gl_Position + vec4(0.05, 0.0, 0.0, 0.0);\n"
1095 " gl_PrimitiveID = int(floor(v_geom_primitiveID[0].x)) + 3;\n"
1098 " gl_Position = gl_in[0].gl_Position - vec4(0.05, 0.0, 0.0, 0.0);\n"
1099 " gl_PrimitiveID = int(floor(v_geom_primitiveID[0].x)) + 3;\n"
1102 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.05, 0.0, 0.0);\n"
1103 " gl_PrimitiveID = int(floor(v_geom_primitiveID[0].x)) + 3;\n"
1108 DE_ASSERT(DE_FALSE);
1115 std::string BuiltinVariableShader::genVertexSource (VariableTest test) const
1117 std::ostringstream buf;
1119 buf << "#version 310 es\n"
1120 "in highp vec4 a_position;\n";
1122 if (test == TEST_POINT_SIZE)
1123 buf << "in highp vec4 a_pointSize;\n";
1124 else if (test == TEST_PRIMITIVE_ID)
1125 buf << "in highp vec4 a_primitiveID;\n";
1127 if (test == TEST_POINT_SIZE)
1128 buf << "out highp vec4 v_geom_pointSize;\n";
1129 else if (test == TEST_PRIMITIVE_ID)
1130 buf << "out highp vec4 v_geom_primitiveID;\n";
1132 buf << "void main (void)\n"
1134 " gl_Position = a_position;\n"
1135 " gl_PointSize = 1.0;\n";
1137 if (test == TEST_POINT_SIZE)
1138 buf << " v_geom_pointSize = a_pointSize;\n";
1139 else if (test == TEST_PRIMITIVE_ID)
1140 buf << " v_geom_primitiveID = a_primitiveID;\n";
1147 std::string BuiltinVariableShader::genFragmentSource (VariableTest test) const
1149 if (test == TEST_POINT_SIZE || test == TEST_PRIMITIVE_ID_IN)
1150 return s_commonShaderSourceFragment;
1151 else if (test == TEST_PRIMITIVE_ID)
1153 return "#version 310 es\n"
1154 "#extension GL_EXT_geometry_shader : require\n"
1155 "layout(location = 0) out mediump vec4 fragColor;\n"
1156 "void main (void)\n"
1158 " const mediump vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
1159 " const mediump vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
1160 " const mediump vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
1161 " const mediump vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
1162 " const mediump vec4 colors[4] = vec4[4](yellow, red, green, blue);\n"
1163 " fragColor = colors[gl_PrimitiveID % 4];\n"
1168 DE_ASSERT(DE_FALSE);
1173 class VaryingOutputCountShader : public sglr::ShaderProgram
1187 EMIT_COUNT_VERTEX_0 = 6,
1188 EMIT_COUNT_VERTEX_1 = 0,
1189 EMIT_COUNT_VERTEX_2 = -1,
1190 EMIT_COUNT_VERTEX_3 = 10,
1193 VaryingOutputCountShader (VaryingSource source, int maxEmitCount, bool instanced);
1195 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
1196 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
1197 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
1199 static const char* getAttributeName (VaryingSource test);
1202 static std::string genGeometrySource (VaryingSource test, int maxEmitCount, bool instanced);
1203 static std::string genVertexSource (VaryingSource test);
1205 const VaryingSource m_test;
1206 const sglr::UniformSlot& m_sampler;
1207 const sglr::UniformSlot& m_emitCount;
1208 const int m_maxEmitCount;
1209 const bool m_instanced;
1212 VaryingOutputCountShader::VaryingOutputCountShader (VaryingSource source, int maxEmitCount, bool instanced)
1213 : sglr::ShaderProgram (sglr::pdec::ShaderProgramDeclaration()
1214 << sglr::pdec::Uniform("u_sampler", glu::TYPE_SAMPLER_2D)
1215 << sglr::pdec::Uniform("u_emitCount", glu::TYPE_INT_VEC4)
1216 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1217 << sglr::pdec::VertexAttribute(getAttributeName(source), rr::GENERICVECTYPE_FLOAT)
1218 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
1219 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
1220 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
1221 << sglr::pdec::VertexSource(genVertexSource(source))
1222 << sglr::pdec::FragmentSource(s_commonShaderSourceFragment)
1223 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS,
1224 rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP,
1226 (instanced) ? (4) : (1))
1227 << sglr::pdec::GeometrySource(genGeometrySource(source, maxEmitCount, instanced).c_str()))
1229 , m_sampler (getUniformByName("u_sampler"))
1230 , m_emitCount (getUniformByName("u_emitCount"))
1231 , m_maxEmitCount (maxEmitCount)
1232 , m_instanced (instanced)
1236 void VaryingOutputCountShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
1238 for (int ndx = 0; ndx < numPackets; ++ndx)
1240 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
1241 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
1245 void VaryingOutputCountShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1247 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1248 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1249 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
1252 void VaryingOutputCountShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
1254 DE_UNREF(verticesIn);
1256 const tcu::Vec4 red = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
1257 const tcu::Vec4 green = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
1258 const tcu::Vec4 blue = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
1259 const tcu::Vec4 yellow = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
1260 const tcu::Vec4 colors[4] = { red, green, blue, yellow };
1262 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1264 const rr::VertexPacket* vertex = packets[packetNdx].vertices[0];
1266 tcu::Vec4 color = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
1268 if (m_test == READ_ATTRIBUTE)
1270 emitCount = (int)vertex->outputs[0].get<float>()[(m_instanced) ? (invocationID) : (0)];
1271 color = tcu::Vec4((emitCount < 10) ? (0.0f) : (1.0f), (emitCount > 10) ? (0.0f) : (1.0f), 1.0f, 1.0f);
1273 else if (m_test == READ_UNIFORM)
1275 const int primitiveNdx = (m_instanced) ? (invocationID) : ((int)vertex->outputs[0].get<float>().x());
1277 DE_ASSERT(primitiveNdx >= 0);
1278 DE_ASSERT(primitiveNdx < 4);
1280 emitCount = m_emitCount.value.i4[primitiveNdx];
1281 color = colors[primitiveNdx];
1283 else if (m_test == READ_TEXTURE)
1285 const int primitiveNdx = (m_instanced) ? (invocationID) : ((int)vertex->outputs[0].get<float>().x());
1286 const tcu::Vec2 texCoord = tcu::Vec2(1.0f / 8.0f + primitiveNdx / 4.0f, 0.5f);
1287 const tcu::Vec4 texColor = m_sampler.sampler.tex2D->sample(texCoord.x(), texCoord.y(), 0.0f);
1289 DE_ASSERT(primitiveNdx >= 0);
1290 DE_ASSERT(primitiveNdx < 4);
1292 color = colors[primitiveNdx];
1295 if (texColor.x() > 0.0f)
1296 emitCount += (EMIT_COUNT_VERTEX_0 == -1) ? (m_maxEmitCount) : (EMIT_COUNT_VERTEX_0);
1297 if (texColor.y() > 0.0f)
1298 emitCount += (EMIT_COUNT_VERTEX_1 == -1) ? (m_maxEmitCount) : (EMIT_COUNT_VERTEX_1);
1299 if (texColor.z() > 0.0f)
1300 emitCount += (EMIT_COUNT_VERTEX_2 == -1) ? (m_maxEmitCount) : (EMIT_COUNT_VERTEX_2);
1301 if (texColor.w() > 0.0f)
1302 emitCount += (EMIT_COUNT_VERTEX_3 == -1) ? (m_maxEmitCount) : (EMIT_COUNT_VERTEX_3);
1305 DE_ASSERT(DE_FALSE);
1307 for (int ndx = 0; ndx < (int)emitCount / 2; ++ndx)
1309 const float angle = (float(ndx) + 0.5f) / float(emitCount / 2) * 3.142f;
1310 const tcu::Vec4 basePosition = (m_instanced) ?
1311 (vertex->position + tcu::Vec4(deFloatCos(float(invocationID)), deFloatSin(float(invocationID)), 0.0f, 0.0f) * 0.5f) :
1313 const tcu::Vec4 position0 = basePosition + tcu::Vec4(deFloatCos(angle), deFloatSin(angle), 0.0f, 0.0f) * 0.15f;
1314 const tcu::Vec4 position1 = basePosition + tcu::Vec4(deFloatCos(angle), -deFloatSin(angle), 0.0f, 0.0f) * 0.15f;
1315 rr::GenericVec4 fragColor;
1319 output.EmitVertex(position0, 0.0f, &fragColor, packets[packetNdx].primitiveIDIn);
1320 output.EmitVertex(position1, 0.0f, &fragColor, packets[packetNdx].primitiveIDIn);
1323 output.EndPrimitive();
1327 const char* VaryingOutputCountShader::getAttributeName (VaryingSource test)
1331 case READ_ATTRIBUTE: return "a_emitCount";
1332 case READ_UNIFORM: return "a_vertexNdx";
1333 case READ_TEXTURE: return "a_vertexNdx";
1335 DE_ASSERT(DE_FALSE);
1340 std::string VaryingOutputCountShader::genGeometrySource (VaryingSource test, int maxEmitCount, bool instanced)
1342 std::ostringstream buf;
1344 buf << "#version 310 es\n"
1345 "#extension GL_EXT_geometry_shader : require\n"
1346 "layout(points" << ((instanced) ? (",invocations=4") : ("")) << ") in;\n"
1347 "layout(triangle_strip, max_vertices = " << maxEmitCount << ") out;\n";
1349 if (test == READ_ATTRIBUTE)
1350 buf << "in highp vec4 v_geom_emitCount[];\n";
1351 else if (test == READ_UNIFORM)
1352 buf << "in highp vec4 v_geom_vertexNdx[];\n"
1353 "uniform highp ivec4 u_emitCount;\n";
1355 buf << "in highp vec4 v_geom_vertexNdx[];\n"
1356 "uniform highp sampler2D u_sampler;\n";
1358 buf << "out highp vec4 v_frag_FragColor;\n"
1360 "void main (void)\n"
1365 if (test == READ_ATTRIBUTE)
1367 buf << " highp vec4 attrEmitCounts = v_geom_emitCount[0];\n"
1368 " mediump int emitCount = int(attrEmitCounts[" << ((instanced) ? ("gl_InvocationID") : ("0")) << "]);\n";
1370 else if (test == READ_UNIFORM)
1372 buf << " mediump int primitiveNdx = " << ((instanced) ? ("gl_InvocationID") : ("int(v_geom_vertexNdx[0].x)")) << ";\n"
1373 " mediump int emitCount = u_emitCount[primitiveNdx];\n";
1375 else if (test == READ_TEXTURE)
1377 buf << " highp float primitiveNdx = " << ((instanced) ? ("float(gl_InvocationID)") : ("v_geom_vertexNdx[0].x")) << ";\n"
1378 " highp vec2 texCoord = vec2(1.0 / 8.0 + primitiveNdx / 4.0, 0.5);\n"
1379 " highp vec4 texColor = texture(u_sampler, texCoord);\n"
1380 " mediump int emitCount = 0;\n"
1381 " if (texColor.x > 0.0)\n"
1382 " emitCount += " << ((EMIT_COUNT_VERTEX_0 == -1) ? (maxEmitCount) : (EMIT_COUNT_VERTEX_0)) << ";\n"
1383 " if (texColor.y > 0.0)\n"
1384 " emitCount += " << ((EMIT_COUNT_VERTEX_1 == -1) ? (maxEmitCount) : (EMIT_COUNT_VERTEX_1)) << ";\n"
1385 " if (texColor.z > 0.0)\n"
1386 " emitCount += " << ((EMIT_COUNT_VERTEX_2 == -1) ? (maxEmitCount) : (EMIT_COUNT_VERTEX_2)) << ";\n"
1387 " if (texColor.w > 0.0)\n"
1388 " emitCount += " << ((EMIT_COUNT_VERTEX_3 == -1) ? (maxEmitCount) : (EMIT_COUNT_VERTEX_3)) << ";\n";
1391 DE_ASSERT(DE_FALSE);
1395 if (test == READ_ATTRIBUTE)
1397 // We don't want color to be compile time constant
1398 buf << " highp vec4 color = vec4((emitCount < 10) ? (0.0) : (1.0), (emitCount > 10) ? (0.0) : (1.0), 1.0, 1.0);\n";
1400 else if (test == READ_UNIFORM || test == READ_TEXTURE)
1403 " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
1404 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
1405 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
1406 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
1407 " const highp vec4 colors[4] = vec4[4](red, green, blue, yellow);\n"
1408 " highp vec4 color = colors[int(primitiveNdx)];\n";
1411 DE_ASSERT(DE_FALSE);
1414 " highp vec4 basePos = " << ((instanced) ? ("gl_in[0].gl_Position + 0.5 * vec4(cos(float(gl_InvocationID)), sin(float(gl_InvocationID)), 0.0, 0.0)") : ("gl_in[0].gl_Position")) << ";\n"
1415 " for (mediump int i = 0; i < emitCount / 2; i++)\n"
1417 " highp float angle = (float(i) + 0.5) / float(emitCount / 2) * 3.142;\n"
1418 " gl_Position = basePos + vec4(cos(angle), sin(angle), 0.0, 0.0) * 0.15;\n"
1419 " v_frag_FragColor = color;\n"
1421 " gl_Position = basePos + vec4(cos(angle), -sin(angle), 0.0, 0.0) * 0.15;\n"
1422 " v_frag_FragColor = color;\n"
1430 std::string VaryingOutputCountShader::genVertexSource (VaryingSource test)
1432 std::ostringstream buf;
1434 buf << "#version 310 es\n"
1435 "in highp vec4 a_position;\n";
1437 if (test == READ_ATTRIBUTE)
1439 buf << "in highp vec4 a_emitCount;\n";
1440 buf << "out highp vec4 v_geom_emitCount;\n";
1442 else if (test == READ_UNIFORM || test == READ_TEXTURE)
1444 buf << "in highp vec4 a_vertexNdx;\n";
1445 buf << "out highp vec4 v_geom_vertexNdx;\n";
1448 buf << "void main (void)\n"
1450 " gl_Position = a_position;\n";
1452 if (test == READ_ATTRIBUTE)
1453 buf << " v_geom_emitCount = a_emitCount;\n";
1454 else if (test == READ_UNIFORM || test == READ_TEXTURE)
1455 buf << " v_geom_vertexNdx = a_vertexNdx;\n";
1462 class InvocationCountShader : public sglr::ShaderProgram
1467 CASE_FIXED_OUTPUT_COUNTS = 0,
1468 CASE_DIFFERENT_OUTPUT_COUNTS,
1473 InvocationCountShader (int numInvocations, OutputCase testCase);
1476 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
1477 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
1478 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
1480 static std::string genGeometrySource (int numInvocations, OutputCase testCase);
1481 static size_t getNumVertices (int numInvocations, OutputCase testCase);
1483 const int m_numInvocations;
1484 const OutputCase m_testCase;
1487 InvocationCountShader::InvocationCountShader (int numInvocations, OutputCase testCase)
1488 : sglr::ShaderProgram (sglr::pdec::ShaderProgramDeclaration()
1489 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1490 << sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
1491 << sglr::pdec::VertexToGeometryVarying(rr::GENERICVECTYPE_FLOAT)
1492 << sglr::pdec::GeometryToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
1493 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
1494 << sglr::pdec::VertexSource(s_commonShaderSourceVertex)
1495 << sglr::pdec::FragmentSource(s_commonShaderSourceFragment)
1496 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS,
1497 rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP,
1498 getNumVertices(numInvocations, testCase),
1500 << sglr::pdec::GeometrySource(genGeometrySource(numInvocations, testCase).c_str()))
1501 , m_numInvocations (numInvocations)
1502 , m_testCase (testCase)
1506 void InvocationCountShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
1508 for (int ndx = 0; ndx < numPackets; ++ndx)
1510 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
1511 packets[ndx]->outputs[0] = rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
1515 void InvocationCountShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1517 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1518 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1519 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, rr::readVarying<float>(packets[packetNdx], context, 0, fragNdx));
1522 void InvocationCountShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
1524 DE_UNREF(verticesIn);
1526 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1528 const float l_angle = float(invocationID) / float(m_numInvocations) * 5.5f;
1529 const float l_radius = 0.6f;
1531 const rr::VertexPacket* vertex = packets[packetNdx].vertices[0];
1533 if (m_testCase == CASE_FIXED_OUTPUT_COUNTS)
1535 const tcu::Vec4 position0 = vertex->position + tcu::Vec4(deFloatCos(l_angle) * (l_radius - 0.1f), deFloatSin(l_angle) * (l_radius - 0.1f), 0.0f, 0.0f);
1536 const tcu::Vec4 position1 = vertex->position + tcu::Vec4(deFloatCos(l_angle+0.1f) * l_radius, deFloatSin(l_angle+0.1f) * l_radius, 0.0f, 0.0f);
1537 const tcu::Vec4 position2 = vertex->position + tcu::Vec4(deFloatCos(l_angle-0.1f) * l_radius, deFloatSin(l_angle-0.1f) * l_radius, 0.0f, 0.0f);
1539 rr::GenericVec4 tipColor;
1540 rr::GenericVec4 baseColor;
1542 tipColor = tcu::Vec4(1.0, 1.0, 0.0, 1.0) * packets[packetNdx].vertices[0]->outputs[0].get<float>();
1543 baseColor = tcu::Vec4(1.0, 0.0, 0.0, 1.0) * packets[packetNdx].vertices[0]->outputs[0].get<float>();
1545 output.EmitVertex(position0, 0.0f, &tipColor, packets[packetNdx].primitiveIDIn);
1546 output.EmitVertex(position1, 0.0f, &baseColor, packets[packetNdx].primitiveIDIn);
1547 output.EmitVertex(position2, 0.0f, &baseColor, packets[packetNdx].primitiveIDIn);
1548 output.EndPrimitive();
1550 else if (m_testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
1552 const tcu::Vec4 color = tcu::Vec4(float(invocationID % 2), (((invocationID / 2) % 2) == 0) ? (1.0f) : (0.0f), 1.0f, 1.0f);
1553 const tcu::Vec4 basePosition = vertex->position + tcu::Vec4(deFloatCos(l_angle) * l_radius, deFloatSin(l_angle) * l_radius, 0.0f, 0.0f);
1554 const int numNgonVtx = invocationID + 3;
1556 rr::GenericVec4 outColor;
1559 for (int ndx = 0; ndx + 1 < numNgonVtx; ndx += 2)
1561 const float subAngle = (float(ndx) + 1.0f) / float(numNgonVtx) * 3.141f;
1563 output.EmitVertex(basePosition + tcu::Vec4(deFloatCos(subAngle) * 0.1f, deFloatSin(subAngle) * 0.1f, 0.0f, 0.0f), 0.0f, &outColor, packets[packetNdx].primitiveIDIn);
1564 output.EmitVertex(basePosition + tcu::Vec4(deFloatCos(subAngle) * 0.1f, deFloatSin(subAngle) * -0.1f, 0.0f, 0.0f), 0.0f, &outColor, packets[packetNdx].primitiveIDIn);
1567 if ((numNgonVtx % 2) == 1)
1568 output.EmitVertex(basePosition + tcu::Vec4(-0.1f, 0.0f, 0.0f, 0.0f), 0.0f, &outColor, packets[packetNdx].primitiveIDIn);
1570 output.EndPrimitive();
1575 std::string InvocationCountShader::genGeometrySource (int numInvocations, OutputCase testCase)
1577 const int maxVertices = (int)getNumVertices(numInvocations, testCase);
1578 std::ostringstream buf;
1580 buf << "#version 310 es\n"
1581 "#extension GL_EXT_geometry_shader : require\n"
1582 "layout(points, invocations = " << numInvocations << ") in;\n"
1583 "layout(triangle_strip, max_vertices = " << maxVertices << ") out;\n"
1585 "in highp vec4 v_geom_FragColor[];\n"
1586 "out highp vec4 v_frag_FragColor;\n"
1590 " highp float l_angle = float(gl_InvocationID) / float(" << numInvocations << ") * 5.5;\n"
1591 " highp float l_radius = 0.6;\n"
1594 if (testCase == CASE_FIXED_OUTPUT_COUNTS)
1596 buf << " v_frag_FragColor = vec4(1.0, 1.0, 0.0, 1.0) * v_geom_FragColor[0];\n"
1597 " gl_Position = gl_in[0].gl_Position + vec4(cos(l_angle) * (l_radius - 0.1), sin(l_angle) * (l_radius - 0.1), 0.0, 0.0);\n"
1600 " v_frag_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * v_geom_FragColor[0];\n"
1601 " gl_Position = gl_in[0].gl_Position + vec4(cos(l_angle+0.1) * l_radius, sin(l_angle+0.1) * l_radius, 0.0, 0.0);\n"
1604 " v_frag_FragColor = vec4(1.0, 0.0, 0.0, 1.0) * v_geom_FragColor[0];\n"
1605 " gl_Position = gl_in[0].gl_Position + vec4(cos(l_angle-0.1) * l_radius, sin(l_angle-0.1) * l_radius, 0.0, 0.0);\n"
1608 else if (testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
1610 buf << " highp vec4 l_color = vec4(float(gl_InvocationID % 2), (((gl_InvocationID / 2) % 2) == 0) ? (1.0) : (0.0), 1.0, 1.0);\n"
1611 " highp vec4 basePosition = gl_in[0].gl_Position + vec4(cos(l_angle) * l_radius, sin(l_angle) * l_radius, 0.0, 0.0);\n"
1612 " mediump int numNgonVtx = gl_InvocationID + 3;\n"
1614 " for (int ndx = 0; ndx + 1 < numNgonVtx; ndx += 2)\n"
1616 " highp float sub_angle = (float(ndx) + 1.0) / float(numNgonVtx) * 3.141;\n"
1618 " v_frag_FragColor = l_color;\n"
1619 " gl_Position = basePosition + vec4(cos(sub_angle) * 0.1, sin(sub_angle) * 0.1, 0.0, 0.0);\n"
1622 " v_frag_FragColor = l_color;\n"
1623 " gl_Position = basePosition + vec4(cos(sub_angle) * 0.1, sin(sub_angle) * -0.1, 0.0, 0.0);\n"
1626 " if ((numNgonVtx % 2) == 1)\n"
1628 " v_frag_FragColor = l_color;\n"
1629 " gl_Position = basePosition + vec4(-0.1, 0.0, 0.0, 0.0);\n"
1641 size_t InvocationCountShader::getNumVertices (int numInvocations, OutputCase testCase)
1645 case CASE_FIXED_OUTPUT_COUNTS: return 3;
1646 case CASE_DIFFERENT_OUTPUT_COUNTS: return (size_t)(2 + numInvocations);
1653 class InstancedExpansionShader : public sglr::ShaderProgram
1656 InstancedExpansionShader (int numInvocations);
1659 void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const;
1660 void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const;
1661 void shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const;
1663 static std::string genVertexSource (void);
1664 static std::string genFragmentSource (void);
1665 static std::string genGeometrySource (int numInvocations);
1667 const int m_numInvocations;
1670 InstancedExpansionShader::InstancedExpansionShader (int numInvocations)
1671 : sglr::ShaderProgram (sglr::pdec::ShaderProgramDeclaration()
1672 << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
1673 << sglr::pdec::VertexAttribute("a_offset", rr::GENERICVECTYPE_FLOAT)
1674 << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
1675 << sglr::pdec::VertexSource(genVertexSource())
1676 << sglr::pdec::FragmentSource(genFragmentSource())
1677 << sglr::pdec::GeometryShaderDeclaration(rr::GEOMETRYSHADERINPUTTYPE_POINTS,
1678 rr::GEOMETRYSHADEROUTPUTTYPE_TRIANGLE_STRIP,
1681 << sglr::pdec::GeometrySource(genGeometrySource(numInvocations).c_str()))
1682 , m_numInvocations (numInvocations)
1686 void InstancedExpansionShader::shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const
1688 for (int ndx = 0; ndx < numPackets; ++ndx)
1690 packets[ndx]->position = rr::readVertexAttribFloat(inputs[0], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx) +
1691 rr::readVertexAttribFloat(inputs[1], packets[ndx]->instanceNdx, packets[ndx]->vertexNdx);
1695 void InstancedExpansionShader::shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const
1699 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1700 for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
1701 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
1704 void InstancedExpansionShader::shadePrimitives (rr::GeometryEmitter& output, int verticesIn, const rr::PrimitivePacket* packets, const int numPackets, int invocationID) const
1706 DE_UNREF(verticesIn);
1708 for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
1710 const rr::VertexPacket* vertex = packets[packetNdx].vertices[0];
1711 const tcu::Vec4 basePosition = vertex->position;
1712 const float phase = float(invocationID) / float(m_numInvocations) * 6.3f;
1713 const tcu::Vec4 centerPosition = basePosition + tcu::Vec4(deFloatCos(phase), deFloatSin(phase), 0.0f, 0.0f) * 0.1f;
1715 output.EmitVertex(centerPosition + tcu::Vec4( 0.0f, -0.1f, 0.0f, 0.0f), 0.0f, DE_NULL, packets[packetNdx].primitiveIDIn);
1716 output.EmitVertex(centerPosition + tcu::Vec4(-0.05f, 0.0f, 0.0f, 0.0f), 0.0f, DE_NULL, packets[packetNdx].primitiveIDIn);
1717 output.EmitVertex(centerPosition + tcu::Vec4( 0.05f, 0.0f, 0.0f, 0.0f), 0.0f, DE_NULL, packets[packetNdx].primitiveIDIn);
1718 output.EndPrimitive();
1722 std::string InstancedExpansionShader::genVertexSource (void)
1724 return "#version 310 es\n"
1725 "in highp vec4 a_position;\n"
1726 "in highp vec4 a_offset;\n"
1727 "void main (void)\n"
1729 " gl_Position = a_position + a_offset;\n"
1733 std::string InstancedExpansionShader::genFragmentSource (void)
1735 return "#version 310 es\n"
1736 "layout(location = 0) out mediump vec4 fragColor;\n"
1737 "void main (void)\n"
1739 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
1743 std::string InstancedExpansionShader::genGeometrySource (int numInvocations)
1745 std::ostringstream buf;
1747 buf << "#version 310 es\n"
1748 "#extension GL_EXT_geometry_shader : require\n"
1749 "layout(points,invocations=" << numInvocations << ") in;\n"
1750 "layout(triangle_strip, max_vertices = 3) out;\n"
1752 "void main (void)\n"
1754 " highp vec4 basePosition = gl_in[0].gl_Position;\n"
1755 " highp float phase = float(gl_InvocationID) / float(" << numInvocations << ") * 6.3;\n"
1756 " highp vec4 centerPosition = basePosition + 0.1 * vec4(cos(phase), sin(phase), 0.0, 0.0);\n"
1758 " gl_Position = centerPosition + vec4( 0.00, -0.1, 0.0, 0.0);\n"
1760 " gl_Position = centerPosition + vec4(-0.05, 0.0, 0.0, 0.0);\n"
1762 " gl_Position = centerPosition + vec4( 0.05, 0.0, 0.0, 0.0);\n"
1769 class GeometryShaderRenderTest : public TestCase
1774 FLAG_DRAW_INSTANCED = 1,
1775 FLAG_USE_INDICES = 2,
1776 FLAG_USE_RESTART_INDEX = 4,
1779 GeometryShaderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives, const char* dataAttributeName, int flags = 0);
1780 virtual ~GeometryShaderRenderTest (void);
1785 IterateResult iterate (void);
1786 bool compare (void);
1788 virtual sglr::ShaderProgram& getProgram (void) = 0;
1791 virtual void genVertexAttribData (void);
1792 void renderWithContext (sglr::Context& ctx, sglr::ShaderProgram& program, tcu::Surface& dstSurface);
1793 virtual void preRender (sglr::Context& ctx, GLuint programID);
1794 virtual void postRender (sglr::Context& ctx, GLuint programID);
1796 int m_numDrawVertices;
1797 int m_numDrawInstances;
1798 int m_vertexAttrDivisor;
1800 const GLenum m_inputPrimitives;
1801 const GLenum m_outputPrimitives;
1802 const char* const m_dataAttributeName;
1805 tcu::IVec2 m_viewportSize;
1806 int m_interationCount;
1808 tcu::Surface* m_glResult;
1809 tcu::Surface* m_refResult;
1811 sglr::ReferenceContextBuffers* m_refBuffers;
1812 sglr::ReferenceContext* m_refContext;
1813 sglr::Context* m_glContext;
1815 std::vector<tcu::Vec4> m_vertexPosData;
1816 std::vector<tcu::Vec4> m_vertexAttrData;
1817 std::vector<deUint16> m_indices;
1820 GeometryShaderRenderTest::GeometryShaderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives, const char* dataAttributeName, int flags)
1821 : TestCase (context, name, desc)
1822 , m_numDrawVertices (0)
1823 , m_numDrawInstances (0)
1824 , m_vertexAttrDivisor (0)
1825 , m_inputPrimitives (inputPrimitives)
1826 , m_outputPrimitives (outputPrimitives)
1827 , m_dataAttributeName (dataAttributeName)
1829 , m_viewportSize (TEST_CANVAS_SIZE, TEST_CANVAS_SIZE)
1830 , m_interationCount (0)
1831 , m_glResult (DE_NULL)
1832 , m_refResult (DE_NULL)
1833 , m_refBuffers (DE_NULL)
1834 , m_refContext (DE_NULL)
1835 , m_glContext (DE_NULL)
1837 // Disallow instanced drawElements
1838 DE_ASSERT(((m_flags & FLAG_DRAW_INSTANCED) == 0) || ((m_flags & FLAG_USE_INDICES) == 0));
1839 // Disallow restart without indices
1840 DE_ASSERT(!(((m_flags & FLAG_USE_RESTART_INDEX) != 0) && ((m_flags & FLAG_USE_INDICES) == 0)));
1843 GeometryShaderRenderTest::~GeometryShaderRenderTest (void)
1848 void GeometryShaderRenderTest::init (void)
1851 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
1852 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
1856 sglr::ReferenceContextLimits limits;
1858 m_glResult = new tcu::Surface(m_viewportSize.x(), m_viewportSize.y());
1859 m_refResult = new tcu::Surface(m_viewportSize.x(), m_viewportSize.y());
1861 m_refBuffers = new sglr::ReferenceContextBuffers(m_context.getRenderTarget().getPixelFormat(), m_context.getRenderTarget().getDepthBits(), 0, m_viewportSize.x(), m_viewportSize.y());
1862 m_refContext = new sglr::ReferenceContext(limits, m_refBuffers->getColorbuffer(), m_refBuffers->getDepthbuffer(), m_refBuffers->getStencilbuffer());
1863 m_glContext = new sglr::GLContext(m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS, tcu::IVec4(0, 0, m_viewportSize.x(), m_viewportSize.y()));
1867 void GeometryShaderRenderTest::deinit (void)
1872 m_glResult = DE_NULL;
1873 m_refResult = DE_NULL;
1875 delete m_refContext;
1877 delete m_refBuffers;
1879 m_refBuffers = DE_NULL;
1880 m_refContext = DE_NULL;
1881 m_glContext = DE_NULL;
1884 tcu::TestCase::IterateResult GeometryShaderRenderTest::iterate (void)
1886 // init() must be called
1887 DE_ASSERT(m_glContext);
1888 DE_ASSERT(m_refContext);
1890 const int iteration = m_interationCount++;
1894 // Check requirements
1895 const int width = m_context.getRenderTarget().getWidth();
1896 const int height = m_context.getRenderTarget().getHeight();
1898 if (width < m_viewportSize.x() || height < m_viewportSize.y())
1899 throw tcu::NotSupportedError(std::string("Render target size must be at least ") + de::toString(m_viewportSize.x()) + "x" + de::toString(m_viewportSize.y()));
1902 genVertexAttribData();
1906 else if (iteration == 1)
1909 sglr::ShaderProgram& program = getProgram();
1911 renderWithContext(*m_glContext, program, *m_glResult);
1912 renderWithContext(*m_refContext, program, *m_refResult);
1919 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1921 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
1927 bool GeometryShaderRenderTest::compare (void)
1931 if (m_context.getRenderTarget().getNumSamples() > 1)
1933 return tcu::fuzzyCompare(m_testCtx.getLog(), "Compare Results", "Compare Results", m_refResult->getAccess(), m_glResult->getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
1937 tcu::Surface errorMask (m_viewportSize.x(), m_viewportSize.y());
1938 const tcu::RGBA green (0, 255, 0, 255);
1939 const tcu::RGBA red (255, 0, 0, 255);
1940 const int colorComponentThreshold = 20;
1941 bool testResult = true;
1943 for (int x = 1; x + 1 < m_viewportSize.x(); ++x)
1944 for (int y = 1; y + 1 < m_viewportSize.y(); ++y)
1947 const tcu::RGBA refcolor = m_refResult->getPixel(x, y);
1949 // Got to find similar pixel near this pixel (3x3 kernel)
1950 for (int dx = -1; dx <= 1; ++dx)
1951 for (int dy = -1; dy <= 1; ++dy)
1953 const tcu::RGBA testColor = m_glResult->getPixel(x + dx, y + dy);
1954 const tcu::IVec4 colDiff = tcu::abs(testColor.toIVec() - refcolor.toIVec());
1956 const int maxColDiff = de::max(de::max(colDiff.x(), colDiff.y()), colDiff.z()); // check RGB channels
1958 if (maxColDiff <= colorComponentThreshold)
1965 errorMask.setPixel(x, y, (found) ? (green) : (red));
1970 m_testCtx.getLog() << TestLog::ImageSet("Compare result", "Result of rendering")
1971 << TestLog::Image("Result", "Result", *m_glResult)
1972 << TestLog::EndImageSet;
1973 m_testCtx.getLog() << TestLog::Message << "Image compare ok." << TestLog::EndMessage;
1977 m_testCtx.getLog() << TestLog::ImageSet("Compare result", "Result of rendering")
1978 << TestLog::Image("Result", "Result", *m_glResult)
1979 << TestLog::Image("Reference", "Reference", *m_refResult)
1980 << TestLog::Image("ErrorMask", "Error mask", errorMask)
1981 << TestLog::EndImageSet;
1982 m_testCtx.getLog() << TestLog::Message << "Image compare failed." << TestLog::EndMessage;
1989 void GeometryShaderRenderTest::genVertexAttribData (void)
1991 // Create 1 X 2 grid in triangle strip adjacent - order
1992 const float scale = 0.3f;
1993 const tcu::Vec4 offset(-0.5f, -0.2f, 0.0f, 1.0f);
1995 m_vertexPosData.resize(12);
1996 m_vertexPosData[ 0] = tcu::Vec4( 0, 0, 0.0f, 0.0f) * scale + offset;
1997 m_vertexPosData[ 1] = tcu::Vec4(-1, -1, 0.0f, 0.0f) * scale + offset;
1998 m_vertexPosData[ 2] = tcu::Vec4( 0, -1, 0.0f, 0.0f) * scale + offset;
1999 m_vertexPosData[ 3] = tcu::Vec4( 1, 1, 0.0f, 0.0f) * scale + offset;
2000 m_vertexPosData[ 4] = tcu::Vec4( 1, 0, 0.0f, 0.0f) * scale + offset;
2001 m_vertexPosData[ 5] = tcu::Vec4( 0, -2, 0.0f, 0.0f) * scale + offset;
2002 m_vertexPosData[ 6] = tcu::Vec4( 1, -1, 0.0f, 0.0f) * scale + offset;
2003 m_vertexPosData[ 7] = tcu::Vec4( 2, 1, 0.0f, 0.0f) * scale + offset;
2004 m_vertexPosData[ 8] = tcu::Vec4( 2, 0, 0.0f, 0.0f) * scale + offset;
2005 m_vertexPosData[ 9] = tcu::Vec4( 1, -2, 0.0f, 0.0f) * scale + offset;
2006 m_vertexPosData[10] = tcu::Vec4( 2, -1, 0.0f, 0.0f) * scale + offset;
2007 m_vertexPosData[11] = tcu::Vec4( 3, 0, 0.0f, 0.0f) * scale + offset;
2010 m_vertexAttrData.resize(12);
2011 for (int i = 0; i < 12; ++i)
2012 m_vertexAttrData[i] = (i % 2 == 0) ? tcu::Vec4(1, 1, 1, 1) : tcu::Vec4(1, 0, 0, 1);
2014 m_numDrawVertices = 12;
2017 void GeometryShaderRenderTest::renderWithContext (sglr::Context& ctx, sglr::ShaderProgram& program, tcu::Surface& dstSurface)
2019 #define CHECK_GL_CTX_ERRORS() glu::checkError(ctx.getError(), DE_NULL, __FILE__, __LINE__)
2021 const GLuint programId = ctx.createProgram(&program);
2022 const GLint attrPosLoc = ctx.getAttribLocation(programId, "a_position");
2023 const GLint attrColLoc = ctx.getAttribLocation(programId, m_dataAttributeName);
2025 GLuint vertexPosBuf = 0;
2026 GLuint vertexAttrBuf = 0;
2027 GLuint elementArrayBuf = 0;
2029 ctx.genVertexArrays(1, &vaoId);
2030 ctx.bindVertexArray(vaoId);
2032 if (attrPosLoc != -1)
2034 ctx.genBuffers(1, &vertexPosBuf);
2035 ctx.bindBuffer(GL_ARRAY_BUFFER, vertexPosBuf);
2036 ctx.bufferData(GL_ARRAY_BUFFER, m_vertexPosData.size() * sizeof(tcu::Vec4), &m_vertexPosData[0], GL_STATIC_DRAW);
2037 ctx.vertexAttribPointer(attrPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2038 ctx.enableVertexAttribArray(attrPosLoc);
2041 if (attrColLoc != -1)
2043 ctx.genBuffers(1, &vertexAttrBuf);
2044 ctx.bindBuffer(GL_ARRAY_BUFFER, vertexAttrBuf);
2045 ctx.bufferData(GL_ARRAY_BUFFER, m_vertexAttrData.size() * sizeof(tcu::Vec4), &m_vertexAttrData[0], GL_STATIC_DRAW);
2046 ctx.vertexAttribPointer(attrColLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2047 ctx.enableVertexAttribArray(attrColLoc);
2049 if (m_vertexAttrDivisor)
2050 ctx.vertexAttribDivisor(attrColLoc, m_vertexAttrDivisor);
2053 if (m_flags & FLAG_USE_INDICES)
2055 ctx.genBuffers(1, &elementArrayBuf);
2056 ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBuf);
2057 ctx.bufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(deUint16), &m_indices[0], GL_STATIC_DRAW);
2060 ctx.clearColor(0, 0, 0, 1);
2061 ctx.clear(GL_COLOR_BUFFER_BIT);
2063 ctx.viewport(0, 0, m_viewportSize.x(), m_viewportSize.y());
2064 CHECK_GL_CTX_ERRORS();
2066 ctx.useProgram(programId);
2067 CHECK_GL_CTX_ERRORS();
2069 preRender(ctx, programId);
2070 CHECK_GL_CTX_ERRORS();
2072 if (m_flags & FLAG_USE_RESTART_INDEX)
2074 ctx.enable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
2075 CHECK_GL_CTX_ERRORS();
2078 if (m_flags & FLAG_USE_INDICES)
2079 ctx.drawElements(m_inputPrimitives, m_numDrawVertices, GL_UNSIGNED_SHORT, DE_NULL);
2080 else if (m_flags & FLAG_DRAW_INSTANCED)
2081 ctx.drawArraysInstanced(m_inputPrimitives, 0, m_numDrawVertices, m_numDrawInstances);
2083 ctx.drawArrays(m_inputPrimitives, 0, m_numDrawVertices);
2085 CHECK_GL_CTX_ERRORS();
2087 if (m_flags & FLAG_USE_RESTART_INDEX)
2089 ctx.disable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
2090 CHECK_GL_CTX_ERRORS();
2093 postRender(ctx, programId);
2094 CHECK_GL_CTX_ERRORS();
2098 if (attrPosLoc != -1)
2099 ctx.disableVertexAttribArray(attrPosLoc);
2100 if (attrColLoc != -1)
2101 ctx.disableVertexAttribArray(attrColLoc);
2104 ctx.deleteBuffers(1, &vertexPosBuf);
2106 ctx.deleteBuffers(1, &vertexAttrBuf);
2107 if (elementArrayBuf)
2108 ctx.deleteBuffers(1, &elementArrayBuf);
2110 ctx.deleteVertexArrays(1, &vaoId);
2112 CHECK_GL_CTX_ERRORS();
2115 ctx.readPixels(dstSurface, 0, 0, m_viewportSize.x(), m_viewportSize.y());
2117 #undef CHECK_GL_CTX_ERRORS
2120 void GeometryShaderRenderTest::preRender (sglr::Context& ctx, GLuint programID)
2123 DE_UNREF(programID);
2126 void GeometryShaderRenderTest::postRender (sglr::Context& ctx, GLuint programID)
2129 DE_UNREF(programID);
2132 class GeometryExpanderRenderTest : public GeometryShaderRenderTest
2135 GeometryExpanderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives);
2136 virtual ~GeometryExpanderRenderTest (void);
2138 sglr::ShaderProgram& getProgram (void);
2141 VertexExpanderShader m_program;
2144 GeometryExpanderRenderTest::GeometryExpanderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives)
2145 : GeometryShaderRenderTest (context, name, desc, inputPrimitives, outputPrimitives, "a_color")
2146 , m_program (sglr::rr_util::mapGLGeometryShaderInputType(inputPrimitives), sglr::rr_util::mapGLGeometryShaderOutputType(outputPrimitives))
2150 GeometryExpanderRenderTest::~GeometryExpanderRenderTest (void)
2154 sglr::ShaderProgram& GeometryExpanderRenderTest::getProgram (void)
2159 class EmitTest : public GeometryShaderRenderTest
2162 EmitTest (Context& context, const char* name, const char* desc, int emitCountA, int endCountA, int emitCountB, int endCountB, GLenum outputType);
2164 sglr::ShaderProgram& getProgram (void);
2166 void genVertexAttribData (void);
2168 VertexEmitterShader m_program;
2171 EmitTest::EmitTest (Context& context, const char* name, const char* desc, int emitCountA, int endCountA, int emitCountB, int endCountB, GLenum outputType)
2172 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, outputType, "a_color")
2173 , m_program (emitCountA, endCountA, emitCountB, endCountB, sglr::rr_util::mapGLGeometryShaderOutputType(outputType))
2177 sglr::ShaderProgram& EmitTest::getProgram (void)
2182 void EmitTest::genVertexAttribData (void)
2184 m_vertexPosData.resize(1);
2185 m_vertexPosData[0] = tcu::Vec4(0, 0, 0, 1);
2187 m_vertexAttrData.resize(1);
2188 m_vertexAttrData[0] = tcu::Vec4(1, 1, 1, 1);
2190 m_numDrawVertices = 1;
2193 class VaryingTest : public GeometryShaderRenderTest
2196 VaryingTest (Context& context, const char* name, const char* desc, int vertexOut, int geometryOut);
2198 sglr::ShaderProgram& getProgram (void);
2200 void genVertexAttribData (void);
2202 VertexVaryingShader m_program;
2205 VaryingTest::VaryingTest (Context& context, const char* name, const char* desc, int vertexOut, int geometryOut)
2206 : GeometryShaderRenderTest (context, name, desc, GL_TRIANGLES, GL_TRIANGLE_STRIP, "a_color")
2207 , m_program (vertexOut, geometryOut)
2211 sglr::ShaderProgram& VaryingTest::getProgram (void)
2216 void VaryingTest::genVertexAttribData (void)
2218 m_vertexPosData.resize(3);
2219 m_vertexPosData[0] = tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f);
2220 m_vertexPosData[1] = tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f);
2221 m_vertexPosData[2] = tcu::Vec4(0.1f, 0.0f, 0.0f, 1.0f);
2223 m_vertexAttrData.resize(3);
2224 m_vertexAttrData[0] = tcu::Vec4(0.7f, 0.4f, 0.6f, 1.0f);
2225 m_vertexAttrData[1] = tcu::Vec4(0.9f, 0.2f, 0.5f, 1.0f);
2226 m_vertexAttrData[2] = tcu::Vec4(0.1f, 0.8f, 0.3f, 1.0f);
2228 m_numDrawVertices = 3;
2231 class TriangleStripAdjacencyVertexCountTest : public GeometryExpanderRenderTest
2234 TriangleStripAdjacencyVertexCountTest (Context& context, const char* name, const char* desc, int numInputVertices);
2237 void genVertexAttribData (void);
2239 int m_numInputVertices;
2242 TriangleStripAdjacencyVertexCountTest::TriangleStripAdjacencyVertexCountTest (Context& context, const char* name, const char* desc, int numInputVertices)
2243 : GeometryExpanderRenderTest (context, name, desc, GL_TRIANGLE_STRIP_ADJACENCY, GL_TRIANGLE_STRIP)
2244 , m_numInputVertices (numInputVertices)
2248 void TriangleStripAdjacencyVertexCountTest::genVertexAttribData (void)
2250 this->GeometryShaderRenderTest::genVertexAttribData();
2251 m_numDrawVertices = m_numInputVertices;
2254 class NegativeDrawCase : public TestCase
2257 NegativeDrawCase (Context& context, const char* name, const char* desc, GLenum inputType, GLenum inputPrimitives);
2258 ~NegativeDrawCase (void);
2263 IterateResult iterate (void);
2266 sglr::Context* m_ctx;
2267 VertexExpanderShader* m_program;
2269 GLenum m_inputPrimitives;
2272 NegativeDrawCase::NegativeDrawCase (Context& context, const char* name, const char* desc, GLenum inputType, GLenum inputPrimitives)
2273 : TestCase (context, name, desc)
2275 , m_program (DE_NULL)
2276 , m_inputType (inputType)
2277 , m_inputPrimitives (inputPrimitives)
2281 NegativeDrawCase::~NegativeDrawCase (void)
2286 void NegativeDrawCase::init (void)
2288 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2289 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2291 m_ctx = new sglr::GLContext(m_context.getRenderContext(), m_testCtx.getLog(), sglr::GLCONTEXT_LOG_CALLS | sglr::GLCONTEXT_LOG_PROGRAMS, tcu::IVec4(0, 0, 1, 1));
2292 m_program = new VertexExpanderShader(sglr::rr_util::mapGLGeometryShaderInputType(m_inputType), rr::GEOMETRYSHADEROUTPUTTYPE_POINTS);
2295 void NegativeDrawCase::deinit (void)
2301 m_program = DE_NULL;
2304 NegativeDrawCase::IterateResult NegativeDrawCase::iterate (void)
2306 const GLuint programId = m_ctx->createProgram(m_program);
2307 const GLint attrPosLoc = m_ctx->getAttribLocation(programId, "a_position");
2308 const tcu::Vec4 vertexPosData (0, 0, 0, 1);
2311 GLuint vertexPosBuf = 0;
2312 GLenum errorCode = 0;
2314 m_ctx->genVertexArrays(1, &vaoId);
2315 m_ctx->bindVertexArray(vaoId);
2317 m_ctx->genBuffers(1, &vertexPosBuf);
2318 m_ctx->bindBuffer(GL_ARRAY_BUFFER, vertexPosBuf);
2319 m_ctx->bufferData(GL_ARRAY_BUFFER, sizeof(tcu::Vec4), vertexPosData.m_data, GL_STATIC_DRAW);
2320 m_ctx->vertexAttribPointer(attrPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2321 m_ctx->enableVertexAttribArray(attrPosLoc);
2323 m_ctx->clearColor(0, 0, 0, 1);
2324 m_ctx->clear(GL_COLOR_BUFFER_BIT);
2326 m_ctx->viewport(0, 0, 1, 1);
2328 m_ctx->useProgram(programId);
2331 glu::checkError(m_ctx->getError(), "", __FILE__, __LINE__);
2333 m_ctx->drawArrays(m_inputPrimitives, 0, 1);
2335 errorCode = m_ctx->getError();
2336 if (errorCode != GL_INVALID_OPERATION)
2338 m_testCtx.getLog() << tcu::TestLog::Message << "Expected GL_INVALID_OPERATION, got " << glu::getErrorStr(errorCode) << tcu::TestLog::EndMessage;
2339 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got wrong error code");
2343 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2346 m_ctx->useProgram(0);
2348 m_ctx->disableVertexAttribArray(attrPosLoc);
2349 m_ctx->deleteBuffers(1, &vertexPosBuf);
2351 m_ctx->deleteVertexArrays(1, &vaoId);
2356 class OutputCountCase : public GeometryShaderRenderTest
2359 OutputCountCase (Context& context, const char* name, const char* desc, const OutputCountPatternSpec&);
2364 sglr::ShaderProgram& getProgram (void);
2365 void genVertexAttribData (void);
2367 const int m_primitiveCount;
2368 OutputCountShader* m_program;
2369 OutputCountPatternSpec m_spec;
2372 OutputCountCase::OutputCountCase (Context& context, const char* name, const char* desc, const OutputCountPatternSpec& spec)
2373 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_TRIANGLE_STRIP, "a_color")
2374 , m_primitiveCount ((int)spec.pattern.size())
2375 , m_program (DE_NULL)
2380 void OutputCountCase::init (void)
2382 // Check requirements and adapt to them
2384 const int componentsPerVertex = 4 + 4; // vec4 pos, vec4 color
2385 const int testVertices = *std::max_element(m_spec.pattern.begin(), m_spec.pattern.end());
2386 glw::GLint maxVertices = 0;
2387 glw::GLint maxComponents = 0;
2389 // check the extension before querying anything
2390 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2391 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2393 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxVertices);
2394 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
2396 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_OUTPUT_VERTICES = " << maxVertices << tcu::TestLog::EndMessage;
2397 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = " << maxComponents << tcu::TestLog::EndMessage;
2398 m_testCtx.getLog() << tcu::TestLog::Message << "Components per vertex = " << componentsPerVertex << tcu::TestLog::EndMessage;
2400 if (testVertices == -1)
2402 // "max vertices"-case
2403 DE_ASSERT((int)m_spec.pattern.size() == 1);
2404 m_spec.pattern[0] = de::min(maxVertices, maxComponents / componentsPerVertex);
2406 // make sure size is dividable by 2, as OutputShader requires
2407 m_spec.pattern[0] = m_spec.pattern[0] & ~0x00000001;
2409 if (m_spec.pattern[0] == 0)
2410 throw tcu::InternalError("Pattern size is invalid.");
2415 if (testVertices > maxVertices)
2416 throw tcu::NotSupportedError(de::toString(testVertices) + " output vertices required.");
2417 if (testVertices * componentsPerVertex > maxComponents)
2418 throw tcu::NotSupportedError(de::toString(testVertices * componentsPerVertex) + " output components required.");
2422 // Log what the test tries to do
2424 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering " << (int)m_spec.pattern.size() << " row(s).\nOne geometry shader invocation generates one row.\nRow sizes:" << tcu::TestLog::EndMessage;
2425 for (int ndx = 0; ndx < (int)m_spec.pattern.size(); ++ndx)
2426 m_testCtx.getLog() << tcu::TestLog::Message << "Row " << ndx << ": " << m_spec.pattern[ndx] << " vertices." << tcu::TestLog::EndMessage;
2429 DE_ASSERT(!m_program);
2430 m_program = new OutputCountShader(m_spec);
2433 GeometryShaderRenderTest::init();
2436 void OutputCountCase::deinit (void)
2441 m_program = DE_NULL;
2444 GeometryShaderRenderTest::deinit();
2447 sglr::ShaderProgram& OutputCountCase::getProgram (void)
2452 void OutputCountCase::genVertexAttribData (void)
2454 m_vertexPosData.resize(m_primitiveCount);
2455 m_vertexAttrData.resize(m_primitiveCount);
2457 for (int ndx = 0; ndx < m_primitiveCount; ++ndx)
2459 m_vertexPosData[ndx] = tcu::Vec4(-1.0f, ((float)ndx) / m_primitiveCount * 2.0f - 1.0f, 0.0f, 1.0f);
2460 m_vertexAttrData[ndx] = (ndx % 2 == 0) ? tcu::Vec4(1, 1, 1, 1) : tcu::Vec4(1, 0, 0, 1);
2463 m_numDrawVertices = m_primitiveCount;
2466 class BuiltinVariableRenderTest : public GeometryShaderRenderTest
2469 BuiltinVariableRenderTest (Context& context, const char* name, const char* desc, BuiltinVariableShader::VariableTest test, int flags = 0);
2474 sglr::ShaderProgram& getProgram (void);
2475 void genVertexAttribData (void);
2477 BuiltinVariableShader m_program;
2478 const BuiltinVariableShader::VariableTest m_test;
2481 BuiltinVariableRenderTest::BuiltinVariableRenderTest (Context& context, const char* name, const char* desc, BuiltinVariableShader::VariableTest test, int flags)
2482 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_POINTS, BuiltinVariableShader::getTestAttributeName(test), flags)
2488 void BuiltinVariableRenderTest::init (void)
2491 if (m_test == BuiltinVariableShader::TEST_POINT_SIZE)
2493 const float requiredPointSize = 5.0f;
2495 tcu::Vec2 range = tcu::Vec2(1.0f, 1.0f);
2497 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_point_size"))
2498 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_point_size extension");
2500 m_context.getRenderContext().getFunctions().getFloatv(GL_ALIASED_POINT_SIZE_RANGE, range.getPtr());
2501 if (range.y() < requiredPointSize)
2502 throw tcu::NotSupportedError("Test case requires point size " + de::toString(requiredPointSize));
2506 GeometryShaderRenderTest::init();
2509 sglr::ShaderProgram& BuiltinVariableRenderTest::getProgram (void)
2514 void BuiltinVariableRenderTest::genVertexAttribData (void)
2516 m_vertexPosData.resize(4);
2517 m_vertexPosData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 1.0f);
2518 m_vertexPosData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 1.0f);
2519 m_vertexPosData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 1.0f);
2520 m_vertexPosData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 1.0f);
2522 m_vertexAttrData.resize(4);
2523 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
2524 m_vertexAttrData[1] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
2525 m_vertexAttrData[2] = tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f);
2526 m_vertexAttrData[3] = tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f);
2528 // Only used by primitive ID restart test
2529 m_indices.resize(4);
2532 m_indices[2] = 0xFFFF; // restart
2535 m_numDrawVertices = 4;
2538 class LayeredRenderCase : public TestCase
2541 enum LayeredRenderTargetType
2553 TEST_DEFAULT_LAYER, // !< draw to default layer
2554 TEST_SINGLE_LAYER, // !< draw to single layer
2555 TEST_ALL_LAYERS, // !< draw all layers
2556 TEST_DIFFERENT_LAYERS, // !< draw different content to different layers
2557 TEST_INVOCATION_PER_LAYER, // !< draw to all layers, one invocation per layer
2558 TEST_MULTIPLE_LAYERS_PER_INVOCATION, // !< draw to all layers, multiple invocations write to multiple layers
2559 TEST_LAYER_ID, // !< draw to all layers, verify gl_Layer fragment input
2560 TEST_LAYER_PROVOKING_VERTEX, // !< draw primitive with vertices in different layers, check which layer it was drawn to
2564 LayeredRenderCase (Context& context, const char* name, const char* desc, LayeredRenderTargetType target, TestType test);
2565 ~LayeredRenderCase (void);
2569 IterateResult iterate (void);
2572 void initTexture (void);
2573 void initFbo (void);
2574 void initRenderShader (void);
2575 void initSamplerShader (void);
2577 std::string genFragmentSource (void) const;
2578 std::string genGeometrySource (void) const;
2579 std::string genSamplerFragmentSource (void) const;
2581 void renderToTexture (void);
2582 void sampleTextureLayer (tcu::Surface& dst, int layer);
2583 bool verifyLayerContent (const tcu::Surface& layer, int layerNdx);
2584 bool verifyImageSingleColoredRow (const tcu::Surface& layer, float rowWidthRatio, const tcu::Vec4& color, bool logging = true);
2585 bool verifyEmptyImage (const tcu::Surface& layer, bool logging = true);
2586 bool verifyProvokingVertexLayers (const tcu::Surface& layer0, const tcu::Surface& layer1);
2588 static int getTargetLayers (LayeredRenderTargetType target);
2589 static glw::GLenum getTargetTextureTarget (LayeredRenderTargetType target);
2590 static tcu::IVec3 getTargetDimensions (LayeredRenderTargetType target);
2591 static tcu::IVec2 getResolveDimensions (LayeredRenderTargetType target);
2593 const LayeredRenderTargetType m_target;
2594 const TestType m_test;
2595 const int m_numLayers;
2596 const int m_targetLayer;
2597 const tcu::IVec2 m_resolveDimensions;
2602 glw::GLuint m_texture;
2604 glu::ShaderProgram* m_renderShader;
2605 glu::ShaderProgram* m_samplerShader;
2607 glw::GLint m_samplerSamplerLoc;
2608 glw::GLint m_samplerLayerLoc;
2610 glw::GLenum m_provokingVertex;
2613 LayeredRenderCase::LayeredRenderCase (Context& context, const char* name, const char* desc, LayeredRenderTargetType target, TestType test)
2614 : TestCase (context, name, desc)
2617 , m_numLayers (getTargetLayers(target))
2618 , m_targetLayer (m_numLayers / 2)
2619 , m_resolveDimensions (getResolveDimensions(target))
2621 , m_allLayersOk (true)
2624 , m_renderShader (DE_NULL)
2625 , m_samplerShader (DE_NULL)
2626 , m_samplerSamplerLoc (-1)
2627 , m_samplerLayerLoc (-1)
2628 , m_provokingVertex (0)
2632 LayeredRenderCase::~LayeredRenderCase (void)
2637 void LayeredRenderCase::init (void)
2641 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2642 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2644 if (m_target == TARGET_2D_MS_ARRAY && !m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
2645 throw tcu::NotSupportedError("Test requires OES_texture_storage_multisample_2d_array extension");
2647 if (m_context.getRenderTarget().getWidth() < m_resolveDimensions.x() || m_context.getRenderTarget().getHeight() < m_resolveDimensions.y())
2648 throw tcu::NotSupportedError("Render target size must be at least " + de::toString(m_resolveDimensions.x()) + "x" + de::toString(m_resolveDimensions.y()));
2650 // log what the test tries to do
2652 if (m_test == TEST_DEFAULT_LAYER)
2653 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to the default layer." << tcu::TestLog::EndMessage;
2654 else if (m_test == TEST_SINGLE_LAYER)
2655 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to a single layer." << tcu::TestLog::EndMessage;
2656 else if (m_test == TEST_ALL_LAYERS)
2657 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to all layers." << tcu::TestLog::EndMessage;
2658 else if (m_test == TEST_DIFFERENT_LAYERS)
2659 m_testCtx.getLog() << tcu::TestLog::Message << "Outputting different number of vertices to each layer." << tcu::TestLog::EndMessage;
2660 else if (m_test == TEST_INVOCATION_PER_LAYER)
2661 m_testCtx.getLog() << tcu::TestLog::Message << "Using a different invocation to output to each layer." << tcu::TestLog::EndMessage;
2662 else if (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
2663 m_testCtx.getLog() << tcu::TestLog::Message << "Outputting to each layer from multiple invocations." << tcu::TestLog::EndMessage;
2664 else if (m_test == TEST_LAYER_ID)
2665 m_testCtx.getLog() << tcu::TestLog::Message << "Using gl_Layer in fragment shader." << tcu::TestLog::EndMessage;
2666 else if (m_test == TEST_LAYER_PROVOKING_VERTEX)
2667 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying LAYER_PROVOKING_VERTEX." << tcu::TestLog::EndMessage;
2676 initSamplerShader();
2679 void LayeredRenderCase::deinit (void)
2683 m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texture);
2689 m_context.getRenderContext().getFunctions().deleteFramebuffers(1, &m_fbo);
2693 delete m_renderShader;
2694 delete m_samplerShader;
2696 m_renderShader = DE_NULL;
2697 m_samplerShader = DE_NULL;
2700 LayeredRenderCase::IterateResult LayeredRenderCase::iterate (void)
2704 if (m_iteration == 1)
2706 if (m_test == TEST_LAYER_PROVOKING_VERTEX)
2708 // which layer the implementation claims to render to
2710 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
2712 m_context.getRenderContext().getFunctions().getIntegerv(GL_LAYER_PROVOKING_VERTEX, &state);
2713 GLU_EXPECT_NO_ERROR(m_context.getRenderContext().getFunctions().getError(), "getInteger(GL_LAYER_PROVOKING_VERTEX)");
2715 if (!state.verifyValidity(m_testCtx))
2718 m_testCtx.getLog() << tcu::TestLog::Message << "GL_LAYER_PROVOKING_VERTEX = " << glu::getProvokingVertexStr(state) << tcu::TestLog::EndMessage;
2720 if (state != GL_FIRST_VERTEX_CONVENTION &&
2721 state != GL_LAST_VERTEX_CONVENTION &&
2722 state != GL_UNDEFINED_VERTEX)
2724 m_testCtx.getLog() << tcu::TestLog::Message << "getInteger(GL_LAYER_PROVOKING_VERTEX) returned illegal value. Got " << state << tcu::TestLog::EndMessage;
2725 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected provoking vertex value");
2729 m_provokingVertex = (glw::GLenum)state;
2732 // render to texture
2734 const tcu::ScopedLogSection section(m_testCtx.getLog(), "RenderToTexture", "Render to layered texture");
2736 // render to layered texture with the geometry shader
2742 else if (m_test == TEST_LAYER_PROVOKING_VERTEX && m_provokingVertex == GL_UNDEFINED_VERTEX)
2744 // Verification requires information from another layers, layers not independent
2746 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayers", "Verify layers 0 and 1");
2747 tcu::Surface layer0 (m_resolveDimensions.x(), m_resolveDimensions.y());
2748 tcu::Surface layer1 (m_resolveDimensions.x(), m_resolveDimensions.y());
2750 // sample layer to frame buffer
2751 sampleTextureLayer(layer0, 0);
2752 sampleTextureLayer(layer1, 1);
2754 m_allLayersOk &= verifyProvokingVertexLayers(layer0, layer1);
2757 // Other layers empty
2758 for (int layerNdx = 2; layerNdx < m_numLayers; ++layerNdx)
2760 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayer", "Verify layer " + de::toString(layerNdx));
2761 tcu::Surface layer (m_resolveDimensions.x(), m_resolveDimensions.y());
2763 // sample layer to frame buffer
2764 sampleTextureLayer(layer, layerNdx);
2767 m_allLayersOk &= verifyEmptyImage(layer);
2772 // Layers independent
2774 const int layerNdx = m_iteration - 2;
2775 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayer", "Verify layer " + de::toString(layerNdx));
2776 tcu::Surface layer (m_resolveDimensions.x(), m_resolveDimensions.y());
2778 // sample layer to frame buffer
2779 sampleTextureLayer(layer, layerNdx);
2782 m_allLayersOk &= verifyLayerContent(layer, layerNdx);
2784 if (layerNdx < m_numLayers-1)
2790 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2792 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Detected invalid layer content");
2797 void LayeredRenderCase::initTexture (void)
2799 DE_ASSERT(!m_texture);
2801 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2802 const tcu::IVec3 texSize = getTargetDimensions(m_target);
2803 const tcu::TextureFormat texFormat = glu::mapGLInternalFormat(GL_RGBA8);
2804 const glu::TransferFormat transferFormat = glu::getTransferFormat(texFormat);
2806 gl.genTextures(1, &m_texture);
2807 GLU_EXPECT_NO_ERROR(gl.getError(), "gen texture");
2812 m_testCtx.getLog() << tcu::TestLog::Message << "Creating cubemap texture, size = " << texSize.x() << "x" << texSize.y() << tcu::TestLog::EndMessage;
2813 gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
2814 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2815 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2816 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2817 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2818 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2819 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2823 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 3d texture, size = " << texSize.x() << "x" << texSize.y() << "x" << texSize.z() << tcu::TestLog::EndMessage;
2824 gl.bindTexture(GL_TEXTURE_3D, m_texture);
2825 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2828 case TARGET_1D_ARRAY:
2829 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 1d texture array, size = " << texSize.x() << ", layers = " << texSize.y() << tcu::TestLog::EndMessage;
2830 gl.bindTexture(GL_TEXTURE_1D_ARRAY, m_texture);
2831 gl.texImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2834 case TARGET_2D_ARRAY:
2835 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 2d texture array, size = " << texSize.x() << "x" << texSize.y() << ", layers = " << texSize.z() << tcu::TestLog::EndMessage;
2836 gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_texture);
2837 gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2840 case TARGET_2D_MS_ARRAY:
2842 const int numSamples = 2;
2845 gl.getIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxSamples);
2847 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 2d multisample texture array, size = " << texSize.x() << "x" << texSize.y() << ", layers = " << texSize.z() << ", samples = " << numSamples << tcu::TestLog::EndMessage;
2849 if (numSamples > maxSamples)
2850 throw tcu::NotSupportedError("Test requires " + de::toString(numSamples) + " color texture samples." );
2852 gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_texture);
2853 gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, numSamples, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), GL_TRUE);
2858 DE_ASSERT(DE_FALSE);
2860 GLU_EXPECT_NO_ERROR(gl.getError(), "tex image");
2862 // Multisample textures don't use filters
2863 if (getTargetTextureTarget(m_target) != GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
2865 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2866 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2867 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_S, GL_REPEAT);
2868 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_T, GL_REPEAT);
2869 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_R, GL_REPEAT);
2870 GLU_EXPECT_NO_ERROR(gl.getError(), "tex filter");
2874 void LayeredRenderCase::initFbo (void)
2878 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2880 m_testCtx.getLog() << tcu::TestLog::Message << "Creating FBO" << tcu::TestLog::EndMessage;
2882 gl.genFramebuffers(1, &m_fbo);
2883 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2884 gl.framebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture, 0);
2885 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
2887 GLU_EXPECT_NO_ERROR(gl.getError(), "setup fbo");
2890 void LayeredRenderCase::initRenderShader (void)
2892 const tcu::ScopedLogSection section(m_testCtx.getLog(), "RenderToTextureShader", "Create layered rendering shader program");
2894 static const char* const positionVertex = "#version 310 es\n"
2895 "void main (void)\n"
2897 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
2900 m_renderShader = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(positionVertex) << glu::FragmentSource(genFragmentSource()) << glu::GeometrySource(genGeometrySource()));
2901 m_testCtx.getLog() << *m_renderShader;
2903 if (!m_renderShader->isOk())
2904 throw tcu::TestError("failed to build render shader");
2907 void LayeredRenderCase::initSamplerShader (void)
2909 const tcu::ScopedLogSection section(m_testCtx.getLog(), "TextureSamplerShader", "Create shader sampler program");
2911 static const char* const positionVertex = "#version 310 es\n"
2912 "in highp vec4 a_position;\n"
2913 "void main (void)\n"
2915 " gl_Position = a_position;\n"
2918 m_samplerShader = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
2919 << glu::VertexSource(positionVertex)
2920 << glu::FragmentSource(genSamplerFragmentSource()));
2922 m_testCtx.getLog() << *m_samplerShader;
2924 if (!m_samplerShader->isOk())
2925 throw tcu::TestError("failed to build sampler shader");
2927 m_samplerSamplerLoc = m_context.getRenderContext().getFunctions().getUniformLocation(m_samplerShader->getProgram(), "u_sampler");
2928 if (m_samplerSamplerLoc == -1)
2929 throw tcu::TestError("u_sampler uniform location = -1");
2931 m_samplerLayerLoc = m_context.getRenderContext().getFunctions().getUniformLocation(m_samplerShader->getProgram(), "u_layer");
2932 if (m_samplerLayerLoc == -1)
2933 throw tcu::TestError("u_layer uniform location = -1");
2936 std::string LayeredRenderCase::genFragmentSource (void) const
2938 static const char* const fragmentLayerIdShader = "#version 310 es\n"
2939 "#extension GL_EXT_geometry_shader : require\n"
2940 "layout(location = 0) out mediump vec4 fragColor;\n"
2941 "void main (void)\n"
2943 " fragColor = vec4(((gl_Layer % 2) == 1) ? 1.0 : 0.5,\n"
2944 " (((gl_Layer / 2) % 2) == 1) ? 1.0 : 0.5,\n"
2945 " (gl_Layer == 0) ? 1.0 : 0.0,\n"
2949 if (m_test != TEST_LAYER_ID)
2950 return std::string(s_commonShaderSourceFragment);
2952 return std::string(fragmentLayerIdShader);
2955 std::string LayeredRenderCase::genGeometrySource (void) const
2957 // TEST_DIFFERENT_LAYERS: draw 0 quad to first layer, 1 to second, etc.
2958 // TEST_ALL_LAYERS: draw 1 quad to all layers
2959 // TEST_MULTIPLE_LAYERS_PER_INVOCATION: draw 1 triangle to "current layer" and 1 triangle to another layer
2960 // else: draw 1 quad to some single layer
2961 const int maxVertices = (m_test == TEST_DIFFERENT_LAYERS) ? ((2 + m_numLayers-1) * m_numLayers) :
2962 (m_test == TEST_ALL_LAYERS || m_test == TEST_LAYER_ID) ? (m_numLayers * 4) :
2963 (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION) ? (6) :
2964 (m_test == TEST_LAYER_PROVOKING_VERTEX) ? (6) :
2966 std::ostringstream buf;
2968 buf << "#version 310 es\n"
2969 "#extension GL_EXT_geometry_shader : require\n";
2971 if (m_test == TEST_INVOCATION_PER_LAYER || m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
2972 buf << "layout(points, invocations=" << m_numLayers << ") in;\n";
2974 buf << "layout(points) in;\n";
2976 buf << "layout(triangle_strip, max_vertices = " << maxVertices << ") out;\n"
2977 "out highp vec4 v_frag_FragColor;\n"
2979 "void main (void)\n"
2982 if (m_test == TEST_DEFAULT_LAYER)
2984 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
2985 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
2986 " v_frag_FragColor = white;\n"
2987 " EmitVertex();\n\n"
2988 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2989 " v_frag_FragColor = white;\n"
2990 " EmitVertex();\n\n"
2991 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
2992 " v_frag_FragColor = white;\n"
2993 " EmitVertex();\n\n"
2994 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
2995 " v_frag_FragColor = white;\n"
2998 else if (m_test == TEST_SINGLE_LAYER)
3000 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3001 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3002 " gl_Layer = " << m_targetLayer << ";\n"
3003 " v_frag_FragColor = white;\n"
3004 " EmitVertex();\n\n"
3005 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3006 " gl_Layer = " << m_targetLayer << ";\n"
3007 " v_frag_FragColor = white;\n"
3008 " EmitVertex();\n\n"
3009 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3010 " gl_Layer = " << m_targetLayer << ";\n"
3011 " v_frag_FragColor = white;\n"
3012 " EmitVertex();\n\n"
3013 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3014 " gl_Layer = " << m_targetLayer << ";\n"
3015 " v_frag_FragColor = white;\n"
3018 else if (m_test == TEST_ALL_LAYERS || m_test == TEST_LAYER_ID)
3020 DE_ASSERT(m_numLayers <= 6);
3022 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3023 " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3024 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3025 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3026 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3027 " const highp vec4 magenta = vec4(1.0, 0.0, 1.0, 1.0);\n"
3028 " const highp vec4 colors[6] = vec4[6](white, red, green, blue, yellow, magenta);\n\n"
3029 " for (mediump int layerNdx = 0; layerNdx < " << m_numLayers << "; ++layerNdx)\n"
3031 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3032 " gl_Layer = layerNdx;\n"
3033 " v_frag_FragColor = colors[layerNdx];\n"
3034 " EmitVertex();\n\n"
3035 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3036 " gl_Layer = layerNdx;\n"
3037 " v_frag_FragColor = colors[layerNdx];\n"
3038 " EmitVertex();\n\n"
3039 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3040 " gl_Layer = layerNdx;\n"
3041 " v_frag_FragColor = colors[layerNdx];\n"
3042 " EmitVertex();\n\n"
3043 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3044 " gl_Layer = layerNdx;\n"
3045 " v_frag_FragColor = colors[layerNdx];\n"
3047 " EndPrimitive();\n"
3050 else if (m_test == TEST_DIFFERENT_LAYERS)
3052 DE_ASSERT(m_numLayers <= 6);
3054 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3055 " for (mediump int layerNdx = 0; layerNdx < " << m_numLayers << "; ++layerNdx)\n"
3057 " for (mediump int colNdx = 0; colNdx <= layerNdx; ++colNdx)\n"
3059 " highp float posX = float(colNdx) / float(" << m_numLayers << ") * 2.0 - 1.0;\n\n"
3060 " gl_Position = vec4(posX, 1.0, 0.0, 1.0);\n"
3061 " gl_Layer = layerNdx;\n"
3062 " v_frag_FragColor = white;\n"
3063 " EmitVertex();\n\n"
3064 " gl_Position = vec4(posX, -1.0, 0.0, 1.0);\n"
3065 " gl_Layer = layerNdx;\n"
3066 " v_frag_FragColor = white;\n"
3069 " EndPrimitive();\n"
3072 else if (m_test == TEST_INVOCATION_PER_LAYER)
3074 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3075 " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3076 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3077 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3078 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3079 " const highp vec4 magenta = vec4(1.0, 0.0, 1.0, 1.0);\n"
3080 " const highp vec4 colors[6] = vec4[6](white, red, green, blue, yellow, magenta);\n"
3082 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3083 " gl_Layer = gl_InvocationID;\n"
3084 " v_frag_FragColor = colors[gl_InvocationID];\n"
3085 " EmitVertex();\n\n"
3086 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3087 " gl_Layer = gl_InvocationID;\n"
3088 " v_frag_FragColor = colors[gl_InvocationID];\n"
3089 " EmitVertex();\n\n"
3090 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3091 " gl_Layer = gl_InvocationID;\n"
3092 " v_frag_FragColor = colors[gl_InvocationID];\n"
3093 " EmitVertex();\n\n"
3094 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3095 " gl_Layer = gl_InvocationID;\n"
3096 " v_frag_FragColor = colors[gl_InvocationID];\n"
3098 " EndPrimitive();\n";
3100 else if (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
3102 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3104 " mediump int layerA = gl_InvocationID;\n"
3105 " mediump int layerB = (gl_InvocationID + 1) % " << m_numLayers << ";\n"
3106 " highp float aEnd = float(layerA) / float(" << m_numLayers << ") * 2.0 - 1.0;\n"
3107 " highp float bEnd = float(layerB) / float(" << m_numLayers << ") * 2.0 - 1.0;\n"
3109 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3110 " gl_Layer = layerA;\n"
3111 " v_frag_FragColor = white;\n"
3112 " EmitVertex();\n\n"
3113 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3114 " gl_Layer = layerA;\n"
3115 " v_frag_FragColor = white;\n"
3116 " EmitVertex();\n\n"
3117 " gl_Position = vec4(aEnd, -1.0, 0.0, 1.0);\n"
3118 " gl_Layer = layerA;\n"
3119 " v_frag_FragColor = white;\n"
3120 " EmitVertex();\n\n"
3121 " EndPrimitive();\n"
3123 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3124 " gl_Layer = layerB;\n"
3125 " v_frag_FragColor = white;\n"
3126 " EmitVertex();\n\n"
3127 " gl_Position = vec4(bEnd, 1.0, 0.0, 1.0);\n"
3128 " gl_Layer = layerB;\n"
3129 " v_frag_FragColor = white;\n"
3130 " EmitVertex();\n\n"
3131 " gl_Position = vec4(bEnd, -1.0, 0.0, 1.0);\n"
3132 " gl_Layer = layerB;\n"
3133 " v_frag_FragColor = white;\n"
3134 " EmitVertex();\n\n"
3135 " EndPrimitive();\n";
3137 else if (m_test == TEST_LAYER_PROVOKING_VERTEX)
3139 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3140 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3142 " v_frag_FragColor = white;\n"
3143 " EmitVertex();\n\n"
3144 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3146 " v_frag_FragColor = white;\n"
3147 " EmitVertex();\n\n"
3148 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3150 " v_frag_FragColor = white;\n"
3151 " EmitVertex();\n\n"
3152 " EndPrimitive();\n\n"
3153 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3155 " v_frag_FragColor = white;\n"
3156 " EmitVertex();\n\n"
3157 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3159 " v_frag_FragColor = white;\n"
3160 " EmitVertex();\n\n"
3161 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3163 " v_frag_FragColor = white;\n"
3167 DE_ASSERT(DE_FALSE);
3174 std::string LayeredRenderCase::genSamplerFragmentSource (void) const
3176 std::ostringstream buf;
3178 buf << "#version 310 es\n";
3179 if (m_target == TARGET_2D_MS_ARRAY)
3180 buf << "#extension GL_OES_texture_storage_multisample_2d_array : require\n";
3181 buf << "layout(location = 0) out mediump vec4 fragColor;\n";
3185 case TARGET_CUBE: buf << "uniform highp samplerCube u_sampler;\n"; break;
3186 case TARGET_3D: buf << "uniform highp sampler3D u_sampler;\n"; break;
3187 case TARGET_2D_ARRAY: buf << "uniform highp sampler2DArray u_sampler;\n"; break;
3188 case TARGET_1D_ARRAY: buf << "uniform highp sampler1DArray u_sampler;\n"; break;
3189 case TARGET_2D_MS_ARRAY: buf << "uniform highp sampler2DMSArray u_sampler;\n"; break;
3191 DE_ASSERT(DE_FALSE);
3194 buf << "uniform highp int u_layer;\n"
3195 "void main (void)\n"
3201 buf << " highp vec2 facepos = 2.0 * gl_FragCoord.xy / vec2(ivec2(" << m_resolveDimensions.x() << ", " << m_resolveDimensions.y() << ")) - vec2(1.0, 1.0);\n"
3202 " if (u_layer == 0)\n"
3203 " fragColor = textureLod(u_sampler, vec3(1.0, -facepos.y, -facepos.x), 0.0);\n"
3204 " else if (u_layer == 1)\n"
3205 " fragColor = textureLod(u_sampler, vec3(-1.0, -facepos.y, facepos.x), 0.0);\n"
3206 " else if (u_layer == 2)\n"
3207 " fragColor = textureLod(u_sampler, vec3(facepos.x, 1.0, facepos.y), 0.0);\n"
3208 " else if (u_layer == 3)\n"
3209 " fragColor = textureLod(u_sampler, vec3(facepos.x, -1.0, -facepos.y), 0.0);\n"
3210 " else if (u_layer == 4)\n"
3211 " fragColor = textureLod(u_sampler, vec3(facepos.x, -facepos.y, 1.0), 0.0);\n"
3212 " else if (u_layer == 5)\n"
3213 " fragColor = textureLod(u_sampler, vec3(-facepos.x, -facepos.y, -1.0), 0.0);\n"
3215 " fragColor = vec4(1.0, 0.0, 1.0, 1.0);\n";
3219 case TARGET_2D_ARRAY:
3220 case TARGET_2D_MS_ARRAY:
3221 buf << " highp ivec2 screenpos = ivec2(floor(gl_FragCoord.xy));\n"
3222 " fragColor = texelFetch(u_sampler, ivec3(screenpos, u_layer), 0);\n";
3225 case TARGET_1D_ARRAY:
3226 buf << " highp ivec2 screenpos = ivec2(floor(gl_FragCoord.xy));\n"
3227 " fragColor = texelFetch(u_sampler, ivec2(screenpos.x, u_layer), 0);\n";
3231 DE_ASSERT(DE_FALSE);
3237 void LayeredRenderCase::renderToTexture (void)
3239 const tcu::IVec3 texSize = getTargetDimensions(m_target);
3240 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3241 glu::VertexArray vao (m_context.getRenderContext());
3243 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to texture" << tcu::TestLog::EndMessage;
3245 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
3246 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3247 gl.clear(GL_COLOR_BUFFER_BIT);
3248 gl.viewport(0, 0, texSize.x(), texSize.y());
3249 gl.clear(GL_COLOR_BUFFER_BIT);
3251 gl.bindVertexArray(*vao);
3252 gl.useProgram(m_renderShader->getProgram());
3253 gl.drawArrays(GL_POINTS, 0, 1);
3255 gl.bindVertexArray(0);
3256 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
3258 GLU_EXPECT_NO_ERROR(gl.getError(), "render");
3261 void LayeredRenderCase::sampleTextureLayer (tcu::Surface& dst, int layer)
3263 DE_ASSERT(dst.getWidth() == m_resolveDimensions.x());
3264 DE_ASSERT(dst.getHeight() == m_resolveDimensions.y());
3266 static const tcu::Vec4 fullscreenQuad[4] =
3268 tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
3269 tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
3270 tcu::Vec4( 1.0f, -1.0f, 0.0f, 1.0f),
3271 tcu::Vec4( 1.0f, 1.0f, 0.0f, 1.0f),
3274 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3275 const int positionLoc = gl.getAttribLocation(m_samplerShader->getProgram(), "a_position");
3276 glu::VertexArray vao (m_context.getRenderContext());
3277 glu::Buffer buf (m_context.getRenderContext());
3279 m_testCtx.getLog() << tcu::TestLog::Message << "Sampling from texture layer " << layer << tcu::TestLog::EndMessage;
3281 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3282 gl.clear(GL_COLOR_BUFFER_BIT);
3283 gl.viewport(0, 0, m_resolveDimensions.x(), m_resolveDimensions.y());
3284 GLU_EXPECT_NO_ERROR(gl.getError(), "clear");
3286 gl.bindBuffer(GL_ARRAY_BUFFER, *buf);
3287 gl.bufferData(GL_ARRAY_BUFFER, sizeof(fullscreenQuad), fullscreenQuad, GL_STATIC_DRAW);
3288 GLU_EXPECT_NO_ERROR(gl.getError(), "buf");
3290 gl.bindVertexArray(*vao);
3291 gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
3292 gl.enableVertexAttribArray(positionLoc);
3293 GLU_EXPECT_NO_ERROR(gl.getError(), "setup attribs");
3295 gl.activeTexture(GL_TEXTURE0);
3296 gl.bindTexture(getTargetTextureTarget(m_target), m_texture);
3297 GLU_EXPECT_NO_ERROR(gl.getError(), "bind texture");
3299 gl.useProgram(m_samplerShader->getProgram());
3300 gl.uniform1i(m_samplerLayerLoc, layer);
3301 gl.uniform1i(m_samplerSamplerLoc, 0);
3302 GLU_EXPECT_NO_ERROR(gl.getError(), "setup program");
3304 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3305 GLU_EXPECT_NO_ERROR(gl.getError(), "draw");
3308 gl.bindVertexArray(0);
3309 GLU_EXPECT_NO_ERROR(gl.getError(), "clean");
3311 glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
3314 bool LayeredRenderCase::verifyLayerContent (const tcu::Surface& layer, int layerNdx)
3316 const tcu::Vec4 white = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
3317 const tcu::Vec4 red = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
3318 const tcu::Vec4 green = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
3319 const tcu::Vec4 blue = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
3320 const tcu::Vec4 yellow = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
3321 const tcu::Vec4 magenta = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
3322 const tcu::Vec4 colors[6] = { white, red, green, blue, yellow, magenta };
3324 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying layer contents" << tcu::TestLog::EndMessage;
3328 case TEST_DEFAULT_LAYER:
3330 return verifyImageSingleColoredRow(layer, 0.5f, white);
3332 return verifyEmptyImage(layer);
3334 case TEST_SINGLE_LAYER:
3335 if (layerNdx == m_targetLayer)
3336 return verifyImageSingleColoredRow(layer, 0.5f, white);
3338 return verifyEmptyImage(layer);
3340 case TEST_ALL_LAYERS:
3341 case TEST_INVOCATION_PER_LAYER:
3342 return verifyImageSingleColoredRow(layer, 0.5f, colors[layerNdx]);
3344 case TEST_DIFFERENT_LAYERS:
3345 case TEST_MULTIPLE_LAYERS_PER_INVOCATION:
3347 return verifyEmptyImage(layer);
3349 return verifyImageSingleColoredRow(layer, layerNdx / (float)m_numLayers, white);
3353 const tcu::Vec4 layerColor((layerNdx % 2 == 1) ? (1.0f) : (0.5f),
3354 ((layerNdx/2) % 2 == 1) ? (1.0f) : (0.5f),
3355 (layerNdx == 0) ? (1.0f) : (0.0f),
3357 return verifyImageSingleColoredRow(layer, 0.5f, layerColor);
3360 case TEST_LAYER_PROVOKING_VERTEX:
3361 if (m_provokingVertex == GL_FIRST_VERTEX_CONVENTION)
3364 return verifyImageSingleColoredRow(layer, 0.5f, white);
3366 return verifyEmptyImage(layer);
3368 else if (m_provokingVertex == GL_LAST_VERTEX_CONVENTION)
3371 return verifyImageSingleColoredRow(layer, 0.5f, white);
3373 return verifyEmptyImage(layer);
3382 DE_ASSERT(DE_FALSE);
3387 bool LayeredRenderCase::verifyImageSingleColoredRow (const tcu::Surface& layer, float rowWidthRatio, const tcu::Vec4& barColor, bool logging)
3389 DE_ASSERT(rowWidthRatio > 0.0f);
3391 const int barLength = (int)(rowWidthRatio*layer.getWidth());
3392 const int barLengthThreshold = 1;
3393 tcu::Surface errorMask (layer.getWidth(), layer.getHeight());
3394 bool allPixelsOk = true;
3397 m_testCtx.getLog() << tcu::TestLog::Message << "Expecting all pixels with distance less or equal to (about) " << barLength << " pixels from left border to be of color " << barColor.swizzle(0,1,2) << "." << tcu::TestLog::EndMessage;
3399 tcu::clear(errorMask.getAccess(), tcu::RGBA::green.toIVec());
3401 for (int y = 0; y < layer.getHeight(); ++y)
3402 for (int x = 0; x < layer.getWidth(); ++x)
3404 const tcu::RGBA color = layer.getPixel(x, y);
3405 const tcu::RGBA refColor = tcu::RGBA(barColor);
3406 const int threshold = 8;
3407 const bool isBlack = color.getRed() <= threshold || color.getGreen() <= threshold || color.getBlue() <= threshold;
3408 const bool isColor = tcu::allEqual(tcu::lessThan(tcu::abs(color.toIVec().swizzle(0, 1, 2) - refColor.toIVec().swizzle(0, 1, 2)), tcu::IVec3(threshold, threshold, threshold)), tcu::BVec3(true, true, true));
3412 if (x <= barLength - barLengthThreshold)
3414 else if (x >= barLength + barLengthThreshold)
3417 isOk = isColor || isBlack;
3419 allPixelsOk &= isOk;
3422 errorMask.setPixel(x, y, tcu::RGBA::red);
3428 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid." << tcu::TestLog::EndMessage
3429 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3430 << tcu::TestLog::Image("Layer", "Layer", layer)
3431 << tcu::TestLog::EndImageSet;
3437 m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed. Got unexpected pixels." << tcu::TestLog::EndMessage
3438 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3439 << tcu::TestLog::Image("Layer", "Layer", layer)
3440 << tcu::TestLog::Image("ErrorMask", "Errors", errorMask)
3441 << tcu::TestLog::EndImageSet;
3446 m_testCtx.getLog() << tcu::TestLog::Image("LayerContent", "Layer content", layer);
3451 bool LayeredRenderCase::verifyEmptyImage (const tcu::Surface& layer, bool logging)
3455 m_testCtx.getLog() << tcu::TestLog::Message << "Expecting empty image" << tcu::TestLog::EndMessage;
3457 for (int y = 0; y < layer.getHeight(); ++y)
3458 for (int x = 0; x < layer.getWidth(); ++x)
3460 const tcu::RGBA color = layer.getPixel(x, y);
3461 const int threshold = 8;
3462 const bool isBlack = color.getRed() <= threshold || color.getGreen() <= threshold || color.getBlue() <= threshold;
3467 m_testCtx.getLog() << tcu::TestLog::Message
3468 << "Found (at least) one bad pixel at " << x << "," << y << ". Pixel color is not background color."
3469 << tcu::TestLog::EndMessage
3470 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3471 << tcu::TestLog::Image("Layer", "Layer", layer)
3472 << tcu::TestLog::EndImageSet;
3478 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid" << tcu::TestLog::EndMessage;
3483 bool LayeredRenderCase::verifyProvokingVertexLayers (const tcu::Surface& layer0, const tcu::Surface& layer1)
3485 const bool layer0Empty = verifyEmptyImage(layer0, false);
3486 const bool layer1Empty = verifyEmptyImage(layer1, false);
3489 // Both images could contain something if the quad triangles get assigned to different layers
3490 m_testCtx.getLog() << tcu::TestLog::Message << "Expecting non-empty layers, or non-empty layer." << tcu::TestLog::EndMessage;
3492 if (layer0Empty == true && layer1Empty == true)
3494 m_testCtx.getLog() << tcu::TestLog::Message << "Got empty images." << tcu::TestLog::EndMessage;
3498 // log images always
3500 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3501 << tcu::TestLog::Image("Layer", "Layer0", layer0)
3502 << tcu::TestLog::Image("Layer", "Layer1", layer1)
3503 << tcu::TestLog::EndImageSet;
3506 m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed." << tcu::TestLog::EndMessage;
3508 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid." << tcu::TestLog::EndMessage;
3513 int LayeredRenderCase::getTargetLayers (LayeredRenderTargetType target)
3517 case TARGET_CUBE: return 6;
3518 case TARGET_3D: return 4;
3519 case TARGET_1D_ARRAY: return 4;
3520 case TARGET_2D_ARRAY: return 4;
3521 case TARGET_2D_MS_ARRAY: return 2;
3523 DE_ASSERT(DE_FALSE);
3528 glw::GLenum LayeredRenderCase::getTargetTextureTarget (LayeredRenderTargetType target)
3532 case TARGET_CUBE: return GL_TEXTURE_CUBE_MAP;
3533 case TARGET_3D: return GL_TEXTURE_3D;
3534 case TARGET_1D_ARRAY: return GL_TEXTURE_1D_ARRAY;
3535 case TARGET_2D_ARRAY: return GL_TEXTURE_2D_ARRAY;
3536 case TARGET_2D_MS_ARRAY: return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3538 DE_ASSERT(DE_FALSE);
3543 tcu::IVec3 LayeredRenderCase::getTargetDimensions (LayeredRenderTargetType target)
3547 case TARGET_CUBE: return tcu::IVec3(64, 64, 0);
3548 case TARGET_3D: return tcu::IVec3(64, 64, 4);
3549 case TARGET_1D_ARRAY: return tcu::IVec3(64, 4, 0);
3550 case TARGET_2D_ARRAY: return tcu::IVec3(64, 64, 4);
3551 case TARGET_2D_MS_ARRAY: return tcu::IVec3(64, 64, 2);
3553 DE_ASSERT(DE_FALSE);
3554 return tcu::IVec3(0, 0, 0);
3558 tcu::IVec2 LayeredRenderCase::getResolveDimensions (LayeredRenderTargetType target)
3562 case TARGET_CUBE: return tcu::IVec2(64, 64);
3563 case TARGET_3D: return tcu::IVec2(64, 64);
3564 case TARGET_1D_ARRAY: return tcu::IVec2(64, 1);
3565 case TARGET_2D_ARRAY: return tcu::IVec2(64, 64);
3566 case TARGET_2D_MS_ARRAY: return tcu::IVec2(64, 64);
3568 DE_ASSERT(DE_FALSE);
3569 return tcu::IVec2(0, 0);
3573 class VaryingOutputCountCase : public GeometryShaderRenderTest
3576 enum ShaderInstancingMode
3578 MODE_WITHOUT_INSTANCING = 0,
3579 MODE_WITH_INSTANCING,
3583 VaryingOutputCountCase (Context& context, const char* name, const char* desc, VaryingOutputCountShader::VaryingSource test, ShaderInstancingMode mode);
3587 void preRender (sglr::Context& ctx, GLuint programID);
3589 sglr::ShaderProgram& getProgram (void);
3590 void genVertexAttribData (void);
3591 void genVertexDataWithoutInstancing (void);
3592 void genVertexDataWithInstancing (void);
3594 VaryingOutputCountShader* m_program;
3595 const VaryingOutputCountShader::VaryingSource m_test;
3596 const ShaderInstancingMode m_mode;
3600 VaryingOutputCountCase::VaryingOutputCountCase (Context& context, const char* name, const char* desc, VaryingOutputCountShader::VaryingSource test, ShaderInstancingMode mode)
3601 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_TRIANGLE_STRIP, VaryingOutputCountShader::getAttributeName(test))
3602 , m_program (DE_NULL)
3605 , m_maxEmitCount (0)
3607 DE_ASSERT(mode < MODE_LAST);
3610 void VaryingOutputCountCase::init (void)
3612 // Check requirements
3614 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
3615 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
3617 if (m_test == VaryingOutputCountShader::READ_TEXTURE)
3619 glw::GLint maxTextures = 0;
3621 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxTextures);
3623 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS = " << maxTextures << tcu::TestLog::EndMessage;
3625 if (maxTextures < 1)
3626 throw tcu::NotSupportedError("Geometry shader texture units required");
3629 // Get max emit count
3631 const int componentsPerVertex = 4 + 4; // vec4 pos, vec4 color
3632 glw::GLint maxVertices = 0;
3633 glw::GLint maxComponents = 0;
3635 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxVertices);
3636 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
3638 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_OUTPUT_VERTICES = " << maxVertices << tcu::TestLog::EndMessage;
3639 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = " << maxComponents << tcu::TestLog::EndMessage;
3640 m_testCtx.getLog() << tcu::TestLog::Message << "Components per vertex = " << componentsPerVertex << tcu::TestLog::EndMessage;
3642 if (maxVertices < 256)
3643 throw tcu::TestError("MAX_GEOMETRY_OUTPUT_VERTICES was less than minimum required (256)");
3644 if (maxComponents < 1024)
3645 throw tcu::TestError("MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS was less than minimum required (1024)");
3647 m_maxEmitCount = de::min(maxVertices, maxComponents / componentsPerVertex);
3650 // Log what the test tries to do
3653 << tcu::TestLog::Message
3654 << "Rendering 4 n-gons with n = "
3655 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_0 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0)) << ", "
3656 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_1 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1)) << ", "
3657 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_2 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2)) << ", and "
3658 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_3 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3)) << ".\n"
3659 << "N is supplied to the geomery shader with "
3660 << ((m_test == VaryingOutputCountShader::READ_ATTRIBUTE) ? ("attribute") : (m_test == VaryingOutputCountShader::READ_UNIFORM) ? ("uniform") : ("texture"))
3661 << tcu::TestLog::EndMessage;
3665 const bool instanced = (m_mode == MODE_WITH_INSTANCING);
3667 DE_ASSERT(!m_program);
3668 m_program = new VaryingOutputCountShader(m_test, m_maxEmitCount, instanced);
3672 GeometryShaderRenderTest::init();
3675 void VaryingOutputCountCase::deinit (void)
3680 m_program = DE_NULL;
3683 GeometryShaderRenderTest::deinit();
3686 void VaryingOutputCountCase::preRender (sglr::Context& ctx, GLuint programID)
3688 if (m_test == VaryingOutputCountShader::READ_UNIFORM)
3690 const int location = ctx.getUniformLocation(programID, "u_emitCount");
3691 const deInt32 emitCount[4] = { 6, 0, m_maxEmitCount, 10 };
3694 throw tcu::TestError("uniform location of u_emitCount was -1.");
3696 ctx.uniform4iv(location, 1, emitCount);
3698 else if (m_test == VaryingOutputCountShader::READ_TEXTURE)
3700 const deUint8 data[4*4] =
3707 const int location = ctx.getUniformLocation(programID, "u_sampler");
3711 throw tcu::TestError("uniform location of u_sampler was -1.");
3712 ctx.uniform1i(location, 0);
3714 // \note we don't need to explicitly delete the texture, the sglr context will delete it
3715 ctx.genTextures(1, &texID);
3716 ctx.bindTexture(GL_TEXTURE_2D, texID);
3717 ctx.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
3718 ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3719 ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3723 sglr::ShaderProgram& VaryingOutputCountCase::getProgram (void)
3728 void VaryingOutputCountCase::genVertexAttribData (void)
3730 if (m_mode == MODE_WITHOUT_INSTANCING)
3731 genVertexDataWithoutInstancing();
3732 else if (m_mode == MODE_WITH_INSTANCING)
3733 genVertexDataWithInstancing();
3738 void VaryingOutputCountCase::genVertexDataWithoutInstancing (void)
3740 m_numDrawVertices = 4;
3742 m_vertexPosData.resize(4);
3743 m_vertexAttrData.resize(4);
3745 m_vertexPosData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 1.0f);
3746 m_vertexPosData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 1.0f);
3747 m_vertexPosData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 1.0f);
3748 m_vertexPosData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 1.0f);
3750 if (m_test == VaryingOutputCountShader::READ_ATTRIBUTE)
3752 m_vertexAttrData[0] = tcu::Vec4(((VaryingOutputCountShader::EMIT_COUNT_VERTEX_0 == -1) ? ((float)m_maxEmitCount) : ((float)VaryingOutputCountShader::EMIT_COUNT_VERTEX_0)), 0.0f, 0.0f, 0.0f);
3753 m_vertexAttrData[1] = tcu::Vec4(((VaryingOutputCountShader::EMIT_COUNT_VERTEX_1 == -1) ? ((float)m_maxEmitCount) : ((float)VaryingOutputCountShader::EMIT_COUNT_VERTEX_1)), 0.0f, 0.0f, 0.0f);
3754 m_vertexAttrData[2] = tcu::Vec4(((VaryingOutputCountShader::EMIT_COUNT_VERTEX_2 == -1) ? ((float)m_maxEmitCount) : ((float)VaryingOutputCountShader::EMIT_COUNT_VERTEX_2)), 0.0f, 0.0f, 0.0f);
3755 m_vertexAttrData[3] = tcu::Vec4(((VaryingOutputCountShader::EMIT_COUNT_VERTEX_3 == -1) ? ((float)m_maxEmitCount) : ((float)VaryingOutputCountShader::EMIT_COUNT_VERTEX_3)), 0.0f, 0.0f, 0.0f);
3759 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
3760 m_vertexAttrData[1] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
3761 m_vertexAttrData[2] = tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f);
3762 m_vertexAttrData[3] = tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f);
3766 void VaryingOutputCountCase::genVertexDataWithInstancing (void)
3768 m_numDrawVertices = 1;
3770 m_vertexPosData.resize(1);
3771 m_vertexAttrData.resize(1);
3773 m_vertexPosData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
3775 if (m_test == VaryingOutputCountShader::READ_ATTRIBUTE)
3777 const int emitCounts[] =
3779 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0),
3780 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1),
3781 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2),
3782 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3),
3785 m_vertexAttrData[0] = tcu::Vec4((float)emitCounts[0], (float)emitCounts[1], (float)emitCounts[2], (float)emitCounts[3]);
3790 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
3794 class GeometryProgramQueryCase : public TestCase
3799 const char* description;
3804 GeometryProgramQueryCase (Context& context, const char* name, const char* description, glw::GLenum target);
3807 IterateResult iterate (void);
3810 void expectProgramValue (deUint32 program, int value);
3811 void expectQueryError (deUint32 program);
3813 const glw::GLenum m_target;
3816 std::vector<ProgramCase> m_cases;
3819 GeometryProgramQueryCase::GeometryProgramQueryCase (Context& context, const char* name, const char* description, glw::GLenum target)
3820 : TestCase (context, name, description)
3825 void GeometryProgramQueryCase::init (void)
3827 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
3828 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
3831 GeometryProgramQueryCase::IterateResult GeometryProgramQueryCase::iterate (void)
3833 static const char* const s_vertexSource = "#version 310 es\n"
3836 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
3838 static const char* const s_fragmentSource = "#version 310 es\n"
3839 "layout(location = 0) out mediump vec4 fragColor;\n"
3842 " fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
3844 static const char* const s_geometryBody = "void main ()\n"
3846 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
3850 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3853 for (int ndx = 0; ndx < (int)m_cases.size(); ++ndx)
3855 const tcu::ScopedLogSection section (m_testCtx.getLog(), "Case", m_cases[ndx].description);
3856 const std::string geometrySource = m_cases[ndx].header + std::string(s_geometryBody);
3857 const glu::ShaderProgram program (m_context.getRenderContext(),
3858 glu::ProgramSources()
3859 << glu::VertexSource(s_vertexSource)
3860 << glu::FragmentSource(s_fragmentSource)
3861 << glu::GeometrySource(geometrySource));
3863 m_testCtx.getLog() << program;
3864 expectProgramValue(program.getProgram(), m_cases[ndx].value);
3867 // no geometry shader -case (INVALID OP)
3869 const tcu::ScopedLogSection section (m_testCtx.getLog(), "NoGeometryShader", "No geometry shader");
3870 const glu::ShaderProgram program (m_context.getRenderContext(),
3871 glu::ProgramSources()
3872 << glu::VertexSource(s_vertexSource)
3873 << glu::FragmentSource(s_fragmentSource));
3875 m_testCtx.getLog() << program;
3876 expectQueryError(program.getProgram());
3879 // not linked -case (INVALID OP)
3881 const tcu::ScopedLogSection section (m_testCtx.getLog(), "NotLinkedProgram", "Shader program not linked");
3882 const std::string geometrySource = "#version 310 es\n"
3883 "#extension GL_EXT_geometry_shader : require\n"
3884 "layout (triangles) in;\n"
3885 "layout (points, max_vertices = 3) out;\n"
3886 + std::string(s_geometryBody);
3889 glu::Shader vertexShader (m_context.getRenderContext(), glu::SHADERTYPE_VERTEX);
3890 glu::Shader fragmentShader (m_context.getRenderContext(), glu::SHADERTYPE_FRAGMENT);
3891 glu::Shader geometryShader (m_context.getRenderContext(), glu::SHADERTYPE_GEOMETRY);
3892 glu::Program program (m_context.getRenderContext());
3894 const char* const geometrySourceArray[1] = { geometrySource.c_str() };
3896 vertexShader.setSources(1, &s_vertexSource, DE_NULL);
3897 fragmentShader.setSources(1, &s_fragmentSource, DE_NULL);
3898 geometryShader.setSources(1, geometrySourceArray, DE_NULL);
3900 vertexShader.compile();
3901 fragmentShader.compile();
3902 geometryShader.compile();
3904 if (!vertexShader.getCompileStatus() ||
3905 !fragmentShader.getCompileStatus() ||
3906 !geometryShader.getCompileStatus())
3907 throw tcu::TestError("Failed to compile shader");
3909 program.attachShader(vertexShader.getShader());
3910 program.attachShader(fragmentShader.getShader());
3911 program.attachShader(geometryShader.getShader());
3913 m_testCtx.getLog() << tcu::TestLog::Message << "Creating a program with geometry shader, but not linking it" << tcu::TestLog::EndMessage;
3915 expectQueryError(program.getProgram());
3921 void GeometryProgramQueryCase::expectProgramValue (deUint32 program, int value)
3923 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3924 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
3926 gl.getProgramiv(program, m_target, &state);
3927 GLU_EXPECT_NO_ERROR(gl.getError(), "getProgramiv");
3929 m_testCtx.getLog() << tcu::TestLog::Message << glu::getProgramParamStr(m_target) << " = " << state << tcu::TestLog::EndMessage;
3933 m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: Expected " << value << ", got " << state << tcu::TestLog::EndMessage;
3935 // don't overwrite error
3936 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
3937 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
3941 void GeometryProgramQueryCase::expectQueryError (deUint32 program)
3943 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3945 glw::GLenum errorCode;
3947 m_testCtx.getLog() << tcu::TestLog::Message << "Querying " << glu::getProgramParamStr(m_target) << ", expecting INVALID_OPERATION" << tcu::TestLog::EndMessage;
3948 gl.getProgramiv(program, m_target, &dummy);
3950 errorCode = gl.getError();
3952 if (errorCode != GL_INVALID_OPERATION)
3954 m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: Expected INVALID_OPERATION, got " << glu::getErrorStr(errorCode) << tcu::TestLog::EndMessage;
3956 // don't overwrite error
3957 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
3958 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected error code");
3962 class GeometryShaderInvocationsQueryCase : public GeometryProgramQueryCase
3965 GeometryShaderInvocationsQueryCase(Context& context, const char* name, const char* description);
3968 GeometryShaderInvocationsQueryCase::GeometryShaderInvocationsQueryCase(Context& context, const char* name, const char* description)
3969 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_SHADER_INVOCATIONS)
3974 m_cases[0].description = "Default value";
3975 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
3976 m_cases[0].value = 1;
3978 m_cases[1].description = "Value declared";
3979 m_cases[1].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles, invocations=2) in;\nlayout (points, max_vertices = 3) out;\n";
3980 m_cases[1].value = 2;
3983 class GeometryShaderVerticesQueryCase : public GeometryProgramQueryCase
3986 GeometryShaderVerticesQueryCase(Context& context, const char* name, const char* description);
3989 GeometryShaderVerticesQueryCase::GeometryShaderVerticesQueryCase(Context& context, const char* name, const char* description)
3990 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_VERTICES_OUT_EXT)
3994 m_cases[0].description = "max_vertices = 1";
3995 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 1) out;\n";
3996 m_cases[0].value = 1;
3999 class GeometryShaderInputQueryCase : public GeometryProgramQueryCase
4002 GeometryShaderInputQueryCase(Context& context, const char* name, const char* description);
4005 GeometryShaderInputQueryCase::GeometryShaderInputQueryCase(Context& context, const char* name, const char* description)
4006 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_INPUT_TYPE_EXT)
4010 m_cases[0].description = "Triangles";
4011 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
4012 m_cases[0].value = GL_TRIANGLES;
4014 m_cases[1].description = "Lines";
4015 m_cases[1].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (lines) in;\nlayout (points, max_vertices = 3) out;\n";
4016 m_cases[1].value = GL_LINES;
4018 m_cases[2].description = "Points";
4019 m_cases[2].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (points) in;\nlayout (points, max_vertices = 3) out;\n";
4020 m_cases[2].value = GL_POINTS;
4023 class GeometryShaderOutputQueryCase : public GeometryProgramQueryCase
4026 GeometryShaderOutputQueryCase(Context& context, const char* name, const char* description);
4029 GeometryShaderOutputQueryCase::GeometryShaderOutputQueryCase(Context& context, const char* name, const char* description)
4030 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT)
4034 m_cases[0].description = "Triangle strip";
4035 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (triangle_strip, max_vertices = 3) out;\n";
4036 m_cases[0].value = GL_TRIANGLE_STRIP;
4038 m_cases[1].description = "Lines";
4039 m_cases[1].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (line_strip, max_vertices = 3) out;\n";
4040 m_cases[1].value = GL_LINE_STRIP;
4042 m_cases[2].description = "Points";
4043 m_cases[2].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
4044 m_cases[2].value = GL_POINTS;
4047 class ImplementationLimitCase : public TestCase
4050 ImplementationLimitCase (Context& context, const char* name, const char* description, glw::GLenum target, int minValue);
4053 IterateResult iterate (void);
4055 const glw::GLenum m_target;
4056 const int m_minValue;
4059 ImplementationLimitCase::ImplementationLimitCase (Context& context, const char* name, const char* description, glw::GLenum target, int minValue)
4060 : TestCase (context, name, description)
4062 , m_minValue (minValue)
4066 void ImplementationLimitCase::init (void)
4068 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4069 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4072 ImplementationLimitCase::IterateResult ImplementationLimitCase::iterate (void)
4074 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4075 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4077 gl.enableLogging(true);
4078 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER);
4081 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4082 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_BOOLEAN);
4083 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER64);
4084 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_FLOAT);
4087 result.setTestContextResult(m_testCtx);
4091 class LayerProvokingVertexQueryCase : public TestCase
4094 LayerProvokingVertexQueryCase (Context& context, const char* name, const char* description);
4097 IterateResult iterate (void);
4100 LayerProvokingVertexQueryCase::LayerProvokingVertexQueryCase(Context& context, const char* name, const char* description)
4101 : TestCase(context, name, description)
4105 void LayerProvokingVertexQueryCase::init (void)
4107 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4108 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4111 LayerProvokingVertexQueryCase::IterateResult LayerProvokingVertexQueryCase::iterate (void)
4113 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4114 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4117 gl.enableLogging(true);
4118 queryState(result, gl, QUERY_INTEGER, GL_LAYER_PROVOKING_VERTEX, state);
4120 if (!state.isUndefined())
4122 m_testCtx.getLog() << tcu::TestLog::Message << "LAYER_PROVOKING_VERTEX = " << glu::getProvokingVertexStr(state.getIntAccess()) << tcu::TestLog::EndMessage;
4124 if (state.getIntAccess() != GL_FIRST_VERTEX_CONVENTION &&
4125 state.getIntAccess() != GL_LAST_VERTEX_CONVENTION &&
4126 state.getIntAccess() != GL_UNDEFINED_VERTEX)
4129 << tcu::TestLog::Message
4130 << "getInteger(GL_LAYER_PROVOKING_VERTEX) returned illegal value. Got "
4131 << state.getIntAccess() << "\n"
4132 << "Expected any of {FIRST_VERTEX_CONVENTION, LAST_VERTEX_CONVENTION, UNDEFINED_VERTEX}."
4133 << tcu::TestLog::EndMessage;
4135 result.fail("got unexpected provoking vertex value");
4139 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4140 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_BOOLEAN);
4141 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_INTEGER64);
4142 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_FLOAT);
4146 result.setTestContextResult(m_testCtx);
4150 class GeometryInvocationCase : public GeometryShaderRenderTest
4155 CASE_FIXED_OUTPUT_COUNTS = 0,
4156 CASE_DIFFERENT_OUTPUT_COUNTS,
4161 GeometryInvocationCase (Context& context, const char* name, const char* description, int numInvocations, OutputCase testCase);
4162 ~GeometryInvocationCase (void);
4168 sglr::ShaderProgram& getProgram (void);
4169 void genVertexAttribData (void);
4171 static InvocationCountShader::OutputCase mapToShaderCaseType (OutputCase testCase);
4173 const OutputCase m_testCase;
4174 int m_numInvocations;
4175 InvocationCountShader* m_program;
4178 GeometryInvocationCase::GeometryInvocationCase (Context& context, const char* name, const char* description, int numInvocations, OutputCase testCase)
4179 : GeometryShaderRenderTest (context, name, description, GL_POINTS, GL_TRIANGLE_STRIP, "a_color")
4180 , m_testCase (testCase)
4181 , m_numInvocations (numInvocations)
4182 , m_program (DE_NULL)
4184 DE_ASSERT(m_testCase < CASE_LAST);
4187 GeometryInvocationCase::~GeometryInvocationCase (void)
4192 void GeometryInvocationCase::init (void)
4194 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4195 int maxGeometryShaderInvocations = 0;
4196 int maxComponents = 0;
4200 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4201 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4203 gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_INVOCATIONS, &maxGeometryShaderInvocations);
4204 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv(GL_MAX_GEOMETRY_SHADER_INVOCATIONS)");
4206 gl.getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
4207 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS)");
4209 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_SHADER_INVOCATIONS = " << maxGeometryShaderInvocations << tcu::TestLog::EndMessage;
4211 // set target num invocations
4213 if (m_numInvocations == -1)
4214 m_numInvocations = maxGeometryShaderInvocations;
4215 else if (maxGeometryShaderInvocations < m_numInvocations)
4216 throw tcu::NotSupportedError("Test requires larger GL_MAX_GEOMETRY_SHADER_INVOCATIONS");
4218 if (m_testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
4220 const int maxEmitCount = m_numInvocations + 2;
4221 const int numComponents = 8; // pos + color
4222 if (maxEmitCount * numComponents > maxComponents)
4223 throw tcu::NotSupportedError("Test requires larger GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS");
4226 // Log what the test tries to do
4228 if (m_testCase == CASE_FIXED_OUTPUT_COUNTS)
4231 << tcu::TestLog::Message
4232 << "Rendering triangles in a partial circle formation with a geometry shader. Each triangle is generated by a separate invocation.\n"
4233 << "Drawing 2 points, each generating " << m_numInvocations << " triangles."
4234 << tcu::TestLog::EndMessage;
4236 else if (m_testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
4239 << tcu::TestLog::Message
4240 << "Rendering n-gons in a partial circle formation with a geometry shader. Each n-gon is generated by a separate invocation.\n"
4241 << "Drawing 2 points, each generating " << m_numInvocations << " n-gons."
4242 << tcu::TestLog::EndMessage;
4249 m_program = new InvocationCountShader(m_numInvocations, mapToShaderCaseType(m_testCase));
4251 GeometryShaderRenderTest::init();
4254 void GeometryInvocationCase::deinit (void)
4259 m_program = DE_NULL;
4262 GeometryShaderRenderTest::deinit();
4265 sglr::ShaderProgram& GeometryInvocationCase::getProgram (void)
4270 void GeometryInvocationCase::genVertexAttribData (void)
4272 m_vertexPosData.resize(2);
4273 m_vertexPosData[0] = tcu::Vec4(0.0f,-0.3f, 0.0f, 1.0f);
4274 m_vertexPosData[1] = tcu::Vec4(0.2f, 0.3f, 0.0f, 1.0f);
4276 m_vertexAttrData.resize(2);
4277 m_vertexAttrData[0] = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
4278 m_vertexAttrData[1] = tcu::Vec4(0.8f, 0.8f, 0.8f, 1.0f);
4279 m_numDrawVertices = 2;
4282 InvocationCountShader::OutputCase GeometryInvocationCase::mapToShaderCaseType (OutputCase testCase)
4286 case CASE_FIXED_OUTPUT_COUNTS: return InvocationCountShader::CASE_FIXED_OUTPUT_COUNTS;
4287 case CASE_DIFFERENT_OUTPUT_COUNTS: return InvocationCountShader::CASE_DIFFERENT_OUTPUT_COUNTS;
4290 return InvocationCountShader::CASE_LAST;
4294 class DrawInstancedGeometryInstancedCase : public GeometryShaderRenderTest
4297 DrawInstancedGeometryInstancedCase (Context& context, const char* name, const char* description, int numInstances, int numInvocations);
4298 ~DrawInstancedGeometryInstancedCase (void);
4302 sglr::ShaderProgram& getProgram (void);
4303 void genVertexAttribData (void);
4305 const int m_numInstances;
4306 const int m_numInvocations;
4307 InstancedExpansionShader m_program;
4310 DrawInstancedGeometryInstancedCase::DrawInstancedGeometryInstancedCase (Context& context, const char* name, const char* description, int numInstances, int numInvocations)
4311 : GeometryShaderRenderTest (context, name, description, GL_POINTS, GL_TRIANGLE_STRIP, "a_offset", FLAG_DRAW_INSTANCED)
4312 , m_numInstances (numInstances)
4313 , m_numInvocations (numInvocations)
4314 , m_program (numInvocations)
4318 DrawInstancedGeometryInstancedCase::~DrawInstancedGeometryInstancedCase (void)
4322 void DrawInstancedGeometryInstancedCase::init (void)
4325 << tcu::TestLog::Message
4326 << "Rendering a single point with " << m_numInstances << " instances. "
4327 << "Each geometry shader is invoked " << m_numInvocations << " times for each primitive. "
4328 << tcu::TestLog::EndMessage;
4330 GeometryShaderRenderTest::init();
4333 sglr::ShaderProgram& DrawInstancedGeometryInstancedCase::getProgram (void)
4338 void DrawInstancedGeometryInstancedCase::genVertexAttribData (void)
4340 m_numDrawVertices = 1;
4341 m_numDrawInstances = m_numInstances;
4342 m_vertexAttrDivisor = 1;
4344 m_vertexPosData.resize(1);
4345 m_vertexAttrData.resize(8);
4347 m_vertexPosData[0] = tcu::Vec4( 0.0f, 0.0f, 0.0f, 1.0f);
4349 m_vertexAttrData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 0.0f);
4350 m_vertexAttrData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 0.0f);
4351 m_vertexAttrData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 0.0f);
4352 m_vertexAttrData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 0.0f);
4353 m_vertexAttrData[4] = tcu::Vec4(-0.8f, -0.7f, 0.0f, 0.0f);
4354 m_vertexAttrData[5] = tcu::Vec4(-0.9f, 0.6f, 0.0f, 0.0f);
4355 m_vertexAttrData[6] = tcu::Vec4(-0.8f, 0.3f, 0.0f, 0.0f);
4356 m_vertexAttrData[7] = tcu::Vec4(-0.1f, 0.1f, 0.0f, 0.0f);
4358 DE_ASSERT(m_numInstances <= (int)m_vertexAttrData.size());
4361 class GeometryProgramLimitCase : public TestCase
4364 GeometryProgramLimitCase (Context& context, const char* name, const char* description, glw::GLenum apiName, const std::string& glslName, int limit);
4368 IterateResult iterate (void);
4370 const glw::GLenum m_apiName;
4371 const std::string m_glslName;
4375 GeometryProgramLimitCase::GeometryProgramLimitCase (Context& context, const char* name, const char* description, glw::GLenum apiName, const std::string& glslName, int limit)
4376 : TestCase (context, name, description)
4377 , m_apiName (apiName)
4378 , m_glslName (glslName)
4383 void GeometryProgramLimitCase::init (void)
4385 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4386 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4389 GeometryProgramLimitCase::IterateResult GeometryProgramLimitCase::iterate (void)
4391 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4396 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
4397 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4399 gl.enableLogging(true);
4400 gl.glGetIntegerv(m_apiName, &state);
4401 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getIntegerv()");
4403 m_testCtx.getLog() << tcu::TestLog::Message << glu::getGettableStateStr(m_apiName) << " = " << state << tcu::TestLog::EndMessage;
4405 if (!state.verifyValidity(result))
4407 result.setTestContextResult(m_testCtx);
4411 if (state < m_limit)
4413 result.fail("Minimum value = " + de::toString(m_limit) + ", got " + de::toString(state.get()));
4414 result.setTestContextResult(m_testCtx);
4420 // verify other getters
4422 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4423 verifyStateInteger(result, gl, m_apiName, limit, QUERY_BOOLEAN);
4424 verifyStateInteger(result, gl, m_apiName, limit, QUERY_INTEGER64);
4425 verifyStateInteger(result, gl, m_apiName, limit, QUERY_FLOAT);
4429 // verify limit is the same in GLSL
4431 static const char* const vertexSource = "#version 310 es\n"
4434 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
4436 static const char* const fragmentSource = "#version 310 es\n"
4437 "layout(location = 0) out mediump vec4 fragColor;\n"
4440 " fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
4442 const std::string geometrySource = "#version 310 es\n"
4443 "#extension GL_EXT_geometry_shader : require\n"
4444 "layout(points) in;\n"
4445 "layout(points, max_vertices = 1) out;\n"
4448 " // Building the shader will fail if the constant value is not the expected\n"
4449 " const mediump int cArraySize = (gl_" + m_glslName + " == " + de::toString(limit) + ") ? (1) : (-1);\n"
4450 " float[cArraySize] fArray;\n"
4451 " fArray[0] = 0.0f;\n"
4452 " gl_Position = vec4(0.0, 0.0, 0.0, fArray[0]);\n"
4456 const de::UniquePtr<glu::ShaderProgram> program(new glu::ShaderProgram(m_context.getRenderContext(),
4457 glu::ProgramSources()
4458 << glu::VertexSource(vertexSource)
4459 << glu::FragmentSource(fragmentSource)
4460 << glu::GeometrySource(geometrySource)));
4462 m_testCtx.getLog() << tcu::TestLog::Message << "Building a test shader to verify GLSL constant " << m_glslName << " value." << tcu::TestLog::EndMessage;
4463 m_testCtx.getLog() << *program;
4465 if (!program->isOk())
4467 // compile failed, assume static assert failed
4468 result.fail("Shader build failed");
4469 result.setTestContextResult(m_testCtx);
4473 m_testCtx.getLog() << tcu::TestLog::Message << "Build ok" << tcu::TestLog::EndMessage;
4476 result.setTestContextResult(m_testCtx);
4480 class PrimitivesGeneratedQueryCase : public TestCase
4485 TEST_NO_GEOMETRY = 0,
4486 TEST_NO_AMPLIFICATION,
4488 TEST_PARTIAL_PRIMITIVES,
4494 PrimitivesGeneratedQueryCase (Context& context, const char* name, const char* description, QueryTest test);
4495 ~PrimitivesGeneratedQueryCase (void);
4500 IterateResult iterate (void);
4502 glu::ShaderProgram* genProgram (void);
4504 const QueryTest m_test;
4505 glu::ShaderProgram* m_program;
4508 PrimitivesGeneratedQueryCase::PrimitivesGeneratedQueryCase (Context& context, const char* name, const char* description, QueryTest test)
4509 : TestCase (context, name, description)
4511 , m_program (DE_NULL)
4513 DE_ASSERT(m_test < TEST_LAST);
4516 PrimitivesGeneratedQueryCase::~PrimitivesGeneratedQueryCase (void)
4521 void PrimitivesGeneratedQueryCase::init (void)
4525 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4526 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4528 // log what test tries to do
4530 if (m_test == TEST_NO_GEOMETRY)
4531 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering without a geometry shader." << tcu::TestLog::EndMessage;
4532 else if (m_test == TEST_NO_AMPLIFICATION)
4533 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a non-amplifying geometry shader." << tcu::TestLog::EndMessage;
4534 else if (m_test == TEST_AMPLIFICATION)
4535 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a (3x) amplifying geometry shader." << tcu::TestLog::EndMessage;
4536 else if (m_test == TEST_PARTIAL_PRIMITIVES)
4537 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a geometry shader that emits also partial primitives." << tcu::TestLog::EndMessage;
4538 else if (m_test == TEST_INSTANCED)
4539 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a instanced geometry shader." << tcu::TestLog::EndMessage;
4545 m_program = genProgram();
4546 m_testCtx.getLog() << *m_program;
4548 if (!m_program->isOk())
4549 throw tcu::TestError("could not build program");
4552 void PrimitivesGeneratedQueryCase::deinit (void)
4555 m_program = DE_NULL;
4558 PrimitivesGeneratedQueryCase::IterateResult PrimitivesGeneratedQueryCase::iterate (void)
4560 glw::GLuint primitivesGenerated = 0xDEBADBAD;
4563 << tcu::TestLog::Message
4564 << "Drawing 8 points, setting a_one for each to value (1.0, 1.0, 1.0, 1.0)"
4565 << tcu::TestLog::EndMessage;
4568 static const tcu::Vec4 vertexData[8*2] =
4570 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4571 tcu::Vec4(0.1f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4572 tcu::Vec4(0.2f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4573 tcu::Vec4(0.3f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4574 tcu::Vec4(0.4f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4575 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4576 tcu::Vec4(0.6f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4577 tcu::Vec4(0.7f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4580 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4581 const glu::VertexArray vao (m_context.getRenderContext());
4582 const glu::Buffer buffer (m_context.getRenderContext());
4583 const glu::Query query (m_context.getRenderContext());
4584 const int positionLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
4585 const int oneLocation = gl.getAttribLocation(m_program->getProgram(), "a_one");
4587 gl.bindVertexArray(*vao);
4589 gl.bindBuffer(GL_ARRAY_BUFFER, *buffer);
4590 gl.bufferData(GL_ARRAY_BUFFER, (int)sizeof(vertexData), vertexData, GL_STATIC_DRAW);
4592 gl.vertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 2 * sizeof(tcu::Vec4), DE_NULL);
4593 gl.enableVertexAttribArray(positionLocation);
4595 if (oneLocation != -1)
4597 gl.vertexAttribPointer(oneLocation, 4, GL_FLOAT, GL_FALSE, 2 * sizeof(tcu::Vec4), (const tcu::Vec4*)DE_NULL + 1);
4598 gl.enableVertexAttribArray(oneLocation);
4601 gl.useProgram(m_program->getProgram());
4603 GLU_EXPECT_NO_ERROR(gl.getError(), "setup render");
4605 gl.beginQuery(GL_PRIMITIVES_GENERATED, *query);
4606 gl.drawArrays(GL_POINTS, 0, 8);
4607 gl.endQuery(GL_PRIMITIVES_GENERATED);
4609 GLU_EXPECT_NO_ERROR(gl.getError(), "render and query");
4611 gl.getQueryObjectuiv(*query, GL_QUERY_RESULT, &primitivesGenerated);
4612 GLU_EXPECT_NO_ERROR(gl.getError(), "get query result");
4616 << tcu::TestLog::Message
4617 << "GL_PRIMITIVES_GENERATED = " << primitivesGenerated
4618 << tcu::TestLog::EndMessage;
4621 const deUint32 expectedGenerated = (m_test == TEST_AMPLIFICATION) ? (3*8) : (m_test == TEST_INSTANCED) ? (8*(3+1)) : (8);
4623 if (expectedGenerated == primitivesGenerated)
4624 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4627 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got wrong result for GL_PRIMITIVES_GENERATED");
4629 << tcu::TestLog::Message
4630 << "Got unexpected result for GL_PRIMITIVES_GENERATED. Expected " << expectedGenerated << ", got " << primitivesGenerated
4631 << tcu::TestLog::EndMessage;
4638 glu::ShaderProgram* PrimitivesGeneratedQueryCase::genProgram (void)
4640 static const char* const vertexSource = "#version 310 es\n"
4641 "in highp vec4 a_position;\n"
4642 "in highp vec4 a_one;\n"
4643 "out highp vec4 v_one;\n"
4644 "void main (void)\n"
4646 " gl_Position = a_position;\n"
4649 static const char* const fragmentSource = "#version 310 es\n"
4650 "layout(location = 0) out mediump vec4 fragColor;\n"
4651 "void main (void)\n"
4653 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
4655 std::ostringstream geometrySource;
4656 glu::ProgramSources sources;
4658 if (m_test != TEST_NO_GEOMETRY)
4660 geometrySource << "#version 310 es\n"
4661 "#extension GL_EXT_geometry_shader : require\n"
4662 "layout(points" << ((m_test == TEST_INSTANCED) ? (", invocations = 3") : ("")) << ") in;\n"
4663 "layout(triangle_strip, max_vertices = 7) out;\n"
4664 "in highp vec4 v_one[];\n"
4665 "void main (void)\n"
4667 " // always taken\n"
4668 " if (v_one[0].x != 0.0)\n"
4670 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4672 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4674 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4676 " EndPrimitive();\n"
4679 if (m_test == TEST_AMPLIFICATION)
4681 geometrySource << "\n"
4682 " // always taken\n"
4683 " if (v_one[0].y != 0.0)\n"
4685 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4687 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4689 " gl_Position = gl_in[0].gl_Position - vec4(0.0, 0.1, 0.0, 0.0);\n"
4691 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4695 else if (m_test == TEST_PARTIAL_PRIMITIVES)
4697 geometrySource << "\n"
4698 " // always taken\n"
4699 " if (v_one[0].y != 0.0)\n"
4701 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4703 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4707 " if (v_one[0].z < 0.0)\n"
4709 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4714 else if (m_test == TEST_INSTANCED)
4716 geometrySource << "\n"
4718 " if (v_one[0].y > float(gl_InvocationID) + 0.5)\n"
4720 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4722 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4724 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4729 geometrySource << "}\n";
4732 sources << glu::VertexSource(vertexSource);
4733 sources << glu::FragmentSource(fragmentSource);
4735 if (!geometrySource.str().empty())
4736 sources << glu::GeometrySource(geometrySource.str());
4738 return new glu::ShaderProgram(m_context.getRenderContext(), sources);
4741 class PrimitivesGeneratedQueryObjectQueryCase : public TestCase
4744 PrimitivesGeneratedQueryObjectQueryCase (Context& context, const char* name, const char* description);
4747 IterateResult iterate (void);
4750 PrimitivesGeneratedQueryObjectQueryCase::PrimitivesGeneratedQueryObjectQueryCase (Context& context, const char* name, const char* description)
4751 : TestCase(context, name, description)
4755 void PrimitivesGeneratedQueryObjectQueryCase::init (void)
4757 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4758 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4761 PrimitivesGeneratedQueryObjectQueryCase::IterateResult PrimitivesGeneratedQueryObjectQueryCase::iterate (void)
4763 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4764 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4766 gl.enableLogging(true);
4769 glw::GLuint query = 0;
4771 verifyStateQueryInteger(result, gl, GL_PRIMITIVES_GENERATED, GL_CURRENT_QUERY, 0, QUERY_QUERY);
4773 gl.glGenQueries(1, &query);
4774 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGenQueries");
4776 gl.glBeginQuery(GL_PRIMITIVES_GENERATED, query);
4777 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "beginQuery");
4779 verifyStateQueryInteger(result, gl, GL_PRIMITIVES_GENERATED, GL_CURRENT_QUERY, (int)query, QUERY_QUERY);
4781 gl.glEndQuery(GL_PRIMITIVES_GENERATED);
4782 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "endQuery");
4785 result.setTestContextResult(m_testCtx);
4789 class GeometryShaderFeartureTestCase : public TestCase
4792 GeometryShaderFeartureTestCase (Context& context, const char* name, const char* description);
4797 GeometryShaderFeartureTestCase::GeometryShaderFeartureTestCase (Context& context, const char* name, const char* description)
4798 : TestCase(context, name, description)
4802 void GeometryShaderFeartureTestCase::init (void)
4804 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4805 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
4808 class FramebufferDefaultLayersCase : public GeometryShaderFeartureTestCase
4811 FramebufferDefaultLayersCase (Context& context, const char* name, const char* description);
4812 IterateResult iterate (void);
4815 FramebufferDefaultLayersCase::FramebufferDefaultLayersCase (Context& context, const char* name, const char* description)
4816 : GeometryShaderFeartureTestCase(context, name, description)
4820 FramebufferDefaultLayersCase::IterateResult FramebufferDefaultLayersCase::iterate (void)
4822 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4824 gl.enableLogging(true);
4826 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4829 const tcu::ScopedLogSection section (m_testCtx.getLog(), "Default", "Default value");
4830 const glu::Framebuffer fbo (m_context.getRenderContext());
4831 glw::GLint defaultLayers = -1;
4833 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4834 gl.glGetFramebufferParameteriv(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, &defaultLayers);
4835 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4837 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_DEFAULT_LAYERS = " << defaultLayers << tcu::TestLog::EndMessage;
4839 if (defaultLayers != 0)
4841 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected 0, got " << defaultLayers << tcu::TestLog::EndMessage;
4842 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4847 const tcu::ScopedLogSection section (m_testCtx.getLog(), "SetTo12", "Set default layers to 12");
4848 const glu::Framebuffer fbo (m_context.getRenderContext());
4849 glw::GLint defaultLayers = -1;
4851 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4852 gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, 12);
4853 gl.glGetFramebufferParameteriv(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, &defaultLayers);
4854 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4856 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_DEFAULT_LAYERS = " << defaultLayers << tcu::TestLog::EndMessage;
4858 if (defaultLayers != 12)
4860 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected 12, got " << defaultLayers << tcu::TestLog::EndMessage;
4861 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4868 class FramebufferAttachmentLayeredCase : public GeometryShaderFeartureTestCase
4871 FramebufferAttachmentLayeredCase (Context& context, const char* name, const char* description);
4872 IterateResult iterate (void);
4875 FramebufferAttachmentLayeredCase::FramebufferAttachmentLayeredCase (Context& context, const char* name, const char* description)
4876 : GeometryShaderFeartureTestCase(context, name, description)
4880 FramebufferAttachmentLayeredCase::IterateResult FramebufferAttachmentLayeredCase::iterate (void)
4887 TEXTURE_2D_MS_ARRAY,
4889 TEXTURE_2D_ARRAY_LAYER,
4892 static const struct TextureType
4895 const char* description;
4900 { "3D", "3D texture", true, TEXTURE_3D },
4901 { "2DArray", "2D array", true, TEXTURE_2D_ARRAY },
4902 { "Cube", "Cube map", true, TEXTURE_CUBE },
4903 { "2DMSArray", "2D multisample array", true, TEXTURE_2D_MS_ARRAY },
4904 { "3DLayer", "3D texture layer ", false, TEXTURE_3D_LAYER },
4905 { "2DArrayLayer", "2D array layer ", false, TEXTURE_2D_ARRAY_LAYER },
4908 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4909 gl.enableLogging(true);
4911 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4913 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(textureTypes); ++ndx)
4915 const tcu::ScopedLogSection section (m_testCtx.getLog(), textureTypes[ndx].name, textureTypes[ndx].description);
4916 const glu::Framebuffer fbo (m_context.getRenderContext());
4917 const glu::Texture texture (m_context.getRenderContext());
4918 glw::GLint layered = -1;
4920 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4922 if (textureTypes[ndx].type == TEXTURE_3D || textureTypes[ndx].type == TEXTURE_3D_LAYER)
4924 gl.glBindTexture(GL_TEXTURE_3D, *texture);
4925 gl.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4926 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4927 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4929 if (textureTypes[ndx].type == TEXTURE_3D)
4930 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4932 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0, 2);
4934 else if (textureTypes[ndx].type == TEXTURE_2D_ARRAY || textureTypes[ndx].type == TEXTURE_2D_ARRAY_LAYER)
4936 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture);
4937 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4938 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4939 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4941 if (textureTypes[ndx].type == TEXTURE_2D_ARRAY)
4942 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4944 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0, 3);
4946 else if (textureTypes[ndx].type == TEXTURE_CUBE)
4948 gl.glBindTexture(GL_TEXTURE_CUBE_MAP, *texture);
4949 for (int face = 0; face < 6; ++face)
4950 gl.glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4951 gl.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4952 gl.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4953 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4955 else if (textureTypes[ndx].type == TEXTURE_2D_MS_ARRAY)
4958 if (!m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
4960 m_testCtx.getLog() << tcu::TestLog::Message << "GL_OES_texture_storage_multisample_2d_array not supported, skipping." << tcu::TestLog::EndMessage;
4964 gl.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, *texture);
4965 gl.glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 32, 32, 32, GL_FALSE);
4966 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4969 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup attachment");
4971 gl.glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &layered);
4972 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4974 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_ATTACHMENT_LAYERED = " << glu::getBooleanStr(layered) << tcu::TestLog::EndMessage;
4976 if (layered != GL_TRUE && layered != GL_FALSE)
4978 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected boolean, got " << layered << tcu::TestLog::EndMessage;
4979 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid boolean");
4981 else if ((layered == GL_TRUE) != textureTypes[ndx].layered)
4983 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected " << ((textureTypes[ndx].layered) ? ("GL_TRUE") : ("GL_FALSE")) << ", got " << glu::getBooleanStr(layered) << tcu::TestLog::EndMessage;
4984 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4991 class FramebufferIncompleteLayereTargetsCase : public GeometryShaderFeartureTestCase
4994 FramebufferIncompleteLayereTargetsCase (Context& context, const char* name, const char* description);
4995 IterateResult iterate (void);
4998 FramebufferIncompleteLayereTargetsCase::FramebufferIncompleteLayereTargetsCase (Context& context, const char* name, const char* description)
4999 : GeometryShaderFeartureTestCase(context, name, description)
5003 FramebufferIncompleteLayereTargetsCase::IterateResult FramebufferIncompleteLayereTargetsCase::iterate (void)
5005 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5006 gl.enableLogging(true);
5008 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5011 const tcu::ScopedLogSection section (m_testCtx.getLog(), "LayerAndNonLayer", "Layered and non-layered");
5012 const glu::Framebuffer fbo (m_context.getRenderContext());
5013 const glu::Texture texture0 (m_context.getRenderContext());
5014 const glu::Texture texture1 (m_context.getRenderContext());
5016 glw::GLint fboStatus;
5018 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture0);
5019 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5020 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5021 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5023 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture1);
5024 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5025 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5026 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5028 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
5029 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture0, 0);
5030 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, *texture1, 0, 0);
5032 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup fbo");
5034 fboStatus = gl.glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
5035 m_testCtx.getLog() << tcu::TestLog::Message << "Framebuffer status: " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5037 if (fboStatus != GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
5039 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS, got " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5040 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
5045 const tcu::ScopedLogSection section (m_testCtx.getLog(), "DifferentTarget", "Different target");
5046 const glu::Framebuffer fbo (m_context.getRenderContext());
5047 const glu::Texture texture0 (m_context.getRenderContext());
5048 const glu::Texture texture1 (m_context.getRenderContext());
5050 glw::GLint fboStatus;
5052 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture0);
5053 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5054 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5055 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5057 gl.glBindTexture(GL_TEXTURE_3D, *texture1);
5058 gl.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5059 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5060 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5062 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
5063 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture0, 0);
5064 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, *texture1, 0);
5066 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup fbo");
5068 fboStatus = gl.glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
5069 m_testCtx.getLog() << tcu::TestLog::Message << "Framebuffer status: " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5071 if (fboStatus != GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
5073 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS, got " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5074 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
5081 class ReferencedByGeometryShaderCase : public GeometryShaderFeartureTestCase
5084 ReferencedByGeometryShaderCase (Context& context, const char* name, const char* description);
5085 IterateResult iterate (void);
5088 ReferencedByGeometryShaderCase::ReferencedByGeometryShaderCase (Context& context, const char* name, const char* description)
5089 : GeometryShaderFeartureTestCase(context, name, description)
5093 ReferencedByGeometryShaderCase::IterateResult ReferencedByGeometryShaderCase::iterate (void)
5095 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5098 static const char* const vertexSource = "#version 310 es\n"
5099 "uniform highp vec4 u_position;\n"
5100 "void main (void)\n"
5102 " gl_Position = u_position;\n"
5104 static const char* const fragmentSource = "#version 310 es\n"
5105 "layout(location = 0) out mediump vec4 fragColor;\n"
5106 "void main (void)\n"
5108 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
5110 static const char* const geometrySource = "#version 310 es\n"
5111 "#extension GL_EXT_geometry_shader : require\n"
5112 "layout(points) in;\n"
5113 "layout(points, max_vertices=1) out;\n"
5114 "uniform highp vec4 u_offset;\n"
5115 "void main (void)\n"
5117 " gl_Position = gl_in[0].gl_Position + u_offset;\n"
5121 const glu::ShaderProgram program(m_context.getRenderContext(), glu::ProgramSources()
5122 << glu::VertexSource(vertexSource)
5123 << glu::FragmentSource(fragmentSource)
5124 << glu::GeometrySource(geometrySource));
5125 m_testCtx.getLog() << program;
5128 const tcu::ScopedLogSection section (m_testCtx.getLog(), "UnreferencedUniform", "Unreferenced uniform u_position");
5129 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5130 const deUint32 props[1] = { GL_REFERENCED_BY_GEOMETRY_SHADER };
5131 deUint32 resourcePos;
5132 glw::GLsizei length = 0;
5133 glw::GLint referenced = 0;
5135 gl.enableLogging(true);
5137 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_position");
5138 m_testCtx.getLog() << tcu::TestLog::Message << "u_position resource index: " << resourcePos << tcu::TestLog::EndMessage;
5140 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
5141 m_testCtx.getLog() << tcu::TestLog::Message << "Query GL_REFERENCED_BY_GEOMETRY_SHADER, got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced) << tcu::TestLog::EndMessage;
5143 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
5145 if (length == 0 || referenced != GL_FALSE)
5147 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FALSE." << tcu::TestLog::EndMessage;
5148 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected value");
5153 const tcu::ScopedLogSection section (m_testCtx.getLog(), "ReferencedUniform", "Referenced uniform u_offset");
5154 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5155 const deUint32 props[1] = { GL_REFERENCED_BY_GEOMETRY_SHADER };
5156 deUint32 resourcePos;
5157 glw::GLsizei length = 0;
5158 glw::GLint referenced = 0;
5160 gl.enableLogging(true);
5162 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_offset");
5163 m_testCtx.getLog() << tcu::TestLog::Message << "u_offset resource index: " << resourcePos << tcu::TestLog::EndMessage;
5165 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
5166 m_testCtx.getLog() << tcu::TestLog::Message << "Query GL_REFERENCED_BY_GEOMETRY_SHADER, got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced) << tcu::TestLog::EndMessage;
5168 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
5170 if (length == 0 || referenced != GL_TRUE)
5172 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_TRUE." << tcu::TestLog::EndMessage;
5173 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected value");
5181 class CombinedGeometryUniformLimitCase : public GeometryShaderFeartureTestCase
5184 CombinedGeometryUniformLimitCase (Context& context, const char* name, const char* desc);
5186 IterateResult iterate (void);
5189 CombinedGeometryUniformLimitCase::CombinedGeometryUniformLimitCase (Context& context, const char* name, const char* desc)
5190 : GeometryShaderFeartureTestCase(context, name, desc)
5194 CombinedGeometryUniformLimitCase::IterateResult CombinedGeometryUniformLimitCase::iterate (void)
5196 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5197 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
5199 gl.enableLogging(true);
5201 m_testCtx.getLog() << tcu::TestLog::Message
5202 << "The minimum value of MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS is MAX_GEOMETRY_UNIFORM_BLOCKS x MAX_UNIFORM_BLOCK_SIZE / 4 + MAX_GEOMETRY_UNIFORM_COMPONENTS"
5203 << tcu::TestLog::EndMessage;
5205 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlocks;
5206 gl.glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_BLOCKS, &maxUniformBlocks);
5207 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5209 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlockSize;
5210 gl.glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxUniformBlockSize);
5211 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5213 StateQueryMemoryWriteGuard<glw::GLint> maxUniformComponents;
5214 gl.glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, &maxUniformComponents);
5215 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5217 if (maxUniformBlocks.verifyValidity(result) && maxUniformBlockSize.verifyValidity(result) && maxUniformComponents.verifyValidity(result))
5219 const int limit = ((int)maxUniformBlocks) * ((int)maxUniformBlockSize) / 4 + (int)maxUniformComponents;
5220 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_INTEGER);
5223 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
5224 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_BOOLEAN);
5225 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_INTEGER64);
5226 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_FLOAT);
5230 result.setTestContextResult(m_testCtx);
5234 class VertexFeedbackCase : public TestCase
5239 METHOD_DRAW_ARRAYS = 0,
5240 METHOD_DRAW_ARRAYS_INSTANCED,
5241 METHOD_DRAW_ARRAYS_INDIRECT,
5242 METHOD_DRAW_ELEMENTS,
5243 METHOD_DRAW_ELEMENTS_INSTANCED,
5244 METHOD_DRAW_ELEMENTS_INDIRECT,
5250 PRIMITIVE_LINE_LOOP = 0,
5251 PRIMITIVE_LINE_STRIP,
5252 PRIMITIVE_TRIANGLE_STRIP,
5253 PRIMITIVE_TRIANGLE_FAN,
5259 VertexFeedbackCase (Context& context, const char* name, const char* description, DrawMethod method, PrimitiveType output);
5260 ~VertexFeedbackCase (void);
5264 IterateResult iterate (void);
5266 glu::ShaderProgram* genProgram (void);
5267 deUint32 getOutputPrimitive (void);
5268 deUint32 getBasePrimitive (void);
5270 const DrawMethod m_method;
5271 const PrimitiveType m_output;
5273 deUint32 m_elementBuf;
5274 deUint32 m_arrayBuf;
5275 deUint32 m_offsetBuf;
5276 deUint32 m_feedbackBuf;
5277 deUint32 m_indirectBuffer;
5278 glu::ShaderProgram* m_program;
5279 glu::VertexArray* m_vao;
5282 VertexFeedbackCase::VertexFeedbackCase (Context& context, const char* name, const char* description, DrawMethod method, PrimitiveType output)
5283 : TestCase (context, name, description)
5290 , m_indirectBuffer (0)
5291 , m_program (DE_NULL)
5294 DE_ASSERT(method < METHOD_LAST);
5295 DE_ASSERT(output < PRIMITIVE_LAST);
5298 VertexFeedbackCase::~VertexFeedbackCase (void)
5303 void VertexFeedbackCase::init (void)
5307 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
5308 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
5310 // log what test tries to do
5313 << tcu::TestLog::Message
5314 << "Testing GL_EXT_geometry_shader transform feedback relaxations.\n"
5315 << "Capturing vertex shader varying, no geometry shader. Invoke with:"
5316 << tcu::TestLog::EndMessage;
5320 case METHOD_DRAW_ARRAYS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArrays" << tcu::TestLog::EndMessage; break;
5321 case METHOD_DRAW_ARRAYS_INSTANCED: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArraysInstanced" << tcu::TestLog::EndMessage; break;
5322 case METHOD_DRAW_ARRAYS_INDIRECT: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArraysIndirect" << tcu::TestLog::EndMessage; break;
5323 case METHOD_DRAW_ELEMENTS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElements" << tcu::TestLog::EndMessage; break;
5324 case METHOD_DRAW_ELEMENTS_INSTANCED: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElementsInstanced" << tcu::TestLog::EndMessage; break;
5325 case METHOD_DRAW_ELEMENTS_INDIRECT: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElementsIndirect" << tcu::TestLog::EndMessage; break;
5331 case PRIMITIVE_LINE_LOOP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: line loop" << tcu::TestLog::EndMessage; break;
5332 case PRIMITIVE_LINE_STRIP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: line strip" << tcu::TestLog::EndMessage; break;
5333 case PRIMITIVE_TRIANGLE_STRIP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: triangle strip" << tcu::TestLog::EndMessage; break;
5334 case PRIMITIVE_TRIANGLE_FAN: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: triangle fan" << tcu::TestLog::EndMessage; break;
5335 case PRIMITIVE_POINTS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: points" << tcu::TestLog::EndMessage; break;
5343 static const deUint16 elementData[] =
5347 static const tcu::Vec4 arrayData[] =
5349 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5350 tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f),
5351 tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f),
5352 tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f),
5354 static const tcu::Vec4 offsetData[] =
5356 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5357 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5358 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5359 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5362 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5363 const int feedbackSize = 8 * sizeof(float[4]);
5365 m_vao = new glu::VertexArray(m_context.getRenderContext());
5366 gl.bindVertexArray(**m_vao);
5367 GLU_EXPECT_NO_ERROR(gl.getError(), "set up vao");
5369 gl.genBuffers(1, &m_elementBuf);
5370 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5371 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elementData), &elementData[0], GL_STATIC_DRAW);
5372 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5374 gl.genBuffers(1, &m_arrayBuf);
5375 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5376 gl.bufferData(GL_ARRAY_BUFFER, sizeof(arrayData), &arrayData[0], GL_STATIC_DRAW);
5377 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5379 gl.genBuffers(1, &m_offsetBuf);
5380 gl.bindBuffer(GL_ARRAY_BUFFER, m_offsetBuf);
5381 gl.bufferData(GL_ARRAY_BUFFER, sizeof(offsetData), &offsetData[0], GL_STATIC_DRAW);
5382 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5384 gl.genBuffers(1, &m_feedbackBuf);
5385 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_feedbackBuf);
5386 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackSize, DE_NULL, GL_DYNAMIC_COPY);
5387 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5389 m_program = genProgram();
5391 if (!m_program->isOk())
5393 m_testCtx.getLog() << *m_program;
5394 throw tcu::TestError("could not build program");
5399 void VertexFeedbackCase::deinit (void)
5403 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_elementBuf);
5409 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_arrayBuf);
5415 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_offsetBuf);
5421 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_feedbackBuf);
5425 if (m_indirectBuffer)
5427 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indirectBuffer);
5428 m_indirectBuffer = 0;
5432 m_program = DE_NULL;
5438 VertexFeedbackCase::IterateResult VertexFeedbackCase::iterate (void)
5440 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5441 const deUint32 outputPrimitive = getOutputPrimitive();
5442 const deUint32 basePrimitive = getBasePrimitive();
5444 const int posLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
5445 const int offsetLocation = gl.getAttribLocation(m_program->getProgram(), "a_offset");
5447 if (posLocation == -1)
5448 throw tcu::TestError("a_position location was -1");
5449 if (offsetLocation == -1)
5450 throw tcu::TestError("a_offset location was -1");
5452 gl.useProgram(m_program->getProgram());
5454 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5455 gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5456 gl.enableVertexAttribArray(posLocation);
5458 gl.bindBuffer(GL_ARRAY_BUFFER, m_offsetBuf);
5459 gl.vertexAttribPointer(offsetLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5460 gl.enableVertexAttribArray(offsetLocation);
5462 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_feedbackBuf);
5463 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffer base");
5465 m_testCtx.getLog() << tcu::TestLog::Message << "Calling BeginTransformFeedback(" << glu::getPrimitiveTypeStr(basePrimitive) << ")" << tcu::TestLog::EndMessage;
5466 gl.beginTransformFeedback(basePrimitive);
5467 GLU_EXPECT_NO_ERROR(gl.getError(), "beginTransformFeedback");
5471 case METHOD_DRAW_ARRAYS:
5473 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawArrays(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5474 gl.drawArrays(outputPrimitive, 0, 4);
5478 case METHOD_DRAW_ARRAYS_INSTANCED:
5480 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawArraysInstanced(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5481 gl.vertexAttribDivisor(offsetLocation, 2);
5482 gl.drawArraysInstanced(outputPrimitive, 0, 3, 2);
5486 case METHOD_DRAW_ELEMENTS:
5488 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElements(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5489 gl.drawElements(outputPrimitive, 4, GL_UNSIGNED_SHORT, DE_NULL);
5493 case METHOD_DRAW_ELEMENTS_INSTANCED:
5495 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsInstanced(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5496 gl.drawElementsInstanced(outputPrimitive, 3, GL_UNSIGNED_SHORT, DE_NULL, 2);
5500 case METHOD_DRAW_ARRAYS_INDIRECT:
5502 struct DrawArraysIndirectCommand
5505 deUint32 instanceCount;
5507 deUint32 reservedMustBeZero;
5510 DE_STATIC_ASSERT(sizeof(DrawArraysIndirectCommand) == sizeof(deUint32[4]));
5513 params.instanceCount = 1;
5515 params.reservedMustBeZero = 0;
5517 gl.genBuffers(1, &m_indirectBuffer);
5518 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirectBuffer);
5519 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(params), ¶ms, GL_STATIC_DRAW);
5521 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsIndirect(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5522 gl.drawArraysIndirect(outputPrimitive, DE_NULL);
5526 case METHOD_DRAW_ELEMENTS_INDIRECT:
5528 struct DrawElementsIndirectCommand
5531 deUint32 instanceCount;
5532 deUint32 firstIndex;
5534 deUint32 reservedMustBeZero;
5537 DE_STATIC_ASSERT(sizeof(DrawElementsIndirectCommand) == sizeof(deUint32[5]));
5540 params.instanceCount = 1;
5541 params.firstIndex = 0;
5542 params.baseVertex = 0;
5543 params.reservedMustBeZero = 0;
5545 gl.genBuffers(1, &m_indirectBuffer);
5546 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirectBuffer);
5547 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(params), ¶ms, GL_STATIC_DRAW);
5549 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsIndirect(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5550 gl.drawElementsIndirect(outputPrimitive, GL_UNSIGNED_SHORT, DE_NULL);
5557 GLU_EXPECT_NO_ERROR(gl.getError(), "draw");
5559 gl.endTransformFeedback();
5560 GLU_EXPECT_NO_ERROR(gl.getError(), "endTransformFeedback");
5562 m_testCtx.getLog() << tcu::TestLog::Message << "No errors." << tcu::TestLog::EndMessage;
5563 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5568 glu::ShaderProgram* VertexFeedbackCase::genProgram (void)
5570 static const char* const vertexSource = "#version 310 es\n"
5571 "in highp vec4 a_position;\n"
5572 "in highp vec4 a_offset;\n"
5573 "out highp vec4 tf_value;\n"
5574 "void main (void)\n"
5576 " gl_Position = a_position;\n"
5577 " tf_value = a_position + a_offset;\n"
5579 static const char* const fragmentSource = "#version 310 es\n"
5580 "layout(location = 0) out mediump vec4 fragColor;\n"
5581 "void main (void)\n"
5583 " fragColor = vec4(1.0);\n"
5586 return new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5587 << glu::VertexSource(vertexSource)
5588 << glu::FragmentSource(fragmentSource)
5589 << glu::TransformFeedbackVarying("tf_value")
5590 << glu::TransformFeedbackMode(GL_INTERLEAVED_ATTRIBS));
5593 deUint32 VertexFeedbackCase::getOutputPrimitive (void)
5597 case PRIMITIVE_LINE_LOOP: return GL_LINE_LOOP;
5598 case PRIMITIVE_LINE_STRIP: return GL_LINE_STRIP;
5599 case PRIMITIVE_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP;
5600 case PRIMITIVE_TRIANGLE_FAN: return GL_TRIANGLE_FAN;
5601 case PRIMITIVE_POINTS: return GL_POINTS;
5608 deUint32 VertexFeedbackCase::getBasePrimitive (void)
5612 case PRIMITIVE_LINE_LOOP: return GL_LINES;
5613 case PRIMITIVE_LINE_STRIP: return GL_LINES;
5614 case PRIMITIVE_TRIANGLE_STRIP: return GL_TRIANGLES;
5615 case PRIMITIVE_TRIANGLE_FAN: return GL_TRIANGLES;
5616 case PRIMITIVE_POINTS: return GL_POINTS;
5623 class VertexFeedbackOverflowCase : public TestCase
5628 METHOD_DRAW_ARRAYS = 0,
5629 METHOD_DRAW_ELEMENTS,
5632 VertexFeedbackOverflowCase (Context& context, const char* name, const char* description, Method method);
5633 ~VertexFeedbackOverflowCase (void);
5638 IterateResult iterate (void);
5639 glu::ShaderProgram* genProgram (void);
5641 const Method m_method;
5643 deUint32 m_elementBuf;
5644 deUint32 m_arrayBuf;
5645 deUint32 m_feedbackBuf;
5646 glu::ShaderProgram* m_program;
5647 glu::VertexArray* m_vao;
5650 VertexFeedbackOverflowCase::VertexFeedbackOverflowCase (Context& context, const char* name, const char* description, Method method)
5651 : TestCase (context, name, description)
5656 , m_program (DE_NULL)
5661 VertexFeedbackOverflowCase::~VertexFeedbackOverflowCase (void)
5666 void VertexFeedbackOverflowCase::init (void)
5670 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
5671 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
5673 // log what test tries to do
5676 << tcu::TestLog::Message
5677 << "Testing GL_EXT_geometry_shader transform feedback overflow behavior.\n"
5678 << "Capturing vertex shader varying, rendering 2 triangles. Allocating feedback buffer for 5 vertices."
5679 << tcu::TestLog::EndMessage;
5684 static const deUint16 elementData[] =
5689 static const tcu::Vec4 arrayData[] =
5691 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5692 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5693 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5694 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5697 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5699 m_vao = new glu::VertexArray(m_context.getRenderContext());
5700 gl.bindVertexArray(**m_vao);
5701 GLU_EXPECT_NO_ERROR(gl.getError(), "set up vao");
5703 if (m_method == METHOD_DRAW_ELEMENTS)
5705 gl.genBuffers(1, &m_elementBuf);
5706 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5707 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elementData), &elementData[0], GL_STATIC_DRAW);
5708 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5711 gl.genBuffers(1, &m_arrayBuf);
5712 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5713 gl.bufferData(GL_ARRAY_BUFFER, sizeof(arrayData), &arrayData[0], GL_STATIC_DRAW);
5714 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5717 const int feedbackCount = 5 * 4; // 5x vec4
5718 const std::vector<float> initialBufferContents (feedbackCount, -1.0f);
5720 m_testCtx.getLog() << tcu::TestLog::Message << "Filling feeback buffer with dummy value (-1.0)." << tcu::TestLog::EndMessage;
5722 gl.genBuffers(1, &m_feedbackBuf);
5723 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_feedbackBuf);
5724 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, (int)(sizeof(float) * initialBufferContents.size()), &initialBufferContents[0], GL_DYNAMIC_COPY);
5725 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5728 m_program = genProgram();
5730 if (!m_program->isOk())
5732 m_testCtx.getLog() << *m_program;
5733 throw tcu::TestError("could not build program");
5738 void VertexFeedbackOverflowCase::deinit (void)
5742 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_elementBuf);
5748 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_arrayBuf);
5754 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_feedbackBuf);
5759 m_program = DE_NULL;
5765 VertexFeedbackOverflowCase::IterateResult VertexFeedbackOverflowCase::iterate (void)
5767 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5768 const int posLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
5770 if (posLocation == -1)
5771 throw tcu::TestError("a_position location was -1");
5773 gl.useProgram(m_program->getProgram());
5775 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5776 gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5777 gl.enableVertexAttribArray(posLocation);
5779 if (m_method == METHOD_DRAW_ELEMENTS)
5781 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5782 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffers");
5785 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_feedbackBuf);
5786 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffer base");
5788 m_testCtx.getLog() << tcu::TestLog::Message << "Capturing 2 triangles." << tcu::TestLog::EndMessage;
5790 gl.beginTransformFeedback(GL_TRIANGLES);
5792 if (m_method == METHOD_DRAW_ELEMENTS)
5793 gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL);
5794 else if (m_method == METHOD_DRAW_ARRAYS)
5795 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
5799 gl.endTransformFeedback();
5800 GLU_EXPECT_NO_ERROR(gl.getError(), "capture");
5802 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying final triangle was not partially written to the feedback buffer." << tcu::TestLog::EndMessage;
5805 const void* ptr = gl.mapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(float[4]) * 5, GL_MAP_READ_BIT);
5806 std::vector<float> feedback;
5809 GLU_EXPECT_NO_ERROR(gl.getError(), "mapBufferRange");
5811 throw tcu::TestError("mapBufferRange returned null");
5813 feedback.resize(5*4);
5814 deMemcpy(&feedback[0], ptr, sizeof(float[4]) * 5);
5816 if (gl.unmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER) != GL_TRUE)
5817 throw tcu::TestError("unmapBuffer returned false");
5819 // Verify vertices 0 - 2
5820 for (int vertex = 0; vertex < 3; ++vertex)
5822 for (int component = 0; component < 4; ++component)
5824 if (feedback[vertex*4 + component] != 1.0f)
5827 << tcu::TestLog::Message
5828 << "Feedback buffer vertex " << vertex << ", component " << component << ": unexpected value, expected 1.0, got " << feedback[vertex*4 + component]
5829 << tcu::TestLog::EndMessage;
5835 // Verify vertices 3 - 4
5836 for (int vertex = 3; vertex < 5; ++vertex)
5838 for (int component = 0; component < 4; ++component)
5840 if (feedback[vertex*4 + component] != -1.0f)
5843 << tcu::TestLog::Message
5844 << "Feedback buffer vertex " << vertex << ", component " << component << ": unexpected value, expected -1.0, got " << feedback[vertex*4 + component]
5845 << tcu::TestLog::EndMessage;
5852 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Feedback result validation failed");
5854 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5860 glu::ShaderProgram* VertexFeedbackOverflowCase::genProgram (void)
5862 static const char* const vertexSource = "#version 310 es\n"
5863 "in highp vec4 a_position;\n"
5864 "void main (void)\n"
5866 " gl_Position = a_position;\n"
5868 static const char* const fragmentSource = "#version 310 es\n"
5869 "layout(location = 0) out mediump vec4 fragColor;\n"
5870 "void main (void)\n"
5872 " fragColor = vec4(1.0);\n"
5875 return new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5876 << glu::VertexSource(vertexSource)
5877 << glu::FragmentSource(fragmentSource)
5878 << glu::TransformFeedbackVarying("gl_Position")
5879 << glu::TransformFeedbackMode(GL_INTERLEAVED_ATTRIBS));
5884 GeometryShaderTests::GeometryShaderTests (Context& context)
5885 : TestCaseGroup(context, "geometry_shading", "Geometry shader tests")
5889 GeometryShaderTests::~GeometryShaderTests (void)
5893 void GeometryShaderTests::init (void)
5895 struct PrimitiveTestSpec
5897 deUint32 primitiveType;
5899 deUint32 outputType;
5904 deUint32 outputType;
5905 int emitCountA; //!< primitive A emit count
5906 int endCountA; //!< primitive A end count
5907 int emitCountB; //!<
5912 static const struct LayeredTarget
5914 LayeredRenderCase::LayeredRenderTargetType target;
5919 { LayeredRenderCase::TARGET_CUBE, "cubemap", "cubemap" },
5920 { LayeredRenderCase::TARGET_3D, "3d", "3D texture" },
5921 { LayeredRenderCase::TARGET_2D_ARRAY, "2d_array", "2D array texture" },
5922 { LayeredRenderCase::TARGET_2D_MS_ARRAY, "2d_multisample_array", "2D multisample array texture" },
5925 tcu::TestCaseGroup* const queryGroup = new tcu::TestCaseGroup(m_testCtx, "query", "Query tests.");
5926 tcu::TestCaseGroup* const basicGroup = new tcu::TestCaseGroup(m_testCtx, "basic", "Basic tests.");
5927 tcu::TestCaseGroup* const inputPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "input", "Different input primitives.");
5928 tcu::TestCaseGroup* const conversionPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "conversion", "Different input and output primitives.");
5929 tcu::TestCaseGroup* const emitGroup = new tcu::TestCaseGroup(m_testCtx, "emit", "Different emit counts.");
5930 tcu::TestCaseGroup* const varyingGroup = new tcu::TestCaseGroup(m_testCtx, "varying", "Test varyings.");
5931 tcu::TestCaseGroup* const layeredGroup = new tcu::TestCaseGroup(m_testCtx, "layered", "Layered rendering.");
5932 tcu::TestCaseGroup* const instancedGroup = new tcu::TestCaseGroup(m_testCtx, "instanced", "Instanced rendering.");
5933 tcu::TestCaseGroup* const negativeGroup = new tcu::TestCaseGroup(m_testCtx, "negative", "Negative tests.");
5934 tcu::TestCaseGroup* const feedbackGroup = new tcu::TestCaseGroup(m_testCtx, "vertex_transform_feedback", "Transform feedback.");
5936 this->addChild(queryGroup);
5937 this->addChild(basicGroup);
5938 this->addChild(inputPrimitiveGroup);
5939 this->addChild(conversionPrimitiveGroup);
5940 this->addChild(emitGroup);
5941 this->addChild(varyingGroup);
5942 this->addChild(layeredGroup);
5943 this->addChild(instancedGroup);
5944 this->addChild(negativeGroup);
5945 this->addChild(feedbackGroup);
5949 // limits with a corresponding glsl constant
5950 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_input_components", "", GL_MAX_GEOMETRY_INPUT_COMPONENTS, "MaxGeometryInputComponents", 64));
5951 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_output_components", "", GL_MAX_GEOMETRY_OUTPUT_COMPONENTS, "MaxGeometryOutputComponents", 128));
5952 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_image_uniforms", "", GL_MAX_GEOMETRY_IMAGE_UNIFORMS, "MaxGeometryImageUniforms", 0));
5953 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_texture_image_units", "", GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, "MaxGeometryTextureImageUnits", 16));
5954 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_output_vertices", "", GL_MAX_GEOMETRY_OUTPUT_VERTICES, "MaxGeometryOutputVertices", 256));
5955 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_total_output_components", "", GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, "MaxGeometryTotalOutputComponents", 1024));
5956 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_uniform_components", "", GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, "MaxGeometryUniformComponents", 1024));
5957 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_atomic_counters", "", GL_MAX_GEOMETRY_ATOMIC_COUNTERS, "MaxGeometryAtomicCounters", 0));
5958 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_atomic_counter_buffers", "", GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS, "MaxGeometryAtomicCounterBuffers", 0));
5961 queryGroup->addChild(new GeometryShaderVerticesQueryCase (m_context, "geometry_linked_vertices_out", "GL_GEOMETRY_LINKED_VERTICES_OUT"));
5962 queryGroup->addChild(new GeometryShaderInputQueryCase (m_context, "geometry_linked_input_type", "GL_GEOMETRY_LINKED_INPUT_TYPE"));
5963 queryGroup->addChild(new GeometryShaderOutputQueryCase (m_context, "geometry_linked_output_type", "GL_GEOMETRY_LINKED_OUTPUT_TYPE"));
5964 queryGroup->addChild(new GeometryShaderInvocationsQueryCase (m_context, "geometry_shader_invocations", "GL_GEOMETRY_SHADER_INVOCATIONS"));
5967 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_shader_invocations", "", GL_MAX_GEOMETRY_SHADER_INVOCATIONS, 32));
5968 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_uniform_blocks", "", GL_MAX_GEOMETRY_UNIFORM_BLOCKS, 12));
5969 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_shader_storage_blocks", "", GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, 0));
5971 // layer_provoking_vertex_ext
5972 queryGroup->addChild(new LayerProvokingVertexQueryCase(m_context, "layer_provoking_vertex", "GL_LAYER_PROVOKING_VERTEX"));
5974 // primitives_generated
5975 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_no_geometry", "PRIMITIVES_GENERATED query with no geometry shader", PrimitivesGeneratedQueryCase::TEST_NO_GEOMETRY));
5976 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_no_amplification", "PRIMITIVES_GENERATED query with non amplifying geometry shader", PrimitivesGeneratedQueryCase::TEST_NO_AMPLIFICATION));
5977 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_amplification", "PRIMITIVES_GENERATED query with amplifying geometry shader", PrimitivesGeneratedQueryCase::TEST_AMPLIFICATION));
5978 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_partial_primitives", "PRIMITIVES_GENERATED query with geometry shader emitting partial primitives", PrimitivesGeneratedQueryCase::TEST_PARTIAL_PRIMITIVES));
5979 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_instanced", "PRIMITIVES_GENERATED query with instanced geometry shader", PrimitivesGeneratedQueryCase::TEST_INSTANCED));
5981 queryGroup->addChild(new PrimitivesGeneratedQueryObjectQueryCase(m_context, "primitives_generated", "Query bound PRIMITIVES_GENERATED query"));
5984 queryGroup->addChild(new ImplementationLimitCase (m_context, "max_framebuffer_layers", "", GL_MAX_FRAMEBUFFER_LAYERS, 256));
5985 queryGroup->addChild(new FramebufferDefaultLayersCase (m_context, "framebuffer_default_layers", ""));
5986 queryGroup->addChild(new FramebufferAttachmentLayeredCase (m_context, "framebuffer_attachment_layered", ""));
5987 queryGroup->addChild(new FramebufferIncompleteLayereTargetsCase (m_context, "framebuffer_incomplete_layer_targets", ""));
5990 queryGroup->addChild(new ReferencedByGeometryShaderCase (m_context, "referenced_by_geometry_shader", ""));
5993 queryGroup->addChild(new CombinedGeometryUniformLimitCase (m_context, "max_combined_geometry_uniform_components", "MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS"));
5998 basicGroup->addChild(new OutputCountCase (m_context, "output_10", "Output 10 vertices", OutputCountPatternSpec(10)));
5999 basicGroup->addChild(new OutputCountCase (m_context, "output_128", "Output 128 vertices", OutputCountPatternSpec(128)));
6000 basicGroup->addChild(new OutputCountCase (m_context, "output_256", "Output 256 vertices", OutputCountPatternSpec(256)));
6001 basicGroup->addChild(new OutputCountCase (m_context, "output_max", "Output max vertices", OutputCountPatternSpec(-1)));
6002 basicGroup->addChild(new OutputCountCase (m_context, "output_10_and_100", "Output 10 and 100 vertices in two invocations", OutputCountPatternSpec(10, 100)));
6003 basicGroup->addChild(new OutputCountCase (m_context, "output_100_and_10", "Output 100 and 10 vertices in two invocations", OutputCountPatternSpec(100, 10)));
6004 basicGroup->addChild(new OutputCountCase (m_context, "output_0_and_128", "Output 0 and 128 vertices in two invocations", OutputCountPatternSpec(0, 128)));
6005 basicGroup->addChild(new OutputCountCase (m_context, "output_128_and_0", "Output 128 and 0 vertices in two invocations", OutputCountPatternSpec(128, 0)));
6007 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_attribute", "Output varying number of vertices", VaryingOutputCountShader::READ_ATTRIBUTE, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6008 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_uniform", "Output varying number of vertices", VaryingOutputCountShader::READ_UNIFORM, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6009 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_texture", "Output varying number of vertices", VaryingOutputCountShader::READ_TEXTURE, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6011 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "point_size", "test gl_PointSize", BuiltinVariableShader::TEST_POINT_SIZE));
6012 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "primitive_id_in", "test gl_PrimitiveIDIn", BuiltinVariableShader::TEST_PRIMITIVE_ID_IN));
6013 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "primitive_id_in_restarted","test gl_PrimitiveIDIn with primitive restart", BuiltinVariableShader::TEST_PRIMITIVE_ID_IN, GeometryShaderRenderTest::FLAG_USE_RESTART_INDEX | GeometryShaderRenderTest::FLAG_USE_INDICES));
6014 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "primitive_id", "test gl_PrimitiveID", BuiltinVariableShader::TEST_PRIMITIVE_ID));
6019 static const PrimitiveTestSpec inputPrimitives[] =
6021 { GL_POINTS, "points", GL_POINTS },
6022 { GL_LINES, "lines", GL_LINE_STRIP },
6023 { GL_LINE_LOOP, "line_loop", GL_LINE_STRIP },
6024 { GL_LINE_STRIP, "line_strip", GL_LINE_STRIP },
6025 { GL_TRIANGLES, "triangles", GL_TRIANGLE_STRIP },
6026 { GL_TRIANGLE_STRIP, "triangle_strip", GL_TRIANGLE_STRIP },
6027 { GL_TRIANGLE_FAN, "triangle_fan", GL_TRIANGLE_STRIP },
6028 { GL_LINES_ADJACENCY, "lines_adjacency", GL_LINE_STRIP },
6029 { GL_LINE_STRIP_ADJACENCY, "line_strip_adjacency", GL_LINE_STRIP },
6030 { GL_TRIANGLES_ADJACENCY, "triangles_adjacency", GL_TRIANGLE_STRIP }
6033 tcu::TestCaseGroup* const basicPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "basic_primitive", "Different input and output primitives.");
6034 tcu::TestCaseGroup* const triStripAdjacencyGroup = new tcu::TestCaseGroup(m_testCtx, "triangle_strip_adjacency", "Different triangle_strip_adjacency vertex counts.");
6037 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(inputPrimitives); ++ndx)
6038 basicPrimitiveGroup->addChild(new GeometryExpanderRenderTest(m_context, inputPrimitives[ndx].name, inputPrimitives[ndx].name, inputPrimitives[ndx].primitiveType, inputPrimitives[ndx].outputType));
6040 // triangle strip adjacency with different vtx counts
6041 for (int vtxCount = 0; vtxCount <= 12; ++vtxCount)
6043 const std::string name = "vertex_count_" + de::toString(vtxCount);
6044 const std::string desc = "Vertex count is " + de::toString(vtxCount);
6046 triStripAdjacencyGroup->addChild(new TriangleStripAdjacencyVertexCountTest(m_context, name.c_str(), desc.c_str(), vtxCount));
6049 inputPrimitiveGroup->addChild(basicPrimitiveGroup);
6050 inputPrimitiveGroup->addChild(triStripAdjacencyGroup);
6053 // different type conversions
6055 static const PrimitiveTestSpec conversionPrimitives[] =
6057 { GL_TRIANGLES, "triangles_to_points", GL_POINTS },
6058 { GL_LINES, "lines_to_points", GL_POINTS },
6059 { GL_POINTS, "points_to_lines", GL_LINE_STRIP },
6060 { GL_TRIANGLES, "triangles_to_lines", GL_LINE_STRIP },
6061 { GL_POINTS, "points_to_triangles", GL_TRIANGLE_STRIP },
6062 { GL_LINES, "lines_to_triangles", GL_TRIANGLE_STRIP }
6065 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(conversionPrimitives); ++ndx)
6066 conversionPrimitiveGroup->addChild(new GeometryExpanderRenderTest(m_context, conversionPrimitives[ndx].name, conversionPrimitives[ndx].name, conversionPrimitives[ndx].primitiveType, conversionPrimitives[ndx].outputType));
6069 // emit different amounts
6071 static const EmitTestSpec emitTests[] =
6073 { GL_POINTS, 0, 0, 0, 0, "points" },
6074 { GL_POINTS, 0, 1, 0, 0, "points" },
6075 { GL_POINTS, 1, 1, 0, 0, "points" },
6076 { GL_POINTS, 0, 2, 0, 0, "points" },
6077 { GL_POINTS, 1, 2, 0, 0, "points" },
6078 { GL_LINE_STRIP, 0, 0, 0, 0, "line_strip" },
6079 { GL_LINE_STRIP, 0, 1, 0, 0, "line_strip" },
6080 { GL_LINE_STRIP, 1, 1, 0, 0, "line_strip" },
6081 { GL_LINE_STRIP, 2, 1, 0, 0, "line_strip" },
6082 { GL_LINE_STRIP, 0, 2, 0, 0, "line_strip" },
6083 { GL_LINE_STRIP, 1, 2, 0, 0, "line_strip" },
6084 { GL_LINE_STRIP, 2, 2, 0, 0, "line_strip" },
6085 { GL_LINE_STRIP, 2, 2, 2, 0, "line_strip" },
6086 { GL_TRIANGLE_STRIP, 0, 0, 0, 0, "triangle_strip" },
6087 { GL_TRIANGLE_STRIP, 0, 1, 0, 0, "triangle_strip" },
6088 { GL_TRIANGLE_STRIP, 1, 1, 0, 0, "triangle_strip" },
6089 { GL_TRIANGLE_STRIP, 2, 1, 0, 0, "triangle_strip" },
6090 { GL_TRIANGLE_STRIP, 3, 1, 0, 0, "triangle_strip" },
6091 { GL_TRIANGLE_STRIP, 0, 2, 0, 0, "triangle_strip" },
6092 { GL_TRIANGLE_STRIP, 1, 2, 0, 0, "triangle_strip" },
6093 { GL_TRIANGLE_STRIP, 2, 2, 0, 0, "triangle_strip" },
6094 { GL_TRIANGLE_STRIP, 3, 2, 0, 0, "triangle_strip" },
6095 { GL_TRIANGLE_STRIP, 3, 2, 3, 0, "triangle_strip" },
6098 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(emitTests); ++ndx)
6100 std::string name = std::string(emitTests[ndx].name) + "_emit_" + de::toString(emitTests[ndx].emitCountA) + "_end_" + de::toString(emitTests[ndx].endCountA);
6101 std::string desc = std::string(emitTests[ndx].name) + " output, emit " + de::toString(emitTests[ndx].emitCountA) + " vertices, call EndPrimitive " + de::toString(emitTests[ndx].endCountA) + " times";
6103 if (emitTests[ndx].emitCountB)
6105 name += "_emit_" + de::toString(emitTests[ndx].emitCountB) + "_end_" + de::toString(emitTests[ndx].endCountB);
6106 desc += ", emit " + de::toString(emitTests[ndx].emitCountB) + " vertices, call EndPrimitive " + de::toString(emitTests[ndx].endCountB) + " times";
6109 emitGroup->addChild(new EmitTest(m_context, name.c_str(), desc.c_str(), emitTests[ndx].emitCountA, emitTests[ndx].endCountA, emitTests[ndx].emitCountB, emitTests[ndx].endCountB, emitTests[ndx].outputType));
6115 struct VaryingTestSpec
6118 int geometryOutputs;
6123 static const VaryingTestSpec varyingTests[] =
6125 { -1, 1, "vertex_no_op_geometry_out_1", "vertex_no_op_geometry_out_1" },
6126 { 0, 1, "vertex_out_0_geometry_out_1", "vertex_out_0_geometry_out_1" },
6127 { 0, 2, "vertex_out_0_geometry_out_2", "vertex_out_0_geometry_out_2" },
6128 { 1, 0, "vertex_out_1_geometry_out_0", "vertex_out_1_geometry_out_0" },
6129 { 1, 2, "vertex_out_1_geometry_out_2", "vertex_out_1_geometry_out_2" },
6132 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(varyingTests); ++ndx)
6133 varyingGroup->addChild(new VaryingTest(m_context, varyingTests[ndx].name, varyingTests[ndx].desc, varyingTests[ndx].vertexOutputs, varyingTests[ndx].geometryOutputs));
6138 static const struct TestType
6140 LayeredRenderCase::TestType test;
6141 const char* testPrefix;
6142 const char* descPrefix;
6145 { LayeredRenderCase::TEST_DEFAULT_LAYER, "render_with_default_layer_", "Render to all layers of " },
6146 { LayeredRenderCase::TEST_SINGLE_LAYER, "render_to_one_", "Render to one layer of " },
6147 { LayeredRenderCase::TEST_ALL_LAYERS, "render_to_all_", "Render to all layers of " },
6148 { LayeredRenderCase::TEST_DIFFERENT_LAYERS, "render_different_to_", "Render different data to different layers" },
6149 { LayeredRenderCase::TEST_LAYER_ID, "fragment_layer_", "Read gl_Layer in fragment shader" },
6150 { LayeredRenderCase::TEST_LAYER_PROVOKING_VERTEX, "layer_provoking_vertex_", "Verify LAYER_PROVOKING_VERTEX" },
6153 for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
6154 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6156 const std::string name = std::string(tests[testNdx].testPrefix) + layerTargets[targetNdx].name;
6157 const std::string desc = std::string(tests[testNdx].descPrefix) + layerTargets[targetNdx].desc;
6159 layeredGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, tests[testNdx].test));
6165 static const struct InvocationCase
6169 } invocationCases[] =
6177 static const int numDrawInstances[] = { 2, 4, 8 };
6178 static const int numDrawInvocations[] = { 2, 8 };
6180 // same amount of content to all invocations
6181 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(invocationCases); ++ndx)
6182 instancedGroup->addChild(new GeometryInvocationCase(m_context,
6183 (std::string("geometry_") + invocationCases[ndx].name + "_invocations").c_str(),
6184 (std::string("Geometry shader with ") + invocationCases[ndx].name + " invocation(s)").c_str(),
6185 invocationCases[ndx].numInvocations,
6186 GeometryInvocationCase::CASE_FIXED_OUTPUT_COUNTS));
6188 // different amount of content to each invocation
6189 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(invocationCases); ++ndx)
6190 if (invocationCases[ndx].numInvocations != 1)
6191 instancedGroup->addChild(new GeometryInvocationCase(m_context,
6192 (std::string("geometry_output_different_") + invocationCases[ndx].name + "_invocations").c_str(),
6193 "Geometry shader invocation(s) with different emit counts",
6194 invocationCases[ndx].numInvocations,
6195 GeometryInvocationCase::CASE_DIFFERENT_OUTPUT_COUNTS));
6197 // invocation per layer
6198 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6200 const std::string name = std::string("invocation_per_layer_") + layerTargets[targetNdx].name;
6201 const std::string desc = std::string("Render to multiple layers with multiple invocations, one invocation per layer, target ") + layerTargets[targetNdx].desc;
6203 instancedGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, LayeredRenderCase::TEST_INVOCATION_PER_LAYER));
6206 // multiple layers per invocation
6207 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6209 const std::string name = std::string("multiple_layers_per_invocation_") + layerTargets[targetNdx].name;
6210 const std::string desc = std::string("Render to multiple layers with multiple invocations, multiple layers per invocation, target ") + layerTargets[targetNdx].desc;
6212 instancedGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, LayeredRenderCase::TEST_MULTIPLE_LAYERS_PER_INVOCATION));
6215 // different invocation output counts depending on {uniform, attrib, texture}
6216 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_attribute", "Output varying number of vertices", VaryingOutputCountShader::READ_ATTRIBUTE, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6217 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_uniform", "Output varying number of vertices", VaryingOutputCountShader::READ_UNIFORM, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6218 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_texture", "Output varying number of vertices", VaryingOutputCountShader::READ_TEXTURE, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6220 // with drawInstanced
6221 for (int instanceNdx = 0; instanceNdx < DE_LENGTH_OF_ARRAY(numDrawInstances); ++instanceNdx)
6222 for (int invocationNdx = 0; invocationNdx < DE_LENGTH_OF_ARRAY(numDrawInvocations); ++invocationNdx)
6224 const std::string name = std::string("draw_") + de::toString(numDrawInstances[instanceNdx]) + "_instances_geometry_" + de::toString(numDrawInvocations[invocationNdx]) + "_invocations";
6225 const std::string desc = std::string("Draw ") + de::toString(numDrawInstances[instanceNdx]) + " instances, with " + de::toString(numDrawInvocations[invocationNdx]) + " geometry shader invocations.";
6227 instancedGroup->addChild(new DrawInstancedGeometryInstancedCase(m_context, name.c_str(), desc.c_str(), numDrawInstances[instanceNdx], numDrawInvocations[invocationNdx]));
6231 // negative (wrong types)
6233 struct PrimitiveToInputTypeConversion
6236 GLenum primitiveType;
6239 static const PrimitiveToInputTypeConversion legalConversions[] =
6241 { GL_POINTS, GL_POINTS },
6242 { GL_LINES, GL_LINES },
6243 { GL_LINES, GL_LINE_LOOP },
6244 { GL_LINES, GL_LINE_STRIP },
6245 { GL_LINES_ADJACENCY, GL_LINES_ADJACENCY },
6246 { GL_LINES_ADJACENCY, GL_LINE_STRIP_ADJACENCY },
6247 { GL_TRIANGLES, GL_TRIANGLES },
6248 { GL_TRIANGLES, GL_TRIANGLE_STRIP },
6249 { GL_TRIANGLES, GL_TRIANGLE_FAN },
6250 { GL_TRIANGLES_ADJACENCY, GL_TRIANGLES_ADJACENCY },
6251 { GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP_ADJACENCY },
6254 static const GLenum inputTypes[] =
6260 GL_TRIANGLES_ADJACENCY
6263 static const GLenum primitiveTypes[] =
6270 GL_LINE_STRIP_ADJACENCY,
6274 GL_TRIANGLES_ADJACENCY,
6275 GL_TRIANGLE_STRIP_ADJACENCY
6278 for (int inputTypeNdx = 0; inputTypeNdx < DE_LENGTH_OF_ARRAY(inputTypes); ++inputTypeNdx)
6279 for (int primitiveTypeNdx = 0; primitiveTypeNdx < DE_LENGTH_OF_ARRAY(primitiveTypes); ++primitiveTypeNdx)
6281 const GLenum inputType = inputTypes[inputTypeNdx];
6282 const GLenum primitiveType = primitiveTypes[primitiveTypeNdx];
6283 const std::string name = std::string("type_") + inputTypeToGLString(sglr::rr_util::mapGLGeometryShaderInputType(inputType)) + "_primitive_" + primitiveTypeToString(primitiveType);
6284 const std::string desc = std::string("Shader input type ") + inputTypeToGLString(sglr::rr_util::mapGLGeometryShaderInputType(inputType)) + ", draw primitive type " + primitiveTypeToString(primitiveType);
6286 bool isLegal = false;
6288 for (int legalNdx = 0; legalNdx < DE_LENGTH_OF_ARRAY(legalConversions); ++legalNdx)
6289 if (legalConversions[legalNdx].inputType == inputType && legalConversions[legalNdx].primitiveType == primitiveType)
6294 negativeGroup->addChild(new NegativeDrawCase(m_context, name.c_str(), desc.c_str(), inputType, primitiveType));
6298 // vertex transform feedback
6300 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_line_loop", "Capture line loop lines", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_LINE_LOOP));
6301 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_line_strip", "Capture line strip lines", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_LINE_STRIP));
6302 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_triangle_strip", "Capture triangle strip triangles", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_TRIANGLE_STRIP));
6303 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_triangle_fan", "Capture triangle fan triangles", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_TRIANGLE_FAN));
6304 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays", "Capture primitives generated with drawArrays", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_POINTS));
6305 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays_instanced", "Capture primitives generated with drawArraysInstanced", VertexFeedbackCase::METHOD_DRAW_ARRAYS_INSTANCED, VertexFeedbackCase::PRIMITIVE_POINTS));
6306 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays_indirect", "Capture primitives generated with drawArraysIndirect", VertexFeedbackCase::METHOD_DRAW_ARRAYS_INDIRECT, VertexFeedbackCase::PRIMITIVE_POINTS));
6307 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements", "Capture primitives generated with drawElements", VertexFeedbackCase::METHOD_DRAW_ELEMENTS, VertexFeedbackCase::PRIMITIVE_POINTS));
6308 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements_instanced", "Capture primitives generated with drawElementsInstanced", VertexFeedbackCase::METHOD_DRAW_ELEMENTS_INSTANCED, VertexFeedbackCase::PRIMITIVE_POINTS));
6309 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements_indirect", "Capture primitives generated with drawElementsIndirect", VertexFeedbackCase::METHOD_DRAW_ELEMENTS_INDIRECT, VertexFeedbackCase::PRIMITIVE_POINTS));
6311 feedbackGroup->addChild(new VertexFeedbackOverflowCase(m_context, "capture_vertex_draw_arrays_overflow_single_buffer", "Capture triangles to too small a buffer", VertexFeedbackOverflowCase::METHOD_DRAW_ARRAYS));
6312 feedbackGroup->addChild(new VertexFeedbackOverflowCase(m_context, "capture_vertex_draw_elements_overflow_single_buffer", "Capture triangles to too small a buffer", VertexFeedbackOverflowCase::METHOD_DRAW_ELEMENTS));