xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fTextureMipmapTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 2.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 Mipmapping tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2fTextureMipmapTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuMatrix.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuMatrixUtil.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuTexLookupVerifier.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker namespace deqp
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker namespace gles2
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace Functional
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker using std::string;
50*35238bceSAndroid Build Coastguard Worker using std::vector;
51*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
52*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
53*35238bceSAndroid Build Coastguard Worker using tcu::Mat2;
54*35238bceSAndroid Build Coastguard Worker using tcu::Sampler;
55*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
56*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
57*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
58*35238bceSAndroid Build Coastguard Worker using namespace glu;
59*35238bceSAndroid Build Coastguard Worker using namespace gls::TextureTestUtil;
60*35238bceSAndroid Build Coastguard Worker using namespace glu::TextureTestUtil;
61*35238bceSAndroid Build Coastguard Worker 
62*35238bceSAndroid Build Coastguard Worker enum CoordType
63*35238bceSAndroid Build Coastguard Worker {
64*35238bceSAndroid Build Coastguard Worker     COORDTYPE_BASIC,      //!< texCoord = translateScale(position).
65*35238bceSAndroid Build Coastguard Worker     COORDTYPE_BASIC_BIAS, //!< Like basic, but with bias values.
66*35238bceSAndroid Build Coastguard Worker     COORDTYPE_AFFINE,     //!< texCoord = translateScaleRotateShear(position).
67*35238bceSAndroid Build Coastguard Worker     COORDTYPE_PROJECTED,  //!< Projected coordinates, w != 1
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker     COORDTYPE_LAST
70*35238bceSAndroid Build Coastguard Worker };
71*35238bceSAndroid Build Coastguard Worker 
72*35238bceSAndroid Build Coastguard Worker // Texture2DMipmapCase
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker class Texture2DMipmapCase : public tcu::TestCase
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker public:
77*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const glu::ContextInfo &renderCtxInfo,
78*35238bceSAndroid Build Coastguard Worker                         const char *name, const char *desc, CoordType coordType, uint32_t minFilter, uint32_t wrapS,
79*35238bceSAndroid Build Coastguard Worker                         uint32_t wrapT, uint32_t format, uint32_t dataType, int width, int height);
80*35238bceSAndroid Build Coastguard Worker     ~Texture2DMipmapCase(void);
81*35238bceSAndroid Build Coastguard Worker 
82*35238bceSAndroid Build Coastguard Worker     void init(void);
83*35238bceSAndroid Build Coastguard Worker     void deinit(void);
84*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker private:
87*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase(const Texture2DMipmapCase &other);
88*35238bceSAndroid Build Coastguard Worker     Texture2DMipmapCase &operator=(const Texture2DMipmapCase &other);
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
91*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
92*35238bceSAndroid Build Coastguard Worker 
93*35238bceSAndroid Build Coastguard Worker     CoordType m_coordType;
94*35238bceSAndroid Build Coastguard Worker     uint32_t m_minFilter;
95*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapS;
96*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapT;
97*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
98*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
99*35238bceSAndroid Build Coastguard Worker     int m_width;
100*35238bceSAndroid Build Coastguard Worker     int m_height;
101*35238bceSAndroid Build Coastguard Worker 
102*35238bceSAndroid Build Coastguard Worker     glu::Texture2D *m_texture;
103*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
104*35238bceSAndroid Build Coastguard Worker };
105*35238bceSAndroid Build Coastguard Worker 
Texture2DMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * desc,CoordType coordType,uint32_t minFilter,uint32_t wrapS,uint32_t wrapT,uint32_t format,uint32_t dataType,int width,int height)106*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::Texture2DMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
107*35238bceSAndroid Build Coastguard Worker                                          const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
108*35238bceSAndroid Build Coastguard Worker                                          CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT,
109*35238bceSAndroid Build Coastguard Worker                                          uint32_t format, uint32_t dataType, int width, int height)
110*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, desc)
111*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
112*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
113*35238bceSAndroid Build Coastguard Worker     , m_coordType(coordType)
114*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
115*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
116*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
117*35238bceSAndroid Build Coastguard Worker     , m_format(format)
118*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
119*35238bceSAndroid Build Coastguard Worker     , m_width(width)
120*35238bceSAndroid Build Coastguard Worker     , m_height(height)
121*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
122*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES,
123*35238bceSAndroid Build Coastguard Worker                  renderCtxInfo.isFragmentHighPrecisionSupported() ? glu::PRECISION_HIGHP // Use highp if available.
124*35238bceSAndroid Build Coastguard Worker                                                                     :
125*35238bceSAndroid Build Coastguard Worker                                                                     glu::PRECISION_MEDIUMP)
126*35238bceSAndroid Build Coastguard Worker {
127*35238bceSAndroid Build Coastguard Worker }
128*35238bceSAndroid Build Coastguard Worker 
~Texture2DMipmapCase(void)129*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::~Texture2DMipmapCase(void)
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker     deinit();
132*35238bceSAndroid Build Coastguard Worker }
133*35238bceSAndroid Build Coastguard Worker 
init(void)134*35238bceSAndroid Build Coastguard Worker void Texture2DMipmapCase::init(void)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker     if (!m_renderCtxInfo.isFragmentHighPrecisionSupported())
137*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Warning: High precision not supported in fragment shaders."
138*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
139*35238bceSAndroid Build Coastguard Worker 
140*35238bceSAndroid Build Coastguard Worker     if (m_coordType == COORDTYPE_PROJECTED && m_renderCtx.getRenderTarget().getNumSamples() > 0)
141*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Projected lookup validation not supported in multisample config");
142*35238bceSAndroid Build Coastguard Worker 
143*35238bceSAndroid Build Coastguard Worker     m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker     int numLevels = deLog2Floor32(de::max(m_width, m_height)) + 1;
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker     // Fill texture with colored grid.
148*35238bceSAndroid Build Coastguard Worker     for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
149*35238bceSAndroid Build Coastguard Worker     {
150*35238bceSAndroid Build Coastguard Worker         uint32_t step  = 0xff / (numLevels - 1);
151*35238bceSAndroid Build Coastguard Worker         uint32_t inc   = deClamp32(step * levelNdx, 0x00, 0xff);
152*35238bceSAndroid Build Coastguard Worker         uint32_t dec   = 0xff - inc;
153*35238bceSAndroid Build Coastguard Worker         uint32_t rgb   = (inc << 16) | (dec << 8) | 0xff;
154*35238bceSAndroid Build Coastguard Worker         uint32_t color = 0xff000000 | rgb;
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker         m_texture->getRefTexture().allocLevel(levelNdx);
157*35238bceSAndroid Build Coastguard Worker         tcu::clear(m_texture->getRefTexture().getLevel(levelNdx), tcu::RGBA(color).toVec());
158*35238bceSAndroid Build Coastguard Worker     }
159*35238bceSAndroid Build Coastguard Worker }
160*35238bceSAndroid Build Coastguard Worker 
deinit(void)161*35238bceSAndroid Build Coastguard Worker void Texture2DMipmapCase::deinit(void)
162*35238bceSAndroid Build Coastguard Worker {
163*35238bceSAndroid Build Coastguard Worker     delete m_texture;
164*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
165*35238bceSAndroid Build Coastguard Worker 
166*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
167*35238bceSAndroid Build Coastguard Worker }
168*35238bceSAndroid Build Coastguard Worker 
getBasicTexCoord2D(std::vector<float> & dst,int cellNdx)169*35238bceSAndroid Build Coastguard Worker static void getBasicTexCoord2D(std::vector<float> &dst, int cellNdx)
170*35238bceSAndroid Build Coastguard Worker {
171*35238bceSAndroid Build Coastguard Worker     static const struct
172*35238bceSAndroid Build Coastguard Worker     {
173*35238bceSAndroid Build Coastguard Worker         Vec2 bottomLeft;
174*35238bceSAndroid Build Coastguard Worker         Vec2 topRight;
175*35238bceSAndroid Build Coastguard Worker     } s_basicCoords[] = {
176*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.1f, 0.1f), Vec2(0.8f, 1.0f)},     {Vec2(-0.3f, -0.6f), Vec2(0.7f, 0.4f)},
177*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.3f, 0.6f), Vec2(0.7f, -0.9f)},    {Vec2(-0.8f, 0.6f), Vec2(0.7f, -0.9f)},
178*35238bceSAndroid Build Coastguard Worker 
179*35238bceSAndroid Build Coastguard Worker         {Vec2(-0.5f, -0.5f), Vec2(1.5f, 1.5f)},    {Vec2(1.0f, -1.0f), Vec2(-1.3f, 1.0f)},
180*35238bceSAndroid Build Coastguard Worker         {Vec2(1.2f, -1.0f), Vec2(-1.3f, 1.6f)},    {Vec2(2.2f, -1.1f), Vec2(-1.3f, 0.8f)},
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker         {Vec2(-1.5f, 1.6f), Vec2(1.7f, -1.4f)},    {Vec2(2.0f, 1.6f), Vec2(2.3f, -1.4f)},
183*35238bceSAndroid Build Coastguard Worker         {Vec2(1.3f, -2.6f), Vec2(-2.7f, 2.9f)},    {Vec2(-0.8f, -6.6f), Vec2(6.0f, -0.9f)},
184*35238bceSAndroid Build Coastguard Worker 
185*35238bceSAndroid Build Coastguard Worker         {Vec2(-8.0f, 9.0f), Vec2(8.3f, -7.0f)},    {Vec2(-16.0f, 10.0f), Vec2(18.3f, 24.0f)},
186*35238bceSAndroid Build Coastguard Worker         {Vec2(30.2f, 55.0f), Vec2(-24.3f, -1.6f)}, {Vec2(-33.2f, 64.1f), Vec2(32.1f, -64.1f)},
187*35238bceSAndroid Build Coastguard Worker     };
188*35238bceSAndroid Build Coastguard Worker 
189*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(de::inBounds(cellNdx, 0, DE_LENGTH_OF_ARRAY(s_basicCoords)));
190*35238bceSAndroid Build Coastguard Worker 
191*35238bceSAndroid Build Coastguard Worker     const Vec2 &bottomLeft = s_basicCoords[cellNdx].bottomLeft;
192*35238bceSAndroid Build Coastguard Worker     const Vec2 &topRight   = s_basicCoords[cellNdx].topRight;
193*35238bceSAndroid Build Coastguard Worker 
194*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(dst, bottomLeft, topRight);
195*35238bceSAndroid Build Coastguard Worker }
196*35238bceSAndroid Build Coastguard Worker 
getAffineTexCoord2D(std::vector<float> & dst,int cellNdx)197*35238bceSAndroid Build Coastguard Worker static void getAffineTexCoord2D(std::vector<float> &dst, int cellNdx)
198*35238bceSAndroid Build Coastguard Worker {
199*35238bceSAndroid Build Coastguard Worker     // Use basic coords as base.
200*35238bceSAndroid Build Coastguard Worker     getBasicTexCoord2D(dst, cellNdx);
201*35238bceSAndroid Build Coastguard Worker 
202*35238bceSAndroid Build Coastguard Worker     // Rotate based on cell index.
203*35238bceSAndroid Build Coastguard Worker     float angle         = 2.0f * DE_PI * ((float)cellNdx / 16.0f);
204*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 rotMatrix = tcu::rotationMatrix(angle);
205*35238bceSAndroid Build Coastguard Worker 
206*35238bceSAndroid Build Coastguard Worker     // Second and third row are sheared.
207*35238bceSAndroid Build Coastguard Worker     float shearX          = de::inRange(cellNdx, 4, 11) ? (float)(15 - cellNdx) / 16.0f : 0.0f;
208*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 shearMatrix = tcu::shearMatrix(tcu::Vec2(shearX, 0.0f));
209*35238bceSAndroid Build Coastguard Worker 
210*35238bceSAndroid Build Coastguard Worker     tcu::Mat2 transform = rotMatrix * shearMatrix;
211*35238bceSAndroid Build Coastguard Worker     Vec2 p0             = transform * Vec2(dst[0], dst[1]);
212*35238bceSAndroid Build Coastguard Worker     Vec2 p1             = transform * Vec2(dst[2], dst[3]);
213*35238bceSAndroid Build Coastguard Worker     Vec2 p2             = transform * Vec2(dst[4], dst[5]);
214*35238bceSAndroid Build Coastguard Worker     Vec2 p3             = transform * Vec2(dst[6], dst[7]);
215*35238bceSAndroid Build Coastguard Worker 
216*35238bceSAndroid Build Coastguard Worker     dst[0] = p0.x();
217*35238bceSAndroid Build Coastguard Worker     dst[1] = p0.y();
218*35238bceSAndroid Build Coastguard Worker     dst[2] = p1.x();
219*35238bceSAndroid Build Coastguard Worker     dst[3] = p1.y();
220*35238bceSAndroid Build Coastguard Worker     dst[4] = p2.x();
221*35238bceSAndroid Build Coastguard Worker     dst[5] = p2.y();
222*35238bceSAndroid Build Coastguard Worker     dst[6] = p3.x();
223*35238bceSAndroid Build Coastguard Worker     dst[7] = p3.y();
224*35238bceSAndroid Build Coastguard Worker }
225*35238bceSAndroid Build Coastguard Worker 
iterate(void)226*35238bceSAndroid Build Coastguard Worker Texture2DMipmapCase::IterateResult Texture2DMipmapCase::iterate(void)
227*35238bceSAndroid Build Coastguard Worker {
228*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
229*35238bceSAndroid Build Coastguard Worker 
230*35238bceSAndroid Build Coastguard Worker     const tcu::Texture2D &refTexture = m_texture->getRefTexture();
231*35238bceSAndroid Build Coastguard Worker 
232*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter    = GL_NEAREST;
233*35238bceSAndroid Build Coastguard Worker     const int texWidth          = refTexture.getWidth();
234*35238bceSAndroid Build Coastguard Worker     const int texHeight         = refTexture.getHeight();
235*35238bceSAndroid Build Coastguard Worker     const int defViewportWidth  = texWidth * 4;
236*35238bceSAndroid Build Coastguard Worker     const int defViewportHeight = texHeight * 4;
237*35238bceSAndroid Build Coastguard Worker 
238*35238bceSAndroid Build Coastguard Worker     const RandomViewport viewport(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight,
239*35238bceSAndroid Build Coastguard Worker                                   deStringHash(getName()));
240*35238bceSAndroid Build Coastguard Worker     ReferenceParams sampleParams(TEXTURETYPE_2D);
241*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
242*35238bceSAndroid Build Coastguard Worker 
243*35238bceSAndroid Build Coastguard Worker     const bool isProjected = m_coordType == COORDTYPE_PROJECTED;
244*35238bceSAndroid Build Coastguard Worker     const bool useLodBias  = m_coordType == COORDTYPE_BASIC_BIAS;
245*35238bceSAndroid Build Coastguard Worker 
246*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
247*35238bceSAndroid Build Coastguard Worker 
248*35238bceSAndroid Build Coastguard Worker     // Viewport is divided into 4x4 grid.
249*35238bceSAndroid Build Coastguard Worker     int gridWidth  = 4;
250*35238bceSAndroid Build Coastguard Worker     int gridHeight = 4;
251*35238bceSAndroid Build Coastguard Worker     int cellWidth  = viewport.width / gridWidth;
252*35238bceSAndroid Build Coastguard Worker     int cellHeight = viewport.height / gridHeight;
253*35238bceSAndroid Build Coastguard Worker 
254*35238bceSAndroid Build Coastguard Worker     // Bail out if rendertarget is too small.
255*35238bceSAndroid Build Coastguard Worker     if (viewport.width < defViewportWidth / 2 || viewport.height < defViewportHeight / 2)
256*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
257*35238bceSAndroid Build Coastguard Worker 
258*35238bceSAndroid Build Coastguard Worker     // Sampling parameters.
259*35238bceSAndroid Build Coastguard Worker     sampleParams.sampler     = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
260*35238bceSAndroid Build Coastguard Worker     sampleParams.samplerType = glu::TextureTestUtil::getSamplerType(m_texture->getRefTexture().getFormat());
261*35238bceSAndroid Build Coastguard Worker     sampleParams.flags = (isProjected ? ReferenceParams::PROJECTED : 0) | (useLodBias ? ReferenceParams::USE_BIAS : 0);
262*35238bceSAndroid Build Coastguard Worker     sampleParams.lodMode = LODMODE_EXACT; // Use ideal lod.
263*35238bceSAndroid Build Coastguard Worker 
264*35238bceSAndroid Build Coastguard Worker     // Upload texture data.
265*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
266*35238bceSAndroid Build Coastguard Worker 
267*35238bceSAndroid Build Coastguard Worker     // Bind gradient texture and setup sampler parameters.
268*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
269*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
270*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
271*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
272*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
273*35238bceSAndroid Build Coastguard Worker 
274*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
275*35238bceSAndroid Build Coastguard Worker 
276*35238bceSAndroid Build Coastguard Worker     // Bias values.
277*35238bceSAndroid Build Coastguard Worker     static const float s_bias[] = {1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f};
278*35238bceSAndroid Build Coastguard Worker 
279*35238bceSAndroid Build Coastguard Worker     // Projection values.
280*35238bceSAndroid Build Coastguard Worker     static const Vec4 s_projections[] = {Vec4(1.2f, 1.0f, 0.7f, 1.0f), Vec4(1.3f, 0.8f, 0.6f, 2.0f),
281*35238bceSAndroid Build Coastguard Worker                                          Vec4(0.8f, 1.0f, 1.7f, 0.6f), Vec4(1.2f, 1.0f, 1.7f, 1.5f)};
282*35238bceSAndroid Build Coastguard Worker 
283*35238bceSAndroid Build Coastguard Worker     // Render cells.
284*35238bceSAndroid Build Coastguard Worker     for (int gridY = 0; gridY < gridHeight; gridY++)
285*35238bceSAndroid Build Coastguard Worker     {
286*35238bceSAndroid Build Coastguard Worker         for (int gridX = 0; gridX < gridWidth; gridX++)
287*35238bceSAndroid Build Coastguard Worker         {
288*35238bceSAndroid Build Coastguard Worker             const int curX    = cellWidth * gridX;
289*35238bceSAndroid Build Coastguard Worker             const int curY    = cellHeight * gridY;
290*35238bceSAndroid Build Coastguard Worker             const int curW    = gridX + 1 == gridWidth ? (viewport.width - curX) : cellWidth;
291*35238bceSAndroid Build Coastguard Worker             const int curH    = gridY + 1 == gridHeight ? (viewport.height - curY) : cellHeight;
292*35238bceSAndroid Build Coastguard Worker             const int cellNdx = gridY * gridWidth + gridX;
293*35238bceSAndroid Build Coastguard Worker 
294*35238bceSAndroid Build Coastguard Worker             // Compute texcoord.
295*35238bceSAndroid Build Coastguard Worker             switch (m_coordType)
296*35238bceSAndroid Build Coastguard Worker             {
297*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_BASIC_BIAS: // Fall-through.
298*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_PROJECTED:
299*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_BASIC:
300*35238bceSAndroid Build Coastguard Worker                 getBasicTexCoord2D(texCoord, cellNdx);
301*35238bceSAndroid Build Coastguard Worker                 break;
302*35238bceSAndroid Build Coastguard Worker             case COORDTYPE_AFFINE:
303*35238bceSAndroid Build Coastguard Worker                 getAffineTexCoord2D(texCoord, cellNdx);
304*35238bceSAndroid Build Coastguard Worker                 break;
305*35238bceSAndroid Build Coastguard Worker             default:
306*35238bceSAndroid Build Coastguard Worker                 DE_ASSERT(false);
307*35238bceSAndroid Build Coastguard Worker             }
308*35238bceSAndroid Build Coastguard Worker 
309*35238bceSAndroid Build Coastguard Worker             if (isProjected)
310*35238bceSAndroid Build Coastguard Worker                 sampleParams.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
311*35238bceSAndroid Build Coastguard Worker 
312*35238bceSAndroid Build Coastguard Worker             if (useLodBias)
313*35238bceSAndroid Build Coastguard Worker                 sampleParams.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
314*35238bceSAndroid Build Coastguard Worker 
315*35238bceSAndroid Build Coastguard Worker             // Render with GL.
316*35238bceSAndroid Build Coastguard Worker             gl.viewport(viewport.x + curX, viewport.y + curY, curW, curH);
317*35238bceSAndroid Build Coastguard Worker             m_renderer.renderQuad(0, &texCoord[0], sampleParams);
318*35238bceSAndroid Build Coastguard Worker         }
319*35238bceSAndroid Build Coastguard Worker     }
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker     // Read result.
322*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
323*35238bceSAndroid Build Coastguard Worker 
324*35238bceSAndroid Build Coastguard Worker     // Compare and log.
325*35238bceSAndroid Build Coastguard Worker     {
326*35238bceSAndroid Build Coastguard Worker         const tcu::PixelFormat &pixelFormat = m_renderCtx.getRenderTarget().getPixelFormat();
327*35238bceSAndroid Build Coastguard Worker         const bool isTrilinear = m_minFilter == GL_NEAREST_MIPMAP_LINEAR || m_minFilter == GL_LINEAR_MIPMAP_LINEAR;
328*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceFrame(viewport.width, viewport.height);
329*35238bceSAndroid Build Coastguard Worker         tcu::Surface errorMask(viewport.width, viewport.height);
330*35238bceSAndroid Build Coastguard Worker         tcu::LookupPrecision lookupPrec;
331*35238bceSAndroid Build Coastguard Worker         tcu::LodPrecision lodPrec;
332*35238bceSAndroid Build Coastguard Worker         int numFailedPixels = 0;
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker         lookupPrec.coordBits = tcu::IVec3(20, 20, 0);
335*35238bceSAndroid Build Coastguard Worker         lookupPrec.uvwBits   = tcu::IVec3(16, 16, 0); // Doesn't really matter since pixels are unicolored.
336*35238bceSAndroid Build Coastguard Worker         lookupPrec.colorThreshold =
337*35238bceSAndroid Build Coastguard Worker             tcu::computeFixedPointThreshold(max(getBitsVec(pixelFormat) - (isTrilinear ? 2 : 1), tcu::IVec4(0)));
338*35238bceSAndroid Build Coastguard Worker         lookupPrec.colorMask = getCompareMask(pixelFormat);
339*35238bceSAndroid Build Coastguard Worker         lodPrec.derivateBits = 10;
340*35238bceSAndroid Build Coastguard Worker         lodPrec.lodBits      = isProjected ? 6 : 8;
341*35238bceSAndroid Build Coastguard Worker 
342*35238bceSAndroid Build Coastguard Worker         for (int gridY = 0; gridY < gridHeight; gridY++)
343*35238bceSAndroid Build Coastguard Worker         {
344*35238bceSAndroid Build Coastguard Worker             for (int gridX = 0; gridX < gridWidth; gridX++)
345*35238bceSAndroid Build Coastguard Worker             {
346*35238bceSAndroid Build Coastguard Worker                 const int curX    = cellWidth * gridX;
347*35238bceSAndroid Build Coastguard Worker                 const int curY    = cellHeight * gridY;
348*35238bceSAndroid Build Coastguard Worker                 const int curW    = gridX + 1 == gridWidth ? (viewport.width - curX) : cellWidth;
349*35238bceSAndroid Build Coastguard Worker                 const int curH    = gridY + 1 == gridHeight ? (viewport.height - curY) : cellHeight;
350*35238bceSAndroid Build Coastguard Worker                 const int cellNdx = gridY * gridWidth + gridX;
351*35238bceSAndroid Build Coastguard Worker 
352*35238bceSAndroid Build Coastguard Worker                 // Compute texcoord.
353*35238bceSAndroid Build Coastguard Worker                 switch (m_coordType)
354*35238bceSAndroid Build Coastguard Worker                 {
355*35238bceSAndroid Build Coastguard Worker                 case COORDTYPE_BASIC_BIAS: // Fall-through.
356*35238bceSAndroid Build Coastguard Worker                 case COORDTYPE_PROJECTED:
357*35238bceSAndroid Build Coastguard Worker                 case COORDTYPE_BASIC:
358*35238bceSAndroid Build Coastguard Worker                     getBasicTexCoord2D(texCoord, cellNdx);
359*35238bceSAndroid Build Coastguard Worker                     break;
360*35238bceSAndroid Build Coastguard Worker                 case COORDTYPE_AFFINE:
361*35238bceSAndroid Build Coastguard Worker                     getAffineTexCoord2D(texCoord, cellNdx);
362*35238bceSAndroid Build Coastguard Worker                     break;
363*35238bceSAndroid Build Coastguard Worker                 default:
364*35238bceSAndroid Build Coastguard Worker                     DE_ASSERT(false);
365*35238bceSAndroid Build Coastguard Worker                 }
366*35238bceSAndroid Build Coastguard Worker 
367*35238bceSAndroid Build Coastguard Worker                 if (isProjected)
368*35238bceSAndroid Build Coastguard Worker                     sampleParams.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
369*35238bceSAndroid Build Coastguard Worker 
370*35238bceSAndroid Build Coastguard Worker                 if (useLodBias)
371*35238bceSAndroid Build Coastguard Worker                     sampleParams.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
372*35238bceSAndroid Build Coastguard Worker 
373*35238bceSAndroid Build Coastguard Worker                 // Render ideal result
374*35238bceSAndroid Build Coastguard Worker                 sampleTexture(tcu::SurfaceAccess(referenceFrame, pixelFormat, curX, curY, curW, curH), refTexture,
375*35238bceSAndroid Build Coastguard Worker                               &texCoord[0], sampleParams);
376*35238bceSAndroid Build Coastguard Worker 
377*35238bceSAndroid Build Coastguard Worker                 // Compare this cell
378*35238bceSAndroid Build Coastguard Worker                 numFailedPixels += computeTextureLookupDiff(
379*35238bceSAndroid Build Coastguard Worker                     tcu::getSubregion(renderedFrame.getAccess(), curX, curY, curW, curH),
380*35238bceSAndroid Build Coastguard Worker                     tcu::getSubregion(referenceFrame.getAccess(), curX, curY, curW, curH),
381*35238bceSAndroid Build Coastguard Worker                     tcu::getSubregion(errorMask.getAccess(), curX, curY, curW, curH), m_texture->getRefTexture(),
382*35238bceSAndroid Build Coastguard Worker                     &texCoord[0], sampleParams, lookupPrec, lodPrec, m_testCtx.getWatchDog());
383*35238bceSAndroid Build Coastguard Worker             }
384*35238bceSAndroid Build Coastguard Worker         }
385*35238bceSAndroid Build Coastguard Worker 
386*35238bceSAndroid Build Coastguard Worker         if (numFailedPixels > 0)
387*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Message << "ERROR: Image verification failed, found " << numFailedPixels
388*35238bceSAndroid Build Coastguard Worker                                << " invalid pixels!" << TestLog::EndMessage;
389*35238bceSAndroid Build Coastguard Worker 
390*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::ImageSet("Result", "Verification result")
391*35238bceSAndroid Build Coastguard Worker                            << TestLog::Image("Rendered", "Rendered image", renderedFrame);
392*35238bceSAndroid Build Coastguard Worker 
393*35238bceSAndroid Build Coastguard Worker         if (numFailedPixels > 0)
394*35238bceSAndroid Build Coastguard Worker         {
395*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Image("Reference", "Ideal reference", referenceFrame)
396*35238bceSAndroid Build Coastguard Worker                                << TestLog::Image("ErrorMask", "Error mask", errorMask);
397*35238bceSAndroid Build Coastguard Worker         }
398*35238bceSAndroid Build Coastguard Worker 
399*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::EndImageSet;
400*35238bceSAndroid Build Coastguard Worker 
401*35238bceSAndroid Build Coastguard Worker         {
402*35238bceSAndroid Build Coastguard Worker             const bool isOk = numFailedPixels == 0;
403*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
404*35238bceSAndroid Build Coastguard Worker                                     isOk ? "Pass" : "Image verification failed");
405*35238bceSAndroid Build Coastguard Worker         }
406*35238bceSAndroid Build Coastguard Worker     }
407*35238bceSAndroid Build Coastguard Worker 
408*35238bceSAndroid Build Coastguard Worker     return STOP;
409*35238bceSAndroid Build Coastguard Worker }
410*35238bceSAndroid Build Coastguard Worker 
411*35238bceSAndroid Build Coastguard Worker // TextureCubeMipmapCase
412*35238bceSAndroid Build Coastguard Worker 
413*35238bceSAndroid Build Coastguard Worker class TextureCubeMipmapCase : public tcu::TestCase
414*35238bceSAndroid Build Coastguard Worker {
415*35238bceSAndroid Build Coastguard Worker public:
416*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
417*35238bceSAndroid Build Coastguard Worker                           const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
418*35238bceSAndroid Build Coastguard Worker                           CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT, uint32_t format,
419*35238bceSAndroid Build Coastguard Worker                           uint32_t dataType, int size);
420*35238bceSAndroid Build Coastguard Worker     ~TextureCubeMipmapCase(void);
421*35238bceSAndroid Build Coastguard Worker 
422*35238bceSAndroid Build Coastguard Worker     void init(void);
423*35238bceSAndroid Build Coastguard Worker     void deinit(void);
424*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
425*35238bceSAndroid Build Coastguard Worker 
426*35238bceSAndroid Build Coastguard Worker private:
427*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase(const TextureCubeMipmapCase &other);
428*35238bceSAndroid Build Coastguard Worker     TextureCubeMipmapCase &operator=(const TextureCubeMipmapCase &other);
429*35238bceSAndroid Build Coastguard Worker 
430*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
431*35238bceSAndroid Build Coastguard Worker     const glu::ContextInfo &m_renderCtxInfo;
432*35238bceSAndroid Build Coastguard Worker 
433*35238bceSAndroid Build Coastguard Worker     CoordType m_coordType;
434*35238bceSAndroid Build Coastguard Worker     uint32_t m_minFilter;
435*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapS;
436*35238bceSAndroid Build Coastguard Worker     uint32_t m_wrapT;
437*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
438*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
439*35238bceSAndroid Build Coastguard Worker     int m_size;
440*35238bceSAndroid Build Coastguard Worker 
441*35238bceSAndroid Build Coastguard Worker     glu::TextureCube *m_texture;
442*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
443*35238bceSAndroid Build Coastguard Worker };
444*35238bceSAndroid Build Coastguard Worker 
TextureCubeMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const glu::ContextInfo & renderCtxInfo,const char * name,const char * desc,CoordType coordType,uint32_t minFilter,uint32_t wrapS,uint32_t wrapT,uint32_t format,uint32_t dataType,int size)445*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::TextureCubeMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
446*35238bceSAndroid Build Coastguard Worker                                              const glu::ContextInfo &renderCtxInfo, const char *name, const char *desc,
447*35238bceSAndroid Build Coastguard Worker                                              CoordType coordType, uint32_t minFilter, uint32_t wrapS, uint32_t wrapT,
448*35238bceSAndroid Build Coastguard Worker                                              uint32_t format, uint32_t dataType, int size)
449*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, desc)
450*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
451*35238bceSAndroid Build Coastguard Worker     , m_renderCtxInfo(renderCtxInfo)
452*35238bceSAndroid Build Coastguard Worker     , m_coordType(coordType)
453*35238bceSAndroid Build Coastguard Worker     , m_minFilter(minFilter)
454*35238bceSAndroid Build Coastguard Worker     , m_wrapS(wrapS)
455*35238bceSAndroid Build Coastguard Worker     , m_wrapT(wrapT)
456*35238bceSAndroid Build Coastguard Worker     , m_format(format)
457*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
458*35238bceSAndroid Build Coastguard Worker     , m_size(size)
459*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
460*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES,
461*35238bceSAndroid Build Coastguard Worker                  renderCtxInfo.isFragmentHighPrecisionSupported() ? glu::PRECISION_HIGHP // Use highp if available.
462*35238bceSAndroid Build Coastguard Worker                                                                     :
463*35238bceSAndroid Build Coastguard Worker                                                                     glu::PRECISION_MEDIUMP)
464*35238bceSAndroid Build Coastguard Worker {
465*35238bceSAndroid Build Coastguard Worker }
466*35238bceSAndroid Build Coastguard Worker 
~TextureCubeMipmapCase(void)467*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::~TextureCubeMipmapCase(void)
468*35238bceSAndroid Build Coastguard Worker {
469*35238bceSAndroid Build Coastguard Worker     deinit();
470*35238bceSAndroid Build Coastguard Worker }
471*35238bceSAndroid Build Coastguard Worker 
init(void)472*35238bceSAndroid Build Coastguard Worker void TextureCubeMipmapCase::init(void)
473*35238bceSAndroid Build Coastguard Worker {
474*35238bceSAndroid Build Coastguard Worker     if (!m_renderCtxInfo.isFragmentHighPrecisionSupported())
475*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Warning: High precision not supported in fragment shaders."
476*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
477*35238bceSAndroid Build Coastguard Worker 
478*35238bceSAndroid Build Coastguard Worker     if (m_coordType == COORDTYPE_PROJECTED && m_renderCtx.getRenderTarget().getNumSamples() > 0)
479*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Projected lookup validation not supported in multisample config");
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker     m_texture = new TextureCube(m_renderCtx, m_format, m_dataType, m_size);
482*35238bceSAndroid Build Coastguard Worker 
483*35238bceSAndroid Build Coastguard Worker     int numLevels = deLog2Floor32(m_size) + 1;
484*35238bceSAndroid Build Coastguard Worker 
485*35238bceSAndroid Build Coastguard Worker     // Fill texture with colored grid.
486*35238bceSAndroid Build Coastguard Worker     for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
487*35238bceSAndroid Build Coastguard Worker     {
488*35238bceSAndroid Build Coastguard Worker         for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
489*35238bceSAndroid Build Coastguard Worker         {
490*35238bceSAndroid Build Coastguard Worker             uint32_t step = 0xff / (numLevels - 1);
491*35238bceSAndroid Build Coastguard Worker             uint32_t inc  = deClamp32(step * levelNdx, 0x00, 0xff);
492*35238bceSAndroid Build Coastguard Worker             uint32_t dec  = 0xff - inc;
493*35238bceSAndroid Build Coastguard Worker             uint32_t rgb  = 0;
494*35238bceSAndroid Build Coastguard Worker 
495*35238bceSAndroid Build Coastguard Worker             switch (faceNdx)
496*35238bceSAndroid Build Coastguard Worker             {
497*35238bceSAndroid Build Coastguard Worker             case 0:
498*35238bceSAndroid Build Coastguard Worker                 rgb = (inc << 16) | (dec << 8) | 255;
499*35238bceSAndroid Build Coastguard Worker                 break;
500*35238bceSAndroid Build Coastguard Worker             case 1:
501*35238bceSAndroid Build Coastguard Worker                 rgb = (255 << 16) | (inc << 8) | dec;
502*35238bceSAndroid Build Coastguard Worker                 break;
503*35238bceSAndroid Build Coastguard Worker             case 2:
504*35238bceSAndroid Build Coastguard Worker                 rgb = (dec << 16) | (255 << 8) | inc;
505*35238bceSAndroid Build Coastguard Worker                 break;
506*35238bceSAndroid Build Coastguard Worker             case 3:
507*35238bceSAndroid Build Coastguard Worker                 rgb = (dec << 16) | (inc << 8) | 255;
508*35238bceSAndroid Build Coastguard Worker                 break;
509*35238bceSAndroid Build Coastguard Worker             case 4:
510*35238bceSAndroid Build Coastguard Worker                 rgb = (255 << 16) | (dec << 8) | inc;
511*35238bceSAndroid Build Coastguard Worker                 break;
512*35238bceSAndroid Build Coastguard Worker             case 5:
513*35238bceSAndroid Build Coastguard Worker                 rgb = (inc << 16) | (255 << 8) | dec;
514*35238bceSAndroid Build Coastguard Worker                 break;
515*35238bceSAndroid Build Coastguard Worker             }
516*35238bceSAndroid Build Coastguard Worker 
517*35238bceSAndroid Build Coastguard Worker             uint32_t color = 0xff000000 | rgb;
518*35238bceSAndroid Build Coastguard Worker 
519*35238bceSAndroid Build Coastguard Worker             m_texture->getRefTexture().allocLevel((tcu::CubeFace)faceNdx, levelNdx);
520*35238bceSAndroid Build Coastguard Worker             tcu::clear(m_texture->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)faceNdx),
521*35238bceSAndroid Build Coastguard Worker                        tcu::RGBA(color).toVec());
522*35238bceSAndroid Build Coastguard Worker         }
523*35238bceSAndroid Build Coastguard Worker     }
524*35238bceSAndroid Build Coastguard Worker }
525*35238bceSAndroid Build Coastguard Worker 
deinit(void)526*35238bceSAndroid Build Coastguard Worker void TextureCubeMipmapCase::deinit(void)
527*35238bceSAndroid Build Coastguard Worker {
528*35238bceSAndroid Build Coastguard Worker     delete m_texture;
529*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
530*35238bceSAndroid Build Coastguard Worker 
531*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
532*35238bceSAndroid Build Coastguard Worker }
533*35238bceSAndroid Build Coastguard Worker 
randomPartition(vector<IVec4> & dst,de::Random & rnd,int x,int y,int width,int height)534*35238bceSAndroid Build Coastguard Worker static void randomPartition(vector<IVec4> &dst, de::Random &rnd, int x, int y, int width, int height)
535*35238bceSAndroid Build Coastguard Worker {
536*35238bceSAndroid Build Coastguard Worker     const int minWidth  = 8;
537*35238bceSAndroid Build Coastguard Worker     const int minHeight = 8;
538*35238bceSAndroid Build Coastguard Worker 
539*35238bceSAndroid Build Coastguard Worker     bool partition  = rnd.getFloat() > 0.4f;
540*35238bceSAndroid Build Coastguard Worker     bool partitionX = partition && width > minWidth && rnd.getBool();
541*35238bceSAndroid Build Coastguard Worker     bool partitionY = partition && height > minHeight && !partitionX;
542*35238bceSAndroid Build Coastguard Worker 
543*35238bceSAndroid Build Coastguard Worker     if (partitionX)
544*35238bceSAndroid Build Coastguard Worker     {
545*35238bceSAndroid Build Coastguard Worker         int split = width / 2 + rnd.getInt(-width / 4, +width / 4);
546*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y, split, height);
547*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x + split, y, width - split, height);
548*35238bceSAndroid Build Coastguard Worker     }
549*35238bceSAndroid Build Coastguard Worker     else if (partitionY)
550*35238bceSAndroid Build Coastguard Worker     {
551*35238bceSAndroid Build Coastguard Worker         int split = height / 2 + rnd.getInt(-height / 4, +height / 4);
552*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y, width, split);
553*35238bceSAndroid Build Coastguard Worker         randomPartition(dst, rnd, x, y + split, width, height - split);
554*35238bceSAndroid Build Coastguard Worker     }
555*35238bceSAndroid Build Coastguard Worker     else
556*35238bceSAndroid Build Coastguard Worker         dst.push_back(IVec4(x, y, width, height));
557*35238bceSAndroid Build Coastguard Worker }
558*35238bceSAndroid Build Coastguard Worker 
computeGridLayout(vector<IVec4> & dst,int width,int height)559*35238bceSAndroid Build Coastguard Worker static void computeGridLayout(vector<IVec4> &dst, int width, int height)
560*35238bceSAndroid Build Coastguard Worker {
561*35238bceSAndroid Build Coastguard Worker     de::Random rnd(7);
562*35238bceSAndroid Build Coastguard Worker     randomPartition(dst, rnd, 0, 0, width, height);
563*35238bceSAndroid Build Coastguard Worker }
564*35238bceSAndroid Build Coastguard Worker 
iterate(void)565*35238bceSAndroid Build Coastguard Worker TextureCubeMipmapCase::IterateResult TextureCubeMipmapCase::iterate(void)
566*35238bceSAndroid Build Coastguard Worker {
567*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter    = GL_NEAREST;
568*35238bceSAndroid Build Coastguard Worker     const int texWidth          = m_texture->getRefTexture().getSize();
569*35238bceSAndroid Build Coastguard Worker     const int texHeight         = m_texture->getRefTexture().getSize();
570*35238bceSAndroid Build Coastguard Worker     const int defViewportWidth  = texWidth * 2;
571*35238bceSAndroid Build Coastguard Worker     const int defViewportHeight = texHeight * 2;
572*35238bceSAndroid Build Coastguard Worker 
573*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
574*35238bceSAndroid Build Coastguard Worker     const RandomViewport viewport(m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight,
575*35238bceSAndroid Build Coastguard Worker                                   deStringHash(getName()));
576*35238bceSAndroid Build Coastguard Worker 
577*35238bceSAndroid Build Coastguard Worker     const bool isProjected = m_coordType == COORDTYPE_PROJECTED;
578*35238bceSAndroid Build Coastguard Worker     const bool useLodBias  = m_coordType == COORDTYPE_BASIC_BIAS;
579*35238bceSAndroid Build Coastguard Worker 
580*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
581*35238bceSAndroid Build Coastguard Worker     tcu::Surface renderedFrame(viewport.width, viewport.height);
582*35238bceSAndroid Build Coastguard Worker 
583*35238bceSAndroid Build Coastguard Worker     // Bail out if rendertarget is too small.
584*35238bceSAndroid Build Coastguard Worker     if (viewport.width < defViewportWidth / 2 || viewport.height < defViewportHeight / 2)
585*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__);
586*35238bceSAndroid Build Coastguard Worker 
587*35238bceSAndroid Build Coastguard Worker     bool isES3Compatible = m_renderCtxInfo.isES3Compatible();
588*35238bceSAndroid Build Coastguard Worker 
589*35238bceSAndroid Build Coastguard Worker     // Upload texture data.
590*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
591*35238bceSAndroid Build Coastguard Worker 
592*35238bceSAndroid Build Coastguard Worker     // Bind gradient texture and setup sampler parameters.
593*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
594*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS);
595*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT);
596*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter);
597*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, magFilter);
598*35238bceSAndroid Build Coastguard Worker 
599*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
600*35238bceSAndroid Build Coastguard Worker 
601*35238bceSAndroid Build Coastguard Worker     // Compute grid.
602*35238bceSAndroid Build Coastguard Worker     vector<IVec4> gridLayout;
603*35238bceSAndroid Build Coastguard Worker     computeGridLayout(gridLayout, viewport.width, viewport.height);
604*35238bceSAndroid Build Coastguard Worker 
605*35238bceSAndroid Build Coastguard Worker     // Bias values.
606*35238bceSAndroid Build Coastguard Worker     static const float s_bias[] = {1.0f, -2.0f, 0.8f, -0.5f, 1.5f, 0.9f, 2.0f, 4.0f};
607*35238bceSAndroid Build Coastguard Worker 
608*35238bceSAndroid Build Coastguard Worker     // Projection values \note Less agressive than in 2D case due to smaller quads.
609*35238bceSAndroid Build Coastguard Worker     static const Vec4 s_projections[] = {Vec4(1.2f, 1.0f, 0.7f, 1.0f), Vec4(1.3f, 0.8f, 0.6f, 1.1f),
610*35238bceSAndroid Build Coastguard Worker                                          Vec4(0.8f, 1.0f, 1.2f, 0.8f), Vec4(1.2f, 1.0f, 1.3f, 0.9f)};
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker     // Render with GL
613*35238bceSAndroid Build Coastguard Worker     for (int cellNdx = 0; cellNdx < (int)gridLayout.size(); cellNdx++)
614*35238bceSAndroid Build Coastguard Worker     {
615*35238bceSAndroid Build Coastguard Worker         const int curX               = gridLayout[cellNdx].x();
616*35238bceSAndroid Build Coastguard Worker         const int curY               = gridLayout[cellNdx].y();
617*35238bceSAndroid Build Coastguard Worker         const int curW               = gridLayout[cellNdx].z();
618*35238bceSAndroid Build Coastguard Worker         const int curH               = gridLayout[cellNdx].w();
619*35238bceSAndroid Build Coastguard Worker         const tcu::CubeFace cubeFace = (tcu::CubeFace)(cellNdx % tcu::CUBEFACE_LAST);
620*35238bceSAndroid Build Coastguard Worker         RenderParams params(TEXTURETYPE_CUBE);
621*35238bceSAndroid Build Coastguard Worker 
622*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_coordType != COORDTYPE_AFFINE); // Not supported.
623*35238bceSAndroid Build Coastguard Worker         computeQuadTexCoordCube(texCoord, cubeFace);
624*35238bceSAndroid Build Coastguard Worker 
625*35238bceSAndroid Build Coastguard Worker         if (isProjected)
626*35238bceSAndroid Build Coastguard Worker         {
627*35238bceSAndroid Build Coastguard Worker             params.flags |= ReferenceParams::PROJECTED;
628*35238bceSAndroid Build Coastguard Worker             params.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
629*35238bceSAndroid Build Coastguard Worker         }
630*35238bceSAndroid Build Coastguard Worker 
631*35238bceSAndroid Build Coastguard Worker         if (useLodBias)
632*35238bceSAndroid Build Coastguard Worker         {
633*35238bceSAndroid Build Coastguard Worker             params.flags |= ReferenceParams::USE_BIAS;
634*35238bceSAndroid Build Coastguard Worker             params.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
635*35238bceSAndroid Build Coastguard Worker         }
636*35238bceSAndroid Build Coastguard Worker 
637*35238bceSAndroid Build Coastguard Worker         // Render with GL.
638*35238bceSAndroid Build Coastguard Worker         gl.viewport(viewport.x + curX, viewport.y + curY, curW, curH);
639*35238bceSAndroid Build Coastguard Worker         m_renderer.renderQuad(0, &texCoord[0], params);
640*35238bceSAndroid Build Coastguard Worker     }
641*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
642*35238bceSAndroid Build Coastguard Worker 
643*35238bceSAndroid Build Coastguard Worker     // Read result.
644*35238bceSAndroid Build Coastguard Worker     glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess());
645*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Read pixels");
646*35238bceSAndroid Build Coastguard Worker 
647*35238bceSAndroid Build Coastguard Worker     // Render reference and compare
648*35238bceSAndroid Build Coastguard Worker     {
649*35238bceSAndroid Build Coastguard Worker         tcu::Surface referenceFrame(viewport.width, viewport.height);
650*35238bceSAndroid Build Coastguard Worker         tcu::Surface errorMask(viewport.width, viewport.height);
651*35238bceSAndroid Build Coastguard Worker         int numFailedPixels = 0;
652*35238bceSAndroid Build Coastguard Worker         ReferenceParams params(TEXTURETYPE_CUBE);
653*35238bceSAndroid Build Coastguard Worker         tcu::LookupPrecision lookupPrec;
654*35238bceSAndroid Build Coastguard Worker         tcu::LodPrecision lodPrec;
655*35238bceSAndroid Build Coastguard Worker 
656*35238bceSAndroid Build Coastguard Worker         // Params for rendering reference
657*35238bceSAndroid Build Coastguard Worker         params.sampler                 = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, magFilter);
658*35238bceSAndroid Build Coastguard Worker         params.sampler.seamlessCubeMap = isES3Compatible;
659*35238bceSAndroid Build Coastguard Worker         params.lodMode                 = LODMODE_EXACT;
660*35238bceSAndroid Build Coastguard Worker 
661*35238bceSAndroid Build Coastguard Worker         // Comparison parameters
662*35238bceSAndroid Build Coastguard Worker         lookupPrec.colorMask      = getCompareMask(m_renderCtx.getRenderTarget().getPixelFormat());
663*35238bceSAndroid Build Coastguard Worker         lookupPrec.colorThreshold = tcu::computeFixedPointThreshold(
664*35238bceSAndroid Build Coastguard Worker             max(getBitsVec(m_renderCtx.getRenderTarget().getPixelFormat()) - 2, IVec4(0)));
665*35238bceSAndroid Build Coastguard Worker         lookupPrec.coordBits = isProjected ? tcu::IVec3(8) : tcu::IVec3(10);
666*35238bceSAndroid Build Coastguard Worker         lookupPrec.uvwBits   = tcu::IVec3(5, 5, 0);
667*35238bceSAndroid Build Coastguard Worker         lodPrec.derivateBits = 10;
668*35238bceSAndroid Build Coastguard Worker         lodPrec.lodBits      = isES3Compatible ? 3 : 4;
669*35238bceSAndroid Build Coastguard Worker         lodPrec.lodBits      = isProjected ? lodPrec.lodBits : 6;
670*35238bceSAndroid Build Coastguard Worker 
671*35238bceSAndroid Build Coastguard Worker         for (int cellNdx = 0; cellNdx < (int)gridLayout.size(); cellNdx++)
672*35238bceSAndroid Build Coastguard Worker         {
673*35238bceSAndroid Build Coastguard Worker             const int curX               = gridLayout[cellNdx].x();
674*35238bceSAndroid Build Coastguard Worker             const int curY               = gridLayout[cellNdx].y();
675*35238bceSAndroid Build Coastguard Worker             const int curW               = gridLayout[cellNdx].z();
676*35238bceSAndroid Build Coastguard Worker             const int curH               = gridLayout[cellNdx].w();
677*35238bceSAndroid Build Coastguard Worker             const tcu::CubeFace cubeFace = (tcu::CubeFace)(cellNdx % tcu::CUBEFACE_LAST);
678*35238bceSAndroid Build Coastguard Worker 
679*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(m_coordType != COORDTYPE_AFFINE); // Not supported.
680*35238bceSAndroid Build Coastguard Worker             computeQuadTexCoordCube(texCoord, cubeFace);
681*35238bceSAndroid Build Coastguard Worker 
682*35238bceSAndroid Build Coastguard Worker             if (isProjected)
683*35238bceSAndroid Build Coastguard Worker             {
684*35238bceSAndroid Build Coastguard Worker                 params.flags |= ReferenceParams::PROJECTED;
685*35238bceSAndroid Build Coastguard Worker                 params.w = s_projections[cellNdx % DE_LENGTH_OF_ARRAY(s_projections)];
686*35238bceSAndroid Build Coastguard Worker             }
687*35238bceSAndroid Build Coastguard Worker 
688*35238bceSAndroid Build Coastguard Worker             if (useLodBias)
689*35238bceSAndroid Build Coastguard Worker             {
690*35238bceSAndroid Build Coastguard Worker                 params.flags |= ReferenceParams::USE_BIAS;
691*35238bceSAndroid Build Coastguard Worker                 params.bias = s_bias[cellNdx % DE_LENGTH_OF_ARRAY(s_bias)];
692*35238bceSAndroid Build Coastguard Worker             }
693*35238bceSAndroid Build Coastguard Worker 
694*35238bceSAndroid Build Coastguard Worker             // Render ideal reference.
695*35238bceSAndroid Build Coastguard Worker             {
696*35238bceSAndroid Build Coastguard Worker                 tcu::SurfaceAccess idealDst(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), curX, curY,
697*35238bceSAndroid Build Coastguard Worker                                             curW, curH);
698*35238bceSAndroid Build Coastguard Worker                 sampleTexture(idealDst, m_texture->getRefTexture(), &texCoord[0], params);
699*35238bceSAndroid Build Coastguard Worker             }
700*35238bceSAndroid Build Coastguard Worker 
701*35238bceSAndroid Build Coastguard Worker             // Compare this cell
702*35238bceSAndroid Build Coastguard Worker             numFailedPixels += computeTextureLookupDiff(
703*35238bceSAndroid Build Coastguard Worker                 tcu::getSubregion(renderedFrame.getAccess(), curX, curY, curW, curH),
704*35238bceSAndroid Build Coastguard Worker                 tcu::getSubregion(referenceFrame.getAccess(), curX, curY, curW, curH),
705*35238bceSAndroid Build Coastguard Worker                 tcu::getSubregion(errorMask.getAccess(), curX, curY, curW, curH), m_texture->getRefTexture(),
706*35238bceSAndroid Build Coastguard Worker                 &texCoord[0], params, lookupPrec, lodPrec, m_testCtx.getWatchDog());
707*35238bceSAndroid Build Coastguard Worker         }
708*35238bceSAndroid Build Coastguard Worker 
709*35238bceSAndroid Build Coastguard Worker         if (numFailedPixels > 0)
710*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Message << "ERROR: Image verification failed, found " << numFailedPixels
711*35238bceSAndroid Build Coastguard Worker                                << " invalid pixels!" << TestLog::EndMessage;
712*35238bceSAndroid Build Coastguard Worker 
713*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::ImageSet("Result", "Verification result")
714*35238bceSAndroid Build Coastguard Worker                            << TestLog::Image("Rendered", "Rendered image", renderedFrame);
715*35238bceSAndroid Build Coastguard Worker 
716*35238bceSAndroid Build Coastguard Worker         if (numFailedPixels > 0)
717*35238bceSAndroid Build Coastguard Worker         {
718*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Image("Reference", "Ideal reference", referenceFrame)
719*35238bceSAndroid Build Coastguard Worker                                << TestLog::Image("ErrorMask", "Error mask", errorMask);
720*35238bceSAndroid Build Coastguard Worker         }
721*35238bceSAndroid Build Coastguard Worker 
722*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::EndImageSet;
723*35238bceSAndroid Build Coastguard Worker 
724*35238bceSAndroid Build Coastguard Worker         {
725*35238bceSAndroid Build Coastguard Worker             const bool isOk = numFailedPixels == 0;
726*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
727*35238bceSAndroid Build Coastguard Worker                                     isOk ? "Pass" : "Image verification failed");
728*35238bceSAndroid Build Coastguard Worker         }
729*35238bceSAndroid Build Coastguard Worker     }
730*35238bceSAndroid Build Coastguard Worker 
731*35238bceSAndroid Build Coastguard Worker     return STOP;
732*35238bceSAndroid Build Coastguard Worker }
733*35238bceSAndroid Build Coastguard Worker 
734*35238bceSAndroid Build Coastguard Worker // Texture2DGenMipmapCase
735*35238bceSAndroid Build Coastguard Worker 
736*35238bceSAndroid Build Coastguard Worker class Texture2DGenMipmapCase : public tcu::TestCase
737*35238bceSAndroid Build Coastguard Worker {
738*35238bceSAndroid Build Coastguard Worker public:
739*35238bceSAndroid Build Coastguard Worker     Texture2DGenMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name, const char *desc,
740*35238bceSAndroid Build Coastguard Worker                            uint32_t format, uint32_t dataType, uint32_t hint, int width, int height);
741*35238bceSAndroid Build Coastguard Worker     ~Texture2DGenMipmapCase(void);
742*35238bceSAndroid Build Coastguard Worker 
743*35238bceSAndroid Build Coastguard Worker     void init(void);
744*35238bceSAndroid Build Coastguard Worker     void deinit(void);
745*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
746*35238bceSAndroid Build Coastguard Worker 
747*35238bceSAndroid Build Coastguard Worker private:
748*35238bceSAndroid Build Coastguard Worker     Texture2DGenMipmapCase(const Texture2DGenMipmapCase &other);
749*35238bceSAndroid Build Coastguard Worker     Texture2DGenMipmapCase &operator=(const Texture2DGenMipmapCase &other);
750*35238bceSAndroid Build Coastguard Worker 
751*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
752*35238bceSAndroid Build Coastguard Worker 
753*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
754*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
755*35238bceSAndroid Build Coastguard Worker     uint32_t m_hint;
756*35238bceSAndroid Build Coastguard Worker     int m_width;
757*35238bceSAndroid Build Coastguard Worker     int m_height;
758*35238bceSAndroid Build Coastguard Worker 
759*35238bceSAndroid Build Coastguard Worker     glu::Texture2D *m_texture;
760*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
761*35238bceSAndroid Build Coastguard Worker };
762*35238bceSAndroid Build Coastguard Worker 
Texture2DGenMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const char * name,const char * desc,uint32_t format,uint32_t dataType,uint32_t hint,int width,int height)763*35238bceSAndroid Build Coastguard Worker Texture2DGenMipmapCase::Texture2DGenMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
764*35238bceSAndroid Build Coastguard Worker                                                const char *name, const char *desc, uint32_t format, uint32_t dataType,
765*35238bceSAndroid Build Coastguard Worker                                                uint32_t hint, int width, int height)
766*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, desc)
767*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
768*35238bceSAndroid Build Coastguard Worker     , m_format(format)
769*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
770*35238bceSAndroid Build Coastguard Worker     , m_hint(hint)
771*35238bceSAndroid Build Coastguard Worker     , m_width(width)
772*35238bceSAndroid Build Coastguard Worker     , m_height(height)
773*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
774*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
775*35238bceSAndroid Build Coastguard Worker {
776*35238bceSAndroid Build Coastguard Worker }
777*35238bceSAndroid Build Coastguard Worker 
~Texture2DGenMipmapCase(void)778*35238bceSAndroid Build Coastguard Worker Texture2DGenMipmapCase::~Texture2DGenMipmapCase(void)
779*35238bceSAndroid Build Coastguard Worker {
780*35238bceSAndroid Build Coastguard Worker     deinit();
781*35238bceSAndroid Build Coastguard Worker }
782*35238bceSAndroid Build Coastguard Worker 
init(void)783*35238bceSAndroid Build Coastguard Worker void Texture2DGenMipmapCase::init(void)
784*35238bceSAndroid Build Coastguard Worker {
785*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_texture);
786*35238bceSAndroid Build Coastguard Worker     m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height);
787*35238bceSAndroid Build Coastguard Worker }
788*35238bceSAndroid Build Coastguard Worker 
deinit(void)789*35238bceSAndroid Build Coastguard Worker void Texture2DGenMipmapCase::deinit(void)
790*35238bceSAndroid Build Coastguard Worker {
791*35238bceSAndroid Build Coastguard Worker     delete m_texture;
792*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
793*35238bceSAndroid Build Coastguard Worker 
794*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
795*35238bceSAndroid Build Coastguard Worker }
796*35238bceSAndroid Build Coastguard Worker 
iterate(void)797*35238bceSAndroid Build Coastguard Worker Texture2DGenMipmapCase::IterateResult Texture2DGenMipmapCase::iterate(void)
798*35238bceSAndroid Build Coastguard Worker {
799*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
800*35238bceSAndroid Build Coastguard Worker 
801*35238bceSAndroid Build Coastguard Worker     const uint32_t minFilter = GL_NEAREST_MIPMAP_NEAREST;
802*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter = GL_NEAREST;
803*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapS     = GL_CLAMP_TO_EDGE;
804*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapT     = GL_CLAMP_TO_EDGE;
805*35238bceSAndroid Build Coastguard Worker 
806*35238bceSAndroid Build Coastguard Worker     const int numLevels = deLog2Floor32(de::max(m_width, m_height)) + 1;
807*35238bceSAndroid Build Coastguard Worker 
808*35238bceSAndroid Build Coastguard Worker     tcu::Texture2D resultTexture(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
809*35238bceSAndroid Build Coastguard Worker                                  m_texture->getRefTexture().getWidth(), m_texture->getRefTexture().getHeight(),
810*35238bceSAndroid Build Coastguard Worker                                  isES2Context(m_renderCtx.getType()));
811*35238bceSAndroid Build Coastguard Worker 
812*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
813*35238bceSAndroid Build Coastguard Worker 
814*35238bceSAndroid Build Coastguard Worker     // Initialize texture level 0 with colored grid.
815*35238bceSAndroid Build Coastguard Worker     m_texture->getRefTexture().allocLevel(0);
816*35238bceSAndroid Build Coastguard Worker     tcu::fillWithGrid(m_texture->getRefTexture().getLevel(0), 8, tcu::Vec4(1.0f, 0.5f, 0.0f, 0.5f),
817*35238bceSAndroid Build Coastguard Worker                       tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
818*35238bceSAndroid Build Coastguard Worker 
819*35238bceSAndroid Build Coastguard Worker     // Upload data and setup params.
820*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
821*35238bceSAndroid Build Coastguard Worker 
822*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture());
823*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
824*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
825*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
826*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
827*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
828*35238bceSAndroid Build Coastguard Worker 
829*35238bceSAndroid Build Coastguard Worker     // Generate mipmap.
830*35238bceSAndroid Build Coastguard Worker     gl.hint(GL_GENERATE_MIPMAP_HINT, m_hint);
831*35238bceSAndroid Build Coastguard Worker     gl.generateMipmap(GL_TEXTURE_2D);
832*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap()");
833*35238bceSAndroid Build Coastguard Worker 
834*35238bceSAndroid Build Coastguard Worker     // Use (0, 0) -> (1, 1) texture coordinates.
835*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(texCoord, Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f));
836*35238bceSAndroid Build Coastguard Worker 
837*35238bceSAndroid Build Coastguard Worker     // Fetch resulting texture by rendering.
838*35238bceSAndroid Build Coastguard Worker     for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
839*35238bceSAndroid Build Coastguard Worker     {
840*35238bceSAndroid Build Coastguard Worker         const int levelWidth  = de::max(1, m_width >> levelNdx);
841*35238bceSAndroid Build Coastguard Worker         const int levelHeight = de::max(1, m_height >> levelNdx);
842*35238bceSAndroid Build Coastguard Worker         const RandomViewport viewport(m_renderCtx.getRenderTarget(), levelWidth, levelHeight,
843*35238bceSAndroid Build Coastguard Worker                                       deStringHash(getName()) + levelNdx);
844*35238bceSAndroid Build Coastguard Worker 
845*35238bceSAndroid Build Coastguard Worker         gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
846*35238bceSAndroid Build Coastguard Worker         m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_2D);
847*35238bceSAndroid Build Coastguard Worker 
848*35238bceSAndroid Build Coastguard Worker         resultTexture.allocLevel(levelNdx);
849*35238bceSAndroid Build Coastguard Worker         glu::readPixels(m_renderCtx, viewport.x, viewport.y, resultTexture.getLevel(levelNdx));
850*35238bceSAndroid Build Coastguard Worker     }
851*35238bceSAndroid Build Coastguard Worker 
852*35238bceSAndroid Build Coastguard Worker     // Compare results
853*35238bceSAndroid Build Coastguard Worker     {
854*35238bceSAndroid Build Coastguard Worker 
855*35238bceSAndroid Build Coastguard Worker         const IVec4 framebufferBits = max(getBitsVec(m_renderCtx.getRenderTarget().getPixelFormat()) - 2, IVec4(0));
856*35238bceSAndroid Build Coastguard Worker         const IVec4 formatBits      = tcu::getTextureFormatBitDepth(glu::mapGLTransferFormat(m_format, m_dataType));
857*35238bceSAndroid Build Coastguard Worker         const tcu::BVec4 formatMask = greaterThan(formatBits, IVec4(0));
858*35238bceSAndroid Build Coastguard Worker         const IVec4 cmpBits         = select(min(framebufferBits, formatBits), framebufferBits, formatMask);
859*35238bceSAndroid Build Coastguard Worker         GenMipmapPrecision comparePrec;
860*35238bceSAndroid Build Coastguard Worker 
861*35238bceSAndroid Build Coastguard Worker         comparePrec.colorMask      = getCompareMask(m_renderCtx.getRenderTarget().getPixelFormat());
862*35238bceSAndroid Build Coastguard Worker         comparePrec.colorThreshold = tcu::computeFixedPointThreshold(cmpBits);
863*35238bceSAndroid Build Coastguard Worker         comparePrec.filterBits     = tcu::IVec3(4, 4, 0);
864*35238bceSAndroid Build Coastguard Worker 
865*35238bceSAndroid Build Coastguard Worker         const qpTestResult compareResult =
866*35238bceSAndroid Build Coastguard Worker             compareGenMipmapResult(m_testCtx.getLog(), resultTexture, m_texture->getRefTexture(), comparePrec);
867*35238bceSAndroid Build Coastguard Worker 
868*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(compareResult, compareResult == QP_TEST_RESULT_PASS ? "Pass" :
869*35238bceSAndroid Build Coastguard Worker                                                compareResult == QP_TEST_RESULT_QUALITY_WARNING ?
870*35238bceSAndroid Build Coastguard Worker                                                                                       "Low-quality method used" :
871*35238bceSAndroid Build Coastguard Worker                                                compareResult == QP_TEST_RESULT_FAIL ? "Image comparison failed" :
872*35238bceSAndroid Build Coastguard Worker                                                                                       "");
873*35238bceSAndroid Build Coastguard Worker     }
874*35238bceSAndroid Build Coastguard Worker 
875*35238bceSAndroid Build Coastguard Worker     return STOP;
876*35238bceSAndroid Build Coastguard Worker }
877*35238bceSAndroid Build Coastguard Worker 
878*35238bceSAndroid Build Coastguard Worker // TextureCubeGenMipmapCase
879*35238bceSAndroid Build Coastguard Worker 
880*35238bceSAndroid Build Coastguard Worker class TextureCubeGenMipmapCase : public tcu::TestCase
881*35238bceSAndroid Build Coastguard Worker {
882*35238bceSAndroid Build Coastguard Worker public:
883*35238bceSAndroid Build Coastguard Worker     TextureCubeGenMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx, const char *name,
884*35238bceSAndroid Build Coastguard Worker                              const char *desc, uint32_t format, uint32_t dataType, uint32_t hint, int size);
885*35238bceSAndroid Build Coastguard Worker     ~TextureCubeGenMipmapCase(void);
886*35238bceSAndroid Build Coastguard Worker 
887*35238bceSAndroid Build Coastguard Worker     void init(void);
888*35238bceSAndroid Build Coastguard Worker     void deinit(void);
889*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
890*35238bceSAndroid Build Coastguard Worker 
891*35238bceSAndroid Build Coastguard Worker private:
892*35238bceSAndroid Build Coastguard Worker     TextureCubeGenMipmapCase(const TextureCubeGenMipmapCase &other);
893*35238bceSAndroid Build Coastguard Worker     TextureCubeGenMipmapCase &operator=(const TextureCubeGenMipmapCase &other);
894*35238bceSAndroid Build Coastguard Worker 
895*35238bceSAndroid Build Coastguard Worker     glu::RenderContext &m_renderCtx;
896*35238bceSAndroid Build Coastguard Worker 
897*35238bceSAndroid Build Coastguard Worker     uint32_t m_format;
898*35238bceSAndroid Build Coastguard Worker     uint32_t m_dataType;
899*35238bceSAndroid Build Coastguard Worker     uint32_t m_hint;
900*35238bceSAndroid Build Coastguard Worker     int m_size;
901*35238bceSAndroid Build Coastguard Worker 
902*35238bceSAndroid Build Coastguard Worker     glu::TextureCube *m_texture;
903*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
904*35238bceSAndroid Build Coastguard Worker };
905*35238bceSAndroid Build Coastguard Worker 
TextureCubeGenMipmapCase(tcu::TestContext & testCtx,glu::RenderContext & renderCtx,const char * name,const char * desc,uint32_t format,uint32_t dataType,uint32_t hint,int size)906*35238bceSAndroid Build Coastguard Worker TextureCubeGenMipmapCase::TextureCubeGenMipmapCase(tcu::TestContext &testCtx, glu::RenderContext &renderCtx,
907*35238bceSAndroid Build Coastguard Worker                                                    const char *name, const char *desc, uint32_t format,
908*35238bceSAndroid Build Coastguard Worker                                                    uint32_t dataType, uint32_t hint, int size)
909*35238bceSAndroid Build Coastguard Worker     : TestCase(testCtx, name, desc)
910*35238bceSAndroid Build Coastguard Worker     , m_renderCtx(renderCtx)
911*35238bceSAndroid Build Coastguard Worker     , m_format(format)
912*35238bceSAndroid Build Coastguard Worker     , m_dataType(dataType)
913*35238bceSAndroid Build Coastguard Worker     , m_hint(hint)
914*35238bceSAndroid Build Coastguard Worker     , m_size(size)
915*35238bceSAndroid Build Coastguard Worker     , m_texture(DE_NULL)
916*35238bceSAndroid Build Coastguard Worker     , m_renderer(renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP)
917*35238bceSAndroid Build Coastguard Worker {
918*35238bceSAndroid Build Coastguard Worker }
919*35238bceSAndroid Build Coastguard Worker 
~TextureCubeGenMipmapCase(void)920*35238bceSAndroid Build Coastguard Worker TextureCubeGenMipmapCase::~TextureCubeGenMipmapCase(void)
921*35238bceSAndroid Build Coastguard Worker {
922*35238bceSAndroid Build Coastguard Worker     deinit();
923*35238bceSAndroid Build Coastguard Worker }
924*35238bceSAndroid Build Coastguard Worker 
init(void)925*35238bceSAndroid Build Coastguard Worker void TextureCubeGenMipmapCase::init(void)
926*35238bceSAndroid Build Coastguard Worker {
927*35238bceSAndroid Build Coastguard Worker     if (m_renderCtx.getRenderTarget().getWidth() < 3 * m_size || m_renderCtx.getRenderTarget().getHeight() < 2 * m_size)
928*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Render target size must be at least (" + de::toString(3 * m_size) + ", " +
929*35238bceSAndroid Build Coastguard Worker                                      de::toString(2 * m_size) + ")");
930*35238bceSAndroid Build Coastguard Worker 
931*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_texture);
932*35238bceSAndroid Build Coastguard Worker     m_texture = new TextureCube(m_renderCtx, m_format, m_dataType, m_size);
933*35238bceSAndroid Build Coastguard Worker }
934*35238bceSAndroid Build Coastguard Worker 
deinit(void)935*35238bceSAndroid Build Coastguard Worker void TextureCubeGenMipmapCase::deinit(void)
936*35238bceSAndroid Build Coastguard Worker {
937*35238bceSAndroid Build Coastguard Worker     delete m_texture;
938*35238bceSAndroid Build Coastguard Worker     m_texture = DE_NULL;
939*35238bceSAndroid Build Coastguard Worker 
940*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
941*35238bceSAndroid Build Coastguard Worker }
942*35238bceSAndroid Build Coastguard Worker 
iterate(void)943*35238bceSAndroid Build Coastguard Worker TextureCubeGenMipmapCase::IterateResult TextureCubeGenMipmapCase::iterate(void)
944*35238bceSAndroid Build Coastguard Worker {
945*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl = m_renderCtx.getFunctions();
946*35238bceSAndroid Build Coastguard Worker 
947*35238bceSAndroid Build Coastguard Worker     const uint32_t minFilter = GL_NEAREST_MIPMAP_NEAREST;
948*35238bceSAndroid Build Coastguard Worker     const uint32_t magFilter = GL_NEAREST;
949*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapS     = GL_CLAMP_TO_EDGE;
950*35238bceSAndroid Build Coastguard Worker     const uint32_t wrapT     = GL_CLAMP_TO_EDGE;
951*35238bceSAndroid Build Coastguard Worker 
952*35238bceSAndroid Build Coastguard Worker     tcu::TextureCube resultTexture(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
953*35238bceSAndroid Build Coastguard Worker                                    m_size);
954*35238bceSAndroid Build Coastguard Worker 
955*35238bceSAndroid Build Coastguard Worker     const int numLevels = deLog2Floor32(m_size) + 1;
956*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
957*35238bceSAndroid Build Coastguard Worker 
958*35238bceSAndroid Build Coastguard Worker     // Initialize texture level 0 with colored grid.
959*35238bceSAndroid Build Coastguard Worker     for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
960*35238bceSAndroid Build Coastguard Worker     {
961*35238bceSAndroid Build Coastguard Worker         Vec4 ca, cb; // Grid colors.
962*35238bceSAndroid Build Coastguard Worker 
963*35238bceSAndroid Build Coastguard Worker         switch (face)
964*35238bceSAndroid Build Coastguard Worker         {
965*35238bceSAndroid Build Coastguard Worker         case 0:
966*35238bceSAndroid Build Coastguard Worker             ca = Vec4(1.0f, 0.3f, 0.0f, 0.7f);
967*35238bceSAndroid Build Coastguard Worker             cb = Vec4(0.0f, 0.0f, 1.0f, 1.0f);
968*35238bceSAndroid Build Coastguard Worker             break;
969*35238bceSAndroid Build Coastguard Worker         case 1:
970*35238bceSAndroid Build Coastguard Worker             ca = Vec4(0.0f, 1.0f, 0.5f, 0.5f);
971*35238bceSAndroid Build Coastguard Worker             cb = Vec4(1.0f, 0.0f, 0.0f, 1.0f);
972*35238bceSAndroid Build Coastguard Worker             break;
973*35238bceSAndroid Build Coastguard Worker         case 2:
974*35238bceSAndroid Build Coastguard Worker             ca = Vec4(0.7f, 0.0f, 1.0f, 0.3f);
975*35238bceSAndroid Build Coastguard Worker             cb = Vec4(0.0f, 1.0f, 0.0f, 1.0f);
976*35238bceSAndroid Build Coastguard Worker             break;
977*35238bceSAndroid Build Coastguard Worker         case 3:
978*35238bceSAndroid Build Coastguard Worker             ca = Vec4(0.0f, 0.3f, 1.0f, 1.0f);
979*35238bceSAndroid Build Coastguard Worker             cb = Vec4(1.0f, 0.0f, 0.0f, 0.7f);
980*35238bceSAndroid Build Coastguard Worker             break;
981*35238bceSAndroid Build Coastguard Worker         case 4:
982*35238bceSAndroid Build Coastguard Worker             ca = Vec4(1.0f, 0.0f, 0.5f, 1.0f);
983*35238bceSAndroid Build Coastguard Worker             cb = Vec4(0.0f, 1.0f, 0.0f, 0.5f);
984*35238bceSAndroid Build Coastguard Worker             break;
985*35238bceSAndroid Build Coastguard Worker         case 5:
986*35238bceSAndroid Build Coastguard Worker             ca = Vec4(0.7f, 1.0f, 0.0f, 1.0f);
987*35238bceSAndroid Build Coastguard Worker             cb = Vec4(0.0f, 0.0f, 1.0f, 0.3f);
988*35238bceSAndroid Build Coastguard Worker             break;
989*35238bceSAndroid Build Coastguard Worker         }
990*35238bceSAndroid Build Coastguard Worker 
991*35238bceSAndroid Build Coastguard Worker         m_texture->getRefTexture().allocLevel((tcu::CubeFace)face, 0);
992*35238bceSAndroid Build Coastguard Worker         fillWithGrid(m_texture->getRefTexture().getLevelFace(0, (tcu::CubeFace)face), 8, ca, cb);
993*35238bceSAndroid Build Coastguard Worker     }
994*35238bceSAndroid Build Coastguard Worker 
995*35238bceSAndroid Build Coastguard Worker     // Upload data and setup params.
996*35238bceSAndroid Build Coastguard Worker     m_texture->upload();
997*35238bceSAndroid Build Coastguard Worker 
998*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture());
999*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrapS);
1000*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrapT);
1001*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minFilter);
1002*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, magFilter);
1003*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "After texture setup");
1004*35238bceSAndroid Build Coastguard Worker 
1005*35238bceSAndroid Build Coastguard Worker     // Generate mipmap.
1006*35238bceSAndroid Build Coastguard Worker     gl.hint(GL_GENERATE_MIPMAP_HINT, m_hint);
1007*35238bceSAndroid Build Coastguard Worker     gl.generateMipmap(GL_TEXTURE_CUBE_MAP);
1008*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "glGenerateMipmap()");
1009*35238bceSAndroid Build Coastguard Worker 
1010*35238bceSAndroid Build Coastguard Worker     // Render all levels.
1011*35238bceSAndroid Build Coastguard Worker     for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
1012*35238bceSAndroid Build Coastguard Worker     {
1013*35238bceSAndroid Build Coastguard Worker         const int levelWidth  = de::max(1, m_size >> levelNdx);
1014*35238bceSAndroid Build Coastguard Worker         const int levelHeight = de::max(1, m_size >> levelNdx);
1015*35238bceSAndroid Build Coastguard Worker 
1016*35238bceSAndroid Build Coastguard Worker         for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
1017*35238bceSAndroid Build Coastguard Worker         {
1018*35238bceSAndroid Build Coastguard Worker             const RandomViewport viewport(m_renderCtx.getRenderTarget(), levelWidth * 3, levelHeight * 2,
1019*35238bceSAndroid Build Coastguard Worker                                           deStringHash(getName()) ^ deInt32Hash(levelNdx + faceNdx));
1020*35238bceSAndroid Build Coastguard Worker             const tcu::CubeFace face = tcu::CubeFace(faceNdx);
1021*35238bceSAndroid Build Coastguard Worker 
1022*35238bceSAndroid Build Coastguard Worker             computeQuadTexCoordCube(texCoord, face);
1023*35238bceSAndroid Build Coastguard Worker 
1024*35238bceSAndroid Build Coastguard Worker             gl.viewport(viewport.x, viewport.y, levelWidth, levelHeight);
1025*35238bceSAndroid Build Coastguard Worker             m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_CUBE);
1026*35238bceSAndroid Build Coastguard Worker 
1027*35238bceSAndroid Build Coastguard Worker             resultTexture.allocLevel(face, levelNdx);
1028*35238bceSAndroid Build Coastguard Worker             glu::readPixels(m_renderCtx, viewport.x, viewport.y, resultTexture.getLevelFace(levelNdx, face));
1029*35238bceSAndroid Build Coastguard Worker         }
1030*35238bceSAndroid Build Coastguard Worker     }
1031*35238bceSAndroid Build Coastguard Worker 
1032*35238bceSAndroid Build Coastguard Worker     // Compare results
1033*35238bceSAndroid Build Coastguard Worker     {
1034*35238bceSAndroid Build Coastguard Worker         const IVec4 framebufferBits = max(getBitsVec(m_renderCtx.getRenderTarget().getPixelFormat()) - 2, IVec4(0));
1035*35238bceSAndroid Build Coastguard Worker         const IVec4 formatBits      = tcu::getTextureFormatBitDepth(glu::mapGLTransferFormat(m_format, m_dataType));
1036*35238bceSAndroid Build Coastguard Worker         const tcu::BVec4 formatMask = greaterThan(formatBits, IVec4(0));
1037*35238bceSAndroid Build Coastguard Worker         const IVec4 cmpBits         = select(min(framebufferBits, formatBits), framebufferBits, formatMask);
1038*35238bceSAndroid Build Coastguard Worker         GenMipmapPrecision comparePrec;
1039*35238bceSAndroid Build Coastguard Worker 
1040*35238bceSAndroid Build Coastguard Worker         comparePrec.colorMask      = getCompareMask(m_renderCtx.getRenderTarget().getPixelFormat());
1041*35238bceSAndroid Build Coastguard Worker         comparePrec.colorThreshold = tcu::computeFixedPointThreshold(cmpBits);
1042*35238bceSAndroid Build Coastguard Worker         comparePrec.filterBits     = tcu::IVec3(4, 4, 0);
1043*35238bceSAndroid Build Coastguard Worker 
1044*35238bceSAndroid Build Coastguard Worker         const qpTestResult compareResult =
1045*35238bceSAndroid Build Coastguard Worker             compareGenMipmapResult(m_testCtx.getLog(), resultTexture, m_texture->getRefTexture(), comparePrec);
1046*35238bceSAndroid Build Coastguard Worker 
1047*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(compareResult, compareResult == QP_TEST_RESULT_PASS ? "Pass" :
1048*35238bceSAndroid Build Coastguard Worker                                                compareResult == QP_TEST_RESULT_QUALITY_WARNING ?
1049*35238bceSAndroid Build Coastguard Worker                                                                                       "Low-quality method used" :
1050*35238bceSAndroid Build Coastguard Worker                                                compareResult == QP_TEST_RESULT_FAIL ? "Image comparison failed" :
1051*35238bceSAndroid Build Coastguard Worker                                                                                       "");
1052*35238bceSAndroid Build Coastguard Worker     }
1053*35238bceSAndroid Build Coastguard Worker 
1054*35238bceSAndroid Build Coastguard Worker     return STOP;
1055*35238bceSAndroid Build Coastguard Worker }
1056*35238bceSAndroid Build Coastguard Worker 
TextureMipmapTests(Context & context)1057*35238bceSAndroid Build Coastguard Worker TextureMipmapTests::TextureMipmapTests(Context &context) : TestCaseGroup(context, "mipmap", "Mipmapping tests")
1058*35238bceSAndroid Build Coastguard Worker {
1059*35238bceSAndroid Build Coastguard Worker }
1060*35238bceSAndroid Build Coastguard Worker 
~TextureMipmapTests(void)1061*35238bceSAndroid Build Coastguard Worker TextureMipmapTests::~TextureMipmapTests(void)
1062*35238bceSAndroid Build Coastguard Worker {
1063*35238bceSAndroid Build Coastguard Worker }
1064*35238bceSAndroid Build Coastguard Worker 
init(void)1065*35238bceSAndroid Build Coastguard Worker void TextureMipmapTests::init(void)
1066*35238bceSAndroid Build Coastguard Worker {
1067*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *group2D   = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Mipmapping");
1068*35238bceSAndroid Build Coastguard Worker     tcu::TestCaseGroup *groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cube Map Filtering");
1069*35238bceSAndroid Build Coastguard Worker     addChild(group2D);
1070*35238bceSAndroid Build Coastguard Worker     addChild(groupCube);
1071*35238bceSAndroid Build Coastguard Worker 
1072*35238bceSAndroid Build Coastguard Worker     static const struct
1073*35238bceSAndroid Build Coastguard Worker     {
1074*35238bceSAndroid Build Coastguard Worker         const char *name;
1075*35238bceSAndroid Build Coastguard Worker         uint32_t mode;
1076*35238bceSAndroid Build Coastguard Worker     } wrapModes[] = {{"clamp", GL_CLAMP_TO_EDGE}, {"repeat", GL_REPEAT}, {"mirror", GL_MIRRORED_REPEAT}};
1077*35238bceSAndroid Build Coastguard Worker 
1078*35238bceSAndroid Build Coastguard Worker     static const struct
1079*35238bceSAndroid Build Coastguard Worker     {
1080*35238bceSAndroid Build Coastguard Worker         const char *name;
1081*35238bceSAndroid Build Coastguard Worker         uint32_t mode;
1082*35238bceSAndroid Build Coastguard Worker     } minFilterModes[] = {{"nearest_nearest", GL_NEAREST_MIPMAP_NEAREST},
1083*35238bceSAndroid Build Coastguard Worker                           {"linear_nearest", GL_LINEAR_MIPMAP_NEAREST},
1084*35238bceSAndroid Build Coastguard Worker                           {"nearest_linear", GL_NEAREST_MIPMAP_LINEAR},
1085*35238bceSAndroid Build Coastguard Worker                           {"linear_linear", GL_LINEAR_MIPMAP_LINEAR}};
1086*35238bceSAndroid Build Coastguard Worker 
1087*35238bceSAndroid Build Coastguard Worker     static const struct
1088*35238bceSAndroid Build Coastguard Worker     {
1089*35238bceSAndroid Build Coastguard Worker         CoordType type;
1090*35238bceSAndroid Build Coastguard Worker         const char *name;
1091*35238bceSAndroid Build Coastguard Worker         const char *desc;
1092*35238bceSAndroid Build Coastguard Worker     } coordTypes[] = {{COORDTYPE_BASIC, "basic", "Mipmapping with translated and scaled coordinates"},
1093*35238bceSAndroid Build Coastguard Worker                       {COORDTYPE_AFFINE, "affine", "Mipmapping with affine coordinate transform"},
1094*35238bceSAndroid Build Coastguard Worker                       {COORDTYPE_PROJECTED, "projected", "Mipmapping with perspective projection"}};
1095*35238bceSAndroid Build Coastguard Worker 
1096*35238bceSAndroid Build Coastguard Worker     static const struct
1097*35238bceSAndroid Build Coastguard Worker     {
1098*35238bceSAndroid Build Coastguard Worker         const char *name;
1099*35238bceSAndroid Build Coastguard Worker         uint32_t format;
1100*35238bceSAndroid Build Coastguard Worker         uint32_t dataType;
1101*35238bceSAndroid Build Coastguard Worker     } formats[] = {{"a8", GL_ALPHA, GL_UNSIGNED_BYTE},
1102*35238bceSAndroid Build Coastguard Worker                    {"l8", GL_LUMINANCE, GL_UNSIGNED_BYTE},
1103*35238bceSAndroid Build Coastguard Worker                    {"la88", GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE},
1104*35238bceSAndroid Build Coastguard Worker                    {"rgb565", GL_RGB, GL_UNSIGNED_SHORT_5_6_5},
1105*35238bceSAndroid Build Coastguard Worker                    {"rgb888", GL_RGB, GL_UNSIGNED_BYTE},
1106*35238bceSAndroid Build Coastguard Worker                    {"rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4},
1107*35238bceSAndroid Build Coastguard Worker                    {"rgba5551", GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1},
1108*35238bceSAndroid Build Coastguard Worker                    {"rgba8888", GL_RGBA, GL_UNSIGNED_BYTE}};
1109*35238bceSAndroid Build Coastguard Worker 
1110*35238bceSAndroid Build Coastguard Worker     static const struct
1111*35238bceSAndroid Build Coastguard Worker     {
1112*35238bceSAndroid Build Coastguard Worker         const char *name;
1113*35238bceSAndroid Build Coastguard Worker         uint32_t hint;
1114*35238bceSAndroid Build Coastguard Worker     } genHints[] = {{"fastest", GL_FASTEST}, {"nicest", GL_NICEST}};
1115*35238bceSAndroid Build Coastguard Worker 
1116*35238bceSAndroid Build Coastguard Worker     static const struct
1117*35238bceSAndroid Build Coastguard Worker     {
1118*35238bceSAndroid Build Coastguard Worker         const char *name;
1119*35238bceSAndroid Build Coastguard Worker         int width;
1120*35238bceSAndroid Build Coastguard Worker         int height;
1121*35238bceSAndroid Build Coastguard Worker     } tex2DSizes[] = {{DE_NULL, 64, 64}, // Default.
1122*35238bceSAndroid Build Coastguard Worker                       {"non_square", 32, 64}};
1123*35238bceSAndroid Build Coastguard Worker 
1124*35238bceSAndroid Build Coastguard Worker     // 2D cases.
1125*35238bceSAndroid Build Coastguard Worker     for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(coordTypes); coordType++)
1126*35238bceSAndroid Build Coastguard Worker     {
1127*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *coordTypeGroup =
1128*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, coordTypes[coordType].name, coordTypes[coordType].desc);
1129*35238bceSAndroid Build Coastguard Worker         group2D->addChild(coordTypeGroup);
1130*35238bceSAndroid Build Coastguard Worker 
1131*35238bceSAndroid Build Coastguard Worker         for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
1132*35238bceSAndroid Build Coastguard Worker         {
1133*35238bceSAndroid Build Coastguard Worker             for (int wrapMode = 0; wrapMode < DE_LENGTH_OF_ARRAY(wrapModes); wrapMode++)
1134*35238bceSAndroid Build Coastguard Worker             {
1135*35238bceSAndroid Build Coastguard Worker                 // Add non_square variants to basic cases only.
1136*35238bceSAndroid Build Coastguard Worker                 int sizeEnd = coordTypes[coordType].type == COORDTYPE_BASIC ? DE_LENGTH_OF_ARRAY(tex2DSizes) : 1;
1137*35238bceSAndroid Build Coastguard Worker 
1138*35238bceSAndroid Build Coastguard Worker                 for (int size = 0; size < sizeEnd; size++)
1139*35238bceSAndroid Build Coastguard Worker                 {
1140*35238bceSAndroid Build Coastguard Worker                     std::ostringstream name;
1141*35238bceSAndroid Build Coastguard Worker                     name << minFilterModes[minFilter].name << "_" << wrapModes[wrapMode].name;
1142*35238bceSAndroid Build Coastguard Worker 
1143*35238bceSAndroid Build Coastguard Worker                     if (tex2DSizes[size].name)
1144*35238bceSAndroid Build Coastguard Worker                         name << "_" << tex2DSizes[size].name;
1145*35238bceSAndroid Build Coastguard Worker 
1146*35238bceSAndroid Build Coastguard Worker                     coordTypeGroup->addChild(new Texture2DMipmapCase(
1147*35238bceSAndroid Build Coastguard Worker                         m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), name.str().c_str(), "",
1148*35238bceSAndroid Build Coastguard Worker                         coordTypes[coordType].type, minFilterModes[minFilter].mode, wrapModes[wrapMode].mode,
1149*35238bceSAndroid Build Coastguard Worker                         wrapModes[wrapMode].mode, GL_RGBA, GL_UNSIGNED_BYTE, tex2DSizes[size].width,
1150*35238bceSAndroid Build Coastguard Worker                         tex2DSizes[size].height));
1151*35238bceSAndroid Build Coastguard Worker                 }
1152*35238bceSAndroid Build Coastguard Worker             }
1153*35238bceSAndroid Build Coastguard Worker         }
1154*35238bceSAndroid Build Coastguard Worker     }
1155*35238bceSAndroid Build Coastguard Worker 
1156*35238bceSAndroid Build Coastguard Worker     // 2D bias variants.
1157*35238bceSAndroid Build Coastguard Worker     {
1158*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *biasGroup = new tcu::TestCaseGroup(m_testCtx, "bias", "User-supplied bias value");
1159*35238bceSAndroid Build Coastguard Worker         group2D->addChild(biasGroup);
1160*35238bceSAndroid Build Coastguard Worker 
1161*35238bceSAndroid Build Coastguard Worker         for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
1162*35238bceSAndroid Build Coastguard Worker             biasGroup->addChild(new Texture2DMipmapCase(
1163*35238bceSAndroid Build Coastguard Worker                 m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), minFilterModes[minFilter].name, "",
1164*35238bceSAndroid Build Coastguard Worker                 COORDTYPE_BASIC_BIAS, minFilterModes[minFilter].mode, GL_REPEAT, GL_REPEAT, GL_RGBA, GL_UNSIGNED_BYTE,
1165*35238bceSAndroid Build Coastguard Worker                 tex2DSizes[0].width, tex2DSizes[0].height));
1166*35238bceSAndroid Build Coastguard Worker     }
1167*35238bceSAndroid Build Coastguard Worker 
1168*35238bceSAndroid Build Coastguard Worker     // 2D mipmap generation variants.
1169*35238bceSAndroid Build Coastguard Worker     {
1170*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *genMipmapGroup = new tcu::TestCaseGroup(m_testCtx, "generate", "Mipmap generation tests");
1171*35238bceSAndroid Build Coastguard Worker         group2D->addChild(genMipmapGroup);
1172*35238bceSAndroid Build Coastguard Worker 
1173*35238bceSAndroid Build Coastguard Worker         for (int format = 0; format < DE_LENGTH_OF_ARRAY(formats); format++)
1174*35238bceSAndroid Build Coastguard Worker         {
1175*35238bceSAndroid Build Coastguard Worker             for (int size = 0; size < DE_LENGTH_OF_ARRAY(tex2DSizes); size++)
1176*35238bceSAndroid Build Coastguard Worker             {
1177*35238bceSAndroid Build Coastguard Worker                 for (int hint = 0; hint < DE_LENGTH_OF_ARRAY(genHints); hint++)
1178*35238bceSAndroid Build Coastguard Worker                 {
1179*35238bceSAndroid Build Coastguard Worker                     std::ostringstream name;
1180*35238bceSAndroid Build Coastguard Worker                     name << formats[format].name;
1181*35238bceSAndroid Build Coastguard Worker 
1182*35238bceSAndroid Build Coastguard Worker                     if (tex2DSizes[size].name)
1183*35238bceSAndroid Build Coastguard Worker                         name << "_" << tex2DSizes[size].name;
1184*35238bceSAndroid Build Coastguard Worker 
1185*35238bceSAndroid Build Coastguard Worker                     name << "_" << genHints[hint].name;
1186*35238bceSAndroid Build Coastguard Worker 
1187*35238bceSAndroid Build Coastguard Worker                     genMipmapGroup->addChild(new Texture2DGenMipmapCase(
1188*35238bceSAndroid Build Coastguard Worker                         m_testCtx, m_context.getRenderContext(), name.str().c_str(), "", formats[format].format,
1189*35238bceSAndroid Build Coastguard Worker                         formats[format].dataType, genHints[hint].hint, tex2DSizes[size].width,
1190*35238bceSAndroid Build Coastguard Worker                         tex2DSizes[size].height));
1191*35238bceSAndroid Build Coastguard Worker                 }
1192*35238bceSAndroid Build Coastguard Worker             }
1193*35238bceSAndroid Build Coastguard Worker         }
1194*35238bceSAndroid Build Coastguard Worker     }
1195*35238bceSAndroid Build Coastguard Worker 
1196*35238bceSAndroid Build Coastguard Worker     const int cubeMapSize = 64;
1197*35238bceSAndroid Build Coastguard Worker 
1198*35238bceSAndroid Build Coastguard Worker     static const struct
1199*35238bceSAndroid Build Coastguard Worker     {
1200*35238bceSAndroid Build Coastguard Worker         CoordType type;
1201*35238bceSAndroid Build Coastguard Worker         const char *name;
1202*35238bceSAndroid Build Coastguard Worker         const char *desc;
1203*35238bceSAndroid Build Coastguard Worker     } cubeCoordTypes[] = {{COORDTYPE_BASIC, "basic", "Mipmapping with translated and scaled coordinates"},
1204*35238bceSAndroid Build Coastguard Worker                           {COORDTYPE_PROJECTED, "projected", "Mipmapping with perspective projection"},
1205*35238bceSAndroid Build Coastguard Worker                           {COORDTYPE_BASIC_BIAS, "bias", "User-supplied bias value"}};
1206*35238bceSAndroid Build Coastguard Worker 
1207*35238bceSAndroid Build Coastguard Worker     // Cubemap cases.
1208*35238bceSAndroid Build Coastguard Worker     for (int coordType = 0; coordType < DE_LENGTH_OF_ARRAY(cubeCoordTypes); coordType++)
1209*35238bceSAndroid Build Coastguard Worker     {
1210*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *coordTypeGroup =
1211*35238bceSAndroid Build Coastguard Worker             new tcu::TestCaseGroup(m_testCtx, cubeCoordTypes[coordType].name, cubeCoordTypes[coordType].desc);
1212*35238bceSAndroid Build Coastguard Worker         groupCube->addChild(coordTypeGroup);
1213*35238bceSAndroid Build Coastguard Worker 
1214*35238bceSAndroid Build Coastguard Worker         for (int minFilter = 0; minFilter < DE_LENGTH_OF_ARRAY(minFilterModes); minFilter++)
1215*35238bceSAndroid Build Coastguard Worker         {
1216*35238bceSAndroid Build Coastguard Worker             coordTypeGroup->addChild(new TextureCubeMipmapCase(
1217*35238bceSAndroid Build Coastguard Worker                 m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), minFilterModes[minFilter].name, "",
1218*35238bceSAndroid Build Coastguard Worker                 cubeCoordTypes[coordType].type, minFilterModes[minFilter].mode, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE,
1219*35238bceSAndroid Build Coastguard Worker                 GL_RGBA, GL_UNSIGNED_BYTE, cubeMapSize));
1220*35238bceSAndroid Build Coastguard Worker         }
1221*35238bceSAndroid Build Coastguard Worker     }
1222*35238bceSAndroid Build Coastguard Worker 
1223*35238bceSAndroid Build Coastguard Worker     // Cubemap mipmap generation variants.
1224*35238bceSAndroid Build Coastguard Worker     {
1225*35238bceSAndroid Build Coastguard Worker         tcu::TestCaseGroup *genMipmapGroup = new tcu::TestCaseGroup(m_testCtx, "generate", "Mipmap generation tests");
1226*35238bceSAndroid Build Coastguard Worker         groupCube->addChild(genMipmapGroup);
1227*35238bceSAndroid Build Coastguard Worker 
1228*35238bceSAndroid Build Coastguard Worker         for (int format = 0; format < DE_LENGTH_OF_ARRAY(formats); format++)
1229*35238bceSAndroid Build Coastguard Worker         {
1230*35238bceSAndroid Build Coastguard Worker             for (int hint = 0; hint < DE_LENGTH_OF_ARRAY(genHints); hint++)
1231*35238bceSAndroid Build Coastguard Worker             {
1232*35238bceSAndroid Build Coastguard Worker                 std::ostringstream name;
1233*35238bceSAndroid Build Coastguard Worker                 name << formats[format].name << "_" << genHints[hint].name;
1234*35238bceSAndroid Build Coastguard Worker 
1235*35238bceSAndroid Build Coastguard Worker                 genMipmapGroup->addChild(new TextureCubeGenMipmapCase(
1236*35238bceSAndroid Build Coastguard Worker                     m_testCtx, m_context.getRenderContext(), name.str().c_str(), "", formats[format].format,
1237*35238bceSAndroid Build Coastguard Worker                     formats[format].dataType, genHints[hint].hint, cubeMapSize));
1238*35238bceSAndroid Build Coastguard Worker             }
1239*35238bceSAndroid Build Coastguard Worker         }
1240*35238bceSAndroid Build Coastguard Worker     }
1241*35238bceSAndroid Build Coastguard Worker }
1242*35238bceSAndroid Build Coastguard Worker 
1243*35238bceSAndroid Build Coastguard Worker } // namespace Functional
1244*35238bceSAndroid Build Coastguard Worker } // namespace gles2
1245*35238bceSAndroid Build Coastguard Worker } // namespace deqp
1246