2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2011-11-30 20:00:21 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2011-11-30 20:00:21 -07:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
#include <atomic>
|
2017-07-19 23:25:29 -06:00
|
|
|
#include <memory>
|
2018-02-24 05:14:31 -07:00
|
|
|
#include <mutex>
|
2016-01-01 20:28:42 -07:00
|
|
|
#include <tuple>
|
2017-09-08 03:42:56 -06:00
|
|
|
#include <unordered_map>
|
2016-01-01 20:28:42 -07:00
|
|
|
|
2015-09-18 10:40:00 -06:00
|
|
|
#include "Common/GL/GLUtil.h"
|
2017-07-19 23:25:29 -06:00
|
|
|
|
2011-12-26 00:58:52 -07:00
|
|
|
namespace OGL
|
2011-12-25 22:15:54 -07:00
|
|
|
{
|
2017-09-08 03:42:56 -06:00
|
|
|
class OGLShader;
|
2017-07-19 23:25:29 -06:00
|
|
|
class GLVertexFormat;
|
2017-09-08 03:42:56 -06:00
|
|
|
class StreamBuffer;
|
2017-07-19 23:25:29 -06:00
|
|
|
|
2013-02-13 05:12:19 -07:00
|
|
|
struct SHADER
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
void Destroy()
|
|
|
|
{
|
2017-07-19 23:25:29 -06:00
|
|
|
DestroyShaders();
|
|
|
|
if (glprogid)
|
|
|
|
{
|
|
|
|
glDeleteProgram(glprogid);
|
|
|
|
glprogid = 0;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2017-07-19 23:25:29 -06:00
|
|
|
GLuint vsid = 0;
|
|
|
|
GLuint gsid = 0;
|
|
|
|
GLuint psid = 0;
|
|
|
|
GLuint glprogid = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
void SetProgramVariables();
|
2016-11-27 01:14:56 -07:00
|
|
|
void SetProgramBindings(bool is_compute);
|
2017-04-22 22:44:34 -06:00
|
|
|
void Bind() const;
|
2017-07-19 23:25:29 -06:00
|
|
|
void DestroyShaders();
|
2013-02-13 05:12:19 -07:00
|
|
|
};
|
2011-12-26 00:58:52 -07:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
struct PipelineProgramKey
|
|
|
|
{
|
|
|
|
const OGLShader* vertex_shader;
|
|
|
|
const OGLShader* geometry_shader;
|
|
|
|
const OGLShader* pixel_shader;
|
|
|
|
|
|
|
|
bool operator==(const PipelineProgramKey& rhs) const;
|
|
|
|
bool operator!=(const PipelineProgramKey& rhs) const;
|
|
|
|
bool operator<(const PipelineProgramKey& rhs) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PipelineProgramKeyHash
|
|
|
|
{
|
|
|
|
std::size_t operator()(const PipelineProgramKey& key) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PipelineProgram
|
|
|
|
{
|
|
|
|
PipelineProgramKey key;
|
|
|
|
SHADER shader;
|
|
|
|
std::atomic_size_t reference_count{1};
|
|
|
|
};
|
|
|
|
|
2011-12-26 00:58:52 -07:00
|
|
|
class ProgramShaderCache
|
2011-11-30 20:00:21 -07:00
|
|
|
{
|
|
|
|
public:
|
2017-07-19 23:25:29 -06:00
|
|
|
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
|
|
|
static void InvalidateVertexFormat();
|
2017-09-08 03:42:56 -06:00
|
|
|
static void InvalidateLastProgram();
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
|
|
|
|
const std::string& gcode = "");
|
2016-11-27 01:14:56 -07:00
|
|
|
static bool CompileComputeShader(SHADER& shader, const std::string& code);
|
2017-07-19 23:25:29 -06:00
|
|
|
static GLuint CompileSingleShader(GLenum type, const std::string& code);
|
|
|
|
static bool CheckShaderCompileResult(GLuint id, GLenum type, const std::string& code);
|
|
|
|
static bool CheckProgramLinkResult(GLuint id, const std::string& vcode, const std::string& pcode,
|
|
|
|
const std::string& gcode);
|
2017-09-08 03:42:56 -06:00
|
|
|
static StreamBuffer* GetUniformBuffer();
|
|
|
|
static u32 GetUniformBufferAlignment();
|
|
|
|
static void InvalidateConstants();
|
2016-06-24 02:43:46 -06:00
|
|
|
static void UploadConstants();
|
2011-12-26 00:58:52 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
|
|
|
static void CreateHeader();
|
2011-12-26 00:58:52 -07:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
static const PipelineProgram* GetPipelineProgram(const OGLShader* vertex_shader,
|
|
|
|
const OGLShader* geometry_shader,
|
|
|
|
const OGLShader* pixel_shader);
|
|
|
|
static void ReleasePipelineProgram(const PipelineProgram* prog);
|
|
|
|
|
2011-12-26 00:58:52 -07:00
|
|
|
private:
|
2017-09-08 03:42:56 -06:00
|
|
|
typedef std::unordered_map<PipelineProgramKey, std::unique_ptr<PipelineProgram>,
|
|
|
|
PipelineProgramKeyHash>
|
|
|
|
PipelineProgramMap;
|
2017-07-19 23:25:29 -06:00
|
|
|
|
2018-01-20 07:59:10 -07:00
|
|
|
static void CreateAttributelessVAO();
|
2017-06-24 03:20:34 -06:00
|
|
|
|
2017-09-08 03:42:56 -06:00
|
|
|
static PipelineProgramMap pipelineprograms;
|
2018-02-24 05:14:31 -07:00
|
|
|
static std::mutex pipelineprogramlock;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
static u32 s_ubo_buffer_size;
|
|
|
|
static s32 s_ubo_align;
|
2018-01-20 07:59:10 -07:00
|
|
|
|
|
|
|
static GLuint s_attributeless_VBO;
|
|
|
|
static GLuint s_attributeless_VAO;
|
|
|
|
static GLuint s_last_VAO;
|
2011-11-30 20:00:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OGL
|