diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-01-15 06:17:38 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-02-07 02:23:40 +0100 |
commit | 8ee3666a3c19c3522fc980c5bed8a519e99e0d95 (patch) | |
tree | 226bf4dc7f51d76bfa4198bdcc9af1d9e95e3440 | |
parent | gl_shader_disk_cache: Compress program binaries using LZ4 (diff) | |
download | yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.gz yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.bz2 yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.lz yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.xz yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.zst yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.zip |
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 12 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 47 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.h | 17 |
3 files changed, 37 insertions, 39 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 761b355e4..49b872c44 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -344,17 +344,15 @@ ShaderDiskCacheUsage CachedShader::GetUsage(GLenum primitive_mode, ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {} void ShaderCacheOpenGL::LoadDiskCache() { - std::vector<ShaderDiskCacheRaw> raws; - std::vector<ShaderDiskCacheUsage> usages; - if (!disk_cache.LoadTransferable(raws, usages)) { + const auto transferable = disk_cache.LoadTransferable(); + if (!transferable) { return; } + const auto [raws, usages] = *transferable; - std::map<u64, ShaderDiskCacheDecompiled> decompiled; - std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps; - disk_cache.LoadPrecompiled(decompiled, dumps); + auto [decompiled, dumps] = disk_cache.LoadPrecompiled(); - const std::set<GLenum> supported_formats{GetSupportedFormats()}; + const auto supported_formats{GetSupportedFormats()}; const auto unspecialized{GenerateUnspecializedShaders(raws, decompiled)}; // Build shaders 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 f6d950b0b..7783e3c01 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -111,17 +111,17 @@ void ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const { } } -bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws, - std::vector<ShaderDiskCacheUsage>& usages) { +std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>> +ShaderDiskCacheOpenGL::LoadTransferable() { if (!Settings::values.use_disk_shader_cache) { - return false; + return {}; } FileUtil::IOFile file(GetTransferablePath(), "rb"); if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}", GetTitleID()); - return false; + return {}; } const u64 file_size = file.GetSize(); @@ -132,15 +132,17 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing"); file.Close(); FileUtil::Delete(GetTransferablePath()); - return false; + return {}; } if (version > NativeVersion) { LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version " "of the emulator - skipping"); - return false; + return {}; } // Version is valid, load the shaders + std::vector<ShaderDiskCacheRaw> raws; + std::vector<ShaderDiskCacheUsage> usages; while (file.Tell() < file_size) { TransferableEntryKind kind{}; file.ReadBytes(&kind, sizeof(u32)); @@ -161,25 +163,24 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra default: LOG_ERROR(Render_OpenGL, "Unknown transferable shader cache entry kind={} - aborting", static_cast<u32>(kind)); - return false; + return {}; } } - return true; + return {{raws, usages}}; } -bool ShaderDiskCacheOpenGL::LoadPrecompiled( - std::map<u64, ShaderDiskCacheDecompiled>& decompiled, - std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps) { - +std::pair<std::map<u64, ShaderDiskCacheDecompiled>, + std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>> +ShaderDiskCacheOpenGL::LoadPrecompiled() { if (!Settings::values.use_disk_shader_cache) { - return false; + return {}; } FileUtil::IOFile file(GetPrecompiledPath(), "rb"); if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}", GetTitleID()); - return false; + return {}; } const u64 file_size = file.GetSize(); @@ -189,9 +190,11 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled( LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); file.Close(); InvalidatePrecompiled(); - return false; + return {}; } + std::map<u64, ShaderDiskCacheDecompiled> decompiled; + std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps; while (file.Tell() < file_size) { PrecompiledEntryKind kind{}; file.ReadBytes(&kind, sizeof(u32)); @@ -217,9 +220,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled( "Failed to decompress GLSL code in precompiled shader={:016x} - removing", unique_identifier); InvalidatePrecompiled(); - dumps.clear(); - decompiled.clear(); - return false; + return {}; } entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size); @@ -294,9 +295,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled( LOG_ERROR(Render_OpenGL, "Failed to decompress precompiled binary program - removing"); InvalidatePrecompiled(); - dumps.clear(); - decompiled.clear(); - return false; + return {}; } dumps.insert({usage, dump}); @@ -306,12 +305,10 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled( LOG_ERROR(Render_OpenGL, "Unknown precompiled shader cache entry kind={} - removing", static_cast<u32>(kind)); InvalidatePrecompiled(); - dumps.clear(); - decompiled.clear(); - return false; + return {}; } } - return true; + return {decompiled, dumps}; } void ShaderDiskCacheOpenGL::InvalidateTransferable() const { 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 f11693789..c44a776d9 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -4,9 +4,11 @@ #pragma once +#include <optional> #include <set> #include <string> #include <tuple> +#include <utility> #include <vector> #include <glad/glad.h> @@ -142,13 +144,14 @@ struct ShaderDiskCacheDump { class ShaderDiskCacheOpenGL { public: - /// Loads transferable cache. If file has a old version, it deletes it. Returns true on success. - bool LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws, - std::vector<ShaderDiskCacheUsage>& usages); - - /// Loads current game's precompiled cache. Invalidates if emulator's version has changed. - bool LoadPrecompiled(std::map<u64, ShaderDiskCacheDecompiled>& decompiled, - std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps); + /// Loads transferable cache. If file has a old version or on failure, it deletes the file. + std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>> + LoadTransferable(); + + /// Loads current game's precompiled cache. Invalidates on failure. + std::pair<std::map<u64, ShaderDiskCacheDecompiled>, + std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>> + LoadPrecompiled(); /// Removes the transferable (and precompiled) cache file. void InvalidateTransferable() const; |