Fix release of Vulkan resources
This commit is contained in:
@@ -139,9 +139,9 @@ namespace openVulkanoCpp
|
||||
void GraphicsAppManager::ShutDown()
|
||||
{
|
||||
Logger::MANAGER->info("Shutting down ...");
|
||||
app->Close();
|
||||
renderer->Close();
|
||||
window->Close();
|
||||
app->Close();
|
||||
if (platform) platform->Close();
|
||||
windowTitleFormat = "";
|
||||
Logger::MANAGER->info("Shutdown complete");
|
||||
|
||||
@@ -33,6 +33,12 @@ namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
}
|
||||
|
||||
~MemoryAllocation()
|
||||
{
|
||||
if (device && memory)
|
||||
device.free(memory);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t FreeSpace() const
|
||||
{
|
||||
return size - used;
|
||||
|
||||
@@ -79,11 +79,21 @@ namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
device.freeCommandBuffers(cmdPools[i], 1, &cmdBuffers[i]);
|
||||
device.destroyCommandPool(cmdPools[i]);
|
||||
device.destroy(semaphores[i]);
|
||||
}
|
||||
cmdPools = nullptr;
|
||||
cmdBuffers = nullptr;
|
||||
semaphores = nullptr;
|
||||
device.destroyDescriptorPool(descriptorPool);
|
||||
allocations.clear();
|
||||
lastAllocation = nullptr;
|
||||
toFree.clear();
|
||||
recycleBuffers.clear();
|
||||
descriptorSetLayoutCache.clear();
|
||||
shaders.clear();
|
||||
cmdBuffers = nullptr;
|
||||
cmdPools = nullptr;
|
||||
transferQueue = nullptr;
|
||||
device = nullptr;
|
||||
}
|
||||
|
||||
@@ -311,18 +321,18 @@ namespace openVulkanoCpp::Vulkan
|
||||
MemoryAllocation* alloc = new MemoryAllocation(size, type, device);
|
||||
const vk::MemoryAllocateInfo allocInfo = { size, type };
|
||||
alloc->memory = device.allocateMemory(allocInfo);
|
||||
if (addToCache) allocations.push_back(alloc);
|
||||
if (addToCache) allocations.emplace_back(alloc);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
MemoryAllocation* ResourceManager::GetFreeMemoryAllocation(size_t size, uint32_t type, bool createIfAllFull)
|
||||
{
|
||||
MemoryAllocation* alloc = nullptr;
|
||||
for (MemoryAllocation* allocation : allocations)
|
||||
for (auto& allocation : allocations)
|
||||
{
|
||||
if (allocation->type == type && allocation->FreeSpace() >= size)
|
||||
{
|
||||
alloc = allocation;
|
||||
alloc = allocation.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace openVulkanoCpp
|
||||
vk::CommandPool* cmdPools = nullptr;
|
||||
vk::CommandBuffer* cmdBuffers = nullptr;
|
||||
vk::Semaphore* semaphores = nullptr;
|
||||
std::vector<MemoryAllocation*> allocations;
|
||||
std::vector<std::unique_ptr<MemoryAllocation>> allocations;
|
||||
std::vector<std::unique_ptr<VulkanShader>> shaders;
|
||||
MemoryAllocation* lastAllocation = nullptr;
|
||||
std::mutex mutex;
|
||||
|
||||
Reference in New Issue
Block a user