summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar FernandoS272018-10-10 15:06:32 -0400
committerGravatar FernandoS272018-10-22 15:07:32 -0400
commit17315cee16df0848ed095ba3bc3fc1460465a682 (patch)
tree389f727594923b179584c48c85b994d269c1f937 /src
parentRemove SyncAlphaTest and clang format (diff)
downloadyuzu-17315cee16df0848ed095ba3bc3fc1460465a682.tar.gz
yuzu-17315cee16df0848ed095ba3bc3fc1460465a682.tar.xz
yuzu-17315cee16df0848ed095ba3bc3fc1460465a682.zip
Cache uniform locations and restructure the implementation
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp26
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp24
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h12
3 files changed, 29 insertions, 33 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index e5fc6e8f5..0f8227f7b 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -885,18 +885,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
885void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { 885void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
886 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 886 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
887 887
888 glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(),
889 regs.alpha_test_enabled);
890 glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(),
891 regs.alpha_test_ref);
892
893 u32 func = static_cast<u32>(regs.alpha_test_func); 888 u32 func = static_cast<u32>(regs.alpha_test_func);
894 // Normalize the gl variants of opCompare to be the same as the normal variants 889 // Normalize the gl variants of opCompare to be the same as the normal variants
895 if (func >= 0x200) { 890 u32 op = static_cast<u32>(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never);
896 func = func - 0x200 + 1U; 891 if (func >= op) {
892 func = func - op + 1U;
897 } 893 }
898 894
899 glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func); 895 shader->SetAlphaTesting(regs.alpha_test_enabled == 1, regs.alpha_test_ref, func);
900} 896}
901 897
902void RasterizerOpenGL::SyncViewport() { 898void RasterizerOpenGL::SyncViewport() {
@@ -1026,18 +1022,6 @@ void RasterizerOpenGL::SyncLogicOpState() {
1026 state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation); 1022 state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
1027} 1023}
1028 1024
1029<<<<<<< HEAD
1030void RasterizerOpenGL::SyncAlphaTest() {
1031 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
1032
1033 // TODO(Rodrigo): Alpha testing is a legacy OpenGL feature, but it can be
1034 // implemented with a test+discard in fragment shaders.
1035 if (regs.alpha_test_enabled != 0) {
1036 LOG_CRITICAL(Render_OpenGL, "Alpha testing is not implemented");
1037 UNREACHABLE();
1038 }
1039}
1040
1041void RasterizerOpenGL::SyncScissorTest() { 1025void RasterizerOpenGL::SyncScissorTest() {
1042 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 1026 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
1043 1027
@@ -1054,8 +1038,6 @@ void RasterizerOpenGL::SyncScissorTest() {
1054 } 1038 }
1055} 1039}
1056 1040
1057=======
1058>>>>>>> Remove SyncAlphaTest and clang format
1059void RasterizerOpenGL::SyncTransformFeedback() { 1041void RasterizerOpenGL::SyncTransformFeedback() {
1060 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 1042 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
1061 1043
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index f4e99e5f4..ccb8b4805 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -94,6 +94,10 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
94 // Store shader's code to lazily build it on draw 94 // Store shader's code to lazily build it on draw
95 geometry_programs.code = program_result.first; 95 geometry_programs.code = program_result.first;
96 } 96 }
97
98 if (program_type == Maxwell::ShaderProgram::Fragment) {
99 SaveAlphaTestingLocations();
100 }
97} 101}
98 102
99GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) { 103GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
@@ -134,16 +138,20 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
134 return target_program.handle; 138 return target_program.handle;
135}; 139};
136 140
137GLint CachedShader::GetAlphaTestingEnableLocation() { 141void CachedShader::SetAlphaTesting(const bool enable, const float ref, const u32 func) {
138 return glGetUniformLocation(program.handle, "alpha_testing_enable"); 142 if (program_type == Maxwell::ShaderProgram::Fragment) {
139} 143 glProgramUniform1ui(program.handle, alpha_test.enable_loc,
140 144 (enable ? 1 : 0));
141GLint CachedShader::GetAlphaTestingFuncLocation() { 145 glProgramUniform1f(program.handle, alpha_test.ref_loc,
142 return glGetUniformLocation(program.handle, "alpha_testing_func"); 146 ref);
147 glProgramUniform1ui(program.handle, alpha_test.func_loc, func);
148 }
143} 149}
144 150
145GLint CachedShader::GetAlphaTestingRefLocation() { 151void CachedShader::SaveAlphaTestingLocations() {
146 return glGetUniformLocation(program.handle, "alpha_testing_ref"); 152 alpha_test.enable_loc = glGetUniformLocation(program.handle, "alpha_testing_enable");
153 alpha_test.ref_loc = glGetUniformLocation(program.handle, "alpha_testing_ref");
154 alpha_test.func_loc = glGetUniformLocation(program.handle, "alpha_testing_func");
147} 155}
148 156
149Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { 157Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index 2eaa63804..7c80ee86b 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -73,15 +73,15 @@ public:
73 /// Gets the GL uniform location for the specified resource, caching as needed 73 /// Gets the GL uniform location for the specified resource, caching as needed
74 GLint GetUniformLocation(const GLShader::SamplerEntry& sampler); 74 GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
75 75
76 GLint GetAlphaTestingEnableLocation(); 76 void SetAlphaTesting(const bool enable, const float ref, const u32 func);
77 GLint GetAlphaTestingFuncLocation();
78 GLint GetAlphaTestingRefLocation();
79 77
80private: 78private:
81 /// Generates a geometry shader or returns one that already exists. 79 /// Generates a geometry shader or returns one that already exists.
82 GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology, 80 GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
83 const std::string& debug_name); 81 const std::string& debug_name);
84 82
83 void SaveAlphaTestingLocations();
84
85 VAddr addr; 85 VAddr addr;
86 Maxwell::ShaderProgram program_type; 86 Maxwell::ShaderProgram program_type;
87 GLShader::ShaderSetup setup; 87 GLShader::ShaderSetup setup;
@@ -102,6 +102,12 @@ private:
102 OGLProgram triangles_adjacency; 102 OGLProgram triangles_adjacency;
103 } geometry_programs; 103 } geometry_programs;
104 104
105 struct {
106 GLint enable_loc;
107 GLint ref_loc;
108 GLint func_loc;
109 } alpha_test;
110
105 std::map<u32, GLuint> resource_cache; 111 std::map<u32, GLuint> resource_cache;
106 std::map<u32, GLint> uniform_cache; 112 std::map<u32, GLint> uniform_cache;
107}; 113};