diff options
| author | Stenzek <stenzek@gmail.com> | 2017-09-08 19:42:56 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2018-02-22 22:02:34 +1000 |
| commit | fec6bb4d5676de8834c90d93127c1459f46f8dcb (patch) | |
| tree | f484dbc96cc5bdc49282a63b973c98e93ec2bfad /Source/Core/VideoBackends/OGL/ProgramShaderCache.h | |
| parent | 31111ef1432bc5d6d653fbef175e8ca3ac2c152d (diff) | |
VideoBackends: Add AbstractShader and AbstractPipeline classes
Diffstat (limited to 'Source/Core/VideoBackends/OGL/ProgramShaderCache.h')
| -rw-r--r-- | Source/Core/VideoBackends/OGL/ProgramShaderCache.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h index 6d3f95954e..635c1d3097 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h @@ -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; |
