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 if (desc
->format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
43 return V_008F0C_BUF_DATA_FORMAT_10_11_11
;
45 if (first_non_void
< 0)
46 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
47 type
= desc
->channel
[first_non_void
].type
;
49 if (type
== VK_FORMAT_TYPE_FIXED
)
50 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
51 if (desc
->nr_channels
== 4 &&
52 desc
->channel
[0].size
== 10 &&
53 desc
->channel
[1].size
== 10 &&
54 desc
->channel
[2].size
== 10 &&
55 desc
->channel
[3].size
== 2)
56 return V_008F0C_BUF_DATA_FORMAT_2_10_10_10
;
58 /* See whether the components are of the same size. */
59 for (i
= 0; i
< desc
->nr_channels
; i
++) {
60 if (desc
->channel
[first_non_void
].size
!= desc
->channel
[i
].size
)
61 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
64 switch (desc
->channel
[first_non_void
].size
) {
66 switch (desc
->nr_channels
) {
68 return V_008F0C_BUF_DATA_FORMAT_8
;
70 return V_008F0C_BUF_DATA_FORMAT_8_8
;
72 return V_008F0C_BUF_DATA_FORMAT_8_8_8_8
;
76 switch (desc
->nr_channels
) {
78 return V_008F0C_BUF_DATA_FORMAT_16
;
80 return V_008F0C_BUF_DATA_FORMAT_16_16
;
82 return V_008F0C_BUF_DATA_FORMAT_16_16_16_16
;
86 /* From the Southern Islands ISA documentation about MTBUF:
87 * 'Memory reads of data in memory that is 32 or 64 bits do not
88 * undergo any format conversion.'
90 if (type
!= VK_FORMAT_TYPE_FLOAT
&&
91 !desc
->channel
[first_non_void
].pure_integer
)
92 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
94 switch (desc
->nr_channels
) {
96 return V_008F0C_BUF_DATA_FORMAT_32
;
98 return V_008F0C_BUF_DATA_FORMAT_32_32
;
100 return V_008F0C_BUF_DATA_FORMAT_32_32_32
;
102 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
107 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
110 uint32_t radv_translate_buffer_numformat(const struct vk_format_description
*desc
,
113 if (desc
->format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
114 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
116 if (first_non_void
< 0)
119 switch (desc
->channel
[first_non_void
].type
) {
120 case VK_FORMAT_TYPE_SIGNED
:
121 if (desc
->channel
[first_non_void
].normalized
)
122 return V_008F0C_BUF_NUM_FORMAT_SNORM
;
123 else if (desc
->channel
[first_non_void
].pure_integer
)
124 return V_008F0C_BUF_NUM_FORMAT_SINT
;
126 return V_008F0C_BUF_NUM_FORMAT_SSCALED
;
128 case VK_FORMAT_TYPE_UNSIGNED
:
129 if (desc
->channel
[first_non_void
].normalized
)
130 return V_008F0C_BUF_NUM_FORMAT_UNORM
;
131 else if (desc
->channel
[first_non_void
].pure_integer
)
132 return V_008F0C_BUF_NUM_FORMAT_UINT
;
134 return V_008F0C_BUF_NUM_FORMAT_USCALED
;
136 case VK_FORMAT_TYPE_FLOAT
:
138 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
142 uint32_t radv_translate_tex_dataformat(VkFormat format
,
143 const struct vk_format_description
*desc
,
151 /* Colorspace (return non-RGB formats directly). */
152 switch (desc
->colorspace
) {
153 /* Depth stencil formats */
154 case VK_FORMAT_COLORSPACE_ZS
:
156 case VK_FORMAT_D16_UNORM
:
157 return V_008F14_IMG_DATA_FORMAT_16
;
158 case VK_FORMAT_D24_UNORM_S8_UINT
:
159 case VK_FORMAT_X8_D24_UNORM_PACK32
:
160 return V_008F14_IMG_DATA_FORMAT_8_24
;
161 case VK_FORMAT_S8_UINT
:
162 return V_008F14_IMG_DATA_FORMAT_8
;
163 case VK_FORMAT_D32_SFLOAT
:
164 return V_008F14_IMG_DATA_FORMAT_32
;
165 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
166 return V_008F14_IMG_DATA_FORMAT_X24_8_32
;
171 case VK_FORMAT_COLORSPACE_YUV
:
172 goto out_unknown
; /* TODO */
174 case VK_FORMAT_COLORSPACE_SRGB
:
175 if (desc
->nr_channels
!= 4 && desc
->nr_channels
!= 1)
183 if (desc
->layout
== VK_FORMAT_LAYOUT_RGTC
) {
185 case VK_FORMAT_BC4_UNORM_BLOCK
:
186 case VK_FORMAT_BC4_SNORM_BLOCK
:
187 return V_008F14_IMG_DATA_FORMAT_BC4
;
188 case VK_FORMAT_BC5_UNORM_BLOCK
:
189 case VK_FORMAT_BC5_SNORM_BLOCK
:
190 return V_008F14_IMG_DATA_FORMAT_BC5
;
196 if (desc
->layout
== VK_FORMAT_LAYOUT_S3TC
) {
198 case VK_FORMAT_BC1_RGB_UNORM_BLOCK
:
199 case VK_FORMAT_BC1_RGB_SRGB_BLOCK
:
200 case VK_FORMAT_BC1_RGBA_UNORM_BLOCK
:
201 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK
:
202 return V_008F14_IMG_DATA_FORMAT_BC1
;
203 case VK_FORMAT_BC2_UNORM_BLOCK
:
204 case VK_FORMAT_BC2_SRGB_BLOCK
:
205 return V_008F14_IMG_DATA_FORMAT_BC2
;
206 case VK_FORMAT_BC3_UNORM_BLOCK
:
207 case VK_FORMAT_BC3_SRGB_BLOCK
:
208 return V_008F14_IMG_DATA_FORMAT_BC3
;
214 if (desc
->layout
== VK_FORMAT_LAYOUT_BPTC
) {
216 case VK_FORMAT_BC6H_UFLOAT_BLOCK
:
217 case VK_FORMAT_BC6H_SFLOAT_BLOCK
:
218 return V_008F14_IMG_DATA_FORMAT_BC6
;
219 case VK_FORMAT_BC7_UNORM_BLOCK
:
220 case VK_FORMAT_BC7_SRGB_BLOCK
:
221 return V_008F14_IMG_DATA_FORMAT_BC7
;
227 if (format
== VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
) {
228 return V_008F14_IMG_DATA_FORMAT_5_9_9_9
;
229 } else if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) {
230 return V_008F14_IMG_DATA_FORMAT_10_11_11
;
233 /* R8G8Bx_SNORM - TODO CxV8U8 */
235 /* hw cannot support mixed formats (except depth/stencil, since only
237 if (desc
->is_mixed
&& desc
->colorspace
!= VK_FORMAT_COLORSPACE_ZS
)
240 /* See whether the components are of the same size. */
241 for (i
= 1; i
< desc
->nr_channels
; i
++) {
242 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
245 /* Non-uniform formats. */
247 switch(desc
->nr_channels
) {
249 if (desc
->channel
[0].size
== 5 &&
250 desc
->channel
[1].size
== 6 &&
251 desc
->channel
[2].size
== 5) {
252 return V_008F14_IMG_DATA_FORMAT_5_6_5
;
256 if (desc
->channel
[0].size
== 5 &&
257 desc
->channel
[1].size
== 5 &&
258 desc
->channel
[2].size
== 5 &&
259 desc
->channel
[3].size
== 1) {
260 return V_008F14_IMG_DATA_FORMAT_1_5_5_5
;
262 if (desc
->channel
[0].size
== 1 &&
263 desc
->channel
[1].size
== 5 &&
264 desc
->channel
[2].size
== 5 &&
265 desc
->channel
[3].size
== 5) {
266 return V_008F14_IMG_DATA_FORMAT_5_5_5_1
;
268 if (desc
->channel
[0].size
== 10 &&
269 desc
->channel
[1].size
== 10 &&
270 desc
->channel
[2].size
== 10 &&
271 desc
->channel
[3].size
== 2) {
272 /* Closed VK driver does this also no 2/10/10/10 snorm */
273 if (desc
->channel
[0].type
== VK_FORMAT_TYPE_SIGNED
&&
274 desc
->channel
[0].normalized
)
276 return V_008F14_IMG_DATA_FORMAT_2_10_10_10
;
283 if (first_non_void
< 0 || first_non_void
> 3)
286 /* uniform formats */
287 switch (desc
->channel
[first_non_void
].size
) {
289 switch (desc
->nr_channels
) {
290 #if 0 /* Not supported for render targets */
292 return V_008F14_IMG_DATA_FORMAT_4_4
;
295 return V_008F14_IMG_DATA_FORMAT_4_4_4_4
;
299 switch (desc
->nr_channels
) {
301 return V_008F14_IMG_DATA_FORMAT_8
;
303 return V_008F14_IMG_DATA_FORMAT_8_8
;
305 return V_008F14_IMG_DATA_FORMAT_8_8_8_8
;
309 switch (desc
->nr_channels
) {
311 return V_008F14_IMG_DATA_FORMAT_16
;
313 return V_008F14_IMG_DATA_FORMAT_16_16
;
315 return V_008F14_IMG_DATA_FORMAT_16_16_16_16
;
319 switch (desc
->nr_channels
) {
321 return V_008F14_IMG_DATA_FORMAT_32
;
323 return V_008F14_IMG_DATA_FORMAT_32_32
;
324 #if 0 /* Not supported for render targets */
326 return V_008F14_IMG_DATA_FORMAT_32_32_32
;
329 return V_008F14_IMG_DATA_FORMAT_32_32_32_32
;
334 /* R600_ERR("Unable to handle texformat %d %s\n", format, vk_format_name(format)); */
338 uint32_t radv_translate_tex_numformat(VkFormat format
,
339 const struct vk_format_description
*desc
,
343 case VK_FORMAT_D24_UNORM_S8_UINT
:
344 return V_008F14_IMG_NUM_FORMAT_UNORM
;
346 if (first_non_void
< 0) {
347 if (vk_format_is_compressed(format
)) {
349 case VK_FORMAT_BC1_RGB_SRGB_BLOCK
:
350 case VK_FORMAT_BC1_RGBA_SRGB_BLOCK
:
351 case VK_FORMAT_BC2_SRGB_BLOCK
:
352 case VK_FORMAT_BC3_SRGB_BLOCK
:
353 case VK_FORMAT_BC7_SRGB_BLOCK
:
354 return V_008F14_IMG_NUM_FORMAT_SRGB
;
355 case VK_FORMAT_BC4_SNORM_BLOCK
:
356 case VK_FORMAT_BC5_SNORM_BLOCK
:
357 case VK_FORMAT_BC6H_SFLOAT_BLOCK
:
358 return V_008F14_IMG_NUM_FORMAT_SNORM
;
360 return V_008F14_IMG_NUM_FORMAT_UNORM
;
362 } else if (desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
363 return V_008F14_IMG_NUM_FORMAT_UNORM
;
365 return V_008F14_IMG_NUM_FORMAT_FLOAT
;
367 } else if (desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
) {
368 return V_008F14_IMG_NUM_FORMAT_SRGB
;
370 switch (desc
->channel
[first_non_void
].type
) {
371 case VK_FORMAT_TYPE_FLOAT
:
372 return V_008F14_IMG_NUM_FORMAT_FLOAT
;
373 case VK_FORMAT_TYPE_SIGNED
:
374 if (desc
->channel
[first_non_void
].normalized
)
375 return V_008F14_IMG_NUM_FORMAT_SNORM
;
376 else if (desc
->channel
[first_non_void
].pure_integer
)
377 return V_008F14_IMG_NUM_FORMAT_SINT
;
379 return V_008F14_IMG_NUM_FORMAT_SSCALED
;
380 case VK_FORMAT_TYPE_UNSIGNED
:
381 if (desc
->channel
[first_non_void
].normalized
)
382 return V_008F14_IMG_NUM_FORMAT_UNORM
;
383 else if (desc
->channel
[first_non_void
].pure_integer
)
384 return V_008F14_IMG_NUM_FORMAT_UINT
;
386 return V_008F14_IMG_NUM_FORMAT_USCALED
;
388 return V_008F14_IMG_NUM_FORMAT_UNORM
;
394 uint32_t radv_translate_color_numformat(VkFormat format
,
395 const struct vk_format_description
*desc
,
399 if (first_non_void
== -1 || desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_FLOAT
)
400 ntype
= V_028C70_NUMBER_FLOAT
;
402 ntype
= V_028C70_NUMBER_UNORM
;
403 if (desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
)
404 ntype
= V_028C70_NUMBER_SRGB
;
405 else if (desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_SIGNED
) {
406 if (desc
->channel
[first_non_void
].pure_integer
) {
407 ntype
= V_028C70_NUMBER_SINT
;
408 } else if (desc
->channel
[first_non_void
].normalized
) {
409 ntype
= V_028C70_NUMBER_SNORM
;
412 } else if (desc
->channel
[first_non_void
].type
== VK_FORMAT_TYPE_UNSIGNED
) {
413 if (desc
->channel
[first_non_void
].pure_integer
) {
414 ntype
= V_028C70_NUMBER_UINT
;
415 } else if (desc
->channel
[first_non_void
].normalized
) {
416 ntype
= V_028C70_NUMBER_UNORM
;
424 static bool radv_is_sampler_format_supported(VkFormat format
, bool *linear_sampling
)
426 const struct vk_format_description
*desc
= vk_format_description(format
);
428 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
430 num_format
= radv_translate_tex_numformat(format
, desc
,
431 vk_format_get_first_non_void_channel(format
));
433 if (num_format
== V_008F14_IMG_NUM_FORMAT_USCALED
||
434 num_format
== V_008F14_IMG_NUM_FORMAT_SSCALED
)
437 if (num_format
== V_008F14_IMG_NUM_FORMAT_UNORM
||
438 num_format
== V_008F14_IMG_NUM_FORMAT_SNORM
||
439 num_format
== V_008F14_IMG_NUM_FORMAT_FLOAT
||
440 num_format
== V_008F14_IMG_NUM_FORMAT_SRGB
)
441 *linear_sampling
= true;
443 *linear_sampling
= false;
444 return radv_translate_tex_dataformat(format
, vk_format_description(format
),
445 vk_format_get_first_non_void_channel(format
)) != ~0U;
449 static bool radv_is_storage_image_format_supported(struct radv_physical_device
*physical_device
,
452 const struct vk_format_description
*desc
= vk_format_description(format
);
453 unsigned data_format
, num_format
;
454 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
457 data_format
= radv_translate_tex_dataformat(format
, desc
,
458 vk_format_get_first_non_void_channel(format
));
459 num_format
= radv_translate_tex_numformat(format
, desc
,
460 vk_format_get_first_non_void_channel(format
));
462 if(data_format
== ~0 || num_format
== ~0)
465 /* Extracted from the GCN3 ISA document. */
467 case V_008F14_IMG_NUM_FORMAT_UNORM
:
468 case V_008F14_IMG_NUM_FORMAT_SNORM
:
469 case V_008F14_IMG_NUM_FORMAT_UINT
:
470 case V_008F14_IMG_NUM_FORMAT_SINT
:
471 case V_008F14_IMG_NUM_FORMAT_FLOAT
:
477 switch(data_format
) {
478 case V_008F14_IMG_DATA_FORMAT_8
:
479 case V_008F14_IMG_DATA_FORMAT_16
:
480 case V_008F14_IMG_DATA_FORMAT_8_8
:
481 case V_008F14_IMG_DATA_FORMAT_32
:
482 case V_008F14_IMG_DATA_FORMAT_16_16
:
483 case V_008F14_IMG_DATA_FORMAT_10_11_11
:
484 case V_008F14_IMG_DATA_FORMAT_11_11_10
:
485 case V_008F14_IMG_DATA_FORMAT_10_10_10_2
:
486 case V_008F14_IMG_DATA_FORMAT_2_10_10_10
:
487 case V_008F14_IMG_DATA_FORMAT_8_8_8_8
:
488 case V_008F14_IMG_DATA_FORMAT_32_32
:
489 case V_008F14_IMG_DATA_FORMAT_16_16_16_16
:
490 case V_008F14_IMG_DATA_FORMAT_32_32_32_32
:
491 case V_008F14_IMG_DATA_FORMAT_5_6_5
:
492 case V_008F14_IMG_DATA_FORMAT_1_5_5_5
:
493 case V_008F14_IMG_DATA_FORMAT_5_5_5_1
:
494 case V_008F14_IMG_DATA_FORMAT_4_4_4_4
:
495 /* TODO: FMASK formats. */
502 static bool radv_is_buffer_format_supported(VkFormat format
, bool *scaled
)
504 const struct vk_format_description
*desc
= vk_format_description(format
);
505 unsigned data_format
, num_format
;
506 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
509 data_format
= radv_translate_buffer_dataformat(desc
,
510 vk_format_get_first_non_void_channel(format
));
511 num_format
= radv_translate_buffer_numformat(desc
,
512 vk_format_get_first_non_void_channel(format
));
514 *scaled
= (num_format
== V_008F0C_BUF_NUM_FORMAT_SSCALED
) || (num_format
== V_008F0C_BUF_NUM_FORMAT_USCALED
);
515 return data_format
!= V_008F0C_BUF_DATA_FORMAT_INVALID
&&
519 bool radv_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
)
521 const struct vk_format_description
*desc
= vk_format_description(format
);
522 uint32_t color_format
= radv_translate_colorformat(format
);
523 uint32_t color_swap
= radv_translate_colorswap(format
, false);
524 uint32_t color_num_format
= radv_translate_color_numformat(format
,
526 vk_format_get_first_non_void_channel(format
));
528 if (color_num_format
== V_028C70_NUMBER_UINT
|| color_num_format
== V_028C70_NUMBER_SINT
||
529 color_format
== V_028C70_COLOR_8_24
|| color_format
== V_028C70_COLOR_24_8
||
530 color_format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
534 return color_format
!= V_028C70_COLOR_INVALID
&&
536 color_num_format
!= ~0;
539 static bool radv_is_zs_format_supported(VkFormat format
)
541 return radv_translate_dbformat(format
) != V_028040_Z_INVALID
|| format
== VK_FORMAT_S8_UINT
;
544 static bool radv_is_filter_minmax_format_supported(VkFormat format
)
546 /* From the Vulkan spec 1.1.71:
548 * "The following formats must support the
549 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT feature with
550 * VK_IMAGE_TILING_OPTIMAL, if they support
551 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT."
553 /* TODO: enable more formats. */
555 case VK_FORMAT_R8_UNORM
:
556 case VK_FORMAT_R8_SNORM
:
557 case VK_FORMAT_R16_UNORM
:
558 case VK_FORMAT_R16_SNORM
:
559 case VK_FORMAT_R16_SFLOAT
:
560 case VK_FORMAT_R32_SFLOAT
:
561 case VK_FORMAT_D16_UNORM
:
562 case VK_FORMAT_X8_D24_UNORM_PACK32
:
563 case VK_FORMAT_D32_SFLOAT
:
564 case VK_FORMAT_D16_UNORM_S8_UINT
:
565 case VK_FORMAT_D24_UNORM_S8_UINT
:
566 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
574 radv_physical_device_get_format_properties(struct radv_physical_device
*physical_device
,
576 VkFormatProperties
*out_properties
)
578 VkFormatFeatureFlags linear
= 0, tiled
= 0, buffer
= 0;
579 const struct vk_format_description
*desc
= vk_format_description(format
);
583 out_properties
->linearTilingFeatures
= linear
;
584 out_properties
->optimalTilingFeatures
= tiled
;
585 out_properties
->bufferFeatures
= buffer
;
589 if (radv_is_storage_image_format_supported(physical_device
, format
)) {
590 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
591 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
594 if (radv_is_buffer_format_supported(format
, &scaled
)) {
595 buffer
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
597 buffer
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
598 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
601 if (vk_format_is_depth_or_stencil(format
)) {
602 if (radv_is_zs_format_supported(format
)) {
603 tiled
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
;
604 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
605 tiled
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
606 VK_FORMAT_FEATURE_BLIT_DST_BIT
;
607 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR
|
608 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR
;
610 if (radv_is_filter_minmax_format_supported(format
))
611 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
613 /* GFX9 doesn't support linear depth surfaces */
614 if (physical_device
->rad_info
.chip_class
>= GFX9
)
618 bool linear_sampling
;
619 if (radv_is_sampler_format_supported(format
, &linear_sampling
)) {
620 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
621 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
622 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
623 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
625 if (radv_is_filter_minmax_format_supported(format
))
626 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT
;
628 if (linear_sampling
) {
629 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
630 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
633 if (radv_is_colorbuffer_format_supported(format
, &blendable
)) {
634 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
635 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
637 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
638 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
641 if (tiled
&& util_is_power_of_two_or_zero(vk_format_get_blocksize(format
)) && !scaled
) {
642 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR
|
643 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR
;
647 if (linear
&& util_is_power_of_two_or_zero(vk_format_get_blocksize(format
)) && !scaled
) {
648 linear
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR
|
649 VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR
;
652 if (format
== VK_FORMAT_R32_UINT
|| format
== VK_FORMAT_R32_SINT
) {
653 buffer
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
654 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
655 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
658 out_properties
->linearTilingFeatures
= linear
;
659 out_properties
->optimalTilingFeatures
= tiled
;
660 out_properties
->bufferFeatures
= buffer
;
663 uint32_t radv_translate_colorformat(VkFormat format
)
665 const struct vk_format_description
*desc
= vk_format_description(format
);
667 #define HAS_SIZE(x,y,z,w) \
668 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
669 desc->channel[2].size == (z) && desc->channel[3].size == (w))
671 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
) /* isn't plain */
672 return V_028C70_COLOR_10_11_11
;
674 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
675 return V_028C70_COLOR_INVALID
;
677 /* hw cannot support mixed formats (except depth/stencil, since
678 * stencil is not written to). */
679 if (desc
->is_mixed
&& desc
->colorspace
!= VK_FORMAT_COLORSPACE_ZS
)
680 return V_028C70_COLOR_INVALID
;
682 switch (desc
->nr_channels
) {
684 switch (desc
->channel
[0].size
) {
686 return V_028C70_COLOR_8
;
688 return V_028C70_COLOR_16
;
690 return V_028C70_COLOR_32
;
694 if (desc
->channel
[0].size
== desc
->channel
[1].size
) {
695 switch (desc
->channel
[0].size
) {
697 return V_028C70_COLOR_8_8
;
699 return V_028C70_COLOR_16_16
;
701 return V_028C70_COLOR_32_32
;
703 } else if (HAS_SIZE(8,24,0,0)) {
704 return V_028C70_COLOR_24_8
;
705 } else if (HAS_SIZE(24,8,0,0)) {
706 return V_028C70_COLOR_8_24
;
710 if (HAS_SIZE(5,6,5,0)) {
711 return V_028C70_COLOR_5_6_5
;
712 } else if (HAS_SIZE(32,8,24,0)) {
713 return V_028C70_COLOR_X24_8_32_FLOAT
;
717 if (desc
->channel
[0].size
== desc
->channel
[1].size
&&
718 desc
->channel
[0].size
== desc
->channel
[2].size
&&
719 desc
->channel
[0].size
== desc
->channel
[3].size
) {
720 switch (desc
->channel
[0].size
) {
722 return V_028C70_COLOR_4_4_4_4
;
724 return V_028C70_COLOR_8_8_8_8
;
726 return V_028C70_COLOR_16_16_16_16
;
728 return V_028C70_COLOR_32_32_32_32
;
730 } else if (HAS_SIZE(5,5,5,1)) {
731 return V_028C70_COLOR_1_5_5_5
;
732 } else if (HAS_SIZE(1,5,5,5)) {
733 return V_028C70_COLOR_5_5_5_1
;
734 } else if (HAS_SIZE(10,10,10,2)) {
735 return V_028C70_COLOR_2_10_10_10
;
739 return V_028C70_COLOR_INVALID
;
742 uint32_t radv_colorformat_endian_swap(uint32_t colorformat
)
744 if (0/*SI_BIG_ENDIAN*/) {
745 switch(colorformat
) {
747 case V_028C70_COLOR_8
:
748 return V_028C70_ENDIAN_NONE
;
750 /* 16-bit buffers. */
751 case V_028C70_COLOR_5_6_5
:
752 case V_028C70_COLOR_1_5_5_5
:
753 case V_028C70_COLOR_4_4_4_4
:
754 case V_028C70_COLOR_16
:
755 case V_028C70_COLOR_8_8
:
756 return V_028C70_ENDIAN_8IN16
;
758 /* 32-bit buffers. */
759 case V_028C70_COLOR_8_8_8_8
:
760 case V_028C70_COLOR_2_10_10_10
:
761 case V_028C70_COLOR_8_24
:
762 case V_028C70_COLOR_24_8
:
763 case V_028C70_COLOR_16_16
:
764 return V_028C70_ENDIAN_8IN32
;
766 /* 64-bit buffers. */
767 case V_028C70_COLOR_16_16_16_16
:
768 return V_028C70_ENDIAN_8IN16
;
770 case V_028C70_COLOR_32_32
:
771 return V_028C70_ENDIAN_8IN32
;
773 /* 128-bit buffers. */
774 case V_028C70_COLOR_32_32_32_32
:
775 return V_028C70_ENDIAN_8IN32
;
777 return V_028C70_ENDIAN_NONE
; /* Unsupported. */
780 return V_028C70_ENDIAN_NONE
;
784 uint32_t radv_translate_dbformat(VkFormat format
)
787 case VK_FORMAT_D16_UNORM
:
788 case VK_FORMAT_D16_UNORM_S8_UINT
:
789 return V_028040_Z_16
;
790 case VK_FORMAT_D32_SFLOAT
:
791 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
792 return V_028040_Z_32_FLOAT
;
794 return V_028040_Z_INVALID
;
798 unsigned radv_translate_colorswap(VkFormat format
, bool do_endian_swap
)
800 const struct vk_format_description
*desc
= vk_format_description(format
);
802 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == VK_SWIZZLE_##swz)
804 if (format
== VK_FORMAT_B10G11R11_UFLOAT_PACK32
)
805 return V_028C70_SWAP_STD
;
807 if (desc
->layout
!= VK_FORMAT_LAYOUT_PLAIN
)
810 switch (desc
->nr_channels
) {
812 if (HAS_SWIZZLE(0,X
))
813 return V_028C70_SWAP_STD
; /* X___ */
814 else if (HAS_SWIZZLE(3,X
))
815 return V_028C70_SWAP_ALT_REV
; /* ___X */
818 if ((HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,Y
)) ||
819 (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,NONE
)) ||
820 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,Y
)))
821 return V_028C70_SWAP_STD
; /* XY__ */
822 else if ((HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,X
)) ||
823 (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,NONE
)) ||
824 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,X
)))
826 return (do_endian_swap
? V_028C70_SWAP_STD
: V_028C70_SWAP_STD_REV
);
827 else if (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(3,Y
))
828 return V_028C70_SWAP_ALT
; /* X__Y */
829 else if (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(3,X
))
830 return V_028C70_SWAP_ALT_REV
; /* Y__X */
833 if (HAS_SWIZZLE(0,X
))
834 return (do_endian_swap
? V_028C70_SWAP_STD_REV
: V_028C70_SWAP_STD
);
835 else if (HAS_SWIZZLE(0,Z
))
836 return V_028C70_SWAP_STD_REV
; /* ZYX */
839 /* check the middle channels, the 1st and 4th channel can be NONE */
840 if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,Z
)) {
841 return V_028C70_SWAP_STD
; /* XYZW */
842 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,Y
)) {
843 return V_028C70_SWAP_STD_REV
; /* WZYX */
844 } else if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,X
)) {
845 return V_028C70_SWAP_ALT
; /* ZYXW */
846 } else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,W
)) {
849 return V_028C70_SWAP_ALT_REV
;
851 return (do_endian_swap
? V_028C70_SWAP_ALT
: V_028C70_SWAP_ALT_REV
);
858 bool radv_format_pack_clear_color(VkFormat format
,
859 uint32_t clear_vals
[2],
860 VkClearColorValue
*value
)
862 uint8_t r
= 0, g
= 0, b
= 0, a
= 0;
863 const struct vk_format_description
*desc
= vk_format_description(format
);
865 if (vk_format_get_component_bits(format
, VK_FORMAT_COLORSPACE_RGB
, 0) <= 8) {
866 if (desc
->colorspace
== VK_FORMAT_COLORSPACE_RGB
) {
867 r
= float_to_ubyte(value
->float32
[0]);
868 g
= float_to_ubyte(value
->float32
[1]);
869 b
= float_to_ubyte(value
->float32
[2]);
870 a
= float_to_ubyte(value
->float32
[3]);
871 } else if (desc
->colorspace
== VK_FORMAT_COLORSPACE_SRGB
) {
872 r
= util_format_linear_float_to_srgb_8unorm(value
->float32
[0]);
873 g
= util_format_linear_float_to_srgb_8unorm(value
->float32
[1]);
874 b
= util_format_linear_float_to_srgb_8unorm(value
->float32
[2]);
875 a
= float_to_ubyte(value
->float32
[3]);
879 case VK_FORMAT_R8_UNORM
:
880 case VK_FORMAT_R8_SRGB
:
884 case VK_FORMAT_R8G8_UNORM
:
885 case VK_FORMAT_R8G8_SRGB
:
886 clear_vals
[0] = r
| g
<< 8;
889 case VK_FORMAT_R8G8B8A8_SRGB
:
890 case VK_FORMAT_R8G8B8A8_UNORM
:
891 clear_vals
[0] = r
| g
<< 8 | b
<< 16 | a
<< 24;
894 case VK_FORMAT_B8G8R8A8_SRGB
:
895 case VK_FORMAT_B8G8R8A8_UNORM
:
896 clear_vals
[0] = b
| g
<< 8 | r
<< 16 | a
<< 24;
899 case VK_FORMAT_A8B8G8R8_UNORM_PACK32
:
900 case VK_FORMAT_A8B8G8R8_SRGB_PACK32
:
901 clear_vals
[0] = r
| g
<< 8 | b
<< 16 | a
<< 24;
904 case VK_FORMAT_R8_UINT
:
905 clear_vals
[0] = value
->uint32
[0] & 0xff;
908 case VK_FORMAT_R8_SINT
:
909 clear_vals
[0] = value
->int32
[0] & 0xff;
912 case VK_FORMAT_R16_UINT
:
913 clear_vals
[0] = value
->uint32
[0] & 0xffff;
916 case VK_FORMAT_R8G8_UINT
:
917 clear_vals
[0] = value
->uint32
[0] & 0xff;
918 clear_vals
[0] |= (value
->uint32
[1] & 0xff) << 8;
921 case VK_FORMAT_R8G8_SINT
:
922 clear_vals
[0] = value
->int32
[0] & 0xff;
923 clear_vals
[0] |= (value
->int32
[1] & 0xff) << 8;
926 case VK_FORMAT_R8G8B8A8_UINT
:
927 clear_vals
[0] = value
->uint32
[0] & 0xff;
928 clear_vals
[0] |= (value
->uint32
[1] & 0xff) << 8;
929 clear_vals
[0] |= (value
->uint32
[2] & 0xff) << 16;
930 clear_vals
[0] |= (value
->uint32
[3] & 0xff) << 24;
933 case VK_FORMAT_R8G8B8A8_SINT
:
934 clear_vals
[0] = value
->int32
[0] & 0xff;
935 clear_vals
[0] |= (value
->int32
[1] & 0xff) << 8;
936 clear_vals
[0] |= (value
->int32
[2] & 0xff) << 16;
937 clear_vals
[0] |= (value
->int32
[3] & 0xff) << 24;
940 case VK_FORMAT_A8B8G8R8_UINT_PACK32
:
941 clear_vals
[0] = value
->uint32
[0] & 0xff;
942 clear_vals
[0] |= (value
->uint32
[1] & 0xff) << 8;
943 clear_vals
[0] |= (value
->uint32
[2] & 0xff) << 16;
944 clear_vals
[0] |= (value
->uint32
[3] & 0xff) << 24;
947 case VK_FORMAT_R16G16_UINT
:
948 clear_vals
[0] = value
->uint32
[0] & 0xffff;
949 clear_vals
[0] |= (value
->uint32
[1] & 0xffff) << 16;
952 case VK_FORMAT_R16G16B16A16_UINT
:
953 clear_vals
[0] = value
->uint32
[0] & 0xffff;
954 clear_vals
[0] |= (value
->uint32
[1] & 0xffff) << 16;
955 clear_vals
[1] = value
->uint32
[2] & 0xffff;
956 clear_vals
[1] |= (value
->uint32
[3] & 0xffff) << 16;
958 case VK_FORMAT_R32_UINT
:
959 clear_vals
[0] = value
->uint32
[0];
962 case VK_FORMAT_R32G32_UINT
:
963 clear_vals
[0] = value
->uint32
[0];
964 clear_vals
[1] = value
->uint32
[1];
966 case VK_FORMAT_R32_SINT
:
967 clear_vals
[0] = value
->int32
[0];
970 case VK_FORMAT_R16_SFLOAT
:
971 clear_vals
[0] = util_float_to_half(value
->float32
[0]);
974 case VK_FORMAT_R16G16_SFLOAT
:
975 clear_vals
[0] = util_float_to_half(value
->float32
[0]);
976 clear_vals
[0] |= (uint32_t)util_float_to_half(value
->float32
[1]) << 16;
979 case VK_FORMAT_R16G16B16A16_SFLOAT
:
980 clear_vals
[0] = util_float_to_half(value
->float32
[0]);
981 clear_vals
[0] |= (uint32_t)util_float_to_half(value
->float32
[1]) << 16;
982 clear_vals
[1] = util_float_to_half(value
->float32
[2]);
983 clear_vals
[1] |= (uint32_t)util_float_to_half(value
->float32
[3]) << 16;
985 case VK_FORMAT_R16_UNORM
:
986 clear_vals
[0] = ((uint16_t)util_iround(CLAMP(value
->float32
[0], 0.0f
, 1.0f
) * 0xffff)) & 0xffff;
989 case VK_FORMAT_R16G16_UNORM
:
990 clear_vals
[0] = ((uint16_t)util_iround(CLAMP(value
->float32
[0], 0.0f
, 1.0f
) * 0xffff)) & 0xffff;
991 clear_vals
[0] |= ((uint16_t)util_iround(CLAMP(value
->float32
[1], 0.0f
, 1.0f
) * 0xffff)) << 16;
994 case VK_FORMAT_R16G16B16A16_UNORM
:
995 clear_vals
[0] = ((uint16_t)util_iround(CLAMP(value
->float32
[0], 0.0f
, 1.0f
) * 0xffff)) & 0xffff;
996 clear_vals
[0] |= ((uint16_t)util_iround(CLAMP(value
->float32
[1], 0.0f
, 1.0f
) * 0xffff)) << 16;
997 clear_vals
[1] = ((uint16_t)util_iround(CLAMP(value
->float32
[2], 0.0f
, 1.0f
) * 0xffff)) & 0xffff;
998 clear_vals
[1] |= ((uint16_t)util_iround(CLAMP(value
->float32
[3], 0.0f
, 1.0f
) * 0xffff)) << 16;
1000 case VK_FORMAT_R16G16B16A16_SNORM
:
1001 clear_vals
[0] = ((uint16_t)util_iround(CLAMP(value
->float32
[0], -1.0f
, 1.0f
) * 0x7fff)) & 0xffff;
1002 clear_vals
[0] |= ((uint16_t)util_iround(CLAMP(value
->float32
[1], -1.0f
, 1.0f
) * 0x7fff)) << 16;
1003 clear_vals
[1] = ((uint16_t)util_iround(CLAMP(value
->float32
[2], -1.0f
, 1.0f
) * 0x7fff)) & 0xffff;
1004 clear_vals
[1] |= ((uint16_t)util_iround(CLAMP(value
->float32
[3], -1.0f
, 1.0f
) * 0x7fff)) << 16;
1006 case VK_FORMAT_A2B10G10R10_UNORM_PACK32
:
1007 clear_vals
[0] = ((uint16_t)util_iround(CLAMP(value
->float32
[0], 0.0f
, 1.0f
) * 0x3ff)) & 0x3ff;
1008 clear_vals
[0] |= (((uint16_t)util_iround(CLAMP(value
->float32
[1], 0.0f
, 1.0f
) * 0x3ff)) & 0x3ff) << 10;
1009 clear_vals
[0] |= (((uint16_t)util_iround(CLAMP(value
->float32
[2], 0.0f
, 1.0f
) * 0x3ff)) & 0x3ff) << 20;
1010 clear_vals
[0] |= (((uint16_t)util_iround(CLAMP(value
->float32
[3], 0.0f
, 1.0f
) * 0x3)) & 0x3) << 30;
1013 case VK_FORMAT_R32G32_SFLOAT
:
1014 clear_vals
[0] = fui(value
->float32
[0]);
1015 clear_vals
[1] = fui(value
->float32
[1]);
1017 case VK_FORMAT_R32_SFLOAT
:
1019 clear_vals
[0] = fui(value
->float32
[0]);
1021 case VK_FORMAT_B10G11R11_UFLOAT_PACK32
:
1022 clear_vals
[0] = float3_to_r11g11b10f(value
->float32
);
1025 case VK_FORMAT_R32G32B32A32_SFLOAT
:
1026 if (value
->float32
[0] != value
->float32
[1] ||
1027 value
->float32
[0] != value
->float32
[2])
1029 clear_vals
[0] = fui(value
->float32
[0]);
1030 clear_vals
[1] = fui(value
->float32
[3]);
1032 case VK_FORMAT_R32G32B32A32_UINT
:
1033 if (value
->uint32
[0] != value
->uint32
[1] ||
1034 value
->uint32
[0] != value
->uint32
[2])
1036 clear_vals
[0] = value
->uint32
[0];
1037 clear_vals
[1] = value
->uint32
[3];
1039 case VK_FORMAT_R32G32B32A32_SINT
:
1040 if (value
->int32
[0] != value
->int32
[1] ||
1041 value
->int32
[0] != value
->int32
[2])
1043 clear_vals
[0] = value
->int32
[0];
1044 clear_vals
[1] = value
->int32
[3];
1047 fprintf(stderr
, "failed to fast clear %d\n", format
);
1053 void radv_GetPhysicalDeviceFormatProperties(
1054 VkPhysicalDevice physicalDevice
,
1056 VkFormatProperties
* pFormatProperties
)
1058 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1060 radv_physical_device_get_format_properties(physical_device
,
1065 void radv_GetPhysicalDeviceFormatProperties2(
1066 VkPhysicalDevice physicalDevice
,
1068 VkFormatProperties2KHR
* pFormatProperties
)
1070 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1072 radv_physical_device_get_format_properties(physical_device
,
1074 &pFormatProperties
->formatProperties
);
1077 static VkResult
radv_get_image_format_properties(struct radv_physical_device
*physical_device
,
1078 const VkPhysicalDeviceImageFormatInfo2KHR
*info
,
1079 VkImageFormatProperties
*pImageFormatProperties
)
1082 VkFormatProperties format_props
;
1083 VkFormatFeatureFlags format_feature_flags
;
1084 VkExtent3D maxExtent
;
1085 uint32_t maxMipLevels
;
1086 uint32_t maxArraySize
;
1087 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1089 radv_physical_device_get_format_properties(physical_device
, info
->format
,
1091 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
1092 format_feature_flags
= format_props
.linearTilingFeatures
;
1093 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
1094 format_feature_flags
= format_props
.optimalTilingFeatures
;
1096 unreachable("bad VkImageTiling");
1099 if (format_feature_flags
== 0)
1102 if (info
->type
!= VK_IMAGE_TYPE_2D
&& vk_format_is_depth_or_stencil(info
->format
))
1105 switch (info
->type
) {
1107 unreachable("bad vkimage type\n");
1108 case VK_IMAGE_TYPE_1D
:
1109 maxExtent
.width
= 16384;
1110 maxExtent
.height
= 1;
1111 maxExtent
.depth
= 1;
1112 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1113 maxArraySize
= 2048;
1115 case VK_IMAGE_TYPE_2D
:
1116 maxExtent
.width
= 16384;
1117 maxExtent
.height
= 16384;
1118 maxExtent
.depth
= 1;
1119 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1120 maxArraySize
= 2048;
1122 case VK_IMAGE_TYPE_3D
:
1123 maxExtent
.width
= 2048;
1124 maxExtent
.height
= 2048;
1125 maxExtent
.depth
= 2048;
1126 maxMipLevels
= 12; /* log2(maxWidth) + 1 */
1131 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
1132 info
->type
== VK_IMAGE_TYPE_2D
&&
1133 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1134 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
1135 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
) &&
1136 !(info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
)) {
1137 sampleCounts
|= VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
1140 if (info
->usage
& VK_IMAGE_USAGE_SAMPLED_BIT
) {
1141 if (!(format_feature_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)) {
1146 if (info
->usage
& VK_IMAGE_USAGE_STORAGE_BIT
) {
1147 if (!(format_feature_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)) {
1152 if (info
->usage
& VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
) {
1153 if (!(format_feature_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)) {
1158 if (info
->usage
& VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
) {
1159 if (!(format_feature_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) {
1164 *pImageFormatProperties
= (VkImageFormatProperties
) {
1165 .maxExtent
= maxExtent
,
1166 .maxMipLevels
= maxMipLevels
,
1167 .maxArrayLayers
= maxArraySize
,
1168 .sampleCounts
= sampleCounts
,
1170 /* FINISHME: Accurately calculate
1171 * VkImageFormatProperties::maxResourceSize.
1173 .maxResourceSize
= UINT32_MAX
,
1178 *pImageFormatProperties
= (VkImageFormatProperties
) {
1179 .maxExtent
= { 0, 0, 0 },
1181 .maxArrayLayers
= 0,
1183 .maxResourceSize
= 0,
1186 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
1189 VkResult
radv_GetPhysicalDeviceImageFormatProperties(
1190 VkPhysicalDevice physicalDevice
,
1193 VkImageTiling tiling
,
1194 VkImageUsageFlags usage
,
1195 VkImageCreateFlags createFlags
,
1196 VkImageFormatProperties
* pImageFormatProperties
)
1198 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1200 const VkPhysicalDeviceImageFormatInfo2KHR info
= {
1201 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR
,
1207 .flags
= createFlags
,
1210 return radv_get_image_format_properties(physical_device
, &info
,
1211 pImageFormatProperties
);
1215 get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2KHR
*pImageFormatInfo
,
1216 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1217 VkExternalMemoryPropertiesKHR
*external_properties
)
1219 VkExternalMemoryFeatureFlagBitsKHR flags
= 0;
1220 VkExternalMemoryHandleTypeFlagsKHR export_flags
= 0;
1221 VkExternalMemoryHandleTypeFlagsKHR compat_flags
= 0;
1222 switch (handleType
) {
1223 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
1224 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1225 switch (pImageFormatInfo
->type
) {
1226 case VK_IMAGE_TYPE_2D
:
1227 flags
= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR
|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR
|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
;
1228 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
|
1229 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1235 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1236 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
;
1237 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1243 *external_properties
= (VkExternalMemoryPropertiesKHR
) {
1244 .externalMemoryFeatures
= flags
,
1245 .exportFromImportedHandleTypes
= export_flags
,
1246 .compatibleHandleTypes
= compat_flags
,
1250 VkResult
radv_GetPhysicalDeviceImageFormatProperties2(
1251 VkPhysicalDevice physicalDevice
,
1252 const VkPhysicalDeviceImageFormatInfo2KHR
*base_info
,
1253 VkImageFormatProperties2KHR
*base_props
)
1255 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1256 const VkPhysicalDeviceExternalImageFormatInfoKHR
*external_info
= NULL
;
1257 VkExternalImageFormatPropertiesKHR
*external_props
= NULL
;
1260 result
= radv_get_image_format_properties(physical_device
, base_info
,
1261 &base_props
->imageFormatProperties
);
1262 if (result
!= VK_SUCCESS
)
1265 /* Extract input structs */
1266 vk_foreach_struct_const(s
, base_info
->pNext
) {
1268 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR
:
1269 external_info
= (const void *) s
;
1276 /* Extract output structs */
1277 vk_foreach_struct(s
, base_props
->pNext
) {
1279 case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR
:
1280 external_props
= (void *) s
;
1287 /* From the Vulkan 1.0.42 spec:
1289 * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
1290 * behave as if VkPhysicalDeviceExternalImageFormatInfoKHR was not
1291 * present and VkExternalImageFormatPropertiesKHR will be ignored.
1293 if (external_info
&& external_info
->handleType
!= 0) {
1294 switch (external_info
->handleType
) {
1295 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
1296 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1297 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1298 get_external_image_format_properties(base_info
, external_info
->handleType
,
1299 &external_props
->externalMemoryProperties
);
1302 /* From the Vulkan 1.0.42 spec:
1304 * If handleType is not compatible with the [parameters] specified
1305 * in VkPhysicalDeviceImageFormatInfo2KHR, then
1306 * vkGetPhysicalDeviceImageFormatProperties2KHR returns
1307 * VK_ERROR_FORMAT_NOT_SUPPORTED.
1309 result
= vk_errorf(VK_ERROR_FORMAT_NOT_SUPPORTED
,
1310 "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
1311 external_info
->handleType
);
1319 if (result
== VK_ERROR_FORMAT_NOT_SUPPORTED
) {
1320 /* From the Vulkan 1.0.42 spec:
1322 * If the combination of parameters to
1323 * vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by
1324 * the implementation for use in vkCreateImage, then all members of
1325 * imageFormatProperties will be filled with zero.
1327 base_props
->imageFormatProperties
= (VkImageFormatProperties
) {0};
1333 void radv_GetPhysicalDeviceSparseImageFormatProperties(
1334 VkPhysicalDevice physicalDevice
,
1338 VkImageUsageFlags usage
,
1339 VkImageTiling tiling
,
1340 uint32_t* pNumProperties
,
1341 VkSparseImageFormatProperties
* pProperties
)
1343 /* Sparse images are not yet supported. */
1344 *pNumProperties
= 0;
1347 void radv_GetPhysicalDeviceSparseImageFormatProperties2(
1348 VkPhysicalDevice physicalDevice
,
1349 const VkPhysicalDeviceSparseImageFormatInfo2KHR
* pFormatInfo
,
1350 uint32_t *pPropertyCount
,
1351 VkSparseImageFormatProperties2KHR
* pProperties
)
1353 /* Sparse images are not yet supported. */
1354 *pPropertyCount
= 0;
1357 void radv_GetPhysicalDeviceExternalBufferProperties(
1358 VkPhysicalDevice physicalDevice
,
1359 const VkPhysicalDeviceExternalBufferInfoKHR
*pExternalBufferInfo
,
1360 VkExternalBufferPropertiesKHR
*pExternalBufferProperties
)
1362 VkExternalMemoryFeatureFlagBitsKHR flags
= 0;
1363 VkExternalMemoryHandleTypeFlagsKHR export_flags
= 0;
1364 VkExternalMemoryHandleTypeFlagsKHR compat_flags
= 0;
1365 switch(pExternalBufferInfo
->handleType
) {
1366 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
1367 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1368 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR
|
1369 VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
;
1370 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
|
1371 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1373 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1374 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR
;
1375 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1380 pExternalBufferProperties
->externalMemoryProperties
= (VkExternalMemoryPropertiesKHR
) {
1381 .externalMemoryFeatures
= flags
,
1382 .exportFromImportedHandleTypes
= export_flags
,
1383 .compatibleHandleTypes
= compat_flags
,
1387 /* DCC channel type categories within which formats can be reinterpreted
1388 * while keeping the same DCC encoding. The swizzle must also match. */
1389 enum dcc_channel_type
{
1390 dcc_channel_float32
,
1393 dcc_channel_float16
,
1396 dcc_channel_uint_10_10_10_2
,
1399 dcc_channel_incompatible
,
1402 /* Return the type of DCC encoding. */
1403 static enum dcc_channel_type
1404 radv_get_dcc_channel_type(const struct vk_format_description
*desc
)
1408 /* Find the first non-void channel. */
1409 for (i
= 0; i
< desc
->nr_channels
; i
++)
1410 if (desc
->channel
[i
].type
!= VK_FORMAT_TYPE_VOID
)
1412 if (i
== desc
->nr_channels
)
1413 return dcc_channel_incompatible
;
1415 switch (desc
->channel
[i
].size
) {
1417 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1418 return dcc_channel_float32
;
1419 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1420 return dcc_channel_uint32
;
1421 return dcc_channel_sint32
;
1423 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_FLOAT
)
1424 return dcc_channel_float16
;
1425 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1426 return dcc_channel_uint16
;
1427 return dcc_channel_sint16
;
1429 return dcc_channel_uint_10_10_10_2
;
1431 if (desc
->channel
[i
].type
== VK_FORMAT_TYPE_UNSIGNED
)
1432 return dcc_channel_uint8
;
1433 return dcc_channel_sint8
;
1435 return dcc_channel_incompatible
;
1439 /* Return if it's allowed to reinterpret one format as another with DCC enabled. */
1440 bool radv_dcc_formats_compatible(VkFormat format1
,
1443 const struct vk_format_description
*desc1
, *desc2
;
1444 enum dcc_channel_type type1
, type2
;
1447 if (format1
== format2
)
1450 desc1
= vk_format_description(format1
);
1451 desc2
= vk_format_description(format2
);
1453 if (desc1
->nr_channels
!= desc2
->nr_channels
)
1456 /* Swizzles must be the same. */
1457 for (i
= 0; i
< desc1
->nr_channels
; i
++)
1458 if (desc1
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1459 desc2
->swizzle
[i
] <= VK_SWIZZLE_W
&&
1460 desc1
->swizzle
[i
] != desc2
->swizzle
[i
])
1463 type1
= radv_get_dcc_channel_type(desc1
);
1464 type2
= radv_get_dcc_channel_type(desc2
);
1466 return type1
!= dcc_channel_incompatible
&&
1467 type2
!= dcc_channel_incompatible
&&