From b55d8111e66ab909ec932850284a7afd13827303 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 23 Aug 2018 17:30:27 -0400 Subject: renderer_opengl: Implement a new shader cache. --- src/video_core/renderer_opengl/gl_shader_cache.h | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/video_core/renderer_opengl/gl_shader_cache.h (limited to 'src/video_core/renderer_opengl/gl_shader_cache.h') diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h new file mode 100644 index 000000000..44156dcab --- /dev/null +++ b/src/video_core/renderer_opengl/gl_shader_cache.h @@ -0,0 +1,69 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "common/common_types.h" +#include "video_core/memory_manager.h" +#include "video_core/rasterizer_cache.h" +#include "video_core/renderer_opengl/gl_resource_manager.h" +#include "video_core/renderer_opengl/gl_shader_gen.h" + +namespace OpenGL { + +class CachedShader; +using Shader = std::shared_ptr; +using Maxwell = Tegra::Engines::Maxwell3D::Regs; + +class CachedShader final { +public: + CachedShader(Tegra::GPUVAddr addr, Maxwell::ShaderProgram program_type); + + /// Gets the address of the shader in guest memory, required for cache management + Tegra::GPUVAddr GetAddr() const { + return addr; + } + + /// Gets the size of the shader in guest memory, required for cache management + size_t GetSizeInBytes() const { + return sizeof(GLShader::ProgramCode); + } + + /// Gets the shader entries for the shader + const GLShader::ShaderEntries& GetShaderEntries() const { + return entries; + } + + /// Gets the GL program handle for the shader + GLuint GetProgramHandle() const { + return program.handle; + } + + /// Gets the GL program resource location for the specified resource, caching as needed + GLuint GetProgramResourceIndex(const std::string& name); + + /// Gets the GL uniform location for the specified resource, caching as needed + GLint GetUniformLocation(const std::string& name); + +private: + Tegra::GPUVAddr addr; + Maxwell::ShaderProgram program_type; + GLShader::ShaderSetup setup; + GLShader::ShaderEntries entries; + OGLProgram program; + + std::unordered_map resource_cache; + std::unordered_map uniform_cache; +}; + +class ShaderCacheOpenGL final : public RasterizerCache { +public: + /// Gets the current specified shader stage program + Shader GetStageProgram(Maxwell::ShaderProgram program); +}; + +} // namespace OpenGL -- cgit v1.2.3