Tracking and cleaning up Vulkan objects
To keep things under control, we must carefully collect and recycle all our previously allocated Vulkan objects. In this recipe, we will learn how to keep track of allocated Vulkan objects and deallocate them properly at the end of our application.
Getting ready
Since Vulkan is an asynchronous interface, there must be a way to synchronize operations and ensure they complete. One of these synchronization objects is a semaphore. Here, we are declaring a helper function to create a semaphore:
VkResult createSemaphore(Â Â VkDevice device, VkSemaphore* outSemaphore) { Â Â const VkSemaphoreCreateInfo ci = {Â Â Â Â .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO }; Â Â return vkCreateSemaphore(Â Â Â Â device, &ci, nullptr, outSemaphore); }
Now, we can go ahead and use this function in this recipe.
How to do it...
Let's make the ad hoc approach to Vulkan initialization...