2018-08-23 23:30:27 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-06 07:58:43 +01:00
|
|
|
#include <array>
|
2018-09-04 20:55:34 +02:00
|
|
|
#include <map>
|
2018-08-23 23:30:27 +02:00
|
|
|
#include <memory>
|
2019-01-14 04:58:15 +01:00
|
|
|
#include <set>
|
2019-01-05 05:00:06 +01:00
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <glad/glad.h>
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
#include "common/assert.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/rasterizer_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-12-26 05:57:14 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
2019-01-14 02:36:52 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
class CachedShader;
|
2018-11-08 12:08:00 +01:00
|
|
|
class RasterizerOpenGL;
|
2019-01-14 04:58:15 +01:00
|
|
|
struct UnspecializedShader;
|
2018-11-08 12:08:00 +01:00
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
using Shader = std::shared_ptr<CachedShader>;
|
2019-01-14 04:58:15 +01:00
|
|
|
using CachedProgram = std::shared_ptr<OGLProgram>;
|
2018-08-23 23:30:27 +02:00
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
2019-01-14 04:58:15 +01:00
|
|
|
using PrecompiledPrograms = std::map<ShaderDiskCacheUsage, CachedProgram>;
|
|
|
|
using PrecompiledShaders = std::map<u64, GLShader::ProgramResult>;
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
class CachedShader final : public RasterizerCacheObject {
|
2018-08-23 23:30:27 +02:00
|
|
|
public:
|
2019-01-14 04:58:15 +01:00
|
|
|
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);
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
VAddr GetAddr() const override {
|
2018-08-23 23:30:27 +02:00
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2018-10-16 22:51:53 +02:00
|
|
|
std::size_t GetSizeInBytes() const override {
|
2018-11-20 20:14:48 +01:00
|
|
|
return shader_length;
|
2018-08-23 23:30:27 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 01:28:58 +02:00
|
|
|
// We do not have to flush this cache as things in it are never modified by us.
|
2018-10-16 22:51:53 +02:00
|
|
|
void Flush() override {}
|
2018-10-10 01:28:58 +02:00
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
/// Gets the shader entries for the shader
|
|
|
|
const GLShader::ShaderEntries& GetShaderEntries() const {
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the GL program handle for the shader
|
2019-01-05 05:00:06 +01:00
|
|
|
std::tuple<GLuint, BaseBindings> GetProgramHandle(GLenum primitive_mode,
|
|
|
|
BaseBindings base_bindings);
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
private:
|
|
|
|
// Geometry programs. These are needed because GLSL needs an input topology but it's not
|
|
|
|
// declared by the hardware. Workaround this issue by generating a different shader per input
|
|
|
|
// topology class.
|
|
|
|
struct GeometryPrograms {
|
2019-01-14 04:58:15 +01:00
|
|
|
CachedProgram points;
|
|
|
|
CachedProgram lines;
|
|
|
|
CachedProgram lines_adjacency;
|
|
|
|
CachedProgram triangles;
|
|
|
|
CachedProgram triangles_adjacency;
|
2019-01-05 05:00:06 +01:00
|
|
|
};
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
GLuint GetGeometryShader(GLenum primitive_mode, BaseBindings base_bindings);
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
/// Generates a geometry shader or returns one that already exists.
|
2019-01-14 04:58:15 +01:00
|
|
|
GLuint LazyGeometryProgram(CachedProgram& target_program, BaseBindings base_bindings,
|
|
|
|
GLenum primitive_mode);
|
|
|
|
|
|
|
|
CachedProgram TryLoadProgram(GLenum primitive_mode, BaseBindings base_bindings) const;
|
|
|
|
|
|
|
|
ShaderDiskCacheUsage GetUsage(GLenum primitive_mode, BaseBindings base_bindings) const;
|
2018-10-07 04:17:31 +02:00
|
|
|
|
2019-01-14 04:58:15 +01:00
|
|
|
const VAddr addr;
|
|
|
|
const u64 unique_identifier;
|
|
|
|
const Maxwell::ShaderProgram program_type;
|
|
|
|
ShaderDiskCacheOpenGL& disk_cache;
|
|
|
|
const PrecompiledPrograms& precompiled_programs;
|
2018-12-09 22:33:10 +01:00
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
std::size_t shader_length{};
|
2018-08-23 23:30:27 +02:00
|
|
|
GLShader::ShaderEntries entries;
|
2018-10-07 04:17:31 +02:00
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
std::string code;
|
2018-08-23 23:30:27 +02:00
|
|
|
|
2019-01-14 04:58:15 +01:00
|
|
|
std::map<BaseBindings, CachedProgram> programs;
|
2019-01-05 05:00:06 +01:00
|
|
|
std::map<BaseBindings, GeometryPrograms> geometry_programs;
|
2018-10-07 04:17:31 +02:00
|
|
|
|
2019-01-05 05:01:38 +01:00
|
|
|
std::map<u32, GLuint> cbuf_resource_cache;
|
|
|
|
std::map<u32, GLuint> gmem_resource_cache;
|
2018-09-04 20:55:34 +02:00
|
|
|
std::map<u32, GLint> uniform_cache;
|
2018-08-23 23:30:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
|
|
|
|
public:
|
2018-11-08 12:08:00 +01:00
|
|
|
explicit ShaderCacheOpenGL(RasterizerOpenGL& rasterizer);
|
|
|
|
|
2019-01-14 02:05:53 +01:00
|
|
|
/// Loads disk cache for the current game
|
|
|
|
void LoadDiskCache();
|
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
/// Gets the current specified shader stage program
|
|
|
|
Shader GetStageProgram(Maxwell::ShaderProgram program);
|
2019-01-06 07:58:43 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-14 04:58:15 +01:00
|
|
|
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);
|
|
|
|
|
2019-01-06 07:58:43 +01:00
|
|
|
std::array<Shader, Maxwell::MaxShaderProgram> last_shaders;
|
2019-01-14 04:58:15 +01:00
|
|
|
|
|
|
|
ShaderDiskCacheOpenGL disk_cache;
|
|
|
|
PrecompiledShaders precompiled_shaders;
|
|
|
|
PrecompiledPrograms precompiled_programs;
|
2018-08-23 23:30:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|