1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Copyright (c) 2014 The Android Open Source Project
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 Compressed texture tests.
24 *//*--------------------------------------------------------------------*/
26 #include "vktTextureCompressedFormatTests.hpp"
29 #include "deStringUtil.hpp"
30 #include "tcuCompressedTexture.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "vkImageUtil.hpp"
34 #include "vktTestGroupUtil.hpp"
35 #include "vktTextureTestUtil.hpp"
47 using namespace glu::TextureTestUtil;
48 using namespace texture::util;
55 struct Compressed2DTestParameters : public Texture2DTestCaseParameters
59 class Compressed2DTestInstance : public TestInstance
62 typedef Compressed2DTestParameters ParameterType;
64 Compressed2DTestInstance (Context& context,
65 const ParameterType& testParameters);
66 tcu::TestStatus iterate (void);
69 Compressed2DTestInstance (const Compressed2DTestInstance& other);
70 Compressed2DTestInstance& operator= (const Compressed2DTestInstance& other);
72 const ParameterType& m_testParameters;
73 const tcu::CompressedTexFormat m_compressedFormat;
74 TestTexture2DSp m_texture;
75 TextureRenderer m_renderer;
78 Compressed2DTestInstance::Compressed2DTestInstance (Context& context,
79 const ParameterType& testParameters)
80 : TestInstance (context)
81 , m_testParameters (testParameters)
82 , m_compressedFormat (mapVkCompressedFormat(testParameters.format))
83 , m_texture (TestTexture2DSp(new pipeline::TestTexture2D(m_compressedFormat, testParameters.width, testParameters.height)))
84 , m_renderer (context, testParameters.sampleCount, testParameters.width, testParameters.height)
86 m_renderer.add2DTexture(m_texture);
89 tcu::TestStatus Compressed2DTestInstance::iterate (void)
91 tcu::TestLog& log = m_context.getTestContext().getLog();
92 const pipeline::TestTexture2D& texture = m_renderer.get2DTexture(0);
93 const tcu::TextureFormat textureFormat = texture.getTextureFormat();
94 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(textureFormat);
96 ReferenceParams sampleParams (TEXTURETYPE_2D);
97 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
98 vector<float> texCoord;
100 // Setup params for reference.
101 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
102 sampleParams.samplerType = SAMPLERTYPE_FLOAT;
103 sampleParams.lodMode = LODMODE_EXACT;
104 sampleParams.colorBias = formatInfo.lookupBias;
105 sampleParams.colorScale = formatInfo.lookupScale;
107 log << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
109 // Compute texture coordinates.
110 computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
112 m_renderer.renderQuad(rendered, 0, &texCoord[0], sampleParams);
114 // Compute reference.
115 const tcu::IVec4 formatBitDepth = getTextureFormatBitDepth(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
116 const tcu::PixelFormat pixelFormat (formatBitDepth[0], formatBitDepth[1], formatBitDepth[2], formatBitDepth[3]);
117 tcu::Surface referenceFrame (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
118 sampleTexture(tcu::SurfaceAccess(referenceFrame, pixelFormat), m_texture->getTexture(), &texCoord[0], sampleParams);
121 const bool isOk = compareImages(log, referenceFrame, rendered, pixelFormat.getColorThreshold() + tcu::RGBA(1, 1, 1, 1));
123 return isOk ? tcu::TestStatus::pass("Pass") : tcu::TestStatus::fail("Image verification failed");
126 void populateTextureCompressedFormatTests (tcu::TestCaseGroup* compressedTextureTests)
128 tcu::TestContext& testCtx = compressedTextureTests->getTestContext();
130 // ETC2 and EAC compressed formats.
132 const VkFormat format;
135 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK },
136 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK },
137 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK },
138 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK },
139 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK },
140 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK },
142 { VK_FORMAT_EAC_R11_UNORM_BLOCK },
143 { VK_FORMAT_EAC_R11_SNORM_BLOCK },
144 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK },
145 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK },
158 for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes); sizeNdx++)
159 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(etc2Formats); formatNdx++)
161 const string formatStr = de::toString(getFormatStr(etc2Formats[formatNdx].format));
162 const string nameBase = de::toLower(formatStr.substr(10));
164 Compressed2DTestParameters testParameters;
165 testParameters.format = etc2Formats[formatNdx].format;
166 testParameters.width = sizes[sizeNdx].width;
167 testParameters.height = sizes[sizeNdx].height;
168 testParameters.minFilter = tcu::Sampler::NEAREST;
169 testParameters.magFilter = tcu::Sampler::NEAREST;
170 testParameters.programs.push_back(PROGRAM_2D_FLOAT);
172 compressedTextureTests->addChild(new TextureTestCase<Compressed2DTestInstance>(testCtx, (nameBase + "_2d_" + sizes[sizeNdx].name).c_str(), (formatStr + ", TEXTURETYPE_2D").c_str(), testParameters));
178 tcu::TestCaseGroup* createTextureCompressedFormatTests (tcu::TestContext& testCtx)
180 return createTestGroup(testCtx, "compressed", "Texture compressed format tests.", populateTextureCompressedFormatTests);