Use correct non-square register count in structs.

For struct varyings with nested structs, we would count registers
incorrectly, and produce D3D link errors.

This fixes tests in the dEQP's shaders.linkage.varying.struct.

BUG=angle:910

Change-Id: I47ea6dba36bf57cf94a7e7f30997c6c9096c2b40
Reviewed-on: https://chromium-review.googlesource.com/247243
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
index 5f75902..e4c6dd8 100644
--- a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
+++ b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
@@ -98,11 +98,21 @@
 
 static bool packVarying(PackedVarying *varying, const int maxVaryingVectors, VaryingPacking packing)
 {
-    GLenum transposedType = TransposeMatrixType(varying->type);
+    // Make sure we use transposed matrix types to count registers correctly.
+    int registers = 0;
+    int elements = 0;
 
-    // matrices within varying structs are not transposed
-    int registers = (varying->isStruct() ? HLSLVariableRegisterCount(*varying) : VariableRowCount(transposedType)) * varying->elementCount();
-    int elements = (varying->isStruct() ? 4 : VariableColumnCount(transposedType));
+    if (varying->isStruct())
+    {
+        registers = HLSLVariableRegisterCount(*varying, true) * varying->elementCount();
+        elements = 4;
+    }
+    else
+    {
+        GLenum transposedType = TransposeMatrixType(varying->type);
+        registers = VariableRowCount(transposedType) * varying->elementCount();
+        elements = VariableColumnCount(transposedType);
+    }
 
     if (elements >= 2 && elements <= 4)
     {
@@ -340,15 +350,16 @@
                       default:  UNREACHABLE();
                     }
 
-                    unsigned int semanticIndex = elementIndex * variableRows + varying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors + varying.registerIndex + row;
+                    unsigned int semanticIndex = elementIndex * variableRows +
+                                                 varying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors +
+                                                 varying.registerIndex + row;
                     std::string n = Str(semanticIndex);
 
                     std::string typeString;
 
                     if (varying.isStruct())
                     {
-                        // matrices within structs are not transposed, so
-                        // do not use the special struct prefix "rm"
+                        // TODO(jmadill): pass back translated name from the shader translator
                         typeString = decorateVariable(varying.structName);
                     }
                     else