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 "libresoc_private.h"
27 #include "vk_format.h"
31 #include "util/u_half.h"
32 #include "util/format_srgb.h"
33 #include "util/format_r11g11b10f.h"
35 //uint32_t libresoc_translate_buffer_dataformat(const struct vk_format_description *desc,
36 // int first_non_void)
41 // assert(desc->layout != VK_FORMAT_LAYOUT_MULTIPLANE);
43 // if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
44 // return V_008F0C_BUF_DATA_FORMAT_10_11_11;
46 // if (first_non_void < 0)
47 // return V_008F0C_BUF_DATA_FORMAT_INVALID;
48 // type = desc->channel[first_non_void].type;
50 // if (type == VK_FORMAT_TYPE_FIXED)
51 // return V_008F0C_BUF_DATA_FORMAT_INVALID;
52 // if (desc->nr_channels == 4 &&
53 // desc->channel[0].size == 10 &&
54 // desc->channel[1].size == 10 &&
55 // desc->channel[2].size == 10 &&
56 // desc->channel[3].size == 2)
57 // return V_008F0C_BUF_DATA_FORMAT_2_10_10_10;
59 // /* See whether the components are of the same size. */
60 // for (i = 0; i < desc->nr_channels; i++) {
61 // if (desc->channel[first_non_void].size != desc->channel[i].size)
62 // return V_008F0C_BUF_DATA_FORMAT_INVALID;
65 // switch (desc->channel[first_non_void].size) {
67 // switch (desc->nr_channels) {
69 // return V_008F0C_BUF_DATA_FORMAT_8;
71 // return V_008F0C_BUF_DATA_FORMAT_8_8;
73 // return V_008F0C_BUF_DATA_FORMAT_8_8_8_8;
77 // switch (desc->nr_channels) {
79 // return V_008F0C_BUF_DATA_FORMAT_16;
81 // return V_008F0C_BUF_DATA_FORMAT_16_16;
83 // return V_008F0C_BUF_DATA_FORMAT_16_16_16_16;
87 // /* From the Southern Islands ISA documentation about MTBUF:
88 // * 'Memory reads of data in memory that is 32 or 64 bits do not
89 // * undergo any format conversion.'
91 // if (type != VK_FORMAT_TYPE_FLOAT &&
92 // !desc->channel[first_non_void].pure_integer)
93 // return V_008F0C_BUF_DATA_FORMAT_INVALID;
95 // switch (desc->nr_channels) {
97 // return V_008F0C_BUF_DATA_FORMAT_32;
99 // return V_008F0C_BUF_DATA_FORMAT_32_32;
101 // return V_008F0C_BUF_DATA_FORMAT_32_32_32;
103 // return V_008F0C_BUF_DATA_FORMAT_32_32_32_32;
108 // return V_008F0C_BUF_DATA_FORMAT_INVALID;
111 //uint32_t libresoc_translate_buffer_numformat(const struct vk_format_description *desc,
112 // int first_non_void)
114 // assert(desc->layout != VK_FORMAT_LAYOUT_MULTIPLANE);
116 // if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
117 // return V_008F0C_BUF_NUM_FORMAT_FLOAT;
119 // if (first_non_void < 0)
122 // switch (desc->channel[first_non_void].type) {
123 // case VK_FORMAT_TYPE_SIGNED:
124 // if (desc->channel[first_non_void].normalized)
125 // return V_008F0C_BUF_NUM_FORMAT_SNORM;
126 // else if (desc->channel[first_non_void].pure_integer)
127 // return V_008F0C_BUF_NUM_FORMAT_SINT;
129 // return V_008F0C_BUF_NUM_FORMAT_SSCALED;
131 // case VK_FORMAT_TYPE_UNSIGNED:
132 // if (desc->channel[first_non_void].normalized)
133 // return V_008F0C_BUF_NUM_FORMAT_UNORM;
134 // else if (desc->channel[first_non_void].pure_integer)
135 // return V_008F0C_BUF_NUM_FORMAT_UINT;
137 // return V_008F0C_BUF_NUM_FORMAT_USCALED;
139 // case VK_FORMAT_TYPE_FLOAT:
141 // return V_008F0C_BUF_NUM_FORMAT_FLOAT;
145 //uint32_t libresoc_translate_tex_dataformat(VkFormat format,
146 // const struct vk_format_description *desc,
147 // int first_non_void)
149 // bool uniform = true;
152 // assert(vk_format_get_plane_count(format) == 1);
156 // /* Colorspace (return non-RGB formats directly). */
157 // switch (desc->colorspace) {
158 // /* Depth stencil formats */
159 // case VK_FORMAT_COLORSPACE_ZS:
161 // case VK_FORMAT_D16_UNORM:
162 // return V_008F14_IMG_DATA_FORMAT_16;
163 // case VK_FORMAT_D24_UNORM_S8_UINT:
164 // case VK_FORMAT_X8_D24_UNORM_PACK32:
165 // return V_008F14_IMG_DATA_FORMAT_8_24;
166 // case VK_FORMAT_S8_UINT:
167 // return V_008F14_IMG_DATA_FORMAT_8;
168 // case VK_FORMAT_D32_SFLOAT:
169 // return V_008F14_IMG_DATA_FORMAT_32;
170 // case VK_FORMAT_D32_SFLOAT_S8_UINT:
171 // return V_008F14_IMG_DATA_FORMAT_X24_8_32;
176 // case VK_FORMAT_COLORSPACE_YUV:
177 // goto out_unknown; /* TODO */
179 // case VK_FORMAT_COLORSPACE_SRGB:
180 // if (desc->nr_channels != 4 && desc->nr_channels != 1)
188 // if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
190 // /* Don't ask me why this looks inverted. PAL does the same. */
191 // case VK_FORMAT_G8B8G8R8_422_UNORM:
192 // return V_008F14_IMG_DATA_FORMAT_BG_RG;
193 // case VK_FORMAT_B8G8R8G8_422_UNORM:
194 // return V_008F14_IMG_DATA_FORMAT_GB_GR;
200 // if (desc->layout == VK_FORMAT_LAYOUT_RGTC) {
202 // case VK_FORMAT_BC4_UNORM_BLOCK:
203 // case VK_FORMAT_BC4_SNORM_BLOCK:
204 // return V_008F14_IMG_DATA_FORMAT_BC4;
205 // case VK_FORMAT_BC5_UNORM_BLOCK:
206 // case VK_FORMAT_BC5_SNORM_BLOCK:
207 // return V_008F14_IMG_DATA_FORMAT_BC5;
213 // if (desc->layout == VK_FORMAT_LAYOUT_S3TC) {
215 // case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
216 // case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
217 // case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
218 // case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
219 // return V_008F14_IMG_DATA_FORMAT_BC1;
220 // case VK_FORMAT_BC2_UNORM_BLOCK:
221 // case VK_FORMAT_BC2_SRGB_BLOCK:
222 // return V_008F14_IMG_DATA_FORMAT_BC2;
223 // case VK_FORMAT_BC3_UNORM_BLOCK:
224 // case VK_FORMAT_BC3_SRGB_BLOCK:
225 // return V_008F14_IMG_DATA_FORMAT_BC3;
231 // if (desc->layout == VK_FORMAT_LAYOUT_BPTC) {
233 // case VK_FORMAT_BC6H_UFLOAT_BLOCK:
234 // case VK_FORMAT_BC6H_SFLOAT_BLOCK:
235 // return V_008F14_IMG_DATA_FORMAT_BC6;
236 // case VK_FORMAT_BC7_UNORM_BLOCK:
237 // case VK_FORMAT_BC7_SRGB_BLOCK:
238 // return V_008F14_IMG_DATA_FORMAT_BC7;
244 // if (desc->layout == VK_FORMAT_LAYOUT_ETC) {
246 // case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
247 // case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
248 // return V_008F14_IMG_DATA_FORMAT_ETC2_RGB;
249 // case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
250 // case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
251 // return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA1;
252 // case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
253 // case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
254 // return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA;
255 // case VK_FORMAT_EAC_R11_UNORM_BLOCK:
256 // case VK_FORMAT_EAC_R11_SNORM_BLOCK:
257 // return V_008F14_IMG_DATA_FORMAT_ETC2_R;
258 // case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
259 // case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
260 // return V_008F14_IMG_DATA_FORMAT_ETC2_RG;
266 // if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) {
267 // return V_008F14_IMG_DATA_FORMAT_5_9_9_9;
268 // } else if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
269 // return V_008F14_IMG_DATA_FORMAT_10_11_11;
272 // /* R8G8Bx_SNORM - TODO CxV8U8 */
274 // /* hw cannot support mixed formats (except depth/stencil, since only
275 // * depth is read).*/
276 // if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
279 // /* See whether the components are of the same size. */
280 // for (i = 1; i < desc->nr_channels; i++) {
281 // uniform = uniform && desc->channel[0].size == desc->channel[i].size;
284 // /* Non-uniform formats. */
286 // switch(desc->nr_channels) {
288 // if (desc->channel[0].size == 5 &&
289 // desc->channel[1].size == 6 &&
290 // desc->channel[2].size == 5) {
291 // return V_008F14_IMG_DATA_FORMAT_5_6_5;
295 // if (desc->channel[0].size == 5 &&
296 // desc->channel[1].size == 5 &&
297 // desc->channel[2].size == 5 &&
298 // desc->channel[3].size == 1) {
299 // return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
301 // if (desc->channel[0].size == 1 &&
302 // desc->channel[1].size == 5 &&
303 // desc->channel[2].size == 5 &&
304 // desc->channel[3].size == 5) {
305 // return V_008F14_IMG_DATA_FORMAT_5_5_5_1;
307 // if (desc->channel[0].size == 10 &&
308 // desc->channel[1].size == 10 &&
309 // desc->channel[2].size == 10 &&
310 // desc->channel[3].size == 2) {
311 // /* Closed VK driver does this also no 2/10/10/10 snorm */
312 // if (desc->channel[0].type == VK_FORMAT_TYPE_SIGNED &&
313 // desc->channel[0].normalized)
315 // return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
322 // if (first_non_void < 0 || first_non_void > 3)
325 // /* uniform formats */
326 // switch (desc->channel[first_non_void].size) {
328 // switch (desc->nr_channels) {
329 //#if 0 /* Not supported for render targets */
331 // return V_008F14_IMG_DATA_FORMAT_4_4;
334 // return V_008F14_IMG_DATA_FORMAT_4_4_4_4;
338 // switch (desc->nr_channels) {
340 // return V_008F14_IMG_DATA_FORMAT_8;
342 // return V_008F14_IMG_DATA_FORMAT_8_8;
344 // return V_008F14_IMG_DATA_FORMAT_8_8_8_8;
348 // switch (desc->nr_channels) {
350 // return V_008F14_IMG_DATA_FORMAT_16;
352 // return V_008F14_IMG_DATA_FORMAT_16_16;
354 // return V_008F14_IMG_DATA_FORMAT_16_16_16_16;
358 // switch (desc->nr_channels) {
360 // return V_008F14_IMG_DATA_FORMAT_32;
362 // return V_008F14_IMG_DATA_FORMAT_32_32;
364 // return V_008F14_IMG_DATA_FORMAT_32_32_32;
366 // return V_008F14_IMG_DATA_FORMAT_32_32_32_32;
371 // /* R600_ERR("Unable to handle texformat %d %s\n", format, vk_format_name(format)); */
375 //uint32_t libresoc_translate_tex_numformat(VkFormat format,
376 // const struct vk_format_description *desc,
377 // int first_non_void)
379 // assert(vk_format_get_plane_count(format) == 1);
382 // case VK_FORMAT_D24_UNORM_S8_UINT:
383 // return V_008F14_IMG_NUM_FORMAT_UNORM;
385 // if (first_non_void < 0) {
386 // if (vk_format_is_compressed(format)) {
388 // case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
389 // case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
390 // case VK_FORMAT_BC2_SRGB_BLOCK:
391 // case VK_FORMAT_BC3_SRGB_BLOCK:
392 // case VK_FORMAT_BC7_SRGB_BLOCK:
393 // case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
394 // case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
395 // case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
396 // return V_008F14_IMG_NUM_FORMAT_SRGB;
397 // case VK_FORMAT_BC4_SNORM_BLOCK:
398 // case VK_FORMAT_BC5_SNORM_BLOCK:
399 // case VK_FORMAT_BC6H_SFLOAT_BLOCK:
400 // case VK_FORMAT_EAC_R11_SNORM_BLOCK:
401 // case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
402 // return V_008F14_IMG_NUM_FORMAT_SNORM;
404 // return V_008F14_IMG_NUM_FORMAT_UNORM;
406 // } else if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
407 // return V_008F14_IMG_NUM_FORMAT_UNORM;
409 // return V_008F14_IMG_NUM_FORMAT_FLOAT;
411 // } else if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
412 // return V_008F14_IMG_NUM_FORMAT_SRGB;
414 // switch (desc->channel[first_non_void].type) {
415 // case VK_FORMAT_TYPE_FLOAT:
416 // return V_008F14_IMG_NUM_FORMAT_FLOAT;
417 // case VK_FORMAT_TYPE_SIGNED:
418 // if (desc->channel[first_non_void].normalized)
419 // return V_008F14_IMG_NUM_FORMAT_SNORM;
420 // else if (desc->channel[first_non_void].pure_integer)
421 // return V_008F14_IMG_NUM_FORMAT_SINT;
423 // return V_008F14_IMG_NUM_FORMAT_SSCALED;
424 // case VK_FORMAT_TYPE_UNSIGNED:
425 // if (desc->channel[first_non_void].normalized)
426 // return V_008F14_IMG_NUM_FORMAT_UNORM;
427 // else if (desc->channel[first_non_void].pure_integer)
428 // return V_008F14_IMG_NUM_FORMAT_UINT;
430 // return V_008F14_IMG_NUM_FORMAT_USCALED;
432 // return V_008F14_IMG_NUM_FORMAT_UNORM;
438 //uint32_t libresoc_translate_color_numformat(VkFormat format,
439 // const struct vk_format_description *desc,
440 // int first_non_void)
444 // assert(vk_format_get_plane_count(format) == 1);
446 // if (first_non_void == -1 || desc->channel[first_non_void].type == VK_FORMAT_TYPE_FLOAT)
447 // ntype = V_028C70_NUMBER_FLOAT;
449 // ntype = V_028C70_NUMBER_UNORM;
450 // if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB)
451 // ntype = V_028C70_NUMBER_SRGB;
452 // else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_SIGNED) {
453 // if (desc->channel[first_non_void].pure_integer) {
454 // ntype = V_028C70_NUMBER_SINT;
455 // } else if (desc->channel[first_non_void].normalized) {
456 // ntype = V_028C70_NUMBER_SNORM;
459 // } else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_UNSIGNED) {
460 // if (desc->channel[first_non_void].pure_integer) {
461 // ntype = V_028C70_NUMBER_UINT;
462 // } else if (desc->channel[first_non_void].normalized) {
463 // ntype = V_028C70_NUMBER_UNORM;
471 static bool libresoc_is_sampler_format_supported(VkFormat format
, bool *linear_sampling
)
473 const struct vk_format_description
*desc
= vk_format_description(format
);
475 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
478 //TODO: stub, enables everything
483 static bool libresoc_is_storage_image_format_supported(struct libresoc_physical_device
*physical_device
,
486 const struct vk_format_description
*desc
= vk_format_description(format
);
487 unsigned data_format
, num_format
;
488 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
490 //TODO: stub, enables everything
494 bool libresoc_is_buffer_format_supported(VkFormat format
, bool *scaled
)
496 const struct vk_format_description
*desc
= vk_format_description(format
);
497 unsigned data_format
, num_format
;
498 if (!desc
|| format
== VK_FORMAT_UNDEFINED
)
501 //TODO: stub, enables everything
505 bool libresoc_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
)
507 //TODO: stub, enables everything
511 static bool libresoc_is_zs_format_supported(VkFormat format
)
513 //TODO: stub, enables everything
517 static bool libresoc_is_filter_minmax_format_supported(VkFormat format
)
519 /* From the Vulkan spec 1.1.71:
521 * "The following formats must support the
522 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT feature with
523 * VK_IMAGE_TILING_OPTIMAL, if they support
524 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT."
526 /* TODO: enable more formats. */
528 case VK_FORMAT_R8_UNORM
:
529 case VK_FORMAT_R8_SNORM
:
530 case VK_FORMAT_R16_UNORM
:
531 case VK_FORMAT_R16_SNORM
:
532 case VK_FORMAT_R16_SFLOAT
:
533 case VK_FORMAT_R32_SFLOAT
:
534 case VK_FORMAT_D16_UNORM
:
535 case VK_FORMAT_X8_D24_UNORM_PACK32
:
536 case VK_FORMAT_D32_SFLOAT
:
537 case VK_FORMAT_D16_UNORM_S8_UINT
:
538 case VK_FORMAT_D24_UNORM_S8_UINT
:
539 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
547 libresoc_device_supports_etc(struct libresoc_physical_device
*physical_device
)
549 //TODO: stub, enables everything
554 libresoc_physical_device_get_format_properties(struct libresoc_physical_device
*physical_device
,
556 VkFormatProperties
*out_properties
)
558 VkFormatFeatureFlags linear
= 0, tiled
= 0, buffer
= 0;
559 const struct vk_format_description
*desc
= vk_format_description(format
);
562 /* TODO: implement some software emulation of SUBSAMPLED formats. */
563 if (!desc
|| desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
564 out_properties
->linearTilingFeatures
= linear
;
565 out_properties
->optimalTilingFeatures
= tiled
;
566 out_properties
->bufferFeatures
= buffer
;
570 if (desc
->layout
== VK_FORMAT_LAYOUT_ETC
&&
571 !libresoc_device_supports_etc(physical_device
)) {
572 out_properties
->linearTilingFeatures
= linear
;
573 out_properties
->optimalTilingFeatures
= tiled
;
574 out_properties
->bufferFeatures
= buffer
;
578 if (desc
->layout
== VK_FORMAT_LAYOUT_MULTIPLANE
||
579 desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
580 uint32_t tiling
= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
581 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
|
582 VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
583 VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT
|
584 VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT
;
586 /* The subsampled formats have no support for linear filters. */
587 if (desc
->layout
!= VK_FORMAT_LAYOUT_SUBSAMPLED
) {
588 tiling
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT
;
591 /* Fails for unknown reasons with linear tiling & subsampled formats. */
592 out_properties
->linearTilingFeatures
= desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
? 0 : tiling
;
593 out_properties
->optimalTilingFeatures
= tiling
;
594 out_properties
->bufferFeatures
= 0;
598 if (libresoc_is_storage_image_format_supported(physical_device
, format
)) {
599 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
600 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
;
603 if (libresoc_is_buffer_format_supported(format
, &scaled
)) {
604 buffer
|= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
;
606 buffer
|= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
|
607 VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT
;
610 if (vk_format_is_depth_or_stencil(format
)) {
611 if (libresoc_is_zs_format_supported(format
)) {
612 tiled
|= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
;
613 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
;
614 tiled
|= VK_FORMAT_FEATURE_BLIT_SRC_BIT
|
615 VK_FORMAT_FEATURE_BLIT_DST_BIT
;
616 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
617 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
619 if (libresoc_is_filter_minmax_format_supported(format
))
620 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT
;
622 /* Don't support blitting surfaces with depth/stencil. */
623 if (vk_format_is_depth(format
) && vk_format_is_stencil(format
))
624 tiled
&= ~VK_FORMAT_FEATURE_BLIT_DST_BIT
;
626 /* Don't support linear depth surfaces */
630 bool linear_sampling
;
631 if (libresoc_is_sampler_format_supported(format
, &linear_sampling
)) {
632 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
633 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
634 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
635 VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
637 if (libresoc_is_filter_minmax_format_supported(format
))
638 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT
;
640 if (linear_sampling
) {
641 linear
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
642 tiled
|= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
;
645 /* Don't support blitting for R32G32B32 formats. */
646 if (format
== VK_FORMAT_R32G32B32_SFLOAT
||
647 format
== VK_FORMAT_R32G32B32_UINT
||
648 format
== VK_FORMAT_R32G32B32_SINT
) {
649 linear
&= ~VK_FORMAT_FEATURE_BLIT_SRC_BIT
;
652 if (libresoc_is_colorbuffer_format_supported(format
, &blendable
)) {
653 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
654 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
| VK_FORMAT_FEATURE_BLIT_DST_BIT
;
656 linear
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
657 tiled
|= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
;
660 if (tiled
&& !scaled
) {
661 tiled
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
662 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
665 /* Tiled formatting does not support NPOT pixel sizes */
666 if (!util_is_power_of_two_or_zero(vk_format_get_blocksize(format
)))
670 if (linear
&& !scaled
) {
671 linear
|= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
|
672 VK_FORMAT_FEATURE_TRANSFER_DST_BIT
;
675 if (format
== VK_FORMAT_R32_UINT
||
676 format
== VK_FORMAT_R32_SINT
||
677 format
== VK_FORMAT_R32_SFLOAT
) {
678 buffer
|= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT
;
679 linear
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
680 tiled
|= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
;
684 out_properties
->linearTilingFeatures
= linear
;
685 out_properties
->optimalTilingFeatures
= tiled
;
686 out_properties
->bufferFeatures
= buffer
;
689 //uint32_t libresoc_translate_colorformat(VkFormat format)
691 // const struct vk_format_description *desc = vk_format_description(format);
693 //#define HAS_SIZE(x,y,z,w) \
694 // (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
695 // desc->channel[2].size == (z) && desc->channel[3].size == (w))
697 // if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) /* isn't plain */
698 // return V_028C70_COLOR_10_11_11;
700 // if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
701 // return V_028C70_COLOR_INVALID;
703 // /* hw cannot support mixed formats (except depth/stencil, since
704 // * stencil is not written to). */
705 // if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
706 // return V_028C70_COLOR_INVALID;
708 // switch (desc->nr_channels) {
710 // switch (desc->channel[0].size) {
712 // return V_028C70_COLOR_8;
714 // return V_028C70_COLOR_16;
716 // return V_028C70_COLOR_32;
720 // if (desc->channel[0].size == desc->channel[1].size) {
721 // switch (desc->channel[0].size) {
723 // return V_028C70_COLOR_8_8;
725 // return V_028C70_COLOR_16_16;
727 // return V_028C70_COLOR_32_32;
729 // } else if (HAS_SIZE(8,24,0,0)) {
730 // return V_028C70_COLOR_24_8;
731 // } else if (HAS_SIZE(24,8,0,0)) {
732 // return V_028C70_COLOR_8_24;
736 // if (HAS_SIZE(5,6,5,0)) {
737 // return V_028C70_COLOR_5_6_5;
738 // } else if (HAS_SIZE(32,8,24,0)) {
739 // return V_028C70_COLOR_X24_8_32_FLOAT;
743 // if (desc->channel[0].size == desc->channel[1].size &&
744 // desc->channel[0].size == desc->channel[2].size &&
745 // desc->channel[0].size == desc->channel[3].size) {
746 // switch (desc->channel[0].size) {
748 // return V_028C70_COLOR_4_4_4_4;
750 // return V_028C70_COLOR_8_8_8_8;
752 // return V_028C70_COLOR_16_16_16_16;
754 // return V_028C70_COLOR_32_32_32_32;
756 // } else if (HAS_SIZE(5,5,5,1)) {
757 // return V_028C70_COLOR_1_5_5_5;
758 // } else if (HAS_SIZE(1,5,5,5)) {
759 // return V_028C70_COLOR_5_5_5_1;
760 // } else if (HAS_SIZE(10,10,10,2)) {
761 // return V_028C70_COLOR_2_10_10_10;
765 // return V_028C70_COLOR_INVALID;
768 //uint32_t libresoc_colorformat_endian_swap(uint32_t colorformat)
770 // if (0/*SI_BIG_ENDIAN*/) {
771 // switch(colorformat) {
772 // /* 8-bit buffers. */
773 // case V_028C70_COLOR_8:
774 // return V_028C70_ENDIAN_NONE;
776 // /* 16-bit buffers. */
777 // case V_028C70_COLOR_5_6_5:
778 // case V_028C70_COLOR_1_5_5_5:
779 // case V_028C70_COLOR_4_4_4_4:
780 // case V_028C70_COLOR_16:
781 // case V_028C70_COLOR_8_8:
782 // return V_028C70_ENDIAN_8IN16;
784 // /* 32-bit buffers. */
785 // case V_028C70_COLOR_8_8_8_8:
786 // case V_028C70_COLOR_2_10_10_10:
787 // case V_028C70_COLOR_8_24:
788 // case V_028C70_COLOR_24_8:
789 // case V_028C70_COLOR_16_16:
790 // return V_028C70_ENDIAN_8IN32;
792 // /* 64-bit buffers. */
793 // case V_028C70_COLOR_16_16_16_16:
794 // return V_028C70_ENDIAN_8IN16;
796 // case V_028C70_COLOR_32_32:
797 // return V_028C70_ENDIAN_8IN32;
799 // /* 128-bit buffers. */
800 // case V_028C70_COLOR_32_32_32_32:
801 // return V_028C70_ENDIAN_8IN32;
803 // return V_028C70_ENDIAN_NONE; /* Unsupported. */
806 // return V_028C70_ENDIAN_NONE;
810 //uint32_t libresoc_translate_dbformat(VkFormat format)
813 // case VK_FORMAT_D16_UNORM:
814 // case VK_FORMAT_D16_UNORM_S8_UINT:
815 // return V_028040_Z_16;
816 // case VK_FORMAT_D32_SFLOAT:
817 // case VK_FORMAT_D32_SFLOAT_S8_UINT:
818 // return V_028040_Z_32_FLOAT;
820 // return V_028040_Z_INVALID;
824 //unsigned libresoc_translate_colorswap(VkFormat format, bool do_endian_swap)
826 // const struct vk_format_description *desc = vk_format_description(format);
828 //#define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == VK_SWIZZLE_##swz)
830 // if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
831 // return V_028C70_SWAP_STD;
833 // if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
836 // switch (desc->nr_channels) {
838 // if (HAS_SWIZZLE(0,X))
839 // return V_028C70_SWAP_STD; /* X___ */
840 // else if (HAS_SWIZZLE(3,X))
841 // return V_028C70_SWAP_ALT_REV; /* ___X */
844 // if ((HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,Y)) ||
845 // (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,NONE)) ||
846 // (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y)))
847 // return V_028C70_SWAP_STD; /* XY__ */
848 // else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) ||
849 // (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,NONE)) ||
850 // (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X)))
852 // return (do_endian_swap ? V_028C70_SWAP_STD : V_028C70_SWAP_STD_REV);
853 // else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y))
854 // return V_028C70_SWAP_ALT; /* X__Y */
855 // else if (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(3,X))
856 // return V_028C70_SWAP_ALT_REV; /* Y__X */
859 // if (HAS_SWIZZLE(0,X))
860 // return (do_endian_swap ? V_028C70_SWAP_STD_REV : V_028C70_SWAP_STD);
861 // else if (HAS_SWIZZLE(0,Z))
862 // return V_028C70_SWAP_STD_REV; /* ZYX */
865 // /* check the middle channels, the 1st and 4th channel can be NONE */
866 // if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,Z)) {
867 // return V_028C70_SWAP_STD; /* XYZW */
868 // } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,Y)) {
869 // return V_028C70_SWAP_STD_REV; /* WZYX */
870 // } else if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,X)) {
871 // return V_028C70_SWAP_ALT; /* ZYXW */
872 // } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,W)) {
874 // if (desc->is_array)
875 // return V_028C70_SWAP_ALT_REV;
877 // return (do_endian_swap ? V_028C70_SWAP_ALT : V_028C70_SWAP_ALT_REV);
884 //bool libresoc_format_pack_clear_color(VkFormat format,
885 // uint32_t clear_vals[2],
886 // VkClearColorValue *value)
888 // const struct vk_format_description *desc = vk_format_description(format);
890 // if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
891 // clear_vals[0] = float3_to_r11g11b10f(value->float32);
892 // clear_vals[1] = 0;
896 // if (desc->layout != VK_FORMAT_LAYOUT_PLAIN) {
897 // fprintf(stderr, "failed to fast clear for non-plain format %d\n", format);
901 // if (!util_is_power_of_two_or_zero(desc->block.bits)) {
902 // fprintf(stderr, "failed to fast clear for NPOT format %d\n", format);
906 // if (desc->block.bits > 64) {
908 // * We have a 128 bits format, check if the first 3 components are the same.
909 // * Every elements has to be 32 bits since we don't support 64-bit formats,
910 // * and we can skip swizzling checks as alpha always comes last for these and
911 // * we do not care about the rest as they have to be the same.
913 // if (desc->channel[0].type == VK_FORMAT_TYPE_FLOAT) {
914 // if (value->float32[0] != value->float32[1] ||
915 // value->float32[0] != value->float32[2])
918 // if (value->uint32[0] != value->uint32[1] ||
919 // value->uint32[0] != value->uint32[2])
922 // clear_vals[0] = value->uint32[0];
923 // clear_vals[1] = value->uint32[3];
926 // uint64_t clear_val = 0;
928 // for (unsigned c = 0; c < 4; ++c) {
929 // if (desc->swizzle[c] >= 4)
932 // const struct vk_format_channel_description *channel = &desc->channel[desc->swizzle[c]];
933 // assert(channel->size);
936 // if (channel->pure_integer) {
937 // v = value->uint32[c] & ((1ULL << channel->size) - 1);
938 // } else if (channel->normalized) {
939 // if (channel->type == VK_FORMAT_TYPE_UNSIGNED &&
940 // desc->swizzle[c] < 3 &&
941 // desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
942 // assert(channel->size == 8);
944 // v = util_format_linear_float_to_srgb_8unorm(value->float32[c]);
946 // float f = MIN2(value->float32[c], 1.0f);
948 // if (channel->type == VK_FORMAT_TYPE_UNSIGNED) {
949 // f = MAX2(f, 0.0f) * ((1ULL << channel->size) - 1);
951 // f = MAX2(f, -1.0f) * ((1ULL << (channel->size - 1)) - 1);
954 // /* The hardware rounds before conversion. */
962 // } else if (channel->type == VK_FORMAT_TYPE_FLOAT) {
963 // if (channel->size == 32) {
964 // memcpy(&v, &value->float32[c], 4);
965 // } else if(channel->size == 16) {
966 // v = util_float_to_half_rtz(value->float32[c]);
968 // fprintf(stderr, "failed to fast clear for unhandled float size in format %d\n", format);
972 // fprintf(stderr, "failed to fast clear for unhandled component type in format %d\n", format);
975 // clear_val |= (v & ((1ULL << channel->size) - 1)) << channel->shift;
978 // clear_vals[0] = clear_val;
979 // clear_vals[1] = clear_val >> 32;
984 void libresoc_GetPhysicalDeviceFormatProperties(
985 VkPhysicalDevice physicalDevice
,
987 VkFormatProperties
* pFormatProperties
)
989 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, physical_device
, physicalDevice
);
991 libresoc_physical_device_get_format_properties(physical_device
,
996 //void libresoc_GetPhysicalDeviceFormatProperties2(
997 // VkPhysicalDevice physicalDevice,
999 // VkFormatProperties2* pFormatProperties)
1001 // LIBRESOC_FROM_HANDLE(libresoc_physical_device, physical_device, physicalDevice);
1003 // libresoc_physical_device_get_format_properties(physical_device,
1005 // &pFormatProperties->formatProperties);
1008 static VkResult
libresoc_get_image_format_properties(struct libresoc_physical_device
*physical_device
,
1009 const VkPhysicalDeviceImageFormatInfo2
*info
,
1011 VkImageFormatProperties
*pImageFormatProperties
)
1014 VkFormatProperties format_props
;
1015 VkFormatFeatureFlags format_feature_flags
;
1016 VkExtent3D maxExtent
;
1017 uint32_t maxMipLevels
;
1018 uint32_t maxArraySize
;
1019 VkSampleCountFlags sampleCounts
= VK_SAMPLE_COUNT_1_BIT
;
1020 const struct vk_format_description
*desc
= vk_format_description(format
);
1022 libresoc_physical_device_get_format_properties(physical_device
, format
,
1024 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
) {
1025 format_feature_flags
= format_props
.linearTilingFeatures
;
1026 } else if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
) {
1027 format_feature_flags
= format_props
.optimalTilingFeatures
;
1029 unreachable("bad VkImageTiling");
1032 if (format_feature_flags
== 0)
1035 if (info
->type
!= VK_IMAGE_TYPE_2D
&& vk_format_is_depth_or_stencil(format
))
1038 switch (info
->type
) {
1040 unreachable("bad vkimage type\n");
1041 case VK_IMAGE_TYPE_1D
:
1042 maxExtent
.width
= 16384;
1043 maxExtent
.height
= 1;
1044 maxExtent
.depth
= 1;
1045 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1046 maxArraySize
= 2048;
1048 case VK_IMAGE_TYPE_2D
:
1049 maxExtent
.width
= 16384;
1050 maxExtent
.height
= 16384;
1051 maxExtent
.depth
= 1;
1052 maxMipLevels
= 15; /* log2(maxWidth) + 1 */
1053 maxArraySize
= 2048;
1055 case VK_IMAGE_TYPE_3D
:
1056 maxExtent
.width
= 2048;
1057 maxExtent
.height
= 2048;
1058 maxExtent
.depth
= 2048;
1059 maxMipLevels
= util_logbase2(maxExtent
.width
) + 1;
1064 if (desc
->layout
== VK_FORMAT_LAYOUT_SUBSAMPLED
) {
1065 /* Might be able to support but the entire format support is
1066 * messy, so taking the lazy way out. */
1070 if (info
->tiling
== VK_IMAGE_TILING_OPTIMAL
&&
1071 info
->type
== VK_IMAGE_TYPE_2D
&&
1072 (format_feature_flags
& (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
|
1073 VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)) &&
1074 !(info
->flags
& VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
)) {
1075 sampleCounts
|= VK_SAMPLE_COUNT_2_BIT
| VK_SAMPLE_COUNT_4_BIT
| VK_SAMPLE_COUNT_8_BIT
;
1078 if (info
->tiling
== VK_IMAGE_TILING_LINEAR
&&
1079 (format
== VK_FORMAT_R32G32B32_SFLOAT
||
1080 format
== VK_FORMAT_R32G32B32_SINT
||
1081 format
== VK_FORMAT_R32G32B32_UINT
)) {
1082 /* R32G32B32 is a weird format and the driver currently only
1083 * supports the barely minimum.
1084 * TODO: Implement more if we really need to.
1092 *pImageFormatProperties
= (VkImageFormatProperties
) {
1093 .maxExtent
= maxExtent
,
1094 .maxMipLevels
= maxMipLevels
,
1095 .maxArrayLayers
= maxArraySize
,
1096 .sampleCounts
= sampleCounts
,
1098 /* FINISHME: Accurately calculate
1099 * VkImageFormatProperties::maxResourceSize.
1101 .maxResourceSize
= UINT32_MAX
,
1105 //TODO: for now we support everything
1107 *pImageFormatProperties
= (VkImageFormatProperties
) {
1108 .maxExtent
= { 0, 0, 0 },
1110 .maxArrayLayers
= 0,
1112 .maxResourceSize
= 0,
1115 return VK_ERROR_FORMAT_NOT_SUPPORTED
;
1118 VkResult
libresoc_GetPhysicalDeviceImageFormatProperties(
1119 VkPhysicalDevice physicalDevice
,
1122 VkImageTiling tiling
,
1123 VkImageUsageFlags usage
,
1124 VkImageCreateFlags createFlags
,
1125 VkImageFormatProperties
* pImageFormatProperties
)
1127 LIBRESOC_FROM_HANDLE(libresoc_physical_device
, physical_device
, physicalDevice
);
1129 const VkPhysicalDeviceImageFormatInfo2 info
= {
1130 .sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2
,
1136 .flags
= createFlags
,
1139 return libresoc_get_image_format_properties(physical_device
, &info
, format
,
1140 pImageFormatProperties
);
1144 get_external_image_format_properties(struct libresoc_physical_device
*physical_device
,
1145 const VkPhysicalDeviceImageFormatInfo2
*pImageFormatInfo
,
1146 VkExternalMemoryHandleTypeFlagBits handleType
,
1147 VkExternalMemoryProperties
*external_properties
,
1148 VkImageFormatProperties
*format_properties
)
1150 VkExternalMemoryFeatureFlagBits flags
= 0;
1151 VkExternalMemoryHandleTypeFlags export_flags
= 0;
1152 VkExternalMemoryHandleTypeFlags compat_flags
= 0;
1154 if (pImageFormatInfo
->flags
& VK_IMAGE_CREATE_SPARSE_BINDING_BIT
)
1157 switch (handleType
) {
1158 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
:
1159 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
1160 switch (pImageFormatInfo
->type
) {
1161 case VK_IMAGE_TYPE_2D
:
1162 flags
= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT
|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1163 if (pImageFormatInfo
->tiling
!= VK_IMAGE_TILING_LINEAR
)
1164 flags
|= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT
;
1166 compat_flags
= export_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT
|
1167 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
;
1173 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
:
1174 flags
= VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT
;
1175 compat_flags
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
;
1181 *external_properties
= (VkExternalMemoryProperties
) {
1182 .externalMemoryFeatures
= flags
,
1183 .exportFromImportedHandleTypes
= export_flags
,
1184 .compatibleHandleTypes
= compat_flags
,
1188 //VkResult libresoc_GetPhysicalDeviceImageFormatProperties2(
1189 // VkPhysicalDevice physicalDevice,
1190 // const VkPhysicalDeviceImageFormatInfo2 *base_info,
1191 // VkImageFormatProperties2 *base_props)
1193 // LIBRESOC_FROM_HANDLE(libresoc_physical_device, physical_device, physicalDevice);
1194 // const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
1195 // VkExternalImageFormatProperties *external_props = NULL;
1196 // struct VkAndroidHardwareBufferUsageANDROID *android_usage = NULL;
1197 // VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
1198 // VkTextureLODGatherFormatPropertiesAMD *texture_lod_props = NULL;
1200 // VkFormat format = libresoc_select_android_external_format(base_info->pNext, base_info->format);
1202 // result = libresoc_get_image_format_properties(physical_device, base_info, format,
1203 // &base_props->imageFormatProperties);
1204 // if (result != VK_SUCCESS)
1207 // /* Extract input structs */
1208 // vk_foreach_struct_const(s, base_info->pNext) {
1209 // switch (s->sType) {
1210 // case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
1211 // external_info = (const void *) s;
1218 // /* Extract output structs */
1219 // vk_foreach_struct(s, base_props->pNext) {
1220 // switch (s->sType) {
1221 // case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES:
1222 // external_props = (void *) s;
1224 // case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
1225 // ycbcr_props = (void *) s;
1227 // case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID:
1228 // android_usage = (void *) s;
1230 // case VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD:
1231 // texture_lod_props = (void *) s;
1238 // bool ahb_supported = physical_device->supported_extensions.ANDROID_external_memory_android_hardware_buffer;
1239 // if (android_usage && ahb_supported) {
1240 //#if LIBRESOC_SUPPORT_ANDROID_HARDWARE_BUFFER
1241 // android_usage->androidHardwareBufferUsage =
1242 // libresoc_ahb_usage_from_vk_usage(base_info->flags,
1243 // base_info->usage);
1247 // /* From the Vulkan 1.0.97 spec:
1249 // * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
1250 // * behave as if VkPhysicalDeviceExternalImageFormatInfo was not
1251 // * present and VkExternalImageFormatProperties will be ignored.
1253 // if (external_info && external_info->handleType != 0) {
1254 // get_external_image_format_properties(physical_device, base_info, external_info->handleType,
1255 // &external_props->externalMemoryProperties,
1256 // &base_props->imageFormatProperties);
1257 // if (!external_props->externalMemoryProperties.externalMemoryFeatures) {
1258 // /* From the Vulkan 1.0.97 spec:
1260 // * If handleType is not compatible with the [parameters] specified
1261 // * in VkPhysicalDeviceImageFormatInfo2, then
1262 // * vkGetPhysicalDeviceImageFormatProperties2 returns
1263 // * VK_ERROR_FORMAT_NOT_SUPPORTED.
1265 // result = vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
1266 // "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
1267 // external_info->handleType);
1272 // if (ycbcr_props) {
1273 // ycbcr_props->combinedImageSamplerDescriptorCount = vk_format_get_plane_count(format);
1276 // if (texture_lod_props) {
1277 // if (physical_device->rad_info.chip_class >= GFX9) {
1278 // texture_lod_props->supportsTextureGatherLODBiasAMD = true;
1280 // texture_lod_props->supportsTextureGatherLODBiasAMD = !vk_format_is_int(format);
1284 // return VK_SUCCESS;
1287 // if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
1288 // /* From the Vulkan 1.0.97 spec:
1290 // * If the combination of parameters to
1291 // * vkGetPhysicalDeviceImageFormatProperties2 is not supported by
1292 // * the implementation for use in vkCreateImage, then all members of
1293 // * imageFormatProperties will be filled with zero.
1295 // base_props->imageFormatProperties = (VkImageFormatProperties) {0};
1301 void libresoc_GetPhysicalDeviceSparseImageFormatProperties(
1302 VkPhysicalDevice physicalDevice
,
1306 VkImageUsageFlags usage
,
1307 VkImageTiling tiling
,
1308 uint32_t* pNumProperties
,
1309 VkSparseImageFormatProperties
* pProperties
)
1311 /* Sparse images are not yet supported. */
1312 *pNumProperties
= 0;
1315 //void libresoc_GetPhysicalDeviceSparseImageFormatProperties2(
1316 // VkPhysicalDevice physicalDevice,
1317 // const VkPhysicalDeviceSparseImageFormatInfo2 *pFormatInfo,
1318 // uint32_t *pPropertyCount,
1319 // VkSparseImageFormatProperties2 *pProperties)
1321 // /* Sparse images are not yet supported. */
1322 // *pPropertyCount = 0;
1326 //void libresoc_GetPhysicalDeviceExternalBufferProperties(
1327 // VkPhysicalDevice physicalDevice,
1328 // const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
1329 // VkExternalBufferProperties *pExternalBufferProperties)
1331 // VkExternalMemoryFeatureFlagBits flags = 0;
1332 // VkExternalMemoryHandleTypeFlags export_flags = 0;
1333 // VkExternalMemoryHandleTypeFlags compat_flags = 0;
1334 // switch(pExternalBufferInfo->handleType) {
1335 // case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT:
1336 // case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
1337 // flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
1338 // VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1339 // compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT |
1340 // VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
1342 // case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
1343 // flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
1344 // compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
1349 // pExternalBufferProperties->externalMemoryProperties = (VkExternalMemoryProperties) {
1350 // .externalMemoryFeatures = flags,
1351 // .exportFromImportedHandleTypes = export_flags,
1352 // .compatibleHandleTypes = compat_flags,