D3D11: Reload shader cache when relevant config changes
This commit is contained in:
parent
62a901508b
commit
228ddb8aba
|
@ -158,18 +158,29 @@ void GeometryShaderCache::Init()
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
if (g_ActiveConfig.bShaderCache)
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeometryShaderCache::LoadShaderCache()
|
||||||
{
|
{
|
||||||
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
||||||
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
||||||
|
|
||||||
std::string cache_filename =
|
std::string cache_filename = StringFromFormat(
|
||||||
StringFromFormat("%sdx11-%s-gs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
"%sdx11-%s-%s-gs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||||
SConfig::GetInstance().GetGameID().c_str());
|
SConfig::GetInstance().GetGameID().c_str(), g_ActiveConfig.GetHostConfigFilename().c_str());
|
||||||
GeometryShaderCacheInserter inserter;
|
GeometryShaderCacheInserter inserter;
|
||||||
g_gs_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_gs_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_entry = nullptr;
|
void GeometryShaderCache::Reload()
|
||||||
|
{
|
||||||
|
g_gs_disk_cache.Sync();
|
||||||
|
g_gs_disk_cache.Close();
|
||||||
|
Clear();
|
||||||
|
|
||||||
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ONLY to be used during shutdown.
|
// ONLY to be used during shutdown.
|
||||||
|
@ -180,6 +191,7 @@ void GeometryShaderCache::Clear()
|
||||||
GeometryShaders.clear();
|
GeometryShaders.clear();
|
||||||
|
|
||||||
last_entry = nullptr;
|
last_entry = nullptr;
|
||||||
|
last_uid = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryShaderCache::Shutdown()
|
void GeometryShaderCache::Shutdown()
|
||||||
|
|
|
@ -15,6 +15,7 @@ class GeometryShaderCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
|
static void Reload();
|
||||||
static void Clear();
|
static void Clear();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static bool SetShader(u32 primitive_type); // TODO: Should be renamed to LoadShader
|
static bool SetShader(u32 primitive_type); // TODO: Should be renamed to LoadShader
|
||||||
|
@ -38,6 +39,8 @@ private:
|
||||||
|
|
||||||
typedef std::map<GeometryShaderUid, GSCacheEntry> GSCache;
|
typedef std::map<GeometryShaderUid, GSCacheEntry> GSCache;
|
||||||
|
|
||||||
|
static void LoadShaderCache();
|
||||||
|
|
||||||
static GSCache GeometryShaders;
|
static GSCache GeometryShaders;
|
||||||
static const GSCacheEntry* last_entry;
|
static const GSCacheEntry* last_entry;
|
||||||
static GeometryShaderUid last_uid;
|
static GeometryShaderUid last_uid;
|
||||||
|
|
|
@ -498,18 +498,29 @@ void PixelShaderCache::Init()
|
||||||
SETSTAT(stats.numPixelShadersAlive, 0);
|
SETSTAT(stats.numPixelShadersAlive, 0);
|
||||||
|
|
||||||
if (g_ActiveConfig.bShaderCache)
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixelShaderCache::LoadShaderCache()
|
||||||
{
|
{
|
||||||
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
||||||
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
||||||
|
|
||||||
std::string cache_filename =
|
std::string cache_filename = StringFromFormat(
|
||||||
StringFromFormat("%sdx11-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
"%sdx11-%s-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||||
SConfig::GetInstance().GetGameID().c_str());
|
SConfig::GetInstance().GetGameID().c_str(), g_ActiveConfig.GetHostConfigFilename().c_str());
|
||||||
PixelShaderCacheInserter inserter;
|
PixelShaderCacheInserter inserter;
|
||||||
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_entry = nullptr;
|
void PixelShaderCache::Reload()
|
||||||
|
{
|
||||||
|
g_ps_disk_cache.Sync();
|
||||||
|
g_ps_disk_cache.Close();
|
||||||
|
Clear();
|
||||||
|
|
||||||
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ONLY to be used during shutdown.
|
// ONLY to be used during shutdown.
|
||||||
|
@ -520,6 +531,7 @@ void PixelShaderCache::Clear()
|
||||||
PixelShaders.clear();
|
PixelShaders.clear();
|
||||||
|
|
||||||
last_entry = nullptr;
|
last_entry = nullptr;
|
||||||
|
last_uid = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used in Swap() when AA mode has changed
|
// Used in Swap() when AA mode has changed
|
||||||
|
|
|
@ -15,6 +15,7 @@ class PixelShaderCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
|
static void Reload();
|
||||||
static void Clear();
|
static void Clear();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static bool SetShader(); // TODO: Should be renamed to LoadShader
|
static bool SetShader(); // TODO: Should be renamed to LoadShader
|
||||||
|
@ -46,6 +47,8 @@ private:
|
||||||
|
|
||||||
typedef std::map<PixelShaderUid, PSCacheEntry> PSCache;
|
typedef std::map<PixelShaderUid, PSCacheEntry> PSCache;
|
||||||
|
|
||||||
|
static void LoadShaderCache();
|
||||||
|
|
||||||
static PSCache PixelShaders;
|
static PSCache PixelShaders;
|
||||||
static const PSCacheEntry* last_entry;
|
static const PSCacheEntry* last_entry;
|
||||||
static PixelShaderUid last_uid;
|
static PixelShaderUid last_uid;
|
||||||
|
|
|
@ -242,6 +242,7 @@ Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferH
|
||||||
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
|
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
|
||||||
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
|
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
|
||||||
s_last_fullscreen_mode = D3D::GetFullscreenState();
|
s_last_fullscreen_mode = D3D::GetFullscreenState();
|
||||||
|
m_last_host_config_bits = g_ActiveConfig.GetHostConfigBits();
|
||||||
|
|
||||||
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
|
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
|
||||||
SetupDeviceObjects();
|
SetupDeviceObjects();
|
||||||
|
@ -894,6 +895,16 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
|
||||||
D3D11_CLEAR_DEPTH, 0.f, 0);
|
D3D11_CLEAR_DEPTH, 0.f, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
VertexShaderCache::Reload();
|
||||||
|
GeometryShaderCache::Reload();
|
||||||
|
PixelShaderCache::Reload();
|
||||||
|
m_last_host_config_bits = new_host_config_bits;
|
||||||
|
}
|
||||||
|
|
||||||
// begin next frame
|
// begin next frame
|
||||||
RestoreAPIState();
|
RestoreAPIState();
|
||||||
D3D::BeginFrame();
|
D3D::BeginFrame();
|
||||||
|
|
|
@ -64,5 +64,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D* src_texture,
|
void BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D* src_texture,
|
||||||
u32 src_width, u32 src_height, float Gamma);
|
u32 src_width, u32 src_height, float Gamma);
|
||||||
|
|
||||||
|
u32 m_last_host_config_bits = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,18 +159,29 @@ void VertexShaderCache::Init()
|
||||||
SETSTAT(stats.numVertexShadersAlive, 0);
|
SETSTAT(stats.numVertexShadersAlive, 0);
|
||||||
|
|
||||||
if (g_ActiveConfig.bShaderCache)
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VertexShaderCache::LoadShaderCache()
|
||||||
{
|
{
|
||||||
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
||||||
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
||||||
|
|
||||||
std::string cache_filename =
|
std::string cache_filename = StringFromFormat(
|
||||||
StringFromFormat("%sdx11-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
"%sdx11-%s-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
||||||
SConfig::GetInstance().GetGameID().c_str());
|
SConfig::GetInstance().GetGameID().c_str(), g_ActiveConfig.GetHostConfigFilename().c_str());
|
||||||
VertexShaderCacheInserter inserter;
|
VertexShaderCacheInserter inserter;
|
||||||
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_entry = nullptr;
|
void VertexShaderCache::Reload()
|
||||||
|
{
|
||||||
|
g_vs_disk_cache.Sync();
|
||||||
|
g_vs_disk_cache.Close();
|
||||||
|
Clear();
|
||||||
|
|
||||||
|
if (g_ActiveConfig.bShaderCache)
|
||||||
|
LoadShaderCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderCache::Clear()
|
void VertexShaderCache::Clear()
|
||||||
|
@ -180,6 +191,7 @@ void VertexShaderCache::Clear()
|
||||||
vshaders.clear();
|
vshaders.clear();
|
||||||
|
|
||||||
last_entry = nullptr;
|
last_entry = nullptr;
|
||||||
|
last_uid = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderCache::Shutdown()
|
void VertexShaderCache::Shutdown()
|
||||||
|
|
|
@ -17,6 +17,7 @@ class VertexShaderCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
|
static void Reload();
|
||||||
static void Clear();
|
static void Clear();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static bool SetShader(); // TODO: Should be renamed to LoadShader
|
static bool SetShader(); // TODO: Should be renamed to LoadShader
|
||||||
|
@ -53,6 +54,8 @@ private:
|
||||||
};
|
};
|
||||||
typedef std::map<VertexShaderUid, VSCacheEntry> VSCache;
|
typedef std::map<VertexShaderUid, VSCacheEntry> VSCache;
|
||||||
|
|
||||||
|
static void LoadShaderCache();
|
||||||
|
|
||||||
static VSCache vshaders;
|
static VSCache vshaders;
|
||||||
static const VSCacheEntry* last_entry;
|
static const VSCacheEntry* last_entry;
|
||||||
static VertexShaderUid last_uid;
|
static VertexShaderUid last_uid;
|
||||||
|
|
Loading…
Reference in New Issue