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 static 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
));
562 *scaled
= (num_format
== V_008F0C_BUF_NUM_FORMAT_SSCALED
) || (num_format
== V_008F0C_BUF_NUM_FORMAT_USCALED
);
563 return data_format
!= V_008F0C_BUF_DATA_FORMAT_INVALID
&&
567 bool radv_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
)
569 const struct vk_format_description
*desc
= vk_format_description(format
);
570 uint32_t color_format
= radv_translate_colorformat(format
);
571 uint32_t color_swap
= radv_translate_colorswap(format
, false);
572 uint32_t color_num_format
= radv_translate_color_numformat(format
,
574 vk_format_get_first_non_void_channel(format
));
576 if (color_num_format
== V_028C70_NUMBER_UINT
|| color_num_format
== V_028C70_NUMBER_SINT
||
577 color_format
== V_028C70_COLOR_8_24
|| color_format
== V_028C70_COLOR_24_8
||
578 color_format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
582 return color_format
!= V_028C70_COLOR_INVALID
&&
584 color_num_format
!= ~0;
587 static bool radv_is_zs_format_supported(VkFormat format
)
589 return radv_translate_dbformat(format
) != V_028040_Z_INVALID
|| format
== VK_FORMAT_S8_UINT
;
592 static bool radv_is_filter_minmax_format_supported(VkFormat format
)
594 /* From the Vulkan spec 1.1.71:
596 * "The following formats must support the
597 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT feature with
598 * VK_IMAGE_TILING_OPTIMAL, if they support
599 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT."
601 /* TODO: enable more formats. */
603 case VK_FORMAT_R8_UNORM
:
604 case VK_FORMAT_R8_SNORM
:
605 case VK_FORMAT_R16_UNORM
:
606 case VK_FORMAT_R16_SNORM
:
607 case VK_FORMAT_R16_SFLOAT
:
608 case VK_FORMAT_R32_SFLOAT
:
609 case VK_FORMAT_D16_UNORM
:
610 case VK_FORMAT_X8_D24_UNORM_PACK32
:
611 case VK_FORMAT_D32_SFLOAT
:
612 case VK_FORMAT_D16_UNORM_S8_UINT
:
613 case VK_FORMAT_D24_UNORM_S8_UINT
:
614 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
622 radv_device_supports_etc(struct radv_physical_device
*physical_device
)
624 return physical_device
->rad_info
.family
== CHIP_VEGA10
||
625 physical_device
->rad_info
.family
== CHIP_RAVEN
||
626 physical_device
->rad_info
.family
== CHIP_STONEY
;
630 radv_physical_device_get_format_properties(struct radv_physical_device
*physical_device
,
632 VkFormatProperties
*out_properties
)
634 VkFormatFeatureFlags linear
= 0, tiled
= 0, buffer
= 0;
635 const struct vk_format_description
*desc
= vk_format_description(format
);
639 out_properties
->linearTilingFeatures
= linear
;
640 out_properties
->optimalTilingFeatures
= tiled
;
641 out_properties
->bufferFeatures
= buffer
;
645 if (desc
->layout
== VK_FORMAT_LAYOUT_ETC
&&
646 !radv_device_supports_etc(physical_device
)) {
647 out_properties
->linearTilingFeatures
= linear
;
648 out_properties
->optimalTilingFeatures
= tiled
;
649 out_properties
->bufferFeatures
= buffer
;
653 if (radv_is_storage_image_format_supported(physical_device
, format
)) {
654 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
655 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
658 if (radv_is_buffer_format_supported(format
, &scaled
)) {
659 buffer
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
661 buffer
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
662 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
665 if (vk_format_is_depth_or_stencil(format
)) {
666 if (radv_is_zs_format_supported(format
)) {
667 tiled
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
;
668 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
669 tiled
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
670 VK_FORMAT_FEATURE_BLIT_DST_BIT
;
671 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
672 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
674 if (radv_is_filter_minmax_format_supported(format
))
675 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
677 /* Don't support blitting surfaces with depth/stencil. */
678 if (vk_format_is_depth(format
) && vk_format_is_stencil(format
))
679 tiled
&= ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
681 /* Don't support linear depth surfaces */
685 bool linear_sampling
;
686 if (radv_is_sampler_format_supported(format
, &linear_sampling
)) {
687 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
688 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
689 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
690 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
692 if (radv_is_filter_minmax_format_supported(format
))
693 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
695 if (linear_sampling
) {
696 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
697 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
700 /* Don't support blitting for R32G32B32 formats. */
701 if (format
== VK_FORMAT_R32G32B32_SFLOAT
||
702 format
== VK_FORMAT_R32G32B32_UINT
||
703 format
== VK_FORMAT_R32G32B32_SINT
) {
704 linear
&= ~VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
707 if (radv_is_colorbuffer_format_supported(format
, &blendable
)) {
708 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
709 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
711 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
712 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
715 if (tiled
&& !scaled
) {
716 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
717 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
720 /* Tiled formatting does not support NPOT pixel sizes */
721 if (!util_is_power_of_two_or_zero(vk_format_get_blocksize(format
)))
725 if (linear
&& !scaled
) {
726 linear
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
727 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
730 if (format
== VK_FORMAT_R32_UINT
|| format
== VK_FORMAT_R32_SINT
) {
731 buffer
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
732 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
733 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
737 case VK_FORMAT_A2R10G10B10_SNORM_PACK32
:
738 case VK_FORMAT_A2B10G10R10_SNORM_PACK32
:
739 case VK_FORMAT_A2R10G10B10_SSCALED_PACK32
:
740 case VK_FORMAT_A2B10G10R10_SSCALED_PACK32
:
741 case VK_FORMAT_A2R10G10B10_SINT_PACK32
:
742 case VK_FORMAT_A2B10G10R10_SINT_PACK32
:
743 if (physical_device
->rad_info
.chip_class
<= VI
&&
744 physical_device
->rad_info
.family
!= CHIP_STONEY
) {
745 buffer
&= ~(VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
746 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
);
755 out_properties
->linearTilingFeatures
= linear
;
756 out_properties
->optimalTilingFeatures
= tiled
;
757 out_properties
->bufferFeatures
= buffer
;
760 uint32_t radv_translate_colorformat(VkFormat format
)
762 const struct vk_format_description
*desc
= vk_format_description(format
);
764 #define HAS_SIZE(x,y,z,w) \
765 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
766 desc->channel[2].size == (z) && desc->channel[3].size == (w))
768 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) /* isn't plain */
769 return V_028C70_COLOR_10_11_11
;
771 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
772 return V_028C70_COLOR_INVALID
;
774 /* hw cannot support mixed formats (except depth/stencil, since
775 * stencil is not written to). */
776 if (desc
->is_mixed
&& desc
->colorspace
!= VK_FORMAT_COLORSPACE_ZS
)
777 return V_028C70_COLOR_INVALID
;
779 switch (desc
->nr_channels
) {
781 switch (desc
->channel
[0].size
) {
783 return V_028C70_COLOR_8
;
785 return V_028C70_COLOR_16
;
787 return V_028C70_COLOR_32
;
791 if (desc
->channel
[0].size
== desc
->channel
[1].size
) {
792 switch (desc
->channel
[0].size
) {
794 return V_028C70_COLOR_8_8
;
796 return V_028C70_COLOR_16_16
;
798 return V_028C70_COLOR_32_32
;
800 } else if (HAS_SIZE(8,24,0,0)) {
801 return V_028C70_COLOR_24_8
;
802 } else if (HAS_SIZE(24,8,0,0)) {
803 return V_028C70_COLOR_8_24
;
807 if (HAS_SIZE(5,6,5,0)) {
808 return V_028C70_COLOR_5_6_5
;
809 } else if (HAS_SIZE(32,8,24,0)) {
810 return V_028C70_COLOR_X24_8_32_FLOAT
;
814 if (desc
->channel
[0].size
== desc
->channel
[1].size
&&
815 desc
->channel
[0].size
== desc
->channel
[2].size
&&
816 desc
->channel
[0].size
== desc
->channel
[3].size
) {
817 switch (desc
->channel
[0].size
) {
819 return V_028C70_COLOR_4_4_4_4
;
821 return V_028C70_COLOR_8_8_8_8
;
823 return V_028C70_COLOR_16_16_16_16
;
825 return V_028C70_COLOR_32_32_32_32
;
827 } else if (HAS_SIZE(5,5,5,1)) {
828 return V_028C70_COLOR_1_5_5_5
;
829 } else if (HAS_SIZE(1,5,5,5)) {
830 return V_028C70_COLOR_5_5_5_1
;
831 } else if (HAS_SIZE(10,10,10,2)) {
832 return V_028C70_COLOR_2_10_10_10
;
836 return V_028C70_COLOR_INVALID
;
839 uint32_t radv_colorformat_endian_swap(uint32_t colorformat
)
841 if (0/*SI_BIG_ENDIAN*/) {
842 switch(colorformat
) {
844 case V_028C70_COLOR_8
:
845 return V_028C70_ENDIAN_NONE
;
847 /* 16-bit buffers. */
848 case V_028C70_COLOR_5_6_5
:
849 case V_028C70_COLOR_1_5_5_5
:
850 case V_028C70_COLOR_4_4_4_4
:
851 case V_028C70_COLOR_16
:
852 case V_028C70_COLOR_8_8
:
853 return V_028C70_ENDIAN_8IN16
;
855 /* 32-bit buffers. */
856 case V_028C70_COLOR_8_8_8_8
:
857 case V_028C70_COLOR_2_10_10_10
:
858 case V_028C70_COLOR_8_24
:
859 case V_028C70_COLOR_24_8
:
860 case V_028C70_COLOR_16_16
:
861 return V_028C70_ENDIAN_8IN32
;
863 /* 64-bit buffers. */
864 case V_028C70_COLOR_16_16_16_16
:
865 return V_028C70_ENDIAN_8IN16
;
867 case V_028C70_COLOR_32_32
:
868 return V_028C70_ENDIAN_8IN32
;
870 /* 128-bit buffers. */
871 case V_028C70_COLOR_32_32_32_32
:
872 return V_028C70_ENDIAN_8IN32
;
874 return V_028C70_ENDIAN_NONE
; /* Unsupported. */
877 return V_028C70_ENDIAN_NONE
;
881 uint32_t radv_translate_dbformat(VkFormat format
)
884 case VK_FORMAT_D16_UNORM
:
885 case VK_FORMAT_D16_UNORM_S8_UINT
:
886 return V_028040_Z_16
;
887 case VK_FORMAT_D32_SFLOAT
:
888 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
889 return V_028040_Z_32_FLOAT
;
891 return V_028040_Z_INVALID
;
895 unsigned radv_translate_colorswap(VkFormat format
, bool do_endian_swap
)
897 const struct vk_format_description
*desc
= vk_format_description(format
);
899 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == VK_SWIZZLE_##swz)
901 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
902 return V_028C70_SWAP_STD
;
904 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
907 switch (desc
->nr_channels
) {
909 if (HAS_SWIZZLE(0,X
))
910 return V_028C70_SWAP_STD
; /* X___ */
911 else if (HAS_SWIZZLE(3,X
))
912 return V_028C70_SWAP_ALT_REV
; /* ___X */
915 if ((HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,Y
)) ||
916 (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,NONE
)) ||
917 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,Y
)))
918 return V_028C70_SWAP_STD
; /* XY__ */
919 else if ((HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,X
)) ||
920 (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,NONE
)) ||
921 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,X
)))
923 return (do_endian_swap
? V_028C70_SWAP_STD
: V_028C70_SWAP_STD_REV
);
924 else if (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(3,Y
))
925 return V_028C70_SWAP_ALT
; /* X__Y */
926 else if (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(3,X
))
927 return V_028C70_SWAP_ALT_REV
; /* Y__X */
930 if (HAS_SWIZZLE(0,X
))
931 return (do_endian_swap
? V_028C70_SWAP_STD_REV
: V_028C70_SWAP_STD
);
932 else if (HAS_SWIZZLE(0,Z
))
933 return V_028C70_SWAP_STD_REV
; /* ZYX */
936 /* check the middle channels, the 1st and 4th channel can be NONE */
937 if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,Z
)) {
938 return V_028C70_SWAP_STD
; /* XYZW */
939 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,Y
)) {
940 return V_028C70_SWAP_STD_REV
; /* WZYX */
941 } else if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,X
)) {
942 return V_028C70_SWAP_ALT
; /* ZYXW */
943 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,W
)) {
946 return V_028C70_SWAP_ALT_REV
;
948 return (do_endian_swap
? V_028C70_SWAP_ALT
: V_028C70_SWAP_ALT_REV
);
955 bool radv_format_pack_clear_color(VkFormat format
,
956 uint32_t clear_vals
[2],
957 VkClearColorValue
*value
)
959 const struct vk_format_description
*desc
= vk_format_description(format
);
961 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) {
962 clear_vals
[0] = float3_to_r11g11b10f(value
->float32
);
967 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
) {
968 fprintf(stderr
, "failed to fast clear for non-plain format %d\n", format
);
972 if (!util_is_power_of_two_or_zero(desc
->block
.bits
)) {
973 fprintf(stderr
, "failed to fast clear for NPOT format %d\n", format
);
977 if (desc
->block
.bits
> 64) {
979 * We have a 128 bits format, check if the first 3 components are the same.
980 * Every elements has to be 32 bits since we don't support 64-bit formats,
981 * and we can skip swizzling checks as alpha always comes last for these and
982 * we do not care about the rest as they have to be the same.
984 if (desc
->channel
[0].type
== VK_FORMAT_TYPE_FLOAT
) {
985 if (value
->float32
[0] != value
->float32
[1] ||
986 value
->float32
[0] != value
->float32
[2])
989 if (value
->uint32
[0] != value
->uint32
[1] ||
990 value
->uint32
[0] != value
->uint32
[2])
993 clear_vals
[0] = value
->uint32
[0];
994 clear_vals
[1] = value
->uint32
[3];
997 uint64_t clear_val
= 0;
999 for (unsigned c
= 0; c
< 4; ++c
) {
1000 if (desc
->swizzle
[c
] >= 4)
1003 const struct vk_format_channel_description
*channel
= &desc
->channel
[desc
->swizzle
[c
]];
1004 assert(channel
->size
);
1007 if (channel
->pure_integer
) {
1008 v
= value
->uint32
[c
] & ((1ULL << channel
->size
) - 1);
1009 } else if (channel
->normalized
) {
1010 if (channel
->type
== VK_FORMAT_TYPE_UNSIGNED
&&
1011 desc
->swizzle
[c
] < 3 &&
1012 desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
) {
1013 assert(channel
->size
== 8);
1015 v
= util_format_linear_float_to_srgb_8unorm(value
->float32
[c
]);
1016 } else if (channel
->type
== VK_FORMAT_TYPE_UNSIGNED
) {
1017 v
= MAX2(MIN2(value
->float32
[c
], 1.0f
), 0.0f
) * ((1ULL << channel
->size
) - 1);
1019 v
= MAX2(MIN2(value
->float32
[c
], 1.0f
), -1.0f
) * ((1ULL << (channel
->size
- 1)) - 1);
1021 } else if (channel
->type
== VK_FORMAT_TYPE_FLOAT
) {
1022 if (channel
->size
== 32) {
1023 memcpy(&v
, &value
->float32
[c
], 4);
1024 } else if(channel
->size
== 16) {
1025 v
= util_float_to_half(value
->float32
[c
]);
1027 fprintf(stderr
, "failed to fast clear for unhandled float size in format %d\n", format
);
1031 fprintf(stderr
, "failed to fast clear for unhandled component type in format %d\n", format
);
1034 clear_val
|= (v
& ((1ULL << channel
->size
) - 1)) << channel
->shift
;
1037 clear_vals
[0] = clear_val
;
1038 clear_vals
[1] = clear_val
>> 32;
1043 void radv_GetPhysicalDeviceFormatProperties(
1044 VkPhysicalDevice physicalDevice
,
1046 VkFormatProperties
* pFormatProperties
)
1048 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1050 radv_physical_device_get_format_properties(physical_device
,
1055 void radv_GetPhysicalDeviceFormatProperties2(
1056 VkPhysicalDevice physicalDevice
,
1058 VkFormatProperties2
* pFormatProperties
)
1060 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1062 radv_physical_device_get_format_properties(physical_device
,
1064 &pFormatProperties
->formatProperties
);
1067 static VkResult
radv_get_image_format_properties(struct radv_physical_device
*physical_device
,
1068 const VkPhysicalDeviceImageFormatInfo2
*info
,
1069 VkImageFormatProperties
*pImageFormatProperties
)
1072 VkFormatProperties format_props
;
1073 VkFormatFeatureFlags format_feature_flags
;
1074 VkExtent3D maxExtent
;
1075 uint32_t maxMipLevels
;
1076 uint32_t maxArraySize
;
1077 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1079 radv_physical_device_get_format_properties(physical_device
, info
->format
,
1081 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
1082 format_feature_flags
= format_props
.linearTilingFeatures
;
1083 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
1084 format_feature_flags
= format_props
.optimalTilingFeatures
;
1086 unreachable("bad VkImageTiling");
1089 if (format_feature_flags
== 0)
1092 if (info
->type
!= VK_IMAGE_TYPE_2D
&& vk_format_is_depth_or_stencil(info
->format
))
1095 switch (info
->type
) {
1097 unreachable("bad vkimage type\n");
1098 case VK_IMAGE_TYPE_1D
:
1099 maxExtent
.width
= 16384;
1100 maxExtent
.height
= 1;
1101 maxExtent
.depth
= 1;
1102 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1103 maxArraySize
= 2048;
1105 case VK_IMAGE_TYPE_2D
:
1106 maxExtent
.width
= 16384;
1107 maxExtent
.height
= 16384;
1108 maxExtent
.depth
= 1;
1109 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1110 maxArraySize
= 2048;
1112 case VK_IMAGE_TYPE_3D
:
1113 maxExtent
.width
= 2048;
1114 maxExtent
.height
= 2048;
1115 maxExtent
.depth
= 2048;
1116 maxMipLevels
= 12; /* log2(maxWidth) + 1 */
1121 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
1122 info
->type
== VK_IMAGE_TYPE_2D
&&
1123 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1124 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
1125 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)) {
1126 sampleCounts
|= VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
1129 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
&&
1130 (info
->format
== VK_FORMAT_R32G32B32_SFLOAT
||
1131 info
->format
== VK_FORMAT_R32G32B32_SINT
||
1132 info
->format
== VK_FORMAT_R32G32B32_UINT
)) {
1133 /* R32G32B32 is a weird format and the driver currently only
1134 * supports the barely minimum.
1135 * TODO: Implement more if we really need to.
1137 if (info
->type
== VK_IMAGE_TYPE_3D
)
1144 /* We can't create 3d compressed 128bpp images that can be rendered to on GFX9 */
1145 if (physical_device
->rad_info
.chip_class
>= GFX9
&&
1146 info
->type
== VK_IMAGE_TYPE_3D
&&
1147 vk_format_get_blocksizebits(info
->format
) == 128 &&
1148 vk_format_is_compressed(info
->format
) &&
1149 (info
->flags
& VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT
) &&
1150 ((info
->flags
& VK_IMAGE_CREATE_EXTENDED_USAGE_BIT
) ||
1151 (info
->usage
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
))) {
1155 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
1156 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
1161 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
1162 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
1167 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
1168 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
1173 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
1174 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
1179 if (info
->usage
& VK_IMAGE_USAGE_TRANSFER_SRC_BIT
) {
1180 if (!(format_feature_flags
& VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
)) {
1185 if (info
->usage
& VK_IMAGE_USAGE_TRANSFER_DST_BIT
) {
1186 if (!(format_feature_flags
& VK_FORMAT_FEATURE_TRANSFER_DST_BIT
)) {
1191 if (info
->usage
& VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
) {
1192 if (!(format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1193 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
))) {
1198 *pImageFormatProperties
= (VkImageFormatProperties
) {
1199 .maxExtent
= maxExtent
,
1200 .maxMipLevels
= maxMipLevels
,
1201 .maxArrayLayers
= maxArraySize
,
1202 .sampleCounts
= sampleCounts
,
1204 /* FINISHME: Accurately calculate
1205 * VkImageFormatProperties::maxResourceSize.
1207 .maxResourceSize
= UINT32_MAX
,
1212 *pImageFormatProperties
= (VkImageFormatProperties
) {
1213 .maxExtent
= { 0, 0, 0 },
1215 .maxArrayLayers
= 0,
1217 .maxResourceSize
= 0,
1220 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
1223 VkResult
radv_GetPhysicalDeviceImageFormatProperties(
1224 VkPhysicalDevice physicalDevice
,
1227 VkImageTiling tiling
,
1228 VkImageUsageFlags usage
,
1229 VkImageCreateFlags createFlags
,
1230 VkImageFormatProperties
* pImageFormatProperties
)
1232 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1234 const VkPhysicalDeviceImageFormatInfo2 info
= {
1235 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2
,
1241 .flags
= createFlags
,
1244 return radv_get_image_format_properties(physical_device
, &info
,
1245 pImageFormatProperties
);
1249 get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2
*pImageFormatInfo
,
1250 VkExternalMemoryHandleTypeFlagBits handleType
,
1251 VkExternalMemoryProperties
*external_properties
)
1253 VkExternalMemoryFeatureFlagBits flags
= 0;
1254 VkExternalMemoryHandleTypeFlags export_flags
= 0;
1255 VkExternalMemoryHandleTypeFlags compat_flags
= 0;
1256 switch (handleType
) {
1257 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1258 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1259 switch (pImageFormatInfo
->type
) {
1260 case VK_IMAGE_TYPE_2D
:
1261 flags
= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1262 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1263 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1269 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1270 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1271 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1277 *external_properties
= (VkExternalMemoryProperties
) {
1278 .externalMemoryFeatures
= flags
,
1279 .exportFromImportedHandleTypes
= export_flags
,
1280 .compatibleHandleTypes
= compat_flags
,
1284 VkResult
radv_GetPhysicalDeviceImageFormatProperties2(
1285 VkPhysicalDevice physicalDevice
,
1286 const VkPhysicalDeviceImageFormatInfo2
*base_info
,
1287 VkImageFormatProperties2
*base_props
)
1289 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1290 const VkPhysicalDeviceExternalImageFormatInfo
*external_info
= NULL
;
1291 VkExternalImageFormatProperties
*external_props
= NULL
;
1294 result
= radv_get_image_format_properties(physical_device
, base_info
,
1295 &base_props
->imageFormatProperties
);
1296 if (result
!= VK_SUCCESS
)
1299 /* Extract input structs */
1300 vk_foreach_struct_const(s
, base_info
->pNext
) {
1302 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO
:
1303 external_info
= (const void *) s
;
1310 /* Extract output structs */
1311 vk_foreach_struct(s
, base_props
->pNext
) {
1313 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES
:
1314 external_props
= (void *) s
;
1321 /* From the Vulkan 1.0.97 spec:
1323 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
1324 * behave as if VkPhysicalDeviceExternalImageFormatInfo was not
1325 * present and VkExternalImageFormatProperties will be ignored.
1327 if (external_info
&& external_info
->handleType
!= 0) {
1328 switch (external_info
->handleType
) {
1329 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1330 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1331 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1332 get_external_image_format_properties(base_info
, external_info
->handleType
,
1333 &external_props
->externalMemoryProperties
);
1336 /* From the Vulkan 1.0.97 spec:
1338 * If handleType is not compatible with the [parameters] specified
1339 * in VkPhysicalDeviceImageFormatInfo2, then
1340 * vkGetPhysicalDeviceImageFormatProperties2 returns
1341 * VK_ERROR_FORMAT_NOT_SUPPORTED.
1343 result
= vk_errorf(physical_device
->instance
, VK_ERROR_FORMAT_NOT_SUPPORTED
,
1344 "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
1345 external_info
->handleType
);
1353 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
1354 /* From the Vulkan 1.0.97 spec:
1356 * If the combination of parameters to
1357 * vkGetPhysicalDeviceImageFormatProperties2 is not supported by
1358 * the implementation for use in vkCreateImage, then all members of
1359 * imageFormatProperties will be filled with zero.
1361 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {0};
1367 void radv_GetPhysicalDeviceSparseImageFormatProperties(
1368 VkPhysicalDevice physicalDevice
,
1372 VkImageUsageFlags usage
,
1373 VkImageTiling tiling
,
1374 uint32_t* pNumProperties
,
1375 VkSparseImageFormatProperties
* pProperties
)
1377 /* Sparse images are not yet supported. */
1378 *pNumProperties
= 0;
1381 void radv_GetPhysicalDeviceSparseImageFormatProperties2(
1382 VkPhysicalDevice physicalDevice
,
1383 const VkPhysicalDeviceSparseImageFormatInfo2
*pFormatInfo
,
1384 uint32_t *pPropertyCount
,
1385 VkSparseImageFormatProperties2
*pProperties
)
1387 /* Sparse images are not yet supported. */
1388 *pPropertyCount
= 0;
1391 void radv_GetPhysicalDeviceExternalBufferProperties(
1392 VkPhysicalDevice physicalDevice
,
1393 const VkPhysicalDeviceExternalBufferInfo
*pExternalBufferInfo
,
1394 VkExternalBufferProperties
*pExternalBufferProperties
)
1396 VkExternalMemoryFeatureFlagBits flags
= 0;
1397 VkExternalMemoryHandleTypeFlags export_flags
= 0;
1398 VkExternalMemoryHandleTypeFlags compat_flags
= 0;
1399 switch(pExternalBufferInfo
->handleType
) {
1400 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1401 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1402 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|
1403 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1404 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1405 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1407 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1408 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1409 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1414 pExternalBufferProperties
->externalMemoryProperties
= (VkExternalMemoryProperties
) {
1415 .externalMemoryFeatures
= flags
,
1416 .exportFromImportedHandleTypes
= export_flags
,
1417 .compatibleHandleTypes
= compat_flags
,
1421 /* DCC channel type categories within which formats can be reinterpreted
1422 * while keeping the same DCC encoding. The swizzle must also match. */
1423 enum dcc_channel_type
{
1424 dcc_channel_float32
,
1427 dcc_channel_float16
,
1430 dcc_channel_uint_10_10_10_2
,
1433 dcc_channel_incompatible
,
1436 /* Return the type of DCC encoding. */
1437 static enum dcc_channel_type
1438 radv_get_dcc_channel_type(const struct vk_format_description
*desc
)
1442 /* Find the first non-void channel. */
1443 for (i
= 0; i
< desc
->nr_channels
; i
++)
1444 if (desc
->channel
[i
].type
!= VK_FORMAT_TYPE_VOID
)
1446 if (i
== desc
->nr_channels
)
1447 return dcc_channel_incompatible
;
1449 switch (desc
->channel
[i
].size
) {
1451 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1452 return dcc_channel_float32
;
1453 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1454 return dcc_channel_uint32
;
1455 return dcc_channel_sint32
;
1457 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1458 return dcc_channel_float16
;
1459 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1460 return dcc_channel_uint16
;
1461 return dcc_channel_sint16
;
1463 return dcc_channel_uint_10_10_10_2
;
1465 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1466 return dcc_channel_uint8
;
1467 return dcc_channel_sint8
;
1469 return dcc_channel_incompatible
;
1473 /* Return if it's allowed to reinterpret one format as another with DCC enabled. */
1474 bool radv_dcc_formats_compatible(VkFormat format1
,
1477 const struct vk_format_description
*desc1
, *desc2
;
1478 enum dcc_channel_type type1
, type2
;
1481 if (format1
== format2
)
1484 desc1
= vk_format_description(format1
);
1485 desc2
= vk_format_description(format2
);
1487 if (desc1
->nr_channels
!= desc2
->nr_channels
)
1490 /* Swizzles must be the same. */
1491 for (i
= 0; i
< desc1
->nr_channels
; i
++)
1492 if (desc1
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1493 desc2
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1494 desc1
->swizzle
[i
] != desc2
->swizzle
[i
])
1497 type1
= radv_get_dcc_channel_type(desc1
);
1498 type2
= radv_get_dcc_channel_type(desc2
);
1500 return type1
!= dcc_channel_incompatible
&&
1501 type2
!= dcc_channel_incompatible
&&