OGL: Reload shader cache when relevant video config changes
This commit is contained in:
parent
d1381f5021
commit
62a901508b
|
@ -504,7 +504,44 @@ void ProgramShaderCache::Init()
|
|||
|
||||
// Read our shader cache, only if supported and enabled
|
||||
if (g_ogl_config.bSupportsGLSLCache && g_ActiveConfig.bShaderCache)
|
||||
{
|
||||
LoadProgramBinaries();
|
||||
|
||||
CreateHeader();
|
||||
|
||||
CurrentProgram = 0;
|
||||
last_entry = nullptr;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Reload()
|
||||
{
|
||||
const bool use_cache = g_ogl_config.bSupportsGLSLCache && g_ActiveConfig.bShaderCache;
|
||||
if (use_cache)
|
||||
SaveProgramBinaries();
|
||||
|
||||
g_program_disk_cache.Close();
|
||||
DestroyShaders();
|
||||
|
||||
if (use_cache)
|
||||
LoadProgramBinaries();
|
||||
|
||||
CurrentProgram = 0;
|
||||
last_entry = nullptr;
|
||||
last_uid = {};
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Shutdown()
|
||||
{
|
||||
// store all shaders in cache on disk
|
||||
if (g_ogl_config.bSupportsGLSLCache && g_ActiveConfig.bShaderCache)
|
||||
SaveProgramBinaries();
|
||||
g_program_disk_cache.Close();
|
||||
|
||||
DestroyShaders();
|
||||
s_buffer.reset();
|
||||
}
|
||||
|
||||
void ProgramShaderCache::LoadProgramBinaries()
|
||||
{
|
||||
GLint Supported;
|
||||
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
|
||||
if (!Supported)
|
||||
|
@ -518,27 +555,19 @@ void ProgramShaderCache::Init()
|
|||
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
||||
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
||||
|
||||
std::string host_part = g_ActiveConfig.GetHostConfigFilename();
|
||||
std::string cache_filename =
|
||||
StringFromFormat("%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||
SConfig::GetInstance().GetGameID().c_str());
|
||||
StringFromFormat("%sogl-%s-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||
SConfig::GetInstance().GetGameID().c_str(), host_part.c_str());
|
||||
|
||||
ProgramShaderCacheInserter inserter;
|
||||
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||
}
|
||||
SETSTAT(stats.numPixelShadersAlive, pshaders.size());
|
||||
}
|
||||
|
||||
CreateHeader();
|
||||
|
||||
CurrentProgram = 0;
|
||||
last_entry = nullptr;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::Shutdown()
|
||||
void ProgramShaderCache::SaveProgramBinaries()
|
||||
{
|
||||
// store all shaders in cache on disk
|
||||
if (g_ogl_config.bSupportsGLSLCache)
|
||||
{
|
||||
for (auto& entry : pshaders)
|
||||
{
|
||||
// Clear any prior error code
|
||||
|
@ -572,9 +601,10 @@ void ProgramShaderCache::Shutdown()
|
|||
}
|
||||
|
||||
g_program_disk_cache.Sync();
|
||||
g_program_disk_cache.Close();
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramShaderCache::DestroyShaders()
|
||||
{
|
||||
glUseProgram(0);
|
||||
|
||||
for (auto& entry : pshaders)
|
||||
|
@ -582,8 +612,6 @@ void ProgramShaderCache::Shutdown()
|
|||
entry.second.Destroy();
|
||||
}
|
||||
pshaders.clear();
|
||||
|
||||
s_buffer.reset();
|
||||
}
|
||||
|
||||
void ProgramShaderCache::CreateHeader()
|
||||
|
|
|
@ -72,6 +72,7 @@ public:
|
|||
static void UploadConstants();
|
||||
|
||||
static void Init();
|
||||
static void Reload();
|
||||
static void Shutdown();
|
||||
static void CreateHeader();
|
||||
|
||||
|
@ -82,6 +83,10 @@ private:
|
|||
void Read(const SHADERUID& key, const u8* value, u32 value_size) override;
|
||||
};
|
||||
|
||||
static void LoadProgramBinaries();
|
||||
static void SaveProgramBinaries();
|
||||
static void DestroyShaders();
|
||||
|
||||
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
||||
static PCache pshaders;
|
||||
static PCacheEntry* last_entry;
|
||||
|
|
|
@ -688,6 +688,7 @@ Renderer::Renderer()
|
|||
|
||||
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
|
||||
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
|
||||
m_last_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
|
||||
// Handle VSync on/off
|
||||
s_vsync = g_ActiveConfig.IsVSync();
|
||||
|
@ -1469,6 +1470,15 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
|
|||
UpdateActiveConfig();
|
||||
g_texture_cache->OnConfigChanged(g_ActiveConfig);
|
||||
|
||||
// Invalidate shader cache when the host config changes.
|
||||
u32 new_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||
if (new_host_config_bits != m_last_host_config_bits)
|
||||
{
|
||||
OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
|
||||
ProgramShaderCache::Reload();
|
||||
m_last_host_config_bits = new_host_config_bits;
|
||||
}
|
||||
|
||||
// For testing zbuffer targets.
|
||||
// Renderer::SetZBufferRender();
|
||||
// SaveTexture("tex.png", GL_TEXTURE_2D, s_FakeZTarget,
|
||||
|
|
|
@ -148,5 +148,8 @@ private:
|
|||
std::array<int, 2> m_last_frame_height = {};
|
||||
bool m_last_frame_exported = false;
|
||||
AVIDump::Frame m_last_frame_state;
|
||||
|
||||
// last host config state
|
||||
u32 m_last_host_config_bits = 0;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue