From 10bcfb63d56da203c173d8123339c055a86fc9f6 Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Thu, 5 Sep 2024 09:45:28 -0400 Subject: [PATCH] anv: Prevent clear color modifier corruption with views If a dmabuf is shared with a clear color, the raw clear color channels generally won't be interpreted correctly during format reinterpretation. So, prevent Vulkan apps from trying to use such dmabufs as mutable format render targets. Also, prevent such apps from using such dmabufs as blorp_copy() destinations if doing so would require format reinterpretation. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_formats.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 87c7550f90e..b37351565e1 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -840,6 +840,16 @@ anv_get_image_format_features2(const struct anv_physical_device *physical_device flags &= ~VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT; flags &= ~VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT; } + + if (isl_mod_info->supports_clear_color && plane_format.isl_format != + blorp_copy_get_color_format(&physical_device->isl_dev, + plane_format.isl_format)) { + /* If the clear color is non-zero, blorp_copy() may interpret the raw + * clear color channels incorrectly when it changes the surface + * format. Disable support for this format as a copy destination. + */ + flags &= ~VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT; + } } if (devinfo->has_coarse_pixel_primitive_and_cb && @@ -1500,6 +1510,15 @@ anv_get_image_format_properties( maxMipLevels = 1; sampleCounts = VK_SAMPLE_COUNT_1_BIT; + if (isl_mod_info->supports_clear_color && + (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && + (info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) { + /* Format reinterpretation generally won't work correctly with the + * raw clear color channels. + */ + goto unsupported; + } + if (isl_drm_modifier_has_aux(isl_mod_info->modifier) && !anv_formats_ccs_e_compatible(devinfo, info->flags, info->format, info->tiling, info->usage,