From aac66a1b61a0e4c1c2b85d89bc818a8b521bcffa Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 13 Nov 2016 18:39:06 +1000 Subject: Vulkan: Implement a pipeline UID cache This stores enough information to recreate the pipeline, including the shader UIDs, blend/depth/rasterization state, primitive and vertex format. --- Source/Core/VideoBackends/Vulkan/ObjectCache.cpp | 28 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoBackends/Vulkan/ObjectCache.cpp') diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp index 61e685874a..ecfc73c76e 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp @@ -159,12 +159,8 @@ GetVulkanColorBlendState(const BlendState& state, return vk_state; } -VkPipeline ObjectCache::GetPipeline(const PipelineInfo& info) +VkPipeline ObjectCache::CreatePipeline(const PipelineInfo& info) { - auto iter = m_pipeline_objects.find(info); - if (iter != m_pipeline_objects.end()) - return iter->second; - // Declare descriptors for empty vertex buffers/attributes static const VkPipelineVertexInputStateCreateInfo empty_vertex_input_state = { VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType @@ -278,16 +274,34 @@ VkPipeline ObjectCache::GetPipeline(const PipelineInfo& info) -1 // int32_t basePipelineIndex }; - VkPipeline pipeline = VK_NULL_HANDLE; + VkPipeline pipeline; VkResult res = vkCreateGraphicsPipelines(g_vulkan_context->GetDevice(), m_pipeline_cache, 1, &pipeline_info, nullptr, &pipeline); if (res != VK_SUCCESS) + { LOG_VULKAN_ERROR(res, "vkCreateGraphicsPipelines failed: "); + return VK_NULL_HANDLE; + } - m_pipeline_objects.emplace(info, pipeline); return pipeline; } +VkPipeline ObjectCache::GetPipeline(const PipelineInfo& info) +{ + return GetPipelineWithCacheResult(info).first; +} + +std::pair ObjectCache::GetPipelineWithCacheResult(const PipelineInfo& info) +{ + auto iter = m_pipeline_objects.find(info); + if (iter != m_pipeline_objects.end()) + return {iter->second, true}; + + VkPipeline pipeline = CreatePipeline(info); + m_pipeline_objects.emplace(info, pipeline); + return {pipeline, false}; +} + std::string ObjectCache::GetDiskCacheFileName(const char* type) { return StringFromFormat("%svulkan-%s-%s.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), -- cgit v1.2.3