summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2019-01-14 03:22:15 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2019-02-07 02:20:57 +0100
commit98be5a49289ca17b9470669ae94162dfa28eb2fb (patch)
treef69c8e66525b4c9c5fa4ef28a6a7565e0830deb4
parentgl_shader_disk_cache: Add file and move BaseBindings declaration (diff)
downloadyuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.gz
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.bz2
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.lz
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.xz
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.zst
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.zip
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp52
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h24
2 files changed, 76 insertions, 0 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 b7876c3a7..de890676e 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,18 @@
#pragma once
+#include <fmt/format.h>
+
+#include "common/assert.h"
+#include "common/common_paths.h"
+#include "common/common_types.h"
+#include "common/file_util.h"
+#include "common/logging/log.h"
+
+#include "core/core.h"
+#include "core/hle/kernel/process.h"
+
+#include "video_core/renderer_opengl/gl_shader_cache.h"
#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
namespace OpenGL {
@@ -11,4 +23,44 @@ namespace OpenGL {
// Making sure sizes doesn't change by accident
static_assert(sizeof(BaseBindings) == 12);
+namespace {
+std::string GetTitleID() {
+ return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID());
+}
+} // namespace
+
+bool ShaderDiskCacheOpenGL::EnsureDirectories() const {
+ const auto CreateDir = [](const std::string& dir) {
+ if (!FileUtil::CreateDir(dir)) {
+ LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir);
+ return false;
+ }
+ return true;
+ };
+
+ return CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) &&
+ CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) &&
+ CreateDir(GetPrecompiledDir());
+}
+
+std::string ShaderDiskCacheOpenGL::GetTransferablePath() const {
+ return FileUtil::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
+}
+
+std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const {
+ return FileUtil::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
+}
+
+std::string ShaderDiskCacheOpenGL::GetTransferableDir() const {
+ return GetBaseDir() + DIR_SEP "transferable";
+}
+
+std::string ShaderDiskCacheOpenGL::GetPrecompiledDir() const {
+ return GetBaseDir() + DIR_SEP "precompiled";
+}
+
+std::string ShaderDiskCacheOpenGL::GetBaseDir() const {
+ return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
+}
+
} // namespace OpenGL \ No newline at end of file
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 cb40e9926..690c92cae 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 @@
#pragma once
+#include <string>
#include <tuple>
#include "common/common_types.h"
+#include "common/file_util.h"
#include "video_core/engines/maxwell_3d.h"
namespace OpenGL {
@@ -38,4 +40,26 @@ public:
}
};
+class ShaderDiskCacheOpenGL {
+public:
+private:
+ /// Create shader disk cache directories. Returns true on success.
+ bool EnsureDirectories() const;
+
+ /// Gets current game's transferable file path
+ std::string GetTransferablePath() const;
+
+ /// Gets current game's precompiled file path
+ std::string GetPrecompiledPath() const;
+
+ /// Get user's transferable directory path
+ std::string GetTransferableDir() const;
+
+ /// Get user's precompiled directory path
+ std::string GetPrecompiledDir() const;
+
+ /// Get user's shader directory path
+ std::string GetBaseDir() const;
+};
+
} // namespace OpenGL \ No newline at end of file