1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 3.1 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 Multisample interpolation tests
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es31fShaderMultisampleInterpolationTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "es31fMultisampleShaderRenderCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuRGBA.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuStringTemplate.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "deArrayUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
39*35238bceSAndroid Build Coastguard Worker
40*35238bceSAndroid Build Coastguard Worker #include <map>
41*35238bceSAndroid Build Coastguard Worker
42*35238bceSAndroid Build Coastguard Worker namespace deqp
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace gles31
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace Functional
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker namespace
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker
specializeShader(const std::string & shaderSource,const glu::ContextType & contextType)51*35238bceSAndroid Build Coastguard Worker static std::string specializeShader(const std::string &shaderSource, const glu::ContextType &contextType)
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker const bool isES32orGL45 = glu::contextSupports(contextType, glu::ApiType::es(3, 2)) ||
54*35238bceSAndroid Build Coastguard Worker glu::contextSupports(contextType, glu::ApiType::core(4, 5));
55*35238bceSAndroid Build Coastguard Worker
56*35238bceSAndroid Build Coastguard Worker std::map<std::string, std::string> args;
57*35238bceSAndroid Build Coastguard Worker args["GLSL_VERSION_DECL"] = glu::getGLSLVersionDeclaration(glu::getContextTypeGLSLVersion(contextType));
58*35238bceSAndroid Build Coastguard Worker args["GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION"] =
59*35238bceSAndroid Build Coastguard Worker isES32orGL45 ? "" : "#extension GL_OES_shader_multisample_interpolation : require\n";
60*35238bceSAndroid Build Coastguard Worker args["GLSL_EXT_SAMPLE_VARIABLES"] = isES32orGL45 ? "" : "#extension GL_OES_sample_variables : require\n";
61*35238bceSAndroid Build Coastguard Worker
62*35238bceSAndroid Build Coastguard Worker return tcu::StringTemplate(shaderSource).specialize(args);
63*35238bceSAndroid Build Coastguard Worker }
64*35238bceSAndroid Build Coastguard Worker
checkSupport(Context & ctx)65*35238bceSAndroid Build Coastguard Worker static bool checkSupport(Context &ctx)
66*35238bceSAndroid Build Coastguard Worker {
67*35238bceSAndroid Build Coastguard Worker auto ctxType = ctx.getRenderContext().getType();
68*35238bceSAndroid Build Coastguard Worker return glu::contextSupports(ctxType, glu::ApiType::es(3, 2)) ||
69*35238bceSAndroid Build Coastguard Worker glu::contextSupports(ctxType, glu::ApiType::core(4, 5));
70*35238bceSAndroid Build Coastguard Worker }
71*35238bceSAndroid Build Coastguard Worker
verifyGreenImage(const tcu::Surface & image,tcu::TestLog & log)72*35238bceSAndroid Build Coastguard Worker static bool verifyGreenImage(const tcu::Surface &image, tcu::TestLog &log)
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker bool error = false;
75*35238bceSAndroid Build Coastguard Worker
76*35238bceSAndroid Build Coastguard Worker log << tcu::TestLog::Message << "Verifying result image, expecting green." << tcu::TestLog::EndMessage;
77*35238bceSAndroid Build Coastguard Worker
78*35238bceSAndroid Build Coastguard Worker // all pixels must be green
79*35238bceSAndroid Build Coastguard Worker
80*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < image.getHeight(); ++y)
81*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < image.getWidth(); ++x)
82*35238bceSAndroid Build Coastguard Worker {
83*35238bceSAndroid Build Coastguard Worker const tcu::RGBA color = image.getPixel(x, y);
84*35238bceSAndroid Build Coastguard Worker const int greenThreshold = 8;
85*35238bceSAndroid Build Coastguard Worker
86*35238bceSAndroid Build Coastguard Worker if (color.getRed() > 0 || color.getGreen() < 255 - greenThreshold || color.getBlue() > 0)
87*35238bceSAndroid Build Coastguard Worker error = true;
88*35238bceSAndroid Build Coastguard Worker }
89*35238bceSAndroid Build Coastguard Worker
90*35238bceSAndroid Build Coastguard Worker if (error)
91*35238bceSAndroid Build Coastguard Worker log << tcu::TestLog::Image("ResultImage", "Result Image", image.getAccess()) << tcu::TestLog::Message
92*35238bceSAndroid Build Coastguard Worker << "Image verification failed." << tcu::TestLog::EndMessage;
93*35238bceSAndroid Build Coastguard Worker else
94*35238bceSAndroid Build Coastguard Worker log << tcu::TestLog::Image("ResultImage", "Result Image", image.getAccess()) << tcu::TestLog::Message
95*35238bceSAndroid Build Coastguard Worker << "Image verification passed." << tcu::TestLog::EndMessage;
96*35238bceSAndroid Build Coastguard Worker
97*35238bceSAndroid Build Coastguard Worker return !error;
98*35238bceSAndroid Build Coastguard Worker }
99*35238bceSAndroid Build Coastguard Worker
100*35238bceSAndroid Build Coastguard Worker class MultisampleShadeCountRenderCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
101*35238bceSAndroid Build Coastguard Worker {
102*35238bceSAndroid Build Coastguard Worker public:
103*35238bceSAndroid Build Coastguard Worker MultisampleShadeCountRenderCase(Context &context, const char *name, const char *description, int numSamples,
104*35238bceSAndroid Build Coastguard Worker RenderTarget target);
105*35238bceSAndroid Build Coastguard Worker virtual ~MultisampleShadeCountRenderCase(void);
106*35238bceSAndroid Build Coastguard Worker
107*35238bceSAndroid Build Coastguard Worker void init(void);
108*35238bceSAndroid Build Coastguard Worker
109*35238bceSAndroid Build Coastguard Worker private:
110*35238bceSAndroid Build Coastguard Worker enum
111*35238bceSAndroid Build Coastguard Worker {
112*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 128
113*35238bceSAndroid Build Coastguard Worker };
114*35238bceSAndroid Build Coastguard Worker
115*35238bceSAndroid Build Coastguard Worker virtual std::string getIterationDescription(int iteration) const;
116*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
117*35238bceSAndroid Build Coastguard Worker };
118*35238bceSAndroid Build Coastguard Worker
MultisampleShadeCountRenderCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target)119*35238bceSAndroid Build Coastguard Worker MultisampleShadeCountRenderCase::MultisampleShadeCountRenderCase(Context &context, const char *name,
120*35238bceSAndroid Build Coastguard Worker const char *description, int numSamples,
121*35238bceSAndroid Build Coastguard Worker RenderTarget target)
122*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(
123*35238bceSAndroid Build Coastguard Worker context, name, description, numSamples, target, RENDER_SIZE,
124*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::FLAG_PER_ITERATION_SHADER)
125*35238bceSAndroid Build Coastguard Worker {
126*35238bceSAndroid Build Coastguard Worker m_numIterations = -1; // must be set by deriving class
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker
~MultisampleShadeCountRenderCase(void)129*35238bceSAndroid Build Coastguard Worker MultisampleShadeCountRenderCase::~MultisampleShadeCountRenderCase(void)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker }
132*35238bceSAndroid Build Coastguard Worker
init(void)133*35238bceSAndroid Build Coastguard Worker void MultisampleShadeCountRenderCase::init(void)
134*35238bceSAndroid Build Coastguard Worker {
135*35238bceSAndroid Build Coastguard Worker // requirements
136*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
137*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
138*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
139*35238bceSAndroid Build Coastguard Worker
140*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
141*35238bceSAndroid Build Coastguard Worker }
142*35238bceSAndroid Build Coastguard Worker
getIterationDescription(int iteration) const143*35238bceSAndroid Build Coastguard Worker std::string MultisampleShadeCountRenderCase::getIterationDescription(int iteration) const
144*35238bceSAndroid Build Coastguard Worker {
145*35238bceSAndroid Build Coastguard Worker // must be overriden
146*35238bceSAndroid Build Coastguard Worker DE_UNREF(iteration);
147*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
148*35238bceSAndroid Build Coastguard Worker return "";
149*35238bceSAndroid Build Coastguard Worker }
150*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)151*35238bceSAndroid Build Coastguard Worker bool MultisampleShadeCountRenderCase::verifyImage(const tcu::Surface &resultImage)
152*35238bceSAndroid Build Coastguard Worker {
153*35238bceSAndroid Build Coastguard Worker const bool isSingleSampleTarget =
154*35238bceSAndroid Build Coastguard Worker (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) ||
155*35238bceSAndroid Build Coastguard Worker (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);
156*35238bceSAndroid Build Coastguard Worker const int numShadesRequired = (isSingleSampleTarget) ? (2) : (m_numTargetSamples + 1);
157*35238bceSAndroid Build Coastguard Worker const int rareThreshold = 100;
158*35238bceSAndroid Build Coastguard Worker int rareCount = 0;
159*35238bceSAndroid Build Coastguard Worker std::map<uint32_t, int> shadeFrequency;
160*35238bceSAndroid Build Coastguard Worker
161*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Image("ResultImage", "Result Image", resultImage.getAccess())
162*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message << "Verifying image has (at least) " << numShadesRequired
163*35238bceSAndroid Build Coastguard Worker << " different shades.\n"
164*35238bceSAndroid Build Coastguard Worker << "Excluding pixels with no full coverage (pixels on the shared edge of the triangle pair)."
165*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
166*35238bceSAndroid Build Coastguard Worker
167*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < RENDER_SIZE; ++y)
168*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < RENDER_SIZE; ++x)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker const tcu::RGBA color = resultImage.getPixel(x, y);
171*35238bceSAndroid Build Coastguard Worker const uint32_t packed =
172*35238bceSAndroid Build Coastguard Worker ((uint32_t)color.getRed()) + ((uint32_t)color.getGreen() << 8) + ((uint32_t)color.getGreen() << 16);
173*35238bceSAndroid Build Coastguard Worker
174*35238bceSAndroid Build Coastguard Worker // on the triangle edge, skip
175*35238bceSAndroid Build Coastguard Worker if (x == y)
176*35238bceSAndroid Build Coastguard Worker continue;
177*35238bceSAndroid Build Coastguard Worker
178*35238bceSAndroid Build Coastguard Worker if (shadeFrequency.find(packed) == shadeFrequency.end())
179*35238bceSAndroid Build Coastguard Worker shadeFrequency[packed] = 1;
180*35238bceSAndroid Build Coastguard Worker else
181*35238bceSAndroid Build Coastguard Worker shadeFrequency[packed] = shadeFrequency[packed] + 1;
182*35238bceSAndroid Build Coastguard Worker }
183*35238bceSAndroid Build Coastguard Worker
184*35238bceSAndroid Build Coastguard Worker for (std::map<uint32_t, int>::const_iterator it = shadeFrequency.begin(); it != shadeFrequency.end(); ++it)
185*35238bceSAndroid Build Coastguard Worker if (it->second < rareThreshold)
186*35238bceSAndroid Build Coastguard Worker rareCount++;
187*35238bceSAndroid Build Coastguard Worker
188*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Found " << (int)shadeFrequency.size() << " different shades.\n"
189*35238bceSAndroid Build Coastguard Worker << "\tRare (less than " << rareThreshold << " pixels): " << rareCount << "\n"
190*35238bceSAndroid Build Coastguard Worker << "\tCommon: " << (int)shadeFrequency.size() - rareCount << "\n"
191*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
192*35238bceSAndroid Build Coastguard Worker
193*35238bceSAndroid Build Coastguard Worker if ((int)shadeFrequency.size() < numShadesRequired)
194*35238bceSAndroid Build Coastguard Worker {
195*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed." << tcu::TestLog::EndMessage;
196*35238bceSAndroid Build Coastguard Worker return false;
197*35238bceSAndroid Build Coastguard Worker }
198*35238bceSAndroid Build Coastguard Worker return true;
199*35238bceSAndroid Build Coastguard Worker }
200*35238bceSAndroid Build Coastguard Worker
201*35238bceSAndroid Build Coastguard Worker class SampleQualifierRenderCase : public MultisampleShadeCountRenderCase
202*35238bceSAndroid Build Coastguard Worker {
203*35238bceSAndroid Build Coastguard Worker public:
204*35238bceSAndroid Build Coastguard Worker SampleQualifierRenderCase(Context &context, const char *name, const char *description, int numSamples,
205*35238bceSAndroid Build Coastguard Worker RenderTarget target);
206*35238bceSAndroid Build Coastguard Worker ~SampleQualifierRenderCase(void);
207*35238bceSAndroid Build Coastguard Worker
208*35238bceSAndroid Build Coastguard Worker void init(void);
209*35238bceSAndroid Build Coastguard Worker
210*35238bceSAndroid Build Coastguard Worker private:
211*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
212*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
213*35238bceSAndroid Build Coastguard Worker std::string getIterationDescription(int iteration) const;
214*35238bceSAndroid Build Coastguard Worker };
215*35238bceSAndroid Build Coastguard Worker
SampleQualifierRenderCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target)216*35238bceSAndroid Build Coastguard Worker SampleQualifierRenderCase::SampleQualifierRenderCase(Context &context, const char *name, const char *description,
217*35238bceSAndroid Build Coastguard Worker int numSamples, RenderTarget target)
218*35238bceSAndroid Build Coastguard Worker : MultisampleShadeCountRenderCase(context, name, description, numSamples, target)
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker m_numIterations = 6; // float, vec2, .3, .4, array, struct
221*35238bceSAndroid Build Coastguard Worker }
222*35238bceSAndroid Build Coastguard Worker
~SampleQualifierRenderCase(void)223*35238bceSAndroid Build Coastguard Worker SampleQualifierRenderCase::~SampleQualifierRenderCase(void)
224*35238bceSAndroid Build Coastguard Worker {
225*35238bceSAndroid Build Coastguard Worker }
226*35238bceSAndroid Build Coastguard Worker
init(void)227*35238bceSAndroid Build Coastguard Worker void SampleQualifierRenderCase::init(void)
228*35238bceSAndroid Build Coastguard Worker {
229*35238bceSAndroid Build Coastguard Worker const bool isSingleSampleTarget =
230*35238bceSAndroid Build Coastguard Worker (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) ||
231*35238bceSAndroid Build Coastguard Worker (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);
232*35238bceSAndroid Build Coastguard Worker
233*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
234*35238bceSAndroid Build Coastguard Worker if (isSingleSampleTarget)
235*35238bceSAndroid Build Coastguard Worker {
236*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
237*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
238*35238bceSAndroid Build Coastguard Worker << "Verifying that a sample-qualified varying is given different values for different samples.\n"
239*35238bceSAndroid Build Coastguard Worker << " Render high-frequency function, map result to black/white.\n"
240*35238bceSAndroid Build Coastguard Worker << " => Resulting image image should contain both black and white pixels.\n"
241*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
242*35238bceSAndroid Build Coastguard Worker }
243*35238bceSAndroid Build Coastguard Worker else
244*35238bceSAndroid Build Coastguard Worker {
245*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
246*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
247*35238bceSAndroid Build Coastguard Worker << "Verifying that a sample-qualified varying is given different values for different samples.\n"
248*35238bceSAndroid Build Coastguard Worker << " Render high-frequency function, map result to black/white.\n"
249*35238bceSAndroid Build Coastguard Worker << " => Resulting image should contain n+1 shades of gray, n = sample count.\n"
250*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
251*35238bceSAndroid Build Coastguard Worker }
252*35238bceSAndroid Build Coastguard Worker
253*35238bceSAndroid Build Coastguard Worker MultisampleShadeCountRenderCase::init();
254*35238bceSAndroid Build Coastguard Worker }
255*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const256*35238bceSAndroid Build Coastguard Worker std::string SampleQualifierRenderCase::genVertexSource(int numTargetSamples) const
257*35238bceSAndroid Build Coastguard Worker {
258*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
259*35238bceSAndroid Build Coastguard Worker
260*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
261*35238bceSAndroid Build Coastguard Worker
262*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
263*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
264*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n";
265*35238bceSAndroid Build Coastguard Worker
266*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
267*35238bceSAndroid Build Coastguard Worker buf << "sample out highp float v_input;\n";
268*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
269*35238bceSAndroid Build Coastguard Worker buf << "sample out highp vec2 v_input;\n";
270*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
271*35238bceSAndroid Build Coastguard Worker buf << "sample out highp vec3 v_input;\n";
272*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
273*35238bceSAndroid Build Coastguard Worker buf << "sample out highp vec4 v_input;\n";
274*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
275*35238bceSAndroid Build Coastguard Worker buf << "sample out highp float[2] v_input;\n";
276*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 5)
277*35238bceSAndroid Build Coastguard Worker buf << "struct VaryingStruct { highp float a; highp float b; };\n"
278*35238bceSAndroid Build Coastguard Worker "sample out VaryingStruct v_input;\n";
279*35238bceSAndroid Build Coastguard Worker else
280*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
281*35238bceSAndroid Build Coastguard Worker
282*35238bceSAndroid Build Coastguard Worker buf << "void main (void)\n"
283*35238bceSAndroid Build Coastguard Worker "{\n"
284*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n";
285*35238bceSAndroid Build Coastguard Worker
286*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
287*35238bceSAndroid Build Coastguard Worker buf << " v_input = a_position.x + exp(a_position.y) + step(0.9, a_position.x)*step(a_position.y, "
288*35238bceSAndroid Build Coastguard Worker "-0.9)*8.0;\n";
289*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
290*35238bceSAndroid Build Coastguard Worker buf << " v_input = a_position.xy;\n";
291*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
292*35238bceSAndroid Build Coastguard Worker buf << " v_input = vec3(a_position.xy, a_position.x * 2.0 - a_position.y);\n";
293*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
294*35238bceSAndroid Build Coastguard Worker buf << " v_input = vec4(a_position.xy, a_position.x * 2.0 - a_position.y, a_position.x*a_position.y);\n";
295*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
296*35238bceSAndroid Build Coastguard Worker buf << " v_input[0] = a_position.x;\n"
297*35238bceSAndroid Build Coastguard Worker " v_input[1] = a_position.y;\n";
298*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 5)
299*35238bceSAndroid Build Coastguard Worker buf << " v_input.a = a_position.x;\n"
300*35238bceSAndroid Build Coastguard Worker " v_input.b = a_position.y;\n";
301*35238bceSAndroid Build Coastguard Worker else
302*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
303*35238bceSAndroid Build Coastguard Worker
304*35238bceSAndroid Build Coastguard Worker buf << "}";
305*35238bceSAndroid Build Coastguard Worker
306*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
307*35238bceSAndroid Build Coastguard Worker }
308*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const309*35238bceSAndroid Build Coastguard Worker std::string SampleQualifierRenderCase::genFragmentSource(int numTargetSamples) const
310*35238bceSAndroid Build Coastguard Worker {
311*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
314*35238bceSAndroid Build Coastguard Worker
315*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
316*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}";
317*35238bceSAndroid Build Coastguard Worker
318*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
319*35238bceSAndroid Build Coastguard Worker buf << "sample in highp float v_input;\n";
320*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
321*35238bceSAndroid Build Coastguard Worker buf << "sample in highp vec2 v_input;\n";
322*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
323*35238bceSAndroid Build Coastguard Worker buf << "sample in highp vec3 v_input;\n";
324*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
325*35238bceSAndroid Build Coastguard Worker buf << "sample in highp vec4 v_input;\n";
326*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
327*35238bceSAndroid Build Coastguard Worker buf << "sample in highp float[2] v_input;\n";
328*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 5)
329*35238bceSAndroid Build Coastguard Worker buf << "struct VaryingStruct { highp float a; highp float b; };\n"
330*35238bceSAndroid Build Coastguard Worker "sample in VaryingStruct v_input;\n";
331*35238bceSAndroid Build Coastguard Worker else
332*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
333*35238bceSAndroid Build Coastguard Worker
334*35238bceSAndroid Build Coastguard Worker buf << "layout(location = 0) out mediump vec4 fragColor;\n"
335*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
336*35238bceSAndroid Build Coastguard Worker "{\n";
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
339*35238bceSAndroid Build Coastguard Worker buf << " highp float field = exp(v_input) + v_input*v_input;\n";
340*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
341*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(v_input.xy, v_input.xy) + dot(21.0 * v_input.xx, sin(3.1 * v_input.xy));\n";
342*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
343*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(v_input.xy, v_input.xy) + dot(21.0 * v_input.zx, sin(3.1 * v_input.zy));\n";
344*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
345*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(v_input.xy, v_input.zw) + dot(21.0 * v_input.zy, sin(3.1 * v_input.zw));\n";
346*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
347*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(vec2(v_input[0], v_input[1]), vec2(v_input[0], v_input[1])) + dot(21.0 * "
348*35238bceSAndroid Build Coastguard Worker "vec2(v_input[0]), sin(3.1 * vec2(v_input[0], v_input[1])));\n";
349*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 5)
350*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(vec2(v_input.a, v_input.b), vec2(v_input.a, v_input.b)) + dot(21.0 * "
351*35238bceSAndroid Build Coastguard Worker "vec2(v_input.a), sin(3.1 * vec2(v_input.a, v_input.b)));\n";
352*35238bceSAndroid Build Coastguard Worker else
353*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
354*35238bceSAndroid Build Coastguard Worker
355*35238bceSAndroid Build Coastguard Worker buf << " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
356*35238bceSAndroid Build Coastguard Worker "\n"
357*35238bceSAndroid Build Coastguard Worker " if (fract(field) > 0.5)\n"
358*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
359*35238bceSAndroid Build Coastguard Worker "}";
360*35238bceSAndroid Build Coastguard Worker
361*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
362*35238bceSAndroid Build Coastguard Worker }
363*35238bceSAndroid Build Coastguard Worker
getIterationDescription(int iteration) const364*35238bceSAndroid Build Coastguard Worker std::string SampleQualifierRenderCase::getIterationDescription(int iteration) const
365*35238bceSAndroid Build Coastguard Worker {
366*35238bceSAndroid Build Coastguard Worker if (iteration == 0)
367*35238bceSAndroid Build Coastguard Worker return "Test with float varying";
368*35238bceSAndroid Build Coastguard Worker else if (iteration == 1)
369*35238bceSAndroid Build Coastguard Worker return "Test with vec2 varying";
370*35238bceSAndroid Build Coastguard Worker else if (iteration == 2)
371*35238bceSAndroid Build Coastguard Worker return "Test with vec3 varying";
372*35238bceSAndroid Build Coastguard Worker else if (iteration == 3)
373*35238bceSAndroid Build Coastguard Worker return "Test with vec4 varying";
374*35238bceSAndroid Build Coastguard Worker else if (iteration == 4)
375*35238bceSAndroid Build Coastguard Worker return "Test with array varying";
376*35238bceSAndroid Build Coastguard Worker else if (iteration == 5)
377*35238bceSAndroid Build Coastguard Worker return "Test with struct varying";
378*35238bceSAndroid Build Coastguard Worker
379*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
380*35238bceSAndroid Build Coastguard Worker return "";
381*35238bceSAndroid Build Coastguard Worker }
382*35238bceSAndroid Build Coastguard Worker
383*35238bceSAndroid Build Coastguard Worker class InterpolateAtSampleRenderCase : public MultisampleShadeCountRenderCase
384*35238bceSAndroid Build Coastguard Worker {
385*35238bceSAndroid Build Coastguard Worker public:
386*35238bceSAndroid Build Coastguard Worker enum IndexingMode
387*35238bceSAndroid Build Coastguard Worker {
388*35238bceSAndroid Build Coastguard Worker INDEXING_STATIC,
389*35238bceSAndroid Build Coastguard Worker INDEXING_DYNAMIC,
390*35238bceSAndroid Build Coastguard Worker
391*35238bceSAndroid Build Coastguard Worker INDEXING_LAST
392*35238bceSAndroid Build Coastguard Worker };
393*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleRenderCase(Context &context, const char *name, const char *description, int numSamples,
394*35238bceSAndroid Build Coastguard Worker RenderTarget target, IndexingMode mode);
395*35238bceSAndroid Build Coastguard Worker ~InterpolateAtSampleRenderCase(void);
396*35238bceSAndroid Build Coastguard Worker
397*35238bceSAndroid Build Coastguard Worker void init(void);
398*35238bceSAndroid Build Coastguard Worker void preDraw(void);
399*35238bceSAndroid Build Coastguard Worker
400*35238bceSAndroid Build Coastguard Worker private:
401*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
402*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
403*35238bceSAndroid Build Coastguard Worker std::string getIterationDescription(int iteration) const;
404*35238bceSAndroid Build Coastguard Worker
405*35238bceSAndroid Build Coastguard Worker const IndexingMode m_indexMode;
406*35238bceSAndroid Build Coastguard Worker };
407*35238bceSAndroid Build Coastguard Worker
InterpolateAtSampleRenderCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target,IndexingMode mode)408*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleRenderCase::InterpolateAtSampleRenderCase(Context &context, const char *name,
409*35238bceSAndroid Build Coastguard Worker const char *description, int numSamples,
410*35238bceSAndroid Build Coastguard Worker RenderTarget target, IndexingMode mode)
411*35238bceSAndroid Build Coastguard Worker : MultisampleShadeCountRenderCase(context, name, description, numSamples, target)
412*35238bceSAndroid Build Coastguard Worker , m_indexMode(mode)
413*35238bceSAndroid Build Coastguard Worker {
414*35238bceSAndroid Build Coastguard Worker DE_ASSERT(mode < INDEXING_LAST);
415*35238bceSAndroid Build Coastguard Worker
416*35238bceSAndroid Build Coastguard Worker m_numIterations = 5; // float, vec2, .3, .4, array
417*35238bceSAndroid Build Coastguard Worker }
418*35238bceSAndroid Build Coastguard Worker
~InterpolateAtSampleRenderCase(void)419*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleRenderCase::~InterpolateAtSampleRenderCase(void)
420*35238bceSAndroid Build Coastguard Worker {
421*35238bceSAndroid Build Coastguard Worker }
422*35238bceSAndroid Build Coastguard Worker
init(void)423*35238bceSAndroid Build Coastguard Worker void InterpolateAtSampleRenderCase::init(void)
424*35238bceSAndroid Build Coastguard Worker {
425*35238bceSAndroid Build Coastguard Worker const bool isSingleSampleTarget =
426*35238bceSAndroid Build Coastguard Worker (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) ||
427*35238bceSAndroid Build Coastguard Worker (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);
428*35238bceSAndroid Build Coastguard Worker
429*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
430*35238bceSAndroid Build Coastguard Worker if (isSingleSampleTarget)
431*35238bceSAndroid Build Coastguard Worker {
432*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
433*35238bceSAndroid Build Coastguard Worker << "Verifying that a interpolateAtSample returns different values for different samples.\n"
434*35238bceSAndroid Build Coastguard Worker << " Render high-frequency function, map result to black/white.\n"
435*35238bceSAndroid Build Coastguard Worker << " => Resulting image image should contain both black and white pixels.\n"
436*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
437*35238bceSAndroid Build Coastguard Worker }
438*35238bceSAndroid Build Coastguard Worker else
439*35238bceSAndroid Build Coastguard Worker {
440*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
441*35238bceSAndroid Build Coastguard Worker << "Verifying that a interpolateAtSample returns different values for different samples.\n"
442*35238bceSAndroid Build Coastguard Worker << " Render high-frequency function, map result to black/white.\n"
443*35238bceSAndroid Build Coastguard Worker << " => Resulting image should contain n+1 shades of gray, n = sample count.\n"
444*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
445*35238bceSAndroid Build Coastguard Worker }
446*35238bceSAndroid Build Coastguard Worker
447*35238bceSAndroid Build Coastguard Worker MultisampleShadeCountRenderCase::init();
448*35238bceSAndroid Build Coastguard Worker }
449*35238bceSAndroid Build Coastguard Worker
preDraw(void)450*35238bceSAndroid Build Coastguard Worker void InterpolateAtSampleRenderCase::preDraw(void)
451*35238bceSAndroid Build Coastguard Worker {
452*35238bceSAndroid Build Coastguard Worker if (m_indexMode == INDEXING_DYNAMIC)
453*35238bceSAndroid Build Coastguard Worker {
454*35238bceSAndroid Build Coastguard Worker const int32_t range = m_numTargetSamples;
455*35238bceSAndroid Build Coastguard Worker const int32_t offset = 1;
456*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
457*35238bceSAndroid Build Coastguard Worker const int32_t offsetLoc = gl.getUniformLocation(m_program->getProgram(), "u_offset");
458*35238bceSAndroid Build Coastguard Worker const int32_t rangeLoc = gl.getUniformLocation(m_program->getProgram(), "u_range");
459*35238bceSAndroid Build Coastguard Worker
460*35238bceSAndroid Build Coastguard Worker if (offsetLoc == -1)
461*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Location of u_offset was -1");
462*35238bceSAndroid Build Coastguard Worker if (rangeLoc == -1)
463*35238bceSAndroid Build Coastguard Worker throw tcu::TestError("Location of u_range was -1");
464*35238bceSAndroid Build Coastguard Worker
465*35238bceSAndroid Build Coastguard Worker gl.uniform1i(offsetLoc, 0);
466*35238bceSAndroid Build Coastguard Worker gl.uniform1i(rangeLoc, m_numTargetSamples);
467*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "set uniforms");
468*35238bceSAndroid Build Coastguard Worker
469*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Set u_offset = " << offset << "\n"
470*35238bceSAndroid Build Coastguard Worker << "Set u_range = " << range << tcu::TestLog::EndMessage;
471*35238bceSAndroid Build Coastguard Worker }
472*35238bceSAndroid Build Coastguard Worker }
473*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const474*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSampleRenderCase::genVertexSource(int numTargetSamples) const
475*35238bceSAndroid Build Coastguard Worker {
476*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
477*35238bceSAndroid Build Coastguard Worker
478*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
479*35238bceSAndroid Build Coastguard Worker
480*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
481*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n";
482*35238bceSAndroid Build Coastguard Worker
483*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
484*35238bceSAndroid Build Coastguard Worker buf << "out highp float v_input;\n";
485*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
486*35238bceSAndroid Build Coastguard Worker buf << "out highp vec2 v_input;\n";
487*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
488*35238bceSAndroid Build Coastguard Worker buf << "out highp vec3 v_input;\n";
489*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
490*35238bceSAndroid Build Coastguard Worker buf << "out highp vec4 v_input;\n";
491*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
492*35238bceSAndroid Build Coastguard Worker buf << "out highp vec2[2] v_input;\n";
493*35238bceSAndroid Build Coastguard Worker else
494*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
495*35238bceSAndroid Build Coastguard Worker
496*35238bceSAndroid Build Coastguard Worker buf << "void main (void)\n"
497*35238bceSAndroid Build Coastguard Worker "{\n"
498*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n";
499*35238bceSAndroid Build Coastguard Worker
500*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
501*35238bceSAndroid Build Coastguard Worker buf << " v_input = a_position.x + exp(a_position.y) + step(0.9, a_position.x)*step(a_position.y, "
502*35238bceSAndroid Build Coastguard Worker "-0.9)*8.0;\n";
503*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
504*35238bceSAndroid Build Coastguard Worker buf << " v_input = a_position.xy;\n";
505*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
506*35238bceSAndroid Build Coastguard Worker buf << " v_input = vec3(a_position.xy, a_position.x * 2.0 - a_position.y);\n";
507*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
508*35238bceSAndroid Build Coastguard Worker buf << " v_input = vec4(a_position.xy, a_position.x * 2.0 - a_position.y, a_position.x*a_position.y);\n";
509*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
510*35238bceSAndroid Build Coastguard Worker buf << " v_input[0] = a_position.yx + vec2(0.5, 0.5);\n"
511*35238bceSAndroid Build Coastguard Worker " v_input[1] = a_position.xy;\n";
512*35238bceSAndroid Build Coastguard Worker else
513*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
514*35238bceSAndroid Build Coastguard Worker
515*35238bceSAndroid Build Coastguard Worker buf << "}";
516*35238bceSAndroid Build Coastguard Worker
517*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
518*35238bceSAndroid Build Coastguard Worker }
519*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const520*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSampleRenderCase::genFragmentSource(int numTargetSamples) const
521*35238bceSAndroid Build Coastguard Worker {
522*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
523*35238bceSAndroid Build Coastguard Worker
524*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
525*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}";
526*35238bceSAndroid Build Coastguard Worker
527*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
528*35238bceSAndroid Build Coastguard Worker buf << "in highp float v_input;\n";
529*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
530*35238bceSAndroid Build Coastguard Worker buf << "in highp vec2 v_input;\n";
531*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
532*35238bceSAndroid Build Coastguard Worker buf << "in highp vec3 v_input;\n";
533*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
534*35238bceSAndroid Build Coastguard Worker buf << "in highp vec4 v_input;\n";
535*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
536*35238bceSAndroid Build Coastguard Worker buf << "in highp vec2[2] v_input;\n";
537*35238bceSAndroid Build Coastguard Worker else
538*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
539*35238bceSAndroid Build Coastguard Worker
540*35238bceSAndroid Build Coastguard Worker buf << "layout(location = 0) out mediump vec4 fragColor;\n";
541*35238bceSAndroid Build Coastguard Worker
542*35238bceSAndroid Build Coastguard Worker if (m_indexMode == INDEXING_DYNAMIC)
543*35238bceSAndroid Build Coastguard Worker buf << "uniform highp int u_offset;\n"
544*35238bceSAndroid Build Coastguard Worker "uniform highp int u_range;\n";
545*35238bceSAndroid Build Coastguard Worker
546*35238bceSAndroid Build Coastguard Worker buf << "void main (void)\n"
547*35238bceSAndroid Build Coastguard Worker "{\n"
548*35238bceSAndroid Build Coastguard Worker " mediump int coverage = 0;\n"
549*35238bceSAndroid Build Coastguard Worker "\n";
550*35238bceSAndroid Build Coastguard Worker
551*35238bceSAndroid Build Coastguard Worker if (m_indexMode == INDEXING_STATIC)
552*35238bceSAndroid Build Coastguard Worker {
553*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numTargetSamples; ++ndx)
554*35238bceSAndroid Build Coastguard Worker {
555*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
556*35238bceSAndroid Build Coastguard Worker buf << " highp float sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
557*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
558*35238bceSAndroid Build Coastguard Worker buf << " highp vec2 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
559*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
560*35238bceSAndroid Build Coastguard Worker buf << " highp vec3 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
561*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
562*35238bceSAndroid Build Coastguard Worker buf << " highp vec4 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
563*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
564*35238bceSAndroid Build Coastguard Worker buf << " highp vec2 sampleInput" << ndx << " = interpolateAtSample(v_input[1], " << ndx << ");\n";
565*35238bceSAndroid Build Coastguard Worker else
566*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
567*35238bceSAndroid Build Coastguard Worker }
568*35238bceSAndroid Build Coastguard Worker buf << "\n";
569*35238bceSAndroid Build Coastguard Worker
570*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numTargetSamples; ++ndx)
571*35238bceSAndroid Build Coastguard Worker {
572*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
573*35238bceSAndroid Build Coastguard Worker buf << " highp float field" << ndx << " = exp(sampleInput" << ndx << ") + sampleInput" << ndx
574*35238bceSAndroid Build Coastguard Worker << "*sampleInput" << ndx << ";\n";
575*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1 || m_iteration == 4)
576*35238bceSAndroid Build Coastguard Worker buf << " highp float field" << ndx << " = dot(sampleInput" << ndx << ", sampleInput" << ndx
577*35238bceSAndroid Build Coastguard Worker << ") + dot(21.0 * sampleInput" << ndx << ".xx, sin(3.1 * sampleInput" << ndx << "));\n";
578*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
579*35238bceSAndroid Build Coastguard Worker buf << " highp float field" << ndx << " = dot(sampleInput" << ndx << ".xy, sampleInput" << ndx
580*35238bceSAndroid Build Coastguard Worker << ".xy) + dot(21.0 * sampleInput" << ndx << ".zx, sin(3.1 * sampleInput" << ndx << ".zy));\n";
581*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
582*35238bceSAndroid Build Coastguard Worker buf << " highp float field" << ndx << " = dot(sampleInput" << ndx << ".xy, sampleInput" << ndx
583*35238bceSAndroid Build Coastguard Worker << ".zw) + dot(21.0 * sampleInput" << ndx << ".zy, sin(3.1 * sampleInput" << ndx << ".zw));\n";
584*35238bceSAndroid Build Coastguard Worker else
585*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
586*35238bceSAndroid Build Coastguard Worker }
587*35238bceSAndroid Build Coastguard Worker buf << "\n";
588*35238bceSAndroid Build Coastguard Worker
589*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numTargetSamples; ++ndx)
590*35238bceSAndroid Build Coastguard Worker buf << " if (fract(field" << ndx
591*35238bceSAndroid Build Coastguard Worker << ") <= 0.5)\n"
592*35238bceSAndroid Build Coastguard Worker " ++coverage;\n";
593*35238bceSAndroid Build Coastguard Worker }
594*35238bceSAndroid Build Coastguard Worker else if (m_indexMode == INDEXING_DYNAMIC)
595*35238bceSAndroid Build Coastguard Worker {
596*35238bceSAndroid Build Coastguard Worker buf << " for (int ndx = 0; ndx < " << numTargetSamples
597*35238bceSAndroid Build Coastguard Worker << "; ++ndx)\n"
598*35238bceSAndroid Build Coastguard Worker " {\n";
599*35238bceSAndroid Build Coastguard Worker
600*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
601*35238bceSAndroid Build Coastguard Worker buf << " highp float sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
602*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1)
603*35238bceSAndroid Build Coastguard Worker buf << " highp vec2 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
604*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
605*35238bceSAndroid Build Coastguard Worker buf << " highp vec3 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
606*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
607*35238bceSAndroid Build Coastguard Worker buf << " highp vec4 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
608*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 4)
609*35238bceSAndroid Build Coastguard Worker buf << " highp vec2 sampleInput = interpolateAtSample(v_input[1], (u_offset + ndx) % u_range);\n";
610*35238bceSAndroid Build Coastguard Worker else
611*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
612*35238bceSAndroid Build Coastguard Worker
613*35238bceSAndroid Build Coastguard Worker if (m_iteration == 0)
614*35238bceSAndroid Build Coastguard Worker buf << " highp float field = exp(sampleInput) + sampleInput*sampleInput;\n";
615*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 1 || m_iteration == 4)
616*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(sampleInput, sampleInput) + dot(21.0 * sampleInput.xx, sin(3.1 * "
617*35238bceSAndroid Build Coastguard Worker "sampleInput));\n";
618*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 2)
619*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(sampleInput.xy, sampleInput.xy) + dot(21.0 * sampleInput.zx, "
620*35238bceSAndroid Build Coastguard Worker "sin(3.1 * sampleInput.zy));\n";
621*35238bceSAndroid Build Coastguard Worker else if (m_iteration == 3)
622*35238bceSAndroid Build Coastguard Worker buf << " highp float field = dot(sampleInput.xy, sampleInput.zw) + dot(21.0 * sampleInput.zy, "
623*35238bceSAndroid Build Coastguard Worker "sin(3.1 * sampleInput.zw));\n";
624*35238bceSAndroid Build Coastguard Worker else
625*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
626*35238bceSAndroid Build Coastguard Worker
627*35238bceSAndroid Build Coastguard Worker buf << " if (fract(field) <= 0.5)\n"
628*35238bceSAndroid Build Coastguard Worker " ++coverage;\n"
629*35238bceSAndroid Build Coastguard Worker " }\n";
630*35238bceSAndroid Build Coastguard Worker }
631*35238bceSAndroid Build Coastguard Worker
632*35238bceSAndroid Build Coastguard Worker buf << " fragColor = vec4(vec3(float(coverage) / float(" << numTargetSamples
633*35238bceSAndroid Build Coastguard Worker << ")), 1.0);\n"
634*35238bceSAndroid Build Coastguard Worker "}";
635*35238bceSAndroid Build Coastguard Worker
636*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
637*35238bceSAndroid Build Coastguard Worker }
638*35238bceSAndroid Build Coastguard Worker
getIterationDescription(int iteration) const639*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSampleRenderCase::getIterationDescription(int iteration) const
640*35238bceSAndroid Build Coastguard Worker {
641*35238bceSAndroid Build Coastguard Worker if (iteration == 0)
642*35238bceSAndroid Build Coastguard Worker return "Test with float varying";
643*35238bceSAndroid Build Coastguard Worker else if (iteration < 4)
644*35238bceSAndroid Build Coastguard Worker return "Test with vec" + de::toString(iteration + 1) + " varying";
645*35238bceSAndroid Build Coastguard Worker else if (iteration == 4)
646*35238bceSAndroid Build Coastguard Worker return "Test with array varying";
647*35238bceSAndroid Build Coastguard Worker
648*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
649*35238bceSAndroid Build Coastguard Worker return "";
650*35238bceSAndroid Build Coastguard Worker }
651*35238bceSAndroid Build Coastguard Worker
652*35238bceSAndroid Build Coastguard Worker class SingleSampleInterpolateAtSampleCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
653*35238bceSAndroid Build Coastguard Worker {
654*35238bceSAndroid Build Coastguard Worker public:
655*35238bceSAndroid Build Coastguard Worker enum SampleCase
656*35238bceSAndroid Build Coastguard Worker {
657*35238bceSAndroid Build Coastguard Worker SAMPLE_0 = 0,
658*35238bceSAndroid Build Coastguard Worker SAMPLE_N,
659*35238bceSAndroid Build Coastguard Worker
660*35238bceSAndroid Build Coastguard Worker SAMPLE_LAST
661*35238bceSAndroid Build Coastguard Worker };
662*35238bceSAndroid Build Coastguard Worker
663*35238bceSAndroid Build Coastguard Worker SingleSampleInterpolateAtSampleCase(Context &context, const char *name, const char *description, int numSamples,
664*35238bceSAndroid Build Coastguard Worker RenderTarget target, SampleCase sampleCase);
665*35238bceSAndroid Build Coastguard Worker virtual ~SingleSampleInterpolateAtSampleCase(void);
666*35238bceSAndroid Build Coastguard Worker
667*35238bceSAndroid Build Coastguard Worker void init(void);
668*35238bceSAndroid Build Coastguard Worker
669*35238bceSAndroid Build Coastguard Worker private:
670*35238bceSAndroid Build Coastguard Worker enum
671*35238bceSAndroid Build Coastguard Worker {
672*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 32
673*35238bceSAndroid Build Coastguard Worker };
674*35238bceSAndroid Build Coastguard Worker
675*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
676*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
677*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
678*35238bceSAndroid Build Coastguard Worker
679*35238bceSAndroid Build Coastguard Worker const SampleCase m_sampleCase;
680*35238bceSAndroid Build Coastguard Worker };
681*35238bceSAndroid Build Coastguard Worker
SingleSampleInterpolateAtSampleCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target,SampleCase sampleCase)682*35238bceSAndroid Build Coastguard Worker SingleSampleInterpolateAtSampleCase::SingleSampleInterpolateAtSampleCase(Context &context, const char *name,
683*35238bceSAndroid Build Coastguard Worker const char *description, int numSamples,
684*35238bceSAndroid Build Coastguard Worker RenderTarget target, SampleCase sampleCase)
685*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
686*35238bceSAndroid Build Coastguard Worker , m_sampleCase(sampleCase)
687*35238bceSAndroid Build Coastguard Worker {
688*35238bceSAndroid Build Coastguard Worker DE_ASSERT(numSamples == 0);
689*35238bceSAndroid Build Coastguard Worker DE_ASSERT(sampleCase < SAMPLE_LAST);
690*35238bceSAndroid Build Coastguard Worker }
691*35238bceSAndroid Build Coastguard Worker
~SingleSampleInterpolateAtSampleCase(void)692*35238bceSAndroid Build Coastguard Worker SingleSampleInterpolateAtSampleCase::~SingleSampleInterpolateAtSampleCase(void)
693*35238bceSAndroid Build Coastguard Worker {
694*35238bceSAndroid Build Coastguard Worker }
695*35238bceSAndroid Build Coastguard Worker
init(void)696*35238bceSAndroid Build Coastguard Worker void SingleSampleInterpolateAtSampleCase::init(void)
697*35238bceSAndroid Build Coastguard Worker {
698*35238bceSAndroid Build Coastguard Worker // requirements
699*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
700*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
701*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
702*35238bceSAndroid Build Coastguard Worker if (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() > 1)
703*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Non-multisample framebuffer required");
704*35238bceSAndroid Build Coastguard Worker
705*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
706*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
707*35238bceSAndroid Build Coastguard Worker << "Verifying that using interpolateAtSample with multisample buffers not available returns "
708*35238bceSAndroid Build Coastguard Worker "sample evaluated at the center of the pixel.\n"
709*35238bceSAndroid Build Coastguard Worker << " Interpolate varying containing screen space location.\n"
710*35238bceSAndroid Build Coastguard Worker << " => fract(screen space location) should be (about) (0.5, 0.5)\n"
711*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
712*35238bceSAndroid Build Coastguard Worker
713*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
714*35238bceSAndroid Build Coastguard Worker }
715*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const716*35238bceSAndroid Build Coastguard Worker std::string SingleSampleInterpolateAtSampleCase::genVertexSource(int numTargetSamples) const
717*35238bceSAndroid Build Coastguard Worker {
718*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
719*35238bceSAndroid Build Coastguard Worker
720*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
721*35238bceSAndroid Build Coastguard Worker
722*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
723*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
724*35238bceSAndroid Build Coastguard Worker "out highp vec2 v_position;\n"
725*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
726*35238bceSAndroid Build Coastguard Worker "{\n"
727*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
728*35238bceSAndroid Build Coastguard Worker " v_position = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2("
729*35238bceSAndroid Build Coastguard Worker << (int)RENDER_SIZE << ".0, " << (int)RENDER_SIZE
730*35238bceSAndroid Build Coastguard Worker << ".0);\n"
731*35238bceSAndroid Build Coastguard Worker "}\n";
732*35238bceSAndroid Build Coastguard Worker
733*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
734*35238bceSAndroid Build Coastguard Worker }
735*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const736*35238bceSAndroid Build Coastguard Worker std::string SingleSampleInterpolateAtSampleCase::genFragmentSource(int numTargetSamples) const
737*35238bceSAndroid Build Coastguard Worker {
738*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
739*35238bceSAndroid Build Coastguard Worker
740*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
741*35238bceSAndroid Build Coastguard Worker
742*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
743*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
744*35238bceSAndroid Build Coastguard Worker "in highp vec2 v_position;\n"
745*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
746*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
747*35238bceSAndroid Build Coastguard Worker "{\n"
748*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other "
749*35238bceSAndroid Build Coastguard Worker "errors\n"; // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
750*35238bceSAndroid Build Coastguard Worker
751*35238bceSAndroid Build Coastguard Worker if (m_sampleCase == SAMPLE_0)
752*35238bceSAndroid Build Coastguard Worker {
753*35238bceSAndroid Build Coastguard Worker buf << " highp vec2 samplePosition = interpolateAtSample(v_position, 0);\n"
754*35238bceSAndroid Build Coastguard Worker " highp vec2 positionInsideAPixel = fract(samplePosition);\n"
755*35238bceSAndroid Build Coastguard Worker "\n"
756*35238bceSAndroid Build Coastguard Worker " if (abs(positionInsideAPixel.x - 0.5) <= threshold && abs(positionInsideAPixel.y - 0.5) <= "
757*35238bceSAndroid Build Coastguard Worker "threshold)\n"
758*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
759*35238bceSAndroid Build Coastguard Worker " else\n"
760*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
761*35238bceSAndroid Build Coastguard Worker "}\n";
762*35238bceSAndroid Build Coastguard Worker }
763*35238bceSAndroid Build Coastguard Worker else if (m_sampleCase == SAMPLE_N)
764*35238bceSAndroid Build Coastguard Worker {
765*35238bceSAndroid Build Coastguard Worker buf << " bool allOk = true;\n"
766*35238bceSAndroid Build Coastguard Worker " for (int sampleNdx = 159; sampleNdx < 163; ++sampleNdx)\n"
767*35238bceSAndroid Build Coastguard Worker " {\n"
768*35238bceSAndroid Build Coastguard Worker " highp vec2 samplePosition = interpolateAtSample(v_position, sampleNdx);\n"
769*35238bceSAndroid Build Coastguard Worker " highp vec2 positionInsideAPixel = fract(samplePosition);\n"
770*35238bceSAndroid Build Coastguard Worker " if (abs(positionInsideAPixel.x - 0.5) > threshold || abs(positionInsideAPixel.y - 0.5) > "
771*35238bceSAndroid Build Coastguard Worker "threshold)\n"
772*35238bceSAndroid Build Coastguard Worker " allOk = false;\n"
773*35238bceSAndroid Build Coastguard Worker " }\n"
774*35238bceSAndroid Build Coastguard Worker "\n"
775*35238bceSAndroid Build Coastguard Worker " if (allOk)\n"
776*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
777*35238bceSAndroid Build Coastguard Worker " else\n"
778*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
779*35238bceSAndroid Build Coastguard Worker "}\n";
780*35238bceSAndroid Build Coastguard Worker }
781*35238bceSAndroid Build Coastguard Worker else
782*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
783*35238bceSAndroid Build Coastguard Worker
784*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
785*35238bceSAndroid Build Coastguard Worker }
786*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)787*35238bceSAndroid Build Coastguard Worker bool SingleSampleInterpolateAtSampleCase::verifyImage(const tcu::Surface &resultImage)
788*35238bceSAndroid Build Coastguard Worker {
789*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
790*35238bceSAndroid Build Coastguard Worker }
791*35238bceSAndroid Build Coastguard Worker
792*35238bceSAndroid Build Coastguard Worker class CentroidRenderCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
793*35238bceSAndroid Build Coastguard Worker {
794*35238bceSAndroid Build Coastguard Worker public:
795*35238bceSAndroid Build Coastguard Worker CentroidRenderCase(Context &context, const char *name, const char *description, int numSamples, RenderTarget target,
796*35238bceSAndroid Build Coastguard Worker int renderSize);
797*35238bceSAndroid Build Coastguard Worker virtual ~CentroidRenderCase(void);
798*35238bceSAndroid Build Coastguard Worker
799*35238bceSAndroid Build Coastguard Worker void init(void);
800*35238bceSAndroid Build Coastguard Worker
801*35238bceSAndroid Build Coastguard Worker private:
802*35238bceSAndroid Build Coastguard Worker void setupRenderData(void);
803*35238bceSAndroid Build Coastguard Worker };
804*35238bceSAndroid Build Coastguard Worker
CentroidRenderCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target,int renderSize)805*35238bceSAndroid Build Coastguard Worker CentroidRenderCase::CentroidRenderCase(Context &context, const char *name, const char *description, int numSamples,
806*35238bceSAndroid Build Coastguard Worker RenderTarget target, int renderSize)
807*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, renderSize)
808*35238bceSAndroid Build Coastguard Worker {
809*35238bceSAndroid Build Coastguard Worker }
810*35238bceSAndroid Build Coastguard Worker
~CentroidRenderCase(void)811*35238bceSAndroid Build Coastguard Worker CentroidRenderCase::~CentroidRenderCase(void)
812*35238bceSAndroid Build Coastguard Worker {
813*35238bceSAndroid Build Coastguard Worker }
814*35238bceSAndroid Build Coastguard Worker
init(void)815*35238bceSAndroid Build Coastguard Worker void CentroidRenderCase::init(void)
816*35238bceSAndroid Build Coastguard Worker {
817*35238bceSAndroid Build Coastguard Worker // requirements
818*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
819*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
820*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
821*35238bceSAndroid Build Coastguard Worker
822*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
823*35238bceSAndroid Build Coastguard Worker }
824*35238bceSAndroid Build Coastguard Worker
setupRenderData(void)825*35238bceSAndroid Build Coastguard Worker void CentroidRenderCase::setupRenderData(void)
826*35238bceSAndroid Build Coastguard Worker {
827*35238bceSAndroid Build Coastguard Worker const int numTriangles = 200;
828*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
829*35238bceSAndroid Build Coastguard Worker std::vector<tcu::Vec4> data(numTriangles * 3 * 3);
830*35238bceSAndroid Build Coastguard Worker
831*35238bceSAndroid Build Coastguard Worker m_renderMode = GL_TRIANGLES;
832*35238bceSAndroid Build Coastguard Worker m_renderCount = numTriangles * 3;
833*35238bceSAndroid Build Coastguard Worker m_renderSceneDescription = "triangle fan of narrow triangles";
834*35238bceSAndroid Build Coastguard Worker
835*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_position"].offset = 0;
836*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_position"].stride = (int)sizeof(float[4]) * 3;
837*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_barycentricsA"].offset = (int)sizeof(float[4]);
838*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_barycentricsA"].stride = (int)sizeof(float[4]) * 3;
839*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_barycentricsB"].offset = (int)sizeof(float[4]) * 2;
840*35238bceSAndroid Build Coastguard Worker m_renderAttribs["a_barycentricsB"].stride = (int)sizeof(float[4]) * 3;
841*35238bceSAndroid Build Coastguard Worker
842*35238bceSAndroid Build Coastguard Worker for (int triangleNdx = 0; triangleNdx < numTriangles; ++triangleNdx)
843*35238bceSAndroid Build Coastguard Worker {
844*35238bceSAndroid Build Coastguard Worker const float angle = ((float)triangleNdx) / (float)numTriangles * 2.0f * DE_PI;
845*35238bceSAndroid Build Coastguard Worker const float nextAngle = ((float)triangleNdx + 1.0f) / (float)numTriangles * 2.0f * DE_PI;
846*35238bceSAndroid Build Coastguard Worker
847*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 0) * 3 + 0] = tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f);
848*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 0) * 3 + 1] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
849*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 0) * 3 + 2] = tcu::Vec4(1.0f, 0.0f, 0.0f, 0.0f);
850*35238bceSAndroid Build Coastguard Worker
851*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 1) * 3 + 0] = tcu::Vec4(2.0f * deFloatCos(angle), 2.0f * deFloatSin(angle), 0.0f, 1.0f);
852*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 1) * 3 + 1] = tcu::Vec4(0.0f, 1.0f, 0.0f, 0.0f);
853*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 1) * 3 + 2] = tcu::Vec4(0.0f, 1.0f, 0.0f, 0.0f);
854*35238bceSAndroid Build Coastguard Worker
855*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 2) * 3 + 0] =
856*35238bceSAndroid Build Coastguard Worker tcu::Vec4(2.0f * deFloatCos(nextAngle), 2.0f * deFloatSin(nextAngle), 0.0f, 1.0f);
857*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 2) * 3 + 1] = tcu::Vec4(0.0f, 0.0f, 1.0f, 0.0f);
858*35238bceSAndroid Build Coastguard Worker data[(triangleNdx * 3 + 2) * 3 + 2] = tcu::Vec4(0.0f, 0.0f, 1.0f, 0.0f);
859*35238bceSAndroid Build Coastguard Worker }
860*35238bceSAndroid Build Coastguard Worker
861*35238bceSAndroid Build Coastguard Worker gl.bindBuffer(GL_ARRAY_BUFFER, m_buffer);
862*35238bceSAndroid Build Coastguard Worker gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(data.size() * sizeof(tcu::Vec4)), data[0].getPtr(),
863*35238bceSAndroid Build Coastguard Worker GL_STATIC_DRAW);
864*35238bceSAndroid Build Coastguard Worker }
865*35238bceSAndroid Build Coastguard Worker
866*35238bceSAndroid Build Coastguard Worker class CentroidQualifierAtSampleCase : public CentroidRenderCase
867*35238bceSAndroid Build Coastguard Worker {
868*35238bceSAndroid Build Coastguard Worker public:
869*35238bceSAndroid Build Coastguard Worker CentroidQualifierAtSampleCase(Context &context, const char *name, const char *description, int numSamples,
870*35238bceSAndroid Build Coastguard Worker RenderTarget target);
871*35238bceSAndroid Build Coastguard Worker virtual ~CentroidQualifierAtSampleCase(void);
872*35238bceSAndroid Build Coastguard Worker
873*35238bceSAndroid Build Coastguard Worker void init(void);
874*35238bceSAndroid Build Coastguard Worker
875*35238bceSAndroid Build Coastguard Worker private:
876*35238bceSAndroid Build Coastguard Worker enum
877*35238bceSAndroid Build Coastguard Worker {
878*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 128
879*35238bceSAndroid Build Coastguard Worker };
880*35238bceSAndroid Build Coastguard Worker
881*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
882*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
883*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
884*35238bceSAndroid Build Coastguard Worker };
885*35238bceSAndroid Build Coastguard Worker
CentroidQualifierAtSampleCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target)886*35238bceSAndroid Build Coastguard Worker CentroidQualifierAtSampleCase::CentroidQualifierAtSampleCase(Context &context, const char *name,
887*35238bceSAndroid Build Coastguard Worker const char *description, int numSamples,
888*35238bceSAndroid Build Coastguard Worker RenderTarget target)
889*35238bceSAndroid Build Coastguard Worker : CentroidRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
890*35238bceSAndroid Build Coastguard Worker {
891*35238bceSAndroid Build Coastguard Worker }
892*35238bceSAndroid Build Coastguard Worker
~CentroidQualifierAtSampleCase(void)893*35238bceSAndroid Build Coastguard Worker CentroidQualifierAtSampleCase::~CentroidQualifierAtSampleCase(void)
894*35238bceSAndroid Build Coastguard Worker {
895*35238bceSAndroid Build Coastguard Worker }
896*35238bceSAndroid Build Coastguard Worker
init(void)897*35238bceSAndroid Build Coastguard Worker void CentroidQualifierAtSampleCase::init(void)
898*35238bceSAndroid Build Coastguard Worker {
899*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
900*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
901*35238bceSAndroid Build Coastguard Worker << "Verifying that interpolateAtSample ignores the centroid-qualifier.\n"
902*35238bceSAndroid Build Coastguard Worker << " Draw a fan of narrow triangles (large number of pixels on the edges).\n"
903*35238bceSAndroid Build Coastguard Worker << " Set varyings 'barycentricsA' and 'barycentricsB' to contain barycentric coordinates.\n"
904*35238bceSAndroid Build Coastguard Worker << " Add centroid-qualifier for barycentricsB.\n"
905*35238bceSAndroid Build Coastguard Worker << " => interpolateAtSample(barycentricsB, N) ~= interpolateAtSample(barycentricsA, N)\n"
906*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
907*35238bceSAndroid Build Coastguard Worker
908*35238bceSAndroid Build Coastguard Worker CentroidRenderCase::init();
909*35238bceSAndroid Build Coastguard Worker }
910*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const911*35238bceSAndroid Build Coastguard Worker std::string CentroidQualifierAtSampleCase::genVertexSource(int numTargetSamples) const
912*35238bceSAndroid Build Coastguard Worker {
913*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
914*35238bceSAndroid Build Coastguard Worker
915*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
916*35238bceSAndroid Build Coastguard Worker
917*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
918*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
919*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsA;\n"
920*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsB;\n"
921*35238bceSAndroid Build Coastguard Worker "out highp vec3 v_barycentricsA;\n"
922*35238bceSAndroid Build Coastguard Worker "centroid out highp vec3 v_barycentricsB;\n"
923*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
924*35238bceSAndroid Build Coastguard Worker "{\n"
925*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
926*35238bceSAndroid Build Coastguard Worker " v_barycentricsA = a_barycentricsA.xyz;\n"
927*35238bceSAndroid Build Coastguard Worker " v_barycentricsB = a_barycentricsB.xyz;\n"
928*35238bceSAndroid Build Coastguard Worker "}\n";
929*35238bceSAndroid Build Coastguard Worker
930*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
931*35238bceSAndroid Build Coastguard Worker }
932*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const933*35238bceSAndroid Build Coastguard Worker std::string CentroidQualifierAtSampleCase::genFragmentSource(int numTargetSamples) const
934*35238bceSAndroid Build Coastguard Worker {
935*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
936*35238bceSAndroid Build Coastguard Worker
937*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
938*35238bceSAndroid Build Coastguard Worker
939*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
940*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
941*35238bceSAndroid Build Coastguard Worker "in highp vec3 v_barycentricsA;\n"
942*35238bceSAndroid Build Coastguard Worker "centroid in highp vec3 v_barycentricsB;\n"
943*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
944*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
945*35238bceSAndroid Build Coastguard Worker "{\n"
946*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.0005;\n"
947*35238bceSAndroid Build Coastguard Worker " bool allOk = true;\n"
948*35238bceSAndroid Build Coastguard Worker "\n"
949*35238bceSAndroid Build Coastguard Worker " for (int sampleNdx = 0; sampleNdx < "
950*35238bceSAndroid Build Coastguard Worker << numTargetSamples
951*35238bceSAndroid Build Coastguard Worker << "; ++sampleNdx)\n"
952*35238bceSAndroid Build Coastguard Worker " {\n"
953*35238bceSAndroid Build Coastguard Worker " highp vec3 sampleA = interpolateAtSample(v_barycentricsA, sampleNdx);\n"
954*35238bceSAndroid Build Coastguard Worker " highp vec3 sampleB = interpolateAtSample(v_barycentricsB, sampleNdx);\n"
955*35238bceSAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(sampleA - sampleB), vec3(threshold)));\n"
956*35238bceSAndroid Build Coastguard Worker " if (!valuesEqual)\n"
957*35238bceSAndroid Build Coastguard Worker " allOk = false;\n"
958*35238bceSAndroid Build Coastguard Worker " }\n"
959*35238bceSAndroid Build Coastguard Worker "\n"
960*35238bceSAndroid Build Coastguard Worker " if (allOk)\n"
961*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
962*35238bceSAndroid Build Coastguard Worker " else\n"
963*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
964*35238bceSAndroid Build Coastguard Worker "}\n";
965*35238bceSAndroid Build Coastguard Worker
966*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
967*35238bceSAndroid Build Coastguard Worker }
968*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)969*35238bceSAndroid Build Coastguard Worker bool CentroidQualifierAtSampleCase::verifyImage(const tcu::Surface &resultImage)
970*35238bceSAndroid Build Coastguard Worker {
971*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
972*35238bceSAndroid Build Coastguard Worker }
973*35238bceSAndroid Build Coastguard Worker
974*35238bceSAndroid Build Coastguard Worker class InterpolateAtSampleIDCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
975*35238bceSAndroid Build Coastguard Worker {
976*35238bceSAndroid Build Coastguard Worker public:
977*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleIDCase(Context &context, const char *name, const char *description, int numSamples,
978*35238bceSAndroid Build Coastguard Worker RenderTarget target);
979*35238bceSAndroid Build Coastguard Worker virtual ~InterpolateAtSampleIDCase(void);
980*35238bceSAndroid Build Coastguard Worker
981*35238bceSAndroid Build Coastguard Worker void init(void);
982*35238bceSAndroid Build Coastguard Worker
983*35238bceSAndroid Build Coastguard Worker private:
984*35238bceSAndroid Build Coastguard Worker enum
985*35238bceSAndroid Build Coastguard Worker {
986*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 32
987*35238bceSAndroid Build Coastguard Worker };
988*35238bceSAndroid Build Coastguard Worker
989*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
990*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
991*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
992*35238bceSAndroid Build Coastguard Worker };
993*35238bceSAndroid Build Coastguard Worker
InterpolateAtSampleIDCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target)994*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleIDCase::InterpolateAtSampleIDCase(Context &context, const char *name, const char *description,
995*35238bceSAndroid Build Coastguard Worker int numSamples, RenderTarget target)
996*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
997*35238bceSAndroid Build Coastguard Worker {
998*35238bceSAndroid Build Coastguard Worker }
999*35238bceSAndroid Build Coastguard Worker
~InterpolateAtSampleIDCase(void)1000*35238bceSAndroid Build Coastguard Worker InterpolateAtSampleIDCase::~InterpolateAtSampleIDCase(void)
1001*35238bceSAndroid Build Coastguard Worker {
1002*35238bceSAndroid Build Coastguard Worker }
1003*35238bceSAndroid Build Coastguard Worker
init(void)1004*35238bceSAndroid Build Coastguard Worker void InterpolateAtSampleIDCase::init(void)
1005*35238bceSAndroid Build Coastguard Worker {
1006*35238bceSAndroid Build Coastguard Worker // requirements
1007*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
1008*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
1009*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
1010*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) && !m_context.getContextInfo().isExtensionSupported("GL_OES_sample_variables"))
1011*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_sample_variables extension");
1012*35238bceSAndroid Build Coastguard Worker
1013*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
1014*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
1015*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
1016*35238bceSAndroid Build Coastguard Worker << "Verifying that interpolateAtSample with the sample set to the current sampleID returns consistent values.\n"
1017*35238bceSAndroid Build Coastguard Worker << " Interpolate varying containing screen space location.\n"
1018*35238bceSAndroid Build Coastguard Worker << " => interpolateAtSample(varying, sampleID) = varying" << tcu::TestLog::EndMessage;
1019*35238bceSAndroid Build Coastguard Worker
1020*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
1021*35238bceSAndroid Build Coastguard Worker }
1022*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const1023*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSampleIDCase::genVertexSource(int numTargetSamples) const
1024*35238bceSAndroid Build Coastguard Worker {
1025*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1026*35238bceSAndroid Build Coastguard Worker
1027*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1028*35238bceSAndroid Build Coastguard Worker
1029*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1030*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1031*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
1032*35238bceSAndroid Build Coastguard Worker "sample out highp vec2 v_screenPosition;\n"
1033*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1034*35238bceSAndroid Build Coastguard Worker "{\n"
1035*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
1036*35238bceSAndroid Build Coastguard Worker " v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2("
1037*35238bceSAndroid Build Coastguard Worker << (int)RENDER_SIZE << ".0, " << (int)RENDER_SIZE
1038*35238bceSAndroid Build Coastguard Worker << ".0);\n"
1039*35238bceSAndroid Build Coastguard Worker "}\n";
1040*35238bceSAndroid Build Coastguard Worker
1041*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1042*35238bceSAndroid Build Coastguard Worker }
1043*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const1044*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSampleIDCase::genFragmentSource(int numTargetSamples) const
1045*35238bceSAndroid Build Coastguard Worker {
1046*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1047*35238bceSAndroid Build Coastguard Worker
1048*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1049*35238bceSAndroid Build Coastguard Worker
1050*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1051*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SAMPLE_VARIABLES}"
1052*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1053*35238bceSAndroid Build Coastguard Worker "sample in highp vec2 v_screenPosition;\n"
1054*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
1055*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1056*35238bceSAndroid Build Coastguard Worker "{\n"
1057*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other "
1058*35238bceSAndroid Build Coastguard Worker "errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
1059*35238bceSAndroid Build Coastguard Worker "\n"
1060*35238bceSAndroid Build Coastguard Worker " highp vec2 offsetValue = interpolateAtSample(v_screenPosition, gl_SampleID);\n"
1061*35238bceSAndroid Build Coastguard Worker " highp vec2 refValue = v_screenPosition;\n"
1062*35238bceSAndroid Build Coastguard Worker "\n"
1063*35238bceSAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
1064*35238bceSAndroid Build Coastguard Worker " if (valuesEqual)\n"
1065*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1066*35238bceSAndroid Build Coastguard Worker " else\n"
1067*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1068*35238bceSAndroid Build Coastguard Worker "}\n";
1069*35238bceSAndroid Build Coastguard Worker
1070*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1071*35238bceSAndroid Build Coastguard Worker }
1072*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)1073*35238bceSAndroid Build Coastguard Worker bool InterpolateAtSampleIDCase::verifyImage(const tcu::Surface &resultImage)
1074*35238bceSAndroid Build Coastguard Worker {
1075*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
1076*35238bceSAndroid Build Coastguard Worker }
1077*35238bceSAndroid Build Coastguard Worker
1078*35238bceSAndroid Build Coastguard Worker class InterpolateAtCentroidCase : public CentroidRenderCase
1079*35238bceSAndroid Build Coastguard Worker {
1080*35238bceSAndroid Build Coastguard Worker public:
1081*35238bceSAndroid Build Coastguard Worker enum TestType
1082*35238bceSAndroid Build Coastguard Worker {
1083*35238bceSAndroid Build Coastguard Worker TEST_CONSISTENCY = 0,
1084*35238bceSAndroid Build Coastguard Worker TEST_ARRAY_ELEMENT,
1085*35238bceSAndroid Build Coastguard Worker
1086*35238bceSAndroid Build Coastguard Worker TEST_LAST
1087*35238bceSAndroid Build Coastguard Worker };
1088*35238bceSAndroid Build Coastguard Worker
1089*35238bceSAndroid Build Coastguard Worker InterpolateAtCentroidCase(Context &context, const char *name, const char *description, int numSamples,
1090*35238bceSAndroid Build Coastguard Worker RenderTarget target, TestType type);
1091*35238bceSAndroid Build Coastguard Worker virtual ~InterpolateAtCentroidCase(void);
1092*35238bceSAndroid Build Coastguard Worker
1093*35238bceSAndroid Build Coastguard Worker void init(void);
1094*35238bceSAndroid Build Coastguard Worker
1095*35238bceSAndroid Build Coastguard Worker private:
1096*35238bceSAndroid Build Coastguard Worker enum
1097*35238bceSAndroid Build Coastguard Worker {
1098*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 128
1099*35238bceSAndroid Build Coastguard Worker };
1100*35238bceSAndroid Build Coastguard Worker
1101*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
1102*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
1103*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
1104*35238bceSAndroid Build Coastguard Worker
1105*35238bceSAndroid Build Coastguard Worker const TestType m_type;
1106*35238bceSAndroid Build Coastguard Worker };
1107*35238bceSAndroid Build Coastguard Worker
InterpolateAtCentroidCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target,TestType type)1108*35238bceSAndroid Build Coastguard Worker InterpolateAtCentroidCase::InterpolateAtCentroidCase(Context &context, const char *name, const char *description,
1109*35238bceSAndroid Build Coastguard Worker int numSamples, RenderTarget target, TestType type)
1110*35238bceSAndroid Build Coastguard Worker : CentroidRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
1111*35238bceSAndroid Build Coastguard Worker , m_type(type)
1112*35238bceSAndroid Build Coastguard Worker {
1113*35238bceSAndroid Build Coastguard Worker }
1114*35238bceSAndroid Build Coastguard Worker
~InterpolateAtCentroidCase(void)1115*35238bceSAndroid Build Coastguard Worker InterpolateAtCentroidCase::~InterpolateAtCentroidCase(void)
1116*35238bceSAndroid Build Coastguard Worker {
1117*35238bceSAndroid Build Coastguard Worker }
1118*35238bceSAndroid Build Coastguard Worker
init(void)1119*35238bceSAndroid Build Coastguard Worker void InterpolateAtCentroidCase::init(void)
1120*35238bceSAndroid Build Coastguard Worker {
1121*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
1122*35238bceSAndroid Build Coastguard Worker if (m_type == TEST_CONSISTENCY)
1123*35238bceSAndroid Build Coastguard Worker {
1124*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
1125*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
1126*35238bceSAndroid Build Coastguard Worker << "Verifying that interpolateAtCentroid does not return different values than a "
1127*35238bceSAndroid Build Coastguard Worker "corresponding centroid-qualified varying.\n"
1128*35238bceSAndroid Build Coastguard Worker << " Draw a fan of narrow triangles (large number of pixels on the edges).\n"
1129*35238bceSAndroid Build Coastguard Worker << " Set varyings 'barycentricsA' and 'barycentricsB' to contain barycentric coordinates.\n"
1130*35238bceSAndroid Build Coastguard Worker << " Add centroid-qualifier for barycentricsB.\n"
1131*35238bceSAndroid Build Coastguard Worker << " => interpolateAtCentroid(barycentricsA) ~= barycentricsB\n"
1132*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
1133*35238bceSAndroid Build Coastguard Worker }
1134*35238bceSAndroid Build Coastguard Worker else if (m_type == TEST_ARRAY_ELEMENT)
1135*35238bceSAndroid Build Coastguard Worker {
1136*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message
1137*35238bceSAndroid Build Coastguard Worker << "Testing interpolateAtCentroid with element of array as an argument."
1138*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
1139*35238bceSAndroid Build Coastguard Worker }
1140*35238bceSAndroid Build Coastguard Worker else
1141*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1142*35238bceSAndroid Build Coastguard Worker
1143*35238bceSAndroid Build Coastguard Worker CentroidRenderCase::init();
1144*35238bceSAndroid Build Coastguard Worker }
1145*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const1146*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtCentroidCase::genVertexSource(int numTargetSamples) const
1147*35238bceSAndroid Build Coastguard Worker {
1148*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1149*35238bceSAndroid Build Coastguard Worker
1150*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1151*35238bceSAndroid Build Coastguard Worker
1152*35238bceSAndroid Build Coastguard Worker if (m_type == TEST_CONSISTENCY)
1153*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1154*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
1155*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsA;\n"
1156*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsB;\n"
1157*35238bceSAndroid Build Coastguard Worker "out highp vec3 v_barycentricsA;\n"
1158*35238bceSAndroid Build Coastguard Worker "centroid out highp vec3 v_barycentricsB;\n"
1159*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1160*35238bceSAndroid Build Coastguard Worker "{\n"
1161*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
1162*35238bceSAndroid Build Coastguard Worker " v_barycentricsA = a_barycentricsA.xyz;\n"
1163*35238bceSAndroid Build Coastguard Worker " v_barycentricsB = a_barycentricsB.xyz;\n"
1164*35238bceSAndroid Build Coastguard Worker "}\n";
1165*35238bceSAndroid Build Coastguard Worker else if (m_type == TEST_ARRAY_ELEMENT)
1166*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1167*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
1168*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsA;\n"
1169*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_barycentricsB;\n"
1170*35238bceSAndroid Build Coastguard Worker "out highp vec3[2] v_barycentrics;\n"
1171*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1172*35238bceSAndroid Build Coastguard Worker "{\n"
1173*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
1174*35238bceSAndroid Build Coastguard Worker " v_barycentrics[0] = a_barycentricsA.xyz;\n"
1175*35238bceSAndroid Build Coastguard Worker " v_barycentrics[1] = a_barycentricsB.xyz;\n"
1176*35238bceSAndroid Build Coastguard Worker "}\n";
1177*35238bceSAndroid Build Coastguard Worker else
1178*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1179*35238bceSAndroid Build Coastguard Worker
1180*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1181*35238bceSAndroid Build Coastguard Worker }
1182*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const1183*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtCentroidCase::genFragmentSource(int numTargetSamples) const
1184*35238bceSAndroid Build Coastguard Worker {
1185*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1186*35238bceSAndroid Build Coastguard Worker
1187*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1188*35238bceSAndroid Build Coastguard Worker
1189*35238bceSAndroid Build Coastguard Worker if (m_type == TEST_CONSISTENCY)
1190*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1191*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1192*35238bceSAndroid Build Coastguard Worker "in highp vec3 v_barycentricsA;\n"
1193*35238bceSAndroid Build Coastguard Worker "centroid in highp vec3 v_barycentricsB;\n"
1194*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out highp vec4 fragColor;\n"
1195*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1196*35238bceSAndroid Build Coastguard Worker "{\n"
1197*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.0005;\n"
1198*35238bceSAndroid Build Coastguard Worker "\n"
1199*35238bceSAndroid Build Coastguard Worker " highp vec3 centroidASampled = interpolateAtCentroid(v_barycentricsA);\n"
1200*35238bceSAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(centroidASampled - v_barycentricsB), vec3(threshold)));\n"
1201*35238bceSAndroid Build Coastguard Worker " bool centroidAIsInvalid = any(greaterThan(centroidASampled, vec3(1.0))) ||\n"
1202*35238bceSAndroid Build Coastguard Worker " any(lessThan(centroidASampled, vec3(0.0)));\n"
1203*35238bceSAndroid Build Coastguard Worker " bool centroidBIsInvalid = any(greaterThan(v_barycentricsB, vec3(1.0))) ||\n"
1204*35238bceSAndroid Build Coastguard Worker " any(lessThan(v_barycentricsB, vec3(0.0)));\n"
1205*35238bceSAndroid Build Coastguard Worker "\n"
1206*35238bceSAndroid Build Coastguard Worker " if (valuesEqual && !centroidAIsInvalid && !centroidBIsInvalid)\n"
1207*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1208*35238bceSAndroid Build Coastguard Worker " else if (centroidAIsInvalid || centroidBIsInvalid)\n"
1209*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1210*35238bceSAndroid Build Coastguard Worker " else\n"
1211*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
1212*35238bceSAndroid Build Coastguard Worker "}\n";
1213*35238bceSAndroid Build Coastguard Worker else if (m_type == TEST_ARRAY_ELEMENT)
1214*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1215*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1216*35238bceSAndroid Build Coastguard Worker "in highp vec3[2] v_barycentrics;\n"
1217*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
1218*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1219*35238bceSAndroid Build Coastguard Worker "{\n"
1220*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.0005;\n"
1221*35238bceSAndroid Build Coastguard Worker "\n"
1222*35238bceSAndroid Build Coastguard Worker " highp vec3 centroidInterpolated = interpolateAtCentroid(v_barycentrics[1]);\n"
1223*35238bceSAndroid Build Coastguard Worker " bool centroidIsInvalid = any(greaterThan(centroidInterpolated, vec3(1.0))) ||\n"
1224*35238bceSAndroid Build Coastguard Worker " any(lessThan(centroidInterpolated, vec3(0.0)));\n"
1225*35238bceSAndroid Build Coastguard Worker "\n"
1226*35238bceSAndroid Build Coastguard Worker " if (!centroidIsInvalid)\n"
1227*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1228*35238bceSAndroid Build Coastguard Worker " else\n"
1229*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1230*35238bceSAndroid Build Coastguard Worker "}\n";
1231*35238bceSAndroid Build Coastguard Worker else
1232*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1233*35238bceSAndroid Build Coastguard Worker
1234*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1235*35238bceSAndroid Build Coastguard Worker }
1236*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)1237*35238bceSAndroid Build Coastguard Worker bool InterpolateAtCentroidCase::verifyImage(const tcu::Surface &resultImage)
1238*35238bceSAndroid Build Coastguard Worker {
1239*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
1240*35238bceSAndroid Build Coastguard Worker }
1241*35238bceSAndroid Build Coastguard Worker
1242*35238bceSAndroid Build Coastguard Worker class InterpolateAtOffsetCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
1243*35238bceSAndroid Build Coastguard Worker {
1244*35238bceSAndroid Build Coastguard Worker public:
1245*35238bceSAndroid Build Coastguard Worker enum TestType
1246*35238bceSAndroid Build Coastguard Worker {
1247*35238bceSAndroid Build Coastguard Worker TEST_QUALIFIER_NONE = 0,
1248*35238bceSAndroid Build Coastguard Worker TEST_QUALIFIER_CENTROID,
1249*35238bceSAndroid Build Coastguard Worker TEST_QUALIFIER_SAMPLE,
1250*35238bceSAndroid Build Coastguard Worker TEST_ARRAY_ELEMENT,
1251*35238bceSAndroid Build Coastguard Worker
1252*35238bceSAndroid Build Coastguard Worker TEST_LAST
1253*35238bceSAndroid Build Coastguard Worker };
1254*35238bceSAndroid Build Coastguard Worker InterpolateAtOffsetCase(Context &context, const char *name, const char *description, int numSamples,
1255*35238bceSAndroid Build Coastguard Worker RenderTarget target, TestType testType);
1256*35238bceSAndroid Build Coastguard Worker virtual ~InterpolateAtOffsetCase(void);
1257*35238bceSAndroid Build Coastguard Worker
1258*35238bceSAndroid Build Coastguard Worker void init(void);
1259*35238bceSAndroid Build Coastguard Worker
1260*35238bceSAndroid Build Coastguard Worker private:
1261*35238bceSAndroid Build Coastguard Worker enum
1262*35238bceSAndroid Build Coastguard Worker {
1263*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 32
1264*35238bceSAndroid Build Coastguard Worker };
1265*35238bceSAndroid Build Coastguard Worker
1266*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
1267*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
1268*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
1269*35238bceSAndroid Build Coastguard Worker
1270*35238bceSAndroid Build Coastguard Worker const TestType m_testType;
1271*35238bceSAndroid Build Coastguard Worker };
1272*35238bceSAndroid Build Coastguard Worker
InterpolateAtOffsetCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target,TestType testType)1273*35238bceSAndroid Build Coastguard Worker InterpolateAtOffsetCase::InterpolateAtOffsetCase(Context &context, const char *name, const char *description,
1274*35238bceSAndroid Build Coastguard Worker int numSamples, RenderTarget target, TestType testType)
1275*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
1276*35238bceSAndroid Build Coastguard Worker , m_testType(testType)
1277*35238bceSAndroid Build Coastguard Worker {
1278*35238bceSAndroid Build Coastguard Worker DE_ASSERT(testType < TEST_LAST);
1279*35238bceSAndroid Build Coastguard Worker }
1280*35238bceSAndroid Build Coastguard Worker
~InterpolateAtOffsetCase(void)1281*35238bceSAndroid Build Coastguard Worker InterpolateAtOffsetCase::~InterpolateAtOffsetCase(void)
1282*35238bceSAndroid Build Coastguard Worker {
1283*35238bceSAndroid Build Coastguard Worker }
1284*35238bceSAndroid Build Coastguard Worker
init(void)1285*35238bceSAndroid Build Coastguard Worker void InterpolateAtOffsetCase::init(void)
1286*35238bceSAndroid Build Coastguard Worker {
1287*35238bceSAndroid Build Coastguard Worker // requirements
1288*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
1289*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
1290*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
1291*35238bceSAndroid Build Coastguard Worker
1292*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
1293*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
1294*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message << "Verifying that interpolateAtOffset returns correct values.\n"
1295*35238bceSAndroid Build Coastguard Worker << " Interpolate varying containing screen space location.\n"
1296*35238bceSAndroid Build Coastguard Worker << " => interpolateAtOffset(varying, offset) should be \"varying value at the pixel center\" + offset"
1297*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
1298*35238bceSAndroid Build Coastguard Worker
1299*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
1300*35238bceSAndroid Build Coastguard Worker }
1301*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const1302*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtOffsetCase::genVertexSource(int numTargetSamples) const
1303*35238bceSAndroid Build Coastguard Worker {
1304*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1305*35238bceSAndroid Build Coastguard Worker
1306*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1307*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1308*35238bceSAndroid Build Coastguard Worker << "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1309*35238bceSAndroid Build Coastguard Worker << "in highp vec4 a_position;\n";
1310*35238bceSAndroid Build Coastguard Worker
1311*35238bceSAndroid Build Coastguard Worker if (m_testType == TEST_QUALIFIER_NONE || m_testType == TEST_QUALIFIER_CENTROID ||
1312*35238bceSAndroid Build Coastguard Worker m_testType == TEST_QUALIFIER_SAMPLE)
1313*35238bceSAndroid Build Coastguard Worker {
1314*35238bceSAndroid Build Coastguard Worker const char *const qualifier = (m_testType == TEST_QUALIFIER_CENTROID) ? ("centroid ") :
1315*35238bceSAndroid Build Coastguard Worker (m_testType == TEST_QUALIFIER_SAMPLE) ? ("sample ") :
1316*35238bceSAndroid Build Coastguard Worker ("");
1317*35238bceSAndroid Build Coastguard Worker buf << qualifier << "out highp vec2 v_screenPosition;\n" << qualifier << "out highp vec2 v_offset;\n";
1318*35238bceSAndroid Build Coastguard Worker }
1319*35238bceSAndroid Build Coastguard Worker else if (m_testType == TEST_ARRAY_ELEMENT)
1320*35238bceSAndroid Build Coastguard Worker {
1321*35238bceSAndroid Build Coastguard Worker buf << "out highp vec2[2] v_screenPosition;\n"
1322*35238bceSAndroid Build Coastguard Worker << "out highp vec2 v_offset;\n";
1323*35238bceSAndroid Build Coastguard Worker }
1324*35238bceSAndroid Build Coastguard Worker else
1325*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1326*35238bceSAndroid Build Coastguard Worker
1327*35238bceSAndroid Build Coastguard Worker buf << "void main (void)\n"
1328*35238bceSAndroid Build Coastguard Worker << "{\n"
1329*35238bceSAndroid Build Coastguard Worker << " gl_Position = a_position;\n";
1330*35238bceSAndroid Build Coastguard Worker
1331*35238bceSAndroid Build Coastguard Worker if (m_testType != TEST_ARRAY_ELEMENT)
1332*35238bceSAndroid Build Coastguard Worker buf << " v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << (int)RENDER_SIZE << ".0, "
1333*35238bceSAndroid Build Coastguard Worker << (int)RENDER_SIZE << ".0);\n";
1334*35238bceSAndroid Build Coastguard Worker else
1335*35238bceSAndroid Build Coastguard Worker buf << " v_screenPosition[0] = a_position.xy; // not used\n"
1336*35238bceSAndroid Build Coastguard Worker " v_screenPosition[1] = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2("
1337*35238bceSAndroid Build Coastguard Worker << (int)RENDER_SIZE << ".0, " << (int)RENDER_SIZE << ".0);\n";
1338*35238bceSAndroid Build Coastguard Worker
1339*35238bceSAndroid Build Coastguard Worker buf << " v_offset = a_position.xy * 0.5f;\n"
1340*35238bceSAndroid Build Coastguard Worker << "}\n";
1341*35238bceSAndroid Build Coastguard Worker
1342*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1343*35238bceSAndroid Build Coastguard Worker }
1344*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const1345*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtOffsetCase::genFragmentSource(int numTargetSamples) const
1346*35238bceSAndroid Build Coastguard Worker {
1347*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1348*35238bceSAndroid Build Coastguard Worker
1349*35238bceSAndroid Build Coastguard Worker const char *const arrayIndexing = (m_testType == TEST_ARRAY_ELEMENT) ? ("[1]") : ("");
1350*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1351*35238bceSAndroid Build Coastguard Worker
1352*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1353*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}";
1354*35238bceSAndroid Build Coastguard Worker
1355*35238bceSAndroid Build Coastguard Worker if (m_testType == TEST_QUALIFIER_NONE || m_testType == TEST_QUALIFIER_CENTROID ||
1356*35238bceSAndroid Build Coastguard Worker m_testType == TEST_QUALIFIER_SAMPLE)
1357*35238bceSAndroid Build Coastguard Worker {
1358*35238bceSAndroid Build Coastguard Worker const char *const qualifier = (m_testType == TEST_QUALIFIER_CENTROID) ? ("centroid ") :
1359*35238bceSAndroid Build Coastguard Worker (m_testType == TEST_QUALIFIER_SAMPLE) ? ("sample ") :
1360*35238bceSAndroid Build Coastguard Worker ("");
1361*35238bceSAndroid Build Coastguard Worker buf << qualifier << "in highp vec2 v_screenPosition;\n" << qualifier << "in highp vec2 v_offset;\n";
1362*35238bceSAndroid Build Coastguard Worker }
1363*35238bceSAndroid Build Coastguard Worker else if (m_testType == TEST_ARRAY_ELEMENT)
1364*35238bceSAndroid Build Coastguard Worker {
1365*35238bceSAndroid Build Coastguard Worker buf << "in highp vec2[2] v_screenPosition;\n"
1366*35238bceSAndroid Build Coastguard Worker << "in highp vec2 v_offset;\n";
1367*35238bceSAndroid Build Coastguard Worker }
1368*35238bceSAndroid Build Coastguard Worker else
1369*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1370*35238bceSAndroid Build Coastguard Worker
1371*35238bceSAndroid Build Coastguard Worker buf << "layout(location = 0) out mediump vec4 fragColor;\n"
1372*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1373*35238bceSAndroid Build Coastguard Worker "{\n"
1374*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other "
1375*35238bceSAndroid Build Coastguard Worker "errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
1376*35238bceSAndroid Build Coastguard Worker "\n"
1377*35238bceSAndroid Build Coastguard Worker " highp vec2 pixelCenter = floor(v_screenPosition"
1378*35238bceSAndroid Build Coastguard Worker << arrayIndexing
1379*35238bceSAndroid Build Coastguard Worker << ") + vec2(0.5, 0.5);\n"
1380*35238bceSAndroid Build Coastguard Worker " highp vec2 offsetValue = interpolateAtOffset(v_screenPosition"
1381*35238bceSAndroid Build Coastguard Worker << arrayIndexing
1382*35238bceSAndroid Build Coastguard Worker << ", v_offset);\n"
1383*35238bceSAndroid Build Coastguard Worker " highp vec2 refValue = pixelCenter + v_offset;\n"
1384*35238bceSAndroid Build Coastguard Worker "\n"
1385*35238bceSAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
1386*35238bceSAndroid Build Coastguard Worker " if (valuesEqual)\n"
1387*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1388*35238bceSAndroid Build Coastguard Worker " else\n"
1389*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1390*35238bceSAndroid Build Coastguard Worker "}\n";
1391*35238bceSAndroid Build Coastguard Worker
1392*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1393*35238bceSAndroid Build Coastguard Worker }
1394*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)1395*35238bceSAndroid Build Coastguard Worker bool InterpolateAtOffsetCase::verifyImage(const tcu::Surface &resultImage)
1396*35238bceSAndroid Build Coastguard Worker {
1397*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
1398*35238bceSAndroid Build Coastguard Worker }
1399*35238bceSAndroid Build Coastguard Worker
1400*35238bceSAndroid Build Coastguard Worker class InterpolateAtSamplePositionCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
1401*35238bceSAndroid Build Coastguard Worker {
1402*35238bceSAndroid Build Coastguard Worker public:
1403*35238bceSAndroid Build Coastguard Worker InterpolateAtSamplePositionCase(Context &context, const char *name, const char *description, int numSamples,
1404*35238bceSAndroid Build Coastguard Worker RenderTarget target);
1405*35238bceSAndroid Build Coastguard Worker virtual ~InterpolateAtSamplePositionCase(void);
1406*35238bceSAndroid Build Coastguard Worker
1407*35238bceSAndroid Build Coastguard Worker void init(void);
1408*35238bceSAndroid Build Coastguard Worker
1409*35238bceSAndroid Build Coastguard Worker private:
1410*35238bceSAndroid Build Coastguard Worker enum
1411*35238bceSAndroid Build Coastguard Worker {
1412*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 32
1413*35238bceSAndroid Build Coastguard Worker };
1414*35238bceSAndroid Build Coastguard Worker
1415*35238bceSAndroid Build Coastguard Worker std::string genVertexSource(int numTargetSamples) const;
1416*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numTargetSamples) const;
1417*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
1418*35238bceSAndroid Build Coastguard Worker };
1419*35238bceSAndroid Build Coastguard Worker
InterpolateAtSamplePositionCase(Context & context,const char * name,const char * description,int numSamples,RenderTarget target)1420*35238bceSAndroid Build Coastguard Worker InterpolateAtSamplePositionCase::InterpolateAtSamplePositionCase(Context &context, const char *name,
1421*35238bceSAndroid Build Coastguard Worker const char *description, int numSamples,
1422*35238bceSAndroid Build Coastguard Worker RenderTarget target)
1423*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
1424*35238bceSAndroid Build Coastguard Worker {
1425*35238bceSAndroid Build Coastguard Worker }
1426*35238bceSAndroid Build Coastguard Worker
~InterpolateAtSamplePositionCase(void)1427*35238bceSAndroid Build Coastguard Worker InterpolateAtSamplePositionCase::~InterpolateAtSamplePositionCase(void)
1428*35238bceSAndroid Build Coastguard Worker {
1429*35238bceSAndroid Build Coastguard Worker }
1430*35238bceSAndroid Build Coastguard Worker
init(void)1431*35238bceSAndroid Build Coastguard Worker void InterpolateAtSamplePositionCase::init(void)
1432*35238bceSAndroid Build Coastguard Worker {
1433*35238bceSAndroid Build Coastguard Worker // requirements
1434*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
1435*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
1436*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
1437*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) && !m_context.getContextInfo().isExtensionSupported("GL_OES_sample_variables"))
1438*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_sample_variables extension");
1439*35238bceSAndroid Build Coastguard Worker
1440*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
1441*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
1442*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
1443*35238bceSAndroid Build Coastguard Worker << "Verifying that interpolateAtOffset with the offset of current sample position returns consistent values.\n"
1444*35238bceSAndroid Build Coastguard Worker << " Interpolate varying containing screen space location.\n"
1445*35238bceSAndroid Build Coastguard Worker << " => interpolateAtOffset(varying, currentOffset) = varying" << tcu::TestLog::EndMessage;
1446*35238bceSAndroid Build Coastguard Worker
1447*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
1448*35238bceSAndroid Build Coastguard Worker }
1449*35238bceSAndroid Build Coastguard Worker
genVertexSource(int numTargetSamples) const1450*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSamplePositionCase::genVertexSource(int numTargetSamples) const
1451*35238bceSAndroid Build Coastguard Worker {
1452*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1453*35238bceSAndroid Build Coastguard Worker
1454*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1455*35238bceSAndroid Build Coastguard Worker
1456*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1457*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1458*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
1459*35238bceSAndroid Build Coastguard Worker "sample out highp vec2 v_screenPosition;\n"
1460*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1461*35238bceSAndroid Build Coastguard Worker "{\n"
1462*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
1463*35238bceSAndroid Build Coastguard Worker " v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2("
1464*35238bceSAndroid Build Coastguard Worker << (int)RENDER_SIZE << ".0, " << (int)RENDER_SIZE
1465*35238bceSAndroid Build Coastguard Worker << ".0);\n"
1466*35238bceSAndroid Build Coastguard Worker "}\n";
1467*35238bceSAndroid Build Coastguard Worker
1468*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1469*35238bceSAndroid Build Coastguard Worker }
1470*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numTargetSamples) const1471*35238bceSAndroid Build Coastguard Worker std::string InterpolateAtSamplePositionCase::genFragmentSource(int numTargetSamples) const
1472*35238bceSAndroid Build Coastguard Worker {
1473*35238bceSAndroid Build Coastguard Worker DE_UNREF(numTargetSamples);
1474*35238bceSAndroid Build Coastguard Worker
1475*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1476*35238bceSAndroid Build Coastguard Worker
1477*35238bceSAndroid Build Coastguard Worker buf << "${GLSL_VERSION_DECL}\n"
1478*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SAMPLE_VARIABLES}"
1479*35238bceSAndroid Build Coastguard Worker "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}"
1480*35238bceSAndroid Build Coastguard Worker "sample in highp vec2 v_screenPosition;\n"
1481*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
1482*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1483*35238bceSAndroid Build Coastguard Worker "{\n"
1484*35238bceSAndroid Build Coastguard Worker " const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other "
1485*35238bceSAndroid Build Coastguard Worker "errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
1486*35238bceSAndroid Build Coastguard Worker "\n"
1487*35238bceSAndroid Build Coastguard Worker " highp vec2 offset = gl_SamplePosition - vec2(0.5, 0.5);\n"
1488*35238bceSAndroid Build Coastguard Worker " highp vec2 offsetValue = interpolateAtOffset(v_screenPosition, offset);\n"
1489*35238bceSAndroid Build Coastguard Worker " highp vec2 refValue = v_screenPosition;\n"
1490*35238bceSAndroid Build Coastguard Worker "\n"
1491*35238bceSAndroid Build Coastguard Worker " bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
1492*35238bceSAndroid Build Coastguard Worker " if (valuesEqual)\n"
1493*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1494*35238bceSAndroid Build Coastguard Worker " else\n"
1495*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1496*35238bceSAndroid Build Coastguard Worker "}\n";
1497*35238bceSAndroid Build Coastguard Worker
1498*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1499*35238bceSAndroid Build Coastguard Worker }
1500*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)1501*35238bceSAndroid Build Coastguard Worker bool InterpolateAtSamplePositionCase::verifyImage(const tcu::Surface &resultImage)
1502*35238bceSAndroid Build Coastguard Worker {
1503*35238bceSAndroid Build Coastguard Worker return verifyGreenImage(resultImage, m_testCtx.getLog());
1504*35238bceSAndroid Build Coastguard Worker }
1505*35238bceSAndroid Build Coastguard Worker
1506*35238bceSAndroid Build Coastguard Worker class NegativeCompileInterpolationCase : public TestCase
1507*35238bceSAndroid Build Coastguard Worker {
1508*35238bceSAndroid Build Coastguard Worker public:
1509*35238bceSAndroid Build Coastguard Worker enum CaseType
1510*35238bceSAndroid Build Coastguard Worker {
1511*35238bceSAndroid Build Coastguard Worker CASE_VEC4_IDENTITY_SWIZZLE = 0,
1512*35238bceSAndroid Build Coastguard Worker CASE_VEC4_CROP_SWIZZLE,
1513*35238bceSAndroid Build Coastguard Worker CASE_VEC4_MIXED_SWIZZLE,
1514*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_IVEC4,
1515*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_UVEC4,
1516*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_ARRAY,
1517*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_STRUCT,
1518*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_STRUCT_MEMBER,
1519*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_LOCAL,
1520*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_GLOBAL,
1521*35238bceSAndroid Build Coastguard Worker CASE_INTERPOLATE_CONSTANT,
1522*35238bceSAndroid Build Coastguard Worker
1523*35238bceSAndroid Build Coastguard Worker CASE_LAST
1524*35238bceSAndroid Build Coastguard Worker };
1525*35238bceSAndroid Build Coastguard Worker enum InterpolatorType
1526*35238bceSAndroid Build Coastguard Worker {
1527*35238bceSAndroid Build Coastguard Worker INTERPOLATE_AT_SAMPLE = 0,
1528*35238bceSAndroid Build Coastguard Worker INTERPOLATE_AT_CENTROID,
1529*35238bceSAndroid Build Coastguard Worker INTERPOLATE_AT_OFFSET,
1530*35238bceSAndroid Build Coastguard Worker
1531*35238bceSAndroid Build Coastguard Worker INTERPOLATE_LAST
1532*35238bceSAndroid Build Coastguard Worker };
1533*35238bceSAndroid Build Coastguard Worker
1534*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase(Context &context, const char *name, const char *description, CaseType caseType,
1535*35238bceSAndroid Build Coastguard Worker InterpolatorType interpolator);
1536*35238bceSAndroid Build Coastguard Worker
1537*35238bceSAndroid Build Coastguard Worker private:
1538*35238bceSAndroid Build Coastguard Worker void init(void);
1539*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
1540*35238bceSAndroid Build Coastguard Worker
1541*35238bceSAndroid Build Coastguard Worker std::string genShaderSource(void) const;
1542*35238bceSAndroid Build Coastguard Worker
1543*35238bceSAndroid Build Coastguard Worker const CaseType m_caseType;
1544*35238bceSAndroid Build Coastguard Worker const InterpolatorType m_interpolation;
1545*35238bceSAndroid Build Coastguard Worker };
1546*35238bceSAndroid Build Coastguard Worker
NegativeCompileInterpolationCase(Context & context,const char * name,const char * description,CaseType caseType,InterpolatorType interpolator)1547*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::NegativeCompileInterpolationCase(Context &context, const char *name,
1548*35238bceSAndroid Build Coastguard Worker const char *description, CaseType caseType,
1549*35238bceSAndroid Build Coastguard Worker InterpolatorType interpolator)
1550*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
1551*35238bceSAndroid Build Coastguard Worker , m_caseType(caseType)
1552*35238bceSAndroid Build Coastguard Worker , m_interpolation(interpolator)
1553*35238bceSAndroid Build Coastguard Worker {
1554*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_caseType < CASE_LAST);
1555*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_interpolation < INTERPOLATE_LAST);
1556*35238bceSAndroid Build Coastguard Worker }
1557*35238bceSAndroid Build Coastguard Worker
init(void)1558*35238bceSAndroid Build Coastguard Worker void NegativeCompileInterpolationCase::init(void)
1559*35238bceSAndroid Build Coastguard Worker {
1560*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context) &&
1561*35238bceSAndroid Build Coastguard Worker !m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
1562*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires GL_OES_shader_multisample_interpolation extension");
1563*35238bceSAndroid Build Coastguard Worker
1564*35238bceSAndroid Build Coastguard Worker if (!glu::isContextTypeES(m_context.getRenderContext().getType()))
1565*35238bceSAndroid Build Coastguard Worker {
1566*35238bceSAndroid Build Coastguard Worker if (m_caseType == CASE_VEC4_IDENTITY_SWIZZLE || m_caseType == CASE_VEC4_CROP_SWIZZLE ||
1567*35238bceSAndroid Build Coastguard Worker m_caseType == CASE_VEC4_MIXED_SWIZZLE || m_caseType == CASE_INTERPOLATE_IVEC4 ||
1568*35238bceSAndroid Build Coastguard Worker m_caseType == CASE_INTERPOLATE_UVEC4 || m_caseType == CASE_INTERPOLATE_STRUCT_MEMBER)
1569*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "Test requires a GLES context");
1570*35238bceSAndroid Build Coastguard Worker }
1571*35238bceSAndroid Build Coastguard Worker
1572*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Trying to compile illegal shader, expecting compile to fail."
1573*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
1574*35238bceSAndroid Build Coastguard Worker }
1575*35238bceSAndroid Build Coastguard Worker
iterate(void)1576*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::IterateResult NegativeCompileInterpolationCase::iterate(void)
1577*35238bceSAndroid Build Coastguard Worker {
1578*35238bceSAndroid Build Coastguard Worker const std::string source = genShaderSource();
1579*35238bceSAndroid Build Coastguard Worker glu::Shader shader(m_context.getRenderContext(), glu::SHADERTYPE_FRAGMENT);
1580*35238bceSAndroid Build Coastguard Worker const char *const sourceStrPtr = source.c_str();
1581*35238bceSAndroid Build Coastguard Worker
1582*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Fragment shader source:" << tcu::TestLog::EndMessage
1583*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::KernelSource(source);
1584*35238bceSAndroid Build Coastguard Worker
1585*35238bceSAndroid Build Coastguard Worker shader.setSources(1, &sourceStrPtr, DE_NULL);
1586*35238bceSAndroid Build Coastguard Worker shader.compile();
1587*35238bceSAndroid Build Coastguard Worker
1588*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Info log:" << tcu::TestLog::EndMessage
1589*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::KernelSource(shader.getInfoLog());
1590*35238bceSAndroid Build Coastguard Worker
1591*35238bceSAndroid Build Coastguard Worker if (shader.getCompileStatus())
1592*35238bceSAndroid Build Coastguard Worker {
1593*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "ERROR: Illegal shader compiled successfully."
1594*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
1595*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected compile status");
1596*35238bceSAndroid Build Coastguard Worker }
1597*35238bceSAndroid Build Coastguard Worker else
1598*35238bceSAndroid Build Coastguard Worker {
1599*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Compile failed as expected." << tcu::TestLog::EndMessage;
1600*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1601*35238bceSAndroid Build Coastguard Worker }
1602*35238bceSAndroid Build Coastguard Worker return STOP;
1603*35238bceSAndroid Build Coastguard Worker }
1604*35238bceSAndroid Build Coastguard Worker
genShaderSource(void) const1605*35238bceSAndroid Build Coastguard Worker std::string NegativeCompileInterpolationCase::genShaderSource(void) const
1606*35238bceSAndroid Build Coastguard Worker {
1607*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
1608*35238bceSAndroid Build Coastguard Worker std::string interpolation;
1609*35238bceSAndroid Build Coastguard Worker const char *interpolationTemplate;
1610*35238bceSAndroid Build Coastguard Worker const char *description;
1611*35238bceSAndroid Build Coastguard Worker const char *globalDeclarations = "";
1612*35238bceSAndroid Build Coastguard Worker const char *localDeclarations = "";
1613*35238bceSAndroid Build Coastguard Worker const char *interpolationTarget = "";
1614*35238bceSAndroid Build Coastguard Worker const char *postSelector = "";
1615*35238bceSAndroid Build Coastguard Worker
1616*35238bceSAndroid Build Coastguard Worker switch (m_caseType)
1617*35238bceSAndroid Build Coastguard Worker {
1618*35238bceSAndroid Build Coastguard Worker case CASE_VEC4_IDENTITY_SWIZZLE:
1619*35238bceSAndroid Build Coastguard Worker globalDeclarations = "in highp vec4 v_var;\n";
1620*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var.xyzw";
1621*35238bceSAndroid Build Coastguard Worker description = "component selection is illegal";
1622*35238bceSAndroid Build Coastguard Worker break;
1623*35238bceSAndroid Build Coastguard Worker
1624*35238bceSAndroid Build Coastguard Worker case CASE_VEC4_CROP_SWIZZLE:
1625*35238bceSAndroid Build Coastguard Worker globalDeclarations = "in highp vec4 v_var;\n";
1626*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var.xy";
1627*35238bceSAndroid Build Coastguard Worker postSelector = ".x";
1628*35238bceSAndroid Build Coastguard Worker description = "component selection is illegal";
1629*35238bceSAndroid Build Coastguard Worker break;
1630*35238bceSAndroid Build Coastguard Worker
1631*35238bceSAndroid Build Coastguard Worker case CASE_VEC4_MIXED_SWIZZLE:
1632*35238bceSAndroid Build Coastguard Worker globalDeclarations = "in highp vec4 v_var;\n";
1633*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var.yzxw";
1634*35238bceSAndroid Build Coastguard Worker description = "component selection is illegal";
1635*35238bceSAndroid Build Coastguard Worker break;
1636*35238bceSAndroid Build Coastguard Worker
1637*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_IVEC4:
1638*35238bceSAndroid Build Coastguard Worker globalDeclarations = "flat in highp ivec4 v_var;\n";
1639*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var";
1640*35238bceSAndroid Build Coastguard Worker description = "no overload for ivec";
1641*35238bceSAndroid Build Coastguard Worker break;
1642*35238bceSAndroid Build Coastguard Worker
1643*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_UVEC4:
1644*35238bceSAndroid Build Coastguard Worker globalDeclarations = "flat in highp uvec4 v_var;\n";
1645*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var";
1646*35238bceSAndroid Build Coastguard Worker description = "no overload for uvec";
1647*35238bceSAndroid Build Coastguard Worker break;
1648*35238bceSAndroid Build Coastguard Worker
1649*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_ARRAY:
1650*35238bceSAndroid Build Coastguard Worker globalDeclarations = "in highp float v_var[2];\n";
1651*35238bceSAndroid Build Coastguard Worker interpolationTarget = "v_var";
1652*35238bceSAndroid Build Coastguard Worker postSelector = "[1]";
1653*35238bceSAndroid Build Coastguard Worker description = "no overload for arrays";
1654*35238bceSAndroid Build Coastguard Worker break;
1655*35238bceSAndroid Build Coastguard Worker
1656*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_STRUCT:
1657*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_STRUCT_MEMBER:
1658*35238bceSAndroid Build Coastguard Worker globalDeclarations = "struct S\n"
1659*35238bceSAndroid Build Coastguard Worker "{\n"
1660*35238bceSAndroid Build Coastguard Worker " highp float a;\n"
1661*35238bceSAndroid Build Coastguard Worker " highp float b;\n"
1662*35238bceSAndroid Build Coastguard Worker "};\n"
1663*35238bceSAndroid Build Coastguard Worker "in S v_var;\n";
1664*35238bceSAndroid Build Coastguard Worker
1665*35238bceSAndroid Build Coastguard Worker interpolationTarget = (m_caseType == CASE_INTERPOLATE_STRUCT) ? ("v_var") : ("v_var.a");
1666*35238bceSAndroid Build Coastguard Worker postSelector = (m_caseType == CASE_INTERPOLATE_STRUCT) ? (".a") : ("");
1667*35238bceSAndroid Build Coastguard Worker description = (m_caseType == CASE_INTERPOLATE_STRUCT) ?
1668*35238bceSAndroid Build Coastguard Worker ("no overload for this type") :
1669*35238bceSAndroid Build Coastguard Worker ("<interpolant> is not an input variable (just a member of)");
1670*35238bceSAndroid Build Coastguard Worker break;
1671*35238bceSAndroid Build Coastguard Worker
1672*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_LOCAL:
1673*35238bceSAndroid Build Coastguard Worker localDeclarations = " highp vec4 local_var = gl_FragCoord;\n";
1674*35238bceSAndroid Build Coastguard Worker interpolationTarget = "local_var";
1675*35238bceSAndroid Build Coastguard Worker description = "<interpolant> is not an input variable";
1676*35238bceSAndroid Build Coastguard Worker break;
1677*35238bceSAndroid Build Coastguard Worker
1678*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_GLOBAL:
1679*35238bceSAndroid Build Coastguard Worker globalDeclarations = "highp vec4 global_var;\n";
1680*35238bceSAndroid Build Coastguard Worker localDeclarations = " global_var = gl_FragCoord;\n";
1681*35238bceSAndroid Build Coastguard Worker interpolationTarget = "global_var";
1682*35238bceSAndroid Build Coastguard Worker description = "<interpolant> is not an input variable";
1683*35238bceSAndroid Build Coastguard Worker break;
1684*35238bceSAndroid Build Coastguard Worker
1685*35238bceSAndroid Build Coastguard Worker case CASE_INTERPOLATE_CONSTANT:
1686*35238bceSAndroid Build Coastguard Worker globalDeclarations = "const highp vec4 const_var = vec4(0.2);\n";
1687*35238bceSAndroid Build Coastguard Worker interpolationTarget = "const_var";
1688*35238bceSAndroid Build Coastguard Worker description = "<interpolant> is not an input variable";
1689*35238bceSAndroid Build Coastguard Worker break;
1690*35238bceSAndroid Build Coastguard Worker
1691*35238bceSAndroid Build Coastguard Worker default:
1692*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1693*35238bceSAndroid Build Coastguard Worker return "";
1694*35238bceSAndroid Build Coastguard Worker }
1695*35238bceSAndroid Build Coastguard Worker
1696*35238bceSAndroid Build Coastguard Worker switch (m_interpolation)
1697*35238bceSAndroid Build Coastguard Worker {
1698*35238bceSAndroid Build Coastguard Worker case INTERPOLATE_AT_SAMPLE:
1699*35238bceSAndroid Build Coastguard Worker interpolationTemplate = "interpolateAtSample(${TARGET}, 0)${POST_SELECTOR}";
1700*35238bceSAndroid Build Coastguard Worker break;
1701*35238bceSAndroid Build Coastguard Worker
1702*35238bceSAndroid Build Coastguard Worker case INTERPOLATE_AT_CENTROID:
1703*35238bceSAndroid Build Coastguard Worker interpolationTemplate = "interpolateAtCentroid(${TARGET})${POST_SELECTOR}";
1704*35238bceSAndroid Build Coastguard Worker break;
1705*35238bceSAndroid Build Coastguard Worker
1706*35238bceSAndroid Build Coastguard Worker case INTERPOLATE_AT_OFFSET:
1707*35238bceSAndroid Build Coastguard Worker interpolationTemplate = "interpolateAtOffset(${TARGET}, vec2(0.2, 0.2))${POST_SELECTOR}";
1708*35238bceSAndroid Build Coastguard Worker break;
1709*35238bceSAndroid Build Coastguard Worker
1710*35238bceSAndroid Build Coastguard Worker default:
1711*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
1712*35238bceSAndroid Build Coastguard Worker return "";
1713*35238bceSAndroid Build Coastguard Worker }
1714*35238bceSAndroid Build Coastguard Worker
1715*35238bceSAndroid Build Coastguard Worker {
1716*35238bceSAndroid Build Coastguard Worker std::map<std::string, std::string> args;
1717*35238bceSAndroid Build Coastguard Worker args["TARGET"] = interpolationTarget;
1718*35238bceSAndroid Build Coastguard Worker args["POST_SELECTOR"] = postSelector;
1719*35238bceSAndroid Build Coastguard Worker
1720*35238bceSAndroid Build Coastguard Worker interpolation = tcu::StringTemplate(interpolationTemplate).specialize(args);
1721*35238bceSAndroid Build Coastguard Worker }
1722*35238bceSAndroid Build Coastguard Worker
1723*35238bceSAndroid Build Coastguard Worker buf << glu::getGLSLVersionDeclaration(glu::getContextTypeGLSLVersion(m_context.getRenderContext().getType()))
1724*35238bceSAndroid Build Coastguard Worker << "\n"
1725*35238bceSAndroid Build Coastguard Worker << "${GLSL_EXT_SHADER_MULTISAMPLE_INTERPOLATION}" << globalDeclarations
1726*35238bceSAndroid Build Coastguard Worker << "layout(location = 0) out mediump vec4 fragColor;\n"
1727*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
1728*35238bceSAndroid Build Coastguard Worker "{\n"
1729*35238bceSAndroid Build Coastguard Worker << localDeclarations << " fragColor = vec4(" << interpolation << "); // " << description
1730*35238bceSAndroid Build Coastguard Worker << "\n"
1731*35238bceSAndroid Build Coastguard Worker "}\n";
1732*35238bceSAndroid Build Coastguard Worker
1733*35238bceSAndroid Build Coastguard Worker return specializeShader(buf.str(), m_context.getRenderContext().getType());
1734*35238bceSAndroid Build Coastguard Worker }
1735*35238bceSAndroid Build Coastguard Worker
1736*35238bceSAndroid Build Coastguard Worker } // namespace
1737*35238bceSAndroid Build Coastguard Worker
ShaderMultisampleInterpolationTests(Context & context)1738*35238bceSAndroid Build Coastguard Worker ShaderMultisampleInterpolationTests::ShaderMultisampleInterpolationTests(Context &context)
1739*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "multisample_interpolation", "Test multisample interpolation")
1740*35238bceSAndroid Build Coastguard Worker {
1741*35238bceSAndroid Build Coastguard Worker }
1742*35238bceSAndroid Build Coastguard Worker
~ShaderMultisampleInterpolationTests(void)1743*35238bceSAndroid Build Coastguard Worker ShaderMultisampleInterpolationTests::~ShaderMultisampleInterpolationTests(void)
1744*35238bceSAndroid Build Coastguard Worker {
1745*35238bceSAndroid Build Coastguard Worker }
1746*35238bceSAndroid Build Coastguard Worker
init(void)1747*35238bceSAndroid Build Coastguard Worker void ShaderMultisampleInterpolationTests::init(void)
1748*35238bceSAndroid Build Coastguard Worker {
1749*35238bceSAndroid Build Coastguard Worker using namespace MultisampleShaderRenderUtil;
1750*35238bceSAndroid Build Coastguard Worker
1751*35238bceSAndroid Build Coastguard Worker static const struct RenderTarget
1752*35238bceSAndroid Build Coastguard Worker {
1753*35238bceSAndroid Build Coastguard Worker const char *name;
1754*35238bceSAndroid Build Coastguard Worker const char *desc;
1755*35238bceSAndroid Build Coastguard Worker int numSamples;
1756*35238bceSAndroid Build Coastguard Worker MultisampleRenderCase::RenderTarget target;
1757*35238bceSAndroid Build Coastguard Worker } targets[] = {
1758*35238bceSAndroid Build Coastguard Worker {"default_framebuffer", "Test with default framebuffer", 0, MultisampleRenderCase::TARGET_DEFAULT},
1759*35238bceSAndroid Build Coastguard Worker {"singlesample_texture", "Test with singlesample texture", 0, MultisampleRenderCase::TARGET_TEXTURE},
1760*35238bceSAndroid Build Coastguard Worker {"multisample_texture_1", "Test with multisample texture", 1, MultisampleRenderCase::TARGET_TEXTURE},
1761*35238bceSAndroid Build Coastguard Worker {"multisample_texture_2", "Test with multisample texture", 2, MultisampleRenderCase::TARGET_TEXTURE},
1762*35238bceSAndroid Build Coastguard Worker {"multisample_texture_4", "Test with multisample texture", 4, MultisampleRenderCase::TARGET_TEXTURE},
1763*35238bceSAndroid Build Coastguard Worker {"multisample_texture_8", "Test with multisample texture", 8, MultisampleRenderCase::TARGET_TEXTURE},
1764*35238bceSAndroid Build Coastguard Worker {"multisample_texture_16", "Test with multisample texture", 16, MultisampleRenderCase::TARGET_TEXTURE},
1765*35238bceSAndroid Build Coastguard Worker {"singlesample_rbo", "Test with singlesample rbo", 0, MultisampleRenderCase::TARGET_RENDERBUFFER},
1766*35238bceSAndroid Build Coastguard Worker {"multisample_rbo_1", "Test with multisample rbo", 1, MultisampleRenderCase::TARGET_RENDERBUFFER},
1767*35238bceSAndroid Build Coastguard Worker {"multisample_rbo_2", "Test with multisample rbo", 2, MultisampleRenderCase::TARGET_RENDERBUFFER},
1768*35238bceSAndroid Build Coastguard Worker {"multisample_rbo_4", "Test with multisample rbo", 4, MultisampleRenderCase::TARGET_RENDERBUFFER},
1769*35238bceSAndroid Build Coastguard Worker {"multisample_rbo_8", "Test with multisample rbo", 8, MultisampleRenderCase::TARGET_RENDERBUFFER},
1770*35238bceSAndroid Build Coastguard Worker {"multisample_rbo_16", "Test with multisample rbo", 16, MultisampleRenderCase::TARGET_RENDERBUFFER},
1771*35238bceSAndroid Build Coastguard Worker };
1772*35238bceSAndroid Build Coastguard Worker
1773*35238bceSAndroid Build Coastguard Worker static const struct
1774*35238bceSAndroid Build Coastguard Worker {
1775*35238bceSAndroid Build Coastguard Worker const char *name;
1776*35238bceSAndroid Build Coastguard Worker const char *description;
1777*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::CaseType caseType;
1778*35238bceSAndroid Build Coastguard Worker } negativeCompileCases[] = {
1779*35238bceSAndroid Build Coastguard Worker {"vec4_identity_swizzle", "use identity swizzle", NegativeCompileInterpolationCase::CASE_VEC4_IDENTITY_SWIZZLE},
1780*35238bceSAndroid Build Coastguard Worker {"vec4_crop_swizzle", "use cropped identity swizzle", NegativeCompileInterpolationCase::CASE_VEC4_CROP_SWIZZLE},
1781*35238bceSAndroid Build Coastguard Worker {"vec4_mixed_swizzle", "use swizzle", NegativeCompileInterpolationCase::CASE_VEC4_MIXED_SWIZZLE},
1782*35238bceSAndroid Build Coastguard Worker {"interpolate_ivec4", "interpolate integer variable", NegativeCompileInterpolationCase::CASE_INTERPOLATE_IVEC4},
1783*35238bceSAndroid Build Coastguard Worker {"interpolate_uvec4", "interpolate integer variable", NegativeCompileInterpolationCase::CASE_INTERPOLATE_UVEC4},
1784*35238bceSAndroid Build Coastguard Worker {"interpolate_array", "interpolate whole array", NegativeCompileInterpolationCase::CASE_INTERPOLATE_ARRAY},
1785*35238bceSAndroid Build Coastguard Worker {"interpolate_struct", "interpolate whole struct", NegativeCompileInterpolationCase::CASE_INTERPOLATE_STRUCT},
1786*35238bceSAndroid Build Coastguard Worker {"interpolate_struct_member", "interpolate struct member",
1787*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::CASE_INTERPOLATE_STRUCT_MEMBER},
1788*35238bceSAndroid Build Coastguard Worker {"interpolate_local", "interpolate local variable", NegativeCompileInterpolationCase::CASE_INTERPOLATE_LOCAL},
1789*35238bceSAndroid Build Coastguard Worker {"interpolate_global", "interpolate global variable",
1790*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::CASE_INTERPOLATE_GLOBAL},
1791*35238bceSAndroid Build Coastguard Worker {"interpolate_constant", "interpolate constant variable",
1792*35238bceSAndroid Build Coastguard Worker NegativeCompileInterpolationCase::CASE_INTERPOLATE_CONSTANT},
1793*35238bceSAndroid Build Coastguard Worker };
1794*35238bceSAndroid Build Coastguard Worker
1795*35238bceSAndroid Build Coastguard Worker // .sample_qualifier
1796*35238bceSAndroid Build Coastguard Worker {
1797*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const sampleQualifierGroup =
1798*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "sample_qualifier", "Test sample qualifier");
1799*35238bceSAndroid Build Coastguard Worker addChild(sampleQualifierGroup);
1800*35238bceSAndroid Build Coastguard Worker
1801*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1802*35238bceSAndroid Build Coastguard Worker sampleQualifierGroup->addChild(
1803*35238bceSAndroid Build Coastguard Worker new SampleQualifierRenderCase(m_context, targets[targetNdx].name, targets[targetNdx].desc,
1804*35238bceSAndroid Build Coastguard Worker targets[targetNdx].numSamples, targets[targetNdx].target));
1805*35238bceSAndroid Build Coastguard Worker }
1806*35238bceSAndroid Build Coastguard Worker
1807*35238bceSAndroid Build Coastguard Worker // .interpolate_at_sample
1808*35238bceSAndroid Build Coastguard Worker {
1809*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const interpolateAtSampleGroup =
1810*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "interpolate_at_sample", "Test interpolateAtSample");
1811*35238bceSAndroid Build Coastguard Worker addChild(interpolateAtSampleGroup);
1812*35238bceSAndroid Build Coastguard Worker
1813*35238bceSAndroid Build Coastguard Worker // .static_sample_number
1814*35238bceSAndroid Build Coastguard Worker {
1815*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1816*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "static_sample_number", "Test interpolateAtSample sample number");
1817*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1818*35238bceSAndroid Build Coastguard Worker
1819*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1820*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtSampleRenderCase(
1821*35238bceSAndroid Build Coastguard Worker m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples,
1822*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target, InterpolateAtSampleRenderCase::INDEXING_STATIC));
1823*35238bceSAndroid Build Coastguard Worker }
1824*35238bceSAndroid Build Coastguard Worker
1825*35238bceSAndroid Build Coastguard Worker // .dynamic_sample_number
1826*35238bceSAndroid Build Coastguard Worker {
1827*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1828*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "dynamic_sample_number", "Test interpolateAtSample sample number");
1829*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1830*35238bceSAndroid Build Coastguard Worker
1831*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1832*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtSampleRenderCase(
1833*35238bceSAndroid Build Coastguard Worker m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples,
1834*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target, InterpolateAtSampleRenderCase::INDEXING_DYNAMIC));
1835*35238bceSAndroid Build Coastguard Worker }
1836*35238bceSAndroid Build Coastguard Worker
1837*35238bceSAndroid Build Coastguard Worker // .non_multisample_buffer
1838*35238bceSAndroid Build Coastguard Worker {
1839*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group = new tcu::TestCaseGroup(
1840*35238bceSAndroid Build Coastguard Worker m_testCtx, "non_multisample_buffer", "Test interpolateAtSample with non-multisample buffers");
1841*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1842*35238bceSAndroid Build Coastguard Worker
1843*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1844*35238bceSAndroid Build Coastguard Worker if (targets[targetNdx].numSamples == 0)
1845*35238bceSAndroid Build Coastguard Worker group->addChild(new SingleSampleInterpolateAtSampleCase(
1846*35238bceSAndroid Build Coastguard Worker m_context, std::string("sample_0_").append(targets[targetNdx].name).c_str(),
1847*35238bceSAndroid Build Coastguard Worker targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target,
1848*35238bceSAndroid Build Coastguard Worker SingleSampleInterpolateAtSampleCase::SAMPLE_0));
1849*35238bceSAndroid Build Coastguard Worker
1850*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1851*35238bceSAndroid Build Coastguard Worker if (targets[targetNdx].numSamples == 0)
1852*35238bceSAndroid Build Coastguard Worker group->addChild(new SingleSampleInterpolateAtSampleCase(
1853*35238bceSAndroid Build Coastguard Worker m_context, std::string("sample_n_").append(targets[targetNdx].name).c_str(),
1854*35238bceSAndroid Build Coastguard Worker targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target,
1855*35238bceSAndroid Build Coastguard Worker SingleSampleInterpolateAtSampleCase::SAMPLE_N));
1856*35238bceSAndroid Build Coastguard Worker }
1857*35238bceSAndroid Build Coastguard Worker
1858*35238bceSAndroid Build Coastguard Worker // .centroid_qualifier
1859*35238bceSAndroid Build Coastguard Worker {
1860*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group = new tcu::TestCaseGroup(
1861*35238bceSAndroid Build Coastguard Worker m_testCtx, "centroid_qualified", "Test interpolateAtSample with centroid qualified varying");
1862*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1863*35238bceSAndroid Build Coastguard Worker
1864*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1865*35238bceSAndroid Build Coastguard Worker group->addChild(
1866*35238bceSAndroid Build Coastguard Worker new CentroidQualifierAtSampleCase(m_context, targets[targetNdx].name, targets[targetNdx].desc,
1867*35238bceSAndroid Build Coastguard Worker targets[targetNdx].numSamples, targets[targetNdx].target));
1868*35238bceSAndroid Build Coastguard Worker }
1869*35238bceSAndroid Build Coastguard Worker
1870*35238bceSAndroid Build Coastguard Worker // .at_sample_id
1871*35238bceSAndroid Build Coastguard Worker {
1872*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1873*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "at_sample_id", "Test interpolateAtSample at current sample id");
1874*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1875*35238bceSAndroid Build Coastguard Worker
1876*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1877*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtSampleIDCase(m_context, targets[targetNdx].name,
1878*35238bceSAndroid Build Coastguard Worker targets[targetNdx].desc, targets[targetNdx].numSamples,
1879*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target));
1880*35238bceSAndroid Build Coastguard Worker }
1881*35238bceSAndroid Build Coastguard Worker
1882*35238bceSAndroid Build Coastguard Worker // .negative
1883*35238bceSAndroid Build Coastguard Worker {
1884*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1885*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "negative", "interpolateAtSample negative tests");
1886*35238bceSAndroid Build Coastguard Worker interpolateAtSampleGroup->addChild(group);
1887*35238bceSAndroid Build Coastguard Worker
1888*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(negativeCompileCases); ++ndx)
1889*35238bceSAndroid Build Coastguard Worker group->addChild(new NegativeCompileInterpolationCase(
1890*35238bceSAndroid Build Coastguard Worker m_context, negativeCompileCases[ndx].name, negativeCompileCases[ndx].description,
1891*35238bceSAndroid Build Coastguard Worker negativeCompileCases[ndx].caseType, NegativeCompileInterpolationCase::INTERPOLATE_AT_SAMPLE));
1892*35238bceSAndroid Build Coastguard Worker }
1893*35238bceSAndroid Build Coastguard Worker }
1894*35238bceSAndroid Build Coastguard Worker
1895*35238bceSAndroid Build Coastguard Worker // .interpolate_at_centroid
1896*35238bceSAndroid Build Coastguard Worker {
1897*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const methodGroup =
1898*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "interpolate_at_centroid", "Test interpolateAtCentroid");
1899*35238bceSAndroid Build Coastguard Worker addChild(methodGroup);
1900*35238bceSAndroid Build Coastguard Worker
1901*35238bceSAndroid Build Coastguard Worker // .consistency
1902*35238bceSAndroid Build Coastguard Worker {
1903*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group = new tcu::TestCaseGroup(
1904*35238bceSAndroid Build Coastguard Worker m_testCtx, "consistency",
1905*35238bceSAndroid Build Coastguard Worker "Test interpolateAtCentroid return value is consistent to centroid qualified value");
1906*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1907*35238bceSAndroid Build Coastguard Worker
1908*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1909*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtCentroidCase(
1910*35238bceSAndroid Build Coastguard Worker m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples,
1911*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target, InterpolateAtCentroidCase::TEST_CONSISTENCY));
1912*35238bceSAndroid Build Coastguard Worker }
1913*35238bceSAndroid Build Coastguard Worker
1914*35238bceSAndroid Build Coastguard Worker // .array_element
1915*35238bceSAndroid Build Coastguard Worker {
1916*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1917*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "array_element", "Test interpolateAtCentroid with array element");
1918*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1919*35238bceSAndroid Build Coastguard Worker
1920*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1921*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtCentroidCase(
1922*35238bceSAndroid Build Coastguard Worker m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples,
1923*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target, InterpolateAtCentroidCase::TEST_ARRAY_ELEMENT));
1924*35238bceSAndroid Build Coastguard Worker }
1925*35238bceSAndroid Build Coastguard Worker
1926*35238bceSAndroid Build Coastguard Worker // .negative
1927*35238bceSAndroid Build Coastguard Worker {
1928*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1929*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "negative", "interpolateAtCentroid negative tests");
1930*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1931*35238bceSAndroid Build Coastguard Worker
1932*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(negativeCompileCases); ++ndx)
1933*35238bceSAndroid Build Coastguard Worker group->addChild(new NegativeCompileInterpolationCase(
1934*35238bceSAndroid Build Coastguard Worker m_context, negativeCompileCases[ndx].name, negativeCompileCases[ndx].description,
1935*35238bceSAndroid Build Coastguard Worker negativeCompileCases[ndx].caseType, NegativeCompileInterpolationCase::INTERPOLATE_AT_CENTROID));
1936*35238bceSAndroid Build Coastguard Worker }
1937*35238bceSAndroid Build Coastguard Worker }
1938*35238bceSAndroid Build Coastguard Worker
1939*35238bceSAndroid Build Coastguard Worker // .interpolate_at_offset
1940*35238bceSAndroid Build Coastguard Worker {
1941*35238bceSAndroid Build Coastguard Worker static const struct TestConfig
1942*35238bceSAndroid Build Coastguard Worker {
1943*35238bceSAndroid Build Coastguard Worker const char *name;
1944*35238bceSAndroid Build Coastguard Worker InterpolateAtOffsetCase::TestType type;
1945*35238bceSAndroid Build Coastguard Worker } configs[] = {
1946*35238bceSAndroid Build Coastguard Worker {"no_qualifiers", InterpolateAtOffsetCase::TEST_QUALIFIER_NONE},
1947*35238bceSAndroid Build Coastguard Worker {"centroid_qualifier", InterpolateAtOffsetCase::TEST_QUALIFIER_CENTROID},
1948*35238bceSAndroid Build Coastguard Worker {"sample_qualifier", InterpolateAtOffsetCase::TEST_QUALIFIER_SAMPLE},
1949*35238bceSAndroid Build Coastguard Worker };
1950*35238bceSAndroid Build Coastguard Worker
1951*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const methodGroup =
1952*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "interpolate_at_offset", "Test interpolateAtOffset");
1953*35238bceSAndroid Build Coastguard Worker addChild(methodGroup);
1954*35238bceSAndroid Build Coastguard Worker
1955*35238bceSAndroid Build Coastguard Worker // .no_qualifiers
1956*35238bceSAndroid Build Coastguard Worker // .centroid_qualifier
1957*35238bceSAndroid Build Coastguard Worker // .sample_qualifier
1958*35238bceSAndroid Build Coastguard Worker for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(configs); ++configNdx)
1959*35238bceSAndroid Build Coastguard Worker {
1960*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const qualifierGroup = new tcu::TestCaseGroup(
1961*35238bceSAndroid Build Coastguard Worker m_testCtx, configs[configNdx].name, "Test interpolateAtOffset with qualified/non-qualified varying");
1962*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(qualifierGroup);
1963*35238bceSAndroid Build Coastguard Worker
1964*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1965*35238bceSAndroid Build Coastguard Worker qualifierGroup->addChild(new InterpolateAtOffsetCase(
1966*35238bceSAndroid Build Coastguard Worker m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples,
1967*35238bceSAndroid Build Coastguard Worker targets[targetNdx].target, configs[configNdx].type));
1968*35238bceSAndroid Build Coastguard Worker }
1969*35238bceSAndroid Build Coastguard Worker
1970*35238bceSAndroid Build Coastguard Worker // .at_sample_position
1971*35238bceSAndroid Build Coastguard Worker {
1972*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1973*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "at_sample_position", "Test interpolateAtOffset at sample position");
1974*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1975*35238bceSAndroid Build Coastguard Worker
1976*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1977*35238bceSAndroid Build Coastguard Worker group->addChild(
1978*35238bceSAndroid Build Coastguard Worker new InterpolateAtSamplePositionCase(m_context, targets[targetNdx].name, targets[targetNdx].desc,
1979*35238bceSAndroid Build Coastguard Worker targets[targetNdx].numSamples, targets[targetNdx].target));
1980*35238bceSAndroid Build Coastguard Worker }
1981*35238bceSAndroid Build Coastguard Worker
1982*35238bceSAndroid Build Coastguard Worker // .array_element
1983*35238bceSAndroid Build Coastguard Worker {
1984*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1985*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "array_element", "Test interpolateAtOffset with array element");
1986*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1987*35238bceSAndroid Build Coastguard Worker
1988*35238bceSAndroid Build Coastguard Worker for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
1989*35238bceSAndroid Build Coastguard Worker group->addChild(new InterpolateAtOffsetCase(m_context, targets[targetNdx].name, targets[targetNdx].desc,
1990*35238bceSAndroid Build Coastguard Worker targets[targetNdx].numSamples, targets[targetNdx].target,
1991*35238bceSAndroid Build Coastguard Worker InterpolateAtOffsetCase::TEST_ARRAY_ELEMENT));
1992*35238bceSAndroid Build Coastguard Worker }
1993*35238bceSAndroid Build Coastguard Worker
1994*35238bceSAndroid Build Coastguard Worker // .negative
1995*35238bceSAndroid Build Coastguard Worker {
1996*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const group =
1997*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "negative", "interpolateAtOffset negative tests");
1998*35238bceSAndroid Build Coastguard Worker methodGroup->addChild(group);
1999*35238bceSAndroid Build Coastguard Worker
2000*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(negativeCompileCases); ++ndx)
2001*35238bceSAndroid Build Coastguard Worker group->addChild(new NegativeCompileInterpolationCase(
2002*35238bceSAndroid Build Coastguard Worker m_context, negativeCompileCases[ndx].name, negativeCompileCases[ndx].description,
2003*35238bceSAndroid Build Coastguard Worker negativeCompileCases[ndx].caseType, NegativeCompileInterpolationCase::INTERPOLATE_AT_OFFSET));
2004*35238bceSAndroid Build Coastguard Worker }
2005*35238bceSAndroid Build Coastguard Worker }
2006*35238bceSAndroid Build Coastguard Worker }
2007*35238bceSAndroid Build Coastguard Worker
2008*35238bceSAndroid Build Coastguard Worker } // namespace Functional
2009*35238bceSAndroid Build Coastguard Worker } // namespace gles31
2010*35238bceSAndroid Build Coastguard Worker } // namespace deqp
2011