From a1faed99501d04b233d44a7cab0368449d8a9cb5 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 13 Jan 2019 23:33:31 -0300 Subject: [PATCH] gl_shader_disk_cache: Add precompiled load --- .../renderer_opengl/gl_shader_disk_cache.cpp | 39 +++++++++++++++++++ .../renderer_opengl/gl_shader_disk_cache.h | 6 +++ 2 files changed, 45 insertions(+) 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 0c42e3d8a3..a87bb1f9ed 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -121,6 +121,45 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector& ra return true; } +std::vector ShaderDiskCacheOpenGL::LoadPrecompiled() { + FileUtil::IOFile file(GetPrecompiledPath(), "rb"); + if (!file.IsOpen()) { + LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}", + GetTitleID()); + return {}; + } + const u64 file_size = file.GetSize(); + + u64 precompiled_hash{}; + file.ReadBytes(&precompiled_hash, sizeof(precompiled_hash)); + if (precompiled_hash != PrecompiledHash) { + LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); + file.Close(); + InvalidatePrecompiled(); + return {}; + } + + std::vector precompiled; + while (file.Tell() < file_size) { + ShaderDiskCachePrecompiledEntry entry; + file.ReadBytes(&entry.usage, sizeof(entry.usage)); + + file.ReadBytes(&entry.binary_format, sizeof(u32)); + + u32 binary_length{}; + file.ReadBytes(&binary_length, sizeof(u32)); + entry.binary.resize(binary_length); + file.ReadBytes(entry.binary.data(), entry.binary.size()); + + precompiled.push_back(entry); + } + return precompiled; +} + +void ShaderDiskCacheOpenGL::InvalidatePrecompiled() const { + FileUtil::Delete(GetPrecompiledPath()); +} + void ShaderDiskCacheOpenGL::SaveRaw(const ShaderDiskCacheRaw& entry) { const u64 id = entry.GetUniqueIdentifier(); if (transferable.find(id) != transferable.end()) { 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 fdb29caa5a..e68aea6940 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -144,6 +144,12 @@ public: bool LoadTransferable(std::vector& raws, std::vector& usages); + /// Loads current game's precompiled cache. Invalidates if emulator's version has changed. + std::vector LoadPrecompiled(); + + /// Removes the precompiled cache file. + void InvalidatePrecompiled() const; + /// Saves a raw dump to the transferable file. Checks for collisions. void SaveRaw(const ShaderDiskCacheRaw& entry);