VulkanExampleBase::~VulkanExampleBase() { // Clean up Vulkan resources swapChain.cleanup(); if (descriptorPool != VK_NULL_HANDLE) { vkDestroyDescriptorPool(device, descriptorPool, nullptr); } if (setupCmdBuffer != VK_NULL_HANDLE) { vkFreeCommandBuffers(device, cmdPool, 1, &setupCmdBuffer); } destroyCommandBuffers(); vkDestroyRenderPass(device, renderPass, nullptr); for (uint32_t i = 0; i < frameBuffers.size(); i++) { vkDestroyFramebuffer(device, frameBuffers[i], nullptr); } for (auto& shaderModule : shaderModules) { vkDestroyShaderModule(device, shaderModule, nullptr); } vkDestroyImageView(device, depthStencil.view, nullptr); vkDestroyImage(device, depthStencil.image, nullptr); vkFreeMemory(device, depthStencil.mem, nullptr); vkDestroyPipelineCache(device, pipelineCache, nullptr); if (textureLoader) { delete textureLoader; } vkDestroyCommandPool(device, cmdPool, nullptr); vkDestroySemaphore(device, semaphores.presentComplete, nullptr); vkDestroySemaphore(device, semaphores.renderComplete, nullptr); vkDestroyDevice(device, nullptr); if (enableValidation) { vkDebug::freeDebugCallback(instance); } vkDestroyInstance(instance, nullptr); #if defined(__linux) #if defined(__ANDROID__) // todo : android cleanup (if required) #else xcb_destroy_window(connection, window); xcb_disconnect(connection); #endif #endif }
void FVulkanPipeline::Destroy() { if (Pipeline) { #if !VULKAN_ENABLE_PIPELINE_CACHE check(PipelineCache); vkDestroyPipelineCache(Device->GetInstanceHandle(), PipelineCache, nullptr); PipelineCache = VK_NULL_HANDLE; #endif vkDestroyPipeline(Device->GetInstanceHandle(), Pipeline, nullptr); Pipeline = VK_NULL_HANDLE; } }
void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info) { VkPipelineCache cache; VkPipelineCacheCreateInfo ci; memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); if (err == VK_SUCCESS) { NON_DISPATCHABLE_HANDLE_INIT(vkCreateComputePipelines, dev, cache, 1, &info); vkDestroyPipelineCache(dev.handle(), cache, NULL); } }
/** * Default destructor, frees up all Vulkan resources acquired by the text overlay */ ~VulkanTextOverlay() { // Free up all Vulkan resources requested by the text overlay vertexBuffer.destroy(); vkDestroySampler(vulkanDevice->logicalDevice, sampler, nullptr); vkDestroyImage(vulkanDevice->logicalDevice, image, nullptr); vkDestroyImageView(vulkanDevice->logicalDevice, view, nullptr); vkFreeMemory(vulkanDevice->logicalDevice, imageMemory, nullptr); vkDestroyDescriptorSetLayout(vulkanDevice->logicalDevice, descriptorSetLayout, nullptr); vkDestroyDescriptorPool(vulkanDevice->logicalDevice, descriptorPool, nullptr); vkDestroyPipelineLayout(vulkanDevice->logicalDevice, pipelineLayout, nullptr); vkDestroyPipelineCache(vulkanDevice->logicalDevice, pipelineCache, nullptr); vkDestroyPipeline(vulkanDevice->logicalDevice, pipeline, nullptr); vkDestroyRenderPass(vulkanDevice->logicalDevice, renderPass, nullptr); vkFreeCommandBuffers(vulkanDevice->logicalDevice, commandPool, static_cast<uint32_t>(cmdBuffers.size()), cmdBuffers.data()); vkDestroyCommandPool(vulkanDevice->logicalDevice, commandPool, nullptr); vkDestroyFence(vulkanDevice->logicalDevice, fence, nullptr); }
VkResult Pipeline::init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { VkPipeline pipe; VkPipelineCache cache; VkPipelineCacheCreateInfo ci; memset((void *)&ci, 0, sizeof(VkPipelineCacheCreateInfo)); ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; VkResult err = vkCreatePipelineCache(dev.handle(), &ci, NULL, &cache); EXPECT(err == VK_SUCCESS); if (err == VK_SUCCESS) { err = vkCreateGraphicsPipelines(dev.handle(), cache, 1, &info, NULL, &pipe); if (err == VK_SUCCESS) { NonDispHandle::init(dev.handle(), pipe); } vkDestroyPipelineCache(dev.handle(), cache, NULL); } return err; }
VulkanBase::~VulkanBase() { swapChain.cleanup(); vkDestroyDescriptorPool(device, descriptorPool, nullptr); if (setupCmdBuffer != VK_NULL_HANDLE) vkFreeCommandBuffers(device, cmdPool, 1, &setupCmdBuffer); destroyCommandBuffers(); vkDestroyRenderPass(device, renderPass, nullptr); for (uint32_t i = 0; i < frameBuffers.size(); i++) vkDestroyFramebuffer(device, frameBuffers[i], nullptr); for (auto& shaderModule : shaderModules) vkDestroyShaderModule(device, shaderModule, nullptr); vkDestroyImageView(device, depthStencil.view, nullptr); vkDestroyImage(device, depthStencil.image, nullptr); vkFreeMemory(device, depthStencil.mem, nullptr); vkDestroyPipelineCache(device, pipelineCache, nullptr); if (textureLoader) delete textureLoader; vkDestroyCommandPool(device, cmdPool, nullptr); vkDestroySemaphore(device, semaphores.presentComplete, nullptr); vkDestroySemaphore(device, semaphores.renderComplete, nullptr); vkDestroyDevice(device, nullptr); if (enableValidation) vkDebug::freeDebugCallback(instance); vkDestroyInstance(instance, nullptr); }
void VulkanDeleteList::PerformDeletes(VkDevice device) { for (auto &cmdPool : cmdPools_) { vkDestroyCommandPool(device, cmdPool, nullptr); } cmdPools_.clear(); for (auto &descPool : descPools_) { vkDestroyDescriptorPool(device, descPool, nullptr); } descPools_.clear(); for (auto &module : modules_) { vkDestroyShaderModule(device, module, nullptr); } modules_.clear(); for (auto &buf : buffers_) { vkDestroyBuffer(device, buf, nullptr); } buffers_.clear(); for (auto &bufView : bufferViews_) { vkDestroyBufferView(device, bufView, nullptr); } bufferViews_.clear(); for (auto &image : images_) { vkDestroyImage(device, image, nullptr); } images_.clear(); for (auto &imageView : imageViews_) { vkDestroyImageView(device, imageView, nullptr); } imageViews_.clear(); for (auto &mem : deviceMemory_) { vkFreeMemory(device, mem, nullptr); } deviceMemory_.clear(); for (auto &sampler : samplers_) { vkDestroySampler(device, sampler, nullptr); } samplers_.clear(); for (auto &pipeline : pipelines_) { vkDestroyPipeline(device, pipeline, nullptr); } pipelines_.clear(); for (auto &pcache : pipelineCaches_) { vkDestroyPipelineCache(device, pcache, nullptr); } pipelineCaches_.clear(); for (auto &renderPass : renderPasses_) { vkDestroyRenderPass(device, renderPass, nullptr); } renderPasses_.clear(); for (auto &framebuffer : framebuffers_) { vkDestroyFramebuffer(device, framebuffer, nullptr); } framebuffers_.clear(); for (auto &pipeLayout : pipelineLayouts_) { vkDestroyPipelineLayout(device, pipeLayout, nullptr); } pipelineLayouts_.clear(); for (auto &descSetLayout : descSetLayouts_) { vkDestroyDescriptorSetLayout(device, descSetLayout, nullptr); } descSetLayouts_.clear(); for (auto &callback : callbacks_) { callback.func(callback.userdata); } callbacks_.clear(); }
// // Vulkan termination. // void Example::terminate(const vkts::IUpdateThreadContext& updateContext) { if (device.get()) { terminateResources(updateContext); // if (swapchain.get()) { swapchain->destroy(); } if (pipelineLayout != VK_NULL_HANDLE) { vkDestroyPipelineLayout(device->getDevice(), pipelineLayout, nullptr); pipelineLayout = VK_NULL_HANDLE; } if (pipelineCache != VK_NULL_HANDLE) { vkDestroyPipelineCache(device->getDevice(), pipelineCache, nullptr); pipelineCache = VK_NULL_HANDLE; } if (vertexShaderModule != VK_NULL_HANDLE) { vkDestroyShaderModule(device->getDevice(), vertexShaderModule, nullptr); vertexShaderModule = VK_NULL_HANDLE; } if (fragmentShaderModule != VK_NULL_HANDLE) { vkDestroyShaderModule(device->getDevice(), fragmentShaderModule, nullptr); fragmentShaderModule = VK_NULL_HANDLE; } if (vertexBuffer != VK_NULL_HANDLE) { vkDestroyBuffer(device->getDevice(), vertexBuffer, nullptr); vertexBuffer = VK_NULL_HANDLE; } if (deviceMemoryVertexBuffer != VK_NULL_HANDLE) { vkFreeMemory(device->getDevice(), deviceMemoryVertexBuffer, nullptr); deviceMemoryVertexBuffer = VK_NULL_HANDLE; } if (renderingCompleteSemaphore.get()) { renderingCompleteSemaphore->destroy(); } if (imageAcquiredSemaphore.get()) { imageAcquiredSemaphore->destroy(); } if (commandPool.get()) { commandPool->destroy(); } if (surface.get()) { surface->destroy(); } device->destroy(); } if (instance.get()) { instance->destroy(); } }
#include "PipelineCache.h" namespace Vulkan { PipelineCache::PipelineCache(Device* device) : Devicer(device) { createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; } PipelineCache::~PipelineCache() { destroy(); } void PipelineCache::create() { VULKAN_CHECK_RESULT(vkCreatePipelineCache(device->getHandle(), &createInfo, nullptr, &handle), "Failed to create pipeline cache"); } void PipelineCache::destroy() { VULKAN_DESTROY_HANDLE(vkDestroyPipelineCache(device->getHandle(), handle, nullptr)) } } // Vulkan
GrManagerImpl::~GrManagerImpl() { // FIRST THING: wait for the GPU if(m_queue) { LockGuard<Mutex> lock(m_globalMtx); vkQueueWaitIdle(m_queue); m_queue = VK_NULL_HANDLE; } // SECOND THING: The destroy everything that has a reference to GrObjects. for(auto& x : m_backbuffers) { if(x.m_imageView) { vkDestroyImageView(m_device, x.m_imageView, nullptr); x.m_imageView = VK_NULL_HANDLE; } } for(auto& x : m_perFrame) { x.m_presentFence.reset(nullptr); x.m_acquireSemaphore.reset(nullptr); x.m_renderSemaphore.reset(nullptr); x.m_cmdbsSubmitted.destroy(getAllocator()); } m_perThread.destroy(getAllocator()); if(m_samplerCache) { getAllocator().deleteInstance(m_samplerCache); } // THIRD THING: Continue with the rest m_rpCreator.destroy(); m_pplineLayFactory.destroy(); m_dsetAlloc.destroy(); m_transientMem.destroy(); m_gpuMemManager.destroy(); m_semaphores.destroy(); // Destroy before fences m_fences.destroy(); if(m_swapchain) { vkDestroySwapchainKHR(m_device, m_swapchain, nullptr); } if(m_pplineCache) { vkDestroyPipelineCache(m_device, m_pplineCache, nullptr); } if(m_device) { vkDestroyDevice(m_device, nullptr); } if(m_surface) { vkDestroySurfaceKHR(m_instance, m_surface, nullptr); } if(m_instance) { vkDestroyInstance(m_instance, nullptr); } }