aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Perry <[email protected]>2020-04-10 14:25:46 +0100
committerMarge Bot <[email protected]>2020-04-24 18:52:54 +0000
commit51363bd4751c2f8e388c229fe91507a7a181517c (patch)
tree1efe34de27ccdb4775607329c3d7c77a78ad6150
parent62ff2ff8086fd3bbff02004628e0c7498fe3294e (diff)
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 <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4639>
-rw-r--r--src/amd/vulkan/radv_constants.h6
-rw-r--r--src/amd/vulkan/radv_descriptor_set.c12
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;