diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-01-14 03:33:31 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-02-07 02:20:57 +0100 |
commit | a1faed99501d04b233d44a7cab0368449d8a9cb5 (patch) | |
tree | 01cc9ac951d4ef4b62a7db35b2d7c84342acd3cc | |
parent | gl_shader_disk_cache: Add precompiled save (diff) | |
download | yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar.gz yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar.bz2 yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar.lz yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar.xz yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.tar.zst yuzu-a1faed99501d04b233d44a7cab0368449d8a9cb5.zip |
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 39 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.h | 6 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 0c42e3d8a..a87bb1f9e 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -121,6 +121,45 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra return true; } +std::vector<ShaderDiskCachePrecompiledEntry> ShaderDiskCacheOpenGL::LoadPrecompiled() { + FileUtil::IOFile file(GetPrecompiledPath(), "rb"); + if (!file.IsOpen()) { + LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}", + GetTitleID()); + return {}; + } + const u64 file_size = file.GetSize(); + + u64 precompiled_hash{}; + file.ReadBytes(&precompiled_hash, sizeof(precompiled_hash)); + if (precompiled_hash != PrecompiledHash) { + LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); + file.Close(); + InvalidatePrecompiled(); + return {}; + } + + std::vector<ShaderDiskCachePrecompiledEntry> precompiled; + while (file.Tell() < file_size) { + ShaderDiskCachePrecompiledEntry entry; + file.ReadBytes(&entry.usage, sizeof(entry.usage)); + + file.ReadBytes(&entry.binary_format, sizeof(u32)); + + u32 binary_length{}; + file.ReadBytes(&binary_length, sizeof(u32)); + entry.binary.resize(binary_length); + file.ReadBytes(entry.binary.data(), entry.binary.size()); + + precompiled.push_back(entry); + } + return precompiled; +} + +void ShaderDiskCacheOpenGL::InvalidatePrecompiled() const { + FileUtil::Delete(GetPrecompiledPath()); +} + void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { const u64 id = entry.GetUniqueIdentifier(); if (transferable.find(id) != transferable.end()) { diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index fdb29caa5..e68aea694 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -144,6 +144,12 @@ public: bool LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws, std::vector<ShaderDiskCacheUsage>& usages); + /// Loads current game's precompiled cache. Invalidates if emulator's version has changed. + std::vector<ShaderDiskCachePrecompiledEntry> LoadPrecompiled(); + + /// Removes the precompiled cache file. + void InvalidatePrecompiled() const; + /// Saves a raw dump to the transferable file. Checks for collisions. void SaveRaw(const ShaderDiskCacheRaw& entry); |