Merge vk-gl-cts/opengl-es-cts-3.2.3 into vk-gl-cts/opengl-es-cts-3.2.4
[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 "tcuTextureUtil.hpp"
28
29 namespace vk
30 {
31
32 bool isFloatFormat (VkFormat format)
33 {
34         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
35 }
36
37 bool isUnormFormat (VkFormat format)
38 {
39         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
40 }
41
42 bool isSnormFormat (VkFormat format)
43 {
44         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
45 }
46
47 bool isIntFormat (VkFormat format)
48 {
49         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER;
50 }
51
52 bool isUintFormat (VkFormat format)
53 {
54         return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
55 }
56
57 bool isDepthStencilFormat (VkFormat format)
58 {
59         if (isCompressedFormat(format))
60                 return false;
61
62         const tcu::TextureFormat tcuFormat = mapVkFormat(format);
63         return tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS;
64 }
65
66 bool isSrgbFormat (VkFormat format)
67 {
68         switch (mapVkFormat(format).order)
69         {
70                 case tcu::TextureFormat::sR:
71                 case tcu::TextureFormat::sRG:
72                 case tcu::TextureFormat::sRGB:
73                 case tcu::TextureFormat::sRGBA:
74                 case tcu::TextureFormat::sBGR:
75                 case tcu::TextureFormat::sBGRA:
76                         return true;
77
78                 default:
79                         return false;
80         }
81 }
82
83 bool isCompressedFormat (VkFormat format)
84 {
85         // update this mapping if VkFormat changes
86         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
87
88         switch (format)
89         {
90                 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
91                 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
92                 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
93                 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
94                 case VK_FORMAT_BC2_UNORM_BLOCK:
95                 case VK_FORMAT_BC2_SRGB_BLOCK:
96                 case VK_FORMAT_BC3_UNORM_BLOCK:
97                 case VK_FORMAT_BC3_SRGB_BLOCK:
98                 case VK_FORMAT_BC4_UNORM_BLOCK:
99                 case VK_FORMAT_BC4_SNORM_BLOCK:
100                 case VK_FORMAT_BC5_UNORM_BLOCK:
101                 case VK_FORMAT_BC5_SNORM_BLOCK:
102                 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
103                 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
104                 case VK_FORMAT_BC7_UNORM_BLOCK:
105                 case VK_FORMAT_BC7_SRGB_BLOCK:
106                 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
107                 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
108                 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
109                 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
110                 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
111                 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
112                 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
113                 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
114                 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
115                 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
116                 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
117                 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
118                 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
119                 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
120                 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
121                 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
122                 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
123                 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
124                 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
125                 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
126                 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
127                 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
128                 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
129                 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
130                 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
131                 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
132                 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
133                 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
134                 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
135                 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
136                 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
137                 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
138                 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
139                 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
140                 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
141                 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
142                 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
143                 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
144                         return true;
145
146                 default:
147                         return false;
148         }
149 }
150
151 bool isSupportedByFramework (VkFormat format)
152 {
153         if (format == VK_FORMAT_UNDEFINED || format > VK_CORE_FORMAT_LAST)
154                 return false;
155
156         switch (format)
157         {
158                 case VK_FORMAT_R64_UINT:
159                 case VK_FORMAT_R64_SINT:
160                 case VK_FORMAT_R64_SFLOAT:
161                 case VK_FORMAT_R64G64_UINT:
162                 case VK_FORMAT_R64G64_SINT:
163                 case VK_FORMAT_R64G64_SFLOAT:
164                 case VK_FORMAT_R64G64B64_UINT:
165                 case VK_FORMAT_R64G64B64_SINT:
166                 case VK_FORMAT_R64G64B64_SFLOAT:
167                 case VK_FORMAT_R64G64B64A64_UINT:
168                 case VK_FORMAT_R64G64B64A64_SINT:
169                 case VK_FORMAT_R64G64B64A64_SFLOAT:
170                         // \todo [2016-12-01 pyry] Support 64-bit channel types
171                         return false;
172
173                 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
174                 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
175                 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
176                 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
177                 case VK_FORMAT_BC2_UNORM_BLOCK:
178                 case VK_FORMAT_BC2_SRGB_BLOCK:
179                 case VK_FORMAT_BC3_UNORM_BLOCK:
180                 case VK_FORMAT_BC3_SRGB_BLOCK:
181                 case VK_FORMAT_BC4_UNORM_BLOCK:
182                 case VK_FORMAT_BC4_SNORM_BLOCK:
183                 case VK_FORMAT_BC5_UNORM_BLOCK:
184                 case VK_FORMAT_BC5_SNORM_BLOCK:
185                 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
186                 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
187                 case VK_FORMAT_BC7_UNORM_BLOCK:
188                 case VK_FORMAT_BC7_SRGB_BLOCK:
189                         return false;
190
191                 default:
192                         return true;
193         }
194 }
195
196 VkFormat mapTextureFormat (const tcu::TextureFormat& format)
197 {
198         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
199         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
200
201 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
202 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
203
204         // update this mapping if VkFormat changes
205         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
206
207         switch (PACK_FMT(format.order, format.type))
208         {
209                 case FMT_CASE(RG, UNORM_BYTE_44):                                       return VK_FORMAT_R4G4_UNORM_PACK8;
210                 case FMT_CASE(RGB, UNORM_SHORT_565):                            return VK_FORMAT_R5G6B5_UNORM_PACK16;
211                 case FMT_CASE(RGBA, UNORM_SHORT_4444):                          return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
212                 case FMT_CASE(RGBA, UNORM_SHORT_5551):                          return VK_FORMAT_R5G5B5A1_UNORM_PACK16;
213
214                 case FMT_CASE(BGR, UNORM_SHORT_565):                            return VK_FORMAT_B5G6R5_UNORM_PACK16;
215                 case FMT_CASE(BGRA, UNORM_SHORT_4444):                          return VK_FORMAT_B4G4R4A4_UNORM_PACK16;
216                 case FMT_CASE(BGRA, UNORM_SHORT_5551):                          return VK_FORMAT_B5G5R5A1_UNORM_PACK16;
217
218                 case FMT_CASE(ARGB, UNORM_SHORT_1555):                          return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
219
220                 case FMT_CASE(R, UNORM_INT8):                                           return VK_FORMAT_R8_UNORM;
221                 case FMT_CASE(R, SNORM_INT8):                                           return VK_FORMAT_R8_SNORM;
222                 case FMT_CASE(R, UNSIGNED_INT8):                                        return VK_FORMAT_R8_UINT;
223                 case FMT_CASE(R, SIGNED_INT8):                                          return VK_FORMAT_R8_SINT;
224                 case FMT_CASE(sR, UNORM_INT8):                                          return VK_FORMAT_R8_SRGB;
225
226                 case FMT_CASE(RG, UNORM_INT8):                                          return VK_FORMAT_R8G8_UNORM;
227                 case FMT_CASE(RG, SNORM_INT8):                                          return VK_FORMAT_R8G8_SNORM;
228                 case FMT_CASE(RG, UNSIGNED_INT8):                                       return VK_FORMAT_R8G8_UINT;
229                 case FMT_CASE(RG, SIGNED_INT8):                                         return VK_FORMAT_R8G8_SINT;
230                 case FMT_CASE(sRG, UNORM_INT8):                                         return VK_FORMAT_R8G8_SRGB;
231
232                 case FMT_CASE(RGB, UNORM_INT8):                                         return VK_FORMAT_R8G8B8_UNORM;
233                 case FMT_CASE(RGB, SNORM_INT8):                                         return VK_FORMAT_R8G8B8_SNORM;
234                 case FMT_CASE(RGB, UNSIGNED_INT8):                                      return VK_FORMAT_R8G8B8_UINT;
235                 case FMT_CASE(RGB, SIGNED_INT8):                                        return VK_FORMAT_R8G8B8_SINT;
236                 case FMT_CASE(sRGB, UNORM_INT8):                                        return VK_FORMAT_R8G8B8_SRGB;
237
238                 case FMT_CASE(RGBA, UNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_UNORM;
239                 case FMT_CASE(RGBA, SNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_SNORM;
240                 case FMT_CASE(RGBA, UNSIGNED_INT8):                                     return VK_FORMAT_R8G8B8A8_UINT;
241                 case FMT_CASE(RGBA, SIGNED_INT8):                                       return VK_FORMAT_R8G8B8A8_SINT;
242                 case FMT_CASE(sRGBA, UNORM_INT8):                                       return VK_FORMAT_R8G8B8A8_SRGB;
243
244                 case FMT_CASE(RGBA, UNORM_INT_1010102_REV):                     return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
245                 case FMT_CASE(RGBA, SNORM_INT_1010102_REV):                     return VK_FORMAT_A2B10G10R10_SNORM_PACK32;
246                 case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV):          return VK_FORMAT_A2B10G10R10_UINT_PACK32;
247                 case FMT_CASE(RGBA, SIGNED_INT_1010102_REV):            return VK_FORMAT_A2B10G10R10_SINT_PACK32;
248
249                 case FMT_CASE(R, UNORM_INT16):                                          return VK_FORMAT_R16_UNORM;
250                 case FMT_CASE(R, SNORM_INT16):                                          return VK_FORMAT_R16_SNORM;
251                 case FMT_CASE(R, UNSIGNED_INT16):                                       return VK_FORMAT_R16_UINT;
252                 case FMT_CASE(R, SIGNED_INT16):                                         return VK_FORMAT_R16_SINT;
253                 case FMT_CASE(R, HALF_FLOAT):                                           return VK_FORMAT_R16_SFLOAT;
254
255                 case FMT_CASE(RG, UNORM_INT16):                                         return VK_FORMAT_R16G16_UNORM;
256                 case FMT_CASE(RG, SNORM_INT16):                                         return VK_FORMAT_R16G16_SNORM;
257                 case FMT_CASE(RG, UNSIGNED_INT16):                                      return VK_FORMAT_R16G16_UINT;
258                 case FMT_CASE(RG, SIGNED_INT16):                                        return VK_FORMAT_R16G16_SINT;
259                 case FMT_CASE(RG, HALF_FLOAT):                                          return VK_FORMAT_R16G16_SFLOAT;
260
261                 case FMT_CASE(RGB, UNORM_INT16):                                        return VK_FORMAT_R16G16B16_UNORM;
262                 case FMT_CASE(RGB, SNORM_INT16):                                        return VK_FORMAT_R16G16B16_SNORM;
263                 case FMT_CASE(RGB, UNSIGNED_INT16):                                     return VK_FORMAT_R16G16B16_UINT;
264                 case FMT_CASE(RGB, SIGNED_INT16):                                       return VK_FORMAT_R16G16B16_SINT;
265                 case FMT_CASE(RGB, HALF_FLOAT):                                         return VK_FORMAT_R16G16B16_SFLOAT;
266
267                 case FMT_CASE(RGBA, UNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_UNORM;
268                 case FMT_CASE(RGBA, SNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_SNORM;
269                 case FMT_CASE(RGBA, UNSIGNED_INT16):                            return VK_FORMAT_R16G16B16A16_UINT;
270                 case FMT_CASE(RGBA, SIGNED_INT16):                                      return VK_FORMAT_R16G16B16A16_SINT;
271                 case FMT_CASE(RGBA, HALF_FLOAT):                                        return VK_FORMAT_R16G16B16A16_SFLOAT;
272
273                 case FMT_CASE(R, UNSIGNED_INT32):                                       return VK_FORMAT_R32_UINT;
274                 case FMT_CASE(R, SIGNED_INT32):                                         return VK_FORMAT_R32_SINT;
275                 case FMT_CASE(R, FLOAT):                                                        return VK_FORMAT_R32_SFLOAT;
276
277                 case FMT_CASE(RG, UNSIGNED_INT32):                                      return VK_FORMAT_R32G32_UINT;
278                 case FMT_CASE(RG, SIGNED_INT32):                                        return VK_FORMAT_R32G32_SINT;
279                 case FMT_CASE(RG, FLOAT):                                                       return VK_FORMAT_R32G32_SFLOAT;
280
281                 case FMT_CASE(RGB, UNSIGNED_INT32):                                     return VK_FORMAT_R32G32B32_UINT;
282                 case FMT_CASE(RGB, SIGNED_INT32):                                       return VK_FORMAT_R32G32B32_SINT;
283                 case FMT_CASE(RGB, FLOAT):                                                      return VK_FORMAT_R32G32B32_SFLOAT;
284
285                 case FMT_CASE(RGBA, UNSIGNED_INT32):                            return VK_FORMAT_R32G32B32A32_UINT;
286                 case FMT_CASE(RGBA, SIGNED_INT32):                                      return VK_FORMAT_R32G32B32A32_SINT;
287                 case FMT_CASE(RGBA, FLOAT):                                                     return VK_FORMAT_R32G32B32A32_SFLOAT;
288
289                 case FMT_CASE(R, FLOAT64):                                                      return VK_FORMAT_R64_SFLOAT;
290                 case FMT_CASE(RG, FLOAT64):                                                     return VK_FORMAT_R64G64_SFLOAT;
291                 case FMT_CASE(RGB, FLOAT64):                                            return VK_FORMAT_R64G64B64_SFLOAT;
292                 case FMT_CASE(RGBA, FLOAT64):                                           return VK_FORMAT_R64G64B64A64_SFLOAT;
293
294                 case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV):       return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
295                 case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV):            return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
296
297                 case FMT_CASE(BGR, UNORM_INT8):                                         return VK_FORMAT_B8G8R8_UNORM;
298                 case FMT_CASE(BGR, SNORM_INT8):                                         return VK_FORMAT_B8G8R8_SNORM;
299                 case FMT_CASE(BGR, UNSIGNED_INT8):                                      return VK_FORMAT_B8G8R8_UINT;
300                 case FMT_CASE(BGR, SIGNED_INT8):                                        return VK_FORMAT_B8G8R8_SINT;
301                 case FMT_CASE(sBGR, UNORM_INT8):                                        return VK_FORMAT_B8G8R8_SRGB;
302
303                 case FMT_CASE(BGRA, UNORM_INT8):                                        return VK_FORMAT_B8G8R8A8_UNORM;
304                 case FMT_CASE(BGRA, SNORM_INT8):                                        return VK_FORMAT_B8G8R8A8_SNORM;
305                 case FMT_CASE(BGRA, UNSIGNED_INT8):                                     return VK_FORMAT_B8G8R8A8_UINT;
306                 case FMT_CASE(BGRA, SIGNED_INT8):                                       return VK_FORMAT_B8G8R8A8_SINT;
307                 case FMT_CASE(sBGRA, UNORM_INT8):                                       return VK_FORMAT_B8G8R8A8_SRGB;
308
309                 case FMT_CASE(BGRA, UNORM_INT_1010102_REV):                     return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
310                 case FMT_CASE(BGRA, SNORM_INT_1010102_REV):                     return VK_FORMAT_A2R10G10B10_SNORM_PACK32;
311                 case FMT_CASE(BGRA, UNSIGNED_INT_1010102_REV):          return VK_FORMAT_A2R10G10B10_UINT_PACK32;
312                 case FMT_CASE(BGRA, SIGNED_INT_1010102_REV):            return VK_FORMAT_A2R10G10B10_SINT_PACK32;
313
314                 case FMT_CASE(D, UNORM_INT16):                                          return VK_FORMAT_D16_UNORM;
315                 case FMT_CASE(D, UNSIGNED_INT_24_8_REV):                        return VK_FORMAT_X8_D24_UNORM_PACK32;
316                 case FMT_CASE(D, FLOAT):                                                        return VK_FORMAT_D32_SFLOAT;
317
318                 case FMT_CASE(S, UNSIGNED_INT8):                                        return VK_FORMAT_S8_UINT;
319
320                 case FMT_CASE(DS, UNSIGNED_INT_16_8_8):                         return VK_FORMAT_D16_UNORM_S8_UINT;
321                 case FMT_CASE(DS, UNSIGNED_INT_24_8_REV):                       return VK_FORMAT_D24_UNORM_S8_UINT;
322                 case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV):         return VK_FORMAT_D32_SFLOAT_S8_UINT;
323
324                 default:
325                         TCU_THROW(InternalError, "Unknown texture format");
326         }
327
328 #undef PACK_FMT
329 #undef FMT_CASE
330 }
331
332 VkFormat mapCompressedTextureFormat (const tcu::CompressedTexFormat format)
333 {
334         // update this mapping if CompressedTexFormat changes
335         DE_STATIC_ASSERT(tcu::COMPRESSEDTEXFORMAT_LAST == 39);
336
337         switch (format)
338         {
339                 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8:                                                return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
340                 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8:                                               return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK;
341                 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:    return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
342                 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:   return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK;
343                 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8:                                   return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
344                 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8:                    return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK;
345
346                 case tcu::COMPRESSEDTEXFORMAT_EAC_R11:                                                  return VK_FORMAT_EAC_R11_UNORM_BLOCK;
347                 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11:                                   return VK_FORMAT_EAC_R11_SNORM_BLOCK;
348                 case tcu::COMPRESSEDTEXFORMAT_EAC_RG11:                                                 return VK_FORMAT_EAC_R11G11_UNORM_BLOCK;
349                 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11:                                  return VK_FORMAT_EAC_R11G11_SNORM_BLOCK;
350
351                 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA:                                    return VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
352                 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_4x4_SRGB_BLOCK;
353                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA:                                    return VK_FORMAT_ASTC_5x4_UNORM_BLOCK;
354                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_5x4_SRGB_BLOCK;
355                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA:                                    return VK_FORMAT_ASTC_5x5_UNORM_BLOCK;
356                 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_5x5_SRGB_BLOCK;
357                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA:                                    return VK_FORMAT_ASTC_6x5_UNORM_BLOCK;
358                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_6x5_SRGB_BLOCK;
359                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA:                                    return VK_FORMAT_ASTC_6x6_UNORM_BLOCK;
360                 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_6x6_SRGB_BLOCK;
361                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA:                                    return VK_FORMAT_ASTC_8x5_UNORM_BLOCK;
362                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x5_SRGB_BLOCK;
363                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA:                                    return VK_FORMAT_ASTC_8x6_UNORM_BLOCK;
364                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x6_SRGB_BLOCK;
365                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA:                                    return VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
366                 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8:                    return VK_FORMAT_ASTC_8x8_SRGB_BLOCK;
367                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA:                                   return VK_FORMAT_ASTC_10x5_UNORM_BLOCK;
368                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x5_SRGB_BLOCK;
369                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA:                                   return VK_FORMAT_ASTC_10x6_UNORM_BLOCK;
370                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x6_SRGB_BLOCK;
371                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA:                                   return VK_FORMAT_ASTC_10x8_UNORM_BLOCK;
372                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8:                   return VK_FORMAT_ASTC_10x8_SRGB_BLOCK;
373                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA:                                  return VK_FORMAT_ASTC_10x10_UNORM_BLOCK;
374                 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_10x10_SRGB_BLOCK;
375                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA:                                  return VK_FORMAT_ASTC_12x10_UNORM_BLOCK;
376                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_12x10_SRGB_BLOCK;
377                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA:                                  return VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
378                 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8:                  return VK_FORMAT_ASTC_12x12_SRGB_BLOCK;
379
380                 default:
381                         TCU_THROW(InternalError, "Unknown texture format");
382                         return VK_FORMAT_UNDEFINED;
383         }
384 }
385
386 tcu::TextureFormat mapVkFormat (VkFormat format)
387 {
388         using tcu::TextureFormat;
389
390         // update this mapping if VkFormat changes
391         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
392
393         switch (format)
394         {
395                 case VK_FORMAT_R4G4_UNORM_PACK8:                return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_BYTE_44);
396                 case VK_FORMAT_R5G6B5_UNORM_PACK16:             return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_SHORT_565);
397                 case VK_FORMAT_R4G4B4A4_UNORM_PACK16:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_4444);
398                 case VK_FORMAT_R5G5B5A1_UNORM_PACK16:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_5551);
399
400                 case VK_FORMAT_B5G6R5_UNORM_PACK16:             return TextureFormat(TextureFormat::BGR,        TextureFormat::UNORM_SHORT_565);
401                 case VK_FORMAT_B4G4R4A4_UNORM_PACK16:   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_4444);
402                 case VK_FORMAT_B5G5R5A1_UNORM_PACK16:   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_5551);
403
404                 case VK_FORMAT_A1R5G5B5_UNORM_PACK16:   return TextureFormat(TextureFormat::ARGB,       TextureFormat::UNORM_SHORT_1555);
405
406                 case VK_FORMAT_R8_UNORM:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT8);
407                 case VK_FORMAT_R8_SNORM:                                return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT8);
408                 case VK_FORMAT_R8_USCALED:                              return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT8);
409                 case VK_FORMAT_R8_SSCALED:                              return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT8);
410                 case VK_FORMAT_R8_UINT:                                 return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT8);
411                 case VK_FORMAT_R8_SINT:                                 return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT8);
412                 case VK_FORMAT_R8_SRGB:                                 return TextureFormat(TextureFormat::sR,         TextureFormat::UNORM_INT8);
413
414                 case VK_FORMAT_R8G8_UNORM:                              return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT8);
415                 case VK_FORMAT_R8G8_SNORM:                              return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT8);
416                 case VK_FORMAT_R8G8_USCALED:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT8);
417                 case VK_FORMAT_R8G8_SSCALED:                    return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT8);
418                 case VK_FORMAT_R8G8_UINT:                               return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT8);
419                 case VK_FORMAT_R8G8_SINT:                               return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT8);
420                 case VK_FORMAT_R8G8_SRGB:                               return TextureFormat(TextureFormat::sRG,        TextureFormat::UNORM_INT8);
421
422                 case VK_FORMAT_R8G8B8_UNORM:                    return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT8);
423                 case VK_FORMAT_R8G8B8_SNORM:                    return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT8);
424                 case VK_FORMAT_R8G8B8_USCALED:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT8);
425                 case VK_FORMAT_R8G8B8_SSCALED:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT8);
426                 case VK_FORMAT_R8G8B8_UINT:                             return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT8);
427                 case VK_FORMAT_R8G8B8_SINT:                             return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT8);
428                 case VK_FORMAT_R8G8B8_SRGB:                             return TextureFormat(TextureFormat::sRGB,       TextureFormat::UNORM_INT8);
429
430                 case VK_FORMAT_R8G8B8A8_UNORM:                  return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT8);
431                 case VK_FORMAT_R8G8B8A8_SNORM:                  return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT8);
432                 case VK_FORMAT_R8G8B8A8_USCALED:                return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
433                 case VK_FORMAT_R8G8B8A8_SSCALED:                return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
434                 case VK_FORMAT_R8G8B8A8_UINT:                   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
435                 case VK_FORMAT_R8G8B8A8_SINT:                   return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
436                 case VK_FORMAT_R8G8B8A8_SRGB:                   return TextureFormat(TextureFormat::sRGBA,      TextureFormat::UNORM_INT8);
437
438                 case VK_FORMAT_R16_UNORM:                               return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT16);
439                 case VK_FORMAT_R16_SNORM:                               return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT16);
440                 case VK_FORMAT_R16_USCALED:                             return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT16);
441                 case VK_FORMAT_R16_SSCALED:                             return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT16);
442                 case VK_FORMAT_R16_UINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT16);
443                 case VK_FORMAT_R16_SINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT16);
444                 case VK_FORMAT_R16_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::HALF_FLOAT);
445
446                 case VK_FORMAT_R16G16_UNORM:                    return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT16);
447                 case VK_FORMAT_R16G16_SNORM:                    return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT16);
448                 case VK_FORMAT_R16G16_USCALED:                  return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT16);
449                 case VK_FORMAT_R16G16_SSCALED:                  return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT16);
450                 case VK_FORMAT_R16G16_UINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT16);
451                 case VK_FORMAT_R16G16_SINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT16);
452                 case VK_FORMAT_R16G16_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::HALF_FLOAT);
453
454                 case VK_FORMAT_R16G16B16_UNORM:                 return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT16);
455                 case VK_FORMAT_R16G16B16_SNORM:                 return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT16);
456                 case VK_FORMAT_R16G16B16_USCALED:               return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT16);
457                 case VK_FORMAT_R16G16B16_SSCALED:               return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT16);
458                 case VK_FORMAT_R16G16B16_UINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT16);
459                 case VK_FORMAT_R16G16B16_SINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT16);
460                 case VK_FORMAT_R16G16B16_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::HALF_FLOAT);
461
462                 case VK_FORMAT_R16G16B16A16_UNORM:              return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT16);
463                 case VK_FORMAT_R16G16B16A16_SNORM:              return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT16);
464                 case VK_FORMAT_R16G16B16A16_USCALED:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT16);
465                 case VK_FORMAT_R16G16B16A16_SSCALED:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT16);
466                 case VK_FORMAT_R16G16B16A16_UINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT16);
467                 case VK_FORMAT_R16G16B16A16_SINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT16);
468                 case VK_FORMAT_R16G16B16A16_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::HALF_FLOAT);
469
470                 case VK_FORMAT_R32_UINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT32);
471                 case VK_FORMAT_R32_SINT:                                return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT32);
472                 case VK_FORMAT_R32_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::FLOAT);
473
474                 case VK_FORMAT_R32G32_UINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT32);
475                 case VK_FORMAT_R32G32_SINT:                             return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT32);
476                 case VK_FORMAT_R32G32_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::FLOAT);
477
478                 case VK_FORMAT_R32G32B32_UINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT32);
479                 case VK_FORMAT_R32G32B32_SINT:                  return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT32);
480                 case VK_FORMAT_R32G32B32_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::FLOAT);
481
482                 case VK_FORMAT_R32G32B32A32_UINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT32);
483                 case VK_FORMAT_R32G32B32A32_SINT:               return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT32);
484                 case VK_FORMAT_R32G32B32A32_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::FLOAT);
485
486                 case VK_FORMAT_R64_SFLOAT:                              return TextureFormat(TextureFormat::R,          TextureFormat::FLOAT64);
487                 case VK_FORMAT_R64G64_SFLOAT:                   return TextureFormat(TextureFormat::RG,         TextureFormat::FLOAT64);
488                 case VK_FORMAT_R64G64B64_SFLOAT:                return TextureFormat(TextureFormat::RGB,        TextureFormat::FLOAT64);
489                 case VK_FORMAT_R64G64B64A64_SFLOAT:             return TextureFormat(TextureFormat::RGBA,       TextureFormat::FLOAT64);
490
491                 case VK_FORMAT_B10G11R11_UFLOAT_PACK32: return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
492                 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:  return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_999_E5_REV);
493
494                 case VK_FORMAT_B8G8R8_UNORM:                    return TextureFormat(TextureFormat::BGR,        TextureFormat::UNORM_INT8);
495                 case VK_FORMAT_B8G8R8_SNORM:                    return TextureFormat(TextureFormat::BGR,        TextureFormat::SNORM_INT8);
496                 case VK_FORMAT_B8G8R8_USCALED:                  return TextureFormat(TextureFormat::BGR,        TextureFormat::UNSIGNED_INT8);
497                 case VK_FORMAT_B8G8R8_SSCALED:                  return TextureFormat(TextureFormat::BGR,        TextureFormat::SIGNED_INT8);
498                 case VK_FORMAT_B8G8R8_UINT:                             return TextureFormat(TextureFormat::BGR,        TextureFormat::UNSIGNED_INT8);
499                 case VK_FORMAT_B8G8R8_SINT:                             return TextureFormat(TextureFormat::BGR,        TextureFormat::SIGNED_INT8);
500                 case VK_FORMAT_B8G8R8_SRGB:                             return TextureFormat(TextureFormat::sBGR,       TextureFormat::UNORM_INT8);
501
502                 case VK_FORMAT_B8G8R8A8_UNORM:                  return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_INT8);
503                 case VK_FORMAT_B8G8R8A8_SNORM:                  return TextureFormat(TextureFormat::BGRA,       TextureFormat::SNORM_INT8);
504                 case VK_FORMAT_B8G8R8A8_USCALED:                return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT8);
505                 case VK_FORMAT_B8G8R8A8_SSCALED:                return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT8);
506                 case VK_FORMAT_B8G8R8A8_UINT:                   return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT8);
507                 case VK_FORMAT_B8G8R8A8_SINT:                   return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT8);
508                 case VK_FORMAT_B8G8R8A8_SRGB:                   return TextureFormat(TextureFormat::sBGRA,      TextureFormat::UNORM_INT8);
509
510                 case VK_FORMAT_D16_UNORM:                               return TextureFormat(TextureFormat::D,          TextureFormat::UNORM_INT16);
511                 case VK_FORMAT_X8_D24_UNORM_PACK32:             return TextureFormat(TextureFormat::D,          TextureFormat::UNSIGNED_INT_24_8_REV);
512                 case VK_FORMAT_D32_SFLOAT:                              return TextureFormat(TextureFormat::D,          TextureFormat::FLOAT);
513
514                 case VK_FORMAT_S8_UINT:                                 return TextureFormat(TextureFormat::S,          TextureFormat::UNSIGNED_INT8);
515
516                 // \note There is no standard interleaved memory layout for DS formats; buffer-image copies
517                 //               will always operate on either D or S aspect only. See Khronos bug 12998
518                 case VK_FORMAT_D16_UNORM_S8_UINT:               return TextureFormat(TextureFormat::DS,         TextureFormat::UNSIGNED_INT_16_8_8);
519                 case VK_FORMAT_D24_UNORM_S8_UINT:               return TextureFormat(TextureFormat::DS,         TextureFormat::UNSIGNED_INT_24_8_REV);
520                 case VK_FORMAT_D32_SFLOAT_S8_UINT:              return TextureFormat(TextureFormat::DS,         TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
521
522 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
523                 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT8);
524                 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:   return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT8);
525                 case VK_FORMAT_A8B8G8R8_USCALED_PACK32: return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
526                 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
527                 case VK_FORMAT_A8B8G8R8_UINT_PACK32:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
528                 case VK_FORMAT_A8B8G8R8_SINT_PACK32:    return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
529                 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:    return TextureFormat(TextureFormat::sRGBA,      TextureFormat::UNORM_INT8);
530 #else
531 #       error "Big-endian not supported"
532 #endif
533
534                 case VK_FORMAT_A2R10G10B10_UNORM_PACK32:        return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_INT_1010102_REV);
535                 case VK_FORMAT_A2R10G10B10_SNORM_PACK32:        return TextureFormat(TextureFormat::BGRA,       TextureFormat::SNORM_INT_1010102_REV);
536                 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:      return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT_1010102_REV);
537                 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:      return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT_1010102_REV);
538                 case VK_FORMAT_A2R10G10B10_UINT_PACK32:         return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNSIGNED_INT_1010102_REV);
539                 case VK_FORMAT_A2R10G10B10_SINT_PACK32:         return TextureFormat(TextureFormat::BGRA,       TextureFormat::SIGNED_INT_1010102_REV);
540
541                 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:        return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT_1010102_REV);
542                 case VK_FORMAT_A2B10G10R10_SNORM_PACK32:        return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT_1010102_REV);
543                 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT_1010102_REV);
544                 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT_1010102_REV);
545                 case VK_FORMAT_A2B10G10R10_UINT_PACK32:         return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT_1010102_REV);
546                 case VK_FORMAT_A2B10G10R10_SINT_PACK32:         return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT_1010102_REV);
547
548                 default:
549                         TCU_THROW(InternalError, "Unknown image format");
550         }
551 }
552
553 tcu::CompressedTexFormat mapVkCompressedFormat (VkFormat format)
554 {
555         // update this mapping if VkFormat changes
556         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
557
558         switch (format)
559         {
560                 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:         return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
561                 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
562                 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:       return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
563                 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:        return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
564                 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:       return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
565                 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:        return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
566
567                 case VK_FORMAT_EAC_R11_UNORM_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
568                 case VK_FORMAT_EAC_R11_SNORM_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
569                 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
570                 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
571
572                 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
573                 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
574                 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
575                 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8;
576                 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
577                 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
578                 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
579                 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
580                 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
581                 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
582                 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
583                 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8;
584                 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
585                 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
586                 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
587                 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:                     return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
588                 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
589                 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
590                 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
591                 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
592                 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
593                 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:            return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
594                 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
595                 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
596                 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
597                 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
598                 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:          return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
599                 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:           return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
600
601                 default:
602                         TCU_THROW(InternalError, "Unknown image format");
603                         return tcu::COMPRESSEDTEXFORMAT_LAST;
604         }
605 }
606
607 static bool isScaledFormat (VkFormat format)
608 {
609         // update this mapping if VkFormat changes
610         DE_STATIC_ASSERT(VK_CORE_FORMAT_LAST == 185);
611
612         switch (format)
613         {
614                 case VK_FORMAT_R8_USCALED:
615                 case VK_FORMAT_R8_SSCALED:
616                 case VK_FORMAT_R8G8_USCALED:
617                 case VK_FORMAT_R8G8_SSCALED:
618                 case VK_FORMAT_R8G8B8_USCALED:
619                 case VK_FORMAT_R8G8B8_SSCALED:
620                 case VK_FORMAT_R8G8B8A8_USCALED:
621                 case VK_FORMAT_R8G8B8A8_SSCALED:
622                 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
623                 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
624                 case VK_FORMAT_R16_USCALED:
625                 case VK_FORMAT_R16_SSCALED:
626                 case VK_FORMAT_R16G16_USCALED:
627                 case VK_FORMAT_R16G16_SSCALED:
628                 case VK_FORMAT_R16G16B16_USCALED:
629                 case VK_FORMAT_R16G16B16_SSCALED:
630                 case VK_FORMAT_R16G16B16A16_USCALED:
631                 case VK_FORMAT_R16G16B16A16_SSCALED:
632                 case VK_FORMAT_B8G8R8_USCALED:
633                 case VK_FORMAT_B8G8R8_SSCALED:
634                 case VK_FORMAT_B8G8R8A8_USCALED:
635                 case VK_FORMAT_B8G8R8A8_SSCALED:
636                 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
637                 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
638                         return true;
639
640                 default:
641                         return false;
642         }
643 }
644
645 static bool fullTextureFormatRoundTripSupported (VkFormat format)
646 {
647         if (isScaledFormat(format))
648         {
649                 // *SCALED formats get mapped to correspoding (u)int formats since
650                 // accessing them through (float) getPixel/setPixel has same behavior
651                 // as in shader access in Vulkan.
652                 // Unfortunately full round-trip between tcu::TextureFormat and VkFormat
653                 // for most SCALED formats is not supported though.
654
655                 const tcu::TextureFormat        tcuFormat       = mapVkFormat(format);
656
657                 switch (tcuFormat.type)
658                 {
659                         case tcu::TextureFormat::UNSIGNED_INT8:
660                         case tcu::TextureFormat::UNSIGNED_INT16:
661                         case tcu::TextureFormat::UNSIGNED_INT32:
662                         case tcu::TextureFormat::SIGNED_INT8:
663                         case tcu::TextureFormat::SIGNED_INT16:
664                         case tcu::TextureFormat::SIGNED_INT32:
665                         case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
666                         case tcu::TextureFormat::SIGNED_INT_1010102_REV:
667                                 return false;
668
669                         default:
670                                 return true;
671                 }
672         }
673         else
674         {
675                 switch (format)
676                 {
677                         case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
678                         case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
679                         case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
680                         case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
681                         case VK_FORMAT_A8B8G8R8_UINT_PACK32:
682                         case VK_FORMAT_A8B8G8R8_SINT_PACK32:
683                         case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
684                                 return false; // These map to regular byte array formats
685
686                         default:
687                                 break;
688                 }
689
690                 return (format != VK_FORMAT_UNDEFINED);
691         }
692 }
693
694 void imageUtilSelfTest (void)
695 {
696         for (int formatNdx = 0; formatNdx < VK_CORE_FORMAT_LAST; formatNdx++)
697         {
698                 const VkFormat  format  = (VkFormat)formatNdx;
699
700                 if (format == VK_FORMAT_R64_UINT                        ||
701                         format == VK_FORMAT_R64_SINT                    ||
702                         format == VK_FORMAT_R64G64_UINT                 ||
703                         format == VK_FORMAT_R64G64_SINT                 ||
704                         format == VK_FORMAT_R64G64B64_UINT              ||
705                         format == VK_FORMAT_R64G64B64_SINT              ||
706                         format == VK_FORMAT_R64G64B64A64_UINT   ||
707                         format == VK_FORMAT_R64G64B64A64_SINT)
708                         continue; // \todo [2015-12-05 pyry] Add framework support for (u)int64 channel type
709
710                 if (format != VK_FORMAT_UNDEFINED && !isCompressedFormat(format))
711                 {
712                         const tcu::TextureFormat        tcuFormat               = mapVkFormat(format);
713                         const VkFormat                          remappedFormat  = mapTextureFormat(tcuFormat);
714
715                         DE_TEST_ASSERT(isValid(tcuFormat));
716
717                         if (fullTextureFormatRoundTripSupported(format))
718                                 DE_TEST_ASSERT(format == remappedFormat);
719                 }
720         }
721 }
722
723 VkFilter mapFilterMode (tcu::Sampler::FilterMode filterMode)
724 {
725         DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
726
727         switch (filterMode)
728         {
729                 case tcu::Sampler::NEAREST:                                     return VK_FILTER_NEAREST;
730                 case tcu::Sampler::LINEAR:                                      return VK_FILTER_LINEAR;
731                 case tcu::Sampler::NEAREST_MIPMAP_NEAREST:      return VK_FILTER_NEAREST;
732                 case tcu::Sampler::NEAREST_MIPMAP_LINEAR:       return VK_FILTER_NEAREST;
733                 case tcu::Sampler::LINEAR_MIPMAP_NEAREST:       return VK_FILTER_LINEAR;
734                 case tcu::Sampler::LINEAR_MIPMAP_LINEAR:        return VK_FILTER_LINEAR;
735                 default:
736                         DE_FATAL("Illegal filter mode");
737                         return (VkFilter)0;
738         }
739 }
740
741 VkSamplerMipmapMode mapMipmapMode (tcu::Sampler::FilterMode filterMode)
742 {
743         DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
744
745         // \note VkSamplerCreateInfo doesn't have a flag for disabling mipmapping. Instead
746         //               minLod = 0 and maxLod = 0.25 should be used to match OpenGL NEAREST and LINEAR
747         //               filtering mode behavior.
748
749         switch (filterMode)
750         {
751                 case tcu::Sampler::NEAREST:                                     return VK_SAMPLER_MIPMAP_MODE_NEAREST;
752                 case tcu::Sampler::LINEAR:                                      return VK_SAMPLER_MIPMAP_MODE_NEAREST;
753                 case tcu::Sampler::NEAREST_MIPMAP_NEAREST:      return VK_SAMPLER_MIPMAP_MODE_NEAREST;
754                 case tcu::Sampler::NEAREST_MIPMAP_LINEAR:       return VK_SAMPLER_MIPMAP_MODE_LINEAR;
755                 case tcu::Sampler::LINEAR_MIPMAP_NEAREST:       return VK_SAMPLER_MIPMAP_MODE_NEAREST;
756                 case tcu::Sampler::LINEAR_MIPMAP_LINEAR:        return VK_SAMPLER_MIPMAP_MODE_LINEAR;
757                 default:
758                         DE_FATAL("Illegal filter mode");
759                         return (VkSamplerMipmapMode)0;
760         }
761 }
762
763 VkSamplerAddressMode mapWrapMode (tcu::Sampler::WrapMode wrapMode)
764 {
765         switch (wrapMode)
766         {
767                 case tcu::Sampler::CLAMP_TO_EDGE:               return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
768                 case tcu::Sampler::CLAMP_TO_BORDER:             return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
769                 case tcu::Sampler::REPEAT_GL:                   return VK_SAMPLER_ADDRESS_MODE_REPEAT;
770                 case tcu::Sampler::MIRRORED_REPEAT_GL:  return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
771                 case tcu::Sampler::MIRRORED_ONCE:               return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
772                 default:
773                         DE_FATAL("Wrap mode can't be mapped to Vulkan");
774                         return (vk::VkSamplerAddressMode)0;
775         }
776 }
777
778 vk::VkCompareOp mapCompareMode (tcu::Sampler::CompareMode mode)
779 {
780         switch (mode)
781         {
782                 case tcu::Sampler::COMPAREMODE_NONE:                            return vk::VK_COMPARE_OP_NEVER;
783                 case tcu::Sampler::COMPAREMODE_LESS:                            return vk::VK_COMPARE_OP_LESS;
784                 case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:           return vk::VK_COMPARE_OP_LESS_OR_EQUAL;
785                 case tcu::Sampler::COMPAREMODE_GREATER:                         return vk::VK_COMPARE_OP_GREATER;
786                 case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:        return vk::VK_COMPARE_OP_GREATER_OR_EQUAL;
787                 case tcu::Sampler::COMPAREMODE_EQUAL:                           return vk::VK_COMPARE_OP_EQUAL;
788                 case tcu::Sampler::COMPAREMODE_NOT_EQUAL:                       return vk::VK_COMPARE_OP_NOT_EQUAL;
789                 case tcu::Sampler::COMPAREMODE_ALWAYS:                          return vk::VK_COMPARE_OP_ALWAYS;
790                 case tcu::Sampler::COMPAREMODE_NEVER:                           return vk::VK_COMPARE_OP_NEVER;
791                 default:
792                         DE_FATAL("Illegal compare mode");
793                         return (vk::VkCompareOp)0;
794         }
795 }
796
797 static VkBorderColor mapBorderColor (tcu::TextureChannelClass channelClass, const rr::GenericVec4& color)
798 {
799         if (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
800         {
801                 const tcu::UVec4        uColor  = color.get<deUint32>();
802
803                 if (uColor              == tcu::UVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
804                 else if (uColor == tcu::UVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
805                 else if (uColor == tcu::UVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
806         }
807         else if (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
808         {
809                 const tcu::IVec4        sColor  = color.get<deInt32>();
810
811                 if (sColor              == tcu::IVec4(0, 0, 0, 0)) return VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
812                 else if (sColor == tcu::IVec4(0, 0, 0, 1)) return VK_BORDER_COLOR_INT_OPAQUE_BLACK;
813                 else if (sColor == tcu::IVec4(1, 1, 1, 1)) return VK_BORDER_COLOR_INT_OPAQUE_WHITE;
814         }
815         else
816         {
817                 const tcu::Vec4         fColor  = color.get<float>();
818
819                 if (fColor              == tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f)) return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
820                 else if (fColor == tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
821                 else if (fColor == tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)) return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
822         }
823
824         DE_FATAL("Unsupported border color");
825         return VK_BORDER_COLOR_LAST;
826 }
827
828 VkSamplerCreateInfo mapSampler (const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod, float maxLod)
829 {
830         const bool                                      compareEnabled  = (sampler.compare != tcu::Sampler::COMPAREMODE_NONE);
831         const VkCompareOp                       compareOp               = (compareEnabled) ? (mapCompareMode(sampler.compare)) : (VK_COMPARE_OP_ALWAYS);
832         const VkBorderColor                     borderColor             = mapBorderColor(getTextureChannelClass(format.type), sampler.borderColor);
833         const bool                                      isMipmapEnabled = (sampler.minFilter != tcu::Sampler::NEAREST && sampler.minFilter != tcu::Sampler::LINEAR);
834
835         const VkSamplerCreateInfo       createInfo              =
836         {
837                 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
838                 DE_NULL,
839                 (VkSamplerCreateFlags)0,
840                 mapFilterMode(sampler.magFilter),                                                       // magFilter
841                 mapFilterMode(sampler.minFilter),                                                       // minFilter
842                 mapMipmapMode(sampler.minFilter),                                                       // mipMode
843                 mapWrapMode(sampler.wrapS),                                                                     // addressU
844                 mapWrapMode(sampler.wrapT),                                                                     // addressV
845                 mapWrapMode(sampler.wrapR),                                                                     // addressW
846                 0.0f,                                                                                                           // mipLodBias
847                 VK_FALSE,                                                                                                       // anisotropyEnable
848                 1.0f,                                                                                                           // maxAnisotropy
849                 (VkBool32)(compareEnabled ? VK_TRUE : VK_FALSE),                        // compareEnable
850                 compareOp,                                                                                                      // compareOp
851                 (isMipmapEnabled ? minLod : 0.0f),                                                      // minLod
852                 (isMipmapEnabled ? maxLod : 0.25f),                                                     // maxLod
853                 borderColor,                                                                                            // borderColor
854                 (VkBool32)(sampler.normalizedCoords ? VK_FALSE : VK_TRUE),      // unnormalizedCoords
855         };
856
857         return createInfo;
858 }
859
860 tcu::Sampler mapVkSampler (const VkSamplerCreateInfo& samplerCreateInfo)
861 {
862         // \note minLod & maxLod are not supported by tcu::Sampler. LOD must be clamped
863         //       before passing it to tcu::Texture*::sample*()
864
865         tcu::Sampler sampler(mapVkSamplerAddressMode(samplerCreateInfo.addressModeU),
866                                                  mapVkSamplerAddressMode(samplerCreateInfo.addressModeV),
867                                                  mapVkSamplerAddressMode(samplerCreateInfo.addressModeW),
868                                                  mapVkMinTexFilter(samplerCreateInfo.minFilter, samplerCreateInfo.mipmapMode),
869                                                  mapVkMagTexFilter(samplerCreateInfo.magFilter),
870                                                  0.0f,
871                                                  !samplerCreateInfo.unnormalizedCoordinates,
872                                                  samplerCreateInfo.compareEnable ? mapVkSamplerCompareOp(samplerCreateInfo.compareOp)
873                                                                                                                  : tcu::Sampler::COMPAREMODE_NONE,
874                                                  0,
875                                                  tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
876                                                  true);
877
878         if (samplerCreateInfo.anisotropyEnable)
879                 TCU_THROW(InternalError, "Anisotropic filtering is not supported by tcu::Sampler");
880
881         switch (samplerCreateInfo.borderColor)
882         {
883                 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
884                         sampler.borderColor = tcu::UVec4(0,0,0,1);
885                         break;
886                 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
887                         sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
888                         break;
889                 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
890                         sampler.borderColor = tcu::UVec4(1, 1, 1, 1);
891                         break;
892                 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
893                         sampler.borderColor = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
894                         break;
895                 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
896                         sampler.borderColor = tcu::UVec4(0,0,0,0);
897                         break;
898                 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
899                         sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
900                         break;
901
902                 default:
903                         DE_ASSERT(false);
904                         break;
905         }
906
907         return sampler;
908 }
909
910 tcu::Sampler::CompareMode mapVkSamplerCompareOp (VkCompareOp compareOp)
911 {
912         switch (compareOp)
913         {
914                 case VK_COMPARE_OP_NEVER:                               return tcu::Sampler::COMPAREMODE_NEVER;
915                 case VK_COMPARE_OP_LESS:                                return tcu::Sampler::COMPAREMODE_LESS;
916                 case VK_COMPARE_OP_EQUAL:                               return tcu::Sampler::COMPAREMODE_EQUAL;
917                 case VK_COMPARE_OP_LESS_OR_EQUAL:               return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
918                 case VK_COMPARE_OP_GREATER:                             return tcu::Sampler::COMPAREMODE_GREATER;
919                 case VK_COMPARE_OP_NOT_EQUAL:                   return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
920                 case VK_COMPARE_OP_GREATER_OR_EQUAL:    return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
921                 case VK_COMPARE_OP_ALWAYS:                              return tcu::Sampler::COMPAREMODE_ALWAYS;
922                 default:
923                         break;
924         }
925
926         DE_ASSERT(false);
927         return tcu::Sampler::COMPAREMODE_LAST;
928 }
929
930 tcu::Sampler::WrapMode mapVkSamplerAddressMode (VkSamplerAddressMode addressMode)
931 {
932         switch (addressMode)
933         {
934                 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:                     return tcu::Sampler::CLAMP_TO_EDGE;
935                 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:           return tcu::Sampler::CLAMP_TO_BORDER;
936                 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:           return tcu::Sampler::MIRRORED_REPEAT_GL;
937                 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:      return tcu::Sampler::MIRRORED_ONCE;
938                 case VK_SAMPLER_ADDRESS_MODE_REPEAT:                            return tcu::Sampler::REPEAT_GL;
939                 default:
940                         break;
941         }
942
943         DE_ASSERT(false);
944         return tcu::Sampler::WRAPMODE_LAST;
945 }
946
947 tcu::Sampler::FilterMode mapVkMinTexFilter (VkFilter filter, VkSamplerMipmapMode mipMode)
948 {
949         switch (filter)
950         {
951                 case VK_FILTER_LINEAR:
952                         switch (mipMode)
953                         {
954                                 case VK_SAMPLER_MIPMAP_MODE_LINEAR:             return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
955                                 case VK_SAMPLER_MIPMAP_MODE_NEAREST:    return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
956                                 default:
957                                         break;
958                         }
959                         break;
960
961                 case VK_FILTER_NEAREST:
962                         switch (mipMode)
963                         {
964                                 case VK_SAMPLER_MIPMAP_MODE_LINEAR:             return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
965                                 case VK_SAMPLER_MIPMAP_MODE_NEAREST:    return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
966                                 default:
967                                         break;
968                         }
969                         break;
970
971                 default:
972                         break;
973         }
974
975         DE_ASSERT(false);
976         return tcu::Sampler::FILTERMODE_LAST;
977 }
978
979 tcu::Sampler::FilterMode mapVkMagTexFilter (VkFilter filter)
980 {
981         switch (filter)
982         {
983                 case VK_FILTER_LINEAR:          return tcu::Sampler::LINEAR;
984                 case VK_FILTER_NEAREST:         return tcu::Sampler::NEAREST;
985                 default:
986                         break;
987         }
988
989         DE_ASSERT(false);
990         return tcu::Sampler::FILTERMODE_LAST;
991 }
992
993 //! Get a format the matches the layout in buffer memory used for a
994 //! buffer<->image copy on a depth/stencil format.
995 tcu::TextureFormat getDepthCopyFormat (VkFormat combinedFormat)
996 {
997         switch (combinedFormat)
998         {
999                 case VK_FORMAT_D16_UNORM:
1000                 case VK_FORMAT_X8_D24_UNORM_PACK32:
1001                 case VK_FORMAT_D32_SFLOAT:
1002                         return mapVkFormat(combinedFormat);
1003
1004                 case VK_FORMAT_D16_UNORM_S8_UINT:
1005                         return mapVkFormat(VK_FORMAT_D16_UNORM);
1006                 case VK_FORMAT_D24_UNORM_S8_UINT:
1007                         return mapVkFormat(VK_FORMAT_X8_D24_UNORM_PACK32);
1008                 case VK_FORMAT_D32_SFLOAT_S8_UINT:
1009                         return mapVkFormat(VK_FORMAT_D32_SFLOAT);
1010
1011                 case VK_FORMAT_S8_UINT:
1012                 default:
1013                         DE_FATAL("Unexpected depth/stencil format");
1014                         return tcu::TextureFormat();
1015         }
1016 }
1017
1018 //! Get a format the matches the layout in buffer memory used for a
1019 //! buffer<->image copy on a depth/stencil format.
1020 tcu::TextureFormat getStencilCopyFormat (VkFormat combinedFormat)
1021 {
1022         switch (combinedFormat)
1023         {
1024                 case VK_FORMAT_D16_UNORM_S8_UINT:
1025                 case VK_FORMAT_D24_UNORM_S8_UINT:
1026                 case VK_FORMAT_D32_SFLOAT_S8_UINT:
1027                 case VK_FORMAT_S8_UINT:
1028                         return mapVkFormat(VK_FORMAT_S8_UINT);
1029
1030                 case VK_FORMAT_D16_UNORM:
1031                 case VK_FORMAT_X8_D24_UNORM_PACK32:
1032                 case VK_FORMAT_D32_SFLOAT:
1033                 default:
1034                         DE_FATAL("Unexpected depth/stencil format");
1035                         return tcu::TextureFormat();
1036         }
1037 }
1038
1039 } // vk