• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "VkFormat.hpp"
16 
17 #include "System/Debug.hpp"
18 #include "System/Math.hpp"
19 
20 namespace vk {
21 
isUnsignedNormalized() const22 bool Format::isUnsignedNormalized() const
23 {
24 	switch(format)
25 	{
26 	case VK_FORMAT_R4G4_UNORM_PACK8:
27 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
28 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
29 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
30 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
31 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
32 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
33 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
34 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
35 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
36 	case VK_FORMAT_R8_UNORM:
37 	case VK_FORMAT_R8G8_UNORM:
38 	case VK_FORMAT_R8G8B8A8_UNORM:
39 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
40 	case VK_FORMAT_B8G8R8A8_UNORM:
41 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
42 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
43 	case VK_FORMAT_R16_UNORM:
44 	case VK_FORMAT_R16G16_UNORM:
45 	case VK_FORMAT_R16G16B16_UNORM:
46 	case VK_FORMAT_R16G16B16A16_UNORM:
47 		return true;
48 	default:
49 		// sRGB encoded formats are also unsigned normalized.
50 		// Note that floating-pont formats have no need for nonlinear encoding,
51 		// and the sRGB transfer function is only defined for [0.0, 1.0].
52 		return isSRGBformat();
53 	}
54 }
55 
isSignedNormalized() const56 bool Format::isSignedNormalized() const
57 {
58 	switch(format)
59 	{
60 	case VK_FORMAT_R8_SNORM:
61 	case VK_FORMAT_R8G8_SNORM:
62 	case VK_FORMAT_R8G8B8A8_SNORM:
63 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
64 	case VK_FORMAT_B8G8R8A8_SNORM:
65 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
66 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
67 	case VK_FORMAT_R16_SNORM:
68 	case VK_FORMAT_R16G16_SNORM:
69 	case VK_FORMAT_R16G16B16_SNORM:
70 	case VK_FORMAT_R16G16B16A16_SNORM:
71 		return true;
72 	default:
73 		return false;
74 	}
75 }
76 
isSignedUnnormalizedInteger() const77 bool Format::isSignedUnnormalizedInteger() const
78 {
79 	switch(format)
80 	{
81 	case VK_FORMAT_R8_SINT:
82 	case VK_FORMAT_R8G8_SINT:
83 	case VK_FORMAT_R8G8B8A8_SINT:
84 	case VK_FORMAT_B8G8R8A8_SINT:
85 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
86 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
87 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
88 	case VK_FORMAT_R16_SINT:
89 	case VK_FORMAT_R16G16_SINT:
90 	case VK_FORMAT_R16G16B16_SINT:
91 	case VK_FORMAT_R16G16B16A16_SINT:
92 	case VK_FORMAT_R32_SINT:
93 	case VK_FORMAT_R32G32_SINT:
94 	case VK_FORMAT_R32G32B32_SINT:
95 	case VK_FORMAT_R32G32B32A32_SINT:
96 	case VK_FORMAT_R64_SINT:
97 	case VK_FORMAT_R64G64_SINT:
98 	case VK_FORMAT_R64G64B64_SINT:
99 	case VK_FORMAT_R64G64B64A64_SINT:
100 		return true;
101 	default:
102 		return false;
103 	}
104 }
105 
isUnsignedUnnormalizedInteger() const106 bool Format::isUnsignedUnnormalizedInteger() const
107 {
108 	switch(format)
109 	{
110 	case VK_FORMAT_R8_UINT:
111 	case VK_FORMAT_R8G8_UINT:
112 	case VK_FORMAT_R8G8B8A8_UINT:
113 	case VK_FORMAT_B8G8R8A8_UINT:
114 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
115 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
116 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
117 	case VK_FORMAT_R16_UINT:
118 	case VK_FORMAT_R16G16_UINT:
119 	case VK_FORMAT_R16G16B16_UINT:
120 	case VK_FORMAT_R16G16B16A16_UINT:
121 	case VK_FORMAT_R32_UINT:
122 	case VK_FORMAT_R32G32_UINT:
123 	case VK_FORMAT_R32G32B32_UINT:
124 	case VK_FORMAT_R32G32B32A32_UINT:
125 	case VK_FORMAT_R64_UINT:
126 	case VK_FORMAT_R64G64_UINT:
127 	case VK_FORMAT_R64G64B64_UINT:
128 	case VK_FORMAT_R64G64B64A64_UINT:
129 	case VK_FORMAT_S8_UINT:
130 		return true;
131 	default:
132 		return false;
133 	}
134 }
135 
isUnnormalizedInteger() const136 bool Format::isUnnormalizedInteger() const
137 {
138 	return isSignedUnnormalizedInteger() || isUnsignedUnnormalizedInteger();
139 }
140 
getAspects() const141 VkImageAspectFlags Format::getAspects() const
142 {
143 	// TODO: probably just flatten this out to a full format list, and alter
144 	// isDepth / isStencil etc to check for their aspect
145 
146 	VkImageAspectFlags aspects = 0;
147 	if(isDepth()) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
148 	if(isStencil()) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
149 
150 	// YCbCr formats
151 	switch(format)
152 	{
153 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
154 		aspects = VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT;
155 		break;
156 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
157 		aspects = VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT;
158 		break;
159 	default:
160 		ASSERT(!isYcbcrFormat());
161 		break;
162 	}
163 
164 	// Anything else is "color".
165 	if(!aspects) aspects |= VK_IMAGE_ASPECT_COLOR_BIT;
166 	return aspects;
167 }
168 
getAspectFormat(VkImageAspectFlags aspect) const169 Format Format::getAspectFormat(VkImageAspectFlags aspect) const
170 {
171 	switch(aspect)
172 	{
173 	case VK_IMAGE_ASPECT_COLOR_BIT:
174 	case(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT):
175 	case(VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT):
176 	case(VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT):
177 		return format;
178 
179 	case VK_IMAGE_ASPECT_DEPTH_BIT:
180 		switch(format)
181 		{
182 		case VK_FORMAT_D16_UNORM:
183 		case VK_FORMAT_D16_UNORM_S8_UINT:
184 			return VK_FORMAT_D16_UNORM;
185 		case VK_FORMAT_D24_UNORM_S8_UINT:
186 			return VK_FORMAT_X8_D24_UNORM_PACK32;
187 		case VK_FORMAT_D32_SFLOAT:
188 		case VK_FORMAT_D32_SFLOAT_S8_UINT:
189 			return VK_FORMAT_D32_SFLOAT;
190 		default:
191 			UNSUPPORTED("format %d", int(format));
192 			break;
193 		}
194 		break;
195 
196 	case VK_IMAGE_ASPECT_STENCIL_BIT:
197 		switch(format)
198 		{
199 		case VK_FORMAT_S8_UINT:
200 		case VK_FORMAT_D16_UNORM_S8_UINT:
201 		case VK_FORMAT_D24_UNORM_S8_UINT:
202 		case VK_FORMAT_D32_SFLOAT_S8_UINT:
203 			return VK_FORMAT_S8_UINT;
204 		default:
205 			UNSUPPORTED("format %d", int(format));
206 			break;
207 		}
208 		break;
209 
210 	// YCbCr formats
211 	// Vulkan 1.1 section 32.1.1. Compatible formats of planes of multi-planar formats
212 	case VK_IMAGE_ASPECT_PLANE_0_BIT:
213 		switch(format)
214 		{
215 		case VK_FORMAT_R8_UNORM:
216 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
217 		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
218 			return VK_FORMAT_R8_UNORM;
219 		default:
220 			UNSUPPORTED("format %d", int(format));
221 			break;
222 		}
223 		break;
224 
225 	case VK_IMAGE_ASPECT_PLANE_1_BIT:
226 		switch(format)
227 		{
228 		case VK_FORMAT_R8_UNORM:
229 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
230 			return VK_FORMAT_R8_UNORM;
231 		case VK_FORMAT_R8G8_UNORM:
232 		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
233 			return VK_FORMAT_R8G8_UNORM;
234 		case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
235 			return VK_FORMAT_R4G4B4A4_UNORM_PACK16;
236 		default:
237 			UNSUPPORTED("format %d", int(format));
238 			break;
239 		}
240 		break;
241 
242 	case VK_IMAGE_ASPECT_PLANE_2_BIT:
243 		switch(format)
244 		{
245 		case VK_FORMAT_R8_UNORM:
246 		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
247 			return VK_FORMAT_R8_UNORM;
248 		default:
249 			UNSUPPORTED("format %d", int(format));
250 			break;
251 		}
252 		break;
253 
254 	default:
255 		UNSUPPORTED("aspect %x", int(aspect));
256 		break;
257 	}
258 
259 	return format;
260 }
261 
getClearFormat() const262 VkFormat Format::getClearFormat() const
263 {
264 	// Set the proper format for the clear value, as described here:
265 	// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#clears-values
266 	if(isSignedUnnormalizedInteger())
267 	{
268 		return VK_FORMAT_R32G32B32A32_SINT;
269 	}
270 	else if(isUnsignedUnnormalizedInteger())
271 	{
272 		return VK_FORMAT_R32G32B32A32_UINT;
273 	}
274 
275 	return VK_FORMAT_R32G32B32A32_SFLOAT;
276 }
277 
isStencil() const278 bool Format::isStencil() const
279 {
280 	switch(format)
281 	{
282 	case VK_FORMAT_D16_UNORM_S8_UINT:
283 	case VK_FORMAT_D24_UNORM_S8_UINT:
284 	case VK_FORMAT_S8_UINT:
285 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
286 		return true;
287 	case VK_FORMAT_D16_UNORM:
288 	case VK_FORMAT_X8_D24_UNORM_PACK32:
289 	case VK_FORMAT_D32_SFLOAT:
290 	default:
291 		return false;
292 	}
293 }
294 
isDepth() const295 bool Format::isDepth() const
296 {
297 	switch(format)
298 	{
299 	case VK_FORMAT_D16_UNORM:
300 	case VK_FORMAT_D16_UNORM_S8_UINT:
301 	case VK_FORMAT_X8_D24_UNORM_PACK32:
302 	case VK_FORMAT_D24_UNORM_S8_UINT:
303 	case VK_FORMAT_D32_SFLOAT:
304 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
305 		return true;
306 	case VK_FORMAT_S8_UINT:
307 	default:
308 		return false;
309 	}
310 }
311 
isSRGBformat() const312 bool Format::isSRGBformat() const
313 {
314 	switch(format)
315 	{
316 	case VK_FORMAT_R8_SRGB:
317 	case VK_FORMAT_R8G8_SRGB:
318 	case VK_FORMAT_R8G8B8A8_SRGB:
319 	case VK_FORMAT_B8G8R8A8_SRGB:
320 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
321 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
322 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
323 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
324 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
325 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
326 	case VK_FORMAT_BC2_SRGB_BLOCK:
327 	case VK_FORMAT_BC3_SRGB_BLOCK:
328 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
329 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
330 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
331 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
332 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
333 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
334 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
335 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
336 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
337 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
338 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
339 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
340 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
341 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
342 		return true;
343 	default:
344 		return false;
345 	}
346 }
347 
isFloatFormat() const348 bool Format::isFloatFormat() const
349 {
350 	switch(format)
351 	{
352 	case VK_FORMAT_R4G4_UNORM_PACK8:
353 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
354 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
355 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
356 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
357 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
358 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
359 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
360 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
361 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
362 	case VK_FORMAT_R8_UNORM:
363 	case VK_FORMAT_R8_SNORM:
364 	case VK_FORMAT_R8_USCALED:
365 	case VK_FORMAT_R8_SSCALED:
366 	case VK_FORMAT_R8_UINT:
367 	case VK_FORMAT_R8_SINT:
368 	case VK_FORMAT_R8_SRGB:
369 	case VK_FORMAT_R8G8_UNORM:
370 	case VK_FORMAT_R8G8_SNORM:
371 	case VK_FORMAT_R8G8_USCALED:
372 	case VK_FORMAT_R8G8_SSCALED:
373 	case VK_FORMAT_R8G8_UINT:
374 	case VK_FORMAT_R8G8_SINT:
375 	case VK_FORMAT_R8G8_SRGB:
376 	case VK_FORMAT_R8G8B8A8_UNORM:
377 	case VK_FORMAT_R8G8B8A8_SNORM:
378 	case VK_FORMAT_R8G8B8A8_USCALED:
379 	case VK_FORMAT_R8G8B8A8_SSCALED:
380 	case VK_FORMAT_R8G8B8A8_UINT:
381 	case VK_FORMAT_R8G8B8A8_SINT:
382 	case VK_FORMAT_R8G8B8A8_SRGB:
383 	case VK_FORMAT_B8G8R8A8_UNORM:
384 	case VK_FORMAT_B8G8R8A8_SNORM:
385 	case VK_FORMAT_B8G8R8A8_USCALED:
386 	case VK_FORMAT_B8G8R8A8_SSCALED:
387 	case VK_FORMAT_B8G8R8A8_UINT:
388 	case VK_FORMAT_B8G8R8A8_SINT:
389 	case VK_FORMAT_B8G8R8A8_SRGB:
390 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
391 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
392 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
393 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
394 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
395 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
396 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
397 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
398 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
399 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
400 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
401 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
402 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
403 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
404 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
405 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
406 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
407 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
408 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
409 	case VK_FORMAT_R16_UNORM:
410 	case VK_FORMAT_R16_SNORM:
411 	case VK_FORMAT_R16_USCALED:
412 	case VK_FORMAT_R16_SSCALED:
413 	case VK_FORMAT_R16_UINT:
414 	case VK_FORMAT_R16_SINT:
415 	case VK_FORMAT_R16G16_UNORM:
416 	case VK_FORMAT_R16G16_SNORM:
417 	case VK_FORMAT_R16G16_USCALED:
418 	case VK_FORMAT_R16G16_SSCALED:
419 	case VK_FORMAT_R16G16_UINT:
420 	case VK_FORMAT_R16G16_SINT:
421 	case VK_FORMAT_R16G16B16_UNORM:
422 	case VK_FORMAT_R16G16B16_SNORM:
423 	case VK_FORMAT_R16G16B16_USCALED:
424 	case VK_FORMAT_R16G16B16_SSCALED:
425 	case VK_FORMAT_R16G16B16_UINT:
426 	case VK_FORMAT_R16G16B16_SINT:
427 	case VK_FORMAT_R16G16B16A16_UNORM:
428 	case VK_FORMAT_R16G16B16A16_SNORM:
429 	case VK_FORMAT_R16G16B16A16_USCALED:
430 	case VK_FORMAT_R16G16B16A16_SSCALED:
431 	case VK_FORMAT_R16G16B16A16_UINT:
432 	case VK_FORMAT_R16G16B16A16_SINT:
433 	case VK_FORMAT_R32_UINT:
434 	case VK_FORMAT_R32_SINT:
435 	case VK_FORMAT_R32G32_UINT:
436 	case VK_FORMAT_R32G32_SINT:
437 	case VK_FORMAT_R32G32B32_UINT:
438 	case VK_FORMAT_R32G32B32_SINT:
439 	case VK_FORMAT_R32G32B32A32_UINT:
440 	case VK_FORMAT_R32G32B32A32_SINT:
441 	case VK_FORMAT_R64_UINT:
442 	case VK_FORMAT_R64_SINT:
443 	case VK_FORMAT_R64G64_UINT:
444 	case VK_FORMAT_R64G64_SINT:
445 	case VK_FORMAT_R64G64B64_UINT:
446 	case VK_FORMAT_R64G64B64_SINT:
447 	case VK_FORMAT_R64G64B64A64_UINT:
448 	case VK_FORMAT_R64G64B64A64_SINT:
449 	case VK_FORMAT_D16_UNORM:
450 	case VK_FORMAT_X8_D24_UNORM_PACK32:
451 	case VK_FORMAT_S8_UINT:
452 	case VK_FORMAT_D16_UNORM_S8_UINT:
453 	case VK_FORMAT_D24_UNORM_S8_UINT:
454 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
455 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
456 		return false;
457 	case VK_FORMAT_R16_SFLOAT:
458 	case VK_FORMAT_R16G16_SFLOAT:
459 	case VK_FORMAT_R16G16B16_SFLOAT:
460 	case VK_FORMAT_R16G16B16A16_SFLOAT:
461 	case VK_FORMAT_R32_SFLOAT:
462 	case VK_FORMAT_R32G32_SFLOAT:
463 	case VK_FORMAT_R32G32B32_SFLOAT:
464 	case VK_FORMAT_R32G32B32A32_SFLOAT:
465 	case VK_FORMAT_R64_SFLOAT:
466 	case VK_FORMAT_R64G64_SFLOAT:
467 	case VK_FORMAT_R64G64B64_SFLOAT:
468 	case VK_FORMAT_R64G64B64A64_SFLOAT:
469 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
470 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
471 	case VK_FORMAT_D32_SFLOAT:
472 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
473 		return true;
474 	default:
475 		UNSUPPORTED("Format: %d", int(format));
476 	}
477 
478 	return false;
479 }
480 
isYcbcrFormat() const481 bool Format::isYcbcrFormat() const
482 {
483 	switch(format)
484 	{
485 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
486 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
487 		return true;
488 	default:
489 		return false;
490 	}
491 }
492 
isCompressed() const493 bool Format::isCompressed() const
494 {
495 	switch(format)
496 	{
497 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
498 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
499 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
500 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
501 	case VK_FORMAT_BC2_UNORM_BLOCK:
502 	case VK_FORMAT_BC2_SRGB_BLOCK:
503 	case VK_FORMAT_BC3_UNORM_BLOCK:
504 	case VK_FORMAT_BC3_SRGB_BLOCK:
505 	case VK_FORMAT_BC4_UNORM_BLOCK:
506 	case VK_FORMAT_BC4_SNORM_BLOCK:
507 	case VK_FORMAT_BC5_UNORM_BLOCK:
508 	case VK_FORMAT_BC5_SNORM_BLOCK:
509 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
510 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
511 	case VK_FORMAT_BC7_UNORM_BLOCK:
512 	case VK_FORMAT_BC7_SRGB_BLOCK:
513 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
514 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
515 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
516 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
517 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
518 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
519 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
520 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
521 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
522 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
523 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
524 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
525 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
526 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
527 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
528 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
529 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
530 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
531 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
532 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
533 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
534 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
535 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
536 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
537 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
538 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
539 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
540 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
541 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
542 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
543 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
544 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
545 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
546 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
547 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
548 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
549 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
550 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
551 		return true;
552 	default:
553 		return false;
554 	}
555 }
556 
getDecompressedFormat() const557 VkFormat Format::getDecompressedFormat() const
558 {
559 	// Note: our ETC2 decoder decompresses the 64 bit RGB compressed texel data to B8G8R8
560 	switch(format)
561 	{
562 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
563 		return VK_FORMAT_B8G8R8A8_UNORM;
564 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
565 		return VK_FORMAT_B8G8R8A8_SRGB;
566 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
567 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
568 		return VK_FORMAT_B8G8R8A8_UNORM;
569 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
570 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
571 		return VK_FORMAT_B8G8R8A8_SRGB;
572 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
573 		return VK_FORMAT_R16_UNORM;
574 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
575 		return VK_FORMAT_R16_SNORM;
576 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
577 		return VK_FORMAT_R16G16_UNORM;
578 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
579 		return VK_FORMAT_R16G16_SNORM;
580 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
581 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
582 	case VK_FORMAT_BC2_UNORM_BLOCK:
583 	case VK_FORMAT_BC3_UNORM_BLOCK:
584 	case VK_FORMAT_BC7_UNORM_BLOCK:
585 		return VK_FORMAT_B8G8R8A8_UNORM;
586 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
587 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
588 	case VK_FORMAT_BC2_SRGB_BLOCK:
589 	case VK_FORMAT_BC3_SRGB_BLOCK:
590 	case VK_FORMAT_BC7_SRGB_BLOCK:
591 		return VK_FORMAT_B8G8R8A8_SRGB;
592 	case VK_FORMAT_BC4_UNORM_BLOCK:
593 		return VK_FORMAT_R8_UNORM;
594 	case VK_FORMAT_BC4_SNORM_BLOCK:
595 		return VK_FORMAT_R8_SNORM;
596 	case VK_FORMAT_BC5_UNORM_BLOCK:
597 		return VK_FORMAT_R8G8_UNORM;
598 	case VK_FORMAT_BC5_SNORM_BLOCK:
599 		return VK_FORMAT_R8G8_SNORM;
600 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
601 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
602 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
603 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
604 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
605 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
606 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
607 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
608 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
609 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
610 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
611 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
612 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
613 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
614 		return VK_FORMAT_R8G8B8A8_UNORM;
615 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
616 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
617 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
618 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
619 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
620 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
621 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
622 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
623 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
624 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
625 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
626 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
627 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
628 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
629 		return VK_FORMAT_R8G8B8A8_SRGB;
630 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
631 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
632 		return VK_FORMAT_R16G16B16A16_SFLOAT;
633 	default:
634 		UNSUPPORTED("format: %d", int(format));
635 		return VK_FORMAT_UNDEFINED;
636 	}
637 }
638 
compatibleFormat() const639 VkFormat Format::compatibleFormat() const
640 {
641 	// According to the Vulkan 1.1 Spec, 37.1.6. Format Compatibility Classes:
642 	// "Uncompressed color formats are compatible with each other if they occupy
643 	//  the same number of bits per texel block. Compressed color formats are
644 	//  compatible with each other if the only difference between them is the
645 	//  numerical type of the uncompressed pixels (e.g. signed vs. unsigned, or
646 	//  SRGB vs. UNORM encoding). Each depth/stencil format is only compatible
647 	//  with itself. In the following table, all the formats in the same row are
648 	//  compatible."
649 
650 	// Return a single format per group of compatible formats, for quick comparison
651 	switch(format)
652 	{
653 	// 8 - bit, Block size 1 byte, 1 texel / block
654 	case VK_FORMAT_R4G4_UNORM_PACK8:
655 	case VK_FORMAT_R8_UNORM:
656 	case VK_FORMAT_R8_SNORM:
657 	case VK_FORMAT_R8_USCALED:
658 	case VK_FORMAT_R8_SSCALED:
659 	case VK_FORMAT_R8_UINT:
660 	case VK_FORMAT_R8_SINT:
661 	case VK_FORMAT_R8_SRGB:
662 		return VK_FORMAT_R8_UNORM;
663 
664 	// 16 - bit, Block size 2 bytes, 1 texel / block
665 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
666 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
667 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
668 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
669 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
670 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
671 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
672 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
673 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
674 	case VK_FORMAT_R8G8_UNORM:
675 	case VK_FORMAT_R8G8_SNORM:
676 	case VK_FORMAT_R8G8_USCALED:
677 	case VK_FORMAT_R8G8_SSCALED:
678 	case VK_FORMAT_R8G8_UINT:
679 	case VK_FORMAT_R8G8_SINT:
680 	case VK_FORMAT_R8G8_SRGB:
681 	case VK_FORMAT_R16_UNORM:
682 	case VK_FORMAT_R16_SNORM:
683 	case VK_FORMAT_R16_USCALED:
684 	case VK_FORMAT_R16_SSCALED:
685 	case VK_FORMAT_R16_UINT:
686 	case VK_FORMAT_R16_SINT:
687 	case VK_FORMAT_R16_SFLOAT:
688 	case VK_FORMAT_R10X6_UNORM_PACK16:
689 	case VK_FORMAT_R12X4_UNORM_PACK16:
690 		return VK_FORMAT_R16_UNORM;
691 
692 	// 32 - bit, Block size 4 bytes, 1 texel / block
693 	case VK_FORMAT_R8G8B8A8_UNORM:
694 	case VK_FORMAT_R8G8B8A8_SNORM:
695 	case VK_FORMAT_R8G8B8A8_USCALED:
696 	case VK_FORMAT_R8G8B8A8_SSCALED:
697 	case VK_FORMAT_R8G8B8A8_UINT:
698 	case VK_FORMAT_R8G8B8A8_SINT:
699 	case VK_FORMAT_R8G8B8A8_SRGB:
700 	case VK_FORMAT_B8G8R8A8_UNORM:
701 	case VK_FORMAT_B8G8R8A8_SNORM:
702 	case VK_FORMAT_B8G8R8A8_USCALED:
703 	case VK_FORMAT_B8G8R8A8_SSCALED:
704 	case VK_FORMAT_B8G8R8A8_UINT:
705 	case VK_FORMAT_B8G8R8A8_SINT:
706 	case VK_FORMAT_B8G8R8A8_SRGB:
707 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
708 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
709 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
710 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
711 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
712 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
713 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
714 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
715 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
716 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
717 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
718 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
719 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
720 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
721 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
722 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
723 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
724 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
725 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
726 	case VK_FORMAT_R16G16_UNORM:
727 	case VK_FORMAT_R16G16_SNORM:
728 	case VK_FORMAT_R16G16_USCALED:
729 	case VK_FORMAT_R16G16_SSCALED:
730 	case VK_FORMAT_R16G16_UINT:
731 	case VK_FORMAT_R16G16_SINT:
732 	case VK_FORMAT_R16G16_SFLOAT:
733 	case VK_FORMAT_R32_UINT:
734 	case VK_FORMAT_R32_SINT:
735 	case VK_FORMAT_R32_SFLOAT:
736 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
737 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
738 	case VK_FORMAT_R10X6G10X6_UNORM_2PACK16:
739 	case VK_FORMAT_R12X4G12X4_UNORM_2PACK16:
740 		return VK_FORMAT_R8G8B8A8_UNORM;
741 
742 	// 48 - bit, Block size 6 bytes, 1 texel / block
743 	case VK_FORMAT_R16G16B16_UNORM:
744 	case VK_FORMAT_R16G16B16_SNORM:
745 	case VK_FORMAT_R16G16B16_USCALED:
746 	case VK_FORMAT_R16G16B16_SSCALED:
747 	case VK_FORMAT_R16G16B16_UINT:
748 	case VK_FORMAT_R16G16B16_SINT:
749 	case VK_FORMAT_R16G16B16_SFLOAT:
750 		return VK_FORMAT_R16G16B16_UNORM;
751 
752 	// 64 - bit, Block size 8 bytes, 1 texel / block
753 	case VK_FORMAT_R16G16B16A16_UNORM:
754 	case VK_FORMAT_R16G16B16A16_SNORM:
755 	case VK_FORMAT_R16G16B16A16_USCALED:
756 	case VK_FORMAT_R16G16B16A16_SSCALED:
757 	case VK_FORMAT_R16G16B16A16_UINT:
758 	case VK_FORMAT_R16G16B16A16_SINT:
759 	case VK_FORMAT_R16G16B16A16_SFLOAT:
760 	case VK_FORMAT_R32G32_UINT:
761 	case VK_FORMAT_R32G32_SINT:
762 	case VK_FORMAT_R32G32_SFLOAT:
763 	case VK_FORMAT_R64_UINT:
764 	case VK_FORMAT_R64_SINT:
765 	case VK_FORMAT_R64_SFLOAT:
766 		return VK_FORMAT_R16G16B16A16_UNORM;
767 
768 	// 96 - bit, Block size 12 bytes, 1 texel / block
769 	case VK_FORMAT_R32G32B32_UINT:
770 	case VK_FORMAT_R32G32B32_SINT:
771 	case VK_FORMAT_R32G32B32_SFLOAT:
772 		return VK_FORMAT_R32G32B32_UINT;
773 
774 	// 128 - bit, Block size 16 bytes, 1 texel / block
775 	case VK_FORMAT_R32G32B32A32_UINT:
776 	case VK_FORMAT_R32G32B32A32_SINT:
777 	case VK_FORMAT_R32G32B32A32_SFLOAT:
778 	case VK_FORMAT_R64G64_UINT:
779 	case VK_FORMAT_R64G64_SINT:
780 	case VK_FORMAT_R64G64_SFLOAT:
781 		return VK_FORMAT_R32G32B32A32_UINT;
782 
783 	// 192 - bit, Block size 24 bytes, 1 texel / block
784 	case VK_FORMAT_R64G64B64_UINT:
785 	case VK_FORMAT_R64G64B64_SINT:
786 	case VK_FORMAT_R64G64B64_SFLOAT:
787 		return VK_FORMAT_R64G64B64_UINT;
788 
789 	// 256 - bit, Block size 32 bytes, 1 texel / block
790 	case VK_FORMAT_R64G64B64A64_UINT:
791 	case VK_FORMAT_R64G64B64A64_SINT:
792 	case VK_FORMAT_R64G64B64A64_SFLOAT:
793 		return VK_FORMAT_R64G64B64A64_UINT;
794 
795 	// BC1_RGB(64 bit), Block size 8 bytes, 16 texels / block
796 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
797 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
798 		return VK_FORMAT_BC1_RGB_UNORM_BLOCK;
799 
800 	// BC1_RGBA(64 bit), Block size 8 bytes, 16 texels / block
801 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
802 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
803 		return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
804 
805 	// BC2(128 bit), Block size 16 bytes, 16 texels / block
806 	case VK_FORMAT_BC2_UNORM_BLOCK:
807 	case VK_FORMAT_BC2_SRGB_BLOCK:
808 		return VK_FORMAT_BC2_UNORM_BLOCK;
809 
810 	// BC3(128 bit), Block size 16 bytes, 16 texels / block
811 	case VK_FORMAT_BC3_UNORM_BLOCK:
812 	case VK_FORMAT_BC3_SRGB_BLOCK:
813 		return VK_FORMAT_BC3_UNORM_BLOCK;
814 
815 	// BC4(64 bit), Block size 8 bytes, 16 texels / block
816 	case VK_FORMAT_BC4_UNORM_BLOCK:
817 	case VK_FORMAT_BC4_SNORM_BLOCK:
818 		return VK_FORMAT_BC4_UNORM_BLOCK;
819 
820 	// BC5(128 bit), Block size 16 bytes, 16 texels / block
821 	case VK_FORMAT_BC5_UNORM_BLOCK:
822 	case VK_FORMAT_BC5_SNORM_BLOCK:
823 		return VK_FORMAT_BC5_UNORM_BLOCK;
824 
825 	// BC6H(128 bit), Block size 16 bytes, 16 texels / block
826 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
827 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
828 		return VK_FORMAT_BC6H_UFLOAT_BLOCK;
829 
830 	// BC7(128 bit), Block size 16 bytes, 16 texels / block
831 	case VK_FORMAT_BC7_UNORM_BLOCK:
832 	case VK_FORMAT_BC7_SRGB_BLOCK:
833 		return VK_FORMAT_BC7_UNORM_BLOCK;
834 
835 	// ETC2_RGB(64 bit), Block size 8 bytes, 16 texels / block
836 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
837 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
838 		return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
839 
840 	// ETC2_RGBA(64 bit), Block size 8 bytes, 16 texels / block
841 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
842 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
843 		return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
844 
845 	// ETC2_EAC_RGBA(64 bit), Block size 8 bytes, 16 texels / block
846 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
847 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
848 		return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
849 
850 	// EAC_R(64 bit), Block size 8 bytes, 16 texels / block
851 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
852 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
853 		return VK_FORMAT_EAC_R11_UNORM_BLOCK;
854 
855 	// EAC_RG(128 bit), Block size 16 bytes, 16 texels / block
856 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
857 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
858 		return VK_FORMAT_EAC_R11G11_UNORM_BLOCK;
859 
860 	// ASTC_4x4(128 bit), Block size 16 bytes, 16 texels / block
861 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
862 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
863 		return VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
864 
865 	// ASTC_5x4(128 bit), Block size 16 bytes, 20 texels / block
866 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
867 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
868 		return VK_FORMAT_ASTC_5x4_UNORM_BLOCK;
869 
870 	// ASTC_5x5(128 bit), Block size 16 bytes, 25 texels / block
871 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
872 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
873 		return VK_FORMAT_ASTC_5x5_UNORM_BLOCK;
874 
875 	// ASTC_6x5(128 bit), Block size 16 bytes, 30 texels / block
876 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
877 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
878 		return VK_FORMAT_ASTC_6x5_UNORM_BLOCK;
879 
880 	// ASTC_6x6(128 bit), Block size 16 bytes, 36 texels / block
881 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
882 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
883 		return VK_FORMAT_ASTC_6x6_UNORM_BLOCK;
884 
885 	// ASTC_8x5(128 bit), Block size 16 bytes, 40 texels / block
886 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
887 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
888 		return VK_FORMAT_ASTC_8x5_UNORM_BLOCK;
889 
890 	// ASTC_8x6(128 bit), Block size 16 bytes, 48 texels / block
891 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
892 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
893 		return VK_FORMAT_ASTC_8x6_UNORM_BLOCK;
894 
895 	// ASTC_8x8(128 bit), Block size 16 bytes, 64 texels / block
896 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
897 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
898 		return VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
899 
900 	// ASTC_10x5(128 bit), Block size 16 bytes, 50 texels / block
901 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
902 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
903 		return VK_FORMAT_ASTC_10x5_UNORM_BLOCK;
904 
905 	// ASTC_10x6(128 bit), Block size 16 bytes, 60 texels / block
906 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
907 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
908 		return VK_FORMAT_ASTC_10x6_UNORM_BLOCK;
909 
910 	// ASTC_10x8(128 bit), Block size 16 bytes, 80 texels / block
911 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
912 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
913 		return VK_FORMAT_ASTC_10x8_UNORM_BLOCK;
914 
915 	// ASTC_10x10(128 bit), Block size 16 bytes, 100 texels / block
916 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
917 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
918 		return VK_FORMAT_ASTC_10x10_UNORM_BLOCK;
919 
920 	// ASTC_12x10(128 bit), Block size 16 bytes, 120 texels / block
921 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
922 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
923 		return VK_FORMAT_ASTC_12x10_UNORM_BLOCK;
924 
925 	// ASTC_12x12(128 bit), Block size 16 bytes, 144 texels / block
926 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
927 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
928 		return VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
929 
930 	// All other formats are only compatible with themselves
931 	default:
932 		return format;
933 	}
934 }
935 
isCompatible(const Format & other) const936 bool Format::isCompatible(const Format &other) const
937 {
938 	return compatibleFormat() == other.compatibleFormat();
939 }
940 
blockWidth() const941 int Format::blockWidth() const
942 {
943 	switch(format)
944 	{
945 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
946 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
947 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
948 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
949 	case VK_FORMAT_BC2_UNORM_BLOCK:
950 	case VK_FORMAT_BC2_SRGB_BLOCK:
951 	case VK_FORMAT_BC3_UNORM_BLOCK:
952 	case VK_FORMAT_BC3_SRGB_BLOCK:
953 	case VK_FORMAT_BC4_UNORM_BLOCK:
954 	case VK_FORMAT_BC4_SNORM_BLOCK:
955 	case VK_FORMAT_BC5_UNORM_BLOCK:
956 	case VK_FORMAT_BC5_SNORM_BLOCK:
957 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
958 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
959 	case VK_FORMAT_BC7_UNORM_BLOCK:
960 	case VK_FORMAT_BC7_SRGB_BLOCK:
961 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
962 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
963 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
964 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
965 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
966 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
967 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
968 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
969 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
970 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
971 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
972 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
973 		return 4;
974 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
975 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
976 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
977 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
978 		return 5;
979 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
980 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
981 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
982 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
983 		return 6;
984 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
985 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
986 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
987 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
988 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
989 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
990 		return 8;
991 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
992 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
993 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
994 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
995 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
996 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
997 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
998 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
999 		return 10;
1000 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1001 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1002 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1003 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1004 		return 12;
1005 	default:
1006 		return 1;
1007 	}
1008 }
1009 
blockHeight() const1010 int Format::blockHeight() const
1011 {
1012 	switch(format)
1013 	{
1014 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1015 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1016 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1017 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1018 	case VK_FORMAT_BC2_UNORM_BLOCK:
1019 	case VK_FORMAT_BC2_SRGB_BLOCK:
1020 	case VK_FORMAT_BC3_UNORM_BLOCK:
1021 	case VK_FORMAT_BC3_SRGB_BLOCK:
1022 	case VK_FORMAT_BC4_UNORM_BLOCK:
1023 	case VK_FORMAT_BC4_SNORM_BLOCK:
1024 	case VK_FORMAT_BC5_UNORM_BLOCK:
1025 	case VK_FORMAT_BC5_SNORM_BLOCK:
1026 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1027 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1028 	case VK_FORMAT_BC7_UNORM_BLOCK:
1029 	case VK_FORMAT_BC7_SRGB_BLOCK:
1030 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1031 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1032 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1033 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1034 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1035 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1036 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1037 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1038 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1039 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1040 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1041 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1042 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1043 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1044 		return 4;
1045 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1046 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1047 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1048 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1049 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1050 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1051 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1052 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1053 		return 5;
1054 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1055 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1056 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1057 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1058 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1059 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1060 		return 6;
1061 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1062 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1063 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1064 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1065 		return 8;
1066 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1067 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1068 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1069 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1070 		return 10;
1071 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1072 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1073 		return 12;
1074 	default:
1075 		return 1;
1076 	}
1077 }
1078 
bytesPerBlock() const1079 int Format::bytesPerBlock() const
1080 {
1081 	switch(format)
1082 	{
1083 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1084 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1085 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1086 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1087 	case VK_FORMAT_BC4_UNORM_BLOCK:
1088 	case VK_FORMAT_BC4_SNORM_BLOCK:
1089 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1090 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1091 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1092 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1093 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1094 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1095 		return 8;
1096 	case VK_FORMAT_BC2_UNORM_BLOCK:
1097 	case VK_FORMAT_BC2_SRGB_BLOCK:
1098 	case VK_FORMAT_BC3_UNORM_BLOCK:
1099 	case VK_FORMAT_BC3_SRGB_BLOCK:
1100 	case VK_FORMAT_BC5_UNORM_BLOCK:
1101 	case VK_FORMAT_BC5_SNORM_BLOCK:
1102 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1103 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1104 	case VK_FORMAT_BC7_UNORM_BLOCK:
1105 	case VK_FORMAT_BC7_SRGB_BLOCK:
1106 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1107 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1108 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1109 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1110 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1111 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1112 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1113 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1114 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1115 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1116 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1117 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1118 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1119 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1120 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1121 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1122 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1123 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1124 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1125 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1126 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1127 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1128 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1129 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1130 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1131 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1132 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1133 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1134 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1135 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1136 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1137 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1138 		return 16;
1139 	default:
1140 		return bytes();
1141 	}
1142 }
1143 
componentCount() const1144 int Format::componentCount() const
1145 {
1146 	switch(format)
1147 	{
1148 	case VK_FORMAT_R8_UNORM:
1149 	case VK_FORMAT_R8_SNORM:
1150 	case VK_FORMAT_R8_USCALED:
1151 	case VK_FORMAT_R8_SSCALED:
1152 	case VK_FORMAT_R8_UINT:
1153 	case VK_FORMAT_R8_SINT:
1154 	case VK_FORMAT_R8_SRGB:
1155 	case VK_FORMAT_R16_UNORM:
1156 	case VK_FORMAT_R16_SNORM:
1157 	case VK_FORMAT_R16_USCALED:
1158 	case VK_FORMAT_R16_SSCALED:
1159 	case VK_FORMAT_R16_UINT:
1160 	case VK_FORMAT_R16_SINT:
1161 	case VK_FORMAT_R16_SFLOAT:
1162 	case VK_FORMAT_R32_UINT:
1163 	case VK_FORMAT_R32_SINT:
1164 	case VK_FORMAT_R32_SFLOAT:
1165 	case VK_FORMAT_R64_UINT:
1166 	case VK_FORMAT_R64_SINT:
1167 	case VK_FORMAT_R64_SFLOAT:
1168 	case VK_FORMAT_D16_UNORM:
1169 	case VK_FORMAT_X8_D24_UNORM_PACK32:
1170 	case VK_FORMAT_D32_SFLOAT:
1171 	case VK_FORMAT_S8_UINT:
1172 	case VK_FORMAT_D16_UNORM_S8_UINT:
1173 	case VK_FORMAT_D24_UNORM_S8_UINT:
1174 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
1175 	case VK_FORMAT_BC4_UNORM_BLOCK:
1176 	case VK_FORMAT_BC4_SNORM_BLOCK:
1177 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1178 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1179 		return 1;
1180 	case VK_FORMAT_R4G4_UNORM_PACK8:
1181 	case VK_FORMAT_R8G8_UNORM:
1182 	case VK_FORMAT_R8G8_SNORM:
1183 	case VK_FORMAT_R8G8_USCALED:
1184 	case VK_FORMAT_R8G8_SSCALED:
1185 	case VK_FORMAT_R8G8_UINT:
1186 	case VK_FORMAT_R8G8_SINT:
1187 	case VK_FORMAT_R8G8_SRGB:
1188 	case VK_FORMAT_R16G16_UNORM:
1189 	case VK_FORMAT_R16G16_SNORM:
1190 	case VK_FORMAT_R16G16_USCALED:
1191 	case VK_FORMAT_R16G16_SSCALED:
1192 	case VK_FORMAT_R16G16_UINT:
1193 	case VK_FORMAT_R16G16_SINT:
1194 	case VK_FORMAT_R16G16_SFLOAT:
1195 	case VK_FORMAT_R32G32_UINT:
1196 	case VK_FORMAT_R32G32_SINT:
1197 	case VK_FORMAT_R32G32_SFLOAT:
1198 	case VK_FORMAT_R64G64_UINT:
1199 	case VK_FORMAT_R64G64_SINT:
1200 	case VK_FORMAT_R64G64_SFLOAT:
1201 	case VK_FORMAT_BC5_UNORM_BLOCK:
1202 	case VK_FORMAT_BC5_SNORM_BLOCK:
1203 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1204 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1205 		return 2;
1206 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
1207 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
1208 	case VK_FORMAT_R16G16B16_UNORM:
1209 	case VK_FORMAT_R16G16B16_SNORM:
1210 	case VK_FORMAT_R16G16B16_USCALED:
1211 	case VK_FORMAT_R16G16B16_SSCALED:
1212 	case VK_FORMAT_R16G16B16_UINT:
1213 	case VK_FORMAT_R16G16B16_SINT:
1214 	case VK_FORMAT_R16G16B16_SFLOAT:
1215 	case VK_FORMAT_R32G32B32_UINT:
1216 	case VK_FORMAT_R32G32B32_SINT:
1217 	case VK_FORMAT_R32G32B32_SFLOAT:
1218 	case VK_FORMAT_R64G64B64_UINT:
1219 	case VK_FORMAT_R64G64B64_SINT:
1220 	case VK_FORMAT_R64G64B64_SFLOAT:
1221 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1222 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
1223 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1224 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1225 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1226 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1227 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1228 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1229 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1230 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1231 		return 3;
1232 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1233 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1234 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
1235 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
1236 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1237 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1238 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1239 	case VK_FORMAT_R8G8B8A8_UNORM:
1240 	case VK_FORMAT_R8G8B8A8_SNORM:
1241 	case VK_FORMAT_R8G8B8A8_USCALED:
1242 	case VK_FORMAT_R8G8B8A8_SSCALED:
1243 	case VK_FORMAT_R8G8B8A8_UINT:
1244 	case VK_FORMAT_R8G8B8A8_SINT:
1245 	case VK_FORMAT_R8G8B8A8_SRGB:
1246 	case VK_FORMAT_B8G8R8A8_UNORM:
1247 	case VK_FORMAT_B8G8R8A8_SNORM:
1248 	case VK_FORMAT_B8G8R8A8_USCALED:
1249 	case VK_FORMAT_B8G8R8A8_SSCALED:
1250 	case VK_FORMAT_B8G8R8A8_UINT:
1251 	case VK_FORMAT_B8G8R8A8_SINT:
1252 	case VK_FORMAT_B8G8R8A8_SRGB:
1253 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1254 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1255 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1256 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1257 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1258 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1259 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1260 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1261 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
1262 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1263 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1264 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1265 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
1266 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1267 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
1268 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1269 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1270 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1271 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
1272 	case VK_FORMAT_R16G16B16A16_UNORM:
1273 	case VK_FORMAT_R16G16B16A16_SNORM:
1274 	case VK_FORMAT_R16G16B16A16_USCALED:
1275 	case VK_FORMAT_R16G16B16A16_SSCALED:
1276 	case VK_FORMAT_R16G16B16A16_UINT:
1277 	case VK_FORMAT_R16G16B16A16_SINT:
1278 	case VK_FORMAT_R16G16B16A16_SFLOAT:
1279 	case VK_FORMAT_R32G32B32A32_UINT:
1280 	case VK_FORMAT_R32G32B32A32_SINT:
1281 	case VK_FORMAT_R32G32B32A32_SFLOAT:
1282 	case VK_FORMAT_R64G64B64A64_UINT:
1283 	case VK_FORMAT_R64G64B64A64_SINT:
1284 	case VK_FORMAT_R64G64B64A64_SFLOAT:
1285 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1286 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1287 	case VK_FORMAT_BC2_UNORM_BLOCK:
1288 	case VK_FORMAT_BC2_SRGB_BLOCK:
1289 	case VK_FORMAT_BC3_UNORM_BLOCK:
1290 	case VK_FORMAT_BC3_SRGB_BLOCK:
1291 	case VK_FORMAT_BC7_UNORM_BLOCK:
1292 	case VK_FORMAT_BC7_SRGB_BLOCK:
1293 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1294 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1295 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1296 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1297 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1298 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1299 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1300 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1301 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1302 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1303 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1304 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1305 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1306 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1307 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1308 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1309 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1310 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1311 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1312 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1313 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1314 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1315 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1316 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1317 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1318 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1319 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1320 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1321 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1322 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1323 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1324 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1325 		return 4;
1326 	default:
1327 		UNSUPPORTED("Format: %d", int(format));
1328 	}
1329 
1330 	return 1;
1331 }
1332 
isUnsigned() const1333 bool Format::isUnsigned() const
1334 {
1335 	// TODO(b/203068380): create a proper check for signedness
1336 	return isUnsignedComponent(0);
1337 }
1338 
isUnsignedComponent(int component) const1339 bool Format::isUnsignedComponent(int component) const
1340 {
1341 	switch(format)
1342 	{
1343 	case VK_FORMAT_UNDEFINED:
1344 	case VK_FORMAT_R4G4_UNORM_PACK8:
1345 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1346 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1347 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
1348 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
1349 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
1350 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
1351 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1352 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1353 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1354 	case VK_FORMAT_R8_UNORM:
1355 	case VK_FORMAT_R8_UINT:
1356 	case VK_FORMAT_R8_SRGB:
1357 	case VK_FORMAT_R8G8_UNORM:
1358 	case VK_FORMAT_R8G8_USCALED:
1359 	case VK_FORMAT_R8G8_UINT:
1360 	case VK_FORMAT_R8G8_SRGB:
1361 	case VK_FORMAT_R8G8B8A8_UNORM:
1362 	case VK_FORMAT_R8G8B8A8_USCALED:
1363 	case VK_FORMAT_R8G8B8A8_UINT:
1364 	case VK_FORMAT_R8G8B8A8_SRGB:
1365 	case VK_FORMAT_B8G8R8A8_UNORM:
1366 	case VK_FORMAT_B8G8R8A8_USCALED:
1367 	case VK_FORMAT_B8G8R8A8_UINT:
1368 	case VK_FORMAT_B8G8R8A8_SRGB:
1369 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1370 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1371 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1372 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1373 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1374 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1375 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1376 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1377 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1378 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1379 	case VK_FORMAT_R16_UNORM:
1380 	case VK_FORMAT_R16_USCALED:
1381 	case VK_FORMAT_R16_UINT:
1382 	case VK_FORMAT_R16G16_UNORM:
1383 	case VK_FORMAT_R16G16_USCALED:
1384 	case VK_FORMAT_R16G16_UINT:
1385 	case VK_FORMAT_R16G16B16_UNORM:
1386 	case VK_FORMAT_R16G16B16_USCALED:
1387 	case VK_FORMAT_R16G16B16_UINT:
1388 	case VK_FORMAT_R16G16B16A16_UNORM:
1389 	case VK_FORMAT_R16G16B16A16_USCALED:
1390 	case VK_FORMAT_R16G16B16A16_UINT:
1391 	case VK_FORMAT_R32_UINT:
1392 	case VK_FORMAT_R32G32_UINT:
1393 	case VK_FORMAT_R32G32B32_UINT:
1394 	case VK_FORMAT_R32G32B32A32_UINT:
1395 	case VK_FORMAT_R64_UINT:
1396 	case VK_FORMAT_R64G64_UINT:
1397 	case VK_FORMAT_R64G64B64_UINT:
1398 	case VK_FORMAT_R64G64B64A64_UINT:
1399 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1400 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
1401 	case VK_FORMAT_D16_UNORM:
1402 	case VK_FORMAT_X8_D24_UNORM_PACK32:
1403 	case VK_FORMAT_S8_UINT:
1404 	case VK_FORMAT_D16_UNORM_S8_UINT:
1405 	case VK_FORMAT_D24_UNORM_S8_UINT:
1406 	case VK_FORMAT_D32_SFLOAT:
1407 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
1408 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1409 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1410 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1411 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1412 	case VK_FORMAT_BC2_UNORM_BLOCK:
1413 	case VK_FORMAT_BC2_SRGB_BLOCK:
1414 	case VK_FORMAT_BC3_UNORM_BLOCK:
1415 	case VK_FORMAT_BC3_SRGB_BLOCK:
1416 	case VK_FORMAT_BC4_UNORM_BLOCK:
1417 	case VK_FORMAT_BC5_UNORM_BLOCK:
1418 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1419 	case VK_FORMAT_BC7_UNORM_BLOCK:
1420 	case VK_FORMAT_BC7_SRGB_BLOCK:
1421 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1422 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1423 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1424 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1425 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1426 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1427 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1428 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1429 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1430 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1431 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1432 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1433 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1434 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1435 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1436 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1437 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1438 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1439 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1440 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1441 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1442 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1443 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1444 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1445 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1446 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1447 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1448 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1449 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1450 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1451 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1452 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1453 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1454 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1455 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1456 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1457 		return true;
1458 	case VK_FORMAT_R8G8B8A8_SNORM:
1459 	case VK_FORMAT_R8G8B8A8_SSCALED:
1460 	case VK_FORMAT_R8G8B8A8_SINT:
1461 	case VK_FORMAT_B8G8R8A8_SNORM:
1462 	case VK_FORMAT_B8G8R8A8_SSCALED:
1463 	case VK_FORMAT_B8G8R8A8_SINT:
1464 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1465 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1466 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1467 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
1468 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1469 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
1470 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
1471 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1472 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
1473 	case VK_FORMAT_R16G16B16A16_SNORM:
1474 	case VK_FORMAT_R16G16B16A16_SSCALED:
1475 	case VK_FORMAT_R16G16B16A16_SINT:
1476 	case VK_FORMAT_R16G16B16A16_SFLOAT:
1477 	case VK_FORMAT_R32G32B32A32_SINT:
1478 	case VK_FORMAT_R32G32B32A32_SFLOAT:
1479 	case VK_FORMAT_R64G64B64A64_SINT:
1480 	case VK_FORMAT_R64G64B64A64_SFLOAT:
1481 	case VK_FORMAT_BC4_SNORM_BLOCK:
1482 	case VK_FORMAT_BC5_SNORM_BLOCK:
1483 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1484 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1485 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1486 	// YCbCr formats treated as signed because VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY
1487 	// expects chroma components to be in range [-0.5, 0.5]
1488 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1489 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1490 		return false;
1491 	case VK_FORMAT_R8_SNORM:
1492 	case VK_FORMAT_R8_USCALED:
1493 	case VK_FORMAT_R8_SSCALED:
1494 	case VK_FORMAT_R8_SINT:
1495 	case VK_FORMAT_R16_SNORM:
1496 	case VK_FORMAT_R16_SSCALED:
1497 	case VK_FORMAT_R16_SINT:
1498 	case VK_FORMAT_R16_SFLOAT:
1499 	case VK_FORMAT_R32_SINT:
1500 	case VK_FORMAT_R32_SFLOAT:
1501 	case VK_FORMAT_R64_SINT:
1502 	case VK_FORMAT_R64_SFLOAT:
1503 		return component >= 1;
1504 	case VK_FORMAT_R8G8_SNORM:
1505 	case VK_FORMAT_R8G8_SSCALED:
1506 	case VK_FORMAT_R8G8_SINT:
1507 	case VK_FORMAT_R16G16_SNORM:
1508 	case VK_FORMAT_R16G16_SSCALED:
1509 	case VK_FORMAT_R16G16_SINT:
1510 	case VK_FORMAT_R16G16_SFLOAT:
1511 	case VK_FORMAT_R32G32_SINT:
1512 	case VK_FORMAT_R32G32_SFLOAT:
1513 	case VK_FORMAT_R64G64_SINT:
1514 	case VK_FORMAT_R64G64_SFLOAT:
1515 		return component >= 2;
1516 	case VK_FORMAT_R16G16B16_SNORM:
1517 	case VK_FORMAT_R16G16B16_SSCALED:
1518 	case VK_FORMAT_R16G16B16_SINT:
1519 	case VK_FORMAT_R16G16B16_SFLOAT:
1520 	case VK_FORMAT_R32G32B32_SINT:
1521 	case VK_FORMAT_R32G32B32_SFLOAT:
1522 	case VK_FORMAT_R64G64B64_SINT:
1523 	case VK_FORMAT_R64G64B64_SFLOAT:
1524 		return component >= 3;
1525 	default:
1526 		UNSUPPORTED("Format: %d", int(format));
1527 	}
1528 
1529 	return false;
1530 }
1531 
bytes() const1532 size_t Format::bytes() const
1533 {
1534 	switch(format)
1535 	{
1536 	case VK_FORMAT_UNDEFINED:
1537 		return 0;
1538 	case VK_FORMAT_R4G4_UNORM_PACK8:
1539 		return 1;
1540 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1541 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1542 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
1543 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
1544 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
1545 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
1546 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1547 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1548 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1549 		return 2;
1550 	case VK_FORMAT_R8_UNORM:
1551 	case VK_FORMAT_R8_SNORM:
1552 	case VK_FORMAT_R8_USCALED:
1553 	case VK_FORMAT_R8_SSCALED:
1554 	case VK_FORMAT_R8_UINT:
1555 	case VK_FORMAT_R8_SINT:
1556 	case VK_FORMAT_R8_SRGB:
1557 		return 1;
1558 	case VK_FORMAT_R8G8_UNORM:
1559 	case VK_FORMAT_R8G8_SNORM:
1560 	case VK_FORMAT_R8G8_USCALED:
1561 	case VK_FORMAT_R8G8_SSCALED:
1562 	case VK_FORMAT_R8G8_UINT:
1563 	case VK_FORMAT_R8G8_SINT:
1564 	case VK_FORMAT_R8G8_SRGB:
1565 		return 2;
1566 	case VK_FORMAT_R8G8B8A8_UNORM:
1567 	case VK_FORMAT_R8G8B8A8_SNORM:
1568 	case VK_FORMAT_R8G8B8A8_USCALED:
1569 	case VK_FORMAT_R8G8B8A8_SSCALED:
1570 	case VK_FORMAT_R8G8B8A8_UINT:
1571 	case VK_FORMAT_R8G8B8A8_SINT:
1572 	case VK_FORMAT_R8G8B8A8_SRGB:
1573 	case VK_FORMAT_B8G8R8A8_UNORM:
1574 	case VK_FORMAT_B8G8R8A8_SNORM:
1575 	case VK_FORMAT_B8G8R8A8_USCALED:
1576 	case VK_FORMAT_B8G8R8A8_SSCALED:
1577 	case VK_FORMAT_B8G8R8A8_UINT:
1578 	case VK_FORMAT_B8G8R8A8_SINT:
1579 	case VK_FORMAT_B8G8R8A8_SRGB:
1580 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1581 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1582 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1583 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1584 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1585 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1586 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1587 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
1588 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
1589 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1590 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1591 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1592 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
1593 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
1594 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
1595 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1596 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1597 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1598 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
1599 		return 4;
1600 	case VK_FORMAT_R16_UNORM:
1601 	case VK_FORMAT_R16_SNORM:
1602 	case VK_FORMAT_R16_USCALED:
1603 	case VK_FORMAT_R16_SSCALED:
1604 	case VK_FORMAT_R16_UINT:
1605 	case VK_FORMAT_R16_SINT:
1606 	case VK_FORMAT_R16_SFLOAT:
1607 		return 2;
1608 	case VK_FORMAT_R16G16_UNORM:
1609 	case VK_FORMAT_R16G16_SNORM:
1610 	case VK_FORMAT_R16G16_USCALED:
1611 	case VK_FORMAT_R16G16_SSCALED:
1612 	case VK_FORMAT_R16G16_UINT:
1613 	case VK_FORMAT_R16G16_SINT:
1614 	case VK_FORMAT_R16G16_SFLOAT:
1615 		return 4;
1616 	case VK_FORMAT_R16G16B16_UNORM:
1617 	case VK_FORMAT_R16G16B16_SNORM:
1618 	case VK_FORMAT_R16G16B16_USCALED:
1619 	case VK_FORMAT_R16G16B16_SSCALED:
1620 	case VK_FORMAT_R16G16B16_UINT:
1621 	case VK_FORMAT_R16G16B16_SINT:
1622 	case VK_FORMAT_R16G16B16_SFLOAT:
1623 		return 6;
1624 	case VK_FORMAT_R16G16B16A16_UNORM:
1625 	case VK_FORMAT_R16G16B16A16_SNORM:
1626 	case VK_FORMAT_R16G16B16A16_USCALED:
1627 	case VK_FORMAT_R16G16B16A16_SSCALED:
1628 	case VK_FORMAT_R16G16B16A16_UINT:
1629 	case VK_FORMAT_R16G16B16A16_SINT:
1630 	case VK_FORMAT_R16G16B16A16_SFLOAT:
1631 		return 8;
1632 	case VK_FORMAT_R32_UINT:
1633 	case VK_FORMAT_R32_SINT:
1634 	case VK_FORMAT_R32_SFLOAT:
1635 		return 4;
1636 	case VK_FORMAT_R32G32_UINT:
1637 	case VK_FORMAT_R32G32_SINT:
1638 	case VK_FORMAT_R32G32_SFLOAT:
1639 		return 8;
1640 	case VK_FORMAT_R32G32B32_UINT:
1641 	case VK_FORMAT_R32G32B32_SINT:
1642 	case VK_FORMAT_R32G32B32_SFLOAT:
1643 		return 12;
1644 	case VK_FORMAT_R32G32B32A32_UINT:
1645 	case VK_FORMAT_R32G32B32A32_SINT:
1646 	case VK_FORMAT_R32G32B32A32_SFLOAT:
1647 		return 16;
1648 	case VK_FORMAT_R64_UINT:
1649 	case VK_FORMAT_R64_SINT:
1650 	case VK_FORMAT_R64_SFLOAT:
1651 		return 8;
1652 	case VK_FORMAT_R64G64_UINT:
1653 	case VK_FORMAT_R64G64_SINT:
1654 	case VK_FORMAT_R64G64_SFLOAT:
1655 		return 16;
1656 	case VK_FORMAT_R64G64B64_UINT:
1657 	case VK_FORMAT_R64G64B64_SINT:
1658 	case VK_FORMAT_R64G64B64_SFLOAT:
1659 		return 24;
1660 	case VK_FORMAT_R64G64B64A64_UINT:
1661 	case VK_FORMAT_R64G64B64A64_SINT:
1662 	case VK_FORMAT_R64G64B64A64_SFLOAT:
1663 		return 32;
1664 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32: return 4;
1665 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32: return 4;
1666 	case VK_FORMAT_D16_UNORM: return 2;
1667 	case VK_FORMAT_X8_D24_UNORM_PACK32: return 4;
1668 	case VK_FORMAT_D32_SFLOAT: return 4;
1669 	case VK_FORMAT_S8_UINT: return 1;
1670 	case VK_FORMAT_D16_UNORM_S8_UINT: return 2;  // Separate depth and stencil planes  // TODO: ASSERT to ensure this is only called per-aspect?
1671 	case VK_FORMAT_D24_UNORM_S8_UINT: return 4;  // Combined depth and stencil planes  // TODO: ASSERT to ensure this is only called per-aspect?
1672 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
1673 		return 4;  // Separate depth and stencil planes  // TODO: ASSERT to ensure this is only called per-aspect?
1674 	// Note: Compressed formats don't return bytes per pixel,
1675 	//       since these would be fractional. The returned value
1676 	//       is bytes per pixel for 1 column, so 2 for 64 bit 4x4
1677 	//       blocks and 4 for 128 bit 4x4 blocks.
1678 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK: return 2;
1679 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK: return 2;
1680 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: return 2;
1681 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK: return 2;
1682 	case VK_FORMAT_BC2_UNORM_BLOCK: return 4;
1683 	case VK_FORMAT_BC2_SRGB_BLOCK: return 4;
1684 	case VK_FORMAT_BC3_UNORM_BLOCK: return 4;
1685 	case VK_FORMAT_BC3_SRGB_BLOCK: return 4;
1686 	case VK_FORMAT_BC4_UNORM_BLOCK: return 2;
1687 	case VK_FORMAT_BC4_SNORM_BLOCK: return 2;
1688 	case VK_FORMAT_BC5_UNORM_BLOCK: return 4;
1689 	case VK_FORMAT_BC5_SNORM_BLOCK: return 4;
1690 	case VK_FORMAT_BC6H_UFLOAT_BLOCK: return 4;
1691 	case VK_FORMAT_BC6H_SFLOAT_BLOCK: return 4;
1692 	case VK_FORMAT_BC7_UNORM_BLOCK: return 4;
1693 	case VK_FORMAT_BC7_SRGB_BLOCK: return 4;
1694 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: return 2;
1695 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK: return 2;
1696 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK: return 2;
1697 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK: return 2;
1698 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK: return 4;
1699 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK: return 4;
1700 	case VK_FORMAT_EAC_R11_UNORM_BLOCK: return 2;
1701 	case VK_FORMAT_EAC_R11_SNORM_BLOCK: return 2;
1702 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK: return 4;
1703 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK: return 4;
1704 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK: return 4;
1705 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK: return 4;
1706 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1707 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1708 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1709 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1710 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1711 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1712 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1713 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1714 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1715 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1716 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1717 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1718 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1719 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1720 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1721 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1722 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1723 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1724 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1725 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1726 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1727 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1728 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1729 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1730 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1731 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1732 		UNSUPPORTED("format: %d", int(format));
1733 		return 0;
1734 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1735 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1736 		// TODO: ASSERT to ensure this is only called per-aspect?
1737 		return 1;  // Y plane only
1738 	default:
1739 		UNSUPPORTED("Format: %d", int(format));
1740 	}
1741 
1742 	return 0;
1743 }
1744 
pitchB(int width,int border) const1745 size_t Format::pitchB(int width, int border) const
1746 {
1747 	// Render targets require 2x2 quads
1748 	width = sw::align<2>(width + 2 * border);
1749 
1750 	switch(format)
1751 	{
1752 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1753 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1754 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1755 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1756 	case VK_FORMAT_BC4_UNORM_BLOCK:
1757 	case VK_FORMAT_BC4_SNORM_BLOCK:
1758 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1759 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1760 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1761 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1762 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1763 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1764 		return 8 * ((width + 3) / 4);  // 64 bit per 4x4 block, computed per 4 rows
1765 	case VK_FORMAT_BC2_UNORM_BLOCK:
1766 	case VK_FORMAT_BC2_SRGB_BLOCK:
1767 	case VK_FORMAT_BC3_UNORM_BLOCK:
1768 	case VK_FORMAT_BC3_SRGB_BLOCK:
1769 	case VK_FORMAT_BC5_UNORM_BLOCK:
1770 	case VK_FORMAT_BC5_SNORM_BLOCK:
1771 	case VK_FORMAT_BC6H_UFLOAT_BLOCK:
1772 	case VK_FORMAT_BC6H_SFLOAT_BLOCK:
1773 	case VK_FORMAT_BC7_UNORM_BLOCK:
1774 	case VK_FORMAT_BC7_SRGB_BLOCK:
1775 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1776 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1777 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1778 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1779 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1780 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1781 		return 16 * ((width + 3) / 4);  // 128 bit per 4x4 block, computed per 4 rows
1782 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1783 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1784 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1785 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1786 		return 16 * ((width + 4) / 5);
1787 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1788 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1789 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1790 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1791 		return 16 * ((width + 5) / 6);
1792 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1793 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1794 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1795 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1796 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1797 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1798 		return 16 * ((width + 7) / 8);
1799 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1800 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1801 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1802 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1803 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1804 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1805 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1806 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1807 		return 16 * ((width + 9) / 10);
1808 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1809 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1810 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1811 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1812 		return 16 * ((width + 11) / 12);
1813 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1814 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1815 		return sw::align<16>(width);  // Y plane only  // TODO: ASSERT to ensure this is only called per-aspect?
1816 	default:
1817 		return bytes() * width;
1818 	}
1819 }
1820 
sliceBUnpadded(int width,int height,int border) const1821 size_t Format::sliceBUnpadded(int width, int height, int border) const
1822 {
1823 	// Render targets require 2x2 quads
1824 	height = sw::align<2>(height + 2 * border);
1825 
1826 	switch(format)
1827 	{
1828 	case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
1829 	case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
1830 	case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
1831 	case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
1832 	case VK_FORMAT_BC2_UNORM_BLOCK:
1833 	case VK_FORMAT_BC2_SRGB_BLOCK:
1834 	case VK_FORMAT_BC3_UNORM_BLOCK:
1835 	case VK_FORMAT_BC3_SRGB_BLOCK:
1836 	case VK_FORMAT_BC4_UNORM_BLOCK:
1837 	case VK_FORMAT_BC4_SNORM_BLOCK:
1838 	case VK_FORMAT_BC5_UNORM_BLOCK:
1839 	case VK_FORMAT_BC5_SNORM_BLOCK:
1840 	case VK_FORMAT_EAC_R11_UNORM_BLOCK:
1841 	case VK_FORMAT_EAC_R11_SNORM_BLOCK:
1842 	case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
1843 	case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
1844 	case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
1845 	case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
1846 	case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
1847 	case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
1848 	case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
1849 	case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
1850 	case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
1851 	case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
1852 	case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
1853 	case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
1854 		return pitchB(width, border) * ((height + 3) / 4);  // Pitch computed per 4 rows
1855 	case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
1856 	case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
1857 	case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
1858 	case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
1859 	case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
1860 	case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
1861 	case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
1862 	case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
1863 		return pitchB(width, border) * ((height + 4) / 5);  // Pitch computed per 5 rows
1864 	case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
1865 	case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
1866 	case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
1867 	case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
1868 	case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
1869 	case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
1870 		return pitchB(width, border) * ((height + 5) / 6);  // Pitch computed per 6 rows
1871 	case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
1872 	case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
1873 	case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
1874 	case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
1875 		return pitchB(width, border) * ((height + 7) / 8);  // Pitch computed per 8 rows
1876 	case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
1877 	case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
1878 	case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
1879 	case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
1880 		return pitchB(width, border) * ((height + 9) / 10);  // Pitch computed per 10 rows
1881 	case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
1882 	case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
1883 		return pitchB(width, border) * ((height + 11) / 12);  // Pitch computed per 12 rows
1884 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
1885 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
1886 		// "Images in this format must be defined with a width and height that is a multiple of two."
1887 		return pitchB(width, border) * (height + height / 2);  // U and V planes are 1/4 size of Y plane.
1888 	default:
1889 		return pitchB(width, border) * height;  // Pitch computed per row
1890 	}
1891 }
1892 
sliceB(int width,int height,int border) const1893 size_t Format::sliceB(int width, int height, int border) const
1894 {
1895 	return sw::align<16>(sliceBUnpadded(width, height, border) + 15);
1896 }
1897 
getScale() const1898 sw::float4 Format::getScale() const
1899 {
1900 	switch(format)
1901 	{
1902 	case VK_FORMAT_R4G4_UNORM_PACK8:
1903 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
1904 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
1905 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
1906 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
1907 		return sw::float4(0xF, 0xF, 0xF, 0xF);
1908 	case VK_FORMAT_R8_UNORM:
1909 	case VK_FORMAT_R8G8_UNORM:
1910 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
1911 	case VK_FORMAT_R8G8B8A8_UNORM:
1912 	case VK_FORMAT_B8G8R8A8_UNORM:
1913 	case VK_FORMAT_R8_SRGB:
1914 	case VK_FORMAT_R8G8_SRGB:
1915 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
1916 	case VK_FORMAT_R8G8B8A8_SRGB:
1917 	case VK_FORMAT_B8G8R8A8_SRGB:
1918 		return sw::float4(0xFF, 0xFF, 0xFF, 0xFF);
1919 	case VK_FORMAT_R8_SNORM:
1920 	case VK_FORMAT_R8G8_SNORM:
1921 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
1922 	case VK_FORMAT_R8G8B8A8_SNORM:
1923 	case VK_FORMAT_B8G8R8A8_SNORM:
1924 		return sw::float4(0x7F, 0x7F, 0x7F, 0x7F);
1925 	case VK_FORMAT_R16_UNORM:
1926 	case VK_FORMAT_R16G16_UNORM:
1927 	case VK_FORMAT_R16G16B16_UNORM:
1928 	case VK_FORMAT_R16G16B16A16_UNORM:
1929 		return sw::float4(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
1930 	case VK_FORMAT_R16_SNORM:
1931 	case VK_FORMAT_R16G16_SNORM:
1932 	case VK_FORMAT_R16G16B16_SNORM:
1933 	case VK_FORMAT_R16G16B16A16_SNORM:
1934 		return sw::float4(0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF);
1935 	case VK_FORMAT_R8_SINT:
1936 	case VK_FORMAT_R8_UINT:
1937 	case VK_FORMAT_R8G8_SINT:
1938 	case VK_FORMAT_R8G8_UINT:
1939 	case VK_FORMAT_R8G8B8A8_SINT:
1940 	case VK_FORMAT_R8G8B8A8_UINT:
1941 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
1942 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
1943 	case VK_FORMAT_B8G8R8A8_SINT:
1944 	case VK_FORMAT_B8G8R8A8_UINT:
1945 	case VK_FORMAT_R8_USCALED:
1946 	case VK_FORMAT_R8G8_USCALED:
1947 	case VK_FORMAT_R8G8B8A8_USCALED:
1948 	case VK_FORMAT_B8G8R8A8_USCALED:
1949 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
1950 	case VK_FORMAT_R8_SSCALED:
1951 	case VK_FORMAT_R8G8_SSCALED:
1952 	case VK_FORMAT_R8G8B8A8_SSCALED:
1953 	case VK_FORMAT_B8G8R8A8_SSCALED:
1954 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
1955 	case VK_FORMAT_R16_SINT:
1956 	case VK_FORMAT_R16_UINT:
1957 	case VK_FORMAT_R16G16_SINT:
1958 	case VK_FORMAT_R16G16_UINT:
1959 	case VK_FORMAT_R16G16B16A16_SINT:
1960 	case VK_FORMAT_R16G16B16A16_UINT:
1961 	case VK_FORMAT_R16_SSCALED:
1962 	case VK_FORMAT_R16G16_SSCALED:
1963 	case VK_FORMAT_R16G16B16_SSCALED:
1964 	case VK_FORMAT_R16G16B16A16_SSCALED:
1965 	case VK_FORMAT_R16_USCALED:
1966 	case VK_FORMAT_R16G16_USCALED:
1967 	case VK_FORMAT_R16G16B16_USCALED:
1968 	case VK_FORMAT_R16G16B16A16_USCALED:
1969 	case VK_FORMAT_R32_SINT:
1970 	case VK_FORMAT_R32_UINT:
1971 	case VK_FORMAT_R32G32_SINT:
1972 	case VK_FORMAT_R32G32_UINT:
1973 	case VK_FORMAT_R32G32B32_SINT:
1974 	case VK_FORMAT_R32G32B32_UINT:
1975 	case VK_FORMAT_R32G32B32A32_SINT:
1976 	case VK_FORMAT_R32G32B32A32_UINT:
1977 	case VK_FORMAT_R32G32B32A32_SFLOAT:
1978 	case VK_FORMAT_R32G32B32_SFLOAT:
1979 	case VK_FORMAT_R32G32_SFLOAT:
1980 	case VK_FORMAT_R32_SFLOAT:
1981 	case VK_FORMAT_R16G16B16A16_SFLOAT:
1982 	case VK_FORMAT_R16G16B16_SFLOAT:
1983 	case VK_FORMAT_R16G16_SFLOAT:
1984 	case VK_FORMAT_R16_SFLOAT:
1985 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
1986 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
1987 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
1988 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
1989 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
1990 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
1991 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
1992 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
1993 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1994 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
1995 		return sw::float4(1.0f, 1.0f, 1.0f, 1.0f);
1996 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
1997 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
1998 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
1999 		return sw::float4(0x1F, 0x1F, 0x1F, 0x01);
2000 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2001 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2002 		return sw::float4(0x1F, 0x3F, 0x1F, 1.0f);
2003 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2004 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2005 		return sw::float4(0x3FF, 0x3FF, 0x3FF, 0x03);
2006 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
2007 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
2008 		return sw::float4(0x1FF, 0x1FF, 0x1FF, 0x01);
2009 	case VK_FORMAT_D16_UNORM:
2010 		return sw::float4(0xFFFF, 0.0f, 0.0f, 0.0f);
2011 	case VK_FORMAT_D24_UNORM_S8_UINT:
2012 	case VK_FORMAT_X8_D24_UNORM_PACK32:
2013 		return sw::float4(0xFFFFFF, 0.0f, 0.0f, 0.0f);
2014 	case VK_FORMAT_D32_SFLOAT:
2015 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
2016 	case VK_FORMAT_S8_UINT:
2017 		return sw::float4(1.0f, 1.0f, 1.0f, 1.0f);
2018 	default:
2019 		UNSUPPORTED("format %d", int(format));
2020 		break;
2021 	}
2022 
2023 	return sw::float4(1.0f, 1.0f, 1.0f, 1.0f);
2024 }
2025 
bitsPerComponent() const2026 sw::int4 Format::bitsPerComponent() const
2027 {
2028 	switch(format)
2029 	{
2030 	case VK_FORMAT_R4G4_UNORM_PACK8:
2031 		return sw::int4(4, 4, 0, 0);
2032 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2033 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2034 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2035 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2036 		return sw::int4(4, 4, 4, 4);
2037 	case VK_FORMAT_R8_UNORM:
2038 	case VK_FORMAT_R8_SNORM:
2039 	case VK_FORMAT_R8_SRGB:
2040 	case VK_FORMAT_R8_SINT:
2041 	case VK_FORMAT_R8_UINT:
2042 	case VK_FORMAT_R8_USCALED:
2043 	case VK_FORMAT_R8_SSCALED:
2044 	case VK_FORMAT_S8_UINT:
2045 		return sw::int4(8, 0, 0, 0);
2046 	case VK_FORMAT_R8G8_SRGB:
2047 	case VK_FORMAT_R8G8_UNORM:
2048 	case VK_FORMAT_R8G8_SNORM:
2049 	case VK_FORMAT_R8G8_SINT:
2050 	case VK_FORMAT_R8G8_UINT:
2051 	case VK_FORMAT_R8G8_USCALED:
2052 	case VK_FORMAT_R8G8_SSCALED:
2053 		return sw::int4(8, 8, 0, 0);
2054 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2055 	case VK_FORMAT_R8G8B8A8_UNORM:
2056 	case VK_FORMAT_B8G8R8A8_UNORM:
2057 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2058 	case VK_FORMAT_R8G8B8A8_SRGB:
2059 	case VK_FORMAT_B8G8R8A8_SRGB:
2060 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2061 	case VK_FORMAT_R8G8B8A8_SNORM:
2062 	case VK_FORMAT_B8G8R8A8_SNORM:
2063 	case VK_FORMAT_R8G8B8A8_SINT:
2064 	case VK_FORMAT_R8G8B8A8_UINT:
2065 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2066 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2067 	case VK_FORMAT_B8G8R8A8_SINT:
2068 	case VK_FORMAT_B8G8R8A8_UINT:
2069 	case VK_FORMAT_R8G8B8A8_USCALED:
2070 	case VK_FORMAT_B8G8R8A8_USCALED:
2071 	case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
2072 	case VK_FORMAT_R8G8B8A8_SSCALED:
2073 	case VK_FORMAT_B8G8R8A8_SSCALED:
2074 	case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
2075 		return sw::int4(8, 8, 8, 8);
2076 	case VK_FORMAT_R16_UNORM:
2077 	case VK_FORMAT_R16_SNORM:
2078 	case VK_FORMAT_R16_SINT:
2079 	case VK_FORMAT_R16_UINT:
2080 	case VK_FORMAT_R16_SSCALED:
2081 	case VK_FORMAT_R16_USCALED:
2082 	case VK_FORMAT_R16_SFLOAT:
2083 	case VK_FORMAT_D16_UNORM:
2084 		return sw::int4(16, 0, 0, 0);
2085 	case VK_FORMAT_R16G16_UNORM:
2086 	case VK_FORMAT_R16G16_SNORM:
2087 	case VK_FORMAT_R16G16_SINT:
2088 	case VK_FORMAT_R16G16_UINT:
2089 	case VK_FORMAT_R16G16_SSCALED:
2090 	case VK_FORMAT_R16G16_USCALED:
2091 	case VK_FORMAT_R16G16_SFLOAT:
2092 		return sw::int4(16, 16, 0, 0);
2093 	case VK_FORMAT_R16G16B16_UNORM:
2094 	case VK_FORMAT_R16G16B16_SNORM:
2095 	case VK_FORMAT_R16G16B16_SSCALED:
2096 	case VK_FORMAT_R16G16B16_USCALED:
2097 	case VK_FORMAT_R16G16B16_SFLOAT:
2098 		return sw::int4(16, 16, 16, 0);
2099 	case VK_FORMAT_R16G16B16A16_UNORM:
2100 	case VK_FORMAT_R16G16B16A16_SNORM:
2101 	case VK_FORMAT_R16G16B16A16_SINT:
2102 	case VK_FORMAT_R16G16B16A16_UINT:
2103 	case VK_FORMAT_R16G16B16A16_SSCALED:
2104 	case VK_FORMAT_R16G16B16A16_USCALED:
2105 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2106 		return sw::int4(16, 16, 16, 16);
2107 	case VK_FORMAT_D24_UNORM_S8_UINT:
2108 	case VK_FORMAT_X8_D24_UNORM_PACK32:
2109 		return sw::int4(24, 0, 0, 0);
2110 	case VK_FORMAT_R32_SINT:
2111 	case VK_FORMAT_R32_UINT:
2112 	case VK_FORMAT_R32_SFLOAT:
2113 	case VK_FORMAT_D32_SFLOAT:
2114 	case VK_FORMAT_D32_SFLOAT_S8_UINT:
2115 		return sw::int4(32, 0, 0, 0);
2116 	case VK_FORMAT_R32G32_SINT:
2117 	case VK_FORMAT_R32G32_UINT:
2118 	case VK_FORMAT_R32G32_SFLOAT:
2119 		return sw::int4(32, 32, 0, 0);
2120 	case VK_FORMAT_R32G32B32_SINT:
2121 	case VK_FORMAT_R32G32B32_UINT:
2122 	case VK_FORMAT_R32G32B32_SFLOAT:
2123 		return sw::int4(32, 32, 32, 0);
2124 	case VK_FORMAT_R32G32B32A32_SINT:
2125 	case VK_FORMAT_R32G32B32A32_UINT:
2126 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2127 		return sw::int4(32, 32, 32, 32);
2128 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2129 		return sw::int4(11, 11, 10, 0);
2130 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2131 		return sw::int4(9, 9, 9, 0);
2132 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2133 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2134 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2135 		return sw::int4(5, 5, 5, 1);
2136 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2137 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2138 		return sw::int4(5, 6, 5, 0);
2139 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2140 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2141 	case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
2142 	case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
2143 	case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
2144 	case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
2145 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2146 	case VK_FORMAT_A2R10G10B10_SINT_PACK32:
2147 	case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
2148 	case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
2149 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2150 	case VK_FORMAT_A2B10G10R10_SINT_PACK32:
2151 		return sw::int4(10, 10, 10, 2);
2152 	default:
2153 		UNSUPPORTED("format %d", int(format));
2154 		break;
2155 	}
2156 
2157 	return sw::int4(0, 0, 0, 0);
2158 }
2159 
supportsColorAttachmentBlend() const2160 bool Format::supportsColorAttachmentBlend() const
2161 {
2162 	switch(format)
2163 	{
2164 	// Vulkan 1.1 mandatory
2165 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2166 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2167 	case VK_FORMAT_R8_UNORM:
2168 	case VK_FORMAT_R8G8_UNORM:
2169 	case VK_FORMAT_R8G8B8A8_UNORM:
2170 	case VK_FORMAT_R8G8B8A8_SRGB:
2171 	case VK_FORMAT_B8G8R8A8_UNORM:
2172 	case VK_FORMAT_B8G8R8A8_SRGB:
2173 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2174 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2175 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2176 	case VK_FORMAT_R16_SFLOAT:
2177 	case VK_FORMAT_R16G16_SFLOAT:
2178 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2179 	// Optional
2180 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2181 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2182 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2183 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2184 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2185 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2186 	case VK_FORMAT_R16_UNORM:
2187 	case VK_FORMAT_R16G16_UNORM:
2188 	case VK_FORMAT_R16G16B16A16_UNORM:
2189 	case VK_FORMAT_R32_SFLOAT:
2190 	case VK_FORMAT_R32G32_SFLOAT:
2191 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2192 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2193 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2194 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2195 		return true;
2196 	default:
2197 		return false;
2198 	}
2199 }
2200 
has16bitPackedTextureFormat() const2201 bool Format::has16bitPackedTextureFormat() const
2202 {
2203 	if(bytes() != 2)
2204 	{
2205 		return false;
2206 	}
2207 
2208 	switch(format)
2209 	{
2210 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2211 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2212 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2213 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2214 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2215 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2216 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2217 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2218 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2219 		return true;
2220 	case VK_FORMAT_R8G8_SINT:
2221 	case VK_FORMAT_R8G8_UINT:
2222 	case VK_FORMAT_R8G8_UNORM:
2223 	case VK_FORMAT_R8G8_SNORM:
2224 	case VK_FORMAT_R8G8_SRGB:
2225 	case VK_FORMAT_R16_UNORM:
2226 	case VK_FORMAT_R16_SNORM:
2227 	case VK_FORMAT_R16_SINT:
2228 	case VK_FORMAT_R16_UINT:
2229 	case VK_FORMAT_R16_SFLOAT:
2230 	case VK_FORMAT_D16_UNORM:
2231 		return false;
2232 	default:
2233 		UNSUPPORTED("Format: %d", int(format));
2234 	}
2235 
2236 	return false;
2237 }
2238 
has8bitTextureComponents() const2239 bool Format::has8bitTextureComponents() const
2240 {
2241 	switch(format)
2242 	{
2243 	case VK_FORMAT_R8_UNORM:
2244 	case VK_FORMAT_R8_SNORM:
2245 	case VK_FORMAT_R8_UINT:
2246 	case VK_FORMAT_R8_SINT:
2247 	case VK_FORMAT_R8_SRGB:
2248 	case VK_FORMAT_R8G8_UNORM:
2249 	case VK_FORMAT_R8G8_SNORM:
2250 	case VK_FORMAT_R8G8_UINT:
2251 	case VK_FORMAT_R8G8_SINT:
2252 	case VK_FORMAT_R8G8_SRGB:
2253 	case VK_FORMAT_R8G8B8A8_UNORM:
2254 	case VK_FORMAT_R8G8B8A8_SNORM:
2255 	case VK_FORMAT_R8G8B8A8_UINT:
2256 	case VK_FORMAT_R8G8B8A8_SINT:
2257 	case VK_FORMAT_R8G8B8A8_SRGB:
2258 	case VK_FORMAT_B8G8R8A8_UNORM:
2259 	case VK_FORMAT_B8G8R8A8_SNORM:
2260 	case VK_FORMAT_B8G8R8A8_UINT:
2261 	case VK_FORMAT_B8G8R8A8_SINT:
2262 	case VK_FORMAT_B8G8R8A8_SRGB:
2263 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2264 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2265 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2266 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2267 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2268 	case VK_FORMAT_S8_UINT:
2269 		return true;
2270 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2271 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2272 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2273 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2274 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2275 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2276 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2277 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2278 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2279 	case VK_FORMAT_R32_SFLOAT:
2280 	case VK_FORMAT_R32G32_SFLOAT:
2281 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2282 	case VK_FORMAT_R16_UNORM:
2283 	case VK_FORMAT_R16_SNORM:
2284 	case VK_FORMAT_R16G16_UNORM:
2285 	case VK_FORMAT_R16G16_SNORM:
2286 	case VK_FORMAT_R16G16B16A16_UNORM:
2287 	case VK_FORMAT_R16G16B16A16_SNORM:
2288 	case VK_FORMAT_R32_SINT:
2289 	case VK_FORMAT_R32_UINT:
2290 	case VK_FORMAT_R32G32_SINT:
2291 	case VK_FORMAT_R32G32_UINT:
2292 	case VK_FORMAT_R32G32B32A32_SINT:
2293 	case VK_FORMAT_R32G32B32A32_UINT:
2294 	case VK_FORMAT_R16_SINT:
2295 	case VK_FORMAT_R16_UINT:
2296 	case VK_FORMAT_R16_SFLOAT:
2297 	case VK_FORMAT_R16G16_SINT:
2298 	case VK_FORMAT_R16G16_UINT:
2299 	case VK_FORMAT_R16G16_SFLOAT:
2300 	case VK_FORMAT_R16G16B16A16_SINT:
2301 	case VK_FORMAT_R16G16B16A16_UINT:
2302 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2303 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
2304 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
2305 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2306 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2307 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2308 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2309 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2310 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2311 	case VK_FORMAT_D16_UNORM:
2312 		return false;
2313 	default:
2314 		UNSUPPORTED("Format: %d", int(format));
2315 	}
2316 
2317 	return false;
2318 }
2319 
has16bitTextureComponents() const2320 bool Format::has16bitTextureComponents() const
2321 {
2322 	switch(format)
2323 	{
2324 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2325 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2326 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2327 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2328 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2329 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2330 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2331 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2332 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2333 	case VK_FORMAT_R8_UNORM:
2334 	case VK_FORMAT_R8_SNORM:
2335 	case VK_FORMAT_R8_UINT:
2336 	case VK_FORMAT_R8_SINT:
2337 	case VK_FORMAT_R8_SRGB:
2338 	case VK_FORMAT_R8G8_UNORM:
2339 	case VK_FORMAT_R8G8_SNORM:
2340 	case VK_FORMAT_R8G8_UINT:
2341 	case VK_FORMAT_R8G8_SINT:
2342 	case VK_FORMAT_R8G8_SRGB:
2343 	case VK_FORMAT_R8G8B8A8_UNORM:
2344 	case VK_FORMAT_R8G8B8A8_SNORM:
2345 	case VK_FORMAT_R8G8B8A8_UINT:
2346 	case VK_FORMAT_R8G8B8A8_SINT:
2347 	case VK_FORMAT_R8G8B8A8_SRGB:
2348 	case VK_FORMAT_B8G8R8A8_UNORM:
2349 	case VK_FORMAT_B8G8R8A8_SNORM:
2350 	case VK_FORMAT_B8G8R8A8_UINT:
2351 	case VK_FORMAT_B8G8R8A8_SINT:
2352 	case VK_FORMAT_B8G8R8A8_SRGB:
2353 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2354 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2355 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2356 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2357 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2358 	case VK_FORMAT_R32_UINT:
2359 	case VK_FORMAT_R32_SINT:
2360 	case VK_FORMAT_R32_SFLOAT:
2361 	case VK_FORMAT_R32G32_UINT:
2362 	case VK_FORMAT_R32G32_SINT:
2363 	case VK_FORMAT_R32G32_SFLOAT:
2364 	case VK_FORMAT_R32G32B32A32_UINT:
2365 	case VK_FORMAT_R32G32B32A32_SINT:
2366 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2367 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
2368 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
2369 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2370 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2371 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2372 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2373 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2374 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2375 	case VK_FORMAT_S8_UINT:
2376 		return false;
2377 	case VK_FORMAT_R16_UNORM:
2378 	case VK_FORMAT_R16_SNORM:
2379 	case VK_FORMAT_R16_UINT:
2380 	case VK_FORMAT_R16_SINT:
2381 	case VK_FORMAT_R16_SFLOAT:
2382 	case VK_FORMAT_R16G16_UNORM:
2383 	case VK_FORMAT_R16G16_SNORM:
2384 	case VK_FORMAT_R16G16_UINT:
2385 	case VK_FORMAT_R16G16_SINT:
2386 	case VK_FORMAT_R16G16_SFLOAT:
2387 	case VK_FORMAT_R16G16B16A16_UNORM:
2388 	case VK_FORMAT_R16G16B16A16_SNORM:
2389 	case VK_FORMAT_R16G16B16A16_UINT:
2390 	case VK_FORMAT_R16G16B16A16_SINT:
2391 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2392 	case VK_FORMAT_D16_UNORM:
2393 		return true;
2394 	default:
2395 		UNSUPPORTED("Format: %d", int(format));
2396 	}
2397 
2398 	return false;
2399 }
2400 
has32bitIntegerTextureComponents() const2401 bool Format::has32bitIntegerTextureComponents() const
2402 {
2403 	switch(format)
2404 	{
2405 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2406 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2407 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2408 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2409 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2410 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2411 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2412 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2413 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2414 	case VK_FORMAT_R8_UNORM:
2415 	case VK_FORMAT_R8_SNORM:
2416 	case VK_FORMAT_R8_UINT:
2417 	case VK_FORMAT_R8_SINT:
2418 	case VK_FORMAT_R8_SRGB:
2419 	case VK_FORMAT_R8G8_UNORM:
2420 	case VK_FORMAT_R8G8_SNORM:
2421 	case VK_FORMAT_R8G8_UINT:
2422 	case VK_FORMAT_R8G8_SINT:
2423 	case VK_FORMAT_R8G8_SRGB:
2424 	case VK_FORMAT_R8G8B8A8_UNORM:
2425 	case VK_FORMAT_R8G8B8A8_SNORM:
2426 	case VK_FORMAT_R8G8B8A8_UINT:
2427 	case VK_FORMAT_R8G8B8A8_SINT:
2428 	case VK_FORMAT_R8G8B8A8_SRGB:
2429 	case VK_FORMAT_B8G8R8A8_UNORM:
2430 	case VK_FORMAT_B8G8R8A8_SNORM:
2431 	case VK_FORMAT_B8G8R8A8_UINT:
2432 	case VK_FORMAT_B8G8R8A8_SINT:
2433 	case VK_FORMAT_B8G8R8A8_SRGB:
2434 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2435 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2436 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2437 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2438 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2439 	case VK_FORMAT_R16_UNORM:
2440 	case VK_FORMAT_R16_SNORM:
2441 	case VK_FORMAT_R16_UINT:
2442 	case VK_FORMAT_R16_SINT:
2443 	case VK_FORMAT_R16_SFLOAT:
2444 	case VK_FORMAT_R16G16_UNORM:
2445 	case VK_FORMAT_R16G16_SNORM:
2446 	case VK_FORMAT_R16G16_UINT:
2447 	case VK_FORMAT_R16G16_SINT:
2448 	case VK_FORMAT_R16G16_SFLOAT:
2449 	case VK_FORMAT_R16G16B16A16_UNORM:
2450 	case VK_FORMAT_R16G16B16A16_SNORM:
2451 	case VK_FORMAT_R16G16B16A16_UINT:
2452 	case VK_FORMAT_R16G16B16A16_SINT:
2453 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2454 	case VK_FORMAT_R32_SFLOAT:
2455 	case VK_FORMAT_R32G32_SFLOAT:
2456 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2457 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
2458 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
2459 	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
2460 	case VK_FORMAT_A2B10G10R10_UINT_PACK32:
2461 	case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
2462 	case VK_FORMAT_A2R10G10B10_UINT_PACK32:
2463 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2464 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2465 	case VK_FORMAT_D16_UNORM:
2466 	case VK_FORMAT_S8_UINT:
2467 		return false;
2468 	case VK_FORMAT_R32_SINT:
2469 	case VK_FORMAT_R32_UINT:
2470 	case VK_FORMAT_R32G32_SINT:
2471 	case VK_FORMAT_R32G32_UINT:
2472 	case VK_FORMAT_R32G32B32A32_SINT:
2473 	case VK_FORMAT_R32G32B32A32_UINT:
2474 		return true;
2475 	default:
2476 		UNSUPPORTED("Format: %d", int(format));
2477 	}
2478 
2479 	return false;
2480 }
2481 
isRGBComponent(int component) const2482 bool Format::isRGBComponent(int component) const
2483 {
2484 	switch(format)
2485 	{
2486 	case VK_FORMAT_R8_UNORM:
2487 	case VK_FORMAT_R8_SNORM:
2488 	case VK_FORMAT_R8_UINT:
2489 	case VK_FORMAT_R8_SINT:
2490 	case VK_FORMAT_R8_SRGB:
2491 	case VK_FORMAT_R16_UNORM:
2492 	case VK_FORMAT_R16_SNORM:
2493 	case VK_FORMAT_R16_UINT:
2494 	case VK_FORMAT_R16_SINT:
2495 	case VK_FORMAT_R16_SFLOAT:
2496 	case VK_FORMAT_R32_UINT:
2497 	case VK_FORMAT_R32_SINT:
2498 	case VK_FORMAT_R32_SFLOAT:
2499 		return component < 1;
2500 	case VK_FORMAT_R8G8_UNORM:
2501 	case VK_FORMAT_R8G8_SNORM:
2502 	case VK_FORMAT_R8G8_UINT:
2503 	case VK_FORMAT_R8G8_SINT:
2504 	case VK_FORMAT_R8G8_SRGB:
2505 	case VK_FORMAT_R16G16_UNORM:
2506 	case VK_FORMAT_R16G16_SNORM:
2507 	case VK_FORMAT_R16G16_UINT:
2508 	case VK_FORMAT_R16G16_SINT:
2509 	case VK_FORMAT_R16G16_SFLOAT:
2510 	case VK_FORMAT_R32G32_UINT:
2511 	case VK_FORMAT_R32G32_SINT:
2512 	case VK_FORMAT_R32G32_SFLOAT:
2513 		return component < 2;
2514 	case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
2515 	case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
2516 	case VK_FORMAT_R5G6B5_UNORM_PACK16:
2517 	case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
2518 	case VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT:
2519 	case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
2520 	case VK_FORMAT_B5G6R5_UNORM_PACK16:
2521 	case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
2522 	case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
2523 	case VK_FORMAT_R8G8B8A8_UNORM:
2524 	case VK_FORMAT_R8G8B8A8_SNORM:
2525 	case VK_FORMAT_R8G8B8A8_UINT:
2526 	case VK_FORMAT_R8G8B8A8_SINT:
2527 	case VK_FORMAT_R8G8B8A8_SRGB:
2528 	case VK_FORMAT_B8G8R8A8_UNORM:
2529 	case VK_FORMAT_B8G8R8A8_SNORM:
2530 	case VK_FORMAT_B8G8R8A8_UINT:
2531 	case VK_FORMAT_B8G8R8A8_SINT:
2532 	case VK_FORMAT_B8G8R8A8_SRGB:
2533 	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
2534 	case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
2535 	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
2536 	case VK_FORMAT_A8B8G8R8_SINT_PACK32:
2537 	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
2538 	case VK_FORMAT_R16G16B16A16_UNORM:
2539 	case VK_FORMAT_R16G16B16A16_SINT:
2540 	case VK_FORMAT_R16G16B16A16_UINT:
2541 	case VK_FORMAT_R16G16B16A16_SFLOAT:
2542 	case VK_FORMAT_R32G32B32A32_SINT:
2543 	case VK_FORMAT_R32G32B32A32_UINT:
2544 	case VK_FORMAT_R32G32B32A32_SFLOAT:
2545 	case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
2546 	case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
2547 	case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
2548 	case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2549 		return component < 3;
2550 	case VK_FORMAT_D32_SFLOAT:
2551 	case VK_FORMAT_D16_UNORM:
2552 	case VK_FORMAT_S8_UINT:
2553 		return false;
2554 	default:
2555 		UNSUPPORTED("Format: %d", int(format));
2556 	}
2557 
2558 	return false;
2559 }
2560 
pack(VkFormat format)2561 static constexpr uint8_t pack(VkFormat format)
2562 {
2563 	if(format > VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT)
2564 	{
2565 		return 0;
2566 	}
2567 
2568 	// 0 - 184 direct mapping
2569 	if(format >= 0 && format <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK)
2570 	{
2571 		return uint8_t(format);
2572 	}
2573 
2574 	// 10001560xx -> 185 - 218
2575 	if(format >= VK_FORMAT_G8B8G8R8_422_UNORM && format <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM)
2576 	{
2577 		return uint8_t(format - VK_FORMAT_G8B8G8R8_422_UNORM + 185);
2578 	}
2579 
2580 	// 100005400x -> 219 - 226
2581 	if(format >= VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG && format <= VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG)
2582 	{
2583 		return uint8_t(format - VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG + 219);
2584 	}
2585 
2586 	// 10000660xx -> 227 - 240
2587 	if(format >= VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT && format <= VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT)
2588 	{
2589 		return uint8_t(format - VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT + 227);
2590 	}
2591 
2592 	// 100034000x -> 241 - 242
2593 	if(format >= VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT && format <= VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT)
2594 	{
2595 		return uint8_t(format - VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT + 241);
2596 	}
2597 
2598 	return 0;
2599 }
2600 
2601 static_assert(pack(VK_FORMAT_UNDEFINED) == 0, "Incorrect VkFormat packed value");
2602 static_assert(pack(VK_FORMAT_ASTC_12x12_SRGB_BLOCK) == 184, "Incorrect VkFormat packed value");
2603 static_assert(pack(VK_FORMAT_G8B8G8R8_422_UNORM) == 185, "Incorrect VkFormat packed value");
2604 static_assert(pack(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM) == 218, "Incorrect VkFormat packed value");
2605 static_assert(pack(VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG) == 219, "Incorrect VkFormat packed value");
2606 static_assert(pack(VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG) == 226, "Incorrect VkFormat packed value");
2607 static_assert(pack(VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT) == 227, "Incorrect VkFormat packed value");
2608 static_assert(pack(VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT) == 240, "Incorrect VkFormat packed value");
2609 static_assert(pack(VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT) == 241, "Incorrect VkFormat packed value");
2610 static_assert(pack(VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT) == 242, "Incorrect VkFormat packed value");
2611 
unpack(uint8_t format)2612 static constexpr VkFormat unpack(uint8_t format)
2613 {
2614 	// 0 - 184 direct mapping
2615 	if(format >= 0 && format <= 184)
2616 	{
2617 		return static_cast<VkFormat>(format);
2618 	}
2619 
2620 	// 185 - 218 -> 10001560xx
2621 	if(format >= 185 && format <= 218)
2622 	{
2623 		return static_cast<VkFormat>(VK_FORMAT_G8B8G8R8_422_UNORM + (format - 185));
2624 	}
2625 
2626 	// 219 - 226 -> 100005400x
2627 	if(format >= 219 && format <= 226)
2628 	{
2629 		return static_cast<VkFormat>(VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG + (format - 219));
2630 	}
2631 
2632 	// 227 - 240 -> 10000660xx
2633 	if(format >= 227 && format <= 240)
2634 	{
2635 		return static_cast<VkFormat>(VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT + (format - 227));
2636 	}
2637 
2638 	// 241 - 242 -> 100034000x
2639 	if(format >= 241 && format <= 242)
2640 	{
2641 		return static_cast<VkFormat>(VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT + (format - 241));
2642 	}
2643 
2644 	return VK_FORMAT_UNDEFINED;
2645 }
2646 
2647 static_assert(unpack(0) == VK_FORMAT_UNDEFINED, "Incorrect VkFormat unpacked value");
2648 static_assert(unpack(184) == VK_FORMAT_ASTC_12x12_SRGB_BLOCK, "Incorrect VkFormat unpacked value");
2649 static_assert(unpack(185) == VK_FORMAT_G8B8G8R8_422_UNORM, "Incorrect VkFormat unpacked value");
2650 static_assert(unpack(218) == VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM, "Incorrect VkFormat unpacked value");
2651 static_assert(unpack(219) == VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG, "Incorrect VkFormat unpacked value");
2652 static_assert(unpack(226) == VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG, "Incorrect VkFormat unpacked value");
2653 static_assert(unpack(227) == VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT, "Incorrect VkFormat unpacked value");
2654 static_assert(unpack(240) == VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT, "Incorrect VkFormat unpacked value");
2655 static_assert(unpack(241) == VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT, "Incorrect VkFormat unpacked value");
2656 static_assert(unpack(242) == VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT, "Incorrect VkFormat unpacked value");
2657 static_assert(unpack(243) == VK_FORMAT_UNDEFINED, "Incorrect VkFormat unpacked value");
2658 
mapTo8bit(VkFormat format)2659 uint8_t Format::mapTo8bit(VkFormat format)
2660 {
2661 	ASSERT(format <= VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT);
2662 	uint8_t packed = pack(format);
2663 	ASSERT_MSG(packed > 0, "Update VkFormat to uint8_t mapping");
2664 	return packed;
2665 }
2666 
mapFrom8bit(uint8_t format)2667 VkFormat Format::mapFrom8bit(uint8_t format)
2668 {
2669 	ASSERT(format <= 242);
2670 	VkFormat unpacked = unpack(format);
2671 	ASSERT_MSG(unpacked != VK_FORMAT_UNDEFINED, "Update uint8_t to VkFormat mapping");
2672 	return unpacked;
2673 }
2674 
2675 }  // namespace vk
2676