From 51363bd4751c2f8e388c229fe91507a7a181517c Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 10 Apr 2020 14:25:46 +0100 Subject: radv: align buffer descriptor sizes to dword This is needed to prevent bounds checking issues when load 8/16-bit values with dword loads. Signed-off-by: Rhys Perry Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_constants.h | 6 ++++-- src/amd/vulkan/radv_descriptor_set.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/amd/vulkan/radv_constants.h b/src/amd/vulkan/radv_constants.h index a42984e83c6..b494e5c71e7 100644 --- a/src/amd/vulkan/radv_constants.h +++ b/src/amd/vulkan/radv_constants.h @@ -81,8 +81,10 @@ */ #define RADV_MAX_PER_SET_DESCRIPTORS ((1ull << 31 ) / 96) -/* Our buffer size fields allow only this much */ -#define RADV_MAX_MEMORY_ALLOCATION_SIZE 0xFFFFFFFFull +/* Our buffer size fields allow only 2**32 - 1. We round that down to a multiple + * of 4 bytes so we can align buffer sizes up. + */ +#define RADV_MAX_MEMORY_ALLOCATION_SIZE 0xFFFFFFFCull /* Number of invocations in each subgroup. */ #define RADV_SUBGROUP_SIZE 64 diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c index ea3d733ba61..dff774ace69 100644 --- a/src/amd/vulkan/radv_descriptor_set.c +++ b/src/amd/vulkan/radv_descriptor_set.c @@ -851,6 +851,12 @@ static void write_buffer_descriptor(struct radv_device *device, if (buffer_info->range == VK_WHOLE_SIZE) range = buffer->size - buffer_info->offset; + /* 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. */ + range = align(range, 4); + va += buffer_info->offset + buffer->offset; dst[0] = va; dst[1] = S_008F04_BASE_ADDRESS_HI(va >> 32); @@ -898,6 +904,12 @@ static void write_dynamic_buffer_descriptor(struct radv_device *device, if (buffer_info->range == VK_WHOLE_SIZE) size = buffer->size - buffer_info->offset; + /* 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. */ + size = align(size, 4); + va += buffer_info->offset + buffer->offset; range->va = va; range->size = size; -- cgit v1.2.3