mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Improved shaders cache
This commit is contained in:
parent
223979c088
commit
32830d45ff
6 changed files with 56 additions and 17 deletions
|
@ -1207,7 +1207,7 @@ const std::string& fs::get_executable_dir()
|
||||||
return s_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))
|
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)
|
u64 fs::get_dir_size(const std::string& path)
|
||||||
|
|
|
@ -440,7 +440,7 @@ namespace fs
|
||||||
const std::string& get_executable_dir();
|
const std::string& get_executable_dir();
|
||||||
|
|
||||||
// Delete directory and all its contents recursively
|
// 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
|
// Get size of all files recursively
|
||||||
u64 get_dir_size(const std::string& path);
|
u64 get_dir_size(const std::string& path);
|
||||||
|
|
4
bin/data/.gitignore
vendored
4
bin/data/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
||||||
# Ignore everything in this directory
|
|
||||||
*
|
|
||||||
# Except this file
|
|
||||||
!.gitignore
|
|
4
bin/data/cache/.gitignore
vendored
4
bin/data/cache/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
||||||
# Ignore everything in this directory
|
|
||||||
*
|
|
||||||
# Except this file
|
|
||||||
!.gitignore
|
|
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
namespace rsx
|
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)
|
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);
|
auto found_entry = m_entries.find(raw_shader);
|
||||||
|
@ -11,8 +16,6 @@ namespace rsx
|
||||||
shader_info info;
|
shader_info info;
|
||||||
entry_t *entry;
|
entry_t *entry;
|
||||||
|
|
||||||
static const std::string &path = fs::get_executable_dir() + "data/cache/";
|
|
||||||
|
|
||||||
if (found_entry != m_entries.end())
|
if (found_entry != m_entries.end())
|
||||||
{
|
{
|
||||||
entry = &found_entry->second;
|
entry = &found_entry->second;
|
||||||
|
@ -21,10 +24,18 @@ namespace rsx
|
||||||
{
|
{
|
||||||
//analyze_raw_shader(raw_shader);
|
//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 }
|
std::string shader_name_base =
|
||||||
.write(raw_shader.ucode.data(), raw_shader.ucode.size());
|
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);
|
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;
|
auto inserted = m_entries.insert({ raw_shader, entry_t{ decompiled_shader } }).first;
|
||||||
inserted->second.decompiled.raw = &inserted->first;
|
inserted->second.decompiled.raw = &inserted->first;
|
||||||
entry = &inserted->second;
|
entry = &inserted->second;
|
||||||
|
@ -45,7 +56,15 @@ namespace rsx
|
||||||
info.complete = &entry->complete.insert({ state, complete_shader }).first->second;
|
info.complete = &entry->complete.insert({ state, complete_shader }).first->second;
|
||||||
info.complete->user_data = nullptr;
|
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)
|
if (info.complete->user_data == nullptr)
|
||||||
|
@ -69,6 +88,27 @@ namespace rsx
|
||||||
m_entries.clear();
|
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()
|
programs_cache::~programs_cache()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace rsx
|
||||||
void(*remove_shader)(void *ptr);
|
void(*remove_shader)(void *ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct shaders_cache
|
class shaders_cache
|
||||||
{
|
{
|
||||||
struct entry_t
|
struct entry_t
|
||||||
{
|
{
|
||||||
|
@ -37,8 +37,11 @@ namespace rsx
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_map<raw_shader, entry_t, hasher> m_entries;
|
std::unordered_map<raw_shader, entry_t, hasher> m_entries;
|
||||||
|
std::string m_path;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void path(const std::string &path_);
|
||||||
|
|
||||||
shader_info get(const program_cache_context &ctxt, raw_shader &raw_shader, const program_state& state);
|
shader_info get(const program_cache_context &ctxt, raw_shader &raw_shader, const program_state& state);
|
||||||
void clear(const program_cache_context& context);
|
void clear(const program_cache_context& context);
|
||||||
};
|
};
|
||||||
|
@ -53,6 +56,7 @@ namespace rsx
|
||||||
public:
|
public:
|
||||||
program_cache_context context;
|
program_cache_context context;
|
||||||
|
|
||||||
|
programs_cache();
|
||||||
~programs_cache();
|
~programs_cache();
|
||||||
|
|
||||||
program_info get(raw_program raw_program_, decompile_language lang);
|
program_info get(raw_program raw_program_, decompile_language lang);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue