Sort the elements of the D3D11 input layouts before we store them in the cache.

This prevents a D3D11 error complaining that the input layout
uses a different ordering of the vertex elements than the vertex shader.

TRAC #22561

Signed-off-by: Geoff Lang
Signed-off-by: Shannon Woods
Author: Jamie Madill

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1931 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/renderer/InputLayoutCache.cpp b/src/libGLESv2/renderer/InputLayoutCache.cpp
index 6bef612..ea850a8 100644
--- a/src/libGLESv2/renderer/InputLayoutCache.cpp
+++ b/src/libGLESv2/renderer/InputLayoutCache.cpp
@@ -51,6 +51,9 @@
 GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
                                             gl::ProgramBinary *programBinary)
 {
+    int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS];
+    programBinary->sortAttributesByLayout(attributes, sortedSemanticIndices);
+
     if (!mDevice || !mDeviceContext)
     {
         ERR("InputLayoutCache is not initialized.");
@@ -75,7 +78,7 @@
             D3D11_INPUT_CLASSIFICATION inputClass = attributes[i].divisor > 0 ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA;
 
             ilKey.elements[ilKey.elementCount].SemanticName = semanticName;
-            ilKey.elements[ilKey.elementCount].SemanticIndex = programBinary->getSemanticIndex(i);
+            ilKey.elements[ilKey.elementCount].SemanticIndex = sortedSemanticIndices[i];
             ilKey.elements[ilKey.elementCount].Format = attributes[i].attribute->mArrayEnabled ? vertexBuffer->getDXGIFormat(*attributes[i].attribute) : DXGI_FORMAT_R32G32B32A32_FLOAT;
             ilKey.elements[ilKey.elementCount].InputSlot = i;
             ilKey.elements[ilKey.elementCount].AlignedByteOffset = 0;