summaryrefslogtreecommitdiffstats
path: root/src/video_core
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2019-01-14 05:58:46 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2019-02-07 02:20:57 +0100
commitbe4641c43f0c6c68d183549a9a8715ba6fde9c50 (patch)
treec923d382f2e9c27e4d92090c4c331fd99e0c7c47 /src/video_core
parentgl_shader_cache: Refactor to support disk shader cache (diff)
downloadyuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.gz
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.bz2
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.lz
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.xz
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.zst
yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.zip
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp23
1 files changed, 16 insertions, 7 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 4d02a800d..4b0e50b90 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
@@ -4,6 +4,8 @@
#pragma once
+#include <cstring>
+
#include <fmt/format.h>
#include "common/assert.h"
@@ -11,6 +13,7 @@
#include "common/common_types.h"
#include "common/file_util.h"
#include "common/logging/log.h"
+#include "common/scm_rev.h"
#include "core/core.h"
#include "core/hle/kernel/process.h"
@@ -26,9 +29,7 @@ enum class EntryKind : u32 {
};
constexpr u32 NativeVersion = 1;
-
-// TODO(Rodrigo): Hash files
-constexpr u64 PrecompiledHash = 0xdeadbeefdeadbeef;
+constexpr u32 ShaderHashSize = 64;
// Making sure sizes doesn't change by accident
static_assert(sizeof(BaseBindings) == 12);
@@ -38,6 +39,12 @@ namespace {
std::string GetTitleID() {
return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID());
}
+
+std::string GetShaderHash() {
+ std::array<char, ShaderHashSize> hash{};
+ std::strncpy(hash.data(), Common::g_shader_cache_version, ShaderHashSize);
+ return std::string(hash.data());
+}
} // namespace
ShaderDiskCacheRaw::ShaderDiskCacheRaw(FileUtil::IOFile& file) {
@@ -130,9 +137,9 @@ std::vector<ShaderDiskCachePrecompiledEntry> ShaderDiskCacheOpenGL::LoadPrecompi
}
const u64 file_size = file.GetSize();
- u64 precompiled_hash{};
- file.ReadBytes(&precompiled_hash, sizeof(precompiled_hash));
- if (precompiled_hash != PrecompiledHash) {
+ char precompiled_hash[ShaderHashSize];
+ file.ReadBytes(&precompiled_hash, ShaderHashSize);
+ if (std::string(precompiled_hash) != GetShaderHash()) {
LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing");
file.Close();
InvalidatePrecompiled();
@@ -255,7 +262,9 @@ FileUtil::IOFile ShaderDiskCacheOpenGL::AppendPrecompiledFile() const {
}
if (!existed || file.GetSize() == 0) {
- file.WriteObject(PrecompiledHash);
+ std::array<char, ShaderHashSize> hash{};
+ std::strcpy(hash.data(), GetShaderHash().c_str());
+ file.WriteArray(hash.data(), hash.size());
}
return file;
}