1 #ifndef MSP_GL_VULKAN_MEMORYALLOCATOR_H_
2 #define MSP_GL_VULKAN_MEMORYALLOCATOR_H_
5 #include <msp/core/noncopyable.h>
6 #include <msp/graphics/vulkancontext.h>
22 class MemoryAllocator: public NonCopyable
27 MemoryType type = UNKNOWN_MEMORY;
28 std::vector<unsigned> free_blocks;
29 bool can_consolidate = false;
36 VkDeviceMemory memory = 0;
38 void *mapped_address = 0;
39 unsigned map_count = 0;
45 bool allocated = false;
46 std::size_t offset = 0;
53 VkPhysicalDevice phys_device;
54 std::size_t total_device_memory = 0;
55 std::size_t default_region_size = 0;
56 std::size_t direct_alloc_threshold = 0;
57 std::size_t min_alignment = 256;
58 std::vector<Pool> pools;
59 std::vector<Region> regions;
60 std::vector<Block> blocks;
63 MemoryAllocator(Device &);
67 unsigned find_memory_pool(unsigned, MemoryType);
68 unsigned create_region(unsigned, size_t, bool);
69 std::vector<unsigned>::iterator lower_bound_by_size(std::vector<unsigned> &, std::size_t);
70 unsigned allocate(std::size_t, std::size_t, unsigned, MemoryType);
71 unsigned split_block(unsigned, std::size_t);
72 void consolidate(unsigned);
73 void merge_block_with_next(unsigned);
76 unsigned allocate(VkBuffer, MemoryType);
77 unsigned allocate(VkImage, MemoryType);
78 void release(unsigned);