Skip to content
Snippets Groups Projects
Commit a3703f57 authored by ReinUsesLisp's avatar ReinUsesLisp
Browse files

gl_shader_cache: Refactor to support disk shader cache

parent 40390862
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <array> #include <array>
#include <map> #include <map>
#include <memory> #include <memory>
#include <set>
#include <tuple> #include <tuple>
#include <glad/glad.h> #include <glad/glad.h>
...@@ -23,13 +24,25 @@ namespace OpenGL { ...@@ -23,13 +24,25 @@ namespace OpenGL {
class CachedShader; class CachedShader;
class RasterizerOpenGL; class RasterizerOpenGL;
struct UnspecializedShader;
using Shader = std::shared_ptr<CachedShader>; using Shader = std::shared_ptr<CachedShader>;
using CachedProgram = std::shared_ptr<OGLProgram>;
using Maxwell = Tegra::Engines::Maxwell3D::Regs; using Maxwell = Tegra::Engines::Maxwell3D::Regs;
using PrecompiledPrograms = std::map<ShaderDiskCacheUsage, CachedProgram>;
using PrecompiledShaders = std::map<u64, GLShader::ProgramResult>;
class CachedShader final : public RasterizerCacheObject { class CachedShader final : public RasterizerCacheObject {
public: public:
CachedShader(VAddr addr, Maxwell::ShaderProgram program_type); explicit CachedShader(VAddr addr, u64 unique_identifier, Maxwell::ShaderProgram program_type,
ShaderDiskCacheOpenGL& disk_cache,
const PrecompiledPrograms& precompiled_programs,
ProgramCode&& program_code, ProgramCode&& program_code_b);
explicit CachedShader(VAddr addr, u64 unique_identifier, Maxwell::ShaderProgram program_type,
ShaderDiskCacheOpenGL& disk_cache,
const PrecompiledPrograms& precompiled_programs,
GLShader::ProgramResult result);
VAddr GetAddr() const override { VAddr GetAddr() const override {
return addr; return addr;
...@@ -56,33 +69,35 @@ private: ...@@ -56,33 +69,35 @@ private:
// declared by the hardware. Workaround this issue by generating a different shader per input // declared by the hardware. Workaround this issue by generating a different shader per input
// topology class. // topology class.
struct GeometryPrograms { struct GeometryPrograms {
OGLProgram points; CachedProgram points;
OGLProgram lines; CachedProgram lines;
OGLProgram lines_adjacency; CachedProgram lines_adjacency;
OGLProgram triangles; CachedProgram triangles;
OGLProgram triangles_adjacency; CachedProgram triangles_adjacency;
}; };
std::string AllocateBindings(BaseBindings base_bindings);
GLuint GetGeometryShader(GLenum primitive_mode, BaseBindings base_bindings); GLuint GetGeometryShader(GLenum primitive_mode, BaseBindings base_bindings);
/// Generates a geometry shader or returns one that already exists. /// Generates a geometry shader or returns one that already exists.
GLuint LazyGeometryProgram(OGLProgram& target_program, BaseBindings base_bindings, GLuint LazyGeometryProgram(CachedProgram& target_program, BaseBindings base_bindings,
const std::string& glsl_topology, u32 max_vertices, GLenum primitive_mode);
const std::string& debug_name);
CachedProgram TryLoadProgram(GLenum primitive_mode, BaseBindings base_bindings) const;
ShaderDiskCacheUsage GetUsage(GLenum primitive_mode, BaseBindings base_bindings) const;
void CalculateProperties(); const VAddr addr;
const u64 unique_identifier;
const Maxwell::ShaderProgram program_type;
ShaderDiskCacheOpenGL& disk_cache;
const PrecompiledPrograms& precompiled_programs;
VAddr addr{};
std::size_t shader_length{}; std::size_t shader_length{};
Maxwell::ShaderProgram program_type{};
GLShader::ShaderSetup setup;
GLShader::ShaderEntries entries; GLShader::ShaderEntries entries;
std::string code; std::string code;
std::map<BaseBindings, OGLProgram> programs; std::map<BaseBindings, CachedProgram> programs;
std::map<BaseBindings, GeometryPrograms> geometry_programs; std::map<BaseBindings, GeometryPrograms> geometry_programs;
std::map<u32, GLuint> cbuf_resource_cache; std::map<u32, GLuint> cbuf_resource_cache;
...@@ -101,7 +116,19 @@ public: ...@@ -101,7 +116,19 @@ public:
Shader GetStageProgram(Maxwell::ShaderProgram program); Shader GetStageProgram(Maxwell::ShaderProgram program);
private: private:
std::map<u64, UnspecializedShader> GenerateUnspecializedShaders(
const std::vector<ShaderDiskCacheRaw>& raws);
CachedProgram GeneratePrecompiledProgram(
std::vector<ShaderDiskCachePrecompiledEntry>& precompiled,
const ShaderDiskCachePrecompiledEntry& precompiled_entry,
const std::set<GLenum>& supported_formats);
std::array<Shader, Maxwell::MaxShaderProgram> last_shaders; std::array<Shader, Maxwell::MaxShaderProgram> last_shaders;
ShaderDiskCacheOpenGL disk_cache;
PrecompiledShaders precompiled_shaders;
PrecompiledPrograms precompiled_programs;
}; };
} // namespace OpenGL } // namespace OpenGL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment