Use the CollectVariables path on the HLSL translator.

This approach consolidates our two methods, and lets us reuse the
same code for both methods of variable collection.

BUG=angle:466

Change-Id: Ie92f76ff0b6d0d0dbfd211a234d0ab86290fa798
Reviewed-on: https://chromium-review.googlesource.com/213504
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp b/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
index 404525c..6aa0d13 100644
--- a/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
+++ b/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
@@ -223,6 +223,13 @@
     for (unsigned int varyingIndex = 0; varyingIndex < fragmentVaryings.size(); varyingIndex++)
     {
         PackedVarying *varying = &fragmentVaryings[varyingIndex];
+
+        // Do not assign registers to built-in or unreferenced varyings
+        if (varying->isBuiltIn() || !varying->staticUse)
+        {
+            continue;
+        }
+
         if (packVarying(varying, maxVaryingVectors, packing))
         {
             packedVaryings.insert(varying->name);
@@ -278,17 +285,19 @@
     return registers;
 }
 
-std::string DynamicHLSL::generateVaryingHLSL(rx::ShaderD3D *shader) const
+std::string DynamicHLSL::generateVaryingHLSL(const ShaderD3D *shader) const
 {
     std::string varyingSemantic = getVaryingSemantic(shader->mUsesPointSize);
     std::string varyingHLSL;
 
-    std::vector<gl::PackedVarying> &varyings = shader->getVaryings();
+    const std::vector<gl::PackedVarying> &varyings = shader->getVaryings();
+
     for (unsigned int varyingIndex = 0; varyingIndex < varyings.size(); varyingIndex++)
     {
         const PackedVarying &varying = varyings[varyingIndex];
         if (varying.registerAssigned())
         {
+            ASSERT(!varying.isBuiltIn());
             GLenum transposedType = TransposeMatrixType(varying.type);
             int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
 
@@ -616,8 +625,10 @@
     for (unsigned int varyingIndex = 0; varyingIndex < varyings.size(); varyingIndex++)
     {
         const PackedVarying &varying = varyings[varyingIndex];
+
         if (varying.registerAssigned())
         {
+            ASSERT(!varying.isBuiltIn());
             GLenum transposedType = TransposeMatrixType(varying.type);
             int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
 
@@ -825,6 +836,8 @@
             const std::string &variableName = "out_" + outputLocation.name;
             const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
 
+            ASSERT(outputVariable.staticUse);
+
             PixelShaderOuputVariable outputKeyVariable;
             outputKeyVariable.type = outputVariable.type;
             outputKeyVariable.name = variableName + elementString;
@@ -907,6 +920,7 @@
         const PackedVarying &varying = fragmentVaryings[varyingIndex];
         if (varying.registerAssigned())
         {
+            ASSERT(!varying.isBuiltIn());
             for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
             {
                 GLenum transposedType = TransposeMatrixType(varying.type);
@@ -944,7 +958,10 @@
                 }
             }
         }
-        else UNREACHABLE();
+        else
+        {
+            ASSERT(varying.isBuiltIn() || !varying.staticUse);
+        }
     }
 
     pixelHLSL += "\n"
@@ -965,6 +982,8 @@
         const sh::Attribute &outputVariable = shaderOutputVars[outputVariableIndex];
         const int baseLocation = outputVariable.location == -1 ? 0 : outputVariable.location;
 
+        ASSERT(outputVariable.staticUse);
+
         if (outputVariable.arraySize > 0)
         {
             for (unsigned int elementIndex = 0; elementIndex < outputVariable.arraySize; elementIndex++)