From 3fd4142f361bd6af2c147faf48e1d1d62d170067 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 21 Jan 2018 00:59:10 +1000 Subject: OGL: Track state of last bound vertex array object This reduces the overhead of calling glBindVertexArray() every time RestoreAPIState() is called, even when it is redundant. --- Source/Core/VideoBackends/OGL/ProgramShaderCache.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/ProgramShaderCache.h') diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h index 83f9d0e817..6d3f95954e 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h @@ -98,7 +98,6 @@ public: static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format); static void BindVertexFormat(const GLVertexFormat* vertex_format); static void InvalidateVertexFormat(); - static void BindLastVertexFormat(); static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode, const std::string& gcode = ""); @@ -191,6 +190,7 @@ private: typedef std::map PCache; typedef std::map UberPCache; + static void CreateAttributelessVAO(); static GLuint CreateProgramFromBinary(const u8* value, u32 value_size); static bool CreateCacheEntryFromBinary(PCacheEntry* entry, const u8* value, u32 value_size); static void LoadProgramBinaries(); @@ -210,7 +210,10 @@ private: static std::unique_ptr s_async_compiler; static u32 s_ubo_buffer_size; static s32 s_ubo_align; - static u32 s_last_VAO; + + static GLuint s_attributeless_VBO; + static GLuint s_attributeless_VAO; + static GLuint s_last_VAO; }; } // namespace OGL -- cgit v1.2.3 From fec6bb4d5676de8834c90d93127c1459f46f8dcb Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 8 Sep 2017 19:42:56 +1000 Subject: VideoBackends: Add AbstractShader and AbstractPipeline classes --- Source/Core/VideoBackends/OGL/ProgramShaderCache.h | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'Source/Core/VideoBackends/OGL/ProgramShaderCache.h') 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 #include #include +#include #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 class ProgramShaderCacheInserter : public LinearDiskCacheReader @@ -189,6 +225,9 @@ private: typedef std::map PCache; typedef std::map UberPCache; + typedef std::unordered_map, + 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; -- cgit v1.2.3