summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp55
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h1
2 files changed, 11 insertions, 45 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 53752b38d..170d53e83 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
@@ -247,20 +247,12 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
247 return {}; 247 return {};
248 248
249 u32 binary_length{}; 249 u32 binary_length{};
250 u32 compressed_size{}; 250 if (file.ReadBytes(&binary_length, sizeof(u32)) != sizeof(u32)) {
251 if (file.ReadBytes(&binary_length, sizeof(u32)) != sizeof(u32) ||
252 file.ReadBytes(&compressed_size, sizeof(u32)) != sizeof(u32)) {
253 return {}; 251 return {};
254 } 252 }
255 253
256 std::vector<u8> compressed_binary(compressed_size); 254 dump.binary.resize(binary_length);
257 if (file.ReadArray(compressed_binary.data(), compressed_binary.size()) != 255 if (file.ReadArray(dump.binary.data(), binary_length) != binary_length) {
258 compressed_binary.size()) {
259 return {};
260 }
261
262 dump.binary = Common::Compression::DecompressDataZSTD(compressed_binary);
263 if (dump.binary.empty()) {
264 return {}; 256 return {};
265 } 257 }
266 258
@@ -277,21 +269,15 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
277std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEntry( 269std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEntry(
278 FileUtil::IOFile& file) { 270 FileUtil::IOFile& file) {
279 u32 code_size{}; 271 u32 code_size{};
280 u32 compressed_code_size{}; 272 if (file.ReadBytes(&code_size, sizeof(u32)) != sizeof(u32)) {
281 if (file.ReadBytes(&code_size, sizeof(u32)) != sizeof(u32) ||
282 file.ReadBytes(&compressed_code_size, sizeof(u32)) != sizeof(u32)) {
283 return {}; 273 return {};
284 } 274 }
285 275
286 std::vector<u8> compressed_code(compressed_code_size); 276 std::vector<u8> code(code_size);
287 if (file.ReadArray(compressed_code.data(), compressed_code.size()) != compressed_code.size()) { 277 if (file.ReadArray(code.data(), code.size()) != code_size) {
288 return {}; 278 return {};
289 } 279 }
290 280
291 const std::vector<u8> code = Common::Compression::DecompressDataZSTD(compressed_code);
292 if (code.empty()) {
293 return {};
294 }
295 ShaderDiskCacheDecompiled entry; 281 ShaderDiskCacheDecompiled entry;
296 entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size); 282 entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size);
297 283
@@ -369,13 +355,11 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
369 355
370bool ShaderDiskCacheOpenGL::SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier, 356bool ShaderDiskCacheOpenGL::SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier,
371 const std::string& code, 357 const std::string& code,
372 const std::vector<u8>& compressed_code,
373 const GLShader::ShaderEntries& entries) { 358 const GLShader::ShaderEntries& entries) {
374 if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 || 359 if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 ||
375 file.WriteObject(unique_identifier) != 1 || 360 file.WriteObject(unique_identifier) != 1 ||
376 file.WriteObject(static_cast<u32>(code.size())) != 1 || 361 file.WriteObject(static_cast<u32>(code.size())) != 1 ||
377 file.WriteObject(static_cast<u32>(compressed_code.size())) != 1 || 362 file.WriteArray(code.data(), code.size()) != code.size()) {
378 file.WriteArray(compressed_code.data(), compressed_code.size()) != compressed_code.size()) {
379 return false; 363 return false;
380 } 364 }
381 365
@@ -485,19 +469,12 @@ void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::str
485 if (!IsUsable()) 469 if (!IsUsable())
486 return; 470 return;
487 471
488 const std::vector<u8> compressed_code{Common::Compression::CompressDataZSTDDefault(
489 reinterpret_cast<const u8*>(code.data()), code.size())};
490 if (compressed_code.empty()) {
491 LOG_ERROR(Render_OpenGL, "Failed to compress GLSL code - skipping shader {:016x}",
492 unique_identifier);
493 return;
494 }
495
496 FileUtil::IOFile file = AppendPrecompiledFile(); 472 FileUtil::IOFile file = AppendPrecompiledFile();
473
497 if (!file.IsOpen()) 474 if (!file.IsOpen())
498 return; 475 return;
499 476
500 if (!SaveDecompiledFile(file, unique_identifier, code, compressed_code, entries)) { 477 if (!SaveDecompiledFile(file, unique_identifier, code, entries)) {
501 LOG_ERROR(Render_OpenGL, 478 LOG_ERROR(Render_OpenGL,
502 "Failed to save decompiled entry to the precompiled file - removing"); 479 "Failed to save decompiled entry to the precompiled file - removing");
503 file.Close(); 480 file.Close();
@@ -516,25 +493,15 @@ void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint p
516 std::vector<u8> binary(binary_length); 493 std::vector<u8> binary(binary_length);
517 glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data()); 494 glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data());
518 495
519 const std::vector<u8> compressed_binary =
520 Common::Compression::CompressDataZSTDDefault(binary.data(), binary.size());
521
522 if (compressed_binary.empty()) {
523 LOG_ERROR(Render_OpenGL, "Failed to compress binary program in shader={:016x}",
524 usage.unique_identifier);
525 return;
526 }
527
528 FileUtil::IOFile file = AppendPrecompiledFile(); 496 FileUtil::IOFile file = AppendPrecompiledFile();
497
529 if (!file.IsOpen()) 498 if (!file.IsOpen())
530 return; 499 return;
531 500
532 if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 || 501 if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 ||
533 file.WriteObject(usage) != 1 || file.WriteObject(static_cast<u32>(binary_format)) != 1 || 502 file.WriteObject(usage) != 1 || file.WriteObject(static_cast<u32>(binary_format)) != 1 ||
534 file.WriteObject(static_cast<u32>(binary_length)) != 1 || 503 file.WriteObject(static_cast<u32>(binary_length)) != 1 ||
535 file.WriteObject(static_cast<u32>(compressed_binary.size())) != 1 || 504 file.WriteArray(binary.data(), binary.size()) != binary_length) {
536 file.WriteArray(compressed_binary.data(), compressed_binary.size()) !=
537 compressed_binary.size()) {
538 LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing", 505 LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing",
539 usage.unique_identifier); 506 usage.unique_identifier);
540 file.Close(); 507 file.Close();
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 6be0c0547..a2864c5e2 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h
@@ -201,7 +201,6 @@ private:
201 201
202 /// Saves a decompiled entry to the passed file. Returns true on success. 202 /// Saves a decompiled entry to the passed file. Returns true on success.
203 bool SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier, const std::string& code, 203 bool SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier, const std::string& code,
204 const std::vector<u8>& compressed_code,
205 const GLShader::ShaderEntries& entries); 204 const GLShader::ShaderEntries& entries);
206 205
207 /// Returns if the cache can be used 206 /// Returns if the cache can be used