From 8ee3666a3c19c3522fc980c5bed8a519e99e0d95 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 15 Jan 2019 02:17:38 -0300 Subject: [PATCH] gl_shader_disk_cache: Pass return values returning instead of by parameters --- .../renderer_opengl/gl_shader_cache.cpp | 12 ++--- .../renderer_opengl/gl_shader_disk_cache.cpp | 47 +++++++++---------- .../renderer_opengl/gl_shader_disk_cache.h | 15 +++--- 3 files changed, 36 insertions(+), 38 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 raws; - std::vector usages; - if (!disk_cache.LoadTransferable(raws, usages)) { + const auto transferable = disk_cache.LoadTransferable(); + if (!transferable) { return; } + const auto [raws, usages] = *transferable; - std::map decompiled; - std::map dumps; - disk_cache.LoadPrecompiled(decompiled, dumps); + auto [decompiled, dumps] = disk_cache.LoadPrecompiled(); - const std::set 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& raws, - std::vector& usages) { +std::optional, std::vector>> +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& 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 raws; + std::vector usages; while (file.Tell() < file_size) { TransferableEntryKind kind{}; file.ReadBytes(&kind, sizeof(u32)); @@ -161,25 +163,24 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector& ra default: LOG_ERROR(Render_OpenGL, "Unknown transferable shader cache entry kind={} - aborting", static_cast(kind)); - return false; + return {}; } } - return true; + return {{raws, usages}}; } -bool ShaderDiskCacheOpenGL::LoadPrecompiled( - std::map& decompiled, - std::map& dumps) { - +std::pair, + std::map> +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 decompiled; + std::map 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(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(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 #include #include #include +#include #include #include @@ -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& raws, - std::vector& usages); + /// Loads transferable cache. If file has a old version or on failure, it deletes the file. + std::optional, std::vector>> + LoadTransferable(); - /// Loads current game's precompiled cache. Invalidates if emulator's version has changed. - bool LoadPrecompiled(std::map& decompiled, - std::map& dumps); + /// Loads current game's precompiled cache. Invalidates on failure. + std::pair, + std::map> + LoadPrecompiled(); /// Removes the transferable (and precompiled) cache file. void InvalidateTransferable() const;