From 58b597c5eca01d3b9d8b2348d879d0340c80f346 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 6 Oct 2019 17:48:48 -0300 Subject: gl_shader_disk_cache: Properly ignore existing cache Previously old entries where appended to the file even if the shader cache was ignored at boot. Address that issue. --- .../renderer_opengl/gl_shader_disk_cache.cpp | 28 ++++++++++++---------- .../renderer_opengl/gl_shader_disk_cache.h | 5 +--- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src') 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 6a7012b54..74cc33476 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -112,14 +112,15 @@ std::optional, std::vectorGetTitleID() != 0; - if (!Settings::values.use_disk_shader_cache || !has_title_id) + if (!Settings::values.use_disk_shader_cache || !has_title_id) { return {}; - tried_to_load = true; + } FileUtil::IOFile file(GetTransferablePath(), "rb"); if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}", GetTitleID()); + is_usable = true; return {}; } @@ -135,6 +136,7 @@ ShaderDiskCacheOpenGL::LoadTransferable() { LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing"); file.Close(); InvalidateTransferable(); + is_usable = true; return {}; } if (version > NativeVersion) { @@ -180,13 +182,15 @@ ShaderDiskCacheOpenGL::LoadTransferable() { } } - return {{raws, usages}}; + is_usable = true; + return {{std::move(raws), std::move(usages)}}; } std::pair, ShaderDumpsMap> ShaderDiskCacheOpenGL::LoadPrecompiled() { - if (!IsUsable()) + if (!is_usable) { return {}; + } FileUtil::IOFile file(GetPrecompiledPath(), "rb"); if (!file.IsOpen()) { @@ -479,8 +483,9 @@ void ShaderDiskCacheOpenGL::InvalidatePrecompiled() { } void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { - if (!IsUsable()) + if (!is_usable) { return; + } const u64 id = entry.GetUniqueIdentifier(); if (transferable.find(id) != transferable.end()) { @@ -501,8 +506,9 @@ void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { } void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) { - if (!IsUsable()) + if (!is_usable) { return; + } const auto it = transferable.find(usage.unique_identifier); ASSERT_MSG(it != transferable.end(), "Saving shader usage without storing raw previously"); @@ -528,8 +534,9 @@ void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) { void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::string& code, const GLShader::ShaderEntries& entries) { - if (!IsUsable()) + if (!is_usable) { return; + } if (precompiled_cache_virtual_file.GetSize() == 0) { SavePrecompiledHeaderToVirtualPrecompiledCache(); @@ -543,8 +550,9 @@ void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::str } void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint program) { - if (!IsUsable()) + if (!is_usable) { return; + } GLint binary_length{}; glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length); @@ -565,10 +573,6 @@ void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint p } } -bool ShaderDiskCacheOpenGL::IsUsable() const { - return tried_to_load && Settings::values.use_disk_shader_cache; -} - FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { if (!EnsureDirectories()) return {}; 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 cc8bbd61e..9595bd71b 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -224,9 +224,6 @@ private: bool SaveDecompiledFile(u64 unique_identifier, const std::string& code, const GLShader::ShaderEntries& entries); - /// Returns if the cache can be used - bool IsUsable() const; - /// Opens current game's transferable file and write it's header if it doesn't exist FileUtil::IOFile AppendTransferableFile() const; @@ -297,7 +294,7 @@ private: std::unordered_map> transferable; // The cache has been loaded at boot - bool tried_to_load{}; + bool is_usable{}; }; } // namespace OpenGL -- cgit v1.2.3