2
* Copyright © 2016 Red Hat.
3
* Copyright © 2016 Bas Nieuwenhuizen
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:
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
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
25
#include "radv_debug.h"
26
#include "radv_private.h"
29
#include "vk_format.h"
33
#include "ac_drm_fourcc.h"
34
#include "util/format_r11g11b10f.h"
35
#include "util/format_rgb9e5.h"
36
#include "util/format_srgb.h"
37
#include "util/half_float.h"
38
#include "vulkan/util/vk_format.h"
39
#include "vulkan/util/vk_enum_defines.h"
42
radv_translate_buffer_dataformat(const struct util_format_description *desc, int first_non_void)
47
assert(util_format_get_num_planes(desc->format) == 1);
49
if (desc->format == PIPE_FORMAT_R11G11B10_FLOAT)
50
return V_008F0C_BUF_DATA_FORMAT_10_11_11;
52
if (first_non_void < 0)
53
return V_008F0C_BUF_DATA_FORMAT_INVALID;
54
type = desc->channel[first_non_void].type;
56
if (type == UTIL_FORMAT_TYPE_FIXED)
57
return V_008F0C_BUF_DATA_FORMAT_INVALID;
58
if (desc->nr_channels == 4 && desc->channel[0].size == 10 && desc->channel[1].size == 10 &&
59
desc->channel[2].size == 10 && desc->channel[3].size == 2)
60
return V_008F0C_BUF_DATA_FORMAT_2_10_10_10;
62
/* See whether the components are of the same size. */
63
for (i = 0; i < desc->nr_channels; i++) {
64
if (desc->channel[first_non_void].size != desc->channel[i].size)
65
return V_008F0C_BUF_DATA_FORMAT_INVALID;
68
switch (desc->channel[first_non_void].size) {
70
switch (desc->nr_channels) {
72
return V_008F0C_BUF_DATA_FORMAT_8;
74
return V_008F0C_BUF_DATA_FORMAT_8_8;
76
return V_008F0C_BUF_DATA_FORMAT_8_8_8_8;
80
switch (desc->nr_channels) {
82
return V_008F0C_BUF_DATA_FORMAT_16;
84
return V_008F0C_BUF_DATA_FORMAT_16_16;
86
return V_008F0C_BUF_DATA_FORMAT_16_16_16_16;
90
/* From the Southern Islands ISA documentation about MTBUF:
91
* 'Memory reads of data in memory that is 32 or 64 bits do not
92
* undergo any format conversion.'
94
if (type != UTIL_FORMAT_TYPE_FLOAT && !desc->channel[first_non_void].pure_integer)
95
return V_008F0C_BUF_DATA_FORMAT_INVALID;
97
switch (desc->nr_channels) {
99
return V_008F0C_BUF_DATA_FORMAT_32;
101
return V_008F0C_BUF_DATA_FORMAT_32_32;
103
return V_008F0C_BUF_DATA_FORMAT_32_32_32;
105
return V_008F0C_BUF_DATA_FORMAT_32_32_32_32;
109
if (type != UTIL_FORMAT_TYPE_FLOAT && desc->nr_channels == 1)
110
return V_008F0C_BUF_DATA_FORMAT_32_32;
113
return V_008F0C_BUF_DATA_FORMAT_INVALID;
117
radv_translate_buffer_numformat(const struct util_format_description *desc, int first_non_void)
119
assert(util_format_get_num_planes(desc->format) == 1);
121
if (desc->format == PIPE_FORMAT_R11G11B10_FLOAT)
122
return V_008F0C_BUF_NUM_FORMAT_FLOAT;
124
if (first_non_void < 0)
127
switch (desc->channel[first_non_void].type) {
128
case UTIL_FORMAT_TYPE_SIGNED:
129
if (desc->channel[first_non_void].normalized)
130
return V_008F0C_BUF_NUM_FORMAT_SNORM;
131
else if (desc->channel[first_non_void].pure_integer)
132
return V_008F0C_BUF_NUM_FORMAT_SINT;
134
return V_008F0C_BUF_NUM_FORMAT_SSCALED;
136
case UTIL_FORMAT_TYPE_UNSIGNED:
137
if (desc->channel[first_non_void].normalized)
138
return V_008F0C_BUF_NUM_FORMAT_UNORM;
139
else if (desc->channel[first_non_void].pure_integer)
140
return V_008F0C_BUF_NUM_FORMAT_UINT;
142
return V_008F0C_BUF_NUM_FORMAT_USCALED;
144
case UTIL_FORMAT_TYPE_FLOAT:
146
return V_008F0C_BUF_NUM_FORMAT_FLOAT;
151
radv_translate_vertex_format(const struct radv_physical_device *pdevice, VkFormat format,
152
const struct util_format_description *desc, unsigned *dfmt,
153
unsigned *nfmt, bool *post_shuffle,
154
enum radv_vs_input_alpha_adjust *alpha_adjust)
156
assert(desc->channel[0].type != UTIL_FORMAT_TYPE_VOID);
157
*nfmt = radv_translate_buffer_numformat(desc, 0);
158
*dfmt = radv_translate_buffer_dataformat(desc, 0);
160
*alpha_adjust = ALPHA_ADJUST_NONE;
161
if (pdevice->rad_info.chip_class <= GFX8 && pdevice->rad_info.family != CHIP_STONEY) {
163
case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
164
case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
165
*alpha_adjust = ALPHA_ADJUST_SNORM;
167
case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
168
case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
169
*alpha_adjust = ALPHA_ADJUST_SSCALED;
171
case VK_FORMAT_A2R10G10B10_SINT_PACK32:
172
case VK_FORMAT_A2B10G10R10_SINT_PACK32:
173
*alpha_adjust = ALPHA_ADJUST_SINT;
181
case VK_FORMAT_B8G8R8A8_UNORM:
182
case VK_FORMAT_B8G8R8A8_SNORM:
183
case VK_FORMAT_B8G8R8A8_USCALED:
184
case VK_FORMAT_B8G8R8A8_SSCALED:
185
case VK_FORMAT_B8G8R8A8_UINT:
186
case VK_FORMAT_B8G8R8A8_SINT:
187
case VK_FORMAT_B8G8R8A8_SRGB:
188
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
189
case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
190
case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
191
case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
192
case VK_FORMAT_A2R10G10B10_UINT_PACK32:
193
case VK_FORMAT_A2R10G10B10_SINT_PACK32:
194
*post_shuffle = true;
197
*post_shuffle = false;
203
radv_translate_tex_dataformat(VkFormat format, const struct util_format_description *desc,
209
assert(vk_format_get_plane_count(format) == 1);
213
/* Colorspace (return non-RGB formats directly). */
214
switch (desc->colorspace) {
215
/* Depth stencil formats */
216
case UTIL_FORMAT_COLORSPACE_ZS:
218
case VK_FORMAT_D16_UNORM:
219
return V_008F14_IMG_DATA_FORMAT_16;
220
case VK_FORMAT_D24_UNORM_S8_UINT:
221
case VK_FORMAT_X8_D24_UNORM_PACK32:
222
return V_008F14_IMG_DATA_FORMAT_8_24;
223
case VK_FORMAT_S8_UINT:
224
return V_008F14_IMG_DATA_FORMAT_8;
225
case VK_FORMAT_D32_SFLOAT:
226
return V_008F14_IMG_DATA_FORMAT_32;
227
case VK_FORMAT_D32_SFLOAT_S8_UINT:
228
return V_008F14_IMG_DATA_FORMAT_X24_8_32;
233
case UTIL_FORMAT_COLORSPACE_YUV:
234
goto out_unknown; /* TODO */
240
if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
242
/* Don't ask me why this looks inverted. PAL does the same. */
243
case VK_FORMAT_G8B8G8R8_422_UNORM:
244
return V_008F14_IMG_DATA_FORMAT_BG_RG;
245
case VK_FORMAT_B8G8R8G8_422_UNORM:
246
return V_008F14_IMG_DATA_FORMAT_GB_GR;
252
if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
254
case VK_FORMAT_BC4_UNORM_BLOCK:
255
case VK_FORMAT_BC4_SNORM_BLOCK:
256
return V_008F14_IMG_DATA_FORMAT_BC4;
257
case VK_FORMAT_BC5_UNORM_BLOCK:
258
case VK_FORMAT_BC5_SNORM_BLOCK:
259
return V_008F14_IMG_DATA_FORMAT_BC5;
265
if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
267
case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
268
case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
269
case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
270
case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
271
return V_008F14_IMG_DATA_FORMAT_BC1;
272
case VK_FORMAT_BC2_UNORM_BLOCK:
273
case VK_FORMAT_BC2_SRGB_BLOCK:
274
return V_008F14_IMG_DATA_FORMAT_BC2;
275
case VK_FORMAT_BC3_UNORM_BLOCK:
276
case VK_FORMAT_BC3_SRGB_BLOCK:
277
return V_008F14_IMG_DATA_FORMAT_BC3;
283
if (desc->layout == UTIL_FORMAT_LAYOUT_BPTC) {
285
case VK_FORMAT_BC6H_UFLOAT_BLOCK:
286
case VK_FORMAT_BC6H_SFLOAT_BLOCK:
287
return V_008F14_IMG_DATA_FORMAT_BC6;
288
case VK_FORMAT_BC7_UNORM_BLOCK:
289
case VK_FORMAT_BC7_SRGB_BLOCK:
290
return V_008F14_IMG_DATA_FORMAT_BC7;
296
if (desc->layout == UTIL_FORMAT_LAYOUT_ETC) {
298
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
299
case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
300
return V_008F14_IMG_DATA_FORMAT_ETC2_RGB;
301
case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
302
case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
303
return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA1;
304
case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
305
case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
306
return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA;
307
case VK_FORMAT_EAC_R11_UNORM_BLOCK:
308
case VK_FORMAT_EAC_R11_SNORM_BLOCK:
309
return V_008F14_IMG_DATA_FORMAT_ETC2_R;
310
case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
311
case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
312
return V_008F14_IMG_DATA_FORMAT_ETC2_RG;
318
if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
319
return V_008F14_IMG_DATA_FORMAT_5_9_9_9;
320
} else if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
321
return V_008F14_IMG_DATA_FORMAT_10_11_11;
324
/* R8G8Bx_SNORM - TODO CxV8U8 */
326
/* hw cannot support mixed formats (except depth/stencil, since only
328
if (desc->is_mixed && desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
331
/* See whether the components are of the same size. */
332
for (i = 1; i < desc->nr_channels; i++) {
333
uniform = uniform && desc->channel[0].size == desc->channel[i].size;
336
/* Non-uniform formats. */
338
switch (desc->nr_channels) {
340
if (desc->channel[0].size == 5 && desc->channel[1].size == 6 &&
341
desc->channel[2].size == 5) {
342
return V_008F14_IMG_DATA_FORMAT_5_6_5;
346
if (desc->channel[0].size == 5 && desc->channel[1].size == 5 &&
347
desc->channel[2].size == 5 && desc->channel[3].size == 1) {
348
return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
350
if (desc->channel[0].size == 1 && desc->channel[1].size == 5 &&
351
desc->channel[2].size == 5 && desc->channel[3].size == 5) {
352
return V_008F14_IMG_DATA_FORMAT_5_5_5_1;
354
if (desc->channel[0].size == 10 && desc->channel[1].size == 10 &&
355
desc->channel[2].size == 10 && desc->channel[3].size == 2) {
356
/* Closed VK driver does this also no 2/10/10/10 snorm */
357
if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED && desc->channel[0].normalized)
359
return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
366
if (first_non_void < 0 || first_non_void > 3)
369
/* uniform formats */
370
switch (desc->channel[first_non_void].size) {
372
switch (desc->nr_channels) {
373
#if 0 /* Not supported for render targets */
375
return V_008F14_IMG_DATA_FORMAT_4_4;
378
return V_008F14_IMG_DATA_FORMAT_4_4_4_4;
382
switch (desc->nr_channels) {
384
return V_008F14_IMG_DATA_FORMAT_8;
386
return V_008F14_IMG_DATA_FORMAT_8_8;
388
return V_008F14_IMG_DATA_FORMAT_8_8_8_8;
392
switch (desc->nr_channels) {
394
return V_008F14_IMG_DATA_FORMAT_16;
396
return V_008F14_IMG_DATA_FORMAT_16_16;
398
return V_008F14_IMG_DATA_FORMAT_16_16_16_16;
402
switch (desc->nr_channels) {
404
return V_008F14_IMG_DATA_FORMAT_32;
406
return V_008F14_IMG_DATA_FORMAT_32_32;
408
return V_008F14_IMG_DATA_FORMAT_32_32_32;
410
return V_008F14_IMG_DATA_FORMAT_32_32_32_32;
414
if (desc->channel[0].type != UTIL_FORMAT_TYPE_FLOAT && desc->nr_channels == 1)
415
return V_008F14_IMG_DATA_FORMAT_32_32;
420
/* R600_ERR("Unable to handle texformat %d %s\n", format, vk_format_name(format)); */
425
radv_translate_tex_numformat(VkFormat format, const struct util_format_description *desc,
428
assert(vk_format_get_plane_count(format) == 1);
431
case VK_FORMAT_D24_UNORM_S8_UINT:
432
return V_008F14_IMG_NUM_FORMAT_UNORM;
434
if (first_non_void < 0) {
435
if (vk_format_is_compressed(format)) {
437
case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
438
case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
439
case VK_FORMAT_BC2_SRGB_BLOCK:
440
case VK_FORMAT_BC3_SRGB_BLOCK:
441
case VK_FORMAT_BC7_SRGB_BLOCK:
442
case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
443
case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
444
case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
445
return V_008F14_IMG_NUM_FORMAT_SRGB;
446
case VK_FORMAT_BC4_SNORM_BLOCK:
447
case VK_FORMAT_BC5_SNORM_BLOCK:
448
case VK_FORMAT_BC6H_SFLOAT_BLOCK:
449
case VK_FORMAT_EAC_R11_SNORM_BLOCK:
450
case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
451
return V_008F14_IMG_NUM_FORMAT_SNORM;
453
return V_008F14_IMG_NUM_FORMAT_UNORM;
455
} else if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
456
return V_008F14_IMG_NUM_FORMAT_UNORM;
458
return V_008F14_IMG_NUM_FORMAT_FLOAT;
460
} else if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
461
return V_008F14_IMG_NUM_FORMAT_SRGB;
463
switch (desc->channel[first_non_void].type) {
464
case UTIL_FORMAT_TYPE_FLOAT:
465
return V_008F14_IMG_NUM_FORMAT_FLOAT;
466
case UTIL_FORMAT_TYPE_SIGNED:
467
if (desc->channel[first_non_void].normalized)
468
return V_008F14_IMG_NUM_FORMAT_SNORM;
469
else if (desc->channel[first_non_void].pure_integer)
470
return V_008F14_IMG_NUM_FORMAT_SINT;
472
return V_008F14_IMG_NUM_FORMAT_SSCALED;
473
case UTIL_FORMAT_TYPE_UNSIGNED:
474
if (desc->channel[first_non_void].normalized)
475
return V_008F14_IMG_NUM_FORMAT_UNORM;
476
else if (desc->channel[first_non_void].pure_integer)
477
return V_008F14_IMG_NUM_FORMAT_UINT;
479
return V_008F14_IMG_NUM_FORMAT_USCALED;
481
return V_008F14_IMG_NUM_FORMAT_UNORM;
488
radv_translate_color_numformat(VkFormat format, const struct util_format_description *desc,
493
assert(vk_format_get_plane_count(format) == 1);
495
if (first_non_void == -1 || desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_FLOAT)
496
ntype = V_028C70_NUMBER_FLOAT;
498
ntype = V_028C70_NUMBER_UNORM;
499
if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
500
ntype = V_028C70_NUMBER_SRGB;
501
else if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_SIGNED) {
502
if (desc->channel[first_non_void].pure_integer) {
503
ntype = V_028C70_NUMBER_SINT;
504
} else if (desc->channel[first_non_void].normalized) {
505
ntype = V_028C70_NUMBER_SNORM;
508
} else if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_UNSIGNED) {
509
if (desc->channel[first_non_void].pure_integer) {
510
ntype = V_028C70_NUMBER_UINT;
511
} else if (desc->channel[first_non_void].normalized) {
512
ntype = V_028C70_NUMBER_UNORM;
521
radv_is_sampler_format_supported(VkFormat format, bool *linear_sampling)
523
const struct util_format_description *desc = vk_format_description(format);
525
if (!desc || format == VK_FORMAT_UNDEFINED || format == VK_FORMAT_R64_UINT ||
526
format == VK_FORMAT_R64_SINT)
529
radv_translate_tex_numformat(format, desc, vk_format_get_first_non_void_channel(format));
531
if (num_format == V_008F14_IMG_NUM_FORMAT_USCALED ||
532
num_format == V_008F14_IMG_NUM_FORMAT_SSCALED)
535
if (num_format == V_008F14_IMG_NUM_FORMAT_UNORM || num_format == V_008F14_IMG_NUM_FORMAT_SNORM ||
536
num_format == V_008F14_IMG_NUM_FORMAT_FLOAT || num_format == V_008F14_IMG_NUM_FORMAT_SRGB)
537
*linear_sampling = true;
539
*linear_sampling = false;
540
return radv_translate_tex_dataformat(format, vk_format_description(format),
541
vk_format_get_first_non_void_channel(format)) != ~0U;
545
radv_is_atomic_format_supported(VkFormat format)
547
return format == VK_FORMAT_R32_UINT || format == VK_FORMAT_R32_SINT ||
548
format == VK_FORMAT_R32_SFLOAT || format == VK_FORMAT_R64_UINT ||
549
format == VK_FORMAT_R64_SINT;
553
radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,
556
const struct util_format_description *desc = vk_format_description(format);
557
unsigned data_format, num_format;
558
if (!desc || format == VK_FORMAT_UNDEFINED)
562
radv_translate_tex_dataformat(format, desc, vk_format_get_first_non_void_channel(format));
564
radv_translate_tex_numformat(format, desc, vk_format_get_first_non_void_channel(format));
566
if (data_format == ~0 || num_format == ~0)
569
/* Extracted from the GCN3 ISA document. */
570
switch (num_format) {
571
case V_008F14_IMG_NUM_FORMAT_UNORM:
572
case V_008F14_IMG_NUM_FORMAT_SNORM:
573
case V_008F14_IMG_NUM_FORMAT_UINT:
574
case V_008F14_IMG_NUM_FORMAT_SINT:
575
case V_008F14_IMG_NUM_FORMAT_FLOAT:
581
switch (data_format) {
582
case V_008F14_IMG_DATA_FORMAT_8:
583
case V_008F14_IMG_DATA_FORMAT_16:
584
case V_008F14_IMG_DATA_FORMAT_8_8:
585
case V_008F14_IMG_DATA_FORMAT_32:
586
case V_008F14_IMG_DATA_FORMAT_16_16:
587
case V_008F14_IMG_DATA_FORMAT_10_11_11:
588
case V_008F14_IMG_DATA_FORMAT_11_11_10:
589
case V_008F14_IMG_DATA_FORMAT_10_10_10_2:
590
case V_008F14_IMG_DATA_FORMAT_2_10_10_10:
591
case V_008F14_IMG_DATA_FORMAT_8_8_8_8:
592
case V_008F14_IMG_DATA_FORMAT_32_32:
593
case V_008F14_IMG_DATA_FORMAT_16_16_16_16:
594
case V_008F14_IMG_DATA_FORMAT_32_32_32_32:
595
case V_008F14_IMG_DATA_FORMAT_5_6_5:
596
case V_008F14_IMG_DATA_FORMAT_1_5_5_5:
597
case V_008F14_IMG_DATA_FORMAT_5_5_5_1:
598
case V_008F14_IMG_DATA_FORMAT_4_4_4_4:
599
/* TODO: FMASK formats. */
601
case V_008F14_IMG_DATA_FORMAT_5_9_9_9:
602
return physical_device->rad_info.chip_class >= GFX10_3;
609
radv_is_buffer_format_supported(VkFormat format, bool *scaled)
611
const struct util_format_description *desc = vk_format_description(format);
612
unsigned data_format, num_format;
613
if (!desc || format == VK_FORMAT_UNDEFINED)
617
radv_translate_buffer_dataformat(desc, vk_format_get_first_non_void_channel(format));
618
num_format = radv_translate_buffer_numformat(desc, vk_format_get_first_non_void_channel(format));
621
*scaled = (num_format == V_008F0C_BUF_NUM_FORMAT_SSCALED) ||
622
(num_format == V_008F0C_BUF_NUM_FORMAT_USCALED);
623
return data_format != V_008F0C_BUF_DATA_FORMAT_INVALID && num_format != ~0;
627
radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdevice, VkFormat format,
630
const struct util_format_description *desc = vk_format_description(format);
631
uint32_t color_format = radv_translate_colorformat(format);
632
uint32_t color_swap = radv_translate_colorswap(format, false);
633
uint32_t color_num_format =
634
radv_translate_color_numformat(format, desc, vk_format_get_first_non_void_channel(format));
636
if (color_num_format == V_028C70_NUMBER_UINT || color_num_format == V_028C70_NUMBER_SINT ||
637
color_format == V_028C70_COLOR_8_24 || color_format == V_028C70_COLOR_24_8 ||
638
color_format == V_028C70_COLOR_X24_8_32_FLOAT) {
643
if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 && pdevice->rad_info.chip_class < GFX10_3)
646
return color_format != V_028C70_COLOR_INVALID && color_swap != ~0U && color_num_format != ~0;
650
radv_is_zs_format_supported(VkFormat format)
652
return radv_translate_dbformat(format) != V_028040_Z_INVALID || format == VK_FORMAT_S8_UINT;
656
radv_is_filter_minmax_format_supported(VkFormat format)
658
/* From the Vulkan spec 1.1.71:
660
* "The following formats must support the
661
* VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_MINMAX_BIT feature with
662
* VK_IMAGE_TILING_OPTIMAL, if they support
663
* VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT."
665
/* TODO: enable more formats. */
667
case VK_FORMAT_R8_UNORM:
668
case VK_FORMAT_R8_SNORM:
669
case VK_FORMAT_R16_UNORM:
670
case VK_FORMAT_R16_SNORM:
671
case VK_FORMAT_R16_SFLOAT:
672
case VK_FORMAT_R32_SFLOAT:
673
case VK_FORMAT_D16_UNORM:
674
case VK_FORMAT_X8_D24_UNORM_PACK32:
675
case VK_FORMAT_D32_SFLOAT:
676
case VK_FORMAT_D16_UNORM_S8_UINT:
677
case VK_FORMAT_D24_UNORM_S8_UINT:
678
case VK_FORMAT_D32_SFLOAT_S8_UINT:
686
radv_device_supports_etc(struct radv_physical_device *physical_device)
688
return physical_device->rad_info.family == CHIP_VEGA10 ||
689
physical_device->rad_info.family == CHIP_RAVEN ||
690
physical_device->rad_info.family == CHIP_RAVEN2 ||
691
physical_device->rad_info.family == CHIP_STONEY;
695
radv_physical_device_get_format_properties(struct radv_physical_device *physical_device,
696
VkFormat format, VkFormatProperties3 *out_properties)
698
VkFormatFeatureFlags2 linear = 0, tiled = 0, buffer = 0;
699
const struct util_format_description *desc = vk_format_description(format);
702
/* TODO: implement some software emulation of SUBSAMPLED formats. */
703
if (!desc || vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE ||
704
desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
705
out_properties->linearTilingFeatures = linear;
706
out_properties->optimalTilingFeatures = tiled;
707
out_properties->bufferFeatures = buffer;
711
if (desc->layout == UTIL_FORMAT_LAYOUT_ETC && !radv_device_supports_etc(physical_device) &&
712
!physical_device->emulate_etc2) {
713
out_properties->linearTilingFeatures = linear;
714
out_properties->optimalTilingFeatures = tiled;
715
out_properties->bufferFeatures = buffer;
719
if (vk_format_get_plane_count(format) > 1 || desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
720
uint64_t tiling = VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT |
721
VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT |
722
VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT |
723
VK_FORMAT_FEATURE_2_COSITED_CHROMA_SAMPLES_BIT |
724
VK_FORMAT_FEATURE_2_MIDPOINT_CHROMA_SAMPLES_BIT;
726
/* The subsampled formats have no support for linear filters. */
727
if (desc->layout != UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
728
tiling |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
731
/* Fails for unknown reasons with linear tiling & subsampled formats. */
732
out_properties->linearTilingFeatures =
733
desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED ? 0 : tiling;
734
out_properties->optimalTilingFeatures = tiling;
735
out_properties->bufferFeatures = 0;
739
if (radv_is_storage_image_format_supported(physical_device, format)) {
740
tiled |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT |
741
VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT |
742
VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT;
743
linear |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT |
744
VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT |
745
VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT;
748
if (radv_is_buffer_format_supported(format, &scaled)) {
749
if (format != VK_FORMAT_R64_UINT && format != VK_FORMAT_R64_SINT) {
750
buffer |= VK_FORMAT_FEATURE_2_VERTEX_BUFFER_BIT;
752
buffer |= VK_FORMAT_FEATURE_2_UNIFORM_TEXEL_BUFFER_BIT;
754
buffer |= VK_FORMAT_FEATURE_2_STORAGE_TEXEL_BUFFER_BIT |
755
VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT |
756
VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT;
759
if (vk_format_is_depth_or_stencil(format)) {
760
if (radv_is_zs_format_supported(format)) {
761
tiled |= VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT;
762
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT;
763
tiled |= VK_FORMAT_FEATURE_2_BLIT_SRC_BIT | VK_FORMAT_FEATURE_2_BLIT_DST_BIT;
764
tiled |= VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT;
766
if (radv_is_filter_minmax_format_supported(format))
767
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_MINMAX_BIT;
769
if (vk_format_has_depth(format)) {
770
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
771
VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT;
774
/* Don't support blitting surfaces with depth/stencil. */
775
if (vk_format_has_depth(format) && vk_format_has_stencil(format))
776
tiled &= ~VK_FORMAT_FEATURE_2_BLIT_DST_BIT;
778
/* Don't support linear depth surfaces */
782
bool linear_sampling;
783
if (radv_is_sampler_format_supported(format, &linear_sampling)) {
784
linear |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_2_BLIT_SRC_BIT;
785
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_2_BLIT_SRC_BIT;
787
if (radv_is_filter_minmax_format_supported(format))
788
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_MINMAX_BIT;
790
if (linear_sampling) {
791
linear |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
792
tiled |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
795
/* Don't support blitting for R32G32B32 formats. */
796
if (format == VK_FORMAT_R32G32B32_SFLOAT || format == VK_FORMAT_R32G32B32_UINT ||
797
format == VK_FORMAT_R32G32B32_SINT) {
798
linear &= ~VK_FORMAT_FEATURE_2_BLIT_SRC_BIT;
801
if (radv_is_colorbuffer_format_supported(physical_device, format, &blendable)) {
802
linear |= VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_2_BLIT_DST_BIT;
803
tiled |= VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_2_BLIT_DST_BIT;
805
linear |= VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BLEND_BIT;
806
tiled |= VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BLEND_BIT;
809
if (tiled && !scaled) {
810
tiled |= VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT;
813
/* Tiled formatting does not support NPOT pixel sizes */
814
if (!util_is_power_of_two_or_zero(vk_format_get_blocksize(format)))
818
if (linear && !scaled) {
819
linear |= VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT;
822
if (radv_is_atomic_format_supported(format)) {
823
buffer |= VK_FORMAT_FEATURE_2_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
824
linear |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT;
825
tiled |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT;
829
case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
830
case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
831
case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
832
case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
833
case VK_FORMAT_A2R10G10B10_SINT_PACK32:
834
case VK_FORMAT_A2B10G10R10_SINT_PACK32:
836
~(VK_FORMAT_FEATURE_2_UNIFORM_TEXEL_BUFFER_BIT | VK_FORMAT_FEATURE_2_STORAGE_TEXEL_BUFFER_BIT);
845
case VK_FORMAT_R32G32_SFLOAT:
846
case VK_FORMAT_R32G32B32_SFLOAT:
847
case VK_FORMAT_R32G32B32A32_SFLOAT:
848
case VK_FORMAT_R16G16_SFLOAT:
849
case VK_FORMAT_R16G16B16_SFLOAT:
850
case VK_FORMAT_R16G16B16A16_SFLOAT:
851
case VK_FORMAT_R16G16_SNORM:
852
case VK_FORMAT_R16G16_UNORM:
853
case VK_FORMAT_R16G16B16A16_SNORM:
854
case VK_FORMAT_R16G16B16A16_UNORM:
855
case VK_FORMAT_R8G8_SNORM:
856
case VK_FORMAT_R8G8_UNORM:
857
case VK_FORMAT_R8G8B8A8_SNORM:
858
case VK_FORMAT_R8G8B8A8_UNORM:
859
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
860
buffer |= VK_FORMAT_FEATURE_2_ACCELERATION_STRUCTURE_VERTEX_BUFFER_BIT_KHR;
865
/* addrlib does not support linear compressed textures. */
866
if (vk_format_is_compressed(format))
869
/* From the Vulkan spec 1.2.163:
871
* "VK_FORMAT_FEATURE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT must be supported for the
872
* following formats if the attachmentFragmentShadingRate feature is supported:"
874
* - VK_FORMAT_R8_UINT
876
if (format == VK_FORMAT_R8_UINT) {
877
tiled |= VK_FORMAT_FEATURE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR;
880
/* It's invalid to expose buffer features with depth/stencil formats. */
881
if (vk_format_is_depth_or_stencil(format)) {
885
out_properties->linearTilingFeatures = linear;
886
out_properties->optimalTilingFeatures = tiled;
887
out_properties->bufferFeatures = buffer;
891
radv_translate_colorformat(VkFormat format)
893
const struct util_format_description *desc = vk_format_description(format);
895
#define HAS_SIZE(x, y, z, w) \
896
(desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
897
desc->channel[2].size == (z) && desc->channel[3].size == (w))
899
if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) /* isn't plain */
900
return V_028C70_COLOR_10_11_11;
902
if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)
903
return V_028C70_COLOR_5_9_9_9;
905
if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
906
return V_028C70_COLOR_INVALID;
908
/* hw cannot support mixed formats (except depth/stencil, since
909
* stencil is not written to). */
910
if (desc->is_mixed && desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
911
return V_028C70_COLOR_INVALID;
913
switch (desc->nr_channels) {
915
switch (desc->channel[0].size) {
917
return V_028C70_COLOR_8;
919
return V_028C70_COLOR_16;
921
return V_028C70_COLOR_32;
925
if (desc->channel[0].size == desc->channel[1].size) {
926
switch (desc->channel[0].size) {
928
return V_028C70_COLOR_8_8;
930
return V_028C70_COLOR_16_16;
932
return V_028C70_COLOR_32_32;
934
} else if (HAS_SIZE(8, 24, 0, 0)) {
935
return V_028C70_COLOR_24_8;
936
} else if (HAS_SIZE(24, 8, 0, 0)) {
937
return V_028C70_COLOR_8_24;
941
if (HAS_SIZE(5, 6, 5, 0)) {
942
return V_028C70_COLOR_5_6_5;
943
} else if (HAS_SIZE(32, 8, 24, 0)) {
944
return V_028C70_COLOR_X24_8_32_FLOAT;
948
if (desc->channel[0].size == desc->channel[1].size &&
949
desc->channel[0].size == desc->channel[2].size &&
950
desc->channel[0].size == desc->channel[3].size) {
951
switch (desc->channel[0].size) {
953
return V_028C70_COLOR_4_4_4_4;
955
return V_028C70_COLOR_8_8_8_8;
957
return V_028C70_COLOR_16_16_16_16;
959
return V_028C70_COLOR_32_32_32_32;
961
} else if (HAS_SIZE(5, 5, 5, 1)) {
962
return V_028C70_COLOR_1_5_5_5;
963
} else if (HAS_SIZE(1, 5, 5, 5)) {
964
return V_028C70_COLOR_5_5_5_1;
965
} else if (HAS_SIZE(10, 10, 10, 2)) {
966
return V_028C70_COLOR_2_10_10_10;
970
return V_028C70_COLOR_INVALID;
974
radv_colorformat_endian_swap(uint32_t colorformat)
976
if (0 /*SI_BIG_ENDIAN*/) {
977
switch (colorformat) {
979
case V_028C70_COLOR_8:
980
return V_028C70_ENDIAN_NONE;
982
/* 16-bit buffers. */
983
case V_028C70_COLOR_5_6_5:
984
case V_028C70_COLOR_1_5_5_5:
985
case V_028C70_COLOR_4_4_4_4:
986
case V_028C70_COLOR_16:
987
case V_028C70_COLOR_8_8:
988
return V_028C70_ENDIAN_8IN16;
990
/* 32-bit buffers. */
991
case V_028C70_COLOR_8_8_8_8:
992
case V_028C70_COLOR_2_10_10_10:
993
case V_028C70_COLOR_8_24:
994
case V_028C70_COLOR_24_8:
995
case V_028C70_COLOR_16_16:
996
return V_028C70_ENDIAN_8IN32;
998
/* 64-bit buffers. */
999
case V_028C70_COLOR_16_16_16_16:
1000
return V_028C70_ENDIAN_8IN16;
1002
case V_028C70_COLOR_32_32:
1003
return V_028C70_ENDIAN_8IN32;
1005
/* 128-bit buffers. */
1006
case V_028C70_COLOR_32_32_32_32:
1007
return V_028C70_ENDIAN_8IN32;
1009
return V_028C70_ENDIAN_NONE; /* Unsupported. */
1012
return V_028C70_ENDIAN_NONE;
1017
radv_translate_dbformat(VkFormat format)
1020
case VK_FORMAT_D16_UNORM:
1021
case VK_FORMAT_D16_UNORM_S8_UINT:
1022
return V_028040_Z_16;
1023
case VK_FORMAT_D32_SFLOAT:
1024
case VK_FORMAT_D32_SFLOAT_S8_UINT:
1025
return V_028040_Z_32_FLOAT;
1027
return V_028040_Z_INVALID;
1032
radv_translate_colorswap(VkFormat format, bool do_endian_swap)
1034
const struct util_format_description *desc = vk_format_description(format);
1036
#define HAS_SWIZZLE(chan, swz) (desc->swizzle[chan] == PIPE_SWIZZLE_##swz)
1038
if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
1039
return V_028C70_SWAP_STD;
1041
if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)
1042
return V_028C70_SWAP_STD;
1044
if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
1047
switch (desc->nr_channels) {
1049
if (HAS_SWIZZLE(0, X))
1050
return V_028C70_SWAP_STD; /* X___ */
1051
else if (HAS_SWIZZLE(3, X))
1052
return V_028C70_SWAP_ALT_REV; /* ___X */
1055
if ((HAS_SWIZZLE(0, X) && HAS_SWIZZLE(1, Y)) || (HAS_SWIZZLE(0, X) && HAS_SWIZZLE(1, NONE)) ||
1056
(HAS_SWIZZLE(0, NONE) && HAS_SWIZZLE(1, Y)))
1057
return V_028C70_SWAP_STD; /* XY__ */
1058
else if ((HAS_SWIZZLE(0, Y) && HAS_SWIZZLE(1, X)) ||
1059
(HAS_SWIZZLE(0, Y) && HAS_SWIZZLE(1, NONE)) ||
1060
(HAS_SWIZZLE(0, NONE) && HAS_SWIZZLE(1, X)))
1062
return (do_endian_swap ? V_028C70_SWAP_STD : V_028C70_SWAP_STD_REV);
1063
else if (HAS_SWIZZLE(0, X) && HAS_SWIZZLE(3, Y))
1064
return V_028C70_SWAP_ALT; /* X__Y */
1065
else if (HAS_SWIZZLE(0, Y) && HAS_SWIZZLE(3, X))
1066
return V_028C70_SWAP_ALT_REV; /* Y__X */
1069
if (HAS_SWIZZLE(0, X))
1070
return (do_endian_swap ? V_028C70_SWAP_STD_REV : V_028C70_SWAP_STD);
1071
else if (HAS_SWIZZLE(0, Z))
1072
return V_028C70_SWAP_STD_REV; /* ZYX */
1075
/* check the middle channels, the 1st and 4th channel can be NONE */
1076
if (HAS_SWIZZLE(1, Y) && HAS_SWIZZLE(2, Z)) {
1077
return V_028C70_SWAP_STD; /* XYZW */
1078
} else if (HAS_SWIZZLE(1, Z) && HAS_SWIZZLE(2, Y)) {
1079
return V_028C70_SWAP_STD_REV; /* WZYX */
1080
} else if (HAS_SWIZZLE(1, Y) && HAS_SWIZZLE(2, X)) {
1081
return V_028C70_SWAP_ALT; /* ZYXW */
1082
} else if (HAS_SWIZZLE(1, Z) && HAS_SWIZZLE(2, W)) {
1085
return V_028C70_SWAP_ALT_REV;
1087
return (do_endian_swap ? V_028C70_SWAP_ALT : V_028C70_SWAP_ALT_REV);
1095
radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2], VkClearColorValue *value)
1097
const struct util_format_description *desc = vk_format_description(format);
1099
if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
1100
clear_vals[0] = float3_to_r11g11b10f(value->float32);
1103
} else if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
1104
clear_vals[0] = float3_to_rgb9e5(value->float32);
1109
if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
1110
fprintf(stderr, "failed to fast clear for non-plain format %d\n", format);
1114
if (!util_is_power_of_two_or_zero(desc->block.bits)) {
1115
fprintf(stderr, "failed to fast clear for NPOT format %d\n", format);
1119
if (desc->block.bits > 64) {
1121
* We have a 128 bits format, check if the first 3 components are the same.
1122
* Every elements has to be 32 bits since we don't support 64-bit formats,
1123
* and we can skip swizzling checks as alpha always comes last for these and
1124
* we do not care about the rest as they have to be the same.
1126
if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) {
1127
if (value->float32[0] != value->float32[1] || value->float32[0] != value->float32[2])
1130
if (value->uint32[0] != value->uint32[1] || value->uint32[0] != value->uint32[2])
1133
clear_vals[0] = value->uint32[0];
1134
clear_vals[1] = value->uint32[3];
1137
uint64_t clear_val = 0;
1139
for (unsigned c = 0; c < 4; ++c) {
1140
if (desc->swizzle[c] >= 4)
1143
const struct util_format_channel_description *channel = &desc->channel[desc->swizzle[c]];
1144
assert(channel->size);
1147
if (channel->pure_integer) {
1148
v = value->uint32[c] & ((1ULL << channel->size) - 1);
1149
} else if (channel->normalized) {
1150
if (channel->type == UTIL_FORMAT_TYPE_UNSIGNED && desc->swizzle[c] < 3 &&
1151
desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
1152
assert(channel->size == 8);
1154
v = util_format_linear_float_to_srgb_8unorm(value->float32[c]);
1156
float f = MIN2(value->float32[c], 1.0f);
1158
if (channel->type == UTIL_FORMAT_TYPE_UNSIGNED) {
1159
f = MAX2(f, 0.0f) * ((1ULL << channel->size) - 1);
1161
f = MAX2(f, -1.0f) * ((1ULL << (channel->size - 1)) - 1);
1164
/* The hardware rounds before conversion. */
1172
} else if (channel->type == UTIL_FORMAT_TYPE_FLOAT) {
1173
if (channel->size == 32) {
1174
memcpy(&v, &value->float32[c], 4);
1175
} else if (channel->size == 16) {
1176
v = _mesa_float_to_float16_rtz(value->float32[c]);
1178
fprintf(stderr, "failed to fast clear for unhandled float size in format %d\n", format);
1182
fprintf(stderr, "failed to fast clear for unhandled component type in format %d\n",
1186
clear_val |= (v & ((1ULL << channel->size) - 1)) << channel->shift;
1189
clear_vals[0] = clear_val;
1190
clear_vals[1] = clear_val >> 32;
1195
static const struct ac_modifier_options radv_modifier_options = {
1200
static VkFormatFeatureFlags2
1201
radv_get_modifier_flags(struct radv_physical_device *dev, VkFormat format, uint64_t modifier,
1202
const VkFormatProperties3 *props)
1204
VkFormatFeatureFlags2 features;
1206
if (vk_format_is_compressed(format) || vk_format_is_depth_or_stencil(format))
1209
if (modifier == DRM_FORMAT_MOD_LINEAR)
1210
features = props->linearTilingFeatures;
1212
features = props->optimalTilingFeatures;
1214
if (ac_modifier_has_dcc(modifier)) {
1215
/* Only disable support for STORAGE_IMAGE on modifiers that
1216
* do not support DCC image stores.
1218
if (!ac_modifier_supports_dcc_image_stores(modifier) || radv_is_atomic_format_supported(format))
1219
features &= ~VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT;
1221
if (dev->instance->debug_flags & (RADV_DEBUG_NO_DCC | RADV_DEBUG_NO_DISPLAY_DCC))
1228
static VkFormatFeatureFlags
1229
features2_to_features(VkFormatFeatureFlags2 features2)
1231
return features2 & VK_ALL_FORMAT_FEATURE_FLAG_BITS;
1235
radv_list_drm_format_modifiers(struct radv_physical_device *dev, VkFormat format,
1236
const VkFormatProperties3 *format_props,
1237
VkDrmFormatModifierPropertiesListEXT *mod_list)
1244
if (vk_format_is_compressed(format) || vk_format_is_depth_or_stencil(format)) {
1245
mod_list->drmFormatModifierCount = 0;
1249
VK_OUTARRAY_MAKE_TYPED(VkDrmFormatModifierPropertiesEXT, out,
1250
mod_list->pDrmFormatModifierProperties,
1251
&mod_list->drmFormatModifierCount);
1253
ac_get_supported_modifiers(&dev->rad_info, &radv_modifier_options,
1254
vk_format_to_pipe_format(format), &mod_count, NULL);
1256
uint64_t *mods = malloc(mod_count * sizeof(uint64_t));
1258
/* We can't return an error here ... */
1259
mod_list->drmFormatModifierCount = 0;
1262
ac_get_supported_modifiers(&dev->rad_info, &radv_modifier_options,
1263
vk_format_to_pipe_format(format), &mod_count, mods);
1265
for (unsigned i = 0; i < mod_count; ++i) {
1266
VkFormatFeatureFlags2 features =
1267
radv_get_modifier_flags(dev, format, mods[i], format_props);
1268
unsigned planes = vk_format_get_plane_count(format);
1270
if (ac_modifier_has_dcc_retile(mods[i]))
1272
else if (ac_modifier_has_dcc(mods[i]))
1279
vk_outarray_append_typed(VkDrmFormatModifierPropertiesEXT, &out, out_props) {
1280
*out_props = (VkDrmFormatModifierPropertiesEXT) {
1281
.drmFormatModifier = mods[i],
1282
.drmFormatModifierPlaneCount = planes,
1283
.drmFormatModifierTilingFeatures = features2_to_features(features),
1292
radv_list_drm_format_modifiers_2(struct radv_physical_device *dev, VkFormat format,
1293
const VkFormatProperties3 *format_props,
1294
VkDrmFormatModifierPropertiesList2EXT *mod_list)
1301
if (vk_format_is_compressed(format) || vk_format_is_depth_or_stencil(format)) {
1302
mod_list->drmFormatModifierCount = 0;
1306
VK_OUTARRAY_MAKE_TYPED(VkDrmFormatModifierProperties2EXT, out,
1307
mod_list->pDrmFormatModifierProperties,
1308
&mod_list->drmFormatModifierCount);
1310
ac_get_supported_modifiers(&dev->rad_info, &radv_modifier_options,
1311
vk_format_to_pipe_format(format), &mod_count, NULL);
1313
uint64_t *mods = malloc(mod_count * sizeof(uint64_t));
1315
/* We can't return an error here ... */
1316
mod_list->drmFormatModifierCount = 0;
1319
ac_get_supported_modifiers(&dev->rad_info, &radv_modifier_options,
1320
vk_format_to_pipe_format(format), &mod_count, mods);
1322
for (unsigned i = 0; i < mod_count; ++i) {
1323
VkFormatFeatureFlags2 features =
1324
radv_get_modifier_flags(dev, format, mods[i], format_props);
1325
unsigned planes = vk_format_get_plane_count(format);
1327
if (ac_modifier_has_dcc_retile(mods[i]))
1329
else if (ac_modifier_has_dcc(mods[i]))
1336
vk_outarray_append_typed(VkDrmFormatModifierProperties2EXT, &out, out_props) {
1337
*out_props = (VkDrmFormatModifierProperties2EXT) {
1338
.drmFormatModifier = mods[i],
1339
.drmFormatModifierPlaneCount = planes,
1340
.drmFormatModifierTilingFeatures = features,
1349
radv_check_modifier_support(struct radv_physical_device *dev,
1350
const VkPhysicalDeviceImageFormatInfo2 *info,
1351
VkImageFormatProperties *props, VkFormat format, uint64_t modifier)
1353
const struct util_format_description *desc = vk_format_description(format);
1354
uint32_t max_width, max_height;
1356
if (info->type != VK_IMAGE_TYPE_2D)
1357
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1359
if (!desc || (desc->layout == UTIL_FORMAT_LAYOUT_ETC && dev->emulate_etc2))
1360
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1362
/* We did not add modifiers for sparse textures. */
1363
if (info->flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT |
1364
VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))
1365
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1368
* Need to check the modifier is supported in general:
1369
* "If the drmFormatModifier is incompatible with the parameters specified
1370
* in VkPhysicalDeviceImageFormatInfo2 and its pNext chain, then
1371
* vkGetPhysicalDeviceImageFormatProperties2 returns VK_ERROR_FORMAT_NOT_SUPPORTED.
1372
* The implementation must support the query of any drmFormatModifier,
1373
* including unknown and invalid modifier values."
1375
VkDrmFormatModifierPropertiesListEXT mod_list = {
1376
.sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
1379
VkFormatProperties2 format_props2 = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
1380
.pNext = &mod_list};
1382
radv_GetPhysicalDeviceFormatProperties2(radv_physical_device_to_handle(dev), format,
1385
if (!mod_list.drmFormatModifierCount)
1386
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1388
mod_list.pDrmFormatModifierProperties =
1389
calloc(mod_list.drmFormatModifierCount, sizeof(*mod_list.pDrmFormatModifierProperties));
1390
if (!mod_list.pDrmFormatModifierProperties)
1391
return VK_ERROR_OUT_OF_HOST_MEMORY;
1393
radv_GetPhysicalDeviceFormatProperties2(radv_physical_device_to_handle(dev), format,
1397
for (uint32_t i = 0; i < mod_list.drmFormatModifierCount && !found; ++i)
1398
if (mod_list.pDrmFormatModifierProperties[i].drmFormatModifier == modifier)
1401
free(mod_list.pDrmFormatModifierProperties);
1404
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1406
bool need_dcc_sign_reinterpret = false;
1407
if (ac_modifier_has_dcc(modifier) &&
1408
!radv_are_formats_dcc_compatible(dev, info->pNext, format, info->flags,
1409
&need_dcc_sign_reinterpret) &&
1410
!need_dcc_sign_reinterpret)
1411
return VK_ERROR_FORMAT_NOT_SUPPORTED;
1413
/* We can expand this as needed and implemented but there is not much demand
1415
if (ac_modifier_has_dcc(modifier)) {
1416
props->maxMipLevels = 1;
1417
props->maxArrayLayers = 1;
1420
ac_modifier_max_extent(&dev->rad_info, modifier, &max_width, &max_height);
1421
props->maxExtent.width = MIN2(props->maxExtent.width, max_width);
1422
props->maxExtent.height = MIN2(props->maxExtent.width, max_height);
1424
/* We don't support MSAA for modifiers */
1425
props->sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
1429
VKAPI_ATTR void VKAPI_CALL
1430
radv_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format,
1431
VkFormatProperties2 *pFormatProperties)
1433
RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1434
VkFormatProperties3 format_props;
1436
radv_physical_device_get_format_properties(physical_device, format, &format_props);
1438
pFormatProperties->formatProperties.linearTilingFeatures =
1439
features2_to_features(format_props.linearTilingFeatures);
1440
pFormatProperties->formatProperties.optimalTilingFeatures =
1441
features2_to_features(format_props.optimalTilingFeatures);
1442
pFormatProperties->formatProperties.bufferFeatures =
1443
features2_to_features(format_props.bufferFeatures);
1445
VkFormatProperties3 *format_props_extended =
1446
vk_find_struct(pFormatProperties, FORMAT_PROPERTIES_3);
1447
if (format_props_extended) {
1448
format_props_extended->linearTilingFeatures = format_props.linearTilingFeatures;
1449
format_props_extended->optimalTilingFeatures = format_props.optimalTilingFeatures;
1450
format_props_extended->bufferFeatures = format_props.bufferFeatures;
1453
radv_list_drm_format_modifiers(
1454
physical_device, format, &format_props,
1455
vk_find_struct(pFormatProperties, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT));
1456
radv_list_drm_format_modifiers_2(
1457
physical_device, format, &format_props,
1458
vk_find_struct(pFormatProperties, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_2_EXT));
1462
radv_get_image_format_properties(struct radv_physical_device *physical_device,
1463
const VkPhysicalDeviceImageFormatInfo2 *info, VkFormat format,
1464
VkImageFormatProperties *pImageFormatProperties)
1467
VkFormatProperties3 format_props;
1468
VkFormatFeatureFlags2 format_feature_flags;
1469
VkExtent3D maxExtent;
1470
uint32_t maxMipLevels;
1471
uint32_t maxArraySize;
1472
VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
1473
const struct util_format_description *desc = vk_format_description(format);
1474
enum chip_class chip_class = physical_device->rad_info.chip_class;
1475
VkImageTiling tiling = info->tiling;
1476
const VkPhysicalDeviceImageDrmFormatModifierInfoEXT *mod_info =
1477
vk_find_struct_const(info->pNext, PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT);
1478
VkResult result = VK_ERROR_FORMAT_NOT_SUPPORTED;
1480
radv_physical_device_get_format_properties(physical_device, format, &format_props);
1481
if (tiling == VK_IMAGE_TILING_LINEAR) {
1482
format_feature_flags = format_props.linearTilingFeatures;
1483
} else if (tiling == VK_IMAGE_TILING_OPTIMAL) {
1484
format_feature_flags = format_props.optimalTilingFeatures;
1485
} else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
1486
format_feature_flags = radv_get_modifier_flags(physical_device, format,
1487
mod_info->drmFormatModifier, &format_props);
1489
unreachable("bad VkImageTiling");
1492
if (format_feature_flags == 0)
1495
if (info->type != VK_IMAGE_TYPE_2D && vk_format_is_depth_or_stencil(format))
1498
switch (info->type) {
1500
unreachable("bad vkimage type\n");
1501
case VK_IMAGE_TYPE_1D:
1502
maxExtent.width = 16384;
1503
maxExtent.height = 1;
1504
maxExtent.depth = 1;
1505
maxMipLevels = 15; /* log2(maxWidth) + 1 */
1506
maxArraySize = chip_class >= GFX10 ? 8192 : 2048;
1508
case VK_IMAGE_TYPE_2D:
1509
maxExtent.width = 16384;
1510
maxExtent.height = 16384;
1511
maxExtent.depth = 1;
1512
maxMipLevels = 15; /* log2(maxWidth) + 1 */
1513
maxArraySize = chip_class >= GFX10 ? 8192 : 2048;
1515
case VK_IMAGE_TYPE_3D:
1516
if (chip_class >= GFX10) {
1517
maxExtent.width = 8192;
1518
maxExtent.height = 8192;
1519
maxExtent.depth = 8192;
1521
maxExtent.width = 2048;
1522
maxExtent.height = 2048;
1523
maxExtent.depth = 2048;
1525
maxMipLevels = util_logbase2(maxExtent.width) + 1;
1530
if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
1531
/* Might be able to support but the entire format support is
1532
* messy, so taking the lazy way out. */
1536
if (tiling == VK_IMAGE_TILING_OPTIMAL && info->type == VK_IMAGE_TYPE_2D &&
1537
(format_feature_flags & (VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT |
1538
VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT)) &&
1539
!(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
1540
!(info->usage & VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR)) {
1541
sampleCounts |= VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT | VK_SAMPLE_COUNT_8_BIT;
1544
if (tiling == VK_IMAGE_TILING_LINEAR &&
1545
(format == VK_FORMAT_R32G32B32_SFLOAT || format == VK_FORMAT_R32G32B32_SINT ||
1546
format == VK_FORMAT_R32G32B32_UINT)) {
1547
/* R32G32B32 is a weird format and the driver currently only
1548
* supports the barely minimum.
1549
* TODO: Implement more if we really need to.
1551
if (info->type == VK_IMAGE_TYPE_3D)
1557
/* We can't create 3d compressed 128bpp images that can be rendered to on GFX9 */
1558
if (physical_device->rad_info.chip_class >= GFX9 && info->type == VK_IMAGE_TYPE_3D &&
1559
vk_format_get_blocksizebits(format) == 128 && vk_format_is_compressed(format) &&
1560
(info->flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT) &&
1561
((info->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT) ||
1562
(info->usage & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT))) {
1566
/* From the Vulkan 1.3.206 spec:
1568
* "VK_IMAGE_CREATE_EXTENDED_USAGE_BIT specifies that the image can be created with usage flags
1569
* that are not supported for the format the image is created with but are supported for at least
1570
* one format a VkImageView created from the image can have."
1572
VkImageUsageFlags image_usage = info->usage;
1573
if (info->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)
1576
if (image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
1577
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT)) {
1582
if (image_usage & VK_IMAGE_USAGE_STORAGE_BIT) {
1583
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT)) {
1588
if (image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
1589
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT)) {
1594
if (image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
1595
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT)) {
1600
if (image_usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
1601
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT)) {
1606
if (image_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
1607
if (!(format_feature_flags & VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT)) {
1612
if (image_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
1613
if (!(format_feature_flags & (VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT |
1614
VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT))) {
1619
/* Sparse resources with multi-planar formats are unsupported. */
1620
if (info->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
1621
if (vk_format_get_plane_count(format) > 1)
1625
if (info->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) {
1626
/* Sparse textures are only supported on GFX8+. */
1627
if (physical_device->rad_info.chip_class < GFX8)
1630
if (vk_format_get_plane_count(format) > 1 || info->type != VK_IMAGE_TYPE_2D ||
1631
info->tiling != VK_IMAGE_TILING_OPTIMAL || vk_format_is_depth_or_stencil(format))
1636
(VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT)) &&
1637
(desc->layout == UTIL_FORMAT_LAYOUT_ETC && physical_device->emulate_etc2)) {
1641
*pImageFormatProperties = (VkImageFormatProperties){
1642
.maxExtent = maxExtent,
1643
.maxMipLevels = maxMipLevels,
1644
.maxArrayLayers = maxArraySize,
1645
.sampleCounts = sampleCounts,
1647
/* FINISHME: Accurately calculate
1648
* VkImageFormatProperties::maxResourceSize.
1650
.maxResourceSize = UINT32_MAX,
1654
result = radv_check_modifier_support(physical_device, info, pImageFormatProperties, format,
1655
mod_info->drmFormatModifier);
1656
if (result != VK_SUCCESS)
1662
*pImageFormatProperties = (VkImageFormatProperties){
1663
.maxExtent = {0, 0, 0},
1665
.maxArrayLayers = 0,
1667
.maxResourceSize = 0,
1674
get_external_image_format_properties(struct radv_physical_device *physical_device,
1675
const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
1676
VkExternalMemoryHandleTypeFlagBits handleType,
1677
VkExternalMemoryProperties *external_properties,
1678
VkImageFormatProperties *format_properties)
1680
VkExternalMemoryFeatureFlagBits flags = 0;
1681
VkExternalMemoryHandleTypeFlags export_flags = 0;
1682
VkExternalMemoryHandleTypeFlags compat_flags = 0;
1683
const struct util_format_description *desc = vk_format_description(pImageFormatInfo->format);
1685
if (!desc || (desc->layout == UTIL_FORMAT_LAYOUT_ETC && physical_device->emulate_etc2))
1688
if (pImageFormatInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
1691
switch (handleType) {
1692
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
1693
if (pImageFormatInfo->tiling != VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT)
1696
switch (pImageFormatInfo->type) {
1697
case VK_IMAGE_TYPE_2D:
1699
VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1701
compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
1707
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
1708
switch (pImageFormatInfo->type) {
1709
case VK_IMAGE_TYPE_2D:
1711
VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1712
if (pImageFormatInfo->tiling != VK_IMAGE_TILING_LINEAR)
1713
flags |= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
1715
compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
1721
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID:
1722
if (!physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer)
1725
if (!radv_android_gralloc_supports_format(pImageFormatInfo->format, pImageFormatInfo->usage))
1728
if (pImageFormatInfo->type != VK_IMAGE_TYPE_2D)
1731
format_properties->maxMipLevels = MIN2(1, format_properties->maxMipLevels);
1732
format_properties->maxArrayLayers = MIN2(1, format_properties->maxArrayLayers);
1733
format_properties->sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
1735
flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1736
if (pImageFormatInfo->tiling != VK_IMAGE_TILING_LINEAR)
1737
flags |= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT;
1739
compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
1741
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
1742
flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1743
compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
1749
*external_properties = (VkExternalMemoryProperties){
1750
.externalMemoryFeatures = flags,
1751
.exportFromImportedHandleTypes = export_flags,
1752
.compatibleHandleTypes = compat_flags,
1756
VKAPI_ATTR VkResult VKAPI_CALL
1757
radv_GetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,
1758
const VkPhysicalDeviceImageFormatInfo2 *base_info,
1759
VkImageFormatProperties2 *base_props)
1761
RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
1762
const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
1763
VkExternalImageFormatProperties *external_props = NULL;
1764
struct VkAndroidHardwareBufferUsageANDROID *android_usage = NULL;
1765
VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
1766
VkTextureLODGatherFormatPropertiesAMD *texture_lod_props = NULL;
1768
VkFormat format = radv_select_android_external_format(base_info->pNext, base_info->format);
1770
result = radv_get_image_format_properties(physical_device, base_info, format,
1771
&base_props->imageFormatProperties);
1772
if (result != VK_SUCCESS)
1775
/* Extract input structs */
1776
vk_foreach_struct_const(s, base_info->pNext)
1779
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
1780
external_info = (const void *)s;
1787
/* Extract output structs */
1788
vk_foreach_struct(s, base_props->pNext)
1791
case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
1792
external_props = (void *)s;
1794
case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
1795
ycbcr_props = (void *)s;
1797
case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID:
1798
android_usage = (void *)s;
1800
case VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD:
1801
texture_lod_props = (void *)s;
1808
bool ahb_supported =
1809
physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer;
1810
if (android_usage && ahb_supported) {
1811
#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
1812
android_usage->androidHardwareBufferUsage =
1813
radv_ahb_usage_from_vk_usage(base_info->flags, base_info->usage);
1817
/* From the Vulkan 1.0.97 spec:
1819
* If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
1820
* behave as if VkPhysicalDeviceExternalImageFormatInfo was not
1821
* present and VkExternalImageFormatProperties will be ignored.
1823
if (external_info && external_info->handleType != 0) {
1824
VkExternalImageFormatProperties fallback_external_props;
1826
if (!external_props) {
1827
memset(&fallback_external_props, 0, sizeof(fallback_external_props));
1828
external_props = &fallback_external_props;
1831
get_external_image_format_properties(physical_device, base_info, external_info->handleType,
1832
&external_props->externalMemoryProperties,
1833
&base_props->imageFormatProperties);
1834
if (!external_props->externalMemoryProperties.externalMemoryFeatures) {
1835
/* From the Vulkan 1.0.97 spec:
1837
* If handleType is not compatible with the [parameters] specified
1838
* in VkPhysicalDeviceImageFormatInfo2, then
1839
* vkGetPhysicalDeviceImageFormatProperties2 returns
1840
* VK_ERROR_FORMAT_NOT_SUPPORTED.
1842
result = vk_errorf(physical_device, VK_ERROR_FORMAT_NOT_SUPPORTED,
1843
"unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
1844
external_info->handleType);
1850
ycbcr_props->combinedImageSamplerDescriptorCount = vk_format_get_plane_count(format);
1853
if (texture_lod_props) {
1854
if (physical_device->rad_info.chip_class >= GFX9) {
1855
texture_lod_props->supportsTextureGatherLODBiasAMD = true;
1857
texture_lod_props->supportsTextureGatherLODBiasAMD = !vk_format_is_int(format);
1864
if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
1865
/* From the Vulkan 1.0.97 spec:
1867
* If the combination of parameters to
1868
* vkGetPhysicalDeviceImageFormatProperties2 is not supported by
1869
* the implementation for use in vkCreateImage, then all members of
1870
* imageFormatProperties will be filled with zero.
1872
base_props->imageFormatProperties = (VkImageFormatProperties){0};
1879
fill_sparse_image_format_properties(struct radv_physical_device *pdev, VkFormat format,
1880
VkSparseImageFormatProperties *prop)
1882
prop->aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1885
/* On GFX8 we first subdivide by level and then layer, leading to a single
1886
* miptail. On GFX9+ we first subdivide by layer and then level which results
1887
* in a miptail per layer. */
1888
if (pdev->rad_info.chip_class < GFX9)
1889
prop->flags |= VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT;
1891
/* This assumes the sparse image tile size is always 64 KiB (1 << 16) */
1892
unsigned l2_size = 16 - util_logbase2(vk_format_get_blocksize(format));
1893
unsigned w = (1u << ((l2_size + 1) / 2)) * vk_format_get_blockwidth(format);
1894
unsigned h = (1u << (l2_size / 2)) * vk_format_get_blockheight(format);
1896
prop->imageGranularity = (VkExtent3D){w, h, 1};
1899
VKAPI_ATTR void VKAPI_CALL
1900
radv_GetPhysicalDeviceSparseImageFormatProperties2(
1901
VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2 *pFormatInfo,
1902
uint32_t *pPropertyCount, VkSparseImageFormatProperties2 *pProperties)
1904
RADV_FROM_HANDLE(radv_physical_device, pdev, physicalDevice);
1907
if (pFormatInfo->samples > VK_SAMPLE_COUNT_1_BIT) {
1908
*pPropertyCount = 0;
1912
const VkPhysicalDeviceImageFormatInfo2 fmt_info = {
1913
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
1914
.format = pFormatInfo->format,
1915
.type = pFormatInfo->type,
1916
.tiling = pFormatInfo->tiling,
1917
.usage = pFormatInfo->usage,
1918
.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT};
1920
VkImageFormatProperties fmt_props;
1921
result = radv_get_image_format_properties(pdev, &fmt_info, pFormatInfo->format, &fmt_props);
1922
if (result != VK_SUCCESS) {
1923
*pPropertyCount = 0;
1927
VK_OUTARRAY_MAKE_TYPED(VkSparseImageFormatProperties2, out, pProperties, pPropertyCount);
1929
vk_outarray_append_typed(VkSparseImageFormatProperties2, &out, prop)
1931
fill_sparse_image_format_properties(pdev, pFormatInfo->format, &prop->properties);
1935
VKAPI_ATTR void VKAPI_CALL
1936
radv_GetImageSparseMemoryRequirements2(VkDevice _device,
1937
const VkImageSparseMemoryRequirementsInfo2 *pInfo,
1938
uint32_t *pSparseMemoryRequirementCount,
1939
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements)
1941
RADV_FROM_HANDLE(radv_device, device, _device);
1942
RADV_FROM_HANDLE(radv_image, image, pInfo->image);
1944
if (!(image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
1945
*pSparseMemoryRequirementCount = 0;
1949
VK_OUTARRAY_MAKE_TYPED(VkSparseImageMemoryRequirements2, out, pSparseMemoryRequirements,
1950
pSparseMemoryRequirementCount);
1952
vk_outarray_append_typed(VkSparseImageMemoryRequirements2, &out, req)
1954
fill_sparse_image_format_properties(device->physical_device, image->vk_format,
1955
&req->memoryRequirements.formatProperties);
1956
req->memoryRequirements.imageMipTailFirstLod = image->planes[0].surface.first_mip_tail_level;
1958
if (req->memoryRequirements.imageMipTailFirstLod < image->info.levels) {
1959
if (device->physical_device->rad_info.chip_class >= GFX9) {
1960
/* The tail is always a single tile per layer. */
1961
req->memoryRequirements.imageMipTailSize = 65536;
1962
req->memoryRequirements.imageMipTailOffset =
1964
.surface.u.gfx9.prt_level_offset[req->memoryRequirements.imageMipTailFirstLod] &
1966
req->memoryRequirements.imageMipTailStride =
1967
image->planes[0].surface.u.gfx9.surf_slice_size;
1969
req->memoryRequirements.imageMipTailOffset =
1970
(uint64_t)image->planes[0]
1971
.surface.u.legacy.level[req->memoryRequirements.imageMipTailFirstLod]
1973
req->memoryRequirements.imageMipTailSize =
1974
image->size - req->memoryRequirements.imageMipTailOffset;
1975
req->memoryRequirements.imageMipTailStride = 0;
1978
req->memoryRequirements.imageMipTailSize = 0;
1979
req->memoryRequirements.imageMipTailOffset = 0;
1980
req->memoryRequirements.imageMipTailStride = 0;
1985
VKAPI_ATTR void VKAPI_CALL
1986
radv_GetDeviceImageSparseMemoryRequirements(VkDevice device,
1987
const VkDeviceImageMemoryRequirements* pInfo,
1988
uint32_t *pSparseMemoryRequirementCount,
1989
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements)
1991
UNUSED VkResult result;
1994
/* Determining the image size/alignment require to create a surface, which is complicated without
1995
* creating an image.
1996
* TODO: Avoid creating an image.
1998
result = radv_CreateImage(device, pInfo->pCreateInfo, NULL, &image);
1999
assert(result == VK_SUCCESS);
2001
VkImageSparseMemoryRequirementsInfo2 info2 = {
2002
.sType = VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2,
2006
radv_GetImageSparseMemoryRequirements2(device, &info2, pSparseMemoryRequirementCount,
2007
pSparseMemoryRequirements);
2009
radv_DestroyImage(device, image, NULL);
2012
VKAPI_ATTR void VKAPI_CALL
2013
radv_GetPhysicalDeviceExternalBufferProperties(
2014
VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
2015
VkExternalBufferProperties *pExternalBufferProperties)
2017
VkExternalMemoryFeatureFlagBits flags = 0;
2018
VkExternalMemoryHandleTypeFlags export_flags = 0;
2019
VkExternalMemoryHandleTypeFlags compat_flags = 0;
2020
switch (pExternalBufferInfo->handleType) {
2021
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
2022
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
2023
flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
2024
compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
2025
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
2027
case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
2028
flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
2029
compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
2034
pExternalBufferProperties->externalMemoryProperties = (VkExternalMemoryProperties){
2035
.externalMemoryFeatures = flags,
2036
.exportFromImportedHandleTypes = export_flags,
2037
.compatibleHandleTypes = compat_flags,
2041
/* DCC channel type categories within which formats can be reinterpreted
2042
* while keeping the same DCC encoding. The swizzle must also match. */
2043
enum dcc_channel_type {
2047
dcc_channel_incompatible,
2050
/* Return the type of DCC encoding. */
2052
radv_get_dcc_channel_type(const struct util_format_description *desc, enum dcc_channel_type *type,
2057
/* Find the first non-void channel. */
2058
for (i = 0; i < desc->nr_channels; i++)
2059
if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
2061
if (i == desc->nr_channels) {
2062
*type = dcc_channel_incompatible;
2066
switch (desc->channel[i].size) {
2071
*size = desc->channel[i].size;
2072
if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
2073
*type = dcc_channel_float;
2074
else if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
2075
*type = dcc_channel_uint;
2077
*type = dcc_channel_sint;
2080
*type = dcc_channel_incompatible;
2085
/* Return if it's allowed to reinterpret one format as another with DCC enabled. */
2087
radv_dcc_formats_compatible(VkFormat format1, VkFormat format2, bool *sign_reinterpret)
2089
const struct util_format_description *desc1, *desc2;
2090
enum dcc_channel_type type1, type2;
2091
unsigned size1, size2;
2094
if (format1 == format2)
2097
desc1 = vk_format_description(format1);
2098
desc2 = vk_format_description(format2);
2100
if (desc1->nr_channels != desc2->nr_channels)
2103
/* Swizzles must be the same. */
2104
for (i = 0; i < desc1->nr_channels; i++)
2105
if (desc1->swizzle[i] <= PIPE_SWIZZLE_W && desc2->swizzle[i] <= PIPE_SWIZZLE_W &&
2106
desc1->swizzle[i] != desc2->swizzle[i])
2109
radv_get_dcc_channel_type(desc1, &type1, &size1);
2110
radv_get_dcc_channel_type(desc2, &type2, &size2);
2112
if (type1 == dcc_channel_incompatible || type2 == dcc_channel_incompatible ||
2113
(type1 == dcc_channel_float) != (type2 == dcc_channel_float) || size1 != size2)
2117
*sign_reinterpret = true;