Browse Source

vulkan: use temporary pipeline cache

niki 2 years ago
parent
commit
a2466a4a1b
2 changed files with 18 additions and 6 deletions
  1. 16 6
      src/modules/graphics/vulkan/Graphics.cpp
  2. 2 0
      src/modules/graphics/vulkan/Graphics.h

+ 16 - 6
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<Texture*>(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<Texture*>(rts.depthStencil.texture)->getMsaaSamples() };
+		renderPassConfiguration.staticData.depthAttachment = {
+			Vulkan::getTextureFormat(rts.depthStencil.texture->getPixelFormat(), false).internalFormat,
+			false,
+			dynamic_cast<Texture*>(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);

+ 2 - 0
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<VkFramebuffer> defaultFramebuffers;
 	std::unordered_map<RenderPassConfiguration, VkRenderPass, RenderPassConfigurationHasher> renderPasses;
 	std::unordered_map<FramebufferConfiguration, VkFramebuffer, FramebufferConfigurationHasher> framebuffers;