diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2018-03-10 08:22:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-10 08:22:28 +0100 |
| commit | a4ef133456a18178f345d3c25195bf74c0e83750 (patch) | |
| tree | 1564aa8e85c3800882466b953984a57be0bf0b0c /Source/Core/VideoBackends/OGL/ProgramShaderCache.h | |
| parent | 63838c013bde06ed13bfc1b5e24c53594934f641 (diff) | |
| parent | 93ab50c55584c416d32b5bbdf39f37e9c67f4105 (diff) | |
Merge pull request #6399 from stenzek/videocommon-shader-cache
VideoCommon Shader (Pipeline) Cache
Diffstat (limited to 'Source/Core/VideoBackends/OGL/ProgramShaderCache.h')
| -rw-r--r-- | Source/Core/VideoBackends/OGL/ProgramShaderCache.h | 162 |
1 files changed, 13 insertions, 149 deletions
diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h index 635c1d3097..0096c6e5b9 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.h +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.h @@ -6,20 +6,12 @@ #include <atomic> #include <memory> +#include <mutex> #include <tuple> #include <unordered_map> #include "Common/GL/GLUtil.h" -#include "Common/LinearDiskCache.h" - #include "VideoCommon/AsyncShaderCompiler.h" -#include "VideoCommon/GeometryShaderGen.h" -#include "VideoCommon/PixelShaderGen.h" -#include "VideoCommon/UberShaderPixel.h" -#include "VideoCommon/UberShaderVertex.h" -#include "VideoCommon/VertexShaderGen.h" - -class cInterfaceBase; namespace OGL { @@ -27,41 +19,6 @@ class OGLShader; class GLVertexFormat; class StreamBuffer; -class SHADERUID -{ -public: - VertexShaderUid vuid; - PixelShaderUid puid; - GeometryShaderUid guid; - - bool operator<(const SHADERUID& r) const - { - return std::tie(vuid, puid, guid) < std::tie(r.vuid, r.puid, r.guid); - } - - bool operator==(const SHADERUID& r) const - { - return std::tie(vuid, puid, guid) == std::tie(r.vuid, r.puid, r.guid); - } -}; -class UBERSHADERUID -{ -public: - UberShader::VertexShaderUid vuid; - UberShader::PixelShaderUid puid; - GeometryShaderUid guid; - - bool operator<(const UBERSHADERUID& r) const - { - return std::tie(vuid, puid, guid) < std::tie(r.vuid, r.puid, r.guid); - } - - bool operator==(const UBERSHADERUID& r) const - { - return std::tie(vuid, puid, guid) == std::tie(r.vuid, r.puid, r.guid); - } -}; - struct SHADER { void Destroy() @@ -111,18 +68,6 @@ struct PipelineProgram class ProgramShaderCache { public: - struct PCacheEntry - { - SHADER shader; - bool in_cache; - bool pending; - - void Destroy() { shader.Destroy(); } - }; - - static PCacheEntry GetShaderProgram(); - static SHADER* SetShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format); - static SHADER* SetUberShader(PrimitiveType primitive_type, const GLVertexFormat* vertex_format); static void BindVertexFormat(const GLVertexFormat* vertex_format); static void InvalidateVertexFormat(); static void InvalidateLastProgram(); @@ -140,114 +85,25 @@ public: static void UploadConstants(); static void Init(); - static void Reload(); static void Shutdown(); static void CreateHeader(); - static void RetrieveAsyncShaders(); - static void PrecompileUberShaders(); - static const PipelineProgram* GetPipelineProgram(const OGLShader* vertex_shader, + static const PipelineProgram* GetPipelineProgram(const GLVertexFormat* vertex_format, + 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> - { - public: - ProgramShaderCacheInserter(std::map<UIDType, PCacheEntry>& shader_map) - : m_shader_map(shader_map) - { - } - - void Read(const UIDType& key, const u8* value, u32 value_size) override - { - if (m_shader_map.find(key) != m_shader_map.end()) - return; - - PCacheEntry& entry = m_shader_map[key]; - if (!CreateCacheEntryFromBinary(&entry, value, value_size)) - { - m_shader_map.erase(key); - return; - } - } - - private: - std::map<UIDType, PCacheEntry>& m_shader_map; - }; - - class SharedContextAsyncShaderCompiler : public VideoCommon::AsyncShaderCompiler - { - protected: - bool WorkerThreadInitMainThread(void** param) override; - bool WorkerThreadInitWorkerThread(void* param) override; - void WorkerThreadExit(void* param) override; - }; - - struct SharedContextData - { - std::unique_ptr<cInterfaceBase> context; - GLuint prerender_FBO; - GLuint prerender_FBO_tex; - GLuint prerender_FBO_depth; - GLuint prerender_VBO; - GLuint prerender_VAO; - GLuint prerender_IBO; - }; - - class ShaderCompileWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem - { - public: - explicit ShaderCompileWorkItem(const SHADERUID& uid); - - bool Compile() override; - void Retrieve() override; - - private: - SHADERUID m_uid; - SHADER m_program; - }; - - class UberShaderCompileWorkItem : public VideoCommon::AsyncShaderCompiler::WorkItem - { - public: - explicit UberShaderCompileWorkItem(const UBERSHADERUID& uid); - - bool Compile() override; - void Retrieve() override; - - private: - UBERSHADERUID m_uid; - SHADER m_program; - }; - - 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); - static bool CreateCacheEntryFromBinary(PCacheEntry* entry, const u8* value, u32 value_size); - static void LoadProgramBinaries(); - static void SaveProgramBinaries(); - static void DestroyShaders(); - static void CreatePrerenderArrays(SharedContextData* data); - static void DestroyPrerenderArrays(SharedContextData* data); - static void DrawPrerenderArray(const SHADER& shader, PrimitiveType primitive_type); - static PCache pshaders; - static UberPCache ubershaders; - static PipelineProgramMap pipelineprograms; - static PCacheEntry* last_entry; - static PCacheEntry* last_uber_entry; - static SHADERUID last_uid; - static UBERSHADERUID last_uber_uid; + static PipelineProgramMap s_pipeline_programs; + static std::mutex s_pipeline_program_lock; - static std::unique_ptr<SharedContextAsyncShaderCompiler> s_async_compiler; static u32 s_ubo_buffer_size; static s32 s_ubo_align; @@ -256,4 +112,12 @@ private: static GLuint s_last_VAO; }; +class SharedContextAsyncShaderCompiler : public VideoCommon::AsyncShaderCompiler +{ +protected: + bool WorkerThreadInitMainThread(void** param) override; + bool WorkerThreadInitWorkerThread(void* param) override; + void WorkerThreadExit(void* param) override; +}; + } // namespace OGL |
