Bind native GL attributes to match the locations in gl::Program.

Simplifies a lot of logic when we don't have to maintain mappings between
the driver and gl-layer locations.

BUG=angleproject:882
BUG=angleproject:1123

Change-Id: Ia94257a322f768fdfa3167000a46a0715820ef4d
Reviewed-on: https://chromium-review.googlesource.com/295231
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index 7c6b8c3..1dcd5ea 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -258,7 +258,6 @@
 void Program::bindAttributeLocation(GLuint index, const char *name)
 {
     mAttributeBindings.bindAttributeLocation(index, name);
-    mProgram->bindAttributeLocation(index, name);
 }
 
 // Links the HLSL code of the vertex and pixel shader by matching up their varyings,
diff --git a/src/libANGLE/renderer/ProgramImpl.h b/src/libANGLE/renderer/ProgramImpl.h
index d2f7041..10b2c61 100644
--- a/src/libANGLE/renderer/ProgramImpl.h
+++ b/src/libANGLE/renderer/ProgramImpl.h
@@ -50,8 +50,6 @@
 
     virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0;
 
-    virtual void bindAttributeLocation(GLuint index, const std::string &name) = 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 setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
diff --git a/src/libANGLE/renderer/d3d/ProgramD3D.cpp b/src/libANGLE/renderer/d3d/ProgramD3D.cpp
index e4f7d54..fbfa887 100644
--- a/src/libANGLE/renderer/d3d/ProgramD3D.cpp
+++ b/src/libANGLE/renderer/d3d/ProgramD3D.cpp
@@ -1175,10 +1175,6 @@
     return validateSamplers(infoLog, caps);
 }
 
-void ProgramD3D::bindAttributeLocation(GLuint index, const std::string &name)
-{
-}
-
 void ProgramD3D::initializeUniformStorage()
 {
     // Compute total default block size
diff --git a/src/libANGLE/renderer/d3d/ProgramD3D.h b/src/libANGLE/renderer/d3d/ProgramD3D.h
index 7207d8c..ab7d096 100644
--- a/src/libANGLE/renderer/d3d/ProgramD3D.h
+++ b/src/libANGLE/renderer/d3d/ProgramD3D.h
@@ -76,8 +76,6 @@
 
     GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
 
-    void bindAttributeLocation(GLuint index, const std::string &name) override;
-
     void initializeUniformStorage();
     gl::Error applyUniforms();
     gl::Error applyUniformBuffers(const gl::Data &data);
diff --git a/src/libANGLE/renderer/gl/ProgramGL.cpp b/src/libANGLE/renderer/gl/ProgramGL.cpp
index b7b72e4..95e28e0 100644
--- a/src/libANGLE/renderer/gl/ProgramGL.cpp
+++ b/src/libANGLE/renderer/gl/ProgramGL.cpp
@@ -74,6 +74,23 @@
     mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID());
     mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID());
 
+    // Bind attribute locations to match the GL layer.
+    for (const sh::Attribute &attribute : mData.getAttributes())
+    {
+        if (!attribute.staticUse)
+        {
+            continue;
+        }
+
+        mFunctions->bindAttribLocation(mProgramID, attribute.location, attribute.name.c_str());
+
+        int registerCount = gl::VariableRegisterCount(attribute.type);
+        for (int offset = 0; offset < registerCount; ++offset)
+        {
+            mActiveAttributesMask.set(attribute.location + offset);
+        }
+    }
+
     // Link and verify
     mFunctions->linkProgram(mProgramID);
 
@@ -169,37 +186,6 @@
         }
     }
 
-    for (const sh::Attribute &attribute : mData.getAttributes())
-    {
-        if (!attribute.staticUse)
-            continue;
-
-        GLint realLocation = mFunctions->getAttribLocation(mProgramID, attribute.name.c_str());
-
-        // Some drivers optimize attributes more aggressively.
-        if (realLocation == -1)
-        {
-            continue;
-        }
-
-        // TODO(jmadill): Fix this
-        ASSERT(attribute.location == realLocation);
-
-        int registerCount = gl::VariableRegisterCount(attribute.type);
-
-        if (static_cast<GLint>(mAttributeRealLocations.size()) <
-            attribute.location + registerCount + 1)
-        {
-            mAttributeRealLocations.resize(attribute.location + registerCount + 1, -1);
-        }
-
-        for (int offset = 0; offset < registerCount; ++offset)
-        {
-            mActiveAttributesMask.set(attribute.location + offset);
-            mAttributeRealLocations[attribute.location + offset] = realLocation + offset;
-        }
-    }
-
     return LinkResult(true, gl::Error(GL_NO_ERROR));
 }
 
@@ -209,11 +195,6 @@
     return true;
 }
 
-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)
 {
     mStateManager->useProgram(mProgramID);
@@ -378,7 +359,6 @@
     mSamplerUniformMap.clear();
     mSamplerBindings.clear();
     mActiveAttributesMask.reset();
-    mAttributeRealLocations.clear();
 }
 
 GLuint ProgramGL::getProgramID() const
diff --git a/src/libANGLE/renderer/gl/ProgramGL.h b/src/libANGLE/renderer/gl/ProgramGL.h
index c900c09..48e085b 100644
--- a/src/libANGLE/renderer/gl/ProgramGL.h
+++ b/src/libANGLE/renderer/gl/ProgramGL.h
@@ -45,8 +45,6 @@
 
     GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
 
-    void bindAttributeLocation(GLuint index, const std::string &name) override;
-
     void setUniform1fv(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;
@@ -101,9 +99,6 @@
     // An array of the samplers that are used by the program
     std::vector<SamplerBindingGL> mSamplerBindings;
 
-    // Map from GL-layer attribute location to native location.
-    std::vector<GLint> mAttributeRealLocations;
-
     // Array of attribute locations used by this program
     gl::AttributesMask mActiveAttributesMask;