Merge vk-gl-cts/opengl-es-cts-3.2.4 into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkImageUtil.cpp
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 "vkRefUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "tcuTextureUtil.hpp"
30
31 namespace vk
32 {
33
34 bool isFloatFormat (VkFormat format)
35 {
36         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
37 }
38
39 bool isUnormFormat (VkFormat format)
40 {
41         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
42 }
43
44 bool isSnormFormat (VkFormat format)
45 {
46         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
47 }
48
49 bool isIntFormat (VkFormat format)
50 {
51         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER;
52 }
53
54 bool isUintFormat (VkFormat format)
55 {
56         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
57 }
58
59 bool isDepthStencilFormat (VkFormat format)
60 {
61         if (isCompressedFormat(format))
62                 return false;
63
64         if (isYCbCrFormat(format))
65                 return false;
66
67         const tcu::TextureFormat tcuFormat = mapVkFormat(format);
68         return tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS;
69 }
70
71 bool isSrgbFormat (VkFormat format)
72 {
73         switch (mapVkFormat(format).order)
74         {
75                 case tcu::TextureFormat::sR:
76                 case tcu::TextureFormat::sRG:
77                 case tcu::TextureFormat::sRGB:
78                 case tcu::TextureFormat::sRGBA:
79                 case tcu::TextureFormat::sBGR:
80                 case tcu::TextureFormat::sBGRA:
81                         return true;
82
83                 default:
84                         return false;
85         }
86 }
87
88 bool isCompressedFormat (VkFormat format)
89 {
90         // update this mapping if VkFormat changes
91         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
92
93         switch (format)
94         {
95                 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
96                 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
97                 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
98                 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
99                 case VK_FORMAT_BC2_UNORM_BLOCK:
100                 case VK_FORMAT_BC2_SRGB_BLOCK:
101                 case VK_FORMAT_BC3_UNORM_BLOCK:
102                 case VK_FORMAT_BC3_SRGB_BLOCK:
103                 case VK_FORMAT_BC4_UNORM_BLOCK:
104                 case VK_FORMAT_BC4_SNORM_BLOCK:
105                 case VK_FORMAT_BC5_UNORM_BLOCK:
106                 case VK_FORMAT_BC5_SNORM_BLOCK:
107                 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
108                 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
109                 case VK_FORMAT_BC7_UNORM_BLOCK:
110                 case VK_FORMAT_BC7_SRGB_BLOCK:
111                 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
112                 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
113                 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
114                 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
115                 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
116                 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
117                 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
118                 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
119                 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
120                 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
121                 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
122                 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
123                 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
124                 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
125                 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
126                 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
127                 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
128                 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
129                 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
130                 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
131                 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
132                 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
133                 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
134                 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
135                 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
136                 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
137                 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
138                 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
139                 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
140                 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
141                 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
142                 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
143                 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
144                 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
145                 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
146                 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
147                 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
148                 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
149                         return true;
150
151                 default:
152                         return false;
153         }
154 }
155
156 bool isYCbCrFormat (VkFormat format)
157 {
158         switch (format)
159         {
160                 case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
161                 case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
162                 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
163                 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
164                 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
165                 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
166                 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
167                 case VK_FORMAT_R10X6_UNORM_PACK16_KHR:
168                 case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:
169                 case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:
170                 case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
171                 case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
172                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
173                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
174                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
175                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
176                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
177                 case VK_FORMAT_R12X4_UNORM_PACK16_KHR:
178                 case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:
179                 case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:
180                 case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
181                 case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
182                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
183                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
184                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
185                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
186                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
187                 case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
188                 case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
189                 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
190                 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
191                 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
192                 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
193                 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
194                         return true;
195
196                 default:
197                         return false;
198         }
199 }
200
201 const PlanarFormatDescription& getYCbCrPlanarFormatDescription (VkFormat format)
202 {
203         using tcu::TextureFormat;
204
205         const deUint32  chanR                   = PlanarFormatDescription::CHANNEL_R;
206         const deUint32  chanG                   = PlanarFormatDescription::CHANNEL_G;
207         const deUint32  chanB                   = PlanarFormatDescription::CHANNEL_B;
208         const deUint32  chanA                   = PlanarFormatDescription::CHANNEL_A;
209
210         const deUint8   unorm                   = (deUint8)tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
211
212         static const PlanarFormatDescription s_formatInfo[] =
213         {
214                 // VK_FORMAT_G8B8G8R8_422_UNORM_KHR
215                 {
216                         1, // planes
217                         chanR|chanG|chanB,
218                         {
219                         //              Size    WDiv    HDiv
220                                 {       4,              2,              1       },
221                                 {       0,              0,              0       },
222                                 {       0,              0,              0       },
223                         },
224                         {
225                         //              Plane   Type    Offs    Size    Stride
226                                 {       0,              unorm,  24,             8,              4 },    // R
227                                 {       0,              unorm,  0,              8,              2 },    // G
228                                 {       0,              unorm,  8,              8,              4 },    // B
229                                 { 0, 0, 0, 0, 0 }
230                         }
231                 },
232                 // VK_FORMAT_B8G8R8G8_422_UNORM_KHR
233                 {
234                         1, // planes
235                         chanR|chanG|chanB,
236                         {
237                         //              Size    WDiv    HDiv
238                                 {       4,              2,              1 },
239                                 {       0,              0,              0 },
240                                 {       0,              0,              0 },
241                         },
242                         {
243                         //              Plane   Type    Offs    Size    Stride
244                                 {       0,              unorm,  16,             8,              4 },    // R
245                                 {       0,              unorm,  8,              8,              2 },    // G
246                                 {       0,              unorm,  0,              8,              4 },    // B
247                                 { 0, 0, 0, 0, 0 }
248                         }
249                 },
250                 // VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR
251                 {
252                         3, // planes
253                         chanR|chanG|chanB,
254                         {
255                         //              Size    WDiv    HDiv
256                                 {  1, 1, 1 },
257                                 {  1, 2, 2 },
258                                 {  1, 2, 2 },
259                         },
260                         {
261                         //              Plane   Type    Offs    Size    Stride
262                                 {       2,              unorm,  0,              8,              1 },    // R
263                                 {       0,              unorm,  0,              8,              1 },    // G
264                                 {       1,              unorm,  0,              8,              1 },    // B
265                                 { 0, 0, 0, 0, 0 }
266                         }
267                 },
268                 // VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR
269                 {
270                         2, // planes
271                         chanR|chanG|chanB,
272                         {
273                         //              Size    WDiv    HDiv
274                                 {  1, 1, 1 },
275                                 {  2, 2, 2 },
276                                 {  0, 0, 0 },
277                         },
278                         {
279                         //              Plane   Type    Offs    Size    Stride
280                                 {       1,              unorm,  8,              8,              2 },    // R
281                                 {       0,              unorm,  0,              8,              1 },    // G
282                                 {       1,              unorm,  0,              8,              2 },    // B
283                                 { 0, 0, 0, 0, 0 }
284                         }
285                 },
286                 // VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR
287                 {
288                         3, // planes
289                         chanR|chanG|chanB,
290                         {
291                         //              Size    WDiv    HDiv
292                                 {  1, 1, 1 },
293                                 {  1, 2, 1 },
294                                 {  1, 2, 1 },
295                         },
296                         {
297                         //              Plane   Type    Offs    Size    Stride
298                                 {       2,              unorm,  0,              8,              1 },    // R
299                                 {       0,              unorm,  0,              8,              1 },    // G
300                                 {       1,              unorm,  0,              8,              1 },    // B
301                                 { 0, 0, 0, 0, 0 }
302                         }
303                 },
304                 // VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR
305                 {
306                         2, // planes
307                         chanR|chanG|chanB,
308                         {
309                         //              Size    WDiv    HDiv
310                                 {  1, 1, 1 },
311                                 {  2, 2, 1 },
312                                 {  0, 0, 0 },
313                         },
314                         {
315                         //              Plane   Type    Offs    Size    Stride
316                                 {       1,              unorm,  8,              8,              2 },    // R
317                                 {       0,              unorm,  0,              8,              1 },    // G
318                                 {       1,              unorm,  0,              8,              2 },    // B
319                                 { 0, 0, 0, 0, 0 }
320                         }
321                 },
322                 // VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR
323                 {
324                         3, // planes
325                         chanR|chanG|chanB,
326                         {
327                         //              Size    WDiv    HDiv
328                                 {  1, 1, 1 },
329                                 {  1, 1, 1 },
330                                 {  1, 1, 1 },
331                         },
332                         {
333                         //              Plane   Type    Offs    Size    Stride
334                                 {       2,              unorm,  0,              8,              1 },    // R
335                                 {       0,              unorm,  0,              8,              1 },    // G
336                                 {       1,              unorm,  0,              8,              1 },    // B
337                                 { 0, 0, 0, 0, 0 }
338                         }
339                 },
340                 // VK_FORMAT_R10X6_UNORM_PACK16_KHR
341                 {
342                         1, // planes
343                         chanR,
344                         {
345                         //              Size    WDiv    HDiv
346                                 {       2,              1,              1 },
347                                 {       0,              0,              0 },
348                                 {       0,              0,              0 },
349                         },
350                         {
351                         //              Plane   Type    Offs    Size    Stride
352                                 {       0,              unorm,  6,              10,             2 },    // R
353                                 { 0, 0, 0, 0, 0 },
354                                 { 0, 0, 0, 0, 0 },
355                                 { 0, 0, 0, 0, 0 },
356                         }
357                 },
358                 // VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR
359                 {
360                         1, // planes
361                         chanR|chanG,
362                         {
363                         //              Size    WDiv    HDiv
364                                 {       4,              1,              1 },
365                                 {       0,              0,              0 },
366                                 {       0,              0,              0 },
367                         },
368                         {
369                         //              Plane   Type    Offs    Size    Stride
370                                 {       0,              unorm,  6,              10,             4 },    // R
371                                 {       0,              unorm,  22,             10,             4 },    // G
372                                 { 0, 0, 0, 0, 0 },
373                                 { 0, 0, 0, 0, 0 },
374                         }
375                 },
376                 // VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR
377                 {
378                         1, // planes
379                         chanR|chanG|chanB|chanA,
380                         {
381                         //              Size    WDiv    HDiv
382                                 {       8,              1,              1 },
383                                 {       0,              0,              0 },
384                                 {       0,              0,              0 },
385                         },
386                         {
387                         //              Plane   Type    Offs    Size    Stride
388                                 {       0,              unorm,  6,              10,             8 },    // R
389                                 {       0,              unorm,  22,             10,             8 },    // G
390                                 {       0,              unorm,  38,             10,             8 },    // B
391                                 {       0,              unorm,  54,             10,             8 },    // A
392                         }
393                 },
394                 // VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR
395                 {
396                         1, // planes
397                         chanR|chanG|chanB,
398                         {
399                         //              Size    WDiv    HDiv
400                                 {       8,              2,              1 },
401                                 {       0,              0,              0 },
402                                 {       0,              0,              0 },
403                         },
404                         {
405                         //              Plane   Type    Offs    Size    Stride
406                                 {       0,              unorm,  54,             10,             8 },    // R
407                                 {       0,              unorm,  6,              10,             4 },    // G
408                                 {       0,              unorm,  22,             10,             8 },    // B
409                                 { 0, 0, 0, 0, 0 }
410                         }
411                 },
412                 // VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR
413                 {
414                         1, // planes
415                         chanR|chanG|chanB,
416                         {
417                         //              Size    WDiv    HDiv
418                                 {       8,              2,              1 },
419                                 {       0,              0,              0 },
420                                 {       0,              0,              0 },
421                         },
422                         {
423                         //              Plane   Type    Offs    Size    Stride
424                                 {       0,              unorm,  38,             10,             8 },    // R
425                                 {       0,              unorm,  22,             10,             4 },    // G
426                                 {       0,              unorm,  6,              10,             8 },    // B
427                                 { 0, 0, 0, 0, 0 }
428                         }
429                 },
430                 // VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR
431                 {
432                         3, // planes
433                         chanR|chanG|chanB,
434                         {
435                         //              Size    WDiv    HDiv
436                                 {       2,              1,              1 },
437                                 {       2,              2,              2 },
438                                 {       2,              2,              2 },
439                         },
440                         {
441                         //              Plane   Type    Offs    Size    Stride
442                                 {       2,              unorm,  6,              10,             2 },    // R
443                                 {       0,              unorm,  6,              10,             2 },    // G
444                                 {       1,              unorm,  6,              10,             2 },    // B
445                                 { 0, 0, 0, 0, 0 }
446                         }
447                 },
448                 // VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR
449                 {
450                         2, // planes
451                         chanR|chanG|chanB,
452                         {
453                         //              Size    WDiv    HDiv
454                                 {       2,              1,              1 },
455                                 {       4,              2,              2 },
456                                 {       0,              0,              0 },
457                         },
458                         {
459                         //              Plane   Type    Offs    Size    Stride
460                                 {       1,              unorm,  22,             10,             4 },    // R
461                                 {       0,              unorm,  6,              10,             2 },    // G
462                                 {       1,              unorm,  6,              10,             4 },    // B
463                                 { 0, 0, 0, 0, 0 }
464                         }
465                 },
466                 // VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR
467                 {
468                         3, // planes
469                         chanR|chanG|chanB,
470                         {
471                         //              Size    WDiv    HDiv
472                                 {       2,              1,              1 },
473                                 {       2,              2,              1 },
474                                 {       2,              2,              1 },
475                         },
476                         {
477                         //              Plane   Type    Offs    Size    Stride
478                                 {       2,              unorm,  6,              10,             2 },    // R
479                                 {       0,              unorm,  6,              10,             2 },    // G
480                                 {       1,              unorm,  6,              10,             2 },    // B
481                                 { 0, 0, 0, 0, 0 }
482                         }
483                 },
484                 // VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR
485                 {
486                         2, // planes
487                         chanR|chanG|chanB,
488                         {
489                         //              Size    WDiv    HDiv
490                                 {       2,              1,              1 },
491                                 {       4,              2,              1 },
492                                 {       0,              0,              0 },
493                         },
494                         {
495                         //              Plane   Type    Offs    Size    Stride
496                                 {       1,              unorm,  22,             10,             4 },    // R
497                                 {       0,              unorm,  6,              10,             2 },    // G
498                                 {       1,              unorm,  6,              10,             4 },    // B
499                                 { 0, 0, 0, 0, 0 }
500                         }
501                 },
502                 // VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR
503                 {
504                         3, // planes
505                         chanR|chanG|chanB,
506                         {
507                         //              Size    WDiv    HDiv
508                                 {       2,              1,              1 },
509                                 {       2,              1,              1 },
510                                 {       2,              1,              1 },
511                         },
512                         {
513                         //              Plane   Type    Offs    Size    Stride
514                                 {       2,              unorm,  6,              10,             2 },    // R
515                                 {       0,              unorm,  6,              10,             2 },    // G
516                                 {       1,              unorm,  6,              10,             2 },    // B
517                                 { 0, 0, 0, 0, 0 }
518                         }
519                 },
520                 // VK_FORMAT_R12X4_UNORM_PACK16_KHR
521                 {
522                         1, // planes
523                         chanR,
524                         {
525                         //              Size    WDiv    HDiv
526                                 {       2,              1,              1 },
527                                 {       0,              0,              0 },
528                                 {       0,              0,              0 },
529                         },
530                         {
531                         //              Plane   Type    Offs    Size    Stride
532                                 {       0,              unorm,  4,              12,             2 },    // R
533                                 { 0, 0, 0, 0, 0 },
534                                 { 0, 0, 0, 0, 0 },
535                                 { 0, 0, 0, 0, 0 },
536                         }
537                 },
538                 // VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR
539                 {
540                         1, // planes
541                         chanR|chanG,
542                         {
543                         //              Size    WDiv    HDiv
544                                 {       4,              1,              1 },
545                                 {       0,              0,              0 },
546                                 {       0,              0,              0 },
547                         },
548                         {
549                         //              Plane   Type    Offs    Size    Stride
550                                 {       0,              unorm,  4,              12,             4 },    // R
551                                 {       0,              unorm,  20,             12,             4 },    // G
552                                 { 0, 0, 0, 0, 0 },
553                                 { 0, 0, 0, 0, 0 },
554                         }
555                 },
556                 // VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR
557                 {
558                         1, // planes
559                         chanR|chanG|chanB|chanA,
560                         {
561                         //              Size    WDiv    HDiv
562                                 {       8,              1,              1 },
563                                 {       0,              0,              0 },
564                                 {       0,              0,              0 },
565                         },
566                         {
567                         //              Plane   Type    Offs    Size    Stride
568                                 {       0,              unorm,  4,              12,             8 },    // R
569                                 {       0,              unorm,  20,             12,             8 },    // G
570                                 {       0,              unorm,  36,             12,             8 },    // B
571                                 {       0,              unorm,  52,             12,             8 },    // A
572                         }
573                 },
574                 // VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR
575                 {
576                         1, // planes
577                         chanR|chanG|chanB,
578                         {
579                         //              Size    WDiv    HDiv
580                                 {       8,              2,              1 },
581                                 {       0,              0,              0 },
582                                 {       0,              0,              0 },
583                         },
584                         {
585                         //              Plane   Type    Offs    Size    Stride
586                                 {       0,              unorm,  52,             12,             8 },    // R
587                                 {       0,              unorm,  4,              12,             4 },    // G
588                                 {       0,              unorm,  20,             12,             8 },    // B
589                                 { 0, 0, 0, 0, 0 }
590                         }
591                 },
592                 // VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR
593                 {
594                         1, // planes
595                         chanR|chanG|chanB,
596                         {
597                         //              Size    WDiv    HDiv
598                                 {       8,              2,              1 },
599                                 {       0,              0,              0 },
600                                 {       0,              0,              0 },
601                         },
602                         {
603                         //              Plane   Type    Offs    Size    Stride
604                                 {       0,              unorm,  36,             12,             8 },    // R
605                                 {       0,              unorm,  20,             12,             4 },    // G
606                                 {       0,              unorm,  4,              12,             8 },    // B
607                                 { 0, 0, 0, 0, 0 }
608                         }
609                 },
610                 // VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR
611                 {
612                         3, // planes
613                         chanR|chanG|chanB,
614                         {
615                         //              Size    WDiv    HDiv
616                                 {       2,              1,              1 },
617                                 {       2,              2,              2 },
618                                 {       2,              2,              2 },
619                         },
620                         {
621                         //              Plane   Type    Offs    Size    Stride
622                                 {       2,              unorm,  4,              12,             2 },    // R
623                                 {       0,              unorm,  4,              12,             2 },    // G
624                                 {       1,              unorm,  4,              12,             2 },    // B
625                                 { 0, 0, 0, 0, 0 }
626                         }
627                 },
628                 // VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR
629                 {
630                         2, // planes
631                         chanR|chanG|chanB,
632                         {
633                         //              Size    WDiv    HDiv
634                                 {       2,              1,              1 },
635                                 {       4,              2,              2 },
636                                 {       0,              0,              0 },
637                         },
638                         {
639                         //              Plane   Type    Offs    Size    Stride
640                                 {       1,              unorm,  20,             12,             4 },    // R
641                                 {       0,              unorm,  4,              12,             2 },    // G
642                                 {       1,              unorm,  4,              12,             4 },    // B
643                                 { 0, 0, 0, 0, 0 }
644                         }
645                 },
646                 // VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR
647                 {
648                         3, // planes
649                         chanR|chanG|chanB,
650                         {
651                         //              Size    WDiv    HDiv
652                                 {       2,              1,              1 },
653                                 {       2,              2,              1 },
654                                 {       2,              2,              1 },
655                         },
656                         {
657                         //              Plane   Type    Offs    Size    Stride
658                                 {       2,              unorm,  4,              12,             2 },    // R
659                                 {       0,              unorm,  4,              12,             2 },    // G
660                                 {       1,              unorm,  4,              12,             2 },    // B
661                                 { 0, 0, 0, 0, 0 }
662                         }
663                 },
664                 // VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR
665                 {
666                         2, // planes
667                         chanR|chanG|chanB,
668                         {
669                         //              Size    WDiv    HDiv
670                                 {       2,              1,              1 },
671                                 {       4,              2,              1 },
672                                 {       0,              0,              0 },
673                         },
674                         {
675                         //              Plane   Type    Offs    Size    Stride
676                                 {       1,              unorm,  20,             12,             4 },    // R
677                                 {       0,              unorm,  4,              12,             2 },    // G
678                                 {       1,              unorm,  4,              12,             4 },    // B
679                                 { 0, 0, 0, 0, 0 }
680                         }
681                 },
682                 // VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR
683                 {
684                         3, // planes
685                         chanR|chanG|chanB,
686                         {
687                         //              Size    WDiv    HDiv
688                                 {       2,              1,              1 },
689                                 {       2,              1,              1 },
690                                 {       2,              1,              1 },
691                         },
692                         {
693                         //              Plane   Type    Offs    Size    Stride
694                                 {       2,              unorm,  4,              12,             2 },    // R
695                                 {       0,              unorm,  4,              12,             2 },    // G
696                                 {       1,              unorm,  4,              12,             2 },    // B
697                                 { 0, 0, 0, 0, 0 }
698                         }
699                 },
700                 // VK_FORMAT_G16B16G16R16_422_UNORM_KHR
701                 {
702                         1, // planes
703                         chanR|chanG|chanB,
704                         {
705                         //              Size    WDiv    HDiv
706                                 {       8,              2,              1 },
707                                 {       0,              0,              0 },
708                                 {       0,              0,              0 },
709                         },
710                         {
711                         //              Plane   Type    Offs    Size    Stride
712                                 {       0,              unorm,  48,             16,             8 },    // R
713                                 {       0,              unorm,  0,              16,             4 },    // G
714                                 {       0,              unorm,  16,             16,             8 },    // B
715                                 { 0, 0, 0, 0, 0 }
716                         }
717                 },
718                 // VK_FORMAT_B16G16R16G16_422_UNORM_KHR
719                 {
720                         1, // planes
721                         chanR|chanG|chanB,
722                         {
723                         //              Size    WDiv    HDiv
724                                 {       8,              2,              1 },
725                                 {       0,              0,              0 },
726                                 {       0,              0,              0 },
727                         },
728                         {
729                         //              Plane   Type    Offs    Size    Stride
730                                 {       0,              unorm,  32,             16,             8 },    // R
731                                 {       0,              unorm,  16,             16,             4 },    // G
732                                 {       0,              unorm,  0,              16,             8 },    // B
733                                 { 0, 0, 0, 0, 0 }
734                         }
735                 },
736                 // VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR
737                 {
738                         3, // planes
739                         chanR|chanG|chanB,
740                         {
741                         //              Size    WDiv    HDiv
742                                 {       2,              1,              1 },
743                                 {       2,              2,              2 },
744                                 {       2,              2,              2 },
745                         },
746                         {
747                         //              Plane   Type    Offs    Size    Stride
748                                 {       2,              unorm,  0,              16,             2 },    // R
749                                 {       0,              unorm,  0,              16,             2 },    // G
750                                 {       1,              unorm,  0,              16,             2 },    // B
751                                 { 0, 0, 0, 0, 0 }
752                         }
753                 },
754                 // VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR
755                 {
756                         2, // planes
757                         chanR|chanG|chanB,
758                         {
759                         //              Size    WDiv    HDiv
760                                 {       2,              1,              1 },
761                                 {       4,              2,              2 },
762                                 {       0,              0,              0 },
763                         },
764                         {
765                         //              Plane   Type    Offs    Size    Stride
766                                 {       1,              unorm,  16,             16,             4 },    // R
767                                 {       0,              unorm,  0,              16,             2 },    // G
768                                 {       1,              unorm,  0,              16,             4 },    // B
769                                 { 0, 0, 0, 0, 0 }
770                         }
771                 },
772                 // VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR
773                 {
774                         3, // planes
775                         chanR|chanG|chanB,
776                         {
777                         //              Size    WDiv    HDiv
778                                 {       2,              1,              1 },
779                                 {       2,              2,              1 },
780                                 {       2,              2,              1 },
781                         },
782                         {
783                         //              Plane   Type    Offs    Size    Stride
784                                 {       2,              unorm,  0,              16,             2 },    // R
785                                 {       0,              unorm,  0,              16,             2 },    // G
786                                 {       1,              unorm,  0,              16,             2 },    // B
787                                 { 0, 0, 0, 0, 0 }
788                         }
789                 },
790                 // VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR
791                 {
792                         2, // planes
793                         chanR|chanG|chanB,
794                         {
795                         //              Size    WDiv    HDiv
796                                 {       2,              1,              1 },
797                                 {       4,              2,              1 },
798                                 {       0,              0,              0 },
799                         },
800                         {
801                         //              Plane   Type    Offs    Size    Stride
802                                 {       1,              unorm,  16,             16,             4 },    // R
803                                 {       0,              unorm,  0,              16,             2 },    // G
804                                 {       1,              unorm,  0,              16,             4 },    // B
805                                 { 0, 0, 0, 0, 0 }
806                         }
807                 },
808                 // VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR
809                 {
810                         3, // planes
811                         chanR|chanG|chanB,
812                         {
813                         //              Size    WDiv    HDiv
814                                 {       2,              1,              1 },
815                                 {       2,              1,              1 },
816                                 {       2,              1,              1 },
817                         },
818                         {
819                         //              Plane   Type    Offs    Size    Stride
820                                 {       2,              unorm,  0,              16,             2 },    // R
821                                 {       0,              unorm,  0,              16,             2 },    // G
822                                 {       1,              unorm,  0,              16,             2 },    // B
823                                 { 0, 0, 0, 0, 0 }
824                         }
825                 },
826         };
827
828         const size_t    offset  = (size_t)VK_FORMAT_G8B8G8R8_422_UNORM_KHR;
829
830         DE_ASSERT(de::inBounds<size_t>((size_t)format, offset, offset+(size_t)DE_LENGTH_OF_ARRAY(s_formatInfo)));
831
832         return s_formatInfo[(size_t)format-offset];
833 }
834
835 PlanarFormatDescription getCorePlanarFormatDescription (VkFormat format)
836 {
837         const deUint8                   unorm   = (deUint8)tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
838
839         const deUint8                   chanR   = (deUint8)PlanarFormatDescription::CHANNEL_R;
840         const deUint8                   chanG   = (deUint8)PlanarFormatDescription::CHANNEL_G;
841         const deUint8                   chanB   = (deUint8)PlanarFormatDescription::CHANNEL_B;
842         const deUint8                   chanA   = (deUint8)PlanarFormatDescription::CHANNEL_A;
843
844         DE_ASSERT(de::inBounds<deUint32>(format, VK_FORMAT_UNDEFINED+1, VK_CORE_FORMAT_LAST));
845
846 #if (DE_ENDIANNESS != DE_LITTLE_ENDIAN)
847 #       error "Big-endian is not supported"
848 #endif
849
850         switch (format)
851         {
852                 case VK_FORMAT_R8_UNORM:
853                 {
854                         const PlanarFormatDescription   desc    =
855                         {
856                                 1, // planes
857                                 chanR,
858                                 {
859                                 //              Size    WDiv    HDiv
860                                         {       1,              1,              1 },
861                                         {       0,              0,              0 },
862                                         {       0,              0,              0 },
863                                 },
864                                 {
865                                 //              Plane   Type    Offs    Size    Stride
866                                         {       0,              unorm,  0,              8,              1 },    // R
867                                         {       0,              0,              0,              0,              0 },    // G
868                                         {       0,              0,              0,              0,              0 },    // B
869                                         {       0,              0,              0,              0,              0 }             // A
870                                 }
871                         };
872                         return desc;
873                 }
874
875                 case VK_FORMAT_R8G8_UNORM:
876                 {
877                         const PlanarFormatDescription   desc    =
878                         {
879                                 1, // planes
880                                 chanR|chanG,
881                                 {
882                                 //              Size    WDiv    HDiv
883                                         {       2,              1,              1 },
884                                         {       0,              0,              0 },
885                                         {       0,              0,              0 },
886                                 },
887                                 {
888                                 //              Plane   Type    Offs    Size    Stride
889                                         {       0,              unorm,  0,              8,              2 },    // R
890                                         {       0,              unorm,  8,              8,              2 },    // G
891                                         {       0,              0,              0,              0,              0 },    // B
892                                         {       0,              0,              0,              0,              0 }             // A
893                                 }
894                         };
895                         return desc;
896                 }
897
898                 case VK_FORMAT_R16_UNORM:
899                 {
900                         const PlanarFormatDescription   desc    =
901                         {
902                                 1, // planes
903                                 chanR,
904                                 {
905                                 //              Size    WDiv    HDiv
906                                         {       2,              1,              1 },
907                                         {       0,              0,              0 },
908                                         {       0,              0,              0 },
909                                 },
910                                 {
911                                 //              Plane   Type    Offs    Size    Stride
912                                         {       0,              unorm,  0,              16,             2 },    // R
913                                         {       0,              0,              0,              0,              0 },    // G
914                                         {       0,              0,              0,              0,              0 },    // B
915                                         {       0,              0,              0,              0,              0 }             // A
916                                 }
917                         };
918                         return desc;
919                 }
920
921                 case VK_FORMAT_R16G16_UNORM:
922                 {
923                         const PlanarFormatDescription   desc    =
924                         {
925                                 1, // planes
926                                 chanR|chanG,
927                                 {
928                                 //              Size    WDiv    HDiv
929                                         {       4,              1,              1 },
930                                         {       0,              0,              0 },
931                                         {       0,              0,              0 },
932                                 },
933                                 {
934                                 //              Plane   Type    Offs    Size    Stride
935                                         {       0,              unorm,  0,              16,             4 },    // R
936                                         {       0,              unorm,  16,             16,             4 },    // G
937                                         {       0,              0,              0,              0,              0 },    // B
938                                         {       0,              0,              0,              0,              0 }             // A
939                                 }
940                         };
941                         return desc;
942                 }
943
944                 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
945                 {
946                         const PlanarFormatDescription   desc    =
947                         {
948                                 1, // planes
949                                 chanR|chanG|chanB,
950                                 {
951                                 //              Size    WDiv    HDiv
952                                         {       4,              1,              1 },
953                                         {       0,              0,              0 },
954                                         {       0,              0,              0 },
955                                 },
956                                 {
957                                 //              Plane   Type    Offs    Size    Stride
958                                         {       0,              unorm,  0,              11,             4 },    // R
959                                         {       0,              unorm,  11,             11,             4 },    // G
960                                         {       0,              unorm,  22,             10,             4 },    // B
961                                         {       0,              0,              0,              0,              0 }             // A
962                                 }
963                         };
964                         return desc;
965                 }
966
967                 case VK_FORMAT_R4G4_UNORM_PACK8:
968                 {
969                         const PlanarFormatDescription   desc    =
970                         {
971                                 1, // planes
972                                 chanR|chanG,
973                                 {
974                                 //              Size    WDiv    HDiv
975                                         {       1,              1,              1 },
976                                         {       0,              0,              0 },
977                                         {       0,              0,              0 },
978                                 },
979                                 {
980                                 //              Plane   Type    Offs    Size    Stride
981                                         {       0,              unorm,  4,              4,              1 },    // R
982                                         {       0,              unorm,  0,              4,              1 },    // G
983                                         {       0,              0,              0,              0,              0 },    // B
984                                         {       0,              0,              0,              0,              0 }             // A
985                                 }
986                         };
987                         return desc;
988                 }
989
990                 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
991                 {
992                         const PlanarFormatDescription   desc    =
993                         {
994                                 1, // planes
995                                 chanR|chanG|chanB|chanA,
996                                 {
997                                 //              Size    WDiv    HDiv
998                                         {       2,              1,              1 },
999                                         {       0,              0,              0 },
1000                                         {       0,              0,              0 },
1001                                 },
1002                                 {
1003                                 //              Plane   Type    Offs    Size    Stride
1004                                         {       0,              unorm,  12,             4,              2 },    // R
1005                                         {       0,              unorm,  8,              4,              2 },    // G
1006                                         {       0,              unorm,  4,              4,              2 },    // B
1007                                         {       0,              unorm,  0,              4,              2 }             // A
1008                                 }
1009                         };
1010                         return desc;
1011                 }
1012
1013                 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1014                 {
1015                         const PlanarFormatDescription   desc    =
1016                         {
1017                                 1, // planes
1018                                 chanR|chanG|chanB|chanA,
1019                                 {
1020                                 //              Size    WDiv    HDiv
1021                                         {       2,              1,              1 },
1022                                         {       0,              0,              0 },
1023                                         {       0,              0,              0 },
1024                                 },
1025                                 {
1026                                 //              Plane   Type    Offs    Size    Stride
1027                                         {       0,              unorm,  4,              4,              2 },    // R
1028                                         {       0,              unorm,  8,              4,              2 },    // G
1029                                         {       0,              unorm,  12,             4,              2 },    // B
1030                                         {       0,              unorm,  0,              4,              2 }             // A
1031                                 }
1032                         };
1033                         return desc;
1034                 }
1035
1036                 case VK_FORMAT_R5G6B5_UNORM_PACK16:
1037                 {
1038                         const PlanarFormatDescription   desc    =
1039                         {
1040                                 1, // planes
1041                                 chanR|chanG|chanB,
1042                                 {
1043                                 //              Size    WDiv    HDiv
1044                                         {       2,              1,              1 },
1045                                         {       0,              0,              0 },
1046                                         {       0,              0,              0 },
1047                                 },
1048                                 {
1049                                 //              Plane   Type    Offs    Size    Stride
1050                                         {       0,              unorm,  11,             5,              2 },    // R
1051                                         {       0,              unorm,  5,              6,              2 },    // G
1052                                         {       0,              unorm,  0,              5,              2 },    // B
1053                                         {       0,              0,              0,              0,              0 }             // A
1054                                 }
1055                         };
1056                         return desc;
1057                 }
1058
1059                 case VK_FORMAT_B5G6R5_UNORM_PACK16:
1060                 {
1061                         const PlanarFormatDescription   desc    =
1062                         {
1063                                 1, // planes
1064                                 chanR|chanG|chanB,
1065                                 {
1066                                 //              Size    WDiv    HDiv
1067                                         {       2,              1,              1 },
1068                                         {       0,              0,              0 },
1069                                         {       0,              0,              0 },
1070                                 },
1071                                 {
1072                                 //              Plane   Type    Offs    Size    Stride
1073                                         {       0,              unorm,  0,              5,              2 },    // R
1074                                         {       0,              unorm,  5,              6,              2 },    // G
1075                                         {       0,              unorm,  11,             5,              2 },    // B
1076                                         {       0,              0,              0,              0,              0 }             // A
1077                                 }
1078                         };
1079                         return desc;
1080                 }
1081
1082                 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1083                 {
1084                         const PlanarFormatDescription   desc    =
1085                         {
1086                                 1, // planes
1087                                 chanR|chanG|chanB|chanA,
1088                                 {
1089                                 //              Size    WDiv    HDiv
1090                                         {       2,              1,              1 },
1091                                         {       0,              0,              0 },
1092                                         {       0,              0,              0 },
1093                                 },
1094                                 {
1095                                 //              Plane   Type    Offs    Size    Stride
1096                                         {       0,              unorm,  11,             5,              2 },    // R
1097                                         {       0,              unorm,  6,              5,              2 },    // G
1098                                         {       0,              unorm,  1,              5,              2 },    // B
1099                                         {       0,              unorm,  0,              1,              2 }             // A
1100                                 }
1101                         };
1102                         return desc;
1103                 }
1104
1105                 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1106                 {
1107                         const PlanarFormatDescription   desc    =
1108                         {
1109                                 1, // planes
1110                                 chanR|chanG|chanB|chanA,
1111                                 {
1112                                 //              Size    WDiv    HDiv
1113                                         {       2,              1,              1 },
1114                                         {       0,              0,              0 },
1115                                         {       0,              0,              0 },
1116                                 },
1117                                 {
1118                                 //              Plane   Type    Offs    Size    Stride
1119                                         {       0,              unorm,  1,              5,              2 },    // R
1120                                         {       0,              unorm,  6,              5,              2 },    // G
1121                                         {       0,              unorm,  11,             5,              2 },    // B
1122                                         {       0,              unorm,  0,              1,              2 }             // A
1123                                 }
1124                         };
1125                         return desc;
1126                 }
1127
1128                 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1129                 {
1130                         const PlanarFormatDescription   desc    =
1131                         {
1132                                 1, // planes
1133                                 chanR|chanG|chanB|chanA,
1134                                 {
1135                                 //              Size    WDiv    HDiv
1136                                         {       2,              1,              1 },
1137                                         {       0,              0,              0 },
1138                                         {       0,              0,              0 },
1139                                 },
1140                                 {
1141                                 //              Plane   Type    Offs    Size    Stride
1142                                         {       0,              unorm,  10,             5,              2 },    // R
1143                                         {       0,              unorm,  5,              5,              2 },    // G
1144                                         {       0,              unorm,  0,              5,              2 },    // B
1145                                         {       0,              unorm,  15,             1,              2 }             // A
1146                                 }
1147                         };
1148                         return desc;
1149                 }
1150
1151                 case VK_FORMAT_R8G8B8_UNORM:
1152                 {
1153                         const PlanarFormatDescription   desc    =
1154                         {
1155                                 1, // planes
1156                                 chanR|chanG|chanB,
1157                                 {
1158                                 //              Size    WDiv    HDiv
1159                                         {       3,              1,              1 },
1160                                         {       0,              0,              0 },
1161                                         {       0,              0,              0 },
1162                                 },
1163                                 {
1164                                 //              Plane   Type    Offs    Size    Stride
1165                                         {       0,              unorm,  0,              8,              3 },    // R
1166                                         {       0,              unorm,  8,              8,              3 },    // G
1167                                         {       0,              unorm,  16,             8,              3 },    // B
1168                                         {       0,              0,              0,              0,              0 }             // A
1169                                 }
1170                         };
1171                         return desc;
1172                 }
1173
1174                 case VK_FORMAT_B8G8R8_UNORM:
1175                 {
1176                         const PlanarFormatDescription   desc    =
1177                         {
1178                                 1, // planes
1179                                 chanR|chanG|chanB,
1180                                 {
1181                                 //              Size    WDiv    HDiv
1182                                         {       3,              1,              1 },
1183                                         {       0,              0,              0 },
1184                                         {       0,              0,              0 },
1185                                 },
1186                                 {
1187                                 //              Plane   Type    Offs    Size    Stride
1188                                         {       0,              unorm,  16,             8,              3 },    // R
1189                                         {       0,              unorm,  8,              8,              3 },    // G
1190                                         {       0,              unorm,  0,              8,              3 },    // B
1191                                         {       0,              0,              0,              0,              0 }             // A
1192                                 }
1193                         };
1194                         return desc;
1195                 }
1196
1197                 case VK_FORMAT_R8G8B8A8_UNORM:
1198                 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1199                 {
1200                         const PlanarFormatDescription   desc    =
1201                         {
1202                                 1, // planes
1203                                 chanR|chanG|chanB|chanA,
1204                                 {
1205                                 //              Size    WDiv    HDiv
1206                                         {       4,              1,              1 },
1207                                         {       0,              0,              0 },
1208                                         {       0,              0,              0 },
1209                                 },
1210                                 {
1211                                 //              Plane   Type    Offs    Size    Stride
1212                                         {       0,              unorm,  0,              8,              4 },    // R
1213                                         {       0,              unorm,  8,              8,              4 },    // G
1214                                         {       0,              unorm,  16,             8,              4 },    // B
1215                                         {       0,              unorm,  24,             8,              4 }             // A
1216                                 }
1217                         };
1218                         return desc;
1219                 }
1220
1221                 case VK_FORMAT_B8G8R8A8_UNORM:
1222                 {
1223                         const PlanarFormatDescription   desc    =
1224                         {
1225                                 1, // planes
1226                                 chanR|chanG|chanB|chanA,
1227                                 {
1228                                 //              Size    WDiv    HDiv
1229                                         {       4,              1,              1 },
1230                                         {       0,              0,              0 },
1231                                         {       0,              0,              0 },
1232                                 },
1233                                 {
1234                                 //              Plane   Type    Offs    Size    Stride
1235                                         {       0,              unorm,  16,             8,              4 },    // R
1236                                         {       0,              unorm,  8,              8,              4 },    // G
1237                                         {       0,              unorm,  0,              8,              4 },    // B
1238                                         {       0,              unorm,  24,             8,              4 }             // A
1239                                 }
1240                         };
1241                         return desc;
1242                 }
1243
1244                 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1245                 {
1246                         const PlanarFormatDescription   desc    =
1247                         {
1248                                 1, // planes
1249                                 chanR|chanG|chanB|chanA,
1250                                 {
1251                                 //              Size    WDiv    HDiv
1252                                         {       4,              1,              1 },
1253                                         {       0,              0,              0 },
1254                                         {       0,              0,              0 },
1255                                 },
1256                                 {
1257                                 //              Plane   Type    Offs    Size    Stride
1258                                         {       0,              unorm,  20,             10,             4 },    // R
1259                                         {       0,              unorm,  10,             10,             4 },    // G
1260                                         {       0,              unorm,  0,              10,             4 },    // B
1261                                         {       0,              unorm,  30,             2,              4 }             // A
1262                                 }
1263                         };
1264                         return desc;
1265                 }
1266
1267                 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1268                 {
1269                         const PlanarFormatDescription   desc    =
1270                         {
1271                                 1, // planes
1272                                 chanR|chanG|chanB|chanA,
1273                                 {
1274                                 //              Size    WDiv    HDiv
1275                                         {       4,              1,              1 },
1276                                         {       0,              0,              0 },
1277                                         {       0,              0,              0 },
1278                                 },
1279                                 {
1280                                 //              Plane   Type    Offs    Size    Stride
1281                                         {       0,              unorm,  0,              10,             4 },    // R
1282                                         {       0,              unorm,  10,             10,             4 },    // G
1283                                         {       0,              unorm,  20,             10,             4 },    // B
1284                                         {       0,              unorm,  30,             2,              4 }             // A
1285                                 }
1286                         };
1287                         return desc;
1288                 }
1289
1290                 case VK_FORMAT_R16G16B16_UNORM:
1291                 {
1292                         const PlanarFormatDescription   desc    =
1293                         {
1294                                 1, // planes
1295                                 chanR|chanG|chanB,
1296                                 {
1297                                 //              Size    WDiv    HDiv
1298                                         {       6,              1,              1 },
1299                                         {       0,              0,              0 },
1300                                         {       0,              0,              0 },
1301                                 },
1302                                 {
1303                                 //              Plane   Type    Offs    Size    Stride
1304                                         {       0,              unorm,  0,              16,             6 },    // R
1305                                         {       0,              unorm,  16,             16,             6 },    // G
1306                                         {       0,              unorm,  32,             16,             6 },    // B
1307                                         {       0,              0,              0,              0,              0 }             // A
1308                                 }
1309                         };
1310                         return desc;
1311                 }
1312
1313                 case VK_FORMAT_R16G16B16A16_UNORM:
1314                 {
1315                         const PlanarFormatDescription   desc    =
1316                         {
1317                                 1, // planes
1318                                 chanR|chanG|chanB|chanA,
1319                                 {
1320                                 //              Size    WDiv    HDiv
1321                                         {       16,             1,              1 },
1322                                         {       0,              0,              0 },
1323                                         {       0,              0,              0 },
1324                                 },
1325                                 {
1326                                 //              Plane   Type    Offs    Size    Stride
1327                                         {       0,              unorm,  0,              16,             8 },    // R
1328                                         {       0,              unorm,  16,             16,             8 },    // G
1329                                         {       0,              unorm,  32,             16,             8 },    // B
1330                                         {       0,              unorm,  48,             16,             8 }             // A
1331                                 }
1332                         };
1333                         return desc;
1334                 }
1335
1336                 default:
1337                         TCU_THROW(InternalError, "Not implemented");
1338         }
1339 }
1340
1341 PlanarFormatDescription getPlanarFormatDescription (VkFormat format)
1342 {
1343         if (isYCbCrFormat(format))
1344                 return getYCbCrPlanarFormatDescription(format);
1345         else
1346                 return getCorePlanarFormatDescription(format);
1347 }
1348
1349 int getPlaneCount (VkFormat format)
1350 {
1351         switch (format)
1352         {
1353                 case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
1354                 case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
1355                 case VK_FORMAT_R10X6_UNORM_PACK16_KHR:
1356                 case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:
1357                 case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:
1358                 case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
1359                 case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
1360                 case VK_FORMAT_R12X4_UNORM_PACK16_KHR:
1361                 case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:
1362                 case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:
1363                 case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
1364                 case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
1365                 case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
1366                 case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
1367                         return 1;
1368
1369                 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
1370                 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
1371                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
1372                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
1373                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
1374                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
1375                 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
1376                 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
1377                         return 2;
1378
1379                 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
1380                 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
1381                 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
1382                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
1383                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
1384                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
1385                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
1386                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
1387                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
1388                 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
1389                 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
1390                 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
1391                         return 3;
1392
1393                 default:
1394                         DE_FATAL("Not YCbCr format");
1395                         return 0;
1396         }
1397 }
1398
1399 VkImageAspectFlagBits getPlaneAspect (deUint32 planeNdx)
1400 {
1401         DE_ASSERT(de::inBounds(planeNdx, 0u, 3u));
1402         return (VkImageAspectFlagBits)(VK_IMAGE_ASPECT_PLANE_0_BIT_KHR << planeNdx);
1403 }
1404
1405 deUint32 getAspectPlaneNdx (VkImageAspectFlagBits flags)
1406 {
1407         switch (flags)
1408         {
1409                 case VK_IMAGE_ASPECT_PLANE_0_BIT_KHR:   return 0;
1410                 case VK_IMAGE_ASPECT_PLANE_1_BIT_KHR:   return 1;
1411                 case VK_IMAGE_ASPECT_PLANE_2_BIT_KHR:   return 2;
1412                 default:
1413                         DE_FATAL("Invalid plane aspect");
1414                         return 0;
1415         }
1416 }
1417
1418 bool isChromaSubsampled (VkFormat format)
1419 {
1420         switch (format)
1421         {
1422                 case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
1423                 case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
1424                 case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
1425                 case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
1426                 case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
1427                 case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
1428                 case VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR:
1429                 case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
1430                 case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
1431                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
1432                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
1433                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
1434                 case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
1435                 case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR:
1436                 case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
1437                 case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
1438                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
1439                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
1440                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
1441                 case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
1442                 case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR:
1443                 case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
1444                 case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
1445                 case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
1446                 case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
1447                 case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
1448                 case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
1449                 case VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR:
1450                         return true;
1451
1452                 default:
1453                         return false;
1454         }
1455 }
1456
1457 bool isSupportedByFramework (VkFormat format)
1458 {
1459         if (format == VK_FORMAT_UNDEFINED || format > VK_CORE_FORMAT_LAST)
1460                 return false;
1461
1462         switch (format)
1463         {
1464                 case VK_FORMAT_R64_UINT:
1465                 case VK_FORMAT_R64_SINT:
1466                 case VK_FORMAT_R64_SFLOAT:
1467                 case VK_FORMAT_R64G64_UINT:
1468                 case VK_FORMAT_R64G64_SINT:
1469                 case VK_FORMAT_R64G64_SFLOAT:
1470                 case VK_FORMAT_R64G64B64_UINT:
1471                 case VK_FORMAT_R64G64B64_SINT:
1472                 case VK_FORMAT_R64G64B64_SFLOAT:
1473                 case VK_FORMAT_R64G64B64A64_UINT:
1474                 case VK_FORMAT_R64G64B64A64_SINT:
1475                 case VK_FORMAT_R64G64B64A64_SFLOAT:
1476                         // \todo [2016-12-01 pyry] Support 64-bit channel types
1477                         return false;
1478
1479                 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1480                 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1481                 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1482                 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1483                 case VK_FORMAT_BC2_UNORM_BLOCK:
1484                 case VK_FORMAT_BC2_SRGB_BLOCK:
1485                 case VK_FORMAT_BC3_UNORM_BLOCK:
1486                 case VK_FORMAT_BC3_SRGB_BLOCK:
1487                 case VK_FORMAT_BC4_UNORM_BLOCK:
1488                 case VK_FORMAT_BC4_SNORM_BLOCK:
1489                 case VK_FORMAT_BC5_UNORM_BLOCK:
1490                 case VK_FORMAT_BC5_SNORM_BLOCK:
1491                 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1492                 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1493                 case VK_FORMAT_BC7_UNORM_BLOCK:
1494                 case VK_FORMAT_BC7_SRGB_BLOCK:
1495                         return false;
1496
1497                 default:
1498                         return true;
1499         }
1500 }
1501
1502 VkFormat mapTextureFormat (const tcu::TextureFormat& format)
1503 {
1504         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
1505         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
1506
1507 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
1508 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
1509
1510         // update this mapping if VkFormat changes
1511         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1512
1513         switch (PACK_FMT(format.order, format.type))
1514         {
1515                 case FMT_CASE(RG, UNORM_BYTE_44):                                       return VK_FORMAT_R4G4_UNORM_PACK8;
1516                 case FMT_CASE(RGB, UNORM_SHORT_565):                            return VK_FORMAT_R5G6B5_UNORM_PACK16;
1517                 case FMT_CASE(RGBA, UNORM_SHORT_4444):                          return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
1518                 case FMT_CASE(RGBA, UNORM_SHORT_5551):                          return VK_FORMAT_R5G5B5A1_UNORM_PACK16;
1519
1520                 case FMT_CASE(BGR, UNORM_SHORT_565):                            return VK_FORMAT_B5G6R5_UNORM_PACK16;
1521                 case FMT_CASE(BGRA, UNORM_SHORT_4444):                          return VK_FORMAT_B4G4R4A4_UNORM_PACK16;
1522                 case FMT_CASE(BGRA, UNORM_SHORT_5551):                          return VK_FORMAT_B5G5R5A1_UNORM_PACK16;
1523
1524                 case FMT_CASE(ARGB, UNORM_SHORT_1555):                          return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
1525
1526                 case FMT_CASE(R, UNORM_INT8):                                           return VK_FORMAT_R8_UNORM;
1527                 case FMT_CASE(R, SNORM_INT8):                                           return VK_FORMAT_R8_SNORM;
1528                 case FMT_CASE(R, UNSIGNED_INT8):                                        return VK_FORMAT_R8_UINT;
1529                 case FMT_CASE(R, SIGNED_INT8):                                          return VK_FORMAT_R8_SINT;
1530                 case FMT_CASE(sR, UNORM_INT8):                                          return VK_FORMAT_R8_SRGB;
1531
1532                 case FMT_CASE(RG, UNORM_INT8):                                          return VK_FORMAT_R8G8_UNORM;
1533                 case FMT_CASE(RG, SNORM_INT8):                                          return VK_FORMAT_R8G8_SNORM;
1534                 case FMT_CASE(RG, UNSIGNED_INT8):                                       return VK_FORMAT_R8G8_UINT;
1535                 case FMT_CASE(RG, SIGNED_INT8):                                         return VK_FORMAT_R8G8_SINT;
1536                 case FMT_CASE(sRG, UNORM_INT8):                                         return VK_FORMAT_R8G8_SRGB;
1537
1538                 case FMT_CASE(RGB, UNORM_INT8):                                         return VK_FORMAT_R8G8B8_UNORM;
1539                 case FMT_CASE(RGB, SNORM_INT8):                                         return VK_FORMAT_R8G8B8_SNORM;
1540                 case FMT_CASE(RGB, UNSIGNED_INT8):                                      return VK_FORMAT_R8G8B8_UINT;
1541                 case FMT_CASE(RGB, SIGNED_INT8):                                        return VK_FORMAT_R8G8B8_SINT;
1542                 case FMT_CASE(sRGB, UNORM_INT8):                                        return VK_FORMAT_R8G8B8_SRGB;
1543
1544                 case FMT_CASE(RGBA, UNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_UNORM;
1545                 case FMT_CASE(RGBA, SNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_SNORM;
1546                 case FMT_CASE(RGBA, UNSIGNED_INT8):                                     return VK_FORMAT_R8G8B8A8_UINT;
1547                 case FMT_CASE(RGBA, SIGNED_INT8):                                       return VK_FORMAT_R8G8B8A8_SINT;
1548                 case FMT_CASE(sRGBA, UNORM_INT8):                                       return VK_FORMAT_R8G8B8A8_SRGB;
1549
1550                 case FMT_CASE(RGBA, UNORM_INT_1010102_REV):                     return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
1551                 case FMT_CASE(RGBA, SNORM_INT_1010102_REV):                     return VK_FORMAT_A2B10G10R10_SNORM_PACK32;
1552                 case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV):          return VK_FORMAT_A2B10G10R10_UINT_PACK32;
1553                 case FMT_CASE(RGBA, SIGNED_INT_1010102_REV):            return VK_FORMAT_A2B10G10R10_SINT_PACK32;
1554
1555                 case FMT_CASE(R, UNORM_INT16):                                          return VK_FORMAT_R16_UNORM;
1556                 case FMT_CASE(R, SNORM_INT16):                                          return VK_FORMAT_R16_SNORM;
1557                 case FMT_CASE(R, UNSIGNED_INT16):                                       return VK_FORMAT_R16_UINT;
1558                 case FMT_CASE(R, SIGNED_INT16):                                         return VK_FORMAT_R16_SINT;
1559                 case FMT_CASE(R, HALF_FLOAT):                                           return VK_FORMAT_R16_SFLOAT;
1560
1561                 case FMT_CASE(RG, UNORM_INT16):                                         return VK_FORMAT_R16G16_UNORM;
1562                 case FMT_CASE(RG, SNORM_INT16):                                         return VK_FORMAT_R16G16_SNORM;
1563                 case FMT_CASE(RG, UNSIGNED_INT16):                                      return VK_FORMAT_R16G16_UINT;
1564                 case FMT_CASE(RG, SIGNED_INT16):                                        return VK_FORMAT_R16G16_SINT;
1565                 case FMT_CASE(RG, HALF_FLOAT):                                          return VK_FORMAT_R16G16_SFLOAT;
1566
1567                 case FMT_CASE(RGB, UNORM_INT16):                                        return VK_FORMAT_R16G16B16_UNORM;
1568                 case FMT_CASE(RGB, SNORM_INT16):                                        return VK_FORMAT_R16G16B16_SNORM;
1569                 case FMT_CASE(RGB, UNSIGNED_INT16):                                     return VK_FORMAT_R16G16B16_UINT;
1570                 case FMT_CASE(RGB, SIGNED_INT16):                                       return VK_FORMAT_R16G16B16_SINT;
1571                 case FMT_CASE(RGB, HALF_FLOAT):                                         return VK_FORMAT_R16G16B16_SFLOAT;
1572
1573                 case FMT_CASE(RGBA, UNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_UNORM;
1574                 case FMT_CASE(RGBA, SNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_SNORM;
1575                 case FMT_CASE(RGBA, UNSIGNED_INT16):                            return VK_FORMAT_R16G16B16A16_UINT;
1576                 case FMT_CASE(RGBA, SIGNED_INT16):                                      return VK_FORMAT_R16G16B16A16_SINT;
1577                 case FMT_CASE(RGBA, HALF_FLOAT):                                        return VK_FORMAT_R16G16B16A16_SFLOAT;
1578
1579                 case FMT_CASE(R, UNSIGNED_INT32):                                       return VK_FORMAT_R32_UINT;
1580                 case FMT_CASE(R, SIGNED_INT32):                                         return VK_FORMAT_R32_SINT;
1581                 case FMT_CASE(R, FLOAT):                                                        return VK_FORMAT_R32_SFLOAT;
1582
1583                 case FMT_CASE(RG, UNSIGNED_INT32):                                      return VK_FORMAT_R32G32_UINT;
1584                 case FMT_CASE(RG, SIGNED_INT32):                                        return VK_FORMAT_R32G32_SINT;
1585                 case FMT_CASE(RG, FLOAT):                                                       return VK_FORMAT_R32G32_SFLOAT;
1586
1587                 case FMT_CASE(RGB, UNSIGNED_INT32):                                     return VK_FORMAT_R32G32B32_UINT;
1588                 case FMT_CASE(RGB, SIGNED_INT32):                                       return VK_FORMAT_R32G32B32_SINT;
1589                 case FMT_CASE(RGB, FLOAT):                                                      return VK_FORMAT_R32G32B32_SFLOAT;
1590
1591                 case FMT_CASE(RGBA, UNSIGNED_INT32):                            return VK_FORMAT_R32G32B32A32_UINT;
1592                 case FMT_CASE(RGBA, SIGNED_INT32):                                      return VK_FORMAT_R32G32B32A32_SINT;
1593                 case FMT_CASE(RGBA, FLOAT):                                                     return VK_FORMAT_R32G32B32A32_SFLOAT;
1594
1595                 case FMT_CASE(R, FLOAT64):                                                      return VK_FORMAT_R64_SFLOAT;
1596                 case FMT_CASE(RG, FLOAT64):                                                     return VK_FORMAT_R64G64_SFLOAT;
1597                 case FMT_CASE(RGB, FLOAT64):                                            return VK_FORMAT_R64G64B64_SFLOAT;
1598                 case FMT_CASE(RGBA, FLOAT64):                                           return VK_FORMAT_R64G64B64A64_SFLOAT;
1599
1600                 case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV):       return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
1601                 case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV):            return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
1602
1603                 case FMT_CASE(BGR, UNORM_INT8):                                         return VK_FORMAT_B8G8R8_UNORM;
1604                 case FMT_CASE(BGR, SNORM_INT8):                                         return VK_FORMAT_B8G8R8_SNORM;
1605                 case FMT_CASE(BGR, UNSIGNED_INT8):                                      return VK_FORMAT_B8G8R8_UINT;
1606                 case FMT_CASE(BGR, SIGNED_INT8):                                        return VK_FORMAT_B8G8R8_SINT;
1607                 case FMT_CASE(sBGR, UNORM_INT8):                                        return VK_FORMAT_B8G8R8_SRGB;
1608
1609                 case FMT_CASE(BGRA, UNORM_INT8):                                        return VK_FORMAT_B8G8R8A8_UNORM;
1610                 case FMT_CASE(BGRA, SNORM_INT8):                                        return VK_FORMAT_B8G8R8A8_SNORM;
1611                 case FMT_CASE(BGRA, UNSIGNED_INT8):                                     return VK_FORMAT_B8G8R8A8_UINT;
1612                 case FMT_CASE(BGRA, SIGNED_INT8):                                       return VK_FORMAT_B8G8R8A8_SINT;
1613                 case FMT_CASE(sBGRA, UNORM_INT8):                                       return VK_FORMAT_B8G8R8A8_SRGB;
1614
1615                 case FMT_CASE(BGRA, UNORM_INT_1010102_REV):                     return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
1616                 case FMT_CASE(BGRA, SNORM_INT_1010102_REV):                     return VK_FORMAT_A2R10G10B10_SNORM_PACK32;
1617                 case FMT_CASE(BGRA, UNSIGNED_INT_1010102_REV):          return VK_FORMAT_A2R10G10B10_UINT_PACK32;
1618                 case FMT_CASE(BGRA, SIGNED_INT_1010102_REV):            return VK_FORMAT_A2R10G10B10_SINT_PACK32;
1619
1620                 case FMT_CASE(D, UNORM_INT16):                                          return VK_FORMAT_D16_UNORM;
1621                 case FMT_CASE(D, UNSIGNED_INT_24_8_REV):                        return VK_FORMAT_X8_D24_UNORM_PACK32;
1622                 case FMT_CASE(D, FLOAT):                                                        return VK_FORMAT_D32_SFLOAT;
1623
1624                 case FMT_CASE(S, UNSIGNED_INT8):                                        return VK_FORMAT_S8_UINT;
1625
1626                 case FMT_CASE(DS, UNSIGNED_INT_16_8_8):                         return VK_FORMAT_D16_UNORM_S8_UINT;
1627                 case FMT_CASE(DS, UNSIGNED_INT_24_8_REV):                       return VK_FORMAT_D24_UNORM_S8_UINT;
1628                 case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV):         return VK_FORMAT_D32_SFLOAT_S8_UINT;
1629
1630
1631                 case FMT_CASE(R,        UNORM_SHORT_10):                                return VK_FORMAT_R10X6_UNORM_PACK16_KHR;
1632                 case FMT_CASE(RG,       UNORM_SHORT_10):                                return VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR;
1633                 case FMT_CASE(RGBA,     UNORM_SHORT_10):                                return VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR;
1634
1635                 case FMT_CASE(R,        UNORM_SHORT_12):                                return VK_FORMAT_R12X4_UNORM_PACK16_KHR;
1636                 case FMT_CASE(RG,       UNORM_SHORT_12):                                return VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR;
1637                 case FMT_CASE(RGBA,     UNORM_SHORT_12):                                return VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR;
1638
1639                 default:
1640                         TCU_THROW(InternalError, "Unknown texture format");
1641         }
1642
1643 #undef PACK_FMT
1644 #undef FMT_CASE
1645 }
1646
1647 VkFormat mapCompressedTextureFormat (const tcu::CompressedTexFormat format)
1648 {
1649         // update this mapping if CompressedTexFormat changes
1650         DE_STATIC_ASSERT(tcu::COMPRESSEDTEXFORMAT_LAST == 55);
1651
1652         switch (format)
1653         {
1654                 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8:                                                return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
1655                 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8:                                               return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK;
1656                 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:    return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
1657                 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:   return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK;
1658                 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8:                                   return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
1659                 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8:                    return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK;
1660
1661                 case tcu::COMPRESSEDTEXFORMAT_EAC_R11:                                                  return VK_FORMAT_EAC_R11_UNORM_BLOCK;
1662                 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11:                                   return VK_FORMAT_EAC_R11_SNORM_BLOCK;
1663                 case tcu::COMPRESSEDTEXFORMAT_EAC_RG11:                                                 return VK_FORMAT_EAC_R11G11_UNORM_BLOCK;
1664                 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11:                                  return VK_FORMAT_EAC_R11G11_SNORM_BLOCK;
1665
1666                 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA:                                    return VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
1667                 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_4x4_SRGB_BLOCK;
1668                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA:                                    return VK_FORMAT_ASTC_5x4_UNORM_BLOCK;
1669                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_5x4_SRGB_BLOCK;
1670                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA:                                    return VK_FORMAT_ASTC_5x5_UNORM_BLOCK;
1671                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_5x5_SRGB_BLOCK;
1672                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA:                                    return VK_FORMAT_ASTC_6x5_UNORM_BLOCK;
1673                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_6x5_SRGB_BLOCK;
1674                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA:                                    return VK_FORMAT_ASTC_6x6_UNORM_BLOCK;
1675                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_6x6_SRGB_BLOCK;
1676                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA:                                    return VK_FORMAT_ASTC_8x5_UNORM_BLOCK;
1677                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x5_SRGB_BLOCK;
1678                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA:                                    return VK_FORMAT_ASTC_8x6_UNORM_BLOCK;
1679                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x6_SRGB_BLOCK;
1680                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA:                                    return VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
1681                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x8_SRGB_BLOCK;
1682                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA:                                   return VK_FORMAT_ASTC_10x5_UNORM_BLOCK;
1683                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x5_SRGB_BLOCK;
1684                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA:                                   return VK_FORMAT_ASTC_10x6_UNORM_BLOCK;
1685                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x6_SRGB_BLOCK;
1686                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA:                                   return VK_FORMAT_ASTC_10x8_UNORM_BLOCK;
1687                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x8_SRGB_BLOCK;
1688                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA:                                  return VK_FORMAT_ASTC_10x10_UNORM_BLOCK;
1689                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_10x10_SRGB_BLOCK;
1690                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA:                                  return VK_FORMAT_ASTC_12x10_UNORM_BLOCK;
1691                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_12x10_SRGB_BLOCK;
1692                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA:                                  return VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
1693                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_12x12_SRGB_BLOCK;
1694
1695                 case tcu::COMPRESSEDTEXFORMAT_BC1_RGB_UNORM_BLOCK:                              return VK_FORMAT_BC1_RGB_UNORM_BLOCK;
1696                 case tcu::COMPRESSEDTEXFORMAT_BC1_RGB_SRGB_BLOCK:                               return VK_FORMAT_BC1_RGB_SRGB_BLOCK;
1697                 case tcu::COMPRESSEDTEXFORMAT_BC1_RGBA_UNORM_BLOCK:                             return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
1698                 case tcu::COMPRESSEDTEXFORMAT_BC1_RGBA_SRGB_BLOCK:                              return VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
1699                 case tcu::COMPRESSEDTEXFORMAT_BC2_UNORM_BLOCK:                                  return VK_FORMAT_BC2_UNORM_BLOCK;
1700                 case tcu::COMPRESSEDTEXFORMAT_BC2_SRGB_BLOCK:                                   return VK_FORMAT_BC2_SRGB_BLOCK;
1701                 case tcu::COMPRESSEDTEXFORMAT_BC3_UNORM_BLOCK:                                  return VK_FORMAT_BC3_UNORM_BLOCK;
1702                 case tcu::COMPRESSEDTEXFORMAT_BC3_SRGB_BLOCK:                                   return VK_FORMAT_BC3_SRGB_BLOCK;
1703                 case tcu::COMPRESSEDTEXFORMAT_BC4_UNORM_BLOCK:                                  return VK_FORMAT_BC4_UNORM_BLOCK;
1704                 case tcu::COMPRESSEDTEXFORMAT_BC4_SNORM_BLOCK:                                  return VK_FORMAT_BC4_SNORM_BLOCK;
1705                 case tcu::COMPRESSEDTEXFORMAT_BC5_UNORM_BLOCK:                                  return VK_FORMAT_BC5_UNORM_BLOCK;
1706                 case tcu::COMPRESSEDTEXFORMAT_BC5_SNORM_BLOCK:                                  return VK_FORMAT_BC5_SNORM_BLOCK;
1707                 case tcu::COMPRESSEDTEXFORMAT_BC6H_UFLOAT_BLOCK:                                return VK_FORMAT_BC6H_UFLOAT_BLOCK;
1708                 case tcu::COMPRESSEDTEXFORMAT_BC6H_SFLOAT_BLOCK:                                return VK_FORMAT_BC6H_SFLOAT_BLOCK;
1709                 case tcu::COMPRESSEDTEXFORMAT_BC7_UNORM_BLOCK:                                  return VK_FORMAT_BC7_UNORM_BLOCK;
1710                 case tcu::COMPRESSEDTEXFORMAT_BC7_SRGB_BLOCK:                                   return VK_FORMAT_BC7_SRGB_BLOCK;
1711
1712                 default:
1713                         TCU_THROW(InternalError, "Unknown texture format");
1714                         return VK_FORMAT_UNDEFINED;
1715         }
1716 }
1717
1718 tcu::TextureFormat mapVkFormat (VkFormat format)
1719 {
1720         using tcu::TextureFormat;
1721
1722         // update this mapping if VkFormat changes
1723         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1724
1725         switch (format)
1726         {
1727                 case VK_FORMAT_R4G4_UNORM_PACK8:                return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_BYTE_44);
1728                 case VK_FORMAT_R5G6B5_UNORM_PACK16:             return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_SHORT_565);
1729                 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_4444);
1730                 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_5551);
1731
1732                 case VK_FORMAT_B5G6R5_UNORM_PACK16:             return TextureFormat(TextureFormat::BGR,        TextureFormat::UNORM_SHORT_565);
1733                 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_4444);
1734                 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_5551);
1735
1736                 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:   return TextureFormat(TextureFormat::ARGB,       TextureFormat::UNORM_SHORT_1555);
1737
1738                 case VK_FORMAT_R8_UNORM:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT8);
1739                 case VK_FORMAT_R8_SNORM:                                return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT8);
1740                 case VK_FORMAT_R8_USCALED:                              return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT8);
1741                 case VK_FORMAT_R8_SSCALED:                              return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT8);
1742                 case VK_FORMAT_R8_UINT:                                 return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT8);
1743                 case VK_FORMAT_R8_SINT:                                 return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT8);
1744                 case VK_FORMAT_R8_SRGB:                                 return TextureFormat(TextureFormat::sR,         TextureFormat::UNORM_INT8);
1745
1746                 case VK_FORMAT_R8G8_UNORM:                              return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT8);
1747                 case VK_FORMAT_R8G8_SNORM:                              return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT8);
1748                 case VK_FORMAT_R8G8_USCALED:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT8);
1749                 case VK_FORMAT_R8G8_SSCALED:                    return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT8);
1750                 case VK_FORMAT_R8G8_UINT:                               return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT8);
1751                 case VK_FORMAT_R8G8_SINT:                               return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT8);
1752                 case VK_FORMAT_R8G8_SRGB:                               return TextureFormat(TextureFormat::sRG,        TextureFormat::UNORM_INT8);
1753
1754                 case VK_FORMAT_R8G8B8_UNORM:                    return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT8);
1755                 case VK_FORMAT_R8G8B8_SNORM:                    return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT8);
1756                 case VK_FORMAT_R8G8B8_USCALED:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT8);
1757                 case VK_FORMAT_R8G8B8_SSCALED:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT8);
1758                 case VK_FORMAT_R8G8B8_UINT:                             return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT8);
1759                 case VK_FORMAT_R8G8B8_SINT:                             return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT8);
1760                 case VK_FORMAT_R8G8B8_SRGB:                             return TextureFormat(TextureFormat::sRGB,       TextureFormat::UNORM_INT8);
1761
1762                 case VK_FORMAT_R8G8B8A8_UNORM:                  return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT8);
1763                 case VK_FORMAT_R8G8B8A8_SNORM:                  return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT8);
1764                 case VK_FORMAT_R8G8B8A8_USCALED:                return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
1765                 case VK_FORMAT_R8G8B8A8_SSCALED:                return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
1766                 case VK_FORMAT_R8G8B8A8_UINT:                   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
1767                 case VK_FORMAT_R8G8B8A8_SINT:                   return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
1768                 case VK_FORMAT_R8G8B8A8_SRGB:                   return TextureFormat(TextureFormat::sRGBA,      TextureFormat::UNORM_INT8);
1769
1770                 case VK_FORMAT_R16_UNORM:                               return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT16);
1771                 case VK_FORMAT_R16_SNORM:                               return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT16);
1772                 case VK_FORMAT_R16_USCALED:                             return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT16);
1773                 case VK_FORMAT_R16_SSCALED:                             return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT16);
1774                 case VK_FORMAT_R16_UINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT16);
1775                 case VK_FORMAT_R16_SINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT16);
1776                 case VK_FORMAT_R16_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::HALF_FLOAT);
1777
1778                 case VK_FORMAT_R16G16_UNORM:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT16);
1779                 case VK_FORMAT_R16G16_SNORM:                    return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT16);
1780                 case VK_FORMAT_R16G16_USCALED:                  return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT16);
1781                 case VK_FORMAT_R16G16_SSCALED:                  return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT16);
1782                 case VK_FORMAT_R16G16_UINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT16);
1783                 case VK_FORMAT_R16G16_SINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT16);
1784                 case VK_FORMAT_R16G16_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::HALF_FLOAT);
1785
1786                 case VK_FORMAT_R16G16B16_UNORM:                 return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT16);
1787                 case VK_FORMAT_R16G16B16_SNORM:                 return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT16);
1788                 case VK_FORMAT_R16G16B16_USCALED:               return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT16);
1789                 case VK_FORMAT_R16G16B16_SSCALED:               return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT16);
1790                 case VK_FORMAT_R16G16B16_UINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT16);
1791                 case VK_FORMAT_R16G16B16_SINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT16);
1792                 case VK_FORMAT_R16G16B16_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::HALF_FLOAT);
1793
1794                 case VK_FORMAT_R16G16B16A16_UNORM:              return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT16);
1795                 case VK_FORMAT_R16G16B16A16_SNORM:              return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT16);
1796                 case VK_FORMAT_R16G16B16A16_USCALED:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT16);
1797                 case VK_FORMAT_R16G16B16A16_SSCALED:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT16);
1798                 case VK_FORMAT_R16G16B16A16_UINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT16);
1799                 case VK_FORMAT_R16G16B16A16_SINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT16);
1800                 case VK_FORMAT_R16G16B16A16_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::HALF_FLOAT);
1801
1802                 case VK_FORMAT_R32_UINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT32);
1803                 case VK_FORMAT_R32_SINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT32);
1804                 case VK_FORMAT_R32_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::FLOAT);
1805
1806                 case VK_FORMAT_R32G32_UINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT32);
1807                 case VK_FORMAT_R32G32_SINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT32);
1808                 case VK_FORMAT_R32G32_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::FLOAT);
1809
1810                 case VK_FORMAT_R32G32B32_UINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT32);
1811                 case VK_FORMAT_R32G32B32_SINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT32);
1812                 case VK_FORMAT_R32G32B32_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::FLOAT);
1813
1814                 case VK_FORMAT_R32G32B32A32_UINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT32);
1815                 case VK_FORMAT_R32G32B32A32_SINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT32);
1816                 case VK_FORMAT_R32G32B32A32_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::FLOAT);
1817
1818                 case VK_FORMAT_R64_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::FLOAT64);
1819                 case VK_FORMAT_R64G64_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::FLOAT64);
1820                 case VK_FORMAT_R64G64B64_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::FLOAT64);
1821                 case VK_FORMAT_R64G64B64A64_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::FLOAT64);
1822
1823                 case VK_FORMAT_B10G11R11_UFLOAT_PACK32: return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
1824                 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_999_E5_REV);
1825
1826                 case VK_FORMAT_B8G8R8_UNORM:                    return TextureFormat(TextureFormat::BGR,        TextureFormat::UNORM_INT8);
1827                 case VK_FORMAT_B8G8R8_SNORM:                    return TextureFormat(TextureFormat::BGR,        TextureFormat::SNORM_INT8);
1828                 case VK_FORMAT_B8G8R8_USCALED:                  return TextureFormat(TextureFormat::BGR,        TextureFormat::UNSIGNED_INT8);
1829                 case VK_FORMAT_B8G8R8_SSCALED:                  return TextureFormat(TextureFormat::BGR,        TextureFormat::SIGNED_INT8);
1830                 case VK_FORMAT_B8G8R8_UINT:                             return TextureFormat(TextureFormat::BGR,        TextureFormat::UNSIGNED_INT8);
1831                 case VK_FORMAT_B8G8R8_SINT:                             return TextureFormat(TextureFormat::BGR,        TextureFormat::SIGNED_INT8);
1832                 case VK_FORMAT_B8G8R8_SRGB:                             return TextureFormat(TextureFormat::sBGR,       TextureFormat::UNORM_INT8);
1833
1834                 case VK_FORMAT_B8G8R8A8_UNORM:                  return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_INT8);
1835                 case VK_FORMAT_B8G8R8A8_SNORM:                  return TextureFormat(TextureFormat::BGRA,       TextureFormat::SNORM_INT8);
1836                 case VK_FORMAT_B8G8R8A8_USCALED:                return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT8);
1837                 case VK_FORMAT_B8G8R8A8_SSCALED:                return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT8);
1838                 case VK_FORMAT_B8G8R8A8_UINT:                   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT8);
1839                 case VK_FORMAT_B8G8R8A8_SINT:                   return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT8);
1840                 case VK_FORMAT_B8G8R8A8_SRGB:                   return TextureFormat(TextureFormat::sBGRA,      TextureFormat::UNORM_INT8);
1841
1842                 case VK_FORMAT_D16_UNORM:                               return TextureFormat(TextureFormat::D,          TextureFormat::UNORM_INT16);
1843                 case VK_FORMAT_X8_D24_UNORM_PACK32:             return TextureFormat(TextureFormat::D,          TextureFormat::UNSIGNED_INT_24_8_REV);
1844                 case VK_FORMAT_D32_SFLOAT:                              return TextureFormat(TextureFormat::D,          TextureFormat::FLOAT);
1845
1846                 case VK_FORMAT_S8_UINT:                                 return TextureFormat(TextureFormat::S,          TextureFormat::UNSIGNED_INT8);
1847
1848                 // \note There is no standard interleaved memory layout for DS formats; buffer-image copies
1849                 //               will always operate on either D or S aspect only. See Khronos bug 12998
1850                 case VK_FORMAT_D16_UNORM_S8_UINT:               return TextureFormat(TextureFormat::DS,         TextureFormat::UNSIGNED_INT_16_8_8);
1851                 case VK_FORMAT_D24_UNORM_S8_UINT:               return TextureFormat(TextureFormat::DS,         TextureFormat::UNSIGNED_INT_24_8_REV);
1852                 case VK_FORMAT_D32_SFLOAT_S8_UINT:              return TextureFormat(TextureFormat::DS,         TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
1853
1854 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
1855                 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT8);
1856                 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT8);
1857                 case VK_FORMAT_A8B8G8R8_USCALED_PACK32: return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
1858                 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
1859                 case VK_FORMAT_A8B8G8R8_UINT_PACK32:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
1860                 case VK_FORMAT_A8B8G8R8_SINT_PACK32:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
1861                 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:    return TextureFormat(TextureFormat::sRGBA,      TextureFormat::UNORM_INT8);
1862 #else
1863 #       error "Big-endian not supported"
1864 #endif
1865
1866                 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:        return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_INT_1010102_REV);
1867                 case VK_FORMAT_A2R10G10B10_SNORM_PACK32:        return TextureFormat(TextureFormat::BGRA,       TextureFormat::SNORM_INT_1010102_REV);
1868                 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:      return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT_1010102_REV);
1869                 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:      return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT_1010102_REV);
1870                 case VK_FORMAT_A2R10G10B10_UINT_PACK32:         return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT_1010102_REV);
1871                 case VK_FORMAT_A2R10G10B10_SINT_PACK32:         return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT_1010102_REV);
1872
1873                 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:        return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT_1010102_REV);
1874                 case VK_FORMAT_A2B10G10R10_SNORM_PACK32:        return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT_1010102_REV);
1875                 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT_1010102_REV);
1876                 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT_1010102_REV);
1877                 case VK_FORMAT_A2B10G10R10_UINT_PACK32:         return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT_1010102_REV);
1878                 case VK_FORMAT_A2B10G10R10_SINT_PACK32:         return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT_1010102_REV);
1879
1880                 // YCbCr formats that can be mapped
1881                 case VK_FORMAT_R10X6_UNORM_PACK16_KHR:                                  return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_SHORT_10);
1882                 case VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_SHORT_10);
1883                 case VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR:  return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_10);
1884
1885                 case VK_FORMAT_R12X4_UNORM_PACK16_KHR:                                  return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_SHORT_12);
1886                 case VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_SHORT_12);
1887                 case VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR:  return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_12);
1888
1889                 default:
1890                         TCU_THROW(InternalError, "Unknown image format");
1891         }
1892 }
1893
1894 tcu::CompressedTexFormat mapVkCompressedFormat (VkFormat format)
1895 {
1896         // update this mapping if VkFormat changes
1897         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1898
1899         switch (format)
1900         {
1901                 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:         return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
1902                 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
1903                 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:       return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
1904                 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:        return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
1905                 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:       return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
1906                 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:        return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
1907
1908                 case VK_FORMAT_EAC_R11_UNORM_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
1909                 case VK_FORMAT_EAC_R11_SNORM_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
1910                 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
1911                 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
1912
1913                 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
1914                 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
1915                 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
1916                 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8;
1917                 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
1918                 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
1919                 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
1920                 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
1921                 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
1922                 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
1923                 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
1924                 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8;
1925                 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
1926                 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
1927                 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
1928                 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
1929                 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
1930                 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
1931                 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
1932                 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
1933                 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
1934                 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
1935                 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
1936                 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
1937                 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
1938                 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
1939                 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
1940                 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
1941
1942                 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_BC1_RGB_UNORM_BLOCK;
1943                 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:                      return tcu::COMPRESSEDTEXFORMAT_BC1_RGB_SRGB_BLOCK;
1944                 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_BC1_RGBA_UNORM_BLOCK;
1945                 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_BC1_RGBA_SRGB_BLOCK;
1946                 case VK_FORMAT_BC2_UNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC2_UNORM_BLOCK;
1947                 case VK_FORMAT_BC2_SRGB_BLOCK:                          return tcu::COMPRESSEDTEXFORMAT_BC2_SRGB_BLOCK;
1948                 case VK_FORMAT_BC3_UNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC3_UNORM_BLOCK;
1949                 case VK_FORMAT_BC3_SRGB_BLOCK:                          return tcu::COMPRESSEDTEXFORMAT_BC3_SRGB_BLOCK;
1950                 case VK_FORMAT_BC4_UNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC4_UNORM_BLOCK;
1951                 case VK_FORMAT_BC4_SNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC4_SNORM_BLOCK;
1952                 case VK_FORMAT_BC5_UNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC5_UNORM_BLOCK;
1953                 case VK_FORMAT_BC5_SNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC5_SNORM_BLOCK;
1954                 case VK_FORMAT_BC6H_UFLOAT_BLOCK:                       return tcu::COMPRESSEDTEXFORMAT_BC6H_UFLOAT_BLOCK;
1955                 case VK_FORMAT_BC6H_SFLOAT_BLOCK:                       return tcu::COMPRESSEDTEXFORMAT_BC6H_SFLOAT_BLOCK;
1956                 case VK_FORMAT_BC7_UNORM_BLOCK:                         return tcu::COMPRESSEDTEXFORMAT_BC7_UNORM_BLOCK;
1957                 case VK_FORMAT_BC7_SRGB_BLOCK:                          return tcu::COMPRESSEDTEXFORMAT_BC7_SRGB_BLOCK;
1958
1959                 default:
1960                         TCU_THROW(InternalError, "Unknown image format");
1961                         return tcu::COMPRESSEDTEXFORMAT_LAST;
1962         }
1963 }
1964
1965 static bool isScaledFormat (VkFormat format)
1966 {
1967         // update this mapping if VkFormat changes
1968         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
1969
1970         switch (format)
1971         {
1972                 case VK_FORMAT_R8_USCALED:
1973                 case VK_FORMAT_R8_SSCALED:
1974                 case VK_FORMAT_R8G8_USCALED:
1975                 case VK_FORMAT_R8G8_SSCALED:
1976                 case VK_FORMAT_R8G8B8_USCALED:
1977                 case VK_FORMAT_R8G8B8_SSCALED:
1978                 case VK_FORMAT_R8G8B8A8_USCALED:
1979                 case VK_FORMAT_R8G8B8A8_SSCALED:
1980                 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1981                 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1982                 case VK_FORMAT_R16_USCALED:
1983                 case VK_FORMAT_R16_SSCALED:
1984                 case VK_FORMAT_R16G16_USCALED:
1985                 case VK_FORMAT_R16G16_SSCALED:
1986                 case VK_FORMAT_R16G16B16_USCALED:
1987                 case VK_FORMAT_R16G16B16_SSCALED:
1988                 case VK_FORMAT_R16G16B16A16_USCALED:
1989                 case VK_FORMAT_R16G16B16A16_SSCALED:
1990                 case VK_FORMAT_B8G8R8_USCALED:
1991                 case VK_FORMAT_B8G8R8_SSCALED:
1992                 case VK_FORMAT_B8G8R8A8_USCALED:
1993                 case VK_FORMAT_B8G8R8A8_SSCALED:
1994                 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1995                 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1996                         return true;
1997
1998                 default:
1999                         return false;
2000         }
2001 }
2002
2003 static bool fullTextureFormatRoundTripSupported (VkFormat format)
2004 {
2005         if (isScaledFormat(format))
2006         {
2007                 // *SCALED formats get mapped to correspoding (u)int formats since
2008                 // accessing them through (float) getPixel/setPixel has same behavior
2009                 // as in shader access in Vulkan.
2010                 // Unfortunately full round-trip between tcu::TextureFormat and VkFormat
2011                 // for most SCALED formats is not supported though.
2012
2013                 const tcu::TextureFormat        tcuFormat       = mapVkFormat(format);
2014
2015                 switch (tcuFormat.type)
2016                 {
2017                         case tcu::TextureFormat::UNSIGNED_INT8:
2018                         case tcu::TextureFormat::UNSIGNED_INT16:
2019                         case tcu::TextureFormat::UNSIGNED_INT32:
2020                         case tcu::TextureFormat::SIGNED_INT8:
2021                         case tcu::TextureFormat::SIGNED_INT16:
2022                         case tcu::TextureFormat::SIGNED_INT32:
2023                         case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
2024                         case tcu::TextureFormat::SIGNED_INT_1010102_REV:
2025                                 return false;
2026
2027                         default:
2028                                 return true;
2029                 }
2030         }
2031         else
2032         {
2033                 switch (format)
2034                 {
2035                         case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2036                         case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2037                         case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
2038                         case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
2039                         case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2040                         case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2041                         case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2042                                 return false; // These map to regular byte array formats
2043
2044                         default:
2045                                 break;
2046                 }
2047
2048                 return (format != VK_FORMAT_UNDEFINED);
2049         }
2050 }
2051
2052 tcu::TextureFormat getChannelAccessFormat (tcu::TextureChannelClass     type,
2053                                                                                    deUint32                                     offsetBits,
2054                                                                                    deUint32                                     sizeBits)
2055 {
2056         using tcu::TextureFormat;
2057
2058         if (offsetBits == 0)
2059         {
2060                 static const TextureFormat::ChannelType s_size8[tcu::TEXTURECHANNELCLASS_LAST] =
2061                 {
2062                         TextureFormat::SNORM_INT8,                      // snorm
2063                         TextureFormat::UNORM_INT8,                      // unorm
2064                         TextureFormat::SIGNED_INT8,                     // sint
2065                         TextureFormat::UNSIGNED_INT8,           // uint
2066                         TextureFormat::CHANNELTYPE_LAST,        // float
2067                 };
2068                 static const TextureFormat::ChannelType s_size16[tcu::TEXTURECHANNELCLASS_LAST] =
2069                 {
2070                         TextureFormat::SNORM_INT16,                     // snorm
2071                         TextureFormat::UNORM_INT16,                     // unorm
2072                         TextureFormat::SIGNED_INT16,            // sint
2073                         TextureFormat::UNSIGNED_INT16,          // uint
2074                         TextureFormat::HALF_FLOAT,                      // float
2075                 };
2076                 static const TextureFormat::ChannelType s_size32[tcu::TEXTURECHANNELCLASS_LAST] =
2077                 {
2078                         TextureFormat::SNORM_INT32,                     // snorm
2079                         TextureFormat::UNORM_INT32,                     // unorm
2080                         TextureFormat::SIGNED_INT32,            // sint
2081                         TextureFormat::UNSIGNED_INT32,          // uint
2082                         TextureFormat::FLOAT,                           // float
2083                 };
2084
2085                 TextureFormat::ChannelType      chnType         = TextureFormat::CHANNELTYPE_LAST;
2086
2087                 if (sizeBits == 8)
2088                         chnType = s_size8[type];
2089                 else if (sizeBits == 16)
2090                         chnType = s_size16[type];
2091                 else if (sizeBits == 32)
2092                         chnType = s_size32[type];
2093
2094                 if (chnType != TextureFormat::CHANNELTYPE_LAST)
2095                         return TextureFormat(TextureFormat::R, chnType);
2096         }
2097         else
2098         {
2099                 if (type                == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT        &&
2100                         offsetBits      == 6                                                                                            &&
2101                         sizeBits        == 10)
2102                         return TextureFormat(TextureFormat::R, TextureFormat::UNORM_SHORT_10);
2103                 else if (type           == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT        &&
2104                                  offsetBits     == 4                                                                                            &&
2105                                  sizeBits       == 12)
2106                         return TextureFormat(TextureFormat::R, TextureFormat::UNORM_SHORT_12);
2107         }
2108
2109         TCU_THROW(InternalError, "Channel access format is not supported");
2110 }
2111
2112 tcu::PixelBufferAccess getChannelAccess (const PlanarFormatDescription& formatInfo,
2113                                                                                  const tcu::UVec2&                              size,
2114                                                                                  const deUint32*                                planeRowPitches,
2115                                                                                  void* const*                                   planePtrs,
2116                                                                                  deUint32                                               channelNdx)
2117 {
2118         DE_ASSERT(formatInfo.hasChannelNdx(channelNdx));
2119
2120         const deUint32  planeNdx                        = formatInfo.channels[channelNdx].planeNdx;
2121         const deUint32  planeOffsetBytes        = formatInfo.channels[channelNdx].offsetBits / 8;
2122         const deUint32  valueOffsetBits         = formatInfo.channels[channelNdx].offsetBits % 8;
2123         const deUint32  pixelStrideBytes        = formatInfo.channels[channelNdx].strideBytes;
2124
2125         DE_ASSERT(size.x() % formatInfo.planes[planeNdx].widthDivisor == 0);
2126         DE_ASSERT(size.y() % formatInfo.planes[planeNdx].heightDivisor == 0);
2127
2128         deUint32                accessWidth                     = size.x() / formatInfo.planes[planeNdx].widthDivisor;
2129         const deUint32  accessHeight            = size.y() / formatInfo.planes[planeNdx].heightDivisor;
2130         const deUint32  elementSizeBytes        = formatInfo.planes[planeNdx].elementSizeBytes;
2131
2132         const deUint32  rowPitch                        = planeRowPitches[planeNdx];
2133
2134         if (pixelStrideBytes != elementSizeBytes)
2135         {
2136                 DE_ASSERT(elementSizeBytes % pixelStrideBytes == 0);
2137                 accessWidth *= elementSizeBytes/pixelStrideBytes;
2138         }
2139
2140         return tcu::PixelBufferAccess(getChannelAccessFormat((tcu::TextureChannelClass)formatInfo.channels[channelNdx].type,
2141                                                                                                                  valueOffsetBits,
2142                                                                                                                  formatInfo.channels[channelNdx].sizeBits),
2143                                                                   tcu::IVec3((int)accessWidth, (int)accessHeight, 1),
2144                                                                   tcu::IVec3((int)pixelStrideBytes, (int)rowPitch, 0),
2145                                                                   (deUint8*)planePtrs[planeNdx] + planeOffsetBytes);
2146 }
2147
2148
2149 tcu::ConstPixelBufferAccess getChannelAccess (const PlanarFormatDescription&    formatInfo,
2150                                                                                           const tcu::UVec2&                                     size,
2151                                                                                           const deUint32*                                       planeRowPitches,
2152                                                                                           const void* const*                            planePtrs,
2153                                                                                           deUint32                                                      channelNdx)
2154 {
2155         return getChannelAccess(formatInfo, size, planeRowPitches, const_cast<void* const*>(planePtrs), channelNdx);
2156 }
2157
2158 void imageUtilSelfTest (void)
2159 {
2160         for (int formatNdx = 0; formatNdx < VK_CORE_FORMAT_LAST; formatNdx++)
2161         {
2162                 const VkFormat  format  = (VkFormat)formatNdx;
2163
2164                 if (format == VK_FORMAT_R64_UINT                        ||
2165                         format == VK_FORMAT_R64_SINT                    ||
2166                         format == VK_FORMAT_R64G64_UINT                 ||
2167                         format == VK_FORMAT_R64G64_SINT                 ||
2168                         format == VK_FORMAT_R64G64B64_UINT              ||
2169                         format == VK_FORMAT_R64G64B64_SINT              ||
2170                         format == VK_FORMAT_R64G64B64A64_UINT   ||
2171                         format == VK_FORMAT_R64G64B64A64_SINT)
2172                         continue; // \todo [2015-12-05 pyry] Add framework support for (u)int64 channel type
2173
2174                 if (format != VK_FORMAT_UNDEFINED && !isCompressedFormat(format))
2175                 {
2176                         const tcu::TextureFormat        tcuFormat               = mapVkFormat(format);
2177                         const VkFormat                          remappedFormat  = mapTextureFormat(tcuFormat);
2178
2179                         DE_TEST_ASSERT(isValid(tcuFormat));
2180
2181                         if (fullTextureFormatRoundTripSupported(format))
2182                                 DE_TEST_ASSERT(format == remappedFormat);
2183                 }
2184         }
2185
2186         for (int formatNdx = VK_FORMAT_G8B8G8R8_422_UNORM_KHR; formatNdx <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR; formatNdx++)
2187         {
2188                 const VkFormat                                  format  = (VkFormat)formatNdx;
2189                 const PlanarFormatDescription&  info    = getPlanarFormatDescription(format);
2190
2191                 DE_TEST_ASSERT(isYCbCrFormat(format));
2192                 DE_TEST_ASSERT(de::inRange<deUint8>(info.numPlanes, 1u, 3u));
2193                 DE_TEST_ASSERT(info.numPlanes == getPlaneCount(format));
2194         }
2195 }
2196
2197 VkFilter mapFilterMode (tcu::Sampler::FilterMode filterMode)
2198 {
2199         DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
2200
2201         switch (filterMode)
2202         {
2203                 case tcu::Sampler::NEAREST:                                     return VK_FILTER_NEAREST;
2204                 case tcu::Sampler::LINEAR:                                      return VK_FILTER_LINEAR;
2205                 case tcu::Sampler::NEAREST_MIPMAP_NEAREST:      return VK_FILTER_NEAREST;
2206                 case tcu::Sampler::NEAREST_MIPMAP_LINEAR:       return VK_FILTER_NEAREST;
2207                 case tcu::Sampler::LINEAR_MIPMAP_NEAREST:       return VK_FILTER_LINEAR;
2208                 case tcu::Sampler::LINEAR_MIPMAP_LINEAR:        return VK_FILTER_LINEAR;
2209                 default:
2210                         DE_FATAL("Illegal filter mode");
2211                         return (VkFilter)0;
2212         }
2213 }
2214
2215 VkSamplerMipmapMode mapMipmapMode (tcu::Sampler::FilterMode filterMode)
2216 {
2217         DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
2218
2219         // \note VkSamplerCreateInfo doesn't have a flag for disabling mipmapping. Instead
2220         //               minLod = 0 and maxLod = 0.25 should be used to match OpenGL NEAREST and LINEAR
2221         //               filtering mode behavior.
2222
2223         switch (filterMode)
2224         {
2225                 case tcu::Sampler::NEAREST:                                     return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2226                 case tcu::Sampler::LINEAR:                                      return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2227                 case tcu::Sampler::NEAREST_MIPMAP_NEAREST:      return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2228                 case tcu::Sampler::NEAREST_MIPMAP_LINEAR:       return VK_SAMPLER_MIPMAP_MODE_LINEAR;
2229                 case tcu::Sampler::LINEAR_MIPMAP_NEAREST:       return VK_SAMPLER_MIPMAP_MODE_NEAREST;
2230                 case tcu::Sampler::LINEAR_MIPMAP_LINEAR:        return VK_SAMPLER_MIPMAP_MODE_LINEAR;
2231                 default:
2232                         DE_FATAL("Illegal filter mode");
2233                         return (VkSamplerMipmapMode)0;
2234         }
2235 }
2236
2237 VkSamplerAddressMode mapWrapMode (tcu::Sampler::WrapMode wrapMode)
2238 {
2239         switch (wrapMode)
2240         {
2241                 case tcu::Sampler::CLAMP_TO_EDGE:               return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
2242                 case tcu::Sampler::CLAMP_TO_BORDER:             return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
2243                 case tcu::Sampler::REPEAT_GL:                   return VK_SAMPLER_ADDRESS_MODE_REPEAT;
2244                 case tcu::Sampler::MIRRORED_REPEAT_GL:  return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
2245                 case tcu::Sampler::MIRRORED_ONCE:               return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
2246                 default:
2247                         DE_FATAL("Wrap mode can't be mapped to Vulkan");
2248                         return (vk::VkSamplerAddressMode)0;
2249         }
2250 }
2251
2252 vk::VkCompareOp mapCompareMode (tcu::Sampler::CompareMode mode)
2253 {
2254         switch (mode)
2255         {
2256                 case tcu::Sampler::COMPAREMODE_NONE:                            return vk::VK_COMPARE_OP_NEVER;
2257                 case tcu::Sampler::COMPAREMODE_LESS:                            return vk::VK_COMPARE_OP_LESS;
2258                 case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:           return vk::VK_COMPARE_OP_LESS_OR_EQUAL;
2259                 case tcu::Sampler::COMPAREMODE_GREATER:                         return vk::VK_COMPARE_OP_GREATER;
2260                 case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:        return vk::VK_COMPARE_OP_GREATER_OR_EQUAL;
2261                 case tcu::Sampler::COMPAREMODE_EQUAL:                           return vk::VK_COMPARE_OP_EQUAL;
2262                 case tcu::Sampler::COMPAREMODE_NOT_EQUAL:                       return vk::VK_COMPARE_OP_NOT_EQUAL;
2263                 case tcu::Sampler::COMPAREMODE_ALWAYS:                          return vk::VK_COMPARE_OP_ALWAYS;
2264                 case tcu::Sampler::COMPAREMODE_NEVER:                           return vk::VK_COMPARE_OP_NEVER;
2265                 default:
2266                         DE_FATAL("Illegal compare mode");
2267                         return (vk::VkCompareOp)0;
2268         }
2269 }
2270
2271 static VkBorderColor mapBorderColor (tcu::TextureChannelClass channelClass, const rr::GenericVec4& color)
2272 {
2273         if (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
2274         {
2275                 const tcu::UVec4        uColor  = color.get<deUint32>();
2276
2277                 if (uColor              == tcu::UVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
2278                 else if (uColor == tcu::UVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
2279                 else if (uColor == tcu::UVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
2280         }
2281         else if (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
2282         {
2283                 const tcu::IVec4        sColor  = color.get<deInt32>();
2284
2285                 if (sColor              == tcu::IVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
2286                 else if (sColor == tcu::IVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
2287                 else if (sColor == tcu::IVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
2288         }
2289         else
2290         {
2291                 const tcu::Vec4         fColor  = color.get<float>();
2292
2293                 if (fColor              == tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f)) return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
2294                 else if (fColor == tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
2295                 else if (fColor == tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
2296         }
2297
2298         DE_FATAL("Unsupported border color");
2299         return VK_BORDER_COLOR_LAST;
2300 }
2301
2302 VkSamplerCreateInfo mapSampler (const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod, float maxLod)
2303 {
2304         const bool                                      compareEnabled  = (sampler.compare != tcu::Sampler::COMPAREMODE_NONE);
2305         const VkCompareOp                       compareOp               = (compareEnabled) ? (mapCompareMode(sampler.compare)) : (VK_COMPARE_OP_ALWAYS);
2306         const VkBorderColor                     borderColor             = mapBorderColor(getTextureChannelClass(format.type), sampler.borderColor);
2307         const bool                                      isMipmapEnabled = (sampler.minFilter != tcu::Sampler::NEAREST && sampler.minFilter != tcu::Sampler::LINEAR);
2308
2309         const VkSamplerCreateInfo       createInfo              =
2310         {
2311                 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
2312                 DE_NULL,
2313                 (VkSamplerCreateFlags)0,
2314                 mapFilterMode(sampler.magFilter),                                                       // magFilter
2315                 mapFilterMode(sampler.minFilter),                                                       // minFilter
2316                 mapMipmapMode(sampler.minFilter),                                                       // mipMode
2317                 mapWrapMode(sampler.wrapS),                                                                     // addressU
2318                 mapWrapMode(sampler.wrapT),                                                                     // addressV
2319                 mapWrapMode(sampler.wrapR),                                                                     // addressW
2320                 0.0f,                                                                                                           // mipLodBias
2321                 VK_FALSE,                                                                                                       // anisotropyEnable
2322                 1.0f,                                                                                                           // maxAnisotropy
2323                 (VkBool32)(compareEnabled ? VK_TRUE : VK_FALSE),                        // compareEnable
2324                 compareOp,                                                                                                      // compareOp
2325                 (isMipmapEnabled ? minLod : 0.0f),                                                      // minLod
2326                 (isMipmapEnabled ? maxLod : 0.25f),                                                     // maxLod
2327                 borderColor,                                                                                            // borderColor
2328                 (VkBool32)(sampler.normalizedCoords ? VK_FALSE : VK_TRUE),      // unnormalizedCoords
2329         };
2330
2331         return createInfo;
2332 }
2333
2334 tcu::Sampler mapVkSampler (const VkSamplerCreateInfo& samplerCreateInfo)
2335 {
2336         // \note minLod & maxLod are not supported by tcu::Sampler. LOD must be clamped
2337         //       before passing it to tcu::Texture*::sample*()
2338
2339         tcu::Sampler::ReductionMode reductionMode = tcu::Sampler::WEIGHTED_AVERAGE;
2340
2341         void const *pNext = samplerCreateInfo.pNext;
2342         while (pNext != DE_NULL)
2343         {
2344                 const VkStructureType nextType = *reinterpret_cast<const VkStructureType*>(pNext);
2345                 switch (nextType)
2346                 {
2347                         case VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT:
2348                         {
2349                                 const VkSamplerReductionModeCreateInfoEXT reductionModeCreateInfo = *reinterpret_cast<const VkSamplerReductionModeCreateInfoEXT*>(pNext);
2350                                 reductionMode = mapVkSamplerReductionMode(reductionModeCreateInfo.reductionMode);
2351                                 pNext = reinterpret_cast<const VkSamplerReductionModeCreateInfoEXT*>(pNext)->pNext;
2352                                 break;
2353                         }
2354                         case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO:
2355                                 pNext = reinterpret_cast<const VkSamplerYcbcrConversionInfo*>(pNext)->pNext;
2356                                 break;
2357                         default:
2358                                 TCU_FAIL("Unrecognized sType in chained sampler create info");
2359                 }
2360         }
2361
2362
2363
2364         tcu::Sampler sampler(mapVkSamplerAddressMode(samplerCreateInfo.addressModeU),
2365                                                  mapVkSamplerAddressMode(samplerCreateInfo.addressModeV),
2366                                                  mapVkSamplerAddressMode(samplerCreateInfo.addressModeW),
2367                                                  mapVkMinTexFilter(samplerCreateInfo.minFilter, samplerCreateInfo.mipmapMode),
2368                                                  mapVkMagTexFilter(samplerCreateInfo.magFilter),
2369                                                  0.0f,
2370                                                  !samplerCreateInfo.unnormalizedCoordinates,
2371                                                  samplerCreateInfo.compareEnable ? mapVkSamplerCompareOp(samplerCreateInfo.compareOp)
2372                                                                                                                  : tcu::Sampler::COMPAREMODE_NONE,
2373                                                  0,
2374                                                  tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
2375                                                  true,
2376                                                  tcu::Sampler::MODE_DEPTH,
2377                                                  reductionMode);
2378
2379         if (samplerCreateInfo.anisotropyEnable)
2380                 TCU_THROW(InternalError, "Anisotropic filtering is not supported by tcu::Sampler");
2381
2382         switch (samplerCreateInfo.borderColor)
2383         {
2384                 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
2385                         sampler.borderColor = tcu::UVec4(0,0,0,1);
2386                         break;
2387                 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
2388                         sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
2389                         break;
2390                 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
2391                         sampler.borderColor = tcu::UVec4(1, 1, 1, 1);
2392                         break;
2393                 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
2394                         sampler.borderColor = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
2395                         break;
2396                 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
2397                         sampler.borderColor = tcu::UVec4(0,0,0,0);
2398                         break;
2399                 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
2400                         sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
2401                         break;
2402
2403                 default:
2404                         DE_ASSERT(false);
2405                         break;
2406         }
2407
2408         return sampler;
2409 }
2410
2411 tcu::Sampler::CompareMode mapVkSamplerCompareOp (VkCompareOp compareOp)
2412 {
2413         switch (compareOp)
2414         {
2415                 case VK_COMPARE_OP_NEVER:                               return tcu::Sampler::COMPAREMODE_NEVER;
2416                 case VK_COMPARE_OP_LESS:                                return tcu::Sampler::COMPAREMODE_LESS;
2417                 case VK_COMPARE_OP_EQUAL:                               return tcu::Sampler::COMPAREMODE_EQUAL;
2418                 case VK_COMPARE_OP_LESS_OR_EQUAL:               return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
2419                 case VK_COMPARE_OP_GREATER:                             return tcu::Sampler::COMPAREMODE_GREATER;
2420                 case VK_COMPARE_OP_NOT_EQUAL:                   return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
2421                 case VK_COMPARE_OP_GREATER_OR_EQUAL:    return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
2422                 case VK_COMPARE_OP_ALWAYS:                              return tcu::Sampler::COMPAREMODE_ALWAYS;
2423                 default:
2424                         break;
2425         }
2426
2427         DE_ASSERT(false);
2428         return tcu::Sampler::COMPAREMODE_LAST;
2429 }
2430
2431 tcu::Sampler::WrapMode mapVkSamplerAddressMode (VkSamplerAddressMode addressMode)
2432 {
2433         switch (addressMode)
2434         {
2435                 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:                     return tcu::Sampler::CLAMP_TO_EDGE;
2436                 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:           return tcu::Sampler::CLAMP_TO_BORDER;
2437                 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:           return tcu::Sampler::MIRRORED_REPEAT_GL;
2438                 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:      return tcu::Sampler::MIRRORED_ONCE;
2439                 case VK_SAMPLER_ADDRESS_MODE_REPEAT:                            return tcu::Sampler::REPEAT_GL;
2440                 default:
2441                         break;
2442         }
2443
2444         DE_ASSERT(false);
2445         return tcu::Sampler::WRAPMODE_LAST;
2446 }
2447
2448 tcu::Sampler::ReductionMode mapVkSamplerReductionMode (VkSamplerReductionModeEXT reductionMode)
2449 {
2450         switch (reductionMode)
2451         {
2452                 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT:    return tcu::Sampler::WEIGHTED_AVERAGE;
2453                 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT:                                 return tcu::Sampler::MIN;
2454                 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT:                                 return tcu::Sampler::MAX;
2455                 default:
2456                         break;
2457         }
2458
2459         DE_ASSERT(false);
2460         return tcu::Sampler::REDUCTIONMODE_LAST;
2461 }
2462
2463 tcu::Sampler::FilterMode mapVkMinTexFilter (VkFilter filter, VkSamplerMipmapMode mipMode)
2464 {
2465         switch (filter)
2466         {
2467                 case VK_FILTER_LINEAR:
2468                         switch (mipMode)
2469                         {
2470                                 case VK_SAMPLER_MIPMAP_MODE_LINEAR:             return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
2471                                 case VK_SAMPLER_MIPMAP_MODE_NEAREST:    return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
2472                                 default:
2473                                         break;
2474                         }
2475                         break;
2476
2477                 case VK_FILTER_NEAREST:
2478                         switch (mipMode)
2479                         {
2480                                 case VK_SAMPLER_MIPMAP_MODE_LINEAR:             return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
2481                                 case VK_SAMPLER_MIPMAP_MODE_NEAREST:    return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
2482                                 default:
2483                                         break;
2484                         }
2485                         break;
2486
2487                 default:
2488                         break;
2489         }
2490
2491         DE_ASSERT(false);
2492         return tcu::Sampler::FILTERMODE_LAST;
2493 }
2494
2495 tcu::Sampler::FilterMode mapVkMagTexFilter (VkFilter filter)
2496 {
2497         switch (filter)
2498         {
2499                 case VK_FILTER_LINEAR:          return tcu::Sampler::LINEAR;
2500                 case VK_FILTER_NEAREST:         return tcu::Sampler::NEAREST;
2501                 default:
2502                         break;
2503         }
2504
2505         DE_ASSERT(false);
2506         return tcu::Sampler::FILTERMODE_LAST;
2507 }
2508
2509 //! Get a format the matches the layout in buffer memory used for a
2510 //! buffer<->image copy on a depth/stencil format.
2511 tcu::TextureFormat getDepthCopyFormat (VkFormat combinedFormat)
2512 {
2513         switch (combinedFormat)
2514         {
2515                 case VK_FORMAT_D16_UNORM:
2516                 case VK_FORMAT_X8_D24_UNORM_PACK32:
2517                 case VK_FORMAT_D32_SFLOAT:
2518                         return mapVkFormat(combinedFormat);
2519
2520                 case VK_FORMAT_D16_UNORM_S8_UINT:
2521                         return mapVkFormat(VK_FORMAT_D16_UNORM);
2522                 case VK_FORMAT_D24_UNORM_S8_UINT:
2523                         return mapVkFormat(VK_FORMAT_X8_D24_UNORM_PACK32);
2524                 case VK_FORMAT_D32_SFLOAT_S8_UINT:
2525                         return mapVkFormat(VK_FORMAT_D32_SFLOAT);
2526
2527                 case VK_FORMAT_S8_UINT:
2528                 default:
2529                         DE_FATAL("Unexpected depth/stencil format");
2530                         return tcu::TextureFormat();
2531         }
2532 }
2533
2534 //! Get a format the matches the layout in buffer memory used for a
2535 //! buffer<->image copy on a depth/stencil format.
2536 tcu::TextureFormat getStencilCopyFormat (VkFormat combinedFormat)
2537 {
2538         switch (combinedFormat)
2539         {
2540                 case VK_FORMAT_D16_UNORM_S8_UINT:
2541                 case VK_FORMAT_D24_UNORM_S8_UINT:
2542                 case VK_FORMAT_D32_SFLOAT_S8_UINT:
2543                 case VK_FORMAT_S8_UINT:
2544                         return mapVkFormat(VK_FORMAT_S8_UINT);
2545
2546                 case VK_FORMAT_D16_UNORM:
2547                 case VK_FORMAT_X8_D24_UNORM_PACK32:
2548                 case VK_FORMAT_D32_SFLOAT:
2549                 default:
2550                         DE_FATAL("Unexpected depth/stencil format");
2551                         return tcu::TextureFormat();
2552         }
2553 }
2554
2555 VkImageAspectFlags getImageAspectFlags (const tcu::TextureFormat textureFormat)
2556 {
2557         VkImageAspectFlags imageAspectFlags = 0;
2558
2559         if (tcu::hasDepthComponent(textureFormat.order))
2560                 imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
2561
2562         if (tcu::hasStencilComponent(textureFormat.order))
2563                 imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
2564
2565         if (imageAspectFlags == 0)
2566                 imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
2567
2568         return imageAspectFlags;
2569 }
2570
2571 VkExtent3D mipLevelExtents (const VkExtent3D& baseExtents, const deUint32 mipLevel)
2572 {
2573         VkExtent3D result;
2574
2575         result.width    = std::max(baseExtents.width >> mipLevel, 1u);
2576         result.height   = std::max(baseExtents.height >> mipLevel, 1u);
2577         result.depth    = std::max(baseExtents.depth >> mipLevel, 1u);
2578
2579         return result;
2580 }
2581
2582 tcu::UVec3 alignedDivide (const VkExtent3D& extent, const VkExtent3D& divisor)
2583 {
2584         tcu::UVec3 result;
2585
2586         result.x() = extent.width  / divisor.width  + ((extent.width  % divisor.width != 0)  ? 1u : 0u);
2587         result.y() = extent.height / divisor.height + ((extent.height % divisor.height != 0) ? 1u : 0u);
2588         result.z() = extent.depth  / divisor.depth  + ((extent.depth  % divisor.depth != 0)  ? 1u : 0u);
2589
2590         return result;
2591 }
2592
2593 void copyBufferToImage (const DeviceInterface&                                  vk,
2594                                                 VkDevice                                                                device,
2595                                                 VkQueue                                                                 queue,
2596                                                 deUint32                                                                queueFamilyIndex,
2597                                                 const VkBuffer&                                                 buffer,
2598                                                 deUint32                                                                bufferSize,
2599                                                 const std::vector<VkBufferImageCopy>&   copyRegions,
2600                                                 const VkSemaphore*                                              waitSemaphore,
2601                                                 VkImageAspectFlags                                              imageAspectFlags,
2602                                                 deUint32                                                                mipLevels,
2603                                                 deUint32                                                                arrayLayers,
2604                                                 VkImage                                                                 destImage)
2605 {
2606         Move<VkCommandPool>             cmdPool         = createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
2607         Move<VkCommandBuffer>   cmdBuffer       = allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2608         Move<VkFence>                   fence           = createFence(vk, device);
2609
2610         // Barriers for copying buffer to image
2611         const VkBufferMemoryBarrier preBufferBarrier =
2612         {
2613                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
2614                 DE_NULL,                                                                        // const void*          pNext;
2615                 VK_ACCESS_HOST_WRITE_BIT,                                       // VkAccessFlags        srcAccessMask;
2616                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags        dstAccessMask;
2617                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
2618                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
2619                 buffer,                                                                         // VkBuffer                     buffer;
2620                 0u,                                                                                     // VkDeviceSize         offset;
2621                 bufferSize                                                                      // VkDeviceSize         size;
2622         };
2623
2624         const VkImageMemoryBarrier preImageBarrier =
2625         {
2626                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
2627                 DE_NULL,                                                                                // const void*                          pNext;
2628                 0u,                                                                                             // VkAccessFlags                        srcAccessMask;
2629                 VK_ACCESS_TRANSFER_WRITE_BIT,                                   // VkAccessFlags                        dstAccessMask;
2630                 VK_IMAGE_LAYOUT_UNDEFINED,                                              // VkImageLayout                        oldLayout;
2631                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                   // VkImageLayout                        newLayout;
2632                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
2633                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
2634                 destImage,                                                                              // VkImage                                      image;
2635                 {                                                                                               // VkImageSubresourceRange      subresourceRange;
2636                         imageAspectFlags,                                                       // VkImageAspectFlags           aspect;
2637                         0u,                                                                                     // deUint32                                     baseMipLevel;
2638                         mipLevels,                                                                      // deUint32                                     mipLevels;
2639                         0u,                                                                                     // deUint32                                     baseArraySlice;
2640                         arrayLayers                                                                     // deUint32                                     arraySize;
2641                 }
2642         };
2643
2644         const VkImageMemoryBarrier postImageBarrier =
2645         {
2646                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
2647                 DE_NULL,                                                                                // const void*                          pNext;
2648                 VK_ACCESS_TRANSFER_WRITE_BIT,                                   // VkAccessFlags                        srcAccessMask;
2649                 VK_ACCESS_SHADER_READ_BIT,                                              // VkAccessFlags                        dstAccessMask;
2650                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                   // VkImageLayout                        oldLayout;
2651                 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,               // VkImageLayout                        newLayout;
2652                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
2653                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
2654                 destImage,                                                                              // VkImage                                      image;
2655                 {                                                                                               // VkImageSubresourceRange      subresourceRange;
2656                         imageAspectFlags,                                                       // VkImageAspectFlags           aspect;
2657                         0u,                                                                                     // deUint32                                     baseMipLevel;
2658                         mipLevels,                                                                      // deUint32                                     mipLevels;
2659                         0u,                                                                                     // deUint32                                     baseArraySlice;
2660                         arrayLayers                                                                     // deUint32                                     arraySize;
2661                 }
2662         };
2663
2664         const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2665         {
2666                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                                      sType;
2667                 DE_NULL,                                                                                // const void*                                          pNext;
2668                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,    // VkCommandBufferUsageFlags            flags;
2669                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2670         };
2671
2672         // Copy buffer to image
2673         VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
2674         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &preBufferBarrier, 1, &preImageBarrier);
2675         vk.cmdCopyBufferToImage(*cmdBuffer, buffer, destImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)copyRegions.size(), copyRegions.data());
2676         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
2677         VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
2678
2679         const VkPipelineStageFlags pipelineStageFlags = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
2680
2681         const VkSubmitInfo submitInfo =
2682         {
2683                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                              sType;
2684                 DE_NULL,                                                // const void*                                  pNext;
2685                 waitSemaphore ? 1u : 0u,                // deUint32                                             waitSemaphoreCount;
2686                 waitSemaphore,                                  // const VkSemaphore*                   pWaitSemaphores;
2687                 &pipelineStageFlags,                    // const VkPipelineStageFlags*  pWaitDstStageMask;
2688                 1u,                                                             // deUint32                                             commandBufferCount;
2689                 &cmdBuffer.get(),                               // const VkCommandBuffer*               pCommandBuffers;
2690                 0u,                                                             // deUint32                                             signalSemaphoreCount;
2691                 DE_NULL                                                 // const VkSemaphore*                   pSignalSemaphores;
2692         };
2693
2694         try
2695         {
2696                 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
2697                 VK_CHECK(vk.waitForFences(device, 1, &fence.get(), true, ~(0ull) /* infinity */));
2698         }
2699         catch (...)
2700         {
2701                 VK_CHECK(vk.deviceWaitIdle(device));
2702                 throw;
2703         }
2704 }
2705
2706 void allocateAndBindSparseImage (const DeviceInterface&                                         vk,
2707                                                                  VkDevice                                                                       device,
2708                                                                  const VkPhysicalDevice                                         physicalDevice,
2709                                                                  const InstanceInterface&                                       instance,
2710                                                                  const VkImageCreateInfo&                                       imageCreateInfo,
2711                                                                  const VkSemaphore&                                                     signalSemaphore,
2712                                                                  VkQueue                                                                        queue,
2713                                                                  Allocator&                                                                     allocator,
2714                                                                  std::vector<de::SharedPtr<Allocation> >&       allocations,
2715                                                                  tcu::TextureFormat                                                     format,
2716                                                                  VkImage                                                                        destImage)
2717 {
2718         const VkImageAspectFlags                                imageAspectFlags                = getImageAspectFlags(format);
2719         const VkPhysicalDeviceProperties                deviceProperties                = getPhysicalDeviceProperties(instance, physicalDevice);
2720         const VkPhysicalDeviceMemoryProperties  deviceMemoryProperties  = getPhysicalDeviceMemoryProperties(instance, physicalDevice);
2721         deUint32                                                                sparseMemoryReqCount    = 0;
2722
2723         // Check if the image format supports sparse operations
2724         if (!checkSparseImageFormatSupport(physicalDevice, instance, imageCreateInfo))
2725                 TCU_THROW(NotSupportedError, "The image format does not support sparse operations.");
2726
2727         vk.getImageSparseMemoryRequirements(device, destImage, &sparseMemoryReqCount, DE_NULL);
2728
2729         DE_ASSERT(sparseMemoryReqCount != 0);
2730
2731         std::vector<VkSparseImageMemoryRequirements> sparseImageMemoryRequirements;
2732         sparseImageMemoryRequirements.resize(sparseMemoryReqCount);
2733
2734         vk.getImageSparseMemoryRequirements(device, destImage, &sparseMemoryReqCount, &sparseImageMemoryRequirements[0]);
2735
2736         const deUint32 noMatchFound = ~((deUint32)0);
2737
2738         deUint32 aspectIndex = noMatchFound;
2739         for (deUint32 memoryReqNdx = 0; memoryReqNdx < sparseMemoryReqCount; ++memoryReqNdx)
2740         {
2741                 if (sparseImageMemoryRequirements[memoryReqNdx].formatProperties.aspectMask == imageAspectFlags)
2742                 {
2743                         aspectIndex = memoryReqNdx;
2744                         break;
2745                 }
2746         }
2747
2748         deUint32 metadataAspectIndex = noMatchFound;
2749         for (deUint32 memoryReqNdx = 0; memoryReqNdx < sparseMemoryReqCount; ++memoryReqNdx)
2750         {
2751                 if (sparseImageMemoryRequirements[memoryReqNdx].formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT)
2752                 {
2753                         metadataAspectIndex = memoryReqNdx;
2754                         break;
2755                 }
2756         }
2757
2758         if (aspectIndex == noMatchFound)
2759                 TCU_THROW(NotSupportedError, "Required image aspect not supported.");
2760
2761         const VkMemoryRequirements      memoryRequirements      = getImageMemoryRequirements(vk, device, destImage);
2762
2763         deUint32 memoryType = noMatchFound;
2764         for (deUint32 memoryTypeNdx = 0; memoryTypeNdx < deviceMemoryProperties.memoryTypeCount; ++memoryTypeNdx)
2765         {
2766                 if ((memoryRequirements.memoryTypeBits & (1u << memoryTypeNdx)) != 0 &&
2767                         MemoryRequirement::Any.matchesHeap(deviceMemoryProperties.memoryTypes[memoryTypeNdx].propertyFlags))
2768                 {
2769                         memoryType = memoryTypeNdx;
2770                         break;
2771                 }
2772         }
2773
2774         if (memoryType == noMatchFound)
2775                 TCU_THROW(NotSupportedError, "No matching memory type found.");
2776
2777         if (memoryRequirements.size > deviceProperties.limits.sparseAddressSpaceSize)
2778                 TCU_THROW(NotSupportedError, "Required memory size for sparse resource exceeds device limits.");
2779
2780         const VkSparseImageMemoryRequirements           aspectRequirements      = sparseImageMemoryRequirements[aspectIndex];
2781         const VkExtent3D                                                        imageGranularity        = aspectRequirements.formatProperties.imageGranularity;
2782
2783         std::vector<VkSparseImageMemoryBind>            imageResidencyMemoryBinds;
2784         std::vector<VkSparseMemoryBind>                         imageMipTailMemoryBinds;
2785
2786         for (deUint32 layerNdx = 0; layerNdx < imageCreateInfo.arrayLayers; ++layerNdx)
2787         {
2788                 for (deUint32 mipLevelNdx = 0; mipLevelNdx < aspectRequirements.imageMipTailFirstLod; ++mipLevelNdx)
2789                 {
2790                         const VkExtent3D        mipExtent               = mipLevelExtents(imageCreateInfo.extent, mipLevelNdx);
2791                         const tcu::UVec3        numSparseBinds  = alignedDivide(mipExtent, imageGranularity);
2792                         const tcu::UVec3        lastBlockExtent = tcu::UVec3(mipExtent.width  % imageGranularity.width  ? mipExtent.width  % imageGranularity.width  : imageGranularity.width,
2793                                                                                                                          mipExtent.height % imageGranularity.height ? mipExtent.height % imageGranularity.height : imageGranularity.height,
2794                                                                                                                          mipExtent.depth  % imageGranularity.depth  ? mipExtent.depth  % imageGranularity.depth  : imageGranularity.depth );
2795
2796                         for (deUint32 z = 0; z < numSparseBinds.z(); ++z)
2797                         for (deUint32 y = 0; y < numSparseBinds.y(); ++y)
2798                         for (deUint32 x = 0; x < numSparseBinds.x(); ++x)
2799                         {
2800                                 const VkMemoryRequirements allocRequirements =
2801                                 {
2802                                         // 28.7.5 alignment shows the block size in bytes
2803                                         memoryRequirements.alignment,           // VkDeviceSize size;
2804                                         memoryRequirements.alignment,           // VkDeviceSize alignment;
2805                                         memoryRequirements.memoryTypeBits,      // uint32_t             memoryTypeBits;
2806                                 };
2807
2808                                 de::SharedPtr<Allocation> allocation(allocator.allocate(allocRequirements, MemoryRequirement::Any).release());
2809                                 allocations.push_back(allocation);
2810
2811                                 VkOffset3D offset;
2812                                 offset.x = x*imageGranularity.width;
2813                                 offset.y = y*imageGranularity.height;
2814                                 offset.z = z*imageGranularity.depth;
2815
2816                                 VkExtent3D extent;
2817                                 extent.width    = (x == numSparseBinds.x() - 1) ? lastBlockExtent.x() : imageGranularity.width;
2818                                 extent.height   = (y == numSparseBinds.y() - 1) ? lastBlockExtent.y() : imageGranularity.height;
2819                                 extent.depth    = (z == numSparseBinds.z() - 1) ? lastBlockExtent.z() : imageGranularity.depth;
2820
2821                                 const VkSparseImageMemoryBind imageMemoryBind =
2822                                 {
2823                                         {
2824                                                 imageAspectFlags,       // VkImageAspectFlags   aspectMask;
2825                                                 mipLevelNdx,            // uint32_t                             mipLevel;
2826                                                 layerNdx,                       // uint32_t                             arrayLayer;
2827                                         },                                                      // VkImageSubresource           subresource;
2828                                         offset,                                         // VkOffset3D                           offset;
2829                                         extent,                                         // VkExtent3D                           extent;
2830                                         allocation->getMemory(),        // VkDeviceMemory                       memory;
2831                                         allocation->getOffset(),        // VkDeviceSize                         memoryOffset;
2832                                         0u,                                                     // VkSparseMemoryBindFlags      flags;
2833                                 };
2834
2835                                 imageResidencyMemoryBinds.push_back(imageMemoryBind);
2836                         }
2837                 }
2838
2839                 // Handle MIP tail. There are two cases to consider here:
2840                 //
2841                 // 1) VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT is requested by the driver: each layer needs a separate tail.
2842                 // 2) otherwise:                                                            only one tail is needed.
2843                 if (aspectRequirements.imageMipTailSize > 0)
2844                 {
2845                         if (layerNdx == 0 || (aspectRequirements.formatProperties.flags & VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT) == 0)
2846                         {
2847                                 const VkMemoryRequirements allocRequirements =
2848                                 {
2849                                         aspectRequirements.imageMipTailSize,    // VkDeviceSize size;
2850                                         memoryRequirements.alignment,                   // VkDeviceSize alignment;
2851                                         memoryRequirements.memoryTypeBits,              // uint32_t             memoryTypeBits;
2852                                 };
2853
2854                                 const de::SharedPtr<Allocation> allocation(allocator.allocate(allocRequirements, MemoryRequirement::Any).release());
2855
2856                                 const VkSparseMemoryBind imageMipTailMemoryBind =
2857                                 {
2858                                         aspectRequirements.imageMipTailOffset + layerNdx * aspectRequirements.imageMipTailStride,       // VkDeviceSize                                 resourceOffset;
2859                                         aspectRequirements.imageMipTailSize,                                                                                                            // VkDeviceSize                                 size;
2860                                         allocation->getMemory(),                                                                                                                                        // VkDeviceMemory                               memory;
2861                                         allocation->getOffset(),                                                                                                                                        // VkDeviceSize                                 memoryOffset;
2862                                         0u,                                                                                                                                                                                     // VkSparseMemoryBindFlags              flags;
2863                                 };
2864
2865                                 allocations.push_back(allocation);
2866
2867                                 imageMipTailMemoryBinds.push_back(imageMipTailMemoryBind);
2868                         }
2869                 }
2870
2871                 // Handle Metadata. Similarly to MIP tail in aspectRequirements, there are two cases to consider here:
2872                 //
2873                 // 1) VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT is requested by the driver: each layer needs a separate tail.
2874                 // 2) otherwise:
2875                 if (metadataAspectIndex != noMatchFound)
2876                 {
2877                         const VkSparseImageMemoryRequirements   metadataAspectRequirements = sparseImageMemoryRequirements[metadataAspectIndex];
2878
2879                         if (layerNdx == 0 || (metadataAspectRequirements.formatProperties.flags & VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT) == 0)
2880                         {
2881                                 const VkMemoryRequirements metadataAllocRequirements =
2882                                 {
2883                                         metadataAspectRequirements.imageMipTailSize,    // VkDeviceSize size;
2884                                         memoryRequirements.alignment,                                   // VkDeviceSize alignment;
2885                                         memoryRequirements.memoryTypeBits,                              // uint32_t             memoryTypeBits;
2886                                 };
2887                                 const de::SharedPtr<Allocation> metadataAllocation(allocator.allocate(metadataAllocRequirements, MemoryRequirement::Any).release());
2888
2889                                 const VkSparseMemoryBind metadataMipTailMemoryBind =
2890                                 {
2891                                         metadataAspectRequirements.imageMipTailOffset +
2892                                         layerNdx * metadataAspectRequirements.imageMipTailStride,                       // VkDeviceSize                                 resourceOffset;
2893                                         metadataAspectRequirements.imageMipTailSize,                                            // VkDeviceSize                                 size;
2894                                         metadataAllocation->getMemory(),                                                                        // VkDeviceMemory                               memory;
2895                                         metadataAllocation->getOffset(),                                                                        // VkDeviceSize                                 memoryOffset;
2896                                         VK_SPARSE_MEMORY_BIND_METADATA_BIT                                                                      // VkSparseMemoryBindFlags              flags;
2897                                 };
2898
2899                                 allocations.push_back(metadataAllocation);
2900
2901                                 imageMipTailMemoryBinds.push_back(metadataMipTailMemoryBind);
2902                         }
2903                 }
2904         }
2905
2906         VkBindSparseInfo bindSparseInfo =
2907         {
2908                 VK_STRUCTURE_TYPE_BIND_SPARSE_INFO,                     //VkStructureType                                                       sType;
2909                 DE_NULL,                                                                        //const void*                                                           pNext;
2910                 0u,                                                                                     //deUint32                                                                      waitSemaphoreCount;
2911                 DE_NULL,                                                                        //const VkSemaphore*                                            pWaitSemaphores;
2912                 0u,                                                                                     //deUint32                                                                      bufferBindCount;
2913                 DE_NULL,                                                                        //const VkSparseBufferMemoryBindInfo*           pBufferBinds;
2914                 0u,                                                                                     //deUint32                                                                      imageOpaqueBindCount;
2915                 DE_NULL,                                                                        //const VkSparseImageOpaqueMemoryBindInfo*      pImageOpaqueBinds;
2916                 0u,                                                                                     //deUint32                                                                      imageBindCount;
2917                 DE_NULL,                                                                        //const VkSparseImageMemoryBindInfo*            pImageBinds;
2918                 1u,                                                                                     //deUint32                                                                      signalSemaphoreCount;
2919                 &signalSemaphore                                                        //const VkSemaphore*                                            pSignalSemaphores;
2920         };
2921
2922         VkSparseImageMemoryBindInfo                     imageResidencyBindInfo;
2923         VkSparseImageOpaqueMemoryBindInfo       imageMipTailBindInfo;
2924
2925         if (imageResidencyMemoryBinds.size() > 0)
2926         {
2927                 imageResidencyBindInfo.image            = destImage;
2928                 imageResidencyBindInfo.bindCount        = static_cast<deUint32>(imageResidencyMemoryBinds.size());
2929                 imageResidencyBindInfo.pBinds           = &imageResidencyMemoryBinds[0];
2930
2931                 bindSparseInfo.imageBindCount           = 1u;
2932                 bindSparseInfo.pImageBinds                      = &imageResidencyBindInfo;
2933         }
2934
2935         if (imageMipTailMemoryBinds.size() > 0)
2936         {
2937                 imageMipTailBindInfo.image                      = destImage;
2938                 imageMipTailBindInfo.bindCount          = static_cast<deUint32>(imageMipTailMemoryBinds.size());
2939                 imageMipTailBindInfo.pBinds                     = &imageMipTailMemoryBinds[0];
2940
2941                 bindSparseInfo.imageOpaqueBindCount     = 1u;
2942                 bindSparseInfo.pImageOpaqueBinds        = &imageMipTailBindInfo;
2943         }
2944
2945         VK_CHECK(vk.queueBindSparse(queue, 1u, &bindSparseInfo, DE_NULL));
2946 }
2947
2948 bool checkSparseImageFormatSupport (const VkPhysicalDevice              physicalDevice,
2949                                                                         const InstanceInterface&        instance,
2950                                                                         const VkImageCreateInfo&        imageCreateInfo)
2951 {
2952         const std::vector<VkSparseImageFormatProperties> sparseImageFormatPropVec =
2953                 getPhysicalDeviceSparseImageFormatProperties(instance, physicalDevice, imageCreateInfo.format, imageCreateInfo.imageType, imageCreateInfo.samples, imageCreateInfo.usage, imageCreateInfo.tiling);
2954
2955         return (sparseImageFormatPropVec.size() != 0);
2956 }
2957
2958 } // vk