Cleanup memory pool data on close
This commit is contained in:
@@ -26,16 +26,28 @@ namespace OpenVulkano::Vulkan
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
MemoryPool::MemoryPool()
|
||||
{
|
||||
freeFunction = [this](ManagedBuffer* buffer) { this->FreeBuffer(buffer); };
|
||||
MEM_POOLS.push_back(this);
|
||||
Logger::RENDER->info("Created gpu memory pool");
|
||||
}
|
||||
|
||||
MemoryPool::~MemoryPool()
|
||||
{
|
||||
if (!allocations.empty()) Close();
|
||||
}
|
||||
|
||||
void MemoryPool::Close()
|
||||
{
|
||||
Utils::Remove(MEM_POOLS, this);
|
||||
for(ManagedBuffer* buffer : recycleBuffers)
|
||||
{
|
||||
delete buffer;
|
||||
}
|
||||
recycleBuffers.clear();
|
||||
for(auto& fF : toFree)
|
||||
{
|
||||
for(ManagedBuffer* buffer : fF)
|
||||
{
|
||||
delete buffer;
|
||||
}
|
||||
fF.clear();
|
||||
}
|
||||
allocations.clear();
|
||||
Logger::RENDER->info("Destroyed gpu memory pool");
|
||||
}
|
||||
|
||||
@@ -43,6 +55,7 @@ namespace OpenVulkano::Vulkan
|
||||
{
|
||||
device = dev;
|
||||
toFree = decltype(toFree)(bufferCount);
|
||||
MEM_POOLS.push_back(this);
|
||||
}
|
||||
|
||||
void MemoryPool::StartFrame(uint64_t bufferId)
|
||||
|
||||
@@ -35,12 +35,14 @@ namespace OpenVulkano::Vulkan
|
||||
public:
|
||||
using ManagedBufferPtr = std::unique_ptr<ManagedBuffer, ManagedBufferDeleter>;
|
||||
|
||||
MemoryPool();
|
||||
MemoryPool() = default;
|
||||
|
||||
~MemoryPool();
|
||||
|
||||
void Init(Device* dev, int bufferCount);
|
||||
|
||||
void Close();
|
||||
|
||||
void StartFrame(uint64_t bufferId);
|
||||
|
||||
MemoryAllocation* CreateMemoryAllocation(size_t size, uint32_t type, bool addToCache = true);
|
||||
|
||||
@@ -114,6 +114,7 @@ namespace OpenVulkano::Vulkan
|
||||
}
|
||||
descriptorSetLayoutCache.clear();
|
||||
shaders.clear();
|
||||
memPool.Close();
|
||||
device = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user