summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-01-13 23:22:15 -0300
committerGravatar ReinUsesLisp2019-02-06 22:20:57 -0300
commit98be5a49289ca17b9470669ae94162dfa28eb2fb (patch)
treef69c8e66525b4c9c5fa4ef28a6a7565e0830deb4 /src/video_core
parentgl_shader_disk_cache: Add file and move BaseBindings declaration (diff)
downloadyuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.gz
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.xz
yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.zip
gl_shader_disk_cache: Add ShaderDiskCacheOpenGL class and helpers
Diffstat (limited to 'src/video_core')
-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 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <fmt/format.h>
8
9#include "common/assert.h"
10#include "common/common_paths.h"
11#include "common/common_types.h"
12#include "common/file_util.h"
13#include "common/logging/log.h"
14
15#include "core/core.h"
16#include "core/hle/kernel/process.h"
17
18#include "video_core/renderer_opengl/gl_shader_cache.h"
7#include "video_core/renderer_opengl/gl_shader_disk_cache.h" 19#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
8 20
9namespace OpenGL { 21namespace OpenGL {
@@ -11,4 +23,44 @@ namespace OpenGL {
11// Making sure sizes doesn't change by accident 23// Making sure sizes doesn't change by accident
12static_assert(sizeof(BaseBindings) == 12); 24static_assert(sizeof(BaseBindings) == 12);
13 25
26namespace {
27std::string GetTitleID() {
28 return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID());
29}
30} // namespace
31
32bool ShaderDiskCacheOpenGL::EnsureDirectories() const {
33 const auto CreateDir = [](const std::string& dir) {
34 if (!FileUtil::CreateDir(dir)) {
35 LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir);
36 return false;
37 }
38 return true;
39 };
40
41 return CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) &&
42 CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) &&
43 CreateDir(GetPrecompiledDir());
44}
45
46std::string ShaderDiskCacheOpenGL::GetTransferablePath() const {
47 return FileUtil::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
48}
49
50std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const {
51 return FileUtil::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
52}
53
54std::string ShaderDiskCacheOpenGL::GetTransferableDir() const {
55 return GetBaseDir() + DIR_SEP "transferable";
56}
57
58std::string ShaderDiskCacheOpenGL::GetPrecompiledDir() const {
59 return GetBaseDir() + DIR_SEP "precompiled";
60}
61
62std::string ShaderDiskCacheOpenGL::GetBaseDir() const {
63 return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
64}
65
14} // namespace OpenGL \ No newline at end of file 66} // 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 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <string>
7#include <tuple> 8#include <tuple>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/file_util.h"
10#include "video_core/engines/maxwell_3d.h" 12#include "video_core/engines/maxwell_3d.h"
11 13
12namespace OpenGL { 14namespace OpenGL {
@@ -38,4 +40,26 @@ public:
38 } 40 }
39}; 41};
40 42
43class ShaderDiskCacheOpenGL {
44public:
45private:
46 /// Create shader disk cache directories. Returns true on success.
47 bool EnsureDirectories() const;
48
49 /// Gets current game's transferable file path
50 std::string GetTransferablePath() const;
51
52 /// Gets current game's precompiled file path
53 std::string GetPrecompiledPath() const;
54
55 /// Get user's transferable directory path
56 std::string GetTransferableDir() const;
57
58 /// Get user's precompiled directory path
59 std::string GetPrecompiledDir() const;
60
61 /// Get user's shader directory path
62 std::string GetBaseDir() const;
63};
64
41} // namespace OpenGL \ No newline at end of file 65} // namespace OpenGL \ No newline at end of file