diff options
| author | 2019-01-13 23:22:15 -0300 | |
|---|---|---|
| committer | 2019-02-06 22:20:57 -0300 | |
| commit | 98be5a49289ca17b9470669ae94162dfa28eb2fb (patch) | |
| tree | f69c8e66525b4c9c5fa4ef28a6a7565e0830deb4 | |
| parent | gl_shader_disk_cache: Add file and move BaseBindings declaration (diff) | |
| download | yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.gz yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.tar.xz yuzu-98be5a49289ca17b9470669ae94162dfa28eb2fb.zip | |
gl_shader_disk_cache: Add ShaderDiskCacheOpenGL class and helpers
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 52 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.h | 24 |
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 | ||
| 9 | namespace OpenGL { | 21 | namespace 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 |
| 12 | static_assert(sizeof(BaseBindings) == 12); | 24 | static_assert(sizeof(BaseBindings) == 12); |
| 13 | 25 | ||
| 26 | namespace { | ||
| 27 | std::string GetTitleID() { | ||
| 28 | return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID()); | ||
| 29 | } | ||
| 30 | } // namespace | ||
| 31 | |||
| 32 | bool 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 | |||
| 46 | std::string ShaderDiskCacheOpenGL::GetTransferablePath() const { | ||
| 47 | return FileUtil::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin"); | ||
| 48 | } | ||
| 49 | |||
| 50 | std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const { | ||
| 51 | return FileUtil::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin"); | ||
| 52 | } | ||
| 53 | |||
| 54 | std::string ShaderDiskCacheOpenGL::GetTransferableDir() const { | ||
| 55 | return GetBaseDir() + DIR_SEP "transferable"; | ||
| 56 | } | ||
| 57 | |||
| 58 | std::string ShaderDiskCacheOpenGL::GetPrecompiledDir() const { | ||
| 59 | return GetBaseDir() + DIR_SEP "precompiled"; | ||
| 60 | } | ||
| 61 | |||
| 62 | std::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 | ||
| 12 | namespace OpenGL { | 14 | namespace OpenGL { |
| @@ -38,4 +40,26 @@ public: | |||
| 38 | } | 40 | } |
| 39 | }; | 41 | }; |
| 40 | 42 | ||
| 43 | class ShaderDiskCacheOpenGL { | ||
| 44 | public: | ||
| 45 | private: | ||
| 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 |