xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fShaderMetamorphicTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2017 Hugues Evrard, Imperial College London
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 Shader metamorphic tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es3fShaderMetamorphicTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsShaderRenderCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "deFilePath.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestContext.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuResource.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "gluDrawUtil.hpp"
36*35238bceSAndroid Build Coastguard Worker 
37*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
38*35238bceSAndroid Build Coastguard Worker 
39*35238bceSAndroid Build Coastguard Worker using std::vector;
40*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker namespace deqp
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace gles3
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace Functional
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker static const int MAX_RENDER_WIDTH  = 256;
50*35238bceSAndroid Build Coastguard Worker static const int MAX_RENDER_HEIGHT = 256;
51*35238bceSAndroid Build Coastguard Worker 
52*35238bceSAndroid Build Coastguard Worker typedef bool (*SanityCheckFunc)(const tcu::ConstPixelBufferAccess &);
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
55*35238bceSAndroid Build Coastguard Worker  * \brief ShaderMetamorphicVariant
56*35238bceSAndroid Build Coastguard Worker  *
57*35238bceSAndroid Build Coastguard Worker  * ShaderMetamorphicVariant aims at rendering a recipient shader and a
58*35238bceSAndroid Build Coastguard Worker  * variant shader, and compare whether the resulting images are the
59*35238bceSAndroid Build Coastguard Worker  * approximately the same. It also checks non-deterministic renderings,
60*35238bceSAndroid Build Coastguard Worker  * by rendering each fragment shader a couple of times.
61*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
62*35238bceSAndroid Build Coastguard Worker class ShaderMetamorphicVariant : public TestCase
63*35238bceSAndroid Build Coastguard Worker {
64*35238bceSAndroid Build Coastguard Worker public:
65*35238bceSAndroid Build Coastguard Worker     ShaderMetamorphicVariant(Context &context, const char *name, const std::string &vertexFilename,
66*35238bceSAndroid Build Coastguard Worker                              const std::string &recipientFilename, const std::string &variantFilename,
67*35238bceSAndroid Build Coastguard Worker                              SanityCheckFunc sanityCheck);
68*35238bceSAndroid Build Coastguard Worker     ~ShaderMetamorphicVariant(void);
69*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker private:
72*35238bceSAndroid Build Coastguard Worker     const std::string m_vertexFilename;
73*35238bceSAndroid Build Coastguard Worker     const std::string m_recipientFilename;
74*35238bceSAndroid Build Coastguard Worker     const std::string m_variantFilename;
75*35238bceSAndroid Build Coastguard Worker     SanityCheckFunc m_sanityCheck;
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker     std::string fileContents(const std::string &filename);
78*35238bceSAndroid Build Coastguard Worker     void render(const tcu::PixelBufferAccess &img, const std::string &vertexSrc, const std::string &fragmentSrc);
79*35238bceSAndroid Build Coastguard Worker     void checkNondet(const tcu::Surface &refImg, const std::string &vertexSrc, const std::string &fragmentSrc);
80*35238bceSAndroid Build Coastguard Worker };
81*35238bceSAndroid Build Coastguard Worker 
ShaderMetamorphicVariant(Context & context,const char * name,const std::string & vertexFilename,const std::string & recipientFilename,const std::string & variantFilename,SanityCheckFunc sanityCheck)82*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicVariant::ShaderMetamorphicVariant(Context &context, const char *name,
83*35238bceSAndroid Build Coastguard Worker                                                    const std::string &vertexFilename,
84*35238bceSAndroid Build Coastguard Worker                                                    const std::string &recipientFilename,
85*35238bceSAndroid Build Coastguard Worker                                                    const std::string &variantFilename, SanityCheckFunc sanityCheck)
86*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, "Test a given variant")
87*35238bceSAndroid Build Coastguard Worker     , m_vertexFilename(vertexFilename)
88*35238bceSAndroid Build Coastguard Worker     , m_recipientFilename(recipientFilename)
89*35238bceSAndroid Build Coastguard Worker     , m_variantFilename(variantFilename)
90*35238bceSAndroid Build Coastguard Worker     , m_sanityCheck(sanityCheck)
91*35238bceSAndroid Build Coastguard Worker {
92*35238bceSAndroid Build Coastguard Worker }
93*35238bceSAndroid Build Coastguard Worker 
~ShaderMetamorphicVariant(void)94*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicVariant::~ShaderMetamorphicVariant(void)
95*35238bceSAndroid Build Coastguard Worker {
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker 
fileContents(const std::string & filename)98*35238bceSAndroid Build Coastguard Worker std::string ShaderMetamorphicVariant::fileContents(const std::string &filename)
99*35238bceSAndroid Build Coastguard Worker {
100*35238bceSAndroid Build Coastguard Worker     de::UniquePtr<tcu::Resource> resource(m_testCtx.getArchive().getResource(filename.c_str()));
101*35238bceSAndroid Build Coastguard Worker     int size = resource->getSize();
102*35238bceSAndroid Build Coastguard Worker     std::vector<uint8_t> data;
103*35238bceSAndroid Build Coastguard Worker 
104*35238bceSAndroid Build Coastguard Worker     data.resize(size + 1);
105*35238bceSAndroid Build Coastguard Worker     resource->read(&data[0], size);
106*35238bceSAndroid Build Coastguard Worker     data[size]           = '\0';
107*35238bceSAndroid Build Coastguard Worker     std::string contents = std::string((const char *)(&data[0]));
108*35238bceSAndroid Build Coastguard Worker     return contents;
109*35238bceSAndroid Build Coastguard Worker }
110*35238bceSAndroid Build Coastguard Worker 
render(const tcu::PixelBufferAccess & img,const std::string & vertexSrc,const std::string & fragmentSrc)111*35238bceSAndroid Build Coastguard Worker void ShaderMetamorphicVariant::render(const tcu::PixelBufferAccess &img, const std::string &vertexSrc,
112*35238bceSAndroid Build Coastguard Worker                                       const std::string &fragmentSrc)
113*35238bceSAndroid Build Coastguard Worker {
114*35238bceSAndroid Build Coastguard Worker     TestLog &log             = m_testCtx.getLog();
115*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
116*35238bceSAndroid Build Coastguard Worker 
117*35238bceSAndroid Build Coastguard Worker     // Positions, shared between shaders
118*35238bceSAndroid Build Coastguard Worker     const float positions[] = {
119*35238bceSAndroid Build Coastguard Worker         -1.0f, 1.0f,  // top-left
120*35238bceSAndroid Build Coastguard Worker         -1.0f, -1.0f, // bottom-left
121*35238bceSAndroid Build Coastguard Worker         1.0f,  -1.0f, // bottom-right
122*35238bceSAndroid Build Coastguard Worker         1.0f,  1.0f,  // top-right
123*35238bceSAndroid Build Coastguard Worker     };
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     const uint16_t indices[] = {
126*35238bceSAndroid Build Coastguard Worker         0, 1, 2, // bottom-left triangle
127*35238bceSAndroid Build Coastguard Worker         0, 3, 2, // top-right triangle
128*35238bceSAndroid Build Coastguard Worker     };
129*35238bceSAndroid Build Coastguard Worker 
130*35238bceSAndroid Build Coastguard Worker     glu::VertexArrayBinding posBinding = glu::va::Float("coord2d", 2, 6, 0, &positions[0]);
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker     const glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexSrc, fragmentSrc));
133*35238bceSAndroid Build Coastguard Worker     log << program;
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker     if (!program.isOk())
136*35238bceSAndroid Build Coastguard Worker         throw tcu::TestError("Compile failed");
137*35238bceSAndroid Build Coastguard Worker 
138*35238bceSAndroid Build Coastguard Worker     // Set uniforms expected in GraphicsFuzz generated programs
139*35238bceSAndroid Build Coastguard Worker     gl.useProgram(program.getProgram());
140*35238bceSAndroid Build Coastguard Worker     // Uniform: injectionSwitch
141*35238bceSAndroid Build Coastguard Worker     int uniformLoc = gl.getUniformLocation(program.getProgram(), "injectionSwitch");
142*35238bceSAndroid Build Coastguard Worker     if (uniformLoc != -1)
143*35238bceSAndroid Build Coastguard Worker         gl.uniform2f(uniformLoc, 0.0f, 1.0f);
144*35238bceSAndroid Build Coastguard Worker     // Uniform: resolution
145*35238bceSAndroid Build Coastguard Worker     uniformLoc = gl.getUniformLocation(program.getProgram(), "resolution");
146*35238bceSAndroid Build Coastguard Worker     if (uniformLoc != -1)
147*35238bceSAndroid Build Coastguard Worker         gl.uniform2f(uniformLoc, glw::GLfloat(img.getWidth()), glw::GLfloat(img.getHeight()));
148*35238bceSAndroid Build Coastguard Worker     // Uniform: mouse
149*35238bceSAndroid Build Coastguard Worker     uniformLoc = gl.getUniformLocation(program.getProgram(), "mouse");
150*35238bceSAndroid Build Coastguard Worker     if (uniformLoc != -1)
151*35238bceSAndroid Build Coastguard Worker         gl.uniform2f(uniformLoc, 0.0f, 0.0f);
152*35238bceSAndroid Build Coastguard Worker     // Uniform: time
153*35238bceSAndroid Build Coastguard Worker     uniformLoc = gl.getUniformLocation(program.getProgram(), "time");
154*35238bceSAndroid Build Coastguard Worker     if (uniformLoc != -1)
155*35238bceSAndroid Build Coastguard Worker         gl.uniform1f(uniformLoc, 0.0f);
156*35238bceSAndroid Build Coastguard Worker 
157*35238bceSAndroid Build Coastguard Worker     // Render two times to check nondeterministic renderings
158*35238bceSAndroid Build Coastguard Worker     glu::draw(m_context.getRenderContext(), program.getProgram(), 1, &posBinding,
159*35238bceSAndroid Build Coastguard Worker               glu::pr::Triangles(DE_LENGTH_OF_ARRAY(indices), &indices[0]));
160*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_context.getRenderContext(), 0, 0, img);
161*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
162*35238bceSAndroid Build Coastguard Worker }
163*35238bceSAndroid Build Coastguard Worker 
checkNondet(const tcu::Surface & refImg,const std::string & vertexSrc,const std::string & fragmentSrc)164*35238bceSAndroid Build Coastguard Worker void ShaderMetamorphicVariant::checkNondet(const tcu::Surface &refImg, const std::string &vertexSrc,
165*35238bceSAndroid Build Coastguard Worker                                            const std::string &fragmentSrc)
166*35238bceSAndroid Build Coastguard Worker {
167*35238bceSAndroid Build Coastguard Worker     TestLog &log     = m_testCtx.getLog();
168*35238bceSAndroid Build Coastguard Worker     tcu::Surface img = tcu::Surface(refImg.getWidth(), refImg.getHeight());
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker     render(img.getAccess(), vertexSrc, fragmentSrc);
171*35238bceSAndroid Build Coastguard Worker     bool same = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", img, refImg, tcu::RGBA(0, 0, 0, 0),
172*35238bceSAndroid Build Coastguard Worker                                            tcu::COMPARE_LOG_RESULT);
173*35238bceSAndroid Build Coastguard Worker     if (!same)
174*35238bceSAndroid Build Coastguard Worker         throw tcu::TestError("Nondeterministic rendering");
175*35238bceSAndroid Build Coastguard Worker }
176*35238bceSAndroid Build Coastguard Worker 
iterate(void)177*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicVariant::IterateResult ShaderMetamorphicVariant::iterate(void)
178*35238bceSAndroid Build Coastguard Worker {
179*35238bceSAndroid Build Coastguard Worker     TestLog &log = m_testCtx.getLog();
180*35238bceSAndroid Build Coastguard Worker     const tcu::RGBA threshold =
181*35238bceSAndroid Build Coastguard Worker         tcu::RGBA(1, 1, 1, 1) + m_context.getRenderTarget().getPixelFormat().getColorThreshold();
182*35238bceSAndroid Build Coastguard Worker     std::string vertexSrc     = fileContents(m_vertexFilename);
183*35238bceSAndroid Build Coastguard Worker     std::string recipientSrc  = fileContents(m_recipientFilename);
184*35238bceSAndroid Build Coastguard Worker     std::string variantSrc    = fileContents(m_variantFilename);
185*35238bceSAndroid Build Coastguard Worker     const int width           = deMin32(m_context.getRenderTarget().getWidth(), MAX_RENDER_WIDTH);
186*35238bceSAndroid Build Coastguard Worker     const int height          = deMin32(m_context.getRenderTarget().getHeight(), MAX_RENDER_HEIGHT);
187*35238bceSAndroid Build Coastguard Worker     tcu::Surface recipientImg = tcu::Surface(width, height);
188*35238bceSAndroid Build Coastguard Worker     tcu::Surface variantImg   = tcu::Surface(width, height);
189*35238bceSAndroid Build Coastguard Worker 
190*35238bceSAndroid Build Coastguard Worker     render(recipientImg.getAccess(), vertexSrc, recipientSrc);
191*35238bceSAndroid Build Coastguard Worker     render(variantImg.getAccess(), vertexSrc, variantSrc);
192*35238bceSAndroid Build Coastguard Worker 
193*35238bceSAndroid Build Coastguard Worker     checkNondet(recipientImg, vertexSrc, recipientSrc);
194*35238bceSAndroid Build Coastguard Worker     checkNondet(variantImg, vertexSrc, variantSrc);
195*35238bceSAndroid Build Coastguard Worker 
196*35238bceSAndroid Build Coastguard Worker     if (m_sanityCheck != DE_NULL)
197*35238bceSAndroid Build Coastguard Worker     {
198*35238bceSAndroid Build Coastguard Worker         bool isSane = m_sanityCheck(recipientImg.getAccess());
199*35238bceSAndroid Build Coastguard Worker         if (!isSane)
200*35238bceSAndroid Build Coastguard Worker             throw tcu::TestError("Quick check fails on recipient");
201*35238bceSAndroid Build Coastguard Worker     }
202*35238bceSAndroid Build Coastguard Worker 
203*35238bceSAndroid Build Coastguard Worker     bool isOk = tcu::pixelThresholdCompare(log, "Result", "Image comparison result", recipientImg, variantImg,
204*35238bceSAndroid Build Coastguard Worker                                            threshold, tcu::COMPARE_LOG_RESULT);
205*35238bceSAndroid Build Coastguard Worker 
206*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
207*35238bceSAndroid Build Coastguard Worker                             isOk ? "Pass" : "Image comparison failed");
208*35238bceSAndroid Build Coastguard Worker 
209*35238bceSAndroid Build Coastguard Worker     return STOP;
210*35238bceSAndroid Build Coastguard Worker }
211*35238bceSAndroid Build Coastguard Worker 
212*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
213*35238bceSAndroid Build Coastguard Worker  * \brief ShaderMetamorphicShaderset
214*35238bceSAndroid Build Coastguard Worker  *
215*35238bceSAndroid Build Coastguard Worker  * ShaderMetamorphicShaderset gathers a set of ShaderMetamorphicVariant
216*35238bceSAndroid Build Coastguard Worker  * for a similar recipient.
217*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
218*35238bceSAndroid Build Coastguard Worker class ShaderMetamorphicShaderset : public TestCaseGroup
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker public:
221*35238bceSAndroid Build Coastguard Worker     ShaderMetamorphicShaderset(Context &context, const char *name, const std::string &vertexFilename,
222*35238bceSAndroid Build Coastguard Worker                                const std::string &recipientFilename, std::vector<std::string> variantFilenames,
223*35238bceSAndroid Build Coastguard Worker                                SanityCheckFunc sanityCheck);
224*35238bceSAndroid Build Coastguard Worker     ~ShaderMetamorphicShaderset(void);
225*35238bceSAndroid Build Coastguard Worker     virtual void init(void);
226*35238bceSAndroid Build Coastguard Worker 
227*35238bceSAndroid Build Coastguard Worker private:
228*35238bceSAndroid Build Coastguard Worker     const std::string m_vertexFilename;
229*35238bceSAndroid Build Coastguard Worker     const std::string m_recipientFilename;
230*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> m_variantFilenames;
231*35238bceSAndroid Build Coastguard Worker     SanityCheckFunc m_sanityCheck;
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker     ShaderMetamorphicShaderset(const ShaderMetamorphicShaderset &);            // Not allowed!
234*35238bceSAndroid Build Coastguard Worker     ShaderMetamorphicShaderset &operator=(const ShaderMetamorphicShaderset &); // Not allowed!
235*35238bceSAndroid Build Coastguard Worker };
236*35238bceSAndroid Build Coastguard Worker 
ShaderMetamorphicShaderset(Context & context,const char * name,const std::string & vertexFilename,const std::string & recipientFilename,std::vector<std::string> variantFilenames,SanityCheckFunc sanityCheck)237*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicShaderset::ShaderMetamorphicShaderset(Context &context, const char *name,
238*35238bceSAndroid Build Coastguard Worker                                                        const std::string &vertexFilename,
239*35238bceSAndroid Build Coastguard Worker                                                        const std::string &recipientFilename,
240*35238bceSAndroid Build Coastguard Worker                                                        std::vector<std::string> variantFilenames,
241*35238bceSAndroid Build Coastguard Worker                                                        SanityCheckFunc sanityCheck)
242*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, name, "Metamorphic Shader Set")
243*35238bceSAndroid Build Coastguard Worker     , m_vertexFilename(vertexFilename)
244*35238bceSAndroid Build Coastguard Worker     , m_recipientFilename(recipientFilename)
245*35238bceSAndroid Build Coastguard Worker     , m_variantFilenames(variantFilenames)
246*35238bceSAndroid Build Coastguard Worker     , m_sanityCheck(sanityCheck)
247*35238bceSAndroid Build Coastguard Worker {
248*35238bceSAndroid Build Coastguard Worker }
249*35238bceSAndroid Build Coastguard Worker 
~ShaderMetamorphicShaderset(void)250*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicShaderset::~ShaderMetamorphicShaderset(void)
251*35238bceSAndroid Build Coastguard Worker {
252*35238bceSAndroid Build Coastguard Worker }
253*35238bceSAndroid Build Coastguard Worker 
init(void)254*35238bceSAndroid Build Coastguard Worker void ShaderMetamorphicShaderset::init(void)
255*35238bceSAndroid Build Coastguard Worker {
256*35238bceSAndroid Build Coastguard Worker     for (size_t variantNdx = 0; variantNdx < m_variantFilenames.size(); variantNdx++)
257*35238bceSAndroid Build Coastguard Worker     {
258*35238bceSAndroid Build Coastguard Worker         std::string variantName = de::FilePath(m_variantFilenames[variantNdx]).getBaseName();
259*35238bceSAndroid Build Coastguard Worker         // Remove extension
260*35238bceSAndroid Build Coastguard Worker         size_t pos  = variantName.find_last_of(".");
261*35238bceSAndroid Build Coastguard Worker         variantName = variantName.substr(0, pos);
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker         addChild(new ShaderMetamorphicVariant(m_context, variantName.c_str(), m_vertexFilename, m_recipientFilename,
264*35238bceSAndroid Build Coastguard Worker                                               m_variantFilenames[variantNdx], m_sanityCheck));
265*35238bceSAndroid Build Coastguard Worker     }
266*35238bceSAndroid Build Coastguard Worker }
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
269*35238bceSAndroid Build Coastguard Worker  * \brief SanityPixel
270*35238bceSAndroid Build Coastguard Worker  *
271*35238bceSAndroid Build Coastguard Worker  * A place holder to store info on reference pixel for quick checking.
272*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
273*35238bceSAndroid Build Coastguard Worker class SanityPixel
274*35238bceSAndroid Build Coastguard Worker {
275*35238bceSAndroid Build Coastguard Worker public:
276*35238bceSAndroid Build Coastguard Worker     float m_xRelative;
277*35238bceSAndroid Build Coastguard Worker     float m_yRelative;
278*35238bceSAndroid Build Coastguard Worker     tcu::Vec4 m_RGBA;
279*35238bceSAndroid Build Coastguard Worker 
280*35238bceSAndroid Build Coastguard Worker     SanityPixel(float xRelative, float yRelative, tcu::Vec4 RGBA);
281*35238bceSAndroid Build Coastguard Worker };
282*35238bceSAndroid Build Coastguard Worker 
SanityPixel(float xRelative,float yRelative,tcu::Vec4 RGBA)283*35238bceSAndroid Build Coastguard Worker SanityPixel::SanityPixel(float xRelative, float yRelative, tcu::Vec4 RGBA)
284*35238bceSAndroid Build Coastguard Worker     : m_xRelative(xRelative)
285*35238bceSAndroid Build Coastguard Worker     , m_yRelative(yRelative)
286*35238bceSAndroid Build Coastguard Worker     , m_RGBA(RGBA)
287*35238bceSAndroid Build Coastguard Worker {
288*35238bceSAndroid Build Coastguard Worker }
289*35238bceSAndroid Build Coastguard Worker 
sanityComparePixels(const tcu::ConstPixelBufferAccess & img,std::vector<SanityPixel> sanityPixels)290*35238bceSAndroid Build Coastguard Worker static bool sanityComparePixels(const tcu::ConstPixelBufferAccess &img, std::vector<SanityPixel> sanityPixels)
291*35238bceSAndroid Build Coastguard Worker {
292*35238bceSAndroid Build Coastguard Worker     const int depth           = 0;
293*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 threshold = tcu::Vec4(0.01f, 0.01f, 0.01f, 0.01f);
294*35238bceSAndroid Build Coastguard Worker 
295*35238bceSAndroid Build Coastguard Worker     for (uint32_t i = 0; i < sanityPixels.size(); i++)
296*35238bceSAndroid Build Coastguard Worker     {
297*35238bceSAndroid Build Coastguard Worker         SanityPixel sanPix = sanityPixels[i];
298*35238bceSAndroid Build Coastguard Worker         int x              = (int)((float)img.getWidth() * sanPix.m_xRelative);
299*35238bceSAndroid Build Coastguard Worker         int y              = (int)((float)img.getHeight() * sanPix.m_yRelative);
300*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 RGBA     = img.getPixel(x, y, depth);
301*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 diff     = abs(RGBA - sanPix.m_RGBA);
302*35238bceSAndroid Build Coastguard Worker         for (int j = 0; j < 4; j++)
303*35238bceSAndroid Build Coastguard Worker             if (diff[j] >= threshold[j])
304*35238bceSAndroid Build Coastguard Worker                 return false;
305*35238bceSAndroid Build Coastguard Worker     }
306*35238bceSAndroid Build Coastguard Worker     return true;
307*35238bceSAndroid Build Coastguard Worker }
308*35238bceSAndroid Build Coastguard Worker 
sanityCheck_synthetic(const tcu::ConstPixelBufferAccess & img)309*35238bceSAndroid Build Coastguard Worker static bool sanityCheck_synthetic(const tcu::ConstPixelBufferAccess &img)
310*35238bceSAndroid Build Coastguard Worker {
311*35238bceSAndroid Build Coastguard Worker     std::vector<SanityPixel> sanityPixels;
312*35238bceSAndroid Build Coastguard Worker     bool isOK;
313*35238bceSAndroid Build Coastguard Worker 
314*35238bceSAndroid Build Coastguard Worker     sanityPixels.push_back(SanityPixel(0.5f, 0.5f, tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f)));
315*35238bceSAndroid Build Coastguard Worker 
316*35238bceSAndroid Build Coastguard Worker     isOK = sanityComparePixels(img, sanityPixels);
317*35238bceSAndroid Build Coastguard Worker     return isOK;
318*35238bceSAndroid Build Coastguard Worker }
319*35238bceSAndroid Build Coastguard Worker 
sanityCheck_bubblesort_flag(const tcu::ConstPixelBufferAccess & img)320*35238bceSAndroid Build Coastguard Worker static bool sanityCheck_bubblesort_flag(const tcu::ConstPixelBufferAccess &img)
321*35238bceSAndroid Build Coastguard Worker {
322*35238bceSAndroid Build Coastguard Worker     std::vector<SanityPixel> sanityPixels;
323*35238bceSAndroid Build Coastguard Worker     bool isOK;
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker     sanityPixels.push_back(SanityPixel(0.25f, 0.25f, tcu::Vec4(0.1f, 0.6f, 1.0f, 1.0f)));
326*35238bceSAndroid Build Coastguard Worker     sanityPixels.push_back(SanityPixel(0.25f, 0.75f, tcu::Vec4(1.0f, 0.5f, 0.1f, 1.0f)));
327*35238bceSAndroid Build Coastguard Worker     sanityPixels.push_back(SanityPixel(0.75f, 0.25f, tcu::Vec4(0.6f, 1.0f, 0.1f, 1.0f)));
328*35238bceSAndroid Build Coastguard Worker     sanityPixels.push_back(SanityPixel(0.75f, 0.75f, tcu::Vec4(0.5f, 0.1f, 1.0f, 1.0f)));
329*35238bceSAndroid Build Coastguard Worker 
330*35238bceSAndroid Build Coastguard Worker     isOK = sanityComparePixels(img, sanityPixels);
331*35238bceSAndroid Build Coastguard Worker     return isOK;
332*35238bceSAndroid Build Coastguard Worker }
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
335*35238bceSAndroid Build Coastguard Worker  * \brief ShaderMetamorphicTests
336*35238bceSAndroid Build Coastguard Worker  *
337*35238bceSAndroid Build Coastguard Worker  * ShaderMetamorphicTests regroups metamorphic shadersets.
338*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
ShaderMetamorphicTests(Context & context)339*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicTests::ShaderMetamorphicTests(Context &context)
340*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(context, "metamorphic", "Shader Metamorphic Tests")
341*35238bceSAndroid Build Coastguard Worker {
342*35238bceSAndroid Build Coastguard Worker }
343*35238bceSAndroid Build Coastguard Worker 
~ShaderMetamorphicTests(void)344*35238bceSAndroid Build Coastguard Worker ShaderMetamorphicTests::~ShaderMetamorphicTests(void)
345*35238bceSAndroid Build Coastguard Worker {
346*35238bceSAndroid Build Coastguard Worker }
347*35238bceSAndroid Build Coastguard Worker 
init(void)348*35238bceSAndroid Build Coastguard Worker void ShaderMetamorphicTests::init(void)
349*35238bceSAndroid Build Coastguard Worker {
350*35238bceSAndroid Build Coastguard Worker     std::vector<std::string> fragNames;
351*35238bceSAndroid Build Coastguard Worker     std::string vertexFilename = "graphicsfuzz/vertexShader.glsl";
352*35238bceSAndroid Build Coastguard Worker 
353*35238bceSAndroid Build Coastguard Worker     // synthetic
354*35238bceSAndroid Build Coastguard Worker     fragNames.clear();
355*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/synthetic/variant_1.frag");
356*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/synthetic/variant_2.frag");
357*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/synthetic/variant_3.frag");
358*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/synthetic/variant_4.frag");
359*35238bceSAndroid Build Coastguard Worker     addChild(new ShaderMetamorphicShaderset(m_context, "synthetic", vertexFilename,
360*35238bceSAndroid Build Coastguard Worker                                             "graphicsfuzz/synthetic/recipient.frag", fragNames, sanityCheck_synthetic));
361*35238bceSAndroid Build Coastguard Worker 
362*35238bceSAndroid Build Coastguard Worker     // bubblesort_flag
363*35238bceSAndroid Build Coastguard Worker     fragNames.clear();
364*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/bubblesort_flag/variant_1.frag");
365*35238bceSAndroid Build Coastguard Worker     fragNames.push_back("graphicsfuzz/bubblesort_flag/variant_2.frag");
366*35238bceSAndroid Build Coastguard Worker     addChild(new ShaderMetamorphicShaderset(m_context, "bubblesort_flag", vertexFilename,
367*35238bceSAndroid Build Coastguard Worker                                             "graphicsfuzz/bubblesort_flag/recipient.frag", fragNames,
368*35238bceSAndroid Build Coastguard Worker                                             sanityCheck_bubblesort_flag));
369*35238bceSAndroid Build Coastguard Worker }
370*35238bceSAndroid Build Coastguard Worker 
371*35238bceSAndroid Build Coastguard Worker } // namespace Functional
372*35238bceSAndroid Build Coastguard Worker } // namespace gles3
373*35238bceSAndroid Build Coastguard Worker } // namespace deqp
374