mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
VideoBackends: Add AbstractShader and AbstractPipeline classes
This commit is contained in:
@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Common/GL/GLUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
@ -21,7 +23,9 @@ class cInterfaceBase;
|
||||
|
||||
namespace OGL
|
||||
{
|
||||
class OGLShader;
|
||||
class GLVertexFormat;
|
||||
class StreamBuffer;
|
||||
|
||||
class SHADERUID
|
||||
{
|
||||
@ -81,6 +85,29 @@ struct SHADER
|
||||
void DestroyShaders();
|
||||
};
|
||||
|
||||
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};
|
||||
};
|
||||
|
||||
class ProgramShaderCache
|
||||
{
|
||||
public:
|
||||
@ -98,6 +125,7 @@ public:
|
||||
static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format);
|
||||
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
||||
static void InvalidateVertexFormat();
|
||||
static void InvalidateLastProgram();
|
||||
|
||||
static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
|
||||
const std::string& gcode = "");
|
||||
@ -106,6 +134,9 @@ public:
|
||||
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);
|
||||
static StreamBuffer* GetUniformBuffer();
|
||||
static u32 GetUniformBufferAlignment();
|
||||
static void InvalidateConstants();
|
||||
static void UploadConstants();
|
||||
|
||||
static void Init();
|
||||
@ -115,6 +146,11 @@ public:
|
||||
static void RetrieveAsyncShaders();
|
||||
static void PrecompileUberShaders();
|
||||
|
||||
static const PipelineProgram* GetPipelineProgram(const OGLShader* vertex_shader,
|
||||
const OGLShader* geometry_shader,
|
||||
const OGLShader* pixel_shader);
|
||||
static void ReleasePipelineProgram(const PipelineProgram* prog);
|
||||
|
||||
private:
|
||||
template <typename UIDType>
|
||||
class ProgramShaderCacheInserter : public LinearDiskCacheReader<UIDType, u8>
|
||||
@ -189,6 +225,9 @@ private:
|
||||
|
||||
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
||||
typedef std::map<UBERSHADERUID, PCacheEntry> UberPCache;
|
||||
typedef std::unordered_map<PipelineProgramKey, std::unique_ptr<PipelineProgram>,
|
||||
PipelineProgramKeyHash>
|
||||
PipelineProgramMap;
|
||||
|
||||
static void CreateAttributelessVAO();
|
||||
static GLuint CreateProgramFromBinary(const u8* value, u32 value_size);
|
||||
@ -202,6 +241,7 @@ private:
|
||||
|
||||
static PCache pshaders;
|
||||
static UberPCache ubershaders;
|
||||
static PipelineProgramMap pipelineprograms;
|
||||
static PCacheEntry* last_entry;
|
||||
static PCacheEntry* last_uber_entry;
|
||||
static SHADERUID last_uid;
|
||||
|
Reference in New Issue
Block a user