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 Depth and stencil clear tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es3fDepthStencilClearTests.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
29*35238bceSAndroid Build Coastguard Worker
30*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
36*35238bceSAndroid Build Coastguard Worker
37*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
39*35238bceSAndroid Build Coastguard Worker #include "deString.h"
40*35238bceSAndroid Build Coastguard Worker
41*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
43*35238bceSAndroid Build Coastguard Worker
44*35238bceSAndroid Build Coastguard Worker namespace deqp
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace gles3
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker namespace Functional
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker
51*35238bceSAndroid Build Coastguard Worker using std::string;
52*35238bceSAndroid Build Coastguard Worker using std::vector;
53*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
54*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
55*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
56*35238bceSAndroid Build Coastguard Worker
57*35238bceSAndroid Build Coastguard Worker namespace
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker
60*35238bceSAndroid Build Coastguard Worker enum
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker STENCIL_STEPS = 32,
63*35238bceSAndroid Build Coastguard Worker DEPTH_STEPS = 32
64*35238bceSAndroid Build Coastguard Worker };
65*35238bceSAndroid Build Coastguard Worker
66*35238bceSAndroid Build Coastguard Worker struct Clear
67*35238bceSAndroid Build Coastguard Worker {
Cleardeqp::gles3::Functional::__anonde2a0efa0111::Clear68*35238bceSAndroid Build Coastguard Worker Clear(void)
69*35238bceSAndroid Build Coastguard Worker : clearMask(0)
70*35238bceSAndroid Build Coastguard Worker , clearDepth(0.0f)
71*35238bceSAndroid Build Coastguard Worker , clearStencil(0)
72*35238bceSAndroid Build Coastguard Worker , useScissor(false)
73*35238bceSAndroid Build Coastguard Worker , scissor(0, 0, 0, 0)
74*35238bceSAndroid Build Coastguard Worker , depthMask(false)
75*35238bceSAndroid Build Coastguard Worker , stencilMask(0)
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker
79*35238bceSAndroid Build Coastguard Worker uint32_t clearMask;
80*35238bceSAndroid Build Coastguard Worker float clearDepth;
81*35238bceSAndroid Build Coastguard Worker int clearStencil;
82*35238bceSAndroid Build Coastguard Worker
83*35238bceSAndroid Build Coastguard Worker bool useScissor;
84*35238bceSAndroid Build Coastguard Worker tcu::IVec4 scissor;
85*35238bceSAndroid Build Coastguard Worker
86*35238bceSAndroid Build Coastguard Worker bool depthMask;
87*35238bceSAndroid Build Coastguard Worker uint32_t stencilMask;
88*35238bceSAndroid Build Coastguard Worker };
89*35238bceSAndroid Build Coastguard Worker
getDepthFormat(int depthBits)90*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getDepthFormat(int depthBits)
91*35238bceSAndroid Build Coastguard Worker {
92*35238bceSAndroid Build Coastguard Worker switch (depthBits)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker case 8:
95*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT8);
96*35238bceSAndroid Build Coastguard Worker case 16:
97*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
98*35238bceSAndroid Build Coastguard Worker case 24:
99*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT24);
100*35238bceSAndroid Build Coastguard Worker case 32:
101*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
102*35238bceSAndroid Build Coastguard Worker default:
103*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
104*35238bceSAndroid Build Coastguard Worker }
105*35238bceSAndroid Build Coastguard Worker }
106*35238bceSAndroid Build Coastguard Worker
getStencilFormat(int stencilBits)107*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getStencilFormat(int stencilBits)
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker switch (stencilBits)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker case 8:
112*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8);
113*35238bceSAndroid Build Coastguard Worker case 16:
114*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT16);
115*35238bceSAndroid Build Coastguard Worker case 24:
116*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT24);
117*35238bceSAndroid Build Coastguard Worker case 32:
118*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32);
119*35238bceSAndroid Build Coastguard Worker default:
120*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
121*35238bceSAndroid Build Coastguard Worker }
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker
124*35238bceSAndroid Build Coastguard Worker } // namespace
125*35238bceSAndroid Build Coastguard Worker
126*35238bceSAndroid Build Coastguard Worker class DepthStencilClearCase : public TestCase
127*35238bceSAndroid Build Coastguard Worker {
128*35238bceSAndroid Build Coastguard Worker public:
129*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase(Context &context, const char *name, const char *description, int numIters, int numClears,
130*35238bceSAndroid Build Coastguard Worker bool depth, bool stencil, bool scissor, bool masked);
131*35238bceSAndroid Build Coastguard Worker ~DepthStencilClearCase(void);
132*35238bceSAndroid Build Coastguard Worker
133*35238bceSAndroid Build Coastguard Worker void init(void);
134*35238bceSAndroid Build Coastguard Worker void deinit(void);
135*35238bceSAndroid Build Coastguard Worker
136*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker private:
139*35238bceSAndroid Build Coastguard Worker void generateClears(vector<Clear> &dst, uint32_t seed);
140*35238bceSAndroid Build Coastguard Worker void renderGL(tcu::Surface &dst, const vector<Clear> &clears);
141*35238bceSAndroid Build Coastguard Worker void renderReference(tcu::Surface &dst, const vector<Clear> &clears);
142*35238bceSAndroid Build Coastguard Worker
143*35238bceSAndroid Build Coastguard Worker bool m_testDepth;
144*35238bceSAndroid Build Coastguard Worker bool m_testStencil;
145*35238bceSAndroid Build Coastguard Worker bool m_testScissor;
146*35238bceSAndroid Build Coastguard Worker bool m_masked;
147*35238bceSAndroid Build Coastguard Worker int m_numIters;
148*35238bceSAndroid Build Coastguard Worker int m_numClears;
149*35238bceSAndroid Build Coastguard Worker int m_curIter;
150*35238bceSAndroid Build Coastguard Worker
151*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram *m_visProgram;
152*35238bceSAndroid Build Coastguard Worker };
153*35238bceSAndroid Build Coastguard Worker
DepthStencilClearCase(Context & context,const char * name,const char * description,int numIters,int numClears,bool depth,bool stencil,bool scissor,bool masked)154*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::DepthStencilClearCase(Context &context, const char *name, const char *description, int numIters,
155*35238bceSAndroid Build Coastguard Worker int numClears, bool depth, bool stencil, bool scissor, bool masked)
156*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
157*35238bceSAndroid Build Coastguard Worker , m_testDepth(depth)
158*35238bceSAndroid Build Coastguard Worker , m_testStencil(stencil)
159*35238bceSAndroid Build Coastguard Worker , m_testScissor(scissor)
160*35238bceSAndroid Build Coastguard Worker , m_masked(masked)
161*35238bceSAndroid Build Coastguard Worker , m_numIters(numIters)
162*35238bceSAndroid Build Coastguard Worker , m_numClears(numClears)
163*35238bceSAndroid Build Coastguard Worker , m_curIter(0)
164*35238bceSAndroid Build Coastguard Worker , m_visProgram(DE_NULL)
165*35238bceSAndroid Build Coastguard Worker {
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker
~DepthStencilClearCase(void)168*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::~DepthStencilClearCase(void)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::deinit();
171*35238bceSAndroid Build Coastguard Worker }
172*35238bceSAndroid Build Coastguard Worker
init(void)173*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::init(void)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
176*35238bceSAndroid Build Coastguard Worker
177*35238bceSAndroid Build Coastguard Worker m_visProgram =
178*35238bceSAndroid Build Coastguard Worker new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(
179*35238bceSAndroid Build Coastguard Worker // Vertex shader.
180*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
181*35238bceSAndroid Build Coastguard Worker "in highp vec4 a_position;\n"
182*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
183*35238bceSAndroid Build Coastguard Worker "{\n"
184*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
185*35238bceSAndroid Build Coastguard Worker "}\n",
186*35238bceSAndroid Build Coastguard Worker
187*35238bceSAndroid Build Coastguard Worker // Fragment shader.
188*35238bceSAndroid Build Coastguard Worker "#version 300 es\n"
189*35238bceSAndroid Build Coastguard Worker "uniform mediump vec4 u_color;\n"
190*35238bceSAndroid Build Coastguard Worker "layout(location = 0) out mediump vec4 o_color;\n"
191*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
192*35238bceSAndroid Build Coastguard Worker "{\n"
193*35238bceSAndroid Build Coastguard Worker " o_color = u_color;\n"
194*35238bceSAndroid Build Coastguard Worker "}\n"));
195*35238bceSAndroid Build Coastguard Worker
196*35238bceSAndroid Build Coastguard Worker if (!m_visProgram->isOk())
197*35238bceSAndroid Build Coastguard Worker {
198*35238bceSAndroid Build Coastguard Worker log << *m_visProgram;
199*35238bceSAndroid Build Coastguard Worker delete m_visProgram;
200*35238bceSAndroid Build Coastguard Worker m_visProgram = DE_NULL;
201*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Compile failed");
202*35238bceSAndroid Build Coastguard Worker }
203*35238bceSAndroid Build Coastguard Worker
204*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
205*35238bceSAndroid Build Coastguard Worker }
206*35238bceSAndroid Build Coastguard Worker
deinit(void)207*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::deinit(void)
208*35238bceSAndroid Build Coastguard Worker {
209*35238bceSAndroid Build Coastguard Worker delete m_visProgram;
210*35238bceSAndroid Build Coastguard Worker m_visProgram = DE_NULL;
211*35238bceSAndroid Build Coastguard Worker }
212*35238bceSAndroid Build Coastguard Worker
iterate(void)213*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::IterateResult DepthStencilClearCase::iterate(void)
214*35238bceSAndroid Build Coastguard Worker {
215*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
216*35238bceSAndroid Build Coastguard Worker int width = renderTarget.getWidth();
217*35238bceSAndroid Build Coastguard Worker int height = renderTarget.getHeight();
218*35238bceSAndroid Build Coastguard Worker tcu::Surface result(width, height);
219*35238bceSAndroid Build Coastguard Worker tcu::Surface reference(width, height);
220*35238bceSAndroid Build Coastguard Worker tcu::RGBA threshold = renderTarget.getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
221*35238bceSAndroid Build Coastguard Worker vector<Clear> clears;
222*35238bceSAndroid Build Coastguard Worker
223*35238bceSAndroid Build Coastguard Worker if ((m_testDepth && renderTarget.getDepthBits() == 0) || (m_testStencil && renderTarget.getStencilBits() == 0))
224*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("No depth/stencil buffers", "", __FILE__, __LINE__);
225*35238bceSAndroid Build Coastguard Worker
226*35238bceSAndroid Build Coastguard Worker generateClears(clears, deStringHash(getName()) ^ deInt32Hash(m_curIter));
227*35238bceSAndroid Build Coastguard Worker renderGL(result, clears);
228*35238bceSAndroid Build Coastguard Worker renderReference(reference, clears);
229*35238bceSAndroid Build Coastguard Worker
230*35238bceSAndroid Build Coastguard Worker bool isLastIter = m_curIter + 1 == m_numIters;
231*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::pixelThresholdCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result,
232*35238bceSAndroid Build Coastguard Worker threshold, isLastIter ? tcu::COMPARE_LOG_RESULT : tcu::COMPARE_LOG_ON_ERROR);
233*35238bceSAndroid Build Coastguard Worker
234*35238bceSAndroid Build Coastguard Worker if (!isOk)
235*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
236*35238bceSAndroid Build Coastguard Worker
237*35238bceSAndroid Build Coastguard Worker m_curIter += 1;
238*35238bceSAndroid Build Coastguard Worker return isLastIter || !isOk ? STOP : CONTINUE;
239*35238bceSAndroid Build Coastguard Worker }
240*35238bceSAndroid Build Coastguard Worker
generateClears(vector<Clear> & clears,uint32_t seed)241*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::generateClears(vector<Clear> &clears, uint32_t seed)
242*35238bceSAndroid Build Coastguard Worker {
243*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
244*35238bceSAndroid Build Coastguard Worker int width = renderTarget.getWidth();
245*35238bceSAndroid Build Coastguard Worker int height = renderTarget.getHeight();
246*35238bceSAndroid Build Coastguard Worker de::Random rnd(seed);
247*35238bceSAndroid Build Coastguard Worker
248*35238bceSAndroid Build Coastguard Worker clears.resize(m_numClears);
249*35238bceSAndroid Build Coastguard Worker
250*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::iterator clear = clears.begin(); clear != clears.end(); clear++)
251*35238bceSAndroid Build Coastguard Worker {
252*35238bceSAndroid Build Coastguard Worker if (m_testScissor)
253*35238bceSAndroid Build Coastguard Worker {
254*35238bceSAndroid Build Coastguard Worker int w = rnd.getInt(1, width);
255*35238bceSAndroid Build Coastguard Worker int h = rnd.getInt(1, height);
256*35238bceSAndroid Build Coastguard Worker int x = rnd.getInt(0, width - w);
257*35238bceSAndroid Build Coastguard Worker int y = rnd.getInt(0, height - h);
258*35238bceSAndroid Build Coastguard Worker
259*35238bceSAndroid Build Coastguard Worker clear->useScissor = true; // \todo [pyry] Should we randomize?
260*35238bceSAndroid Build Coastguard Worker clear->scissor = tcu::IVec4(x, y, w, h);
261*35238bceSAndroid Build Coastguard Worker }
262*35238bceSAndroid Build Coastguard Worker else
263*35238bceSAndroid Build Coastguard Worker clear->useScissor = false;
264*35238bceSAndroid Build Coastguard Worker
265*35238bceSAndroid Build Coastguard Worker clear->clearDepth = rnd.getFloat(-0.2f, 1.2f);
266*35238bceSAndroid Build Coastguard Worker clear->clearStencil = rnd.getUint32();
267*35238bceSAndroid Build Coastguard Worker
268*35238bceSAndroid Build Coastguard Worker clear->depthMask = m_masked ? rnd.getBool() : true;
269*35238bceSAndroid Build Coastguard Worker clear->stencilMask = m_masked ? rnd.getUint32() : 0xffffffffu;
270*35238bceSAndroid Build Coastguard Worker
271*35238bceSAndroid Build Coastguard Worker if (m_testDepth && m_testStencil)
272*35238bceSAndroid Build Coastguard Worker {
273*35238bceSAndroid Build Coastguard Worker switch (rnd.getInt(0, 2))
274*35238bceSAndroid Build Coastguard Worker {
275*35238bceSAndroid Build Coastguard Worker case 0:
276*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT;
277*35238bceSAndroid Build Coastguard Worker break;
278*35238bceSAndroid Build Coastguard Worker case 1:
279*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_STENCIL_BUFFER_BIT;
280*35238bceSAndroid Build Coastguard Worker break;
281*35238bceSAndroid Build Coastguard Worker case 2:
282*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
283*35238bceSAndroid Build Coastguard Worker break;
284*35238bceSAndroid Build Coastguard Worker }
285*35238bceSAndroid Build Coastguard Worker }
286*35238bceSAndroid Build Coastguard Worker else if (m_testDepth)
287*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT;
288*35238bceSAndroid Build Coastguard Worker else
289*35238bceSAndroid Build Coastguard Worker {
290*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_testStencil);
291*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_STENCIL_BUFFER_BIT;
292*35238bceSAndroid Build Coastguard Worker }
293*35238bceSAndroid Build Coastguard Worker }
294*35238bceSAndroid Build Coastguard Worker }
295*35238bceSAndroid Build Coastguard Worker
renderGL(tcu::Surface & dst,const vector<Clear> & clears)296*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::renderGL(tcu::Surface &dst, const vector<Clear> &clears)
297*35238bceSAndroid Build Coastguard Worker {
298*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
299*35238bceSAndroid Build Coastguard Worker int colorLoc = gl.getUniformLocation(m_visProgram->getProgram(), "u_color");
300*35238bceSAndroid Build Coastguard Worker int positionLoc = gl.getAttribLocation(m_visProgram->getProgram(), "a_position");
301*35238bceSAndroid Build Coastguard Worker static const uint8_t indices[] = {0, 1, 2, 2, 1, 3};
302*35238bceSAndroid Build Coastguard Worker
303*35238bceSAndroid Build Coastguard Worker // Clear with default values.
304*35238bceSAndroid Build Coastguard Worker gl.clearDepthf(1.0f);
305*35238bceSAndroid Build Coastguard Worker gl.clearStencil(0);
306*35238bceSAndroid Build Coastguard Worker gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
307*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
308*35238bceSAndroid Build Coastguard Worker
309*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Before clears");
310*35238bceSAndroid Build Coastguard Worker
311*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
312*35238bceSAndroid Build Coastguard Worker {
313*35238bceSAndroid Build Coastguard Worker if (clear->useScissor)
314*35238bceSAndroid Build Coastguard Worker {
315*35238bceSAndroid Build Coastguard Worker gl.enable(GL_SCISSOR_TEST);
316*35238bceSAndroid Build Coastguard Worker gl.scissor(clear->scissor.x(), clear->scissor.y(), clear->scissor.z(), clear->scissor.w());
317*35238bceSAndroid Build Coastguard Worker }
318*35238bceSAndroid Build Coastguard Worker
319*35238bceSAndroid Build Coastguard Worker // Clear values.
320*35238bceSAndroid Build Coastguard Worker gl.clearDepthf(clear->clearDepth);
321*35238bceSAndroid Build Coastguard Worker gl.clearStencil(clear->clearStencil);
322*35238bceSAndroid Build Coastguard Worker
323*35238bceSAndroid Build Coastguard Worker // Masks.
324*35238bceSAndroid Build Coastguard Worker gl.depthMask(clear->depthMask ? GL_TRUE : GL_FALSE);
325*35238bceSAndroid Build Coastguard Worker gl.stencilMask(clear->stencilMask);
326*35238bceSAndroid Build Coastguard Worker
327*35238bceSAndroid Build Coastguard Worker // Execute clear.
328*35238bceSAndroid Build Coastguard Worker gl.clear(clear->clearMask);
329*35238bceSAndroid Build Coastguard Worker
330*35238bceSAndroid Build Coastguard Worker if (clear->useScissor)
331*35238bceSAndroid Build Coastguard Worker gl.disable(GL_SCISSOR_TEST);
332*35238bceSAndroid Build Coastguard Worker }
333*35238bceSAndroid Build Coastguard Worker
334*35238bceSAndroid Build Coastguard Worker // Restore default masks.
335*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_TRUE);
336*35238bceSAndroid Build Coastguard Worker gl.stencilMask(0xffffffffu);
337*35238bceSAndroid Build Coastguard Worker
338*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After clears");
339*35238bceSAndroid Build Coastguard Worker
340*35238bceSAndroid Build Coastguard Worker gl.useProgram(m_visProgram->getProgram());
341*35238bceSAndroid Build Coastguard Worker gl.enableVertexAttribArray(positionLoc);
342*35238bceSAndroid Build Coastguard Worker
343*35238bceSAndroid Build Coastguard Worker // Visualize depth / stencil buffers.
344*35238bceSAndroid Build Coastguard Worker if (m_testDepth)
345*35238bceSAndroid Build Coastguard Worker {
346*35238bceSAndroid Build Coastguard Worker int numSteps = DEPTH_STEPS;
347*35238bceSAndroid Build Coastguard Worker float step = 2.0f / (float)numSteps;
348*35238bceSAndroid Build Coastguard Worker
349*35238bceSAndroid Build Coastguard Worker gl.enable(GL_DEPTH_TEST);
350*35238bceSAndroid Build Coastguard Worker gl.depthFunc(GL_LESS);
351*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_FALSE);
352*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
353*35238bceSAndroid Build Coastguard Worker
354*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numSteps; ndx++)
355*35238bceSAndroid Build Coastguard Worker {
356*35238bceSAndroid Build Coastguard Worker float d = -1.0f + step * (float)ndx;
357*35238bceSAndroid Build Coastguard Worker float c = (float)ndx / (float)(numSteps - 1);
358*35238bceSAndroid Build Coastguard Worker float pos[] = {-1.0f, -1.0f, d, -1.0f, 1.0f, d, 1.0f, -1.0f, d, 1.0f, 1.0f, d};
359*35238bceSAndroid Build Coastguard Worker
360*35238bceSAndroid Build Coastguard Worker gl.uniform4f(colorLoc, 0.0f, 0.0f, c, 1.0f);
361*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, &pos[0]);
362*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]);
363*35238bceSAndroid Build Coastguard Worker }
364*35238bceSAndroid Build Coastguard Worker
365*35238bceSAndroid Build Coastguard Worker gl.disable(GL_DEPTH_TEST);
366*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_TRUE);
367*35238bceSAndroid Build Coastguard Worker
368*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After depth visualization");
369*35238bceSAndroid Build Coastguard Worker }
370*35238bceSAndroid Build Coastguard Worker
371*35238bceSAndroid Build Coastguard Worker if (m_testStencil)
372*35238bceSAndroid Build Coastguard Worker {
373*35238bceSAndroid Build Coastguard Worker int numSteps = STENCIL_STEPS;
374*35238bceSAndroid Build Coastguard Worker int numValues = (1 << TestCase::m_context.getRenderContext().getRenderTarget().getStencilBits()); // 2^bits
375*35238bceSAndroid Build Coastguard Worker int step = numValues / numSteps;
376*35238bceSAndroid Build Coastguard Worker
377*35238bceSAndroid Build Coastguard Worker gl.enable(GL_STENCIL_TEST);
378*35238bceSAndroid Build Coastguard Worker gl.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
379*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
380*35238bceSAndroid Build Coastguard Worker
381*35238bceSAndroid Build Coastguard Worker static const float pos[] = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
382*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 0, &pos[0]);
383*35238bceSAndroid Build Coastguard Worker
384*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numSteps; ndx++)
385*35238bceSAndroid Build Coastguard Worker {
386*35238bceSAndroid Build Coastguard Worker int s = step * ndx;
387*35238bceSAndroid Build Coastguard Worker float c = (float)ndx / (float)(numSteps - 1);
388*35238bceSAndroid Build Coastguard Worker
389*35238bceSAndroid Build Coastguard Worker gl.stencilFunc(GL_LEQUAL, s, 0xffu);
390*35238bceSAndroid Build Coastguard Worker gl.uniform4f(colorLoc, 0.0f, c, 0.0f, 1.0f);
391*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]);
392*35238bceSAndroid Build Coastguard Worker }
393*35238bceSAndroid Build Coastguard Worker
394*35238bceSAndroid Build Coastguard Worker gl.disable(GL_STENCIL_TEST);
395*35238bceSAndroid Build Coastguard Worker
396*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After stencil visualization");
397*35238bceSAndroid Build Coastguard Worker }
398*35238bceSAndroid Build Coastguard Worker
399*35238bceSAndroid Build Coastguard Worker // Restore color mask (changed by visualization).
400*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
401*35238bceSAndroid Build Coastguard Worker
402*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
403*35238bceSAndroid Build Coastguard Worker }
404*35238bceSAndroid Build Coastguard Worker
renderReference(tcu::Surface & dst,const vector<Clear> & clears)405*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::renderReference(tcu::Surface &dst, const vector<Clear> &clears)
406*35238bceSAndroid Build Coastguard Worker {
407*35238bceSAndroid Build Coastguard Worker glu::RenderContext &renderCtx = TestCase::m_context.getRenderContext();
408*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = renderCtx.getRenderTarget();
409*35238bceSAndroid Build Coastguard Worker
410*35238bceSAndroid Build Coastguard Worker // Clear surface to red.
411*35238bceSAndroid Build Coastguard Worker tcu::clear(dst.getAccess(), tcu::RGBA::red().toVec());
412*35238bceSAndroid Build Coastguard Worker
413*35238bceSAndroid Build Coastguard Worker if (m_testDepth)
414*35238bceSAndroid Build Coastguard Worker {
415*35238bceSAndroid Build Coastguard Worker // Simulated depth buffer span.
416*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel depthBufRow(getDepthFormat(renderTarget.getDepthBits()), dst.getWidth(), 1, 1);
417*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess();
418*35238bceSAndroid Build Coastguard Worker
419*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dst.getHeight(); y++)
420*35238bceSAndroid Build Coastguard Worker {
421*35238bceSAndroid Build Coastguard Worker // Clear to default value.
422*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < rowAccess.getWidth(); x++)
423*35238bceSAndroid Build Coastguard Worker rowAccess.setPixel(Vec4(1.0f), x, 0);
424*35238bceSAndroid Build Coastguard Worker
425*35238bceSAndroid Build Coastguard Worker // Execute clears.
426*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
427*35238bceSAndroid Build Coastguard Worker {
428*35238bceSAndroid Build Coastguard Worker // Clear / mask test.
429*35238bceSAndroid Build Coastguard Worker if ((clear->clearMask & GL_DEPTH_BUFFER_BIT) == 0 || !clear->depthMask)
430*35238bceSAndroid Build Coastguard Worker continue;
431*35238bceSAndroid Build Coastguard Worker
432*35238bceSAndroid Build Coastguard Worker tcu::IVec4 clearRect =
433*35238bceSAndroid Build Coastguard Worker clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight());
434*35238bceSAndroid Build Coastguard Worker
435*35238bceSAndroid Build Coastguard Worker // Intersection test.
436*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(y, clearRect.y(), clearRect.y() + clearRect.w()))
437*35238bceSAndroid Build Coastguard Worker continue;
438*35238bceSAndroid Build Coastguard Worker
439*35238bceSAndroid Build Coastguard Worker for (int x = clearRect.x(); x < clearRect.x() + clearRect.z(); x++)
440*35238bceSAndroid Build Coastguard Worker rowAccess.setPixDepth(de::clamp(clear->clearDepth, 0.0f, 1.0f), x, 0);
441*35238bceSAndroid Build Coastguard Worker }
442*35238bceSAndroid Build Coastguard Worker
443*35238bceSAndroid Build Coastguard Worker // Map to colors.
444*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dst.getWidth(); x++)
445*35238bceSAndroid Build Coastguard Worker {
446*35238bceSAndroid Build Coastguard Worker float depth = rowAccess.getPixDepth(x, 0);
447*35238bceSAndroid Build Coastguard Worker float step = deFloatFloor(depth * (float)DEPTH_STEPS) / (float)(DEPTH_STEPS - 1);
448*35238bceSAndroid Build Coastguard Worker tcu::RGBA oldColor = dst.getPixel(x, y);
449*35238bceSAndroid Build Coastguard Worker tcu::RGBA newColor =
450*35238bceSAndroid Build Coastguard Worker tcu::RGBA(oldColor.getRed(), oldColor.getGreen(),
451*35238bceSAndroid Build Coastguard Worker deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getAlpha());
452*35238bceSAndroid Build Coastguard Worker
453*35238bceSAndroid Build Coastguard Worker dst.setPixel(x, y, newColor);
454*35238bceSAndroid Build Coastguard Worker }
455*35238bceSAndroid Build Coastguard Worker }
456*35238bceSAndroid Build Coastguard Worker }
457*35238bceSAndroid Build Coastguard Worker
458*35238bceSAndroid Build Coastguard Worker if (m_testStencil)
459*35238bceSAndroid Build Coastguard Worker {
460*35238bceSAndroid Build Coastguard Worker // Simulated stencil buffer span.
461*35238bceSAndroid Build Coastguard Worker int stencilBits = renderTarget.getStencilBits();
462*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel depthBufRow(getStencilFormat(stencilBits), dst.getWidth(), 1, 1);
463*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess();
464*35238bceSAndroid Build Coastguard Worker uint32_t bufMask = (1u << stencilBits) - 1;
465*35238bceSAndroid Build Coastguard Worker
466*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dst.getHeight(); y++)
467*35238bceSAndroid Build Coastguard Worker {
468*35238bceSAndroid Build Coastguard Worker // Clear to default value.
469*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < rowAccess.getWidth(); x++)
470*35238bceSAndroid Build Coastguard Worker rowAccess.setPixel(tcu::UVec4(0), x, 0);
471*35238bceSAndroid Build Coastguard Worker
472*35238bceSAndroid Build Coastguard Worker // Execute clears.
473*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
474*35238bceSAndroid Build Coastguard Worker {
475*35238bceSAndroid Build Coastguard Worker // Clear / mask test.
476*35238bceSAndroid Build Coastguard Worker if ((clear->clearMask & GL_STENCIL_BUFFER_BIT) == 0 || clear->stencilMask == 0)
477*35238bceSAndroid Build Coastguard Worker continue;
478*35238bceSAndroid Build Coastguard Worker
479*35238bceSAndroid Build Coastguard Worker tcu::IVec4 clearRect =
480*35238bceSAndroid Build Coastguard Worker clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight());
481*35238bceSAndroid Build Coastguard Worker
482*35238bceSAndroid Build Coastguard Worker // Intersection test.
483*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(y, clearRect.y(), clearRect.y() + clearRect.w()))
484*35238bceSAndroid Build Coastguard Worker continue;
485*35238bceSAndroid Build Coastguard Worker
486*35238bceSAndroid Build Coastguard Worker for (int x = clearRect.x(); x < clearRect.x() + clearRect.z(); x++)
487*35238bceSAndroid Build Coastguard Worker {
488*35238bceSAndroid Build Coastguard Worker uint32_t oldVal = rowAccess.getPixStencil(x, 0);
489*35238bceSAndroid Build Coastguard Worker uint32_t newVal =
490*35238bceSAndroid Build Coastguard Worker ((oldVal & ~clear->stencilMask) | (clear->clearStencil & clear->stencilMask)) & bufMask;
491*35238bceSAndroid Build Coastguard Worker rowAccess.setPixStencil(newVal, x, 0);
492*35238bceSAndroid Build Coastguard Worker }
493*35238bceSAndroid Build Coastguard Worker }
494*35238bceSAndroid Build Coastguard Worker
495*35238bceSAndroid Build Coastguard Worker // Map to colors.
496*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dst.getWidth(); x++)
497*35238bceSAndroid Build Coastguard Worker {
498*35238bceSAndroid Build Coastguard Worker uint32_t stencil = rowAccess.getPixStencil(x, 0);
499*35238bceSAndroid Build Coastguard Worker float step =
500*35238bceSAndroid Build Coastguard Worker (float)(stencil / ((1u << stencilBits) / (uint32_t)STENCIL_STEPS)) / (float)(STENCIL_STEPS - 1);
501*35238bceSAndroid Build Coastguard Worker tcu::RGBA oldColor = dst.getPixel(x, y);
502*35238bceSAndroid Build Coastguard Worker tcu::RGBA newColor = tcu::RGBA(oldColor.getRed(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255),
503*35238bceSAndroid Build Coastguard Worker oldColor.getBlue(), oldColor.getAlpha());
504*35238bceSAndroid Build Coastguard Worker
505*35238bceSAndroid Build Coastguard Worker dst.setPixel(x, y, newColor);
506*35238bceSAndroid Build Coastguard Worker }
507*35238bceSAndroid Build Coastguard Worker }
508*35238bceSAndroid Build Coastguard Worker }
509*35238bceSAndroid Build Coastguard Worker }
510*35238bceSAndroid Build Coastguard Worker
DepthStencilClearTests(Context & context)511*35238bceSAndroid Build Coastguard Worker DepthStencilClearTests::DepthStencilClearTests(Context &context)
512*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "depth_stencil_clear", "Depth and stencil clear tests")
513*35238bceSAndroid Build Coastguard Worker {
514*35238bceSAndroid Build Coastguard Worker }
515*35238bceSAndroid Build Coastguard Worker
init(void)516*35238bceSAndroid Build Coastguard Worker void DepthStencilClearTests::init(void)
517*35238bceSAndroid Build Coastguard Worker {
518*35238bceSAndroid Build Coastguard Worker // iters clears depth stencil scissor masked
519*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth", "", 4, 2, true, false, false, false));
520*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_scissored", "", 4, 16, true, false, true, false));
521*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_scissored_masked", "", 4, 16, true, false, true, true));
522*35238bceSAndroid Build Coastguard Worker
523*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil", "", 4, 2, false, true, false, false));
524*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_masked", "", 4, 8, false, true, false, true));
525*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_scissored", "", 4, 16, false, true, true, false));
526*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_scissored_masked", "", 4, 16, false, true, true, true));
527*35238bceSAndroid Build Coastguard Worker
528*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil", "", 4, 2, true, true, false, false));
529*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_masked", "", 4, 8, true, true, false, true));
530*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored", "", 4, 16, true, true, true, false));
531*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored_masked", "", 4, 16, true, true, true, true));
532*35238bceSAndroid Build Coastguard Worker }
533*35238bceSAndroid Build Coastguard Worker
534*35238bceSAndroid Build Coastguard Worker } // namespace Functional
535*35238bceSAndroid Build Coastguard Worker } // namespace gles3
536*35238bceSAndroid Build Coastguard Worker } // namespace deqp
537