Home | History | Annotate | Download | only in texture
      1 #ifndef _VKTTEXTURETESTUTIL_HPP
      2 #define _VKTTEXTURETESTUTIL_HPP
      3 /*------------------------------------------------------------------------
      4  * Vulkan Conformance Tests
      5  * ------------------------
      6  *
      7  * Copyright (c) 2016 The Khronos Group Inc.
      8  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
      9  * Copyright (c) 2014 The Android Open Source Project
     10  *
     11  * Licensed under the Apache License, Version 2.0 (the "License");
     12  * you may not use this file except in compliance with the License.
     13  * You may obtain a copy of the License at
     14  *
     15  *      http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  * Unless required by applicable law or agreed to in writing, software
     18  * distributed under the License is distributed on an "AS IS" BASIS,
     19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20  * See the License for the specific language governing permissions and
     21  * limitations under the License.
     22  *
     23  *//*!
     24  * \file
     25  * \brief Texture test utilities.
     26  *
     27  * About coordinates:
     28  *  + Quads consist of 2 triangles, rendered using explicit indices.
     29  *  + All TextureTestUtil functions and classes expect texture coordinates
     30  *    for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1).
     31  *//*--------------------------------------------------------------------*/
     32 
     33 #include "tcuDefs.hpp"
     34 #include "tcuSurface.hpp"
     35 
     36 #include "vkDefs.hpp"
     37 #include "vktTestCase.hpp"
     38 
     39 #include "gluShaderProgram.hpp"
     40 #include "gluTextureTestUtil.hpp"
     41 #include "deSharedPtr.hpp"
     42 
     43 #include "../pipeline/vktPipelineImageUtil.hpp"
     44 
     45 namespace vkt
     46 {
     47 
     48 namespace texture
     49 {
     50 
     51 namespace util
     52 {
     53 
     54 enum Program
     55 {
     56 	PROGRAM_2D_FLOAT = 0,
     57 	PROGRAM_2D_INT,
     58 	PROGRAM_2D_UINT,
     59 	PROGRAM_2D_SHADOW,
     60 
     61 	PROGRAM_2D_FLOAT_BIAS,
     62 	PROGRAM_2D_INT_BIAS,
     63 	PROGRAM_2D_UINT_BIAS,
     64 	PROGRAM_2D_SHADOW_BIAS,
     65 
     66 	PROGRAM_1D_FLOAT,
     67 	PROGRAM_1D_INT,
     68 	PROGRAM_1D_UINT,
     69 	PROGRAM_1D_SHADOW,
     70 
     71 	PROGRAM_1D_FLOAT_BIAS,
     72 	PROGRAM_1D_INT_BIAS,
     73 	PROGRAM_1D_UINT_BIAS,
     74 	PROGRAM_1D_SHADOW_BIAS,
     75 
     76 	PROGRAM_CUBE_FLOAT,
     77 	PROGRAM_CUBE_INT,
     78 	PROGRAM_CUBE_UINT,
     79 	PROGRAM_CUBE_SHADOW,
     80 
     81 	PROGRAM_CUBE_FLOAT_BIAS,
     82 	PROGRAM_CUBE_INT_BIAS,
     83 	PROGRAM_CUBE_UINT_BIAS,
     84 	PROGRAM_CUBE_SHADOW_BIAS,
     85 
     86 	PROGRAM_1D_ARRAY_FLOAT,
     87 	PROGRAM_1D_ARRAY_INT,
     88 	PROGRAM_1D_ARRAY_UINT,
     89 	PROGRAM_1D_ARRAY_SHADOW,
     90 
     91 	PROGRAM_2D_ARRAY_FLOAT,
     92 	PROGRAM_2D_ARRAY_INT,
     93 	PROGRAM_2D_ARRAY_UINT,
     94 	PROGRAM_2D_ARRAY_SHADOW,
     95 
     96 	PROGRAM_3D_FLOAT,
     97 	PROGRAM_3D_INT,
     98 	PROGRAM_3D_UINT,
     99 
    100 	PROGRAM_3D_FLOAT_BIAS,
    101 	PROGRAM_3D_INT_BIAS,
    102 	PROGRAM_3D_UINT_BIAS,
    103 
    104 	PROGRAM_CUBE_ARRAY_FLOAT,
    105 	PROGRAM_CUBE_ARRAY_INT,
    106 	PROGRAM_CUBE_ARRAY_UINT,
    107 	PROGRAM_CUBE_ARRAY_SHADOW,
    108 
    109 	PROGRAM_BUFFER_FLOAT,
    110 	PROGRAM_BUFFER_INT,
    111 	PROGRAM_BUFFER_UINT,
    112 
    113 	PROGRAM_LAST
    114 };
    115 
    116 void initializePrograms(vk::SourceCollections& programCollection, glu::Precision texCoordPrecision, const std::vector<Program>& programs);
    117 
    118 typedef de::SharedPtr<pipeline::TestTexture>		TestTextureSp;
    119 typedef de::SharedPtr<pipeline::TestTexture2D>		TestTexture2DSp;
    120 typedef de::SharedPtr<pipeline::TestTextureCube>	TestTextureCubeSp;
    121 typedef de::SharedPtr<pipeline::TestTexture2DArray>	TestTexture2DArraySp;
    122 typedef de::SharedPtr<pipeline::TestTexture3D>		TestTexture3DSp;
    123 
    124 class TextureBinding {
    125 public:
    126 	enum Type
    127 	{
    128 		TYPE_NONE = 0,
    129 		TYPE_2D,
    130 		TYPE_CUBE_MAP,
    131 		TYPE_2D_ARRAY,
    132 		TYPE_3D,
    133 
    134 		TYPE_LAST
    135 	};
    136 										TextureBinding				(Context& context);
    137 										TextureBinding				(Context& context, const TestTextureSp& textureData, const Type type);
    138 	vk::VkImage							getImage					(void) { return *m_textureImage; }
    139 	vk::VkImageView						getImageView				(void) { return *m_textureImageView; }
    140 	Type								getType						(void) { return m_type; }
    141 	const pipeline::TestTexture&		getTestTexture				(void) { return *m_textureData; }
    142 	void								updateTextureViewMipLevels	(deUint32 baseLevel, deUint32 maxLevel);
    143 
    144 private:
    145 										TextureBinding				(const TextureBinding&);	// not allowed!
    146 	TextureBinding&						operator=					(const TextureBinding&);	// not allowed!
    147 
    148 	void								updateTextureData			(const TestTextureSp& textureData, const Type type);
    149 
    150 	Context&							m_context;
    151 	Type								m_type;
    152 	TestTextureSp						m_textureData;
    153 	vk::Move<vk::VkImage>				m_textureImage;
    154 	de::MovePtr<vk::Allocation>			m_textureImageMemory;
    155 	vk::Move<vk::VkImageView>			m_textureImageView;
    156 };
    157 
    158 typedef de::SharedPtr<TextureBinding>	TextureBindingSp;
    159 
    160 class TextureRenderer
    161 {
    162 public:
    163 										TextureRenderer				(Context& context, vk::VkSampleCountFlagBits sampleCount, deUint32 renderWidth, deUint32 renderHeight);
    164 										~TextureRenderer			(void);
    165 
    166 	void								renderQuad					(tcu::Surface& result, int texUnit, const float* texCoord, glu::TextureTestUtil::TextureType texType);
    167 	void								renderQuad					(tcu::Surface& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
    168 	void								renderQuad					(tcu::Surface&									result,
    169 																	 const float*									positions,
    170 																	 const int										texUnit,
    171 																	 const float*									texCoord,
    172 																	 const glu::TextureTestUtil::ReferenceParams&	params,
    173 																	 const float									maxAnisotropy);
    174 
    175 	void								clearImage					(vk::VkImage image);
    176 	void								add2DTexture				(const TestTexture2DSp& texture);
    177 	const pipeline::TestTexture2D&		get2DTexture				(int textureIndex) const;
    178 
    179 	void								addCubeTexture				(const TestTextureCubeSp& texture);
    180 	const pipeline::TestTextureCube&	getCubeTexture				(int textureIndex) const;
    181 
    182 	void								add2DArrayTexture			(const TestTexture2DArraySp& texture);
    183 	const pipeline::TestTexture2DArray&	get2DArrayTexture			(int textureIndex) const;
    184 
    185 	void								add3DTexture				(const TestTexture3DSp& texture);
    186 	const pipeline::TestTexture3D&		get3DTexture				(int textureIndex) const;
    187 
    188 	void								setViewport					(float viewportX, float viewportY, float viewportW, float viewportH);
    189 
    190 	TextureBinding*						getTextureBinding			(int textureIndex) const;
    191 
    192 	deUint32							getRenderWidth				(void) const;
    193 	deUint32							getRenderHeight				(void) const;
    194 
    195 protected:
    196 										TextureRenderer				(const TextureRenderer& other);
    197 	TextureRenderer&					operator=					(const TextureRenderer& other);
    198 
    199 	Context&							m_context;
    200 	tcu::TestLog&						m_log;
    201 
    202 	const deUint32						m_renderWidth;
    203 	const deUint32						m_renderHeight;
    204 	const vk::VkSampleCountFlagBits		m_sampleCount;
    205 	const deBool						m_multisampling;
    206 
    207 	const vk::VkFormat					m_imageFormat;
    208 	const tcu::TextureFormat			m_textureFormat;
    209 
    210 	vk::Move<vk::VkImage>				m_image;
    211 	de::MovePtr<vk::Allocation>			m_imageMemory;
    212 	vk::Move<vk::VkImageView>			m_imageView;
    213 
    214 	vk::Move<vk::VkImage>				m_resolvedImage;
    215 	de::MovePtr<vk::Allocation>			m_resolvedImageMemory;
    216 	vk::Move<vk::VkImageView>			m_resolvedImageView;
    217 
    218 	vk::Move<vk::VkCommandPool>			m_commandPool;
    219 	vk::Move<vk::VkRenderPass>			m_renderPass;
    220 	vk::Move<vk::VkFramebuffer>			m_frameBuffer;
    221 
    222 	vk::Move<vk::VkDescriptorPool>		m_descriptorPool;
    223 
    224 	vk::Move<vk::VkBuffer>				m_uniformBuffer;
    225 	de::MovePtr<vk::Allocation>			m_uniformBufferMemory;
    226 	const vk::VkDeviceSize				m_uniformBufferSize;
    227 
    228 	vk::Move<vk::VkBuffer>				m_vertexIndexBuffer;
    229 	de::MovePtr<vk::Allocation>			m_vertexIndexBufferMemory;
    230 	static const vk::VkDeviceSize		s_vertexIndexBufferSize;
    231 	static const deUint16				s_vertexIndices[6];
    232 
    233 	vk::Move<vk::VkFence>				m_fence;
    234 
    235 	vk::Move<vk::VkBuffer>				m_resultBuffer;
    236 	de::MovePtr<vk::Allocation>			m_resultBufferMemory;
    237 	const vk::VkDeviceSize				m_resultBufferSize;
    238 
    239 	std::vector<TextureBindingSp>		m_textureBindings;
    240 
    241 	float								m_viewportOffsetX;
    242 	float								m_viewportOffsetY;
    243 	float								m_viewportWidth;
    244 	float								m_viewportHeight;
    245 
    246 private:
    247 	vk::Move<vk::VkDescriptorSet>		makeDescriptorSet			(const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout) const;
    248 	void								addImageTransitionBarrier	(vk::VkCommandBuffer commandBuffer, vk::VkImage image, vk::VkPipelineStageFlags srcStageMask, vk::VkPipelineStageFlags dstStageMask, vk::VkAccessFlags srcAccessMask, vk::VkAccessFlags dstAccessMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout) const;
    249 
    250 };
    251 
    252 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::WrapMode wrapW, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
    253 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
    254 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode);
    255 
    256 TestTexture2DSp loadTexture2D (const tcu::Archive& archive, const std::vector<std::string>& filenames);
    257 TestTextureCubeSp loadTextureCube (const tcu::Archive& archive, const std::vector<std::string>& filenames);
    258 
    259 template <typename INSTANCE_TYPE>
    260 class TextureTestCase : public TestCase
    261 {
    262 public:
    263 										TextureTestCase	(tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters)
    264 												: TestCase				(context, name, description)
    265 												, m_testsParameters		(testParameters)
    266 										{}
    267 
    268 	virtual TestInstance*				createInstance				(Context& context) const
    269 										{
    270 											return new INSTANCE_TYPE(context, m_testsParameters);
    271 										}
    272 
    273 	virtual void						initPrograms				(vk::SourceCollections& programCollection) const
    274 										{
    275 											initializePrograms(programCollection, m_testsParameters.texCoordPrecision, m_testsParameters.programs);
    276 										}
    277 
    278 protected:
    279 	const typename INSTANCE_TYPE::ParameterType m_testsParameters;
    280 };
    281 
    282 struct TextureCommonTestCaseParameters
    283 {
    284 								TextureCommonTestCaseParameters	(void);
    285 
    286 	vk::VkSampleCountFlagBits	sampleCount;
    287 	glu::Precision				texCoordPrecision;
    288 
    289 	tcu::Sampler::FilterMode	minFilter;
    290 	tcu::Sampler::FilterMode	magFilter;
    291 	tcu::Sampler::WrapMode		wrapS;
    292 	tcu::Sampler::WrapMode		wrapT;
    293 
    294 	vk::VkFormat				format;
    295 
    296 	std::vector<util::Program>	programs;
    297 };
    298 
    299 struct Texture2DTestCaseParameters : public TextureCommonTestCaseParameters
    300 {
    301 								Texture2DTestCaseParameters		(void);
    302 	int							width;
    303 	int							height;
    304 };
    305 
    306 struct TextureCubeTestCaseParameters : public TextureCommonTestCaseParameters
    307 {
    308 								TextureCubeTestCaseParameters	(void);
    309 	int							size;
    310 };
    311 
    312 struct Texture2DArrayTestCaseParameters : public Texture2DTestCaseParameters
    313 {
    314 								Texture2DArrayTestCaseParameters(void);
    315 	int							numLayers;
    316 };
    317 
    318 struct Texture3DTestCaseParameters : public Texture2DTestCaseParameters
    319 {
    320 								Texture3DTestCaseParameters		(void);
    321 	tcu::Sampler::WrapMode		wrapR;
    322 	int							depth;
    323 };
    324 
    325 } // util
    326 } // texture
    327 } // vkt
    328 
    329 #endif // _VKTTEXTURETESTUTIL_HPP
    330