VideoBackends: Add a developer option to disable the shader cache.

Makes it easier to disable the cache while working on the shaders.
This commit is contained in:
Jules Blok 2017-02-19 12:02:47 +01:00
parent 51944afa56
commit 21967b1f6e
8 changed files with 73 additions and 54 deletions

View File

@ -157,6 +157,8 @@ void GeometryShaderCache::Init()
Clear();
if (g_ActiveConfig.bShaderCache)
{
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
@ -165,6 +167,7 @@ void GeometryShaderCache::Init()
SConfig::GetInstance().m_strGameID.c_str());
GeometryShaderCacheInserter inserter;
g_gs_disk_cache.OpenAndRead(cache_filename, inserter);
}
last_entry = nullptr;
}

View File

@ -494,17 +494,20 @@ void PixelShaderCache::Init()
Clear();
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
SETSTAT(stats.numPixelShadersCreated, 0);
SETSTAT(stats.numPixelShadersAlive, 0);
if (g_ActiveConfig.bShaderCache)
{
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string cache_filename =
StringFromFormat("%sdx11-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
SConfig::GetInstance().m_strGameID.c_str());
PixelShaderCacheInserter inserter;
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
}
last_entry = nullptr;
}

View File

@ -155,17 +155,20 @@ void VertexShaderCache::Init()
Clear();
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
SETSTAT(stats.numVertexShadersCreated, 0);
SETSTAT(stats.numVertexShadersAlive, 0);
if (g_ActiveConfig.bShaderCache)
{
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string cache_filename =
StringFromFormat("%sdx11-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
SConfig::GetInstance().m_strGameID.c_str());
VertexShaderCacheInserter inserter;
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
}
last_entry = nullptr;
}

View File

@ -69,6 +69,8 @@ void ShaderCache::Init()
s_last_pixel_shader_uid = {};
s_last_vertex_shader_uid = {};
if (g_ActiveConfig.bShaderCache)
{
// Ensure shader cache directory exists..
std::string shader_cache_path = File::GetUserPath(D_SHADERCACHE_IDX);
@ -92,6 +94,7 @@ void ShaderCache::Init()
ShaderCacheInserter<VertexShaderUid, VsBytecodeCache, &s_vs_bytecode_cache> vs_inserter;
s_vs_disk_cache.OpenAndRead(vs_cache_filename, vs_inserter);
}
SETSTAT(stats.numPixelShadersAlive, static_cast<int>(s_ps_bytecode_cache.size()));
SETSTAT(stats.numPixelShadersCreated, static_cast<int>(s_ps_bytecode_cache.size()));

View File

@ -419,8 +419,8 @@ void ProgramShaderCache::Init()
// Then once more to get bytes
s_buffer = StreamBuffer::Create(GL_UNIFORM_BUFFER, UBO_LENGTH);
// Read our shader cache, only if supported
if (g_ogl_config.bSupportsGLSLCache)
// Read our shader cache, only if supported and enabled
if (g_ogl_config.bSupportsGLSLCache && g_ActiveConfig.bShaderCache)
{
GLint Supported;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);

View File

@ -535,16 +535,14 @@ struct ShaderCacheReader : public LinearDiskCacheReader<Uid, u32>
};
void ObjectCache::LoadShaderCaches()
{
if (g_ActiveConfig.bShaderCache)
{
ShaderCacheReader<VertexShaderUid> vs_reader(m_vs_cache.shader_map);
m_vs_cache.disk_cache.OpenAndRead(GetDiskCacheFileName("vs"), vs_reader);
SETSTAT(stats.numVertexShadersCreated, static_cast<int>(m_vs_cache.shader_map.size()));
SETSTAT(stats.numVertexShadersAlive, static_cast<int>(m_vs_cache.shader_map.size()));
ShaderCacheReader<PixelShaderUid> ps_reader(m_ps_cache.shader_map);
m_ps_cache.disk_cache.OpenAndRead(GetDiskCacheFileName("ps"), ps_reader);
SETSTAT(stats.numPixelShadersCreated, static_cast<int>(m_ps_cache.shader_map.size()));
SETSTAT(stats.numPixelShadersAlive, static_cast<int>(m_ps_cache.shader_map.size()));
if (g_vulkan_context->SupportsGeometryShaders())
{
@ -553,6 +551,12 @@ void ObjectCache::LoadShaderCaches()
}
}
SETSTAT(stats.numPixelShadersCreated, static_cast<int>(m_ps_cache.shader_map.size()));
SETSTAT(stats.numPixelShadersAlive, static_cast<int>(m_ps_cache.shader_map.size()));
SETSTAT(stats.numVertexShadersCreated, static_cast<int>(m_vs_cache.shader_map.size()));
SETSTAT(stats.numVertexShadersAlive, static_cast<int>(m_vs_cache.shader_map.size()));
}
template <typename T>
static void DestroyShaderCache(T& cache)
{

View File

@ -89,6 +89,7 @@ void VideoConfig::Load(const std::string& ini_file)
settings->Get("EnableValidationLayer", &bEnableValidationLayer, false);
settings->Get("BackendMultithreading", &bBackendMultithreading, true);
settings->Get("CommandBufferExecuteInterval", &iCommandBufferExecuteInterval, 100);
settings->Get("ShaderCache", &bShaderCache, true);
settings->Get("SWZComploc", &bZComploc, true);
settings->Get("SWZFreeze", &bZFreeze, true);
@ -307,6 +308,7 @@ void VideoConfig::Save(const std::string& ini_file)
settings->Set("EnableValidationLayer", bEnableValidationLayer);
settings->Set("BackendMultithreading", bBackendMultithreading);
settings->Set("CommandBufferExecuteInterval", iCommandBufferExecuteInterval);
settings->Set("ShaderCache", bShaderCache);
settings->Set("SWZComploc", bZComploc);
settings->Set("SWZFreeze", bZFreeze);

View File

@ -69,6 +69,7 @@ struct VideoConfig final
bool bCrop; // Aspect ratio controls.
bool bUseXFB;
bool bUseRealXFB;
bool bShaderCache;
// Enhancements
int iMultisamples;