From 86c88369c692c0e8fcf7d3957f1a98cf5f13e0e7 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Thu, 29 Feb 2024 04:48:32 +0800 Subject: [PATCH] pvr: Merge imagination/vulkan/vk_format.h into imagination/vulkan/pvr_formats.h Signed-off-by: Yonggang Luo Reviewed-by: Matt Coster Part-of: --- src/imagination/vulkan/pvr_formats.h | 64 +++++++++++++++ src/imagination/vulkan/pvr_job_common.c | 1 + src/imagination/vulkan/vk_format.h | 105 ------------------------ 3 files changed, 65 insertions(+), 105 deletions(-) delete mode 100644 src/imagination/vulkan/vk_format.h diff --git a/src/imagination/vulkan/pvr_formats.h b/src/imagination/vulkan/pvr_formats.h index a0b2e07c0b7..83d2cbfcd96 100644 --- a/src/imagination/vulkan/pvr_formats.h +++ b/src/imagination/vulkan/pvr_formats.h @@ -29,6 +29,7 @@ #include #include "util/format/u_formats.h" +#include "vk_format.h" /* This is based on VkClearColorValue which is an array of RGBA, and on the * output register usage for the biggest 32 bit 4 component formats which use up @@ -252,4 +253,67 @@ void pvr_get_hw_clear_color(VkFormat vk_format, uint32_t pvr_pbe_pixel_num_loads(enum pvr_transfer_pbe_pixel_src pbe_format); +static inline bool vk_format_has_32bit_component(VkFormat vk_format) +{ + const struct util_format_description *desc = + vk_format_description(vk_format); + + for (uint32_t i = 0; i < desc->nr_channels; i++) { + if (desc->channel[i].size == 32U) + return true; + } + + return false; +} + +static inline bool vk_format_is_normalized(VkFormat vk_format) +{ + const struct util_format_description *desc = + vk_format_description(vk_format); + + for (uint32_t i = 0; i < desc->nr_channels; i++) { + if (!desc->channel[i].normalized) + return false; + } + + return true; +} + +static inline uint32_t +vk_format_get_common_color_channel_count(VkFormat src_format, + VkFormat dst_format) +{ + const struct util_format_description *dst_desc = + vk_format_description(dst_format); + const struct util_format_description *src_desc = + vk_format_description(src_format); + uint32_t count = 0; + + /* Check if destination format is alpha only and source format has alpha + * channel. + */ + if (util_format_is_alpha(vk_format_to_pipe_format(dst_format))) { + count = 1; + } else if (dst_desc->nr_channels <= src_desc->nr_channels) { + for (uint32_t i = 0; i < dst_desc->nr_channels; i++) { + enum pipe_swizzle swizzle = dst_desc->swizzle[i]; + + if (swizzle > PIPE_SWIZZLE_W) + continue; + + for (uint32_t j = 0; j < src_desc->nr_channels; j++) { + if (src_desc->swizzle[j] == swizzle) { + count++; + break; + } + } + } + } else { + count = dst_desc->nr_channels; + } + + return count; +} + + #endif /* PVR_FORMATS_H */ diff --git a/src/imagination/vulkan/pvr_job_common.c b/src/imagination/vulkan/pvr_job_common.c index e481f4fcb3f..d4bbb530c93 100644 --- a/src/imagination/vulkan/pvr_job_common.c +++ b/src/imagination/vulkan/pvr_job_common.c @@ -28,6 +28,7 @@ #include "hwdef/rogue_hw_utils.h" #include "pvr_csb_enum_helpers.h" #include "pvr_device_info.h" +#include "pvr_formats.h" #include "pvr_job_common.h" #include "pvr_private.h" #include "util/macros.h" diff --git a/src/imagination/vulkan/vk_format.h b/src/imagination/vulkan/vk_format.h deleted file mode 100644 index 6446b1ce6c7..00000000000 --- a/src/imagination/vulkan/vk_format.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2022 Imagination Technologies Ltd. - * - * based in part on radv driver which is: - * Copyright © 2016 Red Hat. - * Copyright © 2016 Bas Nieuwenhuizen - * - * Based on u_format.h which is: - * Copyright 2009-2010 VMware, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef VK_FORMAT_H -#define VK_FORMAT_H - -#include -#include -#include - -#include - -#include "util/u_endian.h" - - -static inline bool vk_format_has_32bit_component(VkFormat vk_format) -{ - const struct util_format_description *desc = - vk_format_description(vk_format); - - for (uint32_t i = 0; i < desc->nr_channels; i++) { - if (desc->channel[i].size == 32U) - return true; - } - - return false; -} - -static inline bool vk_format_is_normalized(VkFormat vk_format) -{ - const struct util_format_description *desc = - vk_format_description(vk_format); - - for (uint32_t i = 0; i < desc->nr_channels; i++) { - if (!desc->channel[i].normalized) - return false; - } - - return true; -} - -static inline uint32_t -vk_format_get_common_color_channel_count(VkFormat src_format, - VkFormat dst_format) -{ - const struct util_format_description *dst_desc = - vk_format_description(dst_format); - const struct util_format_description *src_desc = - vk_format_description(src_format); - uint32_t count = 0; - - /* Check if destination format is alpha only and source format has alpha - * channel. - */ - if (util_format_is_alpha(vk_format_to_pipe_format(dst_format))) { - count = 1; - } else if (dst_desc->nr_channels <= src_desc->nr_channels) { - for (uint32_t i = 0; i < dst_desc->nr_channels; i++) { - enum pipe_swizzle swizzle = dst_desc->swizzle[i]; - - if (swizzle > PIPE_SWIZZLE_W) - continue; - - for (uint32_t j = 0; j < src_desc->nr_channels; j++) { - if (src_desc->swizzle[j] == swizzle) { - count++; - break; - } - } - } - } else { - count = dst_desc->nr_channels; - } - - return count; -} - -#endif /* VK_FORMAT_H */