Pass current value type instead of the object.

This allows us to simplify the logic in VertexDataManager enough
that we can start to cache attribute information.

BUG=angleproject:959

Change-Id: I7b53a137d73f40f86e3acb9caebb66f9cacf8b6f
Reviewed-on: https://chromium-review.googlesource.com/277283
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/VertexBuffer.cpp b/src/libANGLE/renderer/d3d/VertexBuffer.cpp
index c7aa7fc..bb8d5ee 100644
--- a/src/libANGLE/renderer/d3d/VertexBuffer.cpp
+++ b/src/libANGLE/renderer/d3d/VertexBuffer.cpp
@@ -91,7 +91,7 @@
 }
 
 gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                                       const gl::VertexAttribCurrentValueData &currentValue,
+                                                       GLenum currentValueType,
                                                        GLint start,
                                                        GLsizei count,
                                                        GLsizei instances,
@@ -119,7 +119,7 @@
     }
     mReservedSpace = 0;
 
-    error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition, sourceData);
+    error = mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count, instances, mWritePosition, sourceData);
     if (error.isError())
     {
         return error;
@@ -170,7 +170,7 @@
 }
 
 bool VertexBufferInterface::directStoragePossible(const gl::VertexAttribute &attrib,
-                                                  const gl::VertexAttribCurrentValueData &currentValue) const
+                                                  GLenum currentValueType) const
 {
     gl::Buffer *buffer = attrib.buffer.get();
     BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
@@ -188,7 +188,7 @@
 
     if (attrib.type != GL_FLOAT)
     {
-        gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+        gl::VertexFormat vertexFormat(attrib, currentValueType);
 
         unsigned int outputElementSize;
         getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
@@ -292,7 +292,7 @@
 }
 
 gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                                             const gl::VertexAttribCurrentValueData &currentValue,
+                                                             GLenum currentValueType,
                                                              GLint start,
                                                              GLsizei count,
                                                              GLsizei instances,
@@ -300,7 +300,7 @@
                                                              const uint8_t *sourceData)
 {
     unsigned int streamOffset;
-    gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset, sourceData);
+    gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValueType, start, count, instances, &streamOffset, sourceData);
     if (error.isError())
     {
         return error;
diff --git a/src/libANGLE/renderer/d3d/VertexBuffer.h b/src/libANGLE/renderer/d3d/VertexBuffer.h
index cc69ea6..81a90f6 100644
--- a/src/libANGLE/renderer/d3d/VertexBuffer.h
+++ b/src/libANGLE/renderer/d3d/VertexBuffer.h
@@ -38,7 +38,7 @@
     virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
 
     virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                            const gl::VertexAttribCurrentValueData &currentValue,
+                                            GLenum currentValueType,
                                             GLint start,
                                             GLsizei count,
                                             GLsizei instances,
@@ -77,7 +77,7 @@
     unsigned int getSerial() const;
 
     virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                            const gl::VertexAttribCurrentValueData &currentValue,
+                                            GLenum currentValueType,
                                             GLint start,
                                             GLsizei count,
                                             GLsizei instances,
@@ -85,7 +85,7 @@
                                             const uint8_t *sourceData);
 
     bool directStoragePossible(const gl::VertexAttribute &attrib,
-                               const gl::VertexAttribCurrentValueData &currentValue) const;
+                               GLenum currentValueType) const;
 
     VertexBuffer* getVertexBuffer() const;
 
@@ -126,7 +126,7 @@
     ~StaticVertexBufferInterface();
 
     gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                    const gl::VertexAttribCurrentValueData &currentValue,
+                                    GLenum currentValueType,
                                     GLint start,
                                     GLsizei count,
                                     GLsizei instances,
