1 #include "destroyqueue.h"
8 DestroyQueue::DestroyQueue(Device &d):
12 DestroyQueue::~DestroyQueue()
18 void DestroyQueue::destroy(VkBuffer handle, unsigned mem_id)
20 destroy<VkBuffer, &VulkanFunctions::DestroyBuffer>(handle, mem_id);
23 void DestroyQueue::destroy(VkFence handle)
25 destroy<VkFence, &VulkanFunctions::DestroyFence>(handle);
28 void DestroyQueue::destroy(VkFramebuffer handle)
30 destroy<VkFramebuffer, &VulkanFunctions::DestroyFramebuffer>(handle);
33 void DestroyQueue::destroy(VkImage handle, unsigned mem_id)
35 destroy<VkImage, &VulkanFunctions::DestroyImage>(handle, mem_id);
38 void DestroyQueue::destroy(VkImageView handle)
40 destroy<VkImageView, &VulkanFunctions::DestroyImageView>(handle);
43 void DestroyQueue::destroy(VkSampler handle)
45 destroy<VkSampler, &VulkanFunctions::DestroySampler>(handle);
48 void DestroyQueue::destroy(VkSemaphore handle)
50 destroy<VkSemaphore, &VulkanFunctions::DestroySemaphore>(handle);
53 template<typename T, void (VulkanFunctions::*destroy_func)(T) const>
54 void DestroyQueue::destroy(T handle, unsigned mem_id)
57 entry.handle = handle;
58 entry.destroy_func = [](const VulkanFunctions &vk, void *h){ (vk.*destroy_func)(static_cast<T>(h)); };
59 entry.memory_id = mem_id;
60 entry.on_frame = current_frame+MAX_FRAMES_IN_FLIGHT;
61 queue.push_back(entry);
64 void DestroyQueue::tick()
66 const VulkanFunctions &vk = device.get_functions();
67 MemoryAllocator &allocator = device.get_allocator();
70 while(!queue.empty() && current_frame>=queue.front().on_frame)
72 const Entry &e = queue.front();
73 e.destroy_func(vk, e.handle);
75 allocator.release(e.memory_id);