Mesa (main): radv: Require an alignment of 64 for accel structs
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jun 6 14:10:28 UTC 2022
Module: Mesa
Branch: main
Commit: e8da8fc5b7429e3aa832e1153f900765951470d4
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e8da8fc5b7429e3aa832e1153f900765951470d4
Author: Konstantin Seurer <konstantin.seurer at gmail.com>
Date: Sat Jun 4 20:50:49 2022 +0200
radv: Require an alignment of 64 for accel structs
Top level acceleration structures need the bottom
6 bits to store the root ids of instances. If we
don't require that alignment, more "advanced"
allocators like VMA may sub allocate a buffer
which can lead to the 6 getting lost.
Fixes the Khronos ray tracing Vulkan samples.
Closes: #6598
Signed-off-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16870>
---
src/amd/vulkan/radv_device.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 830516c157d..752683075f5 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -5043,9 +5043,8 @@ radv_InvalidateMappedMemoryRanges(VkDevice _device, uint32_t memoryRangeCount,
}
static void
-radv_get_buffer_memory_requirements(struct radv_device *device,
- VkDeviceSize size,
- VkBufferCreateFlags flags,
+radv_get_buffer_memory_requirements(struct radv_device *device, VkDeviceSize size,
+ VkBufferCreateFlags flags, VkBufferCreateFlags usage,
VkMemoryRequirements2 *pMemoryRequirements)
{
pMemoryRequirements->memoryRequirements.memoryTypeBits =
@@ -5056,6 +5055,14 @@ radv_get_buffer_memory_requirements(struct radv_device *device,
else
pMemoryRequirements->memoryRequirements.alignment = 16;
+ /* Top level acceleration structures need the bottom 6 bits to store
+ * the root ids of instances. The hardware also needs bvh nodes to
+ * be 64 byte aligned.
+ */
+ if (usage & VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR)
+ pMemoryRequirements->memoryRequirements.alignment =
+ MAX2(pMemoryRequirements->memoryRequirements.alignment, 64);
+
pMemoryRequirements->memoryRequirements.size =
align64(size, pMemoryRequirements->memoryRequirements.alignment);
@@ -5082,7 +5089,7 @@ radv_GetBufferMemoryRequirements2(VkDevice _device, const VkBufferMemoryRequirem
RADV_FROM_HANDLE(radv_buffer, buffer, pInfo->buffer);
radv_get_buffer_memory_requirements(device, buffer->vk.size, buffer->vk.create_flags,
- pMemoryRequirements);
+ buffer->vk.usage, pMemoryRequirements);
}
VKAPI_ATTR void VKAPI_CALL
@@ -5093,7 +5100,7 @@ radv_GetDeviceBufferMemoryRequirements(VkDevice _device,
RADV_FROM_HANDLE(radv_device, device, _device);
radv_get_buffer_memory_requirements(device, pInfo->pCreateInfo->size, pInfo->pCreateInfo->flags,
- pMemoryRequirements);
+ pInfo->pCreateInfo->usage, pMemoryRequirements);
}
VKAPI_ATTR void VKAPI_CALL
More information about the mesa-commit
mailing list