X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fmemoryallocator.cpp;h=82155faf41624ef03829cd994ebbbfc2eab246ab;hb=4795cdfc7936ac89da46f4d6f9de33fd481933a4;hp=227b54b6595904041cdff1d77c81b6944e0fa3b2;hpb=738e2879b3cc64a7200f64e7a838704db82550b4;p=libs%2Fgl.git diff --git a/source/backends/vulkan/memoryallocator.cpp b/source/backends/vulkan/memoryallocator.cpp index 227b54b6..82155faf 100644 --- a/source/backends/vulkan/memoryallocator.cpp +++ b/source/backends/vulkan/memoryallocator.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "device.h" #include "error.h" #include "memoryallocator.h" @@ -54,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::iterator MemoryAllocator::lower_bound_by_size(vector &indices, size_t size) +vector::iterator MemoryAllocator::lower_bound_by_size(vector &indices, size_t size) const { return lower_bound(indices, size, [this](unsigned j, unsigned s){ return blocks[j].size(i)) + { + total_heap += regions[j].size; + pool_debug += format(" Region %d: %d kB", j, (regions[j].size+512)/1024); + if(regions[j].direct) + pool_debug += ", direct"; + pool_debug += '\n'; + + int block_index = -1; + for(unsigned k=0; (block_index<0 && k(j) && blocks[k].offset==0) + block_index = k; + + unsigned slice_index = 0; + unsigned slice_data = 0; + + string bar = " ["; + string region_debug; + StringCodec::Utf8::Encoder bar_enc; + while(block_index>=0) + { + const Block &block = blocks[block_index]; + if(block.allocated) + total_used += block.size; + const char *state_str = (block.allocated ? "allocated" : "free"); + region_debug += format(" Block %d: %d bytes at %d, %s\n", block_index, block.size, block.offset, state_str); + block_index = block.next; + + size_t block_end = block.offset+block.size; + while(1) + { + size_t slice_end = regions[j].size*(slice_index+1)/140; + slice_data |= 1<<(block.allocated+slice_index%2*2); + if(slice_end>block_end) + break; + ++slice_index; + if(slice_index%2==0) + { + slice_data = 5+((slice_data>>1)&5)-(slice_data&5); + bar_enc.encode_char(bar_chars[(slice_data&3)+3*((slice_data>>2)&3)], bar); + slice_data = 0; + } + } + } + + bar += "]\n"; + if(!regions[j].direct) + pool_debug += bar; + pool_debug += region_debug; + } + + if(!pool_debug.empty()) + { + MemoryType t = pool.type; + const char *type_str = (t==DEVICE_MEMORY ? "device" : t==STAGING_MEMORY ? "staging" : + t==STREAMING_MEMORY ? "streaming" : "unknown"); + debug += format("Pool %d: %s, %d/%d kB used\n", i, type_str, (total_used+512)/1024, (total_heap+512)/1024); + debug += pool_debug; + } + + if(!pool.free_blocks.empty()) + { + debug += " Free blocks:\n"; + for(unsigned j: pool.free_blocks) + { + const char *type = (blocks[j].type==BUFFER ? "buffer" : blocks[j].type==IMAGE ? "image" : "undecided"); + debug += format(" Block %d: %d bytes, %s\n", j, blocks[j].size, type); + } + } + } + + return debug; +} + } // namespace GL } // namespace Msp