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