From 9b3e344ad8d8d2b36af28d26b6cff1e7e3d5b1a1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 4 Jul 2020 20:49:50 +1000 Subject: [PATCH] Renderers: Support empty shader cache --- src/common/d3d11/shader_cache.cpp | 13 ++++++++----- src/common/gl/shader_cache.cpp | 13 ++++++++----- src/common/vulkan/shader_cache.cpp | 25 ++++++++++++++++--------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/common/d3d11/shader_cache.cpp b/src/common/d3d11/shader_cache.cpp index fa9194071..030f52f71 100644 --- a/src/common/d3d11/shader_cache.cpp +++ b/src/common/d3d11/shader_cache.cpp @@ -47,12 +47,15 @@ void ShaderCache::Open(std::string_view base_path, D3D_FEATURE_LEVEL feature_lev m_feature_level = feature_level; m_debug = debug; - const std::string base_filename = GetCacheBaseFileName(base_path, feature_level, debug); - const std::string index_filename = base_filename + ".idx"; - const std::string blob_filename = base_filename + ".bin"; + if (!base_path.empty()) + { + const std::string base_filename = GetCacheBaseFileName(base_path, feature_level, debug); + const std::string index_filename = base_filename + ".idx"; + const std::string blob_filename = base_filename + ".bin"; - if (!ReadExisting(index_filename, blob_filename)) - CreateNew(index_filename, blob_filename); + if (!ReadExisting(index_filename, blob_filename)) + CreateNew(index_filename, blob_filename); + } } bool ShaderCache::CreateNew(const std::string& index_filename, const std::string& blob_filename) diff --git a/src/common/gl/shader_cache.cpp b/src/common/gl/shader_cache.cpp index 752d50484..90166bd78 100644 --- a/src/common/gl/shader_cache.cpp +++ b/src/common/gl/shader_cache.cpp @@ -72,11 +72,14 @@ void ShaderCache::Open(bool is_gles, std::string_view base_path) return; } - const std::string index_filename = GetIndexFileName(); - const std::string blob_filename = GetBlobFileName(); + if (!base_path.empty()) + { + const std::string index_filename = GetIndexFileName(); + const std::string blob_filename = GetBlobFileName(); - if (!ReadExisting(index_filename, blob_filename)) - CreateNew(index_filename, blob_filename); + if (!ReadExisting(index_filename, blob_filename)) + CreateNew(index_filename, blob_filename); + } } bool ShaderCache::CreateNew(const std::string& index_filename, const std::string& blob_filename) @@ -256,7 +259,7 @@ std::optional ShaderCache::GetProgram(const std::string_view vertex_sha const std::string_view geometry_shader, const std::string_view fragment_shader, const PreLinkCallback& callback) { - if (!m_program_binary_supported) + if (!m_program_binary_supported || !m_blob_file) return CompileProgram(vertex_shader, geometry_shader, fragment_shader, callback, false); const auto key = GetCacheKey(vertex_shader, geometry_shader, fragment_shader); diff --git a/src/common/vulkan/shader_cache.cpp b/src/common/vulkan/shader_cache.cpp index 6f56684d3..80951cdab 100644 --- a/src/common/vulkan/shader_cache.cpp +++ b/src/common/vulkan/shader_cache.cpp @@ -121,17 +121,24 @@ void ShaderCache::Open(std::string_view base_path, bool debug) { m_debug = debug; - m_pipeline_cache_filename = GetPipelineCacheBaseFileName(base_path, debug); + if (!base_path.empty()) + { + m_pipeline_cache_filename = GetPipelineCacheBaseFileName(base_path, debug); - const std::string base_filename = GetShaderCacheBaseFileName(base_path, debug); - const std::string index_filename = base_filename + ".idx"; - const std::string blob_filename = base_filename + ".bin"; + const std::string base_filename = GetShaderCacheBaseFileName(base_path, debug); + const std::string index_filename = base_filename + ".idx"; + const std::string blob_filename = base_filename + ".bin"; - if (!ReadExistingShaderCache(index_filename, blob_filename)) - CreateNewShaderCache(index_filename, blob_filename); + if (!ReadExistingShaderCache(index_filename, blob_filename)) + CreateNewShaderCache(index_filename, blob_filename); - if (!ReadExistingPipelineCache()) + if (!ReadExistingPipelineCache()) + CreateNewPipelineCache(); + } + else + { CreateNewPipelineCache(); + } } VkPipelineCache ShaderCache::GetPipelineCache(bool set_dirty /*= true*/) @@ -273,7 +280,7 @@ void ShaderCache::CloseShaderCache() bool ShaderCache::CreateNewPipelineCache() { - if (FileSystem::FileExists(m_pipeline_cache_filename.c_str())) + if (!m_pipeline_cache_filename.empty() && FileSystem::FileExists(m_pipeline_cache_filename.c_str())) { Log_WarningPrintf("Removing existing pipeline cache '%s'", m_pipeline_cache_filename.c_str()); FileSystem::DeleteFile(m_pipeline_cache_filename.c_str()); @@ -322,7 +329,7 @@ bool ShaderCache::ReadExistingPipelineCache() bool ShaderCache::FlushPipelineCache() { - if (m_pipeline_cache == VK_NULL_HANDLE || !m_pipeline_cache_dirty) + if (m_pipeline_cache == VK_NULL_HANDLE || !m_pipeline_cache_dirty || m_pipeline_cache_filename.empty()) return false; size_t data_size;