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