Commit 0ca53786 by Geoff Lang

Fix issues with ProgramGL.

* Don't re-create the native GL program every link, some program state should persist between re-linking such as bound attribute locations. * Forward glBindAttribLocation calls to the ProgramImpl, fixes some chromium rendering issues because chromium always binds attribute locations, sometimes with gaps. * Query the real attrib location before inserting it into the list of attribs. It was unsafe to rely on the attrib having the same location as its index into the active attributes. BUG=angleproject:882 Change-Id: If14b4c4c2f5ebcdaa4f7c5a890b9519d6d4e6e43 Reviewed-on: https://chromium-review.googlesource.com/269991Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 98e7d071
...@@ -252,6 +252,7 @@ void AttributeBindings::bindAttributeLocation(GLuint index, const char *name) ...@@ -252,6 +252,7 @@ void AttributeBindings::bindAttributeLocation(GLuint index, const char *name)
void Program::bindAttributeLocation(GLuint index, const char *name) void Program::bindAttributeLocation(GLuint index, const char *name)
{ {
mAttributeBindings.bindAttributeLocation(index, name); mAttributeBindings.bindAttributeLocation(index, name);
mProgram->bindAttributeLocation(index, name);
} }
// Links the HLSL code of the vertex and pixel shader by matching up their varyings, // Links the HLSL code of the vertex and pixel shader by matching up their varyings,
......
...@@ -51,6 +51,8 @@ class ProgramImpl : angle::NonCopyable ...@@ -51,6 +51,8 @@ class ProgramImpl : angle::NonCopyable
int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *outputVariables) = 0; std::map<int, gl::VariableLocation> *outputVariables) = 0;
virtual void bindAttributeLocation(GLuint index, const std::string &name) = 0;
virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0; virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0;
virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0; virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0;
virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0; virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
......
...@@ -1086,6 +1086,10 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog, ...@@ -1086,6 +1086,10 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog,
return LinkResult(true, gl::Error(GL_NO_ERROR)); return LinkResult(true, gl::Error(GL_NO_ERROR));
} }
void ProgramD3D::bindAttributeLocation(GLuint index, const std::string &name)
{
}
void ProgramD3D::getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const void ProgramD3D::getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const
{ {
mDynamicHLSL->getInputLayoutSignature(inputLayout, signature); mDynamicHLSL->getInputLayoutSignature(inputLayout, signature);
......
...@@ -78,6 +78,8 @@ class ProgramD3D : public ProgramImpl ...@@ -78,6 +78,8 @@ class ProgramD3D : public ProgramImpl
int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *outputVariables); std::map<int, gl::VariableLocation> *outputVariables);
void bindAttributeLocation(GLuint index, const std::string &name) override;
void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const; void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
void initializeUniformStorage(); void initializeUniformStorage();
......
...@@ -25,15 +25,14 @@ ProgramGL::ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager) ...@@ -25,15 +25,14 @@ ProgramGL::ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager)
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
ASSERT(mStateManager); ASSERT(mStateManager);
mProgramID = mFunctions->createProgram();
} }
ProgramGL::~ProgramGL() ProgramGL::~ProgramGL()
{ {
if (mProgramID != 0) mFunctions->deleteProgram(mProgramID);
{ mProgramID = 0;
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
}
} }
bool ProgramGL::usesPointSize() const bool ProgramGL::usesPointSize() const
...@@ -85,19 +84,18 @@ LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog, ...@@ -85,19 +84,18 @@ LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog,
ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(vertexShader); ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(vertexShader);
ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(fragmentShader); ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(fragmentShader);
// Generate a new program, make sure one doesn't already exist
ASSERT(mProgramID == 0);
mProgramID = mFunctions->createProgram();
// Attach the shaders // Attach the shaders
mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID()); mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID());
mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID()); mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID());
// TODO: bind attribute locations?
// Link and verify // Link and verify
mFunctions->linkProgram(mProgramID); mFunctions->linkProgram(mProgramID);
// Detach the shaders
mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID());
mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID());
// Verify the link
GLint linkStatus = GL_FALSE; GLint linkStatus = GL_FALSE;
mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus); mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
ASSERT(linkStatus == GL_TRUE); ASSERT(linkStatus == GL_TRUE);
...@@ -183,13 +181,20 @@ LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog, ...@@ -183,13 +181,20 @@ LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog,
std::string attributeName(&attributeNameBuffer[0], attributeNameLength); std::string attributeName(&attributeNameBuffer[0], attributeNameLength);
GLint location = mFunctions->getAttribLocation(mProgramID, attributeName.c_str());
// TODO: determine attribute precision // TODO: determine attribute precision
setShaderAttribute(static_cast<size_t>(i), attributeType, GL_NONE, attributeName, attributeSize, i); setShaderAttribute(static_cast<size_t>(i), attributeType, GL_NONE, attributeName, attributeSize, location);
} }
return LinkResult(true, gl::Error(GL_NO_ERROR)); return LinkResult(true, gl::Error(GL_NO_ERROR));
} }
void ProgramGL::bindAttributeLocation(GLuint index, const std::string &name)
{
mFunctions->bindAttribLocation(mProgramID, index, name.c_str());
}
void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
{ {
mStateManager->useProgram(mProgramID); mStateManager->useProgram(mProgramID);
...@@ -403,9 +408,6 @@ bool ProgramGL::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBloc ...@@ -403,9 +408,6 @@ bool ProgramGL::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBloc
void ProgramGL::reset() void ProgramGL::reset()
{ {
ProgramImpl::reset(); ProgramImpl::reset();
mStateManager->deleteProgram(mProgramID);
mProgramID = 0;
} }
GLuint ProgramGL::getProgramID() const GLuint ProgramGL::getProgramID() const
......
...@@ -38,6 +38,8 @@ class ProgramGL : public ProgramImpl ...@@ -38,6 +38,8 @@ class ProgramGL : public ProgramImpl
int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *outputVariables) override; std::map<int, gl::VariableLocation> *outputVariables) override;
void bindAttributeLocation(GLuint index, const std::string &name) override;
void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override; void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override; void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override; void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment