summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-01-15 02:17:38 -0300
committerGravatar ReinUsesLisp2019-02-06 22:23:40 -0300
commit8ee3666a3c19c3522fc980c5bed8a519e99e0d95 (patch)
tree226bf4dc7f51d76bfa4198bdcc9af1d9e95e3440 /src
parentgl_shader_disk_cache: Compress program binaries using LZ4 (diff)
downloadyuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.gz
yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.tar.xz
yuzu-8ee3666a3c19c3522fc980c5bed8a519e99e0d95.zip
gl_shader_disk_cache: Pass return values returning instead of by parameters
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp12
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp47
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h17
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,
344ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {} 344ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {}
345 345
346void ShaderCacheOpenGL::LoadDiskCache() { 346void ShaderCacheOpenGL::LoadDiskCache() {
347 std::vector<ShaderDiskCacheRaw> raws; 347 const auto transferable = disk_cache.LoadTransferable();
348 std::vector<ShaderDiskCacheUsage> usages; 348 if (!transferable) {
349 if (!disk_cache.LoadTransferable(raws, usages)) {
350 return; 349 return;
351 } 350 }
351 const auto [raws, usages] = *transferable;
352 352
353 std::map<u64, ShaderDiskCacheDecompiled> decompiled; 353 auto [decompiled, dumps] = disk_cache.LoadPrecompiled();
354 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps;
355 disk_cache.LoadPrecompiled(decompiled, dumps);
356 354
357 const std::set<GLenum> supported_formats{GetSupportedFormats()}; 355 const auto supported_formats{GetSupportedFormats()};
358 const auto unspecialized{GenerateUnspecializedShaders(raws, decompiled)}; 356 const auto unspecialized{GenerateUnspecializedShaders(raws, decompiled)};
359 357
360 // Build shaders 358 // 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 {
111 } 111 }
112} 112}
113 113
114bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws, 114std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
115 std::vector<ShaderDiskCacheUsage>& usages) { 115ShaderDiskCacheOpenGL::LoadTransferable() {
116 if (!Settings::values.use_disk_shader_cache) { 116 if (!Settings::values.use_disk_shader_cache) {
117 return false; 117 return {};
118 } 118 }
119 119
120 FileUtil::IOFile file(GetTransferablePath(), "rb"); 120 FileUtil::IOFile file(GetTransferablePath(), "rb");
121 if (!file.IsOpen()) { 121 if (!file.IsOpen()) {
122 LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}", 122 LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}",
123 GetTitleID()); 123 GetTitleID());
124 return false; 124 return {};
125 } 125 }
126 const u64 file_size = file.GetSize(); 126 const u64 file_size = file.GetSize();
127 127
@@ -132,15 +132,17 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra
132 LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing"); 132 LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing");
133 file.Close(); 133 file.Close();
134 FileUtil::Delete(GetTransferablePath()); 134 FileUtil::Delete(GetTransferablePath());
135 return false; 135 return {};
136 } 136 }
137 if (version > NativeVersion) { 137 if (version > NativeVersion) {
138 LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version " 138 LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version "
139 "of the emulator - skipping"); 139 "of the emulator - skipping");
140 return false; 140 return {};
141 } 141 }
142 142
143 // Version is valid, load the shaders 143 // Version is valid, load the shaders
144 std::vector<ShaderDiskCacheRaw> raws;
145 std::vector<ShaderDiskCacheUsage> usages;
144 while (file.Tell() < file_size) { 146 while (file.Tell() < file_size) {
145 TransferableEntryKind kind{}; 147 TransferableEntryKind kind{};
146 file.ReadBytes(&kind, sizeof(u32)); 148 file.ReadBytes(&kind, sizeof(u32));
@@ -161,25 +163,24 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra
161 default: 163 default:
162 LOG_ERROR(Render_OpenGL, "Unknown transferable shader cache entry kind={} - aborting", 164 LOG_ERROR(Render_OpenGL, "Unknown transferable shader cache entry kind={} - aborting",
163 static_cast<u32>(kind)); 165 static_cast<u32>(kind));
164 return false; 166 return {};
165 } 167 }
166 } 168 }
167 return true; 169 return {{raws, usages}};
168} 170}
169 171
170bool ShaderDiskCacheOpenGL::LoadPrecompiled( 172std::pair<std::map<u64, ShaderDiskCacheDecompiled>,
171 std::map<u64, ShaderDiskCacheDecompiled>& decompiled, 173 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
172 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps) { 174ShaderDiskCacheOpenGL::LoadPrecompiled() {
173
174 if (!Settings::values.use_disk_shader_cache) { 175 if (!Settings::values.use_disk_shader_cache) {
175 return false; 176 return {};
176 } 177 }
177 178
178 FileUtil::IOFile file(GetPrecompiledPath(), "rb"); 179 FileUtil::IOFile file(GetPrecompiledPath(), "rb");
179 if (!file.IsOpen()) { 180 if (!file.IsOpen()) {
180 LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}", 181 LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}",
181 GetTitleID()); 182 GetTitleID());
182 return false; 183 return {};
183 } 184 }
184 const u64 file_size = file.GetSize(); 185 const u64 file_size = file.GetSize();
185 186
@@ -189,9 +190,11 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
189 LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); 190 LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing");
190 file.Close(); 191 file.Close();
191 InvalidatePrecompiled(); 192 InvalidatePrecompiled();
192 return false; 193 return {};
193 } 194 }
194 195
196 std::map<u64, ShaderDiskCacheDecompiled> decompiled;
197 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps;
195 while (file.Tell() < file_size) { 198 while (file.Tell() < file_size) {
196 PrecompiledEntryKind kind{}; 199 PrecompiledEntryKind kind{};
197 file.ReadBytes(&kind, sizeof(u32)); 200 file.ReadBytes(&kind, sizeof(u32));
@@ -217,9 +220,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
217 "Failed to decompress GLSL code in precompiled shader={:016x} - removing", 220 "Failed to decompress GLSL code in precompiled shader={:016x} - removing",
218 unique_identifier); 221 unique_identifier);
219 InvalidatePrecompiled(); 222 InvalidatePrecompiled();
220 dumps.clear(); 223 return {};
221 decompiled.clear();
222 return false;
223 } 224 }
224 entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size); 225 entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size);
225 226
@@ -294,9 +295,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
294 LOG_ERROR(Render_OpenGL, 295 LOG_ERROR(Render_OpenGL,
295 "Failed to decompress precompiled binary program - removing"); 296 "Failed to decompress precompiled binary program - removing");
296 InvalidatePrecompiled(); 297 InvalidatePrecompiled();
297 dumps.clear(); 298 return {};
298 decompiled.clear();
299 return false;
300 } 299 }
301 300
302 dumps.insert({usage, dump}); 301 dumps.insert({usage, dump});
@@ -306,12 +305,10 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
306 LOG_ERROR(Render_OpenGL, "Unknown precompiled shader cache entry kind={} - removing", 305 LOG_ERROR(Render_OpenGL, "Unknown precompiled shader cache entry kind={} - removing",
307 static_cast<u32>(kind)); 306 static_cast<u32>(kind));
308 InvalidatePrecompiled(); 307 InvalidatePrecompiled();
309 dumps.clear(); 308 return {};
310 decompiled.clear();
311 return false;
312 } 309 }
313 } 310 }
314 return true; 311 return {decompiled, dumps};
315} 312}
316 313
317void ShaderDiskCacheOpenGL::InvalidateTransferable() const { 314void 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 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <optional>
7#include <set> 8#include <set>
8#include <string> 9#include <string>
9#include <tuple> 10#include <tuple>
11#include <utility>
10#include <vector> 12#include <vector>
11 13
12#include <glad/glad.h> 14#include <glad/glad.h>
@@ -142,13 +144,14 @@ struct ShaderDiskCacheDump {
142 144
143class ShaderDiskCacheOpenGL { 145class ShaderDiskCacheOpenGL {
144public: 146public:
145 /// Loads transferable cache. If file has a old version, it deletes it. Returns true on success. 147 /// Loads transferable cache. If file has a old version or on failure, it deletes the file.
146 bool LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws, 148 std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
147 std::vector<ShaderDiskCacheUsage>& usages); 149 LoadTransferable();
148 150
149 /// Loads current game's precompiled cache. Invalidates if emulator's version has changed. 151 /// Loads current game's precompiled cache. Invalidates on failure.
150 bool LoadPrecompiled(std::map<u64, ShaderDiskCacheDecompiled>& decompiled, 152 std::pair<std::map<u64, ShaderDiskCacheDecompiled>,
151 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps); 153 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
154 LoadPrecompiled();
152 155
153 /// Removes the transferable (and precompiled) cache file. 156 /// Removes the transferable (and precompiled) cache file.
154 void InvalidateTransferable() const; 157 void InvalidateTransferable() const;