1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 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 Randomized per-fragment operation tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es3fRandomFragmentOpTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsFragmentOpUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "glsInteractionTestUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuCommandLine.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "gluCallLogWrapper.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
40*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "rrFragmentOperations.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceUtils.hpp"
44*35238bceSAndroid Build Coastguard Worker
45*35238bceSAndroid Build Coastguard Worker #include <algorithm>
46*35238bceSAndroid Build Coastguard Worker
47*35238bceSAndroid Build Coastguard Worker namespace deqp
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker namespace gles3
50*35238bceSAndroid Build Coastguard Worker {
51*35238bceSAndroid Build Coastguard Worker namespace Functional
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker
54*35238bceSAndroid Build Coastguard Worker using std::vector;
55*35238bceSAndroid Build Coastguard Worker using tcu::BVec4;
56*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
57*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
58*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
59*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
60*35238bceSAndroid Build Coastguard Worker
61*35238bceSAndroid Build Coastguard Worker enum
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker VIEWPORT_WIDTH = 64,
64*35238bceSAndroid Build Coastguard Worker VIEWPORT_HEIGHT = 64,
65*35238bceSAndroid Build Coastguard Worker NUM_CALLS_PER_ITERATION = 3,
66*35238bceSAndroid Build Coastguard Worker NUM_ITERATIONS_PER_CASE = 10
67*35238bceSAndroid Build Coastguard Worker };
68*35238bceSAndroid Build Coastguard Worker
69*35238bceSAndroid Build Coastguard Worker static const tcu::Vec4 CLEAR_COLOR(0.25f, 0.5f, 0.75f, 1.0f);
70*35238bceSAndroid Build Coastguard Worker static const float CLEAR_DEPTH = 1.0f;
71*35238bceSAndroid Build Coastguard Worker static const int CLEAR_STENCIL = 0;
72*35238bceSAndroid Build Coastguard Worker static const bool ENABLE_CALL_LOG = true;
73*35238bceSAndroid Build Coastguard Worker
74*35238bceSAndroid Build Coastguard Worker using namespace gls::FragmentOpUtil;
75*35238bceSAndroid Build Coastguard Worker using namespace gls::InteractionTestUtil;
76*35238bceSAndroid Build Coastguard Worker
translateStencilState(const StencilState & src,rr::StencilState & dst)77*35238bceSAndroid Build Coastguard Worker void translateStencilState(const StencilState &src, rr::StencilState &dst)
78*35238bceSAndroid Build Coastguard Worker {
79*35238bceSAndroid Build Coastguard Worker dst.func = sglr::rr_util::mapGLTestFunc(src.function);
80*35238bceSAndroid Build Coastguard Worker dst.ref = src.reference;
81*35238bceSAndroid Build Coastguard Worker dst.compMask = src.compareMask;
82*35238bceSAndroid Build Coastguard Worker dst.sFail = sglr::rr_util::mapGLStencilOp(src.stencilFailOp);
83*35238bceSAndroid Build Coastguard Worker dst.dpFail = sglr::rr_util::mapGLStencilOp(src.depthFailOp);
84*35238bceSAndroid Build Coastguard Worker dst.dpPass = sglr::rr_util::mapGLStencilOp(src.depthPassOp);
85*35238bceSAndroid Build Coastguard Worker dst.writeMask = src.writeMask;
86*35238bceSAndroid Build Coastguard Worker }
87*35238bceSAndroid Build Coastguard Worker
translateBlendState(const BlendState & src,rr::BlendState & dst)88*35238bceSAndroid Build Coastguard Worker void translateBlendState(const BlendState &src, rr::BlendState &dst)
89*35238bceSAndroid Build Coastguard Worker {
90*35238bceSAndroid Build Coastguard Worker dst.equation = sglr::rr_util::mapGLBlendEquation(src.equation);
91*35238bceSAndroid Build Coastguard Worker dst.srcFunc = sglr::rr_util::mapGLBlendFunc(src.srcFunc);
92*35238bceSAndroid Build Coastguard Worker dst.dstFunc = sglr::rr_util::mapGLBlendFunc(src.dstFunc);
93*35238bceSAndroid Build Coastguard Worker }
94*35238bceSAndroid Build Coastguard Worker
translateState(const RenderState & src,rr::FragmentOperationState & dst,const tcu::RenderTarget & renderTarget)95*35238bceSAndroid Build Coastguard Worker void translateState(const RenderState &src, rr::FragmentOperationState &dst, const tcu::RenderTarget &renderTarget)
96*35238bceSAndroid Build Coastguard Worker {
97*35238bceSAndroid Build Coastguard Worker bool hasDepth = renderTarget.getDepthBits() > 0;
98*35238bceSAndroid Build Coastguard Worker bool hasStencil = renderTarget.getStencilBits() > 0;
99*35238bceSAndroid Build Coastguard Worker
100*35238bceSAndroid Build Coastguard Worker dst.scissorTestEnabled = src.scissorTestEnabled;
101*35238bceSAndroid Build Coastguard Worker dst.scissorRectangle = src.scissorRectangle;
102*35238bceSAndroid Build Coastguard Worker dst.stencilTestEnabled = hasStencil && src.stencilTestEnabled;
103*35238bceSAndroid Build Coastguard Worker dst.depthTestEnabled = hasDepth && src.depthTestEnabled;
104*35238bceSAndroid Build Coastguard Worker dst.blendMode = src.blendEnabled ? rr::BLENDMODE_STANDARD : rr::BLENDMODE_NONE;
105*35238bceSAndroid Build Coastguard Worker dst.numStencilBits = renderTarget.getStencilBits();
106*35238bceSAndroid Build Coastguard Worker
107*35238bceSAndroid Build Coastguard Worker dst.colorMask = src.colorMask;
108*35238bceSAndroid Build Coastguard Worker
109*35238bceSAndroid Build Coastguard Worker if (dst.depthTestEnabled)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker dst.depthFunc = sglr::rr_util::mapGLTestFunc(src.depthFunc);
112*35238bceSAndroid Build Coastguard Worker dst.depthMask = src.depthWriteMask;
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker
115*35238bceSAndroid Build Coastguard Worker if (dst.stencilTestEnabled)
116*35238bceSAndroid Build Coastguard Worker {
117*35238bceSAndroid Build Coastguard Worker translateStencilState(src.stencil[rr::FACETYPE_BACK], dst.stencilStates[rr::FACETYPE_BACK]);
118*35238bceSAndroid Build Coastguard Worker translateStencilState(src.stencil[rr::FACETYPE_FRONT], dst.stencilStates[rr::FACETYPE_FRONT]);
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker
121*35238bceSAndroid Build Coastguard Worker if (src.blendEnabled)
122*35238bceSAndroid Build Coastguard Worker {
123*35238bceSAndroid Build Coastguard Worker translateBlendState(src.blendRGBState, dst.blendRGBState);
124*35238bceSAndroid Build Coastguard Worker translateBlendState(src.blendAState, dst.blendAState);
125*35238bceSAndroid Build Coastguard Worker dst.blendColor = tcu::clamp(src.blendColor, Vec4(0.0f), Vec4(1.0f));
126*35238bceSAndroid Build Coastguard Worker }
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker
renderQuad(const glw::Functions & gl,gls::FragmentOpUtil::QuadRenderer & renderer,const gls::FragmentOpUtil::IntegerQuad & quad,int baseX,int baseY)129*35238bceSAndroid Build Coastguard Worker static void renderQuad(const glw::Functions &gl, gls::FragmentOpUtil::QuadRenderer &renderer,
130*35238bceSAndroid Build Coastguard Worker const gls::FragmentOpUtil::IntegerQuad &quad, int baseX, int baseY)
131*35238bceSAndroid Build Coastguard Worker {
132*35238bceSAndroid Build Coastguard Worker gls::FragmentOpUtil::Quad translated;
133*35238bceSAndroid Build Coastguard Worker
134*35238bceSAndroid Build Coastguard Worker std::copy(DE_ARRAY_BEGIN(quad.color), DE_ARRAY_END(quad.color), DE_ARRAY_BEGIN(translated.color));
135*35238bceSAndroid Build Coastguard Worker
136*35238bceSAndroid Build Coastguard Worker bool flipX = quad.posB.x() < quad.posA.x();
137*35238bceSAndroid Build Coastguard Worker bool flipY = quad.posB.y() < quad.posA.y();
138*35238bceSAndroid Build Coastguard Worker int viewportX = de::min(quad.posA.x(), quad.posB.x());
139*35238bceSAndroid Build Coastguard Worker int viewportY = de::min(quad.posA.y(), quad.posB.y());
140*35238bceSAndroid Build Coastguard Worker int viewportW = de::abs(quad.posA.x() - quad.posB.x()) + 1;
141*35238bceSAndroid Build Coastguard Worker int viewportH = de::abs(quad.posA.y() - quad.posB.y()) + 1;
142*35238bceSAndroid Build Coastguard Worker
143*35238bceSAndroid Build Coastguard Worker translated.posA = Vec2(flipX ? 1.0f : -1.0f, flipY ? 1.0f : -1.0f);
144*35238bceSAndroid Build Coastguard Worker translated.posB = Vec2(flipX ? -1.0f : 1.0f, flipY ? -1.0f : 1.0f);
145*35238bceSAndroid Build Coastguard Worker
146*35238bceSAndroid Build Coastguard Worker // \todo [2012-12-18 pyry] Pass in DepthRange parameters.
147*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(quad.depth); ndx++)
148*35238bceSAndroid Build Coastguard Worker translated.depth[ndx] = quad.depth[ndx] * 2.0f - 1.0f;
149*35238bceSAndroid Build Coastguard Worker
150*35238bceSAndroid Build Coastguard Worker gl.viewport(baseX + viewportX, baseY + viewportY, viewportW, viewportH);
151*35238bceSAndroid Build Coastguard Worker renderer.render(translated);
152*35238bceSAndroid Build Coastguard Worker }
153*35238bceSAndroid Build Coastguard Worker
setGLState(glu::CallLogWrapper & wrapper,const RenderState & state,int viewportX,int viewportY)154*35238bceSAndroid Build Coastguard Worker static void setGLState(glu::CallLogWrapper &wrapper, const RenderState &state, int viewportX, int viewportY)
155*35238bceSAndroid Build Coastguard Worker {
156*35238bceSAndroid Build Coastguard Worker if (state.scissorTestEnabled)
157*35238bceSAndroid Build Coastguard Worker {
158*35238bceSAndroid Build Coastguard Worker wrapper.glEnable(GL_SCISSOR_TEST);
159*35238bceSAndroid Build Coastguard Worker wrapper.glScissor(viewportX + state.scissorRectangle.left, viewportY + state.scissorRectangle.bottom,
160*35238bceSAndroid Build Coastguard Worker state.scissorRectangle.width, state.scissorRectangle.height);
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker else
163*35238bceSAndroid Build Coastguard Worker wrapper.glDisable(GL_SCISSOR_TEST);
164*35238bceSAndroid Build Coastguard Worker
165*35238bceSAndroid Build Coastguard Worker if (state.stencilTestEnabled)
166*35238bceSAndroid Build Coastguard Worker {
167*35238bceSAndroid Build Coastguard Worker wrapper.glEnable(GL_STENCIL_TEST);
168*35238bceSAndroid Build Coastguard Worker
169*35238bceSAndroid Build Coastguard Worker for (int face = 0; face < rr::FACETYPE_LAST; face++)
170*35238bceSAndroid Build Coastguard Worker {
171*35238bceSAndroid Build Coastguard Worker uint32_t glFace = face == rr::FACETYPE_BACK ? GL_BACK : GL_FRONT;
172*35238bceSAndroid Build Coastguard Worker const StencilState &sParams = state.stencil[face];
173*35238bceSAndroid Build Coastguard Worker
174*35238bceSAndroid Build Coastguard Worker wrapper.glStencilFuncSeparate(glFace, sParams.function, sParams.reference, sParams.compareMask);
175*35238bceSAndroid Build Coastguard Worker wrapper.glStencilOpSeparate(glFace, sParams.stencilFailOp, sParams.depthFailOp, sParams.depthPassOp);
176*35238bceSAndroid Build Coastguard Worker wrapper.glStencilMaskSeparate(glFace, sParams.writeMask);
177*35238bceSAndroid Build Coastguard Worker }
178*35238bceSAndroid Build Coastguard Worker }
179*35238bceSAndroid Build Coastguard Worker else
180*35238bceSAndroid Build Coastguard Worker wrapper.glDisable(GL_STENCIL_TEST);
181*35238bceSAndroid Build Coastguard Worker
182*35238bceSAndroid Build Coastguard Worker if (state.depthTestEnabled)
183*35238bceSAndroid Build Coastguard Worker {
184*35238bceSAndroid Build Coastguard Worker wrapper.glEnable(GL_DEPTH_TEST);
185*35238bceSAndroid Build Coastguard Worker wrapper.glDepthFunc(state.depthFunc);
186*35238bceSAndroid Build Coastguard Worker wrapper.glDepthMask(state.depthWriteMask ? GL_TRUE : GL_FALSE);
187*35238bceSAndroid Build Coastguard Worker }
188*35238bceSAndroid Build Coastguard Worker else
189*35238bceSAndroid Build Coastguard Worker wrapper.glDisable(GL_DEPTH_TEST);
190*35238bceSAndroid Build Coastguard Worker
191*35238bceSAndroid Build Coastguard Worker if (state.blendEnabled)
192*35238bceSAndroid Build Coastguard Worker {
193*35238bceSAndroid Build Coastguard Worker wrapper.glEnable(GL_BLEND);
194*35238bceSAndroid Build Coastguard Worker wrapper.glBlendEquationSeparate(state.blendRGBState.equation, state.blendAState.equation);
195*35238bceSAndroid Build Coastguard Worker wrapper.glBlendFuncSeparate(state.blendRGBState.srcFunc, state.blendRGBState.dstFunc, state.blendAState.srcFunc,
196*35238bceSAndroid Build Coastguard Worker state.blendAState.dstFunc);
197*35238bceSAndroid Build Coastguard Worker wrapper.glBlendColor(state.blendColor.x(), state.blendColor.y(), state.blendColor.z(), state.blendColor.w());
198*35238bceSAndroid Build Coastguard Worker }
199*35238bceSAndroid Build Coastguard Worker else
200*35238bceSAndroid Build Coastguard Worker wrapper.glDisable(GL_BLEND);
201*35238bceSAndroid Build Coastguard Worker
202*35238bceSAndroid Build Coastguard Worker if (state.ditherEnabled)
203*35238bceSAndroid Build Coastguard Worker wrapper.glEnable(GL_DITHER);
204*35238bceSAndroid Build Coastguard Worker else
205*35238bceSAndroid Build Coastguard Worker wrapper.glDisable(GL_DITHER);
206*35238bceSAndroid Build Coastguard Worker
207*35238bceSAndroid Build Coastguard Worker wrapper.glColorMask(state.colorMask[0] ? GL_TRUE : GL_FALSE, state.colorMask[1] ? GL_TRUE : GL_FALSE,
208*35238bceSAndroid Build Coastguard Worker state.colorMask[2] ? GL_TRUE : GL_FALSE, state.colorMask[3] ? GL_TRUE : GL_FALSE);
209*35238bceSAndroid Build Coastguard Worker }
210*35238bceSAndroid Build Coastguard Worker
211*35238bceSAndroid Build Coastguard Worker class RandomFragmentOpCase : public TestCase
212*35238bceSAndroid Build Coastguard Worker {
213*35238bceSAndroid Build Coastguard Worker public:
214*35238bceSAndroid Build Coastguard Worker RandomFragmentOpCase(Context &context, const char *name, const char *desc, uint32_t seed);
215*35238bceSAndroid Build Coastguard Worker ~RandomFragmentOpCase(void);
216*35238bceSAndroid Build Coastguard Worker
217*35238bceSAndroid Build Coastguard Worker void init(void);
218*35238bceSAndroid Build Coastguard Worker void deinit(void);
219*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
220*35238bceSAndroid Build Coastguard Worker
221*35238bceSAndroid Build Coastguard Worker private:
222*35238bceSAndroid Build Coastguard Worker tcu::UVec4 getCompareThreshold(void) const;
223*35238bceSAndroid Build Coastguard Worker
224*35238bceSAndroid Build Coastguard Worker uint32_t m_seed;
225*35238bceSAndroid Build Coastguard Worker
226*35238bceSAndroid Build Coastguard Worker glu::CallLogWrapper m_callLogWrapper;
227*35238bceSAndroid Build Coastguard Worker
228*35238bceSAndroid Build Coastguard Worker gls::FragmentOpUtil::QuadRenderer *m_renderer;
229*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel *m_refColorBuffer;
230*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel *m_refDepthBuffer;
231*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel *m_refStencilBuffer;
232*35238bceSAndroid Build Coastguard Worker gls::FragmentOpUtil::ReferenceQuadRenderer *m_refRenderer;
233*35238bceSAndroid Build Coastguard Worker
234*35238bceSAndroid Build Coastguard Worker int m_iterNdx;
235*35238bceSAndroid Build Coastguard Worker };
236*35238bceSAndroid Build Coastguard Worker
RandomFragmentOpCase(Context & context,const char * name,const char * desc,uint32_t seed)237*35238bceSAndroid Build Coastguard Worker RandomFragmentOpCase::RandomFragmentOpCase(Context &context, const char *name, const char *desc, uint32_t seed)
238*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, desc)
239*35238bceSAndroid Build Coastguard Worker , m_seed(seed)
240*35238bceSAndroid Build Coastguard Worker , m_callLogWrapper(context.getRenderContext().getFunctions(), context.getTestContext().getLog())
241*35238bceSAndroid Build Coastguard Worker , m_renderer(DE_NULL)
242*35238bceSAndroid Build Coastguard Worker , m_refColorBuffer(DE_NULL)
243*35238bceSAndroid Build Coastguard Worker , m_refDepthBuffer(DE_NULL)
244*35238bceSAndroid Build Coastguard Worker , m_refStencilBuffer(DE_NULL)
245*35238bceSAndroid Build Coastguard Worker , m_refRenderer(DE_NULL)
246*35238bceSAndroid Build Coastguard Worker , m_iterNdx(0)
247*35238bceSAndroid Build Coastguard Worker {
248*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.enableLogging(ENABLE_CALL_LOG);
249*35238bceSAndroid Build Coastguard Worker }
250*35238bceSAndroid Build Coastguard Worker
~RandomFragmentOpCase(void)251*35238bceSAndroid Build Coastguard Worker RandomFragmentOpCase::~RandomFragmentOpCase(void)
252*35238bceSAndroid Build Coastguard Worker {
253*35238bceSAndroid Build Coastguard Worker delete m_renderer;
254*35238bceSAndroid Build Coastguard Worker delete m_refColorBuffer;
255*35238bceSAndroid Build Coastguard Worker delete m_refDepthBuffer;
256*35238bceSAndroid Build Coastguard Worker delete m_refStencilBuffer;
257*35238bceSAndroid Build Coastguard Worker delete m_refRenderer;
258*35238bceSAndroid Build Coastguard Worker }
259*35238bceSAndroid Build Coastguard Worker
init(void)260*35238bceSAndroid Build Coastguard Worker void RandomFragmentOpCase::init(void)
261*35238bceSAndroid Build Coastguard Worker {
262*35238bceSAndroid Build Coastguard Worker DE_ASSERT(!m_renderer && !m_refColorBuffer && !m_refDepthBuffer && !m_refStencilBuffer && !m_refRenderer);
263*35238bceSAndroid Build Coastguard Worker
264*35238bceSAndroid Build Coastguard Worker int width = de::min<int>(m_context.getRenderTarget().getWidth(), VIEWPORT_WIDTH);
265*35238bceSAndroid Build Coastguard Worker int height = de::min<int>(m_context.getRenderTarget().getHeight(), VIEWPORT_HEIGHT);
266*35238bceSAndroid Build Coastguard Worker bool useRGB = m_context.getRenderTarget().getPixelFormat().alphaBits == 0;
267*35238bceSAndroid Build Coastguard Worker
268*35238bceSAndroid Build Coastguard Worker m_renderer = new gls::FragmentOpUtil::QuadRenderer(m_context.getRenderContext(), glu::GLSL_VERSION_300_ES);
269*35238bceSAndroid Build Coastguard Worker m_refColorBuffer = new tcu::TextureLevel(
270*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(useRGB ? tcu::TextureFormat::RGB : tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
271*35238bceSAndroid Build Coastguard Worker width, height);
272*35238bceSAndroid Build Coastguard Worker m_refDepthBuffer =
273*35238bceSAndroid Build Coastguard Worker new tcu::TextureLevel(tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT), width, height);
274*35238bceSAndroid Build Coastguard Worker m_refStencilBuffer = new tcu::TextureLevel(
275*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32), width, height);
276*35238bceSAndroid Build Coastguard Worker m_refRenderer = new gls::FragmentOpUtil::ReferenceQuadRenderer();
277*35238bceSAndroid Build Coastguard Worker m_iterNdx = 0;
278*35238bceSAndroid Build Coastguard Worker
279*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
280*35238bceSAndroid Build Coastguard Worker }
281*35238bceSAndroid Build Coastguard Worker
deinit(void)282*35238bceSAndroid Build Coastguard Worker void RandomFragmentOpCase::deinit(void)
283*35238bceSAndroid Build Coastguard Worker {
284*35238bceSAndroid Build Coastguard Worker delete m_renderer;
285*35238bceSAndroid Build Coastguard Worker delete m_refColorBuffer;
286*35238bceSAndroid Build Coastguard Worker delete m_refDepthBuffer;
287*35238bceSAndroid Build Coastguard Worker delete m_refStencilBuffer;
288*35238bceSAndroid Build Coastguard Worker delete m_refRenderer;
289*35238bceSAndroid Build Coastguard Worker
290*35238bceSAndroid Build Coastguard Worker m_renderer = DE_NULL;
291*35238bceSAndroid Build Coastguard Worker m_refColorBuffer = DE_NULL;
292*35238bceSAndroid Build Coastguard Worker m_refDepthBuffer = DE_NULL;
293*35238bceSAndroid Build Coastguard Worker m_refStencilBuffer = DE_NULL;
294*35238bceSAndroid Build Coastguard Worker m_refRenderer = DE_NULL;
295*35238bceSAndroid Build Coastguard Worker }
296*35238bceSAndroid Build Coastguard Worker
iterate(void)297*35238bceSAndroid Build Coastguard Worker RandomFragmentOpCase::IterateResult RandomFragmentOpCase::iterate(void)
298*35238bceSAndroid Build Coastguard Worker {
299*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
300*35238bceSAndroid Build Coastguard Worker const bool isMSAA = m_context.getRenderTarget().getNumSamples() > 1;
301*35238bceSAndroid Build Coastguard Worker const uint32_t iterSeed =
302*35238bceSAndroid Build Coastguard Worker deUint32Hash(m_seed) ^ deInt32Hash(m_iterNdx) ^ deInt32Hash(m_testCtx.getCommandLine().getBaseSeed());
303*35238bceSAndroid Build Coastguard Worker de::Random rnd(iterSeed);
304*35238bceSAndroid Build Coastguard Worker
305*35238bceSAndroid Build Coastguard Worker const int width = m_refColorBuffer->getWidth();
306*35238bceSAndroid Build Coastguard Worker const int height = m_refColorBuffer->getHeight();
307*35238bceSAndroid Build Coastguard Worker const int viewportX = rnd.getInt(0, m_context.getRenderTarget().getWidth() - width);
308*35238bceSAndroid Build Coastguard Worker const int viewportY = rnd.getInt(0, m_context.getRenderTarget().getHeight() - height);
309*35238bceSAndroid Build Coastguard Worker
310*35238bceSAndroid Build Coastguard Worker tcu::Surface renderedImg(width, height);
311*35238bceSAndroid Build Coastguard Worker tcu::Surface referenceImg(width, height);
312*35238bceSAndroid Build Coastguard Worker
313*35238bceSAndroid Build Coastguard Worker const Vec4 clearColor = CLEAR_COLOR;
314*35238bceSAndroid Build Coastguard Worker const float clearDepth = CLEAR_DEPTH;
315*35238bceSAndroid Build Coastguard Worker const int clearStencil = CLEAR_STENCIL;
316*35238bceSAndroid Build Coastguard Worker
317*35238bceSAndroid Build Coastguard Worker bool gotError = false;
318*35238bceSAndroid Build Coastguard Worker
319*35238bceSAndroid Build Coastguard Worker const tcu::ScopedLogSection iterSection(m_testCtx.getLog(), std::string("Iteration") + de::toString(m_iterNdx),
320*35238bceSAndroid Build Coastguard Worker std::string("Iteration ") + de::toString(m_iterNdx));
321*35238bceSAndroid Build Coastguard Worker
322*35238bceSAndroid Build Coastguard Worker // Compute randomized rendering commands.
323*35238bceSAndroid Build Coastguard Worker vector<RenderCommand> commands;
324*35238bceSAndroid Build Coastguard Worker computeRandomRenderCommands(rnd, glu::ApiType::es(3, 0), NUM_CALLS_PER_ITERATION, width, height, commands);
325*35238bceSAndroid Build Coastguard Worker
326*35238bceSAndroid Build Coastguard Worker // Reset default fragment state.
327*35238bceSAndroid Build Coastguard Worker gl.disable(GL_SCISSOR_TEST);
328*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
329*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_TRUE);
330*35238bceSAndroid Build Coastguard Worker gl.stencilMask(~0u);
331*35238bceSAndroid Build Coastguard Worker
332*35238bceSAndroid Build Coastguard Worker // Render using GL.
333*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
334*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.glClearDepthf(clearDepth);
335*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.glClearStencil(clearStencil);
336*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
337*35238bceSAndroid Build Coastguard Worker m_callLogWrapper.glViewport(viewportX, viewportY, width, height);
338*35238bceSAndroid Build Coastguard Worker
339*35238bceSAndroid Build Coastguard Worker for (vector<RenderCommand>::const_iterator cmd = commands.begin(); cmd != commands.end(); cmd++)
340*35238bceSAndroid Build Coastguard Worker {
341*35238bceSAndroid Build Coastguard Worker setGLState(m_callLogWrapper, cmd->state, viewportX, viewportY);
342*35238bceSAndroid Build Coastguard Worker
343*35238bceSAndroid Build Coastguard Worker if (ENABLE_CALL_LOG)
344*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << TestLog::Message << "// Quad: " << cmd->quad.posA << " -> " << cmd->quad.posB
345*35238bceSAndroid Build Coastguard Worker << ", color: [" << cmd->quad.color[0] << ", " << cmd->quad.color[1] << ", "
346*35238bceSAndroid Build Coastguard Worker << cmd->quad.color[2] << ", " << cmd->quad.color[3] << "]"
347*35238bceSAndroid Build Coastguard Worker << ", depth: [" << cmd->quad.depth[0] << ", " << cmd->quad.depth[1] << ", "
348*35238bceSAndroid Build Coastguard Worker << cmd->quad.depth[2] << ", " << cmd->quad.depth[3] << "]" << TestLog::EndMessage;
349*35238bceSAndroid Build Coastguard Worker
350*35238bceSAndroid Build Coastguard Worker renderQuad(gl, *m_renderer, cmd->quad, viewportX, viewportY);
351*35238bceSAndroid Build Coastguard Worker }
352*35238bceSAndroid Build Coastguard Worker
353*35238bceSAndroid Build Coastguard Worker // Check error.
354*35238bceSAndroid Build Coastguard Worker if (m_callLogWrapper.glGetError() != GL_NO_ERROR)
355*35238bceSAndroid Build Coastguard Worker gotError = true;
356*35238bceSAndroid Build Coastguard Worker
357*35238bceSAndroid Build Coastguard Worker gl.flush();
358*35238bceSAndroid Build Coastguard Worker
359*35238bceSAndroid Build Coastguard Worker // Render reference while GPU is doing work.
360*35238bceSAndroid Build Coastguard Worker tcu::clear(m_refColorBuffer->getAccess(), clearColor);
361*35238bceSAndroid Build Coastguard Worker tcu::clearDepth(m_refDepthBuffer->getAccess(), clearDepth);
362*35238bceSAndroid Build Coastguard Worker tcu::clearStencil(m_refStencilBuffer->getAccess(), clearStencil);
363*35238bceSAndroid Build Coastguard Worker
364*35238bceSAndroid Build Coastguard Worker for (vector<RenderCommand>::const_iterator cmd = commands.begin(); cmd != commands.end(); cmd++)
365*35238bceSAndroid Build Coastguard Worker {
366*35238bceSAndroid Build Coastguard Worker rr::FragmentOperationState refState;
367*35238bceSAndroid Build Coastguard Worker translateState(cmd->state, refState, m_context.getRenderTarget());
368*35238bceSAndroid Build Coastguard Worker m_refRenderer->render(gls::FragmentOpUtil::getMultisampleAccess(m_refColorBuffer->getAccess()),
369*35238bceSAndroid Build Coastguard Worker gls::FragmentOpUtil::getMultisampleAccess(m_refDepthBuffer->getAccess()),
370*35238bceSAndroid Build Coastguard Worker gls::FragmentOpUtil::getMultisampleAccess(m_refStencilBuffer->getAccess()), cmd->quad,
371*35238bceSAndroid Build Coastguard Worker refState);
372*35238bceSAndroid Build Coastguard Worker }
373*35238bceSAndroid Build Coastguard Worker
374*35238bceSAndroid Build Coastguard Worker // Expand reference color buffer to RGBA8
375*35238bceSAndroid Build Coastguard Worker copy(referenceImg.getAccess(), m_refColorBuffer->getAccess());
376*35238bceSAndroid Build Coastguard Worker
377*35238bceSAndroid Build Coastguard Worker // Read rendered image.
378*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), viewportX, viewportY, renderedImg.getAccess());
379*35238bceSAndroid Build Coastguard Worker
380*35238bceSAndroid Build Coastguard Worker m_iterNdx += 1;
381*35238bceSAndroid Build Coastguard Worker
382*35238bceSAndroid Build Coastguard Worker // Compare to reference.
383*35238bceSAndroid Build Coastguard Worker const bool isLastIter = m_iterNdx >= NUM_ITERATIONS_PER_CASE;
384*35238bceSAndroid Build Coastguard Worker const tcu::UVec4 threshold = getCompareThreshold();
385*35238bceSAndroid Build Coastguard Worker bool compareOk;
386*35238bceSAndroid Build Coastguard Worker
387*35238bceSAndroid Build Coastguard Worker if (isMSAA)
388*35238bceSAndroid Build Coastguard Worker {
389*35238bceSAndroid Build Coastguard Worker // in MSAA cases, the sampling points could be anywhere in the pixel and we could
390*35238bceSAndroid Build Coastguard Worker // even have multiple samples that are combined in resolve. Allow arbitrary sample
391*35238bceSAndroid Build Coastguard Worker // positions by using bilinearCompare.
392*35238bceSAndroid Build Coastguard Worker compareOk = tcu::bilinearCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
393*35238bceSAndroid Build Coastguard Worker referenceImg.getAccess(), renderedImg.getAccess(),
394*35238bceSAndroid Build Coastguard Worker tcu::RGBA(threshold.x(), threshold.y(), threshold.z(), threshold.w()),
395*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
396*35238bceSAndroid Build Coastguard Worker }
397*35238bceSAndroid Build Coastguard Worker else
398*35238bceSAndroid Build Coastguard Worker compareOk = tcu::intThresholdCompare(m_testCtx.getLog(), "CompareResult", "Image Comparison Result",
399*35238bceSAndroid Build Coastguard Worker referenceImg.getAccess(), renderedImg.getAccess(), threshold,
400*35238bceSAndroid Build Coastguard Worker tcu::COMPARE_LOG_RESULT);
401*35238bceSAndroid Build Coastguard Worker
402*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << TestLog::Message << (compareOk ? " Passed." : " FAILED!") << TestLog::EndMessage;
403*35238bceSAndroid Build Coastguard Worker
404*35238bceSAndroid Build Coastguard Worker if (!compareOk)
405*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
406*35238bceSAndroid Build Coastguard Worker else if (gotError)
407*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "GL error");
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker if (compareOk && !gotError && !isLastIter)
410*35238bceSAndroid Build Coastguard Worker return CONTINUE;
411*35238bceSAndroid Build Coastguard Worker else
412*35238bceSAndroid Build Coastguard Worker return STOP;
413*35238bceSAndroid Build Coastguard Worker }
414*35238bceSAndroid Build Coastguard Worker
getCompareThreshold(void) const415*35238bceSAndroid Build Coastguard Worker tcu::UVec4 RandomFragmentOpCase::getCompareThreshold(void) const
416*35238bceSAndroid Build Coastguard Worker {
417*35238bceSAndroid Build Coastguard Worker tcu::PixelFormat format = m_context.getRenderTarget().getPixelFormat();
418*35238bceSAndroid Build Coastguard Worker
419*35238bceSAndroid Build Coastguard Worker if (format == tcu::PixelFormat(8, 8, 8, 8) || format == tcu::PixelFormat(8, 8, 8, 0))
420*35238bceSAndroid Build Coastguard Worker return format.getColorThreshold().toIVec().asUint() + tcu::UVec4(2); // Default threshold.
421*35238bceSAndroid Build Coastguard Worker else
422*35238bceSAndroid Build Coastguard Worker return format.getColorThreshold().toIVec().asUint() * tcu::UVec4(5) +
423*35238bceSAndroid Build Coastguard Worker tcu::UVec4(
424*35238bceSAndroid Build Coastguard Worker 2); // \note Non-scientific ad hoc formula. Need big threshold when few color bits; especially multiple blendings bring extra inaccuracy.
425*35238bceSAndroid Build Coastguard Worker }
426*35238bceSAndroid Build Coastguard Worker
RandomFragmentOpTests(Context & context)427*35238bceSAndroid Build Coastguard Worker RandomFragmentOpTests::RandomFragmentOpTests(Context &context)
428*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "random", "Randomized Per-Fragment Operation Tests")
429*35238bceSAndroid Build Coastguard Worker {
430*35238bceSAndroid Build Coastguard Worker }
431*35238bceSAndroid Build Coastguard Worker
~RandomFragmentOpTests(void)432*35238bceSAndroid Build Coastguard Worker RandomFragmentOpTests::~RandomFragmentOpTests(void)
433*35238bceSAndroid Build Coastguard Worker {
434*35238bceSAndroid Build Coastguard Worker }
435*35238bceSAndroid Build Coastguard Worker
init(void)436*35238bceSAndroid Build Coastguard Worker void RandomFragmentOpTests::init(void)
437*35238bceSAndroid Build Coastguard Worker {
438*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < 100; ndx++)
439*35238bceSAndroid Build Coastguard Worker addChild(new RandomFragmentOpCase(m_context, de::toString(ndx).c_str(), "",
440*35238bceSAndroid Build Coastguard Worker (uint32_t)(ndx * NUM_ITERATIONS_PER_CASE)));
441*35238bceSAndroid Build Coastguard Worker }
442*35238bceSAndroid Build Coastguard Worker
443*35238bceSAndroid Build Coastguard Worker } // namespace Functional
444*35238bceSAndroid Build Coastguard Worker } // namespace gles3
445*35238bceSAndroid Build Coastguard Worker } // namespace deqp
446