Cleanup memory pool data on close

This commit is contained in:
Georg Hagen
2024-07-11 16:56:26 +02:00
parent 0fda5a0241
commit 888e30193b
3 changed files with 24 additions and 8 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -114,6 +114,7 @@ namespace OpenVulkano::Vulkan
}
descriptorSetLayoutCache.clear();
shaders.clear();
memPool.Close();
device = nullptr;
}