Cache maximum enabled vertex attribute.

This can give us much faster draw call validation, by saving us from
checking buffer sizes for non-enabled attribs. Also for checking if
vertex buffers are mapped. Gives >100% increase in the benchmark.

BUG=angleproject:959

Change-Id: I211c310385bdee46ed06f68ecd9c98385e1f8db9
Reviewed-on: https://chromium-review.googlesource.com/267751
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
diff --git a/src/libANGLE/VertexArray.cpp b/src/libANGLE/VertexArray.cpp
index f0aded9..a920a77 100644
--- a/src/libANGLE/VertexArray.cpp
+++ b/src/libANGLE/VertexArray.cpp
@@ -16,7 +16,8 @@
 VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
     : mId(id),
       mVertexArray(impl),
-      mVertexAttributes(maxAttribs)
+      mVertexAttributes(maxAttribs),
+      mMaxEnabledAttribute(0)
 {
     ASSERT(impl != NULL);
 }
@@ -76,6 +77,19 @@
     ASSERT(attributeIndex < getMaxAttribs());
     mVertexAttributes[attributeIndex].enabled = enabledState;
     mVertexArray->enableAttribute(attributeIndex, enabledState);
+
+    // Update state cache
+    if (enabledState)
+    {
+        mMaxEnabledAttribute = std::max(attributeIndex, mMaxEnabledAttribute);
+    }
+    else if (mMaxEnabledAttribute == attributeIndex)
+    {
+        while (mMaxEnabledAttribute > 0 && !mVertexAttributes[mMaxEnabledAttribute].enabled)
+        {
+            --mMaxEnabledAttribute;
+        }
+    }
 }
 
 void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,