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(VkDescriptorPool handle)
25 destroy<VkDescriptorPool, &VulkanFunctions::DestroyDescriptorPool>(handle);
28 void DestroyQueue::destroy(VkFence handle)
30 destroy<VkFence, &VulkanFunctions::DestroyFence>(handle);
33 void DestroyQueue::destroy(VkFramebuffer handle)
35 destroy<VkFramebuffer, &VulkanFunctions::DestroyFramebuffer>(handle);
38 void DestroyQueue::destroy(VkImage handle, unsigned mem_id)
40 destroy<VkImage, &VulkanFunctions::DestroyImage>(handle, mem_id);
43 void DestroyQueue::destroy(VkImageView handle)
45 destroy<VkImageView, &VulkanFunctions::DestroyImageView>(handle);
48 void DestroyQueue::destroy(VkSampler handle)
50 destroy<VkSampler, &VulkanFunctions::DestroySampler>(handle);
53 void DestroyQueue::destroy(VkSemaphore handle)
55 destroy<VkSemaphore, &VulkanFunctions::DestroySemaphore>(handle);
58 template<typename T, void (VulkanFunctions::*destroy_func)(T) const>
59 void DestroyQueue::destroy(T handle, unsigned mem_id)
62 entry.handle = handle;
63 entry.destroy_func = [](const VulkanFunctions &vk, void *h){ (vk.*destroy_func)(static_cast<T>(h)); };
64 entry.memory_id = mem_id;
65 entry.on_frame = current_frame+MAX_FRAMES_IN_FLIGHT;
66 queue.push_back(entry);
69 void DestroyQueue::tick()
71 const VulkanFunctions &vk = device.get_functions();
72 MemoryAllocator &allocator = device.get_allocator();
74 while(!queue.empty() && current_frame>=queue.front().on_frame)
76 const Entry &e = queue.front();
77 e.destroy_func(vk, e.handle);
79 allocator.release(e.memory_id);