Home | History | Annotate | Download | only in pipeline
      1 #ifndef _VKTPIPELINEIMAGEUTIL_HPP
      2 #define _VKTPIPELINEIMAGEUTIL_HPP
      3 /*------------------------------------------------------------------------
      4  * Vulkan Conformance Tests
      5  * ------------------------
      6  *
      7  * Copyright (c) 2015 The Khronos Group Inc.
      8  * Copyright (c) 2015 Imagination Technologies Ltd.
      9  *
     10  * Licensed under the Apache License, Version 2.0 (the "License");
     11  * you may not use this file except in compliance with the License.
     12  * You may obtain a copy of the License at
     13  *
     14  *      http://www.apache.org/licenses/LICENSE-2.0
     15  *
     16  * Unless required by applicable law or agreed to in writing, software
     17  * distributed under the License is distributed on an "AS IS" BASIS,
     18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     19  * See the License for the specific language governing permissions and
     20  * limitations under the License.
     21  *
     22  *//*!
     23  * \file
     24  * \brief Utilities for images.
     25  *//*--------------------------------------------------------------------*/
     26 
     27 #include "tcuDefs.hpp"
     28 #include "vkDefs.hpp"
     29 #include "vkDefs.hpp"
     30 #include "vkPlatform.hpp"
     31 #include "vkMemUtil.hpp"
     32 #include "vkRef.hpp"
     33 #include "tcuTexture.hpp"
     34 #include "tcuCompressedTexture.hpp"
     35 #include "deSharedPtr.hpp"
     36 
     37 namespace vkt
     38 {
     39 namespace pipeline
     40 {
     41 
     42 class TestTexture;
     43 
     44 enum BorderColor
     45 {
     46 	BORDER_COLOR_OPAQUE_BLACK,
     47 	BORDER_COLOR_OPAQUE_WHITE,
     48 	BORDER_COLOR_TRANSPARENT_BLACK,
     49 
     50 	BORDER_COLOR_COUNT
     51 };
     52 
     53 bool							isSupportedSamplableFormat	(const vk::InstanceInterface&	instanceInterface,
     54 															 vk::VkPhysicalDevice			device,
     55 															 vk::VkFormat					format);
     56 bool							isLinearFilteringSupported	(const vk::InstanceInterface&	instanceInterface,
     57 															 vk::VkPhysicalDevice			device,
     58 															 vk::VkFormat					format,
     59 															 vk::VkImageTiling				tiling);
     60 
     61 bool							isMinMaxFilteringSupported	(const vk::InstanceInterface&	instanceInterface,
     62 															 vk::VkPhysicalDevice			device,
     63 															 vk::VkFormat					format,
     64 															 vk::VkImageTiling				tiling);
     65 
     66 vk::VkBorderColor				getFormatBorderColor		(BorderColor color, vk::VkFormat format);
     67 
     68 void							getLookupScaleBias			(vk::VkFormat					format,
     69 															 tcu::Vec4&						lookupScale,
     70 															 tcu::Vec4&						lookupBias);
     71 
     72 /*--------------------------------------------------------------------*//*!
     73  * Gets a tcu::TextureLevel initialized with data from a VK color
     74  * attachment.
     75  *
     76  * The VkImage must be non-multisampled and able to be used as a source
     77  * operand for transfer operations.
     78  *//*--------------------------------------------------------------------*/
     79 de::MovePtr<tcu::TextureLevel>	readColorAttachment			 (const vk::DeviceInterface&	vk,
     80 															  vk::VkDevice					device,
     81 															  vk::VkQueue					queue,
     82 															  deUint32						queueFamilyIndex,
     83 															  vk::Allocator&				allocator,
     84 															  vk::VkImage					image,
     85 															  vk::VkFormat					format,
     86 															  const tcu::UVec2&				renderSize);
     87 
     88 /*--------------------------------------------------------------------*//*!
     89  * Uploads data from a test texture to a destination VK image.
     90  *
     91  * The VkImage must be non-multisampled and able to be used as a
     92  * destination operand for transfer operations.
     93  *//*--------------------------------------------------------------------*/
     94 void							uploadTestTexture			(const vk::DeviceInterface&		vk,
     95 															 vk::VkDevice					device,
     96 															 vk::VkQueue					queue,
     97 															 deUint32						queueFamilyIndex,
     98 															 vk::Allocator&					allocator,
     99 															 const TestTexture&				testTexture,
    100 															 vk::VkImage					destImage);
    101 
    102 /*--------------------------------------------------------------------*//*!
    103  * Uploads data from a test texture to a destination VK image using sparse
    104  * binding.
    105  *
    106  * The VkImage must be non-multisampled and able to be used as a
    107  * destination operand for transfer operations.
    108  *//*--------------------------------------------------------------------*/
    109 void							uploadTestTextureSparse		(const vk::DeviceInterface&						vk,
    110 															 vk::VkDevice									device,
    111 															 const vk::VkPhysicalDevice						physicalDevice,
    112 															 const vk::InstanceInterface&					instance,
    113 															 const vk::VkImageCreateInfo&					imageCreateInfo,
    114 															 vk::VkQueue									universalQueue,
    115 															 deUint32										universalQueueFamilyIndex,
    116 															 vk::VkQueue									sparseQueue,
    117 															 vk::Allocator&									allocator,
    118 															 std::vector<de::SharedPtr<vk::Allocation> >&	allocations,
    119 															 const TestTexture&								srcTexture,
    120 															 vk::VkImage									destImage);
    121 
    122 class TestTexture
    123 {
    124 public:
    125 												TestTexture					(const tcu::TextureFormat& format, int width, int height, int depth);
    126 												TestTexture					(const tcu::CompressedTexFormat& format, int width, int height, int depth);
    127 	virtual										~TestTexture				(void);
    128 
    129 	virtual int									getNumLevels				(void) const = 0;
    130 	virtual deUint32							getSize						(void) const;
    131 	virtual int									getArraySize				(void) const { return 1; }
    132 
    133 	virtual bool								isCompressed				(void) const { return !m_compressedLevels.empty(); }
    134 	virtual deUint32							getCompressedSize			(void) const;
    135 
    136 	virtual tcu::PixelBufferAccess				getLevel					(int level, int layer) = 0;
    137 	virtual const tcu::ConstPixelBufferAccess	getLevel					(int level, int layer) const = 0;
    138 
    139 	virtual tcu::CompressedTexture&				getCompressedLevel			(int level, int layer);
    140 	virtual const tcu::CompressedTexture&		getCompressedLevel			(int level, int layer) const;
    141 
    142 	virtual std::vector<vk::VkBufferImageCopy>	getBufferCopyRegions		(void) const;
    143 	virtual void								write						(deUint8* destPtr) const;
    144 	virtual de::MovePtr<TestTexture>			copy						(const tcu::TextureFormat) const = 0;
    145 
    146 	virtual const tcu::TextureFormat&			getTextureFormat			(void) const = 0;
    147 	virtual tcu::UVec3							getTextureDimension			(void) const = 0;
    148 
    149 protected:
    150 	void										populateLevels				(const std::vector<tcu::PixelBufferAccess>& levels);
    151 	void										populateCompressedLevels	(tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
    152 
    153 	static void									fillWithGradient			(const tcu::PixelBufferAccess& levelAccess);
    154 
    155 	void										copyToTexture				(TestTexture&) const;
    156 
    157 protected:
    158 	std::vector<tcu::CompressedTexture*>		m_compressedLevels;
    159 };
    160 
    161 class TestTexture1D : public TestTexture
    162 {
    163 private:
    164 	tcu::Texture1D								m_texture;
    165 
    166 public:
    167 												TestTexture1D		(const tcu::TextureFormat& format, int width);
    168 												TestTexture1D		(const tcu::CompressedTexFormat& format, int width);
    169 	virtual										~TestTexture1D		(void);
    170 
    171 	virtual int getNumLevels (void) const;
    172 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    173 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    174 	virtual const tcu::Texture1D&				getTexture			(void) const;
    175 	virtual tcu::Texture1D&						getTexture			(void);
    176 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    177 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
    178 
    179 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    180 };
    181 
    182 class TestTexture1DArray : public TestTexture
    183 {
    184 private:
    185 	tcu::Texture1DArray							m_texture;
    186 
    187 public:
    188 												TestTexture1DArray	(const tcu::TextureFormat& format, int width, int arraySize);
    189 												TestTexture1DArray	(const tcu::CompressedTexFormat& format, int width, int arraySize);
    190 	virtual										~TestTexture1DArray	(void);
    191 
    192 	virtual int									getNumLevels		(void) const;
    193 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    194 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    195 	virtual const tcu::Texture1DArray&			getTexture			(void) const;
    196 	virtual tcu::Texture1DArray&				getTexture			(void);
    197 	virtual int									getArraySize		(void) const;
    198 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    199 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
    200 
    201 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    202 };
    203 
    204 class TestTexture2D : public TestTexture
    205 {
    206 private:
    207 	tcu::Texture2D								m_texture;
    208 
    209 public:
    210 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height);
    211 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height, int miplevels);
    212 												TestTexture2D		(const tcu::CompressedTexFormat& format, int width, int height);
    213 	virtual										~TestTexture2D		(void);
    214 
    215 	virtual int									getNumLevels		(void) const;
    216 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    217 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    218 	virtual const tcu::Texture2D&				getTexture			(void) const;
    219 	virtual tcu::Texture2D&						getTexture			(void);
    220 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    221 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
    222 
    223 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    224 };
    225 
    226 class TestTexture2DArray : public TestTexture
    227 {
    228 private:
    229 	tcu::Texture2DArray	m_texture;
    230 
    231 public:
    232 												TestTexture2DArray	(const tcu::TextureFormat& format, int width, int height, int arraySize);
    233 												TestTexture2DArray	(const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
    234 	virtual										~TestTexture2DArray	(void);
    235 
    236 	virtual int									getNumLevels		(void) const;
    237 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    238 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    239 	virtual const tcu::Texture2DArray&			getTexture			(void) const;
    240 	virtual tcu::Texture2DArray&				getTexture			(void);
    241 	virtual int									getArraySize		(void) const;
    242 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    243 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
    244 
    245 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    246 };
    247 
    248 class TestTexture3D : public TestTexture
    249 {
    250 private:
    251 	tcu::Texture3D	m_texture;
    252 
    253 public:
    254 												TestTexture3D		(const tcu::TextureFormat& format, int width, int height, int depth);
    255 												TestTexture3D		(const tcu::CompressedTexFormat& format, int width, int height, int depth);
    256 	virtual										~TestTexture3D		(void);
    257 
    258 	virtual int									getNumLevels		(void) const;
    259 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    260 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    261 	virtual const tcu::Texture3D&				getTexture			(void) const;
    262 	virtual tcu::Texture3D&						getTexture			(void);
    263 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    264 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
    265 
    266 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    267 };
    268 
    269 class TestTextureCube : public TestTexture
    270 {
    271 private:
    272 	tcu::TextureCube							m_texture;
    273 
    274 public:
    275 												TestTextureCube			(const tcu::TextureFormat& format, int size);
    276 												TestTextureCube			(const tcu::CompressedTexFormat& format, int size);
    277 	virtual										~TestTextureCube		(void);
    278 
    279 	virtual int									getNumLevels			(void) const;
    280 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
    281 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
    282 	virtual int									getArraySize			(void) const;
    283 	virtual const tcu::TextureCube&				getTexture				(void) const;
    284 	virtual tcu::TextureCube&					getTexture				(void);
    285 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
    286 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
    287 
    288 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
    289 };
    290 
    291 class TestTextureCubeArray: public TestTexture
    292 {
    293 private:
    294 	tcu::TextureCubeArray						m_texture;
    295 
    296 public:
    297 												TestTextureCubeArray	(const tcu::TextureFormat& format, int size, int arraySize);
    298 												TestTextureCubeArray	(const tcu::CompressedTexFormat& format, int size, int arraySize);
    299 	virtual										~TestTextureCubeArray	(void);
    300 
    301 	virtual int									getNumLevels			(void) const;
    302 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
    303 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
    304 	virtual int									getArraySize			(void) const;
    305 	virtual const tcu::TextureCubeArray&		getTexture				(void) const;
    306 	virtual tcu::TextureCubeArray&				getTexture				(void);
    307 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
    308 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
    309 
    310 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
    311 };
    312 
    313 } // pipeline
    314 } // vkt
    315 
    316 #endif // _VKTPIPELINEIMAGEUTIL_HPP
    317