From 11f8f333e23dd6bcbeff6a831c67d1acb3cb67d2 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Tue, 27 Jan 2026 15:44:25 +0100 Subject: [PATCH] anv: set a private binding when the image is not externally shared This allows anv to use a suballocator for the clear color address, which should decrease our memory requirement. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13091 Signed-off-by: Rohan Garg Reviewed-by: Nanley Chery Part-of: --- src/intel/vulkan/anv_image.c | 33 ++++++++++++--------------------- src/intel/vulkan/anv_private.h | 8 ++------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 420d01cdce7..95d108e863a 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -650,17 +650,12 @@ add_aux_state_tracking_buffer(struct anv_device *device, const struct isl_drm_modifier_info *mod_info = isl_drm_modifier_get_info(image->vk.drm_format_mod); - /* If an auxiliary surface is used for an externally-shareable image, - * we have to hide this from the memory of the image since other - * processes with access to the memory may not be aware of it or of - * its current state. So put that auxiliary data into a separate - * buffer (ANV_IMAGE_MEMORY_BINDING_PRIVATE). - * - * But when the image is created with a drm modifier that supports - * clear color, it will be exported along with main surface. + /* If the image is created with a drm modifier that supports clear color, + * it will be exported along with main surface. Otherwise, place the + * aux-tracking state in a separate, suballocated buffer to achieve better + * memory utilization. */ - if (anv_image_is_externally_shared(image) && - !mod_info->supports_clear_color) + if (!mod_info || !mod_info->supports_clear_color) binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; /* The indirect clear color BO requires 64B-alignment on gfx11+. If we're @@ -1146,20 +1141,16 @@ check_memory_bindings(const struct anv_device *device, /* Check fast clear state */ if (plane->fast_clear_memory_range.size > 0) { enum anv_image_memory_binding binding = primary_binding; + const struct isl_drm_modifier_info *mod_info = + isl_drm_modifier_get_info(image->vk.drm_format_mod); - /* If an auxiliary surface is used for an externally-shareable image, - * we have to hide this from the memory of the image since other - * processes with access to the memory may not be aware of it or of - * its current state. So put that auxiliary data into a separate - * buffer (ANV_IMAGE_MEMORY_BINDING_PRIVATE). - * - * But when the image is created with a drm modifier that supports - * clear color, it will be exported along with main surface. + /* If the image is created with a drm modifier that supports clear + * color, it will be exported along with main surface. Otherwise, + * place the aux-tracking state in a separate, suballocated buffer + * to achieve better memory utilization. */ - if (anv_image_is_externally_shared(image) - && !isl_drm_modifier_get_info(image->vk.drm_format_mod)->supports_clear_color) { + if (!mod_info || !mod_info->supports_clear_color) binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; - } /* The indirect clear color BO requires 64B-alignment on gfx11+. */ assert(plane->fast_clear_memory_range.alignment % 64 == 0); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 2b9130c4b72..9a51c79b4eb 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -5835,12 +5835,8 @@ anv_image_is_externally_shared(const struct anv_image *image) static inline bool anv_image_has_private_binding(const struct anv_image *image) { - if (image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].memory_range.size > 0) { - assert(anv_image_is_externally_shared(image)); - return true; - } else { - return false; - } + enum anv_image_memory_binding binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE; + return image->bindings[binding].memory_range.size > 0; } /* The ordering of this enum is important */