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 * (float)ndx * colWidth, 0.0, 0.0, 0.0), vertex->pointSize, vertex->outputs, packets[packetNdx].primitiveIDIn);
839 output.EmitVertex(vertex->position + tcu::Vec4(2 * (float)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 + (float)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 = 0; x < m_viewportSize.x(); ++x)
1944 for (int y = 0; y < m_viewportSize.y(); ++y)
1946 if (x == 0 || y == 0 || x + 1 == m_viewportSize.x() || y + 1 == m_viewportSize.y())
1948 // Mark edge pixels as correct since their neighbourhood is undefined
1949 errorMask.setPixel(x, y, green);
1953 const tcu::RGBA refcolor = m_refResult->getPixel(x, y);
1956 // Got to find similar pixel near this pixel (3x3 kernel)
1957 for (int dx = -1; dx <= 1; ++dx)
1958 for (int dy = -1; dy <= 1; ++dy)
1960 const tcu::RGBA testColor = m_glResult->getPixel(x + dx, y + dy);
1961 const tcu::IVec4 colDiff = tcu::abs(testColor.toIVec() - refcolor.toIVec());
1963 const int maxColDiff = de::max(de::max(colDiff.x(), colDiff.y()), colDiff.z()); // check RGB channels
1965 if (maxColDiff <= colorComponentThreshold)
1972 errorMask.setPixel(x, y, (found) ? (green) : (red));
1978 m_testCtx.getLog() << TestLog::ImageSet("Compare result", "Result of rendering")
1979 << TestLog::Image("Result", "Result", *m_glResult)
1980 << TestLog::EndImageSet;
1981 m_testCtx.getLog() << TestLog::Message << "Image compare ok." << TestLog::EndMessage;
1985 m_testCtx.getLog() << TestLog::ImageSet("Compare result", "Result of rendering")
1986 << TestLog::Image("Result", "Result", *m_glResult)
1987 << TestLog::Image("Reference", "Reference", *m_refResult)
1988 << TestLog::Image("ErrorMask", "Error mask", errorMask)
1989 << TestLog::EndImageSet;
1990 m_testCtx.getLog() << TestLog::Message << "Image compare failed." << TestLog::EndMessage;
1997 void GeometryShaderRenderTest::genVertexAttribData (void)
1999 // Create 1 X 2 grid in triangle strip adjacent - order
2000 const float scale = 0.3f;
2001 const tcu::Vec4 offset(-0.5f, -0.2f, 0.0f, 1.0f);
2003 m_vertexPosData.resize(12);
2004 m_vertexPosData[ 0] = tcu::Vec4( 0, 0, 0.0f, 0.0f) * scale + offset;
2005 m_vertexPosData[ 1] = tcu::Vec4(-1, -1, 0.0f, 0.0f) * scale + offset;
2006 m_vertexPosData[ 2] = tcu::Vec4( 0, -1, 0.0f, 0.0f) * scale + offset;
2007 m_vertexPosData[ 3] = tcu::Vec4( 1, 1, 0.0f, 0.0f) * scale + offset;
2008 m_vertexPosData[ 4] = tcu::Vec4( 1, 0, 0.0f, 0.0f) * scale + offset;
2009 m_vertexPosData[ 5] = tcu::Vec4( 0, -2, 0.0f, 0.0f) * scale + offset;
2010 m_vertexPosData[ 6] = tcu::Vec4( 1, -1, 0.0f, 0.0f) * scale + offset;
2011 m_vertexPosData[ 7] = tcu::Vec4( 2, 1, 0.0f, 0.0f) * scale + offset;
2012 m_vertexPosData[ 8] = tcu::Vec4( 2, 0, 0.0f, 0.0f) * scale + offset;
2013 m_vertexPosData[ 9] = tcu::Vec4( 1, -2, 0.0f, 0.0f) * scale + offset;
2014 m_vertexPosData[10] = tcu::Vec4( 2, -1, 0.0f, 0.0f) * scale + offset;
2015 m_vertexPosData[11] = tcu::Vec4( 3, 0, 0.0f, 0.0f) * scale + offset;
2018 m_vertexAttrData.resize(12);
2019 for (int i = 0; i < 12; ++i)
2020 m_vertexAttrData[i] = (i % 2 == 0) ? tcu::Vec4(1, 1, 1, 1) : tcu::Vec4(1, 0, 0, 1);
2022 m_numDrawVertices = 12;
2025 void GeometryShaderRenderTest::renderWithContext (sglr::Context& ctx, sglr::ShaderProgram& program, tcu::Surface& dstSurface)
2027 #define CHECK_GL_CTX_ERRORS() glu::checkError(ctx.getError(), DE_NULL, __FILE__, __LINE__)
2029 const GLuint programId = ctx.createProgram(&program);
2030 const GLint attrPosLoc = ctx.getAttribLocation(programId, "a_position");
2031 const GLint attrColLoc = ctx.getAttribLocation(programId, m_dataAttributeName);
2033 GLuint vertexPosBuf = 0;
2034 GLuint vertexAttrBuf = 0;
2035 GLuint elementArrayBuf = 0;
2037 ctx.genVertexArrays(1, &vaoId);
2038 ctx.bindVertexArray(vaoId);
2040 if (attrPosLoc != -1)
2042 ctx.genBuffers(1, &vertexPosBuf);
2043 ctx.bindBuffer(GL_ARRAY_BUFFER, vertexPosBuf);
2044 ctx.bufferData(GL_ARRAY_BUFFER, m_vertexPosData.size() * sizeof(tcu::Vec4), &m_vertexPosData[0], GL_STATIC_DRAW);
2045 ctx.vertexAttribPointer(attrPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2046 ctx.enableVertexAttribArray(attrPosLoc);
2049 if (attrColLoc != -1)
2051 ctx.genBuffers(1, &vertexAttrBuf);
2052 ctx.bindBuffer(GL_ARRAY_BUFFER, vertexAttrBuf);
2053 ctx.bufferData(GL_ARRAY_BUFFER, m_vertexAttrData.size() * sizeof(tcu::Vec4), &m_vertexAttrData[0], GL_STATIC_DRAW);
2054 ctx.vertexAttribPointer(attrColLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2055 ctx.enableVertexAttribArray(attrColLoc);
2057 if (m_vertexAttrDivisor)
2058 ctx.vertexAttribDivisor(attrColLoc, m_vertexAttrDivisor);
2061 if (m_flags & FLAG_USE_INDICES)
2063 ctx.genBuffers(1, &elementArrayBuf);
2064 ctx.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBuf);
2065 ctx.bufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(deUint16), &m_indices[0], GL_STATIC_DRAW);
2068 ctx.clearColor(0, 0, 0, 1);
2069 ctx.clear(GL_COLOR_BUFFER_BIT);
2071 ctx.viewport(0, 0, m_viewportSize.x(), m_viewportSize.y());
2072 CHECK_GL_CTX_ERRORS();
2074 ctx.useProgram(programId);
2075 CHECK_GL_CTX_ERRORS();
2077 preRender(ctx, programId);
2078 CHECK_GL_CTX_ERRORS();
2080 if (m_flags & FLAG_USE_RESTART_INDEX)
2082 ctx.enable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
2083 CHECK_GL_CTX_ERRORS();
2086 if (m_flags & FLAG_USE_INDICES)
2087 ctx.drawElements(m_inputPrimitives, m_numDrawVertices, GL_UNSIGNED_SHORT, DE_NULL);
2088 else if (m_flags & FLAG_DRAW_INSTANCED)
2089 ctx.drawArraysInstanced(m_inputPrimitives, 0, m_numDrawVertices, m_numDrawInstances);
2091 ctx.drawArrays(m_inputPrimitives, 0, m_numDrawVertices);
2093 CHECK_GL_CTX_ERRORS();
2095 if (m_flags & FLAG_USE_RESTART_INDEX)
2097 ctx.disable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
2098 CHECK_GL_CTX_ERRORS();
2101 postRender(ctx, programId);
2102 CHECK_GL_CTX_ERRORS();
2106 if (attrPosLoc != -1)
2107 ctx.disableVertexAttribArray(attrPosLoc);
2108 if (attrColLoc != -1)
2109 ctx.disableVertexAttribArray(attrColLoc);
2112 ctx.deleteBuffers(1, &vertexPosBuf);
2114 ctx.deleteBuffers(1, &vertexAttrBuf);
2115 if (elementArrayBuf)
2116 ctx.deleteBuffers(1, &elementArrayBuf);
2118 ctx.deleteVertexArrays(1, &vaoId);
2120 CHECK_GL_CTX_ERRORS();
2123 ctx.readPixels(dstSurface, 0, 0, m_viewportSize.x(), m_viewportSize.y());
2125 #undef CHECK_GL_CTX_ERRORS
2128 void GeometryShaderRenderTest::preRender (sglr::Context& ctx, GLuint programID)
2131 DE_UNREF(programID);
2134 void GeometryShaderRenderTest::postRender (sglr::Context& ctx, GLuint programID)
2137 DE_UNREF(programID);
2140 class GeometryExpanderRenderTest : public GeometryShaderRenderTest
2143 GeometryExpanderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives);
2144 virtual ~GeometryExpanderRenderTest (void);
2146 sglr::ShaderProgram& getProgram (void);
2149 VertexExpanderShader m_program;
2152 GeometryExpanderRenderTest::GeometryExpanderRenderTest (Context& context, const char* name, const char* desc, GLenum inputPrimitives, GLenum outputPrimitives)
2153 : GeometryShaderRenderTest (context, name, desc, inputPrimitives, outputPrimitives, "a_color")
2154 , m_program (sglr::rr_util::mapGLGeometryShaderInputType(inputPrimitives), sglr::rr_util::mapGLGeometryShaderOutputType(outputPrimitives))
2158 GeometryExpanderRenderTest::~GeometryExpanderRenderTest (void)
2162 sglr::ShaderProgram& GeometryExpanderRenderTest::getProgram (void)
2167 class EmitTest : public GeometryShaderRenderTest
2170 EmitTest (Context& context, const char* name, const char* desc, int emitCountA, int endCountA, int emitCountB, int endCountB, GLenum outputType);
2172 sglr::ShaderProgram& getProgram (void);
2174 void genVertexAttribData (void);
2176 VertexEmitterShader m_program;
2179 EmitTest::EmitTest (Context& context, const char* name, const char* desc, int emitCountA, int endCountA, int emitCountB, int endCountB, GLenum outputType)
2180 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, outputType, "a_color")
2181 , m_program (emitCountA, endCountA, emitCountB, endCountB, sglr::rr_util::mapGLGeometryShaderOutputType(outputType))
2185 sglr::ShaderProgram& EmitTest::getProgram (void)
2190 void EmitTest::genVertexAttribData (void)
2192 m_vertexPosData.resize(1);
2193 m_vertexPosData[0] = tcu::Vec4(0, 0, 0, 1);
2195 m_vertexAttrData.resize(1);
2196 m_vertexAttrData[0] = tcu::Vec4(1, 1, 1, 1);
2198 m_numDrawVertices = 1;
2201 class VaryingTest : public GeometryShaderRenderTest
2204 VaryingTest (Context& context, const char* name, const char* desc, int vertexOut, int geometryOut);
2206 sglr::ShaderProgram& getProgram (void);
2208 void genVertexAttribData (void);
2210 VertexVaryingShader m_program;
2213 VaryingTest::VaryingTest (Context& context, const char* name, const char* desc, int vertexOut, int geometryOut)
2214 : GeometryShaderRenderTest (context, name, desc, GL_TRIANGLES, GL_TRIANGLE_STRIP, "a_color")
2215 , m_program (vertexOut, geometryOut)
2219 sglr::ShaderProgram& VaryingTest::getProgram (void)
2224 void VaryingTest::genVertexAttribData (void)
2226 m_vertexPosData.resize(3);
2227 m_vertexPosData[0] = tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f);
2228 m_vertexPosData[1] = tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f);
2229 m_vertexPosData[2] = tcu::Vec4(0.1f, 0.0f, 0.0f, 1.0f);
2231 m_vertexAttrData.resize(3);
2232 m_vertexAttrData[0] = tcu::Vec4(0.7f, 0.4f, 0.6f, 1.0f);
2233 m_vertexAttrData[1] = tcu::Vec4(0.9f, 0.2f, 0.5f, 1.0f);
2234 m_vertexAttrData[2] = tcu::Vec4(0.1f, 0.8f, 0.3f, 1.0f);
2236 m_numDrawVertices = 3;
2239 class TriangleStripAdjacencyVertexCountTest : public GeometryExpanderRenderTest
2242 TriangleStripAdjacencyVertexCountTest (Context& context, const char* name, const char* desc, int numInputVertices);
2245 void genVertexAttribData (void);
2247 int m_numInputVertices;
2250 TriangleStripAdjacencyVertexCountTest::TriangleStripAdjacencyVertexCountTest (Context& context, const char* name, const char* desc, int numInputVertices)
2251 : GeometryExpanderRenderTest (context, name, desc, GL_TRIANGLE_STRIP_ADJACENCY, GL_TRIANGLE_STRIP)
2252 , m_numInputVertices (numInputVertices)
2256 void TriangleStripAdjacencyVertexCountTest::genVertexAttribData (void)
2258 this->GeometryShaderRenderTest::genVertexAttribData();
2259 m_numDrawVertices = m_numInputVertices;
2262 class NegativeDrawCase : public TestCase
2265 NegativeDrawCase (Context& context, const char* name, const char* desc, GLenum inputType, GLenum inputPrimitives);
2266 ~NegativeDrawCase (void);
2271 IterateResult iterate (void);
2274 sglr::Context* m_ctx;
2275 VertexExpanderShader* m_program;
2277 GLenum m_inputPrimitives;
2280 NegativeDrawCase::NegativeDrawCase (Context& context, const char* name, const char* desc, GLenum inputType, GLenum inputPrimitives)
2281 : TestCase (context, name, desc)
2283 , m_program (DE_NULL)
2284 , m_inputType (inputType)
2285 , m_inputPrimitives (inputPrimitives)
2289 NegativeDrawCase::~NegativeDrawCase (void)
2294 void NegativeDrawCase::init (void)
2296 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2297 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2299 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));
2300 m_program = new VertexExpanderShader(sglr::rr_util::mapGLGeometryShaderInputType(m_inputType), rr::GEOMETRYSHADEROUTPUTTYPE_POINTS);
2303 void NegativeDrawCase::deinit (void)
2309 m_program = DE_NULL;
2312 NegativeDrawCase::IterateResult NegativeDrawCase::iterate (void)
2314 const GLuint programId = m_ctx->createProgram(m_program);
2315 const GLint attrPosLoc = m_ctx->getAttribLocation(programId, "a_position");
2316 const tcu::Vec4 vertexPosData (0, 0, 0, 1);
2319 GLuint vertexPosBuf = 0;
2320 GLenum errorCode = 0;
2322 m_ctx->genVertexArrays(1, &vaoId);
2323 m_ctx->bindVertexArray(vaoId);
2325 m_ctx->genBuffers(1, &vertexPosBuf);
2326 m_ctx->bindBuffer(GL_ARRAY_BUFFER, vertexPosBuf);
2327 m_ctx->bufferData(GL_ARRAY_BUFFER, sizeof(tcu::Vec4), vertexPosData.m_data, GL_STATIC_DRAW);
2328 m_ctx->vertexAttribPointer(attrPosLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
2329 m_ctx->enableVertexAttribArray(attrPosLoc);
2331 m_ctx->clearColor(0, 0, 0, 1);
2332 m_ctx->clear(GL_COLOR_BUFFER_BIT);
2334 m_ctx->viewport(0, 0, 1, 1);
2336 m_ctx->useProgram(programId);
2339 glu::checkError(m_ctx->getError(), "", __FILE__, __LINE__);
2341 m_ctx->drawArrays(m_inputPrimitives, 0, 1);
2343 errorCode = m_ctx->getError();
2344 if (errorCode != GL_INVALID_OPERATION)
2346 m_testCtx.getLog() << tcu::TestLog::Message << "Expected GL_INVALID_OPERATION, got " << glu::getErrorStr(errorCode) << tcu::TestLog::EndMessage;
2347 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got wrong error code");
2351 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2354 m_ctx->useProgram(0);
2356 m_ctx->disableVertexAttribArray(attrPosLoc);
2357 m_ctx->deleteBuffers(1, &vertexPosBuf);
2359 m_ctx->deleteVertexArrays(1, &vaoId);
2364 class OutputCountCase : public GeometryShaderRenderTest
2367 OutputCountCase (Context& context, const char* name, const char* desc, const OutputCountPatternSpec&);
2372 sglr::ShaderProgram& getProgram (void);
2373 void genVertexAttribData (void);
2375 const int m_primitiveCount;
2376 OutputCountShader* m_program;
2377 OutputCountPatternSpec m_spec;
2380 OutputCountCase::OutputCountCase (Context& context, const char* name, const char* desc, const OutputCountPatternSpec& spec)
2381 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_TRIANGLE_STRIP, "a_color")
2382 , m_primitiveCount ((int)spec.pattern.size())
2383 , m_program (DE_NULL)
2388 void OutputCountCase::init (void)
2390 // Check requirements and adapt to them
2392 const int componentsPerVertex = 4 + 4; // vec4 pos, vec4 color
2393 const int testVertices = *std::max_element(m_spec.pattern.begin(), m_spec.pattern.end());
2394 glw::GLint maxVertices = 0;
2395 glw::GLint maxComponents = 0;
2397 // check the extension before querying anything
2398 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2399 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2401 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxVertices);
2402 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
2404 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_OUTPUT_VERTICES = " << maxVertices << tcu::TestLog::EndMessage;
2405 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = " << maxComponents << tcu::TestLog::EndMessage;
2406 m_testCtx.getLog() << tcu::TestLog::Message << "Components per vertex = " << componentsPerVertex << tcu::TestLog::EndMessage;
2408 if (testVertices == -1)
2410 // "max vertices"-case
2411 DE_ASSERT((int)m_spec.pattern.size() == 1);
2412 m_spec.pattern[0] = de::min(maxVertices, maxComponents / componentsPerVertex);
2414 // make sure size is dividable by 2, as OutputShader requires
2415 m_spec.pattern[0] = m_spec.pattern[0] & ~0x00000001;
2417 if (m_spec.pattern[0] == 0)
2418 throw tcu::InternalError("Pattern size is invalid.");
2423 if (testVertices > maxVertices)
2424 throw tcu::NotSupportedError(de::toString(testVertices) + " output vertices required.");
2425 if (testVertices * componentsPerVertex > maxComponents)
2426 throw tcu::NotSupportedError(de::toString(testVertices * componentsPerVertex) + " output components required.");
2430 // Log what the test tries to do
2432 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;
2433 for (int ndx = 0; ndx < (int)m_spec.pattern.size(); ++ndx)
2434 m_testCtx.getLog() << tcu::TestLog::Message << "Row " << ndx << ": " << m_spec.pattern[ndx] << " vertices." << tcu::TestLog::EndMessage;
2437 DE_ASSERT(!m_program);
2438 m_program = new OutputCountShader(m_spec);
2441 GeometryShaderRenderTest::init();
2444 void OutputCountCase::deinit (void)
2449 m_program = DE_NULL;
2452 GeometryShaderRenderTest::deinit();
2455 sglr::ShaderProgram& OutputCountCase::getProgram (void)
2460 void OutputCountCase::genVertexAttribData (void)
2462 m_vertexPosData.resize(m_primitiveCount);
2463 m_vertexAttrData.resize(m_primitiveCount);
2465 for (int ndx = 0; ndx < m_primitiveCount; ++ndx)
2467 m_vertexPosData[ndx] = tcu::Vec4(-1.0f, ((float)ndx) / (float)m_primitiveCount * 2.0f - 1.0f, 0.0f, 1.0f);
2468 m_vertexAttrData[ndx] = (ndx % 2 == 0) ? tcu::Vec4(1, 1, 1, 1) : tcu::Vec4(1, 0, 0, 1);
2471 m_numDrawVertices = m_primitiveCount;
2474 class BuiltinVariableRenderTest : public GeometryShaderRenderTest
2477 BuiltinVariableRenderTest (Context& context, const char* name, const char* desc, BuiltinVariableShader::VariableTest test, int flags = 0);
2482 sglr::ShaderProgram& getProgram (void);
2483 void genVertexAttribData (void);
2485 BuiltinVariableShader m_program;
2486 const BuiltinVariableShader::VariableTest m_test;
2489 BuiltinVariableRenderTest::BuiltinVariableRenderTest (Context& context, const char* name, const char* desc, BuiltinVariableShader::VariableTest test, int flags)
2490 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_POINTS, BuiltinVariableShader::getTestAttributeName(test), flags)
2496 void BuiltinVariableRenderTest::init (void)
2499 if (m_test == BuiltinVariableShader::TEST_POINT_SIZE)
2501 const float requiredPointSize = 5.0f;
2503 tcu::Vec2 range = tcu::Vec2(1.0f, 1.0f);
2505 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_point_size"))
2506 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_point_size extension");
2508 m_context.getRenderContext().getFunctions().getFloatv(GL_ALIASED_POINT_SIZE_RANGE, range.getPtr());
2509 if (range.y() < requiredPointSize)
2510 throw tcu::NotSupportedError("Test case requires point size " + de::toString(requiredPointSize));
2514 GeometryShaderRenderTest::init();
2517 sglr::ShaderProgram& BuiltinVariableRenderTest::getProgram (void)
2522 void BuiltinVariableRenderTest::genVertexAttribData (void)
2524 m_vertexPosData.resize(4);
2525 m_vertexPosData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 1.0f);
2526 m_vertexPosData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 1.0f);
2527 m_vertexPosData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 1.0f);
2528 m_vertexPosData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 1.0f);
2530 m_vertexAttrData.resize(4);
2531 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
2532 m_vertexAttrData[1] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
2533 m_vertexAttrData[2] = tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f);
2534 m_vertexAttrData[3] = tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f);
2536 // Only used by primitive ID restart test
2537 m_indices.resize(4);
2540 m_indices[2] = 0xFFFF; // restart
2543 m_numDrawVertices = 4;
2546 class LayeredRenderCase : public TestCase
2549 enum LayeredRenderTargetType
2561 TEST_DEFAULT_LAYER, // !< draw to default layer
2562 TEST_SINGLE_LAYER, // !< draw to single layer
2563 TEST_ALL_LAYERS, // !< draw all layers
2564 TEST_DIFFERENT_LAYERS, // !< draw different content to different layers
2565 TEST_INVOCATION_PER_LAYER, // !< draw to all layers, one invocation per layer
2566 TEST_MULTIPLE_LAYERS_PER_INVOCATION, // !< draw to all layers, multiple invocations write to multiple layers
2567 TEST_LAYER_ID, // !< draw to all layers, verify gl_Layer fragment input
2568 TEST_LAYER_PROVOKING_VERTEX, // !< draw primitive with vertices in different layers, check which layer it was drawn to
2572 LayeredRenderCase (Context& context, const char* name, const char* desc, LayeredRenderTargetType target, TestType test);
2573 ~LayeredRenderCase (void);
2577 IterateResult iterate (void);
2580 void initTexture (void);
2581 void initFbo (void);
2582 void initRenderShader (void);
2583 void initSamplerShader (void);
2585 std::string genFragmentSource (void) const;
2586 std::string genGeometrySource (void) const;
2587 std::string genSamplerFragmentSource (void) const;
2589 void renderToTexture (void);
2590 void sampleTextureLayer (tcu::Surface& dst, int layer);
2591 bool verifyLayerContent (const tcu::Surface& layer, int layerNdx);
2592 bool verifyImageSingleColoredRow (const tcu::Surface& layer, float rowWidthRatio, const tcu::Vec4& color, bool logging = true);
2593 bool verifyEmptyImage (const tcu::Surface& layer, bool logging = true);
2594 bool verifyProvokingVertexLayers (const tcu::Surface& layer0, const tcu::Surface& layer1);
2596 static int getTargetLayers (LayeredRenderTargetType target);
2597 static glw::GLenum getTargetTextureTarget (LayeredRenderTargetType target);
2598 static tcu::IVec3 getTargetDimensions (LayeredRenderTargetType target);
2599 static tcu::IVec2 getResolveDimensions (LayeredRenderTargetType target);
2601 const LayeredRenderTargetType m_target;
2602 const TestType m_test;
2603 const int m_numLayers;
2604 const int m_targetLayer;
2605 const tcu::IVec2 m_resolveDimensions;
2610 glw::GLuint m_texture;
2612 glu::ShaderProgram* m_renderShader;
2613 glu::ShaderProgram* m_samplerShader;
2615 glw::GLint m_samplerSamplerLoc;
2616 glw::GLint m_samplerLayerLoc;
2618 glw::GLenum m_provokingVertex;
2621 LayeredRenderCase::LayeredRenderCase (Context& context, const char* name, const char* desc, LayeredRenderTargetType target, TestType test)
2622 : TestCase (context, name, desc)
2625 , m_numLayers (getTargetLayers(target))
2626 , m_targetLayer (m_numLayers / 2)
2627 , m_resolveDimensions (getResolveDimensions(target))
2629 , m_allLayersOk (true)
2632 , m_renderShader (DE_NULL)
2633 , m_samplerShader (DE_NULL)
2634 , m_samplerSamplerLoc (-1)
2635 , m_samplerLayerLoc (-1)
2636 , m_provokingVertex (0)
2640 LayeredRenderCase::~LayeredRenderCase (void)
2645 void LayeredRenderCase::init (void)
2649 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
2650 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
2652 if (m_target == TARGET_2D_MS_ARRAY && !m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
2653 throw tcu::NotSupportedError("Test requires OES_texture_storage_multisample_2d_array extension");
2655 if (m_context.getRenderTarget().getWidth() < m_resolveDimensions.x() || m_context.getRenderTarget().getHeight() < m_resolveDimensions.y())
2656 throw tcu::NotSupportedError("Render target size must be at least " + de::toString(m_resolveDimensions.x()) + "x" + de::toString(m_resolveDimensions.y()));
2658 // log what the test tries to do
2660 if (m_test == TEST_DEFAULT_LAYER)
2661 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to the default layer." << tcu::TestLog::EndMessage;
2662 else if (m_test == TEST_SINGLE_LAYER)
2663 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to a single layer." << tcu::TestLog::EndMessage;
2664 else if (m_test == TEST_ALL_LAYERS)
2665 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to all layers." << tcu::TestLog::EndMessage;
2666 else if (m_test == TEST_DIFFERENT_LAYERS)
2667 m_testCtx.getLog() << tcu::TestLog::Message << "Outputting different number of vertices to each layer." << tcu::TestLog::EndMessage;
2668 else if (m_test == TEST_INVOCATION_PER_LAYER)
2669 m_testCtx.getLog() << tcu::TestLog::Message << "Using a different invocation to output to each layer." << tcu::TestLog::EndMessage;
2670 else if (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
2671 m_testCtx.getLog() << tcu::TestLog::Message << "Outputting to each layer from multiple invocations." << tcu::TestLog::EndMessage;
2672 else if (m_test == TEST_LAYER_ID)
2673 m_testCtx.getLog() << tcu::TestLog::Message << "Using gl_Layer in fragment shader." << tcu::TestLog::EndMessage;
2674 else if (m_test == TEST_LAYER_PROVOKING_VERTEX)
2675 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying LAYER_PROVOKING_VERTEX." << tcu::TestLog::EndMessage;
2684 initSamplerShader();
2687 void LayeredRenderCase::deinit (void)
2691 m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texture);
2697 m_context.getRenderContext().getFunctions().deleteFramebuffers(1, &m_fbo);
2701 delete m_renderShader;
2702 delete m_samplerShader;
2704 m_renderShader = DE_NULL;
2705 m_samplerShader = DE_NULL;
2708 LayeredRenderCase::IterateResult LayeredRenderCase::iterate (void)
2712 if (m_iteration == 1)
2714 if (m_test == TEST_LAYER_PROVOKING_VERTEX)
2716 // which layer the implementation claims to render to
2718 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
2720 m_context.getRenderContext().getFunctions().getIntegerv(GL_LAYER_PROVOKING_VERTEX, &state);
2721 GLU_EXPECT_NO_ERROR(m_context.getRenderContext().getFunctions().getError(), "getInteger(GL_LAYER_PROVOKING_VERTEX)");
2723 if (!state.verifyValidity(m_testCtx))
2726 m_testCtx.getLog() << tcu::TestLog::Message << "GL_LAYER_PROVOKING_VERTEX = " << glu::getProvokingVertexStr(state) << tcu::TestLog::EndMessage;
2728 if (state != GL_FIRST_VERTEX_CONVENTION &&
2729 state != GL_LAST_VERTEX_CONVENTION &&
2730 state != GL_UNDEFINED_VERTEX)
2732 m_testCtx.getLog() << tcu::TestLog::Message << "getInteger(GL_LAYER_PROVOKING_VERTEX) returned illegal value. Got " << state << tcu::TestLog::EndMessage;
2733 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected provoking vertex value");
2737 m_provokingVertex = (glw::GLenum)state;
2740 // render to texture
2742 const tcu::ScopedLogSection section(m_testCtx.getLog(), "RenderToTexture", "Render to layered texture");
2744 // render to layered texture with the geometry shader
2750 else if (m_test == TEST_LAYER_PROVOKING_VERTEX && m_provokingVertex == GL_UNDEFINED_VERTEX)
2752 // Verification requires information from another layers, layers not independent
2754 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayers", "Verify layers 0 and 1");
2755 tcu::Surface layer0 (m_resolveDimensions.x(), m_resolveDimensions.y());
2756 tcu::Surface layer1 (m_resolveDimensions.x(), m_resolveDimensions.y());
2758 // sample layer to frame buffer
2759 sampleTextureLayer(layer0, 0);
2760 sampleTextureLayer(layer1, 1);
2762 m_allLayersOk &= verifyProvokingVertexLayers(layer0, layer1);
2765 // Other layers empty
2766 for (int layerNdx = 2; layerNdx < m_numLayers; ++layerNdx)
2768 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayer", "Verify layer " + de::toString(layerNdx));
2769 tcu::Surface layer (m_resolveDimensions.x(), m_resolveDimensions.y());
2771 // sample layer to frame buffer
2772 sampleTextureLayer(layer, layerNdx);
2775 m_allLayersOk &= verifyEmptyImage(layer);
2780 // Layers independent
2782 const int layerNdx = m_iteration - 2;
2783 const tcu::ScopedLogSection section (m_testCtx.getLog(), "VerifyLayer", "Verify layer " + de::toString(layerNdx));
2784 tcu::Surface layer (m_resolveDimensions.x(), m_resolveDimensions.y());
2786 // sample layer to frame buffer
2787 sampleTextureLayer(layer, layerNdx);
2790 m_allLayersOk &= verifyLayerContent(layer, layerNdx);
2792 if (layerNdx < m_numLayers-1)
2798 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2800 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Detected invalid layer content");
2805 void LayeredRenderCase::initTexture (void)
2807 DE_ASSERT(!m_texture);
2809 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2810 const tcu::IVec3 texSize = getTargetDimensions(m_target);
2811 const tcu::TextureFormat texFormat = glu::mapGLInternalFormat(GL_RGBA8);
2812 const glu::TransferFormat transferFormat = glu::getTransferFormat(texFormat);
2814 gl.genTextures(1, &m_texture);
2815 GLU_EXPECT_NO_ERROR(gl.getError(), "gen texture");
2820 m_testCtx.getLog() << tcu::TestLog::Message << "Creating cubemap texture, size = " << texSize.x() << "x" << texSize.y() << tcu::TestLog::EndMessage;
2821 gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
2822 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2823 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2824 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2825 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2826 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2827 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2831 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 3d texture, size = " << texSize.x() << "x" << texSize.y() << "x" << texSize.z() << tcu::TestLog::EndMessage;
2832 gl.bindTexture(GL_TEXTURE_3D, m_texture);
2833 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2836 case TARGET_1D_ARRAY:
2837 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 1d texture array, size = " << texSize.x() << ", layers = " << texSize.y() << tcu::TestLog::EndMessage;
2838 gl.bindTexture(GL_TEXTURE_1D_ARRAY, m_texture);
2839 gl.texImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA8, texSize.x(), texSize.y(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2842 case TARGET_2D_ARRAY:
2843 m_testCtx.getLog() << tcu::TestLog::Message << "Creating 2d texture array, size = " << texSize.x() << "x" << texSize.y() << ", layers = " << texSize.z() << tcu::TestLog::EndMessage;
2844 gl.bindTexture(GL_TEXTURE_2D_ARRAY, m_texture);
2845 gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), 0, transferFormat.format, transferFormat.dataType, DE_NULL);
2848 case TARGET_2D_MS_ARRAY:
2850 const int numSamples = 2;
2853 gl.getIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxSamples);
2855 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;
2857 if (numSamples > maxSamples)
2858 throw tcu::NotSupportedError("Test requires " + de::toString(numSamples) + " color texture samples." );
2860 gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, m_texture);
2861 gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, numSamples, GL_RGBA8, texSize.x(), texSize.y(), texSize.z(), GL_TRUE);
2866 DE_ASSERT(DE_FALSE);
2868 GLU_EXPECT_NO_ERROR(gl.getError(), "tex image");
2870 // Multisample textures don't use filters
2871 if (getTargetTextureTarget(m_target) != GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
2873 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2874 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2875 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_S, GL_REPEAT);
2876 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_T, GL_REPEAT);
2877 gl.texParameteri(getTargetTextureTarget(m_target), GL_TEXTURE_WRAP_R, GL_REPEAT);
2878 GLU_EXPECT_NO_ERROR(gl.getError(), "tex filter");
2882 void LayeredRenderCase::initFbo (void)
2886 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
2888 m_testCtx.getLog() << tcu::TestLog::Message << "Creating FBO" << tcu::TestLog::EndMessage;
2890 gl.genFramebuffers(1, &m_fbo);
2891 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
2892 gl.framebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture, 0);
2893 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
2895 GLU_EXPECT_NO_ERROR(gl.getError(), "setup fbo");
2898 void LayeredRenderCase::initRenderShader (void)
2900 const tcu::ScopedLogSection section(m_testCtx.getLog(), "RenderToTextureShader", "Create layered rendering shader program");
2902 static const char* const positionVertex = "#version 310 es\n"
2903 "void main (void)\n"
2905 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
2908 m_renderShader = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources() << glu::VertexSource(positionVertex) << glu::FragmentSource(genFragmentSource()) << glu::GeometrySource(genGeometrySource()));
2909 m_testCtx.getLog() << *m_renderShader;
2911 if (!m_renderShader->isOk())
2912 throw tcu::TestError("failed to build render shader");
2915 void LayeredRenderCase::initSamplerShader (void)
2917 const tcu::ScopedLogSection section(m_testCtx.getLog(), "TextureSamplerShader", "Create shader sampler program");
2919 static const char* const positionVertex = "#version 310 es\n"
2920 "in highp vec4 a_position;\n"
2921 "void main (void)\n"
2923 " gl_Position = a_position;\n"
2926 m_samplerShader = new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
2927 << glu::VertexSource(positionVertex)
2928 << glu::FragmentSource(genSamplerFragmentSource()));
2930 m_testCtx.getLog() << *m_samplerShader;
2932 if (!m_samplerShader->isOk())
2933 throw tcu::TestError("failed to build sampler shader");
2935 m_samplerSamplerLoc = m_context.getRenderContext().getFunctions().getUniformLocation(m_samplerShader->getProgram(), "u_sampler");
2936 if (m_samplerSamplerLoc == -1)
2937 throw tcu::TestError("u_sampler uniform location = -1");
2939 m_samplerLayerLoc = m_context.getRenderContext().getFunctions().getUniformLocation(m_samplerShader->getProgram(), "u_layer");
2940 if (m_samplerLayerLoc == -1)
2941 throw tcu::TestError("u_layer uniform location = -1");
2944 std::string LayeredRenderCase::genFragmentSource (void) const
2946 static const char* const fragmentLayerIdShader = "#version 310 es\n"
2947 "#extension GL_EXT_geometry_shader : require\n"
2948 "layout(location = 0) out mediump vec4 fragColor;\n"
2949 "void main (void)\n"
2951 " fragColor = vec4(((gl_Layer % 2) == 1) ? 1.0 : 0.5,\n"
2952 " (((gl_Layer / 2) % 2) == 1) ? 1.0 : 0.5,\n"
2953 " (gl_Layer == 0) ? 1.0 : 0.0,\n"
2957 if (m_test != TEST_LAYER_ID)
2958 return std::string(s_commonShaderSourceFragment);
2960 return std::string(fragmentLayerIdShader);
2963 std::string LayeredRenderCase::genGeometrySource (void) const
2965 // TEST_DIFFERENT_LAYERS: draw 0 quad to first layer, 1 to second, etc.
2966 // TEST_ALL_LAYERS: draw 1 quad to all layers
2967 // TEST_MULTIPLE_LAYERS_PER_INVOCATION: draw 1 triangle to "current layer" and 1 triangle to another layer
2968 // else: draw 1 quad to some single layer
2969 const int maxVertices = (m_test == TEST_DIFFERENT_LAYERS) ? ((2 + m_numLayers-1) * m_numLayers) :
2970 (m_test == TEST_ALL_LAYERS || m_test == TEST_LAYER_ID) ? (m_numLayers * 4) :
2971 (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION) ? (6) :
2972 (m_test == TEST_LAYER_PROVOKING_VERTEX) ? (6) :
2974 std::ostringstream buf;
2976 buf << "#version 310 es\n"
2977 "#extension GL_EXT_geometry_shader : require\n";
2979 if (m_test == TEST_INVOCATION_PER_LAYER || m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
2980 buf << "layout(points, invocations=" << m_numLayers << ") in;\n";
2982 buf << "layout(points) in;\n";
2984 buf << "layout(triangle_strip, max_vertices = " << maxVertices << ") out;\n"
2985 "out highp vec4 v_frag_FragColor;\n"
2987 "void main (void)\n"
2990 if (m_test == TEST_DEFAULT_LAYER)
2992 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
2993 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
2994 " v_frag_FragColor = white;\n"
2995 " EmitVertex();\n\n"
2996 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
2997 " v_frag_FragColor = white;\n"
2998 " EmitVertex();\n\n"
2999 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3000 " v_frag_FragColor = white;\n"
3001 " EmitVertex();\n\n"
3002 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3003 " v_frag_FragColor = white;\n"
3006 else if (m_test == TEST_SINGLE_LAYER)
3008 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3009 " gl_Position = vec4(-1.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(-1.0, 1.0, 0.0, 1.0);\n"
3014 " gl_Layer = " << m_targetLayer << ";\n"
3015 " v_frag_FragColor = white;\n"
3016 " EmitVertex();\n\n"
3017 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3018 " gl_Layer = " << m_targetLayer << ";\n"
3019 " v_frag_FragColor = white;\n"
3020 " EmitVertex();\n\n"
3021 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3022 " gl_Layer = " << m_targetLayer << ";\n"
3023 " v_frag_FragColor = white;\n"
3026 else if (m_test == TEST_ALL_LAYERS || m_test == TEST_LAYER_ID)
3028 DE_ASSERT(m_numLayers <= 6);
3030 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3031 " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3032 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3033 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3034 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3035 " const highp vec4 magenta = vec4(1.0, 0.0, 1.0, 1.0);\n"
3036 " const highp vec4 colors[6] = vec4[6](white, red, green, blue, yellow, magenta);\n\n"
3037 " for (mediump int layerNdx = 0; layerNdx < " << m_numLayers << "; ++layerNdx)\n"
3039 " gl_Position = vec4(-1.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(-1.0, 1.0, 0.0, 1.0);\n"
3044 " gl_Layer = layerNdx;\n"
3045 " v_frag_FragColor = colors[layerNdx];\n"
3046 " EmitVertex();\n\n"
3047 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3048 " gl_Layer = layerNdx;\n"
3049 " v_frag_FragColor = colors[layerNdx];\n"
3050 " EmitVertex();\n\n"
3051 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3052 " gl_Layer = layerNdx;\n"
3053 " v_frag_FragColor = colors[layerNdx];\n"
3055 " EndPrimitive();\n"
3058 else if (m_test == TEST_DIFFERENT_LAYERS)
3060 DE_ASSERT(m_numLayers <= 6);
3062 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3063 " for (mediump int layerNdx = 0; layerNdx < " << m_numLayers << "; ++layerNdx)\n"
3065 " for (mediump int colNdx = 0; colNdx <= layerNdx; ++colNdx)\n"
3067 " highp float posX = float(colNdx) / float(" << m_numLayers << ") * 2.0 - 1.0;\n\n"
3068 " gl_Position = vec4(posX, 1.0, 0.0, 1.0);\n"
3069 " gl_Layer = layerNdx;\n"
3070 " v_frag_FragColor = white;\n"
3071 " EmitVertex();\n\n"
3072 " gl_Position = vec4(posX, -1.0, 0.0, 1.0);\n"
3073 " gl_Layer = layerNdx;\n"
3074 " v_frag_FragColor = white;\n"
3077 " EndPrimitive();\n"
3080 else if (m_test == TEST_INVOCATION_PER_LAYER)
3082 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3083 " const highp vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3084 " const highp vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
3085 " const highp vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3086 " const highp vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3087 " const highp vec4 magenta = vec4(1.0, 0.0, 1.0, 1.0);\n"
3088 " const highp vec4 colors[6] = vec4[6](white, red, green, blue, yellow, magenta);\n"
3090 " gl_Position = vec4(-1.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(-1.0, 1.0, 0.0, 1.0);\n"
3095 " gl_Layer = gl_InvocationID;\n"
3096 " v_frag_FragColor = colors[gl_InvocationID];\n"
3097 " EmitVertex();\n\n"
3098 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3099 " gl_Layer = gl_InvocationID;\n"
3100 " v_frag_FragColor = colors[gl_InvocationID];\n"
3101 " EmitVertex();\n\n"
3102 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3103 " gl_Layer = gl_InvocationID;\n"
3104 " v_frag_FragColor = colors[gl_InvocationID];\n"
3106 " EndPrimitive();\n";
3108 else if (m_test == TEST_MULTIPLE_LAYERS_PER_INVOCATION)
3110 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3112 " mediump int layerA = gl_InvocationID;\n"
3113 " mediump int layerB = (gl_InvocationID + 1) % " << m_numLayers << ";\n"
3114 " highp float aEnd = float(layerA) / float(" << m_numLayers << ") * 2.0 - 1.0;\n"
3115 " highp float bEnd = float(layerB) / float(" << m_numLayers << ") * 2.0 - 1.0;\n"
3117 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3118 " gl_Layer = layerA;\n"
3119 " v_frag_FragColor = white;\n"
3120 " EmitVertex();\n\n"
3121 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3122 " gl_Layer = layerA;\n"
3123 " v_frag_FragColor = white;\n"
3124 " EmitVertex();\n\n"
3125 " gl_Position = vec4(aEnd, -1.0, 0.0, 1.0);\n"
3126 " gl_Layer = layerA;\n"
3127 " v_frag_FragColor = white;\n"
3128 " EmitVertex();\n\n"
3129 " EndPrimitive();\n"
3131 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3132 " gl_Layer = layerB;\n"
3133 " v_frag_FragColor = white;\n"
3134 " EmitVertex();\n\n"
3135 " gl_Position = vec4(bEnd, 1.0, 0.0, 1.0);\n"
3136 " gl_Layer = layerB;\n"
3137 " v_frag_FragColor = white;\n"
3138 " EmitVertex();\n\n"
3139 " gl_Position = vec4(bEnd, -1.0, 0.0, 1.0);\n"
3140 " gl_Layer = layerB;\n"
3141 " v_frag_FragColor = white;\n"
3142 " EmitVertex();\n\n"
3143 " EndPrimitive();\n";
3145 else if (m_test == TEST_LAYER_PROVOKING_VERTEX)
3147 buf << " const highp vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n\n"
3148 " gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);\n"
3150 " v_frag_FragColor = white;\n"
3151 " EmitVertex();\n\n"
3152 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3154 " v_frag_FragColor = white;\n"
3155 " EmitVertex();\n\n"
3156 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3158 " v_frag_FragColor = white;\n"
3159 " EmitVertex();\n\n"
3160 " EndPrimitive();\n\n"
3161 " gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);\n"
3163 " v_frag_FragColor = white;\n"
3164 " EmitVertex();\n\n"
3165 " gl_Position = vec4( 0.0, -1.0, 0.0, 1.0);\n"
3167 " v_frag_FragColor = white;\n"
3168 " EmitVertex();\n\n"
3169 " gl_Position = vec4( 0.0, 1.0, 0.0, 1.0);\n"
3171 " v_frag_FragColor = white;\n"
3175 DE_ASSERT(DE_FALSE);
3182 std::string LayeredRenderCase::genSamplerFragmentSource (void) const
3184 std::ostringstream buf;
3186 buf << "#version 310 es\n";
3187 if (m_target == TARGET_2D_MS_ARRAY)
3188 buf << "#extension GL_OES_texture_storage_multisample_2d_array : require\n";
3189 buf << "layout(location = 0) out mediump vec4 fragColor;\n";
3193 case TARGET_CUBE: buf << "uniform highp samplerCube u_sampler;\n"; break;
3194 case TARGET_3D: buf << "uniform highp sampler3D u_sampler;\n"; break;
3195 case TARGET_2D_ARRAY: buf << "uniform highp sampler2DArray u_sampler;\n"; break;
3196 case TARGET_1D_ARRAY: buf << "uniform highp sampler1DArray u_sampler;\n"; break;
3197 case TARGET_2D_MS_ARRAY: buf << "uniform highp sampler2DMSArray u_sampler;\n"; break;
3199 DE_ASSERT(DE_FALSE);
3202 buf << "uniform highp int u_layer;\n"
3203 "void main (void)\n"
3209 buf << " highp vec2 facepos = 2.0 * gl_FragCoord.xy / vec2(ivec2(" << m_resolveDimensions.x() << ", " << m_resolveDimensions.y() << ")) - vec2(1.0, 1.0);\n"
3210 " if (u_layer == 0)\n"
3211 " fragColor = textureLod(u_sampler, vec3(1.0, -facepos.y, -facepos.x), 0.0);\n"
3212 " else if (u_layer == 1)\n"
3213 " fragColor = textureLod(u_sampler, vec3(-1.0, -facepos.y, facepos.x), 0.0);\n"
3214 " else if (u_layer == 2)\n"
3215 " fragColor = textureLod(u_sampler, vec3(facepos.x, 1.0, facepos.y), 0.0);\n"
3216 " else if (u_layer == 3)\n"
3217 " fragColor = textureLod(u_sampler, vec3(facepos.x, -1.0, -facepos.y), 0.0);\n"
3218 " else if (u_layer == 4)\n"
3219 " fragColor = textureLod(u_sampler, vec3(facepos.x, -facepos.y, 1.0), 0.0);\n"
3220 " else if (u_layer == 5)\n"
3221 " fragColor = textureLod(u_sampler, vec3(-facepos.x, -facepos.y, -1.0), 0.0);\n"
3223 " fragColor = vec4(1.0, 0.0, 1.0, 1.0);\n";
3227 case TARGET_2D_ARRAY:
3228 case TARGET_2D_MS_ARRAY:
3229 buf << " highp ivec2 screenpos = ivec2(floor(gl_FragCoord.xy));\n"
3230 " fragColor = texelFetch(u_sampler, ivec3(screenpos, u_layer), 0);\n";
3233 case TARGET_1D_ARRAY:
3234 buf << " highp ivec2 screenpos = ivec2(floor(gl_FragCoord.xy));\n"
3235 " fragColor = texelFetch(u_sampler, ivec2(screenpos.x, u_layer), 0);\n";
3239 DE_ASSERT(DE_FALSE);
3245 void LayeredRenderCase::renderToTexture (void)
3247 const tcu::IVec3 texSize = getTargetDimensions(m_target);
3248 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3249 glu::VertexArray vao (m_context.getRenderContext());
3251 m_testCtx.getLog() << tcu::TestLog::Message << "Rendering to texture" << tcu::TestLog::EndMessage;
3253 gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
3254 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3255 gl.clear(GL_COLOR_BUFFER_BIT);
3256 gl.viewport(0, 0, texSize.x(), texSize.y());
3257 gl.clear(GL_COLOR_BUFFER_BIT);
3259 gl.bindVertexArray(*vao);
3260 gl.useProgram(m_renderShader->getProgram());
3261 gl.drawArrays(GL_POINTS, 0, 1);
3263 gl.bindVertexArray(0);
3264 gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
3266 GLU_EXPECT_NO_ERROR(gl.getError(), "render");
3269 void LayeredRenderCase::sampleTextureLayer (tcu::Surface& dst, int layer)
3271 DE_ASSERT(dst.getWidth() == m_resolveDimensions.x());
3272 DE_ASSERT(dst.getHeight() == m_resolveDimensions.y());
3274 static const tcu::Vec4 fullscreenQuad[4] =
3276 tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
3277 tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
3278 tcu::Vec4( 1.0f, -1.0f, 0.0f, 1.0f),
3279 tcu::Vec4( 1.0f, 1.0f, 0.0f, 1.0f),
3282 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3283 const int positionLoc = gl.getAttribLocation(m_samplerShader->getProgram(), "a_position");
3284 glu::VertexArray vao (m_context.getRenderContext());
3285 glu::Buffer buf (m_context.getRenderContext());
3287 m_testCtx.getLog() << tcu::TestLog::Message << "Sampling from texture layer " << layer << tcu::TestLog::EndMessage;
3289 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3290 gl.clear(GL_COLOR_BUFFER_BIT);
3291 gl.viewport(0, 0, m_resolveDimensions.x(), m_resolveDimensions.y());
3292 GLU_EXPECT_NO_ERROR(gl.getError(), "clear");
3294 gl.bindBuffer(GL_ARRAY_BUFFER, *buf);
3295 gl.bufferData(GL_ARRAY_BUFFER, sizeof(fullscreenQuad), fullscreenQuad, GL_STATIC_DRAW);
3296 GLU_EXPECT_NO_ERROR(gl.getError(), "buf");
3298 gl.bindVertexArray(*vao);
3299 gl.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
3300 gl.enableVertexAttribArray(positionLoc);
3301 GLU_EXPECT_NO_ERROR(gl.getError(), "setup attribs");
3303 gl.activeTexture(GL_TEXTURE0);
3304 gl.bindTexture(getTargetTextureTarget(m_target), m_texture);
3305 GLU_EXPECT_NO_ERROR(gl.getError(), "bind texture");
3307 gl.useProgram(m_samplerShader->getProgram());
3308 gl.uniform1i(m_samplerLayerLoc, layer);
3309 gl.uniform1i(m_samplerSamplerLoc, 0);
3310 GLU_EXPECT_NO_ERROR(gl.getError(), "setup program");
3312 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
3313 GLU_EXPECT_NO_ERROR(gl.getError(), "draw");
3316 gl.bindVertexArray(0);
3317 GLU_EXPECT_NO_ERROR(gl.getError(), "clean");
3319 glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
3322 bool LayeredRenderCase::verifyLayerContent (const tcu::Surface& layer, int layerNdx)
3324 const tcu::Vec4 white = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
3325 const tcu::Vec4 red = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f);
3326 const tcu::Vec4 green = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f);
3327 const tcu::Vec4 blue = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f);
3328 const tcu::Vec4 yellow = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
3329 const tcu::Vec4 magenta = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
3330 const tcu::Vec4 colors[6] = { white, red, green, blue, yellow, magenta };
3332 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying layer contents" << tcu::TestLog::EndMessage;
3336 case TEST_DEFAULT_LAYER:
3338 return verifyImageSingleColoredRow(layer, 0.5f, white);
3340 return verifyEmptyImage(layer);
3342 case TEST_SINGLE_LAYER:
3343 if (layerNdx == m_targetLayer)
3344 return verifyImageSingleColoredRow(layer, 0.5f, white);
3346 return verifyEmptyImage(layer);
3348 case TEST_ALL_LAYERS:
3349 case TEST_INVOCATION_PER_LAYER:
3350 return verifyImageSingleColoredRow(layer, 0.5f, colors[layerNdx]);
3352 case TEST_DIFFERENT_LAYERS:
3353 case TEST_MULTIPLE_LAYERS_PER_INVOCATION:
3355 return verifyEmptyImage(layer);
3357 return verifyImageSingleColoredRow(layer, (float)layerNdx / (float)m_numLayers, white);
3361 const tcu::Vec4 layerColor((layerNdx % 2 == 1) ? (1.0f) : (0.5f),
3362 ((layerNdx/2) % 2 == 1) ? (1.0f) : (0.5f),
3363 (layerNdx == 0) ? (1.0f) : (0.0f),
3365 return verifyImageSingleColoredRow(layer, 0.5f, layerColor);
3368 case TEST_LAYER_PROVOKING_VERTEX:
3369 if (m_provokingVertex == GL_FIRST_VERTEX_CONVENTION)
3372 return verifyImageSingleColoredRow(layer, 0.5f, white);
3374 return verifyEmptyImage(layer);
3376 else if (m_provokingVertex == GL_LAST_VERTEX_CONVENTION)
3379 return verifyImageSingleColoredRow(layer, 0.5f, white);
3381 return verifyEmptyImage(layer);
3390 DE_ASSERT(DE_FALSE);
3395 bool LayeredRenderCase::verifyImageSingleColoredRow (const tcu::Surface& layer, float rowWidthRatio, const tcu::Vec4& barColor, bool logging)
3397 DE_ASSERT(rowWidthRatio > 0.0f);
3399 const int barLength = (int)(rowWidthRatio * (float)layer.getWidth());
3400 const int barLengthThreshold = 1;
3401 tcu::Surface errorMask (layer.getWidth(), layer.getHeight());
3402 bool allPixelsOk = true;
3405 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;
3407 tcu::clear(errorMask.getAccess(), tcu::RGBA::green().toIVec());
3409 for (int y = 0; y < layer.getHeight(); ++y)
3410 for (int x = 0; x < layer.getWidth(); ++x)
3412 const tcu::RGBA color = layer.getPixel(x, y);
3413 const tcu::RGBA refColor = tcu::RGBA(barColor);
3414 const int threshold = 8;
3415 const bool isBlack = color.getRed() <= threshold || color.getGreen() <= threshold || color.getBlue() <= threshold;
3416 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));
3420 if (x <= barLength - barLengthThreshold)
3422 else if (x >= barLength + barLengthThreshold)
3425 isOk = isColor || isBlack;
3427 allPixelsOk &= isOk;
3430 errorMask.setPixel(x, y, tcu::RGBA::red());
3436 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid." << tcu::TestLog::EndMessage
3437 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3438 << tcu::TestLog::Image("Layer", "Layer", layer)
3439 << tcu::TestLog::EndImageSet;
3445 m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed. Got unexpected pixels." << tcu::TestLog::EndMessage
3446 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3447 << tcu::TestLog::Image("Layer", "Layer", layer)
3448 << tcu::TestLog::Image("ErrorMask", "Errors", errorMask)
3449 << tcu::TestLog::EndImageSet;
3454 m_testCtx.getLog() << tcu::TestLog::Image("LayerContent", "Layer content", layer);
3459 bool LayeredRenderCase::verifyEmptyImage (const tcu::Surface& layer, bool logging)
3463 m_testCtx.getLog() << tcu::TestLog::Message << "Expecting empty image" << tcu::TestLog::EndMessage;
3465 for (int y = 0; y < layer.getHeight(); ++y)
3466 for (int x = 0; x < layer.getWidth(); ++x)
3468 const tcu::RGBA color = layer.getPixel(x, y);
3469 const int threshold = 8;
3470 const bool isBlack = color.getRed() <= threshold || color.getGreen() <= threshold || color.getBlue() <= threshold;
3475 m_testCtx.getLog() << tcu::TestLog::Message
3476 << "Found (at least) one bad pixel at " << x << "," << y << ". Pixel color is not background color."
3477 << tcu::TestLog::EndMessage
3478 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3479 << tcu::TestLog::Image("Layer", "Layer", layer)
3480 << tcu::TestLog::EndImageSet;
3486 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid" << tcu::TestLog::EndMessage;
3491 bool LayeredRenderCase::verifyProvokingVertexLayers (const tcu::Surface& layer0, const tcu::Surface& layer1)
3493 const bool layer0Empty = verifyEmptyImage(layer0, false);
3494 const bool layer1Empty = verifyEmptyImage(layer1, false);
3497 // Both images could contain something if the quad triangles get assigned to different layers
3498 m_testCtx.getLog() << tcu::TestLog::Message << "Expecting non-empty layers, or non-empty layer." << tcu::TestLog::EndMessage;
3500 if (layer0Empty == true && layer1Empty == true)
3502 m_testCtx.getLog() << tcu::TestLog::Message << "Got empty images." << tcu::TestLog::EndMessage;
3506 // log images always
3508 << tcu::TestLog::ImageSet("LayerContent", "Layer content")
3509 << tcu::TestLog::Image("Layer", "Layer0", layer0)
3510 << tcu::TestLog::Image("Layer", "Layer1", layer1)
3511 << tcu::TestLog::EndImageSet;
3514 m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed." << tcu::TestLog::EndMessage;
3516 m_testCtx.getLog() << tcu::TestLog::Message << "Image is valid." << tcu::TestLog::EndMessage;
3521 int LayeredRenderCase::getTargetLayers (LayeredRenderTargetType target)
3525 case TARGET_CUBE: return 6;
3526 case TARGET_3D: return 4;
3527 case TARGET_1D_ARRAY: return 4;
3528 case TARGET_2D_ARRAY: return 4;
3529 case TARGET_2D_MS_ARRAY: return 2;
3531 DE_ASSERT(DE_FALSE);
3536 glw::GLenum LayeredRenderCase::getTargetTextureTarget (LayeredRenderTargetType target)
3540 case TARGET_CUBE: return GL_TEXTURE_CUBE_MAP;
3541 case TARGET_3D: return GL_TEXTURE_3D;
3542 case TARGET_1D_ARRAY: return GL_TEXTURE_1D_ARRAY;
3543 case TARGET_2D_ARRAY: return GL_TEXTURE_2D_ARRAY;
3544 case TARGET_2D_MS_ARRAY: return GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3546 DE_ASSERT(DE_FALSE);
3551 tcu::IVec3 LayeredRenderCase::getTargetDimensions (LayeredRenderTargetType target)
3555 case TARGET_CUBE: return tcu::IVec3(64, 64, 0);
3556 case TARGET_3D: return tcu::IVec3(64, 64, 4);
3557 case TARGET_1D_ARRAY: return tcu::IVec3(64, 4, 0);
3558 case TARGET_2D_ARRAY: return tcu::IVec3(64, 64, 4);
3559 case TARGET_2D_MS_ARRAY: return tcu::IVec3(64, 64, 2);
3561 DE_ASSERT(DE_FALSE);
3562 return tcu::IVec3(0, 0, 0);
3566 tcu::IVec2 LayeredRenderCase::getResolveDimensions (LayeredRenderTargetType target)
3570 case TARGET_CUBE: return tcu::IVec2(64, 64);
3571 case TARGET_3D: return tcu::IVec2(64, 64);
3572 case TARGET_1D_ARRAY: return tcu::IVec2(64, 1);
3573 case TARGET_2D_ARRAY: return tcu::IVec2(64, 64);
3574 case TARGET_2D_MS_ARRAY: return tcu::IVec2(64, 64);
3576 DE_ASSERT(DE_FALSE);
3577 return tcu::IVec2(0, 0);
3581 class VaryingOutputCountCase : public GeometryShaderRenderTest
3584 enum ShaderInstancingMode
3586 MODE_WITHOUT_INSTANCING = 0,
3587 MODE_WITH_INSTANCING,
3591 VaryingOutputCountCase (Context& context, const char* name, const char* desc, VaryingOutputCountShader::VaryingSource test, ShaderInstancingMode mode);
3595 void preRender (sglr::Context& ctx, GLuint programID);
3597 sglr::ShaderProgram& getProgram (void);
3598 void genVertexAttribData (void);
3599 void genVertexDataWithoutInstancing (void);
3600 void genVertexDataWithInstancing (void);
3602 VaryingOutputCountShader* m_program;
3603 const VaryingOutputCountShader::VaryingSource m_test;
3604 const ShaderInstancingMode m_mode;
3608 VaryingOutputCountCase::VaryingOutputCountCase (Context& context, const char* name, const char* desc, VaryingOutputCountShader::VaryingSource test, ShaderInstancingMode mode)
3609 : GeometryShaderRenderTest (context, name, desc, GL_POINTS, GL_TRIANGLE_STRIP, VaryingOutputCountShader::getAttributeName(test))
3610 , m_program (DE_NULL)
3613 , m_maxEmitCount (0)
3615 DE_ASSERT(mode < MODE_LAST);
3618 void VaryingOutputCountCase::init (void)
3620 // Check requirements
3622 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
3623 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
3625 if (m_test == VaryingOutputCountShader::READ_TEXTURE)
3627 glw::GLint maxTextures = 0;
3629 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &maxTextures);
3631 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS = " << maxTextures << tcu::TestLog::EndMessage;
3633 if (maxTextures < 1)
3634 throw tcu::NotSupportedError("Geometry shader texture units required");
3637 // Get max emit count
3639 const int componentsPerVertex = 4 + 4; // vec4 pos, vec4 color
3640 glw::GLint maxVertices = 0;
3641 glw::GLint maxComponents = 0;
3643 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxVertices);
3644 m_context.getRenderContext().getFunctions().getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
3646 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_OUTPUT_VERTICES = " << maxVertices << tcu::TestLog::EndMessage;
3647 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS = " << maxComponents << tcu::TestLog::EndMessage;
3648 m_testCtx.getLog() << tcu::TestLog::Message << "Components per vertex = " << componentsPerVertex << tcu::TestLog::EndMessage;
3650 if (maxVertices < 256)
3651 throw tcu::TestError("MAX_GEOMETRY_OUTPUT_VERTICES was less than minimum required (256)");
3652 if (maxComponents < 1024)
3653 throw tcu::TestError("MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS was less than minimum required (1024)");
3655 m_maxEmitCount = de::min(maxVertices, maxComponents / componentsPerVertex);
3658 // Log what the test tries to do
3661 << tcu::TestLog::Message
3662 << "Rendering 4 n-gons with n = "
3663 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_0 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0)) << ", "
3664 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_1 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1)) << ", "
3665 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_2 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2)) << ", and "
3666 << ((VaryingOutputCountShader::EMIT_COUNT_VERTEX_3 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3)) << ".\n"
3667 << "N is supplied to the geomery shader with "
3668 << ((m_test == VaryingOutputCountShader::READ_ATTRIBUTE) ? ("attribute") : (m_test == VaryingOutputCountShader::READ_UNIFORM) ? ("uniform") : ("texture"))
3669 << tcu::TestLog::EndMessage;
3673 const bool instanced = (m_mode == MODE_WITH_INSTANCING);
3675 DE_ASSERT(!m_program);
3676 m_program = new VaryingOutputCountShader(m_test, m_maxEmitCount, instanced);
3680 GeometryShaderRenderTest::init();
3683 void VaryingOutputCountCase::deinit (void)
3688 m_program = DE_NULL;
3691 GeometryShaderRenderTest::deinit();
3694 void VaryingOutputCountCase::preRender (sglr::Context& ctx, GLuint programID)
3696 if (m_test == VaryingOutputCountShader::READ_UNIFORM)
3698 const int location = ctx.getUniformLocation(programID, "u_emitCount");
3699 const deInt32 emitCount[4] = { 6, 0, m_maxEmitCount, 10 };
3702 throw tcu::TestError("uniform location of u_emitCount was -1.");
3704 ctx.uniform4iv(location, 1, emitCount);
3706 else if (m_test == VaryingOutputCountShader::READ_TEXTURE)
3708 const deUint8 data[4*4] =
3715 const int location = ctx.getUniformLocation(programID, "u_sampler");
3719 throw tcu::TestError("uniform location of u_sampler was -1.");
3720 ctx.uniform1i(location, 0);
3722 // \note we don't need to explicitly delete the texture, the sglr context will delete it
3723 ctx.genTextures(1, &texID);
3724 ctx.bindTexture(GL_TEXTURE_2D, texID);
3725 ctx.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
3726 ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3727 ctx.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3731 sglr::ShaderProgram& VaryingOutputCountCase::getProgram (void)
3736 void VaryingOutputCountCase::genVertexAttribData (void)
3738 if (m_mode == MODE_WITHOUT_INSTANCING)
3739 genVertexDataWithoutInstancing();
3740 else if (m_mode == MODE_WITH_INSTANCING)
3741 genVertexDataWithInstancing();
3746 void VaryingOutputCountCase::genVertexDataWithoutInstancing (void)
3748 m_numDrawVertices = 4;
3750 m_vertexPosData.resize(4);
3751 m_vertexAttrData.resize(4);
3753 m_vertexPosData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 1.0f);
3754 m_vertexPosData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 1.0f);
3755 m_vertexPosData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 1.0f);
3756 m_vertexPosData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 1.0f);
3758 if (m_test == VaryingOutputCountShader::READ_ATTRIBUTE)
3760 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);
3761 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);
3762 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);
3763 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);
3767 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
3768 m_vertexAttrData[1] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
3769 m_vertexAttrData[2] = tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f);
3770 m_vertexAttrData[3] = tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f);
3774 void VaryingOutputCountCase::genVertexDataWithInstancing (void)
3776 m_numDrawVertices = 1;
3778 m_vertexPosData.resize(1);
3779 m_vertexAttrData.resize(1);
3781 m_vertexPosData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
3783 if (m_test == VaryingOutputCountShader::READ_ATTRIBUTE)
3785 const int emitCounts[] =
3787 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_0),
3788 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_1),
3789 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_2),
3790 (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3 == -1) ? (m_maxEmitCount) : (VaryingOutputCountShader::EMIT_COUNT_VERTEX_3),
3793 m_vertexAttrData[0] = tcu::Vec4((float)emitCounts[0], (float)emitCounts[1], (float)emitCounts[2], (float)emitCounts[3]);
3798 m_vertexAttrData[0] = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
3802 class GeometryProgramQueryCase : public TestCase
3807 const char* description;
3812 GeometryProgramQueryCase (Context& context, const char* name, const char* description, glw::GLenum target);
3815 IterateResult iterate (void);
3818 void expectProgramValue (deUint32 program, int value);
3819 void expectQueryError (deUint32 program);
3821 const glw::GLenum m_target;
3824 std::vector<ProgramCase> m_cases;
3827 GeometryProgramQueryCase::GeometryProgramQueryCase (Context& context, const char* name, const char* description, glw::GLenum target)
3828 : TestCase (context, name, description)
3833 void GeometryProgramQueryCase::init (void)
3835 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
3836 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
3839 GeometryProgramQueryCase::IterateResult GeometryProgramQueryCase::iterate (void)
3841 static const char* const s_vertexSource = "#version 310 es\n"
3844 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
3846 static const char* const s_fragmentSource = "#version 310 es\n"
3847 "layout(location = 0) out mediump vec4 fragColor;\n"
3850 " fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
3852 static const char* const s_geometryBody = "void main ()\n"
3854 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
3858 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3861 for (int ndx = 0; ndx < (int)m_cases.size(); ++ndx)
3863 const tcu::ScopedLogSection section (m_testCtx.getLog(), "Case", m_cases[ndx].description);
3864 const std::string geometrySource = m_cases[ndx].header + std::string(s_geometryBody);
3865 const glu::ShaderProgram program (m_context.getRenderContext(),
3866 glu::ProgramSources()
3867 << glu::VertexSource(s_vertexSource)
3868 << glu::FragmentSource(s_fragmentSource)
3869 << glu::GeometrySource(geometrySource));
3871 m_testCtx.getLog() << program;
3872 expectProgramValue(program.getProgram(), m_cases[ndx].value);
3875 // no geometry shader -case (INVALID OP)
3877 const tcu::ScopedLogSection section (m_testCtx.getLog(), "NoGeometryShader", "No geometry shader");
3878 const glu::ShaderProgram program (m_context.getRenderContext(),
3879 glu::ProgramSources()
3880 << glu::VertexSource(s_vertexSource)
3881 << glu::FragmentSource(s_fragmentSource));
3883 m_testCtx.getLog() << program;
3884 expectQueryError(program.getProgram());
3887 // not linked -case (INVALID OP)
3889 const tcu::ScopedLogSection section (m_testCtx.getLog(), "NotLinkedProgram", "Shader program not linked");
3890 const std::string geometrySource = "#version 310 es\n"
3891 "#extension GL_EXT_geometry_shader : require\n"
3892 "layout (triangles) in;\n"
3893 "layout (points, max_vertices = 3) out;\n"
3894 + std::string(s_geometryBody);
3897 glu::Shader vertexShader (m_context.getRenderContext(), glu::SHADERTYPE_VERTEX);
3898 glu::Shader fragmentShader (m_context.getRenderContext(), glu::SHADERTYPE_FRAGMENT);
3899 glu::Shader geometryShader (m_context.getRenderContext(), glu::SHADERTYPE_GEOMETRY);
3900 glu::Program program (m_context.getRenderContext());
3902 const char* const geometrySourceArray[1] = { geometrySource.c_str() };
3904 vertexShader.setSources(1, &s_vertexSource, DE_NULL);
3905 fragmentShader.setSources(1, &s_fragmentSource, DE_NULL);
3906 geometryShader.setSources(1, geometrySourceArray, DE_NULL);
3908 vertexShader.compile();
3909 fragmentShader.compile();
3910 geometryShader.compile();
3912 if (!vertexShader.getCompileStatus() ||
3913 !fragmentShader.getCompileStatus() ||
3914 !geometryShader.getCompileStatus())
3915 throw tcu::TestError("Failed to compile shader");
3917 program.attachShader(vertexShader.getShader());
3918 program.attachShader(fragmentShader.getShader());
3919 program.attachShader(geometryShader.getShader());
3921 m_testCtx.getLog() << tcu::TestLog::Message << "Creating a program with geometry shader, but not linking it" << tcu::TestLog::EndMessage;
3923 expectQueryError(program.getProgram());
3929 void GeometryProgramQueryCase::expectProgramValue (deUint32 program, int value)
3931 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3932 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
3934 gl.getProgramiv(program, m_target, &state);
3935 GLU_EXPECT_NO_ERROR(gl.getError(), "getProgramiv");
3937 m_testCtx.getLog() << tcu::TestLog::Message << glu::getProgramParamStr(m_target) << " = " << state << tcu::TestLog::EndMessage;
3941 m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: Expected " << value << ", got " << state << tcu::TestLog::EndMessage;
3943 // don't overwrite error
3944 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
3945 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
3949 void GeometryProgramQueryCase::expectQueryError (deUint32 program)
3951 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
3953 glw::GLenum errorCode;
3955 m_testCtx.getLog() << tcu::TestLog::Message << "Querying " << glu::getProgramParamStr(m_target) << ", expecting INVALID_OPERATION" << tcu::TestLog::EndMessage;
3956 gl.getProgramiv(program, m_target, &dummy);
3958 errorCode = gl.getError();
3960 if (errorCode != GL_INVALID_OPERATION)
3962 m_testCtx.getLog() << tcu::TestLog::Message << "// ERROR: Expected INVALID_OPERATION, got " << glu::getErrorStr(errorCode) << tcu::TestLog::EndMessage;
3964 // don't overwrite error
3965 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
3966 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected error code");
3970 class GeometryShaderInvocationsQueryCase : public GeometryProgramQueryCase
3973 GeometryShaderInvocationsQueryCase(Context& context, const char* name, const char* description);
3976 GeometryShaderInvocationsQueryCase::GeometryShaderInvocationsQueryCase(Context& context, const char* name, const char* description)
3977 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_SHADER_INVOCATIONS)
3982 m_cases[0].description = "Default value";
3983 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
3984 m_cases[0].value = 1;
3986 m_cases[1].description = "Value declared";
3987 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";
3988 m_cases[1].value = 2;
3991 class GeometryShaderVerticesQueryCase : public GeometryProgramQueryCase
3994 GeometryShaderVerticesQueryCase(Context& context, const char* name, const char* description);
3997 GeometryShaderVerticesQueryCase::GeometryShaderVerticesQueryCase(Context& context, const char* name, const char* description)
3998 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_VERTICES_OUT_EXT)
4002 m_cases[0].description = "max_vertices = 1";
4003 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 1) out;\n";
4004 m_cases[0].value = 1;
4007 class GeometryShaderInputQueryCase : public GeometryProgramQueryCase
4010 GeometryShaderInputQueryCase(Context& context, const char* name, const char* description);
4013 GeometryShaderInputQueryCase::GeometryShaderInputQueryCase(Context& context, const char* name, const char* description)
4014 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_INPUT_TYPE_EXT)
4018 m_cases[0].description = "Triangles";
4019 m_cases[0].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
4020 m_cases[0].value = GL_TRIANGLES;
4022 m_cases[1].description = "Lines";
4023 m_cases[1].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (lines) in;\nlayout (points, max_vertices = 3) out;\n";
4024 m_cases[1].value = GL_LINES;
4026 m_cases[2].description = "Points";
4027 m_cases[2].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (points) in;\nlayout (points, max_vertices = 3) out;\n";
4028 m_cases[2].value = GL_POINTS;
4031 class GeometryShaderOutputQueryCase : public GeometryProgramQueryCase
4034 GeometryShaderOutputQueryCase(Context& context, const char* name, const char* description);
4037 GeometryShaderOutputQueryCase::GeometryShaderOutputQueryCase(Context& context, const char* name, const char* description)
4038 : GeometryProgramQueryCase(context, name, description, GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT)
4042 m_cases[0].description = "Triangle strip";
4043 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";
4044 m_cases[0].value = GL_TRIANGLE_STRIP;
4046 m_cases[1].description = "Lines";
4047 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";
4048 m_cases[1].value = GL_LINE_STRIP;
4050 m_cases[2].description = "Points";
4051 m_cases[2].header = "#version 310 es\n#extension GL_EXT_geometry_shader : require\nlayout (triangles) in;\nlayout (points, max_vertices = 3) out;\n";
4052 m_cases[2].value = GL_POINTS;
4055 class ImplementationLimitCase : public TestCase
4058 ImplementationLimitCase (Context& context, const char* name, const char* description, glw::GLenum target, int minValue);
4061 IterateResult iterate (void);
4063 const glw::GLenum m_target;
4064 const int m_minValue;
4067 ImplementationLimitCase::ImplementationLimitCase (Context& context, const char* name, const char* description, glw::GLenum target, int minValue)
4068 : TestCase (context, name, description)
4070 , m_minValue (minValue)
4074 void ImplementationLimitCase::init (void)
4076 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4077 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4080 ImplementationLimitCase::IterateResult ImplementationLimitCase::iterate (void)
4082 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4083 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4085 gl.enableLogging(true);
4086 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER);
4089 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4090 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_BOOLEAN);
4091 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER64);
4092 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_FLOAT);
4095 result.setTestContextResult(m_testCtx);
4099 class LayerProvokingVertexQueryCase : public TestCase
4102 LayerProvokingVertexQueryCase (Context& context, const char* name, const char* description);
4105 IterateResult iterate (void);
4108 LayerProvokingVertexQueryCase::LayerProvokingVertexQueryCase(Context& context, const char* name, const char* description)
4109 : TestCase(context, name, description)
4113 void LayerProvokingVertexQueryCase::init (void)
4115 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4116 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4119 LayerProvokingVertexQueryCase::IterateResult LayerProvokingVertexQueryCase::iterate (void)
4121 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4122 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4125 gl.enableLogging(true);
4126 queryState(result, gl, QUERY_INTEGER, GL_LAYER_PROVOKING_VERTEX, state);
4128 if (!state.isUndefined())
4130 m_testCtx.getLog() << tcu::TestLog::Message << "LAYER_PROVOKING_VERTEX = " << glu::getProvokingVertexStr(state.getIntAccess()) << tcu::TestLog::EndMessage;
4132 if (state.getIntAccess() != GL_FIRST_VERTEX_CONVENTION &&
4133 state.getIntAccess() != GL_LAST_VERTEX_CONVENTION &&
4134 state.getIntAccess() != GL_UNDEFINED_VERTEX)
4137 << tcu::TestLog::Message
4138 << "getInteger(GL_LAYER_PROVOKING_VERTEX) returned illegal value. Got "
4139 << state.getIntAccess() << "\n"
4140 << "Expected any of {FIRST_VERTEX_CONVENTION, LAST_VERTEX_CONVENTION, UNDEFINED_VERTEX}."
4141 << tcu::TestLog::EndMessage;
4143 result.fail("got unexpected provoking vertex value");
4147 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4148 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_BOOLEAN);
4149 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_INTEGER64);
4150 verifyStateInteger(result, gl, GL_LAYER_PROVOKING_VERTEX, state.getIntAccess(), QUERY_FLOAT);
4154 result.setTestContextResult(m_testCtx);
4158 class GeometryInvocationCase : public GeometryShaderRenderTest
4163 CASE_FIXED_OUTPUT_COUNTS = 0,
4164 CASE_DIFFERENT_OUTPUT_COUNTS,
4169 GeometryInvocationCase (Context& context, const char* name, const char* description, int numInvocations, OutputCase testCase);
4170 ~GeometryInvocationCase (void);
4176 sglr::ShaderProgram& getProgram (void);
4177 void genVertexAttribData (void);
4179 static InvocationCountShader::OutputCase mapToShaderCaseType (OutputCase testCase);
4181 const OutputCase m_testCase;
4182 int m_numInvocations;
4183 InvocationCountShader* m_program;
4186 GeometryInvocationCase::GeometryInvocationCase (Context& context, const char* name, const char* description, int numInvocations, OutputCase testCase)
4187 : GeometryShaderRenderTest (context, name, description, GL_POINTS, GL_TRIANGLE_STRIP, "a_color")
4188 , m_testCase (testCase)
4189 , m_numInvocations (numInvocations)
4190 , m_program (DE_NULL)
4192 DE_ASSERT(m_testCase < CASE_LAST);
4195 GeometryInvocationCase::~GeometryInvocationCase (void)
4200 void GeometryInvocationCase::init (void)
4202 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4203 int maxGeometryShaderInvocations = 0;
4204 int maxComponents = 0;
4208 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4209 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4211 gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_INVOCATIONS, &maxGeometryShaderInvocations);
4212 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv(GL_MAX_GEOMETRY_SHADER_INVOCATIONS)");
4214 gl.getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, &maxComponents);
4215 GLU_EXPECT_NO_ERROR(gl.getError(), "getIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS)");
4217 m_testCtx.getLog() << tcu::TestLog::Message << "GL_MAX_GEOMETRY_SHADER_INVOCATIONS = " << maxGeometryShaderInvocations << tcu::TestLog::EndMessage;
4219 // set target num invocations
4221 if (m_numInvocations == -1)
4222 m_numInvocations = maxGeometryShaderInvocations;
4223 else if (maxGeometryShaderInvocations < m_numInvocations)
4224 throw tcu::NotSupportedError("Test requires larger GL_MAX_GEOMETRY_SHADER_INVOCATIONS");
4226 if (m_testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
4228 const int maxEmitCount = m_numInvocations + 2;
4229 const int numComponents = 8; // pos + color
4230 if (maxEmitCount * numComponents > maxComponents)
4231 throw tcu::NotSupportedError("Test requires larger GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS");
4234 // Log what the test tries to do
4236 if (m_testCase == CASE_FIXED_OUTPUT_COUNTS)
4239 << tcu::TestLog::Message
4240 << "Rendering triangles in a partial circle formation with a geometry shader. Each triangle is generated by a separate invocation.\n"
4241 << "Drawing 2 points, each generating " << m_numInvocations << " triangles."
4242 << tcu::TestLog::EndMessage;
4244 else if (m_testCase == CASE_DIFFERENT_OUTPUT_COUNTS)
4247 << tcu::TestLog::Message
4248 << "Rendering n-gons in a partial circle formation with a geometry shader. Each n-gon is generated by a separate invocation.\n"
4249 << "Drawing 2 points, each generating " << m_numInvocations << " n-gons."
4250 << tcu::TestLog::EndMessage;
4257 m_program = new InvocationCountShader(m_numInvocations, mapToShaderCaseType(m_testCase));
4259 GeometryShaderRenderTest::init();
4262 void GeometryInvocationCase::deinit (void)
4267 m_program = DE_NULL;
4270 GeometryShaderRenderTest::deinit();
4273 sglr::ShaderProgram& GeometryInvocationCase::getProgram (void)
4278 void GeometryInvocationCase::genVertexAttribData (void)
4280 m_vertexPosData.resize(2);
4281 m_vertexPosData[0] = tcu::Vec4(0.0f,-0.3f, 0.0f, 1.0f);
4282 m_vertexPosData[1] = tcu::Vec4(0.2f, 0.3f, 0.0f, 1.0f);
4284 m_vertexAttrData.resize(2);
4285 m_vertexAttrData[0] = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
4286 m_vertexAttrData[1] = tcu::Vec4(0.8f, 0.8f, 0.8f, 1.0f);
4287 m_numDrawVertices = 2;
4290 InvocationCountShader::OutputCase GeometryInvocationCase::mapToShaderCaseType (OutputCase testCase)
4294 case CASE_FIXED_OUTPUT_COUNTS: return InvocationCountShader::CASE_FIXED_OUTPUT_COUNTS;
4295 case CASE_DIFFERENT_OUTPUT_COUNTS: return InvocationCountShader::CASE_DIFFERENT_OUTPUT_COUNTS;
4298 return InvocationCountShader::CASE_LAST;
4302 class DrawInstancedGeometryInstancedCase : public GeometryShaderRenderTest
4305 DrawInstancedGeometryInstancedCase (Context& context, const char* name, const char* description, int numInstances, int numInvocations);
4306 ~DrawInstancedGeometryInstancedCase (void);
4310 sglr::ShaderProgram& getProgram (void);
4311 void genVertexAttribData (void);
4313 const int m_numInstances;
4314 const int m_numInvocations;
4315 InstancedExpansionShader m_program;
4318 DrawInstancedGeometryInstancedCase::DrawInstancedGeometryInstancedCase (Context& context, const char* name, const char* description, int numInstances, int numInvocations)
4319 : GeometryShaderRenderTest (context, name, description, GL_POINTS, GL_TRIANGLE_STRIP, "a_offset", FLAG_DRAW_INSTANCED)
4320 , m_numInstances (numInstances)
4321 , m_numInvocations (numInvocations)
4322 , m_program (numInvocations)
4326 DrawInstancedGeometryInstancedCase::~DrawInstancedGeometryInstancedCase (void)
4330 void DrawInstancedGeometryInstancedCase::init (void)
4333 << tcu::TestLog::Message
4334 << "Rendering a single point with " << m_numInstances << " instances. "
4335 << "Each geometry shader is invoked " << m_numInvocations << " times for each primitive. "
4336 << tcu::TestLog::EndMessage;
4338 GeometryShaderRenderTest::init();
4341 sglr::ShaderProgram& DrawInstancedGeometryInstancedCase::getProgram (void)
4346 void DrawInstancedGeometryInstancedCase::genVertexAttribData (void)
4348 m_numDrawVertices = 1;
4349 m_numDrawInstances = m_numInstances;
4350 m_vertexAttrDivisor = 1;
4352 m_vertexPosData.resize(1);
4353 m_vertexAttrData.resize(8);
4355 m_vertexPosData[0] = tcu::Vec4( 0.0f, 0.0f, 0.0f, 1.0f);
4357 m_vertexAttrData[0] = tcu::Vec4( 0.5f, 0.0f, 0.0f, 0.0f);
4358 m_vertexAttrData[1] = tcu::Vec4( 0.0f, 0.5f, 0.0f, 0.0f);
4359 m_vertexAttrData[2] = tcu::Vec4(-0.7f, -0.1f, 0.0f, 0.0f);
4360 m_vertexAttrData[3] = tcu::Vec4(-0.1f, -0.7f, 0.0f, 0.0f);
4361 m_vertexAttrData[4] = tcu::Vec4(-0.8f, -0.7f, 0.0f, 0.0f);
4362 m_vertexAttrData[5] = tcu::Vec4(-0.9f, 0.6f, 0.0f, 0.0f);
4363 m_vertexAttrData[6] = tcu::Vec4(-0.8f, 0.3f, 0.0f, 0.0f);
4364 m_vertexAttrData[7] = tcu::Vec4(-0.1f, 0.1f, 0.0f, 0.0f);
4366 DE_ASSERT(m_numInstances <= (int)m_vertexAttrData.size());
4369 class GeometryProgramLimitCase : public TestCase
4372 GeometryProgramLimitCase (Context& context, const char* name, const char* description, glw::GLenum apiName, const std::string& glslName, int limit);
4376 IterateResult iterate (void);
4378 const glw::GLenum m_apiName;
4379 const std::string m_glslName;
4383 GeometryProgramLimitCase::GeometryProgramLimitCase (Context& context, const char* name, const char* description, glw::GLenum apiName, const std::string& glslName, int limit)
4384 : TestCase (context, name, description)
4385 , m_apiName (apiName)
4386 , m_glslName (glslName)
4391 void GeometryProgramLimitCase::init (void)
4393 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4394 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4397 GeometryProgramLimitCase::IterateResult GeometryProgramLimitCase::iterate (void)
4399 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4404 gls::StateQueryUtil::StateQueryMemoryWriteGuard<glw::GLint> state;
4405 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4407 gl.enableLogging(true);
4408 gl.glGetIntegerv(m_apiName, &state);
4409 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getIntegerv()");
4411 m_testCtx.getLog() << tcu::TestLog::Message << glu::getGettableStateStr(m_apiName) << " = " << state << tcu::TestLog::EndMessage;
4413 if (!state.verifyValidity(result))
4415 result.setTestContextResult(m_testCtx);
4419 if (state < m_limit)
4421 result.fail("Minimum value = " + de::toString(m_limit) + ", got " + de::toString(state.get()));
4422 result.setTestContextResult(m_testCtx);
4428 // verify other getters
4430 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
4431 verifyStateInteger(result, gl, m_apiName, limit, QUERY_BOOLEAN);
4432 verifyStateInteger(result, gl, m_apiName, limit, QUERY_INTEGER64);
4433 verifyStateInteger(result, gl, m_apiName, limit, QUERY_FLOAT);
4437 // verify limit is the same in GLSL
4439 static const char* const vertexSource = "#version 310 es\n"
4442 " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);\n"
4444 static const char* const fragmentSource = "#version 310 es\n"
4445 "layout(location = 0) out mediump vec4 fragColor;\n"
4448 " fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n"
4450 const std::string geometrySource = "#version 310 es\n"
4451 "#extension GL_EXT_geometry_shader : require\n"
4452 "layout(points) in;\n"
4453 "layout(points, max_vertices = 1) out;\n"
4456 " // Building the shader will fail if the constant value is not the expected\n"
4457 " const mediump int cArraySize = (gl_" + m_glslName + " == " + de::toString(limit) + ") ? (1) : (-1);\n"
4458 " float[cArraySize] fArray;\n"
4459 " fArray[0] = 0.0f;\n"
4460 " gl_Position = vec4(0.0, 0.0, 0.0, fArray[0]);\n"
4464 const de::UniquePtr<glu::ShaderProgram> program(new glu::ShaderProgram(m_context.getRenderContext(),
4465 glu::ProgramSources()
4466 << glu::VertexSource(vertexSource)
4467 << glu::FragmentSource(fragmentSource)
4468 << glu::GeometrySource(geometrySource)));
4470 m_testCtx.getLog() << tcu::TestLog::Message << "Building a test shader to verify GLSL constant " << m_glslName << " value." << tcu::TestLog::EndMessage;
4471 m_testCtx.getLog() << *program;
4473 if (!program->isOk())
4475 // compile failed, assume static assert failed
4476 result.fail("Shader build failed");
4477 result.setTestContextResult(m_testCtx);
4481 m_testCtx.getLog() << tcu::TestLog::Message << "Build ok" << tcu::TestLog::EndMessage;
4484 result.setTestContextResult(m_testCtx);
4488 class PrimitivesGeneratedQueryCase : public TestCase
4493 TEST_NO_GEOMETRY = 0,
4494 TEST_NO_AMPLIFICATION,
4496 TEST_PARTIAL_PRIMITIVES,
4502 PrimitivesGeneratedQueryCase (Context& context, const char* name, const char* description, QueryTest test);
4503 ~PrimitivesGeneratedQueryCase (void);
4508 IterateResult iterate (void);
4510 glu::ShaderProgram* genProgram (void);
4512 const QueryTest m_test;
4513 glu::ShaderProgram* m_program;
4516 PrimitivesGeneratedQueryCase::PrimitivesGeneratedQueryCase (Context& context, const char* name, const char* description, QueryTest test)
4517 : TestCase (context, name, description)
4519 , m_program (DE_NULL)
4521 DE_ASSERT(m_test < TEST_LAST);
4524 PrimitivesGeneratedQueryCase::~PrimitivesGeneratedQueryCase (void)
4529 void PrimitivesGeneratedQueryCase::init (void)
4533 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4534 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4536 // log what test tries to do
4538 if (m_test == TEST_NO_GEOMETRY)
4539 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering without a geometry shader." << tcu::TestLog::EndMessage;
4540 else if (m_test == TEST_NO_AMPLIFICATION)
4541 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a non-amplifying geometry shader." << tcu::TestLog::EndMessage;
4542 else if (m_test == TEST_AMPLIFICATION)
4543 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a (3x) amplifying geometry shader." << tcu::TestLog::EndMessage;
4544 else if (m_test == TEST_PARTIAL_PRIMITIVES)
4545 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a geometry shader that emits also partial primitives." << tcu::TestLog::EndMessage;
4546 else if (m_test == TEST_INSTANCED)
4547 m_testCtx.getLog() << tcu::TestLog::Message << "Querying PRIMITIVES_GENERATED while rendering with a instanced geometry shader." << tcu::TestLog::EndMessage;
4553 m_program = genProgram();
4554 m_testCtx.getLog() << *m_program;
4556 if (!m_program->isOk())
4557 throw tcu::TestError("could not build program");
4560 void PrimitivesGeneratedQueryCase::deinit (void)
4563 m_program = DE_NULL;
4566 PrimitivesGeneratedQueryCase::IterateResult PrimitivesGeneratedQueryCase::iterate (void)
4568 glw::GLuint primitivesGenerated = 0xDEBADBAD;
4571 << tcu::TestLog::Message
4572 << "Drawing 8 points, setting a_one for each to value (1.0, 1.0, 1.0, 1.0)"
4573 << tcu::TestLog::EndMessage;
4576 static const tcu::Vec4 vertexData[8*2] =
4578 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4579 tcu::Vec4(0.1f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4580 tcu::Vec4(0.2f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4581 tcu::Vec4(0.3f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4582 tcu::Vec4(0.4f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4583 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4584 tcu::Vec4(0.6f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4585 tcu::Vec4(0.7f, 0.0f, 0.0f, 1.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
4588 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
4589 const glu::VertexArray vao (m_context.getRenderContext());
4590 const glu::Buffer buffer (m_context.getRenderContext());
4591 const glu::Query query (m_context.getRenderContext());
4592 const int positionLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
4593 const int oneLocation = gl.getAttribLocation(m_program->getProgram(), "a_one");
4595 gl.bindVertexArray(*vao);
4597 gl.bindBuffer(GL_ARRAY_BUFFER, *buffer);
4598 gl.bufferData(GL_ARRAY_BUFFER, (int)sizeof(vertexData), vertexData, GL_STATIC_DRAW);
4600 gl.vertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 2 * (int)sizeof(tcu::Vec4), DE_NULL);
4601 gl.enableVertexAttribArray(positionLocation);
4603 if (oneLocation != -1)
4605 gl.vertexAttribPointer(oneLocation, 4, GL_FLOAT, GL_FALSE, 2 * (int)sizeof(tcu::Vec4), (const tcu::Vec4*)DE_NULL + 1);
4606 gl.enableVertexAttribArray(oneLocation);
4609 gl.useProgram(m_program->getProgram());
4611 GLU_EXPECT_NO_ERROR(gl.getError(), "setup render");
4613 gl.beginQuery(GL_PRIMITIVES_GENERATED, *query);
4614 gl.drawArrays(GL_POINTS, 0, 8);
4615 gl.endQuery(GL_PRIMITIVES_GENERATED);
4617 GLU_EXPECT_NO_ERROR(gl.getError(), "render and query");
4619 gl.getQueryObjectuiv(*query, GL_QUERY_RESULT, &primitivesGenerated);
4620 GLU_EXPECT_NO_ERROR(gl.getError(), "get query result");
4624 << tcu::TestLog::Message
4625 << "GL_PRIMITIVES_GENERATED = " << primitivesGenerated
4626 << tcu::TestLog::EndMessage;
4629 const deUint32 expectedGenerated = (m_test == TEST_AMPLIFICATION) ? (3*8) : (m_test == TEST_INSTANCED) ? (8*(3+1)) : (8);
4631 if (expectedGenerated == primitivesGenerated)
4632 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4635 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got wrong result for GL_PRIMITIVES_GENERATED");
4637 << tcu::TestLog::Message
4638 << "Got unexpected result for GL_PRIMITIVES_GENERATED. Expected " << expectedGenerated << ", got " << primitivesGenerated
4639 << tcu::TestLog::EndMessage;
4646 glu::ShaderProgram* PrimitivesGeneratedQueryCase::genProgram (void)
4648 static const char* const vertexSource = "#version 310 es\n"
4649 "in highp vec4 a_position;\n"
4650 "in highp vec4 a_one;\n"
4651 "out highp vec4 v_one;\n"
4652 "void main (void)\n"
4654 " gl_Position = a_position;\n"
4657 static const char* const fragmentSource = "#version 310 es\n"
4658 "layout(location = 0) out mediump vec4 fragColor;\n"
4659 "void main (void)\n"
4661 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
4663 std::ostringstream geometrySource;
4664 glu::ProgramSources sources;
4666 if (m_test != TEST_NO_GEOMETRY)
4668 geometrySource << "#version 310 es\n"
4669 "#extension GL_EXT_geometry_shader : require\n"
4670 "layout(points" << ((m_test == TEST_INSTANCED) ? (", invocations = 3") : ("")) << ") in;\n"
4671 "layout(triangle_strip, max_vertices = 7) out;\n"
4672 "in highp vec4 v_one[];\n"
4673 "void main (void)\n"
4675 " // always taken\n"
4676 " if (v_one[0].x != 0.0)\n"
4678 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4680 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4682 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4684 " EndPrimitive();\n"
4687 if (m_test == TEST_AMPLIFICATION)
4689 geometrySource << "\n"
4690 " // always taken\n"
4691 " if (v_one[0].y != 0.0)\n"
4693 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4695 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4697 " gl_Position = gl_in[0].gl_Position - vec4(0.0, 0.1, 0.0, 0.0);\n"
4699 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4703 else if (m_test == TEST_PARTIAL_PRIMITIVES)
4705 geometrySource << "\n"
4706 " // always taken\n"
4707 " if (v_one[0].y != 0.0)\n"
4709 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4711 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4715 " if (v_one[0].z < 0.0)\n"
4717 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4722 else if (m_test == TEST_INSTANCED)
4724 geometrySource << "\n"
4726 " if (v_one[0].y > float(gl_InvocationID) + 0.5)\n"
4728 " gl_Position = gl_in[0].gl_Position + vec4(0.0, 0.1, 0.0, 0.0);\n"
4730 " gl_Position = gl_in[0].gl_Position + vec4(0.1, 0.0, 0.0, 0.0);\n"
4732 " gl_Position = gl_in[0].gl_Position - vec4(0.1, 0.0, 0.0, 0.0);\n"
4737 geometrySource << "}\n";
4740 sources << glu::VertexSource(vertexSource);
4741 sources << glu::FragmentSource(fragmentSource);
4743 if (!geometrySource.str().empty())
4744 sources << glu::GeometrySource(geometrySource.str());
4746 return new glu::ShaderProgram(m_context.getRenderContext(), sources);
4749 class PrimitivesGeneratedQueryObjectQueryCase : public TestCase
4752 PrimitivesGeneratedQueryObjectQueryCase (Context& context, const char* name, const char* description);
4755 IterateResult iterate (void);
4758 PrimitivesGeneratedQueryObjectQueryCase::PrimitivesGeneratedQueryObjectQueryCase (Context& context, const char* name, const char* description)
4759 : TestCase(context, name, description)
4763 void PrimitivesGeneratedQueryObjectQueryCase::init (void)
4765 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4766 throw tcu::NotSupportedError("Geometry shader tests require GL_EXT_geometry_shader extension");
4769 PrimitivesGeneratedQueryObjectQueryCase::IterateResult PrimitivesGeneratedQueryObjectQueryCase::iterate (void)
4771 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4772 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
4774 gl.enableLogging(true);
4777 glw::GLuint query = 0;
4779 verifyStateQueryInteger(result, gl, GL_PRIMITIVES_GENERATED, GL_CURRENT_QUERY, 0, QUERY_QUERY);
4781 gl.glGenQueries(1, &query);
4782 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGenQueries");
4784 gl.glBeginQuery(GL_PRIMITIVES_GENERATED, query);
4785 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "beginQuery");
4787 verifyStateQueryInteger(result, gl, GL_PRIMITIVES_GENERATED, GL_CURRENT_QUERY, (int)query, QUERY_QUERY);
4789 gl.glEndQuery(GL_PRIMITIVES_GENERATED);
4790 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "endQuery");
4793 result.setTestContextResult(m_testCtx);
4797 class GeometryShaderFeartureTestCase : public TestCase
4800 GeometryShaderFeartureTestCase (Context& context, const char* name, const char* description);
4805 GeometryShaderFeartureTestCase::GeometryShaderFeartureTestCase (Context& context, const char* name, const char* description)
4806 : TestCase(context, name, description)
4810 void GeometryShaderFeartureTestCase::init (void)
4812 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
4813 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
4816 class FramebufferDefaultLayersCase : public GeometryShaderFeartureTestCase
4819 FramebufferDefaultLayersCase (Context& context, const char* name, const char* description);
4820 IterateResult iterate (void);
4823 FramebufferDefaultLayersCase::FramebufferDefaultLayersCase (Context& context, const char* name, const char* description)
4824 : GeometryShaderFeartureTestCase(context, name, description)
4828 FramebufferDefaultLayersCase::IterateResult FramebufferDefaultLayersCase::iterate (void)
4830 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4832 gl.enableLogging(true);
4834 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4837 const tcu::ScopedLogSection section (m_testCtx.getLog(), "Default", "Default value");
4838 const glu::Framebuffer fbo (m_context.getRenderContext());
4839 glw::GLint defaultLayers = -1;
4841 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4842 gl.glGetFramebufferParameteriv(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, &defaultLayers);
4843 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4845 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_DEFAULT_LAYERS = " << defaultLayers << tcu::TestLog::EndMessage;
4847 if (defaultLayers != 0)
4849 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected 0, got " << defaultLayers << tcu::TestLog::EndMessage;
4850 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4855 const tcu::ScopedLogSection section (m_testCtx.getLog(), "SetTo12", "Set default layers to 12");
4856 const glu::Framebuffer fbo (m_context.getRenderContext());
4857 glw::GLint defaultLayers = -1;
4859 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4860 gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, 12);
4861 gl.glGetFramebufferParameteriv(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, &defaultLayers);
4862 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4864 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_DEFAULT_LAYERS = " << defaultLayers << tcu::TestLog::EndMessage;
4866 if (defaultLayers != 12)
4868 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected 12, got " << defaultLayers << tcu::TestLog::EndMessage;
4869 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4876 class FramebufferAttachmentLayeredCase : public GeometryShaderFeartureTestCase
4879 FramebufferAttachmentLayeredCase (Context& context, const char* name, const char* description);
4880 IterateResult iterate (void);
4883 FramebufferAttachmentLayeredCase::FramebufferAttachmentLayeredCase (Context& context, const char* name, const char* description)
4884 : GeometryShaderFeartureTestCase(context, name, description)
4888 FramebufferAttachmentLayeredCase::IterateResult FramebufferAttachmentLayeredCase::iterate (void)
4895 TEXTURE_2D_MS_ARRAY,
4897 TEXTURE_2D_ARRAY_LAYER,
4900 static const struct TextureType
4903 const char* description;
4908 { "3D", "3D texture", true, TEXTURE_3D },
4909 { "2DArray", "2D array", true, TEXTURE_2D_ARRAY },
4910 { "Cube", "Cube map", true, TEXTURE_CUBE },
4911 { "2DMSArray", "2D multisample array", true, TEXTURE_2D_MS_ARRAY },
4912 { "3DLayer", "3D texture layer ", false, TEXTURE_3D_LAYER },
4913 { "2DArrayLayer", "2D array layer ", false, TEXTURE_2D_ARRAY_LAYER },
4916 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
4917 gl.enableLogging(true);
4919 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4921 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(textureTypes); ++ndx)
4923 const tcu::ScopedLogSection section (m_testCtx.getLog(), textureTypes[ndx].name, textureTypes[ndx].description);
4924 const glu::Framebuffer fbo (m_context.getRenderContext());
4925 const glu::Texture texture (m_context.getRenderContext());
4926 glw::GLint layered = -1;
4928 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
4930 if (textureTypes[ndx].type == TEXTURE_3D || textureTypes[ndx].type == TEXTURE_3D_LAYER)
4932 gl.glBindTexture(GL_TEXTURE_3D, *texture);
4933 gl.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4934 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4935 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4937 if (textureTypes[ndx].type == TEXTURE_3D)
4938 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4940 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0, 2);
4942 else if (textureTypes[ndx].type == TEXTURE_2D_ARRAY || textureTypes[ndx].type == TEXTURE_2D_ARRAY_LAYER)
4944 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture);
4945 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4946 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4947 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4949 if (textureTypes[ndx].type == TEXTURE_2D_ARRAY)
4950 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4952 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0, 3);
4954 else if (textureTypes[ndx].type == TEXTURE_CUBE)
4956 gl.glBindTexture(GL_TEXTURE_CUBE_MAP, *texture);
4957 for (int face = 0; face < 6; ++face)
4958 gl.glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA8, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
4959 gl.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4960 gl.glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4961 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4963 else if (textureTypes[ndx].type == TEXTURE_2D_MS_ARRAY)
4966 if (!m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"))
4968 m_testCtx.getLog() << tcu::TestLog::Message << "GL_OES_texture_storage_multisample_2d_array not supported, skipping." << tcu::TestLog::EndMessage;
4972 gl.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, *texture);
4973 gl.glTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 32, 32, 32, GL_FALSE);
4974 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture, 0);
4977 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup attachment");
4979 gl.glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &layered);
4980 GLU_EXPECT_NO_ERROR(gl.glGetError(), "getFramebufferParameteriv");
4982 m_testCtx.getLog() << tcu::TestLog::Message << "GL_FRAMEBUFFER_ATTACHMENT_LAYERED = " << glu::getBooleanStr(layered) << tcu::TestLog::EndMessage;
4984 if (layered != GL_TRUE && layered != GL_FALSE)
4986 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected boolean, got " << layered << tcu::TestLog::EndMessage;
4987 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid boolean");
4989 else if ((layered == GL_TRUE) != textureTypes[ndx].layered)
4991 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected " << ((textureTypes[ndx].layered) ? ("GL_TRUE") : ("GL_FALSE")) << ", got " << glu::getBooleanStr(layered) << tcu::TestLog::EndMessage;
4992 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
4999 class FramebufferIncompleteLayereTargetsCase : public GeometryShaderFeartureTestCase
5002 FramebufferIncompleteLayereTargetsCase (Context& context, const char* name, const char* description);
5003 IterateResult iterate (void);
5006 FramebufferIncompleteLayereTargetsCase::FramebufferIncompleteLayereTargetsCase (Context& context, const char* name, const char* description)
5007 : GeometryShaderFeartureTestCase(context, name, description)
5011 FramebufferIncompleteLayereTargetsCase::IterateResult FramebufferIncompleteLayereTargetsCase::iterate (void)
5013 glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5014 gl.enableLogging(true);
5016 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5019 const tcu::ScopedLogSection section (m_testCtx.getLog(), "LayerAndNonLayer", "Layered and non-layered");
5020 const glu::Framebuffer fbo (m_context.getRenderContext());
5021 const glu::Texture texture0 (m_context.getRenderContext());
5022 const glu::Texture texture1 (m_context.getRenderContext());
5024 glw::GLint fboStatus;
5026 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture0);
5027 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5028 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5029 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5031 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture1);
5032 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5033 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5034 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5036 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
5037 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture0, 0);
5038 gl.glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, *texture1, 0, 0);
5040 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup fbo");
5042 fboStatus = gl.glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
5043 m_testCtx.getLog() << tcu::TestLog::Message << "Framebuffer status: " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5045 if (fboStatus != GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
5047 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS, got " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5048 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
5053 const tcu::ScopedLogSection section (m_testCtx.getLog(), "DifferentTarget", "Different target");
5054 const glu::Framebuffer fbo (m_context.getRenderContext());
5055 const glu::Texture texture0 (m_context.getRenderContext());
5056 const glu::Texture texture1 (m_context.getRenderContext());
5058 glw::GLint fboStatus;
5060 gl.glBindTexture(GL_TEXTURE_2D_ARRAY, *texture0);
5061 gl.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5062 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5063 gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5065 gl.glBindTexture(GL_TEXTURE_3D, *texture1);
5066 gl.glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
5067 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5068 gl.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5070 gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
5071 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture0, 0);
5072 gl.glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, *texture1, 0);
5074 GLU_EXPECT_NO_ERROR(gl.glGetError(), "setup fbo");
5076 fboStatus = gl.glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
5077 m_testCtx.getLog() << tcu::TestLog::Message << "Framebuffer status: " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5079 if (fboStatus != GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
5081 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS, got " << glu::getFramebufferStatusStr(fboStatus) << tcu::TestLog::EndMessage;
5082 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "invalid layer count");
5089 class ReferencedByGeometryShaderCase : public GeometryShaderFeartureTestCase
5092 ReferencedByGeometryShaderCase (Context& context, const char* name, const char* description);
5093 IterateResult iterate (void);
5096 ReferencedByGeometryShaderCase::ReferencedByGeometryShaderCase (Context& context, const char* name, const char* description)
5097 : GeometryShaderFeartureTestCase(context, name, description)
5101 ReferencedByGeometryShaderCase::IterateResult ReferencedByGeometryShaderCase::iterate (void)
5103 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5106 static const char* const vertexSource = "#version 310 es\n"
5107 "uniform highp vec4 u_position;\n"
5108 "void main (void)\n"
5110 " gl_Position = u_position;\n"
5112 static const char* const fragmentSource = "#version 310 es\n"
5113 "layout(location = 0) out mediump vec4 fragColor;\n"
5114 "void main (void)\n"
5116 " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
5118 static const char* const geometrySource = "#version 310 es\n"
5119 "#extension GL_EXT_geometry_shader : require\n"
5120 "layout(points) in;\n"
5121 "layout(points, max_vertices=1) out;\n"
5122 "uniform highp vec4 u_offset;\n"
5123 "void main (void)\n"
5125 " gl_Position = gl_in[0].gl_Position + u_offset;\n"
5129 const glu::ShaderProgram program(m_context.getRenderContext(), glu::ProgramSources()
5130 << glu::VertexSource(vertexSource)
5131 << glu::FragmentSource(fragmentSource)
5132 << glu::GeometrySource(geometrySource));
5133 m_testCtx.getLog() << program;
5136 const tcu::ScopedLogSection section (m_testCtx.getLog(), "UnreferencedUniform", "Unreferenced uniform u_position");
5137 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5138 const deUint32 props[1] = { GL_REFERENCED_BY_GEOMETRY_SHADER };
5139 deUint32 resourcePos;
5140 glw::GLsizei length = 0;
5141 glw::GLint referenced = 0;
5143 gl.enableLogging(true);
5145 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_position");
5146 m_testCtx.getLog() << tcu::TestLog::Message << "u_position resource index: " << resourcePos << tcu::TestLog::EndMessage;
5148 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
5149 m_testCtx.getLog() << tcu::TestLog::Message << "Query GL_REFERENCED_BY_GEOMETRY_SHADER, got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced) << tcu::TestLog::EndMessage;
5151 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
5153 if (length == 0 || referenced != GL_FALSE)
5155 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_FALSE." << tcu::TestLog::EndMessage;
5156 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected value");
5161 const tcu::ScopedLogSection section (m_testCtx.getLog(), "ReferencedUniform", "Referenced uniform u_offset");
5162 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5163 const deUint32 props[1] = { GL_REFERENCED_BY_GEOMETRY_SHADER };
5164 deUint32 resourcePos;
5165 glw::GLsizei length = 0;
5166 glw::GLint referenced = 0;
5168 gl.enableLogging(true);
5170 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_offset");
5171 m_testCtx.getLog() << tcu::TestLog::Message << "u_offset resource index: " << resourcePos << tcu::TestLog::EndMessage;
5173 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
5174 m_testCtx.getLog() << tcu::TestLog::Message << "Query GL_REFERENCED_BY_GEOMETRY_SHADER, got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced) << tcu::TestLog::EndMessage;
5176 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
5178 if (length == 0 || referenced != GL_TRUE)
5180 m_testCtx.getLog() << tcu::TestLog::Message << "Error, expected GL_TRUE." << tcu::TestLog::EndMessage;
5181 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got unexpected value");
5189 class CombinedGeometryUniformLimitCase : public GeometryShaderFeartureTestCase
5192 CombinedGeometryUniformLimitCase (Context& context, const char* name, const char* desc);
5194 IterateResult iterate (void);
5197 CombinedGeometryUniformLimitCase::CombinedGeometryUniformLimitCase (Context& context, const char* name, const char* desc)
5198 : GeometryShaderFeartureTestCase(context, name, desc)
5202 CombinedGeometryUniformLimitCase::IterateResult CombinedGeometryUniformLimitCase::iterate (void)
5204 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
5205 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
5207 gl.enableLogging(true);
5209 m_testCtx.getLog() << tcu::TestLog::Message
5210 << "The minimum value of MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS is MAX_GEOMETRY_UNIFORM_BLOCKS x MAX_UNIFORM_BLOCK_SIZE / 4 + MAX_GEOMETRY_UNIFORM_COMPONENTS"
5211 << tcu::TestLog::EndMessage;
5213 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlocks;
5214 gl.glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_BLOCKS, &maxUniformBlocks);
5215 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5217 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlockSize;
5218 gl.glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxUniformBlockSize);
5219 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5221 StateQueryMemoryWriteGuard<glw::GLint> maxUniformComponents;
5222 gl.glGetIntegerv(GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, &maxUniformComponents);
5223 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
5225 if (maxUniformBlocks.verifyValidity(result) && maxUniformBlockSize.verifyValidity(result) && maxUniformComponents.verifyValidity(result))
5227 const int limit = ((int)maxUniformBlocks) * ((int)maxUniformBlockSize) / 4 + (int)maxUniformComponents;
5228 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_INTEGER);
5231 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
5232 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_BOOLEAN);
5233 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_INTEGER64);
5234 verifyStateIntegerMin(result, gl, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, limit, QUERY_FLOAT);
5238 result.setTestContextResult(m_testCtx);
5242 class VertexFeedbackCase : public TestCase
5247 METHOD_DRAW_ARRAYS = 0,
5248 METHOD_DRAW_ARRAYS_INSTANCED,
5249 METHOD_DRAW_ARRAYS_INDIRECT,
5250 METHOD_DRAW_ELEMENTS,
5251 METHOD_DRAW_ELEMENTS_INSTANCED,
5252 METHOD_DRAW_ELEMENTS_INDIRECT,
5258 PRIMITIVE_LINE_LOOP = 0,
5259 PRIMITIVE_LINE_STRIP,
5260 PRIMITIVE_TRIANGLE_STRIP,
5261 PRIMITIVE_TRIANGLE_FAN,
5267 VertexFeedbackCase (Context& context, const char* name, const char* description, DrawMethod method, PrimitiveType output);
5268 ~VertexFeedbackCase (void);
5272 IterateResult iterate (void);
5274 glu::ShaderProgram* genProgram (void);
5275 deUint32 getOutputPrimitive (void);
5276 deUint32 getBasePrimitive (void);
5278 const DrawMethod m_method;
5279 const PrimitiveType m_output;
5281 deUint32 m_elementBuf;
5282 deUint32 m_arrayBuf;
5283 deUint32 m_offsetBuf;
5284 deUint32 m_feedbackBuf;
5285 deUint32 m_indirectBuffer;
5286 glu::ShaderProgram* m_program;
5287 glu::VertexArray* m_vao;
5290 VertexFeedbackCase::VertexFeedbackCase (Context& context, const char* name, const char* description, DrawMethod method, PrimitiveType output)
5291 : TestCase (context, name, description)
5298 , m_indirectBuffer (0)
5299 , m_program (DE_NULL)
5302 DE_ASSERT(method < METHOD_LAST);
5303 DE_ASSERT(output < PRIMITIVE_LAST);
5306 VertexFeedbackCase::~VertexFeedbackCase (void)
5311 void VertexFeedbackCase::init (void)
5315 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
5316 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
5318 // log what test tries to do
5321 << tcu::TestLog::Message
5322 << "Testing GL_EXT_geometry_shader transform feedback relaxations.\n"
5323 << "Capturing vertex shader varying, no geometry shader. Invoke with:"
5324 << tcu::TestLog::EndMessage;
5328 case METHOD_DRAW_ARRAYS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArrays" << tcu::TestLog::EndMessage; break;
5329 case METHOD_DRAW_ARRAYS_INSTANCED: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArraysInstanced" << tcu::TestLog::EndMessage; break;
5330 case METHOD_DRAW_ARRAYS_INDIRECT: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawArraysIndirect" << tcu::TestLog::EndMessage; break;
5331 case METHOD_DRAW_ELEMENTS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElements" << tcu::TestLog::EndMessage; break;
5332 case METHOD_DRAW_ELEMENTS_INSTANCED: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElementsInstanced" << tcu::TestLog::EndMessage; break;
5333 case METHOD_DRAW_ELEMENTS_INDIRECT: m_testCtx.getLog() << tcu::TestLog::Message << "Draw method: drawElementsIndirect" << tcu::TestLog::EndMessage; break;
5339 case PRIMITIVE_LINE_LOOP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: line loop" << tcu::TestLog::EndMessage; break;
5340 case PRIMITIVE_LINE_STRIP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: line strip" << tcu::TestLog::EndMessage; break;
5341 case PRIMITIVE_TRIANGLE_STRIP: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: triangle strip" << tcu::TestLog::EndMessage; break;
5342 case PRIMITIVE_TRIANGLE_FAN: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: triangle fan" << tcu::TestLog::EndMessage; break;
5343 case PRIMITIVE_POINTS: m_testCtx.getLog() << tcu::TestLog::Message << "Draw primitive: points" << tcu::TestLog::EndMessage; break;
5351 static const deUint16 elementData[] =
5355 static const tcu::Vec4 arrayData[] =
5357 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5358 tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f),
5359 tcu::Vec4(2.0f, 0.0f, 0.0f, 0.0f),
5360 tcu::Vec4(3.0f, 0.0f, 0.0f, 0.0f),
5362 static const tcu::Vec4 offsetData[] =
5364 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5365 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5366 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5367 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
5370 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5371 const int feedbackSize = 8 * (int)sizeof(float[4]);
5373 m_vao = new glu::VertexArray(m_context.getRenderContext());
5374 gl.bindVertexArray(**m_vao);
5375 GLU_EXPECT_NO_ERROR(gl.getError(), "set up vao");
5377 gl.genBuffers(1, &m_elementBuf);
5378 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5379 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elementData), &elementData[0], GL_STATIC_DRAW);
5380 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5382 gl.genBuffers(1, &m_arrayBuf);
5383 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5384 gl.bufferData(GL_ARRAY_BUFFER, sizeof(arrayData), &arrayData[0], GL_STATIC_DRAW);
5385 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5387 gl.genBuffers(1, &m_offsetBuf);
5388 gl.bindBuffer(GL_ARRAY_BUFFER, m_offsetBuf);
5389 gl.bufferData(GL_ARRAY_BUFFER, sizeof(offsetData), &offsetData[0], GL_STATIC_DRAW);
5390 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5392 gl.genBuffers(1, &m_feedbackBuf);
5393 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_feedbackBuf);
5394 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackSize, DE_NULL, GL_DYNAMIC_COPY);
5395 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5397 m_program = genProgram();
5399 if (!m_program->isOk())
5401 m_testCtx.getLog() << *m_program;
5402 throw tcu::TestError("could not build program");
5407 void VertexFeedbackCase::deinit (void)
5411 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_elementBuf);
5417 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_arrayBuf);
5423 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_offsetBuf);
5429 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_feedbackBuf);
5433 if (m_indirectBuffer)
5435 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_indirectBuffer);
5436 m_indirectBuffer = 0;
5440 m_program = DE_NULL;
5446 VertexFeedbackCase::IterateResult VertexFeedbackCase::iterate (void)
5448 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5449 const deUint32 outputPrimitive = getOutputPrimitive();
5450 const deUint32 basePrimitive = getBasePrimitive();
5452 const int posLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
5453 const int offsetLocation = gl.getAttribLocation(m_program->getProgram(), "a_offset");
5455 if (posLocation == -1)
5456 throw tcu::TestError("a_position location was -1");
5457 if (offsetLocation == -1)
5458 throw tcu::TestError("a_offset location was -1");
5460 gl.useProgram(m_program->getProgram());
5462 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5463 gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5464 gl.enableVertexAttribArray(posLocation);
5466 gl.bindBuffer(GL_ARRAY_BUFFER, m_offsetBuf);
5467 gl.vertexAttribPointer(offsetLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5468 gl.enableVertexAttribArray(offsetLocation);
5470 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_feedbackBuf);
5471 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffer base");
5473 m_testCtx.getLog() << tcu::TestLog::Message << "Calling BeginTransformFeedback(" << glu::getPrimitiveTypeStr(basePrimitive) << ")" << tcu::TestLog::EndMessage;
5474 gl.beginTransformFeedback(basePrimitive);
5475 GLU_EXPECT_NO_ERROR(gl.getError(), "beginTransformFeedback");
5479 case METHOD_DRAW_ARRAYS:
5481 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawArrays(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5482 gl.drawArrays(outputPrimitive, 0, 4);
5486 case METHOD_DRAW_ARRAYS_INSTANCED:
5488 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawArraysInstanced(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5489 gl.vertexAttribDivisor(offsetLocation, 2);
5490 gl.drawArraysInstanced(outputPrimitive, 0, 3, 2);
5494 case METHOD_DRAW_ELEMENTS:
5496 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElements(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5497 gl.drawElements(outputPrimitive, 4, GL_UNSIGNED_SHORT, DE_NULL);
5501 case METHOD_DRAW_ELEMENTS_INSTANCED:
5503 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsInstanced(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5504 gl.drawElementsInstanced(outputPrimitive, 3, GL_UNSIGNED_SHORT, DE_NULL, 2);
5508 case METHOD_DRAW_ARRAYS_INDIRECT:
5510 struct DrawArraysIndirectCommand
5513 deUint32 instanceCount;
5515 deUint32 reservedMustBeZero;
5518 DE_STATIC_ASSERT(sizeof(DrawArraysIndirectCommand) == sizeof(deUint32[4]));
5521 params.instanceCount = 1;
5523 params.reservedMustBeZero = 0;
5525 gl.genBuffers(1, &m_indirectBuffer);
5526 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirectBuffer);
5527 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(params), ¶ms, GL_STATIC_DRAW);
5529 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsIndirect(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5530 gl.drawArraysIndirect(outputPrimitive, DE_NULL);
5534 case METHOD_DRAW_ELEMENTS_INDIRECT:
5536 struct DrawElementsIndirectCommand
5539 deUint32 instanceCount;
5540 deUint32 firstIndex;
5542 deUint32 reservedMustBeZero;
5545 DE_STATIC_ASSERT(sizeof(DrawElementsIndirectCommand) == sizeof(deUint32[5]));
5548 params.instanceCount = 1;
5549 params.firstIndex = 0;
5550 params.baseVertex = 0;
5551 params.reservedMustBeZero = 0;
5553 gl.genBuffers(1, &m_indirectBuffer);
5554 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirectBuffer);
5555 gl.bufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(params), ¶ms, GL_STATIC_DRAW);
5557 m_testCtx.getLog() << tcu::TestLog::Message << "Calling DrawElementsIndirect(" << glu::getPrimitiveTypeStr(outputPrimitive) << ", ...)" << tcu::TestLog::EndMessage;
5558 gl.drawElementsIndirect(outputPrimitive, GL_UNSIGNED_SHORT, DE_NULL);
5565 GLU_EXPECT_NO_ERROR(gl.getError(), "draw");
5567 gl.endTransformFeedback();
5568 GLU_EXPECT_NO_ERROR(gl.getError(), "endTransformFeedback");
5570 m_testCtx.getLog() << tcu::TestLog::Message << "No errors." << tcu::TestLog::EndMessage;
5571 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5576 glu::ShaderProgram* VertexFeedbackCase::genProgram (void)
5578 static const char* const vertexSource = "#version 310 es\n"
5579 "in highp vec4 a_position;\n"
5580 "in highp vec4 a_offset;\n"
5581 "out highp vec4 tf_value;\n"
5582 "void main (void)\n"
5584 " gl_Position = a_position;\n"
5585 " tf_value = a_position + a_offset;\n"
5587 static const char* const fragmentSource = "#version 310 es\n"
5588 "layout(location = 0) out mediump vec4 fragColor;\n"
5589 "void main (void)\n"
5591 " fragColor = vec4(1.0);\n"
5594 return new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5595 << glu::VertexSource(vertexSource)
5596 << glu::FragmentSource(fragmentSource)
5597 << glu::TransformFeedbackVarying("tf_value")
5598 << glu::TransformFeedbackMode(GL_INTERLEAVED_ATTRIBS));
5601 deUint32 VertexFeedbackCase::getOutputPrimitive (void)
5605 case PRIMITIVE_LINE_LOOP: return GL_LINE_LOOP;
5606 case PRIMITIVE_LINE_STRIP: return GL_LINE_STRIP;
5607 case PRIMITIVE_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP;
5608 case PRIMITIVE_TRIANGLE_FAN: return GL_TRIANGLE_FAN;
5609 case PRIMITIVE_POINTS: return GL_POINTS;
5616 deUint32 VertexFeedbackCase::getBasePrimitive (void)
5620 case PRIMITIVE_LINE_LOOP: return GL_LINES;
5621 case PRIMITIVE_LINE_STRIP: return GL_LINES;
5622 case PRIMITIVE_TRIANGLE_STRIP: return GL_TRIANGLES;
5623 case PRIMITIVE_TRIANGLE_FAN: return GL_TRIANGLES;
5624 case PRIMITIVE_POINTS: return GL_POINTS;
5631 class VertexFeedbackOverflowCase : public TestCase
5636 METHOD_DRAW_ARRAYS = 0,
5637 METHOD_DRAW_ELEMENTS,
5640 VertexFeedbackOverflowCase (Context& context, const char* name, const char* description, Method method);
5641 ~VertexFeedbackOverflowCase (void);
5646 IterateResult iterate (void);
5647 glu::ShaderProgram* genProgram (void);
5649 const Method m_method;
5651 deUint32 m_elementBuf;
5652 deUint32 m_arrayBuf;
5653 deUint32 m_feedbackBuf;
5654 glu::ShaderProgram* m_program;
5655 glu::VertexArray* m_vao;
5658 VertexFeedbackOverflowCase::VertexFeedbackOverflowCase (Context& context, const char* name, const char* description, Method method)
5659 : TestCase (context, name, description)
5664 , m_program (DE_NULL)
5669 VertexFeedbackOverflowCase::~VertexFeedbackOverflowCase (void)
5674 void VertexFeedbackOverflowCase::init (void)
5678 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader"))
5679 throw tcu::NotSupportedError("test requires GL_EXT_geometry_shader extension");
5681 // log what test tries to do
5684 << tcu::TestLog::Message
5685 << "Testing GL_EXT_geometry_shader transform feedback overflow behavior.\n"
5686 << "Capturing vertex shader varying, rendering 2 triangles. Allocating feedback buffer for 5 vertices."
5687 << tcu::TestLog::EndMessage;
5692 static const deUint16 elementData[] =
5697 static const tcu::Vec4 arrayData[] =
5699 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5700 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5701 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5702 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
5705 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5707 m_vao = new glu::VertexArray(m_context.getRenderContext());
5708 gl.bindVertexArray(**m_vao);
5709 GLU_EXPECT_NO_ERROR(gl.getError(), "set up vao");
5711 if (m_method == METHOD_DRAW_ELEMENTS)
5713 gl.genBuffers(1, &m_elementBuf);
5714 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5715 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elementData), &elementData[0], GL_STATIC_DRAW);
5716 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5719 gl.genBuffers(1, &m_arrayBuf);
5720 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5721 gl.bufferData(GL_ARRAY_BUFFER, sizeof(arrayData), &arrayData[0], GL_STATIC_DRAW);
5722 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5725 const int feedbackCount = 5 * 4; // 5x vec4
5726 const std::vector<float> initialBufferContents (feedbackCount, -1.0f);
5728 m_testCtx.getLog() << tcu::TestLog::Message << "Filling feeback buffer with dummy value (-1.0)." << tcu::TestLog::EndMessage;
5730 gl.genBuffers(1, &m_feedbackBuf);
5731 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_feedbackBuf);
5732 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, (int)(sizeof(float) * initialBufferContents.size()), &initialBufferContents[0], GL_DYNAMIC_COPY);
5733 GLU_EXPECT_NO_ERROR(gl.getError(), "gen buf");
5736 m_program = genProgram();
5738 if (!m_program->isOk())
5740 m_testCtx.getLog() << *m_program;
5741 throw tcu::TestError("could not build program");
5746 void VertexFeedbackOverflowCase::deinit (void)
5750 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_elementBuf);
5756 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_arrayBuf);
5762 m_context.getRenderContext().getFunctions().deleteBuffers(1, &m_feedbackBuf);
5767 m_program = DE_NULL;
5773 VertexFeedbackOverflowCase::IterateResult VertexFeedbackOverflowCase::iterate (void)
5775 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
5776 const int posLocation = gl.getAttribLocation(m_program->getProgram(), "a_position");
5778 if (posLocation == -1)
5779 throw tcu::TestError("a_position location was -1");
5781 gl.useProgram(m_program->getProgram());
5783 gl.bindBuffer(GL_ARRAY_BUFFER, m_arrayBuf);
5784 gl.vertexAttribPointer(posLocation, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
5785 gl.enableVertexAttribArray(posLocation);
5787 if (m_method == METHOD_DRAW_ELEMENTS)
5789 gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuf);
5790 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffers");
5793 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_feedbackBuf);
5794 GLU_EXPECT_NO_ERROR(gl.getError(), "bind buffer base");
5796 m_testCtx.getLog() << tcu::TestLog::Message << "Capturing 2 triangles." << tcu::TestLog::EndMessage;
5798 gl.beginTransformFeedback(GL_TRIANGLES);
5800 if (m_method == METHOD_DRAW_ELEMENTS)
5801 gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, DE_NULL);
5802 else if (m_method == METHOD_DRAW_ARRAYS)
5803 gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
5807 gl.endTransformFeedback();
5808 GLU_EXPECT_NO_ERROR(gl.getError(), "capture");
5810 m_testCtx.getLog() << tcu::TestLog::Message << "Verifying final triangle was not partially written to the feedback buffer." << tcu::TestLog::EndMessage;
5813 const void* ptr = gl.mapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(float[4]) * 5, GL_MAP_READ_BIT);
5814 std::vector<float> feedback;
5817 GLU_EXPECT_NO_ERROR(gl.getError(), "mapBufferRange");
5819 throw tcu::TestError("mapBufferRange returned null");
5821 feedback.resize(5*4);
5822 deMemcpy(&feedback[0], ptr, sizeof(float[4]) * 5);
5824 if (gl.unmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER) != GL_TRUE)
5825 throw tcu::TestError("unmapBuffer returned false");
5827 // Verify vertices 0 - 2
5828 for (int vertex = 0; vertex < 3; ++vertex)
5830 for (int component = 0; component < 4; ++component)
5832 if (feedback[vertex*4 + component] != 1.0f)
5835 << tcu::TestLog::Message
5836 << "Feedback buffer vertex " << vertex << ", component " << component << ": unexpected value, expected 1.0, got " << feedback[vertex*4 + component]
5837 << tcu::TestLog::EndMessage;
5843 // Verify vertices 3 - 4
5844 for (int vertex = 3; vertex < 5; ++vertex)
5846 for (int component = 0; component < 4; ++component)
5848 if (feedback[vertex*4 + component] != -1.0f)
5851 << tcu::TestLog::Message
5852 << "Feedback buffer vertex " << vertex << ", component " << component << ": unexpected value, expected -1.0, got " << feedback[vertex*4 + component]
5853 << tcu::TestLog::EndMessage;
5860 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Feedback result validation failed");
5862 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5868 glu::ShaderProgram* VertexFeedbackOverflowCase::genProgram (void)
5870 static const char* const vertexSource = "#version 310 es\n"
5871 "in highp vec4 a_position;\n"
5872 "void main (void)\n"
5874 " gl_Position = a_position;\n"
5876 static const char* const fragmentSource = "#version 310 es\n"
5877 "layout(location = 0) out mediump vec4 fragColor;\n"
5878 "void main (void)\n"
5880 " fragColor = vec4(1.0);\n"
5883 return new glu::ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5884 << glu::VertexSource(vertexSource)
5885 << glu::FragmentSource(fragmentSource)
5886 << glu::TransformFeedbackVarying("gl_Position")
5887 << glu::TransformFeedbackMode(GL_INTERLEAVED_ATTRIBS));
5892 GeometryShaderTests::GeometryShaderTests (Context& context)
5893 : TestCaseGroup(context, "geometry_shading", "Geometry shader tests")
5897 GeometryShaderTests::~GeometryShaderTests (void)
5901 void GeometryShaderTests::init (void)
5903 struct PrimitiveTestSpec
5905 deUint32 primitiveType;
5907 deUint32 outputType;
5912 deUint32 outputType;
5913 int emitCountA; //!< primitive A emit count
5914 int endCountA; //!< primitive A end count
5915 int emitCountB; //!<
5920 static const struct LayeredTarget
5922 LayeredRenderCase::LayeredRenderTargetType target;
5927 { LayeredRenderCase::TARGET_CUBE, "cubemap", "cubemap" },
5928 { LayeredRenderCase::TARGET_3D, "3d", "3D texture" },
5929 { LayeredRenderCase::TARGET_2D_ARRAY, "2d_array", "2D array texture" },
5930 { LayeredRenderCase::TARGET_2D_MS_ARRAY, "2d_multisample_array", "2D multisample array texture" },
5933 tcu::TestCaseGroup* const queryGroup = new tcu::TestCaseGroup(m_testCtx, "query", "Query tests.");
5934 tcu::TestCaseGroup* const basicGroup = new tcu::TestCaseGroup(m_testCtx, "basic", "Basic tests.");
5935 tcu::TestCaseGroup* const inputPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "input", "Different input primitives.");
5936 tcu::TestCaseGroup* const conversionPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "conversion", "Different input and output primitives.");
5937 tcu::TestCaseGroup* const emitGroup = new tcu::TestCaseGroup(m_testCtx, "emit", "Different emit counts.");
5938 tcu::TestCaseGroup* const varyingGroup = new tcu::TestCaseGroup(m_testCtx, "varying", "Test varyings.");
5939 tcu::TestCaseGroup* const layeredGroup = new tcu::TestCaseGroup(m_testCtx, "layered", "Layered rendering.");
5940 tcu::TestCaseGroup* const instancedGroup = new tcu::TestCaseGroup(m_testCtx, "instanced", "Instanced rendering.");
5941 tcu::TestCaseGroup* const negativeGroup = new tcu::TestCaseGroup(m_testCtx, "negative", "Negative tests.");
5942 tcu::TestCaseGroup* const feedbackGroup = new tcu::TestCaseGroup(m_testCtx, "vertex_transform_feedback", "Transform feedback.");
5944 this->addChild(queryGroup);
5945 this->addChild(basicGroup);
5946 this->addChild(inputPrimitiveGroup);
5947 this->addChild(conversionPrimitiveGroup);
5948 this->addChild(emitGroup);
5949 this->addChild(varyingGroup);
5950 this->addChild(layeredGroup);
5951 this->addChild(instancedGroup);
5952 this->addChild(negativeGroup);
5953 this->addChild(feedbackGroup);
5957 // limits with a corresponding glsl constant
5958 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_input_components", "", GL_MAX_GEOMETRY_INPUT_COMPONENTS, "MaxGeometryInputComponents", 64));
5959 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_output_components", "", GL_MAX_GEOMETRY_OUTPUT_COMPONENTS, "MaxGeometryOutputComponents", 128));
5960 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_image_uniforms", "", GL_MAX_GEOMETRY_IMAGE_UNIFORMS, "MaxGeometryImageUniforms", 0));
5961 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_texture_image_units", "", GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, "MaxGeometryTextureImageUnits", 16));
5962 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_output_vertices", "", GL_MAX_GEOMETRY_OUTPUT_VERTICES, "MaxGeometryOutputVertices", 256));
5963 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_total_output_components", "", GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, "MaxGeometryTotalOutputComponents", 1024));
5964 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_uniform_components", "", GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, "MaxGeometryUniformComponents", 1024));
5965 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_atomic_counters", "", GL_MAX_GEOMETRY_ATOMIC_COUNTERS, "MaxGeometryAtomicCounters", 0));
5966 queryGroup->addChild(new GeometryProgramLimitCase(m_context, "max_geometry_atomic_counter_buffers", "", GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS, "MaxGeometryAtomicCounterBuffers", 0));
5969 queryGroup->addChild(new GeometryShaderVerticesQueryCase (m_context, "geometry_linked_vertices_out", "GL_GEOMETRY_LINKED_VERTICES_OUT"));
5970 queryGroup->addChild(new GeometryShaderInputQueryCase (m_context, "geometry_linked_input_type", "GL_GEOMETRY_LINKED_INPUT_TYPE"));
5971 queryGroup->addChild(new GeometryShaderOutputQueryCase (m_context, "geometry_linked_output_type", "GL_GEOMETRY_LINKED_OUTPUT_TYPE"));
5972 queryGroup->addChild(new GeometryShaderInvocationsQueryCase (m_context, "geometry_shader_invocations", "GL_GEOMETRY_SHADER_INVOCATIONS"));
5975 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_shader_invocations", "", GL_MAX_GEOMETRY_SHADER_INVOCATIONS, 32));
5976 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_uniform_blocks", "", GL_MAX_GEOMETRY_UNIFORM_BLOCKS, 12));
5977 queryGroup->addChild(new ImplementationLimitCase(m_context, "max_geometry_shader_storage_blocks", "", GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, 0));
5979 // layer_provoking_vertex_ext
5980 queryGroup->addChild(new LayerProvokingVertexQueryCase(m_context, "layer_provoking_vertex", "GL_LAYER_PROVOKING_VERTEX"));
5982 // primitives_generated
5983 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_no_geometry", "PRIMITIVES_GENERATED query with no geometry shader", PrimitivesGeneratedQueryCase::TEST_NO_GEOMETRY));
5984 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_no_amplification", "PRIMITIVES_GENERATED query with non amplifying geometry shader", PrimitivesGeneratedQueryCase::TEST_NO_AMPLIFICATION));
5985 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_amplification", "PRIMITIVES_GENERATED query with amplifying geometry shader", PrimitivesGeneratedQueryCase::TEST_AMPLIFICATION));
5986 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_partial_primitives", "PRIMITIVES_GENERATED query with geometry shader emitting partial primitives", PrimitivesGeneratedQueryCase::TEST_PARTIAL_PRIMITIVES));
5987 queryGroup->addChild(new PrimitivesGeneratedQueryCase(m_context, "primitives_generated_instanced", "PRIMITIVES_GENERATED query with instanced geometry shader", PrimitivesGeneratedQueryCase::TEST_INSTANCED));
5989 queryGroup->addChild(new PrimitivesGeneratedQueryObjectQueryCase(m_context, "primitives_generated", "Query bound PRIMITIVES_GENERATED query"));
5992 queryGroup->addChild(new ImplementationLimitCase (m_context, "max_framebuffer_layers", "", GL_MAX_FRAMEBUFFER_LAYERS, 256));
5993 queryGroup->addChild(new FramebufferDefaultLayersCase (m_context, "framebuffer_default_layers", ""));
5994 queryGroup->addChild(new FramebufferAttachmentLayeredCase (m_context, "framebuffer_attachment_layered", ""));
5995 queryGroup->addChild(new FramebufferIncompleteLayereTargetsCase (m_context, "framebuffer_incomplete_layer_targets", ""));
5998 queryGroup->addChild(new ReferencedByGeometryShaderCase (m_context, "referenced_by_geometry_shader", ""));
6001 queryGroup->addChild(new CombinedGeometryUniformLimitCase (m_context, "max_combined_geometry_uniform_components", "MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS"));
6006 basicGroup->addChild(new OutputCountCase (m_context, "output_10", "Output 10 vertices", OutputCountPatternSpec(10)));
6007 basicGroup->addChild(new OutputCountCase (m_context, "output_128", "Output 128 vertices", OutputCountPatternSpec(128)));
6008 basicGroup->addChild(new OutputCountCase (m_context, "output_256", "Output 256 vertices", OutputCountPatternSpec(256)));
6009 basicGroup->addChild(new OutputCountCase (m_context, "output_max", "Output max vertices", OutputCountPatternSpec(-1)));
6010 basicGroup->addChild(new OutputCountCase (m_context, "output_10_and_100", "Output 10 and 100 vertices in two invocations", OutputCountPatternSpec(10, 100)));
6011 basicGroup->addChild(new OutputCountCase (m_context, "output_100_and_10", "Output 100 and 10 vertices in two invocations", OutputCountPatternSpec(100, 10)));
6012 basicGroup->addChild(new OutputCountCase (m_context, "output_0_and_128", "Output 0 and 128 vertices in two invocations", OutputCountPatternSpec(0, 128)));
6013 basicGroup->addChild(new OutputCountCase (m_context, "output_128_and_0", "Output 128 and 0 vertices in two invocations", OutputCountPatternSpec(128, 0)));
6015 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_attribute", "Output varying number of vertices", VaryingOutputCountShader::READ_ATTRIBUTE, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6016 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_uniform", "Output varying number of vertices", VaryingOutputCountShader::READ_UNIFORM, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6017 basicGroup->addChild(new VaryingOutputCountCase (m_context, "output_vary_by_texture", "Output varying number of vertices", VaryingOutputCountShader::READ_TEXTURE, VaryingOutputCountCase::MODE_WITHOUT_INSTANCING));
6019 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "point_size", "test gl_PointSize", BuiltinVariableShader::TEST_POINT_SIZE));
6020 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "primitive_id_in", "test gl_PrimitiveIDIn", BuiltinVariableShader::TEST_PRIMITIVE_ID_IN));
6021 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));
6022 basicGroup->addChild(new BuiltinVariableRenderTest (m_context, "primitive_id", "test gl_PrimitiveID", BuiltinVariableShader::TEST_PRIMITIVE_ID));
6027 static const PrimitiveTestSpec inputPrimitives[] =
6029 { GL_POINTS, "points", GL_POINTS },
6030 { GL_LINES, "lines", GL_LINE_STRIP },
6031 { GL_LINE_LOOP, "line_loop", GL_LINE_STRIP },
6032 { GL_LINE_STRIP, "line_strip", GL_LINE_STRIP },
6033 { GL_TRIANGLES, "triangles", GL_TRIANGLE_STRIP },
6034 { GL_TRIANGLE_STRIP, "triangle_strip", GL_TRIANGLE_STRIP },
6035 { GL_TRIANGLE_FAN, "triangle_fan", GL_TRIANGLE_STRIP },
6036 { GL_LINES_ADJACENCY, "lines_adjacency", GL_LINE_STRIP },
6037 { GL_LINE_STRIP_ADJACENCY, "line_strip_adjacency", GL_LINE_STRIP },
6038 { GL_TRIANGLES_ADJACENCY, "triangles_adjacency", GL_TRIANGLE_STRIP }
6041 tcu::TestCaseGroup* const basicPrimitiveGroup = new tcu::TestCaseGroup(m_testCtx, "basic_primitive", "Different input and output primitives.");
6042 tcu::TestCaseGroup* const triStripAdjacencyGroup = new tcu::TestCaseGroup(m_testCtx, "triangle_strip_adjacency", "Different triangle_strip_adjacency vertex counts.");
6045 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(inputPrimitives); ++ndx)
6046 basicPrimitiveGroup->addChild(new GeometryExpanderRenderTest(m_context, inputPrimitives[ndx].name, inputPrimitives[ndx].name, inputPrimitives[ndx].primitiveType, inputPrimitives[ndx].outputType));
6048 // triangle strip adjacency with different vtx counts
6049 for (int vtxCount = 0; vtxCount <= 12; ++vtxCount)
6051 const std::string name = "vertex_count_" + de::toString(vtxCount);
6052 const std::string desc = "Vertex count is " + de::toString(vtxCount);
6054 triStripAdjacencyGroup->addChild(new TriangleStripAdjacencyVertexCountTest(m_context, name.c_str(), desc.c_str(), vtxCount));
6057 inputPrimitiveGroup->addChild(basicPrimitiveGroup);
6058 inputPrimitiveGroup->addChild(triStripAdjacencyGroup);
6061 // different type conversions
6063 static const PrimitiveTestSpec conversionPrimitives[] =
6065 { GL_TRIANGLES, "triangles_to_points", GL_POINTS },
6066 { GL_LINES, "lines_to_points", GL_POINTS },
6067 { GL_POINTS, "points_to_lines", GL_LINE_STRIP },
6068 { GL_TRIANGLES, "triangles_to_lines", GL_LINE_STRIP },
6069 { GL_POINTS, "points_to_triangles", GL_TRIANGLE_STRIP },
6070 { GL_LINES, "lines_to_triangles", GL_TRIANGLE_STRIP }
6073 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(conversionPrimitives); ++ndx)
6074 conversionPrimitiveGroup->addChild(new GeometryExpanderRenderTest(m_context, conversionPrimitives[ndx].name, conversionPrimitives[ndx].name, conversionPrimitives[ndx].primitiveType, conversionPrimitives[ndx].outputType));
6077 // emit different amounts
6079 static const EmitTestSpec emitTests[] =
6081 { GL_POINTS, 0, 0, 0, 0, "points" },
6082 { GL_POINTS, 0, 1, 0, 0, "points" },
6083 { GL_POINTS, 1, 1, 0, 0, "points" },
6084 { GL_POINTS, 0, 2, 0, 0, "points" },
6085 { GL_POINTS, 1, 2, 0, 0, "points" },
6086 { GL_LINE_STRIP, 0, 0, 0, 0, "line_strip" },
6087 { GL_LINE_STRIP, 0, 1, 0, 0, "line_strip" },
6088 { GL_LINE_STRIP, 1, 1, 0, 0, "line_strip" },
6089 { GL_LINE_STRIP, 2, 1, 0, 0, "line_strip" },
6090 { GL_LINE_STRIP, 0, 2, 0, 0, "line_strip" },
6091 { GL_LINE_STRIP, 1, 2, 0, 0, "line_strip" },
6092 { GL_LINE_STRIP, 2, 2, 0, 0, "line_strip" },
6093 { GL_LINE_STRIP, 2, 2, 2, 0, "line_strip" },
6094 { GL_TRIANGLE_STRIP, 0, 0, 0, 0, "triangle_strip" },
6095 { GL_TRIANGLE_STRIP, 0, 1, 0, 0, "triangle_strip" },
6096 { GL_TRIANGLE_STRIP, 1, 1, 0, 0, "triangle_strip" },
6097 { GL_TRIANGLE_STRIP, 2, 1, 0, 0, "triangle_strip" },
6098 { GL_TRIANGLE_STRIP, 3, 1, 0, 0, "triangle_strip" },
6099 { GL_TRIANGLE_STRIP, 0, 2, 0, 0, "triangle_strip" },
6100 { GL_TRIANGLE_STRIP, 1, 2, 0, 0, "triangle_strip" },
6101 { GL_TRIANGLE_STRIP, 2, 2, 0, 0, "triangle_strip" },
6102 { GL_TRIANGLE_STRIP, 3, 2, 0, 0, "triangle_strip" },
6103 { GL_TRIANGLE_STRIP, 3, 2, 3, 0, "triangle_strip" },
6106 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(emitTests); ++ndx)
6108 std::string name = std::string(emitTests[ndx].name) + "_emit_" + de::toString(emitTests[ndx].emitCountA) + "_end_" + de::toString(emitTests[ndx].endCountA);
6109 std::string desc = std::string(emitTests[ndx].name) + " output, emit " + de::toString(emitTests[ndx].emitCountA) + " vertices, call EndPrimitive " + de::toString(emitTests[ndx].endCountA) + " times";
6111 if (emitTests[ndx].emitCountB)
6113 name += "_emit_" + de::toString(emitTests[ndx].emitCountB) + "_end_" + de::toString(emitTests[ndx].endCountB);
6114 desc += ", emit " + de::toString(emitTests[ndx].emitCountB) + " vertices, call EndPrimitive " + de::toString(emitTests[ndx].endCountB) + " times";
6117 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));
6123 struct VaryingTestSpec
6126 int geometryOutputs;
6131 static const VaryingTestSpec varyingTests[] =
6133 { -1, 1, "vertex_no_op_geometry_out_1", "vertex_no_op_geometry_out_1" },
6134 { 0, 1, "vertex_out_0_geometry_out_1", "vertex_out_0_geometry_out_1" },
6135 { 0, 2, "vertex_out_0_geometry_out_2", "vertex_out_0_geometry_out_2" },
6136 { 1, 0, "vertex_out_1_geometry_out_0", "vertex_out_1_geometry_out_0" },
6137 { 1, 2, "vertex_out_1_geometry_out_2", "vertex_out_1_geometry_out_2" },
6140 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(varyingTests); ++ndx)
6141 varyingGroup->addChild(new VaryingTest(m_context, varyingTests[ndx].name, varyingTests[ndx].desc, varyingTests[ndx].vertexOutputs, varyingTests[ndx].geometryOutputs));
6146 static const struct TestType
6148 LayeredRenderCase::TestType test;
6149 const char* testPrefix;
6150 const char* descPrefix;
6153 { LayeredRenderCase::TEST_DEFAULT_LAYER, "render_with_default_layer_", "Render to all layers of " },
6154 { LayeredRenderCase::TEST_SINGLE_LAYER, "render_to_one_", "Render to one layer of " },
6155 { LayeredRenderCase::TEST_ALL_LAYERS, "render_to_all_", "Render to all layers of " },
6156 { LayeredRenderCase::TEST_DIFFERENT_LAYERS, "render_different_to_", "Render different data to different layers" },
6157 { LayeredRenderCase::TEST_LAYER_ID, "fragment_layer_", "Read gl_Layer in fragment shader" },
6158 { LayeredRenderCase::TEST_LAYER_PROVOKING_VERTEX, "layer_provoking_vertex_", "Verify LAYER_PROVOKING_VERTEX" },
6161 for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(tests); ++testNdx)
6162 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6164 const std::string name = std::string(tests[testNdx].testPrefix) + layerTargets[targetNdx].name;
6165 const std::string desc = std::string(tests[testNdx].descPrefix) + layerTargets[targetNdx].desc;
6167 layeredGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, tests[testNdx].test));
6173 static const struct InvocationCase
6177 } invocationCases[] =
6185 static const int numDrawInstances[] = { 2, 4, 8 };
6186 static const int numDrawInvocations[] = { 2, 8 };
6188 // same amount of content to all invocations
6189 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(invocationCases); ++ndx)
6190 instancedGroup->addChild(new GeometryInvocationCase(m_context,
6191 (std::string("geometry_") + invocationCases[ndx].name + "_invocations").c_str(),
6192 (std::string("Geometry shader with ") + invocationCases[ndx].name + " invocation(s)").c_str(),
6193 invocationCases[ndx].numInvocations,
6194 GeometryInvocationCase::CASE_FIXED_OUTPUT_COUNTS));
6196 // different amount of content to each invocation
6197 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(invocationCases); ++ndx)
6198 if (invocationCases[ndx].numInvocations != 1)
6199 instancedGroup->addChild(new GeometryInvocationCase(m_context,
6200 (std::string("geometry_output_different_") + invocationCases[ndx].name + "_invocations").c_str(),
6201 "Geometry shader invocation(s) with different emit counts",
6202 invocationCases[ndx].numInvocations,
6203 GeometryInvocationCase::CASE_DIFFERENT_OUTPUT_COUNTS));
6205 // invocation per layer
6206 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6208 const std::string name = std::string("invocation_per_layer_") + layerTargets[targetNdx].name;
6209 const std::string desc = std::string("Render to multiple layers with multiple invocations, one invocation per layer, target ") + layerTargets[targetNdx].desc;
6211 instancedGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, LayeredRenderCase::TEST_INVOCATION_PER_LAYER));
6214 // multiple layers per invocation
6215 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(layerTargets); ++targetNdx)
6217 const std::string name = std::string("multiple_layers_per_invocation_") + layerTargets[targetNdx].name;
6218 const std::string desc = std::string("Render to multiple layers with multiple invocations, multiple layers per invocation, target ") + layerTargets[targetNdx].desc;
6220 instancedGroup->addChild(new LayeredRenderCase(m_context, name.c_str(), desc.c_str(), layerTargets[targetNdx].target, LayeredRenderCase::TEST_MULTIPLE_LAYERS_PER_INVOCATION));
6223 // different invocation output counts depending on {uniform, attrib, texture}
6224 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_attribute", "Output varying number of vertices", VaryingOutputCountShader::READ_ATTRIBUTE, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6225 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_uniform", "Output varying number of vertices", VaryingOutputCountShader::READ_UNIFORM, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6226 instancedGroup->addChild(new VaryingOutputCountCase(m_context, "invocation_output_vary_by_texture", "Output varying number of vertices", VaryingOutputCountShader::READ_TEXTURE, VaryingOutputCountCase::MODE_WITH_INSTANCING));
6228 // with drawInstanced
6229 for (int instanceNdx = 0; instanceNdx < DE_LENGTH_OF_ARRAY(numDrawInstances); ++instanceNdx)
6230 for (int invocationNdx = 0; invocationNdx < DE_LENGTH_OF_ARRAY(numDrawInvocations); ++invocationNdx)
6232 const std::string name = std::string("draw_") + de::toString(numDrawInstances[instanceNdx]) + "_instances_geometry_" + de::toString(numDrawInvocations[invocationNdx]) + "_invocations";
6233 const std::string desc = std::string("Draw ") + de::toString(numDrawInstances[instanceNdx]) + " instances, with " + de::toString(numDrawInvocations[invocationNdx]) + " geometry shader invocations.";
6235 instancedGroup->addChild(new DrawInstancedGeometryInstancedCase(m_context, name.c_str(), desc.c_str(), numDrawInstances[instanceNdx], numDrawInvocations[invocationNdx]));
6239 // negative (wrong types)
6241 struct PrimitiveToInputTypeConversion
6244 GLenum primitiveType;
6247 static const PrimitiveToInputTypeConversion legalConversions[] =
6249 { GL_POINTS, GL_POINTS },
6250 { GL_LINES, GL_LINES },
6251 { GL_LINES, GL_LINE_LOOP },
6252 { GL_LINES, GL_LINE_STRIP },
6253 { GL_LINES_ADJACENCY, GL_LINES_ADJACENCY },
6254 { GL_LINES_ADJACENCY, GL_LINE_STRIP_ADJACENCY },
6255 { GL_TRIANGLES, GL_TRIANGLES },
6256 { GL_TRIANGLES, GL_TRIANGLE_STRIP },
6257 { GL_TRIANGLES, GL_TRIANGLE_FAN },
6258 { GL_TRIANGLES_ADJACENCY, GL_TRIANGLES_ADJACENCY },
6259 { GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP_ADJACENCY },
6262 static const GLenum inputTypes[] =
6268 GL_TRIANGLES_ADJACENCY
6271 static const GLenum primitiveTypes[] =
6278 GL_LINE_STRIP_ADJACENCY,
6282 GL_TRIANGLES_ADJACENCY,
6283 GL_TRIANGLE_STRIP_ADJACENCY
6286 for (int inputTypeNdx = 0; inputTypeNdx < DE_LENGTH_OF_ARRAY(inputTypes); ++inputTypeNdx)
6287 for (int primitiveTypeNdx = 0; primitiveTypeNdx < DE_LENGTH_OF_ARRAY(primitiveTypes); ++primitiveTypeNdx)
6289 const GLenum inputType = inputTypes[inputTypeNdx];
6290 const GLenum primitiveType = primitiveTypes[primitiveTypeNdx];
6291 const std::string name = std::string("type_") + inputTypeToGLString(sglr::rr_util::mapGLGeometryShaderInputType(inputType)) + "_primitive_" + primitiveTypeToString(primitiveType);
6292 const std::string desc = std::string("Shader input type ") + inputTypeToGLString(sglr::rr_util::mapGLGeometryShaderInputType(inputType)) + ", draw primitive type " + primitiveTypeToString(primitiveType);
6294 bool isLegal = false;
6296 for (int legalNdx = 0; legalNdx < DE_LENGTH_OF_ARRAY(legalConversions); ++legalNdx)
6297 if (legalConversions[legalNdx].inputType == inputType && legalConversions[legalNdx].primitiveType == primitiveType)
6302 negativeGroup->addChild(new NegativeDrawCase(m_context, name.c_str(), desc.c_str(), inputType, primitiveType));
6306 // vertex transform feedback
6308 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_line_loop", "Capture line loop lines", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_LINE_LOOP));
6309 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_line_strip", "Capture line strip lines", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_LINE_STRIP));
6310 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_triangle_strip", "Capture triangle strip triangles", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_TRIANGLE_STRIP));
6311 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_triangle_fan", "Capture triangle fan triangles", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_TRIANGLE_FAN));
6312 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays", "Capture primitives generated with drawArrays", VertexFeedbackCase::METHOD_DRAW_ARRAYS, VertexFeedbackCase::PRIMITIVE_POINTS));
6313 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays_instanced", "Capture primitives generated with drawArraysInstanced", VertexFeedbackCase::METHOD_DRAW_ARRAYS_INSTANCED, VertexFeedbackCase::PRIMITIVE_POINTS));
6314 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_arrays_indirect", "Capture primitives generated with drawArraysIndirect", VertexFeedbackCase::METHOD_DRAW_ARRAYS_INDIRECT, VertexFeedbackCase::PRIMITIVE_POINTS));
6315 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements", "Capture primitives generated with drawElements", VertexFeedbackCase::METHOD_DRAW_ELEMENTS, VertexFeedbackCase::PRIMITIVE_POINTS));
6316 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements_instanced", "Capture primitives generated with drawElementsInstanced", VertexFeedbackCase::METHOD_DRAW_ELEMENTS_INSTANCED, VertexFeedbackCase::PRIMITIVE_POINTS));
6317 feedbackGroup->addChild(new VertexFeedbackCase(m_context, "capture_vertex_draw_elements_indirect", "Capture primitives generated with drawElementsIndirect", VertexFeedbackCase::METHOD_DRAW_ELEMENTS_INDIRECT, VertexFeedbackCase::PRIMITIVE_POINTS));
6319 feedbackGroup->addChild(new VertexFeedbackOverflowCase(m_context, "capture_vertex_draw_arrays_overflow_single_buffer", "Capture triangles to too small a buffer", VertexFeedbackOverflowCase::METHOD_DRAW_ARRAYS));
6320 feedbackGroup->addChild(new VertexFeedbackOverflowCase(m_context, "capture_vertex_draw_elements_overflow_single_buffer", "Capture triangles to too small a buffer", VertexFeedbackOverflowCase::METHOD_DRAW_ELEMENTS));