ES31: Refactor VertexArray for Vertex Attrib Binding

OpenGL ES3.1 feature Vertex Attrib Binding requires vertex arrays should
be split into two arrays:
1. an array of vertex buffer binding points, each of which specifies:
  - a bound buffer object,
  - a starting offset for vertex attribute data in that buffer object,
  - a stride used by all attributes using that binding point,
  - a frequency divisor used by all attributes using that binding point.
2. an array of generic vertex attribute format information records, each
of which specifies:
  - a reference to one of the new buffer binding points above,
  - a component count and format, and a normalization flag for the
    attribute data,
  - the offset of the attribute data relative to the base offset of each
    vertex found at the associated binding point.

Current ANGLE implementation simply uses a struct to represent a vertex
attribute object, which does not meet the requirements above.

This patch aims to be the the basis of the implementation of all ES3.1
Vertex Attrib Binding APIs by refactoring the struct VertexAttribute and
the class VertexArray to fit the new data layout and ensuring all current
functionality is retained.

BUG=angleproject:1593

TEST=angle_unittests, angle_end2end_tests, gpu_unittests

Change-Id: Ieb41f1bf503f815fd0476d2ea045dcb863465254
Reviewed-on: https://chromium-review.googlesource.com/418880
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index aabc42f..9985573 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -46,6 +46,7 @@
 
     const VertexArray *vao    = state.getVertexArray();
     const auto &vertexAttribs = vao->getVertexAttributes();
+    const auto &vertexBindings = vao->getVertexBindings();
     size_t maxEnabledAttrib   = vao->getMaxEnabledAttribute();
     for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
     {
@@ -55,8 +56,9 @@
             continue;
         }
 
+        const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
         // If we have no buffer, then we either get an error, or there are no more checks to be done.
-        gl::Buffer *buffer = attrib.buffer.get();
+        gl::Buffer *buffer = binding.buffer.get();
         if (!buffer)
         {
             if (webglCompatibility || !state.areClientArraysEnabled())
@@ -89,13 +91,13 @@
         }
 
         GLint maxVertexElement = 0;
-        if (attrib.divisor == 0)
+        if (binding.divisor == 0)
         {
             maxVertexElement = maxVertex;
         }
         else
         {
-            maxVertexElement = (primcount - 1) / attrib.divisor;
+            maxVertexElement = (primcount - 1) / binding.divisor;
         }
 
         // We do manual overflow checks here instead of using safe_math.h because it was
@@ -110,7 +112,7 @@
         // We know attribStride is given as a GLsizei which is typedefed to int.
         // We also know an upper bound for attribSize.
         static_assert(std::is_same<int, GLsizei>::value, "");
-        uint64_t attribStride = ComputeVertexAttributeStride(attrib);
+        uint64_t attribStride = ComputeVertexAttributeStride(attrib, binding);
         uint64_t attribSize   = ComputeVertexAttributeTypeSize(attrib);
         ASSERT(attribStride <= kIntMax && attribSize <= kMaxAttribSize);
 
@@ -120,8 +122,8 @@
         uint64_t attribDataSizeNoOffset = maxVertexElement * attribStride + attribSize;
 
         // An overflow can happen when adding the offset, check for it.
-        uint64_t attribOffset = attrib.offset;
-        if (attribDataSizeNoOffset > kUint64Max - attrib.offset)
+        uint64_t attribOffset = ComputeVertexAttributeOffset(attrib, binding);
+        if (attribDataSizeNoOffset > kUint64Max - attribOffset)
         {
             context->handleError(Error(GL_INVALID_OPERATION, "Integer overflow."));
             return false;
@@ -3385,11 +3387,13 @@
 
     gl::Program *program = state.getProgram();
 
-    const VertexArray *vao = state.getVertexArray();
+    const auto &attribs  = state.getVertexArray()->getVertexAttributes();
+    const auto &bindings = state.getVertexArray()->getVertexBindings();
     for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
     {
-        const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
-        if (program->isAttribLocationActive(attributeIndex) && attrib.divisor == 0)
+        const VertexAttribute &attrib = attribs[attributeIndex];
+        const VertexBinding &binding  = bindings[attrib.bindingIndex];
+        if (program->isAttribLocationActive(attributeIndex) && binding.divisor == 0)
         {
             return true;
         }