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 
     36 namespace vkt
     37 {
     38 namespace pipeline
     39 {
     40 
     41 class TestTexture;
     42 
     43 enum BorderColor
     44 {
     45 	BORDER_COLOR_OPAQUE_BLACK,
     46 	BORDER_COLOR_OPAQUE_WHITE,
     47 	BORDER_COLOR_TRANSPARENT_BLACK,
     48 
     49 	BORDER_COLOR_COUNT
     50 };
     51 
     52 bool							isSupportedSamplableFormat	(const vk::InstanceInterface&	instanceInterface,
     53 															 vk::VkPhysicalDevice			device,
     54 															 vk::VkFormat					format);
     55 bool							isLinearFilteringSupported	(const vk::InstanceInterface&	instanceInterface,
     56 															 vk::VkPhysicalDevice			device,
     57 															 vk::VkFormat					format,
     58 															 vk::VkImageTiling				tiling);
     59 
     60 vk::VkBorderColor				getFormatBorderColor		(BorderColor color, vk::VkFormat format);
     61 
     62 void							getLookupScaleBias			(vk::VkFormat					format,
     63 															 tcu::Vec4&						lookupScale,
     64 															 tcu::Vec4&						lookupBias);
     65 
     66 /*--------------------------------------------------------------------*//*!
     67  * Gets a tcu::TextureLevel initialized with data from a VK color
     68  * attachment.
     69  *
     70  * The VkImage must be non-multisampled and able to be used as a source
     71  * operand for transfer operations.
     72  *//*--------------------------------------------------------------------*/
     73 de::MovePtr<tcu::TextureLevel>	readColorAttachment			 (const vk::DeviceInterface&	vk,
     74 															  vk::VkDevice					device,
     75 															  vk::VkQueue					queue,
     76 															  deUint32						queueFamilyIndex,
     77 															  vk::Allocator&				allocator,
     78 															  vk::VkImage					image,
     79 															  vk::VkFormat					format,
     80 															  const tcu::UVec2&				renderSize);
     81 
     82 /*--------------------------------------------------------------------*//*!
     83  * Uploads data from a test texture to a destination VK image.
     84  *
     85  * The VkImage must be non-multisampled and able to be used as a
     86  * destination operand for transfer operations.
     87  *//*--------------------------------------------------------------------*/
     88 void							uploadTestTexture			(const vk::DeviceInterface&		vk,
     89 															 vk::VkDevice					device,
     90 															 vk::VkQueue					queue,
     91 															 deUint32						queueFamilyIndex,
     92 															 vk::Allocator&					allocator,
     93 															 const TestTexture&				testTexture,
     94 															 vk::VkImage					destImage);
     95 
     96 class TestTexture
     97 {
     98 public:
     99 												TestTexture					(const tcu::TextureFormat& format, int width, int height, int depth);
    100 												TestTexture					(const tcu::CompressedTexFormat& format, int width, int height, int depth);
    101 	virtual										~TestTexture				(void);
    102 
    103 	virtual int									getNumLevels				(void) const = 0;
    104 	virtual deUint32							getSize						(void) const;
    105 	virtual int									getArraySize				(void) const { return 1; }
    106 
    107 	virtual bool								isCompressed				(void) const { return !m_compressedLevels.empty(); }
    108 	virtual deUint32							getCompressedSize			(void) const;
    109 
    110 	virtual tcu::PixelBufferAccess				getLevel					(int level, int layer) = 0;
    111 	virtual const tcu::ConstPixelBufferAccess	getLevel					(int level, int layer) const = 0;
    112 
    113 	virtual tcu::CompressedTexture&				getCompressedLevel			(int level, int layer);
    114 	virtual const tcu::CompressedTexture&		getCompressedLevel			(int level, int layer) const;
    115 
    116 	virtual std::vector<vk::VkBufferImageCopy>	getBufferCopyRegions		(void) const;
    117 	virtual void								write						(deUint8* destPtr) const;
    118 	virtual de::MovePtr<TestTexture>			copy						(const tcu::TextureFormat) const = 0;
    119 
    120 	virtual const tcu::TextureFormat&			getTextureFormat			(void) const = 0;
    121 	virtual tcu::UVec3							getTextureDimension			(void) const = 0;
    122 
    123 protected:
    124 	void										populateLevels				(const std::vector<tcu::PixelBufferAccess>& levels);
    125 	void										populateCompressedLevels	(tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
    126 
    127 	static void									fillWithGradient			(const tcu::PixelBufferAccess& levelAccess);
    128 
    129 	void										copyToTexture				(TestTexture&) const;
    130 
    131 protected:
    132 	std::vector<tcu::CompressedTexture*>		m_compressedLevels;
    133 };
    134 
    135 class TestTexture1D : public TestTexture
    136 {
    137 private:
    138 	tcu::Texture1D								m_texture;
    139 
    140 public:
    141 												TestTexture1D		(const tcu::TextureFormat& format, int width);
    142 												TestTexture1D		(const tcu::CompressedTexFormat& format, int width);
    143 	virtual										~TestTexture1D		(void);
    144 
    145 	virtual int getNumLevels (void) const;
    146 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    147 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    148 	virtual const tcu::Texture1D&				getTexture			(void) const;
    149 	virtual tcu::Texture1D&						getTexture			(void);
    150 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    151 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
    152 
    153 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    154 };
    155 
    156 class TestTexture1DArray : public TestTexture
    157 {
    158 private:
    159 	tcu::Texture1DArray							m_texture;
    160 
    161 public:
    162 												TestTexture1DArray	(const tcu::TextureFormat& format, int width, int arraySize);
    163 												TestTexture1DArray	(const tcu::CompressedTexFormat& format, int width, int arraySize);
    164 	virtual										~TestTexture1DArray	(void);
    165 
    166 	virtual int									getNumLevels		(void) const;
    167 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    168 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    169 	virtual const tcu::Texture1DArray&			getTexture			(void) const;
    170 	virtual tcu::Texture1DArray&				getTexture			(void);
    171 	virtual int									getArraySize		(void) const;
    172 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    173 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
    174 
    175 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    176 };
    177 
    178 class TestTexture2D : public TestTexture
    179 {
    180 private:
    181 	tcu::Texture2D								m_texture;
    182 
    183 public:
    184 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height);
    185 												TestTexture2D		(const tcu::CompressedTexFormat& format, int width, int height);
    186 	virtual										~TestTexture2D		(void);
    187 
    188 	virtual int									getNumLevels		(void) const;
    189 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    190 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    191 	virtual const tcu::Texture2D&				getTexture			(void) const;
    192 	virtual tcu::Texture2D&						getTexture			(void);
    193 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    194 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
    195 
    196 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    197 };
    198 
    199 class TestTexture2DArray : public TestTexture
    200 {
    201 private:
    202 	tcu::Texture2DArray	m_texture;
    203 
    204 public:
    205 												TestTexture2DArray	(const tcu::TextureFormat& format, int width, int height, int arraySize);
    206 												TestTexture2DArray	(const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
    207 	virtual										~TestTexture2DArray	(void);
    208 
    209 	virtual int									getNumLevels		(void) const;
    210 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    211 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    212 	virtual const tcu::Texture2DArray&			getTexture			(void) const;
    213 	virtual tcu::Texture2DArray&				getTexture			(void);
    214 	virtual int									getArraySize		(void) const;
    215 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    216 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
    217 
    218 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    219 };
    220 
    221 class TestTexture3D : public TestTexture
    222 {
    223 private:
    224 	tcu::Texture3D	m_texture;
    225 
    226 public:
    227 												TestTexture3D		(const tcu::TextureFormat& format, int width, int height, int depth);
    228 												TestTexture3D		(const tcu::CompressedTexFormat& format, int width, int height, int depth);
    229 	virtual										~TestTexture3D		(void);
    230 
    231 	virtual int									getNumLevels		(void) const;
    232 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
    233 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
    234 	virtual const tcu::Texture3D&				getTexture			(void) const;
    235 	virtual tcu::Texture3D&						getTexture			(void);
    236 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
    237 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
    238 
    239 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
    240 };
    241 
    242 class TestTextureCube : public TestTexture
    243 {
    244 private:
    245 	tcu::TextureCube							m_texture;
    246 
    247 public:
    248 												TestTextureCube			(const tcu::TextureFormat& format, int size);
    249 												TestTextureCube			(const tcu::CompressedTexFormat& format, int size);
    250 	virtual										~TestTextureCube		(void);
    251 
    252 	virtual int									getNumLevels			(void) const;
    253 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
    254 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
    255 	virtual int									getArraySize			(void) const;
    256 	virtual const tcu::TextureCube&				getTexture				(void) const;
    257 	virtual tcu::TextureCube&					getTexture				(void);
    258 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
    259 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
    260 
    261 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
    262 };
    263 
    264 class TestTextureCubeArray: public TestTexture
    265 {
    266 private:
    267 	tcu::TextureCubeArray						m_texture;
    268 
    269 public:
    270 												TestTextureCubeArray	(const tcu::TextureFormat& format, int size, int arraySize);
    271 												TestTextureCubeArray	(const tcu::CompressedTexFormat& format, int size, int arraySize);
    272 	virtual										~TestTextureCubeArray	(void);
    273 
    274 	virtual int									getNumLevels			(void) const;
    275 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
    276 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
    277 	virtual int									getArraySize			(void) const;
    278 	virtual const tcu::TextureCubeArray&		getTexture				(void) const;
    279 	virtual tcu::TextureCubeArray&				getTexture				(void);
    280 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
    281 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
    282 
    283 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
    284 };
    285 
    286 } // pipeline
    287 } // vkt
    288 
    289 #endif // _VKTPIPELINEIMAGEUTIL_HPP
    290