mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-18 16:37:33 +01:00
gl_shader_disk_cache: Pass core system as argument and guard against games without title ids
This commit is contained in:
parent
2bc6a699dc
commit
7fefec585c
@ -123,7 +123,7 @@ struct System::Impl {
|
|||||||
Service::Init(service_manager, *virtual_filesystem);
|
Service::Init(service_manager, *virtual_filesystem);
|
||||||
GDBStub::Init();
|
GDBStub::Init();
|
||||||
|
|
||||||
renderer = VideoCore::CreateRenderer(emu_window);
|
renderer = VideoCore::CreateRenderer(emu_window, system);
|
||||||
if (!renderer->Init()) {
|
if (!renderer->Init()) {
|
||||||
return ResultStatus::ErrorVideoCore;
|
return ResultStatus::ErrorVideoCore;
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,9 @@ struct FramebufferCacheKey {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo& info)
|
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, Core::System& system,
|
||||||
: res_cache{*this}, shader_cache{*this}, emu_window{window}, screen_info{info},
|
ScreenInfo& info)
|
||||||
|
: res_cache{*this}, shader_cache{*this, system}, emu_window{window}, screen_info{info},
|
||||||
buffer_cache(*this, STREAM_BUFFER_SIZE), global_cache{*this} {
|
buffer_cache(*this, STREAM_BUFFER_SIZE), global_cache{*this} {
|
||||||
// Create sampler objects
|
// Create sampler objects
|
||||||
for (std::size_t i = 0; i < texture_samplers.size(); ++i) {
|
for (std::size_t i = 0; i < texture_samplers.size(); ++i) {
|
||||||
|
@ -33,6 +33,10 @@
|
|||||||
#include "video_core/renderer_opengl/gl_state.h"
|
#include "video_core/renderer_opengl/gl_state.h"
|
||||||
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core::Frontend {
|
namespace Core::Frontend {
|
||||||
class EmuWindow;
|
class EmuWindow;
|
||||||
}
|
}
|
||||||
@ -45,7 +49,8 @@ struct FramebufferCacheKey;
|
|||||||
|
|
||||||
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
||||||
public:
|
public:
|
||||||
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer, ScreenInfo& info);
|
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& window, Core::System& system,
|
||||||
|
ScreenInfo& info);
|
||||||
~RasterizerOpenGL() override;
|
~RasterizerOpenGL() override;
|
||||||
|
|
||||||
void DrawArrays() override;
|
void DrawArrays() override;
|
||||||
|
@ -342,7 +342,8 @@ ShaderDiskCacheUsage CachedShader::GetUsage(GLenum primitive_mode,
|
|||||||
return {unique_identifier, base_bindings, primitive_mode};
|
return {unique_identifier, base_bindings, primitive_mode};
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {}
|
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system)
|
||||||
|
: RasterizerCache{rasterizer}, disk_cache{system} {}
|
||||||
|
|
||||||
void ShaderCacheOpenGL::LoadDiskCache() {
|
void ShaderCacheOpenGL::LoadDiskCache() {
|
||||||
const auto transferable = disk_cache.LoadTransferable();
|
const auto transferable = disk_cache.LoadTransferable();
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
|
#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
class CachedShader;
|
class CachedShader;
|
||||||
@ -107,7 +111,7 @@ private:
|
|||||||
|
|
||||||
class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
|
class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
|
||||||
public:
|
public:
|
||||||
explicit ShaderCacheOpenGL(RasterizerOpenGL& rasterizer);
|
explicit ShaderCacheOpenGL(RasterizerOpenGL& rasterizer, Core::System& system);
|
||||||
|
|
||||||
/// Loads disk cache for the current game
|
/// Loads disk cache for the current game
|
||||||
void LoadDiskCache();
|
void LoadDiskCache();
|
||||||
|
@ -43,9 +43,6 @@ static_assert(sizeof(BaseBindings) == 12);
|
|||||||
static_assert(sizeof(ShaderDiskCacheUsage) == 24);
|
static_assert(sizeof(ShaderDiskCacheUsage) == 24);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string GetTitleID() {
|
|
||||||
return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID());
|
|
||||||
}
|
|
||||||
|
|
||||||
ShaderCacheVersionHash GetShaderCacheVersionHash() {
|
ShaderCacheVersionHash GetShaderCacheVersionHash() {
|
||||||
ShaderCacheVersionHash hash{};
|
ShaderCacheVersionHash hash{};
|
||||||
@ -82,6 +79,7 @@ std::vector<u8> DecompressData(const std::vector<u8>& compressed, std::size_t un
|
|||||||
}
|
}
|
||||||
return uncompressed;
|
return uncompressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ShaderDiskCacheRaw::ShaderDiskCacheRaw(u64 unique_identifier, Maxwell::ShaderProgram program_type,
|
ShaderDiskCacheRaw::ShaderDiskCacheRaw(u64 unique_identifier, Maxwell::ShaderProgram program_type,
|
||||||
@ -137,9 +135,13 @@ bool ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShaderDiskCacheOpenGL::ShaderDiskCacheOpenGL(Core::System& system) : system{system} {}
|
||||||
|
|
||||||
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
|
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
|
||||||
ShaderDiskCacheOpenGL::LoadTransferable() {
|
ShaderDiskCacheOpenGL::LoadTransferable() {
|
||||||
if (!Settings::values.use_disk_shader_cache)
|
// Skip games without title id
|
||||||
|
const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0;
|
||||||
|
if (!Settings::values.use_disk_shader_cache || !has_title_id)
|
||||||
return {};
|
return {};
|
||||||
tried_to_load = true;
|
tried_to_load = true;
|
||||||
|
|
||||||
@ -643,4 +645,8 @@ std::string ShaderDiskCacheOpenGL::GetBaseDir() const {
|
|||||||
return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
|
return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ShaderDiskCacheOpenGL::GetTitleID() const {
|
||||||
|
return fmt::format("{:016X}", system.CurrentProcess()->GetTitleID());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace OpenGL
|
} // namespace OpenGL
|
@ -18,9 +18,13 @@
|
|||||||
#include "video_core/engines/maxwell_3d.h"
|
#include "video_core/engines/maxwell_3d.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace FileUtil {
|
||||||
class IOFile;
|
class IOFile;
|
||||||
} // namespace FileUtil
|
}
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
@ -148,6 +152,8 @@ struct ShaderDiskCacheDump {
|
|||||||
|
|
||||||
class ShaderDiskCacheOpenGL {
|
class ShaderDiskCacheOpenGL {
|
||||||
public:
|
public:
|
||||||
|
explicit ShaderDiskCacheOpenGL(Core::System& system);
|
||||||
|
|
||||||
/// Loads transferable cache. If file has a old version or on failure, it deletes the file.
|
/// Loads transferable cache. If file has a old version or on failure, it deletes the file.
|
||||||
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
|
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
|
||||||
LoadTransferable();
|
LoadTransferable();
|
||||||
@ -217,6 +223,11 @@ private:
|
|||||||
/// Get user's shader directory path
|
/// Get user's shader directory path
|
||||||
std::string GetBaseDir() const;
|
std::string GetBaseDir() const;
|
||||||
|
|
||||||
|
/// Get current game's title id
|
||||||
|
std::string GetTitleID() const;
|
||||||
|
|
||||||
|
// Copre system
|
||||||
|
Core::System& system;
|
||||||
// Stored transferable shaders
|
// Stored transferable shaders
|
||||||
std::map<u64, std::set<ShaderDiskCacheUsage>> transferable;
|
std::map<u64, std::set<ShaderDiskCacheUsage>> transferable;
|
||||||
// The cache has been loaded at boot
|
// The cache has been loaded at boot
|
||||||
|
@ -98,8 +98,8 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
RendererOpenGL::RendererOpenGL(Core::Frontend::EmuWindow& window)
|
RendererOpenGL::RendererOpenGL(Core::Frontend::EmuWindow& window, Core::System& system)
|
||||||
: VideoCore::RendererBase{window} {}
|
: VideoCore::RendererBase{window}, system{system} {}
|
||||||
|
|
||||||
RendererOpenGL::~RendererOpenGL() = default;
|
RendererOpenGL::~RendererOpenGL() = default;
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ void RendererOpenGL::CreateRasterizer() {
|
|||||||
}
|
}
|
||||||
// Initialize sRGB Usage
|
// Initialize sRGB Usage
|
||||||
OpenGLState::ClearsRGBUsed();
|
OpenGLState::ClearsRGBUsed();
|
||||||
rasterizer = std::make_unique<RasterizerOpenGL>(render_window, screen_info);
|
rasterizer = std::make_unique<RasterizerOpenGL>(render_window, system, screen_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
|
void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||||
#include "video_core/renderer_opengl/gl_state.h"
|
#include "video_core/renderer_opengl/gl_state.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core::Frontend {
|
namespace Core::Frontend {
|
||||||
class EmuWindow;
|
class EmuWindow;
|
||||||
}
|
}
|
||||||
@ -41,7 +45,7 @@ struct ScreenInfo {
|
|||||||
|
|
||||||
class RendererOpenGL : public VideoCore::RendererBase {
|
class RendererOpenGL : public VideoCore::RendererBase {
|
||||||
public:
|
public:
|
||||||
explicit RendererOpenGL(Core::Frontend::EmuWindow& window);
|
explicit RendererOpenGL(Core::Frontend::EmuWindow& window, Core::System& system);
|
||||||
~RendererOpenGL() override;
|
~RendererOpenGL() override;
|
||||||
|
|
||||||
/// Swap buffers (render frame)
|
/// Swap buffers (render frame)
|
||||||
@ -72,6 +76,8 @@ private:
|
|||||||
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
|
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
|
||||||
const TextureInfo& texture);
|
const TextureInfo& texture);
|
||||||
|
|
||||||
|
Core::System& system;
|
||||||
|
|
||||||
OpenGLState state;
|
OpenGLState state;
|
||||||
|
|
||||||
// OpenGL object IDs
|
// OpenGL object IDs
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
namespace VideoCore {
|
namespace VideoCore {
|
||||||
|
|
||||||
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window) {
|
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window,
|
||||||
return std::make_unique<OpenGL::RendererOpenGL>(emu_window);
|
Core::System& system) {
|
||||||
|
return std::make_unique<OpenGL::RendererOpenGL>(emu_window, system);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 GetResolutionScaleFactor(const RendererBase& renderer) {
|
u16 GetResolutionScaleFactor(const RendererBase& renderer) {
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core::Frontend {
|
namespace Core::Frontend {
|
||||||
class EmuWindow;
|
class EmuWindow;
|
||||||
}
|
}
|
||||||
@ -20,7 +24,8 @@ class RendererBase;
|
|||||||
* @note The returned renderer instance is simply allocated. Its Init()
|
* @note The returned renderer instance is simply allocated. Its Init()
|
||||||
* function still needs to be called to fully complete its setup.
|
* function still needs to be called to fully complete its setup.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window);
|
std::unique_ptr<RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window,
|
||||||
|
Core::System& system);
|
||||||
|
|
||||||
u16 GetResolutionScaleFactor(const RendererBase& renderer);
|
u16 GetResolutionScaleFactor(const RendererBase& renderer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user