Presort reverse mapping of ProgramBinary::mSemanticIndex.
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 135facd..922cd3d 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -1647,6 +1647,8 @@
         stream.read(&mSemanticIndex[i]);
     }
 
+    initAttributesByLayout();
+
     for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
     {
         stream.read(&mSamplersPS[i].active);
@@ -2053,6 +2055,8 @@
         }
     }
 
+    initAttributesByLayout();
+
     return true;
 }
 
@@ -2579,12 +2583,6 @@
     AttributeSorter(const int (&semanticIndices)[MAX_VERTEX_ATTRIBS])
         : originalIndices(semanticIndices)
     {
-        for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
-        {
-            indices[i] = i;
-        }
-
-        std::sort(&indices[0], &indices[MAX_VERTEX_ATTRIBS], *this);
     }
 
     bool operator()(int a, int b)
@@ -2592,27 +2590,32 @@
         return originalIndices[a] == -1 ? false : originalIndices[a] < originalIndices[b];
     }
 
-    int indices[MAX_VERTEX_ATTRIBS];
     const int (&originalIndices)[MAX_VERTEX_ATTRIBS];
 };
 
+void ProgramBinary::initAttributesByLayout()
+{
+    for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
+    {
+        mAttributesByLayout[i] = i;
+    }
+
+    std::sort(&mAttributesByLayout[0], &mAttributesByLayout[MAX_VERTEX_ATTRIBS], AttributeSorter(mSemanticIndex));
+}
+
 void ProgramBinary::sortAttributesByLayout(rx::TranslatedAttribute attributes[MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const
 {
-    AttributeSorter sorter(mSemanticIndex);
-
-    int oldIndices[MAX_VERTEX_ATTRIBS];
     rx::TranslatedAttribute oldTranslatedAttributes[MAX_VERTEX_ATTRIBS];
 
     for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
     {
-        oldIndices[i] = mSemanticIndex[i];
         oldTranslatedAttributes[i] = attributes[i];
     }
 
     for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
     {
-        int oldIndex = sorter.indices[i];
-        sortedSemanticIndices[i] = oldIndices[oldIndex];
+        int oldIndex = mAttributesByLayout[i];
+        sortedSemanticIndices[i] = mSemanticIndex[oldIndex];
         attributes[i] = oldTranslatedAttributes[oldIndex];
     }
 }
diff --git a/src/libGLESv2/ProgramBinary.h b/src/libGLESv2/ProgramBinary.h
index 2386c0b..d632086 100644
--- a/src/libGLESv2/ProgramBinary.h
+++ b/src/libGLESv2/ProgramBinary.h
@@ -114,6 +114,7 @@
 
     unsigned int getSerial() const;
 
+    void initAttributesByLayout();
     void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const;
 
     static std::string decorateAttribute(const std::string &name);    // Prepend an underscore
@@ -142,6 +143,7 @@
 
     Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS];
     int mSemanticIndex[MAX_VERTEX_ATTRIBS];
+    int mAttributesByLayout[MAX_VERTEX_ATTRIBS];
 
     struct Sampler
     {