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_private.h"
27 #include "vk_format.h"
32 #include "util/u_half.h"
33 #include "util/format_srgb.h"
34 #include "util/format_r11g11b10f.h"
36 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description
*desc
,
42 assert(desc
->layout
!= VK_FORMAT_LAYOUT_MULTIPLANE
);
44 if (desc
->format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
45 return V_008F0C_BUF_DATA_FORMAT_10_11_11
;
47 if (first_non_void
< 0)
48 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
49 type
= desc
->channel
[first_non_void
].type
;
51 if (type
== VK_FORMAT_TYPE_FIXED
)
52 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
53 if (desc
->nr_channels
== 4 &&
54 desc
->channel
[0].size
== 10 &&
55 desc
->channel
[1].size
== 10 &&
56 desc
->channel
[2].size
== 10 &&
57 desc
->channel
[3].size
== 2)
58 return V_008F0C_BUF_DATA_FORMAT_2_10_10_10
;
60 /* See whether the components are of the same size. */
61 for (i
= 0; i
< desc
->nr_channels
; i
++) {
62 if (desc
->channel
[first_non_void
].size
!= desc
->channel
[i
].size
)
63 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
66 switch (desc
->channel
[first_non_void
].size
) {
68 switch (desc
->nr_channels
) {
70 return V_008F0C_BUF_DATA_FORMAT_8
;
72 return V_008F0C_BUF_DATA_FORMAT_8_8
;
74 return V_008F0C_BUF_DATA_FORMAT_8_8_8_8
;
78 switch (desc
->nr_channels
) {
80 return V_008F0C_BUF_DATA_FORMAT_16
;
82 return V_008F0C_BUF_DATA_FORMAT_16_16
;
84 return V_008F0C_BUF_DATA_FORMAT_16_16_16_16
;
88 /* From the Southern Islands ISA documentation about MTBUF:
89 * 'Memory reads of data in memory that is 32 or 64 bits do not
90 * undergo any format conversion.'
92 if (type
!= VK_FORMAT_TYPE_FLOAT
&&
93 !desc
->channel
[first_non_void
].pure_integer
)
94 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
96 switch (desc
->nr_channels
) {
98 return V_008F0C_BUF_DATA_FORMAT_32
;
100 return V_008F0C_BUF_DATA_FORMAT_32_32
;
102 return V_008F0C_BUF_DATA_FORMAT_32_32_32
;
104 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
109 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
112 uint32_t radv_translate_buffer_numformat(const struct vk_format_description
*desc
,
115 assert(desc
->layout
!= VK_FORMAT_LAYOUT_MULTIPLANE
);
117 if (desc
->format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
118 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
120 if (first_non_void
< 0)
123 switch (desc
->channel
[first_non_void
].type
) {
124 case VK_FORMAT_TYPE_SIGNED
:
125 if (desc
->channel
[first_non_void
].normalized
)
126 return V_008F0C_BUF_NUM_FORMAT_SNORM
;
127 else if (desc
->channel
[first_non_void
].pure_integer
)
128 return V_008F0C_BUF_NUM_FORMAT_SINT
;
130 return V_008F0C_BUF_NUM_FORMAT_SSCALED
;
132 case VK_FORMAT_TYPE_UNSIGNED
:
133 if (desc
->channel
[first_non_void
].normalized
)
134 return V_008F0C_BUF_NUM_FORMAT_UNORM
;
135 else if (desc
->channel
[first_non_void
].pure_integer
)
136 return V_008F0C_BUF_NUM_FORMAT_UINT
;
138 return V_008F0C_BUF_NUM_FORMAT_USCALED
;
140 case VK_FORMAT_TYPE_FLOAT
:
142 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
146 uint32_t radv_translate_tex_dataformat(VkFormat format
,
147 const struct vk_format_description
*desc
,
153 assert(vk_format_get_plane_count(format
) == 1);
157 /* Colorspace (return non-RGB formats directly). */
158 switch (desc
->colorspace
) {
159 /* Depth stencil formats */
160 case VK_FORMAT_COLORSPACE_ZS
:
162 case VK_FORMAT_D16_UNORM
:
163 return V_008F14_IMG_DATA_FORMAT_16
;
164 case VK_FORMAT_D24_UNORM_S8_UINT
:
165 case VK_FORMAT_X8_D24_UNORM_PACK32
:
166 return V_008F14_IMG_DATA_FORMAT_8_24
;
167 case VK_FORMAT_S8_UINT
:
168 return V_008F14_IMG_DATA_FORMAT_8
;
169 case VK_FORMAT_D32_SFLOAT
:
170 return V_008F14_IMG_DATA_FORMAT_32
;
171 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
172 return V_008F14_IMG_DATA_FORMAT_X24_8_32
;
177 case VK_FORMAT_COLORSPACE_YUV
:
178 goto out_unknown
; /* TODO */
180 case VK_FORMAT_COLORSPACE_SRGB
:
181 if (desc
->nr_channels
!= 4 && desc
->nr_channels
!= 1)
189 if (desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
191 /* Don't ask me why this looks inverted. PAL does the same. */
192 case VK_FORMAT_G8B8G8R8_422_UNORM
:
193 return V_008F14_IMG_DATA_FORMAT_BG_RG
;
194 case VK_FORMAT_B8G8R8G8_422_UNORM
:
195 return V_008F14_IMG_DATA_FORMAT_GB_GR
;
201 if (desc
->layout
== VK_FORMAT_LAYOUT_RGTC
) {
203 case VK_FORMAT_BC4_UNORM_BLOCK
:
204 case VK_FORMAT_BC4_SNORM_BLOCK
:
205 return V_008F14_IMG_DATA_FORMAT_BC4
;
206 case VK_FORMAT_BC5_UNORM_BLOCK
:
207 case VK_FORMAT_BC5_SNORM_BLOCK
:
208 return V_008F14_IMG_DATA_FORMAT_BC5
;
214 if (desc
->layout
== VK_FORMAT_LAYOUT_S3TC
) {
216 case VK_FORMAT_BC1_RGB_UNORM_BLOCK
:
217 case VK_FORMAT_BC1_RGB_SRGB_BLOCK
:
218 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK
:
219 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK
:
220 return V_008F14_IMG_DATA_FORMAT_BC1
;
221 case VK_FORMAT_BC2_UNORM_BLOCK
:
222 case VK_FORMAT_BC2_SRGB_BLOCK
:
223 return V_008F14_IMG_DATA_FORMAT_BC2
;
224 case VK_FORMAT_BC3_UNORM_BLOCK
:
225 case VK_FORMAT_BC3_SRGB_BLOCK
:
226 return V_008F14_IMG_DATA_FORMAT_BC3
;
232 if (desc
->layout
== VK_FORMAT_LAYOUT_BPTC
) {
234 case VK_FORMAT_BC6H_UFLOAT_BLOCK
:
235 case VK_FORMAT_BC6H_SFLOAT_BLOCK
:
236 return V_008F14_IMG_DATA_FORMAT_BC6
;
237 case VK_FORMAT_BC7_UNORM_BLOCK
:
238 case VK_FORMAT_BC7_SRGB_BLOCK
:
239 return V_008F14_IMG_DATA_FORMAT_BC7
;
245 if (desc
->layout
== VK_FORMAT_LAYOUT_ETC
) {
247 case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
:
248 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK
:
249 return V_008F14_IMG_DATA_FORMAT_ETC2_RGB
;
250 case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK
:
251 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK
:
252 return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA1
;
253 case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK
:
254 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK
:
255 return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA
;
256 case VK_FORMAT_EAC_R11_UNORM_BLOCK
:
257 case VK_FORMAT_EAC_R11_SNORM_BLOCK
:
258 return V_008F14_IMG_DATA_FORMAT_ETC2_R
;
259 case VK_FORMAT_EAC_R11G11_UNORM_BLOCK
:
260 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK
:
261 return V_008F14_IMG_DATA_FORMAT_ETC2_RG
;
267 if (format
== VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
) {
268 return V_008F14_IMG_DATA_FORMAT_5_9_9_9
;
269 } else if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) {
270 return V_008F14_IMG_DATA_FORMAT_10_11_11
;
273 /* R8G8Bx_SNORM - TODO CxV8U8 */
275 /* hw cannot support mixed formats (except depth/stencil, since only
277 if (desc
->is_mixed
&& desc
->colorspace
!= VK_FORMAT_COLORSPACE_ZS
)
280 /* See whether the components are of the same size. */
281 for (i
= 1; i
< desc
->nr_channels
; i
++) {
282 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
285 /* Non-uniform formats. */
287 switch(desc
->nr_channels
) {
289 if (desc
->channel
[0].size
== 5 &&
290 desc
->channel
[1].size
== 6 &&
291 desc
->channel
[2].size
== 5) {
292 return V_008F14_IMG_DATA_FORMAT_5_6_5
;
296 if (desc
->channel
[0].size
== 5 &&
297 desc
->channel
[1].size
== 5 &&
298 desc
->channel
[2].size
== 5 &&
299 desc
->channel
[3].size
== 1) {
300 return V_008F14_IMG_DATA_FORMAT_1_5_5_5
;
302 if (desc
->channel
[0].size
== 1 &&
303 desc
->channel
[1].size
== 5 &&
304 desc
->channel
[2].size
== 5 &&
305 desc
->channel
[3].size
== 5) {
306 return V_008F14_IMG_DATA_FORMAT_5_5_5_1
;
308 if (desc
->channel
[0].size
== 10 &&
309 desc
->channel
[1].size
== 10 &&
310 desc
->channel
[2].size
== 10 &&
311 desc
->channel
[3].size
== 2) {
312 /* Closed VK driver does this also no 2/10/10/10 snorm */
313 if (desc
->channel
[0].type
== VK_FORMAT_TYPE_SIGNED
&&
314 desc
->channel
[0].normalized
)
316 return V_008F14_IMG_DATA_FORMAT_2_10_10_10
;
323 if (first_non_void
< 0 || first_non_void
> 3)
326 /* uniform formats */
327 switch (desc
->channel
[first_non_void
].size
) {
329 switch (desc
->nr_channels
) {
330 #if 0 /* Not supported for render targets */
332 return V_008F14_IMG_DATA_FORMAT_4_4
;
335 return V_008F14_IMG_DATA_FORMAT_4_4_4_4
;
339 switch (desc
->nr_channels
) {
341 return V_008F14_IMG_DATA_FORMAT_8
;
343 return V_008F14_IMG_DATA_FORMAT_8_8
;
345 return V_008F14_IMG_DATA_FORMAT_8_8_8_8
;
349 switch (desc
->nr_channels
) {
351 return V_008F14_IMG_DATA_FORMAT_16
;
353 return V_008F14_IMG_DATA_FORMAT_16_16
;
355 return V_008F14_IMG_DATA_FORMAT_16_16_16_16
;
359 switch (desc
->nr_channels
) {
361 return V_008F14_IMG_DATA_FORMAT_32
;
363 return V_008F14_IMG_DATA_FORMAT_32_32
;
365 return V_008F14_IMG_DATA_FORMAT_32_32_32
;
367 return V_008F14_IMG_DATA_FORMAT_32_32_32_32
;
372 /* R600_ERR("Unable to handle texformat %d %s\n", format, vk_format_name(format)); */
376 uint32_t radv_translate_tex_numformat(VkFormat format
,
377 const struct vk_format_description
*desc
,
380 assert(vk_format_get_plane_count(format
) == 1);
383 case VK_FORMAT_D24_UNORM_S8_UINT
:
384 return V_008F14_IMG_NUM_FORMAT_UNORM
;
386 if (first_non_void
< 0) {
387 if (vk_format_is_compressed(format
)) {
389 case VK_FORMAT_BC1_RGB_SRGB_BLOCK
:
390 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK
:
391 case VK_FORMAT_BC2_SRGB_BLOCK
:
392 case VK_FORMAT_BC3_SRGB_BLOCK
:
393 case VK_FORMAT_BC7_SRGB_BLOCK
:
394 case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK
:
395 case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK
:
396 case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK
:
397 return V_008F14_IMG_NUM_FORMAT_SRGB
;
398 case VK_FORMAT_BC4_SNORM_BLOCK
:
399 case VK_FORMAT_BC5_SNORM_BLOCK
:
400 case VK_FORMAT_BC6H_SFLOAT_BLOCK
:
401 case VK_FORMAT_EAC_R11_SNORM_BLOCK
:
402 case VK_FORMAT_EAC_R11G11_SNORM_BLOCK
:
403 return V_008F14_IMG_NUM_FORMAT_SNORM
;
405 return V_008F14_IMG_NUM_FORMAT_UNORM
;
407 } else if (desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
408 return V_008F14_IMG_NUM_FORMAT_UNORM
;
410 return V_008F14_IMG_NUM_FORMAT_FLOAT
;
412 } else if (desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
) {
413 return V_008F14_IMG_NUM_FORMAT_SRGB
;
415 switch (desc
->channel
[first_non_void
].type
) {
416 case VK_FORMAT_TYPE_FLOAT
:
417 return V_008F14_IMG_NUM_FORMAT_FLOAT
;
418 case VK_FORMAT_TYPE_SIGNED
:
419 if (desc
->channel
[first_non_void
].normalized
)
420 return V_008F14_IMG_NUM_FORMAT_SNORM
;
421 else if (desc
->channel
[first_non_void
].pure_integer
)
422 return V_008F14_IMG_NUM_FORMAT_SINT
;
424 return V_008F14_IMG_NUM_FORMAT_SSCALED
;
425 case VK_FORMAT_TYPE_UNSIGNED
:
426 if (desc
->channel
[first_non_void
].normalized
)
427 return V_008F14_IMG_NUM_FORMAT_UNORM
;
428 else if (desc
->channel
[first_non_void
].pure_integer
)
429 return V_008F14_IMG_NUM_FORMAT_UINT
;
431 return V_008F14_IMG_NUM_FORMAT_USCALED
;
433 return V_008F14_IMG_NUM_FORMAT_UNORM
;
439 uint32_t radv_translate_color_numformat(VkFormat format
,
440 const struct vk_format_description
*desc
,
445 assert(vk_format_get_plane_count(format
) == 1);
447 if (first_non_void
== -1 || desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_FLOAT
)
448 ntype
= V_028C70_NUMBER_FLOAT
;
450 ntype
= V_028C70_NUMBER_UNORM
;
451 if (desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
)
452 ntype
= V_028C70_NUMBER_SRGB
;
453 else if (desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_SIGNED
) {
454 if (desc
->channel
[first_non_void
].pure_integer
) {
455 ntype
= V_028C70_NUMBER_SINT
;
456 } else if (desc
->channel
[first_non_void
].normalized
) {
457 ntype
= V_028C70_NUMBER_SNORM
;
460 } else if (desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_UNSIGNED
) {
461 if (desc
->channel
[first_non_void
].pure_integer
) {
462 ntype
= V_028C70_NUMBER_UINT
;
463 } else if (desc
->channel
[first_non_void
].normalized
) {
464 ntype
= V_028C70_NUMBER_UNORM
;
472 static bool radv_is_sampler_format_supported(VkFormat format
, bool *linear_sampling
)
474 const struct vk_format_description
*desc
= vk_format_description(format
);
476 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
478 num_format
= radv_translate_tex_numformat(format
, desc
,
479 vk_format_get_first_non_void_channel(format
));
481 if (num_format
== V_008F14_IMG_NUM_FORMAT_USCALED
||
482 num_format
== V_008F14_IMG_NUM_FORMAT_SSCALED
)
485 if (num_format
== V_008F14_IMG_NUM_FORMAT_UNORM
||
486 num_format
== V_008F14_IMG_NUM_FORMAT_SNORM
||
487 num_format
== V_008F14_IMG_NUM_FORMAT_FLOAT
||
488 num_format
== V_008F14_IMG_NUM_FORMAT_SRGB
)
489 *linear_sampling
= true;
491 *linear_sampling
= false;
492 return radv_translate_tex_dataformat(format
, vk_format_description(format
),
493 vk_format_get_first_non_void_channel(format
)) != ~0U;
497 static bool radv_is_storage_image_format_supported(struct radv_physical_device
*physical_device
,
500 const struct vk_format_description
*desc
= vk_format_description(format
);
501 unsigned data_format
, num_format
;
502 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
505 data_format
= radv_translate_tex_dataformat(format
, desc
,
506 vk_format_get_first_non_void_channel(format
));
507 num_format
= radv_translate_tex_numformat(format
, desc
,
508 vk_format_get_first_non_void_channel(format
));
510 if(data_format
== ~0 || num_format
== ~0)
513 /* Extracted from the GCN3 ISA document. */
515 case V_008F14_IMG_NUM_FORMAT_UNORM
:
516 case V_008F14_IMG_NUM_FORMAT_SNORM
:
517 case V_008F14_IMG_NUM_FORMAT_UINT
:
518 case V_008F14_IMG_NUM_FORMAT_SINT
:
519 case V_008F14_IMG_NUM_FORMAT_FLOAT
:
525 switch(data_format
) {
526 case V_008F14_IMG_DATA_FORMAT_8
:
527 case V_008F14_IMG_DATA_FORMAT_16
:
528 case V_008F14_IMG_DATA_FORMAT_8_8
:
529 case V_008F14_IMG_DATA_FORMAT_32
:
530 case V_008F14_IMG_DATA_FORMAT_16_16
:
531 case V_008F14_IMG_DATA_FORMAT_10_11_11
:
532 case V_008F14_IMG_DATA_FORMAT_11_11_10
:
533 case V_008F14_IMG_DATA_FORMAT_10_10_10_2
:
534 case V_008F14_IMG_DATA_FORMAT_2_10_10_10
:
535 case V_008F14_IMG_DATA_FORMAT_8_8_8_8
:
536 case V_008F14_IMG_DATA_FORMAT_32_32
:
537 case V_008F14_IMG_DATA_FORMAT_16_16_16_16
:
538 case V_008F14_IMG_DATA_FORMAT_32_32_32_32
:
539 case V_008F14_IMG_DATA_FORMAT_5_6_5
:
540 case V_008F14_IMG_DATA_FORMAT_1_5_5_5
:
541 case V_008F14_IMG_DATA_FORMAT_5_5_5_1
:
542 case V_008F14_IMG_DATA_FORMAT_4_4_4_4
:
543 /* TODO: FMASK formats. */
550 bool radv_is_buffer_format_supported(VkFormat format
, bool *scaled
)
552 const struct vk_format_description
*desc
= vk_format_description(format
);
553 unsigned data_format
, num_format
;
554 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
557 data_format
= radv_translate_buffer_dataformat(desc
,
558 vk_format_get_first_non_void_channel(format
));
559 num_format
= radv_translate_buffer_numformat(desc
,
560 vk_format_get_first_non_void_channel(format
));
563 *scaled
= (num_format
== V_008F0C_BUF_NUM_FORMAT_SSCALED
) || (num_format
== V_008F0C_BUF_NUM_FORMAT_USCALED
);
564 return data_format
!= V_008F0C_BUF_DATA_FORMAT_INVALID
&&
568 bool radv_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
)
570 const struct vk_format_description
*desc
= vk_format_description(format
);
571 uint32_t color_format
= radv_translate_colorformat(format
);
572 uint32_t color_swap
= radv_translate_colorswap(format
, false);
573 uint32_t color_num_format
= radv_translate_color_numformat(format
,
575 vk_format_get_first_non_void_channel(format
));
577 if (color_num_format
== V_028C70_NUMBER_UINT
|| color_num_format
== V_028C70_NUMBER_SINT
||
578 color_format
== V_028C70_COLOR_8_24
|| color_format
== V_028C70_COLOR_24_8
||
579 color_format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
583 return color_format
!= V_028C70_COLOR_INVALID
&&
585 color_num_format
!= ~0;
588 static bool radv_is_zs_format_supported(VkFormat format
)
590 return radv_translate_dbformat(format
) != V_028040_Z_INVALID
|| format
== VK_FORMAT_S8_UINT
;
593 static bool radv_is_filter_minmax_format_supported(VkFormat format
)
595 /* From the Vulkan spec 1.1.71:
597 * "The following formats must support the
598 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT feature with
599 * VK_IMAGE_TILING_OPTIMAL, if they support
600 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT."
602 /* TODO: enable more formats. */
604 case VK_FORMAT_R8_UNORM
:
605 case VK_FORMAT_R8_SNORM
:
606 case VK_FORMAT_R16_UNORM
:
607 case VK_FORMAT_R16_SNORM
:
608 case VK_FORMAT_R16_SFLOAT
:
609 case VK_FORMAT_R32_SFLOAT
:
610 case VK_FORMAT_D16_UNORM
:
611 case VK_FORMAT_X8_D24_UNORM_PACK32
:
612 case VK_FORMAT_D32_SFLOAT
:
613 case VK_FORMAT_D16_UNORM_S8_UINT
:
614 case VK_FORMAT_D24_UNORM_S8_UINT
:
615 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
623 radv_device_supports_etc(struct radv_physical_device
*physical_device
)
625 return physical_device
->rad_info
.family
== CHIP_VEGA10
||
626 physical_device
->rad_info
.family
== CHIP_RAVEN
||
627 physical_device
->rad_info
.family
== CHIP_RAVEN2
||
628 physical_device
->rad_info
.family
== CHIP_STONEY
;
632 radv_physical_device_get_format_properties(struct radv_physical_device
*physical_device
,
634 VkFormatProperties
*out_properties
)
636 VkFormatFeatureFlags linear
= 0, tiled
= 0, buffer
= 0;
637 const struct vk_format_description
*desc
= vk_format_description(format
);
640 /* TODO: implement some software emulation of SUBSAMPLED formats. */
641 if (!desc
|| desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
642 out_properties
->linearTilingFeatures
= linear
;
643 out_properties
->optimalTilingFeatures
= tiled
;
644 out_properties
->bufferFeatures
= buffer
;
648 if (desc
->layout
== VK_FORMAT_LAYOUT_ETC
&&
649 !radv_device_supports_etc(physical_device
)) {
650 out_properties
->linearTilingFeatures
= linear
;
651 out_properties
->optimalTilingFeatures
= tiled
;
652 out_properties
->bufferFeatures
= buffer
;
656 if (desc
->layout
== VK_FORMAT_LAYOUT_MULTIPLANE
||
657 desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
658 uint32_t tiling
= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
659 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
|
660 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
661 VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT
|
662 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT
;
664 /* The subsampled formats have no support for linear filters. */
665 if (desc
->layout
!= VK_FORMAT_LAYOUT_SUBSAMPLED
) {
666 tiling
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT
;
669 /* Fails for unknown reasons with linear tiling & subsampled formats. */
670 out_properties
->linearTilingFeatures
= desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
? 0 : tiling
;
671 out_properties
->optimalTilingFeatures
= tiling
;
672 out_properties
->bufferFeatures
= 0;
676 if (radv_is_storage_image_format_supported(physical_device
, format
)) {
677 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
678 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
681 if (radv_is_buffer_format_supported(format
, &scaled
)) {
682 buffer
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
684 buffer
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
685 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
688 if (vk_format_is_depth_or_stencil(format
)) {
689 if (radv_is_zs_format_supported(format
)) {
690 tiled
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
;
691 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
692 tiled
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
693 VK_FORMAT_FEATURE_BLIT_DST_BIT
;
694 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
695 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
697 if (radv_is_filter_minmax_format_supported(format
))
698 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT
;
700 /* Don't support blitting surfaces with depth/stencil. */
701 if (vk_format_is_depth(format
) && vk_format_is_stencil(format
))
702 tiled
&= ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
704 /* Don't support linear depth surfaces */
708 bool linear_sampling
;
709 if (radv_is_sampler_format_supported(format
, &linear_sampling
)) {
710 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
711 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
712 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
713 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
715 if (radv_is_filter_minmax_format_supported(format
))
716 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT
;
718 if (linear_sampling
) {
719 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
720 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
723 /* Don't support blitting for R32G32B32 formats. */
724 if (format
== VK_FORMAT_R32G32B32_SFLOAT
||
725 format
== VK_FORMAT_R32G32B32_UINT
||
726 format
== VK_FORMAT_R32G32B32_SINT
) {
727 linear
&= ~VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
730 if (radv_is_colorbuffer_format_supported(format
, &blendable
)) {
731 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
732 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
734 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
735 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
738 if (tiled
&& !scaled
) {
739 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
740 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
743 /* Tiled formatting does not support NPOT pixel sizes */
744 if (!util_is_power_of_two_or_zero(vk_format_get_blocksize(format
)))
748 if (linear
&& !scaled
) {
749 linear
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
750 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
753 if (format
== VK_FORMAT_R32_UINT
||
754 format
== VK_FORMAT_R32_SINT
||
755 format
== VK_FORMAT_R32_SFLOAT
) {
756 buffer
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
757 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
758 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
762 case VK_FORMAT_A2R10G10B10_SNORM_PACK32
:
763 case VK_FORMAT_A2B10G10R10_SNORM_PACK32
:
764 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32
:
765 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32
:
766 case VK_FORMAT_A2R10G10B10_SINT_PACK32
:
767 case VK_FORMAT_A2B10G10R10_SINT_PACK32
:
768 if (physical_device
->rad_info
.chip_class
<= GFX8
&&
769 physical_device
->rad_info
.family
!= CHIP_STONEY
) {
770 buffer
&= ~(VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
771 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
);
780 /* addrlib does not support linear compressed textures. */
781 if (vk_format_is_compressed(format
))
784 out_properties
->linearTilingFeatures
= linear
;
785 out_properties
->optimalTilingFeatures
= tiled
;
786 out_properties
->bufferFeatures
= buffer
;
789 uint32_t radv_translate_colorformat(VkFormat format
)
791 const struct vk_format_description
*desc
= vk_format_description(format
);
793 #define HAS_SIZE(x,y,z,w) \
794 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
795 desc->channel[2].size == (z) && desc->channel[3].size == (w))
797 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) /* isn't plain */
798 return V_028C70_COLOR_10_11_11
;
800 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
801 return V_028C70_COLOR_INVALID
;
803 /* hw cannot support mixed formats (except depth/stencil, since
804 * stencil is not written to). */
805 if (desc
->is_mixed
&& desc
->colorspace
!= VK_FORMAT_COLORSPACE_ZS
)
806 return V_028C70_COLOR_INVALID
;
808 switch (desc
->nr_channels
) {
810 switch (desc
->channel
[0].size
) {
812 return V_028C70_COLOR_8
;
814 return V_028C70_COLOR_16
;
816 return V_028C70_COLOR_32
;
820 if (desc
->channel
[0].size
== desc
->channel
[1].size
) {
821 switch (desc
->channel
[0].size
) {
823 return V_028C70_COLOR_8_8
;
825 return V_028C70_COLOR_16_16
;
827 return V_028C70_COLOR_32_32
;
829 } else if (HAS_SIZE(8,24,0,0)) {
830 return V_028C70_COLOR_24_8
;
831 } else if (HAS_SIZE(24,8,0,0)) {
832 return V_028C70_COLOR_8_24
;
836 if (HAS_SIZE(5,6,5,0)) {
837 return V_028C70_COLOR_5_6_5
;
838 } else if (HAS_SIZE(32,8,24,0)) {
839 return V_028C70_COLOR_X24_8_32_FLOAT
;
843 if (desc
->channel
[0].size
== desc
->channel
[1].size
&&
844 desc
->channel
[0].size
== desc
->channel
[2].size
&&
845 desc
->channel
[0].size
== desc
->channel
[3].size
) {
846 switch (desc
->channel
[0].size
) {
848 return V_028C70_COLOR_4_4_4_4
;
850 return V_028C70_COLOR_8_8_8_8
;
852 return V_028C70_COLOR_16_16_16_16
;
854 return V_028C70_COLOR_32_32_32_32
;
856 } else if (HAS_SIZE(5,5,5,1)) {
857 return V_028C70_COLOR_1_5_5_5
;
858 } else if (HAS_SIZE(1,5,5,5)) {
859 return V_028C70_COLOR_5_5_5_1
;
860 } else if (HAS_SIZE(10,10,10,2)) {
861 return V_028C70_COLOR_2_10_10_10
;
865 return V_028C70_COLOR_INVALID
;
868 uint32_t radv_colorformat_endian_swap(uint32_t colorformat
)
870 if (0/*SI_BIG_ENDIAN*/) {
871 switch(colorformat
) {
873 case V_028C70_COLOR_8
:
874 return V_028C70_ENDIAN_NONE
;
876 /* 16-bit buffers. */
877 case V_028C70_COLOR_5_6_5
:
878 case V_028C70_COLOR_1_5_5_5
:
879 case V_028C70_COLOR_4_4_4_4
:
880 case V_028C70_COLOR_16
:
881 case V_028C70_COLOR_8_8
:
882 return V_028C70_ENDIAN_8IN16
;
884 /* 32-bit buffers. */
885 case V_028C70_COLOR_8_8_8_8
:
886 case V_028C70_COLOR_2_10_10_10
:
887 case V_028C70_COLOR_8_24
:
888 case V_028C70_COLOR_24_8
:
889 case V_028C70_COLOR_16_16
:
890 return V_028C70_ENDIAN_8IN32
;
892 /* 64-bit buffers. */
893 case V_028C70_COLOR_16_16_16_16
:
894 return V_028C70_ENDIAN_8IN16
;
896 case V_028C70_COLOR_32_32
:
897 return V_028C70_ENDIAN_8IN32
;
899 /* 128-bit buffers. */
900 case V_028C70_COLOR_32_32_32_32
:
901 return V_028C70_ENDIAN_8IN32
;
903 return V_028C70_ENDIAN_NONE
; /* Unsupported. */
906 return V_028C70_ENDIAN_NONE
;
910 uint32_t radv_translate_dbformat(VkFormat format
)
913 case VK_FORMAT_D16_UNORM
:
914 case VK_FORMAT_D16_UNORM_S8_UINT
:
915 return V_028040_Z_16
;
916 case VK_FORMAT_D32_SFLOAT
:
917 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
918 return V_028040_Z_32_FLOAT
;
920 return V_028040_Z_INVALID
;
924 unsigned radv_translate_colorswap(VkFormat format
, bool do_endian_swap
)
926 const struct vk_format_description
*desc
= vk_format_description(format
);
928 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == VK_SWIZZLE_##swz)
930 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
931 return V_028C70_SWAP_STD
;
933 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
936 switch (desc
->nr_channels
) {
938 if (HAS_SWIZZLE(0,X
))
939 return V_028C70_SWAP_STD
; /* X___ */
940 else if (HAS_SWIZZLE(3,X
))
941 return V_028C70_SWAP_ALT_REV
; /* ___X */
944 if ((HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,Y
)) ||
945 (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,NONE
)) ||
946 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,Y
)))
947 return V_028C70_SWAP_STD
; /* XY__ */
948 else if ((HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,X
)) ||
949 (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,NONE
)) ||
950 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,X
)))
952 return (do_endian_swap
? V_028C70_SWAP_STD
: V_028C70_SWAP_STD_REV
);
953 else if (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(3,Y
))
954 return V_028C70_SWAP_ALT
; /* X__Y */
955 else if (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(3,X
))
956 return V_028C70_SWAP_ALT_REV
; /* Y__X */
959 if (HAS_SWIZZLE(0,X
))
960 return (do_endian_swap
? V_028C70_SWAP_STD_REV
: V_028C70_SWAP_STD
);
961 else if (HAS_SWIZZLE(0,Z
))
962 return V_028C70_SWAP_STD_REV
; /* ZYX */
965 /* check the middle channels, the 1st and 4th channel can be NONE */
966 if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,Z
)) {
967 return V_028C70_SWAP_STD
; /* XYZW */
968 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,Y
)) {
969 return V_028C70_SWAP_STD_REV
; /* WZYX */
970 } else if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,X
)) {
971 return V_028C70_SWAP_ALT
; /* ZYXW */
972 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,W
)) {
975 return V_028C70_SWAP_ALT_REV
;
977 return (do_endian_swap
? V_028C70_SWAP_ALT
: V_028C70_SWAP_ALT_REV
);
984 bool radv_format_pack_clear_color(VkFormat format
,
985 uint32_t clear_vals
[2],
986 VkClearColorValue
*value
)
988 const struct vk_format_description
*desc
= vk_format_description(format
);
990 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) {
991 clear_vals
[0] = float3_to_r11g11b10f(value
->float32
);
996 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
) {
997 fprintf(stderr
, "failed to fast clear for non-plain format %d\n", format
);
1001 if (!util_is_power_of_two_or_zero(desc
->block
.bits
)) {
1002 fprintf(stderr
, "failed to fast clear for NPOT format %d\n", format
);
1006 if (desc
->block
.bits
> 64) {
1008 * We have a 128 bits format, check if the first 3 components are the same.
1009 * Every elements has to be 32 bits since we don't support 64-bit formats,
1010 * and we can skip swizzling checks as alpha always comes last for these and
1011 * we do not care about the rest as they have to be the same.
1013 if (desc
->channel
[0].type
== VK_FORMAT_TYPE_FLOAT
) {
1014 if (value
->float32
[0] != value
->float32
[1] ||
1015 value
->float32
[0] != value
->float32
[2])
1018 if (value
->uint32
[0] != value
->uint32
[1] ||
1019 value
->uint32
[0] != value
->uint32
[2])
1022 clear_vals
[0] = value
->uint32
[0];
1023 clear_vals
[1] = value
->uint32
[3];
1026 uint64_t clear_val
= 0;
1028 for (unsigned c
= 0; c
< 4; ++c
) {
1029 if (desc
->swizzle
[c
] >= 4)
1032 const struct vk_format_channel_description
*channel
= &desc
->channel
[desc
->swizzle
[c
]];
1033 assert(channel
->size
);
1036 if (channel
->pure_integer
) {
1037 v
= value
->uint32
[c
] & ((1ULL << channel
->size
) - 1);
1038 } else if (channel
->normalized
) {
1039 if (channel
->type
== VK_FORMAT_TYPE_UNSIGNED
&&
1040 desc
->swizzle
[c
] < 3 &&
1041 desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
) {
1042 assert(channel
->size
== 8);
1044 v
= util_format_linear_float_to_srgb_8unorm(value
->float32
[c
]);
1046 float f
= MIN2(value
->float32
[c
], 1.0f
);
1048 if (channel
->type
== VK_FORMAT_TYPE_UNSIGNED
) {
1049 f
= MAX2(f
, 0.0f
) * ((1ULL << channel
->size
) - 1);
1051 f
= MAX2(f
, -1.0f
) * ((1ULL << (channel
->size
- 1)) - 1);
1054 /* The hardware rounds before conversion. */
1062 } else if (channel
->type
== VK_FORMAT_TYPE_FLOAT
) {
1063 if (channel
->size
== 32) {
1064 memcpy(&v
, &value
->float32
[c
], 4);
1065 } else if(channel
->size
== 16) {
1066 v
= util_float_to_half_rtz(value
->float32
[c
]);
1068 fprintf(stderr
, "failed to fast clear for unhandled float size in format %d\n", format
);
1072 fprintf(stderr
, "failed to fast clear for unhandled component type in format %d\n", format
);
1075 clear_val
|= (v
& ((1ULL << channel
->size
) - 1)) << channel
->shift
;
1078 clear_vals
[0] = clear_val
;
1079 clear_vals
[1] = clear_val
>> 32;
1084 void radv_GetPhysicalDeviceFormatProperties(
1085 VkPhysicalDevice physicalDevice
,
1087 VkFormatProperties
* pFormatProperties
)
1089 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1091 radv_physical_device_get_format_properties(physical_device
,
1096 void radv_GetPhysicalDeviceFormatProperties2(
1097 VkPhysicalDevice physicalDevice
,
1099 VkFormatProperties2
* pFormatProperties
)
1101 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1103 radv_physical_device_get_format_properties(physical_device
,
1105 &pFormatProperties
->formatProperties
);
1108 static VkResult
radv_get_image_format_properties(struct radv_physical_device
*physical_device
,
1109 const VkPhysicalDeviceImageFormatInfo2
*info
,
1111 VkImageFormatProperties
*pImageFormatProperties
)
1114 VkFormatProperties format_props
;
1115 VkFormatFeatureFlags format_feature_flags
;
1116 VkExtent3D maxExtent
;
1117 uint32_t maxMipLevels
;
1118 uint32_t maxArraySize
;
1119 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1120 const struct vk_format_description
*desc
= vk_format_description(format
);
1121 enum chip_class chip_class
= physical_device
->rad_info
.chip_class
;
1123 radv_physical_device_get_format_properties(physical_device
, format
,
1125 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
1126 format_feature_flags
= format_props
.linearTilingFeatures
;
1127 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
1128 format_feature_flags
= format_props
.optimalTilingFeatures
;
1130 unreachable("bad VkImageTiling");
1133 if (format_feature_flags
== 0)
1136 if (info
->type
!= VK_IMAGE_TYPE_2D
&& vk_format_is_depth_or_stencil(format
))
1139 switch (info
->type
) {
1141 unreachable("bad vkimage type\n");
1142 case VK_IMAGE_TYPE_1D
:
1143 maxExtent
.width
= 16384;
1144 maxExtent
.height
= 1;
1145 maxExtent
.depth
= 1;
1146 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1147 maxArraySize
= chip_class
>= GFX10
? 8192 : 2048;
1149 case VK_IMAGE_TYPE_2D
:
1150 maxExtent
.width
= 16384;
1151 maxExtent
.height
= 16384;
1152 maxExtent
.depth
= 1;
1153 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1154 maxArraySize
= chip_class
>= GFX10
? 8192 : 2048;
1156 case VK_IMAGE_TYPE_3D
:
1157 if (chip_class
>= GFX10
) {
1158 maxExtent
.width
= 8192;
1159 maxExtent
.height
= 8192;
1160 maxExtent
.depth
= 8192;
1162 maxExtent
.width
= 2048;
1163 maxExtent
.height
= 2048;
1164 maxExtent
.depth
= 2048;
1166 maxMipLevels
= util_logbase2(maxExtent
.width
) + 1;
1171 if (desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
1172 /* Might be able to support but the entire format support is
1173 * messy, so taking the lazy way out. */
1177 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
1178 info
->type
== VK_IMAGE_TYPE_2D
&&
1179 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1180 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
1181 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)) {
1182 sampleCounts
|= VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
1185 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
&&
1186 (format
== VK_FORMAT_R32G32B32_SFLOAT
||
1187 format
== VK_FORMAT_R32G32B32_SINT
||
1188 format
== VK_FORMAT_R32G32B32_UINT
)) {
1189 /* R32G32B32 is a weird format and the driver currently only
1190 * supports the barely minimum.
1191 * TODO: Implement more if we really need to.
1193 if (info
->type
== VK_IMAGE_TYPE_3D
)
1200 /* We can't create 3d compressed 128bpp images that can be rendered to on GFX9 */
1201 if (physical_device
->rad_info
.chip_class
>= GFX9
&&
1202 info
->type
== VK_IMAGE_TYPE_3D
&&
1203 vk_format_get_blocksizebits(format
) == 128 &&
1204 vk_format_is_compressed(format
) &&
1205 (info
->flags
& VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT
) &&
1206 ((info
->flags
& VK_IMAGE_CREATE_EXTENDED_USAGE_BIT
) ||
1207 (info
->usage
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
))) {
1211 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
1212 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
1217 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
1218 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
1223 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
1224 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
1229 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
1230 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
1235 if (info
->usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
1236 if (!(format_feature_flags
& VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
)) {
1241 if (info
->usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
1242 if (!(format_feature_flags
& VK_FORMAT_FEATURE_TRANSFER_DST_BIT
)) {
1247 if (info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
1248 if (!(format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1249 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
))) {
1254 /* Sparse resources with multi-planar formats are unsupported. */
1255 if (info
->flags
& VK_IMAGE_CREATE_SPARSE_BINDING_BIT
) {
1256 if (desc
->plane_count
> 1)
1260 *pImageFormatProperties
= (VkImageFormatProperties
) {
1261 .maxExtent
= maxExtent
,
1262 .maxMipLevels
= maxMipLevels
,
1263 .maxArrayLayers
= maxArraySize
,
1264 .sampleCounts
= sampleCounts
,
1266 /* FINISHME: Accurately calculate
1267 * VkImageFormatProperties::maxResourceSize.
1269 .maxResourceSize
= UINT32_MAX
,
1274 *pImageFormatProperties
= (VkImageFormatProperties
) {
1275 .maxExtent
= { 0, 0, 0 },
1277 .maxArrayLayers
= 0,
1279 .maxResourceSize
= 0,
1282 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
1285 VkResult
radv_GetPhysicalDeviceImageFormatProperties(
1286 VkPhysicalDevice physicalDevice
,
1289 VkImageTiling tiling
,
1290 VkImageUsageFlags usage
,
1291 VkImageCreateFlags createFlags
,
1292 VkImageFormatProperties
* pImageFormatProperties
)
1294 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1296 const VkPhysicalDeviceImageFormatInfo2 info
= {
1297 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2
,
1303 .flags
= createFlags
,
1306 return radv_get_image_format_properties(physical_device
, &info
, format
,
1307 pImageFormatProperties
);
1311 get_external_image_format_properties(struct radv_physical_device
*physical_device
,
1312 const VkPhysicalDeviceImageFormatInfo2
*pImageFormatInfo
,
1313 VkExternalMemoryHandleTypeFlagBits handleType
,
1314 VkExternalMemoryProperties
*external_properties
,
1315 VkImageFormatProperties
*format_properties
)
1317 VkExternalMemoryFeatureFlagBits flags
= 0;
1318 VkExternalMemoryHandleTypeFlags export_flags
= 0;
1319 VkExternalMemoryHandleTypeFlags compat_flags
= 0;
1321 if (pImageFormatInfo
->flags
& VK_IMAGE_CREATE_SPARSE_BINDING_BIT
)
1324 switch (handleType
) {
1325 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1326 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1327 switch (pImageFormatInfo
->type
) {
1328 case VK_IMAGE_TYPE_2D
:
1329 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1330 if (pImageFormatInfo
->tiling
!= VK_IMAGE_TILING_LINEAR
)
1331 flags
|= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
;
1333 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1334 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1340 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
:
1341 if (!physical_device
->supported_extensions
.ANDROID_external_memory_android_hardware_buffer
)
1344 if (!radv_android_gralloc_supports_format(pImageFormatInfo
->format
,
1345 pImageFormatInfo
->usage
))
1348 if (pImageFormatInfo
->type
!= VK_IMAGE_TYPE_2D
)
1351 format_properties
->maxMipLevels
= MIN2(1, format_properties
->maxMipLevels
);
1352 format_properties
->maxArrayLayers
= MIN2(1, format_properties
->maxArrayLayers
);
1353 format_properties
->sampleCounts
&= VK_SAMPLE_COUNT_1_BIT
;
1355 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1356 if (pImageFormatInfo
->tiling
!= VK_IMAGE_TILING_LINEAR
)
1357 flags
|= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
;
1359 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID
;
1361 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1362 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1363 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1369 *external_properties
= (VkExternalMemoryProperties
) {
1370 .externalMemoryFeatures
= flags
,
1371 .exportFromImportedHandleTypes
= export_flags
,
1372 .compatibleHandleTypes
= compat_flags
,
1376 VkResult
radv_GetPhysicalDeviceImageFormatProperties2(
1377 VkPhysicalDevice physicalDevice
,
1378 const VkPhysicalDeviceImageFormatInfo2
*base_info
,
1379 VkImageFormatProperties2
*base_props
)
1381 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1382 const VkPhysicalDeviceExternalImageFormatInfo
*external_info
= NULL
;
1383 VkExternalImageFormatProperties
*external_props
= NULL
;
1384 struct VkAndroidHardwareBufferUsageANDROID
*android_usage
= NULL
;
1385 VkSamplerYcbcrConversionImageFormatProperties
*ycbcr_props
= NULL
;
1386 VkTextureLODGatherFormatPropertiesAMD
*texture_lod_props
= NULL
;
1388 VkFormat format
= radv_select_android_external_format(base_info
->pNext
, base_info
->format
);
1390 result
= radv_get_image_format_properties(physical_device
, base_info
, format
,
1391 &base_props
->imageFormatProperties
);
1392 if (result
!= VK_SUCCESS
)
1395 /* Extract input structs */
1396 vk_foreach_struct_const(s
, base_info
->pNext
) {
1398 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO
:
1399 external_info
= (const void *) s
;
1406 /* Extract output structs */
1407 vk_foreach_struct(s
, base_props
->pNext
) {
1409 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES
:
1410 external_props
= (void *) s
;
1412 case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES
:
1413 ycbcr_props
= (void *) s
;
1415 case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID
:
1416 android_usage
= (void *) s
;
1418 case VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD
:
1419 texture_lod_props
= (void *) s
;
1426 bool ahb_supported
= physical_device
->supported_extensions
.ANDROID_external_memory_android_hardware_buffer
;
1427 if (android_usage
&& ahb_supported
) {
1428 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
1429 android_usage
->androidHardwareBufferUsage
=
1430 radv_ahb_usage_from_vk_usage(base_info
->flags
,
1435 /* From the Vulkan 1.0.97 spec:
1437 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
1438 * behave as if VkPhysicalDeviceExternalImageFormatInfo was not
1439 * present and VkExternalImageFormatProperties will be ignored.
1441 if (external_info
&& external_info
->handleType
!= 0) {
1442 get_external_image_format_properties(physical_device
, base_info
, external_info
->handleType
,
1443 &external_props
->externalMemoryProperties
,
1444 &base_props
->imageFormatProperties
);
1445 if (!external_props
->externalMemoryProperties
.externalMemoryFeatures
) {
1446 /* From the Vulkan 1.0.97 spec:
1448 * If handleType is not compatible with the [parameters] specified
1449 * in VkPhysicalDeviceImageFormatInfo2, then
1450 * vkGetPhysicalDeviceImageFormatProperties2 returns
1451 * VK_ERROR_FORMAT_NOT_SUPPORTED.
1453 result
= vk_errorf(physical_device
->instance
, VK_ERROR_FORMAT_NOT_SUPPORTED
,
1454 "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
1455 external_info
->handleType
);
1461 ycbcr_props
->combinedImageSamplerDescriptorCount
= vk_format_get_plane_count(format
);
1464 if (texture_lod_props
) {
1465 if (physical_device
->rad_info
.chip_class
>= GFX9
) {
1466 texture_lod_props
->supportsTextureGatherLODBiasAMD
= true;
1468 texture_lod_props
->supportsTextureGatherLODBiasAMD
= !vk_format_is_int(format
);
1475 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
1476 /* From the Vulkan 1.0.97 spec:
1478 * If the combination of parameters to
1479 * vkGetPhysicalDeviceImageFormatProperties2 is not supported by
1480 * the implementation for use in vkCreateImage, then all members of
1481 * imageFormatProperties will be filled with zero.
1483 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {0};
1489 void radv_GetPhysicalDeviceSparseImageFormatProperties(
1490 VkPhysicalDevice physicalDevice
,
1494 VkImageUsageFlags usage
,
1495 VkImageTiling tiling
,
1496 uint32_t* pNumProperties
,
1497 VkSparseImageFormatProperties
* pProperties
)
1499 /* Sparse images are not yet supported. */
1500 *pNumProperties
= 0;
1503 void radv_GetPhysicalDeviceSparseImageFormatProperties2(
1504 VkPhysicalDevice physicalDevice
,
1505 const VkPhysicalDeviceSparseImageFormatInfo2
*pFormatInfo
,
1506 uint32_t *pPropertyCount
,
1507 VkSparseImageFormatProperties2
*pProperties
)
1509 /* Sparse images are not yet supported. */
1510 *pPropertyCount
= 0;
1513 void radv_GetPhysicalDeviceExternalBufferProperties(
1514 VkPhysicalDevice physicalDevice
,
1515 const VkPhysicalDeviceExternalBufferInfo
*pExternalBufferInfo
,
1516 VkExternalBufferProperties
*pExternalBufferProperties
)
1518 VkExternalMemoryFeatureFlagBits flags
= 0;
1519 VkExternalMemoryHandleTypeFlags export_flags
= 0;
1520 VkExternalMemoryHandleTypeFlags compat_flags
= 0;
1521 switch(pExternalBufferInfo
->handleType
) {
1522 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1523 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1524 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|
1525 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1526 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1527 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1529 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1530 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1531 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1536 pExternalBufferProperties
->externalMemoryProperties
= (VkExternalMemoryProperties
) {
1537 .externalMemoryFeatures
= flags
,
1538 .exportFromImportedHandleTypes
= export_flags
,
1539 .compatibleHandleTypes
= compat_flags
,
1543 /* DCC channel type categories within which formats can be reinterpreted
1544 * while keeping the same DCC encoding. The swizzle must also match. */
1545 enum dcc_channel_type
{
1546 dcc_channel_float32
,
1549 dcc_channel_float16
,
1552 dcc_channel_uint_10_10_10_2
,
1555 dcc_channel_incompatible
,
1558 /* Return the type of DCC encoding. */
1559 static enum dcc_channel_type
1560 radv_get_dcc_channel_type(const struct vk_format_description
*desc
)
1564 /* Find the first non-void channel. */
1565 for (i
= 0; i
< desc
->nr_channels
; i
++)
1566 if (desc
->channel
[i
].type
!= VK_FORMAT_TYPE_VOID
)
1568 if (i
== desc
->nr_channels
)
1569 return dcc_channel_incompatible
;
1571 switch (desc
->channel
[i
].size
) {
1573 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1574 return dcc_channel_float32
;
1575 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1576 return dcc_channel_uint32
;
1577 return dcc_channel_sint32
;
1579 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1580 return dcc_channel_float16
;
1581 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1582 return dcc_channel_uint16
;
1583 return dcc_channel_sint16
;
1585 return dcc_channel_uint_10_10_10_2
;
1587 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1588 return dcc_channel_uint8
;
1589 return dcc_channel_sint8
;
1591 return dcc_channel_incompatible
;
1595 /* Return if it's allowed to reinterpret one format as another with DCC enabled. */
1596 bool radv_dcc_formats_compatible(VkFormat format1
,
1599 const struct vk_format_description
*desc1
, *desc2
;
1600 enum dcc_channel_type type1
, type2
;
1603 if (format1
== format2
)
1606 desc1
= vk_format_description(format1
);
1607 desc2
= vk_format_description(format2
);
1609 if (desc1
->nr_channels
!= desc2
->nr_channels
)
1612 /* Swizzles must be the same. */
1613 for (i
= 0; i
< desc1
->nr_channels
; i
++)
1614 if (desc1
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1615 desc2
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1616 desc1
->swizzle
[i
] != desc2
->swizzle
[i
])
1619 type1
= radv_get_dcc_channel_type(desc1
);
1620 type2
= radv_get_dcc_channel_type(desc2
);
1622 return type1
!= dcc_channel_incompatible
&&
1623 type2
!= dcc_channel_incompatible
&&