Renderers: Support empty shader cache

This commit is contained in:
Connor McLaughlin 2020-07-04 20:49:50 +10:00
parent f396a2c373
commit 9b3e344ad8
3 changed files with 32 additions and 19 deletions

View File

@ -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)

View File

@ -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<Program> 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);

View File

@ -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;