summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-10-06 17:48:48 -0300
committerGravatar ReinUsesLisp2019-10-06 18:00:20 -0300
commit58b597c5eca01d3b9d8b2348d879d0340c80f346 (patch)
tree1a1a50a8618ff7175098db81f62e9e0abf8bf668 /src
parentMerge pull request #2942 from ReinUsesLisp/clang-warnings (diff)
downloadyuzu-58b597c5eca01d3b9d8b2348d879d0340c80f346.tar.gz
yuzu-58b597c5eca01d3b9d8b2348d879d0340c80f346.tar.xz
yuzu-58b597c5eca01d3b9d8b2348d879d0340c80f346.zip
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.
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp28
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h5
2 files changed, 17 insertions, 16 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 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::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskC
112ShaderDiskCacheOpenGL::LoadTransferable() { 112ShaderDiskCacheOpenGL::LoadTransferable() {
113 // Skip games without title id 113 // Skip games without title id
114 const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0; 114 const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0;
115 if (!Settings::values.use_disk_shader_cache || !has_title_id) 115 if (!Settings::values.use_disk_shader_cache || !has_title_id) {
116 return {}; 116 return {};
117 tried_to_load = true; 117 }
118 118
119 FileUtil::IOFile file(GetTransferablePath(), "rb"); 119 FileUtil::IOFile file(GetTransferablePath(), "rb");
120 if (!file.IsOpen()) { 120 if (!file.IsOpen()) {
121 LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}", 121 LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}",
122 GetTitleID()); 122 GetTitleID());
123 is_usable = true;
123 return {}; 124 return {};
124 } 125 }
125 126
@@ -135,6 +136,7 @@ ShaderDiskCacheOpenGL::LoadTransferable() {
135 LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing"); 136 LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing");
136 file.Close(); 137 file.Close();
137 InvalidateTransferable(); 138 InvalidateTransferable();
139 is_usable = true;
138 return {}; 140 return {};
139 } 141 }
140 if (version > NativeVersion) { 142 if (version > NativeVersion) {
@@ -180,13 +182,15 @@ ShaderDiskCacheOpenGL::LoadTransferable() {
180 } 182 }
181 } 183 }
182 184
183 return {{raws, usages}}; 185 is_usable = true;
186 return {{std::move(raws), std::move(usages)}};
184} 187}
185 188
186std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap> 189std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>
187ShaderDiskCacheOpenGL::LoadPrecompiled() { 190ShaderDiskCacheOpenGL::LoadPrecompiled() {
188 if (!IsUsable()) 191 if (!is_usable) {
189 return {}; 192 return {};
193 }
190 194
191 FileUtil::IOFile file(GetPrecompiledPath(), "rb"); 195 FileUtil::IOFile file(GetPrecompiledPath(), "rb");
192 if (!file.IsOpen()) { 196 if (!file.IsOpen()) {
@@ -479,8 +483,9 @@ void ShaderDiskCacheOpenGL::InvalidatePrecompiled() {
479} 483}
480 484
481void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { 485void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) {
482 if (!IsUsable()) 486 if (!is_usable) {
483 return; 487 return;
488 }
484 489
485 const u64 id = entry.GetUniqueIdentifier(); 490 const u64 id = entry.GetUniqueIdentifier();
486 if (transferable.find(id) != transferable.end()) { 491 if (transferable.find(id) != transferable.end()) {
@@ -501,8 +506,9 @@ void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) {
501} 506}
502 507
503void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) { 508void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) {
504 if (!IsUsable()) 509 if (!is_usable) {
505 return; 510 return;
511 }
506 512
507 const auto it = transferable.find(usage.unique_identifier); 513 const auto it = transferable.find(usage.unique_identifier);
508 ASSERT_MSG(it != transferable.end(), "Saving shader usage without storing raw previously"); 514 ASSERT_MSG(it != transferable.end(), "Saving shader usage without storing raw previously");
@@ -528,8 +534,9 @@ void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) {
528 534
529void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::string& code, 535void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::string& code,
530 const GLShader::ShaderEntries& entries) { 536 const GLShader::ShaderEntries& entries) {
531 if (!IsUsable()) 537 if (!is_usable) {
532 return; 538 return;
539 }
533 540
534 if (precompiled_cache_virtual_file.GetSize() == 0) { 541 if (precompiled_cache_virtual_file.GetSize() == 0) {
535 SavePrecompiledHeaderToVirtualPrecompiledCache(); 542 SavePrecompiledHeaderToVirtualPrecompiledCache();
@@ -543,8 +550,9 @@ void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::str
543} 550}
544 551
545void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint program) { 552void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint program) {
546 if (!IsUsable()) 553 if (!is_usable) {
547 return; 554 return;
555 }
548 556
549 GLint binary_length{}; 557 GLint binary_length{};
550 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length); 558 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length);
@@ -565,10 +573,6 @@ void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint p
565 } 573 }
566} 574}
567 575
568bool ShaderDiskCacheOpenGL::IsUsable() const {
569 return tried_to_load && Settings::values.use_disk_shader_cache;
570}
571
572FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { 576FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const {
573 if (!EnsureDirectories()) 577 if (!EnsureDirectories())
574 return {}; 578 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:
224 bool SaveDecompiledFile(u64 unique_identifier, const std::string& code, 224 bool SaveDecompiledFile(u64 unique_identifier, const std::string& code,
225 const GLShader::ShaderEntries& entries); 225 const GLShader::ShaderEntries& entries);
226 226
227 /// Returns if the cache can be used
228 bool IsUsable() const;
229
230 /// Opens current game's transferable file and write it's header if it doesn't exist 227 /// Opens current game's transferable file and write it's header if it doesn't exist
231 FileUtil::IOFile AppendTransferableFile() const; 228 FileUtil::IOFile AppendTransferableFile() const;
232 229
@@ -297,7 +294,7 @@ private:
297 std::unordered_map<u64, std::unordered_set<ShaderDiskCacheUsage>> transferable; 294 std::unordered_map<u64, std::unordered_set<ShaderDiskCacheUsage>> transferable;
298 295
299 // The cache has been loaded at boot 296 // The cache has been loaded at boot
300 bool tried_to_load{}; 297 bool is_usable{};
301}; 298};
302 299
303} // namespace OpenGL 300} // namespace OpenGL