From 0be39ce4adbe14e1ef27743547ffeb883a005015 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 10 Apr 2026 18:24:18 +0200 Subject: [PATCH] radv: use the "LOW" address space for UBOs Read-only and no sparse feedback support. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_descriptor_set.c | 2 +- src/amd/vulkan/radv_descriptor_update_template.c | 3 ++- src/amd/vulkan/radv_descriptors.c | 6 +++--- src/amd/vulkan/radv_descriptors.h | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c index fa32771abb7..8a9d5870126 100644 --- a/src/amd/vulkan/radv_descriptor_set.c +++ b/src/amd/vulkan/radv_descriptor_set.c @@ -592,7 +592,7 @@ radv_update_descriptor_sets_impl(struct radv_device *device, struct radv_cmd_buf } case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - radv_write_buffer_descriptor_impl(device, ptr, writeset->pBufferInfo + j); + radv_write_buffer_descriptor_impl(device, writeset->descriptorType, ptr, writeset->pBufferInfo + j); break; case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: diff --git a/src/amd/vulkan/radv_descriptor_update_template.c b/src/amd/vulkan/radv_descriptor_update_template.c index d618e98ad1c..4b75cac535f 100644 --- a/src/amd/vulkan/radv_descriptor_update_template.c +++ b/src/amd/vulkan/radv_descriptor_update_template.c @@ -143,7 +143,8 @@ radv_update_descriptor_set_with_template_impl(struct radv_device *device, struct } case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - radv_write_buffer_descriptor_impl(device, pDst, (struct VkDescriptorBufferInfo *)pSrc); + radv_write_buffer_descriptor_impl(device, templ->entry[i].descriptor_type, pDst, + (struct VkDescriptorBufferInfo *)pSrc); break; case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: diff --git a/src/amd/vulkan/radv_descriptors.c b/src/amd/vulkan/radv_descriptors.c index 9afd9b90672..1bc6999cc28 100644 --- a/src/amd/vulkan/radv_descriptors.c +++ b/src/amd/vulkan/radv_descriptors.c @@ -144,7 +144,7 @@ radv_GetDescriptorEXT(VkDevice _device, const VkDescriptorGetInfoEXT *pDescripto ? pDescriptorInfo->data.pUniformBuffer : pDescriptorInfo->data.pStorageBuffer; - radv_write_buffer_descriptor(device, pDescriptor, addr_info ? addr_info->address : 0, + radv_write_buffer_descriptor(device, pDescriptorInfo->type, pDescriptor, addr_info ? addr_info->address : 0, addr_info ? addr_info->range : 0); break; } @@ -242,8 +242,8 @@ radv_WriteResourceDescriptorsEXT(VkDevice _device, uint32_t resourceCount, case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: { const VkDeviceAddressRangeEXT *addr_range = resource->data.pAddressRange; - radv_write_buffer_descriptor(device, host_addr_range->address, addr_range ? addr_range->address : 0, - addr_range ? addr_range->size : 0); + radv_write_buffer_descriptor(device, resource->type, host_addr_range->address, + addr_range ? addr_range->address : 0, addr_range ? addr_range->size : 0); break; } case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: diff --git a/src/amd/vulkan/radv_descriptors.h b/src/amd/vulkan/radv_descriptors.h index 556f1d3689f..adb9a779a3b 100644 --- a/src/amd/vulkan/radv_descriptors.h +++ b/src/amd/vulkan/radv_descriptors.h @@ -44,7 +44,8 @@ radv_write_texel_buffer_descriptor(unsigned *dst, const VkBufferView _buffer_vie } static ALWAYS_INLINE void -radv_write_buffer_descriptor(struct radv_device *device, unsigned *dst, uint64_t va, uint64_t range) +radv_write_buffer_descriptor(struct radv_device *device, VkDescriptorType descriptor_type, unsigned *dst, uint64_t va, + uint64_t range) { const struct radv_physical_device *pdev = radv_device_physical(device); @@ -53,6 +54,13 @@ radv_write_buffer_descriptor(struct radv_device *device, unsigned *dst, uint64_t return; } + if (pdev->info.compiler_info.has_smem_with_null_prt_bug && descriptor_type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) { + /* Always use the "LOW" address space for UBOs because they are read-only and sparse feedback + * isn't possible. This avoids clearing the control bit in shaders. + */ + va &= ~(1ull << pdev->info.address_prt_wa_control_bit); + } + /* robustBufferAccess is relaxed enough to allow this (in combination with the alignment/size * we return from vkGetBufferMemoryRequirements) and this allows the shader compiler to create * more efficient 8/16-bit buffer accesses. @@ -61,7 +69,8 @@ radv_write_buffer_descriptor(struct radv_device *device, unsigned *dst, uint64_t } static ALWAYS_INLINE void -radv_write_buffer_descriptor_impl(struct radv_device *device, unsigned *dst, const VkDescriptorBufferInfo *buffer_info) +radv_write_buffer_descriptor_impl(struct radv_device *device, VkDescriptorType descriptor_type, unsigned *dst, + const VkDescriptorBufferInfo *buffer_info) { VK_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer); uint64_t va = 0, range = 0; @@ -73,7 +82,7 @@ radv_write_buffer_descriptor_impl(struct radv_device *device, unsigned *dst, con assert(buffer->vk.size > 0 && range > 0); } - radv_write_buffer_descriptor(device, dst, va, range); + radv_write_buffer_descriptor(device, descriptor_type, dst, va, range); } static ALWAYS_INLINE void