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