1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright 2014 The Android Open Source Project
6 * Copyright (c) 2016 The Khronos Group Inc.
7 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Shadow texture lookup tests.
24 *//*--------------------------------------------------------------------*/
26 #include "vktTextureShadowTests.hpp"
30 #include "deStringUtil.hpp"
31 #include "gluPixelTransfer.hpp"
32 #include "gluTextureTestUtil.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuImageIO.hpp"
36 #include "tcuRenderTarget.hpp"
37 #include "tcuTexCompareVerifier.hpp"
38 #include "tcuTexVerifierUtil.hpp"
39 #include "tcuTexture.hpp"
40 #include "tcuTextureUtil.hpp"
41 #include "vkImageUtil.hpp"
42 #include "vkTypeUtil.hpp"
43 #include "vktTestGroupUtil.hpp"
44 #include "vktTextureTestUtil.hpp"
59 using namespace texture::util;
60 using namespace glu::TextureTestUtil;
64 TEXCUBE_VIEWPORT_SIZE = 28,
65 TEX2D_VIEWPORT_WIDTH = 64,
66 TEX2D_VIEWPORT_HEIGHT = 64
69 struct TextureShadowCommonTestCaseParameters
71 TextureShadowCommonTestCaseParameters (void);
72 Sampler::CompareMode compareOp;
75 TextureShadowCommonTestCaseParameters::TextureShadowCommonTestCaseParameters (void)
76 : compareOp (Sampler::COMPAREMODE_EQUAL)
80 struct Texture2DShadowTestCaseParameters : public Texture2DTestCaseParameters, public TextureShadowCommonTestCaseParameters
84 bool isFloatingPointDepthFormat (const tcu::TextureFormat& format)
86 // Only two depth and depth-stencil formats are floating point
87 return (format.order == tcu::TextureFormat::D && format.type == tcu::TextureFormat::FLOAT) ||
88 (format.order == tcu::TextureFormat::DS && format.type == tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
91 void clampFloatingPointTexture (const tcu::PixelBufferAccess& access)
93 DE_ASSERT(isFloatingPointDepthFormat(access.getFormat()));
95 for (int z = 0; z < access.getDepth(); ++z)
96 for (int y = 0; y < access.getHeight(); ++y)
97 for (int x = 0; x < access.getWidth(); ++x)
98 access.setPixDepth(de::clamp(access.getPixDepth(x, y, z), 0.0f, 1.0f), x, y, z);
101 void clampFloatingPointTexture (tcu::Texture2D& target)
103 for (int level = 0; level < target.getNumLevels(); ++level)
104 if (!target.isLevelEmpty(level))
105 clampFloatingPointTexture(target.getLevel(level));
108 static void clampFloatingPointTexture (tcu::Texture2DArray& target)
110 for (int level = 0; level < target.getNumLevels(); ++level)
111 if (!target.isLevelEmpty(level))
112 clampFloatingPointTexture(target.getLevel(level));
115 void clampFloatingPointTexture (tcu::TextureCube& target)
117 for (int level = 0; level < target.getNumLevels(); ++level)
118 for (int face = tcu::CUBEFACE_NEGATIVE_X; face < tcu::CUBEFACE_LAST; ++face)
119 clampFloatingPointTexture(target.getLevelFace(level, (tcu::CubeFace)face));
122 tcu::PixelFormat getPixelFormat(tcu::TextureFormat texFormat)
124 const tcu::IVec4 formatBitDepth = tcu::getTextureFormatBitDepth(tcu::getEffectiveDepthStencilTextureFormat(texFormat, Sampler::MODE_DEPTH));
125 return tcu::PixelFormat(formatBitDepth[0], formatBitDepth[1], formatBitDepth[2], formatBitDepth[3]);
128 template<typename TextureType>
129 bool verifyTexCompareResult (tcu::TestContext& testCtx,
130 const tcu::ConstPixelBufferAccess& result,
131 const TextureType& src,
132 const float* texCoord,
133 const ReferenceParams& sampleParams,
134 const tcu::TexComparePrecision& comparePrec,
135 const tcu::LodPrecision& lodPrec,
136 const tcu::PixelFormat& pixelFormat)
138 tcu::TestLog& log = testCtx.getLog();
139 tcu::Surface reference (result.getWidth(), result.getHeight());
140 tcu::Surface errorMask (result.getWidth(), result.getHeight());
141 const tcu::Vec3 nonShadowThreshold = tcu::computeFixedPointThreshold(getBitsVec(pixelFormat)-1).swizzle(1,2,3);
144 // sampleTexture() expects source image to be the same state as it would be in a GL implementation, that is
145 // the floating point depth values should be in [0, 1] range as data is clamped during texture upload. Since
146 // we don't have a separate "uploading" phase and just reuse the buffer we used for GL-upload, do the clamping
147 // here if necessary.
149 if (isFloatingPointDepthFormat(src.getFormat()))
151 TextureType clampedSource(src);
153 clampFloatingPointTexture(clampedSource);
155 // sample clamped values
157 sampleTexture(tcu::SurfaceAccess(reference, pixelFormat), clampedSource, texCoord, sampleParams);
158 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), clampedSource, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
162 // sample raw values (they are guaranteed to be in [0, 1] range as the format cannot represent any other values)
164 sampleTexture(tcu::SurfaceAccess(reference, pixelFormat), src, texCoord, sampleParams);
165 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), src, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
168 if (numFailedPixels > 0)
169 log << TestLog::Message << "ERROR: Result verification failed, got " << numFailedPixels << " invalid pixels!" << TestLog::EndMessage;
171 log << TestLog::ImageSet("VerifyResult", "Verification result")
172 << TestLog::Image("Rendered", "Rendered image", result);
174 if (numFailedPixels > 0)
176 log << TestLog::Image("Reference", "Ideal reference image", reference)
177 << TestLog::Image("ErrorMask", "Error mask", errorMask);
180 log << TestLog::EndImageSet;
182 return numFailedPixels == 0;
185 class Texture2DShadowTestInstance : public TestInstance
188 typedef Texture2DShadowTestCaseParameters ParameterType;
189 Texture2DShadowTestInstance (Context& context, const ParameterType& testParameters);
190 ~Texture2DShadowTestInstance (void);
192 virtual tcu::TestStatus iterate (void);
195 Texture2DShadowTestInstance (const Texture2DShadowTestInstance& other);
196 Texture2DShadowTestInstance& operator= (const Texture2DShadowTestInstance& other);
212 FilterCase (int tex_, const float ref_, const tcu::Vec2& minCoord_, const tcu::Vec2& maxCoord_)
213 : textureIndex (tex_)
214 , minCoord (minCoord_)
215 , maxCoord (maxCoord_)
221 const ParameterType& m_testParameters;
222 std::vector<TestTexture2DSp> m_textures;
223 std::vector<FilterCase> m_cases;
225 TextureRenderer m_renderer;
230 Texture2DShadowTestInstance::Texture2DShadowTestInstance (Context& context, const ParameterType& testParameters)
231 : TestInstance (context)
232 , m_testParameters (testParameters)
233 , m_renderer (context, testParameters.sampleCount, TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT)
236 // Create 2 textures.
237 m_textures.reserve(2);
238 for (int ndx = 0; ndx < 2; ndx++)
240 m_textures.push_back(TestTexture2DSp(new pipeline::TestTexture2D(vk::mapVkFormat(m_testParameters.format), m_testParameters.width, m_testParameters.height)));
243 const int numLevels = m_textures[0]->getNumLevels();
245 // Fill first gradient texture.
246 for (int levelNdx = 0; levelNdx < numLevels; ++levelNdx)
248 tcu::fillWithComponentGradients(m_textures[0]->getLevel(levelNdx, 0), tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
251 // Fill second with grid texture.
252 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
254 const deUint32 step = 0x00ffffff / numLevels;
255 const deUint32 rgb = step*levelNdx;
256 const deUint32 colorA = 0xff000000 | rgb;
257 const deUint32 colorB = 0xff000000 | ~rgb;
259 tcu::fillWithGrid(m_textures[1]->getLevel(levelNdx, 0), 4, tcu::RGBA(colorA).toVec(), tcu::RGBA(colorB).toVec());
263 for (std::vector<TestTexture2DSp>::iterator i = m_textures.begin(); i != m_textures.end(); ++i)
265 m_renderer.add2DTexture(*i);
270 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
271 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
272 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
273 const float refOutOfBoundsLower = -0.1f;
285 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
286 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
287 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
288 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
289 { 1, refOutOfBoundsUpper, -0.39f, -0.52f, 0.65f, 0.87f },
290 { 1, refOutOfBoundsLower, -1.55f, 0.65f, 0.35f, 0.91f },
293 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
295 const int texNdx = de::clamp(cases[caseNdx].texNdx, 0, (int)m_textures.size()-1);
296 const float ref = cases[caseNdx].ref;
297 const float lodX = cases[caseNdx].lodX;
298 const float lodY = cases[caseNdx].lodY;
299 const float oX = cases[caseNdx].oX;
300 const float oY = cases[caseNdx].oY;
301 const float sX = deFloatExp2(lodX) * float(m_renderer.getRenderWidth()) / float(m_textures[texNdx]->getTexture().getWidth());
302 const float sY = deFloatExp2(lodY) * float(m_renderer.getRenderHeight()) / float(m_textures[texNdx]->getTexture().getHeight());
304 m_cases.push_back(FilterCase(texNdx, ref, tcu::Vec2(oX, oY), tcu::Vec2(oX+sX, oY+sY)));
311 Texture2DShadowTestInstance::~Texture2DShadowTestInstance (void)
317 tcu::TestStatus Texture2DShadowTestInstance::iterate (void)
319 tcu::TestLog& log = m_context.getTestContext().getLog();
320 const pipeline::TestTexture2D& texture = m_renderer.get2DTexture(m_cases[m_caseNdx].textureIndex);
321 const tcu::TextureFormat texFmt = texture.getTextureFormat();
322 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
323 const tcu::ScopedLogSection section (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
325 const FilterCase& curCase = m_cases[m_caseNdx];
326 ReferenceParams sampleParams (TEXTURETYPE_2D);
327 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
328 vector<float> texCoord;
330 // Setup params for reference.
331 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
332 sampleParams.sampler.compare = m_testParameters.compareOp;
333 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
334 sampleParams.lodMode = LODMODE_EXACT;
335 sampleParams.colorBias = fmtInfo.lookupBias;
336 sampleParams.colorScale = fmtInfo.lookupScale;
337 sampleParams.ref = curCase.ref;
339 log << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
341 // Compute texture coordinates.
342 log << TestLog::Message << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord << TestLog::EndMessage;
343 computeQuadTexCoord2D(texCoord, curCase.minCoord, curCase.maxCoord);
345 m_renderer.renderQuad(rendered, curCase.textureIndex, &texCoord[0], sampleParams);
348 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
349 tcu::LodPrecision lodPrecision;
350 tcu::TexComparePrecision texComparePrecision;
352 lodPrecision.derivateBits = 18;
353 lodPrecision.lodBits = 6;
354 texComparePrecision.coordBits = tcu::IVec3(20,20,0);
355 texComparePrecision.uvwBits = tcu::IVec3(7,7,0);
356 texComparePrecision.pcfBits = 5;
357 texComparePrecision.referenceBits = 16;
358 texComparePrecision.resultBits = pixelFormat.redBits-1;
360 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
361 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
365 m_context.getTestContext().getLog() << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
367 lodPrecision.lodBits = 4;
368 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
369 texComparePrecision.pcfBits = 0;
371 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
372 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
376 m_context.getTestContext().getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
377 return tcu::TestStatus::fail("Image verification failed");
383 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
386 struct TextureCubeShadowTestCaseParameters : public TextureShadowCommonTestCaseParameters, public TextureCubeTestCaseParameters
390 class TextureCubeShadowTestInstance : public TestInstance
393 typedef TextureCubeShadowTestCaseParameters ParameterType;
394 TextureCubeShadowTestInstance (Context& context, const ParameterType& testParameters);
395 ~TextureCubeShadowTestInstance (void);
397 virtual tcu::TestStatus iterate (void);
400 TextureCubeShadowTestInstance (const TextureCubeShadowTestInstance& other);
401 TextureCubeShadowTestInstance& operator= (const TextureCubeShadowTestInstance& other);
406 tcu::Vec2 bottomLeft;
416 FilterCase (const int tex_, const float ref_, const tcu::Vec2& bottomLeft_, const tcu::Vec2& topRight_)
417 : textureIndex (tex_)
418 , bottomLeft (bottomLeft_)
419 , topRight (topRight_)
425 const ParameterType& m_testParameters;
426 vector<TestTextureCubeSp> m_textures;
427 std::vector<FilterCase> m_cases;
429 TextureRenderer m_renderer;
433 TextureCubeShadowTestInstance::TextureCubeShadowTestInstance (Context& context, const ParameterType& testParameters)
434 : TestInstance (context)
435 , m_testParameters (testParameters)
436 , m_renderer (context, testParameters.sampleCount, TEXCUBE_VIEWPORT_SIZE, TEXCUBE_VIEWPORT_SIZE)
439 const int numLevels = deLog2Floor32(m_testParameters.size)+1;
440 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(vk::mapVkFormat(m_testParameters.format));
441 const tcu::Vec4 cBias = fmtInfo.valueMin;
442 const tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
446 m_textures.reserve(2);
447 for (int ndx = 0; ndx < 2; ndx++)
449 m_textures.push_back(TestTextureCubeSp(new pipeline::TestTextureCube(vk::mapVkFormat(m_testParameters.format), m_testParameters.size)));
452 // Fill first with gradient texture.
453 static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] =
455 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x
456 { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x
457 { tcu::Vec4(-1.0f, 0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y
458 { tcu::Vec4(-1.0f, -1.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y
459 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z
460 { tcu::Vec4( 0.0f, 0.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z
462 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
464 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
466 tcu::fillWithComponentGradients(m_textures[0]->getLevel(levelNdx, face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias);
470 // Fill second with grid texture.
471 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
473 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
475 const deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST);
476 const deUint32 rgb = step*levelNdx*face;
477 const deUint32 colorA = 0xff000000 | rgb;
478 const deUint32 colorB = 0xff000000 | ~rgb;
480 tcu::fillWithGrid(m_textures[1]->getLevel(levelNdx, face), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
485 for (vector<TestTextureCubeSp>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
487 m_renderer.addCubeTexture(*i);
492 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
493 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
494 const float refOutOfBoundsUpper = 1.1f;
495 const float refOutOfBoundsLower = -0.1f;
497 m_cases.push_back(FilterCase(0, refInRangeUpper, tcu::Vec2(-1.25f, -1.2f), tcu::Vec2(1.2f, 1.25f))); // minification
498 m_cases.push_back(FilterCase(0, refInRangeLower, tcu::Vec2(0.8f, 0.8f), tcu::Vec2(1.25f, 1.20f))); // magnification
499 m_cases.push_back(FilterCase(1, refInRangeUpper, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f))); // minification
500 m_cases.push_back(FilterCase(1, refInRangeLower, tcu::Vec2(-1.2f, -1.1f), tcu::Vec2(-0.8f, -0.8f))); // magnification
501 m_cases.push_back(FilterCase(1, refOutOfBoundsUpper, tcu::Vec2(-0.61f, -0.1f), tcu::Vec2(0.9f, 1.18f))); // reference value clamp, upper
502 m_cases.push_back(FilterCase(1, refOutOfBoundsLower, tcu::Vec2(-0.75f, 1.0f), tcu::Vec2(0.05f, 0.75f))); // reference value clamp, lower
506 TextureCubeShadowTestInstance::~TextureCubeShadowTestInstance (void)
510 static const char* getFaceDesc (const tcu::CubeFace face)
514 case tcu::CUBEFACE_NEGATIVE_X: return "-X";
515 case tcu::CUBEFACE_POSITIVE_X: return "+X";
516 case tcu::CUBEFACE_NEGATIVE_Y: return "-Y";
517 case tcu::CUBEFACE_POSITIVE_Y: return "+Y";
518 case tcu::CUBEFACE_NEGATIVE_Z: return "-Z";
519 case tcu::CUBEFACE_POSITIVE_Z: return "+Z";
526 tcu::TestStatus TextureCubeShadowTestInstance::iterate (void)
529 tcu::TestLog& log = m_context.getTestContext().getLog();
530 const tcu::ScopedLogSection iterSection (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
531 const FilterCase& curCase = m_cases[m_caseNdx];
532 const pipeline::TestTextureCube& texture = m_renderer.getCubeTexture(curCase.textureIndex);
534 ReferenceParams sampleParams (TEXTURETYPE_CUBE);
536 // Params for reference computation.
537 sampleParams.sampler = util::createSampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, m_testParameters.minFilter, m_testParameters.magFilter);
538 sampleParams.sampler.seamlessCubeMap = true;
539 sampleParams.sampler.compare = m_testParameters.compareOp;
540 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
541 sampleParams.lodMode = LODMODE_EXACT;
542 sampleParams.ref = curCase.ref;
544 log << TestLog::Message
545 << "Compare reference value = " << sampleParams.ref << "\n"
546 << "Coordinates: " << curCase.bottomLeft << " -> " << curCase.topRight
547 << TestLog::EndMessage;
549 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
551 const tcu::CubeFace face = tcu::CubeFace(faceNdx);
552 tcu::Surface result (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
553 vector<float> texCoord;
555 computeQuadTexCoordCube(texCoord, face, curCase.bottomLeft, curCase.topRight);
557 log << TestLog::Message << "Face " << getFaceDesc(face) << TestLog::EndMessage;
559 // \todo Log texture coordinates.
561 m_renderer.renderQuad(result, curCase.textureIndex, &texCoord[0], sampleParams);
564 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
565 tcu::LodPrecision lodPrecision;
566 tcu::TexComparePrecision texComparePrecision;
568 lodPrecision.derivateBits = 10;
569 lodPrecision.lodBits = 5;
570 texComparePrecision.coordBits = tcu::IVec3(10,10,10);
571 texComparePrecision.uvwBits = tcu::IVec3(6,6,0);
572 texComparePrecision.pcfBits = 5;
573 texComparePrecision.referenceBits = 16;
574 texComparePrecision.resultBits = pixelFormat.redBits-1;
576 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), result.getAccess(), texture.getTexture(),
577 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
581 log << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
583 lodPrecision.lodBits = 4;
584 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
585 texComparePrecision.pcfBits = 0;
587 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), result.getAccess(), texture.getTexture(),
588 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
592 log << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
593 return tcu::TestStatus::fail("Image verification failed");
600 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
603 struct Texture2DArrayShadowTestCaseParameters : public TextureShadowCommonTestCaseParameters, public Texture2DArrayTestCaseParameters
607 class Texture2DArrayShadowTestInstance : public TestInstance
610 typedef Texture2DArrayShadowTestCaseParameters ParameterType;
611 Texture2DArrayShadowTestInstance (Context& context, const ParameterType& testParameters);
612 ~Texture2DArrayShadowTestInstance (void);
614 virtual tcu::TestStatus iterate (void);
617 Texture2DArrayShadowTestInstance (const Texture2DArrayShadowTestInstance& other);
618 Texture2DArrayShadowTestInstance& operator= (const Texture2DArrayShadowTestInstance& other);
633 FilterCase (const int tex_, float ref_, const tcu::Vec3& minCoord_, const tcu::Vec3& maxCoord_)
634 : textureIndex (tex_)
635 , minCoord (minCoord_)
636 , maxCoord (maxCoord_)
642 const ParameterType& m_testParameters;
643 std::vector<TestTexture2DArraySp> m_textures;
644 std::vector<FilterCase> m_cases;
646 TextureRenderer m_renderer;
651 Texture2DArrayShadowTestInstance::Texture2DArrayShadowTestInstance (Context& context, const ParameterType& testParameters)
652 : TestInstance (context)
653 , m_testParameters (testParameters)
654 , m_renderer (context, testParameters.sampleCount, TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT)
657 const int numLevels = deLog2Floor32(de::max(m_testParameters.width, m_testParameters.height))+1;
658 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(vk::mapVkFormat(m_testParameters.format));
659 const tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
660 const tcu::Vec4 cBias = fmtInfo.valueMin;
662 // Create 2 textures.
663 m_textures.reserve(2);
664 for (int ndx = 0; ndx < 2; ndx++)
666 m_textures.push_back(TestTexture2DArraySp(new pipeline::TestTexture2DArray(vk::mapVkFormat(m_testParameters.format), m_testParameters.width, m_testParameters.height, m_testParameters.numLayers)));
669 // Fill first gradient texture.
670 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
672 const tcu::Vec4 gMin = tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias;
673 const tcu::Vec4 gMax = tcu::Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias;
675 tcu::fillWithComponentGradients(m_textures[0]->getTexture().getLevel(levelNdx), gMin, gMax);
678 // Fill second with grid texture.
679 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
681 const deUint32 step = 0x00ffffff / numLevels;
682 const deUint32 rgb = step*levelNdx;
683 const deUint32 colorA = 0xff000000 | rgb;
684 const deUint32 colorB = 0xff000000 | ~rgb;
686 tcu::fillWithGrid(m_textures[1]->getTexture().getLevel(levelNdx), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
690 for (std::vector<TestTexture2DArraySp>::iterator i = m_textures.begin(); i != m_textures.end(); ++i)
692 m_renderer.add2DArrayTexture(*i);
697 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
698 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
699 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
700 const float refOutOfBoundsLower = -0.1f;
712 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
713 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
714 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
715 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
716 { 1, refOutOfBoundsUpper, -0.49f, -0.22f, 0.45f, 0.97f },
717 { 1, refOutOfBoundsLower, -0.85f, 0.75f, 0.25f, 0.61f },
720 const float minLayer = -0.5f;
721 const float maxLayer = (float)m_testParameters.numLayers;
723 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
725 const int tex = cases[caseNdx].texNdx > 0 ? 1 : 0;
726 const float ref = cases[caseNdx].ref;
727 const float lodX = cases[caseNdx].lodX;
728 const float lodY = cases[caseNdx].lodY;
729 const float oX = cases[caseNdx].oX;
730 const float oY = cases[caseNdx].oY;
731 const float sX = deFloatExp2(lodX) * float(m_renderer.getRenderWidth()) / float(m_textures[tex]->getTexture().getWidth());
732 const float sY = deFloatExp2(lodY) * float(m_renderer.getRenderHeight()) / float(m_textures[tex]->getTexture().getHeight());
734 m_cases.push_back(FilterCase(tex, ref, tcu::Vec3(oX, oY, minLayer), tcu::Vec3(oX+sX, oY+sY, maxLayer)));
739 Texture2DArrayShadowTestInstance::~Texture2DArrayShadowTestInstance (void)
743 tcu::TestStatus Texture2DArrayShadowTestInstance::iterate (void)
745 tcu::TestLog& log = m_context.getTestContext().getLog();
746 const FilterCase& curCase = m_cases[m_caseNdx];
747 const pipeline::TestTexture2DArray& texture = m_renderer.get2DArrayTexture(curCase.textureIndex);
749 ReferenceParams sampleParams (TEXTURETYPE_2D_ARRAY);
750 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
751 const tcu::ScopedLogSection section (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
753 const float texCoord[] =
755 curCase.minCoord.x(), curCase.minCoord.y(), curCase.minCoord.z(),
756 curCase.minCoord.x(), curCase.maxCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
757 curCase.maxCoord.x(), curCase.minCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
758 curCase.maxCoord.x(), curCase.maxCoord.y(), curCase.maxCoord.z()
761 // Setup params for reference.
762 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
763 sampleParams.sampler.compare = m_testParameters.compareOp;
764 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
765 sampleParams.lodMode = LODMODE_EXACT;
766 sampleParams.ref = curCase.ref;
768 log << TestLog::Message
769 << "Compare reference value = " << sampleParams.ref << "\n"
770 << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord
771 << TestLog::EndMessage;
773 m_renderer.renderQuad(rendered, curCase.textureIndex, &texCoord[0], sampleParams);
776 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
777 tcu::LodPrecision lodPrecision;
778 tcu::TexComparePrecision texComparePrecision;
780 lodPrecision.derivateBits = 18;
781 lodPrecision.lodBits = 6;
782 texComparePrecision.coordBits = tcu::IVec3(20,20,20);
783 texComparePrecision.uvwBits = tcu::IVec3(7,7,7);
784 texComparePrecision.pcfBits = 5;
785 texComparePrecision.referenceBits = 16;
786 texComparePrecision.resultBits = pixelFormat.redBits-1;
788 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
789 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
793 log << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
795 lodPrecision.lodBits = 4;
796 texComparePrecision.uvwBits = tcu::IVec3(4,4,4);
797 texComparePrecision.pcfBits = 0;
799 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
800 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
804 log << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
805 return tcu::TestStatus::fail("Image verification failed");
811 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
814 void populateTextureShadowTests (tcu::TestCaseGroup* textureShadowTests)
816 tcu::TestContext& testCtx = textureShadowTests->getTestContext();
821 const VkFormat format;
824 { "d16_unorm", VK_FORMAT_D16_UNORM },
825 { "x8_d24_unorm_pack32", VK_FORMAT_X8_D24_UNORM_PACK32 },
826 { "d32_sfloat", VK_FORMAT_D32_SFLOAT },
827 { "d16_unorm_s8_uint", VK_FORMAT_D16_UNORM_S8_UINT },
828 { "d24_unorm_s8_uint", VK_FORMAT_D24_UNORM_S8_UINT },
829 { "d32_sfloat_s8_uint", VK_FORMAT_D32_SFLOAT_S8_UINT }
835 const Sampler::FilterMode minFilter;
836 const Sampler::FilterMode magFilter;
839 { "nearest", Sampler::NEAREST, Sampler::NEAREST },
840 { "linear", Sampler::LINEAR, Sampler::LINEAR },
841 { "nearest_mipmap_nearest", Sampler::NEAREST_MIPMAP_NEAREST, Sampler::LINEAR },
842 { "linear_mipmap_nearest", Sampler::LINEAR_MIPMAP_NEAREST, Sampler::LINEAR },
843 { "nearest_mipmap_linear", Sampler::NEAREST_MIPMAP_LINEAR, Sampler::LINEAR },
844 { "linear_mipmap_linear", Sampler::LINEAR_MIPMAP_LINEAR, Sampler::LINEAR }
850 const Sampler::CompareMode op;
853 { "less_or_equal", Sampler::COMPAREMODE_LESS_OR_EQUAL },
854 { "greater_or_equal", Sampler::COMPAREMODE_GREATER_OR_EQUAL },
855 { "less", Sampler::COMPAREMODE_LESS },
856 { "greater", Sampler::COMPAREMODE_GREATER },
857 { "equal", Sampler::COMPAREMODE_EQUAL },
858 { "not_equal", Sampler::COMPAREMODE_NOT_EQUAL },
859 { "always", Sampler::COMPAREMODE_ALWAYS },
860 { "never", Sampler::COMPAREMODE_NEVER }
865 de::MovePtr<tcu::TestCaseGroup> group2D (new tcu::TestCaseGroup(testCtx, "2d", "2D texture shadow lookup tests"));
867 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
869 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
871 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
873 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
875 const string name = string(compareOp[compareNdx].name) + "_" + formats[formatNdx].name;
876 Texture2DShadowTestCaseParameters testParameters;
878 testParameters.minFilter = filters[filterNdx].minFilter;
879 testParameters.magFilter = filters[filterNdx].magFilter;
880 testParameters.format = formats[formatNdx].format;
881 testParameters.compareOp = compareOp[compareNdx].op;
882 testParameters.wrapS = Sampler::REPEAT_GL;
883 testParameters.wrapT = Sampler::REPEAT_GL;
884 testParameters.width = 32;
885 testParameters.height = 64;
887 testParameters.programs.push_back(PROGRAM_2D_SHADOW);
889 filterGroup->addChild(new TextureTestCase<Texture2DShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
893 group2D->addChild(filterGroup.release());
896 textureShadowTests->addChild(group2D.release());
901 de::MovePtr<tcu::TestCaseGroup> groupCube (new tcu::TestCaseGroup(testCtx, "cube", "Cube map texture shadow lookup tests"));
903 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
905 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
907 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
909 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
911 const string name = string(compareOp[compareNdx].name) + "_" + formats[formatNdx].name;
912 TextureCubeShadowTestCaseParameters testParameters;
914 testParameters.minFilter = filters[filterNdx].minFilter;
915 testParameters.magFilter = filters[filterNdx].magFilter;
916 testParameters.format = formats[formatNdx].format;
917 testParameters.compareOp = compareOp[compareNdx].op;
918 testParameters.wrapS = Sampler::REPEAT_GL;
919 testParameters.wrapT = Sampler::REPEAT_GL;
920 testParameters.size = 32;
922 testParameters.programs.push_back(PROGRAM_CUBE_SHADOW);
924 filterGroup->addChild(new TextureTestCase<TextureCubeShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
928 groupCube->addChild(filterGroup.release());
931 textureShadowTests->addChild(groupCube.release());
936 de::MovePtr<tcu::TestCaseGroup> group2DArray (new tcu::TestCaseGroup(testCtx, "2d_array", "2D texture array shadow lookup tests"));
938 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
940 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
942 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
944 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
946 const string name = string(compareOp[compareNdx].name) + "_" + formats[formatNdx].name;
947 Texture2DArrayShadowTestCaseParameters testParameters;
949 testParameters.minFilter = filters[filterNdx].minFilter;
950 testParameters.magFilter = filters[filterNdx].magFilter;
951 testParameters.format = formats[formatNdx].format;
952 testParameters.compareOp = compareOp[compareNdx].op;
953 testParameters.wrapS = Sampler::REPEAT_GL;
954 testParameters.wrapT = Sampler::REPEAT_GL;
955 testParameters.width = 32;
956 testParameters.height = 64;
957 testParameters.numLayers = 8;
959 testParameters.programs.push_back(PROGRAM_2D_ARRAY_SHADOW);
961 filterGroup->addChild(new TextureTestCase<Texture2DArrayShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
965 group2DArray->addChild(filterGroup.release());
968 textureShadowTests->addChild(group2DArray.release());
974 tcu::TestCaseGroup* createTextureShadowTests (tcu::TestContext& testCtx)
976 return createTestGroup(testCtx, "shadow", "Texture shadow tests.", populateTextureShadowTests);