Fix atomic ssbo xor test am: f0fa05e898 am: 14cd264501 am: 6e80057a20 am: cae1fe52ac...
[platform/upstream/VK-GL-CTS.git] / modules / gles3 / functional / es3fTextureSizeTests.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture size tests.
22  *//*--------------------------------------------------------------------*/
23
24 #include "es3fTextureSizeTests.hpp"
25 #include "glsTextureTestUtil.hpp"
26 #include "gluTexture.hpp"
27 #include "gluStrUtil.hpp"
28 #include "gluTextureUtil.hpp"
29 #include "gluPixelTransfer.hpp"
30 #include "tcuTestLog.hpp"
31 #include "tcuTextureUtil.hpp"
32
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35
36 namespace deqp
37 {
38 namespace gles3
39 {
40 namespace Functional
41 {
42
43 using tcu::TestLog;
44 using std::vector;
45 using std::string;
46 using tcu::Sampler;
47 using namespace glu;
48 using namespace gls::TextureTestUtil;
49 using namespace glu::TextureTestUtil;
50
51
52 class Texture2DSizeCase : public tcu::TestCase
53 {
54 public:
55                                                         Texture2DSizeCase               (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps);
56                                                         ~Texture2DSizeCase              (void);
57
58         void                                    init                                    (void);
59         void                                    deinit                                  (void);
60         IterateResult                   iterate                                 (void);
61
62 private:
63                                                         Texture2DSizeCase               (const Texture2DSizeCase& other);
64         Texture2DSizeCase&              operator=                               (const Texture2DSizeCase& other);
65
66         glu::RenderContext&             m_renderCtx;
67
68         deUint32                                m_format;
69         deUint32                                m_dataType;
70         int                                             m_width;
71         int                                             m_height;
72         bool                                    m_useMipmaps;
73
74         glu::Texture2D*                 m_texture;
75         TextureRenderer                 m_renderer;
76 };
77
78 Texture2DSizeCase::Texture2DSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps)
79         : TestCase              (testCtx, name, description)
80         , m_renderCtx   (renderCtx)
81         , m_format              (format)
82         , m_dataType    (dataType)
83         , m_width               (width)
84         , m_height              (height)
85         , m_useMipmaps  (mipmaps)
86         , m_texture             (DE_NULL)
87         , m_renderer    (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_MEDIUMP)
88 {
89 }
90
91 Texture2DSizeCase::~Texture2DSizeCase (void)
92 {
93         Texture2DSizeCase::deinit();
94 }
95
96 void Texture2DSizeCase::init (void)
97 {
98         DE_ASSERT(!m_texture);
99         m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
100
101         int numLevels = m_useMipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1;
102
103         // Fill levels.
104         for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
105         {
106                 m_texture->getRefTexture().allocLevel(levelNdx);
107                 tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(levelNdx), tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
108         }
109 }
110
111 void Texture2DSizeCase::deinit (void)
112 {
113         delete m_texture;
114         m_texture = DE_NULL;
115
116         m_renderer.clear();
117 }
118
119 Texture2DSizeCase::IterateResult Texture2DSizeCase::iterate (void)
120 {
121         const glw::Functions&   gl                              = m_renderCtx.getFunctions();
122         TestLog&                                log                             = m_testCtx.getLog();
123         RandomViewport                  viewport                (m_renderCtx.getRenderTarget(), 128, 128, deStringHash(getName()));
124         tcu::Surface                    renderedFrame   (viewport.width, viewport.height);
125         tcu::Surface                    referenceFrame  (viewport.width, viewport.height);
126         tcu::RGBA                               threshold               = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(7,7,7,7);
127         deUint32                                wrapS                   = GL_CLAMP_TO_EDGE;
128         deUint32                                wrapT                   = GL_CLAMP_TO_EDGE;
129         deUint32                                minFilter               = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST;
130         deUint32                                magFilter               = GL_NEAREST;
131         vector<float>                   texCoord;
132
133         computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
134
135         // Setup base viewport.
136         gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
137
138         // Upload texture data to GL.
139         m_texture->upload();
140
141         // Bind to unit 0.
142         gl.activeTexture(GL_TEXTURE0);
143         gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
144
145         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,              wrapS);
146         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,              wrapT);
147         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,  minFilter);
148         gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,  magFilter);
149         GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
150
151         // Draw.
152         m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_2D);
153         glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
154
155         // Compute reference.
156         sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()), m_texture->getRefTexture(), &texCoord[0], ReferenceParams(TEXTURETYPE_2D, mapGLSampler(wrapS, wrapT, minFilter, magFilter)));
157
158         // Compare and log.
159         bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold);
160
161         m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS      : QP_TEST_RESULT_FAIL,
162                                                         isOk ? "Pass"                           : "Image comparison failed");
163
164         return STOP;
165 }
166
167 class TextureCubeSizeCase : public tcu::TestCase
168 {
169 public:
170                                                         TextureCubeSizeCase             (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps);
171                                                         ~TextureCubeSizeCase    (void);
172
173         void                                    init                                    (void);
174         void                                    deinit                                  (void);
175         IterateResult                   iterate                                 (void);
176
177 private:
178                                                         TextureCubeSizeCase             (const TextureCubeSizeCase& other);
179         TextureCubeSizeCase&    operator=                               (const TextureCubeSizeCase& other);
180
181         bool                                    testFace                                (tcu::CubeFace face);
182
183         glu::RenderContext&             m_renderCtx;
184
185         deUint32                                m_format;
186         deUint32                                m_dataType;
187         int                                             m_width;
188         int                                             m_height;
189         bool                                    m_useMipmaps;
190
191         glu::TextureCube*               m_texture;
192         TextureRenderer                 m_renderer;
193
194         int                                             m_curFace;
195         bool                                    m_isOk;
196 };
197
198 TextureCubeSizeCase::TextureCubeSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps)
199         : TestCase              (testCtx, name, description)
200         , m_renderCtx   (renderCtx)
201         , m_format              (format)
202         , m_dataType    (dataType)
203         , m_width               (width)
204         , m_height              (height)
205         , m_useMipmaps  (mipmaps)
206         , m_texture             (DE_NULL)
207         , m_renderer    (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_MEDIUMP)
208         , m_curFace             (0)
209         , m_isOk                (false)
210 {
211 }
212
213 TextureCubeSizeCase::~TextureCubeSizeCase (void)
214 {
215         TextureCubeSizeCase::deinit();
216 }
217
218 void TextureCubeSizeCase::init (void)
219 {
220         DE_ASSERT(!m_texture);
221         DE_ASSERT(m_width == m_height);
222         m_texture = new TextureCube(m_renderCtx, m_format, m_dataType, m_width);
223
224         static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] =
225         {
226                 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x
227                 { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x
228                 { tcu::Vec4(-1.0f,  0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y
229                 { tcu::Vec4(-1.0f, -1.0f,  0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y
230                 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z
231                 { tcu::Vec4( 0.0f,  0.0f,  0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }  // positive z
232         };
233
234         int numLevels = m_useMipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1;
235
236         // Fill levels.
237         for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
238         {
239                 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
240                 {
241                         m_texture->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx);
242                         fillWithComponentGradients(m_texture->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0], gradients[face][1]);
243                 }
244         }
245
246         // Upload texture data to GL.
247         m_texture->upload();
248
249         // Initialize iteration state.
250         m_curFace       = 0;
251         m_isOk          = true;
252 }
253
254 void TextureCubeSizeCase::deinit (void)
255 {
256         delete m_texture;
257         m_texture = DE_NULL;
258
259         m_renderer.clear();
260 }
261
262 bool TextureCubeSizeCase::testFace (tcu::CubeFace face)
263 {
264         const glw::Functions&   gl                              = m_renderCtx.getFunctions();
265         TestLog&                                log                             = m_testCtx.getLog();
266         RandomViewport                  viewport                (m_renderCtx.getRenderTarget(), 128, 128, deStringHash(getName())+(deUint32)face);
267         tcu::Surface                    renderedFrame   (viewport.width, viewport.height);
268         tcu::Surface                    referenceFrame  (viewport.width, viewport.height);
269         tcu::RGBA                               threshold               = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(7,7,7,7);
270         deUint32                                wrapS                   = GL_CLAMP_TO_EDGE;
271         deUint32                                wrapT                   = GL_CLAMP_TO_EDGE;
272         deUint32                                minFilter               = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST;
273         deUint32                                magFilter               = GL_NEAREST;
274         vector<float>                   texCoord;
275
276         computeQuadTexCoordCube(texCoord, face);
277
278         // \todo [2011-10-28 pyry] Image set name / section?
279         log << TestLog::Message << face << TestLog::EndMessage;
280
281         // Setup base viewport.
282         gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
283
284         // Bind to unit 0.
285         gl.activeTexture(GL_TEXTURE0);
286         gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
287
288         gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrapS);
289         gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrapT);
290         gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minFilter);
291         gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, magFilter);
292         GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
293
294         m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_CUBE);
295         glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
296
297         // Compute reference.
298         Sampler sampler = mapGLSampler(wrapS, wrapT, minFilter, magFilter);
299         sampler.seamlessCubeMap = true;
300         sampleTexture(tcu::SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()), m_texture->getRefTexture(), &texCoord[0], ReferenceParams(TEXTURETYPE_CUBE, sampler));
301
302         // Compare and log.
303         return compareImages(log, referenceFrame, renderedFrame, threshold);
304 }
305
306 TextureCubeSizeCase::IterateResult TextureCubeSizeCase::iterate (void)
307 {
308         // Execute test for all faces.
309         if (!testFace((tcu::CubeFace)m_curFace))
310                 m_isOk = false;
311
312         m_curFace += 1;
313
314         if (m_curFace == tcu::CUBEFACE_LAST)
315         {
316                 m_testCtx.setTestResult(m_isOk ? QP_TEST_RESULT_PASS    : QP_TEST_RESULT_FAIL,
317                                                                 m_isOk ? "Pass"                                 : "Image comparison failed");
318                 return STOP;
319         }
320         else
321                 return CONTINUE;
322 }
323
324 TextureSizeTests::TextureSizeTests (Context& context)
325         : TestCaseGroup(context, "size", "Texture Size Tests")
326 {
327 }
328
329 TextureSizeTests::~TextureSizeTests (void)
330 {
331 }
332
333 void TextureSizeTests::init (void)
334 {
335         struct
336         {
337                 int     width;
338                 int     height;
339         } sizes2D[] =
340         {
341                 {   64,   64 }, // Spec-mandated minimum.
342                 {   65,   63 },
343                 {  512,  512 },
344                 { 1024, 1024 },
345                 { 2048, 2048 }
346         };
347
348         struct
349         {
350                 int     width;
351                 int     height;
352         } sizesCube[] =
353         {
354                 {  15,  15 },
355                 {  16,  16 }, // Spec-mandated minimum
356                 {  64,  64 },
357                 { 128, 128 },
358                 { 256, 256 },
359                 { 512, 512 }
360         };
361
362         struct
363         {
364                 const char*     name;
365                 deUint32        format;
366                 deUint32        dataType;
367         } formats[] =
368         {
369                 { "l8",                 GL_LUMINANCE,           GL_UNSIGNED_BYTE },
370                 { "rgba4444",   GL_RGBA,                        GL_UNSIGNED_SHORT_4_4_4_4 },
371                 { "rgb888",             GL_RGB,                         GL_UNSIGNED_BYTE },
372                 { "rgba8888",   GL_RGBA,                        GL_UNSIGNED_BYTE }
373         };
374
375         // 2D cases.
376         tcu::TestCaseGroup* group2D = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Size Tests");
377         addChild(group2D);
378         for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes2D); sizeNdx++)
379         {
380                 int             width   = sizes2D[sizeNdx].width;
381                 int             height  = sizes2D[sizeNdx].height;
382                 bool    isPOT   = deIsPowerOfTwo32(width) && deIsPowerOfTwo32(height);
383
384                 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
385                 {
386                         for (int mipmap = 0; mipmap < (isPOT ? 2 : 1); mipmap++)
387                         {
388                                 std::ostringstream name;
389                                 name << width << "x" << height << "_" << formats[formatNdx].name << (mipmap ? "_mipmap" : "");
390
391                                 group2D->addChild(new Texture2DSizeCase(m_testCtx, m_context.getRenderContext(), name.str().c_str(), "",
392                                                                                                                 formats[formatNdx].format, formats[formatNdx].dataType,
393                                                                                                                 width, height, mipmap != 0));
394                         }
395                 }
396         }
397
398         // Cubemap cases.
399         tcu::TestCaseGroup* groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cubemap Texture Size Tests");
400         addChild(groupCube);
401         for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizesCube); sizeNdx++)
402         {
403                 int             width   = sizesCube[sizeNdx].width;
404                 int             height  = sizesCube[sizeNdx].height;
405                 bool    isPOT   = deIsPowerOfTwo32(width) && deIsPowerOfTwo32(height);
406
407                 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
408                 {
409                         for (int mipmap = 0; mipmap < (isPOT ? 2 : 1); mipmap++)
410                         {
411                                 std::ostringstream name;
412                                 name << width << "x" << height << "_" << formats[formatNdx].name << (mipmap ? "_mipmap" : "");
413
414                                 groupCube->addChild(new TextureCubeSizeCase(m_testCtx, m_context.getRenderContext(), name.str().c_str(), "",
415                                                                                                                         formats[formatNdx].format, formats[formatNdx].dataType,
416                                                                                                                         width, height, mipmap != 0));
417                         }
418                 }
419         }
420 }
421
422 } // Functional
423 } // gles3
424 } // deqp