1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program EGL Module
3*35238bceSAndroid Build Coastguard Worker * ---------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2015 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 Test EXT_buffer_age
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "teglBufferAgeTests.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker
31*35238bceSAndroid Build Coastguard Worker #include "egluNativeWindow.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "egluConfigFilter.hpp"
34*35238bceSAndroid Build Coastguard Worker
35*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
37*35238bceSAndroid Build Coastguard Worker
38*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
41*35238bceSAndroid Build Coastguard Worker
42*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
45*35238bceSAndroid Build Coastguard Worker
46*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
47*35238bceSAndroid Build Coastguard Worker #include "deString.h"
48*35238bceSAndroid Build Coastguard Worker
49*35238bceSAndroid Build Coastguard Worker #include <string>
50*35238bceSAndroid Build Coastguard Worker #include <vector>
51*35238bceSAndroid Build Coastguard Worker #include <sstream>
52*35238bceSAndroid Build Coastguard Worker
53*35238bceSAndroid Build Coastguard Worker using glw::GLubyte;
54*35238bceSAndroid Build Coastguard Worker using std::string;
55*35238bceSAndroid Build Coastguard Worker using std::vector;
56*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker using namespace eglw;
59*35238bceSAndroid Build Coastguard Worker
60*35238bceSAndroid Build Coastguard Worker namespace deqp
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker namespace egl
63*35238bceSAndroid Build Coastguard Worker {
64*35238bceSAndroid Build Coastguard Worker namespace
65*35238bceSAndroid Build Coastguard Worker {
66*35238bceSAndroid Build Coastguard Worker
67*35238bceSAndroid Build Coastguard Worker typedef tcu::Vector<GLubyte, 3> Color;
68*35238bceSAndroid Build Coastguard Worker
69*35238bceSAndroid Build Coastguard Worker class GLES2Renderer;
70*35238bceSAndroid Build Coastguard Worker
71*35238bceSAndroid Build Coastguard Worker class ReferenceRenderer;
72*35238bceSAndroid Build Coastguard Worker
73*35238bceSAndroid Build Coastguard Worker class BufferAgeTest : public TestCase
74*35238bceSAndroid Build Coastguard Worker {
75*35238bceSAndroid Build Coastguard Worker public:
76*35238bceSAndroid Build Coastguard Worker enum DrawType
77*35238bceSAndroid Build Coastguard Worker {
78*35238bceSAndroid Build Coastguard Worker DRAWTYPE_GLES2_CLEAR,
79*35238bceSAndroid Build Coastguard Worker DRAWTYPE_GLES2_RENDER
80*35238bceSAndroid Build Coastguard Worker };
81*35238bceSAndroid Build Coastguard Worker
82*35238bceSAndroid Build Coastguard Worker enum ResizeType
83*35238bceSAndroid Build Coastguard Worker {
84*35238bceSAndroid Build Coastguard Worker RESIZETYPE_NONE = 0,
85*35238bceSAndroid Build Coastguard Worker RESIZETYPE_BEFORE_SWAP,
86*35238bceSAndroid Build Coastguard Worker RESIZETYPE_AFTER_SWAP,
87*35238bceSAndroid Build Coastguard Worker
88*35238bceSAndroid Build Coastguard Worker RESIZETYPE_LAST
89*35238bceSAndroid Build Coastguard Worker };
90*35238bceSAndroid Build Coastguard Worker
91*35238bceSAndroid Build Coastguard Worker BufferAgeTest(EglTestContext &eglTestCtx, bool preserveColorBuffer, const vector<DrawType> &oddFrameDrawType,
92*35238bceSAndroid Build Coastguard Worker const vector<DrawType> &evenFrameDrawType, ResizeType resizeType, const char *name,
93*35238bceSAndroid Build Coastguard Worker const char *description);
94*35238bceSAndroid Build Coastguard Worker
95*35238bceSAndroid Build Coastguard Worker ~BufferAgeTest(void);
96*35238bceSAndroid Build Coastguard Worker
97*35238bceSAndroid Build Coastguard Worker void init(void);
98*35238bceSAndroid Build Coastguard Worker void deinit(void);
99*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
100*35238bceSAndroid Build Coastguard Worker
101*35238bceSAndroid Build Coastguard Worker private:
102*35238bceSAndroid Build Coastguard Worker void initEGLSurface(EGLConfig config);
103*35238bceSAndroid Build Coastguard Worker void initEGLContext(EGLConfig config);
104*35238bceSAndroid Build Coastguard Worker
105*35238bceSAndroid Build Coastguard Worker const int m_seed;
106*35238bceSAndroid Build Coastguard Worker const bool m_preserveColorBuffer;
107*35238bceSAndroid Build Coastguard Worker const vector<DrawType> m_oddFrameDrawType;
108*35238bceSAndroid Build Coastguard Worker const vector<DrawType> m_evenFrameDrawType;
109*35238bceSAndroid Build Coastguard Worker const ResizeType m_resizeType;
110*35238bceSAndroid Build Coastguard Worker
111*35238bceSAndroid Build Coastguard Worker EGLDisplay m_eglDisplay;
112*35238bceSAndroid Build Coastguard Worker eglu::NativeWindow *m_window;
113*35238bceSAndroid Build Coastguard Worker EGLSurface m_eglSurface;
114*35238bceSAndroid Build Coastguard Worker EGLConfig m_eglConfig;
115*35238bceSAndroid Build Coastguard Worker EGLContext m_eglContext;
116*35238bceSAndroid Build Coastguard Worker glw::Functions m_gl;
117*35238bceSAndroid Build Coastguard Worker
118*35238bceSAndroid Build Coastguard Worker GLES2Renderer *m_gles2Renderer;
119*35238bceSAndroid Build Coastguard Worker ReferenceRenderer *m_refRenderer;
120*35238bceSAndroid Build Coastguard Worker };
121*35238bceSAndroid Build Coastguard Worker
122*35238bceSAndroid Build Coastguard Worker struct ColoredRect
123*35238bceSAndroid Build Coastguard Worker {
124*35238bceSAndroid Build Coastguard Worker public:
125*35238bceSAndroid Build Coastguard Worker ColoredRect(const IVec2 &bottomLeft_, const IVec2 &topRight_, const Color &color_);
126*35238bceSAndroid Build Coastguard Worker IVec2 bottomLeft;
127*35238bceSAndroid Build Coastguard Worker IVec2 topRight;
128*35238bceSAndroid Build Coastguard Worker Color color;
129*35238bceSAndroid Build Coastguard Worker };
130*35238bceSAndroid Build Coastguard Worker
ColoredRect(const IVec2 & bottomLeft_,const IVec2 & topRight_,const Color & color_)131*35238bceSAndroid Build Coastguard Worker ColoredRect::ColoredRect(const IVec2 &bottomLeft_, const IVec2 &topRight_, const Color &color_)
132*35238bceSAndroid Build Coastguard Worker : bottomLeft(bottomLeft_)
133*35238bceSAndroid Build Coastguard Worker , topRight(topRight_)
134*35238bceSAndroid Build Coastguard Worker , color(color_)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker }
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker struct DrawCommand
139*35238bceSAndroid Build Coastguard Worker {
140*35238bceSAndroid Build Coastguard Worker DrawCommand(const BufferAgeTest::DrawType drawType_, const ColoredRect &rect_);
141*35238bceSAndroid Build Coastguard Worker BufferAgeTest::DrawType drawType;
142*35238bceSAndroid Build Coastguard Worker ColoredRect rect;
143*35238bceSAndroid Build Coastguard Worker };
144*35238bceSAndroid Build Coastguard Worker
DrawCommand(const BufferAgeTest::DrawType drawType_,const ColoredRect & rect_)145*35238bceSAndroid Build Coastguard Worker DrawCommand::DrawCommand(const BufferAgeTest::DrawType drawType_, const ColoredRect &rect_)
146*35238bceSAndroid Build Coastguard Worker : drawType(drawType_)
147*35238bceSAndroid Build Coastguard Worker , rect(rect_)
148*35238bceSAndroid Build Coastguard Worker {
149*35238bceSAndroid Build Coastguard Worker }
150*35238bceSAndroid Build Coastguard Worker
151*35238bceSAndroid Build Coastguard Worker struct Frame
152*35238bceSAndroid Build Coastguard Worker {
153*35238bceSAndroid Build Coastguard Worker Frame(int width_, int height_);
154*35238bceSAndroid Build Coastguard Worker int width;
155*35238bceSAndroid Build Coastguard Worker int height;
156*35238bceSAndroid Build Coastguard Worker vector<DrawCommand> draws;
157*35238bceSAndroid Build Coastguard Worker };
158*35238bceSAndroid Build Coastguard Worker
Frame(int width_,int height_)159*35238bceSAndroid Build Coastguard Worker Frame::Frame(int width_, int height_) : width(width_), height(height_)
160*35238bceSAndroid Build Coastguard Worker {
161*35238bceSAndroid Build Coastguard Worker }
162*35238bceSAndroid Build Coastguard Worker
163*35238bceSAndroid Build Coastguard Worker // (x1,y1) lie in the lower-left quadrant while (x2,y2) lie in the upper-right.
164*35238bceSAndroid Build Coastguard Worker // the coords are multiplied by 4 to amplify the minimial difference between coords to 4 (if not zero)
165*35238bceSAndroid Build Coastguard Worker // to avoid the situation where two edges are too close to each other which makes the rounding error
166*35238bceSAndroid Build Coastguard Worker // intoleratable by compareToReference()
generateRandomFrame(Frame * dst,const vector<BufferAgeTest::DrawType> & drawTypes,de::Random & rnd)167*35238bceSAndroid Build Coastguard Worker void generateRandomFrame(Frame *dst, const vector<BufferAgeTest::DrawType> &drawTypes, de::Random &rnd)
168*35238bceSAndroid Build Coastguard Worker {
169*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < drawTypes.size(); ndx++)
170*35238bceSAndroid Build Coastguard Worker {
171*35238bceSAndroid Build Coastguard Worker const int x1 = rnd.getInt(0, (dst->width - 1) / 8) * 4;
172*35238bceSAndroid Build Coastguard Worker const int y1 = rnd.getInt(0, (dst->height - 1) / 8) * 4;
173*35238bceSAndroid Build Coastguard Worker const int x2 = rnd.getInt((dst->width - 1) / 8, (dst->width - 1) / 4) * 4;
174*35238bceSAndroid Build Coastguard Worker const int y2 = rnd.getInt((dst->height - 1) / 8, (dst->height - 1) / 4) * 4;
175*35238bceSAndroid Build Coastguard Worker const GLubyte r = rnd.getUint8();
176*35238bceSAndroid Build Coastguard Worker const GLubyte g = rnd.getUint8();
177*35238bceSAndroid Build Coastguard Worker const GLubyte b = rnd.getUint8();
178*35238bceSAndroid Build Coastguard Worker const ColoredRect coloredRect(IVec2(x1, y1), IVec2(x2, y2), Color(r, g, b));
179*35238bceSAndroid Build Coastguard Worker const DrawCommand drawCommand(drawTypes[ndx], coloredRect);
180*35238bceSAndroid Build Coastguard Worker (*dst).draws.push_back(drawCommand);
181*35238bceSAndroid Build Coastguard Worker }
182*35238bceSAndroid Build Coastguard Worker }
183*35238bceSAndroid Build Coastguard Worker
184*35238bceSAndroid Build Coastguard Worker typedef vector<Frame> FrameSequence;
185*35238bceSAndroid Build Coastguard Worker
186*35238bceSAndroid Build Coastguard Worker //helper function declaration
187*35238bceSAndroid Build Coastguard Worker EGLConfig getEGLConfig(const Library &egl, EGLDisplay eglDisplay, bool preserveColorBuffer);
188*35238bceSAndroid Build Coastguard Worker void clearColorScreen(const glw::Functions &gl, const tcu::Vec4 &clearColor);
189*35238bceSAndroid Build Coastguard Worker void clearColorReference(tcu::Surface *ref, const tcu::Vec4 &clearColor);
190*35238bceSAndroid Build Coastguard Worker void readPixels(const glw::Functions &gl, tcu::Surface *screen);
191*35238bceSAndroid Build Coastguard Worker float windowToDeviceCoordinates(int x, int length);
192*35238bceSAndroid Build Coastguard Worker bool compareToReference(tcu::TestLog &log, const tcu::Surface &reference, const tcu::Surface &buffer, int frameNdx,
193*35238bceSAndroid Build Coastguard Worker int bufferNum);
194*35238bceSAndroid Build Coastguard Worker vector<int> getFramesOnBuffer(const vector<int> &bufferAges, int frameNdx);
195*35238bceSAndroid Build Coastguard Worker
196*35238bceSAndroid Build Coastguard Worker class GLES2Renderer
197*35238bceSAndroid Build Coastguard Worker {
198*35238bceSAndroid Build Coastguard Worker public:
199*35238bceSAndroid Build Coastguard Worker GLES2Renderer(const glw::Functions &gl);
200*35238bceSAndroid Build Coastguard Worker ~GLES2Renderer(void);
201*35238bceSAndroid Build Coastguard Worker void render(int width, int height, const Frame &frame) const;
202*35238bceSAndroid Build Coastguard Worker
203*35238bceSAndroid Build Coastguard Worker private:
204*35238bceSAndroid Build Coastguard Worker GLES2Renderer(const GLES2Renderer &);
205*35238bceSAndroid Build Coastguard Worker GLES2Renderer &operator=(const GLES2Renderer &);
206*35238bceSAndroid Build Coastguard Worker
207*35238bceSAndroid Build Coastguard Worker const glw::Functions &m_gl;
208*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram m_glProgram;
209*35238bceSAndroid Build Coastguard Worker glw::GLuint m_coordLoc;
210*35238bceSAndroid Build Coastguard Worker glw::GLuint m_colorLoc;
211*35238bceSAndroid Build Coastguard Worker };
212*35238bceSAndroid Build Coastguard Worker
213*35238bceSAndroid Build Coastguard Worker // generate sources for vertex and fragment buffer
getSources(void)214*35238bceSAndroid Build Coastguard Worker glu::ProgramSources getSources(void)
215*35238bceSAndroid Build Coastguard Worker {
216*35238bceSAndroid Build Coastguard Worker const char *const vertexShaderSource = "attribute mediump vec4 a_pos;\n"
217*35238bceSAndroid Build Coastguard Worker "attribute mediump vec4 a_color;\n"
218*35238bceSAndroid Build Coastguard Worker "varying mediump vec4 v_color;\n"
219*35238bceSAndroid Build Coastguard Worker "void main(void)\n"
220*35238bceSAndroid Build Coastguard Worker "{\n"
221*35238bceSAndroid Build Coastguard Worker "\tv_color = a_color;\n"
222*35238bceSAndroid Build Coastguard Worker "\tgl_Position = a_pos;\n"
223*35238bceSAndroid Build Coastguard Worker "}";
224*35238bceSAndroid Build Coastguard Worker
225*35238bceSAndroid Build Coastguard Worker const char *const fragmentShaderSource = "varying mediump vec4 v_color;\n"
226*35238bceSAndroid Build Coastguard Worker "void main(void)\n"
227*35238bceSAndroid Build Coastguard Worker "{\n"
228*35238bceSAndroid Build Coastguard Worker "\tgl_FragColor = v_color;\n"
229*35238bceSAndroid Build Coastguard Worker "}";
230*35238bceSAndroid Build Coastguard Worker
231*35238bceSAndroid Build Coastguard Worker return glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource);
232*35238bceSAndroid Build Coastguard Worker }
233*35238bceSAndroid Build Coastguard Worker
GLES2Renderer(const glw::Functions & gl)234*35238bceSAndroid Build Coastguard Worker GLES2Renderer::GLES2Renderer(const glw::Functions &gl)
235*35238bceSAndroid Build Coastguard Worker : m_gl(gl)
236*35238bceSAndroid Build Coastguard Worker , m_glProgram(gl, getSources())
237*35238bceSAndroid Build Coastguard Worker , m_coordLoc((glw::GLuint)-1)
238*35238bceSAndroid Build Coastguard Worker , m_colorLoc((glw::GLuint)-1)
239*35238bceSAndroid Build Coastguard Worker {
240*35238bceSAndroid Build Coastguard Worker m_colorLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_color");
241*35238bceSAndroid Build Coastguard Worker m_coordLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_pos");
242*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to get attribute locations");
243*35238bceSAndroid Build Coastguard Worker }
244*35238bceSAndroid Build Coastguard Worker
~GLES2Renderer(void)245*35238bceSAndroid Build Coastguard Worker GLES2Renderer::~GLES2Renderer(void)
246*35238bceSAndroid Build Coastguard Worker {
247*35238bceSAndroid Build Coastguard Worker }
248*35238bceSAndroid Build Coastguard Worker
render(int width,int height,const Frame & frame) const249*35238bceSAndroid Build Coastguard Worker void GLES2Renderer::render(int width, int height, const Frame &frame) const
250*35238bceSAndroid Build Coastguard Worker {
251*35238bceSAndroid Build Coastguard Worker for (size_t drawNdx = 0; drawNdx < frame.draws.size(); drawNdx++)
252*35238bceSAndroid Build Coastguard Worker {
253*35238bceSAndroid Build Coastguard Worker const ColoredRect &coloredRect = frame.draws[drawNdx].rect;
254*35238bceSAndroid Build Coastguard Worker if (frame.draws[drawNdx].drawType == BufferAgeTest::DRAWTYPE_GLES2_RENDER)
255*35238bceSAndroid Build Coastguard Worker {
256*35238bceSAndroid Build Coastguard Worker float x1 = windowToDeviceCoordinates(coloredRect.bottomLeft.x(), width);
257*35238bceSAndroid Build Coastguard Worker float y1 = windowToDeviceCoordinates(coloredRect.bottomLeft.y(), height);
258*35238bceSAndroid Build Coastguard Worker float x2 = windowToDeviceCoordinates(coloredRect.topRight.x(), width);
259*35238bceSAndroid Build Coastguard Worker float y2 = windowToDeviceCoordinates(coloredRect.topRight.y(), height);
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker const glw::GLfloat coords[] = {x1, y1, 0.0f, 1.0f, x1, y2, 0.0f, 1.0f, x2, y2, 0.0f, 1.0f,
262*35238bceSAndroid Build Coastguard Worker
263*35238bceSAndroid Build Coastguard Worker x2, y2, 0.0f, 1.0f, x2, y1, 0.0f, 1.0f, x1, y1, 0.0f, 1.0f};
264*35238bceSAndroid Build Coastguard Worker
265*35238bceSAndroid Build Coastguard Worker const glw::GLubyte colors[] = {
266*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
267*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
268*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
269*35238bceSAndroid Build Coastguard Worker
270*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
271*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
272*35238bceSAndroid Build Coastguard Worker coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255,
273*35238bceSAndroid Build Coastguard Worker };
274*35238bceSAndroid Build Coastguard Worker
275*35238bceSAndroid Build Coastguard Worker m_gl.useProgram(m_glProgram.getProgram());
276*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
277*35238bceSAndroid Build Coastguard Worker
278*35238bceSAndroid Build Coastguard Worker m_gl.enableVertexAttribArray(m_coordLoc);
279*35238bceSAndroid Build Coastguard Worker m_gl.enableVertexAttribArray(m_colorLoc);
280*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to enable attributes");
281*35238bceSAndroid Build Coastguard Worker
282*35238bceSAndroid Build Coastguard Worker m_gl.vertexAttribPointer(m_coordLoc, 4, GL_FLOAT, GL_FALSE, 0, coords);
283*35238bceSAndroid Build Coastguard Worker m_gl.vertexAttribPointer(m_colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors);
284*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set attribute pointers");
285*35238bceSAndroid Build Coastguard Worker
286*35238bceSAndroid Build Coastguard Worker m_gl.drawArrays(GL_TRIANGLES, 0, DE_LENGTH_OF_ARRAY(coords) / 4);
287*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "glDrawArrays(), failed");
288*35238bceSAndroid Build Coastguard Worker
289*35238bceSAndroid Build Coastguard Worker m_gl.disableVertexAttribArray(m_coordLoc);
290*35238bceSAndroid Build Coastguard Worker m_gl.disableVertexAttribArray(m_colorLoc);
291*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to disable attributes");
292*35238bceSAndroid Build Coastguard Worker
293*35238bceSAndroid Build Coastguard Worker m_gl.useProgram(0);
294*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
295*35238bceSAndroid Build Coastguard Worker }
296*35238bceSAndroid Build Coastguard Worker else if (frame.draws[drawNdx].drawType == BufferAgeTest::DRAWTYPE_GLES2_CLEAR)
297*35238bceSAndroid Build Coastguard Worker {
298*35238bceSAndroid Build Coastguard Worker m_gl.enable(GL_SCISSOR_TEST);
299*35238bceSAndroid Build Coastguard Worker m_gl.scissor(coloredRect.bottomLeft.x(), coloredRect.bottomLeft.y(),
300*35238bceSAndroid Build Coastguard Worker coloredRect.topRight.x() - coloredRect.bottomLeft.x(),
301*35238bceSAndroid Build Coastguard Worker coloredRect.topRight.y() - coloredRect.bottomLeft.y());
302*35238bceSAndroid Build Coastguard Worker m_gl.clearColor(coloredRect.color.x() / 255.0f, coloredRect.color.y() / 255.0f,
303*35238bceSAndroid Build Coastguard Worker coloredRect.color.z() / 255.0f, 1.0f);
304*35238bceSAndroid Build Coastguard Worker m_gl.clear(GL_COLOR_BUFFER_BIT);
305*35238bceSAndroid Build Coastguard Worker m_gl.disable(GL_SCISSOR_TEST);
306*35238bceSAndroid Build Coastguard Worker }
307*35238bceSAndroid Build Coastguard Worker else
308*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
309*35238bceSAndroid Build Coastguard Worker }
310*35238bceSAndroid Build Coastguard Worker }
311*35238bceSAndroid Build Coastguard Worker
312*35238bceSAndroid Build Coastguard Worker class ReferenceRenderer
313*35238bceSAndroid Build Coastguard Worker {
314*35238bceSAndroid Build Coastguard Worker public:
315*35238bceSAndroid Build Coastguard Worker ReferenceRenderer(void);
316*35238bceSAndroid Build Coastguard Worker void render(tcu::Surface *target, const Frame &frame) const;
317*35238bceSAndroid Build Coastguard Worker
318*35238bceSAndroid Build Coastguard Worker private:
319*35238bceSAndroid Build Coastguard Worker ReferenceRenderer(const ReferenceRenderer &);
320*35238bceSAndroid Build Coastguard Worker ReferenceRenderer &operator=(const ReferenceRenderer &);
321*35238bceSAndroid Build Coastguard Worker };
322*35238bceSAndroid Build Coastguard Worker
ReferenceRenderer(void)323*35238bceSAndroid Build Coastguard Worker ReferenceRenderer::ReferenceRenderer(void)
324*35238bceSAndroid Build Coastguard Worker {
325*35238bceSAndroid Build Coastguard Worker }
326*35238bceSAndroid Build Coastguard Worker
render(tcu::Surface * target,const Frame & frame) const327*35238bceSAndroid Build Coastguard Worker void ReferenceRenderer::render(tcu::Surface *target, const Frame &frame) const
328*35238bceSAndroid Build Coastguard Worker {
329*35238bceSAndroid Build Coastguard Worker for (size_t drawNdx = 0; drawNdx < frame.draws.size(); drawNdx++)
330*35238bceSAndroid Build Coastguard Worker {
331*35238bceSAndroid Build Coastguard Worker const ColoredRect &coloredRect = frame.draws[drawNdx].rect;
332*35238bceSAndroid Build Coastguard Worker if (frame.draws[drawNdx].drawType == BufferAgeTest::DRAWTYPE_GLES2_RENDER ||
333*35238bceSAndroid Build Coastguard Worker frame.draws[drawNdx].drawType == BufferAgeTest::DRAWTYPE_GLES2_CLEAR)
334*35238bceSAndroid Build Coastguard Worker {
335*35238bceSAndroid Build Coastguard Worker // tcu does not support degenerate subregions. Since they correspond to no-op rendering, just skip them.
336*35238bceSAndroid Build Coastguard Worker if (coloredRect.bottomLeft.x() == coloredRect.topRight.x() ||
337*35238bceSAndroid Build Coastguard Worker coloredRect.bottomLeft.y() == coloredRect.topRight.y())
338*35238bceSAndroid Build Coastguard Worker continue;
339*35238bceSAndroid Build Coastguard Worker
340*35238bceSAndroid Build Coastguard Worker const tcu::UVec4 color(coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), 255);
341*35238bceSAndroid Build Coastguard Worker tcu::clear(tcu::getSubregion(target->getAccess(), coloredRect.bottomLeft.x(), coloredRect.bottomLeft.y(),
342*35238bceSAndroid Build Coastguard Worker coloredRect.topRight.x() - coloredRect.bottomLeft.x(),
343*35238bceSAndroid Build Coastguard Worker coloredRect.topRight.y() - coloredRect.bottomLeft.y()),
344*35238bceSAndroid Build Coastguard Worker color);
345*35238bceSAndroid Build Coastguard Worker }
346*35238bceSAndroid Build Coastguard Worker else
347*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
348*35238bceSAndroid Build Coastguard Worker }
349*35238bceSAndroid Build Coastguard Worker }
350*35238bceSAndroid Build Coastguard Worker
BufferAgeTest(EglTestContext & eglTestCtx,bool preserveColorBuffer,const vector<DrawType> & oddFrameDrawType,const vector<DrawType> & evenFrameDrawType,ResizeType resizeType,const char * name,const char * description)351*35238bceSAndroid Build Coastguard Worker BufferAgeTest::BufferAgeTest(EglTestContext &eglTestCtx, bool preserveColorBuffer,
352*35238bceSAndroid Build Coastguard Worker const vector<DrawType> &oddFrameDrawType, const vector<DrawType> &evenFrameDrawType,
353*35238bceSAndroid Build Coastguard Worker ResizeType resizeType, const char *name, const char *description)
354*35238bceSAndroid Build Coastguard Worker : TestCase(eglTestCtx, name, description)
355*35238bceSAndroid Build Coastguard Worker , m_seed(deStringHash(name))
356*35238bceSAndroid Build Coastguard Worker , m_preserveColorBuffer(preserveColorBuffer)
357*35238bceSAndroid Build Coastguard Worker , m_oddFrameDrawType(oddFrameDrawType)
358*35238bceSAndroid Build Coastguard Worker , m_evenFrameDrawType(evenFrameDrawType)
359*35238bceSAndroid Build Coastguard Worker , m_resizeType(resizeType)
360*35238bceSAndroid Build Coastguard Worker , m_eglDisplay(EGL_NO_DISPLAY)
361*35238bceSAndroid Build Coastguard Worker , m_window(DE_NULL)
362*35238bceSAndroid Build Coastguard Worker , m_eglSurface(EGL_NO_SURFACE)
363*35238bceSAndroid Build Coastguard Worker , m_eglContext(EGL_NO_CONTEXT)
364*35238bceSAndroid Build Coastguard Worker , m_gles2Renderer(DE_NULL)
365*35238bceSAndroid Build Coastguard Worker , m_refRenderer(DE_NULL)
366*35238bceSAndroid Build Coastguard Worker {
367*35238bceSAndroid Build Coastguard Worker }
368*35238bceSAndroid Build Coastguard Worker
~BufferAgeTest(void)369*35238bceSAndroid Build Coastguard Worker BufferAgeTest::~BufferAgeTest(void)
370*35238bceSAndroid Build Coastguard Worker {
371*35238bceSAndroid Build Coastguard Worker deinit();
372*35238bceSAndroid Build Coastguard Worker }
373*35238bceSAndroid Build Coastguard Worker
init(void)374*35238bceSAndroid Build Coastguard Worker void BufferAgeTest::init(void)
375*35238bceSAndroid Build Coastguard Worker {
376*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
377*35238bceSAndroid Build Coastguard Worker
378*35238bceSAndroid Build Coastguard Worker m_eglDisplay = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
379*35238bceSAndroid Build Coastguard Worker
380*35238bceSAndroid Build Coastguard Worker if (eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_buffer_age") == false)
381*35238bceSAndroid Build Coastguard Worker {
382*35238bceSAndroid Build Coastguard Worker egl.terminate(m_eglDisplay);
383*35238bceSAndroid Build Coastguard Worker m_eglDisplay = EGL_NO_DISPLAY;
384*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "EGL_EXT_buffer_age is not supported");
385*35238bceSAndroid Build Coastguard Worker }
386*35238bceSAndroid Build Coastguard Worker
387*35238bceSAndroid Build Coastguard Worker m_eglConfig = getEGLConfig(m_eglTestCtx.getLibrary(), m_eglDisplay, m_preserveColorBuffer);
388*35238bceSAndroid Build Coastguard Worker
389*35238bceSAndroid Build Coastguard Worker if (m_eglConfig == DE_NULL)
390*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "No supported config found");
391*35238bceSAndroid Build Coastguard Worker
392*35238bceSAndroid Build Coastguard Worker //create surface and context and make them current
393*35238bceSAndroid Build Coastguard Worker initEGLSurface(m_eglConfig);
394*35238bceSAndroid Build Coastguard Worker initEGLContext(m_eglConfig);
395*35238bceSAndroid Build Coastguard Worker
396*35238bceSAndroid Build Coastguard Worker m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
397*35238bceSAndroid Build Coastguard Worker
398*35238bceSAndroid Build Coastguard Worker m_gles2Renderer = new GLES2Renderer(m_gl);
399*35238bceSAndroid Build Coastguard Worker m_refRenderer = new ReferenceRenderer();
400*35238bceSAndroid Build Coastguard Worker }
401*35238bceSAndroid Build Coastguard Worker
deinit(void)402*35238bceSAndroid Build Coastguard Worker void BufferAgeTest::deinit(void)
403*35238bceSAndroid Build Coastguard Worker {
404*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
405*35238bceSAndroid Build Coastguard Worker
406*35238bceSAndroid Build Coastguard Worker delete m_refRenderer;
407*35238bceSAndroid Build Coastguard Worker m_refRenderer = DE_NULL;
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker delete m_gles2Renderer;
410*35238bceSAndroid Build Coastguard Worker m_gles2Renderer = DE_NULL;
411*35238bceSAndroid Build Coastguard Worker
412*35238bceSAndroid Build Coastguard Worker if (m_eglContext != EGL_NO_CONTEXT)
413*35238bceSAndroid Build Coastguard Worker {
414*35238bceSAndroid Build Coastguard Worker egl.makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
415*35238bceSAndroid Build Coastguard Worker egl.destroyContext(m_eglDisplay, m_eglContext);
416*35238bceSAndroid Build Coastguard Worker m_eglContext = EGL_NO_CONTEXT;
417*35238bceSAndroid Build Coastguard Worker }
418*35238bceSAndroid Build Coastguard Worker
419*35238bceSAndroid Build Coastguard Worker if (m_eglSurface != EGL_NO_SURFACE)
420*35238bceSAndroid Build Coastguard Worker {
421*35238bceSAndroid Build Coastguard Worker egl.destroySurface(m_eglDisplay, m_eglSurface);
422*35238bceSAndroid Build Coastguard Worker m_eglSurface = EGL_NO_SURFACE;
423*35238bceSAndroid Build Coastguard Worker }
424*35238bceSAndroid Build Coastguard Worker
425*35238bceSAndroid Build Coastguard Worker if (m_eglDisplay != EGL_NO_DISPLAY)
426*35238bceSAndroid Build Coastguard Worker {
427*35238bceSAndroid Build Coastguard Worker egl.terminate(m_eglDisplay);
428*35238bceSAndroid Build Coastguard Worker m_eglDisplay = EGL_NO_DISPLAY;
429*35238bceSAndroid Build Coastguard Worker }
430*35238bceSAndroid Build Coastguard Worker
431*35238bceSAndroid Build Coastguard Worker delete m_window;
432*35238bceSAndroid Build Coastguard Worker m_window = DE_NULL;
433*35238bceSAndroid Build Coastguard Worker }
434*35238bceSAndroid Build Coastguard Worker
initEGLSurface(EGLConfig config)435*35238bceSAndroid Build Coastguard Worker void BufferAgeTest::initEGLSurface(EGLConfig config)
436*35238bceSAndroid Build Coastguard Worker {
437*35238bceSAndroid Build Coastguard Worker const eglu::NativeWindowFactory &factory =
438*35238bceSAndroid Build Coastguard Worker eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
439*35238bceSAndroid Build Coastguard Worker m_window =
440*35238bceSAndroid Build Coastguard Worker factory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_eglDisplay, config, DE_NULL,
441*35238bceSAndroid Build Coastguard Worker eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
442*35238bceSAndroid Build Coastguard Worker m_eglSurface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_eglDisplay, config, DE_NULL);
443*35238bceSAndroid Build Coastguard Worker }
444*35238bceSAndroid Build Coastguard Worker
initEGLContext(EGLConfig config)445*35238bceSAndroid Build Coastguard Worker void BufferAgeTest::initEGLContext(EGLConfig config)
446*35238bceSAndroid Build Coastguard Worker {
447*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
448*35238bceSAndroid Build Coastguard Worker const EGLint attribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
449*35238bceSAndroid Build Coastguard Worker
450*35238bceSAndroid Build Coastguard Worker egl.bindAPI(EGL_OPENGL_ES_API);
451*35238bceSAndroid Build Coastguard Worker m_eglContext = egl.createContext(m_eglDisplay, config, EGL_NO_CONTEXT, attribList);
452*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "eglCreateContext");
453*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_eglSurface != EGL_NO_SURFACE);
454*35238bceSAndroid Build Coastguard Worker egl.makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
455*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "eglMakeCurrent");
456*35238bceSAndroid Build Coastguard Worker }
457*35238bceSAndroid Build Coastguard Worker
458*35238bceSAndroid Build Coastguard Worker // return indices of frames that have been written to the given buffer
getFramesOnBuffer(const vector<int> & bufferAges,int frameNdx)459*35238bceSAndroid Build Coastguard Worker vector<int> getFramesOnBuffer(const vector<int> &bufferAges, int frameNdx)
460*35238bceSAndroid Build Coastguard Worker {
461*35238bceSAndroid Build Coastguard Worker DE_ASSERT(frameNdx < (int)bufferAges.size());
462*35238bceSAndroid Build Coastguard Worker vector<int> frameOnBuffer;
463*35238bceSAndroid Build Coastguard Worker int age = bufferAges[frameNdx];
464*35238bceSAndroid Build Coastguard Worker while (age != 0)
465*35238bceSAndroid Build Coastguard Worker {
466*35238bceSAndroid Build Coastguard Worker frameNdx = frameNdx - age;
467*35238bceSAndroid Build Coastguard Worker DE_ASSERT(frameNdx >= 0);
468*35238bceSAndroid Build Coastguard Worker frameOnBuffer.push_back(frameNdx);
469*35238bceSAndroid Build Coastguard Worker age = bufferAges[frameNdx];
470*35238bceSAndroid Build Coastguard Worker }
471*35238bceSAndroid Build Coastguard Worker
472*35238bceSAndroid Build Coastguard Worker reverse(frameOnBuffer.begin(), frameOnBuffer.end());
473*35238bceSAndroid Build Coastguard Worker return frameOnBuffer;
474*35238bceSAndroid Build Coastguard Worker }
475*35238bceSAndroid Build Coastguard Worker
iterate(void)476*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult BufferAgeTest::iterate(void)
477*35238bceSAndroid Build Coastguard Worker {
478*35238bceSAndroid Build Coastguard Worker de::Random rnd(m_seed);
479*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
480*35238bceSAndroid Build Coastguard Worker tcu::TestLog &log = m_testCtx.getLog();
481*35238bceSAndroid Build Coastguard Worker const int width = eglu::querySurfaceInt(egl, m_eglDisplay, m_eglSurface, EGL_WIDTH);
482*35238bceSAndroid Build Coastguard Worker const int height = eglu::querySurfaceInt(egl, m_eglDisplay, m_eglSurface, EGL_HEIGHT);
483*35238bceSAndroid Build Coastguard Worker const float clearRed = rnd.getFloat();
484*35238bceSAndroid Build Coastguard Worker const float clearGreen = rnd.getFloat();
485*35238bceSAndroid Build Coastguard Worker const float clearBlue = rnd.getFloat();
486*35238bceSAndroid Build Coastguard Worker const tcu::Vec4 clearColor(clearRed, clearGreen, clearBlue, 1.0f);
487*35238bceSAndroid Build Coastguard Worker const int numFrames = 20;
488*35238bceSAndroid Build Coastguard Worker FrameSequence frameSequence;
489*35238bceSAndroid Build Coastguard Worker vector<int> bufferAges;
490*35238bceSAndroid Build Coastguard Worker
491*35238bceSAndroid Build Coastguard Worker if (m_preserveColorBuffer)
492*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
493*35238bceSAndroid Build Coastguard Worker else
494*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
495*35238bceSAndroid Build Coastguard Worker
496*35238bceSAndroid Build Coastguard Worker for (int frameNdx = 0; frameNdx < numFrames; frameNdx++)
497*35238bceSAndroid Build Coastguard Worker {
498*35238bceSAndroid Build Coastguard Worker tcu::Surface currentBuffer(width, height);
499*35238bceSAndroid Build Coastguard Worker tcu::Surface refBuffer(width, height);
500*35238bceSAndroid Build Coastguard Worker Frame newFrame(width, height);
501*35238bceSAndroid Build Coastguard Worker EGLint currentBufferAge = -1;
502*35238bceSAndroid Build Coastguard Worker
503*35238bceSAndroid Build Coastguard Worker if (frameNdx % 2 == 0)
504*35238bceSAndroid Build Coastguard Worker generateRandomFrame(&newFrame, m_evenFrameDrawType, rnd);
505*35238bceSAndroid Build Coastguard Worker else
506*35238bceSAndroid Build Coastguard Worker generateRandomFrame(&newFrame, m_oddFrameDrawType, rnd);
507*35238bceSAndroid Build Coastguard Worker
508*35238bceSAndroid Build Coastguard Worker frameSequence.push_back(newFrame);
509*35238bceSAndroid Build Coastguard Worker
510*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_BUFFER_AGE_EXT, ¤tBufferAge));
511*35238bceSAndroid Build Coastguard Worker
512*35238bceSAndroid Build Coastguard Worker if (currentBufferAge > frameNdx || currentBufferAge < 0) // invalid buffer age
513*35238bceSAndroid Build Coastguard Worker {
514*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
515*35238bceSAndroid Build Coastguard Worker stream << "Fail, the age is invalid. Age: " << currentBufferAge << ", frameNdx: " << frameNdx;
516*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, stream.str().c_str());
517*35238bceSAndroid Build Coastguard Worker return STOP;
518*35238bceSAndroid Build Coastguard Worker }
519*35238bceSAndroid Build Coastguard Worker
520*35238bceSAndroid Build Coastguard Worker if (frameNdx > 0 && m_preserveColorBuffer && currentBufferAge != 1)
521*35238bceSAndroid Build Coastguard Worker {
522*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
523*35238bceSAndroid Build Coastguard Worker stream << "Fail, EGL_BUFFER_PRESERVED is set to true, but buffer age is: " << currentBufferAge
524*35238bceSAndroid Build Coastguard Worker << " (should be 1)";
525*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, stream.str().c_str());
526*35238bceSAndroid Build Coastguard Worker return STOP;
527*35238bceSAndroid Build Coastguard Worker }
528*35238bceSAndroid Build Coastguard Worker
529*35238bceSAndroid Build Coastguard Worker bufferAges.push_back(currentBufferAge);
530*35238bceSAndroid Build Coastguard Worker DE_ASSERT((int)bufferAges.size() == frameNdx + 1);
531*35238bceSAndroid Build Coastguard Worker
532*35238bceSAndroid Build Coastguard Worker // during first half, just keep rendering without reading pixel back to mimic ordinary use case
533*35238bceSAndroid Build Coastguard Worker if (frameNdx < numFrames / 2)
534*35238bceSAndroid Build Coastguard Worker {
535*35238bceSAndroid Build Coastguard Worker if (currentBufferAge == 0)
536*35238bceSAndroid Build Coastguard Worker clearColorScreen(m_gl, clearColor);
537*35238bceSAndroid Build Coastguard Worker
538*35238bceSAndroid Build Coastguard Worker m_gles2Renderer->render(width, height, newFrame);
539*35238bceSAndroid Build Coastguard Worker
540*35238bceSAndroid Build Coastguard Worker if (m_resizeType == RESIZETYPE_BEFORE_SWAP)
541*35238bceSAndroid Build Coastguard Worker {
542*35238bceSAndroid Build Coastguard Worker if (frameNdx % 2 == 0)
543*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(width * 2, height / 2));
544*35238bceSAndroid Build Coastguard Worker else
545*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(height / 2, width * 2));
546*35238bceSAndroid Build Coastguard Worker }
547*35238bceSAndroid Build Coastguard Worker
548*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, m_eglSurface));
549*35238bceSAndroid Build Coastguard Worker
550*35238bceSAndroid Build Coastguard Worker if (m_resizeType == RESIZETYPE_AFTER_SWAP)
551*35238bceSAndroid Build Coastguard Worker {
552*35238bceSAndroid Build Coastguard Worker if (frameNdx % 2 == 0)
553*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(width * 2, height / 2));
554*35238bceSAndroid Build Coastguard Worker else
555*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(height / 2, width * 2));
556*35238bceSAndroid Build Coastguard Worker }
557*35238bceSAndroid Build Coastguard Worker
558*35238bceSAndroid Build Coastguard Worker continue;
559*35238bceSAndroid Build Coastguard Worker }
560*35238bceSAndroid Build Coastguard Worker
561*35238bceSAndroid Build Coastguard Worker // do verification in the second half
562*35238bceSAndroid Build Coastguard Worker if (currentBufferAge > 0) //buffer contain previous content, need to verify
563*35238bceSAndroid Build Coastguard Worker {
564*35238bceSAndroid Build Coastguard Worker const vector<int> framesOnBuffer = getFramesOnBuffer(bufferAges, frameNdx);
565*35238bceSAndroid Build Coastguard Worker readPixels(m_gl, ¤tBuffer);
566*35238bceSAndroid Build Coastguard Worker clearColorReference(&refBuffer, clearColor);
567*35238bceSAndroid Build Coastguard Worker
568*35238bceSAndroid Build Coastguard Worker for (vector<int>::const_iterator it = framesOnBuffer.begin(); it != framesOnBuffer.end(); it++)
569*35238bceSAndroid Build Coastguard Worker m_refRenderer->render(&refBuffer, frameSequence[*it]);
570*35238bceSAndroid Build Coastguard Worker
571*35238bceSAndroid Build Coastguard Worker if (compareToReference(log, refBuffer, currentBuffer, frameNdx, frameNdx - currentBufferAge) == false)
572*35238bceSAndroid Build Coastguard Worker {
573*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail, buffer content is not well preserved when age > 0");
574*35238bceSAndroid Build Coastguard Worker return STOP;
575*35238bceSAndroid Build Coastguard Worker }
576*35238bceSAndroid Build Coastguard Worker }
577*35238bceSAndroid Build Coastguard Worker else // currentBufferAge == 0, content is undefined, clear the buffer, currentBufferAge < 0 is ruled out at the beginning
578*35238bceSAndroid Build Coastguard Worker {
579*35238bceSAndroid Build Coastguard Worker clearColorScreen(m_gl, clearColor);
580*35238bceSAndroid Build Coastguard Worker clearColorReference(&refBuffer, clearColor);
581*35238bceSAndroid Build Coastguard Worker }
582*35238bceSAndroid Build Coastguard Worker
583*35238bceSAndroid Build Coastguard Worker m_gles2Renderer->render(width, height, newFrame);
584*35238bceSAndroid Build Coastguard Worker m_refRenderer->render(&refBuffer, newFrame);
585*35238bceSAndroid Build Coastguard Worker
586*35238bceSAndroid Build Coastguard Worker readPixels(m_gl, ¤tBuffer);
587*35238bceSAndroid Build Coastguard Worker
588*35238bceSAndroid Build Coastguard Worker if (compareToReference(log, refBuffer, currentBuffer, frameNdx, frameNdx) == false)
589*35238bceSAndroid Build Coastguard Worker {
590*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail, render result is wrong");
591*35238bceSAndroid Build Coastguard Worker return STOP;
592*35238bceSAndroid Build Coastguard Worker }
593*35238bceSAndroid Build Coastguard Worker
594*35238bceSAndroid Build Coastguard Worker if (m_resizeType == RESIZETYPE_BEFORE_SWAP)
595*35238bceSAndroid Build Coastguard Worker {
596*35238bceSAndroid Build Coastguard Worker if (frameNdx % 2 == 0)
597*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(width * 2, height / 2));
598*35238bceSAndroid Build Coastguard Worker else
599*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(height / 2, width * 2));
600*35238bceSAndroid Build Coastguard Worker }
601*35238bceSAndroid Build Coastguard Worker
602*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, m_eglSurface));
603*35238bceSAndroid Build Coastguard Worker
604*35238bceSAndroid Build Coastguard Worker if (m_resizeType == RESIZETYPE_AFTER_SWAP)
605*35238bceSAndroid Build Coastguard Worker {
606*35238bceSAndroid Build Coastguard Worker if (frameNdx % 2 == 0)
607*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(width * 2, height / 2));
608*35238bceSAndroid Build Coastguard Worker else
609*35238bceSAndroid Build Coastguard Worker m_window->setSurfaceSize(IVec2(height / 2, width * 2));
610*35238bceSAndroid Build Coastguard Worker }
611*35238bceSAndroid Build Coastguard Worker }
612*35238bceSAndroid Build Coastguard Worker
613*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
614*35238bceSAndroid Build Coastguard Worker return STOP;
615*35238bceSAndroid Build Coastguard Worker }
616*35238bceSAndroid Build Coastguard Worker
generateDrawTypeName(const vector<BufferAgeTest::DrawType> & drawTypes)617*35238bceSAndroid Build Coastguard Worker string generateDrawTypeName(const vector<BufferAgeTest::DrawType> &drawTypes)
618*35238bceSAndroid Build Coastguard Worker {
619*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
620*35238bceSAndroid Build Coastguard Worker if (drawTypes.size() == 0)
621*35238bceSAndroid Build Coastguard Worker return string("_none");
622*35238bceSAndroid Build Coastguard Worker
623*35238bceSAndroid Build Coastguard Worker for (size_t ndx = 0; ndx < drawTypes.size(); ndx++)
624*35238bceSAndroid Build Coastguard Worker {
625*35238bceSAndroid Build Coastguard Worker if (drawTypes[ndx] == BufferAgeTest::DRAWTYPE_GLES2_RENDER)
626*35238bceSAndroid Build Coastguard Worker stream << "_render";
627*35238bceSAndroid Build Coastguard Worker else if (drawTypes[ndx] == BufferAgeTest::DRAWTYPE_GLES2_CLEAR)
628*35238bceSAndroid Build Coastguard Worker stream << "_clear";
629*35238bceSAndroid Build Coastguard Worker else
630*35238bceSAndroid Build Coastguard Worker DE_ASSERT(false);
631*35238bceSAndroid Build Coastguard Worker }
632*35238bceSAndroid Build Coastguard Worker return stream.str();
633*35238bceSAndroid Build Coastguard Worker }
634*35238bceSAndroid Build Coastguard Worker
generateTestName(const vector<BufferAgeTest::DrawType> & oddFrameDrawType,const vector<BufferAgeTest::DrawType> & evenFrameDrawType)635*35238bceSAndroid Build Coastguard Worker string generateTestName(const vector<BufferAgeTest::DrawType> &oddFrameDrawType,
636*35238bceSAndroid Build Coastguard Worker const vector<BufferAgeTest::DrawType> &evenFrameDrawType)
637*35238bceSAndroid Build Coastguard Worker {
638*35238bceSAndroid Build Coastguard Worker return "odd" + generateDrawTypeName(oddFrameDrawType) + "_even" + generateDrawTypeName(evenFrameDrawType);
639*35238bceSAndroid Build Coastguard Worker }
640*35238bceSAndroid Build Coastguard Worker
generateResizeGroupName(BufferAgeTest::ResizeType resizeType)641*35238bceSAndroid Build Coastguard Worker string generateResizeGroupName(BufferAgeTest::ResizeType resizeType)
642*35238bceSAndroid Build Coastguard Worker {
643*35238bceSAndroid Build Coastguard Worker switch (resizeType)
644*35238bceSAndroid Build Coastguard Worker {
645*35238bceSAndroid Build Coastguard Worker case BufferAgeTest::RESIZETYPE_NONE:
646*35238bceSAndroid Build Coastguard Worker return "no_resize";
647*35238bceSAndroid Build Coastguard Worker
648*35238bceSAndroid Build Coastguard Worker case BufferAgeTest::RESIZETYPE_AFTER_SWAP:
649*35238bceSAndroid Build Coastguard Worker return "resize_after_swap";
650*35238bceSAndroid Build Coastguard Worker
651*35238bceSAndroid Build Coastguard Worker case BufferAgeTest::RESIZETYPE_BEFORE_SWAP:
652*35238bceSAndroid Build Coastguard Worker return "resize_before_swap";
653*35238bceSAndroid Build Coastguard Worker
654*35238bceSAndroid Build Coastguard Worker default:
655*35238bceSAndroid Build Coastguard Worker DE_FATAL("Unknown resize type");
656*35238bceSAndroid Build Coastguard Worker return "";
657*35238bceSAndroid Build Coastguard Worker }
658*35238bceSAndroid Build Coastguard Worker }
659*35238bceSAndroid Build Coastguard Worker
isWindow(const eglu::CandidateConfig & c)660*35238bceSAndroid Build Coastguard Worker bool isWindow(const eglu::CandidateConfig &c)
661*35238bceSAndroid Build Coastguard Worker {
662*35238bceSAndroid Build Coastguard Worker return (c.surfaceType() & EGL_WINDOW_BIT) == EGL_WINDOW_BIT;
663*35238bceSAndroid Build Coastguard Worker }
664*35238bceSAndroid Build Coastguard Worker
isES2Renderable(const eglu::CandidateConfig & c)665*35238bceSAndroid Build Coastguard Worker bool isES2Renderable(const eglu::CandidateConfig &c)
666*35238bceSAndroid Build Coastguard Worker {
667*35238bceSAndroid Build Coastguard Worker return (c.get(EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT;
668*35238bceSAndroid Build Coastguard Worker }
669*35238bceSAndroid Build Coastguard Worker
hasPreserveSwap(const eglu::CandidateConfig & c)670*35238bceSAndroid Build Coastguard Worker bool hasPreserveSwap(const eglu::CandidateConfig &c)
671*35238bceSAndroid Build Coastguard Worker {
672*35238bceSAndroid Build Coastguard Worker return (c.surfaceType() & EGL_SWAP_BEHAVIOR_PRESERVED_BIT) == EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
673*35238bceSAndroid Build Coastguard Worker }
674*35238bceSAndroid Build Coastguard Worker
getEGLConfig(const Library & egl,EGLDisplay eglDisplay,bool preserveColorBuffer)675*35238bceSAndroid Build Coastguard Worker EGLConfig getEGLConfig(const Library &egl, EGLDisplay eglDisplay, bool preserveColorBuffer)
676*35238bceSAndroid Build Coastguard Worker {
677*35238bceSAndroid Build Coastguard Worker eglu::FilterList filters;
678*35238bceSAndroid Build Coastguard Worker filters << isWindow << isES2Renderable;
679*35238bceSAndroid Build Coastguard Worker if (preserveColorBuffer)
680*35238bceSAndroid Build Coastguard Worker filters << hasPreserveSwap;
681*35238bceSAndroid Build Coastguard Worker return eglu::chooseSingleConfig(egl, eglDisplay, filters);
682*35238bceSAndroid Build Coastguard Worker }
683*35238bceSAndroid Build Coastguard Worker
clearColorScreen(const glw::Functions & gl,const tcu::Vec4 & clearColor)684*35238bceSAndroid Build Coastguard Worker void clearColorScreen(const glw::Functions &gl, const tcu::Vec4 &clearColor)
685*35238bceSAndroid Build Coastguard Worker {
686*35238bceSAndroid Build Coastguard Worker gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
687*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT);
688*35238bceSAndroid Build Coastguard Worker }
689*35238bceSAndroid Build Coastguard Worker
clearColorReference(tcu::Surface * ref,const tcu::Vec4 & clearColor)690*35238bceSAndroid Build Coastguard Worker void clearColorReference(tcu::Surface *ref, const tcu::Vec4 &clearColor)
691*35238bceSAndroid Build Coastguard Worker {
692*35238bceSAndroid Build Coastguard Worker tcu::clear(ref->getAccess(), clearColor);
693*35238bceSAndroid Build Coastguard Worker }
694*35238bceSAndroid Build Coastguard Worker
readPixels(const glw::Functions & gl,tcu::Surface * screen)695*35238bceSAndroid Build Coastguard Worker void readPixels(const glw::Functions &gl, tcu::Surface *screen)
696*35238bceSAndroid Build Coastguard Worker {
697*35238bceSAndroid Build Coastguard Worker gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
698*35238bceSAndroid Build Coastguard Worker screen->getAccess().getDataPtr());
699*35238bceSAndroid Build Coastguard Worker }
700*35238bceSAndroid Build Coastguard Worker
windowToDeviceCoordinates(int x,int length)701*35238bceSAndroid Build Coastguard Worker float windowToDeviceCoordinates(int x, int length)
702*35238bceSAndroid Build Coastguard Worker {
703*35238bceSAndroid Build Coastguard Worker return (2.0f * float(x) / float(length)) - 1.0f;
704*35238bceSAndroid Build Coastguard Worker }
705*35238bceSAndroid Build Coastguard Worker
compareToReference(tcu::TestLog & log,const tcu::Surface & reference,const tcu::Surface & buffer,int frameNdx,int bufferNum)706*35238bceSAndroid Build Coastguard Worker bool compareToReference(tcu::TestLog &log, const tcu::Surface &reference, const tcu::Surface &buffer, int frameNdx,
707*35238bceSAndroid Build Coastguard Worker int bufferNum)
708*35238bceSAndroid Build Coastguard Worker {
709*35238bceSAndroid Build Coastguard Worker std::ostringstream stream;
710*35238bceSAndroid Build Coastguard Worker stream << "FrameNdx = " << frameNdx << ", compare current buffer (numbered: " << bufferNum << ") to reference";
711*35238bceSAndroid Build Coastguard Worker return tcu::intThresholdPositionDeviationCompare(log, "buffer age test", stream.str().c_str(),
712*35238bceSAndroid Build Coastguard Worker reference.getAccess(), buffer.getAccess(), tcu::UVec4(8, 8, 8, 0),
713*35238bceSAndroid Build Coastguard Worker tcu::IVec3(2, 2, 0), true, tcu::COMPARE_LOG_RESULT);
714*35238bceSAndroid Build Coastguard Worker }
715*35238bceSAndroid Build Coastguard Worker
716*35238bceSAndroid Build Coastguard Worker } // namespace
717*35238bceSAndroid Build Coastguard Worker
BufferAgeTests(EglTestContext & eglTestCtx)718*35238bceSAndroid Build Coastguard Worker BufferAgeTests::BufferAgeTests(EglTestContext &eglTestCtx)
719*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(eglTestCtx, "buffer_age", "Color buffer age tests")
720*35238bceSAndroid Build Coastguard Worker {
721*35238bceSAndroid Build Coastguard Worker }
722*35238bceSAndroid Build Coastguard Worker
init(void)723*35238bceSAndroid Build Coastguard Worker void BufferAgeTests::init(void)
724*35238bceSAndroid Build Coastguard Worker {
725*35238bceSAndroid Build Coastguard Worker const BufferAgeTest::DrawType clearRender[] = {BufferAgeTest::DRAWTYPE_GLES2_CLEAR,
726*35238bceSAndroid Build Coastguard Worker BufferAgeTest::DRAWTYPE_GLES2_RENDER};
727*35238bceSAndroid Build Coastguard Worker
728*35238bceSAndroid Build Coastguard Worker const BufferAgeTest::DrawType renderClear[] = {BufferAgeTest::DRAWTYPE_GLES2_RENDER,
729*35238bceSAndroid Build Coastguard Worker BufferAgeTest::DRAWTYPE_GLES2_CLEAR};
730*35238bceSAndroid Build Coastguard Worker
731*35238bceSAndroid Build Coastguard Worker const BufferAgeTest::ResizeType resizeTypes[] = {
732*35238bceSAndroid Build Coastguard Worker BufferAgeTest::RESIZETYPE_NONE, BufferAgeTest::RESIZETYPE_BEFORE_SWAP, BufferAgeTest::RESIZETYPE_AFTER_SWAP};
733*35238bceSAndroid Build Coastguard Worker
734*35238bceSAndroid Build Coastguard Worker vector<vector<BufferAgeTest::DrawType>> frameDrawTypes;
735*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>());
736*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(1, BufferAgeTest::DRAWTYPE_GLES2_CLEAR));
737*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(1, BufferAgeTest::DRAWTYPE_GLES2_RENDER));
738*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(2, BufferAgeTest::DRAWTYPE_GLES2_CLEAR));
739*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(2, BufferAgeTest::DRAWTYPE_GLES2_RENDER));
740*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(DE_ARRAY_BEGIN(clearRender), DE_ARRAY_END(clearRender)));
741*35238bceSAndroid Build Coastguard Worker frameDrawTypes.push_back(vector<BufferAgeTest::DrawType>(DE_ARRAY_BEGIN(renderClear), DE_ARRAY_END(renderClear)));
742*35238bceSAndroid Build Coastguard Worker
743*35238bceSAndroid Build Coastguard Worker for (int preserveNdx = 0; preserveNdx < 2; preserveNdx++)
744*35238bceSAndroid Build Coastguard Worker {
745*35238bceSAndroid Build Coastguard Worker const bool preserve = (preserveNdx == 0);
746*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const preserveGroup =
747*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_eglTestCtx, (preserve ? "preserve" : "no_preserve"), "");
748*35238bceSAndroid Build Coastguard Worker
749*35238bceSAndroid Build Coastguard Worker for (size_t resizeTypeNdx = 0; resizeTypeNdx < DE_LENGTH_OF_ARRAY(resizeTypes); resizeTypeNdx++)
750*35238bceSAndroid Build Coastguard Worker {
751*35238bceSAndroid Build Coastguard Worker const BufferAgeTest::ResizeType resizeType = resizeTypes[resizeTypeNdx];
752*35238bceSAndroid Build Coastguard Worker TestCaseGroup *const resizeGroup =
753*35238bceSAndroid Build Coastguard Worker new TestCaseGroup(m_eglTestCtx, generateResizeGroupName(resizeType).c_str(), "");
754*35238bceSAndroid Build Coastguard Worker
755*35238bceSAndroid Build Coastguard Worker for (size_t evenNdx = 0; evenNdx < frameDrawTypes.size(); evenNdx++)
756*35238bceSAndroid Build Coastguard Worker {
757*35238bceSAndroid Build Coastguard Worker const vector<BufferAgeTest::DrawType> &evenFrameDrawType = frameDrawTypes[evenNdx];
758*35238bceSAndroid Build Coastguard Worker
759*35238bceSAndroid Build Coastguard Worker for (size_t oddNdx = evenNdx; oddNdx < frameDrawTypes.size(); oddNdx++)
760*35238bceSAndroid Build Coastguard Worker {
761*35238bceSAndroid Build Coastguard Worker const vector<BufferAgeTest::DrawType> &oddFrameDrawType = frameDrawTypes[oddNdx];
762*35238bceSAndroid Build Coastguard Worker const std::string name = generateTestName(oddFrameDrawType, evenFrameDrawType);
763*35238bceSAndroid Build Coastguard Worker resizeGroup->addChild(new BufferAgeTest(m_eglTestCtx, preserve, oddFrameDrawType, evenFrameDrawType,
764*35238bceSAndroid Build Coastguard Worker BufferAgeTest::RESIZETYPE_NONE, name.c_str(), ""));
765*35238bceSAndroid Build Coastguard Worker }
766*35238bceSAndroid Build Coastguard Worker }
767*35238bceSAndroid Build Coastguard Worker
768*35238bceSAndroid Build Coastguard Worker preserveGroup->addChild(resizeGroup);
769*35238bceSAndroid Build Coastguard Worker }
770*35238bceSAndroid Build Coastguard Worker addChild(preserveGroup);
771*35238bceSAndroid Build Coastguard Worker }
772*35238bceSAndroid Build Coastguard Worker }
773*35238bceSAndroid Build Coastguard Worker
774*35238bceSAndroid Build Coastguard Worker } // namespace egl
775*35238bceSAndroid Build Coastguard Worker } // namespace deqp
776