Implementing gl_InstanceID in the HLSL compiler.

Fixes:
dEQP-GLES3.functional.instanced.draw_arrays_instanced.instance_id
dEQP-GLES3.functional.instanced.draw_arrays_instanced.mixed
dEQP-GLES3.functional.instanced.draw_elements_instanced.instance_id
dEQP-GLES3.functional.instanced.draw_elements_instanced.mixed

BUG=angle:601

Change-Id: I6e120eebc90d00e025fc58f096064e6ed1da826b
Reviewed-on: https://chromium-review.googlesource.com/246911
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Gregoire Payen de La Garanderie <Gregory.Payen@imgtec.com>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
index afe3eab..5f75902 100644
--- a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
+++ b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
@@ -392,11 +392,31 @@
             else
             {
                 GLenum componentType = mRenderer->getVertexComponentType(vertexFormat);
-                structHLSL += "    " + HLSLComponentTypeString(componentType, VariableComponentCount(shaderAttribute.type));
+
+                if (shaderAttribute.name == "gl_InstanceID")
+                {
+                    // The input type of the instance ID in HLSL (uint) differs from the one in ESSL (int).
+                    structHLSL += " uint";
+                }
+                else
+                {
+                    structHLSL += "    " + HLSLComponentTypeString(componentType, VariableComponentCount(shaderAttribute.type));
+                }
             }
 
-            structHLSL += " " + decorateVariable(shaderAttribute.name) + " : TEXCOORD" + Str(semanticIndex) + ";\n";
-            semanticIndex += VariableRegisterCount(shaderAttribute.type);
+            structHLSL += " " + decorateVariable(shaderAttribute.name) + " : ";
+
+            if (shaderAttribute.name == "gl_InstanceID")
+            {
+                structHLSL += "SV_InstanceID";
+            }
+            else
+            {
+                structHLSL += "TEXCOORD" + Str(semanticIndex);
+                semanticIndex += VariableRegisterCount(shaderAttribute.type);
+            }
+
+            structHLSL += ";\n";
 
             // HLSL code for initialization
             initHLSL += "    " + decorateVariable(shaderAttribute.name) + " = ";