• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Imagination Technologies Ltd.
7  * Copyright (c) 2015 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Utilities for images.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkImageUtil.hpp"
27 #include "tcuTextureUtil.hpp"
28 
29 namespace vk
30 {
31 
isFloatFormat(VkFormat format)32 bool isFloatFormat (VkFormat format)
33 {
34 	return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
35 }
36 
isUnormFormat(VkFormat format)37 bool isUnormFormat (VkFormat format)
38 {
39 	return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
40 }
41 
isSnormFormat(VkFormat format)42 bool isSnormFormat (VkFormat format)
43 {
44 	return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
45 }
46 
isIntFormat(VkFormat format)47 bool isIntFormat (VkFormat format)
48 {
49 	return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER;
50 }
51 
isUintFormat(VkFormat format)52 bool isUintFormat (VkFormat format)
53 {
54 	return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
55 }
56 
isDepthStencilFormat(VkFormat format)57 bool isDepthStencilFormat (VkFormat format)
58 {
59 	if (isCompressedFormat(format))
60 		return false;
61 
62 	const tcu::TextureFormat tcuFormat = mapVkFormat(format);
63 	return tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS;
64 }
65 
isSrgbFormat(VkFormat format)66 bool isSrgbFormat (VkFormat format)
67 {
68 	switch (mapVkFormat(format).order)
69 	{
70 		case tcu::TextureFormat::sR:
71 		case tcu::TextureFormat::sRG:
72 		case tcu::TextureFormat::sRGB:
73 		case tcu::TextureFormat::sRGBA:
74 		case tcu::TextureFormat::sBGR:
75 		case tcu::TextureFormat::sBGRA:
76 			return true;
77 
78 		default:
79 			return false;
80 	}
81 }
82 
isCompressedFormat(VkFormat format)83 bool isCompressedFormat (VkFormat format)
84 {
85 	// update this mapping if VkFormat changes
86 	DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
87 
88 	switch (format)
89 	{
90 		case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
91 		case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
92 		case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
93 		case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
94 		case VK_FORMAT_BC2_UNORM_BLOCK:
95 		case VK_FORMAT_BC2_SRGB_BLOCK:
96 		case VK_FORMAT_BC3_UNORM_BLOCK:
97 		case VK_FORMAT_BC3_SRGB_BLOCK:
98 		case VK_FORMAT_BC4_UNORM_BLOCK:
99 		case VK_FORMAT_BC4_SNORM_BLOCK:
100 		case VK_FORMAT_BC5_UNORM_BLOCK:
101 		case VK_FORMAT_BC5_SNORM_BLOCK:
102 		case VK_FORMAT_BC6H_UFLOAT_BLOCK:
103 		case VK_FORMAT_BC6H_SFLOAT_BLOCK:
104 		case VK_FORMAT_BC7_UNORM_BLOCK:
105 		case VK_FORMAT_BC7_SRGB_BLOCK:
106 		case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
107 		case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
108 		case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
109 		case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
110 		case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
111 		case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
112 		case VK_FORMAT_EAC_R11_UNORM_BLOCK:
113 		case VK_FORMAT_EAC_R11_SNORM_BLOCK:
114 		case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
115 		case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
116 		case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
117 		case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
118 		case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
119 		case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
120 		case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
121 		case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
122 		case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
123 		case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
124 		case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
125 		case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
126 		case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
127 		case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
128 		case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
129 		case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
130 		case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
131 		case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
132 		case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
133 		case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
134 		case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
135 		case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
136 		case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
137 		case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
138 		case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
139 		case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
140 		case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
141 		case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
142 		case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
143 		case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
144 			return true;
145 
146 		default:
147 			return false;
148 	}
149 }
150 
isYCbCrFormat(VkFormat format)151 bool isYCbCrFormat (VkFormat format)
152 {
153 	switch (format)
154 	{
155 		case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
156 		case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
157 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
158 		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
159 		case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
160 		case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
161 		case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
162 		case VK_FORMAT_R10X6_UNORM_PACK16_KHR:
163 		case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:
164 		case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:
165 		case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
166 		case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
167 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
168 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
169 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
170 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
171 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
172 		case VK_FORMAT_R12X4_UNORM_PACK16_KHR:
173 		case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:
174 		case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:
175 		case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
176 		case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
177 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
178 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
179 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
180 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
181 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
182 		case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
183 		case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
184 		case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
185 		case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
186 		case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
187 		case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
188 		case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
189 			return true;
190 
191 		default:
192 			return false;
193 	}
194 }
195 
getYCbCrPlanarFormatDescription(VkFormat format)196 const PlanarFormatDescription& getYCbCrPlanarFormatDescription (VkFormat format)
197 {
198 	using tcu::TextureFormat;
199 
200 	const deUint32	chanR			= PlanarFormatDescription::CHANNEL_R;
201 	const deUint32	chanG			= PlanarFormatDescription::CHANNEL_G;
202 	const deUint32	chanB			= PlanarFormatDescription::CHANNEL_B;
203 	const deUint32	chanA			= PlanarFormatDescription::CHANNEL_A;
204 
205 	const deUint8	unorm			= (deUint8)tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
206 
207 	static const PlanarFormatDescription s_formatInfo[] =
208 	{
209 		// VK_FORMAT_G8B8G8R8_422_UNORM_KHR
210 		{
211 			1, // planes
212 			chanR|chanG|chanB,
213 			{
214 			//		Size	WDiv	HDiv
215 				{	4,		2,		1	},
216 				{	0,		0,		0	},
217 				{	0,		0,		0	},
218 			},
219 			{
220 			//		Plane	Type	Offs	Size	Stride
221 				{	0,		unorm,	24,		8,		4 },	// R
222 				{	0,		unorm,	0,		8,		2 },	// G
223 				{	0,		unorm,	8,		8,		4 },	// B
224 				{ 0, 0, 0, 0, 0 }
225 			}
226 		},
227 		// VK_FORMAT_B8G8R8G8_422_UNORM_KHR
228 		{
229 			1, // planes
230 			chanR|chanG|chanB,
231 			{
232 			//		Size	WDiv	HDiv
233 				{	4,		2,		1 },
234 				{	0,		0,		0 },
235 				{	0,		0,		0 },
236 			},
237 			{
238 			//		Plane	Type	Offs	Size	Stride
239 				{	0,		unorm,	16,		8,		4 },	// R
240 				{	0,		unorm,	8,		8,		2 },	// G
241 				{	0,		unorm,	0,		8,		4 },	// B
242 				{ 0, 0, 0, 0, 0 }
243 			}
244 		},
245 		// VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR
246 		{
247 			3, // planes
248 			chanR|chanG|chanB,
249 			{
250 			//		Size	WDiv	HDiv
251 				{  1, 1, 1 },
252 				{  1, 2, 2 },
253 				{  1, 2, 2 },
254 			},
255 			{
256 			//		Plane	Type	Offs	Size	Stride
257 				{	2,		unorm,	0,		8,		1 },	// R
258 				{	0,		unorm,	0,		8,		1 },	// G
259 				{	1,		unorm,	0,		8,		1 },	// B
260 				{ 0, 0, 0, 0, 0 }
261 			}
262 		},
263 		// VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR
264 		{
265 			2, // planes
266 			chanR|chanG|chanB,
267 			{
268 			//		Size	WDiv	HDiv
269 				{  1, 1, 1 },
270 				{  2, 2, 2 },
271 				{  0, 0, 0 },
272 			},
273 			{
274 			//		Plane	Type	Offs	Size	Stride
275 				{	1,		unorm,	8,		8,		2 },	// R
276 				{	0,		unorm,	0,		8,		1 },	// G
277 				{	1,		unorm,	0,		8,		2 },	// B
278 				{ 0, 0, 0, 0, 0 }
279 			}
280 		},
281 		// VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR
282 		{
283 			3, // planes
284 			chanR|chanG|chanB,
285 			{
286 			//		Size	WDiv	HDiv
287 				{  1, 1, 1 },
288 				{  1, 2, 1 },
289 				{  1, 2, 1 },
290 			},
291 			{
292 			//		Plane	Type	Offs	Size	Stride
293 				{	2,		unorm,	0,		8,		1 },	// R
294 				{	0,		unorm,	0,		8,		1 },	// G
295 				{	1,		unorm,	0,		8,		1 },	// B
296 				{ 0, 0, 0, 0, 0 }
297 			}
298 		},
299 		// VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR
300 		{
301 			2, // planes
302 			chanR|chanG|chanB,
303 			{
304 			//		Size	WDiv	HDiv
305 				{  1, 1, 1 },
306 				{  2, 2, 1 },
307 				{  0, 0, 0 },
308 			},
309 			{
310 			//		Plane	Type	Offs	Size	Stride
311 				{	1,		unorm,	8,		8,		2 },	// R
312 				{	0,		unorm,	0,		8,		1 },	// G
313 				{	1,		unorm,	0,		8,		2 },	// B
314 				{ 0, 0, 0, 0, 0 }
315 			}
316 		},
317 		// VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR
318 		{
319 			3, // planes
320 			chanR|chanG|chanB,
321 			{
322 			//		Size	WDiv	HDiv
323 				{  1, 1, 1 },
324 				{  1, 1, 1 },
325 				{  1, 1, 1 },
326 			},
327 			{
328 			//		Plane	Type	Offs	Size	Stride
329 				{	2,		unorm,	0,		8,		1 },	// R
330 				{	0,		unorm,	0,		8,		1 },	// G
331 				{	1,		unorm,	0,		8,		1 },	// B
332 				{ 0, 0, 0, 0, 0 }
333 			}
334 		},
335 		// VK_FORMAT_R10X6_UNORM_PACK16_KHR
336 		{
337 			1, // planes
338 			chanR,
339 			{
340 			//		Size	WDiv	HDiv
341 				{	2,		1,		1 },
342 				{	0,		0,		0 },
343 				{	0,		0,		0 },
344 			},
345 			{
346 			//		Plane	Type	Offs	Size	Stride
347 				{	0,		unorm,	6,		10,		2 },	// R
348 				{ 0, 0, 0, 0, 0 },
349 				{ 0, 0, 0, 0, 0 },
350 				{ 0, 0, 0, 0, 0 },
351 			}
352 		},
353 		// VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR
354 		{
355 			1, // planes
356 			chanR|chanG,
357 			{
358 			//		Size	WDiv	HDiv
359 				{	4,		1,		1 },
360 				{	0,		0,		0 },
361 				{	0,		0,		0 },
362 			},
363 			{
364 			//		Plane	Type	Offs	Size	Stride
365 				{	0,		unorm,	6,		10,		4 },	// R
366 				{	0,		unorm,	22,		10,		4 },	// G
367 				{ 0, 0, 0, 0, 0 },
368 				{ 0, 0, 0, 0, 0 },
369 			}
370 		},
371 		// VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR
372 		{
373 			1, // planes
374 			chanR|chanG|chanB|chanA,
375 			{
376 			//		Size	WDiv	HDiv
377 				{	8,		1,		1 },
378 				{	0,		0,		0 },
379 				{	0,		0,		0 },
380 			},
381 			{
382 			//		Plane	Type	Offs	Size	Stride
383 				{	0,		unorm,	6,		10,		8 },	// R
384 				{	0,		unorm,	22,		10,		8 },	// G
385 				{	0,		unorm,	38,		10,		8 },	// B
386 				{	0,		unorm,	54,		10,		8 },	// A
387 			}
388 		},
389 		// VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR
390 		{
391 			1, // planes
392 			chanR|chanG|chanB,
393 			{
394 			//		Size	WDiv	HDiv
395 				{	8,		2,		1 },
396 				{	0,		0,		0 },
397 				{	0,		0,		0 },
398 			},
399 			{
400 			//		Plane	Type	Offs	Size	Stride
401 				{	0,		unorm,	54,		10,		8 },	// R
402 				{	0,		unorm,	6,		10,		4 },	// G
403 				{	0,		unorm,	22,		10,		8 },	// B
404 				{ 0, 0, 0, 0, 0 }
405 			}
406 		},
407 		// VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR
408 		{
409 			1, // planes
410 			chanR|chanG|chanB,
411 			{
412 			//		Size	WDiv	HDiv
413 				{	8,		2,		1 },
414 				{	0,		0,		0 },
415 				{	0,		0,		0 },
416 			},
417 			{
418 			//		Plane	Type	Offs	Size	Stride
419 				{	0,		unorm,	38,		10,		8 },	// R
420 				{	0,		unorm,	22,		10,		4 },	// G
421 				{	0,		unorm,	6,		10,		8 },	// B
422 				{ 0, 0, 0, 0, 0 }
423 			}
424 		},
425 		// VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR
426 		{
427 			3, // planes
428 			chanR|chanG|chanB,
429 			{
430 			//		Size	WDiv	HDiv
431 				{	2,		1,		1 },
432 				{	2,		2,		2 },
433 				{	2,		2,		2 },
434 			},
435 			{
436 			//		Plane	Type	Offs	Size	Stride
437 				{	2,		unorm,	6,		10,		2 },	// R
438 				{	0,		unorm,	6,		10,		2 },	// G
439 				{	1,		unorm,	6,		10,		2 },	// B
440 				{ 0, 0, 0, 0, 0 }
441 			}
442 		},
443 		// VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR
444 		{
445 			2, // planes
446 			chanR|chanG|chanB,
447 			{
448 			//		Size	WDiv	HDiv
449 				{	2,		1,		1 },
450 				{	4,		2,		2 },
451 				{	0,		0,		0 },
452 			},
453 			{
454 			//		Plane	Type	Offs	Size	Stride
455 				{	1,		unorm,	22,		10,		4 },	// R
456 				{	0,		unorm,	6,		10,		2 },	// G
457 				{	1,		unorm,	6,		10,		4 },	// B
458 				{ 0, 0, 0, 0, 0 }
459 			}
460 		},
461 		// VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR
462 		{
463 			3, // planes
464 			chanR|chanG|chanB,
465 			{
466 			//		Size	WDiv	HDiv
467 				{	2,		1,		1 },
468 				{	2,		2,		1 },
469 				{	2,		2,		1 },
470 			},
471 			{
472 			//		Plane	Type	Offs	Size	Stride
473 				{	2,		unorm,	6,		10,		2 },	// R
474 				{	0,		unorm,	6,		10,		2 },	// G
475 				{	1,		unorm,	6,		10,		2 },	// B
476 				{ 0, 0, 0, 0, 0 }
477 			}
478 		},
479 		// VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR
480 		{
481 			2, // planes
482 			chanR|chanG|chanB,
483 			{
484 			//		Size	WDiv	HDiv
485 				{	2,		1,		1 },
486 				{	4,		2,		1 },
487 				{	0,		0,		0 },
488 			},
489 			{
490 			//		Plane	Type	Offs	Size	Stride
491 				{	1,		unorm,	22,		10,		4 },	// R
492 				{	0,		unorm,	6,		10,		2 },	// G
493 				{	1,		unorm,	6,		10,		4 },	// B
494 				{ 0, 0, 0, 0, 0 }
495 			}
496 		},
497 		// VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR
498 		{
499 			3, // planes
500 			chanR|chanG|chanB,
501 			{
502 			//		Size	WDiv	HDiv
503 				{	2,		1,		1 },
504 				{	2,		1,		1 },
505 				{	2,		1,		1 },
506 			},
507 			{
508 			//		Plane	Type	Offs	Size	Stride
509 				{	2,		unorm,	6,		10,		2 },	// R
510 				{	0,		unorm,	6,		10,		2 },	// G
511 				{	1,		unorm,	6,		10,		2 },	// B
512 				{ 0, 0, 0, 0, 0 }
513 			}
514 		},
515 		// VK_FORMAT_R12X4_UNORM_PACK16_KHR
516 		{
517 			1, // planes
518 			chanR,
519 			{
520 			//		Size	WDiv	HDiv
521 				{	2,		1,		1 },
522 				{	0,		0,		0 },
523 				{	0,		0,		0 },
524 			},
525 			{
526 			//		Plane	Type	Offs	Size	Stride
527 				{	0,		unorm,	4,		12,		2 },	// R
528 				{ 0, 0, 0, 0, 0 },
529 				{ 0, 0, 0, 0, 0 },
530 				{ 0, 0, 0, 0, 0 },
531 			}
532 		},
533 		// VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR
534 		{
535 			1, // planes
536 			chanR|chanG,
537 			{
538 			//		Size	WDiv	HDiv
539 				{	4,		1,		1 },
540 				{	0,		0,		0 },
541 				{	0,		0,		0 },
542 			},
543 			{
544 			//		Plane	Type	Offs	Size	Stride
545 				{	0,		unorm,	4,		12,		4 },	// R
546 				{	0,		unorm,	20,		12,		4 },	// G
547 				{ 0, 0, 0, 0, 0 },
548 				{ 0, 0, 0, 0, 0 },
549 			}
550 		},
551 		// VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR
552 		{
553 			1, // planes
554 			chanR|chanG|chanB|chanA,
555 			{
556 			//		Size	WDiv	HDiv
557 				{	8,		1,		1 },
558 				{	0,		0,		0 },
559 				{	0,		0,		0 },
560 			},
561 			{
562 			//		Plane	Type	Offs	Size	Stride
563 				{	0,		unorm,	4,		12,		8 },	// R
564 				{	0,		unorm,	20,		12,		8 },	// G
565 				{	0,		unorm,	36,		12,		8 },	// B
566 				{	0,		unorm,	52,		12,		8 },	// A
567 			}
568 		},
569 		// VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR
570 		{
571 			1, // planes
572 			chanR|chanG|chanB,
573 			{
574 			//		Size	WDiv	HDiv
575 				{	8,		2,		1 },
576 				{	0,		0,		0 },
577 				{	0,		0,		0 },
578 			},
579 			{
580 			//		Plane	Type	Offs	Size	Stride
581 				{	0,		unorm,	52,		12,		8 },	// R
582 				{	0,		unorm,	4,		12,		4 },	// G
583 				{	0,		unorm,	20,		12,		8 },	// B
584 				{ 0, 0, 0, 0, 0 }
585 			}
586 		},
587 		// VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR
588 		{
589 			1, // planes
590 			chanR|chanG|chanB,
591 			{
592 			//		Size	WDiv	HDiv
593 				{	8,		2,		1 },
594 				{	0,		0,		0 },
595 				{	0,		0,		0 },
596 			},
597 			{
598 			//		Plane	Type	Offs	Size	Stride
599 				{	0,		unorm,	36,		12,		8 },	// R
600 				{	0,		unorm,	20,		12,		4 },	// G
601 				{	0,		unorm,	4,		12,		8 },	// B
602 				{ 0, 0, 0, 0, 0 }
603 			}
604 		},
605 		// VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR
606 		{
607 			3, // planes
608 			chanR|chanG|chanB,
609 			{
610 			//		Size	WDiv	HDiv
611 				{	2,		1,		1 },
612 				{	2,		2,		2 },
613 				{	2,		2,		2 },
614 			},
615 			{
616 			//		Plane	Type	Offs	Size	Stride
617 				{	2,		unorm,	4,		12,		2 },	// R
618 				{	0,		unorm,	4,		12,		2 },	// G
619 				{	1,		unorm,	4,		12,		2 },	// B
620 				{ 0, 0, 0, 0, 0 }
621 			}
622 		},
623 		// VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR
624 		{
625 			2, // planes
626 			chanR|chanG|chanB,
627 			{
628 			//		Size	WDiv	HDiv
629 				{	2,		1,		1 },
630 				{	4,		2,		2 },
631 				{	0,		0,		0 },
632 			},
633 			{
634 			//		Plane	Type	Offs	Size	Stride
635 				{	1,		unorm,	20,		12,		4 },	// R
636 				{	0,		unorm,	4,		12,		2 },	// G
637 				{	1,		unorm,	4,		12,		4 },	// B
638 				{ 0, 0, 0, 0, 0 }
639 			}
640 		},
641 		// VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR
642 		{
643 			3, // planes
644 			chanR|chanG|chanB,
645 			{
646 			//		Size	WDiv	HDiv
647 				{	2,		1,		1 },
648 				{	2,		2,		1 },
649 				{	2,		2,		1 },
650 			},
651 			{
652 			//		Plane	Type	Offs	Size	Stride
653 				{	2,		unorm,	4,		12,		2 },	// R
654 				{	0,		unorm,	4,		12,		2 },	// G
655 				{	1,		unorm,	4,		12,		2 },	// B
656 				{ 0, 0, 0, 0, 0 }
657 			}
658 		},
659 		// VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR
660 		{
661 			2, // planes
662 			chanR|chanG|chanB,
663 			{
664 			//		Size	WDiv	HDiv
665 				{	2,		1,		1 },
666 				{	4,		2,		1 },
667 				{	0,		0,		0 },
668 			},
669 			{
670 			//		Plane	Type	Offs	Size	Stride
671 				{	1,		unorm,	20,		12,		4 },	// R
672 				{	0,		unorm,	4,		12,		2 },	// G
673 				{	1,		unorm,	4,		12,		4 },	// B
674 				{ 0, 0, 0, 0, 0 }
675 			}
676 		},
677 		// VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR
678 		{
679 			3, // planes
680 			chanR|chanG|chanB,
681 			{
682 			//		Size	WDiv	HDiv
683 				{	2,		1,		1 },
684 				{	2,		1,		1 },
685 				{	2,		1,		1 },
686 			},
687 			{
688 			//		Plane	Type	Offs	Size	Stride
689 				{	2,		unorm,	4,		12,		2 },	// R
690 				{	0,		unorm,	4,		12,		2 },	// G
691 				{	1,		unorm,	4,		12,		2 },	// B
692 				{ 0, 0, 0, 0, 0 }
693 			}
694 		},
695 		// VK_FORMAT_G16B16G16R16_422_UNORM_KHR
696 		{
697 			1, // planes
698 			chanR|chanG|chanB,
699 			{
700 			//		Size	WDiv	HDiv
701 				{	8,		2,		1 },
702 				{	0,		0,		0 },
703 				{	0,		0,		0 },
704 			},
705 			{
706 			//		Plane	Type	Offs	Size	Stride
707 				{	0,		unorm,	48,		16,		8 },	// R
708 				{	0,		unorm,	0,		16,		4 },	// G
709 				{	0,		unorm,	16,		16,		8 },	// B
710 				{ 0, 0, 0, 0, 0 }
711 			}
712 		},
713 		// VK_FORMAT_B16G16R16G16_422_UNORM_KHR
714 		{
715 			1, // planes
716 			chanR|chanG|chanB,
717 			{
718 			//		Size	WDiv	HDiv
719 				{	8,		2,		1 },
720 				{	0,		0,		0 },
721 				{	0,		0,		0 },
722 			},
723 			{
724 			//		Plane	Type	Offs	Size	Stride
725 				{	0,		unorm,	32,		16,		8 },	// R
726 				{	0,		unorm,	16,		16,		4 },	// G
727 				{	0,		unorm,	0,		16,		8 },	// B
728 				{ 0, 0, 0, 0, 0 }
729 			}
730 		},
731 		// VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR
732 		{
733 			3, // planes
734 			chanR|chanG|chanB,
735 			{
736 			//		Size	WDiv	HDiv
737 				{	2,		1,		1 },
738 				{	2,		2,		2 },
739 				{	2,		2,		2 },
740 			},
741 			{
742 			//		Plane	Type	Offs	Size	Stride
743 				{	2,		unorm,	0,		16,		2 },	// R
744 				{	0,		unorm,	0,		16,		2 },	// G
745 				{	1,		unorm,	0,		16,		2 },	// B
746 				{ 0, 0, 0, 0, 0 }
747 			}
748 		},
749 		// VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR
750 		{
751 			2, // planes
752 			chanR|chanG|chanB,
753 			{
754 			//		Size	WDiv	HDiv
755 				{	2,		1,		1 },
756 				{	4,		2,		2 },
757 				{	0,		0,		0 },
758 			},
759 			{
760 			//		Plane	Type	Offs	Size	Stride
761 				{	1,		unorm,	16,		16,		4 },	// R
762 				{	0,		unorm,	0,		16,		2 },	// G
763 				{	1,		unorm,	0,		16,		4 },	// B
764 				{ 0, 0, 0, 0, 0 }
765 			}
766 		},
767 		// VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR
768 		{
769 			3, // planes
770 			chanR|chanG|chanB,
771 			{
772 			//		Size	WDiv	HDiv
773 				{	2,		1,		1 },
774 				{	2,		2,		1 },
775 				{	2,		2,		1 },
776 			},
777 			{
778 			//		Plane	Type	Offs	Size	Stride
779 				{	2,		unorm,	0,		16,		2 },	// R
780 				{	0,		unorm,	0,		16,		2 },	// G
781 				{	1,		unorm,	0,		16,		2 },	// B
782 				{ 0, 0, 0, 0, 0 }
783 			}
784 		},
785 		// VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR
786 		{
787 			2, // planes
788 			chanR|chanG|chanB,
789 			{
790 			//		Size	WDiv	HDiv
791 				{	2,		1,		1 },
792 				{	4,		2,		1 },
793 				{	0,		0,		0 },
794 			},
795 			{
796 			//		Plane	Type	Offs	Size	Stride
797 				{	1,		unorm,	16,		16,		4 },	// R
798 				{	0,		unorm,	0,		16,		2 },	// G
799 				{	1,		unorm,	0,		16,		4 },	// B
800 				{ 0, 0, 0, 0, 0 }
801 			}
802 		},
803 		// VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR
804 		{
805 			3, // planes
806 			chanR|chanG|chanB,
807 			{
808 			//		Size	WDiv	HDiv
809 				{	2,		1,		1 },
810 				{	2,		1,		1 },
811 				{	2,		1,		1 },
812 			},
813 			{
814 			//		Plane	Type	Offs	Size	Stride
815 				{	2,		unorm,	0,		16,		2 },	// R
816 				{	0,		unorm,	0,		16,		2 },	// G
817 				{	1,		unorm,	0,		16,		2 },	// B
818 				{ 0, 0, 0, 0, 0 }
819 			}
820 		},
821 	};
822 
823 	const size_t	offset	= (size_t)VK_FORMAT_G8B8G8R8_422_UNORM_KHR;
824 
825 	DE_ASSERT(de::inBounds<size_t>((size_t)format, offset, offset+(size_t)DE_LENGTH_OF_ARRAY(s_formatInfo)));
826 
827 	return s_formatInfo[(size_t)format-offset];
828 }
829 
getCorePlanarFormatDescription(VkFormat format)830 PlanarFormatDescription getCorePlanarFormatDescription (VkFormat format)
831 {
832 	const deUint8			unorm	= (deUint8)tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
833 
834 	const deUint8			chanR	= (deUint8)PlanarFormatDescription::CHANNEL_R;
835 	const deUint8			chanG	= (deUint8)PlanarFormatDescription::CHANNEL_G;
836 	const deUint8			chanB	= (deUint8)PlanarFormatDescription::CHANNEL_B;
837 	const deUint8			chanA	= (deUint8)PlanarFormatDescription::CHANNEL_A;
838 
839 	DE_ASSERT(de::inBounds<deUint32>(format, VK_FORMAT_UNDEFINED+1, VK_CORE_FORMAT_LAST));
840 
841 #if (DE_ENDIANNESS != DE_LITTLE_ENDIAN)
842 #	error "Big-endian is not supported"
843 #endif
844 
845 	switch (format)
846 	{
847 		case VK_FORMAT_R8_UNORM:
848 		{
849 			const PlanarFormatDescription	desc	=
850 			{
851 				1, // planes
852 				chanR,
853 				{
854 				//		Size	WDiv	HDiv
855 					{	1,		1,		1 },
856 					{	0,		0,		0 },
857 					{	0,		0,		0 },
858 				},
859 				{
860 				//		Plane	Type	Offs	Size	Stride
861 					{	0,		unorm,	0,		8,		1 },	// R
862 					{	0,		0,		0,		0,		0 },	// G
863 					{	0,		0,		0,		0,		0 },	// B
864 					{	0,		0,		0,		0,		0 }		// A
865 				}
866 			};
867 			return desc;
868 		}
869 
870 		case VK_FORMAT_R8G8_UNORM:
871 		{
872 			const PlanarFormatDescription	desc	=
873 			{
874 				1, // planes
875 				chanR|chanG,
876 				{
877 				//		Size	WDiv	HDiv
878 					{	2,		1,		1 },
879 					{	0,		0,		0 },
880 					{	0,		0,		0 },
881 				},
882 				{
883 				//		Plane	Type	Offs	Size	Stride
884 					{	0,		unorm,	0,		8,		2 },	// R
885 					{	0,		unorm,	8,		8,		2 },	// G
886 					{	0,		0,		0,		0,		0 },	// B
887 					{	0,		0,		0,		0,		0 }		// A
888 				}
889 			};
890 			return desc;
891 		}
892 
893 		case VK_FORMAT_R16_UNORM:
894 		{
895 			const PlanarFormatDescription	desc	=
896 			{
897 				1, // planes
898 				chanR,
899 				{
900 				//		Size	WDiv	HDiv
901 					{	2,		1,		1 },
902 					{	0,		0,		0 },
903 					{	0,		0,		0 },
904 				},
905 				{
906 				//		Plane	Type	Offs	Size	Stride
907 					{	0,		unorm,	0,		16,		2 },	// R
908 					{	0,		0,		0,		0,		0 },	// G
909 					{	0,		0,		0,		0,		0 },	// B
910 					{	0,		0,		0,		0,		0 }		// A
911 				}
912 			};
913 			return desc;
914 		}
915 
916 		case VK_FORMAT_R16G16_UNORM:
917 		{
918 			const PlanarFormatDescription	desc	=
919 			{
920 				1, // planes
921 				chanR|chanG,
922 				{
923 				//		Size	WDiv	HDiv
924 					{	4,		1,		1 },
925 					{	0,		0,		0 },
926 					{	0,		0,		0 },
927 				},
928 				{
929 				//		Plane	Type	Offs	Size	Stride
930 					{	0,		unorm,	0,		16,		4 },	// R
931 					{	0,		unorm,	16,		16,		4 },	// G
932 					{	0,		0,		0,		0,		0 },	// B
933 					{	0,		0,		0,		0,		0 }		// A
934 				}
935 			};
936 			return desc;
937 		}
938 
939 		case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
940 		{
941 			const PlanarFormatDescription	desc	=
942 			{
943 				1, // planes
944 				chanR|chanG|chanB,
945 				{
946 				//		Size	WDiv	HDiv
947 					{	4,		1,		1 },
948 					{	0,		0,		0 },
949 					{	0,		0,		0 },
950 				},
951 				{
952 				//		Plane	Type	Offs	Size	Stride
953 					{	0,		unorm,	0,		11,		4 },	// R
954 					{	0,		unorm,	11,		11,		4 },	// G
955 					{	0,		unorm,	22,		10,		4 },	// B
956 					{	0,		0,		0,		0,		0 }		// A
957 				}
958 			};
959 			return desc;
960 		}
961 
962 		case VK_FORMAT_R4G4_UNORM_PACK8:
963 		{
964 			const PlanarFormatDescription	desc	=
965 			{
966 				1, // planes
967 				chanR|chanG,
968 				{
969 				//		Size	WDiv	HDiv
970 					{	1,		1,		1 },
971 					{	0,		0,		0 },
972 					{	0,		0,		0 },
973 				},
974 				{
975 				//		Plane	Type	Offs	Size	Stride
976 					{	0,		unorm,	4,		4,		1 },	// R
977 					{	0,		unorm,	0,		4,		1 },	// G
978 					{	0,		0,		0,		0,		0 },	// B
979 					{	0,		0,		0,		0,		0 }		// A
980 				}
981 			};
982 			return desc;
983 		}
984 
985 		case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
986 		{
987 			const PlanarFormatDescription	desc	=
988 			{
989 				1, // planes
990 				chanR|chanG|chanB|chanA,
991 				{
992 				//		Size	WDiv	HDiv
993 					{	2,		1,		1 },
994 					{	0,		0,		0 },
995 					{	0,		0,		0 },
996 				},
997 				{
998 				//		Plane	Type	Offs	Size	Stride
999 					{	0,		unorm,	12,		4,		2 },	// R
1000 					{	0,		unorm,	8,		4,		2 },	// G
1001 					{	0,		unorm,	4,		4,		2 },	// B
1002 					{	0,		unorm,	0,		4,		2 }		// A
1003 				}
1004 			};
1005 			return desc;
1006 		}
1007 
1008 		case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1009 		{
1010 			const PlanarFormatDescription	desc	=
1011 			{
1012 				1, // planes
1013 				chanR|chanG|chanB|chanA,
1014 				{
1015 				//		Size	WDiv	HDiv
1016 					{	2,		1,		1 },
1017 					{	0,		0,		0 },
1018 					{	0,		0,		0 },
1019 				},
1020 				{
1021 				//		Plane	Type	Offs	Size	Stride
1022 					{	0,		unorm,	4,		4,		2 },	// R
1023 					{	0,		unorm,	8,		4,		2 },	// G
1024 					{	0,		unorm,	12,		4,		2 },	// B
1025 					{	0,		unorm,	0,		4,		2 }		// A
1026 				}
1027 			};
1028 			return desc;
1029 		}
1030 
1031 		case VK_FORMAT_R5G6B5_UNORM_PACK16:
1032 		{
1033 			const PlanarFormatDescription	desc	=
1034 			{
1035 				1, // planes
1036 				chanR|chanG|chanB,
1037 				{
1038 				//		Size	WDiv	HDiv
1039 					{	2,		1,		1 },
1040 					{	0,		0,		0 },
1041 					{	0,		0,		0 },
1042 				},
1043 				{
1044 				//		Plane	Type	Offs	Size	Stride
1045 					{	0,		unorm,	11,		5,		2 },	// R
1046 					{	0,		unorm,	5,		6,		2 },	// G
1047 					{	0,		unorm,	0,		5,		2 },	// B
1048 					{	0,		0,		0,		0,		0 }		// A
1049 				}
1050 			};
1051 			return desc;
1052 		}
1053 
1054 		case VK_FORMAT_B5G6R5_UNORM_PACK16:
1055 		{
1056 			const PlanarFormatDescription	desc	=
1057 			{
1058 				1, // planes
1059 				chanR|chanG|chanB,
1060 				{
1061 				//		Size	WDiv	HDiv
1062 					{	2,		1,		1 },
1063 					{	0,		0,		0 },
1064 					{	0,		0,		0 },
1065 				},
1066 				{
1067 				//		Plane	Type	Offs	Size	Stride
1068 					{	0,		unorm,	0,		5,		2 },	// R
1069 					{	0,		unorm,	5,		6,		2 },	// G
1070 					{	0,		unorm,	11,		5,		2 },	// B
1071 					{	0,		0,		0,		0,		0 }		// A
1072 				}
1073 			};
1074 			return desc;
1075 		}
1076 
1077 		case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1078 		{
1079 			const PlanarFormatDescription	desc	=
1080 			{
1081 				1, // planes
1082 				chanR|chanG|chanB|chanA,
1083 				{
1084 				//		Size	WDiv	HDiv
1085 					{	2,		1,		1 },
1086 					{	0,		0,		0 },
1087 					{	0,		0,		0 },
1088 				},
1089 				{
1090 				//		Plane	Type	Offs	Size	Stride
1091 					{	0,		unorm,	11,		5,		2 },	// R
1092 					{	0,		unorm,	6,		5,		2 },	// G
1093 					{	0,		unorm,	1,		5,		2 },	// B
1094 					{	0,		unorm,	0,		1,		2 }		// A
1095 				}
1096 			};
1097 			return desc;
1098 		}
1099 
1100 		case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1101 		{
1102 			const PlanarFormatDescription	desc	=
1103 			{
1104 				1, // planes
1105 				chanR|chanG|chanB|chanA,
1106 				{
1107 				//		Size	WDiv	HDiv
1108 					{	2,		1,		1 },
1109 					{	0,		0,		0 },
1110 					{	0,		0,		0 },
1111 				},
1112 				{
1113 				//		Plane	Type	Offs	Size	Stride
1114 					{	0,		unorm,	1,		5,		2 },	// R
1115 					{	0,		unorm,	6,		5,		2 },	// G
1116 					{	0,		unorm,	11,		5,		2 },	// B
1117 					{	0,		unorm,	0,		1,		2 }		// A
1118 				}
1119 			};
1120 			return desc;
1121 		}
1122 
1123 		case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1124 		{
1125 			const PlanarFormatDescription	desc	=
1126 			{
1127 				1, // planes
1128 				chanR|chanG|chanB|chanA,
1129 				{
1130 				//		Size	WDiv	HDiv
1131 					{	2,		1,		1 },
1132 					{	0,		0,		0 },
1133 					{	0,		0,		0 },
1134 				},
1135 				{
1136 				//		Plane	Type	Offs	Size	Stride
1137 					{	0,		unorm,	10,		5,		2 },	// R
1138 					{	0,		unorm,	5,		5,		2 },	// G
1139 					{	0,		unorm,	0,		5,		2 },	// B
1140 					{	0,		unorm,	15,		1,		2 }		// A
1141 				}
1142 			};
1143 			return desc;
1144 		}
1145 
1146 		case VK_FORMAT_R8G8B8_UNORM:
1147 		{
1148 			const PlanarFormatDescription	desc	=
1149 			{
1150 				1, // planes
1151 				chanR|chanG|chanB,
1152 				{
1153 				//		Size	WDiv	HDiv
1154 					{	3,		1,		1 },
1155 					{	0,		0,		0 },
1156 					{	0,		0,		0 },
1157 				},
1158 				{
1159 				//		Plane	Type	Offs	Size	Stride
1160 					{	0,		unorm,	0,		8,		3 },	// R
1161 					{	0,		unorm,	8,		8,		3 },	// G
1162 					{	0,		unorm,	16,		8,		3 },	// B
1163 					{	0,		0,		0,		0,		0 }		// A
1164 				}
1165 			};
1166 			return desc;
1167 		}
1168 
1169 		case VK_FORMAT_B8G8R8_UNORM:
1170 		{
1171 			const PlanarFormatDescription	desc	=
1172 			{
1173 				1, // planes
1174 				chanR|chanG|chanB,
1175 				{
1176 				//		Size	WDiv	HDiv
1177 					{	3,		1,		1 },
1178 					{	0,		0,		0 },
1179 					{	0,		0,		0 },
1180 				},
1181 				{
1182 				//		Plane	Type	Offs	Size	Stride
1183 					{	0,		unorm,	16,		8,		3 },	// R
1184 					{	0,		unorm,	8,		8,		3 },	// G
1185 					{	0,		unorm,	0,		8,		3 },	// B
1186 					{	0,		0,		0,		0,		0 }		// A
1187 				}
1188 			};
1189 			return desc;
1190 		}
1191 
1192 		case VK_FORMAT_R8G8B8A8_UNORM:
1193 		case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1194 		{
1195 			const PlanarFormatDescription	desc	=
1196 			{
1197 				1, // planes
1198 				chanR|chanG|chanB|chanA,
1199 				{
1200 				//		Size	WDiv	HDiv
1201 					{	4,		1,		1 },
1202 					{	0,		0,		0 },
1203 					{	0,		0,		0 },
1204 				},
1205 				{
1206 				//		Plane	Type	Offs	Size	Stride
1207 					{	0,		unorm,	0,		8,		4 },	// R
1208 					{	0,		unorm,	8,		8,		4 },	// G
1209 					{	0,		unorm,	16,		8,		4 },	// B
1210 					{	0,		unorm,	24,		8,		4 }		// A
1211 				}
1212 			};
1213 			return desc;
1214 		}
1215 
1216 		case VK_FORMAT_B8G8R8A8_UNORM:
1217 		{
1218 			const PlanarFormatDescription	desc	=
1219 			{
1220 				1, // planes
1221 				chanR|chanG|chanB|chanA,
1222 				{
1223 				//		Size	WDiv	HDiv
1224 					{	4,		1,		1 },
1225 					{	0,		0,		0 },
1226 					{	0,		0,		0 },
1227 				},
1228 				{
1229 				//		Plane	Type	Offs	Size	Stride
1230 					{	0,		unorm,	16,		8,		4 },	// R
1231 					{	0,		unorm,	8,		8,		4 },	// G
1232 					{	0,		unorm,	0,		8,		4 },	// B
1233 					{	0,		unorm,	24,		8,		4 }		// A
1234 				}
1235 			};
1236 			return desc;
1237 		}
1238 
1239 		case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1240 		{
1241 			const PlanarFormatDescription	desc	=
1242 			{
1243 				1, // planes
1244 				chanR|chanG|chanB|chanA,
1245 				{
1246 				//		Size	WDiv	HDiv
1247 					{	4,		1,		1 },
1248 					{	0,		0,		0 },
1249 					{	0,		0,		0 },
1250 				},
1251 				{
1252 				//		Plane	Type	Offs	Size	Stride
1253 					{	0,		unorm,	20,		10,		4 },	// R
1254 					{	0,		unorm,	10,		10,		4 },	// G
1255 					{	0,		unorm,	0,		10,		4 },	// B
1256 					{	0,		unorm,	30,		2,		4 }		// A
1257 				}
1258 			};
1259 			return desc;
1260 		}
1261 
1262 		case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1263 		{
1264 			const PlanarFormatDescription	desc	=
1265 			{
1266 				1, // planes
1267 				chanR|chanG|chanB|chanA,
1268 				{
1269 				//		Size	WDiv	HDiv
1270 					{	4,		1,		1 },
1271 					{	0,		0,		0 },
1272 					{	0,		0,		0 },
1273 				},
1274 				{
1275 				//		Plane	Type	Offs	Size	Stride
1276 					{	0,		unorm,	0,		10,		4 },	// R
1277 					{	0,		unorm,	10,		10,		4 },	// G
1278 					{	0,		unorm,	20,		10,		4 },	// B
1279 					{	0,		unorm,	30,		2,		4 }		// A
1280 				}
1281 			};
1282 			return desc;
1283 		}
1284 
1285 		case VK_FORMAT_R16G16B16_UNORM:
1286 		{
1287 			const PlanarFormatDescription	desc	=
1288 			{
1289 				1, // planes
1290 				chanR|chanG|chanB,
1291 				{
1292 				//		Size	WDiv	HDiv
1293 					{	6,		1,		1 },
1294 					{	0,		0,		0 },
1295 					{	0,		0,		0 },
1296 				},
1297 				{
1298 				//		Plane	Type	Offs	Size	Stride
1299 					{	0,		unorm,	0,		16,		6 },	// R
1300 					{	0,		unorm,	16,		16,		6 },	// G
1301 					{	0,		unorm,	32,		16,		6 },	// B
1302 					{	0,		0,		0,		0,		0 }		// A
1303 				}
1304 			};
1305 			return desc;
1306 		}
1307 
1308 		case VK_FORMAT_R16G16B16A16_UNORM:
1309 		{
1310 			const PlanarFormatDescription	desc	=
1311 			{
1312 				1, // planes
1313 				chanR|chanG|chanB|chanA,
1314 				{
1315 				//		Size	WDiv	HDiv
1316 					{	16,		1,		1 },
1317 					{	0,		0,		0 },
1318 					{	0,		0,		0 },
1319 				},
1320 				{
1321 				//		Plane	Type	Offs	Size	Stride
1322 					{	0,		unorm,	0,		16,		8 },	// R
1323 					{	0,		unorm,	16,		16,		8 },	// G
1324 					{	0,		unorm,	32,		16,		8 },	// B
1325 					{	0,		unorm,	48,		16,		8 }		// A
1326 				}
1327 			};
1328 			return desc;
1329 		}
1330 
1331 		default:
1332 			TCU_THROW(InternalError, "Not implemented");
1333 	}
1334 }
1335 
getPlanarFormatDescription(VkFormat format)1336 PlanarFormatDescription getPlanarFormatDescription (VkFormat format)
1337 {
1338 	if (isYCbCrFormat(format))
1339 		return getYCbCrPlanarFormatDescription(format);
1340 	else
1341 		return getCorePlanarFormatDescription(format);
1342 }
1343 
getPlaneCount(VkFormat format)1344 int getPlaneCount (VkFormat format)
1345 {
1346 	switch (format)
1347 	{
1348 		case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
1349 		case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
1350 		case VK_FORMAT_R10X6_UNORM_PACK16_KHR:
1351 		case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:
1352 		case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:
1353 		case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
1354 		case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
1355 		case VK_FORMAT_R12X4_UNORM_PACK16_KHR:
1356 		case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:
1357 		case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:
1358 		case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
1359 		case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
1360 		case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
1361 		case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
1362 			return 1;
1363 
1364 		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
1365 		case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
1366 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
1367 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
1368 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
1369 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
1370 		case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
1371 		case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
1372 			return 2;
1373 
1374 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
1375 		case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
1376 		case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
1377 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
1378 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
1379 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
1380 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
1381 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
1382 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
1383 		case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
1384 		case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
1385 		case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
1386 			return 3;
1387 
1388 		default:
1389 			DE_FATAL("Not YCbCr format");
1390 			return 0;
1391 	}
1392 }
1393 
getPlaneAspect(deUint32 planeNdx)1394 VkImageAspectFlagBits getPlaneAspect (deUint32 planeNdx)
1395 {
1396 	DE_ASSERT(de::inBounds(planeNdx, 0u, 3u));
1397 	return (VkImageAspectFlagBits)(VK_IMAGE_ASPECT_PLANE_0_BIT_KHR << planeNdx);
1398 }
1399 
getAspectPlaneNdx(VkImageAspectFlagBits flags)1400 deUint32 getAspectPlaneNdx (VkImageAspectFlagBits flags)
1401 {
1402 	switch (flags)
1403 	{
1404 		case VK_IMAGE_ASPECT_PLANE_0_BIT_KHR:	return 0;
1405 		case VK_IMAGE_ASPECT_PLANE_1_BIT_KHR:	return 1;
1406 		case VK_IMAGE_ASPECT_PLANE_2_BIT_KHR:	return 2;
1407 		default:
1408 			DE_FATAL("Invalid plane aspect");
1409 			return 0;
1410 	}
1411 }
1412 
isChromaSubsampled(VkFormat format)1413 bool isChromaSubsampled (VkFormat format)
1414 {
1415 	switch (format)
1416 	{
1417 		case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
1418 		case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
1419 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
1420 		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
1421 		case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
1422 		case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
1423 		case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
1424 		case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
1425 		case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
1426 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
1427 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
1428 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
1429 		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
1430 		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
1431 		case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
1432 		case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
1433 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
1434 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
1435 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
1436 		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
1437 		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
1438 		case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
1439 		case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
1440 		case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
1441 		case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
1442 		case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
1443 		case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
1444 		case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
1445 			return true;
1446 
1447 		default:
1448 			return false;
1449 	}
1450 }
1451 
isSupportedByFramework(VkFormat format)1452 bool isSupportedByFramework (VkFormat format)
1453 {
1454 	if (format == VK_FORMAT_UNDEFINED || format > VK_CORE_FORMAT_LAST)
1455 		return false;
1456 
1457 	switch (format)
1458 	{
1459 		case VK_FORMAT_R64_UINT:
1460 		case VK_FORMAT_R64_SINT:
1461 		case VK_FORMAT_R64_SFLOAT:
1462 		case VK_FORMAT_R64G64_UINT:
1463 		case VK_FORMAT_R64G64_SINT:
1464 		case VK_FORMAT_R64G64_SFLOAT:
1465 		case VK_FORMAT_R64G64B64_UINT:
1466 		case VK_FORMAT_R64G64B64_SINT:
1467 		case VK_FORMAT_R64G64B64_SFLOAT:
1468 		case VK_FORMAT_R64G64B64A64_UINT:
1469 		case VK_FORMAT_R64G64B64A64_SINT:
1470 		case VK_FORMAT_R64G64B64A64_SFLOAT:
1471 			// \todo [2016-12-01 pyry] Support 64-bit channel types
1472 			return false;
1473 
1474 		case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1475 		case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1476 		case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1477 		case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1478 		case VK_FORMAT_BC2_UNORM_BLOCK:
1479 		case VK_FORMAT_BC2_SRGB_BLOCK:
1480 		case VK_FORMAT_BC3_UNORM_BLOCK:
1481 		case VK_FORMAT_BC3_SRGB_BLOCK:
1482 		case VK_FORMAT_BC4_UNORM_BLOCK:
1483 		case VK_FORMAT_BC4_SNORM_BLOCK:
1484 		case VK_FORMAT_BC5_UNORM_BLOCK:
1485 		case VK_FORMAT_BC5_SNORM_BLOCK:
1486 		case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1487 		case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1488 		case VK_FORMAT_BC7_UNORM_BLOCK:
1489 		case VK_FORMAT_BC7_SRGB_BLOCK:
1490 			return false;
1491 
1492 		default:
1493 			return true;
1494 	}
1495 }
1496 
mapTextureFormat(const tcu::TextureFormat & format)1497 VkFormat mapTextureFormat (const tcu::TextureFormat& format)
1498 {
1499 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
1500 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
1501 
1502 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
1503 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
1504 
1505 	// update this mapping if VkFormat changes
1506 	DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1507 
1508 	switch (PACK_FMT(format.order, format.type))
1509 	{
1510 		case FMT_CASE(RG, UNORM_BYTE_44):					return VK_FORMAT_R4G4_UNORM_PACK8;
1511 		case FMT_CASE(RGB, UNORM_SHORT_565):				return VK_FORMAT_R5G6B5_UNORM_PACK16;
1512 		case FMT_CASE(RGBA, UNORM_SHORT_4444):				return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
1513 		case FMT_CASE(RGBA, UNORM_SHORT_5551):				return VK_FORMAT_R5G5B5A1_UNORM_PACK16;
1514 
1515 		case FMT_CASE(BGR, UNORM_SHORT_565):				return VK_FORMAT_B5G6R5_UNORM_PACK16;
1516 		case FMT_CASE(BGRA, UNORM_SHORT_4444):				return VK_FORMAT_B4G4R4A4_UNORM_PACK16;
1517 		case FMT_CASE(BGRA, UNORM_SHORT_5551):				return VK_FORMAT_B5G5R5A1_UNORM_PACK16;
1518 
1519 		case FMT_CASE(ARGB, UNORM_SHORT_1555):				return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
1520 
1521 		case FMT_CASE(R, UNORM_INT8):						return VK_FORMAT_R8_UNORM;
1522 		case FMT_CASE(R, SNORM_INT8):						return VK_FORMAT_R8_SNORM;
1523 		case FMT_CASE(R, UNSIGNED_INT8):					return VK_FORMAT_R8_UINT;
1524 		case FMT_CASE(R, SIGNED_INT8):						return VK_FORMAT_R8_SINT;
1525 		case FMT_CASE(sR, UNORM_INT8):						return VK_FORMAT_R8_SRGB;
1526 
1527 		case FMT_CASE(RG, UNORM_INT8):						return VK_FORMAT_R8G8_UNORM;
1528 		case FMT_CASE(RG, SNORM_INT8):						return VK_FORMAT_R8G8_SNORM;
1529 		case FMT_CASE(RG, UNSIGNED_INT8):					return VK_FORMAT_R8G8_UINT;
1530 		case FMT_CASE(RG, SIGNED_INT8):						return VK_FORMAT_R8G8_SINT;
1531 		case FMT_CASE(sRG, UNORM_INT8):						return VK_FORMAT_R8G8_SRGB;
1532 
1533 		case FMT_CASE(RGB, UNORM_INT8):						return VK_FORMAT_R8G8B8_UNORM;
1534 		case FMT_CASE(RGB, SNORM_INT8):						return VK_FORMAT_R8G8B8_SNORM;
1535 		case FMT_CASE(RGB, UNSIGNED_INT8):					return VK_FORMAT_R8G8B8_UINT;
1536 		case FMT_CASE(RGB, SIGNED_INT8):					return VK_FORMAT_R8G8B8_SINT;
1537 		case FMT_CASE(sRGB, UNORM_INT8):					return VK_FORMAT_R8G8B8_SRGB;
1538 
1539 		case FMT_CASE(RGBA, UNORM_INT8):					return VK_FORMAT_R8G8B8A8_UNORM;
1540 		case FMT_CASE(RGBA, SNORM_INT8):					return VK_FORMAT_R8G8B8A8_SNORM;
1541 		case FMT_CASE(RGBA, UNSIGNED_INT8):					return VK_FORMAT_R8G8B8A8_UINT;
1542 		case FMT_CASE(RGBA, SIGNED_INT8):					return VK_FORMAT_R8G8B8A8_SINT;
1543 		case FMT_CASE(sRGBA, UNORM_INT8):					return VK_FORMAT_R8G8B8A8_SRGB;
1544 
1545 		case FMT_CASE(RGBA, UNORM_INT_1010102_REV):			return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
1546 		case FMT_CASE(RGBA, SNORM_INT_1010102_REV):			return VK_FORMAT_A2B10G10R10_SNORM_PACK32;
1547 		case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV):		return VK_FORMAT_A2B10G10R10_UINT_PACK32;
1548 		case FMT_CASE(RGBA, SIGNED_INT_1010102_REV):		return VK_FORMAT_A2B10G10R10_SINT_PACK32;
1549 
1550 		case FMT_CASE(R, UNORM_INT16):						return VK_FORMAT_R16_UNORM;
1551 		case FMT_CASE(R, SNORM_INT16):						return VK_FORMAT_R16_SNORM;
1552 		case FMT_CASE(R, UNSIGNED_INT16):					return VK_FORMAT_R16_UINT;
1553 		case FMT_CASE(R, SIGNED_INT16):						return VK_FORMAT_R16_SINT;
1554 		case FMT_CASE(R, HALF_FLOAT):						return VK_FORMAT_R16_SFLOAT;
1555 
1556 		case FMT_CASE(RG, UNORM_INT16):						return VK_FORMAT_R16G16_UNORM;
1557 		case FMT_CASE(RG, SNORM_INT16):						return VK_FORMAT_R16G16_SNORM;
1558 		case FMT_CASE(RG, UNSIGNED_INT16):					return VK_FORMAT_R16G16_UINT;
1559 		case FMT_CASE(RG, SIGNED_INT16):					return VK_FORMAT_R16G16_SINT;
1560 		case FMT_CASE(RG, HALF_FLOAT):						return VK_FORMAT_R16G16_SFLOAT;
1561 
1562 		case FMT_CASE(RGB, UNORM_INT16):					return VK_FORMAT_R16G16B16_UNORM;
1563 		case FMT_CASE(RGB, SNORM_INT16):					return VK_FORMAT_R16G16B16_SNORM;
1564 		case FMT_CASE(RGB, UNSIGNED_INT16):					return VK_FORMAT_R16G16B16_UINT;
1565 		case FMT_CASE(RGB, SIGNED_INT16):					return VK_FORMAT_R16G16B16_SINT;
1566 		case FMT_CASE(RGB, HALF_FLOAT):						return VK_FORMAT_R16G16B16_SFLOAT;
1567 
1568 		case FMT_CASE(RGBA, UNORM_INT16):					return VK_FORMAT_R16G16B16A16_UNORM;
1569 		case FMT_CASE(RGBA, SNORM_INT16):					return VK_FORMAT_R16G16B16A16_SNORM;
1570 		case FMT_CASE(RGBA, UNSIGNED_INT16):				return VK_FORMAT_R16G16B16A16_UINT;
1571 		case FMT_CASE(RGBA, SIGNED_INT16):					return VK_FORMAT_R16G16B16A16_SINT;
1572 		case FMT_CASE(RGBA, HALF_FLOAT):					return VK_FORMAT_R16G16B16A16_SFLOAT;
1573 
1574 		case FMT_CASE(R, UNSIGNED_INT32):					return VK_FORMAT_R32_UINT;
1575 		case FMT_CASE(R, SIGNED_INT32):						return VK_FORMAT_R32_SINT;
1576 		case FMT_CASE(R, FLOAT):							return VK_FORMAT_R32_SFLOAT;
1577 
1578 		case FMT_CASE(RG, UNSIGNED_INT32):					return VK_FORMAT_R32G32_UINT;
1579 		case FMT_CASE(RG, SIGNED_INT32):					return VK_FORMAT_R32G32_SINT;
1580 		case FMT_CASE(RG, FLOAT):							return VK_FORMAT_R32G32_SFLOAT;
1581 
1582 		case FMT_CASE(RGB, UNSIGNED_INT32):					return VK_FORMAT_R32G32B32_UINT;
1583 		case FMT_CASE(RGB, SIGNED_INT32):					return VK_FORMAT_R32G32B32_SINT;
1584 		case FMT_CASE(RGB, FLOAT):							return VK_FORMAT_R32G32B32_SFLOAT;
1585 
1586 		case FMT_CASE(RGBA, UNSIGNED_INT32):				return VK_FORMAT_R32G32B32A32_UINT;
1587 		case FMT_CASE(RGBA, SIGNED_INT32):					return VK_FORMAT_R32G32B32A32_SINT;
1588 		case FMT_CASE(RGBA, FLOAT):							return VK_FORMAT_R32G32B32A32_SFLOAT;
1589 
1590 		case FMT_CASE(R, FLOAT64):							return VK_FORMAT_R64_SFLOAT;
1591 		case FMT_CASE(RG, FLOAT64):							return VK_FORMAT_R64G64_SFLOAT;
1592 		case FMT_CASE(RGB, FLOAT64):						return VK_FORMAT_R64G64B64_SFLOAT;
1593 		case FMT_CASE(RGBA, FLOAT64):						return VK_FORMAT_R64G64B64A64_SFLOAT;
1594 
1595 		case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV):	return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
1596 		case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV):		return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
1597 
1598 		case FMT_CASE(BGR, UNORM_INT8):						return VK_FORMAT_B8G8R8_UNORM;
1599 		case FMT_CASE(BGR, SNORM_INT8):						return VK_FORMAT_B8G8R8_SNORM;
1600 		case FMT_CASE(BGR, UNSIGNED_INT8):					return VK_FORMAT_B8G8R8_UINT;
1601 		case FMT_CASE(BGR, SIGNED_INT8):					return VK_FORMAT_B8G8R8_SINT;
1602 		case FMT_CASE(sBGR, UNORM_INT8):					return VK_FORMAT_B8G8R8_SRGB;
1603 
1604 		case FMT_CASE(BGRA, UNORM_INT8):					return VK_FORMAT_B8G8R8A8_UNORM;
1605 		case FMT_CASE(BGRA, SNORM_INT8):					return VK_FORMAT_B8G8R8A8_SNORM;
1606 		case FMT_CASE(BGRA, UNSIGNED_INT8):					return VK_FORMAT_B8G8R8A8_UINT;
1607 		case FMT_CASE(BGRA, SIGNED_INT8):					return VK_FORMAT_B8G8R8A8_SINT;
1608 		case FMT_CASE(sBGRA, UNORM_INT8):					return VK_FORMAT_B8G8R8A8_SRGB;
1609 
1610 		case FMT_CASE(BGRA, UNORM_INT_1010102_REV):			return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
1611 		case FMT_CASE(BGRA, SNORM_INT_1010102_REV):			return VK_FORMAT_A2R10G10B10_SNORM_PACK32;
1612 		case FMT_CASE(BGRA, UNSIGNED_INT_1010102_REV):		return VK_FORMAT_A2R10G10B10_UINT_PACK32;
1613 		case FMT_CASE(BGRA, SIGNED_INT_1010102_REV):		return VK_FORMAT_A2R10G10B10_SINT_PACK32;
1614 
1615 		case FMT_CASE(D, UNORM_INT16):						return VK_FORMAT_D16_UNORM;
1616 		case FMT_CASE(D, UNSIGNED_INT_24_8_REV):			return VK_FORMAT_X8_D24_UNORM_PACK32;
1617 		case FMT_CASE(D, FLOAT):							return VK_FORMAT_D32_SFLOAT;
1618 
1619 		case FMT_CASE(S, UNSIGNED_INT8):					return VK_FORMAT_S8_UINT;
1620 
1621 		case FMT_CASE(DS, UNSIGNED_INT_16_8_8):				return VK_FORMAT_D16_UNORM_S8_UINT;
1622 		case FMT_CASE(DS, UNSIGNED_INT_24_8_REV):			return VK_FORMAT_D24_UNORM_S8_UINT;
1623 		case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV):		return VK_FORMAT_D32_SFLOAT_S8_UINT;
1624 
1625 
1626 		case FMT_CASE(R,	UNORM_SHORT_10):				return VK_FORMAT_R10X6_UNORM_PACK16_KHR;
1627 		case FMT_CASE(RG,	UNORM_SHORT_10):				return VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR;
1628 		case FMT_CASE(RGBA,	UNORM_SHORT_10):				return VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR;
1629 
1630 		case FMT_CASE(R,	UNORM_SHORT_12):				return VK_FORMAT_R12X4_UNORM_PACK16_KHR;
1631 		case FMT_CASE(RG,	UNORM_SHORT_12):				return VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR;
1632 		case FMT_CASE(RGBA,	UNORM_SHORT_12):				return VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR;
1633 
1634 		default:
1635 			TCU_THROW(InternalError, "Unknown texture format");
1636 	}
1637 
1638 #undef PACK_FMT
1639 #undef FMT_CASE
1640 }
1641 
mapVkFormat(VkFormat format)1642 tcu::TextureFormat mapVkFormat (VkFormat format)
1643 {
1644 	using tcu::TextureFormat;
1645 
1646 	// update this mapping if VkFormat changes
1647 	DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1648 
1649 	switch (format)
1650 	{
1651 		case VK_FORMAT_R4G4_UNORM_PACK8:		return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_BYTE_44);
1652 		case VK_FORMAT_R5G6B5_UNORM_PACK16:		return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_SHORT_565);
1653 		case VK_FORMAT_R4G4B4A4_UNORM_PACK16:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_4444);
1654 		case VK_FORMAT_R5G5B5A1_UNORM_PACK16:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_5551);
1655 
1656 		case VK_FORMAT_B5G6R5_UNORM_PACK16:		return TextureFormat(TextureFormat::BGR,	TextureFormat::UNORM_SHORT_565);
1657 		case VK_FORMAT_B4G4R4A4_UNORM_PACK16:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNORM_SHORT_4444);
1658 		case VK_FORMAT_B5G5R5A1_UNORM_PACK16:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNORM_SHORT_5551);
1659 
1660 		case VK_FORMAT_A1R5G5B5_UNORM_PACK16:	return TextureFormat(TextureFormat::ARGB,	TextureFormat::UNORM_SHORT_1555);
1661 
1662 		case VK_FORMAT_R8_UNORM:				return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT8);
1663 		case VK_FORMAT_R8_SNORM:				return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT8);
1664 		case VK_FORMAT_R8_USCALED:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT8);
1665 		case VK_FORMAT_R8_SSCALED:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT8);
1666 		case VK_FORMAT_R8_UINT:					return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT8);
1667 		case VK_FORMAT_R8_SINT:					return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT8);
1668 		case VK_FORMAT_R8_SRGB:					return TextureFormat(TextureFormat::sR,		TextureFormat::UNORM_INT8);
1669 
1670 		case VK_FORMAT_R8G8_UNORM:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT8);
1671 		case VK_FORMAT_R8G8_SNORM:				return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT8);
1672 		case VK_FORMAT_R8G8_USCALED:			return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT8);
1673 		case VK_FORMAT_R8G8_SSCALED:			return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT8);
1674 		case VK_FORMAT_R8G8_UINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT8);
1675 		case VK_FORMAT_R8G8_SINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT8);
1676 		case VK_FORMAT_R8G8_SRGB:				return TextureFormat(TextureFormat::sRG,	TextureFormat::UNORM_INT8);
1677 
1678 		case VK_FORMAT_R8G8B8_UNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT8);
1679 		case VK_FORMAT_R8G8B8_SNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT8);
1680 		case VK_FORMAT_R8G8B8_USCALED:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT8);
1681 		case VK_FORMAT_R8G8B8_SSCALED:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT8);
1682 		case VK_FORMAT_R8G8B8_UINT:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT8);
1683 		case VK_FORMAT_R8G8B8_SINT:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT8);
1684 		case VK_FORMAT_R8G8B8_SRGB:				return TextureFormat(TextureFormat::sRGB,	TextureFormat::UNORM_INT8);
1685 
1686 		case VK_FORMAT_R8G8B8A8_UNORM:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT8);
1687 		case VK_FORMAT_R8G8B8A8_SNORM:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT8);
1688 		case VK_FORMAT_R8G8B8A8_USCALED:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
1689 		case VK_FORMAT_R8G8B8A8_SSCALED:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
1690 		case VK_FORMAT_R8G8B8A8_UINT:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
1691 		case VK_FORMAT_R8G8B8A8_SINT:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
1692 		case VK_FORMAT_R8G8B8A8_SRGB:			return TextureFormat(TextureFormat::sRGBA,	TextureFormat::UNORM_INT8);
1693 
1694 		case VK_FORMAT_R16_UNORM:				return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT16);
1695 		case VK_FORMAT_R16_SNORM:				return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT16);
1696 		case VK_FORMAT_R16_USCALED:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT16);
1697 		case VK_FORMAT_R16_SSCALED:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT16);
1698 		case VK_FORMAT_R16_UINT:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT16);
1699 		case VK_FORMAT_R16_SINT:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT16);
1700 		case VK_FORMAT_R16_SFLOAT:				return TextureFormat(TextureFormat::R,		TextureFormat::HALF_FLOAT);
1701 
1702 		case VK_FORMAT_R16G16_UNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT16);
1703 		case VK_FORMAT_R16G16_SNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT16);
1704 		case VK_FORMAT_R16G16_USCALED:			return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT16);
1705 		case VK_FORMAT_R16G16_SSCALED:			return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT16);
1706 		case VK_FORMAT_R16G16_UINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT16);
1707 		case VK_FORMAT_R16G16_SINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT16);
1708 		case VK_FORMAT_R16G16_SFLOAT:			return TextureFormat(TextureFormat::RG,		TextureFormat::HALF_FLOAT);
1709 
1710 		case VK_FORMAT_R16G16B16_UNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT16);
1711 		case VK_FORMAT_R16G16B16_SNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT16);
1712 		case VK_FORMAT_R16G16B16_USCALED:		return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT16);
1713 		case VK_FORMAT_R16G16B16_SSCALED:		return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT16);
1714 		case VK_FORMAT_R16G16B16_UINT:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT16);
1715 		case VK_FORMAT_R16G16B16_SINT:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT16);
1716 		case VK_FORMAT_R16G16B16_SFLOAT:		return TextureFormat(TextureFormat::RGB,	TextureFormat::HALF_FLOAT);
1717 
1718 		case VK_FORMAT_R16G16B16A16_UNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT16);
1719 		case VK_FORMAT_R16G16B16A16_SNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT16);
1720 		case VK_FORMAT_R16G16B16A16_USCALED:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT16);
1721 		case VK_FORMAT_R16G16B16A16_SSCALED:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT16);
1722 		case VK_FORMAT_R16G16B16A16_UINT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT16);
1723 		case VK_FORMAT_R16G16B16A16_SINT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT16);
1724 		case VK_FORMAT_R16G16B16A16_SFLOAT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::HALF_FLOAT);
1725 
1726 		case VK_FORMAT_R32_UINT:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT32);
1727 		case VK_FORMAT_R32_SINT:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT32);
1728 		case VK_FORMAT_R32_SFLOAT:				return TextureFormat(TextureFormat::R,		TextureFormat::FLOAT);
1729 
1730 		case VK_FORMAT_R32G32_UINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT32);
1731 		case VK_FORMAT_R32G32_SINT:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT32);
1732 		case VK_FORMAT_R32G32_SFLOAT:			return TextureFormat(TextureFormat::RG,		TextureFormat::FLOAT);
1733 
1734 		case VK_FORMAT_R32G32B32_UINT:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT32);
1735 		case VK_FORMAT_R32G32B32_SINT:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT32);
1736 		case VK_FORMAT_R32G32B32_SFLOAT:		return TextureFormat(TextureFormat::RGB,	TextureFormat::FLOAT);
1737 
1738 		case VK_FORMAT_R32G32B32A32_UINT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT32);
1739 		case VK_FORMAT_R32G32B32A32_SINT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT32);
1740 		case VK_FORMAT_R32G32B32A32_SFLOAT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::FLOAT);
1741 
1742 		case VK_FORMAT_R64_SFLOAT:				return TextureFormat(TextureFormat::R,		TextureFormat::FLOAT64);
1743 		case VK_FORMAT_R64G64_SFLOAT:			return TextureFormat(TextureFormat::RG,		TextureFormat::FLOAT64);
1744 		case VK_FORMAT_R64G64B64_SFLOAT:		return TextureFormat(TextureFormat::RGB,	TextureFormat::FLOAT64);
1745 		case VK_FORMAT_R64G64B64A64_SFLOAT:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::FLOAT64);
1746 
1747 		case VK_FORMAT_B10G11R11_UFLOAT_PACK32:	return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
1748 		case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:	return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_999_E5_REV);
1749 
1750 		case VK_FORMAT_B8G8R8_UNORM:			return TextureFormat(TextureFormat::BGR,	TextureFormat::UNORM_INT8);
1751 		case VK_FORMAT_B8G8R8_SNORM:			return TextureFormat(TextureFormat::BGR,	TextureFormat::SNORM_INT8);
1752 		case VK_FORMAT_B8G8R8_USCALED:			return TextureFormat(TextureFormat::BGR,	TextureFormat::UNSIGNED_INT8);
1753 		case VK_FORMAT_B8G8R8_SSCALED:			return TextureFormat(TextureFormat::BGR,	TextureFormat::SIGNED_INT8);
1754 		case VK_FORMAT_B8G8R8_UINT:				return TextureFormat(TextureFormat::BGR,	TextureFormat::UNSIGNED_INT8);
1755 		case VK_FORMAT_B8G8R8_SINT:				return TextureFormat(TextureFormat::BGR,	TextureFormat::SIGNED_INT8);
1756 		case VK_FORMAT_B8G8R8_SRGB:				return TextureFormat(TextureFormat::sBGR,	TextureFormat::UNORM_INT8);
1757 
1758 		case VK_FORMAT_B8G8R8A8_UNORM:			return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNORM_INT8);
1759 		case VK_FORMAT_B8G8R8A8_SNORM:			return TextureFormat(TextureFormat::BGRA,	TextureFormat::SNORM_INT8);
1760 		case VK_FORMAT_B8G8R8A8_USCALED:		return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNSIGNED_INT8);
1761 		case VK_FORMAT_B8G8R8A8_SSCALED:		return TextureFormat(TextureFormat::BGRA,	TextureFormat::SIGNED_INT8);
1762 		case VK_FORMAT_B8G8R8A8_UINT:			return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNSIGNED_INT8);
1763 		case VK_FORMAT_B8G8R8A8_SINT:			return TextureFormat(TextureFormat::BGRA,	TextureFormat::SIGNED_INT8);
1764 		case VK_FORMAT_B8G8R8A8_SRGB:			return TextureFormat(TextureFormat::sBGRA,	TextureFormat::UNORM_INT8);
1765 
1766 		case VK_FORMAT_D16_UNORM:				return TextureFormat(TextureFormat::D,		TextureFormat::UNORM_INT16);
1767 		case VK_FORMAT_X8_D24_UNORM_PACK32:		return TextureFormat(TextureFormat::D,		TextureFormat::UNSIGNED_INT_24_8_REV);
1768 		case VK_FORMAT_D32_SFLOAT:				return TextureFormat(TextureFormat::D,		TextureFormat::FLOAT);
1769 
1770 		case VK_FORMAT_S8_UINT:					return TextureFormat(TextureFormat::S,		TextureFormat::UNSIGNED_INT8);
1771 
1772 		// \note There is no standard interleaved memory layout for DS formats; buffer-image copies
1773 		//		 will always operate on either D or S aspect only. See Khronos bug 12998
1774 		case VK_FORMAT_D16_UNORM_S8_UINT:		return TextureFormat(TextureFormat::DS,		TextureFormat::UNSIGNED_INT_16_8_8);
1775 		case VK_FORMAT_D24_UNORM_S8_UINT:		return TextureFormat(TextureFormat::DS,		TextureFormat::UNSIGNED_INT_24_8_REV);
1776 		case VK_FORMAT_D32_SFLOAT_S8_UINT:		return TextureFormat(TextureFormat::DS,		TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
1777 
1778 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
1779 		case VK_FORMAT_A8B8G8R8_UNORM_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT8);
1780 		case VK_FORMAT_A8B8G8R8_SNORM_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT8);
1781 		case VK_FORMAT_A8B8G8R8_USCALED_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
1782 		case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
1783 		case VK_FORMAT_A8B8G8R8_UINT_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
1784 		case VK_FORMAT_A8B8G8R8_SINT_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
1785 		case VK_FORMAT_A8B8G8R8_SRGB_PACK32:	return TextureFormat(TextureFormat::sRGBA,	TextureFormat::UNORM_INT8);
1786 #else
1787 #	error "Big-endian not supported"
1788 #endif
1789 
1790 		case VK_FORMAT_A2R10G10B10_UNORM_PACK32:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNORM_INT_1010102_REV);
1791 		case VK_FORMAT_A2R10G10B10_SNORM_PACK32:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::SNORM_INT_1010102_REV);
1792 		case VK_FORMAT_A2R10G10B10_USCALED_PACK32:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNSIGNED_INT_1010102_REV);
1793 		case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:	return TextureFormat(TextureFormat::BGRA,	TextureFormat::SIGNED_INT_1010102_REV);
1794 		case VK_FORMAT_A2R10G10B10_UINT_PACK32:		return TextureFormat(TextureFormat::BGRA,	TextureFormat::UNSIGNED_INT_1010102_REV);
1795 		case VK_FORMAT_A2R10G10B10_SINT_PACK32:		return TextureFormat(TextureFormat::BGRA,	TextureFormat::SIGNED_INT_1010102_REV);
1796 
1797 		case VK_FORMAT_A2B10G10R10_UNORM_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT_1010102_REV);
1798 		case VK_FORMAT_A2B10G10R10_SNORM_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT_1010102_REV);
1799 		case VK_FORMAT_A2B10G10R10_USCALED_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT_1010102_REV);
1800 		case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT_1010102_REV);
1801 		case VK_FORMAT_A2B10G10R10_UINT_PACK32:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT_1010102_REV);
1802 		case VK_FORMAT_A2B10G10R10_SINT_PACK32:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT_1010102_REV);
1803 
1804 		// YCbCr formats that can be mapped
1805 		case VK_FORMAT_R10X6_UNORM_PACK16_KHR:					return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_SHORT_10);
1806 		case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:			return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_SHORT_10);
1807 		case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_10);
1808 
1809 		case VK_FORMAT_R12X4_UNORM_PACK16_KHR:					return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_SHORT_12);
1810 		case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:			return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_SHORT_12);
1811 		case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:	return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_12);
1812 
1813 		default:
1814 			TCU_THROW(InternalError, "Unknown image format");
1815 	}
1816 }
1817 
mapVkCompressedFormat(VkFormat format)1818 tcu::CompressedTexFormat mapVkCompressedFormat (VkFormat format)
1819 {
1820 	// update this mapping if VkFormat changes
1821 	DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1822 
1823 	switch (format)
1824 	{
1825 		case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
1826 		case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
1827 		case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:	return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
1828 		case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:	return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
1829 		case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:	return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
1830 		case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:	return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
1831 		case VK_FORMAT_EAC_R11_UNORM_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
1832 		case VK_FORMAT_EAC_R11_SNORM_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
1833 		case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
1834 		case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
1835 		case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
1836 		case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
1837 		case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
1838 		case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8;
1839 		case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
1840 		case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
1841 		case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
1842 		case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
1843 		case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
1844 		case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
1845 		case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
1846 		case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8;
1847 		case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
1848 		case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
1849 		case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
1850 		case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:			return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
1851 		case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
1852 		case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
1853 		case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
1854 		case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
1855 		case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
1856 		case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
1857 		case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
1858 		case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
1859 		case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
1860 		case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
1861 		case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
1862 		case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:		return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
1863 		default:
1864 			break;
1865 	}
1866 
1867 	return tcu::COMPRESSEDTEXFORMAT_LAST;
1868 }
1869 
isScaledFormat(VkFormat format)1870 static bool isScaledFormat (VkFormat format)
1871 {
1872 	// update this mapping if VkFormat changes
1873 	DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1874 
1875 	switch (format)
1876 	{
1877 		case VK_FORMAT_R8_USCALED:
1878 		case VK_FORMAT_R8_SSCALED:
1879 		case VK_FORMAT_R8G8_USCALED:
1880 		case VK_FORMAT_R8G8_SSCALED:
1881 		case VK_FORMAT_R8G8B8_USCALED:
1882 		case VK_FORMAT_R8G8B8_SSCALED:
1883 		case VK_FORMAT_R8G8B8A8_USCALED:
1884 		case VK_FORMAT_R8G8B8A8_SSCALED:
1885 		case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1886 		case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1887 		case VK_FORMAT_R16_USCALED:
1888 		case VK_FORMAT_R16_SSCALED:
1889 		case VK_FORMAT_R16G16_USCALED:
1890 		case VK_FORMAT_R16G16_SSCALED:
1891 		case VK_FORMAT_R16G16B16_USCALED:
1892 		case VK_FORMAT_R16G16B16_SSCALED:
1893 		case VK_FORMAT_R16G16B16A16_USCALED:
1894 		case VK_FORMAT_R16G16B16A16_SSCALED:
1895 		case VK_FORMAT_B8G8R8_USCALED:
1896 		case VK_FORMAT_B8G8R8_SSCALED:
1897 		case VK_FORMAT_B8G8R8A8_USCALED:
1898 		case VK_FORMAT_B8G8R8A8_SSCALED:
1899 		case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1900 		case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1901 			return true;
1902 
1903 		default:
1904 			return false;
1905 	}
1906 }
1907 
fullTextureFormatRoundTripSupported(VkFormat format)1908 static bool fullTextureFormatRoundTripSupported (VkFormat format)
1909 {
1910 	if (isScaledFormat(format))
1911 	{
1912 		// *SCALED formats get mapped to correspoding (u)int formats since
1913 		// accessing them through (float) getPixel/setPixel has same behavior
1914 		// as in shader access in Vulkan.
1915 		// Unfortunately full round-trip between tcu::TextureFormat and VkFormat
1916 		// for most SCALED formats is not supported though.
1917 
1918 		const tcu::TextureFormat	tcuFormat	= mapVkFormat(format);
1919 
1920 		switch (tcuFormat.type)
1921 		{
1922 			case tcu::TextureFormat::UNSIGNED_INT8:
1923 			case tcu::TextureFormat::UNSIGNED_INT16:
1924 			case tcu::TextureFormat::UNSIGNED_INT32:
1925 			case tcu::TextureFormat::SIGNED_INT8:
1926 			case tcu::TextureFormat::SIGNED_INT16:
1927 			case tcu::TextureFormat::SIGNED_INT32:
1928 			case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
1929 			case tcu::TextureFormat::SIGNED_INT_1010102_REV:
1930 				return false;
1931 
1932 			default:
1933 				return true;
1934 		}
1935 	}
1936 	else
1937 	{
1938 		switch (format)
1939 		{
1940 			case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1941 			case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1942 			case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1943 			case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1944 			case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1945 			case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1946 			case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1947 				return false; // These map to regular byte array formats
1948 
1949 			default:
1950 				break;
1951 		}
1952 
1953 		return (format != VK_FORMAT_UNDEFINED);
1954 	}
1955 }
1956 
getChannelAccessFormat(tcu::TextureChannelClass type,deUint32 offsetBits,deUint32 sizeBits)1957 tcu::TextureFormat getChannelAccessFormat (tcu::TextureChannelClass	type,
1958 										   deUint32					offsetBits,
1959 										   deUint32					sizeBits)
1960 {
1961 	using tcu::TextureFormat;
1962 
1963 	if (offsetBits == 0)
1964 	{
1965 		static const TextureFormat::ChannelType	s_size8[tcu::TEXTURECHANNELCLASS_LAST] =
1966 		{
1967 			TextureFormat::SNORM_INT8,			// snorm
1968 			TextureFormat::UNORM_INT8,			// unorm
1969 			TextureFormat::SIGNED_INT8,			// sint
1970 			TextureFormat::UNSIGNED_INT8,		// uint
1971 			TextureFormat::CHANNELTYPE_LAST,	// float
1972 		};
1973 		static const TextureFormat::ChannelType	s_size16[tcu::TEXTURECHANNELCLASS_LAST] =
1974 		{
1975 			TextureFormat::SNORM_INT16,			// snorm
1976 			TextureFormat::UNORM_INT16,			// unorm
1977 			TextureFormat::SIGNED_INT16,		// sint
1978 			TextureFormat::UNSIGNED_INT16,		// uint
1979 			TextureFormat::HALF_FLOAT,			// float
1980 		};
1981 		static const TextureFormat::ChannelType	s_size32[tcu::TEXTURECHANNELCLASS_LAST] =
1982 		{
1983 			TextureFormat::SNORM_INT32,			// snorm
1984 			TextureFormat::UNORM_INT32,			// unorm
1985 			TextureFormat::SIGNED_INT32,		// sint
1986 			TextureFormat::UNSIGNED_INT32,		// uint
1987 			TextureFormat::FLOAT,				// float
1988 		};
1989 
1990 		TextureFormat::ChannelType	chnType		= TextureFormat::CHANNELTYPE_LAST;
1991 
1992 		if (sizeBits == 8)
1993 			chnType = s_size8[type];
1994 		else if (sizeBits == 16)
1995 			chnType = s_size16[type];
1996 		else if (sizeBits == 32)
1997 			chnType = s_size32[type];
1998 
1999 		if (chnType != TextureFormat::CHANNELTYPE_LAST)
2000 			return TextureFormat(TextureFormat::R, chnType);
2001 	}
2002 	else
2003 	{
2004 		if (type		== tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT	&&
2005 			offsetBits	== 6												&&
2006 			sizeBits	== 10)
2007 			return TextureFormat(TextureFormat::R, TextureFormat::UNORM_SHORT_10);
2008 		else if (type		== tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT	&&
2009 				 offsetBits	== 4												&&
2010 				 sizeBits	== 12)
2011 			return TextureFormat(TextureFormat::R, TextureFormat::UNORM_SHORT_12);
2012 	}
2013 
2014 	TCU_THROW(InternalError, "Channel access format is not supported");
2015 }
2016 
getChannelAccess(const PlanarFormatDescription & formatInfo,const tcu::UVec2 & size,const deUint32 * planeRowPitches,void * const * planePtrs,deUint32 channelNdx)2017 tcu::PixelBufferAccess getChannelAccess (const PlanarFormatDescription&	formatInfo,
2018 										 const tcu::UVec2&				size,
2019 										 const deUint32*				planeRowPitches,
2020 										 void* const*					planePtrs,
2021 										 deUint32						channelNdx)
2022 {
2023 	DE_ASSERT(formatInfo.hasChannelNdx(channelNdx));
2024 
2025 	const deUint32	planeNdx			= formatInfo.channels[channelNdx].planeNdx;
2026 	const deUint32	planeOffsetBytes	= formatInfo.channels[channelNdx].offsetBits / 8;
2027 	const deUint32	valueOffsetBits		= formatInfo.channels[channelNdx].offsetBits % 8;
2028 	const deUint32	pixelStrideBytes	= formatInfo.channels[channelNdx].strideBytes;
2029 
2030 	DE_ASSERT(size.x() % formatInfo.planes[planeNdx].widthDivisor == 0);
2031 	DE_ASSERT(size.y() % formatInfo.planes[planeNdx].heightDivisor == 0);
2032 
2033 	deUint32		accessWidth			= size.x() / formatInfo.planes[planeNdx].widthDivisor;
2034 	const deUint32	accessHeight		= size.y() / formatInfo.planes[planeNdx].heightDivisor;
2035 	const deUint32	elementSizeBytes	= formatInfo.planes[planeNdx].elementSizeBytes;
2036 
2037 	const deUint32	rowPitch			= planeRowPitches[planeNdx];
2038 
2039 	if (pixelStrideBytes != elementSizeBytes)
2040 	{
2041 		DE_ASSERT(elementSizeBytes % pixelStrideBytes == 0);
2042 		accessWidth *= elementSizeBytes/pixelStrideBytes;
2043 	}
2044 
2045 	return tcu::PixelBufferAccess(getChannelAccessFormat((tcu::TextureChannelClass)formatInfo.channels[channelNdx].type,
2046 														 valueOffsetBits,
2047 														 formatInfo.channels[channelNdx].sizeBits),
2048 								  tcu::IVec3((int)accessWidth, (int)accessHeight, 1),
2049 								  tcu::IVec3((int)pixelStrideBytes, (int)rowPitch, 0),
2050 								  (deUint8*)planePtrs[planeNdx] + planeOffsetBytes);
2051 }
2052 
2053 
getChannelAccess(const PlanarFormatDescription & formatInfo,const tcu::UVec2 & size,const deUint32 * planeRowPitches,const void * const * planePtrs,deUint32 channelNdx)2054 tcu::ConstPixelBufferAccess getChannelAccess (const PlanarFormatDescription&	formatInfo,
2055 											  const tcu::UVec2&					size,
2056 											  const deUint32*					planeRowPitches,
2057 											  const void* const*				planePtrs,
2058 											  deUint32							channelNdx)
2059 {
2060 	return getChannelAccess(formatInfo, size, planeRowPitches, const_cast<void* const*>(planePtrs), channelNdx);
2061 }
2062 
imageUtilSelfTest(void)2063 void imageUtilSelfTest (void)
2064 {
2065 	for (int formatNdx = 0; formatNdx < VK_CORE_FORMAT_LAST; formatNdx++)
2066 	{
2067 		const VkFormat	format	= (VkFormat)formatNdx;
2068 
2069 		if (format == VK_FORMAT_R64_UINT			||
2070 			format == VK_FORMAT_R64_SINT			||
2071 			format == VK_FORMAT_R64G64_UINT			||
2072 			format == VK_FORMAT_R64G64_SINT			||
2073 			format == VK_FORMAT_R64G64B64_UINT		||
2074 			format == VK_FORMAT_R64G64B64_SINT		||
2075 			format == VK_FORMAT_R64G64B64A64_UINT	||
2076 			format == VK_FORMAT_R64G64B64A64_SINT)
2077 			continue; // \todo [2015-12-05 pyry] Add framework support for (u)int64 channel type
2078 
2079 		if (format != VK_FORMAT_UNDEFINED && !isCompressedFormat(format))
2080 		{
2081 			const tcu::TextureFormat	tcuFormat		= mapVkFormat(format);
2082 			const VkFormat				remappedFormat	= mapTextureFormat(tcuFormat);
2083 
2084 			DE_TEST_ASSERT(isValid(tcuFormat));
2085 
2086 			if (fullTextureFormatRoundTripSupported(format))
2087 				DE_TEST_ASSERT(format == remappedFormat);
2088 		}
2089 	}
2090 
2091 	for (int formatNdx = VK_FORMAT_G8B8G8R8_422_UNORM_KHR; formatNdx <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR; formatNdx++)
2092 	{
2093 		const VkFormat					format	= (VkFormat)formatNdx;
2094 		const PlanarFormatDescription&	info	= getPlanarFormatDescription(format);
2095 
2096 		DE_TEST_ASSERT(isYCbCrFormat(format));
2097 		DE_TEST_ASSERT(de::inRange<deUint8>(info.numPlanes, 1u, 3u));
2098 		DE_TEST_ASSERT(info.numPlanes == getPlaneCount(format));
2099 	}
2100 }
2101 
mapFilterMode(tcu::Sampler::FilterMode filterMode)2102 VkFilter mapFilterMode (tcu::Sampler::FilterMode filterMode)
2103 {
2104 	DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
2105 
2106 	switch (filterMode)
2107 	{
2108 		case tcu::Sampler::NEAREST:					return VK_FILTER_NEAREST;
2109 		case tcu::Sampler::LINEAR:					return VK_FILTER_LINEAR;
2110 		case tcu::Sampler::NEAREST_MIPMAP_NEAREST:	return VK_FILTER_NEAREST;
2111 		case tcu::Sampler::NEAREST_MIPMAP_LINEAR:	return VK_FILTER_NEAREST;
2112 		case tcu::Sampler::LINEAR_MIPMAP_NEAREST:	return VK_FILTER_LINEAR;
2113 		case tcu::Sampler::LINEAR_MIPMAP_LINEAR:	return VK_FILTER_LINEAR;
2114 		default:
2115 			DE_FATAL("Illegal filter mode");
2116 			return (VkFilter)0;
2117 
2118 	}
2119 }
2120 
mapMipmapMode(tcu::Sampler::FilterMode filterMode)2121 VkSamplerMipmapMode mapMipmapMode (tcu::Sampler::FilterMode filterMode)
2122 {
2123 	DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
2124 
2125 	// \note VkSamplerCreateInfo doesn't have a flag for disabling mipmapping. Instead
2126 	//		 minLod = 0 and maxLod = 0.25 should be used to match OpenGL NEAREST and LINEAR
2127 	//		 filtering mode behavior.
2128 
2129 	switch (filterMode)
2130 	{
2131 		case tcu::Sampler::NEAREST:					return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2132 		case tcu::Sampler::LINEAR:					return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2133 		case tcu::Sampler::NEAREST_MIPMAP_NEAREST:	return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2134 		case tcu::Sampler::NEAREST_MIPMAP_LINEAR:	return VK_SAMPLER_MIPMAP_MODE_LINEAR;
2135 		case tcu::Sampler::LINEAR_MIPMAP_NEAREST:	return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2136 		case tcu::Sampler::LINEAR_MIPMAP_LINEAR:	return VK_SAMPLER_MIPMAP_MODE_LINEAR;
2137 		default:
2138 			DE_FATAL("Illegal filter mode");
2139 			return (VkSamplerMipmapMode)0;
2140 	}
2141 }
2142 
mapWrapMode(tcu::Sampler::WrapMode wrapMode)2143 VkSamplerAddressMode mapWrapMode (tcu::Sampler::WrapMode wrapMode)
2144 {
2145 	switch (wrapMode)
2146 	{
2147 		case tcu::Sampler::CLAMP_TO_EDGE:		return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2148 		case tcu::Sampler::CLAMP_TO_BORDER:		return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
2149 		case tcu::Sampler::REPEAT_GL:			return VK_SAMPLER_ADDRESS_MODE_REPEAT;
2150 		case tcu::Sampler::MIRRORED_REPEAT_GL:	return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
2151 		case tcu::Sampler::MIRRORED_ONCE:		return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
2152 		default:
2153 			DE_FATAL("Wrap mode can't be mapped to Vulkan");
2154 			return (vk::VkSamplerAddressMode)0;
2155 	}
2156 }
2157 
mapCompareMode(tcu::Sampler::CompareMode mode)2158 vk::VkCompareOp mapCompareMode (tcu::Sampler::CompareMode mode)
2159 {
2160 	switch (mode)
2161 	{
2162 		case tcu::Sampler::COMPAREMODE_NONE:				return vk::VK_COMPARE_OP_NEVER;
2163 		case tcu::Sampler::COMPAREMODE_LESS:				return vk::VK_COMPARE_OP_LESS;
2164 		case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:		return vk::VK_COMPARE_OP_LESS_OR_EQUAL;
2165 		case tcu::Sampler::COMPAREMODE_GREATER:				return vk::VK_COMPARE_OP_GREATER;
2166 		case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:	return vk::VK_COMPARE_OP_GREATER_OR_EQUAL;
2167 		case tcu::Sampler::COMPAREMODE_EQUAL:				return vk::VK_COMPARE_OP_EQUAL;
2168 		case tcu::Sampler::COMPAREMODE_NOT_EQUAL:			return vk::VK_COMPARE_OP_NOT_EQUAL;
2169 		case tcu::Sampler::COMPAREMODE_ALWAYS:				return vk::VK_COMPARE_OP_ALWAYS;
2170 		case tcu::Sampler::COMPAREMODE_NEVER:				return vk::VK_COMPARE_OP_NEVER;
2171 		default:
2172 			DE_FATAL("Illegal compare mode");
2173 			return (vk::VkCompareOp)0;
2174 	}
2175 }
2176 
mapBorderColor(tcu::TextureChannelClass channelClass,const rr::GenericVec4 & color)2177 static VkBorderColor mapBorderColor (tcu::TextureChannelClass channelClass, const rr::GenericVec4& color)
2178 {
2179 	if (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
2180 	{
2181 		const tcu::UVec4	uColor	= color.get<deUint32>();
2182 
2183 		if (uColor		== tcu::UVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
2184 		else if (uColor	== tcu::UVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
2185 		else if (uColor == tcu::UVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
2186 	}
2187 	else if (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
2188 	{
2189 		const tcu::IVec4	sColor	= color.get<deInt32>();
2190 
2191 		if (sColor		== tcu::IVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
2192 		else if (sColor	== tcu::IVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
2193 		else if (sColor == tcu::IVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
2194 	}
2195 	else
2196 	{
2197 		const tcu::Vec4		fColor	= color.get<float>();
2198 
2199 		if (fColor		== tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f)) return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
2200 		else if (fColor == tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
2201 		else if (fColor == tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
2202 	}
2203 
2204 	DE_FATAL("Unsupported border color");
2205 	return VK_BORDER_COLOR_LAST;
2206 }
2207 
mapSampler(const tcu::Sampler & sampler,const tcu::TextureFormat & format,float minLod,float maxLod)2208 VkSamplerCreateInfo mapSampler (const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod, float maxLod)
2209 {
2210 	const bool					compareEnabled	= (sampler.compare != tcu::Sampler::COMPAREMODE_NONE);
2211 	const VkCompareOp			compareOp		= (compareEnabled) ? (mapCompareMode(sampler.compare)) : (VK_COMPARE_OP_ALWAYS);
2212 	const VkBorderColor			borderColor		= mapBorderColor(getTextureChannelClass(format.type), sampler.borderColor);
2213 	const bool					isMipmapEnabled	= (sampler.minFilter != tcu::Sampler::NEAREST && sampler.minFilter != tcu::Sampler::LINEAR);
2214 
2215 	const VkSamplerCreateInfo	createInfo		=
2216 	{
2217 		VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
2218 		DE_NULL,
2219 		(VkSamplerCreateFlags)0,
2220 		mapFilterMode(sampler.magFilter),							// magFilter
2221 		mapFilterMode(sampler.minFilter),							// minFilter
2222 		mapMipmapMode(sampler.minFilter),							// mipMode
2223 		mapWrapMode(sampler.wrapS),									// addressU
2224 		mapWrapMode(sampler.wrapT),									// addressV
2225 		mapWrapMode(sampler.wrapR),									// addressW
2226 		0.0f,														// mipLodBias
2227 		VK_FALSE,													// anisotropyEnable
2228 		1.0f,														// maxAnisotropy
2229 		(VkBool32)(compareEnabled ? VK_TRUE : VK_FALSE),			// compareEnable
2230 		compareOp,													// compareOp
2231 		(isMipmapEnabled ? minLod : 0.0f),							// minLod
2232 		(isMipmapEnabled ? maxLod : 0.25f),							// maxLod
2233 		borderColor,												// borderColor
2234 		(VkBool32)(sampler.normalizedCoords ? VK_FALSE : VK_TRUE),	// unnormalizedCoords
2235 	};
2236 
2237 	return createInfo;
2238 }
2239 
mapVkSampler(const VkSamplerCreateInfo & samplerCreateInfo)2240 tcu::Sampler mapVkSampler (const VkSamplerCreateInfo& samplerCreateInfo)
2241 {
2242 	// \note minLod & maxLod are not supported by tcu::Sampler. LOD must be clamped
2243 	//       before passing it to tcu::Texture*::sample*()
2244 
2245 	tcu::Sampler sampler(mapVkSamplerAddressMode(samplerCreateInfo.addressModeU),
2246 						 mapVkSamplerAddressMode(samplerCreateInfo.addressModeV),
2247 						 mapVkSamplerAddressMode(samplerCreateInfo.addressModeW),
2248 						 mapVkMinTexFilter(samplerCreateInfo.minFilter, samplerCreateInfo.mipmapMode),
2249 						 mapVkMagTexFilter(samplerCreateInfo.magFilter),
2250 						 0.0f,
2251 						 !samplerCreateInfo.unnormalizedCoordinates,
2252 						 samplerCreateInfo.compareEnable ? mapVkSamplerCompareOp(samplerCreateInfo.compareOp)
2253 														 : tcu::Sampler::COMPAREMODE_NONE,
2254 						 0,
2255 						 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
2256 						 true);
2257 
2258 	if (samplerCreateInfo.anisotropyEnable)
2259 		TCU_THROW(InternalError, "Anisotropic filtering is not supported by tcu::Sampler");
2260 
2261 	switch (samplerCreateInfo.borderColor)
2262 	{
2263 		case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
2264 			sampler.borderColor = tcu::UVec4(0,0,0,1);
2265 			break;
2266 		case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
2267 			sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
2268 			break;
2269 		case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
2270 			sampler.borderColor = tcu::UVec4(1, 1, 1, 1);
2271 			break;
2272 		case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
2273 			sampler.borderColor = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
2274 			break;
2275 		case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
2276 			sampler.borderColor = tcu::UVec4(0,0,0,0);
2277 			break;
2278 		case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
2279 			sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
2280 			break;
2281 
2282 		default:
2283 			DE_ASSERT(false);
2284 			break;
2285 	}
2286 
2287 	return sampler;
2288 }
2289 
mapVkSamplerCompareOp(VkCompareOp compareOp)2290 tcu::Sampler::CompareMode mapVkSamplerCompareOp (VkCompareOp compareOp)
2291 {
2292 	switch (compareOp)
2293 	{
2294 		case VK_COMPARE_OP_NEVER:				return tcu::Sampler::COMPAREMODE_NEVER;
2295 		case VK_COMPARE_OP_LESS:				return tcu::Sampler::COMPAREMODE_LESS;
2296 		case VK_COMPARE_OP_EQUAL:				return tcu::Sampler::COMPAREMODE_EQUAL;
2297 		case VK_COMPARE_OP_LESS_OR_EQUAL:		return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
2298 		case VK_COMPARE_OP_GREATER:				return tcu::Sampler::COMPAREMODE_GREATER;
2299 		case VK_COMPARE_OP_NOT_EQUAL:			return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
2300 		case VK_COMPARE_OP_GREATER_OR_EQUAL:	return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
2301 		case VK_COMPARE_OP_ALWAYS:				return tcu::Sampler::COMPAREMODE_ALWAYS;
2302 		default:
2303 			break;
2304 	}
2305 
2306 	DE_ASSERT(false);
2307 	return tcu::Sampler::COMPAREMODE_LAST;
2308 }
2309 
mapVkSamplerAddressMode(VkSamplerAddressMode addressMode)2310 tcu::Sampler::WrapMode mapVkSamplerAddressMode (VkSamplerAddressMode addressMode)
2311 {
2312 	switch (addressMode)
2313 	{
2314 		case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:			return tcu::Sampler::CLAMP_TO_EDGE;
2315 		case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:		return tcu::Sampler::CLAMP_TO_BORDER;
2316 		case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:		return tcu::Sampler::MIRRORED_REPEAT_GL;
2317 		case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:	return tcu::Sampler::MIRRORED_ONCE;
2318 		case VK_SAMPLER_ADDRESS_MODE_REPEAT:				return tcu::Sampler::REPEAT_GL;
2319 		default:
2320 			break;
2321 	}
2322 
2323 	DE_ASSERT(false);
2324 	return tcu::Sampler::WRAPMODE_LAST;
2325 }
2326 
mapVkMinTexFilter(VkFilter filter,VkSamplerMipmapMode mipMode)2327 tcu::Sampler::FilterMode mapVkMinTexFilter (VkFilter filter, VkSamplerMipmapMode mipMode)
2328 {
2329 	switch (filter)
2330 	{
2331 		case VK_FILTER_LINEAR:
2332 			switch (mipMode)
2333 			{
2334 				case VK_SAMPLER_MIPMAP_MODE_LINEAR:		return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
2335 				case VK_SAMPLER_MIPMAP_MODE_NEAREST:	return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
2336 				default:
2337 					break;
2338 			}
2339 			break;
2340 
2341 		case VK_FILTER_NEAREST:
2342 			switch (mipMode)
2343 			{
2344 				case VK_SAMPLER_MIPMAP_MODE_LINEAR:		return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
2345 				case VK_SAMPLER_MIPMAP_MODE_NEAREST:	return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
2346 				default:
2347 					break;
2348 			}
2349 			break;
2350 
2351 		default:
2352 			break;
2353 	}
2354 
2355 	DE_ASSERT(false);
2356 	return tcu::Sampler::FILTERMODE_LAST;
2357 }
2358 
mapVkMagTexFilter(VkFilter filter)2359 tcu::Sampler::FilterMode mapVkMagTexFilter (VkFilter filter)
2360 {
2361 	switch (filter)
2362 	{
2363 		case VK_FILTER_LINEAR:		return tcu::Sampler::LINEAR;
2364 		case VK_FILTER_NEAREST:		return tcu::Sampler::NEAREST;
2365 		default:
2366 			break;
2367 	}
2368 
2369 	DE_ASSERT(false);
2370 	return tcu::Sampler::FILTERMODE_LAST;
2371 }
2372 
2373 //! Get a format the matches the layout in buffer memory used for a
2374 //! buffer<->image copy on a depth/stencil format.
getDepthCopyFormat(VkFormat combinedFormat)2375 tcu::TextureFormat getDepthCopyFormat (VkFormat combinedFormat)
2376 {
2377 	switch (combinedFormat)
2378 	{
2379 		case VK_FORMAT_D16_UNORM:
2380 		case VK_FORMAT_X8_D24_UNORM_PACK32:
2381 		case VK_FORMAT_D32_SFLOAT:
2382 			return mapVkFormat(combinedFormat);
2383 
2384 		case VK_FORMAT_D16_UNORM_S8_UINT:
2385 			return mapVkFormat(VK_FORMAT_D16_UNORM);
2386 		case VK_FORMAT_D24_UNORM_S8_UINT:
2387 			return mapVkFormat(VK_FORMAT_X8_D24_UNORM_PACK32);
2388 		case VK_FORMAT_D32_SFLOAT_S8_UINT:
2389 			return mapVkFormat(VK_FORMAT_D32_SFLOAT);
2390 
2391 		case VK_FORMAT_S8_UINT:
2392 		default:
2393 			DE_FATAL("Unexpected depth/stencil format");
2394 			return tcu::TextureFormat();
2395 	}
2396 }
2397 
2398 //! Get a format the matches the layout in buffer memory used for a
2399 //! buffer<->image copy on a depth/stencil format.
getStencilCopyFormat(VkFormat combinedFormat)2400 tcu::TextureFormat getStencilCopyFormat (VkFormat combinedFormat)
2401 {
2402 	switch (combinedFormat)
2403 	{
2404 		case VK_FORMAT_D16_UNORM_S8_UINT:
2405 		case VK_FORMAT_D24_UNORM_S8_UINT:
2406 		case VK_FORMAT_D32_SFLOAT_S8_UINT:
2407 		case VK_FORMAT_S8_UINT:
2408 			return mapVkFormat(VK_FORMAT_S8_UINT);
2409 
2410 		case VK_FORMAT_D16_UNORM:
2411 		case VK_FORMAT_X8_D24_UNORM_PACK32:
2412 		case VK_FORMAT_D32_SFLOAT:
2413 		default:
2414 			DE_FATAL("Unexpected depth/stencil format");
2415 			return tcu::TextureFormat();
2416 	}
2417 }
2418 
2419 } // vk
2420