VideoCommon: Move shader cache filename generation to common

This commit is contained in:
Stenzek 2017-07-19 20:35:17 +10:00
parent 7c5bbafdd1
commit d01b0bf60f
9 changed files with 61 additions and 51 deletions

View File

@ -163,14 +163,9 @@ void GeometryShaderCache::Init()
void GeometryShaderCache::LoadShaderCache() void GeometryShaderCache::LoadShaderCache()
{ {
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string cache_filename = StringFromFormat(
"%sdx11-%s-%s-gs.cache", File::GetUserPath(D_SHADERCACHE_IDX).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(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "GS", true, true),
inserter);
} }
void GeometryShaderCache::Reload() void GeometryShaderCache::Reload()

View File

@ -503,14 +503,9 @@ void PixelShaderCache::Init()
void PixelShaderCache::LoadShaderCache() void PixelShaderCache::LoadShaderCache()
{ {
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string cache_filename = StringFromFormat(
"%sdx11-%s-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).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(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "PS", true, true),
inserter);
} }
void PixelShaderCache::Reload() void PixelShaderCache::Reload()

View File

@ -164,14 +164,9 @@ void VertexShaderCache::Init()
void VertexShaderCache::LoadShaderCache() void VertexShaderCache::LoadShaderCache()
{ {
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string cache_filename = StringFromFormat(
"%sdx11-%s-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX).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(g_ActiveConfig.GetDiskCacheFileName(APIType::D3D, "VS", true, true),
inserter);
} }
void VertexShaderCache::Reload() void VertexShaderCache::Reload()

View File

@ -552,14 +552,8 @@ void ProgramShaderCache::LoadProgramBinaries()
} }
else else
{ {
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 = std::string cache_filename =
StringFromFormat("%sogl-%s-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), g_ActiveConfig.GetDiskCacheFileName(APIType::OpenGL, "ProgramBinaries", true, true);
SConfig::GetInstance().GetGameID().c_str(), host_part.c_str());
ProgramShaderCacheInserter inserter; ProgramShaderCacheInserter inserter;
g_program_disk_cache.OpenAndRead(cache_filename, inserter); g_program_disk_cache.OpenAndRead(cache_filename, inserter);
} }

View File

@ -446,16 +446,6 @@ void ObjectCache::ClearPipelineCache()
m_compute_pipeline_objects.clear(); m_compute_pipeline_objects.clear();
} }
std::string ObjectCache::GetDiskCacheFileName(const char* type, bool include_gameid,
bool include_host_config)
{
return StringFromFormat(
"%svulkan-%s%s%s%s%s.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), type,
include_gameid ? "-" : "", include_gameid ? SConfig::GetInstance().GetGameID().c_str() : "",
include_host_config ? "-" : "",
include_host_config ? g_ActiveConfig.GetHostConfigFilename().c_str() : "");
}
class PipelineCacheReadCallback : public LinearDiskCacheReader<u32, u8> class PipelineCacheReadCallback : public LinearDiskCacheReader<u32, u8>
{ {
public: public:
@ -482,7 +472,8 @@ bool ObjectCache::CreatePipelineCache()
// Vulkan pipeline caches can be shared between games for shader compile time reduction. // Vulkan pipeline caches can be shared between games for shader compile time reduction.
// This assumes that drivers don't create all pipelines in the cache on load time, only // This assumes that drivers don't create all pipelines in the cache on load time, only
// when a lookup occurs that matches a pipeline (or pipeline data) in the cache. // when a lookup occurs that matches a pipeline (or pipeline data) in the cache.
m_pipeline_cache_filename = GetDiskCacheFileName("pipeline", false, true); m_pipeline_cache_filename =
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "Pipeline", false, true);
VkPipelineCacheCreateInfo info = { VkPipelineCacheCreateInfo info = {
VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, // VkStructureType sType
@ -505,7 +496,8 @@ bool ObjectCache::LoadPipelineCache()
{ {
// We have to keep the pipeline cache file name around since when we save it // We have to keep the pipeline cache file name around since when we save it
// we delete the old one, by which time the game's unique ID is already cleared. // we delete the old one, by which time the game's unique ID is already cleared.
m_pipeline_cache_filename = GetDiskCacheFileName("pipeline", false, true); m_pipeline_cache_filename =
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "Pipeline", false, true);
std::vector<u8> disk_data; std::vector<u8> disk_data;
LinearDiskCache<u32, u8> disk_cache; LinearDiskCache<u32, u8> disk_cache;
@ -671,15 +663,18 @@ struct ShaderCacheReader : public LinearDiskCacheReader<Uid, u32>
void ObjectCache::LoadShaderCaches() void ObjectCache::LoadShaderCaches()
{ {
ShaderCacheReader<VertexShaderUid> vs_reader(m_vs_cache.shader_map); ShaderCacheReader<VertexShaderUid> vs_reader(m_vs_cache.shader_map);
m_vs_cache.disk_cache.OpenAndRead(GetDiskCacheFileName("vs", true, true), vs_reader); m_vs_cache.disk_cache.OpenAndRead(
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "VS", true, true), vs_reader);
ShaderCacheReader<PixelShaderUid> ps_reader(m_ps_cache.shader_map); ShaderCacheReader<PixelShaderUid> ps_reader(m_ps_cache.shader_map);
m_ps_cache.disk_cache.OpenAndRead(GetDiskCacheFileName("ps", true, true), ps_reader); m_ps_cache.disk_cache.OpenAndRead(
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "PS", true, true), ps_reader);
if (g_vulkan_context->SupportsGeometryShaders()) if (g_vulkan_context->SupportsGeometryShaders())
{ {
ShaderCacheReader<GeometryShaderUid> gs_reader(m_gs_cache.shader_map); ShaderCacheReader<GeometryShaderUid> gs_reader(m_gs_cache.shader_map);
m_gs_cache.disk_cache.OpenAndRead(GetDiskCacheFileName("gs", true, true), gs_reader); m_gs_cache.disk_cache.OpenAndRead(
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "GS", true, true), gs_reader);
} }
SETSTAT(stats.numPixelShadersCreated, static_cast<int>(m_ps_cache.shader_map.size())); SETSTAT(stats.numPixelShadersCreated, static_cast<int>(m_ps_cache.shader_map.size()));

View File

@ -162,9 +162,6 @@ public:
VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; } VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; }
VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; } VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; }
VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; } VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; }
// Gets the filename of the specified type of cache object (e.g. vertex shader, pipeline).
std::string GetDiskCacheFileName(const char* type, bool include_gameid, bool include_host_config);
private: private:
bool CreatePipelineCache(); bool CreatePipelineCache();
bool LoadPipelineCache(); bool LoadPipelineCache();

