diff options
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 39 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.h | 5 |
2 files changed, 28 insertions, 16 deletions
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 7bded3ec5..67e5bc648 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -366,7 +366,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device | |||
| 366 | 366 | ||
| 367 | PipelineCache::~PipelineCache() { | 367 | PipelineCache::~PipelineCache() { |
| 368 | if (use_vulkan_pipeline_cache && !vulkan_pipeline_cache_filename.empty()) { | 368 | if (use_vulkan_pipeline_cache && !vulkan_pipeline_cache_filename.empty()) { |
| 369 | SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache); | 369 | SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache, |
| 370 | CACHE_VERSION); | ||
| 370 | } | 371 | } |
| 371 | } | 372 | } |
| 372 | 373 | ||
| @@ -426,7 +427,8 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading | |||
| 426 | 427 | ||
| 427 | if (use_vulkan_pipeline_cache) { | 428 | if (use_vulkan_pipeline_cache) { |
| 428 | vulkan_pipeline_cache_filename = base_dir / "vulkan_pipelines.bin"; | 429 | vulkan_pipeline_cache_filename = base_dir / "vulkan_pipelines.bin"; |
| 429 | vulkan_pipeline_cache = LoadVulkanPipelineCache(vulkan_pipeline_cache_filename); | 430 | vulkan_pipeline_cache = |
| 431 | LoadVulkanPipelineCache(vulkan_pipeline_cache_filename, CACHE_VERSION); | ||
| 430 | } | 432 | } |
| 431 | 433 | ||
| 432 | struct { | 434 | struct { |
| @@ -508,7 +510,8 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading | |||
| 508 | workers.WaitForRequests(stop_loading); | 510 | workers.WaitForRequests(stop_loading); |
| 509 | 511 | ||
| 510 | if (use_vulkan_pipeline_cache) { | 512 | if (use_vulkan_pipeline_cache) { |
| 511 | SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache); | 513 | SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache, |
| 514 | CACHE_VERSION); | ||
| 512 | } | 515 | } |
| 513 | 516 | ||
| 514 | if (state.statistics) { | 517 | if (state.statistics) { |
| @@ -714,15 +717,17 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline( | |||
| 714 | } | 717 | } |
| 715 | 718 | ||
| 716 | void PipelineCache::SerializeVulkanPipelineCache(const std::filesystem::path& filename, | 719 | void PipelineCache::SerializeVulkanPipelineCache(const std::filesystem::path& filename, |
| 717 | const vk::PipelineCache& pipeline_cache) try { | 720 | const vk::PipelineCache& pipeline_cache, |
| 721 | u32 cache_version) try { | ||
| 718 | std::ofstream file(filename, std::ios::binary); | 722 | std::ofstream file(filename, std::ios::binary); |
| 719 | file.exceptions(std::ifstream::failbit); | 723 | file.exceptions(std::ifstream::failbit); |
| 720 | if (!file.is_open()) { | 724 | if (!file.is_open()) { |
| 721 | LOG_ERROR(Common_Filesystem, "Failed to open Vulkan pipeline cache file {}", | 725 | LOG_ERROR(Common_Filesystem, "Failed to open Vulkan driver pipeline cache file {}", |
| 722 | Common::FS::PathToUTF8String(filename)); | 726 | Common::FS::PathToUTF8String(filename)); |
| 723 | return; | 727 | return; |
| 724 | } | 728 | } |
| 725 | file.write(VULKAN_CACHE_MAGIC_NUMBER.data(), VULKAN_CACHE_MAGIC_NUMBER.size()); | 729 | file.write(VULKAN_CACHE_MAGIC_NUMBER.data(), VULKAN_CACHE_MAGIC_NUMBER.size()) |
| 730 | .write(reinterpret_cast<const char*>(&cache_version), sizeof(cache_version)); | ||
| 726 | 731 | ||
| 727 | size_t cache_size = 0; | 732 | size_t cache_size = 0; |
| 728 | std::vector<char> cache_data; | 733 | std::vector<char> cache_data; |
| @@ -733,18 +738,19 @@ void PipelineCache::SerializeVulkanPipelineCache(const std::filesystem::path& fi | |||
| 733 | } | 738 | } |
| 734 | file.write(cache_data.data(), cache_size); | 739 | file.write(cache_data.data(), cache_size); |
| 735 | 740 | ||
| 736 | LOG_INFO(Render_Vulkan, "Vulkan pipelines cached at: {}", | 741 | LOG_INFO(Render_Vulkan, "Vulkan driver pipelines cached at: {}", |
| 737 | Common::FS::PathToUTF8String(filename)); | 742 | Common::FS::PathToUTF8String(filename)); |
| 738 | 743 | ||
| 739 | } catch (const std::ios_base::failure& e) { | 744 | } catch (const std::ios_base::failure& e) { |
| 740 | LOG_ERROR(Common_Filesystem, "{}", e.what()); | 745 | LOG_ERROR(Common_Filesystem, "{}", e.what()); |
| 741 | if (!Common::FS::RemoveFile(filename)) { | 746 | if (!Common::FS::RemoveFile(filename)) { |
| 742 | LOG_ERROR(Common_Filesystem, "Failed to delete Vulkan pipeline cache file {}", | 747 | LOG_ERROR(Common_Filesystem, "Failed to delete Vulkan driver pipeline cache file {}", |
| 743 | Common::FS::PathToUTF8String(filename)); | 748 | Common::FS::PathToUTF8String(filename)); |
| 744 | } | 749 | } |
| 745 | } | 750 | } |
| 746 | 751 | ||
| 747 | vk::PipelineCache PipelineCache::LoadVulkanPipelineCache(const std::filesystem::path& filename) { | 752 | vk::PipelineCache PipelineCache::LoadVulkanPipelineCache(const std::filesystem::path& filename, |
| 753 | u32 expected_cache_version) { | ||
| 748 | const auto create_pipeline_cache = [this](size_t data_size, const void* data) { | 754 | const auto create_pipeline_cache = [this](size_t data_size, const void* data) { |
| 749 | VkPipelineCacheCreateInfo pipeline_cache_ci = { | 755 | VkPipelineCacheCreateInfo pipeline_cache_ci = { |
| 750 | .sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, | 756 | .sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, |
| @@ -764,12 +770,17 @@ vk::PipelineCache PipelineCache::LoadVulkanPipelineCache(const std::filesystem:: | |||
| 764 | file.seekg(0, std::ios::beg); | 770 | file.seekg(0, std::ios::beg); |
| 765 | 771 | ||
| 766 | std::array<char, 8> magic_number; | 772 | std::array<char, 8> magic_number; |
| 767 | file.read(magic_number.data(), magic_number.size()); | 773 | u32 cache_version; |
| 768 | if (magic_number != VULKAN_CACHE_MAGIC_NUMBER) { | 774 | file.read(magic_number.data(), magic_number.size()) |
| 775 | .read(reinterpret_cast<char*>(&cache_version), sizeof(cache_version)); | ||
| 776 | if (magic_number != VULKAN_CACHE_MAGIC_NUMBER || cache_version != expected_cache_version) { | ||
| 769 | file.close(); | 777 | file.close(); |
| 770 | if (Common::FS::RemoveFile(filename)) { | 778 | if (Common::FS::RemoveFile(filename)) { |
| 771 | if (magic_number != VULKAN_CACHE_MAGIC_NUMBER) { | 779 | if (magic_number != VULKAN_CACHE_MAGIC_NUMBER) { |
| 772 | LOG_ERROR(Common_Filesystem, "Invalid Vulkan pipeline cache file"); | 780 | LOG_ERROR(Common_Filesystem, "Invalid Vulkan driver pipeline cache file"); |
| 781 | } | ||
| 782 | if (cache_version != expected_cache_version) { | ||
| 783 | LOG_INFO(Common_Filesystem, "Deleting old Vulkan driver pipeline cache"); | ||
| 773 | } | 784 | } |
| 774 | } else { | 785 | } else { |
| 775 | LOG_ERROR(Common_Filesystem, | 786 | LOG_ERROR(Common_Filesystem, |
| @@ -784,14 +795,14 @@ vk::PipelineCache PipelineCache::LoadVulkanPipelineCache(const std::filesystem:: | |||
| 784 | file.read(cache_data.data(), cache_size); | 795 | file.read(cache_data.data(), cache_size); |
| 785 | 796 | ||
| 786 | LOG_INFO(Render_Vulkan, | 797 | LOG_INFO(Render_Vulkan, |
| 787 | "Loaded Vulkan pipeline cache: ", Common::FS::PathToUTF8String(filename)); | 798 | "Loaded Vulkan driver pipeline cache: ", Common::FS::PathToUTF8String(filename)); |
| 788 | 799 | ||
| 789 | return create_pipeline_cache(cache_size, cache_data.data()); | 800 | return create_pipeline_cache(cache_size, cache_data.data()); |
| 790 | 801 | ||
| 791 | } catch (const std::ios_base::failure& e) { | 802 | } catch (const std::ios_base::failure& e) { |
| 792 | LOG_ERROR(Common_Filesystem, "{}", e.what()); | 803 | LOG_ERROR(Common_Filesystem, "{}", e.what()); |
| 793 | if (!Common::FS::RemoveFile(filename)) { | 804 | if (!Common::FS::RemoveFile(filename)) { |
| 794 | LOG_ERROR(Common_Filesystem, "Failed to delete Vulkan pipeline cache file {}", | 805 | LOG_ERROR(Common_Filesystem, "Failed to delete Vulkan driver pipeline cache file {}", |
| 795 | Common::FS::PathToUTF8String(filename)); | 806 | Common::FS::PathToUTF8String(filename)); |
| 796 | } | 807 | } |
| 797 | 808 | ||
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index cf3bd6b85..5171912d7 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h | |||
| @@ -136,9 +136,10 @@ private: | |||
| 136 | bool build_in_parallel); | 136 | bool build_in_parallel); |
| 137 | 137 | ||
| 138 | void SerializeVulkanPipelineCache(const std::filesystem::path& filename, | 138 | void SerializeVulkanPipelineCache(const std::filesystem::path& filename, |
| 139 | const vk::PipelineCache& pipeline_cache); | 139 | const vk::PipelineCache& pipeline_cache, u32 cache_version); |
| 140 | 140 | ||
| 141 | vk::PipelineCache LoadVulkanPipelineCache(const std::filesystem::path& filename); | 141 | vk::PipelineCache LoadVulkanPipelineCache(const std::filesystem::path& filename, |
| 142 | u32 expected_cache_version); | ||
| 142 | 143 | ||
| 143 | const Device& device; | 144 | const Device& device; |
| 144 | Scheduler& scheduler; | 145 | Scheduler& scheduler; |