X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fbackends%2Fvulkan%2Fmemoryallocator.cpp;h=fad6787307fa955fb15d5a9ac5d6bae2974f44a0;hb=7e48ef177b668f2ed4c0346fa268e3dbfbb63203;hp=6ef5d2bd7a6b8714fb545997819abb11e1995fa9;hpb=a16145549dc87c3b12671f797bd77b14bcc7786b;p=libs%2Fgl.git diff --git a/source/backends/vulkan/memoryallocator.cpp b/source/backends/vulkan/memoryallocator.cpp index 6ef5d2bd..fad67873 100644 --- a/source/backends/vulkan/memoryallocator.cpp +++ b/source/backends/vulkan/memoryallocator.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "device.h" #include "error.h" @@ -64,17 +65,7 @@ unsigned MemoryAllocator::allocate(size_t size, unsigned type_bits, MemoryType t alloc.size = size; allocations.push_back(alloc); - return allocations.size(); -} - -MemoryAllocator::Allocation &MemoryAllocator::get_allocation(unsigned id) -{ - return allocations[id-1]; -} - -const MemoryAllocator::Allocation &MemoryAllocator::get_allocation(unsigned id) const -{ - return allocations[id-1]; + return allocations.size()-1; } unsigned MemoryAllocator::allocate(VkBuffer buffer, MemoryType type) @@ -84,11 +75,11 @@ unsigned MemoryAllocator::allocate(VkBuffer buffer, MemoryType type) VkMemoryRequirements requirements; vk.GetBufferMemoryRequirements(buffer, requirements); - unsigned id = allocate(requirements.size, requirements.memoryTypeBits, type); + unsigned index = allocate(requirements.size, requirements.memoryTypeBits, type); - vk.BindBufferMemory(buffer, get_allocation(id).memory, 0); + vk.BindBufferMemory(buffer, allocations[index].memory, 0); - return id; + return index+1; } unsigned MemoryAllocator::allocate(VkImage image, MemoryType type) @@ -98,34 +89,29 @@ unsigned MemoryAllocator::allocate(VkImage image, MemoryType type) VkMemoryRequirements requirements; vk.GetImageMemoryRequirements(image, requirements); - unsigned id = allocate(requirements.size, requirements.memoryTypeBits, type); + unsigned index = allocate(requirements.size, requirements.memoryTypeBits, type); - vk.BindImageMemory(image, get_allocation(id).memory, 0); + vk.BindImageMemory(image, allocations[index].memory, 0); - return id; + return index+1; } void MemoryAllocator::release(unsigned id) { - Allocation &alloc = get_allocation(id); - if(!alloc.memory) - throw invalid_operation("MemoryAllocator::release"); + if(!id || id>allocations.size() || !allocations[id-1].memory) + throw key_error(id); const VulkanFunctions &vk = device.get_functions(); - vk.FreeMemory(alloc.memory); -} - -size_t MemoryAllocator::get_allocation_size(unsigned id) const -{ - return get_allocation(id).size; + vk.FreeMemory(allocations[id-1].memory); } void *MemoryAllocator::map(unsigned id, size_t offset, size_t size) { - Allocation &alloc = get_allocation(id); - if(alloc.mapped_address) - throw invalid_operation("MemoryAllocator::map"); + if(!id || id>allocations.size() || !allocations[id-1].memory) + throw key_error(id); + + Allocation &alloc = allocations[id-1]; const VulkanFunctions &vk = device.get_functions();