1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.0 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 Shadow texture lookup tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es3fTextureShadowTests.hpp"
25 #include "gluTexture.hpp"
26 #include "gluPixelTransfer.hpp"
27 #include "gluTextureUtil.hpp"
28 #include "glsTextureTestUtil.hpp"
29 #include "tcuTextureUtil.hpp"
30 #include "tcuRenderTarget.hpp"
31 #include "tcuTexCompareVerifier.hpp"
33 #include "deStringUtil.hpp"
34 #include "glwFunctions.hpp"
35 #include "glwEnums.hpp"
47 using namespace deqp::gls::TextureTestUtil;
51 TEX2D_VIEWPORT_WIDTH = 64,
52 TEX2D_VIEWPORT_HEIGHT = 64,
53 TEX2D_MIN_VIEWPORT_WIDTH = 64,
54 TEX2D_MIN_VIEWPORT_HEIGHT = 64
57 static bool isFloatingPointDepthFormat (const tcu::TextureFormat& format)
59 // Only two depth and depth-stencil formats are floating point
60 return (format.order == tcu::TextureFormat::D && format.type == tcu::TextureFormat::FLOAT) ||
61 (format.order == tcu::TextureFormat::DS && format.type == tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
64 static void clampFloatingPointTexture (const tcu::PixelBufferAccess& access)
66 DE_ASSERT(isFloatingPointDepthFormat(access.getFormat()));
68 for (int z = 0; z < access.getDepth(); ++z)
69 for (int y = 0; y < access.getHeight(); ++y)
70 for (int x = 0; x < access.getWidth(); ++x)
71 access.setPixDepth( de::clamp(access.getPixDepth(x, y, z), 0.0f, 1.0f), x, y, z);
74 static void clampFloatingPointTexture (tcu::Texture2D& target)
76 for (int level = 0; level < target.getNumLevels(); ++level)
77 if (!target.isLevelEmpty(level))
78 clampFloatingPointTexture(target.getLevel(level));
81 static void clampFloatingPointTexture (tcu::Texture2DArray& target)
83 for (int level = 0; level < target.getNumLevels(); ++level)
84 if (!target.isLevelEmpty(level))
85 clampFloatingPointTexture(target.getLevel(level));
88 static void clampFloatingPointTexture (tcu::TextureCube& target)
90 for (int level = 0; level < target.getNumLevels(); ++level)
91 for (int face = tcu::CUBEFACE_NEGATIVE_X; face < tcu::CUBEFACE_LAST; ++face)
92 clampFloatingPointTexture(target.getLevelFace(level, (tcu::CubeFace)face));
95 template<typename TextureType>
96 bool verifyTexCompareResult (tcu::TestContext& testCtx,
97 const tcu::ConstPixelBufferAccess& result,
98 const TextureType& src,
99 const float* texCoord,
100 const ReferenceParams& sampleParams,
101 const tcu::TexComparePrecision& comparePrec,
102 const tcu::LodPrecision& lodPrec,
103 const tcu::PixelFormat& pixelFormat)
105 tcu::TestLog& log = testCtx.getLog();
106 tcu::Surface reference (result.getWidth(), result.getHeight());
107 tcu::Surface errorMask (result.getWidth(), result.getHeight());
108 const tcu::Vec3 nonShadowThreshold = tcu::computeFixedPointThreshold(getBitsVec(pixelFormat)-1).swizzle(1,2,3);
111 // sampleTexture() expects source image to be the same state as it would be in a GL implementation, that is
112 // the floating point depth values should be in [0, 1] range as data is clamped during texture upload. Since
113 // we don't have a separate "uploading" phase and just reuse the buffer we used for GL-upload, do the clamping
114 // here if necessary.
116 if (isFloatingPointDepthFormat(src.getFormat()))
118 TextureType clampedSource(src);
120 clampFloatingPointTexture(clampedSource);
122 // sample clamped values
124 sampleTexture(SurfaceAccess(reference, pixelFormat), clampedSource, texCoord, sampleParams);
125 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), clampedSource, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
129 // sample raw values (they are guaranteed to be in [0, 1] range as the format cannot represent any other values)
131 sampleTexture(SurfaceAccess(reference, pixelFormat), src, texCoord, sampleParams);
132 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), src, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
135 if (numFailedPixels > 0)
136 log << TestLog::Message << "ERROR: Result verification failed, got " << numFailedPixels << " invalid pixels!" << TestLog::EndMessage;
138 log << TestLog::ImageSet("VerifyResult", "Verification result")
139 << TestLog::Image("Rendered", "Rendered image", result);
141 if (numFailedPixels > 0)
143 log << TestLog::Image("Reference", "Ideal reference image", reference)
144 << TestLog::Image("ErrorMask", "Error mask", errorMask);
147 log << TestLog::EndImageSet;
149 return numFailedPixels == 0;
152 class Texture2DShadowCase : public TestCase
155 Texture2DShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int width, int height, deUint32 compareFunc);
156 ~Texture2DShadowCase (void);
160 IterateResult iterate (void);
163 Texture2DShadowCase (const Texture2DShadowCase& other);
164 Texture2DShadowCase& operator= (const Texture2DShadowCase& other);
166 const deUint32 m_minFilter;
167 const deUint32 m_magFilter;
168 const deUint32 m_wrapS;
169 const deUint32 m_wrapT;
170 const deUint32 m_format;
173 const deUint32 m_compareFunc;
177 const glu::Texture2D* texture;
188 FilterCase (const glu::Texture2D* tex_, const float ref_, const tcu::Vec2& minCoord_, const tcu::Vec2& maxCoord_)
190 , minCoord (minCoord_)
191 , maxCoord (maxCoord_)
197 std::vector<glu::Texture2D*> m_textures;
198 std::vector<FilterCase> m_cases;
200 TextureRenderer m_renderer;
205 Texture2DShadowCase::Texture2DShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int width, int height, deUint32 compareFunc)
206 : TestCase (context, name, desc)
207 , m_minFilter (minFilter)
208 , m_magFilter (magFilter)
214 , m_compareFunc (compareFunc)
215 , m_renderer (context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP)
220 Texture2DShadowCase::~Texture2DShadowCase (void)
225 void Texture2DShadowCase::init (void)
229 // Create 2 textures.
230 m_textures.reserve(2);
231 m_textures.push_back(new glu::Texture2D(m_context.getRenderContext(), m_format, m_width, m_height));
232 m_textures.push_back(new glu::Texture2D(m_context.getRenderContext(), m_format, m_width, m_height));
234 int numLevels = m_textures[0]->getRefTexture().getNumLevels();
236 // Fill first gradient texture.
237 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
239 m_textures[0]->getRefTexture().allocLevel(levelNdx);
240 tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevel(levelNdx), tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
243 // Fill second with grid texture.
244 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
246 deUint32 step = 0x00ffffff / numLevels;
247 deUint32 rgb = step*levelNdx;
248 deUint32 colorA = 0xff000000 | rgb;
249 deUint32 colorB = 0xff000000 | ~rgb;
251 m_textures[1]->getRefTexture().allocLevel(levelNdx);
252 tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevel(levelNdx), 4, toVec4(tcu::RGBA(colorA)), toVec4(tcu::RGBA(colorB)));
256 for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
259 catch (const std::exception&)
261 // Clean up to save memory.
262 Texture2DShadowCase::deinit();
268 const float refInRangeUpper = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 1.0f : 0.5f;
269 const float refInRangeLower = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 0.0f : 0.5f;
270 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
271 const float refOutOfBoundsLower = -0.1f;
283 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
284 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
285 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
286 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
287 { 1, refOutOfBoundsUpper, -0.39f, -0.52f, 0.65f, 0.87f },
288 { 1, refOutOfBoundsLower, -1.55f, 0.65f, 0.35f, 0.91f },
291 const float viewportW = (float)de::min<int>(TEX2D_VIEWPORT_WIDTH, m_context.getRenderTarget().getWidth());
292 const float viewportH = (float)de::min<int>(TEX2D_VIEWPORT_HEIGHT, m_context.getRenderTarget().getHeight());
294 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
296 const int texNdx = de::clamp(cases[caseNdx].texNdx, 0, (int)m_textures.size()-1);
297 const float ref = cases[caseNdx].ref;
298 const float lodX = cases[caseNdx].lodX;
299 const float lodY = cases[caseNdx].lodY;
300 const float oX = cases[caseNdx].oX;
301 const float oY = cases[caseNdx].oY;
302 const float sX = deFloatExp2(lodX)*viewportW / float(m_textures[texNdx]->getRefTexture().getWidth());
303 const float sY = deFloatExp2(lodY)*viewportH / float(m_textures[texNdx]->getRefTexture().getHeight());
305 m_cases.push_back(FilterCase(m_textures[texNdx], ref, tcu::Vec2(oX, oY), tcu::Vec2(oX+sX, oY+sY)));
310 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
313 void Texture2DShadowCase::deinit (void)
315 for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
323 Texture2DShadowCase::IterateResult Texture2DShadowCase::iterate (void)
325 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
326 const RandomViewport viewport (m_context.getRenderTarget(), TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT, deStringHash(getName()) ^ deInt32Hash(m_caseNdx));
327 const FilterCase& curCase = m_cases[m_caseNdx];
328 const tcu::ScopedLogSection section (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
329 ReferenceParams sampleParams (TEXTURETYPE_2D);
330 tcu::Surface rendered (viewport.width, viewport.height);
331 vector<float> texCoord;
333 if (viewport.width < TEX2D_MIN_VIEWPORT_WIDTH || viewport.height < TEX2D_MIN_VIEWPORT_HEIGHT)
334 throw tcu::NotSupportedError("Too small render target", "", __FILE__, __LINE__);
336 // Setup params for reference.
337 sampleParams.sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
338 sampleParams.sampler.compare = glu::mapGLCompareFunc(m_compareFunc);
339 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
340 sampleParams.lodMode = LODMODE_EXACT;
341 sampleParams.ref = curCase.ref;
343 m_testCtx.getLog() << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
345 // Compute texture coordinates.
346 m_testCtx.getLog() << TestLog::Message << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord << TestLog::EndMessage;
347 computeQuadTexCoord2D(texCoord, curCase.minCoord, curCase.maxCoord);
349 gl.bindTexture (GL_TEXTURE_2D, curCase.texture->getGLTexture());
350 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
351 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
352 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS);
353 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT);
354 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
355 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, m_compareFunc);
357 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
358 m_renderer.renderQuad(0, &texCoord[0], sampleParams);
359 glu::readPixels(m_context.getRenderContext(), viewport.x, viewport.y, rendered.getAccess());
362 const tcu::PixelFormat pixelFormat = m_context.getRenderTarget().getPixelFormat();
363 tcu::LodPrecision lodPrecision;
364 tcu::TexComparePrecision texComparePrecision;
366 lodPrecision.derivateBits = 18;
367 lodPrecision.lodBits = 6;
368 texComparePrecision.coordBits = tcu::IVec3(20,20,0);
369 texComparePrecision.uvwBits = tcu::IVec3(7,7,0);
370 texComparePrecision.pcfBits = 5;
371 texComparePrecision.referenceBits = 16;
372 texComparePrecision.resultBits = pixelFormat.redBits-1;
374 const bool isHighQuality = verifyTexCompareResult(m_testCtx, rendered.getAccess(), curCase.texture->getRefTexture(),
375 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
379 m_testCtx.getLog() << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
381 lodPrecision.lodBits = 4;
382 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
383 texComparePrecision.pcfBits = 0;
385 const bool isOk = verifyTexCompareResult(m_testCtx, rendered.getAccess(), curCase.texture->getRefTexture(),
386 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
390 m_testCtx.getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
391 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
393 else if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
394 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Low-quality result");
399 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
402 class TextureCubeShadowCase : public TestCase
405 TextureCubeShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int size, deUint32 compareFunc);
406 ~TextureCubeShadowCase (void);
410 IterateResult iterate (void);
413 TextureCubeShadowCase (const TextureCubeShadowCase& other);
414 TextureCubeShadowCase& operator= (const TextureCubeShadowCase& other);
416 const deUint32 m_minFilter;
417 const deUint32 m_magFilter;
418 const deUint32 m_wrapS;
419 const deUint32 m_wrapT;
421 const deUint32 m_format;
424 const deUint32 m_compareFunc;
428 const glu::TextureCube* texture;
429 tcu::Vec2 bottomLeft;
439 FilterCase (const glu::TextureCube* tex_, const float ref_, const tcu::Vec2& bottomLeft_, const tcu::Vec2& topRight_)
441 , bottomLeft(bottomLeft_)
442 , topRight (topRight_)
448 glu::TextureCube* m_gradientTex;
449 glu::TextureCube* m_gridTex;
450 std::vector<FilterCase> m_cases;
452 TextureRenderer m_renderer;
457 TextureCubeShadowCase::TextureCubeShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int size, deUint32 compareFunc)
458 : TestCase (context, name, desc)
459 , m_minFilter (minFilter)
460 , m_magFilter (magFilter)
465 , m_compareFunc (compareFunc)
466 , m_gradientTex (DE_NULL)
467 , m_gridTex (DE_NULL)
468 , m_renderer (context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP)
473 TextureCubeShadowCase::~TextureCubeShadowCase (void)
475 TextureCubeShadowCase::deinit();
478 void TextureCubeShadowCase::init (void)
482 DE_ASSERT(!m_gradientTex && !m_gridTex);
484 int numLevels = deLog2Floor32(m_size)+1;
485 tcu::TextureFormat texFmt = glu::mapGLInternalFormat(m_format);
486 tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
487 tcu::Vec4 cBias = fmtInfo.valueMin;
488 tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
491 m_gradientTex = new glu::TextureCube(m_context.getRenderContext(), m_format, m_size);
492 m_gridTex = new glu::TextureCube(m_context.getRenderContext(), m_format, m_size);
494 // Fill first with gradient texture.
495 static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] =
497 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x
498 { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x
499 { tcu::Vec4(-1.0f, 0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y
500 { tcu::Vec4(-1.0f, -1.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y
501 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z
502 { tcu::Vec4( 0.0f, 0.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z
504 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
506 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
508 m_gradientTex->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx);
509 tcu::fillWithComponentGradients(m_gradientTex->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias);
513 // Fill second with grid texture.
514 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
516 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
518 deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST);
519 deUint32 rgb = step*levelNdx*face;
520 deUint32 colorA = 0xff000000 | rgb;
521 deUint32 colorB = 0xff000000 | ~rgb;
523 m_gridTex->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx);
524 tcu::fillWithGrid(m_gridTex->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), 4, toVec4(tcu::RGBA(colorA))*cScale + cBias, toVec4(tcu::RGBA(colorB))*cScale + cBias);
529 m_gradientTex->upload();
532 catch (const std::exception&)
534 // Clean up to save memory.
535 TextureCubeShadowCase::deinit();
541 const float refInRangeUpper = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 1.0f : 0.5f;
542 const float refInRangeLower = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 0.0f : 0.5f;
543 const float refOutOfBoundsUpper = 1.1f;
544 const float refOutOfBoundsLower = -0.1f;
545 const bool singleSample = m_context.getRenderTarget().getNumSamples() == 0;
548 m_cases.push_back(FilterCase(m_gradientTex, refInRangeUpper, tcu::Vec2(-1.25f, -1.2f), tcu::Vec2(1.2f, 1.25f))); // minification
550 m_cases.push_back(FilterCase(m_gradientTex, refInRangeUpper, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f))); // minification - w/ tuned coordinates to avoid hitting triangle edges
552 m_cases.push_back(FilterCase(m_gradientTex, refInRangeLower, tcu::Vec2(0.8f, 0.8f), tcu::Vec2(1.25f, 1.20f))); // magnification
553 m_cases.push_back(FilterCase(m_gridTex, refInRangeUpper, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f))); // minification
554 m_cases.push_back(FilterCase(m_gridTex, refInRangeLower, tcu::Vec2(-1.2f, -1.1f), tcu::Vec2(-0.8f, -0.8f))); // magnification
555 m_cases.push_back(FilterCase(m_gridTex, refOutOfBoundsUpper, tcu::Vec2(-0.61f, -0.1f), tcu::Vec2(0.9f, 1.18f))); // reference value clamp, upper
558 m_cases.push_back(FilterCase(m_gridTex, refOutOfBoundsLower, tcu::Vec2(-0.75f, 1.0f), tcu::Vec2(0.05f, 0.75f))); // reference value clamp, lower
560 m_cases.push_back(FilterCase(m_gridTex, refOutOfBoundsLower, tcu::Vec2(-0.75f, 1.0f), tcu::Vec2(0.25f, 0.75f))); // reference value clamp, lower
564 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
567 void TextureCubeShadowCase::deinit (void)
569 delete m_gradientTex;
572 m_gradientTex = DE_NULL;
579 static const char* getFaceDesc (const tcu::CubeFace face)
583 case tcu::CUBEFACE_NEGATIVE_X: return "-X";
584 case tcu::CUBEFACE_POSITIVE_X: return "+X";
585 case tcu::CUBEFACE_NEGATIVE_Y: return "-Y";
586 case tcu::CUBEFACE_POSITIVE_Y: return "+Y";
587 case tcu::CUBEFACE_NEGATIVE_Z: return "-Z";
588 case tcu::CUBEFACE_POSITIVE_Z: return "+Z";
595 TextureCubeShadowCase::IterateResult TextureCubeShadowCase::iterate (void)
597 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
598 const int viewportSize = 28;
599 const RandomViewport viewport (m_context.getRenderTarget(), viewportSize, viewportSize, deStringHash(getName()) ^ deInt32Hash(m_caseNdx));
600 const tcu::ScopedLogSection iterSection (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
601 const FilterCase& curCase = m_cases[m_caseNdx];
602 ReferenceParams sampleParams (TEXTURETYPE_CUBE);
604 if (viewport.width < viewportSize || viewport.height < viewportSize)
605 throw tcu::NotSupportedError("Too small render target", DE_NULL, __FILE__, __LINE__);
608 gl.bindTexture (GL_TEXTURE_CUBE_MAP, curCase.texture->getGLTexture());
609 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter);
610 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, m_magFilter);
611 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS);
612 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT);
613 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
614 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, m_compareFunc);
617 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
619 // Params for reference computation.
620 sampleParams.sampler = glu::mapGLSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, m_minFilter, m_magFilter);
621 sampleParams.sampler.seamlessCubeMap = true;
622 sampleParams.sampler.compare = glu::mapGLCompareFunc(m_compareFunc);
623 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
624 sampleParams.lodMode = LODMODE_EXACT;
625 sampleParams.ref = curCase.ref;
629 << "Compare reference value = " << sampleParams.ref << "\n"
630 << "Coordinates: " << curCase.bottomLeft << " -> " << curCase.topRight
631 << TestLog::EndMessage;
633 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
635 const tcu::CubeFace face = tcu::CubeFace(faceNdx);
636 tcu::Surface result (viewport.width, viewport.height);
637 vector<float> texCoord;
639 computeQuadTexCoordCube(texCoord, face, curCase.bottomLeft, curCase.topRight);
641 m_testCtx.getLog() << TestLog::Message << "Face " << getFaceDesc(face) << TestLog::EndMessage;
643 // \todo Log texture coordinates.
645 m_renderer.renderQuad(0, &texCoord[0], sampleParams);
646 GLU_EXPECT_NO_ERROR(gl.getError(), "Draw");
648 glu::readPixels(m_context.getRenderContext(), viewport.x, viewport.y, result.getAccess());
649 GLU_EXPECT_NO_ERROR(gl.getError(), "Read pixels");
652 const tcu::PixelFormat pixelFormat = m_context.getRenderTarget().getPixelFormat();
653 tcu::LodPrecision lodPrecision;
654 tcu::TexComparePrecision texComparePrecision;
656 lodPrecision.derivateBits = 10;
657 lodPrecision.lodBits = 5;
658 texComparePrecision.coordBits = tcu::IVec3(10,10,10);
659 texComparePrecision.uvwBits = tcu::IVec3(6,6,0);
660 texComparePrecision.pcfBits = 5;
661 texComparePrecision.referenceBits = 16;
662 texComparePrecision.resultBits = pixelFormat.redBits-1;
664 const bool isHighQuality = verifyTexCompareResult(m_testCtx, result.getAccess(), curCase.texture->getRefTexture(),
665 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
669 m_testCtx.getLog() << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
671 lodPrecision.lodBits = 4;
672 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
673 texComparePrecision.pcfBits = 0;
675 const bool isOk = verifyTexCompareResult(m_testCtx, result.getAccess(), curCase.texture->getRefTexture(),
676 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
680 m_testCtx.getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
681 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
683 else if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
684 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Low-quality result");
690 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
693 class Texture2DArrayShadowCase : public TestCase
696 Texture2DArrayShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int width, int height, int numLayers, deUint32 compareFunc);
697 ~Texture2DArrayShadowCase (void);
701 IterateResult iterate (void);
704 Texture2DArrayShadowCase (const Texture2DArrayShadowCase& other);
705 Texture2DArrayShadowCase& operator= (const Texture2DArrayShadowCase& other);
707 const deUint32 m_minFilter;
708 const deUint32 m_magFilter;
709 const deUint32 m_wrapS;
710 const deUint32 m_wrapT;
712 const deUint32 m_format;
715 const int m_numLayers;
717 const deUint32 m_compareFunc;
721 const glu::Texture2DArray* texture;
732 FilterCase (const glu::Texture2DArray* tex_, float ref_, const tcu::Vec3& minCoord_, const tcu::Vec3& maxCoord_)
734 , minCoord (minCoord_)
735 , maxCoord (maxCoord_)
741 glu::Texture2DArray* m_gradientTex;
742 glu::Texture2DArray* m_gridTex;
743 std::vector<FilterCase> m_cases;
745 TextureRenderer m_renderer;
750 Texture2DArrayShadowCase::Texture2DArrayShadowCase (Context& context, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 format, int width, int height, int numLayers, deUint32 compareFunc)
751 : TestCase (context, name, desc)
752 , m_minFilter (minFilter)
753 , m_magFilter (magFilter)
759 , m_numLayers (numLayers)
760 , m_compareFunc (compareFunc)
761 , m_gradientTex (DE_NULL)
762 , m_gridTex (DE_NULL)
763 , m_renderer (context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP)
768 Texture2DArrayShadowCase::~Texture2DArrayShadowCase (void)
770 Texture2DArrayShadowCase::deinit();
773 void Texture2DArrayShadowCase::init (void)
777 tcu::TextureFormat texFmt = glu::mapGLInternalFormat(m_format);
778 tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
779 tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
780 tcu::Vec4 cBias = fmtInfo.valueMin;
781 int numLevels = deLog2Floor32(de::max(m_width, m_height)) + 1;
784 m_gradientTex = new glu::Texture2DArray(m_context.getRenderContext(), m_format, m_width, m_height, m_numLayers);
785 m_gridTex = new glu::Texture2DArray(m_context.getRenderContext(), m_format, m_width, m_height, m_numLayers);
787 // Fill first gradient texture.
788 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
790 tcu::Vec4 gMin = tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias;
791 tcu::Vec4 gMax = tcu::Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias;
793 m_gradientTex->getRefTexture().allocLevel(levelNdx);
794 tcu::fillWithComponentGradients(m_gradientTex->getRefTexture().getLevel(levelNdx), gMin, gMax);
797 // Fill second with grid texture.
798 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
800 deUint32 step = 0x00ffffff / numLevels;
801 deUint32 rgb = step*levelNdx;
802 deUint32 colorA = 0xff000000 | rgb;
803 deUint32 colorB = 0xff000000 | ~rgb;
805 m_gridTex->getRefTexture().allocLevel(levelNdx);
806 tcu::fillWithGrid(m_gridTex->getRefTexture().getLevel(levelNdx), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
810 m_gradientTex->upload();
815 // Clean up to save memory.
816 Texture2DArrayShadowCase::deinit();
822 const float refInRangeUpper = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 1.0f : 0.5f;
823 const float refInRangeLower = (m_compareFunc == GL_EQUAL || m_compareFunc == GL_NOTEQUAL) ? 0.0f : 0.5f;
824 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
825 const float refOutOfBoundsLower = -0.1f;
837 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
838 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
839 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
840 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
841 { 1, refOutOfBoundsUpper, -0.49f, -0.22f, 0.45f, 0.97f },
842 { 1, refOutOfBoundsLower, -0.85f, 0.75f, 0.25f, 0.61f },
845 const float viewportW = (float)de::min<int>(TEX2D_VIEWPORT_WIDTH, m_context.getRenderTarget().getWidth());
846 const float viewportH = (float)de::min<int>(TEX2D_VIEWPORT_HEIGHT, m_context.getRenderTarget().getHeight());
848 const float minLayer = -0.5f;
849 const float maxLayer = (float)m_numLayers;
851 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
853 const glu::Texture2DArray* tex = cases[caseNdx].texNdx > 0 ? m_gridTex : m_gradientTex;
854 const float ref = cases[caseNdx].ref;
855 const float lodX = cases[caseNdx].lodX;
856 const float lodY = cases[caseNdx].lodY;
857 const float oX = cases[caseNdx].oX;
858 const float oY = cases[caseNdx].oY;
859 const float sX = deFloatExp2(lodX)*viewportW / float(tex->getRefTexture().getWidth());
860 const float sY = deFloatExp2(lodY)*viewportH / float(tex->getRefTexture().getHeight());
862 m_cases.push_back(FilterCase(tex, ref, tcu::Vec3(oX, oY, minLayer), tcu::Vec3(oX+sX, oY+sY, maxLayer)));
867 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
870 void Texture2DArrayShadowCase::deinit (void)
872 delete m_gradientTex;
875 m_gradientTex = DE_NULL;
882 Texture2DArrayShadowCase::IterateResult Texture2DArrayShadowCase::iterate (void)
884 const glw::Functions& gl = m_context.getRenderContext().getFunctions();
885 const RandomViewport viewport (m_context.getRenderTarget(), TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT, deStringHash(getName()) ^ deInt32Hash(m_caseNdx));
886 const FilterCase& curCase = m_cases[m_caseNdx];
887 const tcu::ScopedLogSection section (m_testCtx.getLog(), string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
888 ReferenceParams sampleParams (TEXTURETYPE_2D_ARRAY);
889 tcu::Surface rendered (viewport.width, viewport.height);
891 const float texCoord[] =
893 curCase.minCoord.x(), curCase.minCoord.y(), curCase.minCoord.z(),
894 curCase.minCoord.x(), curCase.maxCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
895 curCase.maxCoord.x(), curCase.minCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
896 curCase.maxCoord.x(), curCase.maxCoord.y(), curCase.maxCoord.z()
899 if (viewport.width < TEX2D_MIN_VIEWPORT_WIDTH || viewport.height < TEX2D_MIN_VIEWPORT_HEIGHT)
900 throw tcu::NotSupportedError("Too small render target", "", __FILE__, __LINE__);
902 // Setup params for reference.
903 sampleParams.sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter);
904 sampleParams.sampler.compare = glu::mapGLCompareFunc(m_compareFunc);
905 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
906 sampleParams.lodMode = LODMODE_EXACT;
907 sampleParams.ref = curCase.ref;
911 << "Compare reference value = " << sampleParams.ref << "\n"
912 << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord
913 << TestLog::EndMessage;
915 gl.bindTexture (GL_TEXTURE_2D_ARRAY, curCase.texture->getGLTexture());
916 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, m_minFilter);
917 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, m_magFilter);
918 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, m_wrapS);
919 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, m_wrapT);
920 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
921 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, m_compareFunc);
923 gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
924 m_renderer.renderQuad(0, &texCoord[0], sampleParams);
925 glu::readPixels(m_context.getRenderContext(), viewport.x, viewport.y, rendered.getAccess());
928 const tcu::PixelFormat pixelFormat = m_context.getRenderTarget().getPixelFormat();
929 tcu::LodPrecision lodPrecision;
930 tcu::TexComparePrecision texComparePrecision;
932 lodPrecision.derivateBits = 18;
933 lodPrecision.lodBits = 6;
934 texComparePrecision.coordBits = tcu::IVec3(20,20,20);
935 texComparePrecision.uvwBits = tcu::IVec3(7,7,7);
936 texComparePrecision.pcfBits = 5;
937 texComparePrecision.referenceBits = 16;
938 texComparePrecision.resultBits = pixelFormat.redBits-1;
940 const bool isHighQuality = verifyTexCompareResult(m_testCtx, rendered.getAccess(), curCase.texture->getRefTexture(),
941 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
945 m_testCtx.getLog() << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
947 lodPrecision.lodBits = 4;
948 texComparePrecision.uvwBits = tcu::IVec3(4,4,4);
949 texComparePrecision.pcfBits = 0;
951 const bool isOk = verifyTexCompareResult(m_testCtx, rendered.getAccess(), curCase.texture->getRefTexture(),
952 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
956 m_testCtx.getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
957 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image verification failed");
959 else if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
960 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Low-quality result");
965 return m_caseNdx < (int)m_cases.size() ? CONTINUE : STOP;
968 TextureShadowTests::TextureShadowTests (Context& context)
969 : TestCaseGroup(context, "shadow", "Shadow texture lookup tests")
973 TextureShadowTests::~TextureShadowTests (void)
977 void TextureShadowTests::init (void)
985 { "depth_component16", GL_DEPTH_COMPONENT16 },
986 { "depth_component32f", GL_DEPTH_COMPONENT32F },
987 { "depth24_stencil8", GL_DEPTH24_STENCIL8 }
997 { "nearest", GL_NEAREST, GL_NEAREST },
998 { "linear", GL_LINEAR, GL_LINEAR },
999 { "nearest_mipmap_nearest", GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR },
1000 { "linear_mipmap_nearest", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR },
1001 { "nearest_mipmap_linear", GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR },
1002 { "linear_mipmap_linear", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR }
1011 { "less_or_equal", GL_LEQUAL },
1012 { "greater_or_equal", GL_GEQUAL },
1013 { "less", GL_LESS },
1014 { "greater", GL_GREATER },
1015 { "equal", GL_EQUAL },
1016 { "not_equal", GL_NOTEQUAL },
1017 { "always", GL_ALWAYS },
1018 { "never", GL_NEVER }
1023 tcu::TestCaseGroup* group2D = new tcu::TestCaseGroup(m_testCtx, "2d", "2D texture shadow lookup tests");
1026 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
1028 tcu::TestCaseGroup* filterGroup = new tcu::TestCaseGroup(m_testCtx, filters[filterNdx].name, "");
1029 group2D->addChild(filterGroup);
1031 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareFuncs); compareNdx++)
1033 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1035 deUint32 minFilter = filters[filterNdx].minFilter;
1036 deUint32 magFilter = filters[filterNdx].magFilter;
1037 deUint32 format = formats[formatNdx].format;
1038 deUint32 compareFunc = compareFuncs[compareNdx].func;
1039 const deUint32 wrapS = GL_REPEAT;
1040 const deUint32 wrapT = GL_REPEAT;
1041 const int width = 32;
1042 const int height = 64;
1043 string name = string(compareFuncs[compareNdx].name) + "_" + formats[formatNdx].name;
1045 filterGroup->addChild(new Texture2DShadowCase(m_context, name.c_str(), "", minFilter, magFilter, wrapS, wrapT, format, width, height, compareFunc));
1053 tcu::TestCaseGroup* groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cube map texture shadow lookup tests");
1054 addChild(groupCube);
1056 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
1058 tcu::TestCaseGroup* filterGroup = new tcu::TestCaseGroup(m_testCtx, filters[filterNdx].name, "");
1059 groupCube->addChild(filterGroup);
1061 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareFuncs); compareNdx++)
1063 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1065 deUint32 minFilter = filters[filterNdx].minFilter;
1066 deUint32 magFilter = filters[filterNdx].magFilter;
1067 deUint32 format = formats[formatNdx].format;
1068 deUint32 compareFunc = compareFuncs[compareNdx].func;
1069 const deUint32 wrapS = GL_REPEAT;
1070 const deUint32 wrapT = GL_REPEAT;
1071 const int size = 32;
1072 string name = string(compareFuncs[compareNdx].name) + "_" + formats[formatNdx].name;
1074 filterGroup->addChild(new TextureCubeShadowCase(m_context, name.c_str(), "", minFilter, magFilter, wrapS, wrapT, format, size, compareFunc));
1082 tcu::TestCaseGroup* group2DArray = new tcu::TestCaseGroup(m_testCtx, "2d_array", "2D texture array shadow lookup tests");
1083 addChild(group2DArray);
1085 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
1087 tcu::TestCaseGroup* filterGroup = new tcu::TestCaseGroup(m_testCtx, filters[filterNdx].name, "");
1088 group2DArray->addChild(filterGroup);
1090 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareFuncs); compareNdx++)
1092 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
1094 deUint32 minFilter = filters[filterNdx].minFilter;
1095 deUint32 magFilter = filters[filterNdx].magFilter;
1096 deUint32 format = formats[formatNdx].format;
1097 deUint32 compareFunc = compareFuncs[compareNdx].func;
1098 const deUint32 wrapS = GL_REPEAT;
1099 const deUint32 wrapT = GL_REPEAT;
1100 const int width = 32;
1101 const int height = 64;
1102 const int numLayers = 8;
1103 string name = string(compareFuncs[compareNdx].name) + "_" + formats[formatNdx].name;
1105 filterGroup->addChild(new Texture2DArrayShadowCase(m_context, name.c_str(), "", minFilter, magFilter, wrapS, wrapT, format, width, height, numLayers, compareFunc));