diff --git a/backends/vulkan/runtime/vk_api/Pipeline.cpp b/backends/vulkan/runtime/vk_api/Pipeline.cpp index 5cc5a76c358..07fc313984a 100644 --- a/backends/vulkan/runtime/vk_api/Pipeline.cpp +++ b/backends/vulkan/runtime/vk_api/Pipeline.cpp @@ -433,12 +433,12 @@ void ComputePipelineCache::purge() { } std::vector ComputePipelineCache::load_cache() { - // Return if path is not specified; this means the optimization is disabled + // No optimization if path is unspecified if (cache_data_path_.empty()) { return {}; } - // Return if file doesn't exist; this is expected on the first model-load + // Return if file doesn't exist; this is expected on first model-load std::ifstream file(cache_data_path_, std::ios::binary | std::ios::ate); if (file.fail()) { return {}; @@ -454,6 +454,17 @@ std::vector ComputePipelineCache::load_cache() { } void ComputePipelineCache::save_cache() { + // No optimization if path is unspecified + if (cache_data_path_.empty()) { + return; + } + + // Return if file exists; the cache is already saved + std::ifstream ifile(cache_data_path_); + if (ifile.good()) { + return; + } + size_t size{}; vkGetPipelineCacheData(device_, pipeline_cache_, &size, nullptr);