From c8a8543af7ac8caa6d7c6474e2ddb62cf5046002 Mon Sep 17 00:00:00 2001 From: Valentine Burley Date: Wed, 4 Sep 2024 20:44:33 +0000 Subject: [PATCH] vulkan: Fix incorrect bpcs value for padded formats Skip padding channels and only consider valid color channels. Add and use a common helper for this. Reviewed-by: Faith Ekstrand Signed-off-by: Valentine Burley Part-of: --- src/vulkan/runtime/vk_nir_convert_ycbcr.c | 8 ++++---- src/vulkan/util/vk_format.h | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/vulkan/runtime/vk_nir_convert_ycbcr.c b/src/vulkan/runtime/vk_nir_convert_ycbcr.c index a4bc64b1415..4aed2b65adc 100644 --- a/src/vulkan/runtime/vk_nir_convert_ycbcr.c +++ b/src/vulkan/runtime/vk_nir_convert_ycbcr.c @@ -358,9 +358,7 @@ lower_ycbcr_tex_instr(nir_builder *b, nir_instr *instr, void *_state) y_format = format_ycbcr_info->planes[p].format; } assert(y_format != VK_FORMAT_UNDEFINED); - const struct util_format_description *y_format_desc = - util_format_description(vk_format_to_pipe_format(y_format)); - uint8_t y_bpc = y_format_desc->channel[0].size; + uint8_t y_bpc = vk_format_get_bpc(y_format); /* |ycbcr_comp| holds components in the order : Cr-Y-Cb */ nir_def *zero = nir_imm_float(b, 0.0f); @@ -399,7 +397,9 @@ lower_ycbcr_tex_instr(nir_builder *b, nir_instr *instr, void *_state) /* Also compute the number of bits for each component. */ const struct util_format_description *plane_format_desc = - util_format_description(vk_format_to_pipe_format(format_plane->format)); + vk_format_description(format_plane->format); + if (plane_format_desc->channel[pc].type == UTIL_FORMAT_TYPE_VOID) + continue; ycbcr_bpcs[ycbcr_component] = plane_format_desc->channel[pc].size; } } diff --git a/src/vulkan/util/vk_format.h b/src/vulkan/util/vk_format.h index 720c5c185d7..04b3adc0963 100644 --- a/src/vulkan/util/vk_format.h +++ b/src/vulkan/util/vk_format.h @@ -222,6 +222,22 @@ vk_format_get_blocksizebits(VkFormat format) return util_format_get_blocksizebits(vk_format_to_pipe_format(format)); } +static inline unsigned +vk_format_get_bpc(VkFormat format) +{ + const struct util_format_description *desc = + vk_format_description(format); + unsigned bpc = 0; + for (unsigned i = 0; i < desc->nr_channels; i++) { + if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) + continue; + + assert(bpc == 0 || bpc == desc->channel[i].size); + bpc = desc->channel[i].size; + } + return bpc; +} + VkFormat vk_format_get_plane_format(VkFormat format, unsigned plane_id); @@ -266,7 +282,7 @@ vk_format_get_plane_width(VkFormat format, unsigned plane, unsigned width) const struct vk_format_ycbcr_info *ycbcr_info = vk_format_get_ycbcr_info(format); const uint8_t width_scale = ycbcr_info ? - ycbcr_info->planes[plane].denominator_scales[0] : 1; + ycbcr_info->planes[plane].denominator_scales[0] : 1; return width / width_scale; } @@ -276,7 +292,7 @@ vk_format_get_plane_height(VkFormat format, unsigned plane, unsigned height) const struct vk_format_ycbcr_info *ycbcr_info = vk_format_get_ycbcr_info(format); const uint8_t height_scale = ycbcr_info ? - ycbcr_info->planes[plane].denominator_scales[1] : 1; + ycbcr_info->planes[plane].denominator_scales[1] : 1; return height / height_scale; }