View File

@ -147,7 +147,8 @@ void StateTracker::ReloadPipelineUIDCache()
m_uid_cache.Close(); m_uid_cache.Close();
// UID caches don't contain any host state, so use a single uid cache per gameid. // UID caches don't contain any host state, so use a single uid cache per gameid.
std::string filename = g_object_cache->GetDiskCacheFileName("pipeline-uid", true, false); std::string filename =
g_ActiveConfig.GetDiskCacheFileName(APIType::Vulkan, "PipelineUID", true, false);
if (g_ActiveConfig.bShaderCache) if (g_ActiveConfig.bShaderCache)
{ {
PipelineInserter inserter(this); PipelineInserter inserter(this);

View File

@ -4,9 +4,12 @@
#include <algorithm> #include <algorithm>
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Config/GraphicsSettings.h" #include "Core/Config/GraphicsSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
@ -256,8 +259,41 @@ u32 VideoConfig::GetHostConfigBits() const
return bits.bits; return bits.bits;
} }
std::string VideoConfig::GetHostConfigFilename() const std::string VideoConfig::GetDiskCacheFileName(APIType api_type, const char* type,
bool include_gameid, bool include_host_config) const
{ {
u32 bits = GetHostConfigBits(); if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
return StringFromFormat("%08X", bits); File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
std::string filename = File::GetUserPath(D_SHADERCACHE_IDX);
switch (api_type)
{
case APIType::D3D:
filename += "D3D";
break;
case APIType::OpenGL:
filename += "OpenGL";
break;
case APIType::Vulkan:
filename += "Vulkan";
break;
}
filename += '-';
filename += type;
if (include_gameid)
{
filename += '-';
filename += SConfig::GetInstance().GetGameID();
}
if (include_host_config)
{
// We're using 18 bits, so 5 hex characters.
filename += StringFromFormat("-%05X", GetHostConfigBits());
}
filename += ".cache";
return filename;
} }

View File

@ -229,7 +229,9 @@ struct VideoConfig final
bool IsSSAAEnabled() const; bool IsSSAAEnabled() const;
// Host config contains the settings which can influence generated shaders. // Host config contains the settings which can influence generated shaders.
u32 GetHostConfigBits() const; u32 GetHostConfigBits() const;
std::string GetHostConfigFilename() const; // Gets the filename of the specified type of cache object (e.g. vertex shader, pipeline).
std::string GetDiskCacheFileName(APIType api_type, const char* type, bool include_gameid,
bool include_host_config) const;
}; };
extern VideoConfig g_Config; extern VideoConfig g_Config;