X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fmemoryallocator.h;h=3e1861bae0fa9b6f088d044babb2460891c2f09c;hb=b0f143b4db544a582b6fb77236e20ed72d2284cb;hp=fee4726be95f9fde3b50471aad720511642695f8;hpb=7e48ef177b668f2ed4c0346fa268e3dbfbb63203;p=libs%2Fgl.git diff --git a/source/backends/vulkan/memoryallocator.h b/source/backends/vulkan/memoryallocator.h index fee4726b..3e1861ba 100644 --- a/source/backends/vulkan/memoryallocator.h +++ b/source/backends/vulkan/memoryallocator.h @@ -2,6 +2,7 @@ #define MSP_GL_VULKAN_MEMORYALLOCATOR_H_ #include +#include #include #include "handles.h" @@ -18,36 +19,68 @@ enum MemoryType STREAMING_MEMORY }; -class MemoryAllocator +class MemoryAllocator: public NonCopyable { private: - struct Allocation + struct Pool { - VkDeviceMemory memory = 0; MemoryType type = UNKNOWN_MEMORY; + std::vector free_blocks; + bool can_consolidate = false; + }; + + struct Region + { + int pool = -1; + bool direct = false; + VkDeviceMemory memory = 0; std::size_t size = 0; void *mapped_address = 0; + unsigned map_count = 0; + }; + + struct Block + { + int region = -1; + bool allocated = false; + std::size_t offset = 0; + std::size_t size = 0; + int prev = -1; + int next = -1; }; Device &device; VkPhysicalDevice phys_device; - std::vector memory_types; - std::vector allocations; + std::size_t total_device_memory = 0; + std::size_t default_region_size = 0; + std::size_t direct_alloc_threshold = 0; + std::size_t min_alignment = 256; + std::vector pools; + std::vector regions; + std::vector blocks; public: MemoryAllocator(Device &); + ~MemoryAllocator(); private: - unsigned find_memory_type_index(unsigned, MemoryType); - unsigned allocate(std::size_t, unsigned, MemoryType); + unsigned find_memory_pool(unsigned, MemoryType); + unsigned create_region(unsigned, size_t, bool); + std::vector::iterator lower_bound_by_size(std::vector &, std::size_t); + unsigned allocate(std::size_t, std::size_t, unsigned, MemoryType); + unsigned split_block(unsigned, std::size_t); + void consolidate(unsigned); + void merge_block_with_next(unsigned); public: unsigned allocate(VkBuffer, MemoryType); unsigned allocate(VkImage, MemoryType); void release(unsigned); - void *map(unsigned, std::size_t, std::size_t); - void unmap(void *); + void *map(unsigned); + void unmap(unsigned); + + std::string get_debug() const; }; } // namespace GL