X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fdestroyqueue.cpp;fp=source%2Fbackends%2Fvulkan%2Fdestroyqueue.cpp;h=bdfea43253418e833ca64c1865fee15bbfdd98eb;hb=99ca354f18119f82f1adeca100cd665a8f640317;hp=0000000000000000000000000000000000000000;hpb=4cd245dafe6a7ee5c93edca5aee2d146f1155309;p=libs%2Fgl.git diff --git a/source/backends/vulkan/destroyqueue.cpp b/source/backends/vulkan/destroyqueue.cpp new file mode 100644 index 00000000..bdfea432 --- /dev/null +++ b/source/backends/vulkan/destroyqueue.cpp @@ -0,0 +1,71 @@ +#include "destroyqueue.h" +#include "device.h" +#include "vulkan.h" + +namespace Msp { +namespace GL { + +DestroyQueue::DestroyQueue(Device &d): + device(d) +{ } + +DestroyQueue::~DestroyQueue() +{ + while(!queue.empty()) + tick(); +} + +void DestroyQueue::destroy(VkBuffer handle, unsigned mem_id) +{ + destroy(handle, mem_id); +} + +void DestroyQueue::destroy(VkFence handle) +{ + destroy(handle); +} + +void DestroyQueue::destroy(VkFramebuffer handle) +{ + destroy(handle); +} + +void DestroyQueue::destroy(VkImageView handle) +{ + destroy(handle); +} + +void DestroyQueue::destroy(VkSemaphore handle) +{ + destroy(handle); +} + +template +void DestroyQueue::destroy(T handle, unsigned mem_id) +{ + Entry entry; + entry.handle = handle; + entry.destroy_func = [](const VulkanFunctions &vk, void *h){ (vk.*destroy_func)(static_cast(h)); }; + entry.memory_id = mem_id; + entry.on_frame = current_frame+MAX_FRAMES_IN_FLIGHT; + queue.push_back(entry); +} + +void DestroyQueue::tick() +{ + const VulkanFunctions &vk = device.get_functions(); + MemoryAllocator &allocator = device.get_allocator(); + + ++current_frame; + while(!queue.empty() && current_frame>=queue.front().on_frame) + { + const Entry &e = queue.front(); + e.destroy_func(vk, e.handle); + if(e.memory_id) + allocator.release(e.memory_id); + queue.pop_front(); + } +} + +} // namespace GL +} // namespace Msp