• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 															  vk::VkImageLayout				oldLayout = vk::VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
91 
92 
93 /*--------------------------------------------------------------------*//*!
94  * Gets a tcu::TextureLevel initialized with data from a VK depth
95  * attachment.
96  *
97  * The VkImage must be non-multisampled and able to be used as a source
98  * operand for transfer operations.
99  *//*--------------------------------------------------------------------*/
100 de::MovePtr<tcu::TextureLevel>	readDepthAttachment			 (const vk::DeviceInterface&	vk,
101 															  vk::VkDevice					device,
102 															  vk::VkQueue					queue,
103 															  deUint32						queueFamilyIndex,
104 															  vk::Allocator&				allocator,
105 															  vk::VkImage					image,
106 															  vk::VkFormat					format,
107 															  const tcu::UVec2&				renderSize,
108 															  vk::VkImageLayout				currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
109 
110 /*--------------------------------------------------------------------*//*!
111  * Gets a tcu::TextureLevel initialized with data from a VK stencil
112  * attachment.
113  *
114  * The VkImage must be non-multisampled and able to be used as a source
115  * operand for transfer operations.
116  *//*--------------------------------------------------------------------*/
117 de::MovePtr<tcu::TextureLevel>	readStencilAttachment		 (const vk::DeviceInterface&	vk,
118 															  vk::VkDevice					device,
119 															  vk::VkQueue					queue,
120 															  deUint32						queueFamilyIndex,
121 															  vk::Allocator&				allocator,
122 															  vk::VkImage					image,
123 															  vk::VkFormat					format,
124 															  const tcu::UVec2&				renderSize,
125 															  vk::VkImageLayout				currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
126 
127 
128 /*--------------------------------------------------------------------*//*!
129  * Uploads data from a test texture to a destination VK image.
130  *
131  * The VkImage must be non-multisampled and able to be used as a
132  * destination operand for transfer operations.
133  *//*--------------------------------------------------------------------*/
134 void							uploadTestTexture			(const vk::DeviceInterface&		vk,
135 															 vk::VkDevice					device,
136 															 vk::VkQueue					queue,
137 															 deUint32						queueFamilyIndex,
138 															 vk::Allocator&					allocator,
139 															 const TestTexture&				testTexture,
140 															 vk::VkImage					destImage);
141 
142 /*--------------------------------------------------------------------*//*!
143  * Uploads data from a test texture to a destination VK image using sparse
144  * binding.
145  *
146  * The VkImage must be non-multisampled and able to be used as a
147  * destination operand for transfer operations.
148  *//*--------------------------------------------------------------------*/
149 void							uploadTestTextureSparse		(const vk::DeviceInterface&						vk,
150 															 vk::VkDevice									device,
151 															 const vk::VkPhysicalDevice						physicalDevice,
152 															 const vk::InstanceInterface&					instance,
153 															 const vk::VkImageCreateInfo&					imageCreateInfo,
154 															 vk::VkQueue									universalQueue,
155 															 deUint32										universalQueueFamilyIndex,
156 															 vk::VkQueue									sparseQueue,
157 															 vk::Allocator&									allocator,
158 															 std::vector<de::SharedPtr<vk::Allocation> >&	allocations,
159 															 const TestTexture&								srcTexture,
160 															 vk::VkImage									destImage);
161 
162 class TestTexture
163 {
164 public:
165 												TestTexture					(const tcu::TextureFormat& format, int width, int height, int depth);
166 												TestTexture					(const tcu::CompressedTexFormat& format, int width, int height, int depth);
167 	virtual										~TestTexture				(void);
168 
169 	virtual int									getNumLevels				(void) const = 0;
170 	virtual deUint32							getSize						(void) const;
getArraySize(void) const171 	virtual int									getArraySize				(void) const { return 1; }
172 
isCompressed(void) const173 	virtual bool								isCompressed				(void) const { return !m_compressedLevels.empty(); }
174 	virtual deUint32							getCompressedSize			(void) const;
175 
176 	virtual tcu::PixelBufferAccess				getLevel					(int level, int layer) = 0;
177 	virtual const tcu::ConstPixelBufferAccess	getLevel					(int level, int layer) const = 0;
178 
179 	virtual tcu::CompressedTexture&				getCompressedLevel			(int level, int layer);
180 	virtual const tcu::CompressedTexture&		getCompressedLevel			(int level, int layer) const;
181 
182 	virtual std::vector<vk::VkBufferImageCopy>	getBufferCopyRegions		(void) const;
183 	virtual void								write						(deUint8* destPtr) const;
184 	virtual de::MovePtr<TestTexture>			copy						(const tcu::TextureFormat) const = 0;
185 
186 	virtual const tcu::TextureFormat&			getTextureFormat			(void) const = 0;
187 	virtual tcu::UVec3							getTextureDimension			(void) const = 0;
188 
189 protected:
190 	void										populateLevels				(const std::vector<tcu::PixelBufferAccess>& levels);
191 	void										populateCompressedLevels	(tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
192 
193 	static void									fillWithGradient			(const tcu::PixelBufferAccess& levelAccess);
194 
195 	void										copyToTexture				(TestTexture&) const;
196 
197 protected:
198 	std::vector<tcu::CompressedTexture*>		m_compressedLevels;
199 };
200 
201 class TestTexture1D : public TestTexture
202 {
203 private:
204 	tcu::Texture1D								m_texture;
205 
206 public:
207 												TestTexture1D		(const tcu::TextureFormat& format, int width);
208 												TestTexture1D		(const tcu::CompressedTexFormat& format, int width);
209 	virtual										~TestTexture1D		(void);
210 
211 	virtual int getNumLevels (void) const;
212 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
213 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
214 	virtual const tcu::Texture1D&				getTexture			(void) const;
215 	virtual tcu::Texture1D&						getTexture			(void);
getTextureFormat(void) const216 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const217 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
218 
219 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
220 };
221 
222 class TestTexture1DArray : public TestTexture
223 {
224 private:
225 	tcu::Texture1DArray							m_texture;
226 
227 public:
228 												TestTexture1DArray	(const tcu::TextureFormat& format, int width, int arraySize);
229 												TestTexture1DArray	(const tcu::CompressedTexFormat& format, int width, int arraySize);
230 	virtual										~TestTexture1DArray	(void);
231 
232 	virtual int									getNumLevels		(void) const;
233 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
234 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
235 	virtual const tcu::Texture1DArray&			getTexture			(void) const;
236 	virtual tcu::Texture1DArray&				getTexture			(void);
237 	virtual int									getArraySize		(void) const;
getTextureFormat(void) const238 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const239 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
240 
241 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
242 };
243 
244 class TestTexture2D : public TestTexture
245 {
246 private:
247 	tcu::Texture2D								m_texture;
248 
249 public:
250 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height);
251 												TestTexture2D		(const tcu::TextureFormat& format, int width, int height, int miplevels);
252 												TestTexture2D		(const tcu::CompressedTexFormat& format, int width, int height);
253 	virtual										~TestTexture2D		(void);
254 
255 	virtual int									getNumLevels		(void) const;
256 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
257 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
258 	virtual const tcu::Texture2D&				getTexture			(void) const;
259 	virtual tcu::Texture2D&						getTexture			(void);
getTextureFormat(void) const260 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const261 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
262 
263 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
264 };
265 
266 class TestTexture2DArray : public TestTexture
267 {
268 private:
269 	tcu::Texture2DArray	m_texture;
270 
271 public:
272 												TestTexture2DArray	(const tcu::TextureFormat& format, int width, int height, int arraySize);
273 												TestTexture2DArray	(const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
274 	virtual										~TestTexture2DArray	(void);
275 
276 	virtual int									getNumLevels		(void) const;
277 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
278 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
279 	virtual const tcu::Texture2DArray&			getTexture			(void) const;
280 	virtual tcu::Texture2DArray&				getTexture			(void);
281 	virtual int									getArraySize		(void) const;
getTextureFormat(void) const282 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const283 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
284 
285 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
286 };
287 
288 class TestTexture3D : public TestTexture
289 {
290 private:
291 	tcu::Texture3D	m_texture;
292 
293 public:
294 												TestTexture3D		(const tcu::TextureFormat& format, int width, int height, int depth);
295 												TestTexture3D		(const tcu::CompressedTexFormat& format, int width, int height, int depth);
296 	virtual										~TestTexture3D		(void);
297 
298 	virtual int									getNumLevels		(void) const;
299 	virtual tcu::PixelBufferAccess				getLevel			(int level, int layer);
300 	virtual const tcu::ConstPixelBufferAccess	getLevel			(int level, int layer) const;
301 	virtual const tcu::Texture3D&				getTexture			(void) const;
302 	virtual tcu::Texture3D&						getTexture			(void);
getTextureFormat(void) const303 	virtual const tcu::TextureFormat&			getTextureFormat	(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const304 	virtual tcu::UVec3							getTextureDimension	(void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
305 
306 	virtual de::MovePtr<TestTexture>			copy				(const tcu::TextureFormat) const;
307 };
308 
309 class TestTextureCube : public TestTexture
310 {
311 private:
312 	tcu::TextureCube							m_texture;
313 
314 public:
315 												TestTextureCube			(const tcu::TextureFormat& format, int size);
316 												TestTextureCube			(const tcu::CompressedTexFormat& format, int size);
317 	virtual										~TestTextureCube		(void);
318 
319 	virtual int									getNumLevels			(void) const;
320 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
321 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
322 	virtual int									getArraySize			(void) const;
323 	virtual const tcu::TextureCube&				getTexture				(void) const;
324 	virtual tcu::TextureCube&					getTexture				(void);
getTextureFormat(void) const325 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const326 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
327 
328 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
329 };
330 
331 class TestTextureCubeArray: public TestTexture
332 {
333 private:
334 	tcu::TextureCubeArray						m_texture;
335 
336 public:
337 												TestTextureCubeArray	(const tcu::TextureFormat& format, int size, int arraySize);
338 												TestTextureCubeArray	(const tcu::CompressedTexFormat& format, int size, int arraySize);
339 	virtual										~TestTextureCubeArray	(void);
340 
341 	virtual int									getNumLevels			(void) const;
342 	virtual tcu::PixelBufferAccess				getLevel				(int level, int layer);
343 	virtual const tcu::ConstPixelBufferAccess	getLevel				(int level, int layer) const;
344 	virtual int									getArraySize			(void) const;
345 	virtual const tcu::TextureCubeArray&		getTexture				(void) const;
346 	virtual tcu::TextureCubeArray&				getTexture				(void);
getTextureFormat(void) const347 	virtual const tcu::TextureFormat&			getTextureFormat		(void) const { return m_texture.getFormat(); }
getTextureDimension(void) const348 	virtual tcu::UVec3							getTextureDimension		(void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
349 
350 	virtual de::MovePtr<TestTexture>			copy					(const tcu::TextureFormat) const;
351 };
352 
353 } // pipeline
354 } // vkt
355 
356 #endif // _VKTPIPELINEIMAGEUTIL_HPP
357