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 Tessellation Tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fTessellationTests.hpp"
25 #include "glsTextureTestUtil.hpp"
26 #include "glsShaderLibrary.hpp"
27 #include "glsStateQueryUtil.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "gluRenderContext.hpp"
30 #include "gluPixelTransfer.hpp"
31 #include "gluDrawUtil.hpp"
32 #include "gluObjectWrapper.hpp"
33 #include "gluStrUtil.hpp"
34 #include "gluContextInfo.hpp"
35 #include "gluVarType.hpp"
36 #include "gluVarTypeUtil.hpp"
37 #include "gluCallLogWrapper.hpp"
38 #include "tcuTestLog.hpp"
39 #include "tcuRenderTarget.hpp"
40 #include "tcuStringTemplate.hpp"
41 #include "tcuSurface.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuVectorUtil.hpp"
44 #include "tcuImageIO.hpp"
45 #include "tcuResource.hpp"
46 #include "tcuImageCompare.hpp"
47 #include "deRandom.hpp"
48 #include "deStringUtil.hpp"
49 #include "deSharedPtr.hpp"
50 #include "deUniquePtr.hpp"
54 #include "glwEnums.hpp"
55 #include "glwDefs.hpp"
56 #include "glwFunctions.hpp"
65 using glu::ShaderProgram;
66 using glu::RenderContext;
67 using tcu::RenderTarget;
78 using namespace glw; // For GL types.
83 using gls::TextureTestUtil::RandomViewport;
90 using namespace gls::StateQueryUtil;
94 MINIMUM_MAX_TESS_GEN_LEVEL = 64 //!< GL-defined minimum for GL_MAX_TESS_GEN_LEVEL.
97 static inline bool vec3XLessThan (const Vec3& a, const Vec3& b) { return a.x() < b.x(); }
99 template <typename IterT>
100 static string elemsStr (const IterT& begin, const IterT& end, int wrapLengthParam = 0, int numIndentationSpaces = 0)
102 const string baseIndentation = string(numIndentationSpaces, ' ');
103 const string deepIndentation = baseIndentation + string(4, ' ');
104 const int wrapLength = wrapLengthParam > 0 ? wrapLengthParam : std::numeric_limits<int>::max();
105 const int length = (int)std::distance(begin, end);
108 if (length > wrapLength)
109 result += "(amount: " + de::toString(length) + ") ";
110 result += string() + "{" + (length > wrapLength ? "\n"+deepIndentation : " ");
114 for (IterT it = begin; it != end; ++it)
117 result += string() + ", " + (index % wrapLength == 0 ? "\n"+deepIndentation : "");
118 result += de::toString(*it);
122 result += length > wrapLength ? "\n"+baseIndentation : " ";
129 template <typename ContainerT>
130 static string containerStr (const ContainerT& c, int wrapLengthParam = 0, int numIndentationSpaces = 0)
132 return elemsStr(c.begin(), c.end(), wrapLengthParam, numIndentationSpaces);
135 template <typename T, int N>
136 static string arrayStr (const T (&arr)[N], int wrapLengthParam = 0, int numIndentationSpaces = 0)
138 return elemsStr(DE_ARRAY_BEGIN(arr), DE_ARRAY_END(arr), wrapLengthParam, numIndentationSpaces);
141 template <typename T, int N>
142 static T arrayMax (const T (&arr)[N])
144 return *std::max_element(DE_ARRAY_BEGIN(arr), DE_ARRAY_END(arr));
147 template <typename T, typename MembT>
148 static vector<MembT> members (const vector<T>& objs, MembT T::* membP)
150 vector<MembT> result(objs.size());
151 for (int i = 0; i < (int)objs.size(); i++)
152 result[i] = objs[i].*membP;
156 template <typename T, int N>
157 static vector<T> arrayToVector (const T (&arr)[N])
159 return vector<T>(DE_ARRAY_BEGIN(arr), DE_ARRAY_END(arr));
162 template <typename ContainerT, typename T>
163 static inline bool contains (const ContainerT& c, const T& key)
165 return c.find(key) != c.end();
169 static inline tcu::Vector<bool, Size> singleTrueMask (int index)
171 DE_ASSERT(de::inBounds(index, 0, Size));
172 tcu::Vector<bool, Size> result;
173 result[index] = true;
177 static int intPow (int base, int exp)
184 const int sub = intPow(base, exp/2);
192 tcu::Surface getPixels (const glu::RenderContext& rCtx, int x, int y, int width, int height)
194 tcu::Surface result(width, height);
195 glu::readPixels(rCtx, x, y, result.getAccess());
199 tcu::Surface getPixels (const glu::RenderContext& rCtx, const RandomViewport& vp)
201 return getPixels(rCtx, vp.x, vp.y, vp.width, vp.height);
204 static inline void checkRenderTargetSize (const RenderTarget& renderTarget, int minSize)
206 if (renderTarget.getWidth() < minSize || renderTarget.getHeight() < minSize)
207 throw tcu::NotSupportedError("Render target width and height must be at least " + de::toString(minSize));
210 tcu::TextureLevel getPNG (const tcu::Archive& archive, const string& filename)
212 tcu::TextureLevel result;
213 tcu::ImageIO::loadPNG(result, archive, filename.c_str());
217 static int numBasicSubobjects (const glu::VarType& type)
219 if (type.isBasicType())
221 else if (type.isArrayType())
222 return type.getArraySize()*numBasicSubobjects(type.getElementType());
223 else if (type.isStructType())
225 const glu::StructType& structType = *type.getStructPtr();
227 for (int i = 0; i < structType.getNumMembers(); i++)
228 result += numBasicSubobjects(structType.getMember(i).getType());
238 static inline int numVerticesPerPrimitive (deUint32 primitiveTypeGL)
240 switch (primitiveTypeGL)
242 case GL_POINTS: return 1;
243 case GL_TRIANGLES: return 3;
244 case GL_LINES: return 2;
251 static inline void setViewport (const glw::Functions& gl, const RandomViewport& vp)
253 gl.viewport(vp.x, vp.y, vp.width, vp.height);
256 static inline deUint32 getQueryResult (const glw::Functions& gl, deUint32 queryObject)
258 deUint32 result = (deUint32)-1;
259 gl.getQueryObjectuiv(queryObject, GL_QUERY_RESULT, &result);
260 TCU_CHECK(result != (deUint32)-1);
264 template <typename T>
265 static void readDataMapped (const glw::Functions& gl, deUint32 bufferTarget, int numElems, T* dst)
267 const int numBytes = numElems*(int)sizeof(T);
268 const T* const mappedData = (const T*)gl.mapBufferRange(bufferTarget, 0, numBytes, GL_MAP_READ_BIT);
269 GLU_EXPECT_NO_ERROR(gl.getError(), (string() + "glMapBufferRange(" + glu::getBufferTargetName((int)bufferTarget) + ", 0, " + de::toString(numBytes) + ", GL_MAP_READ_BIT)").c_str());
270 TCU_CHECK(mappedData != DE_NULL);
272 for (int i = 0; i < numElems; i++)
273 dst[i] = mappedData[i];
275 gl.unmapBuffer(bufferTarget);
278 template <typename T>
279 static vector<T> readDataMapped (const glw::Functions& gl, deUint32 bufferTarget, int numElems)
281 vector<T> result(numElems);
282 readDataMapped(gl, bufferTarget, numElems, &result[0]);
289 template <typename ArgT, bool res>
290 struct ConstantUnaryPredicate
292 bool operator() (const ArgT&) const { return res; }
295 //! Helper for handling simple, one-varying transform feedbacks.
296 template <typename VaryingT>
297 class TransformFeedbackHandler
303 vector<VaryingT> varying;
305 Result (void) : numPrimitives(-1) {}
306 Result (int n, const vector<VaryingT>& v) : numPrimitives(n), varying(v) {}
309 TransformFeedbackHandler (const glu::RenderContext& renderCtx, int maxNumVertices);
311 Result renderAndGetPrimitives (deUint32 programGL, deUint32 tfPrimTypeGL, int numBindings, const glu::VertexArrayBinding* bindings, int numVertices) const;
314 const glu::RenderContext& m_renderCtx;
315 const glu::TransformFeedback m_tf;
316 const glu::Buffer m_tfBuffer;
317 const glu::Query m_tfPrimQuery;
320 template <typename AttribType>
321 TransformFeedbackHandler<AttribType>::TransformFeedbackHandler (const glu::RenderContext& renderCtx, int maxNumVertices)
322 : m_renderCtx (renderCtx)
324 , m_tfBuffer (renderCtx)
325 , m_tfPrimQuery (renderCtx)
327 const glw::Functions& gl = m_renderCtx.getFunctions();
328 // \note Room for 1 extra triangle, to detect if GL returns too many primitives.
329 const int bufferSize = (maxNumVertices + 3) * (int)sizeof(AttribType);
331 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, *m_tfBuffer);
332 gl.bufferData(GL_TRANSFORM_FEEDBACK_BUFFER, bufferSize, DE_NULL, GL_DYNAMIC_READ);
335 template <typename AttribType>
336 typename TransformFeedbackHandler<AttribType>::Result TransformFeedbackHandler<AttribType>::renderAndGetPrimitives (deUint32 programGL, deUint32 tfPrimTypeGL, int numBindings, const glu::VertexArrayBinding* bindings, int numVertices) const
338 DE_ASSERT(tfPrimTypeGL == GL_POINTS || tfPrimTypeGL == GL_LINES || tfPrimTypeGL == GL_TRIANGLES);
340 const glw::Functions& gl = m_renderCtx.getFunctions();
342 gl.bindTransformFeedback(GL_TRANSFORM_FEEDBACK, *m_tf);
343 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, *m_tfBuffer);
344 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, *m_tfBuffer);
346 gl.beginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, *m_tfPrimQuery);
347 gl.beginTransformFeedback(tfPrimTypeGL);
349 glu::draw(m_renderCtx, programGL, numBindings, bindings, glu::pr::Patches(numVertices));
350 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
352 gl.endTransformFeedback();
353 gl.endQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
356 const int numPrimsWritten = (int)getQueryResult(gl, *m_tfPrimQuery);
357 return Result(numPrimsWritten, readDataMapped<AttribType>(gl, GL_TRANSFORM_FEEDBACK_BUFFER, numPrimsWritten * numVerticesPerPrimitive(tfPrimTypeGL)));
361 template <typename T>
365 bool operator() (const T& a, const T& b) const { return a.size() < b.size(); }
368 //! Predicate functor for comparing structs by their members.
369 template <typename Pred, typename T, typename MembT>
373 MemberPred (MembT T::* membP) : m_membP(membP), m_pred(Pred()) {}
374 bool operator() (const T& a, const T& b) const { return m_pred(a.*m_membP, b.*m_membP); }
381 //! Convenience wrapper for MemberPred, because class template arguments aren't deduced based on constructor arguments.
382 template <template <typename> class Pred, typename T, typename MembT>
383 static MemberPred<Pred<MembT>, T, MembT> memberPred (MembT T::* membP) { return MemberPred<Pred<MembT>, T, MembT>(membP); }
385 template <typename SeqT, int Size, typename Pred>
389 LexCompare (void) : m_pred(Pred()) {}
391 bool operator() (const SeqT& a, const SeqT& b) const
393 for (int i = 0; i < Size; i++)
395 if (m_pred(a[i], b[i]))
397 if (m_pred(b[i], a[i]))
408 class VecLexLessThan : public LexCompare<tcu::Vector<float, Size>, Size, std::less<float> >
412 enum TessPrimitiveType
414 TESSPRIMITIVETYPE_TRIANGLES = 0,
415 TESSPRIMITIVETYPE_QUADS,
416 TESSPRIMITIVETYPE_ISOLINES,
418 TESSPRIMITIVETYPE_LAST
424 SPACINGMODE_FRACTIONAL_ODD,
425 SPACINGMODE_FRACTIONAL_EVEN,
438 static inline const char* getTessPrimitiveTypeShaderName (TessPrimitiveType type)
442 case TESSPRIMITIVETYPE_TRIANGLES: return "triangles";
443 case TESSPRIMITIVETYPE_QUADS: return "quads";
444 case TESSPRIMITIVETYPE_ISOLINES: return "isolines";
451 static inline const char* getSpacingModeShaderName (SpacingMode mode)
455 case SPACINGMODE_EQUAL: return "equal_spacing";
456 case SPACINGMODE_FRACTIONAL_ODD: return "fractional_odd_spacing";
457 case SPACINGMODE_FRACTIONAL_EVEN: return "fractional_even_spacing";
464 static inline const char* getWindingShaderName (Winding winding)
468 case WINDING_CCW: return "ccw";
469 case WINDING_CW: return "cw";
476 static inline string getTessellationEvaluationInLayoutString (TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode=false)
478 return string() + "layout (" + getTessPrimitiveTypeShaderName(primType)
479 + ", " + getSpacingModeShaderName(spacing)
480 + ", " + getWindingShaderName(winding)
481 + (usePointMode ? ", point_mode" : "")
485 static inline string getTessellationEvaluationInLayoutString (TessPrimitiveType primType, SpacingMode spacing, bool usePointMode=false)
487 return string() + "layout (" + getTessPrimitiveTypeShaderName(primType)
488 + ", " + getSpacingModeShaderName(spacing)
489 + (usePointMode ? ", point_mode" : "")
493 static inline string getTessellationEvaluationInLayoutString (TessPrimitiveType primType, Winding winding, bool usePointMode=false)
495 return string() + "layout (" + getTessPrimitiveTypeShaderName(primType)
496 + ", " + getWindingShaderName(winding)
497 + (usePointMode ? ", point_mode" : "")
501 static inline string getTessellationEvaluationInLayoutString (TessPrimitiveType primType, bool usePointMode=false)
503 return string() + "layout (" + getTessPrimitiveTypeShaderName(primType)
504 + (usePointMode ? ", point_mode" : "")
508 static inline deUint32 outputPrimitiveTypeGL (TessPrimitiveType tessPrimType, bool usePointMode)
514 switch (tessPrimType)
516 case TESSPRIMITIVETYPE_TRIANGLES: return GL_TRIANGLES;
517 case TESSPRIMITIVETYPE_QUADS: return GL_TRIANGLES;
518 case TESSPRIMITIVETYPE_ISOLINES: return GL_LINES;
526 static inline int numInnerTessellationLevels (TessPrimitiveType primType)
530 case TESSPRIMITIVETYPE_TRIANGLES: return 1;
531 case TESSPRIMITIVETYPE_QUADS: return 2;
532 case TESSPRIMITIVETYPE_ISOLINES: return 0;
533 default: DE_ASSERT(false); return -1;
537 static inline int numOuterTessellationLevels (TessPrimitiveType primType)
541 case TESSPRIMITIVETYPE_TRIANGLES: return 3;
542 case TESSPRIMITIVETYPE_QUADS: return 4;
543 case TESSPRIMITIVETYPE_ISOLINES: return 2;
544 default: DE_ASSERT(false); return -1;
548 static string tessellationLevelsString (const float* inner, int numInner, const float* outer, int numOuter)
550 DE_ASSERT(numInner >= 0 && numOuter >= 0);
551 return "inner: " + elemsStr(inner, inner+numInner) + ", outer: " + elemsStr(outer, outer+numOuter);
554 static string tessellationLevelsString (const float* inner, const float* outer, TessPrimitiveType primType)
556 return tessellationLevelsString(inner, numInnerTessellationLevels(primType), outer, numOuterTessellationLevels(primType));
559 static string tessellationLevelsString (const float* inner, const float* outer)
561 return tessellationLevelsString(inner, 2, outer, 4);
564 static inline float getClampedTessLevel (SpacingMode mode, float tessLevel)
568 case SPACINGMODE_EQUAL: return de::max(1.0f, tessLevel);
569 case SPACINGMODE_FRACTIONAL_ODD: return de::max(1.0f, tessLevel);
570 case SPACINGMODE_FRACTIONAL_EVEN: return de::max(2.0f, tessLevel);
577 static inline int getRoundedTessLevel (SpacingMode mode, float clampedTessLevel)
579 int result = (int)deFloatCeil(clampedTessLevel);
583 case SPACINGMODE_EQUAL: break;
584 case SPACINGMODE_FRACTIONAL_ODD: result += 1 - result % 2; break;
585 case SPACINGMODE_FRACTIONAL_EVEN: result += result % 2; break;
589 DE_ASSERT(de::inRange<int>(result, 1, MINIMUM_MAX_TESS_GEN_LEVEL));
594 static int getClampedRoundedTessLevel (SpacingMode mode, float tessLevel)
596 return getRoundedTessLevel(mode, getClampedTessLevel(mode, tessLevel));
599 //! A description of an outer edge of a triangle, quad or isolines.
600 //! An outer edge can be described by the index of a u/v/w coordinate
601 //! and the coordinate's value along that edge.
602 struct OuterEdgeDescription
604 int constantCoordinateIndex;
605 float constantCoordinateValueChoices[2];
606 int numConstantCoordinateValueChoices;
608 OuterEdgeDescription (int i, float c0) : constantCoordinateIndex(i), numConstantCoordinateValueChoices(1) { constantCoordinateValueChoices[0] = c0; }
609 OuterEdgeDescription (int i, float c0, float c1) : constantCoordinateIndex(i), numConstantCoordinateValueChoices(2) { constantCoordinateValueChoices[0] = c0; constantCoordinateValueChoices[1] = c1; }
611 string description (void) const
613 static const char* const coordinateNames[] = { "u", "v", "w" };
615 for (int i = 0; i < numConstantCoordinateValueChoices; i++)
616 result += string() + (i > 0 ? " or " : "") + coordinateNames[constantCoordinateIndex] + "=" + de::toString(constantCoordinateValueChoices[i]);
620 bool contains (const Vec3& v) const
622 for (int i = 0; i < numConstantCoordinateValueChoices; i++)
623 if (v[constantCoordinateIndex] == constantCoordinateValueChoices[i])
629 static vector<OuterEdgeDescription> outerEdgeDescriptions (TessPrimitiveType primType)
631 static const OuterEdgeDescription triangleOuterEdgeDescriptions[3] =
633 OuterEdgeDescription(0, 0.0f),
634 OuterEdgeDescription(1, 0.0f),
635 OuterEdgeDescription(2, 0.0f)
638 static const OuterEdgeDescription quadOuterEdgeDescriptions[4] =
640 OuterEdgeDescription(0, 0.0f),
641 OuterEdgeDescription(1, 0.0f),
642 OuterEdgeDescription(0, 1.0f),
643 OuterEdgeDescription(1, 1.0f)
646 static const OuterEdgeDescription isolinesOuterEdgeDescriptions[1] =
648 OuterEdgeDescription(0, 0.0f, 1.0f),
653 case TESSPRIMITIVETYPE_TRIANGLES: return arrayToVector(triangleOuterEdgeDescriptions);
654 case TESSPRIMITIVETYPE_QUADS: return arrayToVector(quadOuterEdgeDescriptions);
655 case TESSPRIMITIVETYPE_ISOLINES: return arrayToVector(isolinesOuterEdgeDescriptions);
656 default: DE_ASSERT(false); return vector<OuterEdgeDescription>();
660 // \note The tessellation coordinates generated by this function could break some of the rules given in the spec (e.g. it may not exactly hold that u+v+w == 1.0f, or [uvw] + (1.0f-[uvw]) == 1.0f).
661 static vector<Vec3> generateReferenceTriangleTessCoords (SpacingMode spacingMode, int inner, int outer0, int outer1, int outer2)
663 vector<Vec3> tessCoords;
667 if (outer0 == 1 && outer1 == 1 && outer2 == 1)
669 tessCoords.push_back(Vec3(1.0f, 0.0f, 0.0f));
670 tessCoords.push_back(Vec3(0.0f, 1.0f, 0.0f));
671 tessCoords.push_back(Vec3(0.0f, 0.0f, 1.0f));
675 return generateReferenceTriangleTessCoords(spacingMode, spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
676 outer0, outer1, outer2);
680 for (int i = 0; i < outer0; i++) { const float v = (float)i / (float)outer0; tessCoords.push_back(Vec3( 0.0f, v, 1.0f - v)); }
681 for (int i = 0; i < outer1; i++) { const float v = (float)i / (float)outer1; tessCoords.push_back(Vec3(1.0f - v, 0.0f, v)); }
682 for (int i = 0; i < outer2; i++) { const float v = (float)i / (float)outer2; tessCoords.push_back(Vec3( v, 1.0f - v, 0.0f)); }
684 const int numInnerTriangles = inner/2;
685 for (int innerTriangleNdx = 0; innerTriangleNdx < numInnerTriangles; innerTriangleNdx++)
687 const int curInnerTriangleLevel = inner - 2*(innerTriangleNdx+1);
689 if (curInnerTriangleLevel == 0)
690 tessCoords.push_back(Vec3(1.0f/3.0f));
693 const float minUVW = (float)(2 * (innerTriangleNdx + 1)) / (float)(3 * inner);
694 const float maxUVW = 1.0f - 2.0f*minUVW;
695 const Vec3 corners[3] =
697 Vec3(maxUVW, minUVW, minUVW),
698 Vec3(minUVW, maxUVW, minUVW),
699 Vec3(minUVW, minUVW, maxUVW)
702 for (int i = 0; i < curInnerTriangleLevel; i++)
704 const float f = (float)i / (float)curInnerTriangleLevel;
705 for (int j = 0; j < 3; j++)
706 tessCoords.push_back((1.0f - f)*corners[j] + f*corners[(j+1)%3]);
715 static int referenceTriangleNonPointModePrimitiveCount (SpacingMode spacingMode, int inner, int outer0, int outer1, int outer2)
719 if (outer0 == 1 && outer1 == 1 && outer2 == 1)
722 return referenceTriangleNonPointModePrimitiveCount(spacingMode, spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
723 outer0, outer1, outer2);
727 int result = outer0 + outer1 + outer2;
729 const int numInnerTriangles = inner/2;
730 for (int innerTriangleNdx = 0; innerTriangleNdx < numInnerTriangles; innerTriangleNdx++)
732 const int curInnerTriangleLevel = inner - 2*(innerTriangleNdx+1);
734 if (curInnerTriangleLevel == 1)
737 result += 2*3*curInnerTriangleLevel;
744 // \note The tessellation coordinates generated by this function could break some of the rules given in the spec (e.g. it may not exactly hold that [uv] + (1.0f-[uv]) == 1.0f).
745 static vector<Vec3> generateReferenceQuadTessCoords (SpacingMode spacingMode, int inner0, int inner1, int outer0, int outer1, int outer2, int outer3)
747 vector<Vec3> tessCoords;
749 if (inner0 == 1 || inner1 == 1)
751 if (inner0 == 1 && inner1 == 1 && outer0 == 1 && outer1 == 1 && outer2 == 1 && outer3 == 1)
753 tessCoords.push_back(Vec3(0.0f, 0.0f, 0.0f));
754 tessCoords.push_back(Vec3(1.0f, 0.0f, 0.0f));
755 tessCoords.push_back(Vec3(0.0f, 1.0f, 0.0f));
756 tessCoords.push_back(Vec3(1.0f, 1.0f, 0.0f));
760 return generateReferenceQuadTessCoords(spacingMode, inner0 > 1 ? inner0 : spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
761 inner1 > 1 ? inner1 : spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
762 outer0, outer1, outer2, outer3);
766 for (int i = 0; i < outer0; i++) { const float v = (float)i / (float)outer0; tessCoords.push_back(Vec3(0.0f, v, 0.0f)); }
767 for (int i = 0; i < outer1; i++) { const float v = (float)i / (float)outer1; tessCoords.push_back(Vec3(1.0f-v, 0.0f, 0.0f)); }
768 for (int i = 0; i < outer2; i++) { const float v = (float)i / (float)outer2; tessCoords.push_back(Vec3(1.0f, 1.0f-v, 0.0f)); }
769 for (int i = 0; i < outer3; i++) { const float v = (float)i / (float)outer3; tessCoords.push_back(Vec3(v, 1.0f, 0.0f)); }
771 for (int innerVtxY = 0; innerVtxY < inner1-1; innerVtxY++)
772 for (int innerVtxX = 0; innerVtxX < inner0-1; innerVtxX++)
773 tessCoords.push_back(Vec3((float)(innerVtxX + 1) / (float)inner0,
774 (float)(innerVtxY + 1) / (float)inner1,
781 static int referenceQuadNonPointModePrimitiveCount (SpacingMode spacingMode, int inner0, int inner1, int outer0, int outer1, int outer2, int outer3)
783 vector<Vec3> tessCoords;
785 if (inner0 == 1 || inner1 == 1)
787 if (inner0 == 1 && inner1 == 1 && outer0 == 1 && outer1 == 1 && outer2 == 1 && outer3 == 1)
790 return referenceQuadNonPointModePrimitiveCount(spacingMode, inner0 > 1 ? inner0 : spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
791 inner1 > 1 ? inner1 : spacingMode == SPACINGMODE_FRACTIONAL_ODD ? 3 : 2,
792 outer0, outer1, outer2, outer3);
795 return 2*(inner0-2)*(inner1-2) + 2*(inner0-2) + 2*(inner1-2) + outer0+outer1+outer2+outer3;
798 // \note The tessellation coordinates generated by this function could break some of the rules given in the spec (e.g. it may not exactly hold that [uv] + (1.0f-[uv]) == 1.0f).
799 static vector<Vec3> generateReferenceIsolineTessCoords (int outer0, int outer1)
801 vector<Vec3> tessCoords;
803 for (int y = 0; y < outer0; y++)
804 for (int x = 0; x < outer1+1; x++)
805 tessCoords.push_back(Vec3((float)x / (float)outer1,
806 (float)y / (float)outer0,
812 static int referenceIsolineNonPointModePrimitiveCount (int outer0, int outer1)
814 return outer0*outer1;
817 static void getClampedRoundedTriangleTessLevels (SpacingMode spacingMode, const float* innerSrc, const float* outerSrc, int* innerDst, int *outerDst)
819 innerDst[0] = getClampedRoundedTessLevel(spacingMode, innerSrc[0]);
820 for (int i = 0; i < 3; i++)
821 outerDst[i] = getClampedRoundedTessLevel(spacingMode, outerSrc[i]);
824 static void getClampedRoundedQuadTessLevels (SpacingMode spacingMode, const float* innerSrc, const float* outerSrc, int* innerDst, int *outerDst)
826 for (int i = 0; i < 2; i++)
827 innerDst[i] = getClampedRoundedTessLevel(spacingMode, innerSrc[i]);
828 for (int i = 0; i < 4; i++)
829 outerDst[i] = getClampedRoundedTessLevel(spacingMode, outerSrc[i]);
832 static void getClampedRoundedIsolineTessLevels (SpacingMode spacingMode, const float* outerSrc, int* outerDst)
834 outerDst[0] = getClampedRoundedTessLevel(SPACINGMODE_EQUAL, outerSrc[0]);
835 outerDst[1] = getClampedRoundedTessLevel(spacingMode, outerSrc[1]);
838 static inline bool isPatchDiscarded (TessPrimitiveType primitiveType, const float* outerLevels)
840 const int numOuterLevels = numOuterTessellationLevels(primitiveType);
841 for (int i = 0; i < numOuterLevels; i++)
842 if (outerLevels[i] <= 0.0f)
847 static vector<Vec3> generateReferenceTessCoords (TessPrimitiveType primitiveType, SpacingMode spacingMode, const float* innerLevels, const float* outerLevels)
849 if (isPatchDiscarded(primitiveType, outerLevels))
850 return vector<Vec3>();
852 switch (primitiveType)
854 case TESSPRIMITIVETYPE_TRIANGLES:
858 getClampedRoundedTriangleTessLevels(spacingMode, innerLevels, outerLevels, &inner, &outer[0]);
860 if (spacingMode != SPACINGMODE_EQUAL)
862 // \note For fractional spacing modes, exact results are implementation-defined except in special cases.
863 DE_ASSERT(de::abs(innerLevels[0] - (float)inner) < 0.001f);
864 for (int i = 0; i < 3; i++)
865 DE_ASSERT(de::abs(outerLevels[i] - (float)outer[i]) < 0.001f);
866 DE_ASSERT(inner > 1 || (outer[0] == 1 && outer[1] == 1 && outer[2] == 1));
869 return generateReferenceTriangleTessCoords(spacingMode, inner, outer[0], outer[1], outer[2]);
872 case TESSPRIMITIVETYPE_QUADS:
876 getClampedRoundedQuadTessLevels(spacingMode, innerLevels, outerLevels, &inner[0], &outer[0]);
878 if (spacingMode != SPACINGMODE_EQUAL)
880 // \note For fractional spacing modes, exact results are implementation-defined except in special cases.
881 for (int i = 0; i < 2; i++)
882 DE_ASSERT(de::abs(innerLevels[i] - (float)inner[i]) < 0.001f);
883 for (int i = 0; i < 4; i++)
884 DE_ASSERT(de::abs(outerLevels[i] - (float)outer[i]) < 0.001f);
886 DE_ASSERT((inner[0] > 1 && inner[1] > 1) || (inner[0] == 1 && inner[1] == 1 && outer[0] == 1 && outer[1] == 1 && outer[2] == 1 && outer[3] == 1));
889 return generateReferenceQuadTessCoords(spacingMode, inner[0], inner[1], outer[0], outer[1], outer[2], outer[3]);
892 case TESSPRIMITIVETYPE_ISOLINES:
895 getClampedRoundedIsolineTessLevels(spacingMode, &outerLevels[0], &outer[0]);
897 if (spacingMode != SPACINGMODE_EQUAL)
899 // \note For fractional spacing modes, exact results are implementation-defined except in special cases.
900 DE_ASSERT(de::abs(outerLevels[1] - (float)outer[1]) < 0.001f);
903 return generateReferenceIsolineTessCoords(outer[0], outer[1]);
908 return vector<Vec3>();
912 static int referencePointModePrimitiveCount (TessPrimitiveType primitiveType, SpacingMode spacingMode, const float* innerLevels, const float* outerLevels)
914 if (isPatchDiscarded(primitiveType, outerLevels))
917 switch (primitiveType)
919 case TESSPRIMITIVETYPE_TRIANGLES:
923 getClampedRoundedTriangleTessLevels(spacingMode, innerLevels, outerLevels, &inner, &outer[0]);
924 return (int)generateReferenceTriangleTessCoords(spacingMode, inner, outer[0], outer[1], outer[2]).size();
927 case TESSPRIMITIVETYPE_QUADS:
931 getClampedRoundedQuadTessLevels(spacingMode, innerLevels, outerLevels, &inner[0], &outer[0]);
932 return (int)generateReferenceQuadTessCoords(spacingMode, inner[0], inner[1], outer[0], outer[1], outer[2], outer[3]).size();
935 case TESSPRIMITIVETYPE_ISOLINES:
938 getClampedRoundedIsolineTessLevels(spacingMode, &outerLevels[0], &outer[0]);
939 return (int)generateReferenceIsolineTessCoords(outer[0], outer[1]).size();
948 static int referenceNonPointModePrimitiveCount (TessPrimitiveType primitiveType, SpacingMode spacingMode, const float* innerLevels, const float* outerLevels)
950 if (isPatchDiscarded(primitiveType, outerLevels))
953 switch (primitiveType)
955 case TESSPRIMITIVETYPE_TRIANGLES:
959 getClampedRoundedTriangleTessLevels(spacingMode, innerLevels, outerLevels, &inner, &outer[0]);
960 return referenceTriangleNonPointModePrimitiveCount(spacingMode, inner, outer[0], outer[1], outer[2]);
963 case TESSPRIMITIVETYPE_QUADS:
967 getClampedRoundedQuadTessLevels(spacingMode, innerLevels, outerLevels, &inner[0], &outer[0]);
968 return referenceQuadNonPointModePrimitiveCount(spacingMode, inner[0], inner[1], outer[0], outer[1], outer[2], outer[3]);
971 case TESSPRIMITIVETYPE_ISOLINES:
974 getClampedRoundedIsolineTessLevels(spacingMode, &outerLevels[0], &outer[0]);
975 return referenceIsolineNonPointModePrimitiveCount(outer[0], outer[1]);
984 static int referencePrimitiveCount (TessPrimitiveType primitiveType, SpacingMode spacingMode, bool usePointMode, const float* innerLevels, const float* outerLevels)
986 return usePointMode ? referencePointModePrimitiveCount (primitiveType, spacingMode, innerLevels, outerLevels)
987 : referenceNonPointModePrimitiveCount (primitiveType, spacingMode, innerLevels, outerLevels);
990 static int referenceVertexCount (TessPrimitiveType primitiveType, SpacingMode spacingMode, bool usePointMode, const float* innerLevels, const float* outerLevels)
992 return referencePrimitiveCount(primitiveType, spacingMode, usePointMode, innerLevels, outerLevels)
993 * numVerticesPerPrimitive(outputPrimitiveTypeGL(primitiveType, usePointMode));
996 //! Helper for calling referenceVertexCount multiple times with different tessellation levels.
997 //! \note Levels contains inner and outer levels, per patch, in order IIOOOO. The full 6 levels must always be present, irrespective of primitiveType.
998 static int multiplePatchReferenceVertexCount (TessPrimitiveType primitiveType, SpacingMode spacingMode, bool usePointMode, const float* levels, int numPatches)
1001 for (int patchNdx = 0; patchNdx < numPatches; patchNdx++)
1002 result += referenceVertexCount(primitiveType, spacingMode, usePointMode, &levels[6*patchNdx + 0], &levels[6*patchNdx + 2]);
1006 vector<float> generateRandomPatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel, de::Random& rnd)
1008 vector<float> tessLevels(numPatches*6);
1010 for (int patchNdx = 0; patchNdx < numPatches; patchNdx++)
1012 float* const inner = &tessLevels[patchNdx*6 + 0];
1013 float* const outer = &tessLevels[patchNdx*6 + 2];
1015 for (int j = 0; j < 2; j++)
1016 inner[j] = rnd.getFloat(1.0f, 62.0f);
1017 for (int j = 0; j < 4; j++)
1018 outer[j] = j == constantOuterLevelIndex ? constantOuterLevel : rnd.getFloat(1.0f, 62.0f);
1024 static inline void drawPoint (tcu::Surface& dst, int centerX, int centerY, const tcu::RGBA& color, int size)
1026 const int width = dst.getWidth();
1027 const int height = dst.getHeight();
1028 DE_ASSERT(de::inBounds(centerX, 0, width) && de::inBounds(centerY, 0, height));
1029 DE_ASSERT(size > 0);
1031 for (int yOff = -((size-1)/2); yOff <= size/2; yOff++)
1032 for (int xOff = -((size-1)/2); xOff <= size/2; xOff++)
1034 const int pixX = centerX + xOff;
1035 const int pixY = centerY + yOff;
1036 if (de::inBounds(pixX, 0, width) && de::inBounds(pixY, 0, height))
1037 dst.setPixel(pixX, pixY, color);
1041 static void drawTessCoordPoint (tcu::Surface& dst, TessPrimitiveType primitiveType, const Vec3& pt, const tcu::RGBA& color, int size)
1043 // \note These coordinates should match the description in the log message in TessCoordCase::iterate.
1045 static const Vec2 triangleCorners[3] =
1048 Vec2(0.5f, 0.95f - 0.9f*deFloatSqrt(3.0f/4.0f)),
1052 static const float quadIsolineLDRU[4] =
1054 0.1f, 0.9f, 0.9f, 0.1f
1057 const Vec2 dstPos = primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? pt.x()*triangleCorners[0]
1058 + pt.y()*triangleCorners[1]
1059 + pt.z()*triangleCorners[2]
1061 : primitiveType == TESSPRIMITIVETYPE_QUADS ||
1062 primitiveType == TESSPRIMITIVETYPE_ISOLINES ? Vec2((1.0f - pt.x())*quadIsolineLDRU[0] + pt.x()*quadIsolineLDRU[2],
1063 (1.0f - pt.y())*quadIsolineLDRU[1] + pt.y()*quadIsolineLDRU[3])
1067 drawPoint(dst, (int)(dstPos.x() * (float)dst.getWidth()), (int)(dstPos.y() * (float)dst.getHeight()), color, size);
1070 static void drawTessCoordVisualization (tcu::Surface& dst, TessPrimitiveType primitiveType, const vector<Vec3>& coords)
1072 const int imageWidth = 256;
1073 const int imageHeight = 256;
1074 dst.setSize(imageWidth, imageHeight);
1076 tcu::clear(dst.getAccess(), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
1078 for (int i = 0; i < (int)coords.size(); i++)
1079 drawTessCoordPoint(dst, primitiveType, coords[i], tcu::RGBA::white(), 2);
1082 static int binarySearchFirstVec3WithXAtLeast (const vector<Vec3>& sorted, float x)
1084 const Vec3 ref(x, 0.0f, 0.0f);
1085 const vector<Vec3>::const_iterator first = std::lower_bound(sorted.begin(), sorted.end(), ref, vec3XLessThan);
1086 if (first == sorted.end())
1088 return (int)std::distance(sorted.begin(), first);
1091 template <typename T, typename P>
1092 static vector<T> sorted (const vector<T>& unsorted, P pred)
1094 vector<T> result = unsorted;
1095 std::sort(result.begin(), result.end(), pred);
1099 template <typename T>
1100 static vector<T> sorted (const vector<T>& unsorted)
1102 vector<T> result = unsorted;
1103 std::sort(result.begin(), result.end());
1107 // Check that all points in subset are (approximately) present also in superset.
1108 static bool oneWayComparePointSets (TestLog& log,
1109 tcu::Surface& errorDst,
1110 TessPrimitiveType primitiveType,
1111 const vector<Vec3>& subset,
1112 const vector<Vec3>& superset,
1113 const char* subsetName,
1114 const char* supersetName,
1115 const tcu::RGBA& errorColor)
1117 const vector<Vec3> supersetSorted = sorted(superset, vec3XLessThan);
1118 const float epsilon = 0.01f;
1119 const int maxNumFailurePrints = 5;
1120 int numFailuresDetected = 0;
1122 for (int subNdx = 0; subNdx < (int)subset.size(); subNdx++)
1124 const Vec3& subPt = subset[subNdx];
1126 bool matchFound = false;
1129 // Binary search the index of the first point in supersetSorted with x in the [subPt.x() - epsilon, subPt.x() + epsilon] range.
1130 const Vec3 matchMin = subPt - epsilon;
1131 const Vec3 matchMax = subPt + epsilon;
1132 int firstCandidateNdx = binarySearchFirstVec3WithXAtLeast(supersetSorted, matchMin.x());
1134 if (firstCandidateNdx >= 0)
1136 // Compare subPt to all points in supersetSorted with x in the [subPt.x() - epsilon, subPt.x() + epsilon] range.
1137 for (int superNdx = firstCandidateNdx; superNdx < (int)supersetSorted.size() && supersetSorted[superNdx].x() <= matchMax.x(); superNdx++)
1139 const Vec3& superPt = supersetSorted[superNdx];
1141 if (tcu::boolAll(tcu::greaterThanEqual (superPt, matchMin)) &&
1142 tcu::boolAll(tcu::lessThanEqual (superPt, matchMax)))
1153 numFailuresDetected++;
1154 if (numFailuresDetected < maxNumFailurePrints)
1155 log << TestLog::Message << "Failure: no matching " << supersetName << " point found for " << subsetName << " point " << subPt << TestLog::EndMessage;
1156 else if (numFailuresDetected == maxNumFailurePrints)
1157 log << TestLog::Message << "Note: More errors follow" << TestLog::EndMessage;
1159 drawTessCoordPoint(errorDst, primitiveType, subPt, errorColor, 4);
1163 return numFailuresDetected == 0;
1166 static bool compareTessCoords (TestLog& log, TessPrimitiveType primitiveType, const vector<Vec3>& refCoords, const vector<Vec3>& resCoords)
1168 tcu::Surface refVisual;
1169 tcu::Surface resVisual;
1170 bool success = true;
1172 drawTessCoordVisualization(refVisual, primitiveType, refCoords);
1173 drawTessCoordVisualization(resVisual, primitiveType, resCoords);
1175 // Check that all points in reference also exist in result.
1176 success = oneWayComparePointSets(log, refVisual, primitiveType, refCoords, resCoords, "reference", "result", tcu::RGBA::blue()) && success;
1177 // Check that all points in result also exist in reference.
1178 success = oneWayComparePointSets(log, resVisual, primitiveType, resCoords, refCoords, "result", "reference", tcu::RGBA::red()) && success;
1182 log << TestLog::Message << "Note: in the following reference visualization, points that are missing in result point set are blue (if any)" << TestLog::EndMessage
1183 << TestLog::Image("RefTessCoordVisualization", "Reference tessCoord visualization", refVisual)
1184 << TestLog::Message << "Note: in the following result visualization, points that are missing in reference point set are red (if any)" << TestLog::EndMessage;
1187 log << TestLog::Image("ResTessCoordVisualization", "Result tessCoord visualization", resVisual);
1192 namespace VerifyFractionalSpacingSingleInternal
1197 int index; //!< Index of left coordinate in sortedXCoords.
1199 Segment (void) : index(-1), length(-1.0f) {}
1200 Segment (int index_, float length_) : index(index_), length(length_) {}
1202 static vector<float> lengths (const vector<Segment>& segments) { return members(segments, &Segment::length); }
1207 /*--------------------------------------------------------------------*//*!
1208 * \brief Verify fractional spacing conditions for a single line
1210 * Verify that the splitting of an edge (resulting from e.g. an isoline
1211 * with outer levels { 1.0, tessLevel }) with a given fractional spacing
1212 * mode fulfills certain conditions given in the spec.
1214 * Note that some conditions can't be checked from just one line
1215 * (specifically, that the additional segment decreases monotonically
1216 * length and the requirement that the additional segments be placed
1217 * identically for identical values of clamped level).
1219 * Therefore, the function stores some values to additionalSegmentLengthDst
1220 * and additionalSegmentLocationDst that can later be given to
1221 * verifyFractionalSpacingMultiple(). A negative value in length means that
1222 * no additional segments are present, i.e. there's just one segment.
1223 * A negative value in location means that the value wasn't determinable,
1224 * i.e. all segments had same length.
1225 * The values are not stored if false is returned.
1226 *//*--------------------------------------------------------------------*/
1227 static bool verifyFractionalSpacingSingle (TestLog& log, SpacingMode spacingMode, float tessLevel, const vector<float>& coords, float& additionalSegmentLengthDst, int& additionalSegmentLocationDst)
1229 using namespace VerifyFractionalSpacingSingleInternal;
1231 DE_ASSERT(spacingMode == SPACINGMODE_FRACTIONAL_ODD || spacingMode == SPACINGMODE_FRACTIONAL_EVEN);
1233 const float clampedLevel = getClampedTessLevel(spacingMode, tessLevel);
1234 const int finalLevel = getRoundedTessLevel(spacingMode, clampedLevel);
1235 const vector<float> sortedCoords = sorted(coords);
1236 string failNote = "Note: tessellation level is " + de::toString(tessLevel) + "\nNote: sorted coordinates are:\n " + containerStr(sortedCoords);
1238 if ((int)coords.size() != finalLevel + 1)
1240 log << TestLog::Message << "Failure: number of vertices is " << coords.size() << "; expected " << finalLevel + 1
1241 << " (clamped tessellation level is " << clampedLevel << ")"
1242 << "; final level (clamped level rounded up to " << (spacingMode == SPACINGMODE_FRACTIONAL_EVEN ? "even" : "odd") << ") is " << finalLevel
1243 << " and should equal the number of segments, i.e. number of vertices minus 1" << TestLog::EndMessage
1244 << TestLog::Message << failNote << TestLog::EndMessage;
1248 if (sortedCoords[0] != 0.0f || sortedCoords.back() != 1.0f)
1250 log << TestLog::Message << "Failure: smallest coordinate should be 0.0 and biggest should be 1.0" << TestLog::EndMessage
1251 << TestLog::Message << failNote << TestLog::EndMessage;
1256 vector<Segment> segments(finalLevel);
1257 for (int i = 0; i < finalLevel; i++)
1258 segments[i] = Segment(i, sortedCoords[i+1] - sortedCoords[i]);
1260 failNote += "\nNote: segment lengths are, from left to right:\n " + containerStr(Segment::lengths(segments));
1263 // Divide segments to two different groups based on length.
1265 vector<Segment> segmentsA;
1266 vector<Segment> segmentsB;
1267 segmentsA.push_back(segments[0]);
1269 for (int segNdx = 1; segNdx < (int)segments.size(); segNdx++)
1271 const float epsilon = 0.001f;
1272 const Segment& seg = segments[segNdx];
1274 if (de::abs(seg.length - segmentsA[0].length) < epsilon)
1275 segmentsA.push_back(seg);
1276 else if (segmentsB.empty() || de::abs(seg.length - segmentsB[0].length) < epsilon)
1277 segmentsB.push_back(seg);
1280 log << TestLog::Message << "Failure: couldn't divide segments to 2 groups by length; "
1281 << "e.g. segment of length " << seg.length << " isn't approximately equal to either "
1282 << segmentsA[0].length << " or " << segmentsB[0].length << TestLog::EndMessage
1283 << TestLog::Message << failNote << TestLog::EndMessage;
1288 if (clampedLevel == (float)finalLevel)
1290 // All segments should be of equal length.
1291 if (!segmentsA.empty() && !segmentsB.empty())
1293 log << TestLog::Message << "Failure: clamped and final tessellation level are equal, but not all segments are of equal length." << TestLog::EndMessage
1294 << TestLog::Message << failNote << TestLog::EndMessage;
1299 if (segmentsA.empty() || segmentsB.empty()) // All segments have same length. This is ok.
1301 additionalSegmentLengthDst = segments.size() == 1 ? -1.0f : segments[0].length;
1302 additionalSegmentLocationDst = -1;
1306 if (segmentsA.size() != 2 && segmentsB.size() != 2)
1308 log << TestLog::Message << "Failure: when dividing the segments to 2 groups by length, neither of the two groups has exactly 2 or 0 segments in it" << TestLog::EndMessage
1309 << TestLog::Message << failNote << TestLog::EndMessage;
1313 // For convenience, arrange so that the 2-segment group is segmentsB.
1314 if (segmentsB.size() != 2)
1315 std::swap(segmentsA, segmentsB);
1317 // \note For 4-segment lines both segmentsA and segmentsB have 2 segments each.
1318 // Thus, we can't be sure which ones were meant as the additional segments.
1319 // We give the benefit of the doubt by assuming that they're the shorter
1320 // ones (as they should).
1322 if (segmentsA.size() != 2)
1324 if (segmentsB[0].length > segmentsA[0].length + 0.001f)
1326 log << TestLog::Message << "Failure: the two additional segments are longer than the other segments" << TestLog::EndMessage
1327 << TestLog::Message << failNote << TestLog::EndMessage;
1333 // We have 2 segmentsA and 2 segmentsB, ensure segmentsB has the shorter lengths
1334 if (segmentsB[0].length > segmentsA[0].length)
1335 std::swap(segmentsA, segmentsB);
1338 // Check that the additional segments are placed symmetrically.
1339 if (segmentsB[0].index + segmentsB[1].index + 1 != (int)segments.size())
1341 log << TestLog::Message << "Failure: the two additional segments aren't placed symmetrically; "
1342 << "one is at index " << segmentsB[0].index << " and other is at index " << segmentsB[1].index
1343 << " (note: the two indexes should sum to " << (int)segments.size()-1 << ", i.e. numberOfSegments-1)" << TestLog::EndMessage
1344 << TestLog::Message << failNote << TestLog::EndMessage;
1348 additionalSegmentLengthDst = segmentsB[0].length;
1349 if (segmentsA.size() != 2)
1350 additionalSegmentLocationDst = de::min(segmentsB[0].index, segmentsB[1].index);
1352 additionalSegmentLocationDst = segmentsB[0].length < segmentsA[0].length - 0.001f ? de::min(segmentsB[0].index, segmentsB[1].index)
1353 : -1; // \note -1 when can't reliably decide which ones are the additional segments, a or b.
1360 namespace VerifyFractionalSpacingMultipleInternal
1366 float additionalSegmentLength;
1367 int additionalSegmentLocation;
1368 LineData (float lev, float len, int loc) : tessLevel(lev), additionalSegmentLength(len), additionalSegmentLocation(loc) {}
1373 /*--------------------------------------------------------------------*//*!
1374 * \brief Verify fractional spacing conditions between multiple lines
1376 * Verify the fractional spacing conditions that are not checked in
1377 * verifyFractionalSpacingSingle(). Uses values given by said function
1378 * as parameters, in addition to the spacing mode and tessellation level.
1379 *//*--------------------------------------------------------------------*/
1380 static bool verifyFractionalSpacingMultiple (TestLog& log, SpacingMode spacingMode, const vector<float>& tessLevels, const vector<float>& additionalSegmentLengths, const vector<int>& additionalSegmentLocations)
1382 using namespace VerifyFractionalSpacingMultipleInternal;
1384 DE_ASSERT(spacingMode == SPACINGMODE_FRACTIONAL_ODD || spacingMode == SPACINGMODE_FRACTIONAL_EVEN);
1385 DE_ASSERT(tessLevels.size() == additionalSegmentLengths.size() &&
1386 tessLevels.size() == additionalSegmentLocations.size());
1388 vector<LineData> lineDatas;
1390 for (int i = 0; i < (int)tessLevels.size(); i++)
1391 lineDatas.push_back(LineData(tessLevels[i], additionalSegmentLengths[i], additionalSegmentLocations[i]));
1394 const vector<LineData> lineDatasSortedByLevel = sorted(lineDatas, memberPred<std::less>(&LineData::tessLevel));
1396 // Check that lines with identical clamped tessellation levels have identical additionalSegmentLocation.
1398 for (int lineNdx = 1; lineNdx < (int)lineDatasSortedByLevel.size(); lineNdx++)
1400 const LineData& curData = lineDatasSortedByLevel[lineNdx];
1401 const LineData& prevData = lineDatasSortedByLevel[lineNdx-1];
1403 if (curData.additionalSegmentLocation < 0 || prevData.additionalSegmentLocation < 0)
1404 continue; // Unknown locations, skip.
1406 if (getClampedTessLevel(spacingMode, curData.tessLevel) == getClampedTessLevel(spacingMode, prevData.tessLevel) &&
1407 curData.additionalSegmentLocation != prevData.additionalSegmentLocation)
1409 log << TestLog::Message << "Failure: additional segments not located identically for two edges with identical clamped tessellation levels" << TestLog::EndMessage
1410 << TestLog::Message << "Note: tessellation levels are " << curData.tessLevel << " and " << prevData.tessLevel
1411 << " (clamped level " << getClampedTessLevel(spacingMode, curData.tessLevel) << ")"
1412 << "; but first additional segments located at indices "
1413 << curData.additionalSegmentLocation << " and " << prevData.additionalSegmentLocation << ", respectively" << TestLog::EndMessage;
1418 // Check that, among lines with same clamped rounded tessellation level, additionalSegmentLength is monotonically decreasing with "clampedRoundedTessLevel - clampedTessLevel" (the "fraction").
1420 for (int lineNdx = 1; lineNdx < (int)lineDatasSortedByLevel.size(); lineNdx++)
1422 const LineData& curData = lineDatasSortedByLevel[lineNdx];
1423 const LineData& prevData = lineDatasSortedByLevel[lineNdx-1];
1425 if (curData.additionalSegmentLength < 0.0f || prevData.additionalSegmentLength < 0.0f)
1426 continue; // Unknown segment lengths, skip.
1428 const float curClampedLevel = getClampedTessLevel(spacingMode, curData.tessLevel);
1429 const float prevClampedLevel = getClampedTessLevel(spacingMode, prevData.tessLevel);
1430 const int curFinalLevel = getRoundedTessLevel(spacingMode, curClampedLevel);
1431 const int prevFinalLevel = getRoundedTessLevel(spacingMode, prevClampedLevel);
1433 if (curFinalLevel != prevFinalLevel)
1436 const float curFraction = (float)curFinalLevel - curClampedLevel;
1437 const float prevFraction = (float)prevFinalLevel - prevClampedLevel;
1439 if (curData.additionalSegmentLength < prevData.additionalSegmentLength ||
1440 (curClampedLevel == prevClampedLevel && curData.additionalSegmentLength != prevData.additionalSegmentLength))
1442 log << TestLog::Message << "Failure: additional segment length isn't monotonically decreasing with the fraction <n> - <f>, among edges with same final tessellation level" << TestLog::EndMessage
1443 << TestLog::Message << "Note: <f> stands for the clamped tessellation level and <n> for the final (rounded and clamped) tessellation level" << TestLog::EndMessage
1444 << TestLog::Message << "Note: two edges have tessellation levels " << prevData.tessLevel << " and " << curData.tessLevel << " respectively"
1445 << ", clamped " << prevClampedLevel << " and " << curClampedLevel << ", final " << prevFinalLevel << " and " << curFinalLevel
1446 << "; fractions are " << prevFraction << " and " << curFraction
1447 << ", but resulted in segment lengths " << prevData.additionalSegmentLength << " and " << curData.additionalSegmentLength << TestLog::EndMessage;
1456 //! Compare triangle sets, ignoring triangle order and vertex order within triangle, and possibly exclude some triangles too.
1457 template <typename IsTriangleRelevantT>
1458 static bool compareTriangleSets (const vector<Vec3>& coordsA,
1459 const vector<Vec3>& coordsB,
1461 const IsTriangleRelevantT& isTriangleRelevant,
1462 const char* ignoredTriangleDescription = DE_NULL)
1464 typedef tcu::Vector<Vec3, 3> Triangle;
1465 typedef LexCompare<Triangle, 3, VecLexLessThan<3> > TriangleLexLessThan;
1466 typedef std::set<Triangle, TriangleLexLessThan> TriangleSet;
1468 DE_ASSERT(coordsA.size() % 3 == 0 && coordsB.size() % 3 == 0);
1470 const int numTrianglesA = (int)coordsA.size()/3;
1471 const int numTrianglesB = (int)coordsB.size()/3;
1472 TriangleSet trianglesA;
1473 TriangleSet trianglesB;
1475 for (int aOrB = 0; aOrB < 2; aOrB++)
1477 const vector<Vec3>& coords = aOrB == 0 ? coordsA : coordsB;
1478 const int numTriangles = aOrB == 0 ? numTrianglesA : numTrianglesB;
1479 TriangleSet& triangles = aOrB == 0 ? trianglesA : trianglesB;
1481 for (int triNdx = 0; triNdx < numTriangles; triNdx++)
1483 Triangle triangle(coords[3*triNdx + 0],
1484 coords[3*triNdx + 1],
1485 coords[3*triNdx + 2]);
1487 if (isTriangleRelevant(triangle.getPtr()))
1489 std::sort(triangle.getPtr(), triangle.getPtr()+3, VecLexLessThan<3>());
1490 triangles.insert(triangle);
1496 TriangleSet::const_iterator aIt = trianglesA.begin();
1497 TriangleSet::const_iterator bIt = trianglesB.begin();
1499 while (aIt != trianglesA.end() || bIt != trianglesB.end())
1501 const bool aEnd = aIt == trianglesA.end();
1502 const bool bEnd = bIt == trianglesB.end();
1504 if (aEnd || bEnd || *aIt != *bIt)
1506 log << TestLog::Message << "Failure: triangle sets in two cases are not equal (when ignoring triangle and vertex order"
1507 << (ignoredTriangleDescription == DE_NULL ? "" : string() + ", and " + ignoredTriangleDescription) << ")" << TestLog::EndMessage;
1509 if (!aEnd && (bEnd || TriangleLexLessThan()(*aIt, *bIt)))
1510 log << TestLog::Message << "Note: e.g. triangle " << *aIt << " exists for first case but not for second" << TestLog::EndMessage;
1512 log << TestLog::Message << "Note: e.g. triangle " << *bIt << " exists for second case but not for first" << TestLog::EndMessage;
1525 static bool compareTriangleSets (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, TestLog& log)
1527 return compareTriangleSets(coordsA, coordsB, log, ConstantUnaryPredicate<const Vec3*, true>());
1530 static bool supportsES32orGL45(Context& context)
1532 glu::ContextType contextType = context.getRenderContext().getType();
1533 return glu::contextSupports(contextType, glu::ApiType::es(3, 2)) ||
1534 glu::contextSupports(contextType, glu::ApiType::core(4, 5));
1537 static void checkGPUShader5Support (Context& context)
1539 TCU_CHECK_AND_THROW(NotSupportedError, supportsES32orGL45(context) || context.getContextInfo().isExtensionSupported("GL_EXT_gpu_shader5"), "GL_EXT_gpu_shader5 is not supported");
1542 static void checkTessellationSupport (Context& context)
1544 TCU_CHECK_AND_THROW(NotSupportedError, supportsES32orGL45(context) || context.getContextInfo().isExtensionSupported("GL_EXT_tessellation_shader"), "GL_EXT_tessellation_shader is not supported");
1547 static std::string specializeShader(Context& context, const char* code)
1549 const glu::ContextType contextType = context.getRenderContext().getType();
1550 const glu::GLSLVersion glslVersion = glu::getContextTypeGLSLVersion(contextType);
1551 const bool cSupportsES32orGL45 = supportsES32orGL45(context);
1553 std::map<std::string, std::string> specializationMap =
1555 { "GLSL_VERSION_DECL", glu::getGLSLVersionDeclaration(glslVersion) },
1556 { "GPU_SHADER5_REQUIRE", cSupportsES32orGL45 ? "" : "#extension GL_EXT_gpu_shader5 : require" },
1557 { "TESSELLATION_SHADER_REQUIRE", cSupportsES32orGL45 ? "" : "#extension GL_EXT_tessellation_shader : require" },
1558 { "GLSL_PER_VERTEX_OUT", "" }, // needed for GL4.5
1559 { "GLSL_PER_VERTEX_IN_ARR", "" },
1560 { "GLSL_PER_VERTEX_OUT_ARR", "" },
1561 { "GLSL_PRECISE_PER_VERTEX_OUT", "" },
1562 { "GLSL_PRECISE_PER_VERTEX_IN_ARR", "" },
1563 { "GLSL_PRECISE_PER_VERTEX_OUT_ARR", "" }
1566 // for gl4.5 we need to add per vertex sections
1567 if (!glu::isContextTypeES(context.getRenderContext().getType()))
1569 specializationMap["GLSL_PER_VERTEX_OUT"] = "out gl_PerVertex { vec4 gl_Position; };\n";
1570 specializationMap["GLSL_PER_VERTEX_IN_ARR"] = "in gl_PerVertex { vec4 gl_Position; } gl_in[];\n";
1571 specializationMap["GLSL_PER_VERTEX_OUT_ARR"] = "out gl_PerVertex { vec4 gl_Position; } gl_out[];\n";
1572 specializationMap["GLSL_PRECISE_PER_VERTEX_OUT"] = "out gl_PerVertex { vec4 gl_Position; };\nprecise gl_Position;\n";
1573 specializationMap["GLSL_PRECISE_PER_VERTEX_IN_ARR"] = "in gl_PerVertex { vec4 gl_Position; } gl_in[];\nprecise gl_in;\n";
1574 specializationMap["GLSL_PRECISE_PER_VERTEX_OUT_ARR"] = "out gl_PerVertex { vec4 gl_Position; } gl_out[];\nprecise gl_out;\n";
1577 return tcu::StringTemplate(code).specialize(specializationMap);
1580 // Draw primitives with shared edges and check that no cracks are visible at the shared edges.
1581 class CommonEdgeCase : public TestCase
1586 CASETYPE_BASIC = 0, //!< Order patch vertices such that when two patches share a vertex, it's at the same index for both.
1587 CASETYPE_PRECISE, //!< Vertex indices don't match like for CASETYPE_BASIC, but other measures are taken, using the 'precise' qualifier.
1592 CommonEdgeCase (Context& context, const char* name, const char* description, TessPrimitiveType primitiveType, SpacingMode spacing, CaseType caseType)
1593 : TestCase (context, name, description)
1594 , m_primitiveType (primitiveType)
1595 , m_spacing (spacing)
1596 , m_caseType (caseType)
1598 DE_ASSERT(m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES || m_primitiveType == TESSPRIMITIVETYPE_QUADS);
1603 IterateResult iterate (void);
1606 static const int RENDER_SIZE = 256;
1608 const TessPrimitiveType m_primitiveType;
1609 const SpacingMode m_spacing;
1610 const CaseType m_caseType;
1612 SharedPtr<const ShaderProgram> m_program;
1615 void CommonEdgeCase::init (void)
1617 bool isGL45 = glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5));
1620 checkTessellationSupport(m_context);
1621 if (m_caseType == CASETYPE_PRECISE)
1622 checkGPUShader5Support(m_context);
1625 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
1627 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
1628 "${GLSL_PER_VERTEX_OUT}\n"
1630 "in highp vec2 in_v_position;\n"
1631 "in highp float in_v_tessParam;\n"
1633 "out highp vec2 in_tc_position;\n"
1634 "out highp float in_tc_tessParam;\n"
1636 "void main (void)\n"
1638 " in_tc_position = in_v_position;\n"
1639 " in_tc_tessParam = in_v_tessParam;\n"
1642 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
1643 "${TESSELLATION_SHADER_REQUIRE}\n"
1644 + string(m_caseType == CASETYPE_PRECISE ? "${GPU_SHADER5_REQUIRE}\n" : "") +
1645 "${GLSL_PER_VERTEX_IN_ARR}\n"
1646 "${GLSL_PER_VERTEX_OUT_ARR}\n"
1648 "layout (vertices = " + string(m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? "3" : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? "4" : DE_NULL) + ") out;\n"
1650 "in highp vec2 in_tc_position[];\n"
1651 "in highp float in_tc_tessParam[];\n"
1653 "out highp vec2 in_te_position[];\n"
1655 + (m_caseType == CASETYPE_PRECISE ? "precise gl_TessLevelOuter;\n\n" : "") +
1656 "void main (void)\n"
1658 " in_te_position[gl_InvocationID] = in_tc_position[gl_InvocationID];\n"
1660 " gl_TessLevelInner[0] = 5.0;\n"
1661 " gl_TessLevelInner[1] = 5.0;\n"
1663 + (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
1664 " gl_TessLevelOuter[0] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[1] + in_tc_tessParam[2]);\n"
1665 " gl_TessLevelOuter[1] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[2] + in_tc_tessParam[0]);\n"
1666 " gl_TessLevelOuter[2] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[0] + in_tc_tessParam[1]);\n"
1667 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ?
1668 " gl_TessLevelOuter[0] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[0] + in_tc_tessParam[2]);\n"
1669 " gl_TessLevelOuter[1] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[1] + in_tc_tessParam[0]);\n"
1670 " gl_TessLevelOuter[2] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[3] + in_tc_tessParam[1]);\n"
1671 " gl_TessLevelOuter[3] = 1.0 + 59.0 * 0.5 * (in_tc_tessParam[2] + in_tc_tessParam[3]);\n"
1672 : deFatalStr("Invalid TessPrimitiveType")) +
1675 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
1676 "${TESSELLATION_SHADER_REQUIRE}\n"
1677 + string(m_caseType == CASETYPE_PRECISE ? "${GPU_SHADER5_REQUIRE}\n" : "") +
1678 "${GLSL_PRECISE_PER_VERTEX_IN_ARR}\n"
1679 "${GLSL_PRECISE_PER_VERTEX_OUT}\n"
1681 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing) +
1683 "in highp vec2 in_te_position[];\n"
1685 "out mediump vec4 in_f_color;\n"
1687 + ((m_caseType == CASETYPE_PRECISE && !isGL45) ? "precise gl_Position;\n\n" : "") +
1688 "void main (void)\n"
1690 + (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
1691 " highp vec2 pos = gl_TessCoord.x*in_te_position[0] + gl_TessCoord.y*in_te_position[1] + gl_TessCoord.z*in_te_position[2];\n"
1693 " highp float f = sqrt(3.0 * min(gl_TessCoord.x, min(gl_TessCoord.y, gl_TessCoord.z))) * 0.5 + 0.5;\n"
1694 " in_f_color = vec4(gl_TessCoord*f, 1.0);\n"
1695 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ?
1697 + (m_caseType == CASETYPE_BASIC ?
1698 " highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*in_te_position[0]\n"
1699 " + ( gl_TessCoord.x)*(1.0-gl_TessCoord.y)*in_te_position[1]\n"
1700 " + (1.0-gl_TessCoord.x)*( gl_TessCoord.y)*in_te_position[2]\n"
1701 " + ( gl_TessCoord.x)*( gl_TessCoord.y)*in_te_position[3];\n"
1702 : m_caseType == CASETYPE_PRECISE ?
1703 " highp vec2 a = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*in_te_position[0];\n"
1704 " highp vec2 b = ( gl_TessCoord.x)*(1.0-gl_TessCoord.y)*in_te_position[1];\n"
1705 " highp vec2 c = (1.0-gl_TessCoord.x)*( gl_TessCoord.y)*in_te_position[2];\n"
1706 " highp vec2 d = ( gl_TessCoord.x)*( gl_TessCoord.y)*in_te_position[3];\n"
1707 " highp vec2 pos = a+b+c+d;\n"
1708 : deFatalStr("Invalid CaseType")) +
1710 " highp float f = sqrt(1.0 - 2.0 * max(abs(gl_TessCoord.x - 0.5), abs(gl_TessCoord.y - 0.5)))*0.5 + 0.5;\n"
1711 " in_f_color = vec4(0.1, gl_TessCoord.xy*f, 1.0);\n"
1712 : deFatalStr("Invalid TessPrimitiveType")) +
1714 " // Offset the position slightly, based on the parity of the bits in the float representation.\n"
1715 " // This is done to detect possible small differences in edge vertex positions between patches.\n"
1716 " uvec2 bits = floatBitsToUint(pos);\n"
1717 " uint numBits = 0u;\n"
1718 " for (uint i = 0u; i < 32u; i++)\n"
1719 " numBits += ((bits[0] >> i) & 1u) + ((bits[1] >> i) & 1u);\n"
1720 " pos += float(numBits&1u)*0.04;\n"
1722 " gl_Position = vec4(pos, 0.0, 1.0);\n"
1725 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
1727 "layout (location = 0) out mediump vec4 o_color;\n"
1729 "in mediump vec4 in_f_color;\n"
1731 "void main (void)\n"
1733 " o_color = in_f_color;\n"
1736 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
1737 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
1738 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
1739 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
1740 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
1742 m_testCtx.getLog() << *m_program;
1743 if (!m_program->isOk())
1744 TCU_FAIL("Program compilation failed");
1747 void CommonEdgeCase::deinit (void)
1752 CommonEdgeCase::IterateResult CommonEdgeCase::iterate (void)
1754 TestLog& log = m_testCtx.getLog();
1755 const RenderContext& renderCtx = m_context.getRenderContext();
1756 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
1757 const deUint32 programGL = m_program->getProgram();
1758 const glw::Functions& gl = renderCtx.getFunctions();
1760 const int gridWidth = 4;
1761 const int gridHeight = 4;
1762 const int numVertices = (gridWidth+1)*(gridHeight+1);
1763 const int numIndices = gridWidth*gridHeight * (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3*2 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? 4 : -1);
1764 const int numPosCompsPerVertex = 2;
1765 const int totalNumPosComps = numPosCompsPerVertex*numVertices;
1766 vector<float> gridPosComps;
1767 vector<float> gridTessParams;
1768 vector<deUint16> gridIndices;
1770 gridPosComps.reserve(totalNumPosComps);
1771 gridTessParams.reserve(numVertices);
1772 gridIndices.reserve(numIndices);
1775 for (int i = 0; i < gridHeight+1; i++)
1776 for (int j = 0; j < gridWidth+1; j++)
1778 gridPosComps.push_back(-1.0f + 2.0f * ((float)j + 0.5f) / (float)(gridWidth+1));
1779 gridPosComps.push_back(-1.0f + 2.0f * ((float)i + 0.5f) / (float)(gridHeight+1));
1780 gridTessParams.push_back((float)(i*(gridWidth+1) + j) / (float)(numVertices-1));
1784 // Generate patch vertex indices.
1785 // \note If CASETYPE_BASIC, the vertices are ordered such that when multiple
1786 // triangles/quads share a vertex, it's at the same index for everyone.
1788 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
1790 for (int i = 0; i < gridHeight; i++)
1791 for (int j = 0; j < gridWidth; j++)
1793 const deUint16 corners[4] =
1795 (deUint16)((i+0)*(gridWidth+1) + j+0),
1796 (deUint16)((i+0)*(gridWidth+1) + j+1),
1797 (deUint16)((i+1)*(gridWidth+1) + j+0),
1798 (deUint16)((i+1)*(gridWidth+1) + j+1)
1801 const int secondTriangleVertexIndexOffset = m_caseType == CASETYPE_BASIC ? 0
1802 : m_caseType == CASETYPE_PRECISE ? 1
1804 DE_ASSERT(secondTriangleVertexIndexOffset != -1);
1806 for (int k = 0; k < 3; k++)
1807 gridIndices.push_back(corners[(k+0 + i + (2-j%3)) % 3]);
1808 for (int k = 0; k < 3; k++)
1809 gridIndices.push_back(corners[(k+2 + i + (2-j%3) + secondTriangleVertexIndexOffset) % 3 + 1]);
1812 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
1814 for (int i = 0; i < gridHeight; i++)
1815 for (int j = 0; j < gridWidth; j++)
1817 // \note The vertices are ordered such that when multiple quads
1818 // share a vertices, it's at the same index for everyone.
1819 for (int m = 0; m < 2; m++)
1820 for (int n = 0; n < 2; n++)
1821 gridIndices.push_back((deUint16)((i+(i+m)%2)*(gridWidth+1) + j+(j+n)%2));
1823 if(m_caseType == CASETYPE_PRECISE && (i+j) % 2 == 0)
1824 std::reverse(gridIndices.begin() + (gridIndices.size() - 4),
1825 gridIndices.begin() + gridIndices.size());
1831 DE_ASSERT((int)gridPosComps.size() == totalNumPosComps);
1832 DE_ASSERT((int)gridTessParams.size() == numVertices);
1833 DE_ASSERT((int)gridIndices.size() == numIndices);
1835 setViewport(gl, viewport);
1836 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
1837 gl.useProgram(programGL);
1840 gl.patchParameteri(GL_PATCH_VERTICES, m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? 4 : -1);
1841 gl.clear(GL_COLOR_BUFFER_BIT);
1843 const glu::VertexArrayBinding attrBindings[] =
1845 glu::va::Float("in_v_position", numPosCompsPerVertex, numVertices, 0, &gridPosComps[0]),
1846 glu::va::Float("in_v_tessParam", 1, numVertices, 0, &gridTessParams[0])
1849 glu::draw(renderCtx, programGL, DE_LENGTH_OF_ARRAY(attrBindings), &attrBindings[0],
1850 glu::pr::Patches((int)gridIndices.size(), &gridIndices[0]));
1851 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
1855 const tcu::Surface rendered = getPixels(renderCtx, viewport);
1857 log << TestLog::Image("RenderedImage", "Rendered Image", rendered)
1858 << TestLog::Message << "Note: coloring is done to clarify the positioning and orientation of the "
1859 << (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? "triangles" : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? "quads" : DE_NULL)
1860 << "; the color of a vertex corresponds to the index of that vertex in the patch"
1861 << TestLog::EndMessage;
1863 if (m_caseType == CASETYPE_BASIC)
1864 log << TestLog::Message << "Note: each shared vertex has the same index among the primitives it belongs to" << TestLog::EndMessage;
1865 else if (m_caseType == CASETYPE_PRECISE)
1866 log << TestLog::Message << "Note: the 'precise' qualifier is used to avoid cracks between primitives" << TestLog::EndMessage;
1870 // Ad-hoc result verification - check that a certain rectangle in the image contains no black pixels.
1872 const int startX = (int)(0.15f * (float)rendered.getWidth());
1873 const int endX = (int)(0.85f * (float)rendered.getWidth());
1874 const int startY = (int)(0.15f * (float)rendered.getHeight());
1875 const int endY = (int)(0.85f * (float)rendered.getHeight());
1877 for (int y = startY; y < endY; y++)
1878 for (int x = startX; x < endX; x++)
1880 const tcu::RGBA pixel = rendered.getPixel(x, y);
1882 if (pixel.getRed() == 0 && pixel.getGreen() == 0 && pixel.getBlue() == 0)
1884 log << TestLog::Message << "Failure: there seem to be cracks in the rendered result" << TestLog::EndMessage
1885 << TestLog::Message << "Note: pixel with zero r, g and b channels found at " << tcu::IVec2(x, y) << TestLog::EndMessage;
1887 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
1892 log << TestLog::Message << "Success: there seem to be no cracks in the rendered result" << TestLog::EndMessage;
1895 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1899 // Check tessellation coordinates (read with transform feedback).
1900 class TessCoordCase : public TestCase
1903 TessCoordCase (Context& context, const char* name, const char* description, TessPrimitiveType primitiveType, SpacingMode spacing)
1904 : TestCase (context, name, description)
1905 , m_primitiveType (primitiveType)
1906 , m_spacing (spacing)
1912 IterateResult iterate (void);
1921 static const int RENDER_SIZE = 16;
1923 vector<TessLevels> genTessLevelCases (void) const;
1925 const TessPrimitiveType m_primitiveType;
1926 const SpacingMode m_spacing;
1928 SharedPtr<const ShaderProgram> m_program;
1931 void TessCoordCase::init (void)
1933 checkTessellationSupport(m_context);
1934 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
1936 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
1937 "${GLSL_PER_VERTEX_OUT}\n"
1939 "void main (void)\n"
1943 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
1944 "${TESSELLATION_SHADER_REQUIRE}\n"
1945 "${GLSL_PER_VERTEX_IN_ARR}\n"
1946 "${GLSL_PER_VERTEX_OUT_ARR}\n"
1948 "layout (vertices = 1) out;\n"
1950 "uniform mediump float u_tessLevelInner0;\n"
1951 "uniform mediump float u_tessLevelInner1;\n"
1953 "uniform mediump float u_tessLevelOuter0;\n"
1954 "uniform mediump float u_tessLevelOuter1;\n"
1955 "uniform mediump float u_tessLevelOuter2;\n"
1956 "uniform mediump float u_tessLevelOuter3;\n"
1958 "void main (void)\n"
1960 " gl_TessLevelInner[0] = u_tessLevelInner0;\n"
1961 " gl_TessLevelInner[1] = u_tessLevelInner1;\n"
1963 " gl_TessLevelOuter[0] = u_tessLevelOuter0;\n"
1964 " gl_TessLevelOuter[1] = u_tessLevelOuter1;\n"
1965 " gl_TessLevelOuter[2] = u_tessLevelOuter2;\n"
1966 " gl_TessLevelOuter[3] = u_tessLevelOuter3;\n"
1969 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
1970 "${TESSELLATION_SHADER_REQUIRE}\n"
1971 "${GLSL_PER_VERTEX_IN_ARR}\n"
1972 "${GLSL_PER_VERTEX_OUT}\n"
1974 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, true) +
1976 "out highp vec3 out_te_tessCoord;\n"
1978 "void main (void)\n"
1980 " out_te_tessCoord = gl_TessCoord;\n"
1981 " gl_Position = vec4(gl_TessCoord.xy*1.6 - 0.8, 0.0, 1.0);\n"
1984 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
1986 "layout (location = 0) out mediump vec4 o_color;\n"
1988 "void main (void)\n"
1990 " o_color = vec4(1.0);\n"
1993 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
1994 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
1995 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
1996 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
1997 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
1998 << glu::TransformFeedbackVarying ("out_te_tessCoord")
1999 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
2001 m_testCtx.getLog() << *m_program;
2002 if (!m_program->isOk())
2003 TCU_FAIL("Program compilation failed");
2006 void TessCoordCase::deinit (void)
2011 vector<TessCoordCase::TessLevels> TessCoordCase::genTessLevelCases (void) const
2013 static const TessLevels rawTessLevelCases[] =
2015 { { 1.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
2016 { { 63.0f, 24.0f }, { 15.0f, 42.0f, 10.0f, 12.0f } },
2017 { { 3.0f, 2.0f }, { 6.0f, 8.0f, 7.0f, 9.0f } },
2018 { { 4.0f, 6.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
2019 { { 2.0f, 2.0f }, { 6.0f, 8.0f, 7.0f, 9.0f } },
2020 { { 5.0f, 6.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
2021 { { 1.0f, 6.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
2022 { { 5.0f, 1.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
2023 { { 5.2f, 1.6f }, { 2.9f, 3.4f, 1.5f, 4.1f } }
2026 if (m_spacing == SPACINGMODE_EQUAL)
2027 return vector<TessLevels>(DE_ARRAY_BEGIN(rawTessLevelCases), DE_ARRAY_END(rawTessLevelCases));
2030 vector<TessLevels> result;
2031 result.reserve(DE_LENGTH_OF_ARRAY(rawTessLevelCases));
2033 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < DE_LENGTH_OF_ARRAY(rawTessLevelCases); tessLevelCaseNdx++)
2035 TessLevels curTessLevelCase = rawTessLevelCases[tessLevelCaseNdx];
2037 float* const inner = &curTessLevelCase.inner[0];
2038 float* const outer = &curTessLevelCase.outer[0];
2040 for (int j = 0; j < 2; j++) inner[j] = (float)getClampedRoundedTessLevel(m_spacing, inner[j]);
2041 for (int j = 0; j < 4; j++) outer[j] = (float)getClampedRoundedTessLevel(m_spacing, outer[j]);
2043 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
2045 if (outer[0] > 1.0f || outer[1] > 1.0f || outer[2] > 1.0f)
2047 if (inner[0] == 1.0f)
2048 inner[0] = (float)getClampedRoundedTessLevel(m_spacing, inner[0] + 0.1f);
2051 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
2053 if (outer[0] > 1.0f || outer[1] > 1.0f || outer[2] > 1.0f || outer[3] > 1.0f)
2055 if (inner[0] == 1.0f) inner[0] = (float)getClampedRoundedTessLevel(m_spacing, inner[0] + 0.1f);
2056 if (inner[1] == 1.0f) inner[1] = (float)getClampedRoundedTessLevel(m_spacing, inner[1] + 0.1f);
2060 result.push_back(curTessLevelCase);
2063 DE_ASSERT((int)result.size() == DE_LENGTH_OF_ARRAY(rawTessLevelCases));
2068 TessCoordCase::IterateResult TessCoordCase::iterate (void)
2070 typedef TransformFeedbackHandler<Vec3> TFHandler;
2072 TestLog& log = m_testCtx.getLog();
2073 const RenderContext& renderCtx = m_context.getRenderContext();
2074 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
2075 const deUint32 programGL = m_program->getProgram();
2076 const glw::Functions& gl = renderCtx.getFunctions();
2078 const int tessLevelInner0Loc = gl.getUniformLocation(programGL, "u_tessLevelInner0");
2079 const int tessLevelInner1Loc = gl.getUniformLocation(programGL, "u_tessLevelInner1");
2080 const int tessLevelOuter0Loc = gl.getUniformLocation(programGL, "u_tessLevelOuter0");
2081 const int tessLevelOuter1Loc = gl.getUniformLocation(programGL, "u_tessLevelOuter1");
2082 const int tessLevelOuter2Loc = gl.getUniformLocation(programGL, "u_tessLevelOuter2");
2083 const int tessLevelOuter3Loc = gl.getUniformLocation(programGL, "u_tessLevelOuter3");
2085 const vector<TessLevels> tessLevelCases = genTessLevelCases();
2086 vector<vector<Vec3> > caseReferences (tessLevelCases.size());
2088 for (int i = 0; i < (int)tessLevelCases.size(); i++)
2089 caseReferences[i] = generateReferenceTessCoords(m_primitiveType, m_spacing, &tessLevelCases[i].inner[0], &tessLevelCases[i].outer[0]);
2091 const int maxNumVertices = (int)std::max_element(caseReferences.begin(), caseReferences.end(), SizeLessThan<vector<Vec3> >())->size();
2092 const TFHandler tfHandler (m_context.getRenderContext(), maxNumVertices);
2094 bool success = true;
2096 setViewport(gl, viewport);
2097 gl.useProgram(programGL);
2099 gl.patchParameteri(GL_PATCH_VERTICES, 1);
2101 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < (int)tessLevelCases.size(); tessLevelCaseNdx++)
2103 const float* const innerLevels = &tessLevelCases[tessLevelCaseNdx].inner[0];
2104 const float* const outerLevels = &tessLevelCases[tessLevelCaseNdx].outer[0];
2106 log << TestLog::Message << "Tessellation levels: " << tessellationLevelsString(innerLevels, outerLevels, m_primitiveType) << TestLog::EndMessage;
2108 gl.uniform1f(tessLevelInner0Loc, innerLevels[0]);
2109 gl.uniform1f(tessLevelInner1Loc, innerLevels[1]);
2110 gl.uniform1f(tessLevelOuter0Loc, outerLevels[0]);
2111 gl.uniform1f(tessLevelOuter1Loc, outerLevels[1]);
2112 gl.uniform1f(tessLevelOuter2Loc, outerLevels[2]);
2113 gl.uniform1f(tessLevelOuter3Loc, outerLevels[3]);
2114 GLU_EXPECT_NO_ERROR(gl.getError(), "Setup failed");
2117 const vector<Vec3>& tessCoordsRef = caseReferences[tessLevelCaseNdx];
2118 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, GL_POINTS, 0, DE_NULL, 1);
2120 if (tfResult.numPrimitives != (int)tessCoordsRef.size())
2122 log << TestLog::Message << "Failure: GL reported GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN to be "
2123 << tfResult.numPrimitives << ", reference value is " << tessCoordsRef.size()
2124 << " (logging further info anyway)" << TestLog::EndMessage;
2128 log << TestLog::Message << "Note: GL reported GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN to be " << tfResult.numPrimitives << TestLog::EndMessage;
2130 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
2131 log << TestLog::Message << "Note: in the following visualization(s), the u=1, v=1, w=1 corners are at the right, top, and left corners, respectively" << TestLog::EndMessage;
2132 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS || m_primitiveType == TESSPRIMITIVETYPE_ISOLINES)
2133 log << TestLog::Message << "Note: in the following visualization(s), u and v coordinate go left-to-right and bottom-to-top, respectively" << TestLog::EndMessage;
2137 success = compareTessCoords(log, m_primitiveType, tessCoordsRef, tfResult.varying) && success;
2143 log << TestLog::Message << "All OK" << TestLog::EndMessage;
2146 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Invalid tessellation coordinates");
2150 // Check validity of fractional spacing modes. Draws a single isoline, reads tesscoords with transform feedback.
2151 class FractionalSpacingModeCase : public TestCase
2154 FractionalSpacingModeCase (Context& context, const char* name, const char* description, SpacingMode spacing)
2155 : TestCase (context, name, description)
2156 , m_spacing (spacing)
2158 DE_ASSERT(m_spacing == SPACINGMODE_FRACTIONAL_EVEN || m_spacing == SPACINGMODE_FRACTIONAL_ODD);
2163 IterateResult iterate (void);
2166 static const int RENDER_SIZE = 16;
2168 static vector<float> genTessLevelCases (void);
2170 const SpacingMode m_spacing;
2172 SharedPtr<const ShaderProgram> m_program;
2175 void FractionalSpacingModeCase::init (void)
2177 checkTessellationSupport(m_context);
2178 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
2180 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2181 "${GLSL_PER_VERTEX_OUT}\n"
2183 "void main (void)\n"
2186 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
2187 "${TESSELLATION_SHADER_REQUIRE}\n"
2188 "${GLSL_PER_VERTEX_IN_ARR}\n"
2189 "${GLSL_PER_VERTEX_OUT_ARR}\n"
2191 "layout (vertices = 1) out;\n"
2193 "uniform mediump float u_tessLevelOuter1;\n"
2195 "void main (void)\n"
2197 " gl_TessLevelOuter[0] = 1.0;\n"
2198 " gl_TessLevelOuter[1] = u_tessLevelOuter1;\n"
2200 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
2201 "${TESSELLATION_SHADER_REQUIRE}\n"
2202 "${GLSL_PER_VERTEX_IN_ARR}\n"
2203 "${GLSL_PER_VERTEX_OUT}\n"
2205 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_ISOLINES, m_spacing, true) +
2207 "out highp float out_te_tessCoord;\n"
2209 "void main (void)\n"
2211 " out_te_tessCoord = gl_TessCoord.x;\n"
2212 " gl_Position = vec4(gl_TessCoord.xy*1.6 - 0.8, 0.0, 1.0);\n"
2214 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
2216 "layout (location = 0) out mediump vec4 o_color;\n"
2218 "void main (void)\n"
2220 " o_color = vec4(1.0);\n"
2223 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
2224 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
2225 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
2226 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
2227 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
2228 << glu::TransformFeedbackVarying ("out_te_tessCoord")
2229 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
2231 m_testCtx.getLog() << *m_program;
2232 if (!m_program->isOk())
2233 TCU_FAIL("Program compilation failed");
2236 void FractionalSpacingModeCase::deinit (void)
2241 vector<float> FractionalSpacingModeCase::genTessLevelCases (void)
2243 vector<float> result;
2245 // Ranges [7.0 .. 8.0), [8.0 .. 9.0) and [9.0 .. 10.0)
2247 static const float rangeStarts[] = { 7.0f, 8.0f, 9.0f };
2248 const int numSamplesPerRange = 10;
2250 for (int rangeNdx = 0; rangeNdx < DE_LENGTH_OF_ARRAY(rangeStarts); rangeNdx++)
2251 for (int i = 0; i < numSamplesPerRange; i++)
2252 result.push_back(rangeStarts[rangeNdx] + (float)i/(float)numSamplesPerRange);
2255 // 0.3, 1.3, 2.3, ... , 62.3
2256 for (int i = 0; i <= 62; i++)
2257 result.push_back((float)i + 0.3f);
2262 FractionalSpacingModeCase::IterateResult FractionalSpacingModeCase::iterate (void)
2264 typedef TransformFeedbackHandler<float> TFHandler;
2266 TestLog& log = m_testCtx.getLog();
2267 const RenderContext& renderCtx = m_context.getRenderContext();
2268 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
2269 const deUint32 programGL = m_program->getProgram();
2270 const glw::Functions& gl = renderCtx.getFunctions();
2272 const int tessLevelOuter1Loc = gl.getUniformLocation(programGL, "u_tessLevelOuter1");
2274 // Second outer tessellation levels.
2275 const vector<float> tessLevelCases = genTessLevelCases();
2276 const int maxNumVertices = 1 + getClampedRoundedTessLevel(m_spacing, *std::max_element(tessLevelCases.begin(), tessLevelCases.end()));
2277 vector<float> additionalSegmentLengths;
2278 vector<int> additionalSegmentLocations;
2280 const TFHandler tfHandler (m_context.getRenderContext(), maxNumVertices);
2282 bool success = true;
2284 setViewport(gl, viewport);
2285 gl.useProgram(programGL);
2287 gl.patchParameteri(GL_PATCH_VERTICES, 1);
2289 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < (int)tessLevelCases.size(); tessLevelCaseNdx++)
2291 const float outerLevel1 = tessLevelCases[tessLevelCaseNdx];
2293 gl.uniform1f(tessLevelOuter1Loc, outerLevel1);
2294 GLU_EXPECT_NO_ERROR(gl.getError(), "Setup failed");
2297 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, GL_POINTS, 0, DE_NULL, 1);
2298 float additionalSegmentLength;
2299 int additionalSegmentLocation;
2301 success = verifyFractionalSpacingSingle(log, m_spacing, outerLevel1, tfResult.varying,
2302 additionalSegmentLength, additionalSegmentLocation);
2307 additionalSegmentLengths.push_back(additionalSegmentLength);
2308 additionalSegmentLocations.push_back(additionalSegmentLocation);
2313 success = verifyFractionalSpacingMultiple(log, m_spacing, tessLevelCases, additionalSegmentLengths, additionalSegmentLocations);
2315 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Invalid tessellation coordinates");
2319 // Base class for a case with one input attribute (in_v_position) and optionally a TCS; tests with a couple of different sets of tessellation levels.
2320 class BasicVariousTessLevelsPosAttrCase : public TestCase
2323 BasicVariousTessLevelsPosAttrCase (Context& context,
2325 const char* description,
2326 TessPrimitiveType primitiveType,
2327 SpacingMode spacing,
2328 const char* referenceImagePathPrefix)
2329 : TestCase (context, name, description)
2330 , m_primitiveType (primitiveType)
2331 , m_spacing (spacing)
2332 , m_referenceImagePathPrefix (referenceImagePathPrefix)
2338 IterateResult iterate (void);
2341 virtual const glu::ProgramSources makeSources (TessPrimitiveType, SpacingMode, const char* vtxOutPosAttrName) const = DE_NULL;
2344 static const int RENDER_SIZE = 256;
2346 const TessPrimitiveType m_primitiveType;
2347 const SpacingMode m_spacing;
2348 const string m_referenceImagePathPrefix;
2350 SharedPtr<const ShaderProgram> m_program;
2353 void BasicVariousTessLevelsPosAttrCase::init (void)
2355 checkTessellationSupport(m_context);
2356 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
2359 glu::ProgramSources sources = makeSources(m_primitiveType, m_spacing, "in_tc_position");
2360 DE_ASSERT(sources.sources[glu::SHADERTYPE_TESSELLATION_CONTROL].empty());
2362 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
2363 "${TESSELLATION_SHADER_REQUIRE}\n"
2364 "${GLSL_PER_VERTEX_IN_ARR}\n"
2365 "${GLSL_PER_VERTEX_OUT_ARR}\n"
2367 "layout (vertices = " + string(m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? "3" : "4") + ") out;\n"
2369 "in highp vec2 in_tc_position[];\n"
2371 "out highp vec2 in_te_position[];\n"
2373 "uniform mediump float u_tessLevelInner0;\n"
2374 "uniform mediump float u_tessLevelInner1;\n"
2375 "uniform mediump float u_tessLevelOuter0;\n"
2376 "uniform mediump float u_tessLevelOuter1;\n"
2377 "uniform mediump float u_tessLevelOuter2;\n"
2378 "uniform mediump float u_tessLevelOuter3;\n"
2380 "void main (void)\n"
2382 " in_te_position[gl_InvocationID] = in_tc_position[gl_InvocationID];\n"
2384 " gl_TessLevelInner[0] = u_tessLevelInner0;\n"
2385 " gl_TessLevelInner[1] = u_tessLevelInner1;\n"
2387 " gl_TessLevelOuter[0] = u_tessLevelOuter0;\n"
2388 " gl_TessLevelOuter[1] = u_tessLevelOuter1;\n"
2389 " gl_TessLevelOuter[2] = u_tessLevelOuter2;\n"
2390 " gl_TessLevelOuter[3] = u_tessLevelOuter3;\n"
2393 sources << glu::TessellationControlSource(specializeShader(m_context, tessellationControlTemplate.c_str()));
2395 m_program = SharedPtr<const ShaderProgram>(new glu::ShaderProgram(m_context.getRenderContext(), sources));
2398 m_testCtx.getLog() << *m_program;
2399 if (!m_program->isOk())
2400 TCU_FAIL("Program compilation failed");
2403 void BasicVariousTessLevelsPosAttrCase::deinit (void)
2408 BasicVariousTessLevelsPosAttrCase::IterateResult BasicVariousTessLevelsPosAttrCase::iterate (void)
2414 } tessLevelCases[] =
2416 { { 9.0f, 9.0f }, { 9.0f, 9.0f, 9.0f, 9.0f } },
2417 { { 8.0f, 11.0f }, { 13.0f, 15.0f, 18.0f, 21.0f } },
2418 { { 17.0f, 14.0f }, { 3.0f, 6.0f, 9.0f, 12.0f } }
2421 TestLog& log = m_testCtx.getLog();
2422 const RenderContext& renderCtx = m_context.getRenderContext();
2423 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
2424 const deUint32 programGL = m_program->getProgram();
2425 const glw::Functions& gl = renderCtx.getFunctions();
2426 const int patchSize = m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3
2427 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? 4
2428 : m_primitiveType == TESSPRIMITIVETYPE_ISOLINES ? 4
2431 setViewport(gl, viewport);
2432 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
2433 gl.useProgram(programGL);
2435 gl.patchParameteri(GL_PATCH_VERTICES, patchSize);
2437 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < DE_LENGTH_OF_ARRAY(tessLevelCases); tessLevelCaseNdx++)
2439 float innerLevels[2];
2440 float outerLevels[4];
2442 for (int i = 0; i < DE_LENGTH_OF_ARRAY(innerLevels); i++)
2443 innerLevels[i] = (float)getClampedRoundedTessLevel(m_spacing, tessLevelCases[tessLevelCaseNdx].inner[i]);
2445 for (int i = 0; i < DE_LENGTH_OF_ARRAY(outerLevels); i++)
2446 outerLevels[i] = (float)getClampedRoundedTessLevel(m_spacing, tessLevelCases[tessLevelCaseNdx].outer[i]);
2448 log << TestLog::Message << "Tessellation levels: " << tessellationLevelsString(&innerLevels[0], &outerLevels[0], m_primitiveType) << TestLog::EndMessage;
2450 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelInner0"), innerLevels[0]);
2451 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelInner1"), innerLevels[1]);
2452 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelOuter0"), outerLevels[0]);
2453 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelOuter1"), outerLevels[1]);
2454 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelOuter2"), outerLevels[2]);
2455 gl.uniform1f(gl.getUniformLocation(programGL, "u_tessLevelOuter3"), outerLevels[3]);
2457 gl.clear(GL_COLOR_BUFFER_BIT);
2460 vector<Vec2> positions;
2461 positions.reserve(4);
2463 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
2465 positions.push_back(Vec2( 0.8f, 0.6f));
2466 positions.push_back(Vec2( 0.0f, -0.786f));
2467 positions.push_back(Vec2(-0.8f, 0.6f));
2469 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS || m_primitiveType == TESSPRIMITIVETYPE_ISOLINES)
2471 positions.push_back(Vec2(-0.8f, -0.8f));
2472 positions.push_back(Vec2( 0.8f, -0.8f));
2473 positions.push_back(Vec2(-0.8f, 0.8f));
2474 positions.push_back(Vec2( 0.8f, 0.8f));
2479 DE_ASSERT((int)positions.size() == patchSize);
2481 const glu::VertexArrayBinding attrBindings[] =
2483 glu::va::Float("in_v_position", 2, (int)positions.size(), 0, &positions[0].x())
2486 glu::draw(m_context.getRenderContext(), programGL, DE_LENGTH_OF_ARRAY(attrBindings), &attrBindings[0],
2487 glu::pr::Patches(patchSize));
2488 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
2492 const tcu::Surface rendered = getPixels(renderCtx, viewport);
2493 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePathPrefix + "_" + de::toString(tessLevelCaseNdx) + ".png");
2494 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), rendered.getAccess(), 0.002f, tcu::COMPARE_LOG_RESULT);
2498 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
2504 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
2508 // Test that there are no obvious gaps in the triangulation of a tessellated triangle or quad.
2509 class BasicTriangleFillCoverCase : public BasicVariousTessLevelsPosAttrCase
2512 BasicTriangleFillCoverCase (Context& context, const char* name, const char* description, TessPrimitiveType primitiveType, SpacingMode spacing, const char* referenceImagePathPrefix)
2513 : BasicVariousTessLevelsPosAttrCase (context, name, description, primitiveType, spacing, referenceImagePathPrefix)
2515 DE_ASSERT(primitiveType == TESSPRIMITIVETYPE_TRIANGLES || primitiveType == TESSPRIMITIVETYPE_QUADS);
2521 checkGPUShader5Support(m_context);
2522 BasicVariousTessLevelsPosAttrCase::init();
2525 const glu::ProgramSources makeSources (TessPrimitiveType primitiveType, SpacingMode spacing, const char* vtxOutPosAttrName) const
2527 bool isGL45 = glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5));
2528 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2529 "${GLSL_PER_VERTEX_OUT}\n"
2531 "in highp vec2 in_v_position;\n"
2533 "out highp vec2 " + string(vtxOutPosAttrName) + ";\n"
2535 "void main (void)\n"
2537 " " + vtxOutPosAttrName + " = in_v_position;\n"
2539 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
2540 "${TESSELLATION_SHADER_REQUIRE}\n"
2541 "${GPU_SHADER5_REQUIRE}\n"
2542 "${GLSL_PER_VERTEX_IN_ARR}\n"
2543 "${GLSL_PRECISE_PER_VERTEX_OUT}\n"
2545 + getTessellationEvaluationInLayoutString(primitiveType, spacing) +
2547 "in highp vec2 in_te_position[];\n"
2549 + (isGL45 ? "" : "precise gl_Position;\n") +
2550 "void main (void)\n"
2552 + (primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
2554 " highp float d = 3.0 * min(gl_TessCoord.x, min(gl_TessCoord.y, gl_TessCoord.z));\n"
2555 " highp vec2 corner0 = in_te_position[0];\n"
2556 " highp vec2 corner1 = in_te_position[1];\n"
2557 " highp vec2 corner2 = in_te_position[2];\n"
2558 " highp vec2 pos = corner0*gl_TessCoord.x + corner1*gl_TessCoord.y + corner2*gl_TessCoord.z;\n"
2559 " highp vec2 fromCenter = pos - (corner0 + corner1 + corner2) / 3.0;\n"
2560 " highp float f = (1.0 - length(fromCenter)) * (1.5 - d);\n"
2561 " pos += 0.75 * f * fromCenter / (length(fromCenter) + 0.3);\n"
2562 " gl_Position = vec4(pos, 0.0, 1.0);\n"
2563 : primitiveType == TESSPRIMITIVETYPE_QUADS ?
2564 " highp vec2 corner0 = in_te_position[0];\n"
2565 " highp vec2 corner1 = in_te_position[1];\n"
2566 " highp vec2 corner2 = in_te_position[2];\n"
2567 " highp vec2 corner3 = in_te_position[3];\n"
2568 " highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
2569 " + ( gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
2570 " + (1.0-gl_TessCoord.x)*( gl_TessCoord.y)*corner2\n"
2571 " + ( gl_TessCoord.x)*( gl_TessCoord.y)*corner3;\n"
2572 " highp float d = 2.0 * min(abs(gl_TessCoord.x-0.5), abs(gl_TessCoord.y-0.5));\n"
2573 " highp vec2 fromCenter = pos - (corner0 + corner1 + corner2 + corner3) / 4.0;\n"
2574 " highp float f = (1.0 - length(fromCenter)) * sqrt(1.7 - d);\n"
2575 " pos += 0.75 * f * fromCenter / (length(fromCenter) + 0.3);\n"
2576 " gl_Position = vec4(pos, 0.0, 1.0);\n"
2579 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
2581 "layout (location = 0) out mediump vec4 o_color;\n"
2583 "void main (void)\n"
2585 " o_color = vec4(1.0);\n"
2588 return glu::ProgramSources()
2589 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
2590 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
2591 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()));
2595 // Check that there are no obvious overlaps in the triangulation of a tessellated triangle or quad.
2596 class BasicTriangleFillNonOverlapCase : public BasicVariousTessLevelsPosAttrCase
2599 BasicTriangleFillNonOverlapCase (Context& context, const char* name, const char* description, TessPrimitiveType primitiveType, SpacingMode spacing, const char* referenceImagePathPrefix)
2600 : BasicVariousTessLevelsPosAttrCase (context, name, description, primitiveType, spacing, referenceImagePathPrefix)
2602 DE_ASSERT(primitiveType == TESSPRIMITIVETYPE_TRIANGLES || primitiveType == TESSPRIMITIVETYPE_QUADS);
2606 const glu::ProgramSources makeSources (TessPrimitiveType primitiveType, SpacingMode spacing, const char* vtxOutPosAttrName) const
2608 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2609 "${GLSL_PER_VERTEX_OUT}\n"
2611 "in highp vec2 in_v_position;\n"
2613 "out highp vec2 " + string(vtxOutPosAttrName) + ";\n"
2615 "void main (void)\n"
2617 " " + vtxOutPosAttrName + " = in_v_position;\n"
2619 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
2620 "${TESSELLATION_SHADER_REQUIRE}\n"
2621 "${GLSL_PER_VERTEX_IN_ARR}\n"
2622 "${GLSL_PER_VERTEX_OUT}\n"
2624 + getTessellationEvaluationInLayoutString(primitiveType, spacing) +
2626 "in highp vec2 in_te_position[];\n"
2628 "out mediump vec4 in_f_color;\n"
2630 "uniform mediump float u_tessLevelInner0;\n"
2631 "uniform mediump float u_tessLevelInner1;\n"
2633 "void main (void)\n"
2635 + (primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
2637 " highp vec2 corner0 = in_te_position[0];\n"
2638 " highp vec2 corner1 = in_te_position[1];\n"
2639 " highp vec2 corner2 = in_te_position[2];\n"
2640 " highp vec2 pos = corner0*gl_TessCoord.x + corner1*gl_TessCoord.y + corner2*gl_TessCoord.z;\n"
2641 " gl_Position = vec4(pos, 0.0, 1.0);\n"
2642 " highp int numConcentricTriangles = int(round(u_tessLevelInner0)) / 2 + 1;\n"
2643 " highp float d = 3.0 * min(gl_TessCoord.x, min(gl_TessCoord.y, gl_TessCoord.z));\n"
2644 " highp int phase = int(d*float(numConcentricTriangles)) % 3;\n"
2645 " in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
2646 " : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
2647 " : vec4(0.0, 0.0, 1.0, 1.0);\n"
2648 : primitiveType == TESSPRIMITIVETYPE_QUADS ?
2649 " highp vec2 corner0 = in_te_position[0];\n"
2650 " highp vec2 corner1 = in_te_position[1];\n"
2651 " highp vec2 corner2 = in_te_position[2];\n"
2652 " highp vec2 corner3 = in_te_position[3];\n"
2653 " highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
2654 " + ( gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
2655 " + (1.0-gl_TessCoord.x)*( gl_TessCoord.y)*corner2\n"
2656 " + ( gl_TessCoord.x)*( gl_TessCoord.y)*corner3;\n"
2657 " gl_Position = vec4(pos, 0.0, 1.0);\n"
2658 " highp int phaseX = int(round((0.5 - abs(gl_TessCoord.x-0.5)) * u_tessLevelInner0));\n"
2659 " highp int phaseY = int(round((0.5 - abs(gl_TessCoord.y-0.5)) * u_tessLevelInner1));\n"
2660 " highp int phase = min(phaseX, phaseY) % 3;\n"
2661 " in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
2662 " : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
2663 " : vec4(0.0, 0.0, 1.0, 1.0);\n"
2666 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
2668 "layout (location = 0) out mediump vec4 o_color;\n"
2670 "in mediump vec4 in_f_color;\n"
2672 "void main (void)\n"
2674 " o_color = in_f_color;\n"
2677 return glu::ProgramSources()
2678 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
2679 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
2680 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()));
2684 // Basic isolines rendering case.
2685 class IsolinesRenderCase : public BasicVariousTessLevelsPosAttrCase
2688 IsolinesRenderCase (Context& context, const char* name, const char* description, SpacingMode spacing, const char* referenceImagePathPrefix)
2689 : BasicVariousTessLevelsPosAttrCase (context, name, description, TESSPRIMITIVETYPE_ISOLINES, spacing, referenceImagePathPrefix)
2694 const glu::ProgramSources makeSources (TessPrimitiveType primitiveType, SpacingMode spacing, const char* vtxOutPosAttrName) const
2696 DE_ASSERT(primitiveType == TESSPRIMITIVETYPE_ISOLINES);
2697 DE_UNREF(primitiveType);
2699 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2700 "${GLSL_PER_VERTEX_OUT}\n"
2702 "in highp vec2 in_v_position;\n"
2704 "out highp vec2 " + string(vtxOutPosAttrName) + ";\n"
2706 "void main (void)\n"
2708 " " + vtxOutPosAttrName + " = in_v_position;\n"
2710 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
2711 "${TESSELLATION_SHADER_REQUIRE}\n"
2712 "${GLSL_PER_VERTEX_IN_ARR}\n"
2713 "${GLSL_PER_VERTEX_OUT}\n"
2715 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_ISOLINES, spacing) +
2717 "in highp vec2 in_te_position[];\n"
2719 "out mediump vec4 in_f_color;\n"
2721 "uniform mediump float u_tessLevelOuter0;\n"
2722 "uniform mediump float u_tessLevelOuter1;\n"
2724 "void main (void)\n"
2726 " highp vec2 corner0 = in_te_position[0];\n"
2727 " highp vec2 corner1 = in_te_position[1];\n"
2728 " highp vec2 corner2 = in_te_position[2];\n"
2729 " highp vec2 corner3 = in_te_position[3];\n"
2730 " highp vec2 pos = (1.0-gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner0\n"
2731 " + ( gl_TessCoord.x)*(1.0-gl_TessCoord.y)*corner1\n"
2732 " + (1.0-gl_TessCoord.x)*( gl_TessCoord.y)*corner2\n"
2733 " + ( gl_TessCoord.x)*( gl_TessCoord.y)*corner3;\n"
2734 " pos.y += 0.15*sin(gl_TessCoord.x*10.0);\n"
2735 " gl_Position = vec4(pos, 0.0, 1.0);\n"
2736 " highp int phaseX = int(round(gl_TessCoord.x*u_tessLevelOuter1));\n"
2737 " highp int phaseY = int(round(gl_TessCoord.y*u_tessLevelOuter0));\n"
2738 " highp int phase = (phaseX + phaseY) % 3;\n"
2739 " in_f_color = phase == 0 ? vec4(1.0, 0.0, 0.0, 1.0)\n"
2740 " : phase == 1 ? vec4(0.0, 1.0, 0.0, 1.0)\n"
2741 " : vec4(0.0, 0.0, 1.0, 1.0);\n"
2743 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
2745 "layout (location = 0) out mediump vec4 o_color;\n"
2747 "in mediump vec4 in_f_color;\n"
2749 "void main (void)\n"
2751 " o_color = in_f_color;\n"
2754 return glu::ProgramSources()
2755 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
2756 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
2757 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()));
2761 // Test the "cw" and "ccw" TES input layout qualifiers.
2762 class WindingCase : public TestCase
2765 WindingCase (Context& context, const char* name, const char* description, TessPrimitiveType primitiveType, Winding winding)
2766 : TestCase (context, name, description)
2767 , m_primitiveType (primitiveType)
2768 , m_winding (winding)
2770 DE_ASSERT(primitiveType == TESSPRIMITIVETYPE_TRIANGLES || primitiveType == TESSPRIMITIVETYPE_QUADS);
2775 IterateResult iterate (void);
2778 static const int RENDER_SIZE = 64;
2780 const TessPrimitiveType m_primitiveType;
2781 const Winding m_winding;
2783 SharedPtr<const ShaderProgram> m_program;
2786 void WindingCase::init (void)
2788 checkTessellationSupport(m_context);
2789 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
2791 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2792 "${GLSL_PER_VERTEX_OUT}\n"
2794 "void main (void)\n"
2797 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
2798 "${TESSELLATION_SHADER_REQUIRE}\n"
2799 "${GLSL_PER_VERTEX_IN_ARR}\n"
2800 "${GLSL_PER_VERTEX_OUT_ARR}\n"
2802 "layout (vertices = 1) out;\n"
2804 "void main (void)\n"
2806 " gl_TessLevelInner[0] = 5.0;\n"
2807 " gl_TessLevelInner[1] = 5.0;\n"
2809 " gl_TessLevelOuter[0] = 5.0;\n"
2810 " gl_TessLevelOuter[1] = 5.0;\n"
2811 " gl_TessLevelOuter[2] = 5.0;\n"
2812 " gl_TessLevelOuter[3] = 5.0;\n"
2814 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
2815 "${TESSELLATION_SHADER_REQUIRE}\n"
2816 "${GLSL_PER_VERTEX_IN_ARR}\n"
2817 "${GLSL_PER_VERTEX_OUT}\n"
2819 + getTessellationEvaluationInLayoutString(m_primitiveType, m_winding) +
2821 "void main (void)\n"
2823 " gl_Position = vec4(gl_TessCoord.xy*2.0 - 1.0, 0.0, 1.0);\n"
2825 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
2827 "layout (location = 0) out mediump vec4 o_color;\n"
2829 "void main (void)\n"
2831 " o_color = vec4(1.0);\n"
2834 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
2835 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
2836 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
2837 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
2838 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
2840 m_testCtx.getLog() << *m_program;
2841 if (!m_program->isOk())
2842 TCU_FAIL("Program compilation failed");
2845 void WindingCase::deinit (void)
2850 WindingCase::IterateResult WindingCase::iterate (void)
2852 TestLog& log = m_testCtx.getLog();
2853 const RenderContext& renderCtx = m_context.getRenderContext();
2854 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
2855 const deUint32 programGL = m_program->getProgram();
2856 const glw::Functions& gl = renderCtx.getFunctions();
2857 const glu::VertexArray vao (renderCtx);
2859 bool success = true;
2861 setViewport(gl, viewport);
2862 gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
2863 gl.useProgram(programGL);
2865 gl.patchParameteri(GL_PATCH_VERTICES, 1);
2867 gl.enable(GL_CULL_FACE);
2869 gl.bindVertexArray(*vao);
2871 log << TestLog::Message << "Face culling enabled" << TestLog::EndMessage;
2873 for (int frontFaceWinding = 0; frontFaceWinding < WINDING_LAST; frontFaceWinding++)
2875 log << TestLog::Message << "Setting glFrontFace(" << (frontFaceWinding == WINDING_CW ? "GL_CW" : "GL_CCW") << ")" << TestLog::EndMessage;
2877 gl.frontFace(frontFaceWinding == WINDING_CW ? GL_CW : GL_CCW);
2879 gl.clear(GL_COLOR_BUFFER_BIT);
2880 gl.drawArrays(GL_PATCHES, 0, 1);
2881 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
2884 const tcu::Surface rendered = getPixels(renderCtx, viewport);
2885 log << TestLog::Image("RenderedImage", "Rendered Image", rendered);
2888 const int totalNumPixels = rendered.getWidth()*rendered.getHeight();
2889 const int badPixelTolerance = m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 5*de::max(rendered.getWidth(), rendered.getHeight()) : 0;
2891 int numWhitePixels = 0;
2892 int numRedPixels = 0;
2893 for (int y = 0; y < rendered.getHeight(); y++)
2894 for (int x = 0; x < rendered.getWidth(); x++)
2896 numWhitePixels += rendered.getPixel(x, y) == tcu::RGBA::white() ? 1 : 0;
2897 numRedPixels += rendered.getPixel(x, y) == tcu::RGBA::red() ? 1 : 0;
2900 DE_ASSERT(numWhitePixels + numRedPixels <= totalNumPixels);
2902 log << TestLog::Message << "Note: got " << numWhitePixels << " white and " << numRedPixels << " red pixels" << TestLog::EndMessage;
2904 if (totalNumPixels - numWhitePixels - numRedPixels > badPixelTolerance)
2906 log << TestLog::Message << "Failure: Got " << totalNumPixels - numWhitePixels - numRedPixels << " other than white or red pixels (maximum tolerance " << badPixelTolerance << ")" << TestLog::EndMessage;
2911 if ((Winding)frontFaceWinding == m_winding)
2913 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
2915 if (de::abs(numWhitePixels - totalNumPixels/2) > badPixelTolerance)
2917 log << TestLog::Message << "Failure: wrong number of white pixels; expected approximately " << totalNumPixels/2 << TestLog::EndMessage;
2922 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
2924 if (numWhitePixels != totalNumPixels)
2926 log << TestLog::Message << "Failure: expected only white pixels (full-viewport quad)" << TestLog::EndMessage;
2936 if (numWhitePixels != 0)
2938 log << TestLog::Message << "Failure: expected only red pixels (everything culled)" << TestLog::EndMessage;
2947 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Image verification failed");
2951 // Test potentially differing input and output patch sizes.
2952 class PatchVertexCountCase : public TestCase
2955 PatchVertexCountCase (Context& context, const char* name, const char* description, int inputPatchSize, int outputPatchSize, const char* referenceImagePath)
2956 : TestCase (context, name, description)
2957 , m_inputPatchSize (inputPatchSize)
2958 , m_outputPatchSize (outputPatchSize)
2959 , m_referenceImagePath (referenceImagePath)
2965 IterateResult iterate (void);
2968 static const int RENDER_SIZE = 256;
2970 const int m_inputPatchSize;
2971 const int m_outputPatchSize;
2973 const string m_referenceImagePath;
2975 SharedPtr<const ShaderProgram> m_program;
2978 void PatchVertexCountCase::init (void)
2980 checkTessellationSupport(m_context);
2981 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
2983 const string inSizeStr = de::toString(m_inputPatchSize);
2984 const string outSizeStr = de::toString(m_outputPatchSize);
2986 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
2987 "${GLSL_PER_VERTEX_OUT}\n"
2989 "in highp float in_v_attr;\n"
2991 "out highp float in_tc_attr;\n"
2993 "void main (void)\n"
2995 " in_tc_attr = in_v_attr;\n"
2997 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
2998 "${TESSELLATION_SHADER_REQUIRE}\n"
2999 "${GLSL_PER_VERTEX_IN_ARR}\n"
3000 "${GLSL_PER_VERTEX_OUT_ARR}\n"
3002 "layout (vertices = " + outSizeStr + ") out;\n"
3004 "in highp float in_tc_attr[];\n"
3006 "out highp float in_te_attr[];\n"
3008 "void main (void)\n"
3010 " in_te_attr[gl_InvocationID] = in_tc_attr[gl_InvocationID*" + inSizeStr + "/" + outSizeStr + "];\n"
3012 " gl_TessLevelInner[0] = 5.0;\n"
3013 " gl_TessLevelInner[1] = 5.0;\n"
3015 " gl_TessLevelOuter[0] = 5.0;\n"
3016 " gl_TessLevelOuter[1] = 5.0;\n"
3017 " gl_TessLevelOuter[2] = 5.0;\n"
3018 " gl_TessLevelOuter[3] = 5.0;\n"
3020 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
3021 "${TESSELLATION_SHADER_REQUIRE}\n"
3022 "${GLSL_PER_VERTEX_IN_ARR}\n"
3023 "${GLSL_PER_VERTEX_OUT}\n"
3025 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_QUADS) +
3027 "in highp float in_te_attr[];\n"
3029 "out mediump vec4 in_f_color;\n"
3031 "void main (void)\n"
3033 " highp float x = gl_TessCoord.x*2.0 - 1.0;\n"
3034 " highp float y = gl_TessCoord.y - in_te_attr[int(round(gl_TessCoord.x*float(" + outSizeStr + "-1)))];\n"
3035 " gl_Position = vec4(x, y, 0.0, 1.0);\n"
3036 " in_f_color = vec4(1.0);\n"
3038 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
3040 "layout (location = 0) out mediump vec4 o_color;\n"
3042 "in mediump vec4 in_f_color;\n"
3044 "void main (void)\n"
3046 " o_color = in_f_color;\n"
3049 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
3050 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
3051 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
3052 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
3053 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
3055 m_testCtx.getLog() << *m_program;
3056 if (!m_program->isOk())
3057 TCU_FAIL("Program compilation failed");
3060 void PatchVertexCountCase::deinit (void)
3065 PatchVertexCountCase::IterateResult PatchVertexCountCase::iterate (void)
3067 TestLog& log = m_testCtx.getLog();
3068 const RenderContext& renderCtx = m_context.getRenderContext();
3069 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
3070 const deUint32 programGL = m_program->getProgram();
3071 const glw::Functions& gl = renderCtx.getFunctions();
3073 setViewport(gl, viewport);
3074 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3075 gl.useProgram(programGL);
3077 log << TestLog::Message << "Note: input patch size is " << m_inputPatchSize << ", output patch size is " << m_outputPatchSize << TestLog::EndMessage;
3080 vector<float> attributeData;
3081 attributeData.reserve(m_inputPatchSize);
3083 for (int i = 0; i < m_inputPatchSize; i++)
3085 const float f = (float)i / (float)(m_inputPatchSize-1);
3086 attributeData.push_back(f*f);
3089 gl.patchParameteri(GL_PATCH_VERTICES, m_inputPatchSize);
3090 gl.clear(GL_COLOR_BUFFER_BIT);
3092 const glu::VertexArrayBinding attrBindings[] =
3094 glu::va::Float("in_v_attr", 1, (int)attributeData.size(), 0, &attributeData[0])
3097 glu::draw(m_context.getRenderContext(), programGL, DE_LENGTH_OF_ARRAY(attrBindings), &attrBindings[0],
3098 glu::pr::Patches(m_inputPatchSize));
3099 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
3103 const tcu::Surface rendered = getPixels(renderCtx, viewport);
3104 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePath);
3105 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), rendered.getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
3107 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Image comparison failed");
3112 // Test per-patch inputs/outputs.
3113 class PerPatchDataCase : public TestCase
3118 CASETYPE_PRIMITIVE_ID_TCS = 0,
3119 CASETYPE_PRIMITIVE_ID_TES,
3120 CASETYPE_PATCH_VERTICES_IN_TCS,
3121 CASETYPE_PATCH_VERTICES_IN_TES,
3122 CASETYPE_TESS_LEVEL_INNER0_TES,
3123 CASETYPE_TESS_LEVEL_INNER1_TES,
3124 CASETYPE_TESS_LEVEL_OUTER0_TES,
3125 CASETYPE_TESS_LEVEL_OUTER1_TES,
3126 CASETYPE_TESS_LEVEL_OUTER2_TES,
3127 CASETYPE_TESS_LEVEL_OUTER3_TES,
3132 PerPatchDataCase (Context& context, const char* name, const char* description, CaseType caseType, const char* referenceImagePath)
3133 : TestCase (context, name, description)
3134 , m_caseType (caseType)
3135 , m_referenceImagePath (caseTypeUsesRefImageFromFile(caseType) ? referenceImagePath : "")
3137 DE_ASSERT(caseTypeUsesRefImageFromFile(caseType) == (referenceImagePath != DE_NULL));
3142 IterateResult iterate (void);
3144 static const char* getCaseTypeName (CaseType);
3145 static const char* getCaseTypeDescription (CaseType);
3146 static bool caseTypeUsesRefImageFromFile (CaseType);
3149 static const int RENDER_SIZE = 256;
3150 static const int INPUT_PATCH_SIZE;
3151 static const int OUTPUT_PATCH_SIZE;
3153 const CaseType m_caseType;
3154 const string m_referenceImagePath;
3156 SharedPtr<const ShaderProgram> m_program;
3159 const int PerPatchDataCase::INPUT_PATCH_SIZE = 10;
3160 const int PerPatchDataCase::OUTPUT_PATCH_SIZE = 5;
3162 const char* PerPatchDataCase::getCaseTypeName (CaseType type)
3166 case CASETYPE_PRIMITIVE_ID_TCS: return "primitive_id_tcs";
3167 case CASETYPE_PRIMITIVE_ID_TES: return "primitive_id_tes";
3168 case CASETYPE_PATCH_VERTICES_IN_TCS: return "patch_vertices_in_tcs";
3169 case CASETYPE_PATCH_VERTICES_IN_TES: return "patch_vertices_in_tes";
3170 case CASETYPE_TESS_LEVEL_INNER0_TES: return "tess_level_inner_0_tes";
3171 case CASETYPE_TESS_LEVEL_INNER1_TES: return "tess_level_inner_1_tes";
3172 case CASETYPE_TESS_LEVEL_OUTER0_TES: return "tess_level_outer_0_tes";
3173 case CASETYPE_TESS_LEVEL_OUTER1_TES: return "tess_level_outer_1_tes";
3174 case CASETYPE_TESS_LEVEL_OUTER2_TES: return "tess_level_outer_2_tes";
3175 case CASETYPE_TESS_LEVEL_OUTER3_TES: return "tess_level_outer_3_tes";
3182 const char* PerPatchDataCase::getCaseTypeDescription (CaseType type)
3186 case CASETYPE_PRIMITIVE_ID_TCS: return "Read gl_PrimitiveID in TCS and pass it as patch output to TES";
3187 case CASETYPE_PRIMITIVE_ID_TES: return "Read gl_PrimitiveID in TES";
3188 case CASETYPE_PATCH_VERTICES_IN_TCS: return "Read gl_PatchVerticesIn in TCS and pass it as patch output to TES";
3189 case CASETYPE_PATCH_VERTICES_IN_TES: return "Read gl_PatchVerticesIn in TES";
3190 case CASETYPE_TESS_LEVEL_INNER0_TES: return "Read gl_TessLevelInner[0] in TES";
3191 case CASETYPE_TESS_LEVEL_INNER1_TES: return "Read gl_TessLevelInner[1] in TES";
3192 case CASETYPE_TESS_LEVEL_OUTER0_TES: return "Read gl_TessLevelOuter[0] in TES";
3193 case CASETYPE_TESS_LEVEL_OUTER1_TES: return "Read gl_TessLevelOuter[1] in TES";
3194 case CASETYPE_TESS_LEVEL_OUTER2_TES: return "Read gl_TessLevelOuter[2] in TES";
3195 case CASETYPE_TESS_LEVEL_OUTER3_TES: return "Read gl_TessLevelOuter[3] in TES";
3202 bool PerPatchDataCase::caseTypeUsesRefImageFromFile (CaseType type)
3206 case CASETYPE_PRIMITIVE_ID_TCS:
3207 case CASETYPE_PRIMITIVE_ID_TES:
3215 void PerPatchDataCase::init (void)
3217 checkTessellationSupport(m_context);
3218 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
3220 DE_ASSERT(OUTPUT_PATCH_SIZE < INPUT_PATCH_SIZE);
3222 const string inSizeStr = de::toString(INPUT_PATCH_SIZE);
3223 const string outSizeStr = de::toString(OUTPUT_PATCH_SIZE);
3225 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
3226 "${GLSL_PER_VERTEX_OUT}\n"
3228 "in highp float in_v_attr;\n"
3230 "out highp float in_tc_attr;\n"
3232 "void main (void)\n"
3234 " in_tc_attr = in_v_attr;\n"
3236 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
3237 "${TESSELLATION_SHADER_REQUIRE}\n"
3238 "${GLSL_PER_VERTEX_IN_ARR}\n"
3239 "${GLSL_PER_VERTEX_OUT_ARR}\n"
3241 "layout (vertices = " + outSizeStr + ") out;\n"
3243 "in highp float in_tc_attr[];\n"
3245 "out highp float in_te_attr[];\n"
3246 + (m_caseType == CASETYPE_PRIMITIVE_ID_TCS ? "patch out mediump int in_te_primitiveIDFromTCS;\n"
3247 : m_caseType == CASETYPE_PATCH_VERTICES_IN_TCS ? "patch out mediump int in_te_patchVerticesInFromTCS;\n"
3250 "void main (void)\n"
3252 " in_te_attr[gl_InvocationID] = in_tc_attr[gl_InvocationID];\n"
3253 + (m_caseType == CASETYPE_PRIMITIVE_ID_TCS ? "\tin_te_primitiveIDFromTCS = gl_PrimitiveID;\n"
3254 : m_caseType == CASETYPE_PATCH_VERTICES_IN_TCS ? "\tin_te_patchVerticesInFromTCS = gl_PatchVerticesIn;\n"
3257 " gl_TessLevelInner[0] = 9.0;\n"
3258 " gl_TessLevelInner[1] = 8.0;\n"
3260 " gl_TessLevelOuter[0] = 7.0;\n"
3261 " gl_TessLevelOuter[1] = 6.0;\n"
3262 " gl_TessLevelOuter[2] = 5.0;\n"
3263 " gl_TessLevelOuter[3] = 4.0;\n"
3265 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
3266 "${TESSELLATION_SHADER_REQUIRE}\n"
3267 "${GLSL_PER_VERTEX_IN_ARR}\n"
3268 "${GLSL_PER_VERTEX_OUT}\n"
3270 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_QUADS) +
3272 "in highp float in_te_attr[];\n"
3273 + (m_caseType == CASETYPE_PRIMITIVE_ID_TCS ? "patch in mediump int in_te_primitiveIDFromTCS;\n"
3274 : m_caseType == CASETYPE_PATCH_VERTICES_IN_TCS ? "patch in mediump int in_te_patchVerticesInFromTCS;\n"
3277 "out mediump vec4 in_f_color;\n"
3279 "uniform highp float u_xScale;\n"
3281 "void main (void)\n"
3283 " highp float x = (gl_TessCoord.x*u_xScale + in_te_attr[0]) * 2.0 - 1.0;\n"
3284 " highp float y = gl_TessCoord.y*2.0 - 1.0;\n"
3285 " gl_Position = vec4(x, y, 0.0, 1.0);\n"
3286 + (m_caseType == CASETYPE_PRIMITIVE_ID_TCS ? "\tbool ok = in_te_primitiveIDFromTCS == 3;\n"
3287 : m_caseType == CASETYPE_PRIMITIVE_ID_TES ? "\tbool ok = gl_PrimitiveID == 3;\n"
3288 : m_caseType == CASETYPE_PATCH_VERTICES_IN_TCS ? "\tbool ok = in_te_patchVerticesInFromTCS == " + inSizeStr + ";\n"
3289 : m_caseType == CASETYPE_PATCH_VERTICES_IN_TES ? "\tbool ok = gl_PatchVerticesIn == " + outSizeStr + ";\n"
3290 : m_caseType == CASETYPE_TESS_LEVEL_INNER0_TES ? "\tbool ok = abs(gl_TessLevelInner[0] - 9.0) < 0.1f;\n"
3291 : m_caseType == CASETYPE_TESS_LEVEL_INNER1_TES ? "\tbool ok = abs(gl_TessLevelInner[1] - 8.0) < 0.1f;\n"
3292 : m_caseType == CASETYPE_TESS_LEVEL_OUTER0_TES ? "\tbool ok = abs(gl_TessLevelOuter[0] - 7.0) < 0.1f;\n"
3293 : m_caseType == CASETYPE_TESS_LEVEL_OUTER1_TES ? "\tbool ok = abs(gl_TessLevelOuter[1] - 6.0) < 0.1f;\n"
3294 : m_caseType == CASETYPE_TESS_LEVEL_OUTER2_TES ? "\tbool ok = abs(gl_TessLevelOuter[2] - 5.0) < 0.1f;\n"
3295 : m_caseType == CASETYPE_TESS_LEVEL_OUTER3_TES ? "\tbool ok = abs(gl_TessLevelOuter[3] - 4.0) < 0.1f;\n"
3297 " in_f_color = ok ? vec4(1.0) : vec4(vec3(0.0), 1.0);\n"
3299 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
3301 "layout (location = 0) out mediump vec4 o_color;\n"
3303 "in mediump vec4 in_f_color;\n"
3305 "void main (void)\n"
3307 " o_color = in_f_color;\n"
3310 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
3311 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
3312 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
3313 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
3314 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
3316 m_testCtx.getLog() << *m_program;
3317 if (!m_program->isOk())
3318 TCU_FAIL("Program compilation failed");
3321 void PerPatchDataCase::deinit (void)
3326 PerPatchDataCase::IterateResult PerPatchDataCase::iterate (void)
3328 TestLog& log = m_testCtx.getLog();
3329 const RenderContext& renderCtx = m_context.getRenderContext();
3330 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
3331 const deUint32 programGL = m_program->getProgram();
3332 const glw::Functions& gl = renderCtx.getFunctions();
3334 setViewport(gl, viewport);
3335 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3336 gl.useProgram(programGL);
3338 log << TestLog::Message << "Note: input patch size is " << INPUT_PATCH_SIZE << ", output patch size is " << OUTPUT_PATCH_SIZE << TestLog::EndMessage;
3341 const int numPrimitives = m_caseType == CASETYPE_PRIMITIVE_ID_TCS || m_caseType == CASETYPE_PRIMITIVE_ID_TES ? 8 : 1;
3343 vector<float> attributeData;
3344 attributeData.reserve(numPrimitives*INPUT_PATCH_SIZE);
3346 for (int i = 0; i < numPrimitives; i++)
3348 attributeData.push_back((float)i / (float)numPrimitives);
3349 for (int j = 0; j < INPUT_PATCH_SIZE-1; j++)
3350 attributeData.push_back(0.0f);
3353 gl.patchParameteri(GL_PATCH_VERTICES, INPUT_PATCH_SIZE);
3354 gl.clear(GL_COLOR_BUFFER_BIT);
3356 gl.uniform1f(gl.getUniformLocation(programGL, "u_xScale"), 1.0f / (float)numPrimitives);
3358 const glu::VertexArrayBinding attrBindings[] =
3360 glu::va::Float("in_v_attr", 1, (int)attributeData.size(), 0, &attributeData[0])
3363 glu::draw(m_context.getRenderContext(), programGL, DE_LENGTH_OF_ARRAY(attrBindings), &attrBindings[0],
3364 glu::pr::Patches(numPrimitives*INPUT_PATCH_SIZE));
3365 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
3369 const tcu::Surface rendered = getPixels(renderCtx, viewport);
3371 if (m_caseType == CASETYPE_PRIMITIVE_ID_TCS || m_caseType == CASETYPE_PRIMITIVE_ID_TES)
3373 DE_ASSERT(caseTypeUsesRefImageFromFile(m_caseType));
3375 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePath);
3376 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), rendered.getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
3378 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Image comparison failed");
3383 DE_ASSERT(!caseTypeUsesRefImageFromFile(m_caseType));
3385 log << TestLog::Image("RenderedImage", "Rendered Image", rendered);
3387 for (int y = 0; y < rendered.getHeight(); y++)
3388 for (int x = 0; x < rendered.getWidth(); x++)
3390 if (rendered.getPixel(x, y) != tcu::RGBA::white())
3392 log << TestLog::Message << "Failure: expected all white pixels" << TestLog::EndMessage;
3393 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
3398 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3404 // Basic barrier() usage in TCS.
3405 class BarrierCase : public TestCase
3408 BarrierCase (Context& context, const char* name, const char* description, const char* referenceImagePath)
3409 : TestCase (context, name, description)
3410 , m_referenceImagePath (referenceImagePath)
3416 IterateResult iterate (void);
3419 static const int RENDER_SIZE = 256;
3420 static const int NUM_VERTICES;
3422 const string m_referenceImagePath;
3424 SharedPtr<const ShaderProgram> m_program;
3427 const int BarrierCase::NUM_VERTICES = 32;
3429 void BarrierCase::init (void)
3431 checkTessellationSupport(m_context);
3432 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
3434 const string numVertsStr = de::toString(NUM_VERTICES);
3436 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
3437 "${GLSL_PER_VERTEX_OUT}\n"
3439 "in highp float in_v_attr;\n"
3441 "out highp float in_tc_attr;\n"
3443 "void main (void)\n"
3445 " in_tc_attr = in_v_attr;\n"
3447 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
3448 "${TESSELLATION_SHADER_REQUIRE}\n"
3449 "${GLSL_PER_VERTEX_IN_ARR}\n"
3450 "${GLSL_PER_VERTEX_OUT_ARR}\n"
3452 "layout (vertices = " + numVertsStr + ") out;\n"
3454 "in highp float in_tc_attr[];\n"
3456 "out highp float in_te_attr[];\n"
3457 "patch out highp float in_te_patchAttr;\n"
3459 "void main (void)\n"
3461 " in_te_attr[gl_InvocationID] = in_tc_attr[gl_InvocationID];\n"
3462 " in_te_patchAttr = 0.0f;\n"
3464 " if (gl_InvocationID == 5)\n"
3465 " in_te_patchAttr = float(gl_InvocationID)*0.1;\n"
3467 " highp float temp = in_te_patchAttr + in_te_attr[gl_InvocationID];\n"
3469 " if (gl_InvocationID == " + numVertsStr + "-1)\n"
3470 " in_te_patchAttr = float(gl_InvocationID);\n"
3472 " in_te_attr[gl_InvocationID] = temp;\n"
3474 " temp = temp + in_te_attr[(gl_InvocationID+1) % " + numVertsStr + "];\n"
3476 " in_te_attr[gl_InvocationID] = 0.25*temp;\n"
3478 " gl_TessLevelInner[0] = 32.0;\n"
3479 " gl_TessLevelInner[1] = 32.0;\n"
3481 " gl_TessLevelOuter[0] = 32.0;\n"
3482 " gl_TessLevelOuter[1] = 32.0;\n"
3483 " gl_TessLevelOuter[2] = 32.0;\n"
3484 " gl_TessLevelOuter[3] = 32.0;\n"
3486 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
3487 "${TESSELLATION_SHADER_REQUIRE}\n"
3488 "${GLSL_PER_VERTEX_IN_ARR}\n"
3489 "${GLSL_PER_VERTEX_OUT}\n"
3491 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_QUADS) +
3493 "in highp float in_te_attr[];\n"
3494 "patch in highp float in_te_patchAttr;\n"
3496 "out highp float in_f_blue;\n"
3498 "void main (void)\n"
3500 " highp float x = gl_TessCoord.x*2.0 - 1.0;\n"
3501 " highp float y = gl_TessCoord.y - in_te_attr[int(round(gl_TessCoord.x*float(" + numVertsStr + "-1)))];\n"
3502 " gl_Position = vec4(x, y, 0.0, 1.0);\n"
3503 " in_f_blue = abs(in_te_patchAttr - float(" + numVertsStr + "-1));\n"
3505 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
3507 "layout (location = 0) out mediump vec4 o_color;\n"
3509 "in highp float in_f_blue;\n"
3511 "void main (void)\n"
3513 " o_color = vec4(1.0, 0.0, in_f_blue, 1.0);\n"
3516 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
3517 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
3518 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
3519 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
3520 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
3522 m_testCtx.getLog() << *m_program;
3523 if (!m_program->isOk())
3524 TCU_FAIL("Program compilation failed");
3527 void BarrierCase::deinit (void)
3532 BarrierCase::IterateResult BarrierCase::iterate (void)
3534 TestLog& log = m_testCtx.getLog();
3535 const RenderContext& renderCtx = m_context.getRenderContext();
3536 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
3537 const deUint32 programGL = m_program->getProgram();
3538 const glw::Functions& gl = renderCtx.getFunctions();
3540 setViewport(gl, viewport);
3541 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
3542 gl.useProgram(programGL);
3545 vector<float> attributeData(NUM_VERTICES);
3547 for (int i = 0; i < NUM_VERTICES; i++)
3548 attributeData[i] = (float)i / (float)(NUM_VERTICES-1);
3550 gl.patchParameteri(GL_PATCH_VERTICES, NUM_VERTICES);
3551 gl.clear(GL_COLOR_BUFFER_BIT);
3553 const glu::VertexArrayBinding attrBindings[] =
3555 glu::va::Float("in_v_attr", 1, (int)attributeData.size(), 0, &attributeData[0])
3558 glu::draw(m_context.getRenderContext(), programGL, DE_LENGTH_OF_ARRAY(attrBindings), &attrBindings[0],
3559 glu::pr::Patches(NUM_VERTICES));
3560 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw failed");
3564 const tcu::Surface rendered = getPixels(renderCtx, viewport);
3565 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePath);
3566 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), rendered.getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
3568 m_testCtx.setTestResult(success ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, success ? "Pass" : "Image comparison failed");
3573 /*--------------------------------------------------------------------*//*!
3574 * \brief Base class for testing invariance of entire primitive set
3576 * Draws two patches with identical tessellation levels and compares the
3577 * results. Repeats the same with other programs that are only different
3578 * in irrelevant ways; compares the results between these two programs.
3579 * Also potentially compares to results produced by different tessellation
3580 * levels (see e.g. invariance rule #6).
3581 * Furthermore, repeats the above with multiple different tessellation
3584 * The manner of primitive set comparison is defined by subclass. E.g.
3585 * case for invariance rule #1 tests that same vertices come out, in same
3586 * order; rule #5 only requires that the same triangles are output, but
3587 * not necessarily in the same order.
3588 *//*--------------------------------------------------------------------*/
3589 class PrimitiveSetInvarianceCase : public TestCase
3594 WINDINGUSAGE_CCW = 0,
3601 PrimitiveSetInvarianceCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, bool usePointMode, WindingUsage windingUsage)
3602 : TestCase (context, name, description)
3603 , m_primitiveType (primType)
3604 , m_spacing (spacing)
3605 , m_usePointMode (usePointMode)
3606 , m_windingUsage (windingUsage)
3612 IterateResult iterate (void);
3619 string description (void) const { return tessellationLevelsString(&inner[0], &outer[0]); }
3623 vector<TessLevels> levels;
3624 int mem; //!< Subclass-defined arbitrary piece of data, for type of the levelcase, if needed. Passed to compare().
3625 LevelCase (const TessLevels& lev) : levels(vector<TessLevels>(1, lev)), mem(0) {}
3626 LevelCase (void) : mem(0) {}
3629 virtual vector<LevelCase> genTessLevelCases (void) const;
3630 virtual bool compare (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, int levelCaseMem) const = 0;
3632 const TessPrimitiveType m_primitiveType;
3638 SharedPtr<const ShaderProgram> program;
3640 Program (Winding w, const SharedPtr<const ShaderProgram>& prog) : winding(w), program(prog) {}
3642 string description (void) const { return string() + "winding mode " + getWindingShaderName(winding); }
3645 static const int RENDER_SIZE = 16;
3647 const SpacingMode m_spacing;
3648 const bool m_usePointMode;
3649 const WindingUsage m_windingUsage;
3651 vector<Program> m_programs;
3654 vector<PrimitiveSetInvarianceCase::LevelCase> PrimitiveSetInvarianceCase::genTessLevelCases (void) const
3656 static const TessLevels basicTessLevelCases[] =
3658 { { 1.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
3659 { { 63.0f, 24.0f }, { 15.0f, 42.0f, 10.0f, 12.0f } },
3660 { { 3.0f, 2.0f }, { 6.0f, 8.0f, 7.0f, 9.0f } },
3661 { { 4.0f, 6.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
3662 { { 2.0f, 2.0f }, { 6.0f, 8.0f, 7.0f, 9.0f } },
3663 { { 5.0f, 6.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
3664 { { 1.0f, 6.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
3665 { { 5.0f, 1.0f }, { 2.0f, 3.0f, 1.0f, 4.0f } },
3666 { { 5.2f, 1.6f }, { 2.9f, 3.4f, 1.5f, 4.1f } }
3669 vector<LevelCase> result;
3670 for (int i = 0; i < DE_LENGTH_OF_ARRAY(basicTessLevelCases); i++)
3671 result.push_back(LevelCase(basicTessLevelCases[i]));
3674 de::Random rnd(123);
3675 for (int i = 0; i < 10; i++)
3678 for (int j = 0; j < DE_LENGTH_OF_ARRAY(levels.inner); j++)
3679 levels.inner[j] = rnd.getFloat(1.0f, 16.0f);
3680 for (int j = 0; j < DE_LENGTH_OF_ARRAY(levels.outer); j++)
3681 levels.outer[j] = rnd.getFloat(1.0f, 16.0f);
3682 result.push_back(LevelCase(levels));
3689 void PrimitiveSetInvarianceCase::init (void)
3691 const int numDifferentConstantExprCases = 2;
3692 vector<Winding> windings;
3693 switch (m_windingUsage)
3695 case WINDINGUSAGE_CCW: windings.push_back(WINDING_CCW); break;
3696 case WINDINGUSAGE_CW: windings.push_back(WINDING_CW); break;
3697 case WINDINGUSAGE_VARY: windings.push_back(WINDING_CCW);
3698 windings.push_back(WINDING_CW); break;
3699 default: DE_ASSERT(false);
3702 checkTessellationSupport(m_context);
3703 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
3705 for (int constantExprCaseNdx = 0; constantExprCaseNdx < numDifferentConstantExprCases; constantExprCaseNdx++)
3707 for (int windingCaseNdx = 0; windingCaseNdx < (int)windings.size(); windingCaseNdx++)
3709 const string floatLit01 = de::floatToString(10.0f / (float)(constantExprCaseNdx + 10), 2);
3710 const int programNdx = (int)m_programs.size();
3712 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
3713 "${GLSL_PER_VERTEX_OUT}\n"
3715 "in highp float in_v_attr;\n"
3716 "out highp float in_tc_attr;\n"
3718 "void main (void)\n"
3720 " in_tc_attr = in_v_attr;\n"
3722 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
3723 "${TESSELLATION_SHADER_REQUIRE}\n"
3724 "${GLSL_PER_VERTEX_IN_ARR}\n"
3725 "${GLSL_PER_VERTEX_OUT_ARR}\n"
3727 "layout (vertices = " + de::toString(constantExprCaseNdx+1) + ") out;\n"
3729 "in highp float in_tc_attr[];\n"
3731 "patch out highp float in_te_positionOffset;\n"
3733 "void main (void)\n"
3735 " in_te_positionOffset = in_tc_attr[6];\n"
3737 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
3738 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
3740 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
3741 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
3742 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
3743 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
3745 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
3746 "${TESSELLATION_SHADER_REQUIRE}\n"
3747 "${GLSL_PER_VERTEX_IN_ARR}\n"
3748 "${GLSL_PER_VERTEX_OUT}\n"
3750 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, windings[windingCaseNdx], m_usePointMode) +
3752 "patch in highp float in_te_positionOffset;\n"
3754 "out highp vec4 in_f_color;\n"
3755 "invariant out highp vec3 out_te_tessCoord;\n"
3757 "void main (void)\n"
3759 " gl_Position = vec4(gl_TessCoord.xy*" + floatLit01 + " - in_te_positionOffset + float(gl_PrimitiveID)*0.1, 0.0, 1.0);\n"
3760 " in_f_color = vec4(" + floatLit01 + ");\n"
3761 " out_te_tessCoord = gl_TessCoord;\n"
3763 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
3765 "layout (location = 0) out mediump vec4 o_color;\n"
3767 "in highp vec4 in_f_color;\n"
3769 "void main (void)\n"
3771 " o_color = in_f_color;\n"
3774 m_programs.push_back(Program(windings[windingCaseNdx],
3775 SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
3776 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
3777 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
3778 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
3779 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
3780 << glu::TransformFeedbackVarying ("out_te_tessCoord")
3781 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)))));
3784 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Program" + de::toString(programNdx), "Program " + de::toString(programNdx));
3786 if (programNdx == 0 || !m_programs.back().program->isOk())
3787 m_testCtx.getLog() << *m_programs.back().program;
3789 if (!m_programs.back().program->isOk())
3790 TCU_FAIL("Program compilation failed");
3793 m_testCtx.getLog() << TestLog::Message << "Note: program " << programNdx << " is similar to above, except some constants are different, and: " << m_programs.back().description() << TestLog::EndMessage;
3799 void PrimitiveSetInvarianceCase::deinit (void)
3804 PrimitiveSetInvarianceCase::IterateResult PrimitiveSetInvarianceCase::iterate (void)
3806 typedef TransformFeedbackHandler<Vec3> TFHandler;
3808 TestLog& log = m_testCtx.getLog();
3809 const RenderContext& renderCtx = m_context.getRenderContext();
3810 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
3811 const glw::Functions& gl = renderCtx.getFunctions();
3812 const vector<LevelCase> tessLevelCases = genTessLevelCases();
3813 vector<vector<int> > primitiveCounts;
3814 int maxNumPrimitives = -1;
3816 for (int caseNdx = 0; caseNdx < (int)tessLevelCases.size(); caseNdx++)
3818 primitiveCounts.push_back(vector<int>());
3819 for (int i = 0; i < (int)tessLevelCases[caseNdx].levels.size(); i++)
3821 const int primCount = referencePrimitiveCount(m_primitiveType, m_spacing, m_usePointMode,
3822 &tessLevelCases[caseNdx].levels[i].inner[0], &tessLevelCases[caseNdx].levels[i].outer[0]);
3823 primitiveCounts.back().push_back(primCount);
3824 maxNumPrimitives = de::max(maxNumPrimitives, primCount);
3828 const deUint32 primitiveTypeGL = outputPrimitiveTypeGL(m_primitiveType, m_usePointMode);
3829 const TFHandler transformFeedback (m_context.getRenderContext(), 2*maxNumPrimitives*numVerticesPerPrimitive(primitiveTypeGL));
3831 setViewport(gl, viewport);
3832 gl.patchParameteri(GL_PATCH_VERTICES, 7);
3834 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < (int)tessLevelCases.size(); tessLevelCaseNdx++)
3836 const LevelCase& levelCase = tessLevelCases[tessLevelCaseNdx];
3837 vector<Vec3> firstPrimVertices;
3840 string tessLevelsStr;
3841 for (int i = 0; i < (int)levelCase.levels.size(); i++)
3842 tessLevelsStr += (levelCase.levels.size() > 1 ? "\n" : "") + levelCase.levels[i].description();
3843 log << TestLog::Message << "Tessellation level sets: " << tessLevelsStr << TestLog::EndMessage;
3846 for (int subTessLevelCaseNdx = 0; subTessLevelCaseNdx < (int)levelCase.levels.size(); subTessLevelCaseNdx++)
3848 const TessLevels& tessLevels = levelCase.levels[subTessLevelCaseNdx];
3849 const float (&inner)[2] = tessLevels.inner;
3850 const float (&outer)[4] = tessLevels.outer;
3851 const float attribute[2*7] = { inner[0], inner[1], outer[0], outer[1], outer[2], outer[3], 0.0f,
3852 inner[0], inner[1], outer[0], outer[1], outer[2], outer[3], 0.5f };
3853 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, DE_LENGTH_OF_ARRAY(attribute), 0, &attribute[0]) };
3855 for (int programNdx = 0; programNdx < (int)m_programs.size(); programNdx++)
3857 const deUint32 programGL = m_programs[programNdx].program->getProgram();
3858 gl.useProgram(programGL);
3859 const TFHandler::Result tfResult = transformFeedback.renderAndGetPrimitives(programGL, primitiveTypeGL, DE_LENGTH_OF_ARRAY(bindings), &bindings[0], DE_LENGTH_OF_ARRAY(attribute));
3861 if (tfResult.numPrimitives != 2*primitiveCounts[tessLevelCaseNdx][subTessLevelCaseNdx])
3863 log << TestLog::Message << "Failure: GL reported GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN to be "
3864 << tfResult.numPrimitives << ", reference value is " << 2*primitiveCounts[tessLevelCaseNdx][subTessLevelCaseNdx]
3865 << TestLog::EndMessage;
3867 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of primitives");
3872 const int half = (int)tfResult.varying.size()/2;
3873 const vector<Vec3> prim0Vertices = vector<Vec3>(tfResult.varying.begin(), tfResult.varying.begin() + half);
3874 const Vec3* const prim1Vertices = &tfResult.varying[half];
3876 for (int vtxNdx = 0; vtxNdx < (int)prim0Vertices.size(); vtxNdx++)
3878 if (prim0Vertices[vtxNdx] != prim1Vertices[vtxNdx])
3880 log << TestLog::Message << "Failure: tessellation coordinate at index " << vtxNdx << " differs between two primitives drawn in one draw call" << TestLog::EndMessage
3881 << TestLog::Message << "Note: the coordinate is " << prim0Vertices[vtxNdx] << " for the first primitive and " << prim1Vertices[vtxNdx] << " for the second" << TestLog::EndMessage
3882 << TestLog::Message << "Note: tessellation levels for both primitives were: " << tessellationLevelsString(&inner[0], &outer[0]) << TestLog::EndMessage;
3883 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of primitives");
3888 if (programNdx == 0 && subTessLevelCaseNdx == 0)
3889 firstPrimVertices = prim0Vertices;
3892 const bool compareOk = compare(firstPrimVertices, prim0Vertices, levelCase.mem);
3895 log << TestLog::Message << "Note: comparison of tessellation coordinates failed; comparison was made between following cases:\n"
3896 << " - case A: program 0, tessellation levels: " << tessLevelCases[tessLevelCaseNdx].levels[0].description() << "\n"
3897 << " - case B: program " << programNdx << ", tessellation levels: " << tessLevels.description() << TestLog::EndMessage;
3898 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of primitives");
3907 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
3911 /*--------------------------------------------------------------------*//*!
3912 * \brief Test invariance rule #1
3914 * Test that the sequence of primitives input to the TES only depends on
3915 * the tessellation levels, tessellation mode, spacing mode, winding, and
3917 *//*--------------------------------------------------------------------*/
3918 class InvariantPrimitiveSetCase : public PrimitiveSetInvarianceCase
3921 InvariantPrimitiveSetCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
3922 : PrimitiveSetInvarianceCase(context, name, description, primType, spacing, usePointMode, winding == WINDING_CCW ? WINDINGUSAGE_CCW
3923 : winding == WINDING_CW ? WINDINGUSAGE_CW
3924 : WINDINGUSAGE_LAST)
3929 virtual bool compare (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, int) const
3931 for (int vtxNdx = 0; vtxNdx < (int)coordsA.size(); vtxNdx++)
3933 if (coordsA[vtxNdx] != coordsB[vtxNdx])
3935 m_testCtx.getLog() << TestLog::Message << "Failure: tessellation coordinate at index " << vtxNdx << " differs between two programs" << TestLog::EndMessage
3936 << TestLog::Message << "Note: the coordinate is " << coordsA[vtxNdx] << " for the first program and " << coordsB[vtxNdx] << " for the other" << TestLog::EndMessage;
3944 /*--------------------------------------------------------------------*//*!
3945 * \brief Test invariance rule #2
3947 * Test that the set of vertices along an outer edge of a quad or triangle
3948 * only depends on that edge's tessellation level, and spacing.
3950 * For each (outer) edge in the quad or triangle, draw multiple patches
3951 * with identical tessellation levels for that outer edge but with
3952 * different values for the other outer edges; compare, among the
3953 * primitives, the vertices generated for that outer edge. Repeat with
3954 * different programs, using different winding etc. settings. Compare
3955 * the edge's vertices between different programs.
3956 *//*--------------------------------------------------------------------*/
3957 class InvariantOuterEdgeCase : public TestCase
3960 InvariantOuterEdgeCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing)
3961 : TestCase (context, name, description)
3962 , m_primitiveType (primType)
3963 , m_spacing (spacing)
3965 DE_ASSERT(primType == TESSPRIMITIVETYPE_TRIANGLES || primType == TESSPRIMITIVETYPE_QUADS);
3970 IterateResult iterate (void);
3977 SharedPtr<const ShaderProgram> program;
3979 Program (Winding w, bool point, const SharedPtr<const ShaderProgram>& prog) : winding(w), usePointMode(point), program(prog) {}
3981 string description (void) const { return string() + "winding mode " + getWindingShaderName(winding) + ", " + (usePointMode ? "" : "don't ") + "use point mode"; }
3984 static vector<float> generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel);
3986 static const int RENDER_SIZE = 16;
3988 const TessPrimitiveType m_primitiveType;
3989 const SpacingMode m_spacing;
3991 vector<Program> m_programs;
3994 vector<float> InvariantOuterEdgeCase::generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel)
3996 de::Random rnd(123);
3997 return generateRandomPatchTessLevels(numPatches, constantOuterLevelIndex, constantOuterLevel, rnd);
4000 void InvariantOuterEdgeCase::init (void)
4002 checkTessellationSupport(m_context);
4003 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
4005 for (int windingI = 0; windingI < WINDING_LAST; windingI++)
4007 const Winding winding = (Winding)windingI;
4009 for (int usePointModeI = 0; usePointModeI <= 1; usePointModeI++)
4011 const bool usePointMode = usePointModeI != 0;
4012 const int programNdx = (int)m_programs.size();
4013 const string floatLit01 = de::floatToString(10.0f / (float)(programNdx + 10), 2);
4015 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
4016 "${GLSL_PER_VERTEX_OUT}\n"
4018 "in highp float in_v_attr;\n"
4019 "out highp float in_tc_attr;\n"
4021 "void main (void)\n"
4023 " in_tc_attr = in_v_attr;\n"
4025 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
4026 "${TESSELLATION_SHADER_REQUIRE}\n"
4027 "${GLSL_PER_VERTEX_IN_ARR}\n"
4028 "${GLSL_PER_VERTEX_OUT_ARR}\n"
4030 "layout (vertices = " + de::toString(programNdx+1) + ") out;\n"
4032 "in highp float in_tc_attr[];\n"
4034 "void main (void)\n"
4036 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
4037 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
4039 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
4040 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
4041 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
4042 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
4044 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
4045 "${TESSELLATION_SHADER_REQUIRE}\n"
4046 "${GLSL_PER_VERTEX_IN_ARR}\n"
4047 "${GLSL_PER_VERTEX_OUT}\n"
4049 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, winding, usePointMode) +
4051 "out highp vec4 in_f_color;\n"
4052 "invariant out highp vec3 out_te_tessCoord;\n"
4054 "void main (void)\n"
4056 " gl_Position = vec4(gl_TessCoord.xy*" + floatLit01 + " - float(gl_PrimitiveID)*0.05, 0.0, 1.0);\n"
4057 " in_f_color = vec4(" + floatLit01 + ");\n"
4058 " out_te_tessCoord = gl_TessCoord;\n"
4060 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
4062 "layout (location = 0) out mediump vec4 o_color;\n"
4064 "in highp vec4 in_f_color;\n"
4066 "void main (void)\n"
4068 " o_color = in_f_color;\n"
4071 m_programs.push_back(Program(winding, usePointMode,
4072 SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
4073 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
4074 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
4075 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
4076 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
4077 << glu::TransformFeedbackVarying ("out_te_tessCoord")
4078 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)))));
4081 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Program" + de::toString(programNdx), "Program " + de::toString(programNdx));
4083 if (programNdx == 0 || !m_programs.back().program->isOk())
4084 m_testCtx.getLog() << *m_programs.back().program;
4086 if (!m_programs.back().program->isOk())
4087 TCU_FAIL("Program compilation failed");
4090 m_testCtx.getLog() << TestLog::Message << "Note: program " << programNdx << " is similar to above, except some constants are different, and: " << m_programs.back().description() << TestLog::EndMessage;
4096 void InvariantOuterEdgeCase::deinit (void)
4101 InvariantOuterEdgeCase::IterateResult InvariantOuterEdgeCase::iterate (void)
4103 typedef TransformFeedbackHandler<Vec3> TFHandler;
4105 TestLog& log = m_testCtx.getLog();
4106 const RenderContext& renderCtx = m_context.getRenderContext();
4107 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
4108 const glw::Functions& gl = renderCtx.getFunctions();
4110 static const float singleOuterEdgeLevels[] = { 1.0f, 1.2f, 1.9f, 2.3f, 2.8f, 3.3f, 3.8f, 10.2f, 1.6f, 24.4f, 24.7f, 63.0f };
4111 const int numPatchesPerDrawCall = 10;
4112 const vector<OuterEdgeDescription> edgeDescriptions = outerEdgeDescriptions(m_primitiveType);
4115 // Compute the number vertices in the largest draw call, so we can allocate the TF buffer just once.
4116 int maxNumVerticesInDrawCall = 0;
4118 const vector<float> patchTessLevels = generatePatchTessLevels(numPatchesPerDrawCall, 0 /* outer-edge index doesn't affect vertex count */, arrayMax(singleOuterEdgeLevels));
4120 for (int usePointModeI = 0; usePointModeI <= 1; usePointModeI++)
4121 maxNumVerticesInDrawCall = de::max(maxNumVerticesInDrawCall,
4122 multiplePatchReferenceVertexCount(m_primitiveType, m_spacing, usePointModeI != 0, &patchTessLevels[0], numPatchesPerDrawCall));
4126 const TFHandler tfHandler(m_context.getRenderContext(), maxNumVerticesInDrawCall);
4128 setViewport(gl, viewport);
4129 gl.patchParameteri(GL_PATCH_VERTICES, 6);
4131 for (int outerEdgeIndex = 0; outerEdgeIndex < (int)edgeDescriptions.size(); outerEdgeIndex++)
4133 const OuterEdgeDescription& edgeDesc = edgeDescriptions[outerEdgeIndex];
4135 for (int outerEdgeLevelCaseNdx = 0; outerEdgeLevelCaseNdx < DE_LENGTH_OF_ARRAY(singleOuterEdgeLevels); outerEdgeLevelCaseNdx++)
4137 typedef std::set<Vec3, VecLexLessThan<3> > Vec3Set;
4139 const vector<float> patchTessLevels = generatePatchTessLevels(numPatchesPerDrawCall, outerEdgeIndex, singleOuterEdgeLevels[outerEdgeLevelCaseNdx]);
4140 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, (int)patchTessLevels.size(), 0, &patchTessLevels[0]) };
4141 Vec3Set firstOuterEdgeVertices; // Vertices of the outer edge of the first patch of the first program's draw call; used for comparison with other patches.
4143 log << TestLog::Message << "Testing with outer tessellation level " << singleOuterEdgeLevels[outerEdgeLevelCaseNdx]
4144 << " for the " << edgeDesc.description() << " edge, and with various levels for other edges, and with all programs" << TestLog::EndMessage;
4146 for (int programNdx = 0; programNdx < (int)m_programs.size(); programNdx++)
4148 const Program& program = m_programs[programNdx];
4149 const deUint32 programGL = program.program->getProgram();
4151 gl.useProgram(programGL);
4154 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, program.usePointMode),
4155 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], (int)patchTessLevels.size());
4156 const int refNumVertices = multiplePatchReferenceVertexCount(m_primitiveType, m_spacing, program.usePointMode, &patchTessLevels[0], numPatchesPerDrawCall);
4157 int numVerticesRead = 0;
4159 if ((int)tfResult.varying.size() != refNumVertices)
4161 log << TestLog::Message << "Failure: the number of vertices returned by transform feedback is "
4162 << tfResult.varying.size() << ", expected " << refNumVertices << TestLog::EndMessage
4163 << TestLog::Message << "Note: rendered " << numPatchesPerDrawCall
4164 << " patches in one draw call; tessellation levels for each patch are (in order [inner0, inner1, outer0, outer1, outer2, outer3]):\n"
4165 << containerStr(patchTessLevels, 6) << TestLog::EndMessage;
4167 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4171 // Check the vertices of each patch.
4173 for (int patchNdx = 0; patchNdx < numPatchesPerDrawCall; patchNdx++)
4175 const float* const innerLevels = &patchTessLevels[6*patchNdx + 0];
4176 const float* const outerLevels = &patchTessLevels[6*patchNdx + 2];
4177 const int patchNumVertices = referenceVertexCount(m_primitiveType, m_spacing, program.usePointMode, innerLevels, outerLevels);
4178 Vec3Set outerEdgeVertices;
4180 // We're interested in just the vertices on the current outer edge.
4181 for(int vtxNdx = numVerticesRead; vtxNdx < numVerticesRead + patchNumVertices; vtxNdx++)
4183 const Vec3& vtx = tfResult.varying[vtxNdx];
4184 if (edgeDesc.contains(vtx))
4185 outerEdgeVertices.insert(tfResult.varying[vtxNdx]);
4188 // Check that the outer edge contains an appropriate number of vertices.
4190 const int refNumVerticesOnOuterEdge = 1 + getClampedRoundedTessLevel(m_spacing, singleOuterEdgeLevels[outerEdgeLevelCaseNdx]);
4192 if ((int)outerEdgeVertices.size() != refNumVerticesOnOuterEdge)
4194 log << TestLog::Message << "Failure: the number of vertices on outer edge is " << outerEdgeVertices.size()
4195 << ", expected " << refNumVerticesOnOuterEdge << TestLog::EndMessage
4196 << TestLog::Message << "Note: vertices on the outer edge are:\n" << containerStr(outerEdgeVertices, 5, 0) << TestLog::EndMessage
4197 << TestLog::Message << "Note: the following parameters were used: " << program.description()
4198 << ", tessellation levels: " << tessellationLevelsString(innerLevels, outerLevels) << TestLog::EndMessage;
4199 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4204 // Compare the vertices to those of the first patch (unless this is the first patch).
4206 if (programNdx == 0 && patchNdx == 0)
4207 firstOuterEdgeVertices = outerEdgeVertices;
4210 if (firstOuterEdgeVertices != outerEdgeVertices)
4212 log << TestLog::Message << "Failure: vertices generated for the edge differ between the following cases:\n"
4213 << " - case A: " << m_programs[0].description() << ", tessellation levels: "
4214 << tessellationLevelsString(&patchTessLevels[0], &patchTessLevels[2]) << "\n"
4215 << " - case B: " << program.description() << ", tessellation levels: "
4216 << tessellationLevelsString(innerLevels, outerLevels) << TestLog::EndMessage;
4218 log << TestLog::Message << "Note: resulting vertices for the edge for the cases were:\n"
4219 << " - case A: " << containerStr(firstOuterEdgeVertices, 5, 14) << "\n"
4220 << " - case B: " << containerStr(outerEdgeVertices, 5, 14) << TestLog::EndMessage;
4222 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4227 numVerticesRead += patchNumVertices;
4230 DE_ASSERT(numVerticesRead == (int)tfResult.varying.size());
4238 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4242 /*--------------------------------------------------------------------*//*!
4243 * \brief Test invariance rule #3
4245 * Test that the vertices along an outer edge are placed symmetrically.
4247 * Draw multiple patches with different tessellation levels and different
4248 * point_mode, winding etc. Before outputting tesscoords with TF, mirror
4249 * the vertices in the TES such that every vertex on an outer edge -
4250 * except the possible middle vertex - should be duplicated in the output.
4251 * Check that appropriate duplicates exist.
4252 *//*--------------------------------------------------------------------*/
4253 class SymmetricOuterEdgeCase : public TestCase
4256 SymmetricOuterEdgeCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
4257 : TestCase (context, name, description)
4258 , m_primitiveType (primType)
4259 , m_spacing (spacing)
4260 , m_winding (winding)
4261 , m_usePointMode (usePointMode)
4267 IterateResult iterate (void);
4270 static vector<float> generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel);
4272 static const int RENDER_SIZE = 16;
4274 const TessPrimitiveType m_primitiveType;
4275 const SpacingMode m_spacing;
4276 const Winding m_winding;
4277 const bool m_usePointMode;
4279 SharedPtr<const glu::ShaderProgram> m_program;
4282 vector<float> SymmetricOuterEdgeCase::generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel)
4284 de::Random rnd(123);
4285 return generateRandomPatchTessLevels(numPatches, constantOuterLevelIndex, constantOuterLevel, rnd);
4288 void SymmetricOuterEdgeCase::init (void)
4290 checkTessellationSupport(m_context);
4291 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
4293 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
4295 "${GLSL_PER_VERTEX_OUT}\n"
4296 "in highp float in_v_attr;\n"
4297 "out highp float in_tc_attr;\n"
4299 "void main (void)\n"
4301 " in_tc_attr = in_v_attr;\n"
4303 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
4304 "${TESSELLATION_SHADER_REQUIRE}\n"
4305 "${GLSL_PER_VERTEX_IN_ARR}\n"
4306 "${GLSL_PER_VERTEX_OUT_ARR}\n"
4308 "layout (vertices = 1) out;\n"
4310 "in highp float in_tc_attr[];\n"
4312 "void main (void)\n"
4314 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
4315 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
4317 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
4318 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
4319 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
4320 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
4322 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
4323 "${TESSELLATION_SHADER_REQUIRE}\n"
4324 "${GLSL_PER_VERTEX_IN_ARR}\n"
4325 "${GLSL_PER_VERTEX_OUT}\n"
4327 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, m_winding, m_usePointMode) +
4329 "out highp vec4 in_f_color;\n"
4330 "out highp vec4 out_te_tessCoord_isMirrored;\n"
4332 "void main (void)\n"
4334 + (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
4335 " float x = gl_TessCoord.x;\n"
4336 " float y = gl_TessCoord.y;\n"
4337 " float z = gl_TessCoord.z;\n"
4338 " // Mirror one half of each outer edge onto the other half, except the endpoints (because they belong to two edges)\n"
4339 " out_te_tessCoord_isMirrored = z == 0.0 && x > 0.5 && x != 1.0 ? vec4(1.0-x, 1.0-y, 0.0, 1.0)\n"
4340 " : y == 0.0 && z > 0.5 && z != 1.0 ? vec4(1.0-x, 0.0, 1.0-z, 1.0)\n"
4341 " : x == 0.0 && y > 0.5 && y != 1.0 ? vec4( 0.0, 1.0-y, 1.0-z, 1.0)\n"
4342 " : vec4(x, y, z, 0.0);\n"
4343 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ?
4344 " float x = gl_TessCoord.x;\n"
4345 " float y = gl_TessCoord.y;\n"
4346 " // Mirror one half of each outer edge onto the other half, except the endpoints (because they belong to two edges)\n"
4347 " out_te_tessCoord_isMirrored = (x == 0.0 || x == 1.0) && y > 0.5 && y != 1.0 ? vec4( x, 1.0-y, 0.0, 1.0)\n"
4348 " : (y == 0.0 || y == 1.0) && x > 0.5 && x != 1.0 ? vec4(1.0-x, y, 0.0, 1.0)\n"
4349 " : vec4(x, y, 0.0, 0.0);\n"
4350 : m_primitiveType == TESSPRIMITIVETYPE_ISOLINES ?
4351 " float x = gl_TessCoord.x;\n"
4352 " float y = gl_TessCoord.y;\n"
4353 " // Mirror one half of each outer edge onto the other half\n"
4354 " out_te_tessCoord_isMirrored = (x == 0.0 || x == 1.0) && y > 0.5 ? vec4(x, 1.0-y, 0.0, 1.0)\n"
4355 " : vec4(x, y, 0.0, 0.0f);\n"
4358 " gl_Position = vec4(gl_TessCoord.xy, 0.0, 1.0);\n"
4359 " in_f_color = vec4(1.0);\n"
4361 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
4363 "layout (location = 0) out mediump vec4 o_color;\n"
4365 "in highp vec4 in_f_color;\n"
4367 "void main (void)\n"
4369 " o_color = in_f_color;\n"
4372 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
4373 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
4374 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
4375 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
4376 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
4377 << glu::TransformFeedbackVarying ("out_te_tessCoord_isMirrored")
4378 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
4380 m_testCtx.getLog() << *m_program;
4381 if (!m_program->isOk())
4382 TCU_FAIL("Program compilation failed");
4385 void SymmetricOuterEdgeCase::deinit (void)
4390 SymmetricOuterEdgeCase::IterateResult SymmetricOuterEdgeCase::iterate (void)
4392 typedef TransformFeedbackHandler<Vec4> TFHandler;
4394 TestLog& log = m_testCtx.getLog();
4395 const RenderContext& renderCtx = m_context.getRenderContext();
4396 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
4397 const glw::Functions& gl = renderCtx.getFunctions();
4399 static const float singleOuterEdgeLevels[] = { 1.0f, 1.2f, 1.9f, 2.3f, 2.8f, 3.3f, 3.8f, 10.2f, 1.6f, 24.4f, 24.7f, 63.0f };
4400 const vector<OuterEdgeDescription> edgeDescriptions = outerEdgeDescriptions(m_primitiveType);
4403 // Compute the number vertices in the largest draw call, so we can allocate the TF buffer just once.
4404 int maxNumVerticesInDrawCall;
4406 const vector<float> patchTessLevels = generatePatchTessLevels(1, 0 /* outer-edge index doesn't affect vertex count */, arrayMax(singleOuterEdgeLevels));
4407 maxNumVerticesInDrawCall = referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &patchTessLevels[0], &patchTessLevels[2]);
4411 const TFHandler tfHandler(m_context.getRenderContext(), maxNumVerticesInDrawCall);
4413 setViewport(gl, viewport);
4414 gl.patchParameteri(GL_PATCH_VERTICES, 6);
4416 for (int outerEdgeIndex = 0; outerEdgeIndex < (int)edgeDescriptions.size(); outerEdgeIndex++)
4418 const OuterEdgeDescription& edgeDesc = edgeDescriptions[outerEdgeIndex];
4420 for (int outerEdgeLevelCaseNdx = 0; outerEdgeLevelCaseNdx < DE_LENGTH_OF_ARRAY(singleOuterEdgeLevels); outerEdgeLevelCaseNdx++)
4422 typedef std::set<Vec3, VecLexLessThan<3> > Vec3Set;
4424 const vector<float> patchTessLevels = generatePatchTessLevels(1, outerEdgeIndex, singleOuterEdgeLevels[outerEdgeLevelCaseNdx]);
4425 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, (int)patchTessLevels.size(), 0, &patchTessLevels[0]) };
4427 log << TestLog::Message << "Testing with outer tessellation level " << singleOuterEdgeLevels[outerEdgeLevelCaseNdx]
4428 << " for the " << edgeDesc.description() << " edge, and with various levels for other edges" << TestLog::EndMessage;
4431 const deUint32 programGL = m_program->getProgram();
4433 gl.useProgram(programGL);
4436 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, m_usePointMode),
4437 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], (int)patchTessLevels.size());
4438 const int refNumVertices = referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &patchTessLevels[0], &patchTessLevels[2]);
4440 if ((int)tfResult.varying.size() != refNumVertices)
4442 log << TestLog::Message << "Failure: the number of vertices returned by transform feedback is "
4443 << tfResult.varying.size() << ", expected " << refNumVertices << TestLog::EndMessage
4444 << TestLog::Message << "Note: rendered 1 patch, tessellation levels are (in order [inner0, inner1, outer0, outer1, outer2, outer3]):\n"
4445 << containerStr(patchTessLevels, 6) << TestLog::EndMessage;
4447 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4451 // Check the vertices.
4454 Vec3Set nonMirroredEdgeVertices;
4455 Vec3Set mirroredEdgeVertices;
4457 // We're interested in just the vertices on the current outer edge.
4458 for(int vtxNdx = 0; vtxNdx < refNumVertices; vtxNdx++)
4460 const Vec3& vtx = tfResult.varying[vtxNdx].swizzle(0,1,2);
4461 if (edgeDesc.contains(vtx))
4463 // Ignore the middle vertex of the outer edge, as it's exactly at the mirroring point;
4464 // for isolines, also ignore (0, 0) and (1, 0) because there's no mirrored counterpart for them.
4465 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES && vtx == tcu::select(Vec3(0.0f), Vec3(0.5f), singleTrueMask<3>(edgeDesc.constantCoordinateIndex)))
4467 if (m_primitiveType == TESSPRIMITIVETYPE_QUADS && vtx.swizzle(0,1) == tcu::select(Vec2(edgeDesc.constantCoordinateValueChoices[0]),
4469 singleTrueMask<2>(edgeDesc.constantCoordinateIndex)))
4471 if (m_primitiveType == TESSPRIMITIVETYPE_ISOLINES && (vtx == Vec3(0.0f, 0.5f, 0.0f) || vtx == Vec3(1.0f, 0.5f, 0.0f) ||
4472 vtx == Vec3(0.0f, 0.0f, 0.0f) || vtx == Vec3(1.0f, 0.0f, 0.0f)))
4475 const bool isMirrored = tfResult.varying[vtxNdx].w() > 0.5f;
4477 mirroredEdgeVertices.insert(vtx);
4479 nonMirroredEdgeVertices.insert(vtx);
4483 if (m_primitiveType != TESSPRIMITIVETYPE_ISOLINES)
4485 // Check that both endpoints are present. Note that endpoints aren't mirrored by the shader, since they belong to more than one edge.
4490 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
4492 endpointA = tcu::select(Vec3(1.0f), Vec3(0.0f), singleTrueMask<3>((edgeDesc.constantCoordinateIndex + 1) % 3));
4493 endpointB = tcu::select(Vec3(1.0f), Vec3(0.0f), singleTrueMask<3>((edgeDesc.constantCoordinateIndex + 2) % 3));
4495 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
4497 endpointA.xy() = tcu::select(Vec2(edgeDesc.constantCoordinateValueChoices[0]), Vec2(0.0f), singleTrueMask<2>(edgeDesc.constantCoordinateIndex));
4498 endpointB.xy() = tcu::select(Vec2(edgeDesc.constantCoordinateValueChoices[0]), Vec2(1.0f), singleTrueMask<2>(edgeDesc.constantCoordinateIndex));
4503 if (!contains(nonMirroredEdgeVertices, endpointA) ||
4504 !contains(nonMirroredEdgeVertices, endpointB))
4506 log << TestLog::Message << "Failure: edge doesn't contain both endpoints, " << endpointA << " and " << endpointB << TestLog::EndMessage
4507 << TestLog::Message << "Note: non-mirrored vertices:\n" << containerStr(nonMirroredEdgeVertices, 5)
4508 << "\nmirrored vertices:\n" << containerStr(mirroredEdgeVertices, 5) << TestLog::EndMessage;
4509 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4512 nonMirroredEdgeVertices.erase(endpointA);
4513 nonMirroredEdgeVertices.erase(endpointB);
4516 if (nonMirroredEdgeVertices != mirroredEdgeVertices)
4518 log << TestLog::Message << "Failure: the set of mirrored edges isn't equal to the set of non-mirrored edges (ignoring endpoints and possible middle)" << TestLog::EndMessage
4519 << TestLog::Message << "Note: non-mirrored vertices:\n" << containerStr(nonMirroredEdgeVertices, 5)
4520 << "\nmirrored vertices:\n" << containerStr(mirroredEdgeVertices, 5) << TestLog::EndMessage;
4521 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4532 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4536 /*--------------------------------------------------------------------*//*!
4537 * \brief Test invariance rule #4
4539 * Test that the vertices on an outer edge don't depend on which of the
4540 * edges it is, other than with respect to component order.
4541 *//*--------------------------------------------------------------------*/
4542 class OuterEdgeVertexSetIndexIndependenceCase : public TestCase
4545 OuterEdgeVertexSetIndexIndependenceCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
4546 : TestCase (context, name, description)
4547 , m_primitiveType (primType)
4548 , m_spacing (spacing)
4549 , m_winding (winding)
4550 , m_usePointMode (usePointMode)
4552 DE_ASSERT(primType == TESSPRIMITIVETYPE_TRIANGLES || primType == TESSPRIMITIVETYPE_QUADS);
4557 IterateResult iterate (void);
4560 static vector<float> generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel);
4562 static const int RENDER_SIZE = 16;
4564 const TessPrimitiveType m_primitiveType;
4565 const SpacingMode m_spacing;
4566 const Winding m_winding;
4567 const bool m_usePointMode;
4569 SharedPtr<const glu::ShaderProgram> m_program;
4572 vector<float> OuterEdgeVertexSetIndexIndependenceCase::generatePatchTessLevels (int numPatches, int constantOuterLevelIndex, float constantOuterLevel)
4574 de::Random rnd(123);
4575 return generateRandomPatchTessLevels(numPatches, constantOuterLevelIndex, constantOuterLevel, rnd);
4578 void OuterEdgeVertexSetIndexIndependenceCase::init (void)
4580 checkTessellationSupport(m_context);
4581 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
4583 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
4584 "${GLSL_PER_VERTEX_OUT}\n"
4586 "in highp float in_v_attr;\n"
4587 "out highp float in_tc_attr;\n"
4589 "void main (void)\n"
4591 " in_tc_attr = in_v_attr;\n"
4593 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
4594 "${TESSELLATION_SHADER_REQUIRE}\n"
4595 "${GLSL_PER_VERTEX_IN_ARR}\n"
4596 "${GLSL_PER_VERTEX_OUT_ARR}\n"
4598 "layout (vertices = 1) out;\n"
4600 "in highp float in_tc_attr[];\n"
4602 "void main (void)\n"
4604 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
4605 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
4607 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
4608 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
4609 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
4610 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
4612 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
4613 "${TESSELLATION_SHADER_REQUIRE}\n"
4614 "${GLSL_PER_VERTEX_IN_ARR}\n"
4615 "${GLSL_PER_VERTEX_OUT}\n"
4617 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, m_winding, m_usePointMode) +
4619 "out highp vec4 in_f_color;\n"
4620 "out highp vec3 out_te_tessCoord;\n"
4622 "void main (void)\n"
4624 " out_te_tessCoord = gl_TessCoord;"
4625 " gl_Position = vec4(gl_TessCoord.xy, 0.0, 1.0);\n"
4626 " in_f_color = vec4(1.0);\n"
4628 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
4630 "layout (location = 0) out mediump vec4 o_color;\n"
4632 "in highp vec4 in_f_color;\n"
4634 "void main (void)\n"
4636 " o_color = in_f_color;\n"
4639 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
4640 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
4641 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
4642 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
4643 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
4644 << glu::TransformFeedbackVarying ("out_te_tessCoord")
4645 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
4647 m_testCtx.getLog() << *m_program;
4648 if (!m_program->isOk())
4649 TCU_FAIL("Program compilation failed");
4652 void OuterEdgeVertexSetIndexIndependenceCase::deinit (void)
4657 OuterEdgeVertexSetIndexIndependenceCase::IterateResult OuterEdgeVertexSetIndexIndependenceCase::iterate (void)
4659 typedef TransformFeedbackHandler<Vec3> TFHandler;
4661 TestLog& log = m_testCtx.getLog();
4662 const RenderContext& renderCtx = m_context.getRenderContext();
4663 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
4664 const glw::Functions& gl = renderCtx.getFunctions();
4665 const deUint32 programGL = m_program->getProgram();
4667 static const float singleOuterEdgeLevels[] = { 1.0f, 1.2f, 1.9f, 2.3f, 2.8f, 3.3f, 3.8f, 10.2f, 1.6f, 24.4f, 24.7f, 63.0f };
4668 const vector<OuterEdgeDescription> edgeDescriptions = outerEdgeDescriptions(m_primitiveType);
4670 gl.useProgram(programGL);
4671 setViewport(gl, viewport);
4672 gl.patchParameteri(GL_PATCH_VERTICES, 6);
4675 // Compute the number vertices in the largest draw call, so we can allocate the TF buffer just once.
4676 int maxNumVerticesInDrawCall = 0;
4678 const vector<float> patchTessLevels = generatePatchTessLevels(1, 0 /* outer-edge index doesn't affect vertex count */, arrayMax(singleOuterEdgeLevels));
4679 maxNumVerticesInDrawCall = referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &patchTessLevels[0], &patchTessLevels[2]);
4683 const TFHandler tfHandler(m_context.getRenderContext(), maxNumVerticesInDrawCall);
4685 for (int outerEdgeLevelCaseNdx = 0; outerEdgeLevelCaseNdx < DE_LENGTH_OF_ARRAY(singleOuterEdgeLevels); outerEdgeLevelCaseNdx++)
4687 typedef std::set<Vec3, VecLexLessThan<3> > Vec3Set;
4689 Vec3Set firstEdgeVertices;
4691 for (int outerEdgeIndex = 0; outerEdgeIndex < (int)edgeDescriptions.size(); outerEdgeIndex++)
4693 const OuterEdgeDescription& edgeDesc = edgeDescriptions[outerEdgeIndex];
4694 const vector<float> patchTessLevels = generatePatchTessLevels(1, outerEdgeIndex, singleOuterEdgeLevels[outerEdgeLevelCaseNdx]);
4695 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, (int)patchTessLevels.size(), 0, &patchTessLevels[0]) };
4697 log << TestLog::Message << "Testing with outer tessellation level " << singleOuterEdgeLevels[outerEdgeLevelCaseNdx]
4698 << " for the " << edgeDesc.description() << " edge, and with various levels for other edges" << TestLog::EndMessage;
4701 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, m_usePointMode),
4702 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], (int)patchTessLevels.size());
4703 const int refNumVertices = referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &patchTessLevels[0], &patchTessLevels[2]);
4705 if ((int)tfResult.varying.size() != refNumVertices)
4707 log << TestLog::Message << "Failure: the number of vertices returned by transform feedback is "
4708 << tfResult.varying.size() << ", expected " << refNumVertices << TestLog::EndMessage
4709 << TestLog::Message << "Note: rendered 1 patch, tessellation levels are (in order [inner0, inner1, outer0, outer1, outer2, outer3]):\n"
4710 << containerStr(patchTessLevels, 6) << TestLog::EndMessage;
4712 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4717 Vec3Set currentEdgeVertices;
4719 // Get the vertices on the current outer edge.
4720 for(int vtxNdx = 0; vtxNdx < refNumVertices; vtxNdx++)
4722 const Vec3& vtx = tfResult.varying[vtxNdx];
4723 if (edgeDesc.contains(vtx))
4725 // Swizzle components to match the order of the first edge.
4726 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
4728 currentEdgeVertices.insert(outerEdgeIndex == 0 ? vtx
4729 : outerEdgeIndex == 1 ? vtx.swizzle(1, 0, 2)
4730 : outerEdgeIndex == 2 ? vtx.swizzle(2, 1, 0)
4733 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
4735 currentEdgeVertices.insert(Vec3(outerEdgeIndex == 0 ? vtx.y()
4736 : outerEdgeIndex == 1 ? vtx.x()
4737 : outerEdgeIndex == 2 ? vtx.y()
4738 : outerEdgeIndex == 3 ? vtx.x()
4747 if (outerEdgeIndex == 0)
4748 firstEdgeVertices = currentEdgeVertices;
4751 // Compare vertices of this edge to those of the first edge.
4753 if (currentEdgeVertices != firstEdgeVertices)
4755 const char* const swizzleDesc = m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? (outerEdgeIndex == 1 ? "(y, x, z)"
4756 : outerEdgeIndex == 2 ? "(z, y, x)"
4758 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? (outerEdgeIndex == 1 ? "(x, 0)"
4759 : outerEdgeIndex == 2 ? "(y, 0)"
4760 : outerEdgeIndex == 3 ? "(x, 0)"
4764 log << TestLog::Message << "Failure: the set of vertices on the " << edgeDesc.description() << " edge"
4765 << " doesn't match the set of vertices on the " << edgeDescriptions[0].description() << " edge" << TestLog::EndMessage
4766 << TestLog::Message << "Note: set of vertices on " << edgeDesc.description() << " edge, components swizzled like " << swizzleDesc
4767 << " to match component order on first edge:\n" << containerStr(currentEdgeVertices, 5)
4768 << "\non " << edgeDescriptions[0].description() << " edge:\n" << containerStr(firstEdgeVertices, 5) << TestLog::EndMessage;
4769 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid set of vertices");
4780 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4784 /*--------------------------------------------------------------------*//*!
4785 * \brief Test invariance rule #5
4787 * Test that the set of triangles input to the TES only depends on the
4788 * tessellation levels, tessellation mode and spacing mode. Specifically,
4789 * winding doesn't change the set of triangles, though it can change the
4790 * order in which they are input to TES, and can (and will) change the
4791 * vertex order within a triangle.
4792 *//*--------------------------------------------------------------------*/
4793 class InvariantTriangleSetCase : public PrimitiveSetInvarianceCase
4796 InvariantTriangleSetCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing)
4797 : PrimitiveSetInvarianceCase(context, name, description, primType, spacing, false, WINDINGUSAGE_VARY)
4799 DE_ASSERT(primType == TESSPRIMITIVETYPE_TRIANGLES || primType == TESSPRIMITIVETYPE_QUADS);
4803 virtual bool compare (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, int) const
4805 return compareTriangleSets(coordsA, coordsB, m_testCtx.getLog());
4809 /*--------------------------------------------------------------------*//*!
4810 * \brief Test invariance rule #6
4812 * Test that the set of inner triangles input to the TES only depends on
4813 * the inner tessellation levels, tessellation mode and spacing mode.
4814 *//*--------------------------------------------------------------------*/
4815 class InvariantInnerTriangleSetCase : public PrimitiveSetInvarianceCase
4818 InvariantInnerTriangleSetCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing)
4819 : PrimitiveSetInvarianceCase(context, name, description, primType, spacing, false, WINDINGUSAGE_VARY)
4821 DE_ASSERT(primType == TESSPRIMITIVETYPE_TRIANGLES || primType == TESSPRIMITIVETYPE_QUADS);
4825 virtual vector<LevelCase> genTessLevelCases (void) const
4827 const int numSubCases = 4;
4828 const vector<LevelCase> baseResults = PrimitiveSetInvarianceCase::genTessLevelCases();
4829 vector<LevelCase> result;
4830 de::Random rnd (123);
4832 // Generate variants with different values for irrelevant levels.
4833 for (int baseNdx = 0; baseNdx < (int)baseResults.size(); baseNdx++)
4835 const TessLevels& base = baseResults[baseNdx].levels[0];
4836 TessLevels levels = base;
4837 LevelCase levelCase;
4839 for (int subNdx = 0; subNdx < numSubCases; subNdx++)
4841 levelCase.levels.push_back(levels);
4843 for (int i = 0; i < DE_LENGTH_OF_ARRAY(levels.outer); i++)
4844 levels.outer[i] = rnd.getFloat(2.0f, 16.0f);
4845 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
4846 levels.inner[1] = rnd.getFloat(2.0f, 16.0f);
4849 result.push_back(levelCase);
4855 struct IsInnerTriangleTriangle
4857 bool operator() (const Vec3* vertices) const
4859 for (int v = 0; v < 3; v++)
4860 for (int c = 0; c < 3; c++)
4861 if (vertices[v][c] == 0.0f)
4867 struct IsInnerQuadTriangle
4869 bool operator() (const Vec3* vertices) const
4871 for (int v = 0; v < 3; v++)
4872 for (int c = 0; c < 2; c++)
4873 if (vertices[v][c] == 0.0f || vertices[v][c] == 1.0f)
4879 virtual bool compare (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, int) const
4881 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
4882 return compareTriangleSets(coordsA, coordsB, m_testCtx.getLog(), IsInnerTriangleTriangle(), "outer triangles");
4883 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
4884 return compareTriangleSets(coordsA, coordsB, m_testCtx.getLog(), IsInnerQuadTriangle(), "outer triangles");
4893 /*--------------------------------------------------------------------*//*!
4894 * \brief Test invariance rule #7
4896 * Test that the set of outer triangles input to the TES only depends on
4897 * tessellation mode, spacing mode and the inner and outer tessellation
4898 * levels corresponding to the inner and outer edges relevant to that
4900 *//*--------------------------------------------------------------------*/
4901 class InvariantOuterTriangleSetCase : public PrimitiveSetInvarianceCase
4904 InvariantOuterTriangleSetCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing)
4905 : PrimitiveSetInvarianceCase(context, name, description, primType, spacing, false, WINDINGUSAGE_VARY)
4907 DE_ASSERT(primType == TESSPRIMITIVETYPE_TRIANGLES || primType == TESSPRIMITIVETYPE_QUADS);
4911 virtual vector<LevelCase> genTessLevelCases (void) const
4913 const int numSubCasesPerEdge = 4;
4914 const int numEdges = m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3
4915 : m_primitiveType == TESSPRIMITIVETYPE_QUADS ? 4
4917 const vector<LevelCase> baseResult = PrimitiveSetInvarianceCase::genTessLevelCases();
4918 vector<LevelCase> result;
4919 de::Random rnd (123);
4921 // Generate variants with different values for irrelevant levels.
4922 for (int baseNdx = 0; baseNdx < (int)baseResult.size(); baseNdx++)
4924 const TessLevels& base = baseResult[baseNdx].levels[0];
4925 if (base.inner[0] == 1.0f || (m_primitiveType == TESSPRIMITIVETYPE_QUADS && base.inner[1] == 1.0f))
4928 for (int edgeNdx = 0; edgeNdx < numEdges; edgeNdx++)
4930 TessLevels levels = base;
4931 LevelCase levelCase;
4932 levelCase.mem = edgeNdx;
4934 for (int subCaseNdx = 0; subCaseNdx < numSubCasesPerEdge; subCaseNdx++)
4936 levelCase.levels.push_back(levels);
4938 for (int i = 0; i < DE_LENGTH_OF_ARRAY(levels.outer); i++)
4941 levels.outer[i] = rnd.getFloat(2.0f, 16.0f);
4944 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
4945 levels.inner[1] = rnd.getFloat(2.0f, 16.0f);
4948 result.push_back(levelCase);
4955 class IsTriangleTriangleOnOuterEdge
4958 IsTriangleTriangleOnOuterEdge (int edgeNdx) : m_edgeNdx(edgeNdx) {}
4959 bool operator() (const Vec3* vertices) const
4961 bool touchesAppropriateEdge = false;
4962 for (int v = 0; v < 3; v++)
4963 if (vertices[v][m_edgeNdx] == 0.0f)
4964 touchesAppropriateEdge = true;
4966 if (touchesAppropriateEdge)
4968 const Vec3 avg = (vertices[0] + vertices[1] + vertices[2]) / 3.0f;
4969 return avg[m_edgeNdx] < avg[(m_edgeNdx+1)%3] &&
4970 avg[m_edgeNdx] < avg[(m_edgeNdx+2)%3];
4979 class IsQuadTriangleOnOuterEdge
4982 IsQuadTriangleOnOuterEdge (int edgeNdx) : m_edgeNdx(edgeNdx) {}
4984 bool onEdge (const Vec3& v) const
4986 return v[m_edgeNdx%2] == (m_edgeNdx <= 1 ? 0.0f : 1.0f);
4989 static inline bool onAnyEdge (const Vec3& v)
4991 return v[0] == 0.0f || v[0] == 1.0f || v[1] == 0.0f || v[1] == 1.0f;
4994 bool operator() (const Vec3* vertices) const
4996 for (int v = 0; v < 3; v++)
4998 const Vec3& a = vertices[v];
4999 const Vec3& b = vertices[(v+1)%3];
5000 const Vec3& c = vertices[(v+2)%3];
5001 if (onEdge(a) && onEdge(b))
5003 if (onEdge(c) && !onAnyEdge(a) && !onAnyEdge(b) && a[m_edgeNdx%2] == b[m_edgeNdx%2])
5014 virtual bool compare (const vector<Vec3>& coordsA, const vector<Vec3>& coordsB, int outerEdgeNdx) const
5016 if (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES)
5018 return compareTriangleSets(coordsA, coordsB, m_testCtx.getLog(),
5019 IsTriangleTriangleOnOuterEdge(outerEdgeNdx),
5020 ("inner triangles, and outer triangles corresponding to other edge than edge "
5021 + outerEdgeDescriptions(m_primitiveType)[outerEdgeNdx].description()).c_str());
5023 else if (m_primitiveType == TESSPRIMITIVETYPE_QUADS)
5025 return compareTriangleSets(coordsA, coordsB, m_testCtx.getLog(),
5026 IsQuadTriangleOnOuterEdge(outerEdgeNdx),
5027 ("inner triangles, and outer triangles corresponding to other edge than edge "
5028 + outerEdgeDescriptions(m_primitiveType)[outerEdgeNdx].description()).c_str());
5037 /*--------------------------------------------------------------------*//*!
5038 * \brief Base class for testing individual components of tess coords
5040 * Useful for testing parts of invariance rule #8.
5041 *//*--------------------------------------------------------------------*/
5042 class TessCoordComponentInvarianceCase : public TestCase
5045 TessCoordComponentInvarianceCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
5046 : TestCase (context, name, description)
5047 , m_primitiveType (primType)
5048 , m_spacing (spacing)
5049 , m_winding (winding)
5050 , m_usePointMode (usePointMode)
5056 IterateResult iterate (void);
5059 virtual string tessEvalOutputComponentStatements (const char* tessCoordComponentName, const char* outputComponentName) const = 0;
5060 virtual bool checkTessCoordComponent (float component) const = 0;
5063 static vector<float> genTessLevelCases (int numCases);
5065 static const int RENDER_SIZE = 16;
5067 const TessPrimitiveType m_primitiveType;
5068 const SpacingMode m_spacing;
5069 const Winding m_winding;
5070 const bool m_usePointMode;
5072 SharedPtr<const glu::ShaderProgram> m_program;
5075 void TessCoordComponentInvarianceCase::init (void)
5077 checkTessellationSupport(m_context);
5078 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
5080 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
5081 "${GLSL_PER_VERTEX_OUT}\n"
5083 "in highp float in_v_attr;\n"
5084 "out highp float in_tc_attr;\n"
5086 "void main (void)\n"
5088 " in_tc_attr = in_v_attr;\n"
5090 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
5091 "${TESSELLATION_SHADER_REQUIRE}\n"
5092 "${GLSL_PER_VERTEX_IN_ARR}\n"
5093 "${GLSL_PER_VERTEX_OUT_ARR}\n"
5095 "layout (vertices = 1) out;\n"
5097 "in highp float in_tc_attr[];\n"
5099 "void main (void)\n"
5101 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
5102 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
5104 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
5105 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
5106 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
5107 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
5109 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
5110 "${TESSELLATION_SHADER_REQUIRE}\n"
5111 "${GLSL_PER_VERTEX_IN_ARR}\n"
5112 "${GLSL_PER_VERTEX_OUT}\n"
5114 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, m_winding, m_usePointMode) +
5116 "out highp vec4 in_f_color;\n"
5117 "out highp vec3 out_te_output;\n"
5119 "void main (void)\n"
5121 + tessEvalOutputComponentStatements("gl_TessCoord.x", "out_te_output.x")
5122 + tessEvalOutputComponentStatements("gl_TessCoord.y", "out_te_output.y")
5124 + (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ?
5125 tessEvalOutputComponentStatements("gl_TessCoord.z", "out_te_output.z") :
5126 " out_te_output.z = 0.0f;\n") +
5127 " gl_Position = vec4(gl_TessCoord.xy, 0.0, 1.0);\n"
5128 " in_f_color = vec4(1.0);\n"
5130 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
5132 "layout (location = 0) out mediump vec4 o_color;\n"
5134 "in highp vec4 in_f_color;\n"
5136 "void main (void)\n"
5138 " o_color = in_f_color;\n"
5141 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5142 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
5143 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
5144 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
5145 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
5146 << glu::TransformFeedbackVarying ("out_te_output")
5147 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
5149 m_testCtx.getLog() << *m_program;
5150 if (!m_program->isOk())
5151 TCU_FAIL("Program compilation failed");
5154 void TessCoordComponentInvarianceCase::deinit (void)
5159 vector<float> TessCoordComponentInvarianceCase::genTessLevelCases (int numCases)
5161 de::Random rnd(123);
5162 vector<float> result;
5164 for (int i = 0; i < numCases; i++)
5165 for (int j = 0; j < 6; j++)
5166 result.push_back(rnd.getFloat(1.0f, 63.0f));
5171 TessCoordComponentInvarianceCase::IterateResult TessCoordComponentInvarianceCase::iterate (void)
5173 typedef TransformFeedbackHandler<Vec3> TFHandler;
5175 TestLog& log = m_testCtx.getLog();
5176 const RenderContext& renderCtx = m_context.getRenderContext();
5177 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
5178 const glw::Functions& gl = renderCtx.getFunctions();
5179 const int numTessLevelCases = 32;
5180 const vector<float> tessLevels = genTessLevelCases(numTessLevelCases);
5181 const deUint32 programGL = m_program->getProgram();
5183 gl.useProgram(programGL);
5184 setViewport(gl, viewport);
5185 gl.patchParameteri(GL_PATCH_VERTICES, 6);
5188 // Compute the number vertices in the largest draw call, so we can allocate the TF buffer just once.
5189 int maxNumVerticesInDrawCall = 0;
5190 for (int i = 0; i < numTessLevelCases; i++)
5191 maxNumVerticesInDrawCall = de::max(maxNumVerticesInDrawCall, referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &tessLevels[6*i+0], &tessLevels[6*i+2]));
5194 const TFHandler tfHandler(m_context.getRenderContext(), maxNumVerticesInDrawCall);
5196 for (int tessLevelCaseNdx = 0; tessLevelCaseNdx < numTessLevelCases; tessLevelCaseNdx++)
5198 log << TestLog::Message << "Testing with tessellation levels: " << tessellationLevelsString(&tessLevels[6*tessLevelCaseNdx+0], &tessLevels[6*tessLevelCaseNdx+2]) << TestLog::EndMessage;
5200 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, (int)6, 0, &tessLevels[6*tessLevelCaseNdx]) };
5201 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, m_usePointMode),
5202 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], 6);
5204 for (int vtxNdx = 0; vtxNdx < (int)tfResult.varying.size(); vtxNdx++)
5206 const Vec3& vec = tfResult.varying[vtxNdx];
5207 const int numComps = m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? 3 : 2;
5209 for (int compNdx = 0; compNdx < numComps; compNdx++)
5211 if (!checkTessCoordComponent(vec[compNdx]))
5213 log << TestLog::Message << "Note: output value at index " << vtxNdx << " is "
5214 << (m_primitiveType == TESSPRIMITIVETYPE_TRIANGLES ? de::toString(vec) : de::toString(vec.swizzle(0,1)))
5215 << TestLog::EndMessage;
5216 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid tessellation coordinate component");
5225 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5229 /*--------------------------------------------------------------------*//*!
5230 * \brief Test first part of invariance rule #8
5232 * Test that all (relevant) components of tess coord are in [0,1].
5233 *//*--------------------------------------------------------------------*/
5234 class TessCoordComponentRangeCase : public TessCoordComponentInvarianceCase
5237 TessCoordComponentRangeCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
5238 : TessCoordComponentInvarianceCase(context, name, description, primType, spacing, winding, usePointMode)
5243 virtual string tessEvalOutputComponentStatements (const char* tessCoordComponentName, const char* outputComponentName) const
5245 return string() + "\t" + outputComponentName + " = " + tessCoordComponentName + ";\n";
5248 virtual bool checkTessCoordComponent (float component) const
5250 if (!de::inRange(component, 0.0f, 1.0f))
5252 m_testCtx.getLog() << TestLog::Message << "Failure: tess coord component isn't in range [0,1]" << TestLog::EndMessage;
5259 /*--------------------------------------------------------------------*//*!
5260 * \brief Test second part of invariance rule #8
5262 * Test that all (relevant) components of tess coord are in [0,1] and
5263 * 1.0-c is exact for every such component c.
5264 *//*--------------------------------------------------------------------*/
5265 class OneMinusTessCoordComponentCase : public TessCoordComponentInvarianceCase
5268 OneMinusTessCoordComponentCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
5269 : TessCoordComponentInvarianceCase(context, name, description, primType, spacing, winding, usePointMode)
5274 virtual string tessEvalOutputComponentStatements (const char* tessCoordComponentName, const char* outputComponentName) const
5276 return string() + " {\n"
5277 " float oneMinusComp = 1.0 - " + tessCoordComponentName + ";\n"
5278 " " + outputComponentName + " = " + tessCoordComponentName + " + oneMinusComp;\n"
5282 virtual bool checkTessCoordComponent (float component) const
5284 if (component != 1.0f)
5286 m_testCtx.getLog() << TestLog::Message << "Failure: comp + (1.0-comp) doesn't equal 1.0 for some component of tessellation coordinate" << TestLog::EndMessage;
5293 /*--------------------------------------------------------------------*//*!
5294 * \brief Test that patch is discarded if relevant outer level <= 0.0
5296 * Draws patches with different combinations of tessellation levels,
5297 * varying which levels are negative. Verifies by checking that colored
5298 * pixels exist inside the area of valid primitives, and only black pixels
5299 * exist inside the area of discarded primitives. An additional sanity
5300 * test is done, checking that the number of primitives written by TF is
5302 *//*--------------------------------------------------------------------*/
5303 class PrimitiveDiscardCase : public TestCase
5306 PrimitiveDiscardCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, SpacingMode spacing, Winding winding, bool usePointMode)
5307 : TestCase (context, name, description)
5308 , m_primitiveType (primType)
5309 , m_spacing (spacing)
5310 , m_winding (winding)
5311 , m_usePointMode (usePointMode)
5317 IterateResult iterate (void);
5320 static vector<float> genAttributes (void);
5322 static const int RENDER_SIZE = 256;
5324 const TessPrimitiveType m_primitiveType;
5325 const SpacingMode m_spacing;
5326 const Winding m_winding;
5327 const bool m_usePointMode;
5329 SharedPtr<const glu::ShaderProgram> m_program;
5332 void PrimitiveDiscardCase::init (void)
5334 checkTessellationSupport(m_context);
5335 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
5337 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
5338 "${GLSL_PER_VERTEX_OUT}\n"
5340 "in highp float in_v_attr;\n"
5341 "out highp float in_tc_attr;\n"
5343 "void main (void)\n"
5345 " in_tc_attr = in_v_attr;\n"
5347 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
5348 "${TESSELLATION_SHADER_REQUIRE}\n"
5349 "${GLSL_PER_VERTEX_IN_ARR}\n"
5350 "${GLSL_PER_VERTEX_OUT_ARR}\n"
5352 "layout (vertices = 1) out;\n"
5354 "in highp float in_tc_attr[];\n"
5356 "patch out highp vec2 in_te_positionScale;\n"
5357 "patch out highp vec2 in_te_positionOffset;\n"
5359 "void main (void)\n"
5361 " in_te_positionScale = vec2(in_tc_attr[6], in_tc_attr[7]);\n"
5362 " in_te_positionOffset = vec2(in_tc_attr[8], in_tc_attr[9]);\n"
5364 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
5365 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
5367 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
5368 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
5369 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
5370 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
5372 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
5373 "${TESSELLATION_SHADER_REQUIRE}\n"
5374 "${GLSL_PER_VERTEX_IN_ARR}\n"
5375 "${GLSL_PER_VERTEX_OUT}\n"
5377 + getTessellationEvaluationInLayoutString(m_primitiveType, m_spacing, m_winding, m_usePointMode) +
5379 "patch in highp vec2 in_te_positionScale;\n"
5380 "patch in highp vec2 in_te_positionOffset;\n"
5382 "out highp vec3 out_te_tessCoord;\n"
5384 "void main (void)\n"
5386 " out_te_tessCoord = gl_TessCoord;\n"
5387 " gl_Position = vec4(gl_TessCoord.xy*in_te_positionScale + in_te_positionOffset, 0.0, 1.0);\n"
5389 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
5391 "layout (location = 0) out mediump vec4 o_color;\n"
5393 "void main (void)\n"
5395 " o_color = vec4(1.0);\n"
5398 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
5399 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
5400 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
5401 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
5402 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
5403 << glu::TransformFeedbackVarying ("out_te_tessCoord")
5404 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
5406 m_testCtx.getLog() << *m_program;
5407 if (!m_program->isOk())
5408 TCU_FAIL("Program compilation failed");
5411 void PrimitiveDiscardCase::deinit (void)
5416 vector<float> PrimitiveDiscardCase::genAttributes (void)
5418 // Generate input attributes (tessellation levels, and position scale and
5419 // offset) for a number of primitives. Each primitive has a different
5420 // combination of tessellatio levels; each level is either a valid
5421 // value or an "invalid" value (negative or zero, chosen from
5422 // invalidTessLevelChoices).
5424 // \note The attributes are generated in such an order that all of the
5425 // valid attribute tuples come before the first invalid one both
5426 // in the result vector, and when scanning the resulting 2d grid
5427 // of primitives is scanned in y-major order. This makes
5428 // verification somewhat simpler.
5430 static const float baseTessLevels[6] = { 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
5431 static const float invalidTessLevelChoices[] = { -0.42f, 0.0f };
5432 const int numChoices = 1 + DE_LENGTH_OF_ARRAY(invalidTessLevelChoices);
5433 float choices[6][numChoices];
5434 vector<float> result;
5436 for (int levelNdx = 0; levelNdx < 6; levelNdx++)
5437 for (int choiceNdx = 0; choiceNdx < numChoices; choiceNdx++)
5438 choices[levelNdx][choiceNdx] = choiceNdx == 0 ? baseTessLevels[levelNdx] : invalidTessLevelChoices[choiceNdx-1];
5441 const int numCols = intPow(numChoices, 6/2); // sqrt(numChoices**6) == sqrt(number of primitives)
5442 const int numRows = numCols;
5445 // We could do this with some generic combination-generation function, but meh, it's not that bad.
5446 for (i[2] = 0; i[2] < numChoices; i[2]++) // First outer
5447 for (i[3] = 0; i[3] < numChoices; i[3]++) // Second outer
5448 for (i[4] = 0; i[4] < numChoices; i[4]++) // Third outer
5449 for (i[5] = 0; i[5] < numChoices; i[5]++) // Fourth outer
5450 for (i[0] = 0; i[0] < numChoices; i[0]++) // First inner
5451 for (i[1] = 0; i[1] < numChoices; i[1]++) // Second inner
5453 for (int j = 0; j < 6; j++)
5454 result.push_back(choices[j][i[j]]);
5457 const int col = index % numCols;
5458 const int row = index / numCols;
5460 result.push_back((float)2.0f / (float)numCols);
5461 result.push_back((float)2.0f / (float)numRows);
5463 result.push_back((float)col / (float)numCols * 2.0f - 1.0f);
5464 result.push_back((float)row / (float)numRows * 2.0f - 1.0f);
5474 PrimitiveDiscardCase::IterateResult PrimitiveDiscardCase::iterate (void)
5476 typedef TransformFeedbackHandler<Vec3> TFHandler;
5478 TestLog& log = m_testCtx.getLog();
5479 const RenderContext& renderCtx = m_context.getRenderContext();
5480 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
5481 const glw::Functions& gl = renderCtx.getFunctions();
5482 const vector<float> attributes = genAttributes();
5483 const int numAttribsPerPrimitive = 6+2+2; // Tess levels, scale, offset.
5484 const int numPrimitives = (int)attributes.size() / numAttribsPerPrimitive;
5485 const deUint32 programGL = m_program->getProgram();
5487 gl.useProgram(programGL);
5488 setViewport(gl, viewport);
5489 gl.patchParameteri(GL_PATCH_VERTICES, numAttribsPerPrimitive);
5491 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
5492 gl.clear(GL_COLOR_BUFFER_BIT);
5494 // Check the convenience assertion that all discarded patches come after the last non-discarded patch.
5496 bool discardedPatchEncountered = false;
5497 for (int patchNdx = 0; patchNdx < numPrimitives; patchNdx++)
5499 const bool discard = isPatchDiscarded(m_primitiveType, &attributes[numAttribsPerPrimitive*patchNdx + 2]);
5500 DE_ASSERT(discard || !discardedPatchEncountered);
5501 discardedPatchEncountered = discard;
5503 DE_UNREF(discardedPatchEncountered);
5507 int numVerticesInDrawCall = 0;
5508 for (int patchNdx = 0; patchNdx < numPrimitives; patchNdx++)
5509 numVerticesInDrawCall += referenceVertexCount(m_primitiveType, m_spacing, m_usePointMode, &attributes[numAttribsPerPrimitive*patchNdx+0], &attributes[numAttribsPerPrimitive*patchNdx+2]);
5511 log << TestLog::Message << "Note: rendering " << numPrimitives << " patches; first patches have valid relevant outer levels, "
5512 << "but later patches have one or more invalid (i.e. less than or equal to 0.0) relevant outer levels" << TestLog::EndMessage;
5515 const TFHandler tfHandler (m_context.getRenderContext(), numVerticesInDrawCall);
5516 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, (int)attributes.size(), 0, &attributes[0]) };
5517 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, m_usePointMode),
5518 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], (int)attributes.size());
5519 const tcu::Surface pixels = getPixels(renderCtx, viewport);
5521 log << TestLog::Image("RenderedImage", "Rendered image", pixels);
5523 if ((int)tfResult.varying.size() != numVerticesInDrawCall)
5525 log << TestLog::Message << "Failure: expected " << numVerticesInDrawCall << " vertices from transform feedback, got " << tfResult.varying.size() << TestLog::EndMessage;
5526 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Wrong number of tessellation coordinates");
5530 // Check that white pixels are found around every non-discarded
5531 // patch, and that only black pixels are found after the last
5532 // non-discarded patch.
5534 int lastWhitePixelRow = 0;
5535 int secondToLastWhitePixelRow = 0;
5536 int lastWhitePixelColumnOnSecondToLastWhitePixelRow = 0;
5538 for (int patchNdx = 0; patchNdx < numPrimitives; patchNdx++)
5540 const float* const attr = &attributes[numAttribsPerPrimitive*patchNdx];
5541 const bool validLevels = !isPatchDiscarded(m_primitiveType, &attr[2]);
5545 // Not a discarded patch; check that at least one white pixel is found in its area.
5547 const float* const scale = &attr[6];
5548 const float* const offset = &attr[8];
5549 const int x0 = (int)(( offset[0] + 1.0f)*0.5f*(float)pixels.getWidth()) - 1;
5550 const int x1 = (int)((scale[0] + offset[0] + 1.0f)*0.5f*(float)pixels.getWidth()) + 1;
5551 const int y0 = (int)(( offset[1] + 1.0f)*0.5f*(float)pixels.getHeight()) - 1;
5552 const int y1 = (int)((scale[1] + offset[1] + 1.0f)*0.5f*(float)pixels.getHeight()) + 1;
5553 const bool isMSAA = renderCtx.getRenderTarget().getNumSamples() > 1;
5554 bool pixelOk = false;
5556 if (y1 > lastWhitePixelRow)
5558 secondToLastWhitePixelRow = lastWhitePixelRow;
5559 lastWhitePixelRow = y1;
5561 lastWhitePixelColumnOnSecondToLastWhitePixelRow = x1;
5563 for (int y = y0; y <= y1 && !pixelOk; y++)
5564 for (int x = x0; x <= x1 && !pixelOk; x++)
5566 if (!de::inBounds(x, 0, pixels.getWidth()) || !de::inBounds(y, 0, pixels.getHeight()))
5571 if (pixels.getPixel(x, y) != tcu::RGBA::black())
5576 if (pixels.getPixel(x, y) == tcu::RGBA::white())
5583 log << TestLog::Message << "Failure: expected at least one " << (isMSAA ? "non-black" : "white") << " pixel in the rectangle "
5584 << "[x0=" << x0 << ", y0=" << y0 << ", x1=" << x1 << ", y1=" << y1 << "]" << TestLog::EndMessage
5585 << TestLog::Message << "Note: the rectangle approximately corresponds to the patch with these tessellation levels: "
5586 << tessellationLevelsString(&attr[0], &attr[1]) << TestLog::EndMessage;
5587 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
5593 // First discarded primitive patch; the remaining are guaranteed to be discarded ones as well.
5595 for (int y = 0; y < pixels.getHeight(); y++)
5596 for (int x = 0; x < pixels.getWidth(); x++)
5598 if (y > lastWhitePixelRow || (y > secondToLastWhitePixelRow && x > lastWhitePixelColumnOnSecondToLastWhitePixelRow))
5600 if (pixels.getPixel(x, y) != tcu::RGBA::black())
5602 log << TestLog::Message << "Failure: expected all pixels to be black in the area "
5603 << (lastWhitePixelColumnOnSecondToLastWhitePixelRow < pixels.getWidth()-1
5604 ? string() + "y > " + de::toString(lastWhitePixelRow) + " || (y > " + de::toString(secondToLastWhitePixelRow)
5605 + " && x > " + de::toString(lastWhitePixelColumnOnSecondToLastWhitePixelRow) + ")"
5606 : string() + "y > " + de::toString(lastWhitePixelRow))
5607 << " (they all correspond to patches that should be discarded)" << TestLog::EndMessage
5608 << TestLog::Message << "Note: pixel " << tcu::IVec2(x, y) << " isn't black" << TestLog::EndMessage;
5609 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
5622 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
5626 /*--------------------------------------------------------------------*//*!
5627 * \brief Case testing user-defined IO between TCS and TES
5629 * TCS outputs various values to TES, including aggregates. The outputs
5630 * can be per-patch or per-vertex, and if per-vertex, they can also be in
5631 * an IO block. Per-vertex input array size can be left implicit (i.e.
5632 * inputArray[]) or explicit either by gl_MaxPatchVertices or an integer
5633 * literal whose value is queried from GL.
5635 * The values output are generated in TCS and verified in TES against
5636 * similarly generated values. In case a verification of a value fails, the
5637 * index of the invalid value is output with TF.
5638 * As a sanity check, also the rendering result is verified (against pre-
5639 * rendered reference).
5640 *//*--------------------------------------------------------------------*/
5641 class UserDefinedIOCase : public TestCase
5646 IO_TYPE_PER_PATCH = 0,
5647 IO_TYPE_PER_PATCH_ARRAY,
5648 IO_TYPE_PER_PATCH_BLOCK,
5649 IO_TYPE_PER_PATCH_BLOCK_ARRAY,
5651 IO_TYPE_PER_VERTEX_BLOCK,
5656 enum VertexIOArraySize
5658 VERTEX_IO_ARRAY_SIZE_IMPLICIT = 0,
5659 VERTEX_IO_ARRAY_SIZE_EXPLICIT_SHADER_BUILTIN, //!< Use gl_MaxPatchVertices as size for per-vertex input array.
5660 VERTEX_IO_ARRAY_SIZE_EXPLICIT_QUERY, //!< Query GL_MAX_PATCH_VERTICES, and use that as size for per-vertex input array.
5662 VERTEX_IO_ARRAY_SIZE_LAST
5665 enum TessControlOutArraySize
5667 TESS_CONTROL_OUT_ARRAY_SIZE_IMPLICIT = 0,
5668 TESS_CONTROL_OUT_ARRAY_SIZE_LAYOUT,
5669 TESS_CONTROL_OUT_ARRAY_SIZE_QUERY,
5670 TESS_CONTROL_OUT_ARRAY_SIZE_SHADER_BUILTIN
5673 UserDefinedIOCase (Context& context, const char* name, const char* description, TessPrimitiveType primType, IOType ioType, VertexIOArraySize vertexIOArraySize, TessControlOutArraySize tessControlOutArraySize, const char* referenceImagePath)
5674 : TestCase (context, name, description)
5675 , m_primitiveType (primType)
5677 , m_vertexIOArraySize (vertexIOArraySize)
5678 , m_tessControlOutArraySize (tessControlOutArraySize)
5679 , m_referenceImagePath (referenceImagePath)
5685 IterateResult iterate (void);
5688 typedef string (*BasicTypeVisitFunc)(const string& name, glu::DataType type, int indentationDepth); //!< See glslTraverseBasicTypes below.
5690 class TopLevelObject
5693 virtual ~TopLevelObject (void) {}
5695 virtual string name (void) const = 0;
5696 virtual string declare (void) const = 0;
5697 virtual string declareArray (const string& arraySizeExpr) const = 0;
5698 virtual string glslTraverseBasicTypeArray (int numArrayElements, //!< If negative, traverse just array[gl_InvocationID], not all indices.
5699 int indentationDepth,
5700 BasicTypeVisitFunc) const = 0;
5701 virtual string glslTraverseBasicType (int indentationDepth,
5702 BasicTypeVisitFunc) const = 0;
5703 virtual int numBasicSubobjectsInElementType (void) const = 0;
5704 virtual string basicSubobjectAtIndex (int index, int arraySize) const = 0;
5707 class Variable : public TopLevelObject
5710 Variable (const string& name_, const glu::VarType& type, bool isArray)
5713 , m_isArray (isArray)
5715 DE_ASSERT(!type.isArrayType());
5718 string name (void) const { return m_name; }
5719 string declare (void) const;
5720 string declareArray (const string& arraySizeExpr) const;
5721 string glslTraverseBasicTypeArray (int numArrayElements, int indentationDepth, BasicTypeVisitFunc) const;
5722 string glslTraverseBasicType (int indentationDepth, BasicTypeVisitFunc) const;
5723 int numBasicSubobjectsInElementType (void) const;
5724 string basicSubobjectAtIndex (int index, int arraySize) const;
5728 glu::VarType m_type; //!< If this Variable is an array element, m_type is the element type; otherwise just the variable type.
5729 const bool m_isArray;
5732 class IOBlock : public TopLevelObject
5739 Member (const string& n, const glu::VarType& t) : name(n), type(t) {}
5742 IOBlock (const string& blockName, const string& interfaceName, const vector<Member>& members)
5743 : m_blockName (blockName)
5744 , m_interfaceName (interfaceName)
5745 , m_members (members)
5749 string name (void) const { return m_interfaceName; }
5750 string declare (void) const;
5751 string declareArray (const string& arraySizeExpr) const;
5752 string glslTraverseBasicTypeArray (int numArrayElements, int indentationDepth, BasicTypeVisitFunc) const;
5753 string glslTraverseBasicType (int indentationDepth, BasicTypeVisitFunc) const;
5754 int numBasicSubobjectsInElementType (void) const;
5755 string basicSubobjectAtIndex (int index, int arraySize) const;
5759 string m_interfaceName;
5760 vector<Member> m_members;
5763 static string glslTraverseBasicTypes (const string& rootName,
5764 const glu::VarType& rootType,
5765 int arrayNestingDepth,
5766 int indentationDepth,
5767 BasicTypeVisitFunc visit);
5769 static string glslAssignBasicTypeObject (const string& name, glu::DataType, int indentationDepth);
5770 static string glslCheckBasicTypeObject (const string& name, glu::DataType, int indentationDepth);
5771 static int numBasicSubobjectsInElementType (const vector<SharedPtr<TopLevelObject> >&);
5772 static string basicSubobjectAtIndex (int index, const vector<SharedPtr<TopLevelObject> >&, int topLevelArraySizes);
5780 NUM_OUTPUT_VERTICES = 5
5784 NUM_PER_PATCH_ARRAY_ELEMS = 3
5788 NUM_PER_PATCH_BLOCKS = 2
5791 const TessPrimitiveType m_primitiveType;
5792 const IOType m_ioType;
5793 const VertexIOArraySize m_vertexIOArraySize;
5794 const TessControlOutArraySize m_tessControlOutArraySize;
5795 const string m_referenceImagePath;
5797 vector<glu::StructType> m_structTypes;
5798 vector<SharedPtr<TopLevelObject> > m_tcsOutputs;
5799 vector<SharedPtr<TopLevelObject> > m_tesInputs;
5801 SharedPtr<const glu::ShaderProgram> m_program;
5804 /*--------------------------------------------------------------------*//*!
5805 * \brief Generate GLSL code to traverse (possibly aggregate) object
5807 * Generates a string that represents GLSL code that traverses the
5808 * basic-type subobjects in a rootType-typed object named rootName. Arrays
5809 * are traversed with loops and struct members are each traversed
5810 * separately. The code for each basic-type subobject is generated with
5811 * the function given as the 'visit' argument.
5812 *//*--------------------------------------------------------------------*/
5813 string UserDefinedIOCase::glslTraverseBasicTypes (const string& rootName,
5814 const glu::VarType& rootType,
5815 int arrayNestingDepth,
5816 int indentationDepth,
5817 BasicTypeVisitFunc visit)
5819 if (rootType.isBasicType())
5820 return visit(rootName, rootType.getBasicType(), indentationDepth);
5821 else if (rootType.isArrayType())
5823 const string indentation = string(indentationDepth, '\t');
5824 const string loopIndexName = "i" + de::toString(arrayNestingDepth);
5825 const string arrayLength = de::toString(rootType.getArraySize());
5826 return indentation + "for (int " + loopIndexName + " = 0; " + loopIndexName + " < " + de::toString(rootType.getArraySize()) + "; " + loopIndexName + "++)\n" +
5827 indentation + "{\n" +
5828 glslTraverseBasicTypes(rootName + "[" + loopIndexName + "]", rootType.getElementType(), arrayNestingDepth+1, indentationDepth+1, visit) +
5829 indentation + "}\n";
5831 else if (rootType.isStructType())
5833 const glu::StructType& structType = *rootType.getStructPtr();
5834 const int numMembers = structType.getNumMembers();
5837 for (int membNdx = 0; membNdx < numMembers; membNdx++)
5839 const glu::StructMember& member = structType.getMember(membNdx);
5840 result += glslTraverseBasicTypes(rootName + "." + member.getName(), member.getType(), arrayNestingDepth, indentationDepth, visit);
5852 string UserDefinedIOCase::Variable::declare (void) const
5854 DE_ASSERT(!m_isArray);
5855 return de::toString(glu::declare(m_type, m_name)) + ";\n";
5858 string UserDefinedIOCase::Variable::declareArray (const string& sizeExpr) const
5860 DE_ASSERT(m_isArray);
5861 return de::toString(glu::declare(m_type, m_name)) + "[" + sizeExpr + "];\n";
5864 string UserDefinedIOCase::IOBlock::declare (void) const
5866 std::ostringstream buf;
5868 buf << m_blockName << "\n"
5871 for (int i = 0; i < (int)m_members.size(); i++)
5872 buf << "\t" << glu::declare(m_members[i].type, m_members[i].name) << ";\n";
5874 buf << "} " << m_interfaceName << ";\n";
5878 string UserDefinedIOCase::IOBlock::declareArray (const string& sizeExpr) const
5880 std::ostringstream buf;
5882 buf << m_blockName << "\n"
5885 for (int i = 0; i < (int)m_members.size(); i++)
5886 buf << "\t" << glu::declare(m_members[i].type, m_members[i].name) << ";\n";
5888 buf << "} " << m_interfaceName << "[" << sizeExpr << "];\n";
5892 string UserDefinedIOCase::Variable::glslTraverseBasicTypeArray (int numArrayElements, int indentationDepth, BasicTypeVisitFunc visit) const
5894 DE_ASSERT(m_isArray);
5896 const bool traverseAsArray = numArrayElements >= 0;
5897 const string traversedName = m_name + (!traverseAsArray ? "[gl_InvocationID]" : "");
5898 const glu::VarType type = traverseAsArray ? glu::VarType(m_type, numArrayElements) : m_type;
5900 return UserDefinedIOCase::glslTraverseBasicTypes(traversedName, type, 0, indentationDepth, visit);
5903 string UserDefinedIOCase::Variable::glslTraverseBasicType (int indentationDepth, BasicTypeVisitFunc visit) const
5905 DE_ASSERT(!m_isArray);
5907 return UserDefinedIOCase::glslTraverseBasicTypes(m_name, m_type, 0, indentationDepth, visit);
5910 string UserDefinedIOCase::IOBlock::glslTraverseBasicTypeArray (int numArrayElements, int indentationDepth, BasicTypeVisitFunc visit) const
5912 if (numArrayElements >= 0)
5914 const string indentation = string(indentationDepth, '\t');
5915 string result = indentation + "for (int i0 = 0; i0 < " + de::toString(numArrayElements) + "; i0++)\n" +
5916 indentation + "{\n";
5917 for (int i = 0; i < (int)m_members.size(); i++)
5918 result += UserDefinedIOCase::glslTraverseBasicTypes(m_interfaceName + "[i0]." + m_members[i].name, m_members[i].type, 1, indentationDepth+1, visit);
5919 result += indentation + "}\n";
5925 for (int i = 0; i < (int)m_members.size(); i++)
5926 result += UserDefinedIOCase::glslTraverseBasicTypes(m_interfaceName + "[gl_InvocationID]." + m_members[i].name, m_members[i].type, 0, indentationDepth, visit);
5932 string UserDefinedIOCase::IOBlock::glslTraverseBasicType (int indentationDepth, BasicTypeVisitFunc visit) const
5935 for (int i = 0; i < (int)m_members.size(); i++)
5936 result += UserDefinedIOCase::glslTraverseBasicTypes(m_interfaceName + "." + m_members[i].name, m_members[i].type, 0, indentationDepth, visit);
5940 int UserDefinedIOCase::Variable::numBasicSubobjectsInElementType (void) const
5942 return numBasicSubobjects(m_type);
5945 int UserDefinedIOCase::IOBlock::numBasicSubobjectsInElementType (void) const
5948 for (int i = 0; i < (int)m_members.size(); i++)
5949 result += numBasicSubobjects(m_members[i].type);
5953 string UserDefinedIOCase::Variable::basicSubobjectAtIndex (int subobjectIndex, int arraySize) const
5955 const glu::VarType type = m_isArray ? glu::VarType(m_type, arraySize) : m_type;
5956 int currentIndex = 0;
5958 for (glu::BasicTypeIterator basicIt = glu::BasicTypeIterator::begin(&type);
5959 basicIt != glu::BasicTypeIterator::end(&type);
5962 if (currentIndex == subobjectIndex)
5963 return m_name + de::toString(glu::TypeAccessFormat(type, basicIt.getPath()));
5970 string UserDefinedIOCase::IOBlock::basicSubobjectAtIndex (int subobjectIndex, int arraySize) const
5972 int currentIndex = 0;
5973 for (int arrayNdx = 0; arrayNdx < arraySize; arrayNdx++)
5975 for (int memberNdx = 0; memberNdx < (int)m_members.size(); memberNdx++)
5977 const glu::VarType& membType = m_members[memberNdx].type;
5978 for (glu::BasicTypeIterator basicIt = glu::BasicTypeIterator::begin(&membType);
5979 basicIt != glu::BasicTypeIterator::end(&membType);
5982 if (currentIndex == subobjectIndex)
5983 return m_interfaceName + "[" + de::toString(arrayNdx) + "]." + m_members[memberNdx].name + de::toString(glu::TypeAccessFormat(membType, basicIt.getPath()));
5992 // Used as the 'visit' argument for glslTraverseBasicTypes.
5993 string UserDefinedIOCase::glslAssignBasicTypeObject (const string& name, glu::DataType type, int indentationDepth)
5995 const int scalarSize = glu::getDataTypeScalarSize(type);
5996 const string indentation = string(indentationDepth, '\t');
5999 result += indentation + name + " = ";
6001 if (type != glu::TYPE_FLOAT)
6002 result += string() + glu::getDataTypeName(type) + "(";
6003 for (int i = 0; i < scalarSize; i++)
6004 result += (i > 0 ? ", v+" + de::floatToString(0.8f*(float)i, 1)
6006 if (type != glu::TYPE_FLOAT)
6009 indentation + "v += 0.4;\n";
6013 // Used as the 'visit' argument for glslTraverseBasicTypes.
6014 string UserDefinedIOCase::glslCheckBasicTypeObject (const string& name, glu::DataType type, int indentationDepth)
6016 const int scalarSize = glu::getDataTypeScalarSize(type);
6017 const string indentation = string(indentationDepth, '\t');
6020 result += indentation + "allOk = allOk && compare_" + glu::getDataTypeName(type) + "(" + name + ", ";
6022 if (type != glu::TYPE_FLOAT)
6023 result += string() + glu::getDataTypeName(type) + "(";
6024 for (int i = 0; i < scalarSize; i++)
6025 result += (i > 0 ? ", v+" + de::floatToString(0.8f*(float)i, 1)
6027 if (type != glu::TYPE_FLOAT)
6030 indentation + "v += 0.4;\n" +
6031 indentation + "if (allOk) firstFailedInputIndex++;\n";
6036 int UserDefinedIOCase::numBasicSubobjectsInElementType (const vector<SharedPtr<TopLevelObject> >& objects)
6039 for (int i = 0; i < (int)objects.size(); i++)
6040 result += objects[i]->numBasicSubobjectsInElementType();
6044 string UserDefinedIOCase::basicSubobjectAtIndex (int subobjectIndex, const vector<SharedPtr<TopLevelObject> >& objects, int topLevelArraySize)
6046 int currentIndex = 0;
6047 int objectIndex = 0;
6048 for (; currentIndex < subobjectIndex; objectIndex++)
6049 currentIndex += objects[objectIndex]->numBasicSubobjectsInElementType() * topLevelArraySize;
6050 if (currentIndex > subobjectIndex)
6053 currentIndex -= objects[objectIndex]->numBasicSubobjectsInElementType() * topLevelArraySize;
6056 return objects[objectIndex]->basicSubobjectAtIndex(subobjectIndex - currentIndex, topLevelArraySize);
6059 void UserDefinedIOCase::init (void)
6061 checkTessellationSupport(m_context);
6062 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
6064 const bool isPerPatchIO = m_ioType == IO_TYPE_PER_PATCH ||
6065 m_ioType == IO_TYPE_PER_PATCH_ARRAY ||
6066 m_ioType == IO_TYPE_PER_PATCH_BLOCK ||
6067 m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY;
6069 const bool isExplicitVertexArraySize = m_vertexIOArraySize == VERTEX_IO_ARRAY_SIZE_EXPLICIT_SHADER_BUILTIN ||
6070 m_vertexIOArraySize == VERTEX_IO_ARRAY_SIZE_EXPLICIT_QUERY;
6072 const string vertexAttrArrayInputSize = m_vertexIOArraySize == VERTEX_IO_ARRAY_SIZE_IMPLICIT ? ""
6073 : m_vertexIOArraySize == VERTEX_IO_ARRAY_SIZE_EXPLICIT_SHADER_BUILTIN ? "gl_MaxPatchVertices"
6074 : m_vertexIOArraySize == VERTEX_IO_ARRAY_SIZE_EXPLICIT_QUERY ? de::toString(m_context.getContextInfo().getInt(GL_MAX_PATCH_VERTICES))
6075 : deFatalStr("Invalid VertexIOArraySize");
6077 const char* const maybePatch = isPerPatchIO ? "patch " : "";
6078 const string outMaybePatch = string() + maybePatch + "out ";
6079 const string inMaybePatch = string() + maybePatch + "in ";
6080 const bool useBlock = m_ioType == IO_TYPE_PER_VERTEX_BLOCK ||
6081 m_ioType == IO_TYPE_PER_PATCH_BLOCK ||
6082 m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY;
6084 string tcsDeclarations;
6085 string tcsStatements;
6087 string tesDeclarations;
6088 string tesStatements;
6091 m_structTypes.push_back(glu::StructType("S"));
6093 const glu::VarType highpFloat (glu::TYPE_FLOAT, glu::PRECISION_HIGHP);
6094 glu::StructType& structType = m_structTypes.back();
6095 const glu::VarType structVarType (&structType);
6096 bool usedStruct = false;
6098 structType.addMember("x", glu::VarType(glu::TYPE_INT, glu::PRECISION_HIGHP));
6099 structType.addMember("y", glu::VarType(glu::TYPE_FLOAT_VEC4, glu::PRECISION_HIGHP));
6103 // It is illegal to have a structure containing an array as an output variable
6104 structType.addMember("z", glu::VarType(highpFloat, 2));
6109 const bool useLightweightBlock = (m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY); // use leaner block to make sure it is not larger than allowed (per-patch storage is very limited)
6110 vector<IOBlock::Member> blockMembers;
6112 if (!useLightweightBlock)
6113 blockMembers.push_back(IOBlock::Member("blockS", structVarType));
6115 blockMembers.push_back(IOBlock::Member("blockFa", glu::VarType(highpFloat, 3)));
6116 blockMembers.push_back(IOBlock::Member("blockSa", glu::VarType(structVarType, 2)));
6117 blockMembers.push_back(IOBlock::Member("blockF", highpFloat));
6119 m_tcsOutputs.push_back (SharedPtr<TopLevelObject>(new IOBlock("TheBlock", "tcBlock", blockMembers)));
6120 m_tesInputs.push_back (SharedPtr<TopLevelObject>(new IOBlock("TheBlock", "teBlock", blockMembers)));
6126 const Variable var0("in_te_s", structVarType, m_ioType != IO_TYPE_PER_PATCH);
6127 const Variable var1("in_te_f", highpFloat, m_ioType != IO_TYPE_PER_PATCH);
6129 if (m_ioType != IO_TYPE_PER_PATCH_ARRAY)
6131 // Arrays of structures are disallowed, add struct cases only if not arrayed variable
6132 m_tcsOutputs.push_back (SharedPtr<TopLevelObject>(new Variable(var0)));
6133 m_tesInputs.push_back (SharedPtr<TopLevelObject>(new Variable(var0)));
6138 m_tcsOutputs.push_back (SharedPtr<TopLevelObject>(new Variable(var1)));
6139 m_tesInputs.push_back (SharedPtr<TopLevelObject>(new Variable(var1)));
6142 tcsDeclarations += "in " + Variable("in_tc_attr", highpFloat, true).declareArray(vertexAttrArrayInputSize);
6145 tcsDeclarations += de::toString(glu::declare(structType)) + ";\n";
6147 tcsStatements += "\t{\n"
6148 "\t\thighp float v = 1.3;\n";
6150 for (int tcsOutputNdx = 0; tcsOutputNdx < (int)m_tcsOutputs.size(); tcsOutputNdx++)
6152 const TopLevelObject& output = *m_tcsOutputs[tcsOutputNdx];
6153 const int numElements = !isPerPatchIO ? -1 //!< \note -1 means indexing with gl_InstanceID
6154 : m_ioType == IO_TYPE_PER_PATCH ? 1
6155 : m_ioType == IO_TYPE_PER_PATCH_ARRAY ? NUM_PER_PATCH_ARRAY_ELEMS
6156 : m_ioType == IO_TYPE_PER_PATCH_BLOCK ? 1
6157 : m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY ? NUM_PER_PATCH_BLOCKS
6159 const bool isArray = (numElements != 1);
6161 DE_ASSERT(numElements != -2);
6165 tcsDeclarations += outMaybePatch + output.declareArray(m_ioType == IO_TYPE_PER_PATCH_ARRAY ? de::toString(int(NUM_PER_PATCH_ARRAY_ELEMS))
6166 : m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY ? de::toString(int(NUM_PER_PATCH_BLOCKS))
6167 : m_tessControlOutArraySize == TESS_CONTROL_OUT_ARRAY_SIZE_LAYOUT ? de::toString(int(NUM_OUTPUT_VERTICES))
6168 : m_tessControlOutArraySize == TESS_CONTROL_OUT_ARRAY_SIZE_QUERY ? de::toString(m_context.getContextInfo().getInt(GL_MAX_PATCH_VERTICES))
6169 : m_tessControlOutArraySize == TESS_CONTROL_OUT_ARRAY_SIZE_SHADER_BUILTIN ? "gl_MaxPatchVertices"
6173 tcsDeclarations += outMaybePatch + output.declare();
6176 tcsStatements += "\t\tv += float(gl_InvocationID)*" + de::floatToString(0.4f * (float)output.numBasicSubobjectsInElementType(), 1) + ";\n";
6178 tcsStatements += "\n\t\t// Assign values to output " + output.name() + "\n";
6180 tcsStatements += output.glslTraverseBasicTypeArray(numElements, 2, glslAssignBasicTypeObject);
6182 tcsStatements += output.glslTraverseBasicType(2, glslAssignBasicTypeObject);
6185 tcsStatements += "\t\tv += float(" + de::toString(int(NUM_OUTPUT_VERTICES)) + "-gl_InvocationID-1)*" + de::floatToString(0.4f * (float)output.numBasicSubobjectsInElementType(), 1) + ";\n";
6187 tcsStatements += "\t}\n";
6190 tesDeclarations += de::toString(glu::declare(structType)) + ";\n";
6192 tesStatements += "\tbool allOk = true;\n"
6193 "\thighp uint firstFailedInputIndex = 0u;\n"
6195 "\t\thighp float v = 1.3;\n";
6196 for (int tesInputNdx = 0; tesInputNdx < (int)m_tesInputs.size(); tesInputNdx++)
6198 const TopLevelObject& input = *m_tesInputs[tesInputNdx];
6199 const int numElements = !isPerPatchIO ? (int)NUM_OUTPUT_VERTICES
6200 : m_ioType == IO_TYPE_PER_PATCH ? 1
6201 : m_ioType == IO_TYPE_PER_PATCH_BLOCK ? 1
6202 : m_ioType == IO_TYPE_PER_PATCH_ARRAY ? NUM_PER_PATCH_ARRAY_ELEMS
6203 : m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY ? NUM_PER_PATCH_BLOCKS
6205 const bool isArray = (numElements != 1);
6207 DE_ASSERT(numElements != -2);
6210 tesDeclarations += inMaybePatch + input.declareArray(m_ioType == IO_TYPE_PER_PATCH_ARRAY ? de::toString(int(NUM_PER_PATCH_ARRAY_ELEMS))
6211 : m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY ? de::toString(int(NUM_PER_PATCH_BLOCKS))
6212 : isExplicitVertexArraySize ? de::toString(vertexAttrArrayInputSize)
6215 tesDeclarations += inMaybePatch + input.declare();
6217 tesStatements += "\n\t\t// Check values in input " + input.name() + "\n";
6219 tesStatements += input.glslTraverseBasicTypeArray(numElements, 2, glslCheckBasicTypeObject);
6221 tesStatements += input.glslTraverseBasicType(2, glslCheckBasicTypeObject);
6223 tesStatements += "\t}\n";
6226 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
6227 "${GLSL_PER_VERTEX_OUT}\n"
6229 "in highp float in_v_attr;\n"
6230 "out highp float in_tc_attr;\n"
6232 "void main (void)\n"
6234 " in_tc_attr = in_v_attr;\n"
6236 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
6237 "${TESSELLATION_SHADER_REQUIRE}\n"
6238 "${GLSL_PER_VERTEX_IN_ARR}\n"
6239 "${GLSL_PER_VERTEX_OUT_ARR}\n"
6241 "layout (vertices = " + de::toString(int(NUM_OUTPUT_VERTICES)) + ") out;\n"
6245 "patch out highp vec2 in_te_positionScale;\n"
6246 "patch out highp vec2 in_te_positionOffset;\n"
6248 "void main (void)\n"
6252 " in_te_positionScale = vec2(in_tc_attr[6], in_tc_attr[7]);\n"
6253 " in_te_positionOffset = vec2(in_tc_attr[8], in_tc_attr[9]);\n"
6255 " gl_TessLevelInner[0] = in_tc_attr[0];\n"
6256 " gl_TessLevelInner[1] = in_tc_attr[1];\n"
6258 " gl_TessLevelOuter[0] = in_tc_attr[2];\n"
6259 " gl_TessLevelOuter[1] = in_tc_attr[3];\n"
6260 " gl_TessLevelOuter[2] = in_tc_attr[4];\n"
6261 " gl_TessLevelOuter[3] = in_tc_attr[5];\n"
6263 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
6264 "${TESSELLATION_SHADER_REQUIRE}\n"
6265 "${GLSL_PER_VERTEX_IN_ARR}\n"
6266 "${GLSL_PER_VERTEX_OUT}\n"
6268 + getTessellationEvaluationInLayoutString(m_primitiveType) +
6272 "patch in highp vec2 in_te_positionScale;\n"
6273 "patch in highp vec2 in_te_positionOffset;\n"
6275 "out highp vec4 in_f_color;\n"
6276 "// Will contain the index of the first incorrect input,\n"
6277 "// or the number of inputs if all are correct\n"
6278 "flat out highp uint out_te_firstFailedInputIndex;\n"
6280 "bool compare_int (int a, int b) { return a == b; }\n"
6281 "bool compare_float (float a, float b) { return abs(a - b) < 0.01f; }\n"
6282 "bool compare_vec4 (vec4 a, vec4 b) { return all(lessThan(abs(a - b), vec4(0.01f))); }\n"
6284 "void main (void)\n"
6288 " gl_Position = vec4(gl_TessCoord.xy*in_te_positionScale + in_te_positionOffset, 0.0, 1.0);\n"
6289 " in_f_color = allOk ? vec4(0.0, 1.0, 0.0, 1.0)\n"
6290 " : vec4(1.0, 0.0, 0.0, 1.0);\n"
6291 " out_te_firstFailedInputIndex = firstFailedInputIndex;\n"
6293 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
6295 "layout (location = 0) out mediump vec4 o_color;\n"
6297 "in highp vec4 in_f_color;\n"
6299 "void main (void)\n"
6301 " o_color = in_f_color;\n"
6304 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
6305 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
6306 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
6307 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
6308 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))
6309 << glu::TransformFeedbackVarying ("out_te_firstFailedInputIndex")
6310 << glu::TransformFeedbackMode (GL_INTERLEAVED_ATTRIBS)));
6312 m_testCtx.getLog() << *m_program;
6313 if (!m_program->isOk())
6314 TCU_FAIL("Program compilation failed");
6317 void UserDefinedIOCase::deinit (void)
6322 UserDefinedIOCase::IterateResult UserDefinedIOCase::iterate (void)
6324 typedef TransformFeedbackHandler<deUint32> TFHandler;
6326 TestLog& log = m_testCtx.getLog();
6327 const RenderContext& renderCtx = m_context.getRenderContext();
6328 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
6329 const glw::Functions& gl = renderCtx.getFunctions();
6330 static const float attributes[6+2+2] = { /* inner */ 3.0f, 4.0f, /* outer */ 5.0f, 6.0f, 7.0f, 8.0f, /* pos. scale */ 1.2f, 1.3f, /* pos. offset */ -0.3f, -0.4f };
6331 const deUint32 programGL = m_program->getProgram();
6332 const int numVertices = referenceVertexCount(m_primitiveType, SPACINGMODE_EQUAL, false, &attributes[0], &attributes[2]);
6333 const TFHandler tfHandler (renderCtx, numVertices);
6334 tcu::ResultCollector result;
6336 gl.useProgram(programGL);
6337 setViewport(gl, viewport);
6338 gl.patchParameteri(GL_PATCH_VERTICES, DE_LENGTH_OF_ARRAY(attributes));
6340 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
6341 gl.clear(GL_COLOR_BUFFER_BIT);
6344 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 1, DE_LENGTH_OF_ARRAY(attributes), 0, &attributes[0]) };
6345 const TFHandler::Result tfResult = tfHandler.renderAndGetPrimitives(programGL, outputPrimitiveTypeGL(m_primitiveType, false),
6346 DE_LENGTH_OF_ARRAY(bindings), &bindings[0], DE_LENGTH_OF_ARRAY(attributes));
6349 const tcu::Surface pixels = getPixels(renderCtx, viewport);
6350 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePath.c_str());
6351 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), pixels.getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
6354 result.fail("Image comparison failed");
6357 if ((int)tfResult.varying.size() != numVertices)
6359 log << TestLog::Message << "Failure: transform feedback returned " << tfResult.varying.size() << " vertices; expected " << numVertices << TestLog::EndMessage;
6360 result.fail("Wrong number of vertices");
6364 const int topLevelArraySize = (m_ioType == IO_TYPE_PER_PATCH ? 1
6365 : m_ioType == IO_TYPE_PER_PATCH_ARRAY ? NUM_PER_PATCH_ARRAY_ELEMS
6366 : m_ioType == IO_TYPE_PER_PATCH_BLOCK ? 1
6367 : m_ioType == IO_TYPE_PER_PATCH_BLOCK_ARRAY ? NUM_PER_PATCH_BLOCKS
6368 : (int)NUM_OUTPUT_VERTICES);
6369 const int numTEInputs = numBasicSubobjectsInElementType(m_tesInputs) * topLevelArraySize;
6371 for (int vertexNdx = 0; vertexNdx < (int)numVertices; vertexNdx++)
6373 if (tfResult.varying[vertexNdx] > (deUint32)numTEInputs)
6375 log << TestLog::Message << "Failure: out_te_firstFailedInputIndex has value " << tfResult.varying[vertexNdx]
6376 << ", should be in range [0, " << numTEInputs << "]" << TestLog::EndMessage;
6377 result.fail("Invalid transform feedback output");
6379 else if (tfResult.varying[vertexNdx] != (deUint32)numTEInputs)
6381 log << TestLog::Message << "Failure: in tessellation evaluation shader, check for input "
6382 << basicSubobjectAtIndex(tfResult.varying[vertexNdx], m_tesInputs, topLevelArraySize) << " failed" << TestLog::EndMessage;
6383 result.fail("Invalid input value in tessellation evaluation shader");
6389 result.setTestContextResult(m_testCtx);
6393 /*--------------------------------------------------------------------*//*!
6394 * \brief Pass gl_Position between VS and TCS, or between TCS and TES.
6396 * In TCS gl_Position is in the gl_out[] block and in TES in the gl_in[]
6397 * block, and has no special semantics in those. Arbitrary vec4 data can
6398 * thus be passed there.
6399 *//*--------------------------------------------------------------------*/
6400 class GLPositionCase : public TestCase
6405 CASETYPE_VS_TO_TCS = 0,
6406 CASETYPE_TCS_TO_TES,
6407 CASETYPE_VS_TO_TCS_TO_TES,
6412 GLPositionCase (Context& context, const char* name, const char* description, CaseType caseType, const char* referenceImagePath)
6413 : TestCase (context, name, description)
6414 , m_caseType (caseType)
6415 , m_referenceImagePath (referenceImagePath)
6421 IterateResult iterate (void);
6423 static const char* getCaseTypeName (CaseType type);
6426 static const int RENDER_SIZE = 256;
6428 const CaseType m_caseType;
6429 const string m_referenceImagePath;
6431 SharedPtr<const glu::ShaderProgram> m_program;
6434 const char* GLPositionCase::getCaseTypeName (CaseType type)
6438 case CASETYPE_VS_TO_TCS: return "gl_position_vs_to_tcs";
6439 case CASETYPE_TCS_TO_TES: return "gl_position_tcs_to_tes";
6440 case CASETYPE_VS_TO_TCS_TO_TES: return "gl_position_vs_to_tcs_to_tes";
6442 DE_ASSERT(false); return DE_NULL;
6446 void GLPositionCase::init (void)
6448 checkTessellationSupport(m_context);
6449 checkRenderTargetSize(m_context.getRenderTarget(), RENDER_SIZE);
6451 const bool vsToTCS = m_caseType == CASETYPE_VS_TO_TCS || m_caseType == CASETYPE_VS_TO_TCS_TO_TES;
6452 const bool tcsToTES = m_caseType == CASETYPE_TCS_TO_TES || m_caseType == CASETYPE_VS_TO_TCS_TO_TES;
6454 const string tesIn0 = tcsToTES ? "gl_in[0].gl_Position" : "in_te_attr[0]";
6455 const string tesIn1 = tcsToTES ? "gl_in[1].gl_Position" : "in_te_attr[1]";
6456 const string tesIn2 = tcsToTES ? "gl_in[2].gl_Position" : "in_te_attr[2]";
6458 std::string vertexShaderTemplate ("${GLSL_VERSION_DECL}\n"
6459 "${GLSL_PER_VERTEX_OUT}\n"
6461 "in highp vec4 in_v_attr;\n"
6462 + string(!vsToTCS ? "out highp vec4 in_tc_attr;\n" : "") +
6464 "void main (void)\n"
6466 " " + (vsToTCS ? "gl_Position" : "in_tc_attr") + " = in_v_attr;\n"
6468 std::string tessellationControlTemplate ("${GLSL_VERSION_DECL}\n"
6469 "${TESSELLATION_SHADER_REQUIRE}\n"
6470 "${GLSL_PER_VERTEX_IN_ARR}\n"
6471 "${GLSL_PER_VERTEX_OUT_ARR}\n"
6473 "layout (vertices = 3) out;\n"
6475 + string(!vsToTCS ? "in highp vec4 in_tc_attr[];\n" : "") +
6477 + (!tcsToTES ? "out highp vec4 in_te_attr[];\n" : "") +
6479 "void main (void)\n"
6481 " " + (tcsToTES ? "gl_out[gl_InvocationID].gl_Position" : "in_te_attr[gl_InvocationID]") + " = "
6482 + (vsToTCS ? "gl_in[gl_InvocationID].gl_Position" : "in_tc_attr[gl_InvocationID]") + ";\n"
6484 " gl_TessLevelInner[0] = 2.0;\n"
6485 " gl_TessLevelInner[1] = 3.0;\n"
6487 " gl_TessLevelOuter[0] = 4.0;\n"
6488 " gl_TessLevelOuter[1] = 5.0;\n"
6489 " gl_TessLevelOuter[2] = 6.0;\n"
6490 " gl_TessLevelOuter[3] = 7.0;\n"
6492 std::string tessellationEvaluationTemplate ("${GLSL_VERSION_DECL}\n"
6493 "${TESSELLATION_SHADER_REQUIRE}\n"
6494 "${GLSL_PER_VERTEX_IN_ARR}\n"
6495 "${GLSL_PER_VERTEX_OUT}\n"
6497 + getTessellationEvaluationInLayoutString(TESSPRIMITIVETYPE_TRIANGLES) +
6499 + (!tcsToTES ? "in highp vec4 in_te_attr[];\n" : "") +
6501 "out highp vec4 in_f_color;\n"
6503 "void main (void)\n"
6505 " highp vec2 xy = gl_TessCoord.x * " + tesIn0 + ".xy\n"
6506 " + gl_TessCoord.y * " + tesIn1 + ".xy\n"
6507 " + gl_TessCoord.z * " + tesIn2 + ".xy;\n"
6508 " gl_Position = vec4(xy, 0.0, 1.0);\n"
6509 " in_f_color = vec4(" + tesIn0 + ".z + " + tesIn1 + ".w,\n"
6510 " " + tesIn2 + ".z + " + tesIn0 + ".w,\n"
6511 " " + tesIn1 + ".z + " + tesIn2 + ".w,\n"
6514 std::string fragmentShaderTemplate ("${GLSL_VERSION_DECL}\n"
6516 "layout (location = 0) out mediump vec4 o_color;\n"
6518 "in highp vec4 in_f_color;\n"
6520 "void main (void)\n"
6522 " o_color = in_f_color;\n"
6525 m_program = SharedPtr<const ShaderProgram>(new ShaderProgram(m_context.getRenderContext(), glu::ProgramSources()
6526 << glu::VertexSource (specializeShader(m_context, vertexShaderTemplate.c_str()))
6527 << glu::TessellationControlSource (specializeShader(m_context, tessellationControlTemplate.c_str()))
6528 << glu::TessellationEvaluationSource (specializeShader(m_context, tessellationEvaluationTemplate.c_str()))
6529 << glu::FragmentSource (specializeShader(m_context, fragmentShaderTemplate.c_str()))));
6531 m_testCtx.getLog() << *m_program;
6532 if (!m_program->isOk())
6533 TCU_FAIL("Program compilation failed");
6536 void GLPositionCase::deinit (void)
6541 GLPositionCase::IterateResult GLPositionCase::iterate (void)
6543 TestLog& log = m_testCtx.getLog();
6544 const RenderContext& renderCtx = m_context.getRenderContext();
6545 const RandomViewport viewport (renderCtx.getRenderTarget(), RENDER_SIZE, RENDER_SIZE, deStringHash(getName()));
6546 const glw::Functions& gl = renderCtx.getFunctions();
6547 const deUint32 programGL = m_program->getProgram();
6549 static const float attributes[3*4] =
6551 -0.8f, -0.7f, 0.1f, 0.7f,
6552 -0.5f, 0.4f, 0.2f, 0.5f,
6553 0.3f, 0.2f, 0.3f, 0.45f
6556 gl.useProgram(programGL);
6557 setViewport(gl, viewport);
6558 gl.patchParameteri(GL_PATCH_VERTICES, 3);
6560 gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
6561 gl.clear(GL_COLOR_BUFFER_BIT);
6563 log << TestLog::Message << "Note: input data for in_v_attr:\n" << arrayStr(attributes, 4) << TestLog::EndMessage;
6566 const glu::VertexArrayBinding bindings[] = { glu::va::Float("in_v_attr", 4, 3, 0, &attributes[0]) };
6567 glu::draw(renderCtx, programGL, DE_LENGTH_OF_ARRAY(bindings), &bindings[0], glu::pr::Patches(3));
6570 const tcu::Surface pixels = getPixels(renderCtx, viewport);
6571 const tcu::TextureLevel reference = getPNG(m_testCtx.getArchive(), m_referenceImagePath.c_str());
6572 const bool success = tcu::fuzzyCompare(log, "ImageComparison", "Image Comparison", reference.getAccess(), pixels.getAccess(), 0.02f, tcu::COMPARE_LOG_RESULT);
6576 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
6582 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
6586 class LimitQueryCase : public TestCase
6589 LimitQueryCase (Context& context, const char* name, const char* desc, glw::GLenum target, int minValue);
6591 IterateResult iterate (void);
6593 const glw::GLenum m_target;
6594 const int m_minValue;
6597 LimitQueryCase::LimitQueryCase (Context& context, const char* name, const char* desc, glw::GLenum target, int minValue)
6598 : TestCase (context, name, desc)
6600 , m_minValue (minValue)
6604 LimitQueryCase::IterateResult LimitQueryCase::iterate (void)
6606 checkTessellationSupport(m_context);
6608 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6609 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6611 gl.enableLogging(true);
6612 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER);
6615 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
6616 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_BOOLEAN);
6617 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_INTEGER64);
6618 verifyStateIntegerMin(result, gl, m_target, m_minValue, QUERY_FLOAT);
6621 result.setTestContextResult(m_testCtx);
6625 class CombinedUniformLimitCase : public TestCase
6628 CombinedUniformLimitCase (Context& context, const char* name, const char* desc, glw::GLenum combined, glw::GLenum numBlocks, glw::GLenum defaultComponents);
6630 IterateResult iterate (void);
6632 const glw::GLenum m_combined;
6633 const glw::GLenum m_numBlocks;
6634 const glw::GLenum m_defaultComponents;
6637 CombinedUniformLimitCase::CombinedUniformLimitCase (Context& context, const char* name, const char* desc, glw::GLenum combined, glw::GLenum numBlocks, glw::GLenum defaultComponents)
6638 : TestCase (context, name, desc)
6639 , m_combined (combined)
6640 , m_numBlocks (numBlocks)
6641 , m_defaultComponents (defaultComponents)
6645 CombinedUniformLimitCase::IterateResult CombinedUniformLimitCase::iterate (void)
6647 checkTessellationSupport(m_context);
6649 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6650 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6652 gl.enableLogging(true);
6654 m_testCtx.getLog() << tcu::TestLog::Message
6655 << "The minimum value of " << glu::getGettableStateStr(m_combined)
6656 << " is " << glu::getGettableStateStr(m_numBlocks)
6657 << " x MAX_UNIFORM_BLOCK_SIZE / 4 + "
6658 << glu::getGettableStateStr(m_defaultComponents)
6659 << tcu::TestLog::EndMessage;
6661 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlocks;
6662 gl.glGetIntegerv(m_numBlocks, &maxUniformBlocks);
6663 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
6665 StateQueryMemoryWriteGuard<glw::GLint> maxUniformBlockSize;
6666 gl.glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &maxUniformBlockSize);
6667 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
6669 StateQueryMemoryWriteGuard<glw::GLint> maxUniformComponents;
6670 gl.glGetIntegerv(m_defaultComponents, &maxUniformComponents);
6671 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glGetIntegerv");
6673 if (maxUniformBlocks.verifyValidity(result) && maxUniformBlockSize.verifyValidity(result) && maxUniformComponents.verifyValidity(result))
6675 const int limit = ((int)maxUniformBlocks) * ((int)maxUniformBlockSize) / 4 + (int)maxUniformComponents;
6676 verifyStateIntegerMin(result, gl, m_combined, limit, QUERY_INTEGER);
6679 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Types", "Alternative queries");
6680 verifyStateIntegerMin(result, gl, m_combined, limit, QUERY_BOOLEAN);
6681 verifyStateIntegerMin(result, gl, m_combined, limit, QUERY_INTEGER64);
6682 verifyStateIntegerMin(result, gl, m_combined, limit, QUERY_FLOAT);
6686 result.setTestContextResult(m_testCtx);
6690 class PatchVerticesStateCase : public TestCase
6693 PatchVerticesStateCase (Context& context, const char* name, const char* desc);
6695 IterateResult iterate (void);
6698 PatchVerticesStateCase::PatchVerticesStateCase (Context& context, const char* name, const char* desc)
6699 : TestCase(context, name, desc)
6703 PatchVerticesStateCase::IterateResult PatchVerticesStateCase::iterate (void)
6705 checkTessellationSupport(m_context);
6707 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6708 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6710 gl.enableLogging(true);
6714 const tcu::ScopedLogSection section(m_testCtx.getLog(), "initial", "Initial value");
6716 verifyStateInteger(result, gl, GL_PATCH_VERTICES, 3, QUERY_INTEGER);
6721 const tcu::ScopedLogSection section(m_testCtx.getLog(), "set", "After set");
6723 gl.glPatchParameteri(GL_PATCH_VERTICES, 22);
6724 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "glPatchParameteri");
6726 verifyStateInteger(result, gl, GL_PATCH_VERTICES, 22, QUERY_INTEGER);
6728 const tcu::ScopedLogSection subsection(m_testCtx.getLog(), "Types", "Alternative queries");
6729 verifyStateIntegerMin(result, gl, GL_PATCH_VERTICES, 22, QUERY_BOOLEAN);
6730 verifyStateIntegerMin(result, gl, GL_PATCH_VERTICES, 22, QUERY_INTEGER64);
6731 verifyStateIntegerMin(result, gl, GL_PATCH_VERTICES, 22, QUERY_FLOAT);
6735 result.setTestContextResult(m_testCtx);
6739 class PrimitiveRestartForPatchesSupportedCase : public TestCase
6742 PrimitiveRestartForPatchesSupportedCase (Context& context, const char* name, const char* desc);
6744 IterateResult iterate (void);
6747 PrimitiveRestartForPatchesSupportedCase::PrimitiveRestartForPatchesSupportedCase (Context& context, const char* name, const char* desc)
6748 : TestCase(context, name, desc)
6752 PrimitiveRestartForPatchesSupportedCase::IterateResult PrimitiveRestartForPatchesSupportedCase::iterate (void)
6754 checkTessellationSupport(m_context);
6756 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6757 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6760 gl.enableLogging(true);
6762 queryState(result, gl, QUERY_BOOLEAN, GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED, state);
6764 if (!state.isUndefined())
6766 const tcu::ScopedLogSection subsection(m_testCtx.getLog(), "Types", "Alternative types");
6767 verifyStateBoolean(result, gl, GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED, state.getBoolAccess(), QUERY_INTEGER);
6768 verifyStateBoolean(result, gl, GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED, state.getBoolAccess(), QUERY_INTEGER64);
6769 verifyStateBoolean(result, gl, GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED, state.getBoolAccess(), QUERY_FLOAT);
6772 result.setTestContextResult(m_testCtx);
6776 class TessProgramQueryCase : public TestCase
6779 TessProgramQueryCase (Context& context, const char* name, const char* desc);
6781 std::string getVertexSource (void) const;
6782 std::string getFragmentSource (void) const;
6783 std::string getTessCtrlSource (const char* globalLayouts) const;
6784 std::string getTessEvalSource (const char* globalLayouts) const;
6787 TessProgramQueryCase::TessProgramQueryCase (Context& context, const char* name, const char* desc)
6788 : TestCase(context, name, desc)
6792 std::string TessProgramQueryCase::getVertexSource (void) const
6794 return "${GLSL_VERSION_DECL}\n"
6795 "${GLSL_PER_VERTEX_OUT}\n"
6796 "void main (void)\n"
6798 " gl_Position = vec4(float(gl_VertexID), float(gl_VertexID / 2), 0.0, 1.0);\n"
6802 std::string TessProgramQueryCase::getFragmentSource (void) const
6804 return "${GLSL_VERSION_DECL}\n"
6805 "layout (location = 0) out mediump vec4 o_color;\n"
6806 "void main (void)\n"
6808 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
6812 std::string TessProgramQueryCase::getTessCtrlSource (const char* globalLayouts) const
6814 return "${GLSL_VERSION_DECL}\n"
6815 "${TESSELLATION_SHADER_REQUIRE}\n"
6816 "${GLSL_PER_VERTEX_IN_ARR}\n"
6817 "${GLSL_PER_VERTEX_OUT_ARR}\n"
6818 + std::string(globalLayouts) + ";\n"
6819 "void main (void)\n"
6821 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
6822 " gl_TessLevelInner[0] = 2.8;\n"
6823 " gl_TessLevelInner[1] = 2.8;\n"
6824 " gl_TessLevelOuter[0] = 2.8;\n"
6825 " gl_TessLevelOuter[1] = 2.8;\n"
6826 " gl_TessLevelOuter[2] = 2.8;\n"
6827 " gl_TessLevelOuter[3] = 2.8;\n"
6831 std::string TessProgramQueryCase::getTessEvalSource (const char* globalLayouts) const
6833 return "${GLSL_VERSION_DECL}\n"
6834 "${TESSELLATION_SHADER_REQUIRE}\n"
6835 "${GLSL_PER_VERTEX_IN_ARR}\n"
6836 "${GLSL_PER_VERTEX_OUT}\n"
6837 + std::string(globalLayouts) + ";\n"
6838 "void main (void)\n"
6840 " gl_Position = gl_TessCoord.x * gl_in[0].gl_Position\n"
6841 " + gl_TessCoord.y * gl_in[1].gl_Position\n"
6842 " + gl_TessCoord.y * gl_in[2].gl_Position\n"
6843 " + gl_TessCoord.z * gl_in[3].gl_Position;\n"
6847 class TessControlOutputVerticesCase : public TessProgramQueryCase
6850 TessControlOutputVerticesCase (Context& context, const char* name, const char* desc);
6852 IterateResult iterate (void);
6855 TessControlOutputVerticesCase::TessControlOutputVerticesCase (Context& context, const char* name, const char* desc)
6856 : TessProgramQueryCase(context, name, desc)
6860 TessControlOutputVerticesCase::IterateResult TessControlOutputVerticesCase::iterate (void)
6862 checkTessellationSupport(m_context);
6864 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
6865 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
6866 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
6867 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource("layout(vertices=4) out").c_str()))
6868 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource("layout(triangles) in").c_str())));
6870 m_testCtx.getLog() << program;
6871 if (!program.isOk())
6872 throw tcu::TestError("failed to build program");
6875 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6876 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6878 gl.enableLogging(true);
6879 verifyStateProgramInteger(result, gl, program.getProgram(), GL_TESS_CONTROL_OUTPUT_VERTICES, 4, QUERY_PROGRAM_INTEGER);
6881 result.setTestContextResult(m_testCtx);
6886 class TessGenModeQueryCase : public TessProgramQueryCase
6889 TessGenModeQueryCase (Context& context, const char* name, const char* desc);
6891 IterateResult iterate (void);
6894 TessGenModeQueryCase::TessGenModeQueryCase (Context& context, const char* name, const char* desc)
6895 : TessProgramQueryCase(context, name, desc)
6899 TessGenModeQueryCase::IterateResult TessGenModeQueryCase::iterate (void)
6901 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6902 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6906 const char* description;
6911 { "Triangles", "layout(triangles) in", GL_TRIANGLES },
6912 { "Isolines", "layout(isolines) in", GL_ISOLINES },
6913 { "Quads", "layout(quads) in", GL_QUADS },
6916 checkTessellationSupport(m_context);
6917 gl.enableLogging(true);
6919 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_modes); ++ndx)
6921 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type", s_modes[ndx].description);
6923 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
6924 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
6925 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
6926 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource("layout(vertices=6) out").c_str()))
6927 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource(s_modes[ndx].layout).c_str())));
6929 m_testCtx.getLog() << program;
6930 if (!program.isOk())
6931 result.fail("failed to build program");
6933 verifyStateProgramInteger(result, gl, program.getProgram(), GL_TESS_GEN_MODE, s_modes[ndx].mode, QUERY_PROGRAM_INTEGER);
6936 result.setTestContextResult(m_testCtx);
6940 class TessGenSpacingQueryCase : public TessProgramQueryCase
6943 TessGenSpacingQueryCase (Context& context, const char* name, const char* desc);
6945 IterateResult iterate (void);
6948 TessGenSpacingQueryCase::TessGenSpacingQueryCase (Context& context, const char* name, const char* desc)
6949 : TessProgramQueryCase(context, name, desc)
6953 TessGenSpacingQueryCase::IterateResult TessGenSpacingQueryCase::iterate (void)
6955 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
6956 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
6960 const char* description;
6962 glw::GLenum spacing;
6965 { "Default spacing", "layout(triangles) in", GL_EQUAL },
6966 { "Equal spacing", "layout(triangles, equal_spacing) in", GL_EQUAL },
6967 { "Fractional even spacing", "layout(triangles, fractional_even_spacing) in", GL_FRACTIONAL_EVEN },
6968 { "Fractional odd spacing", "layout(triangles, fractional_odd_spacing) in", GL_FRACTIONAL_ODD },
6971 checkTessellationSupport(m_context);
6972 gl.enableLogging(true);
6974 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_modes); ++ndx)
6976 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type", s_modes[ndx].description);
6978 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
6979 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
6980 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
6981 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource("layout(vertices=6) out").c_str()))
6982 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource(s_modes[ndx].layout).c_str())));
6984 m_testCtx.getLog() << program;
6985 if (!program.isOk())
6986 result.fail("failed to build program");
6988 verifyStateProgramInteger(result, gl, program.getProgram(), GL_TESS_GEN_SPACING, s_modes[ndx].spacing, QUERY_PROGRAM_INTEGER);
6991 result.setTestContextResult(m_testCtx);
6995 class TessGenVertexOrderQueryCase : public TessProgramQueryCase
6998 TessGenVertexOrderQueryCase (Context& context, const char* name, const char* desc);
7000 IterateResult iterate (void);
7003 TessGenVertexOrderQueryCase::TessGenVertexOrderQueryCase (Context& context, const char* name, const char* desc)
7004 : TessProgramQueryCase(context, name, desc)
7008 TessGenVertexOrderQueryCase::IterateResult TessGenVertexOrderQueryCase::iterate (void)
7010 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
7011 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
7015 const char* description;
7020 { "Default order", "layout(triangles) in", GL_CCW },
7021 { "CW order", "layout(triangles, cw) in", GL_CW },
7022 { "CCW order", "layout(triangles, ccw) in", GL_CCW },
7025 checkTessellationSupport(m_context);
7026 gl.enableLogging(true);
7028 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_modes); ++ndx)
7030 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type", s_modes[ndx].description);
7032 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
7033 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
7034 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
7035 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource("layout(vertices=6) out").c_str()))
7036 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource(s_modes[ndx].layout).c_str())));
7038 m_testCtx.getLog() << program;
7039 if (!program.isOk())
7040 result.fail("failed to build program");
7042 verifyStateProgramInteger(result, gl, program.getProgram(), GL_TESS_GEN_VERTEX_ORDER, s_modes[ndx].order, QUERY_PROGRAM_INTEGER);
7045 result.setTestContextResult(m_testCtx);
7049 class TessGenPointModeQueryCase : public TessProgramQueryCase
7052 TessGenPointModeQueryCase (Context& context, const char* name, const char* desc);
7054 IterateResult iterate (void);
7057 TessGenPointModeQueryCase::TessGenPointModeQueryCase (Context& context, const char* name, const char* desc)
7058 : TessProgramQueryCase(context, name, desc)
7062 TessGenPointModeQueryCase::IterateResult TessGenPointModeQueryCase::iterate (void)
7064 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
7065 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
7069 const char* description;
7074 { "Default mode", "layout(triangles) in", GL_FALSE },
7075 { "Point mode", "layout(triangles, point_mode) in", GL_TRUE },
7078 checkTessellationSupport(m_context);
7079 gl.enableLogging(true);
7081 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_modes); ++ndx)
7083 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Type", s_modes[ndx].description);
7085 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
7086 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
7087 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
7088 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource("layout(vertices=6) out").c_str()))
7089 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource(s_modes[ndx].layout).c_str())));
7091 m_testCtx.getLog() << program;
7092 if (!program.isOk())
7093 result.fail("failed to build program");
7095 verifyStateProgramInteger(result, gl, program.getProgram(), GL_TESS_GEN_POINT_MODE, s_modes[ndx].mode, QUERY_PROGRAM_INTEGER);
7098 result.setTestContextResult(m_testCtx);
7102 class ReferencedByTessellationQueryCase : public TestCase
7105 ReferencedByTessellationQueryCase (Context& context, const char* name, const char* desc, bool isCtrlCase);
7108 IterateResult iterate (void);
7110 std::string getVertexSource (void) const;
7111 std::string getFragmentSource (void) const;
7112 std::string getTessCtrlSource (void) const;
7113 std::string getTessEvalSource (void) const;
7115 const bool m_isCtrlCase;
7118 ReferencedByTessellationQueryCase::ReferencedByTessellationQueryCase (Context& context, const char* name, const char* desc, bool isCtrlCase)
7119 : TestCase (context, name, desc)
7120 , m_isCtrlCase (isCtrlCase)
7124 void ReferencedByTessellationQueryCase::init (void)
7126 checkTessellationSupport(m_context);
7129 ReferencedByTessellationQueryCase::IterateResult ReferencedByTessellationQueryCase::iterate (void)
7131 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
7132 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
7133 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
7134 << glu::VertexSource(specializeShader(m_context, getVertexSource().c_str()))
7135 << glu::FragmentSource(specializeShader(m_context, getFragmentSource().c_str()))
7136 << glu::TessellationControlSource(specializeShader(m_context, getTessCtrlSource().c_str()))
7137 << glu::TessellationEvaluationSource(specializeShader(m_context, getTessEvalSource().c_str())));
7139 gl.enableLogging(true);
7141 m_testCtx.getLog() << program;
7142 if (!program.isOk())
7143 result.fail("failed to build program");
7146 const deUint32 props[1] = { (deUint32)((m_isCtrlCase) ? (GL_REFERENCED_BY_TESS_CONTROL_SHADER) : (GL_REFERENCED_BY_TESS_EVALUATION_SHADER)) };
7149 const tcu::ScopedLogSection section (m_testCtx.getLog(), "UnreferencedUniform", "Unreferenced uniform u_unreferenced");
7150 deUint32 resourcePos;
7151 glw::GLsizei length = 0;
7152 glw::GLint referenced = 0;
7154 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_unreferenced");
7155 m_testCtx.getLog() << tcu::TestLog::Message << "u_unreferenced resource index: " << resourcePos << tcu::TestLog::EndMessage;
7157 if (resourcePos == GL_INVALID_INDEX)
7158 result.fail("resourcePos was GL_INVALID_INDEX");
7161 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
7163 << tcu::TestLog::Message
7164 << "Query " << glu::getProgramResourcePropertyStr(props[0])
7165 << ", got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced)
7166 << tcu::TestLog::EndMessage;
7168 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "query resource");
7170 if (length == 0 || referenced != GL_FALSE)
7171 result.fail("expected GL_FALSE");
7176 const tcu::ScopedLogSection section (m_testCtx.getLog(), "ReferencedUniform", "Referenced uniform u_referenced");
7177 deUint32 resourcePos;
7178 glw::GLsizei length = 0;
7179 glw::GLint referenced = 0;
7181 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_UNIFORM, "u_referenced");
7182 m_testCtx.getLog() << tcu::TestLog::Message << "u_referenced resource index: " << resourcePos << tcu::TestLog::EndMessage;
7184 if (resourcePos == GL_INVALID_INDEX)
7185 result.fail("resourcePos was GL_INVALID_INDEX");
7188 gl.glGetProgramResourceiv(program.getProgram(), GL_UNIFORM, resourcePos, 1, props, 1, &length, &referenced);
7190 << tcu::TestLog::Message
7191 << "Query " << glu::getProgramResourcePropertyStr(props[0])
7192 << ", got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced)
7193 << tcu::TestLog::EndMessage;
7195 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
7197 if (length == 0 || referenced != GL_TRUE)
7198 result.fail("expected GL_TRUE");
7203 result.setTestContextResult(m_testCtx);
7207 std::string ReferencedByTessellationQueryCase::getVertexSource (void) const
7209 return "${GLSL_VERSION_DECL}\n"
7210 "${GLSL_PER_VERTEX_OUT}\n"
7211 "void main (void)\n"
7213 " gl_Position = vec4(float(gl_VertexID), float(gl_VertexID / 2), 0.0, 1.0);\n"
7217 std::string ReferencedByTessellationQueryCase::getFragmentSource (void) const
7219 return "${GLSL_VERSION_DECL}\n"
7220 "layout (location = 0) out mediump vec4 o_color;\n"
7221 "void main (void)\n"
7223 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
7227 std::string ReferencedByTessellationQueryCase::getTessCtrlSource (void) const
7229 std::ostringstream buf;
7230 buf << "${GLSL_VERSION_DECL}\n"
7231 "${TESSELLATION_SHADER_REQUIRE}\n"
7232 "${GLSL_PER_VERTEX_IN_ARR}\n"
7233 "${GLSL_PER_VERTEX_OUT_ARR}\n"
7234 "layout(vertices = 3) out;\n"
7235 "uniform highp vec4 " << ((m_isCtrlCase) ? ("u_referenced") : ("u_unreferenced")) << ";\n"
7236 "void main (void)\n"
7238 " vec4 offset = " << ((m_isCtrlCase) ? ("u_referenced") : ("u_unreferenced")) << ";\n"
7239 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position + offset;\n"
7240 " gl_TessLevelInner[0] = 2.8;\n"
7241 " gl_TessLevelInner[1] = 2.8;\n"
7242 " gl_TessLevelOuter[0] = 2.8;\n"
7243 " gl_TessLevelOuter[1] = 2.8;\n"
7244 " gl_TessLevelOuter[2] = 2.8;\n"
7245 " gl_TessLevelOuter[3] = 2.8;\n"
7250 std::string ReferencedByTessellationQueryCase::getTessEvalSource (void) const
7252 std::ostringstream buf;
7253 buf << "${GLSL_VERSION_DECL}\n"
7254 "${TESSELLATION_SHADER_REQUIRE}\n"
7255 "${GLSL_PER_VERTEX_IN_ARR}\n"
7256 "${GLSL_PER_VERTEX_OUT}\n"
7257 "layout(triangles) in;\n"
7258 "uniform highp vec4 " << ((m_isCtrlCase) ? ("u_unreferenced") : ("u_referenced")) << ";\n"
7259 "void main (void)\n"
7261 " vec4 offset = " << ((m_isCtrlCase) ? ("u_unreferenced") : ("u_referenced")) << ";\n"
7262 " gl_Position = gl_TessCoord.x * gl_in[0].gl_Position\n"
7263 " + gl_TessCoord.y * gl_in[1].gl_Position\n"
7264 " + gl_TessCoord.z * gl_in[2].gl_Position\n"
7271 class IsPerPatchQueryCase : public TestCase
7274 IsPerPatchQueryCase (Context& context, const char* name, const char* desc);
7277 IterateResult iterate (void);
7280 IsPerPatchQueryCase::IsPerPatchQueryCase (Context& context, const char* name, const char* desc)
7281 : TestCase(context, name, desc)
7285 void IsPerPatchQueryCase::init (void)
7287 checkTessellationSupport(m_context);
7290 IsPerPatchQueryCase::IterateResult IsPerPatchQueryCase::iterate (void)
7292 static const char* const s_controlSource = "${GLSL_VERSION_DECL}\n"
7293 "${TESSELLATION_SHADER_REQUIRE}\n"
7294 "${GLSL_PER_VERTEX_IN_ARR}\n"
7295 "${GLSL_PER_VERTEX_OUT_ARR}\n"
7296 "layout(vertices = 3) out;\n"
7297 "patch out highp vec4 v_perPatch;\n"
7298 "out highp vec4 v_perVertex[];\n"
7299 "void main (void)\n"
7301 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
7302 " v_perPatch = gl_in[0].gl_Position;\n"
7303 " v_perVertex[gl_InvocationID] = -gl_in[gl_InvocationID].gl_Position;\n"
7304 " gl_TessLevelInner[0] = 2.8;\n"
7305 " gl_TessLevelInner[1] = 2.8;\n"
7306 " gl_TessLevelOuter[0] = 2.8;\n"
7307 " gl_TessLevelOuter[1] = 2.8;\n"
7308 " gl_TessLevelOuter[2] = 2.8;\n"
7309 " gl_TessLevelOuter[3] = 2.8;\n"
7311 tcu::ResultCollector result (m_testCtx.getLog(), " // ERROR: ");
7312 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
7313 glu::ShaderProgram program (m_context.getRenderContext(), glu::ProgramSources()
7314 << glu::TessellationControlSource(specializeShader(m_context, s_controlSource))
7315 << glu::ProgramSeparable(true));
7317 gl.enableLogging(true);
7319 m_testCtx.getLog() << program;
7320 if (!program.isOk())
7321 result.fail("failed to build program");
7324 const deUint32 props[1] = { GL_IS_PER_PATCH };
7327 const tcu::ScopedLogSection section (m_testCtx.getLog(), "PerPatchOutput", "Per patch v_perPatch");
7328 deUint32 resourcePos;
7329 glw::GLsizei length = 0;
7330 glw::GLint referenced = 0;
7332 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_PROGRAM_OUTPUT, "v_perPatch");
7333 m_testCtx.getLog() << tcu::TestLog::Message << "v_perPatch resource index: " << resourcePos << tcu::TestLog::EndMessage;
7335 if (resourcePos == GL_INVALID_INDEX)
7336 result.fail("resourcePos was GL_INVALID_INDEX");
7339 gl.glGetProgramResourceiv(program.getProgram(), GL_PROGRAM_OUTPUT, resourcePos, 1, props, 1, &length, &referenced);
7341 << tcu::TestLog::Message
7342 << "Query " << glu::getProgramResourcePropertyStr(props[0])
7343 << ", got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced)
7344 << tcu::TestLog::EndMessage;
7346 GLS_COLLECT_GL_ERROR(result, gl.glGetError(), "query resource");
7348 if (length == 0 || referenced != GL_TRUE)
7349 result.fail("expected GL_TRUE");
7354 const tcu::ScopedLogSection section (m_testCtx.getLog(), "PerVertexhOutput", "Per vertex v_perVertex");
7355 deUint32 resourcePos;
7356 glw::GLsizei length = 0;
7357 glw::GLint referenced = 0;
7359 resourcePos = gl.glGetProgramResourceIndex(program.getProgram(), GL_PROGRAM_OUTPUT, "v_perVertex");
7360 m_testCtx.getLog() << tcu::TestLog::Message << "v_perVertex resource index: " << resourcePos << tcu::TestLog::EndMessage;
7362 if (resourcePos == GL_INVALID_INDEX)
7363 result.fail("resourcePos was GL_INVALID_INDEX");
7366 gl.glGetProgramResourceiv(program.getProgram(), GL_PROGRAM_OUTPUT, resourcePos, 1, props, 1, &length, &referenced);
7368 << tcu::TestLog::Message
7369 << "Query " << glu::getProgramResourcePropertyStr(props[0])
7370 << ", got " << length << " value(s), value[0] = " << glu::getBooleanStr(referenced)
7371 << tcu::TestLog::EndMessage;
7373 GLU_EXPECT_NO_ERROR(gl.glGetError(), "query resource");
7375 if (length == 0 || referenced != GL_FALSE)
7376 result.fail("expected GL_FALSE");
7381 result.setTestContextResult(m_testCtx);
7387 TessellationTests::TessellationTests (Context& context, bool isGL45)
7388 : TestCaseGroup(context, "tessellation", "Tessellation Tests")
7393 TessellationTests::~TessellationTests (void)
7397 void TessellationTests::init (void)
7400 tcu::TestCaseGroup* const queryGroup = new tcu::TestCaseGroup(m_testCtx, "state_query", "Query tests");
7401 addChild(queryGroup);
7404 queryGroup->addChild(new LimitQueryCase(m_context, "max_patch_vertices", "Test MAX_PATCH_VERTICES", GL_MAX_PATCH_VERTICES, 32));
7405 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_gen_level", "Test MAX_TESS_GEN_LEVEL", GL_MAX_TESS_GEN_LEVEL, 64));
7406 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_uniform_components", "Test MAX_TESS_CONTROL_UNIFORM_COMPONENTS", GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS, 1024));
7407 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_uniform_components", "Test MAX_TESS_EVALUATION_UNIFORM_COMPONENTS", GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS, 1024));
7408 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_texture_image_units", "Test MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS", GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS, 16));
7409 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_texture_image_units", "Test MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS", GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS, 16));
7410 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_output_components", "Test MAX_TESS_CONTROL_OUTPUT_COMPONENTS", GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS, 64));
7411 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_patch_components", "Test MAX_TESS_PATCH_COMPONENTS", GL_MAX_TESS_PATCH_COMPONENTS, 120));
7412 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_total_output_components", "Test MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS", GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS, 2048));
7413 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_output_components", "Test MAX_TESS_EVALUATION_OUTPUT_COMPONENTS", GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS, 64));
7414 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_uniform_blocks", "Test MAX_TESS_CONTROL_UNIFORM_BLOCKS", GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS, 12));
7415 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_uniform_blocks", "Test MAX_TESS_EVALUATION_UNIFORM_BLOCKS", GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS, 12));
7416 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_input_components", "Test MAX_TESS_CONTROL_INPUT_COMPONENTS", GL_MAX_TESS_CONTROL_INPUT_COMPONENTS, 64));
7417 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_input_components", "Test MAX_TESS_EVALUATION_INPUT_COMPONENTS", GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS, 64));
7418 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_atomic_counter_buffers", "Test MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS", GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS, 0));
7419 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_atomic_counter_buffers", "Test MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS", GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS, 0));
7420 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_atomic_counters", "Test MAX_TESS_CONTROL_ATOMIC_COUNTERS", GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS, 0));
7421 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_atomic_counters", "Test MAX_TESS_EVALUATION_ATOMIC_COUNTERS", GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS, 0));
7422 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_image_uniforms", "Test MAX_TESS_CONTROL_IMAGE_UNIFORMS", GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS, 0));
7423 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_image_uniforms", "Test MAX_TESS_EVALUATION_IMAGE_UNIFORMS", GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS, 0));
7424 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_control_shader_storage_blocks", "Test MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS", GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, 0));
7425 queryGroup->addChild(new LimitQueryCase(m_context, "max_tess_evaluation_shader_storage_blocks", "Test MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS", GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, 0));
7428 queryGroup->addChild(new LimitQueryCase(m_context, "max_uniform_buffer_bindings", "Test MAX_UNIFORM_BUFFER_BINDINGS", GL_MAX_UNIFORM_BUFFER_BINDINGS, 72));
7429 queryGroup->addChild(new LimitQueryCase(m_context, "max_combined_uniform_blocks", "Test MAX_COMBINED_UNIFORM_BLOCKS", GL_MAX_COMBINED_UNIFORM_BLOCKS, 60));
7430 queryGroup->addChild(new LimitQueryCase(m_context, "max_combined_texture_image_units", "Test MAX_COMBINED_TEXTURE_IMAGE_UNITS", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, 96));
7433 queryGroup->addChild(new CombinedUniformLimitCase(m_context, "max_combined_tess_control_uniform_components", "Test MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS", GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS, GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS, GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS));
7434 queryGroup->addChild(new CombinedUniformLimitCase(m_context, "max_combined_tess_evaluation_uniform_components", "Test MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS", GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS, GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS, GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS));
7437 queryGroup->addChild(new PrimitiveRestartForPatchesSupportedCase(m_context, "primitive_restart_for_patches_supported", "Test PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED"));
7440 queryGroup->addChild(new PatchVerticesStateCase(m_context, "patch_vertices", "Test PATCH_VERTICES"));
7443 queryGroup->addChild(new TessControlOutputVerticesCase (m_context, "tess_control_output_vertices", "Test TESS_CONTROL_OUTPUT_VERTICES"));
7444 queryGroup->addChild(new TessGenModeQueryCase (m_context, "tess_gen_mode", "Test TESS_GEN_MODE"));
7445 queryGroup->addChild(new TessGenSpacingQueryCase (m_context, "tess_gen_spacing", "Test TESS_GEN_SPACING"));
7446 queryGroup->addChild(new TessGenVertexOrderQueryCase (m_context, "tess_gen_vertex_order", "Test TESS_GEN_VERTEX_ORDER"));
7447 queryGroup->addChild(new TessGenPointModeQueryCase (m_context, "tess_gen_point_mode", "Test TESS_GEN_POINT_MODE"));
7450 queryGroup->addChild(new ReferencedByTessellationQueryCase (m_context, "referenced_by_tess_control_shader", "Test REFERENCED_BY_TESS_CONTROL_SHADER", true));
7451 queryGroup->addChild(new ReferencedByTessellationQueryCase (m_context, "referenced_by_tess_evaluation_shader", "Test REFERENCED_BY_TESS_EVALUATION_SHADER", false));
7452 queryGroup->addChild(new IsPerPatchQueryCase (m_context, "is_per_patch", "Test IS_PER_PATCH"));
7456 TestCaseGroup* const tessCoordGroup = new TestCaseGroup(m_context, "tesscoord", "Get tessellation coordinates with transform feedback and validate them");
7457 addChild(tessCoordGroup);
7459 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7461 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7463 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7464 tessCoordGroup->addChild(new TessCoordCase(m_context,
7465 (string() + getTessPrimitiveTypeShaderName(primitiveType) + "_" + getSpacingModeShaderName((SpacingMode)spacingI)).c_str(), "",
7466 primitiveType, (SpacingMode)spacingI));
7471 TestCaseGroup* const windingGroup = new TestCaseGroup(m_context, "winding", "Test the cw and ccw input layout qualifiers");
7472 addChild(windingGroup);
7474 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7476 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7477 if (primitiveType == TESSPRIMITIVETYPE_ISOLINES)
7480 for (int windingI = 0; windingI < WINDING_LAST; windingI++)
7482 const Winding winding = (Winding)windingI;
7483 windingGroup->addChild(new WindingCase(m_context, (string() + getTessPrimitiveTypeShaderName(primitiveType) + "_" + getWindingShaderName(winding)).c_str(), "", primitiveType, winding));
7489 TestCaseGroup* const shaderInputOutputGroup = new TestCaseGroup(m_context, "shader_input_output", "Test tessellation control and evaluation shader inputs and outputs");
7490 addChild(shaderInputOutputGroup);
7497 } patchVertexCountCases[] =
7503 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(patchVertexCountCases); caseNdx++)
7505 const int inSize = patchVertexCountCases[caseNdx].inPatchSize;
7506 const int outSize = patchVertexCountCases[caseNdx].outPatchSize;
7508 const string caseName = "patch_vertices_" + de::toString(inSize) + "_in_" + de::toString(outSize) + "_out";
7510 shaderInputOutputGroup->addChild(new PatchVertexCountCase(m_context, caseName.c_str(), "Test input and output patch vertex counts", inSize, outSize,
7511 ("data/tessellation/" + caseName + "_ref.png").c_str()));
7515 for (int caseTypeI = 0; caseTypeI < PerPatchDataCase::CASETYPE_LAST; caseTypeI++)
7517 const PerPatchDataCase::CaseType caseType = (PerPatchDataCase::CaseType)caseTypeI;
7518 const char* const caseName = PerPatchDataCase::getCaseTypeName(caseType);
7520 shaderInputOutputGroup->addChild(new PerPatchDataCase(m_context, caseName, PerPatchDataCase::getCaseTypeDescription(caseType), caseType,
7521 PerPatchDataCase::caseTypeUsesRefImageFromFile(caseType) ? (string() + "data/tessellation/" + caseName + "_ref.png").c_str() : DE_NULL));
7524 for (int caseTypeI = 0; caseTypeI < GLPositionCase::CASETYPE_LAST; caseTypeI++)
7526 const GLPositionCase::CaseType caseType = (GLPositionCase::CaseType)caseTypeI;
7527 const char* const caseName = GLPositionCase::getCaseTypeName(caseType);
7529 shaderInputOutputGroup->addChild(new GLPositionCase(m_context, caseName, "", caseType, "data/tessellation/gl_position_ref.png"));
7532 shaderInputOutputGroup->addChild(new BarrierCase(m_context, "barrier", "Basic barrier usage", "data/tessellation/barrier_ref.png"));
7536 TestCaseGroup* const miscDrawGroup = new TestCaseGroup(m_context, "misc_draw", "Miscellaneous draw-result-verifying cases");
7537 addChild(miscDrawGroup);
7539 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7541 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7542 if (primitiveType == TESSPRIMITIVETYPE_ISOLINES)
7545 const char* const primTypeName = getTessPrimitiveTypeShaderName(primitiveType);
7547 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7549 const string caseName = string() + "fill_cover_" + primTypeName + "_" + getSpacingModeShaderName((SpacingMode)spacingI);
7551 miscDrawGroup->addChild(new BasicTriangleFillCoverCase(m_context,
7552 caseName.c_str(), "Check that there are no obvious gaps in the triangle-filled area of a tessellated shape",
7553 primitiveType, (SpacingMode)spacingI,
7554 ("data/tessellation/" + caseName + "_ref").c_str()));
7558 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7560 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7561 if (primitiveType == TESSPRIMITIVETYPE_ISOLINES)
7564 const char* const primTypeName = getTessPrimitiveTypeShaderName(primitiveType);
7566 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7568 const string caseName = string() + "fill_overlap_" + primTypeName + "_" + getSpacingModeShaderName((SpacingMode)spacingI);
7570 miscDrawGroup->addChild(new BasicTriangleFillNonOverlapCase(m_context,
7571 caseName.c_str(), "Check that there are no obvious triangle overlaps in the triangle-filled area of a tessellated shape",
7572 primitiveType, (SpacingMode)spacingI,
7573 ("data/tessellation/" + caseName + "_ref").c_str()));
7577 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7579 const string caseName = string() + "isolines_" + getSpacingModeShaderName((SpacingMode)spacingI);
7581 miscDrawGroup->addChild(new IsolinesRenderCase(m_context,
7582 caseName.c_str(), "Basic isolines render test",
7583 (SpacingMode)spacingI,
7584 ("data/tessellation/" + caseName + "_ref").c_str()));
7589 TestCaseGroup* const commonEdgeGroup = new TestCaseGroup(m_context, "common_edge", "Draw multiple adjacent shapes and check that no cracks appear between them");
7590 addChild(commonEdgeGroup);
7592 for (int caseTypeI = 0; caseTypeI < CommonEdgeCase::CASETYPE_LAST; caseTypeI++)
7594 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7596 const CommonEdgeCase::CaseType caseType = (CommonEdgeCase::CaseType)caseTypeI;
7597 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7598 if (primitiveType == TESSPRIMITIVETYPE_ISOLINES)
7601 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7603 const SpacingMode spacing = (SpacingMode)spacingI;
7604 const string caseName = (string() + getTessPrimitiveTypeShaderName(primitiveType)
7605 + "_" + getSpacingModeShaderName(spacing)
7606 + (caseType == CommonEdgeCase::CASETYPE_BASIC ? ""
7607 : caseType == CommonEdgeCase::CASETYPE_PRECISE ? "_precise"
7610 commonEdgeGroup->addChild(new CommonEdgeCase(m_context, caseName.c_str(), "", primitiveType, spacing, caseType));
7617 TestCaseGroup* const fractionalSpacingModeGroup = new TestCaseGroup(m_context, "fractional_spacing", "Test fractional spacing modes");
7618 addChild(fractionalSpacingModeGroup);
7620 fractionalSpacingModeGroup->addChild(new FractionalSpacingModeCase(m_context, "odd", "", SPACINGMODE_FRACTIONAL_ODD));
7621 fractionalSpacingModeGroup->addChild(new FractionalSpacingModeCase(m_context, "even", "", SPACINGMODE_FRACTIONAL_EVEN));
7625 TestCaseGroup* const primitiveDiscardGroup = new TestCaseGroup(m_context, "primitive_discard", "Test primitive discard with relevant outer tessellation level <= 0.0");
7626 addChild(primitiveDiscardGroup);
7628 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7630 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7632 for (int windingI = 0; windingI < WINDING_LAST; windingI++)
7634 for (int usePointModeI = 0; usePointModeI <= 1; usePointModeI++)
7636 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7637 const SpacingMode spacing = (SpacingMode)spacingI;
7638 const Winding winding = (Winding)windingI;
7639 const bool usePointMode = usePointModeI != 0;
7641 primitiveDiscardGroup->addChild(new PrimitiveDiscardCase(m_context, (string() + getTessPrimitiveTypeShaderName(primitiveType)
7642 + "_" + getSpacingModeShaderName(spacing)
7643 + "_" + getWindingShaderName(winding)
7644 + (usePointMode ? "_point_mode" : "")).c_str(), "",
7645 primitiveType, spacing, winding, usePointMode));
7653 TestCaseGroup* const invarianceGroup = new TestCaseGroup(m_context, "invariance", "Test tessellation invariance rules");
7655 TestCaseGroup* const invariantPrimitiveSetGroup = new TestCaseGroup(m_context, "primitive_set", "Test invariance rule #1");
7656 TestCaseGroup* const invariantOuterEdgeGroup = new TestCaseGroup(m_context, "outer_edge_division", "Test invariance rule #2");
7657 TestCaseGroup* const symmetricOuterEdgeGroup = new TestCaseGroup(m_context, "outer_edge_symmetry", "Test invariance rule #3");
7658 TestCaseGroup* const outerEdgeVertexSetIndexIndependenceGroup = new TestCaseGroup(m_context, "outer_edge_index_independence", "Test invariance rule #4");
7659 TestCaseGroup* const invariantTriangleSetGroup = new TestCaseGroup(m_context, "triangle_set", "Test invariance rule #5");
7660 TestCaseGroup* const invariantInnerTriangleSetGroup = new TestCaseGroup(m_context, "inner_triangle_set", "Test invariance rule #6");
7661 TestCaseGroup* const invariantOuterTriangleSetGroup = new TestCaseGroup(m_context, "outer_triangle_set", "Test invariance rule #7");
7662 TestCaseGroup* const tessCoordComponentRangeGroup = new TestCaseGroup(m_context, "tess_coord_component_range", "Test invariance rule #8, first part");
7663 TestCaseGroup* const oneMinusTessCoordComponentGroup = new TestCaseGroup(m_context, "one_minus_tess_coord_component", "Test invariance rule #8, second part");
7665 addChild(invarianceGroup);
7666 invarianceGroup->addChild(invariantPrimitiveSetGroup);
7667 invarianceGroup->addChild(invariantOuterEdgeGroup);
7668 invarianceGroup->addChild(symmetricOuterEdgeGroup);
7669 invarianceGroup->addChild(outerEdgeVertexSetIndexIndependenceGroup);
7670 invarianceGroup->addChild(invariantTriangleSetGroup);
7671 invarianceGroup->addChild(invariantInnerTriangleSetGroup);
7672 invarianceGroup->addChild(invariantOuterTriangleSetGroup);
7673 invarianceGroup->addChild(tessCoordComponentRangeGroup);
7674 invarianceGroup->addChild(oneMinusTessCoordComponentGroup);
7676 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7678 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7679 const string primName = getTessPrimitiveTypeShaderName(primitiveType);
7680 const bool triOrQuad = primitiveType == TESSPRIMITIVETYPE_TRIANGLES || primitiveType == TESSPRIMITIVETYPE_QUADS;
7682 for (int spacingI = 0; spacingI < SPACINGMODE_LAST; spacingI++)
7684 const SpacingMode spacing = (SpacingMode)spacingI;
7685 const string primSpacName = primName + "_" + getSpacingModeShaderName(spacing);
7689 invariantOuterEdgeGroup->addChild (new InvariantOuterEdgeCase (m_context, primSpacName.c_str(), "", primitiveType, spacing));
7690 invariantTriangleSetGroup->addChild (new InvariantTriangleSetCase (m_context, primSpacName.c_str(), "", primitiveType, spacing));
7691 invariantInnerTriangleSetGroup->addChild(new InvariantInnerTriangleSetCase (m_context, primSpacName.c_str(), "", primitiveType, spacing));
7692 invariantOuterTriangleSetGroup->addChild(new InvariantOuterTriangleSetCase (m_context, primSpacName.c_str(), "", primitiveType, spacing));
7695 for (int windingI = 0; windingI < WINDING_LAST; windingI++)
7697 const Winding winding = (Winding)windingI;
7698 const string primSpacWindName = primSpacName + "_" + getWindingShaderName(winding);
7700 for (int usePointModeI = 0; usePointModeI <= 1; usePointModeI++)
7702 const bool usePointMode = usePointModeI != 0;
7703 const string primSpacWindPointName = primSpacWindName + (usePointMode ? "_point_mode" : "");
7705 invariantPrimitiveSetGroup->addChild (new InvariantPrimitiveSetCase (m_context, primSpacWindPointName.c_str(), "", primitiveType, spacing, winding, usePointMode));
7706 symmetricOuterEdgeGroup->addChild (new SymmetricOuterEdgeCase (m_context, primSpacWindPointName.c_str(), "", primitiveType, spacing, winding, usePointMode));
7707 tessCoordComponentRangeGroup->addChild (new TessCoordComponentRangeCase (m_context, primSpacWindPointName.c_str(), "", primitiveType, spacing, winding, usePointMode));
7708 oneMinusTessCoordComponentGroup->addChild (new OneMinusTessCoordComponentCase (m_context, primSpacWindPointName.c_str(), "", primitiveType, spacing, winding, usePointMode));
7711 outerEdgeVertexSetIndexIndependenceGroup->addChild(new OuterEdgeVertexSetIndexIndependenceCase(m_context, primSpacWindPointName.c_str(), "",
7712 primitiveType, spacing, winding, usePointMode));
7723 const char* description;
7724 UserDefinedIOCase::IOType ioType;
7727 { "per_patch", "Per-patch TCS outputs", UserDefinedIOCase::IO_TYPE_PER_PATCH },
7728 { "per_patch_array", "Per-patch array TCS outputs", UserDefinedIOCase::IO_TYPE_PER_PATCH_ARRAY },
7729 { "per_patch_block", "Per-patch TCS outputs in IO block", UserDefinedIOCase::IO_TYPE_PER_PATCH_BLOCK },
7730 { "per_patch_block_array", "Per-patch TCS outputs in IO block array", UserDefinedIOCase::IO_TYPE_PER_PATCH_BLOCK_ARRAY },
7731 { "per_vertex", "Per-vertex TCS outputs", UserDefinedIOCase::IO_TYPE_PER_VERTEX },
7732 { "per_vertex_block", "Per-vertex TCS outputs in IO block", UserDefinedIOCase::IO_TYPE_PER_VERTEX_BLOCK },
7735 TestCaseGroup* const userDefinedIOGroup = new TestCaseGroup(m_context, "user_defined_io", "Test non-built-in per-patch and per-vertex inputs and outputs");
7736 addChild(userDefinedIOGroup);
7738 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(ioCases); ++ndx)
7740 TestCaseGroup* const ioTypeGroup = new TestCaseGroup(m_context, ioCases[ndx].name, ioCases[ndx].description);
7741 userDefinedIOGroup->addChild(ioTypeGroup);
7743 for (int vertexArraySizeI = 0; vertexArraySizeI < UserDefinedIOCase::VERTEX_IO_ARRAY_SIZE_LAST; vertexArraySizeI++)
7745 const UserDefinedIOCase::VertexIOArraySize vertexArraySize = (UserDefinedIOCase::VertexIOArraySize)vertexArraySizeI;
7746 TestCaseGroup* const vertexArraySizeGroup = new TestCaseGroup(m_context,
7747 vertexArraySizeI == UserDefinedIOCase::VERTEX_IO_ARRAY_SIZE_IMPLICIT
7748 ? "vertex_io_array_size_implicit"
7749 : vertexArraySizeI == UserDefinedIOCase::VERTEX_IO_ARRAY_SIZE_EXPLICIT_SHADER_BUILTIN
7750 ? "vertex_io_array_size_shader_builtin"
7751 : vertexArraySizeI == UserDefinedIOCase::VERTEX_IO_ARRAY_SIZE_EXPLICIT_QUERY
7752 ? "vertex_io_array_size_query"
7755 ioTypeGroup->addChild(vertexArraySizeGroup);
7757 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7759 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7760 vertexArraySizeGroup->addChild(new UserDefinedIOCase(m_context, getTessPrimitiveTypeShaderName(primitiveType), "", primitiveType, ioCases[ndx].ioType, vertexArraySize, UserDefinedIOCase::TESS_CONTROL_OUT_ARRAY_SIZE_IMPLICIT,
7761 (string() + "data/tessellation/user_defined_io_" + getTessPrimitiveTypeShaderName(primitiveType) + "_ref.png").c_str()));
7764 if (ioCases[ndx].ioType == UserDefinedIOCase::IO_TYPE_PER_VERTEX
7765 || ioCases[ndx].ioType == UserDefinedIOCase::IO_TYPE_PER_VERTEX_BLOCK)
7767 for (int primitiveTypeI = 0; primitiveTypeI < TESSPRIMITIVETYPE_LAST; primitiveTypeI++)
7769 const TessPrimitiveType primitiveType = (TessPrimitiveType)primitiveTypeI;
7770 vertexArraySizeGroup->addChild(new UserDefinedIOCase(m_context, (string(getTessPrimitiveTypeShaderName(primitiveType)) + "_explicit_tcs_out_size").c_str(), "", primitiveType, ioCases[ndx].ioType, vertexArraySize, UserDefinedIOCase::TESS_CONTROL_OUT_ARRAY_SIZE_LAYOUT,
7771 (string() + "data/tessellation/user_defined_io_" + getTessPrimitiveTypeShaderName(primitiveType) + "_ref.png").c_str()));
7780 de::MovePtr<TestCaseGroup> negativeGroup (new TestCaseGroup(m_context, "negative", "Negative cases"));
7783 de::MovePtr<TestCaseGroup> es31Group (new TestCaseGroup(m_context, "es31", "GLSL ES 3.1 Negative cases"));
7784 gls::ShaderLibrary shaderLibrary (m_testCtx, m_context.getRenderContext(), m_context.getContextInfo());
7785 const std::vector<tcu::TestNode*> children = shaderLibrary.loadShaderFile("shaders/es31/tessellation_negative_user_defined_io.test");
7787 for (int i = 0; i < (int)children.size(); i++)
7788 es31Group->addChild(children[i]);
7790 negativeGroup->addChild(es31Group.release());
7794 de::MovePtr<TestCaseGroup> es32Group (new TestCaseGroup(m_context, "es32", "GLSL ES 3.2 Negative cases"));
7795 gls::ShaderLibrary shaderLibrary (m_testCtx, m_context.getRenderContext(), m_context.getContextInfo());
7796 const std::vector<tcu::TestNode*> children = shaderLibrary.loadShaderFile("shaders/es32/tessellation_negative_user_defined_io.test");
7798 for (int i = 0; i < (int)children.size(); i++)
7799 es32Group->addChild(children[i]);
7801 negativeGroup->addChild(es32Group.release());
7804 userDefinedIOGroup->addChild(negativeGroup.release());