Home | History | Annotate | Download | only in texture
      1 /*-------------------------------------------------------------------------
      2  * Vulkan Conformance Tests
      3  * ------------------------
      4  *
      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
      8  *
      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
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     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.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Compressed texture tests.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "vktTextureCompressedFormatTests.hpp"
     27 
     28 #include "deString.h"
     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"
     36 #include <string>
     37 #include <vector>
     38 
     39 namespace vkt
     40 {
     41 namespace texture
     42 {
     43 namespace
     44 {
     45 
     46 using namespace vk;
     47 using namespace glu::TextureTestUtil;
     48 using namespace texture::util;
     49 
     50 using std::string;
     51 using std::vector;
     52 using tcu::Sampler;
     53 using tcu::TestLog;
     54 
     55 struct Compressed2DTestParameters : public Texture2DTestCaseParameters
     56 {
     57 };
     58 
     59 class Compressed2DTestInstance : public TestInstance
     60 {
     61 public:
     62 	typedef Compressed2DTestParameters	ParameterType;
     63 
     64 										Compressed2DTestInstance	(Context&				context,
     65 																	 const ParameterType&	testParameters);
     66 	tcu::TestStatus						iterate						(void);
     67 
     68 private:
     69 										Compressed2DTestInstance	(const Compressed2DTestInstance& other);
     70 	Compressed2DTestInstance&			operator=					(const Compressed2DTestInstance& other);
     71 
     72 	const ParameterType&				m_testParameters;
     73 	const tcu::CompressedTexFormat		m_compressedFormat;
     74 	TestTexture2DSp						m_texture;
     75 	TextureRenderer						m_renderer;
     76 };
     77 
     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)
     85 {
     86 	m_renderer.add2DTexture(m_texture);
     87 }
     88 
     89 tcu::TestStatus Compressed2DTestInstance::iterate (void)
     90 {
     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);
     95 
     96 	ReferenceParams					sampleParams	(TEXTURETYPE_2D);
     97 	tcu::Surface					rendered		(m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
     98 	vector<float>					texCoord;
     99 
    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;
    106 
    107 	log << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
    108 
    109 	// Compute texture coordinates.
    110 	computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
    111 
    112 	m_renderer.renderQuad(rendered, 0, &texCoord[0], sampleParams);
    113 
    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);
    119 
    120 	// Compare and log.
    121 	const bool isOk = compareImages(log, referenceFrame, rendered, pixelFormat.getColorThreshold() + tcu::RGBA(1, 1, 1, 1));
    122 
    123 	return isOk ? tcu::TestStatus::pass("Pass") : tcu::TestStatus::fail("Image verification failed");
    124 }
    125 
    126 void populateTextureCompressedFormatTests (tcu::TestCaseGroup* compressedTextureTests)
    127 {
    128 	tcu::TestContext&	testCtx	= compressedTextureTests->getTestContext();
    129 
    130 	// ETC2 and EAC compressed formats.
    131 	const struct {
    132 		const VkFormat	format;
    133 	} etc2Formats[] =
    134 	{
    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	},
    141 
    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		},
    146 	};
    147 
    148 	const struct {
    149 		const int	width;
    150 		const int	height;
    151 		const char*	name;
    152 	} sizes[] =
    153 	{
    154 		{ 128, 64, "pot"  },
    155 		{ 51,  65, "npot" },
    156 	};
    157 
    158 	for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes); sizeNdx++)
    159 	for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(etc2Formats); formatNdx++)
    160 	{
    161 		const string	formatStr	= de::toString(getFormatStr(etc2Formats[formatNdx].format));
    162 		const string	nameBase	= de::toLower(formatStr.substr(10));
    163 
    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);
    171 
    172 		compressedTextureTests->addChild(new TextureTestCase<Compressed2DTestInstance>(testCtx, (nameBase + "_2d_" + sizes[sizeNdx].name).c_str(), (formatStr + ", TEXTURETYPE_2D").c_str(), testParameters));
    173 	}
    174 }
    175 
    176 } // anonymous
    177 
    178 tcu::TestCaseGroup* createTextureCompressedFormatTests (tcu::TestContext& testCtx)
    179 {
    180 	return createTestGroup(testCtx, "compressed", "Texture compressed format tests.", populateTextureCompressedFormatTests);
    181 }
    182 
    183 } // texture
    184 } // vkt
    185