From cb8da4bb419a0dd210bdde018bc21b9c48ac2f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 9 Jun 2026 14:06:27 -0400 Subject: [PATCH] radv: bump the sparse alignment requirement to 64K 4K sparse allocations are super slow because they thrash TLB, so it's better to disallow them. radeonsi already reports 64K alignment for sparse buffers, but RADV reported 4K. VMEM latency with 4K pages: Size , 1024, 1536, 2K, 3K, 4K, 6K, 8K, 12K, 16K, 24K, 32K, 48K, 64K, 96K, 128K, 192K, 256K, 384K, 512K, 768K, 1024K, 1536K, 2M, 3M, 4M, Latency, 86, 86, 86, 86, 89, 86, 86, 87, 87, 126, 127, 126, 128, 387, 409, 448, 423, 450, 446, 424, 430, 429, 428, 433, 432 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ VMEM latency with 64K pages (it's lower, up to 2x lower in some cases): Size , 1024, 1536, 2K, 3K, 4K, 6K, 8K, 12K, 16K, 24K, 32K, 48K, 64K, 96K, 128K, 192K, 256K, 384K, 512K, 768K, 1024K, 1536K, 2M, 3M, 4M, Latency, 87, 86, 86, 86, 86, 86, 86, 87, 87, 125, 127, 126, 128, 198, 196, 197, 198, 376, 392, 411, 381, 401, 392, 432, 451, ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_buffer.c | 7 ++++--- src/amd/vulkan/radv_constants.h | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/amd/vulkan/radv_buffer.c b/src/amd/vulkan/radv_buffer.c index 2ffdb830bf9..5cdb9d59038 100644 --- a/src/amd/vulkan/radv_buffer.c +++ b/src/amd/vulkan/radv_buffer.c @@ -98,8 +98,9 @@ radv_create_buffer(struct radv_device *device, const VkBufferCreateInfo *pCreate (VK_BUFFER_USAGE_2_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | VK_BUFFER_USAGE_2_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT)) flags |= RADEON_FLAG_32BIT; - VkResult result = radv_bo_create(device, &buffer->vk.base, align64(buffer->vk.size, 4096), 4096, 0, flags, - RADV_BO_PRIORITY_VIRTUAL, replay_address, is_internal, &buffer->bo); + VkResult result = radv_bo_create(device, &buffer->vk.base, align64(buffer->vk.size, RADV_SPARSE_BUFFER_ALIGNMENT), + RADV_SPARSE_BUFFER_ALIGNMENT, 0, flags, RADV_BO_PRIORITY_VIRTUAL, replay_address, + is_internal, &buffer->bo); if (result != VK_SUCCESS) { radv_destroy_buffer(device, pAllocator, buffer); return vk_error(device, result); @@ -201,7 +202,7 @@ radv_get_buffer_memory_requirements(struct radv_device *device, VkDeviceSize siz pMemoryRequirements->memoryRequirements.memoryTypeBits &= pdev->memory_types_protected; if (flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) { - pMemoryRequirements->memoryRequirements.alignment = 4096; + pMemoryRequirements->memoryRequirements.alignment = RADV_SPARSE_BUFFER_ALIGNMENT; } else { if (usage & VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT) pMemoryRequirements->memoryRequirements.alignment = radv_dgc_get_buffer_alignment(device); diff --git a/src/amd/vulkan/radv_constants.h b/src/amd/vulkan/radv_constants.h index 95351035041..4e4c36b9ce5 100644 --- a/src/amd/vulkan/radv_constants.h +++ b/src/amd/vulkan/radv_constants.h @@ -156,4 +156,7 @@ #define RADV_MAX_SHADER_ABORT_MESSAGE_SIZE 65536 +/* Don't use 4K alignment for sparse because 4K pages (both sparse and non-sparse) are super slow. */ +#define RADV_SPARSE_BUFFER_ALIGNMENT (64 * 1024) + #endif /* RADV_CONSTANTS_H */