1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Texture filtering tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es31fTextureFilteringTests.hpp"
26 #include "glsTextureTestUtil.hpp"
28 #include "gluPixelTransfer.hpp"
29 #include "gluTexture.hpp"
30 #include "gluTextureUtil.hpp"
32 #include "tcuCommandLine.hpp"
33 #include "tcuTextureUtil.hpp"
34 #include "tcuImageCompare.hpp"
35 #include "tcuTexLookupVerifier.hpp"
36 #include "tcuVectorUtil.hpp"
38 #include "deStringUtil.hpp"
41 #include "glwFunctions.hpp"
42 #include "glwEnums.hpp"
54 using namespace gls::TextureTestUtil;
55 using namespace glu::TextureTestUtil;
57 static const char* getFaceDesc (const tcu::CubeFace face)
61 case tcu::CUBEFACE_NEGATIVE_X: return "-X";
62 case tcu::CUBEFACE_POSITIVE_X: return "+X";
63 case tcu::CUBEFACE_NEGATIVE_Y: return "-Y";
64 case tcu::CUBEFACE_POSITIVE_Y: return "+Y";
65 case tcu::CUBEFACE_NEGATIVE_Z: return "-Z";
66 case tcu::CUBEFACE_POSITIVE_Z: return "+Z";
73 static void logCubeArrayTexCoords(TestLog& log, vector<float>& texCoord)
75 const size_t numVerts = texCoord.size() / 4;
77 DE_ASSERT(texCoord.size() % 4 == 0);
79 for (size_t vertNdx = 0; vertNdx < numVerts; vertNdx++)
81 const size_t coordNdx = vertNdx * 4;
83 const float u = texCoord[coordNdx + 0];
84 const float v = texCoord[coordNdx + 1];
85 const float w = texCoord[coordNdx + 2];
86 const float q = texCoord[coordNdx + 3];
88 log << TestLog::Message
94 << TestLog::EndMessage;
98 // Cube map array filtering
100 class TextureCubeArrayFilteringCase : public TestCase
103 TextureCubeArrayFilteringCase (Context& context,
110 deUint32 internalFormat,
113 bool onlySampleFaceInterior = false);
115 ~TextureCubeArrayFilteringCase (void);
119 IterateResult iterate (void);
122 TextureCubeArrayFilteringCase (const TextureCubeArrayFilteringCase&);
123 TextureCubeArrayFilteringCase& operator= (const TextureCubeArrayFilteringCase&);
125 const deUint32 m_minFilter;
126 const deUint32 m_magFilter;
127 const deUint32 m_wrapS;
128 const deUint32 m_wrapT;
130 const deUint32 m_internalFormat;
134 const bool m_onlySampleFaceInterior; //!< If true, we avoid sampling anywhere near a face's edges.
138 const glu::TextureCubeArray* texture;
139 tcu::Vec2 bottomLeft;
141 tcu::Vec2 layerRange;
148 FilterCase (const glu::TextureCubeArray* tex_, const tcu::Vec2& bottomLeft_, const tcu::Vec2& topRight_, const tcu::Vec2& layerRange_)
150 , bottomLeft (bottomLeft_)
151 , topRight (topRight_)
152 , layerRange (layerRange_)
157 glu::TextureCubeArray* m_gradientTex;
158 glu::TextureCubeArray* m_gridTex;
160 TextureRenderer m_renderer;
162 std::vector<FilterCase> m_cases;
166 TextureCubeArrayFilteringCase::TextureCubeArrayFilteringCase (Context& context,
173 deUint32 internalFormat,
176 bool onlySampleFaceInterior)
177 : TestCase (context, name, desc)
178 , m_minFilter (minFilter)
179 , m_magFilter (magFilter)
182 , m_internalFormat (internalFormat)
185 , m_onlySampleFaceInterior (onlySampleFaceInterior)
186 , m_gradientTex (DE_NULL)
187 , m_gridTex (DE_NULL)
188 , m_renderer (context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_310_ES, glu::PRECISION_HIGHP)
193 TextureCubeArrayFilteringCase::~TextureCubeArrayFilteringCase (void)
195 TextureCubeArrayFilteringCase::deinit();
198 void TextureCubeArrayFilteringCase::init (void)
200 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_cube_map_array"))
201 throw tcu::NotSupportedError("GL_EXT_texture_cube_map_array not supported");
205 const tcu::TextureFormat texFmt = glu::mapGLInternalFormat(m_internalFormat);
206 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
207 const tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
208 const tcu::Vec4 cBias = fmtInfo.valueMin;
209 const int numLevels = deLog2Floor32(m_size) + 1;
210 const int numLayers = m_depth / 6;
213 m_gradientTex = new glu::TextureCubeArray(m_context.getRenderContext(), m_internalFormat, m_size, m_depth);
214 m_gridTex = new glu::TextureCubeArray(m_context.getRenderContext(), m_internalFormat, m_size, m_depth);
216 const tcu::IVec4 levelSwz[] =
224 // Fill first gradient texture (gradient direction varies between layers).
225 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
227 m_gradientTex->getRefTexture().allocLevel(levelNdx);
229 const tcu::PixelBufferAccess levelBuf = m_gradientTex->getRefTexture().getLevel(levelNdx);
231 for (int layerFaceNdx = 0; layerFaceNdx < m_depth; layerFaceNdx++)
233 const tcu::IVec4 swz = levelSwz[layerFaceNdx % DE_LENGTH_OF_ARRAY(levelSwz)];
234 const tcu::Vec4 gMin = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f).swizzle(swz[0],swz[1],swz[2],swz[3])*cScale + cBias;
235 const tcu::Vec4 gMax = tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f).swizzle(swz[0],swz[1],swz[2],swz[3])*cScale + cBias;
237 tcu::fillWithComponentGradients(tcu::getSubregion(levelBuf, 0, 0, layerFaceNdx, levelBuf.getWidth(), levelBuf.getHeight(), 1), gMin, gMax);
241 // Fill second with grid texture (each layer has unique colors).
242 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
244 m_gridTex->getRefTexture().allocLevel(levelNdx);
246 const tcu::PixelBufferAccess levelBuf = m_gridTex->getRefTexture().getLevel(levelNdx);
248 for (int layerFaceNdx = 0; layerFaceNdx < m_depth; layerFaceNdx++)
250 const deUint32 step = 0x00ffffff / (numLevels*m_depth - 1);
251 const deUint32 rgb = step * (levelNdx + layerFaceNdx*numLevels);
252 const deUint32 colorA = 0xff000000 | rgb;
253 const deUint32 colorB = 0xff000000 | ~rgb;
255 tcu::fillWithGrid(tcu::getSubregion(levelBuf, 0, 0, layerFaceNdx, levelBuf.getWidth(), levelBuf.getHeight(), 1),
256 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
261 m_gradientTex->upload();
266 const glu::TextureCubeArray* const tex0 = m_gradientTex;
267 const glu::TextureCubeArray* const tex1 = m_gridTex;
269 if (m_onlySampleFaceInterior)
271 m_cases.push_back(FilterCase(tex0, tcu::Vec2(-0.8f, -0.8f), tcu::Vec2(0.8f, 0.8f), tcu::Vec2(-0.5f, float(numLayers)+0.5f))); // minification
272 m_cases.push_back(FilterCase(tex0, tcu::Vec2(0.5f, 0.65f), tcu::Vec2(0.8f, 0.8f), tcu::Vec2(-0.5f, float(numLayers)+0.5f))); // magnification
273 m_cases.push_back(FilterCase(tex1, tcu::Vec2(-0.8f, -0.8f), tcu::Vec2(0.8f, 0.8f), tcu::Vec2(float(numLayers)+0.5f, -0.5f))); // minification
274 m_cases.push_back(FilterCase(tex1, tcu::Vec2(0.2f, 0.2f), tcu::Vec2(0.6f, 0.5f), tcu::Vec2(float(numLayers)+0.5f, -0.5f))); // magnification
278 const bool isSingleSample = (m_context.getRenderTarget().getNumSamples() == 0);
280 // minification - w/ tweak to avoid hitting triangle edges with a face switchpoint in multisample configs
282 m_cases.push_back(FilterCase(tex0, tcu::Vec2(-1.25f, -1.2f), tcu::Vec2(1.2f, 1.25f), tcu::Vec2(-0.5f, float(numLayers)+0.5f)));
284 m_cases.push_back(FilterCase(tex0, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f), tcu::Vec2(-0.5f, float(numLayers)+0.5f)));
286 m_cases.push_back(FilterCase(tex0, tcu::Vec2(0.8f, 0.8f), tcu::Vec2(1.25f, 1.20f), tcu::Vec2(-0.5f, float(numLayers)+0.5f))); // magnification
287 m_cases.push_back(FilterCase(tex1, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f), tcu::Vec2(float(numLayers)+0.5f, -0.5f))); // minification
288 m_cases.push_back(FilterCase(tex1, tcu::Vec2(-1.2f, -1.1f), tcu::Vec2(-0.8f, -0.8f), tcu::Vec2(float(numLayers)+0.5f, -0.5f))); // magnification
290 // Layer rounding - only in single-sample configs as multisample configs may produce smooth transition at the middle.
291 if (isSingleSample && (numLayers > 1))
292 m_cases.push_back(FilterCase(tex0, tcu::Vec2(-2.0f, -1.5f ), tcu::Vec2(-0.1f, 0.9f), tcu::Vec2(1.50001f, 1.49999f)));
297 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
301 // Clean up to save memory.
302 TextureCubeArrayFilteringCase::deinit();
307 void TextureCubeArrayFilteringCase::deinit (void)
309 delete m_gradientTex;
312 m_gradientTex = DE_NULL;
319 TextureCubeArrayFilteringCase::IterateResult TextureCubeArrayFilteringCase::iterate (void)
321 TestLog& log = m_testCtx.getLog();
322 const glu::RenderContext& renderCtx = m_context.getRenderContext();
323 const glw::Functions& gl = renderCtx.getFunctions();
324 const int viewportSize = 28;
325 const deUint32 randomSeed = deStringHash(getName()) ^ deInt32Hash(m_caseNdx) ^ m_testCtx.getCommandLine().getBaseSeed();
326 const RandomViewport viewport (m_context.getRenderTarget(), viewportSize, viewportSize, randomSeed);
327 const FilterCase& curCase = m_cases[m_caseNdx];
328 const tcu::TextureFormat texFmt = curCase.texture->getRefTexture().getFormat();
329 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
330 const tcu::ScopedLogSection section (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
331 ReferenceParams refParams (TEXTURETYPE_CUBE_ARRAY);
333 if (viewport.width < viewportSize || viewport.height < viewportSize)
334 throw tcu::NotSupportedError("Render target too small", "", __FILE__, __LINE__);
336 // Params for reference computation.
337 refParams.sampler = glu::mapGLSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, m_minFilter, m_magFilter);
338 refParams.sampler.seamlessCubeMap = true;
339 refParams.samplerType = getSamplerType(texFmt);
340 refParams.colorBias = fmtInfo.lookupBias;
341 refParams.colorScale = fmtInfo.lookupScale;
342 refParams.lodMode = LODMODE_EXACT;
344 gl.bindTexture (GL_TEXTURE_CUBE_MAP_ARRAY, curCase.texture->getGLTexture());
345 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, m_minFilter);
346 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, m_magFilter);
347 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, m_wrapS);
348 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, m_wrapT);
350 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
352 m_testCtx.getLog() << TestLog::Message << "Coordinates: " << curCase.bottomLeft << " -> " << curCase.topRight << TestLog::EndMessage;
354 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
356 const tcu::CubeFace face = tcu::CubeFace(faceNdx);
357 tcu::Surface result (viewport.width, viewport.height);
358 vector<float> texCoord;
360 computeQuadTexCoordCubeArray(texCoord, face, curCase.bottomLeft, curCase.topRight, curCase.layerRange);
362 log << TestLog::Message << "Face " << getFaceDesc(face) << TestLog::EndMessage;
364 log << TestLog::Message << "Texture coordinates:" << TestLog::EndMessage;
366 logCubeArrayTexCoords(log, texCoord);
368 m_renderer.renderQuad(0, &texCoord[0], refParams);
369 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
371 glu::readPixels(renderCtx, viewport.x, viewport.y, result.getAccess());
372 GLU_EXPECT_NO_ERROR(gl.getError(), "Read pixels");
375 const bool isNearestOnly = m_minFilter == GL_NEAREST && m_magFilter == GL_NEAREST;
376 const tcu::PixelFormat pixelFormat = renderCtx.getRenderTarget().getPixelFormat();
377 const tcu::IVec4 coordBits = tcu::IVec4(10);
378 const tcu::IVec4 colorBits = max(getBitsVec(pixelFormat) - (isNearestOnly ? 1 : 2), tcu::IVec4(0)); // 1 inaccurate bit if nearest only, 2 otherwise
379 tcu::LodPrecision lodPrecision;
380 tcu::LookupPrecision lookupPrecision;
382 lodPrecision.derivateBits = 10;
383 lodPrecision.lodBits = 5;
384 lookupPrecision.colorThreshold = tcu::computeFixedPointThreshold(colorBits) / refParams.colorScale;
385 lookupPrecision.coordBits = coordBits.toWidth<3>();
386 lookupPrecision.uvwBits = tcu::IVec3(6);
387 lookupPrecision.colorMask = getCompareMask(pixelFormat);
389 const bool isHighQuality = verifyTextureResult(m_testCtx, result.getAccess(), curCase.texture->getRefTexture(),
390 &texCoord[0], refParams, lookupPrecision, coordBits, lodPrecision, pixelFormat);
394 // Evaluate against lower precision requirements.
395 lodPrecision.lodBits = 4;
396 lookupPrecision.uvwBits = tcu::IVec3(4);
398 m_testCtx.getLog() << TestLog::Message << "Warning: Verification against high precision requirements failed, trying with lower requirements." << TestLog::EndMessage;
400 const bool isOk = verifyTextureResult(m_testCtx, result.getAccess(), curCase.texture->getRefTexture(),
401 &texCoord[0], refParams, lookupPrecision, coordBits, lodPrecision, pixelFormat);
405 m_testCtx.getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
406 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
408 else if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
409 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Low-quality filtering result");
415 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
418 TextureFilteringTests::TextureFilteringTests (Context& context)
419 : TestCaseGroup(context, "filtering", "Texture Filtering Tests")
423 TextureFilteringTests::~TextureFilteringTests (void)
427 void TextureFilteringTests::init (void)
435 { "clamp", GL_CLAMP_TO_EDGE },
436 { "repeat", GL_REPEAT },
437 { "mirror", GL_MIRRORED_REPEAT }
446 { "nearest", GL_NEAREST },
447 { "linear", GL_LINEAR },
448 { "nearest_mipmap_nearest", GL_NEAREST_MIPMAP_NEAREST },
449 { "linear_mipmap_nearest", GL_LINEAR_MIPMAP_NEAREST },
450 { "nearest_mipmap_linear", GL_NEAREST_MIPMAP_LINEAR },
451 { "linear_mipmap_linear", GL_LINEAR_MIPMAP_LINEAR }
460 { "nearest", GL_NEAREST },
461 { "linear", GL_LINEAR }
481 } filterableFormatsByType[] =
483 { "rgba16f", GL_RGBA16F },
484 { "r11f_g11f_b10f", GL_R11F_G11F_B10F },
485 { "rgb9_e5", GL_RGB9_E5 },
486 { "rgba8", GL_RGBA8 },
487 { "rgba8_snorm", GL_RGBA8_SNORM },
488 { "rgb565", GL_RGB565 },
489 { "rgba4", GL_RGBA4 },
490 { "rgb5_a1", GL_RGB5_A1 },
491 { "srgb8_alpha8", GL_SRGB8_ALPHA8 },
492 { "rgb10_a2", GL_RGB10_A2 }
495 // Cube map array texture filtering.
497 tcu::TestCaseGroup* const groupCubeArray = new tcu::TestCaseGroup(m_testCtx, "cube_array", "Cube Map Array Texture Filtering");
498 addChild(groupCubeArray);
502 tcu::TestCaseGroup* const formatsGroup = new tcu::TestCaseGroup(m_testCtx, "formats", "Cube Map Array Texture Formats");
503 groupCubeArray->addChild(formatsGroup);
505 for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(filterableFormatsByType); fmtNdx++)
507 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(minFilterModes); filterNdx++)
509 const deUint32 minFilter = minFilterModes[filterNdx].mode;
510 const char* filterName = minFilterModes[filterNdx].name;
511 const deUint32 format = filterableFormatsByType[fmtNdx].format;
512 const char* formatName = filterableFormatsByType[fmtNdx].name;
513 const bool isMipmap = minFilter != GL_NEAREST && minFilter != GL_LINEAR;
514 const deUint32 magFilter = isMipmap ? GL_LINEAR : minFilter;
515 const string name = string(formatName) + "_" + filterName;
516 const deUint32 wrapS = GL_REPEAT;
517 const deUint32 wrapT = GL_REPEAT;
519 const int depth = 12;
521 formatsGroup->addChild(new TextureCubeArrayFilteringCase(m_context,
523 minFilter, magFilter,
533 tcu::TestCaseGroup* const sizesGroup = new tcu::TestCaseGroup(m_testCtx, "sizes", "Texture Sizes");
534 groupCubeArray->addChild(sizesGroup);
536 for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizesCubeArray); sizeNdx++)
538 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(minFilterModes); filterNdx++)
540 const deUint32 minFilter = minFilterModes[filterNdx].mode;
541 const char* filterName = minFilterModes[filterNdx].name;
542 const deUint32 format = GL_RGBA8;
543 const bool isMipmap = minFilter != GL_NEAREST && minFilter != GL_LINEAR;
544 const deUint32 magFilter = isMipmap ? GL_LINEAR : minFilter;
545 const deUint32 wrapS = GL_REPEAT;
546 const deUint32 wrapT = GL_REPEAT;
547 const int size = sizesCubeArray[sizeNdx].size;
548 const int depth = sizesCubeArray[sizeNdx].depth;
549 const string name = de::toString(size) + "x" + de::toString(size) + "x" + de::toString(depth) + "_" + filterName;
551 sizesGroup->addChild(new TextureCubeArrayFilteringCase(m_context,
553 minFilter, magFilter,
563 tcu::TestCaseGroup* const combinationsGroup = new tcu::TestCaseGroup(m_testCtx, "combinations", "Filter and wrap mode combinations");
564 groupCubeArray->addChild(combinationsGroup);
566 for (int minFilterNdx = 0; minFilterNdx < DE_LENGTH_OF_ARRAY(minFilterModes); minFilterNdx++)
568 for (int magFilterNdx = 0; magFilterNdx < DE_LENGTH_OF_ARRAY(magFilterModes); magFilterNdx++)
570 for (int wrapSNdx = 0; wrapSNdx < DE_LENGTH_OF_ARRAY(wrapModes); wrapSNdx++)
572 for (int wrapTNdx = 0; wrapTNdx < DE_LENGTH_OF_ARRAY(wrapModes); wrapTNdx++)
574 const deUint32 minFilter = minFilterModes[minFilterNdx].mode;
575 const deUint32 magFilter = magFilterModes[magFilterNdx].mode;
576 const deUint32 format = GL_RGBA8;
577 const deUint32 wrapS = wrapModes[wrapSNdx].mode;
578 const deUint32 wrapT = wrapModes[wrapTNdx].mode;
580 const int depth = 12;
581 const string name = string(minFilterModes[minFilterNdx].name) + "_" + magFilterModes[magFilterNdx].name + "_" + wrapModes[wrapSNdx].name + "_" + wrapModes[wrapTNdx].name;
583 combinationsGroup->addChild(new TextureCubeArrayFilteringCase(m_context,
585 minFilter, magFilter,
595 // Cases with no visible cube edges.
597 tcu::TestCaseGroup* const onlyFaceInteriorGroup = new tcu::TestCaseGroup(m_testCtx, "no_edges_visible", "Don't sample anywhere near a face's edges");
598 groupCubeArray->addChild(onlyFaceInteriorGroup);
600 for (int isLinearI = 0; isLinearI <= 1; isLinearI++)
602 const bool isLinear = isLinearI != 0;
603 const deUint32 filter = isLinear ? GL_LINEAR : GL_NEAREST;
605 onlyFaceInteriorGroup->addChild(new TextureCubeArrayFilteringCase(m_context,
606 isLinear ? "linear" : "nearest", "",
608 GL_REPEAT, GL_REPEAT,