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 	BORDER_COLOR_CUSTOM,
50 
51 	BORDER_COLOR_COUNT
52 };
53 
54 bool							isSupportedSamplableFormat	(const vk::InstanceInterface&	instanceInterface,
55 															 vk::VkPhysicalDevice			device,
56 															 vk::VkFormat					format);
57 bool							isLinearFilteringSupported	(const vk::InstanceInterface&	instanceInterface,
58 															 vk::VkPhysicalDevice			device,
59 															 vk::VkFormat					format,
60 															 vk::VkImageTiling				tiling);
61 
62 bool							isMinMaxFilteringSupported	(const vk::InstanceInterface&	instanceInterface,
63 															 vk::VkPhysicalDevice			device,
64 															 vk::VkFormat					format,
65 															 vk::VkImageTiling				tiling);
66 
67 vk::VkBorderColor				getFormatBorderColor		(BorderColor color, vk::VkFormat format);
68 
69 rr::GenericVec4					getFormatCustomBorderColor	(tcu::Vec4 floatValue, tcu::IVec4 intValue, vk::VkFormat format);
70 
71 void							getLookupScaleBias			(vk::VkFormat					format,
72 															 tcu::Vec4&						lookupScale,
73 															 tcu::Vec4&						lookupBias);
74 
75 /*--------------------------------------------------------------------*//*!
76  * Gets a tcu::TextureLevel initialized with data from a VK color
77  * attachment.
78  *
79  * The VkImage must be non-multisampled and able to be used as a source
80  * operand for transfer operations.
81  *//*--------------------------------------------------------------------*/
82 de::MovePtr<tcu::TextureLevel>	readColorAttachment			 (const vk::DeviceInterface&	vk,
83 															  vk::VkDevice					device,
84 															  vk::VkQueue					queue,
85 															  deUint32						queueFamilyIndex,
86 															  vk::Allocator&				allocator,
87 															  vk::VkImage					image,
88 															  vk::VkFormat					format,
89 															  const tcu::UVec2&				renderSize);
90 
91 
92 /*--------------------------------------------------------------------*//*!
93  * Gets a tcu::TextureLevel initialized with data from a VK depth
94  * attachment.
95  *
96  * The VkImage must be non-multisampled and able to be used as a source
97  * operand for transfer operations.
98  *//*--------------------------------------------------------------------*/
99 de::MovePtr<tcu::TextureLevel>	readDepthAttachment			 (const vk::DeviceInterface&	vk,
100 															  vk::VkDevice					device,
101 															  vk::VkQueue					queue,
102 															  deUint32						queueFamilyIndex,
103 															  vk::Allocator&				allocator,
104 															  vk::VkImage					image,
105 															  vk::VkFormat					format,
106 															  const tcu::UVec2&				renderSize,
107 															  vk::VkImageLayout				currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
108 
109 /*--------------------------------------------------------------------*//*!
110  * Gets a tcu::TextureLevel initialized with data from a VK stencil
111  * attachment.
112  *
113  * The VkImage must be non-multisampled and able to be used as a source
114  * operand for transfer operations.
115  *//*--------------------------------------------------------------------*/
116 de::MovePtr<tcu::TextureLevel>	readStencilAttachment		 (const vk::DeviceInterface&	vk,
117 															  vk::VkDevice					device,
118 															  vk::VkQueue					queue,
119 															  deUint32						queueFamilyIndex,
120 															  vk::Allocator&				allocator,
121 															  vk::VkImage					image,
122 															  vk::VkFormat					format,
123 															  const tcu::UVec2&				renderSize,
124 															  vk::VkImageLayout				currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
125 
126 
127 /*--------------------------------------------------------------------*//*!
128  * Uploads data from a test texture to a destination VK image.
129  *
130  * The VkImage must be non-multisampled and able to be used as a
131  * destination operand for transfer operations.
132  *//*--------------------------------------------------------------------*/
133 void							uploadTestTexture			(const vk::DeviceInterface&		vk,
134 															 vk::VkDevice					device,
135 															 vk::VkQueue					queue,
136 															 deUint32						queueFamilyIndex,
137 															 vk::Allocator&					allocator,
138 															 const TestTexture&				testTexture,
139 															 vk::VkImage					destImage);
140 
141 /*--------------------------------------------------------------------*//*!
142  * Uploads data from a test texture to a destination VK image using sparse
143  * binding.
144  *
145  * The VkImage must be non-multisampled and able to be used as a
146  * destination operand for transfer operations.
147  *//*--------------------------------------------------------------------*/
148 void							uploadTestTextureSparse		(const vk::DeviceInterface&						vk,
149 															 vk::VkDevice									device,
150 															 const vk::VkPhysicalDevice						physicalDevice,
151 															 const vk::InstanceInterface&					instance,
152 															 const vk::VkImageCreateInfo&					imageCreateInfo,
153 															 vk::VkQueue									universalQueue,
154 															 deUint32										universalQueueFamilyIndex,
155 															 vk::VkQueue									sparseQueue,
156 															 vk::Allocator&									allocator,
157 															 std::vector<de::SharedPtr<vk::Allocation> >&	allocations,
158 															 const TestTexture&								srcTexture,
159 															 vk::VkImage									destImage);
160 
161 class TestTexture
162 {
163 public:
164 												TestTexture					(const tcu::TextureFormat& format, int width, int height, int depth);
165 												TestTexture					(const tcu::CompressedTexFormat& format, int width, int height, int depth);
166 	virtual										~TestTexture				(void);
167 
168 	virtual int									getNumLevels				(void) const = 0;
169 	virtual deUint32							getSize						(void) const;
getArraySize(void) const170 	virtual int									getArraySize				(void) const { return 1; }
171 
isCompressed(void) const172 	virtual bool								isCompressed				(void) const { return !m_compressedLevels.empty(); }
173 	virtual deUint32							getCompressedSize			(void) const;
174 
175 	virtual tcu::PixelBufferAccess				getLevel					(int level, int layer) = 0;
176 	virtual const tcu::ConstPixelBufferAccess	getLevel					(int level, int layer) const = 0;
177 
178 	virtual tcu::CompressedTexture&				getCompressedLevel			(int level, int layer);
179 	virtual const tcu::CompressedTexture&		getCompressedLevel			(int level, int layer) const;
180 
181 	virtual std::vector<vk::VkBufferImageCopy>	getBufferCopyRegions		(void) const;
182 	virtual void								write						(deUint8* destPtr) const;
183 	virtual de::MovePtr<TestTexture>			copy						(const tcu::TextureFormat) const = 0;
184 
185 	virtual const tcu::TextureFormat&			getTextureFormat			(void) const = 0;
186 	virtual tcu::UVec3							getTextureDimension			(void) const = 0;
187 
188 protected:
189 	void										populateLevels				(const std::vector<tcu::PixelBufferAccess>& levels);
190 	void										populateCompressedLevels	(tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
191 
192 	static void									fillWithGradient			(const tcu::PixelBufferAccess& levelAccess);
193 
194 	void										copyToTexture				(TestTexture&) const;
195 
196 protected:
197 	std::vector<tcu::CompressedTexture*>		m_compressedLevels;
198 };
199 
200 class TestTexture1D : public TestTexture
201 {
202 private:
203 	tcu::Texture1D								m_texture;
204 
205 public:
206 												TestTexture1D		(const tcu::TextureFormat& format, int width);
207 												TestTexture1D		(const tcu::CompressedTexFormat& format, int width);
208 	virtual										~TestTexture1D		(void);
209 
210 	virtual int getNumLevels (void) const;
211 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
212 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
213 	virtual const tcu::Texture1D&				getTexture			(void) const;
214 	virtual tcu::Texture1D&						getTexture			(void);
getTextureFormat(void) const215 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const216 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
217 
218 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
219 };
220 
221 class TestTexture1DArray : public TestTexture
222 {
223 private:
224 	tcu::Texture1DArray							m_texture;
225 
226 public:
227 												TestTexture1DArray	(const tcu::TextureFormat& format, int width, int arraySize);
228 												TestTexture1DArray	(const tcu::CompressedTexFormat& format, int width, int arraySize);
229 	virtual										~TestTexture1DArray	(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::Texture1DArray&			getTexture			(void) const;
235 	virtual tcu::Texture1DArray&				getTexture			(void);
236 	virtual int									getArraySize		(void) const;
getTextureFormat(void) const237 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const238 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
239 
240 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
241 };
242 
243 class TestTexture2D : public TestTexture
244 {
245 private:
246 	tcu::Texture2D								m_texture;
247 
248 public:
249 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height);
250 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height, int miplevels);
251 												TestTexture2D		(const tcu::CompressedTexFormat& format, int width, int height);
252 	virtual										~TestTexture2D		(void);
253 
254 	virtual int									getNumLevels		(void) const;
255 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
256 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
257 	virtual const tcu::Texture2D&				getTexture			(void) const;
258 	virtual tcu::Texture2D&						getTexture			(void);
getTextureFormat(void) const259 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const260 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
261 
262 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
263 };
264 
265 class TestTexture2DArray : public TestTexture
266 {
267 private:
268 	tcu::Texture2DArray	m_texture;
269 
270 public:
271 												TestTexture2DArray	(const tcu::TextureFormat& format, int width, int height, int arraySize);
272 												TestTexture2DArray	(const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
273 	virtual										~TestTexture2DArray	(void);
274 
275 	virtual int									getNumLevels		(void) const;
276 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
277 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
278 	virtual const tcu::Texture2DArray&			getTexture			(void) const;
279 	virtual tcu::Texture2DArray&				getTexture			(void);
280 	virtual int									getArraySize		(void) const;
getTextureFormat(void) const281 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const282 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
283 
284 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
285 };
286 
287 class TestTexture3D : public TestTexture
288 {
289 private:
290 	tcu::Texture3D	m_texture;
291 
292 public:
293 												TestTexture3D		(const tcu::TextureFormat& format, int width, int height, int depth);
294 												TestTexture3D		(const tcu::CompressedTexFormat& format, int width, int height, int depth);
295 	virtual										~TestTexture3D		(void);
296 
297 	virtual int									getNumLevels		(void) const;
298 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
299 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
300 	virtual const tcu::Texture3D&				getTexture			(void) const;
301 	virtual tcu::Texture3D&						getTexture			(void);
getTextureFormat(void) const302 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const303 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
304 
305 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
306 };
307 
308 class TestTextureCube : public TestTexture
309 {
310 private:
311 	tcu::TextureCube							m_texture;
312 
313 public:
314 												TestTextureCube			(const tcu::TextureFormat& format, int size);
315 												TestTextureCube			(const tcu::CompressedTexFormat& format, int size);
316 	virtual										~TestTextureCube		(void);
317 
318 	virtual int									getNumLevels			(void) const;
319 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
320 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
321 	virtual int									getArraySize			(void) const;
322 	virtual const tcu::TextureCube&				getTexture				(void) const;
323 	virtual tcu::TextureCube&					getTexture				(void);
getTextureFormat(void) const324 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const325 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
326 
327 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
328 };
329 
330 class TestTextureCubeArray: public TestTexture
331 {
332 private:
333 	tcu::TextureCubeArray						m_texture;
334 
335 public:
336 												TestTextureCubeArray	(const tcu::TextureFormat& format, int size, int arraySize);
337 												TestTextureCubeArray	(const tcu::CompressedTexFormat& format, int size, int arraySize);
338 	virtual										~TestTextureCubeArray	(void);
339 
340 	virtual int									getNumLevels			(void) const;
341 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
342 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
343 	virtual int									getArraySize			(void) const;
344 	virtual const tcu::TextureCubeArray&		getTexture				(void) const;
345 	virtual tcu::TextureCubeArray&				getTexture				(void);
getTextureFormat(void) const346 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const347 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
348 
349 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
350 };
351 
352 } // pipeline
353 } // vkt
354 
355 #endif // _VKTPIPELINEIMAGEUTIL_HPP
356