From 7bbc2888e29ca36b5fa8480b8bb53769a0d12b7b Mon Sep 17 00:00:00 2001 From: niki Date: Mon, 1 Aug 2022 17:38:23 +0200 Subject: [PATCH] vulkan: remove unnecessary recreation on resize --- src/modules/graphics/vulkan/Graphics.cpp | 20 ++++++++++---------- src/modules/graphics/vulkan/Graphics.h | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index e6ffe11a7..7bf9f71bb 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -469,6 +469,7 @@ void Graphics::setRenderTargetsInternal(const RenderTargets& rts, int pixelw, in if (rts.colors.size() == 0) { startRenderPass(nullptr, swapChainExtent.width, swapChainExtent.height); } else { + // fixme: multi canvas render. auto& firstRenderTarget = rts.getFirstTarget(); startRenderPass(static_cast(firstRenderTarget.texture), pixelw, pixelh); } @@ -1492,6 +1493,15 @@ void Graphics::cleanup() { vkDestroyFence(device, inFlightFences[i], nullptr); } + vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), commandBuffers.data()); + vkFreeCommandBuffers(device, commandPool, MAX_FRAMES_IN_FLIGHT, dataTransferCommandBuffers.data()); + + // fixme: maybe we should clean up some pipelines if they haven't been used in a while. + for (auto const& p : graphicsPipelines) { + vkDestroyPipeline(device, p.second, nullptr); + } + graphicsPipelines.clear(); + vkDestroyCommandPool(device, commandPool, nullptr); vkDestroyDevice(device, nullptr); vkDestroySurfaceKHR(instance, surface, nullptr); @@ -1499,14 +1509,6 @@ void Graphics::cleanup() { } void Graphics::cleanupSwapChain() { - vkDestroyDescriptorPool(device, descriptorPool, nullptr); - vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), commandBuffers.data()); - vkFreeCommandBuffers(device, commandPool, MAX_FRAMES_IN_FLIGHT, dataTransferCommandBuffers.data()); - for (auto const& p : graphicsPipelines) { - vkDestroyPipeline(device, p.second, nullptr); - } - graphicsPipelines.clear(); - currentGraphicsPipeline = VK_NULL_HANDLE; for (size_t i = 0; i < swapChainImageViews.size(); i++) { vkDestroyImageView(device, swapChainImageViews[i], nullptr); } @@ -1520,8 +1522,6 @@ void Graphics::recreateSwapChain() { createSwapChain(); createImageViews(); - createCommandBuffers(); - startRecordingGraphicsCommands(); } love::graphics::Graphics* createInstance() { diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index dc88144bc..330d6c456 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -210,7 +210,6 @@ private: VkCommandPool commandPool = VK_NULL_HANDLE; std::vector commandBuffers; std::vector dataTransferCommandBuffers; - VkDescriptorPool descriptorPool = VK_NULL_HANDLE; std::vector imageAvailableSemaphores; std::vector renderFinishedSemaphores; std::vector inFlightFences;