1 #ifndef _TCURASTERIZATIONVERIFIER_HPP 2 #define _TCURASTERIZATIONVERIFIER_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Rasterization verifier utils. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuTestLog.hpp" 28 #include "tcuSurface.hpp" 29 #include "deMath.h" 30 31 #include <vector> 32 33 namespace tcu 34 { 35 36 enum CoverageType 37 { 38 COVERAGE_FULL = 0, // !< primitive fully covers the queried area 39 COVERAGE_PARTIAL, // !< primitive coverage is either partial, or could be full, partial or none depending on rounding and/or fill rules 40 COVERAGE_NONE, // !< primitive does not cover area at all 41 42 COVERAGE_LAST 43 }; 44 45 enum VerificationMode 46 { 47 VERIFICATIONMODE_STRICT = 0, // !< do not allow even a single bad pixel 48 VERIFICATIONMODE_WEAK, // !< allow some bad pixels 49 VERIFICATIONMODE_WEAKER, // !< allow more bad pixels 50 VERIFICATIONMODE_SMOOTH, // !< allow no missing pixels 51 52 VERIFICATIONMODE_LAST 53 }; 54 55 enum LineInterpolationMethod 56 { 57 LINEINTERPOLATION_STRICTLY_CORRECT = 0, // !< line interpolation matches the specification 58 LINEINTERPOLATION_PROJECTED, // !< line interpolation weights are otherwise correct, but they are projected onto major axis 59 LINEINTERPOLATION_INCORRECT // !< line interpolation is incorrect 60 }; 61 62 struct TriangleSceneSpec 63 { 64 struct SceneTriangle 65 { 66 tcu::Vec4 positions[3]; 67 tcu::Vec4 colors[3]; 68 bool sharedEdge[3]; // !< is the edge i -> i+1 shared with another scene triangle 69 }; 70 71 std::vector<SceneTriangle> triangles; 72 }; 73 74 struct LineSceneSpec 75 { LineSceneSpectcu::LineSceneSpec76 LineSceneSpec() 77 : isStrip(false) 78 , isSmooth(false) 79 , isRectangular(false) 80 , stippleEnable(false) 81 , verificationMode(VERIFICATIONMODE_STRICT) 82 {} 83 84 struct SceneLine 85 { 86 tcu::Vec4 positions[2]; 87 tcu::Vec4 colors[2]; 88 }; 89 90 std::vector<SceneLine> lines; 91 float lineWidth; 92 bool isStrip; 93 bool isSmooth; 94 bool isRectangular; 95 bool stippleEnable; 96 deUint32 stippleFactor; 97 deUint16 stipplePattern; 98 VerificationMode verificationMode; 99 }; 100 101 struct PointSceneSpec 102 { 103 struct ScenePoint 104 { 105 tcu::Vec4 position; 106 tcu::Vec4 color; 107 float pointSize; 108 }; 109 110 std::vector<ScenePoint> points; 111 }; 112 113 struct RasterizationArguments 114 { 115 int numSamples; 116 int subpixelBits; 117 int redBits; 118 int greenBits; 119 int blueBits; 120 }; 121 122 struct VerifyTriangleGroupRasterizationLogStash 123 { 124 std::vector<std::string> messages; 125 int missingPixels; 126 int unexpectedPixels; 127 tcu::Surface errorMask; 128 bool result; 129 }; 130 131 struct VerifyTriangleGroupInterpolationLogStash 132 { 133 std::vector<std::string> messages; 134 int invalidPixels; 135 tcu::Surface errorMask; 136 bool success; 137 }; 138 139 /*--------------------------------------------------------------------*//*! 140 * \brief Calculates triangle coverage at given pixel 141 * Calculates the coverage of a triangle given by three vertices. The 142 * triangle should not be z-clipped. If multisample is false, the pixel 143 * center is compared against the triangle. If multisample is true, the 144 * whole pixel area is compared. 145 *//*--------------------------------------------------------------------*/ 146 CoverageType calculateTriangleCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const tcu::Vec4& p2, const tcu::IVec2& pixel, const tcu::IVec2& viewportSize, int subpixelBits, bool multisample); 147 148 /*--------------------------------------------------------------------*//*! 149 * \brief Calculates line coverage at given pixel 150 * Calculates the coverage of a reactangle given by line coordinates and width. 151 *//*--------------------------------------------------------------------*/ 152 CoverageType calculateUnderestimateLineCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const float lineWidth, const tcu::IVec2& pixel, const tcu::IVec2& viewportSize); 153 154 /*--------------------------------------------------------------------*//*! 155 * \brief Calculates triangle coverage at given pixel 156 * Calculates the coverage of a triangle given by by three vertices. 157 *//*--------------------------------------------------------------------*/ 158 CoverageType calculateUnderestimateTriangleCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const tcu::Vec4& p2, const tcu::IVec2& pixel, int subpixelBits, const tcu::IVec2& viewportSize); 159 160 /*--------------------------------------------------------------------*//*! 161 * \brief Verify triangle rasterization result 162 * Verifies pixels in the surface are rasterized within the bounds given 163 * by RasterizationArguments. Triangles should not be z-clipped. 164 * 165 * Triangle colors are not used. The triangle is expected to be white. 166 * If logStash is not NULL the results are not logged, but copied to stash. 167 * 168 * Returns false if invalid rasterization is found. 169 *//*--------------------------------------------------------------------*/ 170 bool verifyTriangleGroupRasterization (const tcu::Surface& surface, const TriangleSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, VerificationMode mode = VERIFICATIONMODE_STRICT, VerifyTriangleGroupRasterizationLogStash* logStash = DE_NULL, const bool vulkanLinesTest = false); 171 172 /*--------------------------------------------------------------------*//*! 173 * \brief Verify line rasterization result 174 * Verifies pixels in the surface are rasterized within the bounds given 175 * by RasterizationArguments. Lines should not be z-clipped. 176 * 177 * Line colors are not used. The line is expected to be white. 178 * 179 * Returns false if invalid rasterization is found. 180 *//*--------------------------------------------------------------------*/ 181 bool verifyLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log); 182 183 /*--------------------------------------------------------------------*//*! 184 * \brief Verify clipped line rasterization result 185 * Verifies pixels in the surface are rasterized within the bounds given 186 * by RasterizationArguments and by clipping the lines with a (-1, -1), (1, 1) 187 * square. Lines should not be z-clipped. 188 * 189 * Line colors are not used. The line is expected to be white. Lines are 190 * rasterized as two triangles. 191 * 192 * Returns false if invalid rasterization is found. 193 *//*--------------------------------------------------------------------*/ 194 bool verifyClippedTriangulatedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log); 195 196 /*--------------------------------------------------------------------*//*! 197 * \brief Verify line rasterization result both clipped and non-clipped 198 * 199 * For details please see verifyLineGroupRasterization and 200 * verifyClippedTriangulatedLineGroupRasterization 201 * 202 * Returns false if both rasterizations are invalid. 203 *//*--------------------------------------------------------------------*/ 204 bool verifyRelaxedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, const bool vulkanLinesTest = false, const bool strict = true); 205 206 /*--------------------------------------------------------------------*//*! 207 * \brief Verify point rasterization result 208 * Verifies points in the surface are rasterized within the bounds given 209 * by RasterizationArguments. Points should not be z-clipped. 210 * 211 * Point colors are not used. The point is expected to be white. 212 * 213 * Returns false if invalid rasterization is found. 214 *//*--------------------------------------------------------------------*/ 215 bool verifyPointGroupRasterization (const tcu::Surface& surface, const PointSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log); 216 217 /*--------------------------------------------------------------------*//*! 218 * \brief Verify triangle color interpolation is valid 219 * Verifies the color of a fragments of a colored triangle is in the 220 * valid range. Triangles should not be z-clipped. 221 * 222 * The background is expected to be black. 223 * 224 * Returns false if invalid rasterization interpolation is found. 225 *//*--------------------------------------------------------------------*/ 226 bool verifyTriangleGroupInterpolation (const tcu::Surface& surface, const TriangleSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log); 227 228 /*--------------------------------------------------------------------*//*! 229 * \brief Verify line color interpolation is valid 230 * Verifies the color of a fragments of a colored line is in the 231 * valid range. Lines should not be z-clipped. 232 * 233 * The background is expected to be black. 234 * 235 * Returns the detected interpolation method of the input image. 236 *//*--------------------------------------------------------------------*/ 237 LineInterpolationMethod verifyLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log); 238 239 /*--------------------------------------------------------------------*//*! 240 * \brief Verify line color interpolation is valid 241 * Verifies the color of a fragments of a colored line is in the 242 * valid range. Lines should not be z-clipped. 243 * 244 * The background is expected to be black. The lines are rasterized 245 * as two triangles. 246 * 247 * Returns false if invalid rasterization interpolation is found. 248 *//*--------------------------------------------------------------------*/ 249 bool verifyTriangulatedLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, const bool strictMode = true, const bool allowBresenhamForNonStrictLines = false); 250 251 } // tcu 252 253 #endif // _TCURASTERIZATIONVERIFIER_HPP 254