• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
SceneTriangletcu::TriangleSceneSpec::SceneTriangle69 		SceneTriangle()
70 		{
71 			// Other members are initialized in Vector constructor
72 			for (int i = 0; i < 3; i++)
73 				sharedEdge[i] = false;
74 		}
75 	};
76 
77 	std::vector<SceneTriangle> triangles;
78 };
79 
80 struct LineSceneSpec
81 {
LineSceneSpectcu::LineSceneSpec82 	LineSceneSpec()
83 		: isStrip(false)
84 		, isSmooth(false)
85 		, isRectangular(false)
86 		, stippleEnable(false)
87 		, verificationMode(VERIFICATIONMODE_STRICT)
88 	{}
89 
90 	struct SceneLine
91 	{
92 		tcu::Vec4	positions[2];
93 		tcu::Vec4	colors[2];
94 	};
95 
96 	std::vector<SceneLine>	lines;
97 	float					lineWidth;
98 	bool					isStrip;
99 	bool					isSmooth;
100 	bool					isRectangular;
101 	bool					stippleEnable;
102 	deUint32				stippleFactor;
103 	deUint16				stipplePattern;
104 	VerificationMode		verificationMode;
105 };
106 
107 struct PointSceneSpec
108 {
109 	struct ScenePoint
110 	{
111 		tcu::Vec4	position;
112 		tcu::Vec4	color;
113 		float		pointSize;
114 	};
115 
116 	std::vector<ScenePoint> points;
117 };
118 
119 struct RasterizationArguments
120 {
121 	int numSamples;
122 	int subpixelBits;
123 	int redBits;
124 	int greenBits;
125 	int blueBits;
126 };
127 
128 struct VerifyTriangleGroupRasterizationLogStash
129 {
130 	std::vector<std::string>	messages;
131 	int							missingPixels;
132 	int							unexpectedPixels;
133 	tcu::Surface				errorMask;
134 	bool						result;
135 };
136 
137 struct VerifyTriangleGroupInterpolationLogStash
138 {
139 	std::vector<std::string>	messages;
140 	int							invalidPixels;
141 	tcu::Surface				errorMask;
142 	bool						success;
143 };
144 
145 /*--------------------------------------------------------------------*//*!
146  * \brief Calculates triangle coverage at given pixel
147  * Calculates the coverage of a triangle given by three vertices. The
148  * triangle should not be z-clipped. If multisample is false, the pixel
149  * center is compared against the triangle. If multisample is true, the
150  * whole pixel area is compared.
151  *//*--------------------------------------------------------------------*/
152 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);
153 
154 /*--------------------------------------------------------------------*//*!
155  * \brief Calculates line coverage at given pixel
156  * Calculates the coverage of a reactangle given by line coordinates and width.
157  *//*--------------------------------------------------------------------*/
158 CoverageType calculateUnderestimateLineCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const float lineWidth, const tcu::IVec2& pixel, const tcu::IVec2& viewportSize);
159 
160 /*--------------------------------------------------------------------*//*!
161  * \brief Calculates triangle coverage at given pixel
162  * Calculates the coverage of a triangle given by by three vertices.
163  *//*--------------------------------------------------------------------*/
164 CoverageType calculateUnderestimateTriangleCoverage (const tcu::Vec4& p0, const tcu::Vec4& p1, const tcu::Vec4& p2, const tcu::IVec2& pixel, int subpixelBits, const tcu::IVec2& viewportSize);
165 
166 /*--------------------------------------------------------------------*//*!
167  * \brief Verify triangle rasterization result
168  * Verifies pixels in the surface are rasterized within the bounds given
169  * by RasterizationArguments. Triangles should not be z-clipped.
170  *
171  * Triangle colors are not used. The triangle is expected to be white.
172  * If logStash is not NULL the results are not logged, but copied to stash.
173  *
174  * Returns false if invalid rasterization is found.
175  *//*--------------------------------------------------------------------*/
176 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);
177 
178 /*--------------------------------------------------------------------*//*!
179  * \brief Verify line rasterization result
180  * Verifies pixels in the surface are rasterized within the bounds given
181  * by RasterizationArguments. Lines should not be z-clipped.
182  *
183  * Line colors are not used. The line is expected to be white.
184  *
185  * Returns false if invalid rasterization is found.
186  *//*--------------------------------------------------------------------*/
187 bool verifyLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
188 
189 /*--------------------------------------------------------------------*//*!
190  * \brief Verify clipped line rasterization result
191  * Verifies pixels in the surface are rasterized within the bounds given
192  * by RasterizationArguments and by clipping the lines with a (-1, -1), (1, 1)
193  * square. Lines should not be z-clipped.
194  *
195  * Line colors are not used. The line is expected to be white. Lines are
196  * rasterized as two triangles.
197  *
198  * Returns false if invalid rasterization is found.
199  *//*--------------------------------------------------------------------*/
200 bool verifyClippedTriangulatedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
201 
202 /*--------------------------------------------------------------------*//*!
203  * \brief Verify line rasterization result both clipped and non-clipped
204  *
205  * For details please see verifyLineGroupRasterization and
206  * verifyClippedTriangulatedLineGroupRasterization
207  *
208  * Returns false if both rasterizations are invalid.
209  *//*--------------------------------------------------------------------*/
210 bool verifyRelaxedLineGroupRasterization (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, const bool vulkanLinesTest = false, const bool strict = true);
211 
212 /*--------------------------------------------------------------------*//*!
213  * \brief Verify point rasterization result
214  * Verifies points in the surface are rasterized within the bounds given
215  * by RasterizationArguments. Points should not be z-clipped.
216  *
217  * Point colors are not used. The point is expected to be white.
218  *
219  * Returns false if invalid rasterization is found.
220  *//*--------------------------------------------------------------------*/
221 bool verifyPointGroupRasterization (const tcu::Surface& surface, const PointSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
222 
223 /*--------------------------------------------------------------------*//*!
224  * \brief Verify triangle color interpolation is valid
225  * Verifies the color of a fragments of a colored triangle is in the
226  * valid range. Triangles should not be z-clipped.
227  *
228  * The background is expected to be black.
229  *
230  * Returns false if invalid rasterization interpolation is found.
231  *//*--------------------------------------------------------------------*/
232 bool verifyTriangleGroupInterpolation (const tcu::Surface& surface, const TriangleSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
233 
234 /*--------------------------------------------------------------------*//*!
235  * \brief Verify line color interpolation is valid
236  * Verifies the color of a fragments of a colored line is in the
237  * valid range. Lines should not be z-clipped.
238  *
239  * The background is expected to be black.
240  *
241  * Returns the detected interpolation method of the input image.
242  *//*--------------------------------------------------------------------*/
243 LineInterpolationMethod verifyLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log);
244 
245 /*--------------------------------------------------------------------*//*!
246  * \brief Verify line color interpolation is valid
247  * Verifies the color of a fragments of a colored line is in the
248  * valid range. Lines should not be z-clipped.
249  *
250  * The background is expected to be black. The lines are rasterized
251  * as two triangles.
252  *
253  * Returns false if invalid rasterization interpolation is found.
254  *//*--------------------------------------------------------------------*/
255 bool verifyTriangulatedLineGroupInterpolation (const tcu::Surface& surface, const LineSceneSpec& scene, const RasterizationArguments& args, tcu::TestLog& log, const bool strictMode = true, const bool allowBresenhamForNonStrictLines = false);
256 
257 } // tcu
258 
259 #endif // _TCURASTERIZATIONVERIFIER_HPP
260