From a2466a4a1ba69a7c0aff7260d191e4732e029264 Mon Sep 17 00:00:00 2001 From: niki Date: Sun, 22 Jan 2023 00:17:42 +0100 Subject: [PATCH] vulkan: use temporary pipeline cache --- src/modules/graphics/vulkan/Graphics.cpp | 22 ++++++++++++++++------ src/modules/graphics/vulkan/Graphics.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 8270faf28..2ee3ca231 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -493,6 +493,7 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int createSurface(); pickPhysicalDevice(); createLogicalDevice(); + createPipelineCache(); initVMA(); initCapabilities(); createSwapChain(); @@ -1573,6 +1574,15 @@ void Graphics::createLogicalDevice() vkGetDeviceQueue(device, indices.presentFamily.value, 0, &presentQueue); } +void Graphics::createPipelineCache() +{ + VkPipelineCacheCreateInfo cacheInfo{}; + cacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; + + if (vkCreatePipelineCache(device, &cacheInfo, nullptr, &pipelineCache) != VK_SUCCESS) + throw love::Exception("could not create pipeline cache"); +} + void Graphics::initVMA() { VmaAllocatorCreateInfo allocatorCreateInfo = {}; @@ -2301,11 +2311,10 @@ void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, b false, dynamic_cast(color.texture)->getMsaaSamples() }); if (rts.depthStencil.texture != nullptr) - if (rts.depthStencil.texture != nullptr) - renderPassConfiguration.staticData.depthAttachment = { - Vulkan::getTextureFormat(rts.depthStencil.texture->getPixelFormat(), false).internalFormat, - false, - dynamic_cast(rts.depthStencil.texture)->getMsaaSamples() }; + renderPassConfiguration.staticData.depthAttachment = { + Vulkan::getTextureFormat(rts.depthStencil.texture->getPixelFormat(), false).internalFormat, + false, + dynamic_cast(rts.depthStencil.texture)->getMsaaSamples() }; FramebufferConfiguration configuration{}; @@ -2648,7 +2657,7 @@ VkPipeline Graphics::createGraphicsPipeline(GraphicsPipelineConfiguration &confi pipelineInfo.renderPass = configuration.renderPass; VkPipeline graphicsPipeline; - if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) + if (vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) throw love::Exception("failed to create graphics pipeline"); return graphicsPipeline; } @@ -2934,6 +2943,7 @@ void Graphics::cleanup() graphicsPipelines.clear(); vkDestroyCommandPool(device, commandPool, nullptr); + vkDestroyPipelineCache(device, pipelineCache, nullptr); vkDestroyDevice(device, nullptr); vkDestroySurfaceKHR(instance, surface, nullptr); vkDestroyInstance(instance, nullptr); diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index 8109ed3b1..a1cb0bbf2 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -316,6 +316,7 @@ private: int rateDeviceSuitability(VkPhysicalDevice device); QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device); void createLogicalDevice(); + void createPipelineCache(); void initVMA(); void createSurface(); bool checkDeviceExtensionSupport(VkPhysicalDevice device); @@ -393,6 +394,7 @@ private: VkImageView depthImageView = VK_NULL_HANDLE; VmaAllocation depthImageAllocation = VK_NULL_HANDLE; VkRenderPass defaultRenderPass = VK_NULL_HANDLE; + VkPipelineCache pipelineCache; std::vector defaultFramebuffers; std::unordered_map renderPasses; std::unordered_map framebuffers;