From 8072cc8f20b51c7a3320d1dc4b6d235365198590 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Wed, 28 Jul 2021 12:20:02 +0300 Subject: [PATCH] anv: move GetBufferMemoryRequirement with other buffer functions Signed-off-by: Lionel Landwerlin Reviewed-by: Jason Ekstrand Part-of: --- src/intel/vulkan/anv_device.c | 108 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index ef21574a366..090830e7a2e 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -4076,60 +4076,6 @@ VkResult anv_InvalidateMappedMemoryRanges( return VK_SUCCESS; } -void anv_GetBufferMemoryRequirements2( - VkDevice _device, - const VkBufferMemoryRequirementsInfo2* pInfo, - VkMemoryRequirements2* pMemoryRequirements) -{ - ANV_FROM_HANDLE(anv_device, device, _device); - ANV_FROM_HANDLE(anv_buffer, buffer, pInfo->buffer); - - /* The Vulkan spec (git aaed022) says: - * - * memoryTypeBits is a bitfield and contains one bit set for every - * supported memory type for the resource. The bit `1<physical->memory.type_count) - 1; - - /* Base alignment requirement of a cache line */ - uint32_t alignment = 16; - - if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) - alignment = MAX2(alignment, ANV_UBO_ALIGNMENT); - - pMemoryRequirements->memoryRequirements.size = buffer->size; - pMemoryRequirements->memoryRequirements.alignment = alignment; - - /* Storage and Uniform buffers should have their size aligned to - * 32-bits to avoid boundary checks when last DWord is not complete. - * This would ensure that not internal padding would be needed for - * 16-bit types. - */ - if (device->robust_buffer_access && - (buffer->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT || - buffer->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) - pMemoryRequirements->memoryRequirements.size = align_u64(buffer->size, 4); - - pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types; - - vk_foreach_struct(ext, pMemoryRequirements->pNext) { - switch (ext->sType) { - case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: { - VkMemoryDedicatedRequirements *requirements = (void *)ext; - requirements->prefersDedicatedAllocation = false; - requirements->requiresDedicatedAllocation = false; - break; - } - - default: - anv_debug_ignored_stype(ext->sType); - break; - } - } -} - void anv_GetDeviceMemoryCommitment( VkDevice device, VkDeviceMemory memory, @@ -4262,6 +4208,60 @@ VkResult anv_ResetEvent( // Buffer functions +void anv_GetBufferMemoryRequirements2( + VkDevice _device, + const VkBufferMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + ANV_FROM_HANDLE(anv_buffer, buffer, pInfo->buffer); + + /* The Vulkan spec (git aaed022) says: + * + * memoryTypeBits is a bitfield and contains one bit set for every + * supported memory type for the resource. The bit `1<physical->memory.type_count) - 1; + + /* Base alignment requirement of a cache line */ + uint32_t alignment = 16; + + if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) + alignment = MAX2(alignment, ANV_UBO_ALIGNMENT); + + pMemoryRequirements->memoryRequirements.size = buffer->size; + pMemoryRequirements->memoryRequirements.alignment = alignment; + + /* Storage and Uniform buffers should have their size aligned to + * 32-bits to avoid boundary checks when last DWord is not complete. + * This would ensure that not internal padding would be needed for + * 16-bit types. + */ + if (device->robust_buffer_access && + (buffer->usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT || + buffer->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) + pMemoryRequirements->memoryRequirements.size = align_u64(buffer->size, 4); + + pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types; + + vk_foreach_struct(ext, pMemoryRequirements->pNext) { + switch (ext->sType) { + case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: { + VkMemoryDedicatedRequirements *requirements = (void *)ext; + requirements->prefersDedicatedAllocation = false; + requirements->requiresDedicatedAllocation = false; + break; + } + + default: + anv_debug_ignored_stype(ext->sType); + break; + } + } +} + VkResult anv_CreateBuffer( VkDevice _device, const VkBufferCreateInfo* pCreateInfo,