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