mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-19 18:52:47 +01:00
VideoCommon: Move shader cache filename generation to common
This commit is contained in:
parent
7c5bbafdd1
commit
d01b0bf60f
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<u32, u8>
|
||||
{
|
||||
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<u8> disk_data;
|
||||
LinearDiskCache<u32, u8> disk_cache;
|
||||
@ -671,15 +663,18 @@ struct ShaderCacheReader : public LinearDiskCacheReader<Uid, u32>
|
||||
void ObjectCache::LoadShaderCaches()
|
||||
{
|
||||
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);
|
||||
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<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()));
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -4,9 +4,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user