diff options
author | bunnei <bunneidev@gmail.com> | 2018-04-15 18:12:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-15 18:12:17 +0200 |
commit | 34264879b359107ec0c2fdb6af4b17faf52e4a6a (patch) | |
tree | f283b7d9b9014488dabd45e97f5687c2d67e842d /src/video_core/renderer_opengl/gl_shader_manager.h | |
parent | Merge pull request #328 from Subv/constbuffers (diff) | |
parent | shaders: Expose hints about used const buffers. (diff) | |
download | yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar.gz yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar.bz2 yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar.lz yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar.xz yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.tar.zst yuzu-34264879b359107ec0c2fdb6af4b17faf52e4a6a.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_manager.h')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_manager.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index f003ce532..ecc92d986 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -41,19 +41,25 @@ class OGLShaderStage { public: OGLShaderStage() = default; - void Create(const char* source, GLenum type) { + void Create(const ProgramResult& program_result, GLenum type) { OGLShader shader; - shader.Create(source, type); + shader.Create(program_result.first.c_str(), type); program.Create(true, shader.handle); Impl::SetShaderUniformBlockBindings(program.handle); Impl::SetShaderSamplerBindings(program.handle); + entries = program_result.second; } GLuint GetHandle() const { return program.handle; } + ShaderEntries GetEntries() const { + return entries; + } + private: OGLProgram program; + ShaderEntries entries; }; // TODO(wwylele): beautify this doc @@ -61,25 +67,28 @@ private: // The double cache is needed because diffent KeyConfigType, which includes a hash of the code // region (including its leftover unused code) can generate the same GLSL code. template <typename KeyConfigType, - std::string (*CodeGenerator)(const ShaderSetup&, const KeyConfigType&), GLenum ShaderType> + ProgramResult (*CodeGenerator)(const ShaderSetup&, const KeyConfigType&), + GLenum ShaderType> class ShaderCache { public: ShaderCache() = default; - GLuint Get(const KeyConfigType& key, const ShaderSetup& setup) { + using Result = std::pair<GLuint, ShaderEntries>; + + Result Get(const KeyConfigType& key, const ShaderSetup& setup) { auto map_it = shader_map.find(key); if (map_it == shader_map.end()) { - std::string program = CodeGenerator(setup, key); + ProgramResult program = CodeGenerator(setup, key); - auto [iter, new_shader] = shader_cache.emplace(program, OGLShaderStage{}); + auto [iter, new_shader] = shader_cache.emplace(program.first, OGLShaderStage{}); OGLShaderStage& cached_shader = iter->second; if (new_shader) { - cached_shader.Create(program.c_str(), ShaderType); + cached_shader.Create(program, ShaderType); } shader_map[key] = &cached_shader; - return cached_shader.GetHandle(); + return {cached_shader.GetHandle(), program.second}; } else { - return map_it->second->GetHandle(); + return {map_it->second->GetHandle(), map_it->second->GetEntries()}; } } @@ -98,12 +107,18 @@ public: pipeline.Create(); } - void UseProgrammableVertexShader(const MaxwellVSConfig& config, const ShaderSetup setup) { - current.vs = vertex_shaders.Get(config, setup); + ShaderEntries UseProgrammableVertexShader(const MaxwellVSConfig& config, + const ShaderSetup setup) { + ShaderEntries result; + std::tie(current.vs, result) = vertex_shaders.Get(config, setup); + return result; } - void UseProgrammableFragmentShader(const MaxwellFSConfig& config, const ShaderSetup setup) { - current.fs = fragment_shaders.Get(config, setup); + ShaderEntries UseProgrammableFragmentShader(const MaxwellFSConfig& config, + const ShaderSetup setup) { + ShaderEntries result; + std::tie(current.fs, result) = fragment_shaders.Get(config, setup); + return result; } void UseTrivialGeometryShader() { |