radv: Start using util_format_description for everything.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 30 Jan 2021 21:14:12 +0000 (22:14 +0100)
committerMarge Bot <eric+marge@anholt.net>
Sat, 13 Feb 2021 21:47:17 +0000 (21:47 +0000)
Steps:

git reset --hard
sed -i 's/struct vk_format_description \*/struct util_format_description \*/g' *.{c,h}
sed -i 's/VK_FORMAT_COLORSPACE/UTIL_FORMAT_COLORSPACE/g' *.c
sed -i 's/= VK_FORMAT_COLORSPACE/= UTIL_FORMAT_COLORSPACE/g' *.h
sed -i 's/enum vk_format_colorspace /enum util_format_colorspace /g' *.h
sed -i 's/VK_FORMAT_TYPE/UTIL_FORMAT_TYPE/g' *.c
sed -i 's/VK_FORMAT_LAYOUT/UTIL_FORMAT_LAYOUT/g' *.c
sed -i 's/vk_format_channel_description/util_format_channel_description/g' *.c
sed -i 's/vk_format_description(/vk_format_description_legacy(/g' *.py
sed -i 's/const struct vk_format_description \*/static const struct vk_format_description \*/g' *.py

Then manually:

1) Rename the vk_format_colorspace definition back (only want the uses renamed)
2) Fix the desc->format == VK_FORMAT_... warnings
3) Add vk_format_description implementation (and remove warning pragmas)

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8797>

src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_formats.c
src/amd/vulkan/radv_image.c
src/amd/vulkan/radv_meta_clear.c
src/amd/vulkan/radv_meta_copy.c
src/amd/vulkan/radv_nir_lower_ycbcr_textures.c
src/amd/vulkan/radv_pass.c
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_private.h
src/amd/vulkan/vk_format.h
src/amd/vulkan/vk_format_table.py

