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