summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-09-04 18:20:14 -0400
committerGravatar GitHub2018-09-04 18:20:14 -0400
commita1ef02c3e6f40eb98b1608229451943f8e64f861 (patch)
tree3ffdcceaf003fdc23244bfb4b639a603ea4aaf57 /src
parentMerge pull request #1178 from DarkLordZach/nsp (diff)
parentgl_shader_cache: Use an u32 for the binding point cache. (diff)
downloadyuzu-a1ef02c3e6f40eb98b1608229451943f8e64f861.tar.gz
yuzu-a1ef02c3e6f40eb98b1608229451943f8e64f861.tar.xz
yuzu-a1ef02c3e6f40eb98b1608229451943f8e64f861.zip
Merge pull request #1240 from degasus/optimizations
gl_shader_cache: Use an u32 for the binding point cache.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp16
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h10
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.h8
4 files changed, 23 insertions, 15 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index e260c9140..7ee3f2ae7 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -709,7 +709,7 @@ std::tuple<u8*, GLintptr, u32> RasterizerOpenGL::SetupConstBuffers(u8* buffer_pt
709 709
710 // Now configure the bindpoint of the buffer inside the shader 710 // Now configure the bindpoint of the buffer inside the shader
711 glUniformBlockBinding(shader->GetProgramHandle(), 711 glUniformBlockBinding(shader->GetProgramHandle(),
712 shader->GetProgramResourceIndex(used_buffer.GetName()), 712 shader->GetProgramResourceIndex(used_buffer),
713 current_bindpoint + bindpoint); 713 current_bindpoint + bindpoint);
714 } 714 }
715 715
@@ -733,7 +733,7 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
733 733
734 // Bind the uniform to the sampler. 734 // Bind the uniform to the sampler.
735 735
736 glProgramUniform1i(shader->GetProgramHandle(), shader->GetUniformLocation(entry.GetName()), 736 glProgramUniform1i(shader->GetProgramHandle(), shader->GetUniformLocation(entry),
737 current_bindpoint); 737 current_bindpoint);
738 738
739 const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset()); 739 const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset());
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index ac9adfd83..7e4b85ac3 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -85,23 +85,23 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
85 SetShaderUniformBlockBindings(program.handle); 85 SetShaderUniformBlockBindings(program.handle);
86} 86}
87 87
88GLuint CachedShader::GetProgramResourceIndex(const std::string& name) { 88GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
89 auto search{resource_cache.find(name)}; 89 auto search{resource_cache.find(buffer.GetHash())};
90 if (search == resource_cache.end()) { 90 if (search == resource_cache.end()) {
91 const GLuint index{ 91 const GLuint index{
92 glGetProgramResourceIndex(program.handle, GL_UNIFORM_BLOCK, name.c_str())}; 92 glGetProgramResourceIndex(program.handle, GL_UNIFORM_BLOCK, buffer.GetName().c_str())};
93 resource_cache[name] = index; 93 resource_cache[buffer.GetHash()] = index;
94 return index; 94 return index;
95 } 95 }
96 96
97 return search->second; 97 return search->second;
98} 98}
99 99
100GLint CachedShader::GetUniformLocation(const std::string& name) { 100GLint CachedShader::GetUniformLocation(const GLShader::SamplerEntry& sampler) {
101 auto search{uniform_cache.find(name)}; 101 auto search{uniform_cache.find(sampler.GetHash())};
102 if (search == uniform_cache.end()) { 102 if (search == uniform_cache.end()) {
103 const GLint index{glGetUniformLocation(program.handle, name.c_str())}; 103 const GLint index{glGetUniformLocation(program.handle, sampler.GetName().c_str())};
104 uniform_cache[name] = index; 104 uniform_cache[sampler.GetHash()] = index;
105 return index; 105 return index;
106 } 106 }
107 107
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index 759987604..6e6febcbc 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -4,8 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <map>
7#include <memory> 8#include <memory>
8#include <unordered_map>
9 9
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "video_core/rasterizer_cache.h" 11#include "video_core/rasterizer_cache.h"
@@ -43,10 +43,10 @@ public:
43 } 43 }
44 44
45 /// Gets the GL program resource location for the specified resource, caching as needed 45 /// Gets the GL program resource location for the specified resource, caching as needed
46 GLuint GetProgramResourceIndex(const std::string& name); 46 GLuint GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer);
47 47
48 /// Gets the GL uniform location for the specified resource, caching as needed 48 /// Gets the GL uniform location for the specified resource, caching as needed
49 GLint GetUniformLocation(const std::string& name); 49 GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
50 50
51private: 51private:
52 VAddr addr; 52 VAddr addr;
@@ -55,8 +55,8 @@ private:
55 GLShader::ShaderEntries entries; 55 GLShader::ShaderEntries entries;
56 OGLProgram program; 56 OGLProgram program;
57 57
58 std::unordered_map<std::string, GLuint> resource_cache; 58 std::map<u32, GLuint> resource_cache;
59 std::unordered_map<std::string, GLint> uniform_cache; 59 std::map<u32, GLint> uniform_cache;
60}; 60};
61 61
62class ShaderCacheOpenGL final : public RasterizerCache<Shader> { 62class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h
index c788099d4..cbb2090ea 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.h
+++ b/src/video_core/renderer_opengl/gl_shader_gen.h
@@ -53,6 +53,10 @@ public:
53 return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index); 53 return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index);
54 } 54 }
55 55
56 u32 GetHash() const {
57 return (static_cast<u32>(stage) << 16) | index;
58 }
59
56private: 60private:
57 static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = { 61 static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = {
58 "buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c", 62 "buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c",
@@ -89,6 +93,10 @@ public:
89 std::to_string(sampler_index) + ']'; 93 std::to_string(sampler_index) + ']';
90 } 94 }
91 95
96 u32 GetHash() const {
97 return (static_cast<u32>(stage) << 16) | static_cast<u32>(sampler_index);
98 }
99
92 static std::string GetArrayName(Maxwell::ShaderStage stage) { 100 static std::string GetArrayName(Maxwell::ShaderStage stage) {
93 return TextureSamplerNames[static_cast<size_t>(stage)]; 101 return TextureSamplerNames[static_cast<size_t>(stage)];
94 } 102 }