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