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;
73 TextureBinding::ImageBackingMode backingMode;
76 TextureShadowCommonTestCaseParameters::TextureShadowCommonTestCaseParameters (void)
77 : compareOp (Sampler::COMPAREMODE_EQUAL)
78 , backingMode (TextureBinding::IMAGE_BACKING_MODE_REGULAR)
82 struct Texture2DShadowTestCaseParameters : public Texture2DTestCaseParameters, public TextureShadowCommonTestCaseParameters
86 bool isFloatingPointDepthFormat (const tcu::TextureFormat& format)
88 // Only two depth and depth-stencil formats are floating point
89 return (format.order == tcu::TextureFormat::D && format.type == tcu::TextureFormat::FLOAT) ||
90 (format.order == tcu::TextureFormat::DS && format.type == tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
93 void clampFloatingPointTexture (const tcu::PixelBufferAccess& access)
95 DE_ASSERT(isFloatingPointDepthFormat(access.getFormat()));
97 for (int z = 0; z < access.getDepth(); ++z)
98 for (int y = 0; y < access.getHeight(); ++y)
99 for (int x = 0; x < access.getWidth(); ++x)
100 access.setPixDepth(de::clamp(access.getPixDepth(x, y, z), 0.0f, 1.0f), x, y, z);
103 void clampFloatingPointTexture (tcu::Texture2D& target)
105 for (int level = 0; level < target.getNumLevels(); ++level)
106 if (!target.isLevelEmpty(level))
107 clampFloatingPointTexture(target.getLevel(level));
110 static void clampFloatingPointTexture (tcu::Texture2DArray& target)
112 for (int level = 0; level < target.getNumLevels(); ++level)
113 if (!target.isLevelEmpty(level))
114 clampFloatingPointTexture(target.getLevel(level));
117 void clampFloatingPointTexture (tcu::TextureCube& target)
119 for (int level = 0; level < target.getNumLevels(); ++level)
120 for (int face = tcu::CUBEFACE_NEGATIVE_X; face < tcu::CUBEFACE_LAST; ++face)
121 clampFloatingPointTexture(target.getLevelFace(level, (tcu::CubeFace)face));
124 tcu::PixelFormat getPixelFormat(tcu::TextureFormat texFormat)
126 const tcu::IVec4 formatBitDepth = tcu::getTextureFormatBitDepth(tcu::getEffectiveDepthStencilTextureFormat(texFormat, Sampler::MODE_DEPTH));
127 return tcu::PixelFormat(formatBitDepth[0], formatBitDepth[1], formatBitDepth[2], formatBitDepth[3]);
130 template<typename TextureType>
131 bool verifyTexCompareResult (tcu::TestContext& testCtx,
132 const tcu::ConstPixelBufferAccess& result,
133 const TextureType& src,
134 const float* texCoord,
135 const ReferenceParams& sampleParams,
136 const tcu::TexComparePrecision& comparePrec,
137 const tcu::LodPrecision& lodPrec,
138 const tcu::PixelFormat& pixelFormat)
140 tcu::TestLog& log = testCtx.getLog();
141 tcu::Surface reference (result.getWidth(), result.getHeight());
142 tcu::Surface errorMask (result.getWidth(), result.getHeight());
143 const tcu::Vec3 nonShadowThreshold = tcu::computeFixedPointThreshold(getBitsVec(pixelFormat)-1).swizzle(1,2,3);
146 // sampleTexture() expects source image to be the same state as it would be in a GL implementation, that is
147 // the floating point depth values should be in [0, 1] range as data is clamped during texture upload. Since
148 // we don't have a separate "uploading" phase and just reuse the buffer we used for GL-upload, do the clamping
149 // here if necessary.
151 if (isFloatingPointDepthFormat(src.getFormat()))
153 TextureType clampedSource(src);
155 clampFloatingPointTexture(clampedSource);
157 // sample clamped values
159 sampleTexture(tcu::SurfaceAccess(reference, pixelFormat), clampedSource, texCoord, sampleParams);
160 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), clampedSource, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
164 // sample raw values (they are guaranteed to be in [0, 1] range as the format cannot represent any other values)
166 sampleTexture(tcu::SurfaceAccess(reference, pixelFormat), src, texCoord, sampleParams);
167 numFailedPixels = computeTextureCompareDiff(result, reference.getAccess(), errorMask.getAccess(), src, texCoord, sampleParams, comparePrec, lodPrec, nonShadowThreshold);
170 if (numFailedPixels > 0)
171 log << TestLog::Message << "ERROR: Result verification failed, got " << numFailedPixels << " invalid pixels!" << TestLog::EndMessage;
173 log << TestLog::ImageSet("VerifyResult", "Verification result")
174 << TestLog::Image("Rendered", "Rendered image", result);
176 if (numFailedPixels > 0)
178 log << TestLog::Image("Reference", "Ideal reference image", reference)
179 << TestLog::Image("ErrorMask", "Error mask", errorMask);
182 log << TestLog::EndImageSet;
184 return numFailedPixels == 0;
187 class Texture2DShadowTestInstance : public TestInstance
190 typedef Texture2DShadowTestCaseParameters ParameterType;
191 Texture2DShadowTestInstance (Context& context, const ParameterType& testParameters);
192 ~Texture2DShadowTestInstance (void);
194 virtual tcu::TestStatus iterate (void);
197 Texture2DShadowTestInstance (const Texture2DShadowTestInstance& other);
198 Texture2DShadowTestInstance& operator= (const Texture2DShadowTestInstance& other);
214 FilterCase (int tex_, const float ref_, const tcu::Vec2& minCoord_, const tcu::Vec2& maxCoord_)
215 : textureIndex (tex_)
216 , minCoord (minCoord_)
217 , maxCoord (maxCoord_)
223 const ParameterType& m_testParameters;
224 std::vector<TestTexture2DSp> m_textures;
225 std::vector<FilterCase> m_cases;
227 TextureRenderer m_renderer;
232 Texture2DShadowTestInstance::Texture2DShadowTestInstance (Context& context, const ParameterType& testParameters)
233 : TestInstance (context)
234 , m_testParameters (testParameters)
235 , m_renderer (context, testParameters.sampleCount, TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT)
238 // Create 2 textures.
239 m_textures.reserve(2);
240 for (int ndx = 0; ndx < 2; ndx++)
242 m_textures.push_back(TestTexture2DSp(new pipeline::TestTexture2D(vk::mapVkFormat(m_testParameters.format), m_testParameters.width, m_testParameters.height)));
245 const int numLevels = m_textures[0]->getNumLevels();
247 // Fill first gradient texture.
248 for (int levelNdx = 0; levelNdx < numLevels; ++levelNdx)
250 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));
253 // Fill second with grid texture.
254 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
256 const deUint32 step = 0x00ffffff / numLevels;
257 const deUint32 rgb = step*levelNdx;
258 const deUint32 colorA = 0xff000000 | rgb;
259 const deUint32 colorB = 0xff000000 | ~rgb;
261 tcu::fillWithGrid(m_textures[1]->getLevel(levelNdx, 0), 4, tcu::RGBA(colorA).toVec(), tcu::RGBA(colorB).toVec());
265 for (std::vector<TestTexture2DSp>::iterator i = m_textures.begin(); i != m_textures.end(); ++i)
267 m_renderer.add2DTexture(*i, m_testParameters.backingMode);
272 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
273 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
274 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
275 const float refOutOfBoundsLower = -0.1f;
287 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
288 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
289 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
290 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
291 { 1, refOutOfBoundsUpper, -0.39f, -0.52f, 0.65f, 0.87f },
292 { 1, refOutOfBoundsLower, -1.55f, 0.65f, 0.35f, 0.91f },
295 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
297 const int texNdx = de::clamp(cases[caseNdx].texNdx, 0, (int)m_textures.size()-1);
298 const float ref = cases[caseNdx].ref;
299 const float lodX = cases[caseNdx].lodX;
300 const float lodY = cases[caseNdx].lodY;
301 const float oX = cases[caseNdx].oX;
302 const float oY = cases[caseNdx].oY;
303 const float sX = deFloatExp2(lodX) * float(m_renderer.getRenderWidth()) / float(m_textures[texNdx]->getTexture().getWidth());
304 const float sY = deFloatExp2(lodY) * float(m_renderer.getRenderHeight()) / float(m_textures[texNdx]->getTexture().getHeight());
306 m_cases.push_back(FilterCase(texNdx, ref, tcu::Vec2(oX, oY), tcu::Vec2(oX+sX, oY+sY)));
313 Texture2DShadowTestInstance::~Texture2DShadowTestInstance (void)
319 tcu::TestStatus Texture2DShadowTestInstance::iterate (void)
321 tcu::TestLog& log = m_context.getTestContext().getLog();
322 const pipeline::TestTexture2D& texture = m_renderer.get2DTexture(m_cases[m_caseNdx].textureIndex);
323 const tcu::TextureFormat texFmt = texture.getTextureFormat();
324 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt);
325 const tcu::ScopedLogSection section (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
327 const FilterCase& curCase = m_cases[m_caseNdx];
328 ReferenceParams sampleParams (TEXTURETYPE_2D);
329 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
330 vector<float> texCoord;
332 // Setup params for reference.
333 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
334 sampleParams.sampler.compare = m_testParameters.compareOp;
335 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
336 sampleParams.lodMode = LODMODE_EXACT;
337 sampleParams.colorBias = fmtInfo.lookupBias;
338 sampleParams.colorScale = fmtInfo.lookupScale;
339 sampleParams.ref = curCase.ref;
341 log << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
343 // Compute texture coordinates.
344 log << TestLog::Message << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord << TestLog::EndMessage;
345 computeQuadTexCoord2D(texCoord, curCase.minCoord, curCase.maxCoord);
347 m_renderer.renderQuad(rendered, curCase.textureIndex, &texCoord[0], sampleParams);
350 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
351 tcu::LodPrecision lodPrecision;
352 tcu::TexComparePrecision texComparePrecision;
354 lodPrecision.derivateBits = 18;
355 lodPrecision.lodBits = 6;
356 texComparePrecision.coordBits = tcu::IVec3(20,20,0);
357 texComparePrecision.uvwBits = tcu::IVec3(7,7,0);
358 texComparePrecision.pcfBits = 5;
359 texComparePrecision.referenceBits = 16;
360 texComparePrecision.resultBits = pixelFormat.redBits-1;
362 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
363 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
367 m_context.getTestContext().getLog() << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
369 lodPrecision.lodBits = 4;
370 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
371 texComparePrecision.pcfBits = 0;
373 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
374 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
378 m_context.getTestContext().getLog() << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
379 return tcu::TestStatus::fail("Image verification failed");
385 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
388 struct TextureCubeShadowTestCaseParameters : public TextureShadowCommonTestCaseParameters, public TextureCubeTestCaseParameters
392 class TextureCubeShadowTestInstance : public TestInstance
395 typedef TextureCubeShadowTestCaseParameters ParameterType;
396 TextureCubeShadowTestInstance (Context& context, const ParameterType& testParameters);
397 ~TextureCubeShadowTestInstance (void);
399 virtual tcu::TestStatus iterate (void);
402 TextureCubeShadowTestInstance (const TextureCubeShadowTestInstance& other);
403 TextureCubeShadowTestInstance& operator= (const TextureCubeShadowTestInstance& other);
408 tcu::Vec2 bottomLeft;
418 FilterCase (const int tex_, const float ref_, const tcu::Vec2& bottomLeft_, const tcu::Vec2& topRight_)
419 : textureIndex (tex_)
420 , bottomLeft (bottomLeft_)
421 , topRight (topRight_)
427 const ParameterType& m_testParameters;
428 vector<TestTextureCubeSp> m_textures;
429 std::vector<FilterCase> m_cases;
431 TextureRenderer m_renderer;
435 TextureCubeShadowTestInstance::TextureCubeShadowTestInstance (Context& context, const ParameterType& testParameters)
436 : TestInstance (context)
437 , m_testParameters (testParameters)
438 , m_renderer (context, testParameters.sampleCount, TEXCUBE_VIEWPORT_SIZE, TEXCUBE_VIEWPORT_SIZE)
441 const int numLevels = deLog2Floor32(m_testParameters.size)+1;
442 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(vk::mapVkFormat(m_testParameters.format));
443 const tcu::Vec4 cBias = fmtInfo.valueMin;
444 const tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
448 m_textures.reserve(2);
449 for (int ndx = 0; ndx < 2; ndx++)
451 m_textures.push_back(TestTextureCubeSp(new pipeline::TestTextureCube(vk::mapVkFormat(m_testParameters.format), m_testParameters.size)));
454 // Fill first with gradient texture.
455 static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] =
457 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x
458 { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x
459 { tcu::Vec4(-1.0f, 0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y
460 { tcu::Vec4(-1.0f, -1.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y
461 { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z
462 { tcu::Vec4( 0.0f, 0.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z
464 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
466 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
468 tcu::fillWithComponentGradients(m_textures[0]->getLevel(levelNdx, face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias);
472 // Fill second with grid texture.
473 for (int face = 0; face < tcu::CUBEFACE_LAST; face++)
475 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
477 const deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST);
478 const deUint32 rgb = step*levelNdx*face;
479 const deUint32 colorA = 0xff000000 | rgb;
480 const deUint32 colorB = 0xff000000 | ~rgb;
482 tcu::fillWithGrid(m_textures[1]->getLevel(levelNdx, face), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
487 for (vector<TestTextureCubeSp>::iterator i = m_textures.begin(); i != m_textures.end(); i++)
489 m_renderer.addCubeTexture(*i, m_testParameters.backingMode);
494 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
495 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
496 const float refOutOfBoundsUpper = 1.1f;
497 const float refOutOfBoundsLower = -0.1f;
499 m_cases.push_back(FilterCase(0, refInRangeUpper, tcu::Vec2(-1.25f, -1.2f), tcu::Vec2(1.2f, 1.25f))); // minification
500 m_cases.push_back(FilterCase(0, refInRangeLower, tcu::Vec2(0.8f, 0.8f), tcu::Vec2(1.25f, 1.20f))); // magnification
501 m_cases.push_back(FilterCase(1, refInRangeUpper, tcu::Vec2(-1.19f, -1.3f), tcu::Vec2(1.1f, 1.35f))); // minification
502 m_cases.push_back(FilterCase(1, refInRangeLower, tcu::Vec2(-1.2f, -1.1f), tcu::Vec2(-0.8f, -0.8f))); // magnification
503 m_cases.push_back(FilterCase(1, refOutOfBoundsUpper, tcu::Vec2(-0.61f, -0.1f), tcu::Vec2(0.9f, 1.18f))); // reference value clamp, upper
504 m_cases.push_back(FilterCase(1, refOutOfBoundsLower, tcu::Vec2(-0.75f, 1.0f), tcu::Vec2(0.05f, 0.75f))); // reference value clamp, lower
508 TextureCubeShadowTestInstance::~TextureCubeShadowTestInstance (void)
512 static const char* getFaceDesc (const tcu::CubeFace face)
516 case tcu::CUBEFACE_NEGATIVE_X: return "-X";
517 case tcu::CUBEFACE_POSITIVE_X: return "+X";
518 case tcu::CUBEFACE_NEGATIVE_Y: return "-Y";
519 case tcu::CUBEFACE_POSITIVE_Y: return "+Y";
520 case tcu::CUBEFACE_NEGATIVE_Z: return "-Z";
521 case tcu::CUBEFACE_POSITIVE_Z: return "+Z";
528 tcu::TestStatus TextureCubeShadowTestInstance::iterate (void)
531 tcu::TestLog& log = m_context.getTestContext().getLog();
532 const tcu::ScopedLogSection iterSection (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
533 const FilterCase& curCase = m_cases[m_caseNdx];
534 const pipeline::TestTextureCube& texture = m_renderer.getCubeTexture(curCase.textureIndex);
536 ReferenceParams sampleParams (TEXTURETYPE_CUBE);
538 // Params for reference computation.
539 sampleParams.sampler = util::createSampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, m_testParameters.minFilter, m_testParameters.magFilter);
540 sampleParams.sampler.seamlessCubeMap = true;
541 sampleParams.sampler.compare = m_testParameters.compareOp;
542 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
543 sampleParams.lodMode = LODMODE_EXACT;
544 sampleParams.ref = curCase.ref;
546 log << TestLog::Message
547 << "Compare reference value = " << sampleParams.ref << "\n"
548 << "Coordinates: " << curCase.bottomLeft << " -> " << curCase.topRight
549 << TestLog::EndMessage;
551 for (int faceNdx = 0; faceNdx < tcu::CUBEFACE_LAST; faceNdx++)
553 const tcu::CubeFace face = tcu::CubeFace(faceNdx);
554 tcu::Surface result (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
555 vector<float> texCoord;
557 computeQuadTexCoordCube(texCoord, face, curCase.bottomLeft, curCase.topRight);
559 log << TestLog::Message << "Face " << getFaceDesc(face) << TestLog::EndMessage;
561 // \todo Log texture coordinates.
563 m_renderer.renderQuad(result, curCase.textureIndex, &texCoord[0], sampleParams);
566 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
567 tcu::LodPrecision lodPrecision;
568 tcu::TexComparePrecision texComparePrecision;
570 lodPrecision.derivateBits = 10;
571 lodPrecision.lodBits = 5;
572 texComparePrecision.coordBits = tcu::IVec3(10,10,10);
573 texComparePrecision.uvwBits = tcu::IVec3(6,6,0);
574 texComparePrecision.pcfBits = 5;
575 texComparePrecision.referenceBits = 16;
576 texComparePrecision.resultBits = pixelFormat.redBits-1;
578 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), result.getAccess(), texture.getTexture(),
579 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
583 log << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
585 lodPrecision.lodBits = 4;
586 texComparePrecision.uvwBits = tcu::IVec3(4,4,0);
587 texComparePrecision.pcfBits = 0;
589 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), result.getAccess(), texture.getTexture(),
590 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
594 log << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
595 return tcu::TestStatus::fail("Image verification failed");
602 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
605 struct Texture2DArrayShadowTestCaseParameters : public TextureShadowCommonTestCaseParameters, public Texture2DArrayTestCaseParameters
609 class Texture2DArrayShadowTestInstance : public TestInstance
612 typedef Texture2DArrayShadowTestCaseParameters ParameterType;
613 Texture2DArrayShadowTestInstance (Context& context, const ParameterType& testParameters);
614 ~Texture2DArrayShadowTestInstance (void);
616 virtual tcu::TestStatus iterate (void);
619 Texture2DArrayShadowTestInstance (const Texture2DArrayShadowTestInstance& other);
620 Texture2DArrayShadowTestInstance& operator= (const Texture2DArrayShadowTestInstance& other);
635 FilterCase (const int tex_, float ref_, const tcu::Vec3& minCoord_, const tcu::Vec3& maxCoord_)
636 : textureIndex (tex_)
637 , minCoord (minCoord_)
638 , maxCoord (maxCoord_)
644 const ParameterType& m_testParameters;
645 std::vector<TestTexture2DArraySp> m_textures;
646 std::vector<FilterCase> m_cases;
648 TextureRenderer m_renderer;
653 Texture2DArrayShadowTestInstance::Texture2DArrayShadowTestInstance (Context& context, const ParameterType& testParameters)
654 : TestInstance (context)
655 , m_testParameters (testParameters)
656 , m_renderer (context, testParameters.sampleCount, TEX2D_VIEWPORT_WIDTH, TEX2D_VIEWPORT_HEIGHT)
659 const int numLevels = deLog2Floor32(de::max(m_testParameters.width, m_testParameters.height))+1;
660 const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(vk::mapVkFormat(m_testParameters.format));
661 const tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin;
662 const tcu::Vec4 cBias = fmtInfo.valueMin;
664 // Create 2 textures.
665 m_textures.reserve(2);
666 for (int ndx = 0; ndx < 2; ndx++)
668 m_textures.push_back(TestTexture2DArraySp(new pipeline::TestTexture2DArray(vk::mapVkFormat(m_testParameters.format), m_testParameters.width, m_testParameters.height, m_testParameters.numLayers)));
671 // Fill first gradient texture.
672 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
674 const tcu::Vec4 gMin = tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias;
675 const tcu::Vec4 gMax = tcu::Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias;
677 tcu::fillWithComponentGradients(m_textures[0]->getTexture().getLevel(levelNdx), gMin, gMax);
680 // Fill second with grid texture.
681 for (int levelNdx = 0; levelNdx < numLevels; levelNdx++)
683 const deUint32 step = 0x00ffffff / numLevels;
684 const deUint32 rgb = step*levelNdx;
685 const deUint32 colorA = 0xff000000 | rgb;
686 const deUint32 colorB = 0xff000000 | ~rgb;
688 tcu::fillWithGrid(m_textures[1]->getTexture().getLevel(levelNdx), 4, tcu::RGBA(colorA).toVec()*cScale + cBias, tcu::RGBA(colorB).toVec()*cScale + cBias);
692 for (std::vector<TestTexture2DArraySp>::iterator i = m_textures.begin(); i != m_textures.end(); ++i)
694 m_renderer.add2DArrayTexture(*i, m_testParameters.backingMode);
699 const float refInRangeUpper = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 1.0f : 0.5f;
700 const float refInRangeLower = (m_testParameters.compareOp == Sampler::COMPAREMODE_EQUAL || m_testParameters.compareOp == Sampler::COMPAREMODE_NOT_EQUAL) ? 0.0f : 0.5f;
701 const float refOutOfBoundsUpper = 1.1f; // !< lookup function should clamp values to [0, 1] range
702 const float refOutOfBoundsLower = -0.1f;
714 { 0, refInRangeUpper, 1.6f, 2.9f, -1.0f, -2.7f },
715 { 0, refInRangeLower, -2.0f, -1.35f, -0.2f, 0.7f },
716 { 1, refInRangeUpper, 0.14f, 0.275f, -1.5f, -1.1f },
717 { 1, refInRangeLower, -0.92f, -2.64f, 0.4f, -0.1f },
718 { 1, refOutOfBoundsUpper, -0.49f, -0.22f, 0.45f, 0.97f },
719 { 1, refOutOfBoundsLower, -0.85f, 0.75f, 0.25f, 0.61f },
722 const float minLayer = -0.5f;
723 const float maxLayer = (float)m_testParameters.numLayers;
725 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); caseNdx++)
727 const int tex = cases[caseNdx].texNdx > 0 ? 1 : 0;
728 const float ref = cases[caseNdx].ref;
729 const float lodX = cases[caseNdx].lodX;
730 const float lodY = cases[caseNdx].lodY;
731 const float oX = cases[caseNdx].oX;
732 const float oY = cases[caseNdx].oY;
733 const float sX = deFloatExp2(lodX) * float(m_renderer.getRenderWidth()) / float(m_textures[tex]->getTexture().getWidth());
734 const float sY = deFloatExp2(lodY) * float(m_renderer.getRenderHeight()) / float(m_textures[tex]->getTexture().getHeight());
736 m_cases.push_back(FilterCase(tex, ref, tcu::Vec3(oX, oY, minLayer), tcu::Vec3(oX+sX, oY+sY, maxLayer)));
741 Texture2DArrayShadowTestInstance::~Texture2DArrayShadowTestInstance (void)
745 tcu::TestStatus Texture2DArrayShadowTestInstance::iterate (void)
747 tcu::TestLog& log = m_context.getTestContext().getLog();
748 const FilterCase& curCase = m_cases[m_caseNdx];
749 const pipeline::TestTexture2DArray& texture = m_renderer.get2DArrayTexture(curCase.textureIndex);
751 ReferenceParams sampleParams (TEXTURETYPE_2D_ARRAY);
752 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
753 const tcu::ScopedLogSection section (log, string("Test") + de::toString(m_caseNdx), string("Test ") + de::toString(m_caseNdx));
755 const float texCoord[] =
757 curCase.minCoord.x(), curCase.minCoord.y(), curCase.minCoord.z(),
758 curCase.minCoord.x(), curCase.maxCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
759 curCase.maxCoord.x(), curCase.minCoord.y(), (curCase.minCoord.z() + curCase.maxCoord.z()) / 2.0f,
760 curCase.maxCoord.x(), curCase.maxCoord.y(), curCase.maxCoord.z()
763 // Setup params for reference.
764 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
765 sampleParams.sampler.compare = m_testParameters.compareOp;
766 sampleParams.samplerType = SAMPLERTYPE_SHADOW;
767 sampleParams.lodMode = LODMODE_EXACT;
768 sampleParams.ref = curCase.ref;
770 log << TestLog::Message
771 << "Compare reference value = " << sampleParams.ref << "\n"
772 << "Texture coordinates: " << curCase.minCoord << " -> " << curCase.maxCoord
773 << TestLog::EndMessage;
775 m_renderer.renderQuad(rendered, curCase.textureIndex, &texCoord[0], sampleParams);
778 const tcu::PixelFormat pixelFormat = getPixelFormat(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
779 tcu::LodPrecision lodPrecision;
780 tcu::TexComparePrecision texComparePrecision;
782 lodPrecision.derivateBits = 18;
783 lodPrecision.lodBits = 6;
784 texComparePrecision.coordBits = tcu::IVec3(20,20,20);
785 texComparePrecision.uvwBits = tcu::IVec3(7,7,7);
786 texComparePrecision.pcfBits = 5;
787 texComparePrecision.referenceBits = 16;
788 texComparePrecision.resultBits = pixelFormat.redBits-1;
790 const bool isHighQuality = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
791 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
795 log << TestLog::Message << "Warning: Verification assuming high-quality PCF filtering failed." << TestLog::EndMessage;
797 lodPrecision.lodBits = 4;
798 texComparePrecision.uvwBits = tcu::IVec3(4,4,4);
799 texComparePrecision.pcfBits = 0;
801 const bool isOk = verifyTexCompareResult(m_context.getTestContext(), rendered.getAccess(), texture.getTexture(),
802 &texCoord[0], sampleParams, texComparePrecision, lodPrecision, pixelFormat);
806 log << TestLog::Message << "ERROR: Verification against low precision requirements failed, failing test case." << TestLog::EndMessage;
807 return tcu::TestStatus::fail("Image verification failed");
813 return m_caseNdx < (int)m_cases.size() ? tcu::TestStatus::incomplete() : tcu::TestStatus::pass("Pass");
816 void populateTextureShadowTests (tcu::TestCaseGroup* textureShadowTests)
818 tcu::TestContext& testCtx = textureShadowTests->getTestContext();
823 const TextureBinding::ImageBackingMode backingMode;
826 { "", TextureBinding::IMAGE_BACKING_MODE_REGULAR },
827 { "sparse_", TextureBinding::IMAGE_BACKING_MODE_SPARSE }
833 const VkFormat format;
836 { "d16_unorm", VK_FORMAT_D16_UNORM },
837 { "x8_d24_unorm_pack32", VK_FORMAT_X8_D24_UNORM_PACK32 },
838 { "d32_sfloat", VK_FORMAT_D32_SFLOAT },
839 { "d16_unorm_s8_uint", VK_FORMAT_D16_UNORM_S8_UINT },
840 { "d24_unorm_s8_uint", VK_FORMAT_D24_UNORM_S8_UINT },
841 { "d32_sfloat_s8_uint", VK_FORMAT_D32_SFLOAT_S8_UINT }
847 const Sampler::FilterMode minFilter;
848 const Sampler::FilterMode magFilter;
851 { "nearest", Sampler::NEAREST, Sampler::NEAREST },
852 { "linear", Sampler::LINEAR, Sampler::LINEAR },
853 { "nearest_mipmap_nearest", Sampler::NEAREST_MIPMAP_NEAREST, Sampler::LINEAR },
854 { "linear_mipmap_nearest", Sampler::LINEAR_MIPMAP_NEAREST, Sampler::LINEAR },
855 { "nearest_mipmap_linear", Sampler::NEAREST_MIPMAP_LINEAR, Sampler::LINEAR },
856 { "linear_mipmap_linear", Sampler::LINEAR_MIPMAP_LINEAR, Sampler::LINEAR }
862 const Sampler::CompareMode op;
865 { "less_or_equal", Sampler::COMPAREMODE_LESS_OR_EQUAL },
866 { "greater_or_equal", Sampler::COMPAREMODE_GREATER_OR_EQUAL },
867 { "less", Sampler::COMPAREMODE_LESS },
868 { "greater", Sampler::COMPAREMODE_GREATER },
869 { "equal", Sampler::COMPAREMODE_EQUAL },
870 { "not_equal", Sampler::COMPAREMODE_NOT_EQUAL },
871 { "always", Sampler::COMPAREMODE_ALWAYS },
872 { "never", Sampler::COMPAREMODE_NEVER }
877 de::MovePtr<tcu::TestCaseGroup> group2D (new tcu::TestCaseGroup(testCtx, "2d", "2D texture shadow lookup tests"));
879 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
881 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
883 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
885 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
887 for (int backingNdx = 0; backingNdx < DE_LENGTH_OF_ARRAY(backingModes); backingNdx++)
889 const string name = string(backingModes[backingNdx].name) + compareOp[compareNdx].name + "_" + formats[formatNdx].name;
890 Texture2DShadowTestCaseParameters testParameters;
892 testParameters.minFilter = filters[filterNdx].minFilter;
893 testParameters.magFilter = filters[filterNdx].magFilter;
894 testParameters.format = formats[formatNdx].format;
895 testParameters.backingMode = backingModes[backingNdx].backingMode;
896 testParameters.compareOp = compareOp[compareNdx].op;
897 testParameters.wrapS = Sampler::REPEAT_GL;
898 testParameters.wrapT = Sampler::REPEAT_GL;
899 testParameters.width = 32;
900 testParameters.height = 64;
902 testParameters.programs.push_back(PROGRAM_2D_SHADOW);
904 filterGroup->addChild(new TextureTestCase<Texture2DShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
909 group2D->addChild(filterGroup.release());
912 textureShadowTests->addChild(group2D.release());
917 de::MovePtr<tcu::TestCaseGroup> groupCube (new tcu::TestCaseGroup(testCtx, "cube", "Cube map texture shadow lookup tests"));
919 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
921 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
923 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
925 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
927 for (int backingNdx = 0; backingNdx < DE_LENGTH_OF_ARRAY(backingModes); backingNdx++)
929 const string name = string(backingModes[backingNdx].name) + compareOp[compareNdx].name + "_" + formats[formatNdx].name;
930 TextureCubeShadowTestCaseParameters testParameters;
932 testParameters.minFilter = filters[filterNdx].minFilter;
933 testParameters.magFilter = filters[filterNdx].magFilter;
934 testParameters.format = formats[formatNdx].format;
935 testParameters.backingMode = backingModes[backingNdx].backingMode;
936 testParameters.compareOp = compareOp[compareNdx].op;
937 testParameters.wrapS = Sampler::REPEAT_GL;
938 testParameters.wrapT = Sampler::REPEAT_GL;
939 testParameters.size = 32;
941 testParameters.programs.push_back(PROGRAM_CUBE_SHADOW);
943 filterGroup->addChild(new TextureTestCase<TextureCubeShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
948 groupCube->addChild(filterGroup.release());
951 textureShadowTests->addChild(groupCube.release());
956 de::MovePtr<tcu::TestCaseGroup> group2DArray (new tcu::TestCaseGroup(testCtx, "2d_array", "2D texture array shadow lookup tests"));
958 for (int filterNdx = 0; filterNdx < DE_LENGTH_OF_ARRAY(filters); filterNdx++)
960 de::MovePtr<tcu::TestCaseGroup> filterGroup (new tcu::TestCaseGroup(testCtx, filters[filterNdx].name, ""));
962 for (int compareNdx = 0; compareNdx < DE_LENGTH_OF_ARRAY(compareOp); compareNdx++)
964 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
966 for (int backingNdx = 0; backingNdx < DE_LENGTH_OF_ARRAY(backingModes); backingNdx++)
968 const string name = string(backingModes[backingNdx].name) + compareOp[compareNdx].name + "_" + formats[formatNdx].name;
969 Texture2DArrayShadowTestCaseParameters testParameters;
971 testParameters.minFilter = filters[filterNdx].minFilter;
972 testParameters.magFilter = filters[filterNdx].magFilter;
973 testParameters.format = formats[formatNdx].format;
974 testParameters.backingMode = backingModes[backingNdx].backingMode;
975 testParameters.compareOp = compareOp[compareNdx].op;
976 testParameters.wrapS = Sampler::REPEAT_GL;
977 testParameters.wrapT = Sampler::REPEAT_GL;
978 testParameters.width = 32;
979 testParameters.height = 64;
980 testParameters.numLayers = 8;
982 testParameters.programs.push_back(PROGRAM_2D_ARRAY_SHADOW);
984 filterGroup->addChild(new TextureTestCase<Texture2DArrayShadowTestInstance>(testCtx, name.c_str(), "", testParameters));
989 group2DArray->addChild(filterGroup.release());
992 textureShadowTests->addChild(group2DArray.release());
998 tcu::TestCaseGroup* createTextureShadowTests (tcu::TestContext& testCtx)
1000 return createTestGroup(testCtx, "shadow", "Texture shadow tests.", populateTextureShadowTests);