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