From: Samuel Pitoiset Date: Fri, 11 Oct 2019 15:40:59 +0000 (+0200) Subject: radv: fix DCC fast clear code for intensity formats X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ea92273cea88b964c6aec45061e74a9ff7339825;p=mesa.git radv: fix DCC fast clear code for intensity formats This fixes a rendering issue with DiRT 4 on GFX10. Only GFX10 was affected because intensity formats are different. Cc: 19.2 Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/1923 Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen --- diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index fa7f47cc8ef..1842daabf68 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -715,7 +715,7 @@ static unsigned gfx9_border_color_swizzle(const enum vk_swizzle swizzle[4]) return bc_swizzle; } -static bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format) +bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format) { const struct vk_format_description *desc = vk_format_description(format); diff --git a/src/amd/vulkan/radv_meta_clear.c b/src/amd/vulkan/radv_meta_clear.c index 83bf45fb4cc..6002fc87a61 100644 --- a/src/amd/vulkan/radv_meta_clear.c +++ b/src/amd/vulkan/radv_meta_clear.c @@ -1450,7 +1450,9 @@ enum { RADV_DCC_CLEAR_SECONDARY_1 = 0x40404040U }; -static void vi_get_fast_clear_parameters(VkFormat format, +static void vi_get_fast_clear_parameters(struct radv_device *device, + VkFormat image_format, + VkFormat view_format, const VkClearColorValue *clear_value, uint32_t* reset_value, bool *can_avoid_fast_clear_elim) @@ -1464,19 +1466,22 @@ static void vi_get_fast_clear_parameters(VkFormat format, *reset_value = RADV_DCC_CLEAR_REG; - const struct vk_format_description *desc = vk_format_description(format); - if (format == VK_FORMAT_B10G11R11_UFLOAT_PACK32 || - format == VK_FORMAT_R5G6B5_UNORM_PACK16 || - format == VK_FORMAT_B5G6R5_UNORM_PACK16) + const struct vk_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) { - if (radv_translate_colorswap(format, false) <= 1) + if (vi_alpha_is_on_msb(device, view_format)) extra_channel = desc->nr_channels - 1; else extra_channel = 0; } else return; + bool image_alpha_is_on_msb = vi_alpha_is_on_msb(device, image_format); + bool view_alpha_is_on_msb = vi_alpha_is_on_msb(device, view_format); + for (i = 0; i < 4; i++) { int index = desc->swizzle[i] - VK_SWIZZLE_X; if (desc->swizzle[i] < VK_SWIZZLE_X || @@ -1511,6 +1516,17 @@ static void vi_get_fast_clear_parameters(VkFormat format, main_value = values[i]; } + /* If alpha isn't present, make it the same as color, and vice versa. */ + if (!extra_value) + extra_value = main_value; + else if (!main_value) + main_value = extra_value; + + if (main_value != extra_value) { + assert(image_alpha_is_on_msb == view_alpha_is_on_msb); + return; /* require ELIMINATE_FAST_CLEAR */ + } + for (int i = 0; i < 4; ++i) if (values[i] != main_value && desc->swizzle[i] - VK_SWIZZLE_X != extra_channel && @@ -1570,7 +1586,9 @@ radv_can_fast_clear_color(struct radv_cmd_buffer *cmd_buffer, bool can_avoid_fast_clear_elim; uint32_t reset_value; - vi_get_fast_clear_parameters(iview->vk_format, + vi_get_fast_clear_parameters(cmd_buffer->device, + iview->image->vk_format, + iview->vk_format, &clear_value, &reset_value, &can_avoid_fast_clear_elim); @@ -1642,7 +1660,9 @@ radv_fast_clear_color(struct radv_cmd_buffer *cmd_buffer, bool can_avoid_fast_clear_elim; bool need_decompress_pass = false; - vi_get_fast_clear_parameters(iview->vk_format, + vi_get_fast_clear_parameters(cmd_buffer->device, + iview->image->vk_format, + iview->vk_format, &clear_value, &reset_value, &can_avoid_fast_clear_elim); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 1995d59045f..1158a30f767 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -1924,6 +1924,8 @@ VkResult radv_image_create(VkDevice _device, const VkAllocationCallbacks* alloc, VkImage *pImage); +bool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format); + VkResult radv_image_from_gralloc(VkDevice device_h, const VkImageCreateInfo *base_info,