diff --git a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp index 951b4287da..90bcca4bb6 100644 --- a/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/GeometryShaderCache.cpp @@ -163,14 +163,9 @@ void GeometryShaderCache::Init() 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; - 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() diff --git a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp index d3bdce59f1..bf31114f47 100644 --- a/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/PixelShaderCache.cpp @@ -503,14 +503,9 @@ void PixelShaderCache::Init() 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; - 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() diff --git a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp index 77aa06b2f4..4addad9326 100644 --- a/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp +++ b/Source/Core/VideoBackends/D3D/VertexShaderCache.cpp @@ -164,14 +164,9 @@ void VertexShaderCache::Init() 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; - 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() diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 3fd3573bb4..98b7695533 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -552,14 +552,8 @@ void ProgramShaderCache::LoadProgramBinaries() } 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 = - StringFromFormat("%sogl-%s-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), - SConfig::GetInstance().GetGameID().c_str(), host_part.c_str()); - + g_ActiveConfig.GetDiskCacheFileName(APIType::OpenGL, "ProgramBinaries", true, true); ProgramShaderCacheInserter inserter; g_program_disk_cache.OpenAndRead(cache_filename, inserter); } diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp index d63533b7f4..15c73c5098 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp @@ -446,16 +446,6 @@ void ObjectCache::ClearPipelineCache() 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 { public: @@ -482,7 +472,8 @@ bool ObjectCache::CreatePipelineCache() // 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 // 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 = { 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 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 disk_data; LinearDiskCache disk_cache; @@ -671,15 +663,18 @@ struct ShaderCacheReader : public LinearDiskCacheReader void ObjectCache::LoadShaderCaches() { ShaderCacheReader 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 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()) { ShaderCacheReader 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(m_ps_cache.shader_map.size())); diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.h b/Source/Core/VideoBackends/Vulkan/ObjectCache.h index 58476f16ab..53f0485698 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.h +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.h @@ -162,9 +162,6 @@ public: VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; } VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_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: bool CreatePipelineCache(); bool LoadPipelineCache(); diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp index 97ad7d4461..32ab5b8c86 100644 --- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp +++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp @@ -147,7 +147,8 @@ void StateTracker::ReloadPipelineUIDCache() m_uid_cache.Close(); // 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) { PipelineInserter inserter(this); diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 78784c5c9c..86cd38bfd8 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -4,9 +4,12 @@ #include +#include "Common/CommonPaths.h" #include "Common/CommonTypes.h" +#include "Common/FileUtil.h" #include "Common/StringUtil.h" #include "Core/Config/GraphicsSettings.h" +#include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/Movie.h" #include "VideoCommon/OnScreenDisplay.h" @@ -256,8 +259,41 @@ u32 VideoConfig::GetHostConfigBits() const 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(); - return StringFromFormat("%08X", bits); + if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) + 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; } diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index dd7dd88fa4..46415463d1 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -229,7 +229,9 @@ struct VideoConfig final bool IsSSAAEnabled() const; // Host config contains the settings which can influence generated shaders. 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;