From 401b2066b053ab4882d90a76628e3edfd70be936 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 17 Nov 2025 11:43:20 +0200 Subject: [PATCH] anv: ensure slab allocated memory matches image requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The VMA of VkDeviceMemory has to accomodate all the resources that can be bound to it. For sparse images it's 64KiB alignment, for other tiled images it's 4KiB. But we also have a workaround that requires a 64KiB alignment for Tile4 images. The initial version of the slab allocator missed the 4KiB alignment. This fix adds the workaround handling too. Signed-off-by: Lionel Landwerlin Fixes: dabb012423 ("anv: Implement anv_slab_bo and enable memory pool") Reviewed-by: Nanley Chery Reviewed-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_allocator.c | 15 ++++++++++++--- src/intel/vulkan/anv_image.c | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 013d5bf1913..cb1f77e1a43 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1551,9 +1551,18 @@ anv_bo_vma_calc_alignment_requirement(struct anv_device *device, const bool is_small_heap = anv_bo_is_small_heap(alloc_flags); uint32_t align = 64; /* A cache line */ - /* If it's big enough to store a tiled resource, we need 64K alignment */ - if (size >= 64 * 1024 && !is_small_heap) - align = MAX2(64 * 1024, align); + /* If it's big enough to store a 64K tiled resource, we need 64K alignment. + * Wa_22015614752 requires that some images be aligned to 64k when used on + * multiple engines, so allocation that might contain 4k tiled images need + * to be aligned to 64k. + */ + const uint64_t image_alignment = + (size >= 64 * 1024 || + (device->queue_count > 1 && + intel_needs_workaround(device->info, 22015614752))) ? + 64 * 1024 : 4 * 1024; + if (size >= 4 * 1024 && !is_small_heap) + align = MAX2(image_alignment, align); /* If we're using the AUX map, make sure we follow the required * alignment. diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index d4db8212ce4..f536a0d4a9d 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -2969,6 +2969,9 @@ anv_image_bind_address(struct anv_device *device, enum anv_image_memory_binding binding, struct anv_address address) { + assert(anv_address_physical(address) % + image->bindings[binding].memory_range.alignment == 0); + image->bindings[binding].address = address; /* Map bindings for images with host transfer usage, so that we don't have