]> git.tdb.fi Git - libs/gl.git/commitdiff
Minor tweaks to MemoryAllocator
authorMikko Rasa <tdb@tdb.fi>
Tue, 8 Mar 2022 13:58:57 +0000 (15:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 8 Mar 2022 13:58:57 +0000 (15:58 +0200)
source/backends/vulkan/memoryallocator.cpp
source/backends/vulkan/memoryallocator.h

index 4b3595b64df8b9d6f61c9922d005a54a59b65f5e..82155faf41624ef03829cd994ebbbfc2eab246ab 100644 (file)
@@ -56,7 +56,7 @@ MemoryAllocator::~MemoryAllocator()
                        vk.FreeMemory(r.memory);
 }
 
-unsigned MemoryAllocator::find_memory_pool(unsigned mask, MemoryType type)
+unsigned MemoryAllocator::find_memory_pool(unsigned mask, MemoryType type) const
 {
        for(unsigned i=0; i<pools.size(); ++i)
                if((mask&(1<<i)) && pools[i].type==type)
@@ -86,7 +86,7 @@ unsigned MemoryAllocator::create_region(unsigned pool_index, size_t size, bool d
        return regions.size()-1;
 }
 
-vector<unsigned>::iterator MemoryAllocator::lower_bound_by_size(vector<unsigned> &indices, size_t size)
+vector<unsigned>::iterator MemoryAllocator::lower_bound_by_size(vector<unsigned> &indices, size_t size) const
 {
        return lower_bound(indices, size, [this](unsigned j, unsigned s){ return blocks[j].size<s; });
 }
@@ -131,7 +131,7 @@ unsigned MemoryAllocator::allocate(size_t size, size_t align, unsigned type_bits
        {
                Block block;
                block.region = create_region(pool_index, default_region_size, false);
-               block.size = default_region_size;
+               block.size = regions[block.region].size;
 
                blocks.push_back(block);
                block_index = blocks.size()-1;
index 3e1861bae0fa9b6f088d044babb2460891c2f09c..0b185585e89e14bab48536449c7c68c8d1bbcfd3 100644 (file)
@@ -64,9 +64,9 @@ public:
        ~MemoryAllocator();
 
 private:
-       unsigned find_memory_pool(unsigned, MemoryType);
+       unsigned find_memory_pool(unsigned, MemoryType) const;
        unsigned create_region(unsigned, size_t, bool);
-       std::vector<unsigned>::iterator lower_bound_by_size(std::vector<unsigned> &, std::size_t);
+       std::vector<unsigned>::iterator lower_bound_by_size(std::vector<unsigned> &, std::size_t) const;
        unsigned allocate(std::size_t, std::size_t, unsigned, MemoryType);
        unsigned split_block(unsigned, std::size_t);
        void consolidate(unsigned);