1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
7 * Copyright (c) 2015 Google Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and/or associated documentation files (the
11 * "Materials"), to deal in the Materials without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Materials, and to
14 * permit persons to whom the Materials are furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice(s) and this permission notice shall be
18 * included in all copies or substantial portions of the Materials.
20 * The Materials are Confidential Information as defined by the
21 * Khronos Membership Agreement until designated non-confidential by
22 * Khronos, at which point this condition clause shall be removed.
24 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
34 * \brief Utilities for images.
35 *//*--------------------------------------------------------------------*/
37 #include "vkImageUtil.hpp"
38 #include "tcuTextureUtil.hpp"
43 bool isFloatFormat (VkFormat format)
45 return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
48 bool isUnormFormat (VkFormat format)
50 return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
53 bool isSnormFormat (VkFormat format)
55 return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT;
58 bool isIntFormat (VkFormat format)
60 return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER;
63 bool isUintFormat (VkFormat format)
65 return tcu::getTextureChannelClass(mapVkFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
68 bool isDepthStencilFormat (VkFormat format)
70 if (isCompressedFormat(format))
73 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
74 return tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS;
77 bool isCompressedFormat (VkFormat format)
79 // update this mapping if VkFormat changes
80 DE_STATIC_ASSERT(VK_FORMAT_LAST == 185);
84 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
85 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
86 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
87 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
88 case VK_FORMAT_BC2_UNORM_BLOCK:
89 case VK_FORMAT_BC2_SRGB_BLOCK:
90 case VK_FORMAT_BC3_UNORM_BLOCK:
91 case VK_FORMAT_BC3_SRGB_BLOCK:
92 case VK_FORMAT_BC4_UNORM_BLOCK:
93 case VK_FORMAT_BC4_SNORM_BLOCK:
94 case VK_FORMAT_BC5_UNORM_BLOCK:
95 case VK_FORMAT_BC5_SNORM_BLOCK:
96 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
97 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
98 case VK_FORMAT_BC7_UNORM_BLOCK:
99 case VK_FORMAT_BC7_SRGB_BLOCK:
100 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
101 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
102 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
103 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
104 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
105 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
106 case VK_FORMAT_EAC_R11_UNORM_BLOCK:
107 case VK_FORMAT_EAC_R11_SNORM_BLOCK:
108 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
109 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
110 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
111 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
112 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
113 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
114 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
115 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
116 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
117 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
118 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
119 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
120 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
121 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
122 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
123 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
124 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
125 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
126 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
127 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
128 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
129 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
130 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
131 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
132 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
133 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
134 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
135 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
136 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
137 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
145 VkFormat mapTextureFormat (const tcu::TextureFormat& format)
147 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
148 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
150 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
151 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
153 // update this mapping if VkFormat changes
154 DE_STATIC_ASSERT(VK_FORMAT_LAST == 185);
156 switch (PACK_FMT(format.order, format.type))
158 case FMT_CASE(RG, UNORM_BYTE_44): return VK_FORMAT_R4G4_UNORM_PACK8;
159 case FMT_CASE(RGB, UNORM_SHORT_565): return VK_FORMAT_R5G6B5_UNORM_PACK16;
160 case FMT_CASE(RGBA, UNORM_SHORT_4444): return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
161 case FMT_CASE(RGBA, UNORM_SHORT_5551): return VK_FORMAT_R5G5B5A1_UNORM_PACK16;
163 case FMT_CASE(BGR, UNORM_SHORT_565): return VK_FORMAT_B5G6R5_UNORM_PACK16;
164 case FMT_CASE(BGRA, UNORM_SHORT_4444): return VK_FORMAT_B4G4R4A4_UNORM_PACK16;
165 case FMT_CASE(BGRA, UNORM_SHORT_5551): return VK_FORMAT_B5G5R5A1_UNORM_PACK16;
167 case FMT_CASE(ARGB, UNORM_SHORT_1555): return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
169 case FMT_CASE(R, UNORM_INT8): return VK_FORMAT_R8_UNORM;
170 case FMT_CASE(R, SNORM_INT8): return VK_FORMAT_R8_SNORM;
171 case FMT_CASE(R, UNSIGNED_INT8): return VK_FORMAT_R8_UINT;
172 case FMT_CASE(R, SIGNED_INT8): return VK_FORMAT_R8_SINT;
173 case FMT_CASE(sR, UNORM_INT8): return VK_FORMAT_R8_SRGB;
175 case FMT_CASE(RG, UNORM_INT8): return VK_FORMAT_R8G8_UNORM;
176 case FMT_CASE(RG, SNORM_INT8): return VK_FORMAT_R8G8_SNORM;
177 case FMT_CASE(RG, UNSIGNED_INT8): return VK_FORMAT_R8G8_UINT;
178 case FMT_CASE(RG, SIGNED_INT8): return VK_FORMAT_R8G8_SINT;
179 case FMT_CASE(sRG, UNORM_INT8): return VK_FORMAT_R8G8_SRGB;
181 case FMT_CASE(RGB, UNORM_INT8): return VK_FORMAT_R8G8B8_UNORM;
182 case FMT_CASE(RGB, SNORM_INT8): return VK_FORMAT_R8G8B8_SNORM;
183 case FMT_CASE(RGB, UNSIGNED_INT8): return VK_FORMAT_R8G8B8_UINT;
184 case FMT_CASE(RGB, SIGNED_INT8): return VK_FORMAT_R8G8B8_SINT;
185 case FMT_CASE(sRGB, UNORM_INT8): return VK_FORMAT_R8G8B8_SRGB;
187 case FMT_CASE(RGBA, UNORM_INT8): return VK_FORMAT_R8G8B8A8_UNORM;
188 case FMT_CASE(RGBA, SNORM_INT8): return VK_FORMAT_R8G8B8A8_SNORM;
189 case FMT_CASE(RGBA, UNSIGNED_INT8): return VK_FORMAT_R8G8B8A8_UINT;
190 case FMT_CASE(RGBA, SIGNED_INT8): return VK_FORMAT_R8G8B8A8_SINT;
191 case FMT_CASE(sRGBA, UNORM_INT8): return VK_FORMAT_R8G8B8A8_SRGB;
193 case FMT_CASE(RGBA, UNORM_INT_1010102_REV): return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
194 case FMT_CASE(RGBA, SNORM_INT_1010102_REV): return VK_FORMAT_A2B10G10R10_SNORM_PACK32;
195 case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV): return VK_FORMAT_A2B10G10R10_UINT_PACK32;
196 case FMT_CASE(RGBA, SIGNED_INT_1010102_REV): return VK_FORMAT_A2B10G10R10_SINT_PACK32;
198 case FMT_CASE(R, UNORM_INT16): return VK_FORMAT_R16_UNORM;
199 case FMT_CASE(R, SNORM_INT16): return VK_FORMAT_R16_SNORM;
200 case FMT_CASE(R, UNSIGNED_INT16): return VK_FORMAT_R16_UINT;
201 case FMT_CASE(R, SIGNED_INT16): return VK_FORMAT_R16_SINT;
202 case FMT_CASE(R, HALF_FLOAT): return VK_FORMAT_R16_SFLOAT;
204 case FMT_CASE(RG, UNORM_INT16): return VK_FORMAT_R16G16_UNORM;
205 case FMT_CASE(RG, SNORM_INT16): return VK_FORMAT_R16G16_SNORM;
206 case FMT_CASE(RG, UNSIGNED_INT16): return VK_FORMAT_R16G16_UINT;
207 case FMT_CASE(RG, SIGNED_INT16): return VK_FORMAT_R16G16_SINT;
208 case FMT_CASE(RG, HALF_FLOAT): return VK_FORMAT_R16G16_SFLOAT;
210 case FMT_CASE(RGB, UNORM_INT16): return VK_FORMAT_R16G16B16_UNORM;
211 case FMT_CASE(RGB, SNORM_INT16): return VK_FORMAT_R16G16B16_SNORM;
212 case FMT_CASE(RGB, UNSIGNED_INT16): return VK_FORMAT_R16G16B16_UINT;
213 case FMT_CASE(RGB, SIGNED_INT16): return VK_FORMAT_R16G16B16_SINT;
214 case FMT_CASE(RGB, HALF_FLOAT): return VK_FORMAT_R16G16B16_SFLOAT;
216 case FMT_CASE(RGBA, UNORM_INT16): return VK_FORMAT_R16G16B16A16_UNORM;
217 case FMT_CASE(RGBA, SNORM_INT16): return VK_FORMAT_R16G16B16A16_SNORM;
218 case FMT_CASE(RGBA, UNSIGNED_INT16): return VK_FORMAT_R16G16B16A16_UINT;
219 case FMT_CASE(RGBA, SIGNED_INT16): return VK_FORMAT_R16G16B16A16_SINT;
220 case FMT_CASE(RGBA, HALF_FLOAT): return VK_FORMAT_R16G16B16A16_SFLOAT;
222 case FMT_CASE(R, UNSIGNED_INT32): return VK_FORMAT_R32_UINT;
223 case FMT_CASE(R, SIGNED_INT32): return VK_FORMAT_R32_SINT;
224 case FMT_CASE(R, FLOAT): return VK_FORMAT_R32_SFLOAT;
226 case FMT_CASE(RG, UNSIGNED_INT32): return VK_FORMAT_R32G32_UINT;
227 case FMT_CASE(RG, SIGNED_INT32): return VK_FORMAT_R32G32_SINT;
228 case FMT_CASE(RG, FLOAT): return VK_FORMAT_R32G32_SFLOAT;
230 case FMT_CASE(RGB, UNSIGNED_INT32): return VK_FORMAT_R32G32B32_UINT;
231 case FMT_CASE(RGB, SIGNED_INT32): return VK_FORMAT_R32G32B32_SINT;
232 case FMT_CASE(RGB, FLOAT): return VK_FORMAT_R32G32B32_SFLOAT;
234 case FMT_CASE(RGBA, UNSIGNED_INT32): return VK_FORMAT_R32G32B32A32_UINT;
235 case FMT_CASE(RGBA, SIGNED_INT32): return VK_FORMAT_R32G32B32A32_SINT;
236 case FMT_CASE(RGBA, FLOAT): return VK_FORMAT_R32G32B32A32_SFLOAT;
238 case FMT_CASE(R, FLOAT64): return VK_FORMAT_R64_SFLOAT;
239 case FMT_CASE(RG, FLOAT64): return VK_FORMAT_R64G64_SFLOAT;
240 case FMT_CASE(RGB, FLOAT64): return VK_FORMAT_R64G64B64_SFLOAT;
241 case FMT_CASE(RGBA, FLOAT64): return VK_FORMAT_R64G64B64A64_SFLOAT;
243 case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV): return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
244 case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV): return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
246 case FMT_CASE(BGR, UNORM_INT8): return VK_FORMAT_B8G8R8_UNORM;
247 case FMT_CASE(BGR, SNORM_INT8): return VK_FORMAT_B8G8R8_SNORM;
248 case FMT_CASE(BGR, UNSIGNED_INT8): return VK_FORMAT_B8G8R8_UINT;
249 case FMT_CASE(BGR, SIGNED_INT8): return VK_FORMAT_B8G8R8_SINT;
250 case FMT_CASE(sBGR, UNORM_INT8): return VK_FORMAT_B8G8R8_SRGB;
252 case FMT_CASE(BGRA, UNORM_INT8): return VK_FORMAT_B8G8R8A8_UNORM;
253 case FMT_CASE(BGRA, SNORM_INT8): return VK_FORMAT_B8G8R8A8_SNORM;
254 case FMT_CASE(BGRA, UNSIGNED_INT8): return VK_FORMAT_B8G8R8A8_UINT;
255 case FMT_CASE(BGRA, SIGNED_INT8): return VK_FORMAT_B8G8R8A8_SINT;
256 case FMT_CASE(sBGRA, UNORM_INT8): return VK_FORMAT_B8G8R8A8_SRGB;
258 case FMT_CASE(BGRA, UNORM_INT_1010102_REV): return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
259 case FMT_CASE(BGRA, SNORM_INT_1010102_REV): return VK_FORMAT_A2R10G10B10_SNORM_PACK32;
260 case FMT_CASE(BGRA, UNSIGNED_INT_1010102_REV): return VK_FORMAT_A2R10G10B10_UINT_PACK32;
261 case FMT_CASE(BGRA, SIGNED_INT_1010102_REV): return VK_FORMAT_A2R10G10B10_SINT_PACK32;
263 case FMT_CASE(D, UNORM_INT16): return VK_FORMAT_D16_UNORM;
264 case FMT_CASE(D, UNSIGNED_INT_24_8_REV): return VK_FORMAT_X8_D24_UNORM_PACK32;
265 case FMT_CASE(D, FLOAT): return VK_FORMAT_D32_SFLOAT;
267 case FMT_CASE(S, UNSIGNED_INT8): return VK_FORMAT_S8_UINT;
269 case FMT_CASE(DS, UNSIGNED_INT_16_8_8): return VK_FORMAT_D16_UNORM_S8_UINT;
270 case FMT_CASE(DS, UNSIGNED_INT_24_8_REV): return VK_FORMAT_D24_UNORM_S8_UINT;
271 case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV): return VK_FORMAT_D32_SFLOAT_S8_UINT;
274 TCU_THROW(InternalError, "Unknown texture format");
281 tcu::TextureFormat mapVkFormat (VkFormat format)
283 using tcu::TextureFormat;
285 // update this mapping if VkFormat changes
286 DE_STATIC_ASSERT(VK_FORMAT_LAST == 185);
290 case VK_FORMAT_R4G4_UNORM_PACK8: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_BYTE_44);
291 case VK_FORMAT_R5G6B5_UNORM_PACK16: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_SHORT_565);
292 case VK_FORMAT_R4G4B4A4_UNORM_PACK16: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_4444);
293 case VK_FORMAT_R5G5B5A1_UNORM_PACK16: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_5551);
295 case VK_FORMAT_B5G6R5_UNORM_PACK16: return TextureFormat(TextureFormat::BGR, TextureFormat::UNORM_SHORT_565);
296 case VK_FORMAT_B4G4R4A4_UNORM_PACK16: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_SHORT_4444);
297 case VK_FORMAT_B5G5R5A1_UNORM_PACK16: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_SHORT_5551);
299 case VK_FORMAT_A1R5G5B5_UNORM_PACK16: return TextureFormat(TextureFormat::ARGB, TextureFormat::UNORM_SHORT_1555);
301 case VK_FORMAT_R8_UNORM: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT8);
302 case VK_FORMAT_R8_SNORM: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT8);
303 case VK_FORMAT_R8_USCALED: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8);
304 case VK_FORMAT_R8_SSCALED: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT8);
305 case VK_FORMAT_R8_UINT: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8);
306 case VK_FORMAT_R8_SINT: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT8);
307 case VK_FORMAT_R8_SRGB: return TextureFormat(TextureFormat::sR, TextureFormat::UNORM_INT8);
309 case VK_FORMAT_R8G8_UNORM: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT8);
310 case VK_FORMAT_R8G8_SNORM: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT8);
311 case VK_FORMAT_R8G8_USCALED: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT8);
312 case VK_FORMAT_R8G8_SSCALED: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT8);
313 case VK_FORMAT_R8G8_UINT: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT8);
314 case VK_FORMAT_R8G8_SINT: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT8);
315 case VK_FORMAT_R8G8_SRGB: return TextureFormat(TextureFormat::sRG, TextureFormat::UNORM_INT8);
317 case VK_FORMAT_R8G8B8_UNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8);
318 case VK_FORMAT_R8G8B8_SNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT8);
319 case VK_FORMAT_R8G8B8_USCALED: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT8);
320 case VK_FORMAT_R8G8B8_SSCALED: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT8);
321 case VK_FORMAT_R8G8B8_UINT: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT8);
322 case VK_FORMAT_R8G8B8_SINT: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT8);
323 case VK_FORMAT_R8G8B8_SRGB: return TextureFormat(TextureFormat::sRGB, TextureFormat::UNORM_INT8);
325 case VK_FORMAT_R8G8B8A8_UNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8);
326 case VK_FORMAT_R8G8B8A8_SNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT8);
327 case VK_FORMAT_R8G8B8A8_USCALED: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8);
328 case VK_FORMAT_R8G8B8A8_SSCALED: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8);
329 case VK_FORMAT_R8G8B8A8_UINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8);
330 case VK_FORMAT_R8G8B8A8_SINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8);
331 case VK_FORMAT_R8G8B8A8_SRGB: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8);
333 case VK_FORMAT_R16_UNORM: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT16);
334 case VK_FORMAT_R16_SNORM: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT16);
335 case VK_FORMAT_R16_USCALED: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT16);
336 case VK_FORMAT_R16_SSCALED: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT16);
337 case VK_FORMAT_R16_UINT: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT16);
338 case VK_FORMAT_R16_SINT: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT16);
339 case VK_FORMAT_R16_SFLOAT: return TextureFormat(TextureFormat::R, TextureFormat::HALF_FLOAT);
341 case VK_FORMAT_R16G16_UNORM: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT16);
342 case VK_FORMAT_R16G16_SNORM: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT16);
343 case VK_FORMAT_R16G16_USCALED: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT16);
344 case VK_FORMAT_R16G16_SSCALED: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT16);
345 case VK_FORMAT_R16G16_UINT: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT16);
346 case VK_FORMAT_R16G16_SINT: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT16);
347 case VK_FORMAT_R16G16_SFLOAT: return TextureFormat(TextureFormat::RG, TextureFormat::HALF_FLOAT);
349 case VK_FORMAT_R16G16B16_UNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT16);
350 case VK_FORMAT_R16G16B16_SNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT16);
351 case VK_FORMAT_R16G16B16_USCALED: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT16);
352 case VK_FORMAT_R16G16B16_SSCALED: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT16);
353 case VK_FORMAT_R16G16B16_UINT: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT16);
354 case VK_FORMAT_R16G16B16_SINT: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT16);
355 case VK_FORMAT_R16G16B16_SFLOAT: return TextureFormat(TextureFormat::RGB, TextureFormat::HALF_FLOAT);
357 case VK_FORMAT_R16G16B16A16_UNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT16);
358 case VK_FORMAT_R16G16B16A16_SNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT16);
359 case VK_FORMAT_R16G16B16A16_USCALED: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT16);
360 case VK_FORMAT_R16G16B16A16_SSCALED: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT16);
361 case VK_FORMAT_R16G16B16A16_UINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT16);
362 case VK_FORMAT_R16G16B16A16_SINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT16);
363 case VK_FORMAT_R16G16B16A16_SFLOAT: return TextureFormat(TextureFormat::RGBA, TextureFormat::HALF_FLOAT);
365 case VK_FORMAT_R32_UINT: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT32);
366 case VK_FORMAT_R32_SINT: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT32);
367 case VK_FORMAT_R32_SFLOAT: return TextureFormat(TextureFormat::R, TextureFormat::FLOAT);
369 case VK_FORMAT_R32G32_UINT: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT32);
370 case VK_FORMAT_R32G32_SINT: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT32);
371 case VK_FORMAT_R32G32_SFLOAT: return TextureFormat(TextureFormat::RG, TextureFormat::FLOAT);
373 case VK_FORMAT_R32G32B32_UINT: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT32);
374 case VK_FORMAT_R32G32B32_SINT: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT32);
375 case VK_FORMAT_R32G32B32_SFLOAT: return TextureFormat(TextureFormat::RGB, TextureFormat::FLOAT);
377 case VK_FORMAT_R32G32B32A32_UINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT32);
378 case VK_FORMAT_R32G32B32A32_SINT: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT32);
379 case VK_FORMAT_R32G32B32A32_SFLOAT: return TextureFormat(TextureFormat::RGBA, TextureFormat::FLOAT);
381 case VK_FORMAT_R64_SFLOAT: return TextureFormat(TextureFormat::R, TextureFormat::FLOAT64);
382 case VK_FORMAT_R64G64_SFLOAT: return TextureFormat(TextureFormat::RG, TextureFormat::FLOAT64);
383 case VK_FORMAT_R64G64B64_SFLOAT: return TextureFormat(TextureFormat::RGB, TextureFormat::FLOAT64);
384 case VK_FORMAT_R64G64B64A64_SFLOAT: return TextureFormat(TextureFormat::RGBA, TextureFormat::FLOAT64);
386 case VK_FORMAT_B10G11R11_UFLOAT_PACK32: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
387 case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_999_E5_REV);
389 case VK_FORMAT_B8G8R8_UNORM: return TextureFormat(TextureFormat::BGR, TextureFormat::UNORM_INT8);
390 case VK_FORMAT_B8G8R8_SNORM: return TextureFormat(TextureFormat::BGR, TextureFormat::SNORM_INT8);
391 case VK_FORMAT_B8G8R8_USCALED: return TextureFormat(TextureFormat::BGR, TextureFormat::UNSIGNED_INT8);
392 case VK_FORMAT_B8G8R8_SSCALED: return TextureFormat(TextureFormat::BGR, TextureFormat::SIGNED_INT8);
393 case VK_FORMAT_B8G8R8_UINT: return TextureFormat(TextureFormat::BGR, TextureFormat::UNSIGNED_INT8);
394 case VK_FORMAT_B8G8R8_SINT: return TextureFormat(TextureFormat::BGR, TextureFormat::SIGNED_INT8);
395 case VK_FORMAT_B8G8R8_SRGB: return TextureFormat(TextureFormat::sBGR, TextureFormat::UNORM_INT8);
397 case VK_FORMAT_B8G8R8A8_UNORM: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_INT8);
398 case VK_FORMAT_B8G8R8A8_SNORM: return TextureFormat(TextureFormat::BGRA, TextureFormat::SNORM_INT8);
399 case VK_FORMAT_B8G8R8A8_USCALED: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNSIGNED_INT8);
400 case VK_FORMAT_B8G8R8A8_SSCALED: return TextureFormat(TextureFormat::BGRA, TextureFormat::SIGNED_INT8);
401 case VK_FORMAT_B8G8R8A8_UINT: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNSIGNED_INT8);
402 case VK_FORMAT_B8G8R8A8_SINT: return TextureFormat(TextureFormat::BGRA, TextureFormat::SIGNED_INT8);
403 case VK_FORMAT_B8G8R8A8_SRGB: return TextureFormat(TextureFormat::sBGRA, TextureFormat::UNORM_INT8);
405 case VK_FORMAT_D16_UNORM: return TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT16);
406 case VK_FORMAT_X8_D24_UNORM_PACK32: return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT_24_8_REV);
407 case VK_FORMAT_D32_SFLOAT: return TextureFormat(TextureFormat::D, TextureFormat::FLOAT);
409 case VK_FORMAT_S8_UINT: return TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8);
411 // \note There is no standard interleaved memory layout for DS formats; buffer-image copies
412 // will always operate on either D or S aspect only. See Khronos bug 12998
413 case VK_FORMAT_D16_UNORM_S8_UINT: return TextureFormat(TextureFormat::DS, TextureFormat::UNSIGNED_INT_16_8_8);
414 case VK_FORMAT_D24_UNORM_S8_UINT: return TextureFormat(TextureFormat::DS, TextureFormat::UNSIGNED_INT_24_8_REV);
415 case VK_FORMAT_D32_SFLOAT_S8_UINT: return TextureFormat(TextureFormat::DS, TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
417 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
418 case VK_FORMAT_A8B8G8R8_UNORM_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8);
419 case VK_FORMAT_A8B8G8R8_SNORM_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT8);
420 case VK_FORMAT_A8B8G8R8_USCALED_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8);
421 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8);
422 case VK_FORMAT_A8B8G8R8_UINT_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8);
423 case VK_FORMAT_A8B8G8R8_SINT_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8);
424 case VK_FORMAT_A8B8G8R8_SRGB_PACK32: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8);
426 # error "Big-endian not supported"
429 case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNORM_INT_1010102_REV);
430 case VK_FORMAT_A2R10G10B10_SNORM_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::SNORM_INT_1010102_REV);
431 case VK_FORMAT_A2R10G10B10_USCALED_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNSIGNED_INT_1010102_REV);
432 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::SIGNED_INT_1010102_REV);
433 case VK_FORMAT_A2R10G10B10_UINT_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::UNSIGNED_INT_1010102_REV);
434 case VK_FORMAT_A2R10G10B10_SINT_PACK32: return TextureFormat(TextureFormat::BGRA, TextureFormat::SIGNED_INT_1010102_REV);
436 case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT_1010102_REV);
437 case VK_FORMAT_A2B10G10R10_SNORM_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT_1010102_REV);
438 case VK_FORMAT_A2B10G10R10_USCALED_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV);
439 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT_1010102_REV);
440 case VK_FORMAT_A2B10G10R10_UINT_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV);
441 case VK_FORMAT_A2B10G10R10_SINT_PACK32: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT_1010102_REV);
445 TCU_THROW(InternalError, "Unknown image format");
449 tcu::CompressedTexFormat mapVkCompressedFormat (VkFormat format)
451 // update this mapping if VkFormat changes
452 DE_STATIC_ASSERT(VK_FORMAT_LAST == 185);
456 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8;
457 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8;
458 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
459 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
460 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8;
461 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8;
462 case VK_FORMAT_EAC_R11_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_EAC_R11;
463 case VK_FORMAT_EAC_R11_SNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11;
464 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_EAC_RG11;
465 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11;
466 case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA;
467 case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8;
468 case VK_FORMAT_ASTC_5x4_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA;
469 case VK_FORMAT_ASTC_5x4_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
470 case VK_FORMAT_ASTC_5x5_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA;
471 case VK_FORMAT_ASTC_5x5_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8;
472 case VK_FORMAT_ASTC_6x5_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA;
473 case VK_FORMAT_ASTC_6x5_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8;
474 case VK_FORMAT_ASTC_6x6_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA;
475 case VK_FORMAT_ASTC_6x6_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8;
476 case VK_FORMAT_ASTC_8x5_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA;
477 case VK_FORMAT_ASTC_8x5_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
478 case VK_FORMAT_ASTC_8x6_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA;
479 case VK_FORMAT_ASTC_8x6_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8;
480 case VK_FORMAT_ASTC_8x8_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA;
481 case VK_FORMAT_ASTC_8x8_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8;
482 case VK_FORMAT_ASTC_10x5_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA;
483 case VK_FORMAT_ASTC_10x5_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8;
484 case VK_FORMAT_ASTC_10x6_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA;
485 case VK_FORMAT_ASTC_10x6_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8;
486 case VK_FORMAT_ASTC_10x8_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA;
487 case VK_FORMAT_ASTC_10x8_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8;
488 case VK_FORMAT_ASTC_10x10_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA;
489 case VK_FORMAT_ASTC_10x10_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8;
490 case VK_FORMAT_ASTC_12x10_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA;
491 case VK_FORMAT_ASTC_12x10_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8;
492 case VK_FORMAT_ASTC_12x12_UNORM_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA;
493 case VK_FORMAT_ASTC_12x12_SRGB_BLOCK: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8;
498 return tcu::COMPRESSEDTEXFORMAT_LAST;
501 VkComponentMapping getFormatComponentMapping (VkFormat format)
503 using tcu::TextureFormat;
505 static const VkComponentMapping R = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ONE };
506 static const VkComponentMapping RG = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ONE };
507 static const VkComponentMapping RGB = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_ONE };
508 static const VkComponentMapping RGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
509 static const VkComponentMapping S = { VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_A };
510 static const VkComponentMapping DS = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_A };
511 static const VkComponentMapping BGRA = { VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_A };
512 static const VkComponentMapping BGR = { VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_ONE };
514 if (format == VK_FORMAT_UNDEFINED)
517 const tcu::TextureFormat tcuFormat = (isCompressedFormat(format)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(format))
518 : mapVkFormat(format);
520 switch (tcuFormat.order)
522 case TextureFormat::R: return R;
523 case TextureFormat::RG: return RG;
524 case TextureFormat::RGB: return RGB;
525 case TextureFormat::RGBA: return RGBA;
526 case TextureFormat::BGRA: return BGRA;
527 case TextureFormat::BGR: return BGR;
528 case TextureFormat::sR: return R;
529 case TextureFormat::sRG: return RG;
530 case TextureFormat::sRGB: return RGB;
531 case TextureFormat::sRGBA: return RGBA;
532 case TextureFormat::sBGR: return BGR;
533 case TextureFormat::sBGRA: return BGRA;
534 case TextureFormat::D: return R;
535 case TextureFormat::S: return S;
536 case TextureFormat::DS: return DS;
545 static bool isScaledFormat (VkFormat format)
547 // update this mapping if VkFormat changes
548 DE_STATIC_ASSERT(VK_FORMAT_LAST == 185);
552 case VK_FORMAT_R8_USCALED:
553 case VK_FORMAT_R8_SSCALED:
554 case VK_FORMAT_R8G8_USCALED:
555 case VK_FORMAT_R8G8_SSCALED:
556 case VK_FORMAT_R8G8B8_USCALED:
557 case VK_FORMAT_R8G8B8_SSCALED:
558 case VK_FORMAT_R8G8B8A8_USCALED:
559 case VK_FORMAT_R8G8B8A8_SSCALED:
560 case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
561 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
562 case VK_FORMAT_R16_USCALED:
563 case VK_FORMAT_R16_SSCALED:
564 case VK_FORMAT_R16G16_USCALED:
565 case VK_FORMAT_R16G16_SSCALED:
566 case VK_FORMAT_R16G16B16_USCALED:
567 case VK_FORMAT_R16G16B16_SSCALED:
568 case VK_FORMAT_R16G16B16A16_USCALED:
569 case VK_FORMAT_R16G16B16A16_SSCALED:
570 case VK_FORMAT_B8G8R8_USCALED:
571 case VK_FORMAT_B8G8R8_SSCALED:
572 case VK_FORMAT_B8G8R8A8_USCALED:
573 case VK_FORMAT_B8G8R8A8_SSCALED:
574 case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
575 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
583 static bool fullTextureFormatRoundTripSupported (VkFormat format)
585 if (isScaledFormat(format))
587 // *SCALED formats get mapped to correspoding (u)int formats since
588 // accessing them through (float) getPixel/setPixel has same behavior
589 // as in shader access in Vulkan.
590 // Unfortunately full round-trip between tcu::TextureFormat and VkFormat
591 // for most SCALED formats is not supported though.
593 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
595 switch (tcuFormat.type)
597 case tcu::TextureFormat::UNSIGNED_INT8:
598 case tcu::TextureFormat::UNSIGNED_INT16:
599 case tcu::TextureFormat::UNSIGNED_INT32:
600 case tcu::TextureFormat::SIGNED_INT8:
601 case tcu::TextureFormat::SIGNED_INT16:
602 case tcu::TextureFormat::SIGNED_INT32:
603 case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
604 case tcu::TextureFormat::SIGNED_INT_1010102_REV:
615 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
616 case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
617 case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
618 case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
619 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
620 case VK_FORMAT_A8B8G8R8_SINT_PACK32:
621 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
622 return false; // These map to regular byte array formats
628 return (format != VK_FORMAT_UNDEFINED);
632 void imageUtilSelfTest (void)
634 for (int formatNdx = 0; formatNdx < VK_FORMAT_LAST; formatNdx++)
636 const VkFormat format = (VkFormat)formatNdx;
638 if (format == VK_FORMAT_R64_UINT ||
639 format == VK_FORMAT_R64_SINT ||
640 format == VK_FORMAT_R64G64_UINT ||
641 format == VK_FORMAT_R64G64_SINT ||
642 format == VK_FORMAT_R64G64B64_UINT ||
643 format == VK_FORMAT_R64G64B64_SINT ||
644 format == VK_FORMAT_R64G64B64A64_UINT ||
645 format == VK_FORMAT_R64G64B64A64_SINT)
646 continue; // \todo [2015-12-05 pyry] Add framework support for (u)int64 channel type
648 if (format != VK_FORMAT_UNDEFINED && !isCompressedFormat(format))
650 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
651 const VkFormat remappedFormat = mapTextureFormat(tcuFormat);
653 DE_TEST_ASSERT(isValid(tcuFormat));
655 if (fullTextureFormatRoundTripSupported(format))
656 DE_TEST_ASSERT(format == remappedFormat);
661 VkFilter mapFilterMode (tcu::Sampler::FilterMode filterMode)
663 DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
667 case tcu::Sampler::NEAREST: return VK_FILTER_NEAREST;
668 case tcu::Sampler::LINEAR: return VK_FILTER_LINEAR;
669 case tcu::Sampler::NEAREST_MIPMAP_NEAREST: return VK_FILTER_NEAREST;
670 case tcu::Sampler::NEAREST_MIPMAP_LINEAR: return VK_FILTER_NEAREST;
671 case tcu::Sampler::LINEAR_MIPMAP_NEAREST: return VK_FILTER_LINEAR;
672 case tcu::Sampler::LINEAR_MIPMAP_LINEAR: return VK_FILTER_LINEAR;
674 DE_FATAL("Illegal filter mode");
680 VkSamplerMipmapMode mapMipmapMode (tcu::Sampler::FilterMode filterMode)
682 DE_STATIC_ASSERT(tcu::Sampler::FILTERMODE_LAST == 6);
686 case tcu::Sampler::NEAREST: return VK_SAMPLER_MIPMAP_MODE_BASE;
687 case tcu::Sampler::LINEAR: return VK_SAMPLER_MIPMAP_MODE_BASE;
688 case tcu::Sampler::NEAREST_MIPMAP_NEAREST: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
689 case tcu::Sampler::NEAREST_MIPMAP_LINEAR: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
690 case tcu::Sampler::LINEAR_MIPMAP_NEAREST: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
691 case tcu::Sampler::LINEAR_MIPMAP_LINEAR: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
693 DE_FATAL("Illegal filter mode");
694 return (VkSamplerMipmapMode)0;
698 VkSamplerAddressMode mapWrapMode (tcu::Sampler::WrapMode wrapMode)
702 case tcu::Sampler::CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
703 case tcu::Sampler::CLAMP_TO_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
704 case tcu::Sampler::REPEAT_GL: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
705 case tcu::Sampler::MIRRORED_REPEAT_GL: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
706 case tcu::Sampler::MIRRORED_ONCE: return VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE;
708 DE_FATAL("Wrap mode can't be mapped to Vulkan");
709 return (vk::VkSamplerAddressMode)0;
713 vk::VkCompareOp mapCompareMode (tcu::Sampler::CompareMode mode)
717 case tcu::Sampler::COMPAREMODE_NONE: return vk::VK_COMPARE_OP_NEVER;
718 case tcu::Sampler::COMPAREMODE_LESS: return vk::VK_COMPARE_OP_LESS;
719 case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL: return vk::VK_COMPARE_OP_LESS_OR_EQUAL;
720 case tcu::Sampler::COMPAREMODE_GREATER: return vk::VK_COMPARE_OP_GREATER;
721 case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL: return vk::VK_COMPARE_OP_GREATER_OR_EQUAL;
722 case tcu::Sampler::COMPAREMODE_EQUAL: return vk::VK_COMPARE_OP_EQUAL;
723 case tcu::Sampler::COMPAREMODE_NOT_EQUAL: return vk::VK_COMPARE_OP_NOT_EQUAL;
724 case tcu::Sampler::COMPAREMODE_ALWAYS: return vk::VK_COMPARE_OP_ALWAYS;
725 case tcu::Sampler::COMPAREMODE_NEVER: return vk::VK_COMPARE_OP_NEVER;
727 DE_FATAL("Illegal compare mode");
728 return (vk::VkCompareOp)0;
732 tcu::Sampler mapVkSampler (const VkSamplerCreateInfo& samplerCreateInfo)
734 tcu::Sampler sampler(mapVkSamplerAddressMode(samplerCreateInfo.addressModeU),
735 mapVkSamplerAddressMode(samplerCreateInfo.addressModeV),
736 mapVkSamplerAddressMode(samplerCreateInfo.addressModeW),
737 mapVkMinTexFilter(samplerCreateInfo.minFilter, samplerCreateInfo.mipmapMode),
738 mapVkMagTexFilter(samplerCreateInfo.magFilter),
740 !samplerCreateInfo.unnormalizedCoordinates,
741 samplerCreateInfo.compareEnable ? mapVkSamplerCompareOp(samplerCreateInfo.compareOp)
742 : tcu::Sampler::COMPAREMODE_NONE,
744 tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f),
747 switch (samplerCreateInfo.borderColor)
749 case VK_BORDER_COLOR_INT_OPAQUE_BLACK:
750 sampler.borderColor = tcu::UVec4(0,0,0,1);
752 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK:
753 sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f);
755 case VK_BORDER_COLOR_INT_OPAQUE_WHITE:
756 sampler.borderColor = tcu::UVec4(1, 1, 1, 1);
758 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE:
759 sampler.borderColor = tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
761 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK:
762 sampler.borderColor = tcu::UVec4(0,0,0,0);
764 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
765 sampler.borderColor = tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f);
776 tcu::Sampler::CompareMode mapVkSamplerCompareOp (VkCompareOp compareOp)
780 case VK_COMPARE_OP_NEVER: return tcu::Sampler::COMPAREMODE_NEVER;
781 case VK_COMPARE_OP_LESS: return tcu::Sampler::COMPAREMODE_LESS;
782 case VK_COMPARE_OP_EQUAL: return tcu::Sampler::COMPAREMODE_EQUAL;
783 case VK_COMPARE_OP_LESS_OR_EQUAL: return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
784 case VK_COMPARE_OP_GREATER: return tcu::Sampler::COMPAREMODE_GREATER;
785 case VK_COMPARE_OP_NOT_EQUAL: return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
786 case VK_COMPARE_OP_GREATER_OR_EQUAL: return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
787 case VK_COMPARE_OP_ALWAYS: return tcu::Sampler::COMPAREMODE_ALWAYS;
793 return tcu::Sampler::COMPAREMODE_LAST;
796 tcu::Sampler::WrapMode mapVkSamplerAddressMode (VkSamplerAddressMode addressMode)
800 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: return tcu::Sampler::CLAMP_TO_EDGE;
801 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: return tcu::Sampler::CLAMP_TO_BORDER;
802 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: return tcu::Sampler::MIRRORED_REPEAT_GL;
803 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: return tcu::Sampler::MIRRORED_ONCE;
804 case VK_SAMPLER_ADDRESS_MODE_REPEAT: return tcu::Sampler::REPEAT_GL;
810 return tcu::Sampler::WRAPMODE_LAST;
813 tcu::Sampler::FilterMode mapVkMinTexFilter (VkFilter filter, VkSamplerMipmapMode mipMode)
817 case VK_FILTER_LINEAR:
820 case VK_SAMPLER_MIPMAP_MODE_BASE: return tcu::Sampler::LINEAR;
821 case VK_SAMPLER_MIPMAP_MODE_LINEAR: return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
822 case VK_SAMPLER_MIPMAP_MODE_NEAREST: return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
828 case VK_FILTER_NEAREST:
831 case VK_SAMPLER_MIPMAP_MODE_BASE: return tcu::Sampler::NEAREST;
832 case VK_SAMPLER_MIPMAP_MODE_LINEAR: return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
833 case VK_SAMPLER_MIPMAP_MODE_NEAREST: return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
844 return tcu::Sampler::FILTERMODE_LAST;
847 tcu::Sampler::FilterMode mapVkMagTexFilter (VkFilter filter)
851 case VK_FILTER_LINEAR: return tcu::Sampler::LINEAR;
852 case VK_FILTER_NEAREST: return tcu::Sampler::NEAREST;
858 return tcu::Sampler::FILTERMODE_LAST;
862 int mapVkComponentSwizzle (const vk::VkComponentSwizzle& channelSwizzle)
864 switch (channelSwizzle)
866 case vk::VK_COMPONENT_SWIZZLE_ZERO: return 0;
867 case vk::VK_COMPONENT_SWIZZLE_ONE: return 1;
868 case vk::VK_COMPONENT_SWIZZLE_R: return 2;
869 case vk::VK_COMPONENT_SWIZZLE_G: return 3;
870 case vk::VK_COMPONENT_SWIZZLE_B: return 4;
871 case vk::VK_COMPONENT_SWIZZLE_A: return 5;
880 tcu::UVec4 mapVkComponentMapping (const vk::VkComponentMapping& mapping)
884 swizzle.x() = mapVkComponentSwizzle(mapping.r);
885 swizzle.y() = mapVkComponentSwizzle(mapping.g);
886 swizzle.z() = mapVkComponentSwizzle(mapping.b);
887 swizzle.w() = mapVkComponentSwizzle(mapping.a);
892 //! Get a format the matches the layout in buffer memory used for a
893 //! buffer<->image copy on a depth/stencil format.
894 tcu::TextureFormat getDepthCopyFormat (VkFormat combinedFormat)
896 switch (combinedFormat)
898 case VK_FORMAT_D16_UNORM:
899 case VK_FORMAT_X8_D24_UNORM_PACK32:
900 case VK_FORMAT_D32_SFLOAT:
901 return mapVkFormat(combinedFormat);
903 case VK_FORMAT_D16_UNORM_S8_UINT:
904 return mapVkFormat(VK_FORMAT_D16_UNORM);
905 case VK_FORMAT_D24_UNORM_S8_UINT:
906 return mapVkFormat(VK_FORMAT_X8_D24_UNORM_PACK32);
907 case VK_FORMAT_D32_SFLOAT_S8_UINT:
908 return mapVkFormat(VK_FORMAT_D32_SFLOAT);
910 case VK_FORMAT_S8_UINT:
912 DE_FATAL("Unexpected depth/stencil format");
913 return tcu::TextureFormat();
917 //! Get a format the matches the layout in buffer memory used for a
918 //! buffer<->image copy on a depth/stencil format.
919 tcu::TextureFormat getStencilCopyFormat (VkFormat combinedFormat)
921 switch (combinedFormat)
923 case VK_FORMAT_D16_UNORM_S8_UINT:
924 case VK_FORMAT_D24_UNORM_S8_UINT:
925 case VK_FORMAT_D32_SFLOAT_S8_UINT:
926 case VK_FORMAT_S8_UINT:
927 return mapVkFormat(VK_FORMAT_S8_UINT);
929 case VK_FORMAT_D16_UNORM:
930 case VK_FORMAT_X8_D24_UNORM_PACK32:
931 case VK_FORMAT_D32_SFLOAT:
933 DE_FATAL("Unexpected depth/stencil format");
934 return tcu::TextureFormat();