gl_shader_disk_cache: Add ShaderDiskCacheOpenGL class and helpers

This commit is contained in:
ReinUsesLisp 2019-01-13 23:22:15 -03:00
parent 145c3ac89e
commit 98be5a4928
2 changed files with 76 additions and 0 deletions

View file

@ -4,6 +4,18 @@
#pragma once #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" #include "video_core/renderer_opengl/gl_shader_disk_cache.h"
namespace OpenGL { namespace OpenGL {
@ -11,4 +23,44 @@ namespace OpenGL {
// Making sure sizes doesn't change by accident // Making sure sizes doesn't change by accident
static_assert(sizeof(BaseBindings) == 12); 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 } // namespace OpenGL

View file

@ -4,9 +4,11 @@
#pragma once #pragma once
#include <string>
#include <tuple> #include <tuple>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h"
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
namespace OpenGL { 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 } // namespace OpenGL