radv/formats: reverse how the image format properties KHR2 is handled
[mesa.git] / src / amd / vulkan / radv_formats.c
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #include "radv_private.h"
26
27 #include "vk_format.h"
28 #include "sid.h"
29 #include "r600d_common.h"
30
31 #include "util/u_half.h"
32 #include "util/format_srgb.h"
33 #include "util/format_r11g11b10f.h"
34
35 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
36 int first_non_void)
37 {
38 unsigned type;
39 int i;
40
41 if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
42 return V_008F0C_BUF_DATA_FORMAT_10_11_11;
43
44 if (first_non_void < 0)
45 return V_008F0C_BUF_DATA_FORMAT_INVALID;
46 type = desc->channel[first_non_void].type;
47
48 if (type == VK_FORMAT_TYPE_FIXED)
49 return V_008F0C_BUF_DATA_FORMAT_INVALID;
50 if (desc->nr_channels == 4 &&
51 desc->channel[0].size == 10 &&
52 desc->channel[1].size == 10 &&
53 desc->channel[2].size == 10 &&
54 desc->channel[3].size == 2)
55 return V_008F0C_BUF_DATA_FORMAT_2_10_10_10;
56
57 /* See whether the components are of the same size. */
58 for (i = 0; i < desc->nr_channels; i++) {
59 if (desc->channel[first_non_void].size != desc->channel[i].size)
60 return V_008F0C_BUF_DATA_FORMAT_INVALID;
61 }
62
63 switch (desc->channel[first_non_void].size) {
64 case 8:
65 switch (desc->nr_channels) {
66 case 1:
67 return V_008F0C_BUF_DATA_FORMAT_8;
68 case 2:
69 return V_008F0C_BUF_DATA_FORMAT_8_8;
70 case 4:
71 return V_008F0C_BUF_DATA_FORMAT_8_8_8_8;
72 }
73 break;
74 case 16:
75 switch (desc->nr_channels) {
76 case 1:
77 return V_008F0C_BUF_DATA_FORMAT_16;
78 case 2:
79 return V_008F0C_BUF_DATA_FORMAT_16_16;
80 case 4:
81 return V_008F0C_BUF_DATA_FORMAT_16_16_16_16;
82 }
83 break;
84 case 32:
85 /* From the Southern Islands ISA documentation about MTBUF:
86 * 'Memory reads of data in memory that is 32 or 64 bits do not
87 * undergo any format conversion.'
88 */
89 if (type != VK_FORMAT_TYPE_FLOAT &&
90 !desc->channel[first_non_void].pure_integer)
91 return V_008F0C_BUF_DATA_FORMAT_INVALID;
92
93 switch (desc->nr_channels) {
94 case 1:
95 return V_008F0C_BUF_DATA_FORMAT_32;
96 case 2:
97 return V_008F0C_BUF_DATA_FORMAT_32_32;
98 case 3:
99 return V_008F0C_BUF_DATA_FORMAT_32_32_32;
100 case 4:
101 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32;
102 }
103 break;
104 }
105
106 return V_008F0C_BUF_DATA_FORMAT_INVALID;
107 }
108
109 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
110 int first_non_void)
111 {
112 if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
113 return V_008F0C_BUF_NUM_FORMAT_FLOAT;
114
115 if (first_non_void < 0)
116 return ~0;
117
118 switch (desc->channel[first_non_void].type) {
119 case VK_FORMAT_TYPE_SIGNED:
120 if (desc->channel[first_non_void].normalized)
121 return V_008F0C_BUF_NUM_FORMAT_SNORM;
122 else if (desc->channel[first_non_void].pure_integer)
123 return V_008F0C_BUF_NUM_FORMAT_SINT;
124 else
125 return V_008F0C_BUF_NUM_FORMAT_SSCALED;
126 break;
127 case VK_FORMAT_TYPE_UNSIGNED:
128 if (desc->channel[first_non_void].normalized)
129 return V_008F0C_BUF_NUM_FORMAT_UNORM;
130 else if (desc->channel[first_non_void].pure_integer)
131 return V_008F0C_BUF_NUM_FORMAT_UINT;
132 else
133 return V_008F0C_BUF_NUM_FORMAT_USCALED;
134 break;
135 case VK_FORMAT_TYPE_FLOAT:
136 default:
137 return V_008F0C_BUF_NUM_FORMAT_FLOAT;
138 }
139 }
140
141 uint32_t radv_translate_tex_dataformat(VkFormat format,
142 const struct vk_format_description *desc,
143 int first_non_void)
144 {
145 bool uniform = true;
146 int i;
147
148 if (!desc)
149 return ~0;
150 /* Colorspace (return non-RGB formats directly). */
151 switch (desc->colorspace) {
152 /* Depth stencil formats */
153 case VK_FORMAT_COLORSPACE_ZS:
154 switch (format) {
155 case VK_FORMAT_D16_UNORM:
156 return V_008F14_IMG_DATA_FORMAT_16;
157 case VK_FORMAT_D24_UNORM_S8_UINT:
158 case VK_FORMAT_X8_D24_UNORM_PACK32:
159 return V_008F14_IMG_DATA_FORMAT_8_24;
160 case VK_FORMAT_S8_UINT:
161 return V_008F14_IMG_DATA_FORMAT_8;
162 case VK_FORMAT_D32_SFLOAT:
163 return V_008F14_IMG_DATA_FORMAT_32;
164 case VK_FORMAT_D32_SFLOAT_S8_UINT:
165 return V_008F14_IMG_DATA_FORMAT_X24_8_32;
166 default:
167 goto out_unknown;
168 }
169
170 case VK_FORMAT_COLORSPACE_YUV:
171 goto out_unknown; /* TODO */
172
173 case VK_FORMAT_COLORSPACE_SRGB:
174 if (desc->nr_channels != 4 && desc->nr_channels != 1)
175 goto out_unknown;
176 break;
177
178 default:
179 break;
180 }
181
182 if (desc->layout == VK_FORMAT_LAYOUT_RGTC) {
183 switch(format) {
184 case VK_FORMAT_BC4_UNORM_BLOCK:
185 case VK_FORMAT_BC4_SNORM_BLOCK:
186 return V_008F14_IMG_DATA_FORMAT_BC4;
187 case VK_FORMAT_BC5_UNORM_BLOCK:
188 case VK_FORMAT_BC5_SNORM_BLOCK:
189 return V_008F14_IMG_DATA_FORMAT_BC5;
190 default:
191 break;
192 }
193 }
194
195 if (desc->layout == VK_FORMAT_LAYOUT_S3TC) {
196 switch(format) {
197 case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
198 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
199 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
200 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
201 return V_008F14_IMG_DATA_FORMAT_BC1;
202 case VK_FORMAT_BC2_UNORM_BLOCK:
203 case VK_FORMAT_BC2_SRGB_BLOCK:
204 return V_008F14_IMG_DATA_FORMAT_BC2;
205 case VK_FORMAT_BC3_UNORM_BLOCK:
206 case VK_FORMAT_BC3_SRGB_BLOCK:
207 return V_008F14_IMG_DATA_FORMAT_BC3;
208 default:
209 break;
210 }
211 }
212
213 if (desc->layout == VK_FORMAT_LAYOUT_BPTC) {
214 switch(format) {
215 case VK_FORMAT_BC6H_UFLOAT_BLOCK:
216 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
217 return V_008F14_IMG_DATA_FORMAT_BC6;
218 case VK_FORMAT_BC7_UNORM_BLOCK:
219 case VK_FORMAT_BC7_SRGB_BLOCK:
220 return V_008F14_IMG_DATA_FORMAT_BC7;
221 default:
222 break;
223 }
224 }
225
226 if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
227 return V_008F14_IMG_DATA_FORMAT_5_9_9_9;
228 } else if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
229 return V_008F14_IMG_DATA_FORMAT_10_11_11;
230 }
231
232 /* R8G8Bx_SNORM - TODO CxV8U8 */
233
234 /* hw cannot support mixed formats (except depth/stencil, since only
235 * depth is read).*/
236 if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
237 goto out_unknown;
238
239 /* See whether the components are of the same size. */
240 for (i = 1; i < desc->nr_channels; i++) {
241 uniform = uniform && desc->channel[0].size == desc->channel[i].size;
242 }
243
244 /* Non-uniform formats. */
245 if (!uniform) {
246 switch(desc->nr_channels) {
247 case 3:
248 if (desc->channel[0].size == 5 &&
249 desc->channel[1].size == 6 &&
250 desc->channel[2].size == 5) {
251 return V_008F14_IMG_DATA_FORMAT_5_6_5;
252 }
253 goto out_unknown;
254 case 4:
255 if (desc->channel[0].size == 5 &&
256 desc->channel[1].size == 5 &&
257 desc->channel[2].size == 5 &&
258 desc->channel[3].size == 1) {
259 return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
260 }
261 if (desc->channel[0].size == 1 &&
262 desc->channel[1].size == 5 &&
263 desc->channel[2].size == 5 &&
264 desc->channel[3].size == 5) {
265 return V_008F14_IMG_DATA_FORMAT_5_5_5_1;
266 }
267 if (desc->channel[0].size == 10 &&
268 desc->channel[1].size == 10 &&
269 desc->channel[2].size == 10 &&
270 desc->channel[3].size == 2) {
271 /* Closed VK driver does this also no 2/10/10/10 snorm */
272 if (desc->channel[0].type == VK_FORMAT_TYPE_SIGNED &&
273 desc->channel[0].normalized)
274 goto out_unknown;
275 return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
276 }
277 goto out_unknown;
278 }
279 goto out_unknown;
280 }
281
282 if (first_non_void < 0 || first_non_void > 3)
283 goto out_unknown;
284
285 /* uniform formats */
286 switch (desc->channel[first_non_void].size) {
287 case 4:
288 switch (desc->nr_channels) {
289 #if 0 /* Not supported for render targets */
290 case 2:
291 return V_008F14_IMG_DATA_FORMAT_4_4;
292 #endif
293 case 4:
294 return V_008F14_IMG_DATA_FORMAT_4_4_4_4;
295 }
296 break;
297 case 8:
298 switch (desc->nr_channels) {
299 case 1:
300 return V_008F14_IMG_DATA_FORMAT_8;
301 case 2:
302 return V_008F14_IMG_DATA_FORMAT_8_8;
303 case 4:
304 return V_008F14_IMG_DATA_FORMAT_8_8_8_8;
305 }
306 break;
307 case 16:
308 switch (desc->nr_channels) {
309 case 1:
310 return V_008F14_IMG_DATA_FORMAT_16;
311 case 2:
312 return V_008F14_IMG_DATA_FORMAT_16_16;
313 case 4:
314 return V_008F14_IMG_DATA_FORMAT_16_16_16_16;
315 }
316 break;
317 case 32:
318 switch (desc->nr_channels) {
319 case 1:
320 return V_008F14_IMG_DATA_FORMAT_32;
321 case 2:
322 return V_008F14_IMG_DATA_FORMAT_32_32;
323 #if 0 /* Not supported for render targets */
324 case 3:
325 return V_008F14_IMG_DATA_FORMAT_32_32_32;
326 #endif
327 case 4:
328 return V_008F14_IMG_DATA_FORMAT_32_32_32_32;
329 }
330 }
331
332 out_unknown:
333 /* R600_ERR("Unable to handle texformat %d %s\n", format, vk_format_name(format)); */
334 return ~0;
335 }
336
337 uint32_t radv_translate_tex_numformat(VkFormat format,
338 const struct vk_format_description *desc,
339 int first_non_void)
340 {
341 switch (format) {
342 case VK_FORMAT_D24_UNORM_S8_UINT:
343 return V_008F14_IMG_NUM_FORMAT_UNORM;
344 default:
345 if (first_non_void < 0) {
346 if (vk_format_is_compressed(format)) {
347 switch (format) {
348 case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
349 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
350 case VK_FORMAT_BC2_SRGB_BLOCK:
351 case VK_FORMAT_BC3_SRGB_BLOCK:
352 case VK_FORMAT_BC7_SRGB_BLOCK:
353 return V_008F14_IMG_NUM_FORMAT_SRGB;
354 case VK_FORMAT_BC4_SNORM_BLOCK:
355 case VK_FORMAT_BC5_SNORM_BLOCK:
356 case VK_FORMAT_BC6H_SFLOAT_BLOCK:
357 return V_008F14_IMG_NUM_FORMAT_SNORM;
358 default:
359 return V_008F14_IMG_NUM_FORMAT_UNORM;
360 }
361 } else if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
362 return V_008F14_IMG_NUM_FORMAT_UNORM;
363 } else {
364 return V_008F14_IMG_NUM_FORMAT_FLOAT;
365 }
366 } else if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
367 return V_008F14_IMG_NUM_FORMAT_SRGB;
368 } else {
369 switch (desc->channel[first_non_void].type) {
370 case VK_FORMAT_TYPE_FLOAT:
371 return V_008F14_IMG_NUM_FORMAT_FLOAT;
372 case VK_FORMAT_TYPE_SIGNED:
373 if (desc->channel[first_non_void].normalized)
374 return V_008F14_IMG_NUM_FORMAT_SNORM;
375 else if (desc->channel[first_non_void].pure_integer)
376 return V_008F14_IMG_NUM_FORMAT_SINT;
377 else
378 return V_008F14_IMG_NUM_FORMAT_SSCALED;
379 case VK_FORMAT_TYPE_UNSIGNED:
380 if (desc->channel[first_non_void].normalized)
381 return V_008F14_IMG_NUM_FORMAT_UNORM;
382 else if (desc->channel[first_non_void].pure_integer)
383 return V_008F14_IMG_NUM_FORMAT_UINT;
384 else
385 return V_008F14_IMG_NUM_FORMAT_USCALED;
386 default:
387 return V_008F14_IMG_NUM_FORMAT_UNORM;
388 }
389 }
390 }
391 }
392
393 uint32_t radv_translate_color_numformat(VkFormat format,
394 const struct vk_format_description *desc,
395 int first_non_void)
396 {
397 unsigned ntype;
398 if (first_non_void == -1 || desc->channel[first_non_void].type == VK_FORMAT_TYPE_FLOAT)
399 ntype = V_028C70_NUMBER_FLOAT;
400 else {
401 ntype = V_028C70_NUMBER_UNORM;
402 if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB)
403 ntype = V_028C70_NUMBER_SRGB;
404 else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_SIGNED) {
405 if (desc->channel[first_non_void].pure_integer) {
406 ntype = V_028C70_NUMBER_SINT;
407 } else if (desc->channel[first_non_void].normalized) {
408 ntype = V_028C70_NUMBER_SNORM;
409 } else
410 ntype = ~0u;
411 } else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_UNSIGNED) {
412 if (desc->channel[first_non_void].pure_integer) {
413 ntype = V_028C70_NUMBER_UINT;
414 } else if (desc->channel[first_non_void].normalized) {
415 ntype = V_028C70_NUMBER_UNORM;
416 } else
417 ntype = ~0u;
418 }
419 }
420 return ntype;
421 }
422
423 static bool radv_is_sampler_format_supported(VkFormat format, bool *linear_sampling)
424 {
425 const struct vk_format_description *desc = vk_format_description(format);
426 uint32_t num_format;
427 if (!desc || format == VK_FORMAT_UNDEFINED)
428 return false;
429 num_format = radv_translate_tex_numformat(format, desc,
430 vk_format_get_first_non_void_channel(format));
431
432 if (num_format == V_008F14_IMG_NUM_FORMAT_USCALED ||
433 num_format == V_008F14_IMG_NUM_FORMAT_SSCALED)
434 return false;
435
436 if (num_format == V_008F14_IMG_NUM_FORMAT_UNORM ||
437 num_format == V_008F14_IMG_NUM_FORMAT_SNORM ||
438 num_format == V_008F14_IMG_NUM_FORMAT_FLOAT ||
439 num_format == V_008F14_IMG_NUM_FORMAT_SRGB)
440 *linear_sampling = true;
441 else
442 *linear_sampling = false;
443 return radv_translate_tex_dataformat(format, vk_format_description(format),
444 vk_format_get_first_non_void_channel(format)) != ~0U;
445 }
446
447
448 static bool radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,
449 VkFormat format)
450 {
451 const struct vk_format_description *desc = vk_format_description(format);
452 unsigned data_format, num_format;
453 if (!desc || format == VK_FORMAT_UNDEFINED)
454 return false;
455
456 data_format = radv_translate_tex_dataformat(format, desc,
457 vk_format_get_first_non_void_channel(format));
458 num_format = radv_translate_tex_numformat(format, desc,
459 vk_format_get_first_non_void_channel(format));
460
461 if(data_format == ~0 || num_format == ~0)
462 return false;
463
464 /* Extracted from the GCN3 ISA document. */
465 switch(num_format) {
466 case V_008F14_IMG_NUM_FORMAT_UNORM:
467 case V_008F14_IMG_NUM_FORMAT_SNORM:
468 case V_008F14_IMG_NUM_FORMAT_UINT:
469 case V_008F14_IMG_NUM_FORMAT_SINT:
470 case V_008F14_IMG_NUM_FORMAT_FLOAT:
471 break;
472 default:
473 return false;
474 }
475
476 switch(data_format) {
477 case V_008F14_IMG_DATA_FORMAT_8:
478 case V_008F14_IMG_DATA_FORMAT_16:
479 case V_008F14_IMG_DATA_FORMAT_8_8:
480 case V_008F14_IMG_DATA_FORMAT_32:
481 case V_008F14_IMG_DATA_FORMAT_16_16:
482 case V_008F14_IMG_DATA_FORMAT_10_11_11:
483 case V_008F14_IMG_DATA_FORMAT_11_11_10:
484 case V_008F14_IMG_DATA_FORMAT_10_10_10_2:
485 case V_008F14_IMG_DATA_FORMAT_2_10_10_10:
486 case V_008F14_IMG_DATA_FORMAT_8_8_8_8:
487 case V_008F14_IMG_DATA_FORMAT_32_32:
488 case V_008F14_IMG_DATA_FORMAT_16_16_16_16:
489 case V_008F14_IMG_DATA_FORMAT_32_32_32_32:
490 case V_008F14_IMG_DATA_FORMAT_5_6_5:
491 case V_008F14_IMG_DATA_FORMAT_1_5_5_5:
492 case V_008F14_IMG_DATA_FORMAT_5_5_5_1:
493 case V_008F14_IMG_DATA_FORMAT_4_4_4_4:
494 /* TODO: FMASK formats. */
495 return true;
496 default:
497 return false;
498 }
499 }
500
501 static bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
502 {
503 const struct vk_format_description *desc = vk_format_description(format);
504 unsigned data_format, num_format;
505 if (!desc || format == VK_FORMAT_UNDEFINED)
506 return false;
507
508 data_format = radv_translate_buffer_dataformat(desc,
509 vk_format_get_first_non_void_channel(format));
510 num_format = radv_translate_buffer_numformat(desc,
511 vk_format_get_first_non_void_channel(format));
512
513 *scaled = (num_format == V_008F0C_BUF_NUM_FORMAT_SSCALED) || (num_format == V_008F0C_BUF_NUM_FORMAT_USCALED);
514 return data_format != V_008F0C_BUF_DATA_FORMAT_INVALID &&
515 num_format != ~0;
516 }
517
518 bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable)
519 {
520 const struct vk_format_description *desc = vk_format_description(format);
521 uint32_t color_format = radv_translate_colorformat(format);
522 uint32_t color_swap = radv_translate_colorswap(format, false);
523 uint32_t color_num_format = radv_translate_color_numformat(format,
524 desc,
525 vk_format_get_first_non_void_channel(format));
526
527 if (color_num_format == V_028C70_NUMBER_UINT || color_num_format == V_028C70_NUMBER_SINT ||
528 color_format == V_028C70_COLOR_8_24 || color_format == V_028C70_COLOR_24_8 ||
529 color_format == V_028C70_COLOR_X24_8_32_FLOAT) {
530 *blendable = false;
531 } else
532 *blendable = true;
533 return color_format != V_028C70_COLOR_INVALID &&
534 color_swap != ~0U &&
535 color_num_format != ~0;
536 }
537
538 static bool radv_is_zs_format_supported(VkFormat format)
539 {
540 return radv_translate_dbformat(format) != V_028040_Z_INVALID || format == VK_FORMAT_S8_UINT;
541 }
542
543 static void
544 radv_physical_device_get_format_properties(struct radv_physical_device *physical_device,
545 VkFormat format,
546 VkFormatProperties *out_properties)
547 {
548 VkFormatFeatureFlags linear = 0, tiled = 0, buffer = 0;
549 const struct vk_format_description *desc = vk_format_description(format);
550 bool blendable;
551 bool scaled = false;
552 if (!desc) {
553 out_properties->linearTilingFeatures = linear;
554 out_properties->optimalTilingFeatures = tiled;
555 out_properties->bufferFeatures = buffer;
556 return;
557 }
558
559 if (radv_is_storage_image_format_supported(physical_device, format)) {
560 tiled |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
561 linear |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
562 }
563
564 if (radv_is_buffer_format_supported(format, &scaled)) {
565 buffer |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
566 if (!scaled)
567 buffer |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT |
568 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
569 }
570
571 if (vk_format_is_depth_or_stencil(format)) {
572 if (radv_is_zs_format_supported(format)) {
573 tiled |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
574 tiled |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
575 tiled |= VK_FORMAT_FEATURE_BLIT_SRC_BIT |
576 VK_FORMAT_FEATURE_BLIT_DST_BIT;
577 tiled |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR |
578 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR;
579 }
580 } else {
581 bool linear_sampling;
582 if (radv_is_sampler_format_supported(format, &linear_sampling)) {
583 linear |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
584 VK_FORMAT_FEATURE_BLIT_SRC_BIT;
585 tiled |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
586 VK_FORMAT_FEATURE_BLIT_SRC_BIT;
587 if (linear_sampling) {
588 linear |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
589 tiled |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
590 }
591 }
592 if (radv_is_colorbuffer_format_supported(format, &blendable)) {
593 linear |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
594 tiled |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
595 if (blendable) {
596 linear |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
597 tiled |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
598 }
599 }
600 if (tiled && util_is_power_of_two(vk_format_get_blocksize(format)) && !scaled) {
601 tiled |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR |
602 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR;
603 }
604 }
605
606 if (linear && util_is_power_of_two(vk_format_get_blocksize(format)) && !scaled) {
607 linear |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR |
608 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR;
609 }
610
611 if (format == VK_FORMAT_R32_UINT || format == VK_FORMAT_R32_SINT) {
612 buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
613 linear |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
614 tiled |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
615 }
616
617 out_properties->linearTilingFeatures = linear;
618 out_properties->optimalTilingFeatures = tiled;
619 out_properties->bufferFeatures = buffer;
620 }
621
622 uint32_t radv_translate_colorformat(VkFormat format)
623 {
624 const struct vk_format_description *desc = vk_format_description(format);
625
626 #define HAS_SIZE(x,y,z,w) \
627 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
628 desc->channel[2].size == (z) && desc->channel[3].size == (w))
629
630 if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) /* isn't plain */
631 return V_028C70_COLOR_10_11_11;
632
633 if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
634 return V_028C70_COLOR_INVALID;
635
636 /* hw cannot support mixed formats (except depth/stencil, since
637 * stencil is not written to). */
638 if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
639 return V_028C70_COLOR_INVALID;
640
641 switch (desc->nr_channels) {
642 case 1:
643 switch (desc->channel[0].size) {
644 case 8:
645 return V_028C70_COLOR_8;
646 case 16:
647 return V_028C70_COLOR_16;
648 case 32:
649 return V_028C70_COLOR_32;
650 }
651 break;
652 case 2:
653 if (desc->channel[0].size == desc->channel[1].size) {
654 switch (desc->channel[0].size) {
655 case 8:
656 return V_028C70_COLOR_8_8;
657 case 16:
658 return V_028C70_COLOR_16_16;
659 case 32:
660 return V_028C70_COLOR_32_32;
661 }
662 } else if (HAS_SIZE(8,24,0,0)) {
663 return V_028C70_COLOR_24_8;
664 } else if (HAS_SIZE(24,8,0,0)) {
665 return V_028C70_COLOR_8_24;
666 }
667 break;
668 case 3:
669 if (HAS_SIZE(5,6,5,0)) {
670 return V_028C70_COLOR_5_6_5;
671 } else if (HAS_SIZE(32,8,24,0)) {
672 return V_028C70_COLOR_X24_8_32_FLOAT;
673 }
674 break;
675 case 4:
676 if (desc->channel[0].size == desc->channel[1].size &&
677 desc->channel[0].size == desc->channel[2].size &&
678 desc->channel[0].size == desc->channel[3].size) {
679 switch (desc->channel[0].size) {
680 case 4:
681 return V_028C70_COLOR_4_4_4_4;
682 case 8:
683 return V_028C70_COLOR_8_8_8_8;
684 case 16:
685 return V_028C70_COLOR_16_16_16_16;
686 case 32:
687 return V_028C70_COLOR_32_32_32_32;
688 }
689 } else if (HAS_SIZE(5,5,5,1)) {
690 return V_028C70_COLOR_1_5_5_5;
691 } else if (HAS_SIZE(1,5,5,5)) {
692 return V_028C70_COLOR_5_5_5_1;
693 } else if (HAS_SIZE(10,10,10,2)) {
694 return V_028C70_COLOR_2_10_10_10;
695 }
696 break;
697 }
698 return V_028C70_COLOR_INVALID;
699 }
700
701 uint32_t radv_colorformat_endian_swap(uint32_t colorformat)
702 {
703 if (0/*SI_BIG_ENDIAN*/) {
704 switch(colorformat) {
705 /* 8-bit buffers. */
706 case V_028C70_COLOR_8:
707 return V_028C70_ENDIAN_NONE;
708
709 /* 16-bit buffers. */
710 case V_028C70_COLOR_5_6_5:
711 case V_028C70_COLOR_1_5_5_5:
712 case V_028C70_COLOR_4_4_4_4:
713 case V_028C70_COLOR_16:
714 case V_028C70_COLOR_8_8:
715 return V_028C70_ENDIAN_8IN16;
716
717 /* 32-bit buffers. */
718 case V_028C70_COLOR_8_8_8_8:
719 case V_028C70_COLOR_2_10_10_10:
720 case V_028C70_COLOR_8_24:
721 case V_028C70_COLOR_24_8:
722 case V_028C70_COLOR_16_16:
723 return V_028C70_ENDIAN_8IN32;
724
725 /* 64-bit buffers. */
726 case V_028C70_COLOR_16_16_16_16:
727 return V_028C70_ENDIAN_8IN16;
728
729 case V_028C70_COLOR_32_32:
730 return V_028C70_ENDIAN_8IN32;
731
732 /* 128-bit buffers. */
733 case V_028C70_COLOR_32_32_32_32:
734 return V_028C70_ENDIAN_8IN32;
735 default:
736 return V_028C70_ENDIAN_NONE; /* Unsupported. */
737 }
738 } else {
739 return V_028C70_ENDIAN_NONE;
740 }
741 }
742
743 uint32_t radv_translate_dbformat(VkFormat format)
744 {
745 switch (format) {
746 case VK_FORMAT_D16_UNORM:
747 case VK_FORMAT_D16_UNORM_S8_UINT:
748 return V_028040_Z_16;
749 case VK_FORMAT_D32_SFLOAT:
750 case VK_FORMAT_D32_SFLOAT_S8_UINT:
751 return V_028040_Z_32_FLOAT;
752 default:
753 return V_028040_Z_INVALID;
754 }
755 }
756
757 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap)
758 {
759 const struct vk_format_description *desc = vk_format_description(format);
760
761 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == VK_SWIZZLE_##swz)
762
763 if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
764 return V_0280A0_SWAP_STD;
765
766 if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
767 return ~0U;
768
769 switch (desc->nr_channels) {
770 case 1:
771 if (HAS_SWIZZLE(0,X))
772 return V_0280A0_SWAP_STD; /* X___ */
773 else if (HAS_SWIZZLE(3,X))
774 return V_0280A0_SWAP_ALT_REV; /* ___X */
775 break;
776 case 2:
777 if ((HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,Y)) ||
778 (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,NONE)) ||
779 (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y)))
780 return V_0280A0_SWAP_STD; /* XY__ */
781 else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) ||
782 (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,NONE)) ||
783 (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X)))
784 /* YX__ */
785 return (do_endian_swap ? V_0280A0_SWAP_STD : V_0280A0_SWAP_STD_REV);
786 else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y))
787 return V_0280A0_SWAP_ALT; /* X__Y */
788 else if (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(3,X))
789 return V_0280A0_SWAP_ALT_REV; /* Y__X */
790 break;
791 case 3:
792 if (HAS_SWIZZLE(0,X))
793 return (do_endian_swap ? V_0280A0_SWAP_STD_REV : V_0280A0_SWAP_STD);
794 else if (HAS_SWIZZLE(0,Z))
795 return V_0280A0_SWAP_STD_REV; /* ZYX */
796 break;
797 case 4:
798 /* check the middle channels, the 1st and 4th channel can be NONE */
799 if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,Z)) {
800 return V_0280A0_SWAP_STD; /* XYZW */
801 } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,Y)) {
802 return V_0280A0_SWAP_STD_REV; /* WZYX */
803 } else if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,X)) {
804 return V_0280A0_SWAP_ALT; /* ZYXW */
805 } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,W)) {
806 /* YZWX */
807 if (desc->is_array)
808 return V_0280A0_SWAP_ALT_REV;
809 else
810 return (do_endian_swap ? V_0280A0_SWAP_ALT : V_0280A0_SWAP_ALT_REV);
811 }
812 break;
813 }
814 return ~0U;
815 }
816
817 bool radv_format_pack_clear_color(VkFormat format,
818 uint32_t clear_vals[2],
819 VkClearColorValue *value)
820 {
821 uint8_t r = 0, g = 0, b = 0, a = 0;
822 const struct vk_format_description *desc = vk_format_description(format);
823
824 if (vk_format_get_component_bits(format, VK_FORMAT_COLORSPACE_RGB, 0) <= 8) {
825 if (desc->colorspace == VK_FORMAT_COLORSPACE_RGB) {
826 r = float_to_ubyte(value->float32[0]);
827 g = float_to_ubyte(value->float32[1]);
828 b = float_to_ubyte(value->float32[2]);
829 a = float_to_ubyte(value->float32[3]);
830 } else if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
831 r = util_format_linear_float_to_srgb_8unorm(value->float32[0]);
832 g = util_format_linear_float_to_srgb_8unorm(value->float32[1]);
833 b = util_format_linear_float_to_srgb_8unorm(value->float32[2]);
834 a = float_to_ubyte(value->float32[3]);
835 }
836 }
837 switch (format) {
838 case VK_FORMAT_R8_UNORM:
839 case VK_FORMAT_R8_SRGB:
840 clear_vals[0] = r;
841 clear_vals[1] = 0;
842 break;
843 case VK_FORMAT_R8G8_UNORM:
844 case VK_FORMAT_R8G8_SRGB:
845 clear_vals[0] = r | g << 8;
846 clear_vals[1] = 0;
847 break;
848 case VK_FORMAT_R8G8B8A8_SRGB:
849 case VK_FORMAT_R8G8B8A8_UNORM:
850 clear_vals[0] = r | g << 8 | b << 16 | a << 24;
851 clear_vals[1] = 0;
852 break;
853 case VK_FORMAT_B8G8R8A8_SRGB:
854 case VK_FORMAT_B8G8R8A8_UNORM:
855 clear_vals[0] = b | g << 8 | r << 16 | a << 24;
856 clear_vals[1] = 0;
857 break;
858 case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
859 case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
860 clear_vals[0] = r | g << 8 | b << 16 | a << 24;
861 clear_vals[1] = 0;
862 break;
863 case VK_FORMAT_R8_UINT:
864 clear_vals[0] = value->uint32[0] & 0xff;
865 clear_vals[1] = 0;
866 break;
867 case VK_FORMAT_R8_SINT:
868 clear_vals[0] = value->int32[0] & 0xff;
869 clear_vals[1] = 0;
870 break;
871 case VK_FORMAT_R16_UINT:
872 clear_vals[0] = value->uint32[0] & 0xffff;
873 clear_vals[1] = 0;
874 break;
875 case VK_FORMAT_R8G8_UINT:
876 clear_vals[0] = value->uint32[0] & 0xff;
877 clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
878 clear_vals[1] = 0;
879 break;
880 case VK_FORMAT_R8G8_SINT:
881 clear_vals[0] = value->int32[0] & 0xff;
882 clear_vals[0] |= (value->int32[1] & 0xff) << 8;
883 clear_vals[1] = 0;
884 break;
885 case VK_FORMAT_R8G8B8A8_UINT:
886 clear_vals[0] = value->uint32[0] & 0xff;
887 clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
888 clear_vals[0] |= (value->uint32[2] & 0xff) << 16;
889 clear_vals[0] |= (value->uint32[3] & 0xff) << 24;
890 clear_vals[1] = 0;
891 break;
892 case VK_FORMAT_R8G8B8A8_SINT:
893 clear_vals[0] = value->int32[0] & 0xff;
894 clear_vals[0] |= (value->int32[1] & 0xff) << 8;
895 clear_vals[0] |= (value->int32[2] & 0xff) << 16;
896 clear_vals[0] |= (value->int32[3] & 0xff) << 24;
897 clear_vals[1] = 0;
898 break;
899 case VK_FORMAT_A8B8G8R8_UINT_PACK32:
900 clear_vals[0] = value->uint32[0] & 0xff;
901 clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
902 clear_vals[0] |= (value->uint32[2] & 0xff) << 16;
903 clear_vals[0] |= (value->uint32[3] & 0xff) << 24;
904 clear_vals[1] = 0;
905 break;
906 case VK_FORMAT_R16G16_UINT:
907 clear_vals[0] = value->uint32[0] & 0xffff;
908 clear_vals[0] |= (value->uint32[1] & 0xffff) << 16;
909 clear_vals[1] = 0;
910 break;
911 case VK_FORMAT_R16G16B16A16_UINT:
912 clear_vals[0] = value->uint32[0] & 0xffff;
913 clear_vals[0] |= (value->uint32[1] & 0xffff) << 16;
914 clear_vals[1] = value->uint32[2] & 0xffff;
915 clear_vals[1] |= (value->uint32[3] & 0xffff) << 16;
916 break;
917 case VK_FORMAT_R32_UINT:
918 clear_vals[0] = value->uint32[0];
919 clear_vals[1] = 0;
920 break;
921 case VK_FORMAT_R32G32_UINT:
922 clear_vals[0] = value->uint32[0];
923 clear_vals[1] = value->uint32[1];
924 break;
925 case VK_FORMAT_R32_SINT:
926 clear_vals[0] = value->int32[0];
927 clear_vals[1] = 0;
928 break;
929 case VK_FORMAT_R16_SFLOAT:
930 clear_vals[0] = util_float_to_half(value->float32[0]);
931 clear_vals[1] = 0;
932 break;
933 case VK_FORMAT_R16G16_SFLOAT:
934 clear_vals[0] = util_float_to_half(value->float32[0]);
935 clear_vals[0] |= (uint32_t)util_float_to_half(value->float32[1]) << 16;
936 clear_vals[1] = 0;
937 break;
938 case VK_FORMAT_R16G16B16A16_SFLOAT:
939 clear_vals[0] = util_float_to_half(value->float32[0]);
940 clear_vals[0] |= (uint32_t)util_float_to_half(value->float32[1]) << 16;
941 clear_vals[1] = util_float_to_half(value->float32[2]);
942 clear_vals[1] |= (uint32_t)util_float_to_half(value->float32[3]) << 16;
943 break;
944 case VK_FORMAT_R16_UNORM:
945 clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
946 clear_vals[1] = 0;
947 break;
948 case VK_FORMAT_R16G16_UNORM:
949 clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
950 clear_vals[0] |= ((uint16_t)util_iround(CLAMP(value->float32[1], 0.0f, 1.0f) * 0xffff)) << 16;
951 clear_vals[1] = 0;
952 break;
953 case VK_FORMAT_R16G16B16A16_UNORM:
954 clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
955 clear_vals[0] |= ((uint16_t)util_iround(CLAMP(value->float32[1], 0.0f, 1.0f) * 0xffff)) << 16;
956 clear_vals[1] = ((uint16_t)util_iround(CLAMP(value->float32[2], 0.0f, 1.0f) * 0xffff)) & 0xffff;
957 clear_vals[1] |= ((uint16_t)util_iround(CLAMP(value->float32[3], 0.0f, 1.0f) * 0xffff)) << 16;
958 break;
959 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
960 clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0x3ff)) & 0x3ff;
961 clear_vals[0] |= (((uint16_t)util_iround(CLAMP(value->float32[1], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 10;
962 clear_vals[0] |= (((uint16_t)util_iround(CLAMP(value->float32[2], 0.0f, 1.0f) * 0x3ff)) & 0x3ff) << 20;
963 clear_vals[0] |= (((uint16_t)util_iround(CLAMP(value->float32[3], 0.0f, 1.0f) * 0x3)) & 0x3) << 30;
964 clear_vals[1] = 0;
965 return true;
966 case VK_FORMAT_R32G32_SFLOAT:
967 clear_vals[0] = fui(value->float32[0]);
968 clear_vals[1] = fui(value->float32[1]);
969 break;
970 case VK_FORMAT_R32_SFLOAT:
971 clear_vals[1] = 0;
972 clear_vals[0] = fui(value->float32[0]);
973 break;
974 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
975 clear_vals[0] = float3_to_r11g11b10f(value->float32);
976 clear_vals[1] = 0;
977 break;
978 default:
979 fprintf(stderr, "failed to fast clear %d\n", format);
980 return false;
981 }
982 return true;
983 }
984
985 void radv_GetPhysicalDeviceFormatProperties(
986 VkPhysicalDevice physicalDevice,
987 VkFormat format,
988 VkFormatProperties* pFormatProperties)
989 {
990 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
991
992 radv_physical_device_get_format_properties(physical_device,
993 format,
994 pFormatProperties);
995 }
996
997 void radv_GetPhysicalDeviceFormatProperties2KHR(
998 VkPhysicalDevice physicalDevice,
999 VkFormat format,
1000 VkFormatProperties2KHR* pFormatProperties)
1001 {
1002 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1003
1004 radv_physical_device_get_format_properties(physical_device,
1005 format,
1006 &pFormatProperties->formatProperties);
1007 }
1008
1009 static VkResult radv_get_image_format_properties(struct radv_physical_device *physical_device,
1010 const VkPhysicalDeviceImageFormatInfo2KHR *info,
1011 VkImageFormatProperties *pImageFormatProperties)
1012
1013 {
1014 VkFormatProperties format_props;
1015 VkFormatFeatureFlags format_feature_flags;
1016 VkExtent3D maxExtent;
1017 uint32_t maxMipLevels;
1018 uint32_t maxArraySize;
1019 VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
1020
1021 radv_physical_device_get_format_properties(physical_device, info->format,
1022 &format_props);
1023 if (info->tiling == VK_IMAGE_TILING_LINEAR) {
1024 format_feature_flags = format_props.linearTilingFeatures;
1025 } else if (info->tiling == VK_IMAGE_TILING_OPTIMAL) {
1026 format_feature_flags = format_props.optimalTilingFeatures;
1027 } else {
1028 unreachable("bad VkImageTiling");
1029 }
1030
1031 if (format_feature_flags == 0)
1032 goto unsupported;
1033
1034 switch (info->type) {
1035 default:
1036 unreachable("bad vkimage type\n");
1037 case VK_IMAGE_TYPE_1D:
1038 maxExtent.width = 16384;
1039 maxExtent.height = 1;
1040 maxExtent.depth = 1;
1041 maxMipLevels = 15; /* log2(maxWidth) + 1 */
1042 maxArraySize = 2048;
1043 break;
1044 case VK_IMAGE_TYPE_2D:
1045 maxExtent.width = 16384;
1046 maxExtent.height = 16384;
1047 maxExtent.depth = 1;
1048 maxMipLevels = 15; /* log2(maxWidth) + 1 */
1049 maxArraySize = 2048;
1050 break;
1051 case VK_IMAGE_TYPE_3D:
1052 maxExtent.width = 2048;
1053 maxExtent.height = 2048;
1054 maxExtent.depth = 2048;
1055 maxMipLevels = 12; /* log2(maxWidth) + 1 */
1056 maxArraySize = 1;
1057 break;
1058 }
1059
1060 if (info->tiling == VK_IMAGE_TILING_OPTIMAL &&
1061 info->type == VK_IMAGE_TYPE_2D &&
1062 (format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
1063 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) &&
1064 !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
1065 !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
1066 sampleCounts |= VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT | VK_SAMPLE_COUNT_8_BIT;
1067 }
1068
1069 if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
1070 if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
1071 goto unsupported;
1072 }
1073 }
1074
1075 if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) {
1076 if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) {
1077 goto unsupported;
1078 }
1079 }
1080
1081 if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
1082 if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
1083 goto unsupported;
1084 }
1085 }
1086
1087 if (info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
1088 if (!(format_feature_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
1089 goto unsupported;
1090 }
1091 }
1092
1093 *pImageFormatProperties = (VkImageFormatProperties) {
1094 .maxExtent = maxExtent,
1095 .maxMipLevels = maxMipLevels,
1096 .maxArrayLayers = maxArraySize,
1097 .sampleCounts = sampleCounts,
1098
1099 /* FINISHME: Accurately calculate
1100 * VkImageFormatProperties::maxResourceSize.
1101 */
1102 .maxResourceSize = UINT32_MAX,
1103 };
1104
1105 return VK_SUCCESS;
1106 unsupported:
1107 *pImageFormatProperties = (VkImageFormatProperties) {
1108 .maxExtent = { 0, 0, 0 },
1109 .maxMipLevels = 0,
1110 .maxArrayLayers = 0,
1111 .sampleCounts = 0,
1112 .maxResourceSize = 0,
1113 };
1114
1115 return VK_ERROR_FORMAT_NOT_SUPPORTED;
1116 }
1117
1118 VkResult radv_GetPhysicalDeviceImageFormatProperties(
1119 VkPhysicalDevice physicalDevice,
1120 VkFormat format,
1121 VkImageType type,
1122 VkImageTiling tiling,
1123 VkImageUsageFlags usage,
1124 VkImageCreateFlags createFlags,
1125 VkImageFormatProperties* pImageFormatProperties)
1126 {
1127 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1128
1129 const VkPhysicalDeviceImageFormatInfo2KHR info = {
1130 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
1131 .pNext = NULL,
1132 .format = format,
1133 .type = type,
1134 .tiling = tiling,
1135 .usage = usage,
1136 .flags = createFlags,
1137 };
1138
1139 return radv_get_image_format_properties(physical_device, &info,
1140 pImageFormatProperties);
1141 }
1142
1143 VkResult radv_GetPhysicalDeviceImageFormatProperties2KHR(
1144 VkPhysicalDevice physicalDevice,
1145 const VkPhysicalDeviceImageFormatInfo2KHR *base_info,
1146 VkImageFormatProperties2KHR *base_props)
1147 {
1148 RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1149 return radv_get_image_format_properties(physical_device, base_info,
1150 &base_props->imageFormatProperties);
1151 }
1152
1153 void radv_GetPhysicalDeviceSparseImageFormatProperties(
1154 VkPhysicalDevice physicalDevice,
1155 VkFormat format,
1156 VkImageType type,
1157 uint32_t samples,
1158 VkImageUsageFlags usage,
1159 VkImageTiling tiling,
1160 uint32_t* pNumProperties,
1161 VkSparseImageFormatProperties* pProperties)
1162 {
1163 /* Sparse images are not yet supported. */
1164 *pNumProperties = 0;
1165 }
1166
1167 void radv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
1168 VkPhysicalDevice physicalDevice,
1169 const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo,
1170 uint32_t *pPropertyCount,
1171 VkSparseImageFormatProperties2KHR* pProperties)
1172 {
1173 /* Sparse images are not yet supported. */
1174 *pPropertyCount = 0;
1175 }