OGL: Fix abstract pipelines on drivers without binding layout support

This commit is contained in:
Stenzek
2018-03-03 19:10:45 +10:00
parent 00204dc988
commit a61fcb0088

View File

@ -98,17 +98,18 @@ static std::string GetGLSLVersionString()
void SHADER::SetProgramVariables() void SHADER::SetProgramVariables()
{ {
// Bind UBO and texture samplers if (g_ActiveConfig.backend_info.bSupportsBindingLayout)
if (!g_ActiveConfig.backend_info.bSupportsBindingLayout) return;
{
// glsl shader must be bind to set samplers if we don't support binding layout
Bind();
// To set uniform blocks/uniforms, the program must be active. We restore the
// current binding at the end of this method to maintain the invariant.
glUseProgram(glprogid);
// Bind UBO and texture samplers
GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock"); GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock"); GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
GLint GSBlock_id = glGetUniformBlockIndex(glprogid, "GSBlock"); GLint GSBlock_id = glGetUniformBlockIndex(glprogid, "GSBlock");
GLint UBERBlock_id = glGetUniformBlockIndex(glprogid, "UBERBlock"); GLint UBERBlock_id = glGetUniformBlockIndex(glprogid, "UBERBlock");
if (PSBlock_id != -1) if (PSBlock_id != -1)
glUniformBlockBinding(glprogid, PSBlock_id, 1); glUniformBlockBinding(glprogid, PSBlock_id, 1);
if (VSBlock_id != -1) if (VSBlock_id != -1)
@ -119,7 +120,7 @@ void SHADER::SetProgramVariables()
glUniformBlockBinding(glprogid, UBERBlock_id, 4); glUniformBlockBinding(glprogid, UBERBlock_id, 4);
// Bind Texture Samplers // Bind Texture Samplers
for (int a = 0; a <= 9; ++a) for (int a = 0; a < 10; ++a)
{ {
std::string name = StringFromFormat(a < 8 ? "samp[%d]" : "samp%d", a); std::string name = StringFromFormat(a < 8 ? "samp[%d]" : "samp%d", a);
@ -128,7 +129,9 @@ void SHADER::SetProgramVariables()
if (loc != -1) if (loc != -1)
glUniform1i(loc, a); glUniform1i(loc, a);
} }
}
// Restore previous program binding.
glUseProgram(CurrentProgram);
} }
void SHADER::SetProgramBindings(bool is_compute) void SHADER::SetProgramBindings(bool is_compute)
@ -956,6 +959,9 @@ const PipelineProgram* ProgramShaderCache::GetPipelineProgram(const OGLShader* v
return iter->second.get(); return iter->second.get();
} }
// Set program variables on the shader which will be returned.
// This is only needed for drivers which don't support binding layout.
prog->shader.SetProgramVariables();
auto ip = pipelineprograms.emplace(key, std::move(prog)); auto ip = pipelineprograms.emplace(key, std::move(prog));
return ip.first->second.get(); return ip.first->second.get();
} }