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 Sample shading tests
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es31fSampleShadingTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "es31fMultisampleShaderRenderCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "glsStateQueryUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluCallLogWrapper.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "gluContextInfo.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
38*35238bceSAndroid Build Coastguard Worker
39*35238bceSAndroid Build Coastguard Worker #include <map>
40*35238bceSAndroid Build Coastguard Worker
41*35238bceSAndroid Build Coastguard Worker namespace deqp
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker namespace gles31
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker namespace Functional
46*35238bceSAndroid Build Coastguard Worker {
47*35238bceSAndroid Build Coastguard Worker namespace
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker
checkSupport(Context & ctx)50*35238bceSAndroid Build Coastguard Worker static bool checkSupport(Context &ctx)
51*35238bceSAndroid Build Coastguard Worker {
52*35238bceSAndroid Build Coastguard Worker auto contextType = ctx.getRenderContext().getType();
53*35238bceSAndroid Build Coastguard Worker return contextSupports(contextType, glu::ApiType::es(3, 2)) ||
54*35238bceSAndroid Build Coastguard Worker contextSupports(contextType, glu::ApiType::core(4, 5)) ||
55*35238bceSAndroid Build Coastguard Worker ctx.getContextInfo().isExtensionSupported("GL_OES_sample_shading");
56*35238bceSAndroid Build Coastguard Worker }
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker using namespace gls::StateQueryUtil;
59*35238bceSAndroid Build Coastguard Worker
60*35238bceSAndroid Build Coastguard Worker class SampleShadingStateCase : public TestCase
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker public:
63*35238bceSAndroid Build Coastguard Worker SampleShadingStateCase(Context &ctx, const char *name, const char *desc, QueryType);
64*35238bceSAndroid Build Coastguard Worker
65*35238bceSAndroid Build Coastguard Worker void init(void);
66*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
67*35238bceSAndroid Build Coastguard Worker
68*35238bceSAndroid Build Coastguard Worker private:
69*35238bceSAndroid Build Coastguard Worker const QueryType m_verifier;
70*35238bceSAndroid Build Coastguard Worker };
71*35238bceSAndroid Build Coastguard Worker
SampleShadingStateCase(Context & ctx,const char * name,const char * desc,QueryType type)72*35238bceSAndroid Build Coastguard Worker SampleShadingStateCase::SampleShadingStateCase(Context &ctx, const char *name, const char *desc, QueryType type)
73*35238bceSAndroid Build Coastguard Worker : TestCase(ctx, name, desc)
74*35238bceSAndroid Build Coastguard Worker , m_verifier(type)
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker }
77*35238bceSAndroid Build Coastguard Worker
init(void)78*35238bceSAndroid Build Coastguard Worker void SampleShadingStateCase::init(void)
79*35238bceSAndroid Build Coastguard Worker {
80*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context))
81*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(
82*35238bceSAndroid Build Coastguard Worker "Test requires GL_OES_sample_shading extension or a context version 3.2 or higher.");
83*35238bceSAndroid Build Coastguard Worker }
84*35238bceSAndroid Build Coastguard Worker
iterate(void)85*35238bceSAndroid Build Coastguard Worker SampleShadingStateCase::IterateResult SampleShadingStateCase::iterate(void)
86*35238bceSAndroid Build Coastguard Worker {
87*35238bceSAndroid Build Coastguard Worker glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
88*35238bceSAndroid Build Coastguard Worker tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
89*35238bceSAndroid Build Coastguard Worker gl.enableLogging(true);
90*35238bceSAndroid Build Coastguard Worker
91*35238bceSAndroid Build Coastguard Worker // initial
92*35238bceSAndroid Build Coastguard Worker {
93*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying initial value" << tcu::TestLog::EndMessage;
94*35238bceSAndroid Build Coastguard Worker verifyStateBoolean(result, gl, GL_SAMPLE_SHADING, false, m_verifier);
95*35238bceSAndroid Build Coastguard Worker }
96*35238bceSAndroid Build Coastguard Worker
97*35238bceSAndroid Build Coastguard Worker // true and false too
98*35238bceSAndroid Build Coastguard Worker {
99*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying random values" << tcu::TestLog::EndMessage;
100*35238bceSAndroid Build Coastguard Worker
101*35238bceSAndroid Build Coastguard Worker gl.glEnable(GL_SAMPLE_SHADING);
102*35238bceSAndroid Build Coastguard Worker verifyStateBoolean(result, gl, GL_SAMPLE_SHADING, true, m_verifier);
103*35238bceSAndroid Build Coastguard Worker
104*35238bceSAndroid Build Coastguard Worker gl.glDisable(GL_SAMPLE_SHADING);
105*35238bceSAndroid Build Coastguard Worker verifyStateBoolean(result, gl, GL_SAMPLE_SHADING, false, m_verifier);
106*35238bceSAndroid Build Coastguard Worker }
107*35238bceSAndroid Build Coastguard Worker
108*35238bceSAndroid Build Coastguard Worker result.setTestContextResult(m_testCtx);
109*35238bceSAndroid Build Coastguard Worker return STOP;
110*35238bceSAndroid Build Coastguard Worker }
111*35238bceSAndroid Build Coastguard Worker
112*35238bceSAndroid Build Coastguard Worker class MinSampleShadingValueCase : public TestCase
113*35238bceSAndroid Build Coastguard Worker {
114*35238bceSAndroid Build Coastguard Worker public:
115*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueCase(Context &ctx, const char *name, const char *desc, QueryType);
116*35238bceSAndroid Build Coastguard Worker
117*35238bceSAndroid Build Coastguard Worker void init(void);
118*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
119*35238bceSAndroid Build Coastguard Worker
120*35238bceSAndroid Build Coastguard Worker private:
121*35238bceSAndroid Build Coastguard Worker const QueryType m_verifier;
122*35238bceSAndroid Build Coastguard Worker };
123*35238bceSAndroid Build Coastguard Worker
MinSampleShadingValueCase(Context & ctx,const char * name,const char * desc,QueryType type)124*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueCase::MinSampleShadingValueCase(Context &ctx, const char *name, const char *desc, QueryType type)
125*35238bceSAndroid Build Coastguard Worker : TestCase(ctx, name, desc)
126*35238bceSAndroid Build Coastguard Worker , m_verifier(type)
127*35238bceSAndroid Build Coastguard Worker {
128*35238bceSAndroid Build Coastguard Worker }
129*35238bceSAndroid Build Coastguard Worker
init(void)130*35238bceSAndroid Build Coastguard Worker void MinSampleShadingValueCase::init(void)
131*35238bceSAndroid Build Coastguard Worker {
132*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context))
133*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(
134*35238bceSAndroid Build Coastguard Worker "Test requires GL_OES_sample_shading extension or a context version 3.2 or higher.");
135*35238bceSAndroid Build Coastguard Worker }
136*35238bceSAndroid Build Coastguard Worker
iterate(void)137*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueCase::IterateResult MinSampleShadingValueCase::iterate(void)
138*35238bceSAndroid Build Coastguard Worker {
139*35238bceSAndroid Build Coastguard Worker glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
140*35238bceSAndroid Build Coastguard Worker tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
141*35238bceSAndroid Build Coastguard Worker
142*35238bceSAndroid Build Coastguard Worker gl.enableLogging(true);
143*35238bceSAndroid Build Coastguard Worker
144*35238bceSAndroid Build Coastguard Worker // initial
145*35238bceSAndroid Build Coastguard Worker {
146*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying initial value" << tcu::TestLog::EndMessage;
147*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.0, m_verifier);
148*35238bceSAndroid Build Coastguard Worker }
149*35238bceSAndroid Build Coastguard Worker
150*35238bceSAndroid Build Coastguard Worker // special values
151*35238bceSAndroid Build Coastguard Worker {
152*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying special values" << tcu::TestLog::EndMessage;
153*35238bceSAndroid Build Coastguard Worker
154*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(0.0f);
155*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.0, m_verifier);
156*35238bceSAndroid Build Coastguard Worker
157*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(1.0f);
158*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 1.0, m_verifier);
159*35238bceSAndroid Build Coastguard Worker
160*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(0.5f);
161*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.5, m_verifier);
162*35238bceSAndroid Build Coastguard Worker }
163*35238bceSAndroid Build Coastguard Worker
164*35238bceSAndroid Build Coastguard Worker // random values
165*35238bceSAndroid Build Coastguard Worker {
166*35238bceSAndroid Build Coastguard Worker const int numRandomTests = 10;
167*35238bceSAndroid Build Coastguard Worker de::Random rnd(0xde123);
168*35238bceSAndroid Build Coastguard Worker
169*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying random values" << tcu::TestLog::EndMessage;
170*35238bceSAndroid Build Coastguard Worker
171*35238bceSAndroid Build Coastguard Worker for (int randNdx = 0; randNdx < numRandomTests; ++randNdx)
172*35238bceSAndroid Build Coastguard Worker {
173*35238bceSAndroid Build Coastguard Worker const float value = rnd.getFloat();
174*35238bceSAndroid Build Coastguard Worker
175*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(value);
176*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, value, m_verifier);
177*35238bceSAndroid Build Coastguard Worker }
178*35238bceSAndroid Build Coastguard Worker }
179*35238bceSAndroid Build Coastguard Worker
180*35238bceSAndroid Build Coastguard Worker result.setTestContextResult(m_testCtx);
181*35238bceSAndroid Build Coastguard Worker return STOP;
182*35238bceSAndroid Build Coastguard Worker }
183*35238bceSAndroid Build Coastguard Worker
184*35238bceSAndroid Build Coastguard Worker class MinSampleShadingValueClampingCase : public TestCase
185*35238bceSAndroid Build Coastguard Worker {
186*35238bceSAndroid Build Coastguard Worker public:
187*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueClampingCase(Context &ctx, const char *name, const char *desc);
188*35238bceSAndroid Build Coastguard Worker
189*35238bceSAndroid Build Coastguard Worker void init(void);
190*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
191*35238bceSAndroid Build Coastguard Worker };
192*35238bceSAndroid Build Coastguard Worker
MinSampleShadingValueClampingCase(Context & ctx,const char * name,const char * desc)193*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueClampingCase::MinSampleShadingValueClampingCase(Context &ctx, const char *name, const char *desc)
194*35238bceSAndroid Build Coastguard Worker : TestCase(ctx, name, desc)
195*35238bceSAndroid Build Coastguard Worker {
196*35238bceSAndroid Build Coastguard Worker }
197*35238bceSAndroid Build Coastguard Worker
init(void)198*35238bceSAndroid Build Coastguard Worker void MinSampleShadingValueClampingCase::init(void)
199*35238bceSAndroid Build Coastguard Worker {
200*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context))
201*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(
202*35238bceSAndroid Build Coastguard Worker "Test requires GL_OES_sample_shading extension or a context version 3.2 or higher.");
203*35238bceSAndroid Build Coastguard Worker }
204*35238bceSAndroid Build Coastguard Worker
iterate(void)205*35238bceSAndroid Build Coastguard Worker MinSampleShadingValueClampingCase::IterateResult MinSampleShadingValueClampingCase::iterate(void)
206*35238bceSAndroid Build Coastguard Worker {
207*35238bceSAndroid Build Coastguard Worker glu::CallLogWrapper gl(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
208*35238bceSAndroid Build Coastguard Worker tcu::ResultCollector result(m_testCtx.getLog(), " // ERROR: ");
209*35238bceSAndroid Build Coastguard Worker gl.enableLogging(true);
210*35238bceSAndroid Build Coastguard Worker
211*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
212*35238bceSAndroid Build Coastguard Worker
213*35238bceSAndroid Build Coastguard Worker // special values
214*35238bceSAndroid Build Coastguard Worker {
215*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Verifying clamped values. Value is clamped when specified."
216*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
217*35238bceSAndroid Build Coastguard Worker
218*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(-0.5f);
219*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.0, QUERY_FLOAT);
220*35238bceSAndroid Build Coastguard Worker
221*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(-1.0f);
222*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.0, QUERY_FLOAT);
223*35238bceSAndroid Build Coastguard Worker
224*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(-1.5f);
225*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 0.0, QUERY_FLOAT);
226*35238bceSAndroid Build Coastguard Worker
227*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(1.5f);
228*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 1.0, QUERY_FLOAT);
229*35238bceSAndroid Build Coastguard Worker
230*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(2.0f);
231*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 1.0, QUERY_FLOAT);
232*35238bceSAndroid Build Coastguard Worker
233*35238bceSAndroid Build Coastguard Worker gl.glMinSampleShading(2.5f);
234*35238bceSAndroid Build Coastguard Worker verifyStateFloat(result, gl, GL_MIN_SAMPLE_SHADING_VALUE, 1.0, QUERY_FLOAT);
235*35238bceSAndroid Build Coastguard Worker }
236*35238bceSAndroid Build Coastguard Worker
237*35238bceSAndroid Build Coastguard Worker result.setTestContextResult(m_testCtx);
238*35238bceSAndroid Build Coastguard Worker return STOP;
239*35238bceSAndroid Build Coastguard Worker }
240*35238bceSAndroid Build Coastguard Worker
241*35238bceSAndroid Build Coastguard Worker class SampleShadingRenderingCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
242*35238bceSAndroid Build Coastguard Worker {
243*35238bceSAndroid Build Coastguard Worker public:
244*35238bceSAndroid Build Coastguard Worker enum TestType
245*35238bceSAndroid Build Coastguard Worker {
246*35238bceSAndroid Build Coastguard Worker TEST_DISCARD = 0,
247*35238bceSAndroid Build Coastguard Worker TEST_COLOR,
248*35238bceSAndroid Build Coastguard Worker
249*35238bceSAndroid Build Coastguard Worker TEST_LAST
250*35238bceSAndroid Build Coastguard Worker };
251*35238bceSAndroid Build Coastguard Worker SampleShadingRenderingCase(Context &ctx, const char *name, const char *desc, RenderTarget target, int numSamples,
252*35238bceSAndroid Build Coastguard Worker TestType type);
253*35238bceSAndroid Build Coastguard Worker ~SampleShadingRenderingCase(void);
254*35238bceSAndroid Build Coastguard Worker
255*35238bceSAndroid Build Coastguard Worker void init(void);
256*35238bceSAndroid Build Coastguard Worker
257*35238bceSAndroid Build Coastguard Worker private:
258*35238bceSAndroid Build Coastguard Worker void setShadingValue(int sampleCount);
259*35238bceSAndroid Build Coastguard Worker
260*35238bceSAndroid Build Coastguard Worker void preDraw(void);
261*35238bceSAndroid Build Coastguard Worker void postDraw(void);
262*35238bceSAndroid Build Coastguard Worker std::string getIterationDescription(int iteration) const;
263*35238bceSAndroid Build Coastguard Worker
264*35238bceSAndroid Build Coastguard Worker bool verifyImage(const tcu::Surface &resultImage);
265*35238bceSAndroid Build Coastguard Worker
266*35238bceSAndroid Build Coastguard Worker std::string genFragmentSource(int numSamples) const;
267*35238bceSAndroid Build Coastguard Worker
268*35238bceSAndroid Build Coastguard Worker enum
269*35238bceSAndroid Build Coastguard Worker {
270*35238bceSAndroid Build Coastguard Worker RENDER_SIZE = 128
271*35238bceSAndroid Build Coastguard Worker };
272*35238bceSAndroid Build Coastguard Worker
273*35238bceSAndroid Build Coastguard Worker const TestType m_type;
274*35238bceSAndroid Build Coastguard Worker };
275*35238bceSAndroid Build Coastguard Worker
SampleShadingRenderingCase(Context & ctx,const char * name,const char * desc,RenderTarget target,int numSamples,TestType type)276*35238bceSAndroid Build Coastguard Worker SampleShadingRenderingCase::SampleShadingRenderingCase(Context &ctx, const char *name, const char *desc,
277*35238bceSAndroid Build Coastguard Worker RenderTarget target, int numSamples, TestType type)
278*35238bceSAndroid Build Coastguard Worker : MultisampleShaderRenderUtil::MultisampleRenderCase(ctx, name, desc, numSamples, target, RENDER_SIZE)
279*35238bceSAndroid Build Coastguard Worker , m_type(type)
280*35238bceSAndroid Build Coastguard Worker {
281*35238bceSAndroid Build Coastguard Worker DE_ASSERT(type < TEST_LAST);
282*35238bceSAndroid Build Coastguard Worker }
283*35238bceSAndroid Build Coastguard Worker
~SampleShadingRenderingCase(void)284*35238bceSAndroid Build Coastguard Worker SampleShadingRenderingCase::~SampleShadingRenderingCase(void)
285*35238bceSAndroid Build Coastguard Worker {
286*35238bceSAndroid Build Coastguard Worker deinit();
287*35238bceSAndroid Build Coastguard Worker }
288*35238bceSAndroid Build Coastguard Worker
init(void)289*35238bceSAndroid Build Coastguard Worker void SampleShadingRenderingCase::init(void)
290*35238bceSAndroid Build Coastguard Worker {
291*35238bceSAndroid Build Coastguard Worker // requirements
292*35238bceSAndroid Build Coastguard Worker if (!checkSupport(m_context))
293*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError(
294*35238bceSAndroid Build Coastguard Worker "Test requires GL_OES_sample_shading extension or a context version 3.2 or higher.");
295*35238bceSAndroid Build Coastguard Worker if (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1)
296*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("Multisampled default framebuffer required");
297*35238bceSAndroid Build Coastguard Worker
298*35238bceSAndroid Build Coastguard Worker // test purpose and expectations
299*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog()
300*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message
301*35238bceSAndroid Build Coastguard Worker << "Verifying that a varying is given at least N different values for different samples within a single "
302*35238bceSAndroid Build Coastguard Worker "pixel.\n"
303*35238bceSAndroid Build Coastguard Worker << " Render high-frequency function, map result to black/white. Modify N with glMinSampleShading().\n"
304*35238bceSAndroid Build Coastguard Worker << " => Resulting image should contain N+1 shades of gray.\n"
305*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
306*35238bceSAndroid Build Coastguard Worker
307*35238bceSAndroid Build Coastguard Worker // setup resources
308*35238bceSAndroid Build Coastguard Worker
309*35238bceSAndroid Build Coastguard Worker MultisampleShaderRenderUtil::MultisampleRenderCase::init();
310*35238bceSAndroid Build Coastguard Worker
311*35238bceSAndroid Build Coastguard Worker // set iterations
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker m_numIterations = m_numTargetSamples + 1;
314*35238bceSAndroid Build Coastguard Worker }
315*35238bceSAndroid Build Coastguard Worker
setShadingValue(int sampleCount)316*35238bceSAndroid Build Coastguard Worker void SampleShadingRenderingCase::setShadingValue(int sampleCount)
317*35238bceSAndroid Build Coastguard Worker {
318*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
319*35238bceSAndroid Build Coastguard Worker
320*35238bceSAndroid Build Coastguard Worker if (sampleCount == 0)
321*35238bceSAndroid Build Coastguard Worker {
322*35238bceSAndroid Build Coastguard Worker gl.disable(GL_SAMPLE_SHADING);
323*35238bceSAndroid Build Coastguard Worker gl.minSampleShading(1.0f);
324*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "set ratio");
325*35238bceSAndroid Build Coastguard Worker }
326*35238bceSAndroid Build Coastguard Worker else
327*35238bceSAndroid Build Coastguard Worker {
328*35238bceSAndroid Build Coastguard Worker // Minimum number of samples is max(ceil(<mss> * <samples>),1). Decrease mss with epsilon to prevent
329*35238bceSAndroid Build Coastguard Worker // ceiling to a too large sample count.
330*35238bceSAndroid Build Coastguard Worker const float epsilon = 0.25f / (float)m_numTargetSamples;
331*35238bceSAndroid Build Coastguard Worker const float ratio = ((float)sampleCount / (float)m_numTargetSamples) - epsilon;
332*35238bceSAndroid Build Coastguard Worker
333*35238bceSAndroid Build Coastguard Worker gl.enable(GL_SAMPLE_SHADING);
334*35238bceSAndroid Build Coastguard Worker gl.minSampleShading(ratio);
335*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "set ratio");
336*35238bceSAndroid Build Coastguard Worker
337*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Setting MIN_SAMPLE_SHADING_VALUE = " << ratio << "\n"
338*35238bceSAndroid Build Coastguard Worker << "Requested sample count: shadingValue * numSamples = " << ratio << " * "
339*35238bceSAndroid Build Coastguard Worker << m_numTargetSamples << " = " << (ratio * (float)m_numTargetSamples) << "\n"
340*35238bceSAndroid Build Coastguard Worker << "Minimum sample count: ceil(shadingValue * numSamples) = ceil("
341*35238bceSAndroid Build Coastguard Worker << (ratio * (float)m_numTargetSamples) << ") = " << sampleCount << tcu::TestLog::EndMessage;
342*35238bceSAndroid Build Coastguard Worker
343*35238bceSAndroid Build Coastguard Worker // can't fail with reasonable values of numSamples
344*35238bceSAndroid Build Coastguard Worker DE_ASSERT(deFloatCeil(ratio * (float)m_numTargetSamples) == float(sampleCount));
345*35238bceSAndroid Build Coastguard Worker }
346*35238bceSAndroid Build Coastguard Worker }
347*35238bceSAndroid Build Coastguard Worker
preDraw(void)348*35238bceSAndroid Build Coastguard Worker void SampleShadingRenderingCase::preDraw(void)
349*35238bceSAndroid Build Coastguard Worker {
350*35238bceSAndroid Build Coastguard Worker setShadingValue(m_iteration);
351*35238bceSAndroid Build Coastguard Worker }
352*35238bceSAndroid Build Coastguard Worker
postDraw(void)353*35238bceSAndroid Build Coastguard Worker void SampleShadingRenderingCase::postDraw(void)
354*35238bceSAndroid Build Coastguard Worker {
355*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker gl.disable(GL_SAMPLE_SHADING);
358*35238bceSAndroid Build Coastguard Worker gl.minSampleShading(1.0f);
359*35238bceSAndroid Build Coastguard Worker }
360*35238bceSAndroid Build Coastguard Worker
getIterationDescription(int iteration) const361*35238bceSAndroid Build Coastguard Worker std::string SampleShadingRenderingCase::getIterationDescription(int iteration) const
362*35238bceSAndroid Build Coastguard Worker {
363*35238bceSAndroid Build Coastguard Worker if (iteration == 0)
364*35238bceSAndroid Build Coastguard Worker return "Disabled SAMPLE_SHADING";
365*35238bceSAndroid Build Coastguard Worker else
366*35238bceSAndroid Build Coastguard Worker return "Samples per pixel: " + de::toString(iteration);
367*35238bceSAndroid Build Coastguard Worker }
368*35238bceSAndroid Build Coastguard Worker
verifyImage(const tcu::Surface & resultImage)369*35238bceSAndroid Build Coastguard Worker bool SampleShadingRenderingCase::verifyImage(const tcu::Surface &resultImage)
370*35238bceSAndroid Build Coastguard Worker {
371*35238bceSAndroid Build Coastguard Worker const int numShadesRequired = (m_iteration == 0) ? (2) : (m_iteration + 1);
372*35238bceSAndroid Build Coastguard Worker const int rareThreshold = 100;
373*35238bceSAndroid Build Coastguard Worker int rareCount = 0;
374*35238bceSAndroid Build Coastguard Worker std::map<uint32_t, int> shadeFrequency;
375*35238bceSAndroid Build Coastguard Worker
376*35238bceSAndroid Build Coastguard Worker // we should now have n+1 different shades of white, n = num samples
377*35238bceSAndroid Build Coastguard Worker
378*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Image("ResultImage", "Result Image", resultImage.getAccess())
379*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::Message << "Verifying image has (at least) " << numShadesRequired
380*35238bceSAndroid Build Coastguard Worker << " different shades.\n"
381*35238bceSAndroid Build Coastguard Worker << "Excluding pixels with no full coverage (pixels on the shared edge of the triangle pair)."
382*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
383*35238bceSAndroid Build Coastguard Worker
384*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < RENDER_SIZE; ++y)
385*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < RENDER_SIZE; ++x)
386*35238bceSAndroid Build Coastguard Worker {
387*35238bceSAndroid Build Coastguard Worker const tcu::RGBA color = resultImage.getPixel(x, y);
388*35238bceSAndroid Build Coastguard Worker const uint32_t packed =
389*35238bceSAndroid Build Coastguard Worker ((uint32_t)color.getRed()) + ((uint32_t)color.getGreen() << 8) + ((uint32_t)color.getGreen() << 16);
390*35238bceSAndroid Build Coastguard Worker
391*35238bceSAndroid Build Coastguard Worker // on the triangle edge, skip
392*35238bceSAndroid Build Coastguard Worker if (x == y)
393*35238bceSAndroid Build Coastguard Worker continue;
394*35238bceSAndroid Build Coastguard Worker
395*35238bceSAndroid Build Coastguard Worker if (shadeFrequency.find(packed) == shadeFrequency.end())
396*35238bceSAndroid Build Coastguard Worker shadeFrequency[packed] = 1;
397*35238bceSAndroid Build Coastguard Worker else
398*35238bceSAndroid Build Coastguard Worker shadeFrequency[packed] = shadeFrequency[packed] + 1;
399*35238bceSAndroid Build Coastguard Worker }
400*35238bceSAndroid Build Coastguard Worker
401*35238bceSAndroid Build Coastguard Worker for (std::map<uint32_t, int>::const_iterator it = shadeFrequency.begin(); it != shadeFrequency.end(); ++it)
402*35238bceSAndroid Build Coastguard Worker if (it->second < rareThreshold)
403*35238bceSAndroid Build Coastguard Worker rareCount++;
404*35238bceSAndroid Build Coastguard Worker
405*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Found " << (int)shadeFrequency.size() << " different shades.\n"
406*35238bceSAndroid Build Coastguard Worker << "\tRare (less than " << rareThreshold << " pixels): " << rareCount << "\n"
407*35238bceSAndroid Build Coastguard Worker << "\tCommon: " << (int)shadeFrequency.size() - rareCount << "\n"
408*35238bceSAndroid Build Coastguard Worker << tcu::TestLog::EndMessage;
409*35238bceSAndroid Build Coastguard Worker
410*35238bceSAndroid Build Coastguard Worker if ((int)shadeFrequency.size() < numShadesRequired)
411*35238bceSAndroid Build Coastguard Worker {
412*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed." << tcu::TestLog::EndMessage;
413*35238bceSAndroid Build Coastguard Worker return false;
414*35238bceSAndroid Build Coastguard Worker }
415*35238bceSAndroid Build Coastguard Worker return true;
416*35238bceSAndroid Build Coastguard Worker }
417*35238bceSAndroid Build Coastguard Worker
genFragmentSource(int numSamples) const418*35238bceSAndroid Build Coastguard Worker std::string SampleShadingRenderingCase::genFragmentSource(int numSamples) const
419*35238bceSAndroid Build Coastguard Worker {
420*35238bceSAndroid Build Coastguard Worker DE_UNREF(numSamples);
421*35238bceSAndroid Build Coastguard Worker
422*35238bceSAndroid Build Coastguard Worker const bool supportsES32orGL45 =
423*35238bceSAndroid Build Coastguard Worker glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::es(3, 2)) ||
424*35238bceSAndroid Build Coastguard Worker glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5));
425*35238bceSAndroid Build Coastguard Worker
426*35238bceSAndroid Build Coastguard Worker const glu::GLSLVersion version = supportsES32orGL45 ? glu::GLSL_VERSION_320_ES : glu::GLSL_VERSION_310_ES;
427*35238bceSAndroid Build Coastguard Worker std::ostringstream buf;
428*35238bceSAndroid Build Coastguard Worker
429*35238bceSAndroid Build Coastguard Worker buf << glu::getGLSLVersionDeclaration(version)
430*35238bceSAndroid Build Coastguard Worker << "\n"
431*35238bceSAndroid Build Coastguard Worker "in highp vec4 v_position;\n"
432*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 fragColor;\n"
433*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
434*35238bceSAndroid Build Coastguard Worker "{\n"
435*35238bceSAndroid Build Coastguard Worker " highp float field = dot(v_position.xy, v_position.xy) + dot(21.0 * v_position.xx, sin(3.1 * "
436*35238bceSAndroid Build Coastguard Worker "v_position.xy));\n"
437*35238bceSAndroid Build Coastguard Worker " fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
438*35238bceSAndroid Build Coastguard Worker "\n"
439*35238bceSAndroid Build Coastguard Worker " if (fract(field) > 0.5)\n";
440*35238bceSAndroid Build Coastguard Worker
441*35238bceSAndroid Build Coastguard Worker if (m_type == TEST_DISCARD)
442*35238bceSAndroid Build Coastguard Worker buf << " discard;\n";
443*35238bceSAndroid Build Coastguard Worker else if (m_type == TEST_COLOR)
444*35238bceSAndroid Build Coastguard Worker buf << " fragColor = vec4(0.0, 0.0, 0.0, 1.0);\n";
445*35238bceSAndroid Build Coastguard Worker else
446*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
447*35238bceSAndroid Build Coastguard Worker
448*35238bceSAndroid Build Coastguard Worker buf << "}";
449*35238bceSAndroid Build Coastguard Worker
450*35238bceSAndroid Build Coastguard Worker return buf.str();
451*35238bceSAndroid Build Coastguard Worker }
452*35238bceSAndroid Build Coastguard Worker
453*35238bceSAndroid Build Coastguard Worker } // namespace
454*35238bceSAndroid Build Coastguard Worker
SampleShadingTests(Context & context)455*35238bceSAndroid Build Coastguard Worker SampleShadingTests::SampleShadingTests(Context &context)
456*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "sample_shading", "Test sample shading")
457*35238bceSAndroid Build Coastguard Worker {
458*35238bceSAndroid Build Coastguard Worker }
459*35238bceSAndroid Build Coastguard Worker
~SampleShadingTests(void)460*35238bceSAndroid Build Coastguard Worker SampleShadingTests::~SampleShadingTests(void)
461*35238bceSAndroid Build Coastguard Worker {
462*35238bceSAndroid Build Coastguard Worker }
463*35238bceSAndroid Build Coastguard Worker
init(void)464*35238bceSAndroid Build Coastguard Worker void SampleShadingTests::init(void)
465*35238bceSAndroid Build Coastguard Worker {
466*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const stateQueryGroup = new tcu::TestCaseGroup(m_testCtx, "state_query", "State query tests.");
467*35238bceSAndroid Build Coastguard Worker tcu::TestCaseGroup *const minSamplesGroup =
468*35238bceSAndroid Build Coastguard Worker new tcu::TestCaseGroup(m_testCtx, "min_sample_shading", "Min sample shading tests.");
469*35238bceSAndroid Build Coastguard Worker
470*35238bceSAndroid Build Coastguard Worker addChild(stateQueryGroup);
471*35238bceSAndroid Build Coastguard Worker addChild(minSamplesGroup);
472*35238bceSAndroid Build Coastguard Worker
473*35238bceSAndroid Build Coastguard Worker // .state query
474*35238bceSAndroid Build Coastguard Worker {
475*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(
476*35238bceSAndroid Build Coastguard Worker new SampleShadingStateCase(m_context, "sample_shading_is_enabled", "test SAMPLE_SHADING", QUERY_ISENABLED));
477*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(
478*35238bceSAndroid Build Coastguard Worker new SampleShadingStateCase(m_context, "sample_shading_get_boolean", "test SAMPLE_SHADING", QUERY_BOOLEAN));
479*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(
480*35238bceSAndroid Build Coastguard Worker new SampleShadingStateCase(m_context, "sample_shading_get_integer", "test SAMPLE_SHADING", QUERY_INTEGER));
481*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(
482*35238bceSAndroid Build Coastguard Worker new SampleShadingStateCase(m_context, "sample_shading_get_float", "test SAMPLE_SHADING", QUERY_FLOAT));
483*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new SampleShadingStateCase(m_context, "sample_shading_get_integer64",
484*35238bceSAndroid Build Coastguard Worker "test SAMPLE_SHADING", QUERY_INTEGER64));
485*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new MinSampleShadingValueCase(m_context, "min_sample_shading_value_get_boolean",
486*35238bceSAndroid Build Coastguard Worker "test MIN_SAMPLE_SHADING_VALUE", QUERY_BOOLEAN));
487*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new MinSampleShadingValueCase(m_context, "min_sample_shading_value_get_integer",
488*35238bceSAndroid Build Coastguard Worker "test MIN_SAMPLE_SHADING_VALUE", QUERY_INTEGER));
489*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new MinSampleShadingValueCase(m_context, "min_sample_shading_value_get_float",
490*35238bceSAndroid Build Coastguard Worker "test MIN_SAMPLE_SHADING_VALUE", QUERY_FLOAT));
491*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new MinSampleShadingValueCase(m_context, "min_sample_shading_value_get_integer64",
492*35238bceSAndroid Build Coastguard Worker "test MIN_SAMPLE_SHADING_VALUE", QUERY_INTEGER64));
493*35238bceSAndroid Build Coastguard Worker stateQueryGroup->addChild(new MinSampleShadingValueClampingCase(m_context, "min_sample_shading_value_clamping",
494*35238bceSAndroid Build Coastguard Worker "test MIN_SAMPLE_SHADING_VALUE clamping"));
495*35238bceSAndroid Build Coastguard Worker }
496*35238bceSAndroid Build Coastguard Worker
497*35238bceSAndroid Build Coastguard Worker // .min_sample_count
498*35238bceSAndroid Build Coastguard Worker {
499*35238bceSAndroid Build Coastguard Worker static const struct Target
500*35238bceSAndroid Build Coastguard Worker {
501*35238bceSAndroid Build Coastguard Worker SampleShadingRenderingCase::RenderTarget target;
502*35238bceSAndroid Build Coastguard Worker int numSamples;
503*35238bceSAndroid Build Coastguard Worker const char *name;
504*35238bceSAndroid Build Coastguard Worker } targets[] = {
505*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_DEFAULT, 0, "default_framebuffer"},
506*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_TEXTURE, 2, "multisample_texture_samples_2"},
507*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_TEXTURE, 4, "multisample_texture_samples_4"},
508*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_TEXTURE, 8, "multisample_texture_samples_8"},
509*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_TEXTURE, 16, "multisample_texture_samples_16"},
510*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_RENDERBUFFER, 2, "multisample_renderbuffer_samples_2"},
511*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_RENDERBUFFER, 4, "multisample_renderbuffer_samples_4"},
512*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_RENDERBUFFER, 8, "multisample_renderbuffer_samples_8"},
513*35238bceSAndroid Build Coastguard Worker {SampleShadingRenderingCase::TARGET_RENDERBUFFER, 16, "multisample_renderbuffer_samples_16"},
514*35238bceSAndroid Build Coastguard Worker };
515*35238bceSAndroid Build Coastguard Worker
516*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(targets); ++ndx)
517*35238bceSAndroid Build Coastguard Worker {
518*35238bceSAndroid Build Coastguard Worker minSamplesGroup->addChild(
519*35238bceSAndroid Build Coastguard Worker new SampleShadingRenderingCase(m_context, (std::string(targets[ndx].name) + "_color").c_str(),
520*35238bceSAndroid Build Coastguard Worker "Test multiple samples per pixel with color", targets[ndx].target,
521*35238bceSAndroid Build Coastguard Worker targets[ndx].numSamples, SampleShadingRenderingCase::TEST_COLOR));
522*35238bceSAndroid Build Coastguard Worker minSamplesGroup->addChild(
523*35238bceSAndroid Build Coastguard Worker new SampleShadingRenderingCase(m_context, (std::string(targets[ndx].name) + "_discard").c_str(),
524*35238bceSAndroid Build Coastguard Worker "Test multiple samples per pixel with", targets[ndx].target,
525*35238bceSAndroid Build Coastguard Worker targets[ndx].numSamples, SampleShadingRenderingCase::TEST_DISCARD));
526*35238bceSAndroid Build Coastguard Worker }
527*35238bceSAndroid Build Coastguard Worker }
528*35238bceSAndroid Build Coastguard Worker }
529*35238bceSAndroid Build Coastguard Worker
530*35238bceSAndroid Build Coastguard Worker } // namespace Functional
531*35238bceSAndroid Build Coastguard Worker } // namespace gles31
532*35238bceSAndroid Build Coastguard Worker } // namespace deqp
533