diff --git a/src/libANGLE/renderer/d3d/VertexDataManager.cpp b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
index 33b0d4c..180b6f0 100644
--- a/src/libANGLE/renderer/d3d/VertexDataManager.cpp
+++ b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
@@ -137,6 +137,8 @@
         {
             // Record the attribute now
             translated[attribIndex].attribute = &vertexAttributes[attribIndex];
+            translated[attribIndex].currentValueType = state.getVertexAttribCurrentValue(attribIndex).Type;
+            translated[attribIndex].divisor = vertexAttributes[attribIndex].divisor;
 
             if (vertexAttributes[attribIndex].enabled)
             {
@@ -152,7 +154,7 @@
     {
         if (translated[i].active && translated[i].attribute->enabled)
         {
-            gl::Error error = reserveSpaceForAttrib(*translated[i].attribute, state.getVertexAttribCurrentValue(i), count, instances);
+            gl::Error error = reserveSpaceForAttrib(translated[i], count, instances);
             if (error.isError())
             {
                 return error;
@@ -167,11 +169,7 @@
         {
             if (translated[i].attribute->enabled)
             {
-                gl::Error error = storeAttribute(state.getVertexAttribCurrentValue(i),
-                                                 &translated[i],
-                                                 start,
-                                                 count,
-                                                 instances);
+                gl::Error error = storeAttribute(&translated[i], start, count, instances);
 
                 if (error.isError())
                 {
@@ -232,24 +230,24 @@
         if (staticBuffer &&
             staticBuffer->getBufferSize() > 0 &&
             !staticBuffer->lookupAttribute(attrib, NULL) &&
-            !staticBuffer->directStoragePossible(attrib, currentValue))
+            !staticBuffer->directStoragePossible(attrib, currentValue.Type))
         {
             bufferImpl->invalidateStaticData();
         }
     }
 }
 
-gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
-                                                   const gl::VertexAttribCurrentValueData &currentValue,
+gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib,
                                                    GLsizei count,
                                                    GLsizei instances) const
 {
+    const gl::VertexAttribute &attrib = *translatedAttrib.attribute;
     gl::Buffer *buffer = attrib.buffer.get();
     BufferD3D *bufferImpl = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
     StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL;
     VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
 
-    if (!vertexBuffer->directStoragePossible(attrib, currentValue))
+    if (!vertexBuffer->directStoragePossible(attrib, translatedAttrib.currentValueType))
     {
         if (staticBuffer)
         {
@@ -279,8 +277,7 @@
     return gl::Error(GL_NO_ERROR);
 }
 
-gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueData &currentValue,
-                                            TranslatedAttribute *translated,
+gl::Error VertexDataManager::storeAttribute(TranslatedAttribute *translated,
                                             GLint start,
                                             GLsizei count,
                                             GLsizei instances)
@@ -294,7 +291,7 @@
     BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
     StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
     VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
-    bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
+    bool directStorage = vertexBuffer->directStoragePossible(attrib, translated->currentValueType);
 
     // Instanced vertices do not apply the 'start' offset
     GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start);
@@ -305,9 +302,6 @@
     {
         translated->storage = storage;
         translated->serial = storage->getSerial();
-        translated->divisor = attrib.divisor;
-
-        translated->currentValueType = currentValue.Type;
         translated->stride = ComputeVertexAttributeStride(attrib);
         translated->offset = static_cast<unsigned int>(attrib.offset + translated->stride * firstVertexIndex);
 
@@ -349,7 +343,7 @@
             int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
 
             error = staticBuffer->storeVertexAttributes(attrib,
-                                                        currentValue,
+                                                        translated->currentValueType,
                                                         -startIndex,
                                                         totalCount,
                                                         0,
@@ -380,7 +374,7 @@
         }
 
         error = mStreamingBuffer->storeVertexAttributes(attrib,
-                                                        currentValue,
+                                                        translated->currentValueType,
                                                         firstVertexIndex,
                                                         totalCount,
                                                         instances,
@@ -394,9 +388,6 @@
 
     translated->storage = nullptr;
     translated->serial = vertexBuffer->getSerial();
-    translated->divisor = attrib.divisor;
-
-    translated->currentValueType = currentValue.Type;
     translated->stride = outputElementSize;
     translated->offset = streamOffset;
 
@@ -418,7 +409,7 @@
 
         const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
         unsigned int streamOffset;
-        error = cachedState->buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset, sourceData);
+        error = cachedState->buffer->storeVertexAttributes(attrib, currentValue.Type, 0, 1, 0, &streamOffset, sourceData);
         if (error.isError())
         {
             return error;
@@ -433,7 +424,6 @@
     translated->serial = cachedState->buffer->getSerial();
     translated->divisor = 0;
 
-    translated->currentValueType = currentValue.Type;
     translated->stride = 0;
     translated->offset = cachedState->offset;
 
diff --git a/src/libANGLE/renderer/d3d/VertexDataManager.h b/src/libANGLE/renderer/d3d/VertexDataManager.h
index b8cdeee..27552bd 100644
--- a/src/libANGLE/renderer/d3d/VertexDataManager.h
+++ b/src/libANGLE/renderer/d3d/VertexDataManager.h
@@ -66,16 +66,14 @@
         size_t offset;
     };
 
-    gl::Error reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
-                                    const gl::VertexAttribCurrentValueData &currentValue,
+    gl::Error reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib,
                                     GLsizei count,
                                     GLsizei instances) const;
 
     void invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
                                       const gl::VertexAttribCurrentValueData &currentValue) const;
 
-    gl::Error storeAttribute(const gl::VertexAttribCurrentValueData &currentValue,
-                             TranslatedAttribute *translated,
+    gl::Error storeAttribute(TranslatedAttribute *translated,
                              GLint start,
                              GLsizei count,
                              GLsizei instances);
diff --git a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
index a6b3e66..f53f9f8 100644
--- a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
+++ b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.cpp
@@ -104,7 +104,7 @@
 }
 
 gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                                const gl::VertexAttribCurrentValueData &currentValue,
+                                                GLenum currentValueType,
                                                 GLint start,
                                                 GLsizei count,
                                                 GLsizei instances,
@@ -134,7 +134,7 @@
         input += inputStride * start;
     }
 
-    gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+    gl::VertexFormat vertexFormat(attrib, currentValueType);
     const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel;
     const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat, featureLevel);
     ASSERT(vertexFormatInfo.copyFunction != NULL);
diff --git a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h
index 88512e2..773c447 100644
--- a/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h
+++ b/src/libANGLE/renderer/d3d/d3d11/VertexBuffer11.h
@@ -26,7 +26,7 @@
     virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
 
     gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                    const gl::VertexAttribCurrentValueData &currentValue,
+                                    GLenum currentValueType,
                                     GLint start,
                                     GLsizei count,
                                     GLsizei instances,
diff --git a/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.cpp b/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.cpp
index fbe98cb..c376c8b 100644
--- a/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.cpp
+++ b/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.cpp
@@ -57,7 +57,7 @@
 }
 
 gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                               const gl::VertexAttribCurrentValueData &currentValue,
+                                               GLenum currentValueType,
                                                GLint start,
                                                GLsizei count,
                                                GLsizei instances,
@@ -96,7 +96,7 @@
         input += inputStride * start;
     }
 
-    gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+    gl::VertexFormat vertexFormat(attrib, currentValueType);
     const d3d9::VertexFormat &d3dVertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
     bool needsConversion = (d3dVertexInfo.conversionType & VERTEX_CONVERT_CPU) > 0;
 
diff --git a/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.h b/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.h
index 58dc462..64271cb 100644
--- a/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.h
+++ b/src/libANGLE/renderer/d3d/d3d9/VertexBuffer9.h
@@ -24,7 +24,7 @@
     virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
 
     gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
-                                    const gl::VertexAttribCurrentValueData &currentValue,
+                                    GLenum currentValueType,
                                     GLint start,
                                     GLsizei count,
                                     GLsizei instances,