index 855a2bd..5e07a5c 100644 (file)
@@ -6848,7 +6848,7 @@ radv_initialise_color_surface(struct radv_device *device,
                              struct radv_color_buffer_info *cb,
                              struct radv_image_view *iview)
 {
-       const struct vk_format_description *desc;
+       const struct util_format_description *desc;
        unsigned ntype, format, swap, endian;
        unsigned blend_clamp = 0, blend_bypass = 0;
        uint64_t va;
index 26506cd..f1c4a36 100644 (file)
@@ -37,7 +37,7 @@
 #include "util/format_rgb9e5.h"
 #include "vulkan/util/vk_format.h"
 
-uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
+uint32_t radv_translate_buffer_dataformat(const struct util_format_description *desc,
                                          int first_non_void)
 {
        unsigned type;
@@ -45,14 +45,14 @@ uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *de
 
        assert(util_format_get_num_planes(desc->format) == 1);
 
-       if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
+       if (desc->format == PIPE_FORMAT_R11G11B10_FLOAT)
                return V_008F0C_BUF_DATA_FORMAT_10_11_11;
 
        if (first_non_void < 0)
                return V_008F0C_BUF_DATA_FORMAT_INVALID;
        type = desc->channel[first_non_void].type;
 
-       if (type == VK_FORMAT_TYPE_FIXED)
+       if (type == UTIL_FORMAT_TYPE_FIXED)
                return V_008F0C_BUF_DATA_FORMAT_INVALID;
        if (desc->nr_channels == 4 &&
            desc->channel[0].size == 10 &&
@@ -93,7 +93,7 @@ uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *de
                 * 'Memory reads of data in memory that is 32 or 64 bits do not
                 * undergo any format conversion.'
                 */
-               if (type != VK_FORMAT_TYPE_FLOAT &&
+               if (type != UTIL_FORMAT_TYPE_FLOAT &&
                    !desc->channel[first_non_void].pure_integer)
                        return V_008F0C_BUF_DATA_FORMAT_INVALID;
 
@@ -116,19 +116,19 @@ uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *de
        return V_008F0C_BUF_DATA_FORMAT_INVALID;
 }
 
-uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
+uint32_t radv_translate_buffer_numformat(const struct util_format_description *desc,
                                         int first_non_void)
 {
        assert(util_format_get_num_planes(desc->format) == 1);
 
-       if (desc->format == VK_FORMAT_B10G11R11_UFLOAT_PACK32)
+       if (desc->format == PIPE_FORMAT_R11G11B10_FLOAT)
                return V_008F0C_BUF_NUM_FORMAT_FLOAT;
 
        if (first_non_void < 0)
                return ~0;
 
        switch (desc->channel[first_non_void].type) {
-       case VK_FORMAT_TYPE_SIGNED:
+       case UTIL_FORMAT_TYPE_SIGNED:
                if (desc->channel[first_non_void].normalized)
                        return V_008F0C_BUF_NUM_FORMAT_SNORM;
                else if (desc->channel[first_non_void].pure_integer)
@@ -136,7 +136,7 @@ uint32_t radv_translate_buffer_numformat(const struct vk_format_description *des
                else
                        return V_008F0C_BUF_NUM_FORMAT_SSCALED;
                break;
-       case VK_FORMAT_TYPE_UNSIGNED:
+       case UTIL_FORMAT_TYPE_UNSIGNED:
                if (desc->channel[first_non_void].normalized)
                        return V_008F0C_BUF_NUM_FORMAT_UNORM;
                else if (desc->channel[first_non_void].pure_integer)
@@ -144,14 +144,14 @@ uint32_t radv_translate_buffer_numformat(const struct vk_format_description *des
                else
                        return V_008F0C_BUF_NUM_FORMAT_USCALED;
                break;
-       case VK_FORMAT_TYPE_FLOAT:
+       case UTIL_FORMAT_TYPE_FLOAT:
        default:
                return V_008F0C_BUF_NUM_FORMAT_FLOAT;
        }
 }
 
 uint32_t radv_translate_tex_dataformat(VkFormat format,
-                                      const struct vk_format_description *desc,
+                                      const struct util_format_description *desc,
                                       int first_non_void)
 {
        bool uniform = true;
@@ -164,7 +164,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
        /* Colorspace (return non-RGB formats directly). */
        switch (desc->colorspace) {
                /* Depth stencil formats */
-       case VK_FORMAT_COLORSPACE_ZS:
+       case UTIL_FORMAT_COLORSPACE_ZS:
                switch (format) {
                case VK_FORMAT_D16_UNORM:
                        return V_008F14_IMG_DATA_FORMAT_16;
@@ -181,10 +181,10 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                        goto out_unknown;
                }
 
-       case VK_FORMAT_COLORSPACE_YUV:
+       case UTIL_FORMAT_COLORSPACE_YUV:
                goto out_unknown; /* TODO */
 
-       case VK_FORMAT_COLORSPACE_SRGB:
+       case UTIL_FORMAT_COLORSPACE_SRGB:
                if (desc->nr_channels != 4 && desc->nr_channels != 1)
                        goto out_unknown;
                break;
@@ -193,7 +193,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                break;
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                switch(format) {
                /* Don't ask me why this looks inverted. PAL does the same. */
                case VK_FORMAT_G8B8G8R8_422_UNORM:
@@ -205,7 +205,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                }
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_RGTC) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
                switch(format) {
                case VK_FORMAT_BC4_UNORM_BLOCK:
                case VK_FORMAT_BC4_SNORM_BLOCK:
@@ -218,7 +218,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                }
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_S3TC) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
                switch(format) {
                case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
                case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
@@ -236,7 +236,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                }
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_BPTC) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_BPTC) {
                switch(format) {
                case VK_FORMAT_BC6H_UFLOAT_BLOCK:
                case VK_FORMAT_BC6H_SFLOAT_BLOCK:
@@ -249,7 +249,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                }
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_ETC) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_ETC) {
                switch (format) {
                case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
                case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
@@ -281,7 +281,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
 
        /* hw cannot support mixed formats (except depth/stencil, since only
         * depth is read).*/
-       if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
+       if (desc->is_mixed && desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
                goto out_unknown;
 
        /* See whether the components are of the same size. */
@@ -317,7 +317,7 @@ uint32_t radv_translate_tex_dataformat(VkFormat format,
                            desc->channel[2].size == 10 &&
                            desc->channel[3].size == 2) {
                                /* Closed VK driver does this also no 2/10/10/10 snorm */
-                               if (desc->channel[0].type == VK_FORMAT_TYPE_SIGNED &&
+                               if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED &&
                                    desc->channel[0].normalized)
                                        goto out_unknown;
                                return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
@@ -386,7 +386,7 @@ out_unknown:
 }
 
 uint32_t radv_translate_tex_numformat(VkFormat format,
-                                     const struct vk_format_description *desc,
+                                     const struct util_format_description *desc,
                                      int first_non_void)
 {
        assert(vk_format_get_plane_count(format) == 1);
@@ -416,25 +416,25 @@ uint32_t radv_translate_tex_numformat(VkFormat format,
                                default:
                                        return V_008F14_IMG_NUM_FORMAT_UNORM;
                                }
-                       } else if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
+                       } else if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                                return V_008F14_IMG_NUM_FORMAT_UNORM;
                        } else {
                                return V_008F14_IMG_NUM_FORMAT_FLOAT;
                        }
-               } else if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
+               } else if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
                        return V_008F14_IMG_NUM_FORMAT_SRGB;
                } else {
                        switch (desc->channel[first_non_void].type) {
-                       case VK_FORMAT_TYPE_FLOAT:
+                       case UTIL_FORMAT_TYPE_FLOAT:
                                return V_008F14_IMG_NUM_FORMAT_FLOAT;
-                       case VK_FORMAT_TYPE_SIGNED:
+                       case UTIL_FORMAT_TYPE_SIGNED:
                                if (desc->channel[first_non_void].normalized)
                                        return V_008F14_IMG_NUM_FORMAT_SNORM;
                                else if (desc->channel[first_non_void].pure_integer)
                                        return V_008F14_IMG_NUM_FORMAT_SINT;
                                else
                                        return V_008F14_IMG_NUM_FORMAT_SSCALED;
-                       case VK_FORMAT_TYPE_UNSIGNED:
+                       case UTIL_FORMAT_TYPE_UNSIGNED:
                                if (desc->channel[first_non_void].normalized)
                                        return V_008F14_IMG_NUM_FORMAT_UNORM;
                                else if (desc->channel[first_non_void].pure_integer)
@@ -449,27 +449,27 @@ uint32_t radv_translate_tex_numformat(VkFormat format,
 }
 
 uint32_t radv_translate_color_numformat(VkFormat format,
-                                       const struct vk_format_description *desc,
+                                       const struct util_format_description *desc,
                                        int first_non_void)
 {
        unsigned ntype;
 
        assert(vk_format_get_plane_count(format) == 1);
 
-       if (first_non_void == -1 || desc->channel[first_non_void].type == VK_FORMAT_TYPE_FLOAT)
+       if (first_non_void == -1 || desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_FLOAT)
                ntype = V_028C70_NUMBER_FLOAT;
        else {
                ntype = V_028C70_NUMBER_UNORM;
-               if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB)
+               if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
                        ntype = V_028C70_NUMBER_SRGB;
-               else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_SIGNED) {
+               else if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_SIGNED) {
                        if (desc->channel[first_non_void].pure_integer) {
                                ntype = V_028C70_NUMBER_SINT;
                        } else if (desc->channel[first_non_void].normalized) {
                                ntype = V_028C70_NUMBER_SNORM;
                        } else
                                ntype = ~0u;
-               } else if (desc->channel[first_non_void].type == VK_FORMAT_TYPE_UNSIGNED) {
+               } else if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_UNSIGNED) {
                        if (desc->channel[first_non_void].pure_integer) {
                                ntype = V_028C70_NUMBER_UINT;
                        } else if (desc->channel[first_non_void].normalized) {
@@ -483,7 +483,7 @@ uint32_t radv_translate_color_numformat(VkFormat format,
 
 static bool radv_is_sampler_format_supported(VkFormat format, bool *linear_sampling)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        uint32_t num_format;
        if (!desc || format == VK_FORMAT_UNDEFINED ||
            format == VK_FORMAT_R64_UINT || format == VK_FORMAT_R64_SINT)
@@ -510,7 +510,7 @@ static bool radv_is_sampler_format_supported(VkFormat format, bool *linear_sampl
 static bool radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,
                                                   VkFormat format)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        unsigned data_format, num_format;
        if (!desc || format == VK_FORMAT_UNDEFINED)
                return false;
@@ -562,7 +562,7 @@ static bool radv_is_storage_image_format_supported(struct radv_physical_device *
 
 bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        unsigned data_format, num_format;
        if (!desc || format == VK_FORMAT_UNDEFINED)
                return false;
@@ -581,7 +581,7 @@ bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
 bool radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdevice,
                                           VkFormat format, bool *blendable)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        uint32_t color_format = radv_translate_colorformat(format);
        uint32_t color_swap = radv_translate_colorswap(format, false);
        uint32_t color_num_format = radv_translate_color_numformat(format,
@@ -652,19 +652,19 @@ radv_physical_device_get_format_properties(struct radv_physical_device *physical
                                           VkFormatProperties *out_properties)
 {
        VkFormatFeatureFlags linear = 0, tiled = 0, buffer = 0;
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        bool blendable;
        bool scaled = false;
        /* TODO: implement some software emulation of SUBSAMPLED formats. */
        if (!desc || vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE ||
-           desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
+           desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                out_properties->linearTilingFeatures = linear;
                out_properties->optimalTilingFeatures = tiled;
                out_properties->bufferFeatures = buffer;
                return;
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_ETC &&
+       if (desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
            !radv_device_supports_etc(physical_device)) {
                out_properties->linearTilingFeatures = linear;
                out_properties->optimalTilingFeatures = tiled;
@@ -673,7 +673,7 @@ radv_physical_device_get_format_properties(struct radv_physical_device *physical
        }
 
        if (vk_format_get_plane_count(format) > 1 ||
-           desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
+           desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                uint32_t tiling = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
                                  VK_FORMAT_FEATURE_TRANSFER_DST_BIT |
                                  VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
@@ -681,12 +681,12 @@ radv_physical_device_get_format_properties(struct radv_physical_device *physical
                                  VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
 
                /* The subsampled formats have no support for linear filters. */
-               if (desc->layout != VK_FORMAT_LAYOUT_SUBSAMPLED) {
+               if (desc->layout != UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                        tiling |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
                }
 
                /* Fails for unknown reasons with linear tiling & subsampled formats. */
-               out_properties->linearTilingFeatures = desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED ? 0 : tiling;
+               out_properties->linearTilingFeatures = desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED ? 0 : tiling;
                out_properties->optimalTilingFeatures = tiling;
                out_properties->bufferFeatures = 0;
                return;
@@ -808,7 +808,7 @@ radv_physical_device_get_format_properties(struct radv_physical_device *physical
 
 uint32_t radv_translate_colorformat(VkFormat format)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
 
 #define HAS_SIZE(x,y,z,w)                                              \
        (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
@@ -820,12 +820,12 @@ uint32_t radv_translate_colorformat(VkFormat format)
        if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)
                return V_028C70_COLOR_5_9_9_9;
 
-       if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
+       if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
                return V_028C70_COLOR_INVALID;
 
        /* hw cannot support mixed formats (except depth/stencil, since
         * stencil is not written to). */
-       if (desc->is_mixed && desc->colorspace != VK_FORMAT_COLORSPACE_ZS)
+       if (desc->is_mixed && desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
                return V_028C70_COLOR_INVALID;
 
        switch (desc->nr_channels) {
@@ -946,7 +946,7 @@ uint32_t radv_translate_dbformat(VkFormat format)
 
 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
 
 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == PIPE_SWIZZLE_##swz)
 
@@ -956,7 +956,7 @@ unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap)
        if (format == VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)
                return V_028C70_SWAP_STD;
 
-       if (desc->layout != VK_FORMAT_LAYOUT_PLAIN)
+       if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
                return ~0U;
 
        switch (desc->nr_channels) {
@@ -1011,7 +1011,7 @@ bool radv_format_pack_clear_color(VkFormat format,
                                  uint32_t clear_vals[2],
                                  VkClearColorValue *value)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
 
        if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
                clear_vals[0] = float3_to_r11g11b10f(value->float32);
@@ -1023,7 +1023,7 @@ bool radv_format_pack_clear_color(VkFormat format,
                return true;
        }
 
-       if (desc->layout != VK_FORMAT_LAYOUT_PLAIN) {
+       if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
                fprintf(stderr, "failed to fast clear for non-plain format %d\n", format);
                return false;
        }
@@ -1040,7 +1040,7 @@ bool radv_format_pack_clear_color(VkFormat format,
                 * and we can skip swizzling checks as alpha always comes last for these and
                 * we do not care about the rest as they have to be the same.
                 */
-               if (desc->channel[0].type == VK_FORMAT_TYPE_FLOAT) {
+               if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) {
                        if (value->float32[0] != value->float32[1] ||
                            value->float32[0] != value->float32[2])
                                return false;
@@ -1059,23 +1059,23 @@ bool radv_format_pack_clear_color(VkFormat format,
                if (desc->swizzle[c] >= 4)
                        continue;
 
-               const struct vk_format_channel_description *channel = &desc->channel[desc->swizzle[c]];
+               const struct util_format_channel_description *channel = &desc->channel[desc->swizzle[c]];
                assert(channel->size);
 
                uint64_t v = 0;
                if (channel->pure_integer) {
                        v = value->uint32[c]  & ((1ULL << channel->size) - 1);
                } else if (channel->normalized) {
-                       if (channel->type == VK_FORMAT_TYPE_UNSIGNED &&
+                       if (channel->type == UTIL_FORMAT_TYPE_UNSIGNED &&
                            desc->swizzle[c] < 3 &&
-                           desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
+                           desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
                                assert(channel->size == 8);
 
                                v = util_format_linear_float_to_srgb_8unorm(value->float32[c]);
                        } else {
                                float f = MIN2(value->float32[c], 1.0f);
 
-                               if (channel->type == VK_FORMAT_TYPE_UNSIGNED) {
+                               if (channel->type == UTIL_FORMAT_TYPE_UNSIGNED) {
                                        f = MAX2(f, 0.0f) * ((1ULL << channel->size) - 1);
                                } else {
                                        f = MAX2(f, -1.0f) * ((1ULL << (channel->size - 1)) - 1);
@@ -1089,7 +1089,7 @@ bool radv_format_pack_clear_color(VkFormat format,
 
                                v = (uint64_t)f;
                        }
-               } else if (channel->type == VK_FORMAT_TYPE_FLOAT) {
+               } else if (channel->type == UTIL_FORMAT_TYPE_FLOAT) {
                        if (channel->size == 32) {
                                memcpy(&v, &value->float32[c], 4);
                        } else if(channel->size == 16) {
@@ -1310,7 +1310,7 @@ static VkResult radv_get_image_format_properties(struct radv_physical_device *ph
        uint32_t maxMipLevels;
        uint32_t maxArraySize;
        VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        enum chip_class chip_class = physical_device->rad_info.chip_class;
        VkImageTiling tiling = info->tiling;
        const VkPhysicalDeviceImageDrmFormatModifierInfoEXT *mod_info =
@@ -1374,7 +1374,7 @@ static VkResult radv_get_image_format_properties(struct radv_physical_device *ph
                break;
        }
 
-       if (desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED) {
+       if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
                /* Might be able to support but the entire format support is
                 * messy, so taking the lazy way out. */
                maxArraySize = 1;
@@ -1947,34 +1947,34 @@ enum dcc_channel_type {
 
 /* Return the type of DCC encoding. */
 static enum dcc_channel_type
-radv_get_dcc_channel_type(const struct vk_format_description *desc)
+radv_get_dcc_channel_type(const struct util_format_description *desc)
 {
         int i;
 
         /* Find the first non-void channel. */
         for (i = 0; i < desc->nr_channels; i++)
-                if (desc->channel[i].type != VK_FORMAT_TYPE_VOID)
+                if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
                         break;
         if (i == desc->nr_channels)
                 return dcc_channel_incompatible;
 
         switch (desc->channel[i].size) {
         case 32:
-                if (desc->channel[i].type == VK_FORMAT_TYPE_FLOAT)
+                if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
                         return dcc_channel_float32;
-                if (desc->channel[i].type == VK_FORMAT_TYPE_UNSIGNED)
+                if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                         return dcc_channel_uint32;
                 return dcc_channel_sint32;
         case 16:
-                if (desc->channel[i].type == VK_FORMAT_TYPE_FLOAT)
+                if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
                         return dcc_channel_float16;
-                if (desc->channel[i].type == VK_FORMAT_TYPE_UNSIGNED)
+                if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                         return dcc_channel_uint16;
                 return dcc_channel_sint16;
         case 10:
                 return dcc_channel_uint_10_10_10_2;
         case 8:
-                if (desc->channel[i].type == VK_FORMAT_TYPE_UNSIGNED)
+                if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                         return dcc_channel_uint8;
                 return dcc_channel_sint8;
         default:
@@ -1986,7 +1986,7 @@ radv_get_dcc_channel_type(const struct vk_format_description *desc)
 bool radv_dcc_formats_compatible(VkFormat format1,
                                  VkFormat format2)
 {
-        const struct vk_format_description *desc1, *desc2;
+        const struct util_format_description *desc1, *desc2;
         enum dcc_channel_type type1, type2;
         int i;
 
index efef246..340882b 100644 (file)
@@ -442,7 +442,7 @@ radv_get_surface_flags(struct radv_device *device,
        uint64_t flags;
        unsigned array_mode = radv_choose_tiling(device, pCreateInfo, image_format);
        VkFormat format = vk_format_get_plane_format(image_format, plane_id);
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        bool is_depth, is_stencil;
 
        is_depth = vk_format_has_depth(desc);
@@ -535,10 +535,10 @@ static unsigned radv_map_swizzle(unsigned swizzle)
 }
 
 static void
-radv_compose_swizzle(const struct vk_format_description *desc,
+radv_compose_swizzle(const struct util_format_description *desc,
                     const VkComponentMapping *mapping, enum pipe_swizzle swizzle[4])
 {
-       if (desc->format == VK_FORMAT_R64_UINT || desc->format == VK_FORMAT_R64_SINT) {
+       if (desc->format == PIPE_FORMAT_R64_UINT || desc->format == PIPE_FORMAT_R64_SINT) {
                /* 64-bit formats only support storage images and storage images
                 * require identity component mappings. We use 32-bit
                 * instructions to access 64-bit images, so we need a special
@@ -555,7 +555,7 @@ radv_compose_swizzle(const struct vk_format_description *desc,
        } else if (!mapping) {
                for (unsigned i = 0; i < 4; i++)
                        swizzle[i] = desc->swizzle[i];
-       } else if (desc->colorspace == VK_FORMAT_COLORSPACE_ZS) {
+       } else if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
                const unsigned char swizzle_xxxx[4] = {
                        PIPE_SWIZZLE_X, PIPE_SWIZZLE_0, PIPE_SWIZZLE_0, PIPE_SWIZZLE_1
                };
@@ -573,7 +573,7 @@ radv_make_buffer_descriptor(struct radv_device *device,
                            unsigned range,
                            uint32_t *state)
 {
-       const struct vk_format_description *desc;
+       const struct util_format_description *desc;
        unsigned stride;
        uint64_t gpu_address = radv_buffer_get_va(buffer->bo);
        uint64_t va = gpu_address + buffer->offset;
@@ -803,7 +803,7 @@ static unsigned gfx9_border_color_swizzle(const enum pipe_swizzle swizzle[4])
 
 bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
 
        if (device->physical_device->rad_info.chip_class >= GFX10 && desc->nr_channels == 1)
                return desc->swizzle[3] == PIPE_SWIZZLE_X;
@@ -826,7 +826,7 @@ gfx10_make_texture_descriptor(struct radv_device *device,
                           uint32_t *state,
                           uint32_t *fmask_state)
 {
-       const struct vk_format_description *desc;
+       const struct util_format_description *desc;
        enum pipe_swizzle swizzle[4];
        unsigned img_format;
        unsigned type;
@@ -956,7 +956,7 @@ si_make_texture_descriptor(struct radv_device *device,
                           uint32_t *state,
                           uint32_t *fmask_state)
 {
-       const struct vk_format_description *desc;
+       const struct util_format_description *desc;
        enum pipe_swizzle swizzle[4];
        int first_non_void;
        unsigned num_format, data_format, type;
@@ -1466,7 +1466,7 @@ radv_image_print_info(struct radv_device *device, struct radv_image *image)
        for (unsigned i = 0; i < image->plane_count; ++i) {
                const struct radv_image_plane *plane = &image->planes[i];
                const struct radeon_surf *surf = &plane->surface;
-               const struct vk_format_description *desc =
+               const struct util_format_description *desc =
                        vk_format_description(plane->format);
                uint64_t offset = ac_surface_get_plane_offset(device->physical_device->rad_info.chip_class,
                                                              &plane->surface, 0, 0);
index f97f269..7259eb2 100644 (file)
@@ -1528,12 +1528,12 @@ static void vi_get_fast_clear_parameters(struct radv_device *device,
 
        *reset_value = RADV_DCC_CLEAR_REG;
 
-       const struct vk_format_description *desc = vk_format_description(view_format);
+       const struct util_format_description *desc = vk_format_description(view_format);
        if (view_format == VK_FORMAT_B10G11R11_UFLOAT_PACK32 ||
            view_format == VK_FORMAT_R5G6B5_UNORM_PACK16 ||
            view_format == VK_FORMAT_B5G6R5_UNORM_PACK16)
                extra_channel = -1;
-       else if (desc->layout == VK_FORMAT_LAYOUT_PLAIN) {
+       else if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
                if (vi_alpha_is_on_msb(device, view_format))
                        extra_channel = desc->nr_channels - 1;
                else
@@ -1548,7 +1548,7 @@ static void vi_get_fast_clear_parameters(struct radv_device *device,
                        continue;
 
                if (desc->channel[i].pure_integer &&
-                   desc->channel[i].type == VK_FORMAT_TYPE_SIGNED) {
+                   desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
                        /* Use the maximum value for clamping the clear color. */
                        int max = u_bit_consecutive(0, desc->channel[i].size - 1);
 
@@ -1556,7 +1556,7 @@ static void vi_get_fast_clear_parameters(struct radv_device *device,
                        if (clear_value->int32[i] != 0 && MIN2(clear_value->int32[i], max) != max)
                                return;
                } else if (desc->channel[i].pure_integer &&
-                          desc->channel[i].type == VK_FORMAT_TYPE_UNSIGNED) {
+                          desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) {
                        /* Use the maximum value for clamping the clear color. */
                        unsigned max = u_bit_consecutive(0, desc->channel[i].size);
 
index ddaa395..3ada978 100644 (file)
@@ -27,7 +27,7 @@
 static VkExtent3D
 meta_image_block_size(const struct radv_image *image)
 {
-       const struct vk_format_description *desc = vk_format_description(image->vk_format);
+       const struct util_format_description *desc = vk_format_description(image->vk_format);
        return (VkExtent3D) { desc->block.width, desc->block.height, 1 };
 }
 
index 31b45ec..0cfe3ef 100644 (file)
@@ -288,7 +288,7 @@ try_lower_tex_ycbcr(const struct radv_pipeline_layout *layout,
        nir_ssa_def *result = build_swizzled_components(builder, format, ycbcr_sampler->components, plane_values);
        if (state.conversion->ycbcr_model != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY) {
                VkFormat first_format = vk_format_get_plane_format(format, 0);
-               uint32_t bits = vk_format_get_component_bits(first_format, VK_FORMAT_COLORSPACE_RGB, PIPE_SWIZZLE_X);
+               uint32_t bits = vk_format_get_component_bits(first_format, UTIL_FORMAT_COLORSPACE_RGB, PIPE_SWIZZLE_X);
                /* TODO: swizzle and bpcs */
                uint32_t bpcs[3] = {bits, bits, bits};
                result = nir_convert_ycbcr_to_rgb(builder,
index 56013b6..adea6d6 100644 (file)
@@ -544,7 +544,7 @@ stencil_ref_layout(const VkAttachmentReference2 *att_ref)
 static VkImageLayout
 stencil_desc_layout(const VkAttachmentDescription2KHR *att_desc, bool final)
 {
-       const struct vk_format_description *desc = vk_format_description(att_desc->format);
+       const struct util_format_description *desc = vk_format_description(att_desc->format);
        if (!vk_format_has_stencil(desc))
                return VK_IMAGE_LAYOUT_UNDEFINED;
 
index c4c4af1..8eeb25d 100644 (file)
@@ -458,7 +458,7 @@ static unsigned radv_choose_spi_color_format(const struct radv_device *device,
                                             bool blend_enable,
                                             bool blend_need_alpha)
 {
-       const struct vk_format_description *desc = vk_format_description(vk_format);
+       const struct util_format_description *desc = vk_format_description(vk_format);
        bool use_rbplus = device->physical_device->rad_info.rbplus_allowed;
        struct ac_spi_color_formats formats = {0};
        unsigned format, ntype, swap;
@@ -484,7 +484,7 @@ static unsigned radv_choose_spi_color_format(const struct radv_device *device,
 static bool
 format_is_int8(VkFormat format)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
        int channel =  vk_format_get_first_non_void_channel(format);
 
        return channel >= 0 && desc->channel[channel].pure_integer &&
@@ -494,7 +494,7 @@ format_is_int8(VkFormat format)
 static bool
 format_is_int10(VkFormat format)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
+       const struct util_format_description *desc = vk_format_description(format);
 
        if (desc->nr_channels != 4)
                return false;
@@ -2569,7 +2569,7 @@ radv_generate_graphics_pipeline_key(const struct radv_pipeline *pipeline,
        for (unsigned i = 0; i < input_state->vertexAttributeDescriptionCount; ++i) {
                const VkVertexInputAttributeDescription *desc =
                        &input_state->pVertexAttributeDescriptions[i];
-               const struct vk_format_description *format_desc;
+               const struct util_format_description *format_desc;
                unsigned location = desc->location;
                unsigned binding = desc->binding;
                unsigned num_format, data_format;
index 41445cb..51b1f55 100644 (file)
@@ -1804,23 +1804,23 @@ struct radv_binning_settings
 radv_get_binning_settings(const struct radv_physical_device *pdev);
 
 struct vk_format_description;
-uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
+uint32_t radv_translate_buffer_dataformat(const struct util_format_description *desc,
                                          int first_non_void);
-uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
+uint32_t radv_translate_buffer_numformat(const struct util_format_description *desc,
                                         int first_non_void);
 bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
 uint32_t radv_translate_colorformat(VkFormat format);
 uint32_t radv_translate_color_numformat(VkFormat format,
-                                       const struct vk_format_description *desc,
+                                       const struct util_format_description *desc,
                                        int first_non_void);
 uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
 unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
 uint32_t radv_translate_dbformat(VkFormat format);
 uint32_t radv_translate_tex_dataformat(VkFormat format,
-                                      const struct vk_format_description *desc,
+                                      const struct util_format_description *desc,
                                       int first_non_void);
 uint32_t radv_translate_tex_numformat(VkFormat format,
-                                     const struct vk_format_description *desc,
+                                     const struct util_format_description *desc,
                                      int first_non_void);
 bool radv_format_pack_clear_color(VkFormat format,
                                  uint32_t clear_vals[2],
index 5352936..9e2171e 100644 (file)
@@ -138,7 +138,7 @@ struct vk_format_description
 
        unsigned char swizzle[4];
 
-       enum vk_format_colorspace colorspace;
+       enum util_format_colorspace colorspace;
 
        unsigned plane_count:2;
        unsigned width_divisor:2;
@@ -148,15 +148,10 @@ struct vk_format_description
 
 extern const struct vk_format_description vk_format_description_table[];
 
-/* Silence warnings triggered by sharing function/struct names */
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#endif
-const struct vk_format_description *vk_format_description(VkFormat format);
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif
+static inline const struct util_format_description *vk_format_description(VkFormat format)
+{
+       return util_format_description(vk_format_to_pipe_format(format));
+}
 
 /**
  * Return total bits needed for the pixel format per block.
@@ -266,16 +261,16 @@ vk_format_is_subsampled(VkFormat format)
 }
 
 static inline bool
-vk_format_has_depth(const struct vk_format_description *desc)
+vk_format_has_depth(const struct util_format_description *desc)
 {
-       return desc->colorspace == VK_FORMAT_COLORSPACE_ZS &&
+       return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
                desc->swizzle[0] != PIPE_SWIZZLE_NONE;
 }
 
 static inline bool
-vk_format_has_stencil(const struct vk_format_description *desc)
+vk_format_has_stencil(const struct util_format_description *desc)
 {
-       return desc->colorspace == VK_FORMAT_COLORSPACE_ZS &&
+       return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
                desc->swizzle[1] != PIPE_SWIZZLE_NONE;
 }
 
@@ -418,11 +413,11 @@ vk_format_stencil_only(VkFormat format)
 
 static inline unsigned
 vk_format_get_component_bits(VkFormat format,
-                            enum vk_format_colorspace colorspace,
+                            enum util_format_colorspace colorspace,
                             unsigned component)
 {
-       const struct vk_format_description *desc = vk_format_description(format);
-       enum vk_format_colorspace desc_colorspace;
+       const struct util_format_description *desc = vk_format_description(format);
+       enum util_format_colorspace desc_colorspace;
 
        assert(format);
        if (!format) {
@@ -432,11 +427,11 @@ vk_format_get_component_bits(VkFormat format,
        assert(component < 4);
 
        /* Treat RGB and SRGB as equivalent. */
-       if (colorspace == VK_FORMAT_COLORSPACE_SRGB) {
-               colorspace = VK_FORMAT_COLORSPACE_RGB;
+       if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
+               colorspace = UTIL_FORMAT_COLORSPACE_RGB;
        }
-       if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
-               desc_colorspace = VK_FORMAT_COLORSPACE_RGB;
+       if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
+               desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
        } else {
                desc_colorspace = desc->colorspace;
        }
index e99b676..34d8811 100644 (file)
@@ -147,8 +147,8 @@ def write_format_table(formats):
         print("};")
         print()
 
-    print("const struct vk_format_description *")
-    print("vk_format_description(VkFormat format)")
+    print("static const struct vk_format_description *")
+    print("vk_format_description_legacy(VkFormat format)")
     print("{")
     print("   switch (format) {")
     for format in formats: