Improved shaders cache

This commit is contained in:
DH 2016-06-27 21:53:56 +03:00
parent 223979c088
commit 32830d45ff
6 changed files with 56 additions and 17 deletions

View file

@ -1207,7 +1207,7 @@ const std::string& fs::get_executable_dir()
return s_dir;
}
void fs::remove_all(const std::string& path)
void fs::remove_all(const std::string& path, bool remove_root)
{
for (const auto& entry : dir(path))
{
@ -1227,7 +1227,10 @@ void fs::remove_all(const std::string& path)
}
}
remove_dir(path);
if (remove_root)
{
remove_dir(path);
}
}
u64 fs::get_dir_size(const std::string& path)

View file

@ -440,7 +440,7 @@ namespace fs
const std::string& get_executable_dir();
// Delete directory and all its contents recursively
void remove_all(const std::string& path);
void remove_all(const std::string& path, bool remove_root = true);
// Get size of all files recursively
u64 get_dir_size(const std::string& path);

4
bin/data/.gitignore vendored
View file

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View file

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View file

@ -4,6 +4,11 @@
namespace rsx
{
void shaders_cache::path(const std::string &path_)
{
m_path = path_;
}
shader_info shaders_cache::get(const program_cache_context &ctxt, raw_shader &raw_shader, const program_state& state)
{
auto found_entry = m_entries.find(raw_shader);
@ -11,8 +16,6 @@ namespace rsx
shader_info info;
entry_t *entry;
static const std::string &path = fs::get_executable_dir() + "data/cache/";
if (found_entry != m_entries.end())
{
entry = &found_entry->second;
@ -21,10 +24,18 @@ namespace rsx
{
//analyze_raw_shader(raw_shader);
fs::file{ path + fmt::format("%016llx.", raw_shader.hash()) + (raw_shader.type == rsx::program_type::fragment ? "fp" : "vp") + ".ucode", fs::rewrite }
.write(raw_shader.ucode.data(), raw_shader.ucode.size());
std::string shader_name_base =
fmt::format("%016llx", raw_shader.hash()) +
(raw_shader.type == rsx::program_type::fragment ? ".fp" : ".vp");
fs::file{ m_path + shader_name_base + ".ucode", fs::rewrite }
.write(raw_shader.ucode.data(), raw_shader.ucode.size());
rsx::decompiled_shader decompiled_shader = decompile(raw_shader, ctxt.lang);
fs::file{ m_path + shader_name_base + (ctxt.lang == rsx::decompile_language::glsl ? ".glsl" : ".hlsl"), fs::rewrite }
.write(decompiled_shader.code);
auto inserted = m_entries.insert({ raw_shader, entry_t{ decompiled_shader } }).first;
inserted->second.decompiled.raw = &inserted->first;
entry = &inserted->second;
@ -45,7 +56,15 @@ namespace rsx
info.complete = &entry->complete.insert({ state, complete_shader }).first->second;
info.complete->user_data = nullptr;
fs::file{ path + fmt::format("%016llx.", raw_shader.hash()) + (raw_shader.type == rsx::program_type::fragment ? "fp" : "vp") + "." + (ctxt.lang == rsx::decompile_language::glsl ? "glsl" : "hlsl"), fs::rewrite }.write(info.complete->code);
const std::string hash_combination = fmt::format("%016llx.%016llx", raw_shader.hash(), state.hash());
std::string shader_name =
hash_combination +
(raw_shader.type == rsx::program_type::fragment ? ".fp" : ".vp") +
(ctxt.lang == rsx::decompile_language::glsl ? ".glsl" : ".hlsl");
fs::file{ m_path + shader_name, fs::rewrite }.write(info.complete->code);
fs::file{ m_path + hash_combination + ".state", fs::rewrite }.write(state);
}
if (info.complete->user_data == nullptr)
@ -69,6 +88,27 @@ namespace rsx
m_entries.clear();
}
programs_cache::programs_cache()
{
std::string path{ fs::get_executable_dir() + "data/cache/" };
std::string title = Emu.GetTitleID();
if (title.empty())
{
path += "temporary/";
fs::remove_all(path, false);
}
else
{
path += title + "/";
}
fs::create_path(path);
m_vertex_shaders_cache.path(path);
m_fragment_shader_cache.path(path);
}
programs_cache::~programs_cache()
{
clear();

View file

@ -28,7 +28,7 @@ namespace rsx
void(*remove_shader)(void *ptr);
};
struct shaders_cache
class shaders_cache
{
struct entry_t
{
@ -37,8 +37,11 @@ namespace rsx
};
std::unordered_map<raw_shader, entry_t, hasher> m_entries;
std::string m_path;
public:
void path(const std::string &path_);
shader_info get(const program_cache_context &ctxt, raw_shader &raw_shader, const program_state& state);
void clear(const program_cache_context& context);
};
@ -53,6 +56,7 @@ namespace rsx
public:
program_cache_context context;
programs_cache();
~programs_cache();
program_info get(raw_program raw_program_, decompile_language lang);