From 0551a40c361c0593d9feb7a081a11417486e8d29 Mon Sep 17 00:00:00 2001 From: Utku Iseri Date: Wed, 8 Oct 2025 16:47:11 +0200 Subject: [PATCH] panvk: only add storage usage without AFBC Instead of always adding storage usage on pre_mod_adjustments and preventing AFBC for all images with usage TRANSFER_DST, only do this when the image doesn't use AFBC, by adding a new post_mod_adjustments pass. Reviewed-by: Boris Brezillon Reviewed-by: Yiwei Zhang Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/panfrost/vulkan/panvk_image.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/panfrost/vulkan/panvk_image.c b/src/panfrost/vulkan/panvk_image.c index 3d82d10e7fe..2b157aa75bb 100644 --- a/src/panfrost/vulkan/panvk_image.c +++ b/src/panfrost/vulkan/panvk_image.c @@ -483,10 +483,8 @@ panvk_image_pre_mod_select_meta_adjustments(struct panvk_image *image) if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) image->vk.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - if (aspects & VK_IMAGE_ASPECT_COLOR_BIT) { + if (aspects & VK_IMAGE_ASPECT_COLOR_BIT) image->vk.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - image->vk.usage |= VK_IMAGE_USAGE_STORAGE_BIT; - } } if (image->vk.stencil_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) @@ -518,6 +516,20 @@ panvk_image_pre_mod_select_meta_adjustments(struct panvk_image *image) } } +static void +panvk_image_post_mod_select_meta_adjustments(struct panvk_image *image) +{ + const VkImageAspectFlags aspects = vk_format_aspects(image->vk.format); + + /* If the image didn't end up using AFBC, we should add the storage flag + * to allow vkmeta to take the compute based copying path. */ + if ((image->vk.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) && + (aspects & VK_IMAGE_ASPECT_COLOR_BIT) && + !drm_is_afbc(image->vk.drm_format_mod)) { + image->vk.usage |= VK_IMAGE_USAGE_STORAGE_BIT; + } +} + static uint64_t panvk_image_get_total_size(const struct panvk_image *image) { @@ -554,6 +566,12 @@ panvk_image_init(struct panvk_image *image, /* Now that we've patched the create/usage flags, we can proceed with the * modifier selection. */ image->vk.drm_format_mod = panvk_image_get_mod(image, pCreateInfo); + + /* Some modifiers like AFBC affect some decisions we make for vkmeta, but + * we don't want to outright prevent these modifiers. If those weren't used, + * we apply additional flags here. */ + panvk_image_post_mod_select_meta_adjustments(image); + return panvk_image_init_layouts(image, pCreateInfo); }