xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fPrerequisiteTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Prerequisite tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2fPrerequisiteTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "deRandom.h"
26*35238bceSAndroid Build Coastguard Worker #include "tcuRGBA.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluStateReset.hpp"
33*35238bceSAndroid Build Coastguard Worker 
34*35238bceSAndroid Build Coastguard Worker #include "glw.h"
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker using tcu::RGBA;
37*35238bceSAndroid Build Coastguard Worker using tcu::Surface;
38*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
39*35238bceSAndroid Build Coastguard Worker 
40*35238bceSAndroid Build Coastguard Worker namespace deqp
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker namespace gles2
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace Functional
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker 
47*35238bceSAndroid Build Coastguard Worker class StateResetCase : public TestCase
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker public:
50*35238bceSAndroid Build Coastguard Worker     StateResetCase(Context &context);
51*35238bceSAndroid Build Coastguard Worker     virtual ~StateResetCase(void);
52*35238bceSAndroid Build Coastguard Worker     virtual TestCase::IterateResult iterate(void);
53*35238bceSAndroid Build Coastguard Worker };
54*35238bceSAndroid Build Coastguard Worker 
StateResetCase(Context & context)55*35238bceSAndroid Build Coastguard Worker StateResetCase::StateResetCase(Context &context) : TestCase(context, "state_reset", "State Reset Test")
56*35238bceSAndroid Build Coastguard Worker {
57*35238bceSAndroid Build Coastguard Worker }
58*35238bceSAndroid Build Coastguard Worker 
~StateResetCase(void)59*35238bceSAndroid Build Coastguard Worker StateResetCase::~StateResetCase(void)
60*35238bceSAndroid Build Coastguard Worker {
61*35238bceSAndroid Build Coastguard Worker }
62*35238bceSAndroid Build Coastguard Worker 
iterate(void)63*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult StateResetCase::iterate(void)
64*35238bceSAndroid Build Coastguard Worker {
65*35238bceSAndroid Build Coastguard Worker     try
66*35238bceSAndroid Build Coastguard Worker     {
67*35238bceSAndroid Build Coastguard Worker         glu::resetState(m_context.getRenderContext(), m_context.getContextInfo());
68*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
69*35238bceSAndroid Build Coastguard Worker     }
70*35238bceSAndroid Build Coastguard Worker     catch (const tcu::TestError &e)
71*35238bceSAndroid Build Coastguard Worker     {
72*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << e;
73*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
74*35238bceSAndroid Build Coastguard Worker     }
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker     return TestCase::STOP;
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker class ClearColorCase : public TestCase
80*35238bceSAndroid Build Coastguard Worker {
81*35238bceSAndroid Build Coastguard Worker public:
82*35238bceSAndroid Build Coastguard Worker     ClearColorCase(Context &context);
83*35238bceSAndroid Build Coastguard Worker     virtual ~ClearColorCase(void);
84*35238bceSAndroid Build Coastguard Worker     virtual TestCase::IterateResult iterate(void);
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker private:
87*35238bceSAndroid Build Coastguard Worker     RGBA m_clearColor;
88*35238bceSAndroid Build Coastguard Worker     int m_numIters;
89*35238bceSAndroid Build Coastguard Worker     int m_curIter;
90*35238bceSAndroid Build Coastguard Worker };
91*35238bceSAndroid Build Coastguard Worker 
ClearColorCase(Context & context)92*35238bceSAndroid Build Coastguard Worker ClearColorCase::ClearColorCase(Context &context)
93*35238bceSAndroid Build Coastguard Worker     : TestCase(context, "clear_color", "glClearColor test")
94*35238bceSAndroid Build Coastguard Worker     , m_numIters(10)
95*35238bceSAndroid Build Coastguard Worker     , m_curIter(0)
96*35238bceSAndroid Build Coastguard Worker {
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker 
~ClearColorCase(void)99*35238bceSAndroid Build Coastguard Worker ClearColorCase::~ClearColorCase(void)
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker }
102*35238bceSAndroid Build Coastguard Worker 
iterate(void)103*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult ClearColorCase::iterate(void)
104*35238bceSAndroid Build Coastguard Worker {
105*35238bceSAndroid Build Coastguard Worker     int r = 0;
106*35238bceSAndroid Build Coastguard Worker     int g = 0;
107*35238bceSAndroid Build Coastguard Worker     int b = 0;
108*35238bceSAndroid Build Coastguard Worker     int a = 255;
109*35238bceSAndroid Build Coastguard Worker 
110*35238bceSAndroid Build Coastguard Worker     switch (m_curIter)
111*35238bceSAndroid Build Coastguard Worker     {
112*35238bceSAndroid Build Coastguard Worker     case 0:
113*35238bceSAndroid Build Coastguard Worker         // Black, skip
114*35238bceSAndroid Build Coastguard Worker         break;
115*35238bceSAndroid Build Coastguard Worker     case 1:
116*35238bceSAndroid Build Coastguard Worker         r = 255;
117*35238bceSAndroid Build Coastguard Worker         g = 255;
118*35238bceSAndroid Build Coastguard Worker         b = 255;
119*35238bceSAndroid Build Coastguard Worker         break;
120*35238bceSAndroid Build Coastguard Worker     case 2:
121*35238bceSAndroid Build Coastguard Worker         r = 255;
122*35238bceSAndroid Build Coastguard Worker         break;
123*35238bceSAndroid Build Coastguard Worker     case 3:
124*35238bceSAndroid Build Coastguard Worker         g = 255;
125*35238bceSAndroid Build Coastguard Worker         break;
126*35238bceSAndroid Build Coastguard Worker     case 4:
127*35238bceSAndroid Build Coastguard Worker         b = 255;
128*35238bceSAndroid Build Coastguard Worker         break;
129*35238bceSAndroid Build Coastguard Worker     default:
130*35238bceSAndroid Build Coastguard Worker         deRandom rnd;
131*35238bceSAndroid Build Coastguard Worker         deRandom_init(&rnd, deInt32Hash(m_curIter));
132*35238bceSAndroid Build Coastguard Worker         r = (int)(deRandom_getUint32(&rnd) & 0xFF);
133*35238bceSAndroid Build Coastguard Worker         g = (int)(deRandom_getUint32(&rnd) & 0xFF);
134*35238bceSAndroid Build Coastguard Worker         b = (int)(deRandom_getUint32(&rnd) & 0xFF);
135*35238bceSAndroid Build Coastguard Worker         a = (int)(deRandom_getUint32(&rnd) & 0xFF);
136*35238bceSAndroid Build Coastguard Worker         break;
137*35238bceSAndroid Build Coastguard Worker     }
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker     glClearColor(float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, float(a) / 255.0f);
140*35238bceSAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_MSG("CLES2 ClearColor failed.");
143*35238bceSAndroid Build Coastguard Worker 
144*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker     return (++m_curIter < m_numIters) ? CONTINUE : STOP;
147*35238bceSAndroid Build Coastguard Worker }
148*35238bceSAndroid Build Coastguard Worker 
149*35238bceSAndroid Build Coastguard Worker class ReadPixelsCase : public TestCase
150*35238bceSAndroid Build Coastguard Worker {
151*35238bceSAndroid Build Coastguard Worker public:
152*35238bceSAndroid Build Coastguard Worker     ReadPixelsCase(Context &context);
153*35238bceSAndroid Build Coastguard Worker     virtual ~ReadPixelsCase(void);
154*35238bceSAndroid Build Coastguard Worker     virtual TestCase::IterateResult iterate(void);
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker private:
157*35238bceSAndroid Build Coastguard Worker     int m_numIters;
158*35238bceSAndroid Build Coastguard Worker     int m_curIter;
159*35238bceSAndroid Build Coastguard Worker };
160*35238bceSAndroid Build Coastguard Worker 
ReadPixelsCase(Context & context)161*35238bceSAndroid Build Coastguard Worker ReadPixelsCase::ReadPixelsCase(Context &context)
162*35238bceSAndroid Build Coastguard Worker     : TestCase(context, "read_pixels", "Read pixels test")
163*35238bceSAndroid Build Coastguard Worker     , m_numIters(20)
164*35238bceSAndroid Build Coastguard Worker     , m_curIter(0)
165*35238bceSAndroid Build Coastguard Worker {
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker 
~ReadPixelsCase(void)168*35238bceSAndroid Build Coastguard Worker ReadPixelsCase::~ReadPixelsCase(void)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker }
171*35238bceSAndroid Build Coastguard Worker 
iterate(void)172*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult ReadPixelsCase::iterate(void)
173*35238bceSAndroid Build Coastguard Worker {
174*35238bceSAndroid Build Coastguard Worker     const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
175*35238bceSAndroid Build Coastguard Worker     tcu::PixelFormat pixelFormat          = renderTarget.getPixelFormat();
176*35238bceSAndroid Build Coastguard Worker     int targetWidth                       = renderTarget.getWidth();
177*35238bceSAndroid Build Coastguard Worker     int targetHeight                      = renderTarget.getHeight();
178*35238bceSAndroid Build Coastguard Worker     int x                                 = 0;
179*35238bceSAndroid Build Coastguard Worker     int y                                 = 0;
180*35238bceSAndroid Build Coastguard Worker     int imageWidth                        = 0;
181*35238bceSAndroid Build Coastguard Worker     int imageHeight                       = 0;
182*35238bceSAndroid Build Coastguard Worker 
183*35238bceSAndroid Build Coastguard Worker     deRandom rnd;
184*35238bceSAndroid Build Coastguard Worker     deRandom_init(&rnd, deInt32Hash(m_curIter));
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker     switch (m_curIter)
187*35238bceSAndroid Build Coastguard Worker     {
188*35238bceSAndroid Build Coastguard Worker     case 0:
189*35238bceSAndroid Build Coastguard Worker         // Fullscreen
190*35238bceSAndroid Build Coastguard Worker         x           = 0;
191*35238bceSAndroid Build Coastguard Worker         y           = 0;
192*35238bceSAndroid Build Coastguard Worker         imageWidth  = targetWidth;
193*35238bceSAndroid Build Coastguard Worker         imageHeight = targetHeight;
194*35238bceSAndroid Build Coastguard Worker         break;
195*35238bceSAndroid Build Coastguard Worker     case 1:
196*35238bceSAndroid Build Coastguard Worker         // Upper left corner
197*35238bceSAndroid Build Coastguard Worker         x           = 0;
198*35238bceSAndroid Build Coastguard Worker         y           = 0;
199*35238bceSAndroid Build Coastguard Worker         imageWidth  = targetWidth / 2;
200*35238bceSAndroid Build Coastguard Worker         imageHeight = targetHeight / 2;
201*35238bceSAndroid Build Coastguard Worker         break;
202*35238bceSAndroid Build Coastguard Worker     case 2:
203*35238bceSAndroid Build Coastguard Worker         // Lower right corner
204*35238bceSAndroid Build Coastguard Worker         x           = targetWidth / 2;
205*35238bceSAndroid Build Coastguard Worker         y           = targetHeight / 2;
206*35238bceSAndroid Build Coastguard Worker         imageWidth  = targetWidth - x;
207*35238bceSAndroid Build Coastguard Worker         imageHeight = targetHeight - y;
208*35238bceSAndroid Build Coastguard Worker         break;
209*35238bceSAndroid Build Coastguard Worker     default:
210*35238bceSAndroid Build Coastguard Worker         x           = deRandom_getUint32(&rnd) % (targetWidth - 1);
211*35238bceSAndroid Build Coastguard Worker         y           = deRandom_getUint32(&rnd) % (targetHeight - 1);
212*35238bceSAndroid Build Coastguard Worker         imageWidth  = 1 + (deRandom_getUint32(&rnd) % (targetWidth - x - 1));
213*35238bceSAndroid Build Coastguard Worker         imageHeight = 1 + (deRandom_getUint32(&rnd) % (targetHeight - y - 1));
214*35238bceSAndroid Build Coastguard Worker         break;
215*35238bceSAndroid Build Coastguard Worker     }
216*35238bceSAndroid Build Coastguard Worker 
217*35238bceSAndroid Build Coastguard Worker     Surface resImage(imageWidth, imageHeight);
218*35238bceSAndroid Build Coastguard Worker     Surface refImage(imageWidth, imageHeight);
219*35238bceSAndroid Build Coastguard Worker     Surface diffImage(imageWidth, imageHeight);
220*35238bceSAndroid Build Coastguard Worker 
221*35238bceSAndroid Build Coastguard Worker     int r = (int)(deRandom_getUint32(&rnd) & 0xFF);
222*35238bceSAndroid Build Coastguard Worker     int g = (int)(deRandom_getUint32(&rnd) & 0xFF);
223*35238bceSAndroid Build Coastguard Worker     int b = (int)(deRandom_getUint32(&rnd) & 0xFF);
224*35238bceSAndroid Build Coastguard Worker 
225*35238bceSAndroid Build Coastguard Worker     tcu::clear(refImage.getAccess(), tcu::IVec4(r, g, b, 255));
226*35238bceSAndroid Build Coastguard Worker     glClearColor(float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, 1.0f);
227*35238bceSAndroid Build Coastguard Worker     glClear(GL_COLOR_BUFFER_BIT);
228*35238bceSAndroid Build Coastguard Worker 
229*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_context.getRenderContext(), x, y, resImage.getAccess());
230*35238bceSAndroid Build Coastguard Worker     GLU_CHECK_MSG("glReadPixels() failed.");
231*35238bceSAndroid Build Coastguard Worker 
232*35238bceSAndroid Build Coastguard Worker     RGBA colorThreshold = pixelFormat.getColorThreshold();
233*35238bceSAndroid Build Coastguard Worker     RGBA matchColor(0, 255, 0, 255);
234*35238bceSAndroid Build Coastguard Worker     RGBA diffColor(255, 0, 0, 255);
235*35238bceSAndroid Build Coastguard Worker     bool isImageOk = true;
236*35238bceSAndroid Build Coastguard Worker 
237*35238bceSAndroid Build Coastguard Worker     for (int j = 0; j < imageHeight; j++)
238*35238bceSAndroid Build Coastguard Worker     {
239*35238bceSAndroid Build Coastguard Worker         for (int i = 0; i < imageWidth; i++)
240*35238bceSAndroid Build Coastguard Worker         {
241*35238bceSAndroid Build Coastguard Worker             RGBA resRGBA   = resImage.getPixel(i, j);
242*35238bceSAndroid Build Coastguard Worker             RGBA refRGBA   = refImage.getPixel(i, j);
243*35238bceSAndroid Build Coastguard Worker             bool isPixelOk = compareThreshold(refRGBA, resRGBA, colorThreshold);
244*35238bceSAndroid Build Coastguard Worker             diffImage.setPixel(i, j, isPixelOk ? matchColor : diffColor);
245*35238bceSAndroid Build Coastguard Worker 
246*35238bceSAndroid Build Coastguard Worker             isImageOk = isImageOk && isPixelOk;
247*35238bceSAndroid Build Coastguard Worker         }
248*35238bceSAndroid Build Coastguard Worker     }
249*35238bceSAndroid Build Coastguard Worker 
250*35238bceSAndroid Build Coastguard Worker     if (isImageOk)
251*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
252*35238bceSAndroid Build Coastguard Worker     else
253*35238bceSAndroid Build Coastguard Worker     {
254*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
255*35238bceSAndroid Build Coastguard Worker 
256*35238bceSAndroid Build Coastguard Worker         TestLog &log = m_testCtx.getLog();
257*35238bceSAndroid Build Coastguard Worker         log << TestLog::ImageSet("Result", "Resulting framebuffer")
258*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Result", "Resulting framebuffer", resImage)
259*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("Reference", "Reference image", refImage)
260*35238bceSAndroid Build Coastguard Worker             << TestLog::Image("DiffMask", "Failing pixels", diffImage) << TestLog::EndImageSet;
261*35238bceSAndroid Build Coastguard Worker     }
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker     return (++m_curIter < m_numIters) ? CONTINUE : STOP;
264*35238bceSAndroid Build Coastguard Worker }
265*35238bceSAndroid Build Coastguard Worker 
PrerequisiteTests(Context & context)266*35238bceSAndroid Build Coastguard Worker PrerequisiteTests::PrerequisiteTests(Context &context)
267*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "prerequisite", "Prerequisite Test Cases")
268*35238bceSAndroid Build Coastguard Worker {
269*35238bceSAndroid Build Coastguard Worker }
270*35238bceSAndroid Build Coastguard Worker 
~PrerequisiteTests(void)271*35238bceSAndroid Build Coastguard Worker PrerequisiteTests::~PrerequisiteTests(void)
272*35238bceSAndroid Build Coastguard Worker {
273*35238bceSAndroid Build Coastguard Worker }
274*35238bceSAndroid Build Coastguard Worker 
init(void)275*35238bceSAndroid Build Coastguard Worker void PrerequisiteTests::init(void)
276*35238bceSAndroid Build Coastguard Worker {
277*35238bceSAndroid Build Coastguard Worker     addChild(new StateResetCase(m_context));
278*35238bceSAndroid Build Coastguard Worker     addChild(new ClearColorCase(m_context));
279*35238bceSAndroid Build Coastguard Worker     addChild(new ReadPixelsCase(m_context));
280*35238bceSAndroid Build Coastguard Worker }
281*35238bceSAndroid Build Coastguard Worker 
282*35238bceSAndroid Build Coastguard Worker } // namespace Functional
283*35238bceSAndroid Build Coastguard Worker } // namespace gles2
284*35238bceSAndroid Build Coastguard Worker } // namespace deqp
285