summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2022-10-23 01:18:47 -0400
committerGitHub <noreply@github.com>2022-10-23 01:18:47 -0400
commit06bd0a908692f61702a483c51c93fadb2ed7eefc (patch)
treedbfa5f3b73e9d58ae5f0a61a30549f9d0ab3e30f /Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
parent8ec1bb6be5b7626b5801e502cb8f647ce5370de7 (diff)
parentaa1679f2c7428720d6ded0c69668311b552c60d4 (diff)
Merge pull request #11132 from K0bin/vma
Vulkan: Use VMA for memory allocations
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp51
1 files changed, 15 insertions, 36 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp b/Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
index 3138a31602..a182bd8483 100644
--- a/Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKBoundingBox.cpp
@@ -20,8 +20,7 @@ VKBoundingBox::~VKBoundingBox()
{
if (m_gpu_buffer != VK_NULL_HANDLE)
{
- vkDestroyBuffer(g_vulkan_context->GetDevice(), m_gpu_buffer, nullptr);
- vkFreeMemory(g_vulkan_context->GetDevice(), m_gpu_memory, nullptr);
+ vmaDestroyBuffer(g_vulkan_context->GetMemoryAllocator(), m_gpu_buffer, m_gpu_allocation);
}
}
@@ -118,47 +117,27 @@ bool VKBoundingBox::CreateGPUBuffer()
nullptr // const uint32_t* pQueueFamilyIndices
};
- VkBuffer buffer;
- VkResult res = vkCreateBuffer(g_vulkan_context->GetDevice(), &info, nullptr, &buffer);
- if (res != VK_SUCCESS)
- {
- LOG_VULKAN_ERROR(res, "vkCreateBuffer failed: ");
- return false;
- }
-
- VkMemoryRequirements memory_requirements;
- vkGetBufferMemoryRequirements(g_vulkan_context->GetDevice(), buffer, &memory_requirements);
-
- uint32_t memory_type_index = g_vulkan_context
- ->GetMemoryType(memory_requirements.memoryTypeBits,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, false)
- .value_or(0);
- VkMemoryAllocateInfo memory_allocate_info = {
- VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType
- nullptr, // const void* pNext
- memory_requirements.size, // VkDeviceSize allocationSize
- memory_type_index // uint32_t memoryTypeIndex
- };
- VkDeviceMemory memory;
- res = vkAllocateMemory(g_vulkan_context->GetDevice(), &memory_allocate_info, nullptr, &memory);
- if (res != VK_SUCCESS)
- {
- LOG_VULKAN_ERROR(res, "vkAllocateMemory failed: ");
- vkDestroyBuffer(g_vulkan_context->GetDevice(), buffer, nullptr);
- return false;
- }
+ VmaAllocationCreateInfo alloc_create_info = {};
+ alloc_create_info.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
+ alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
+ alloc_create_info.pool = VK_NULL_HANDLE;
+ alloc_create_info.pUserData = nullptr;
+ alloc_create_info.priority = 0.0;
+ alloc_create_info.requiredFlags = 0;
+ alloc_create_info.preferredFlags = 0;
- res = vkBindBufferMemory(g_vulkan_context->GetDevice(), buffer, memory, 0);
+ VkBuffer buffer;
+ VmaAllocation alloc;
+ VkResult res = vmaCreateBuffer(g_vulkan_context->GetMemoryAllocator(), &info, &alloc_create_info,
+ &buffer, &alloc, nullptr);
if (res != VK_SUCCESS)
{
- LOG_VULKAN_ERROR(res, "vkBindBufferMemory failed: ");
- vkDestroyBuffer(g_vulkan_context->GetDevice(), buffer, nullptr);
- vkFreeMemory(g_vulkan_context->GetDevice(), memory, nullptr);
+ LOG_VULKAN_ERROR(res, "vmaCreateBuffer failed: ");
return false;
}
m_gpu_buffer = buffer;
- m_gpu_memory = memory;
+ m_gpu_allocation = alloc;
return true;
}