Fix HLSL varying struct linking.

We would always expand a struct name to always include its symbol
ID. This fixes the workaround to only affect scoped structs.
We can leave global structs, which are by definition uniquely named,
without decorating them with a symbol ID.

This fixes several tests in dEQP's shader.linkage.varying.struct.

Re-land with GLSL translator bug fixed.

BUG=angle:910

Change-Id: I23a932bd1dadea5e9aafabde697e6a2af9a43f2b
Reviewed-on: https://chromium-review.googlesource.com/249134
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index e2959d7..06c2ea6 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -2545,7 +2545,10 @@
     TStructure* structure = new TStructure(structName, fieldList);
     TType* structureType = new TType(structure);
 
+    // Store a bool in the struct if we're at global scope, to allow us to
+    // skip the local struct scoping workaround in HLSL.
     structure->setUniqueId(TSymbolTable::nextUniqueId());
+    structure->setAtGlobalScope(symbolTable.atGlobalLevel());
 
     if (!structName->empty())
     {
diff --git a/src/compiler/translator/Types.h b/src/compiler/translator/Types.h
index 2f6fb5f..f0dc8d9 100644
--- a/src/compiler/translator/Types.h
+++ b/src/compiler/translator/Types.h
@@ -113,7 +113,8 @@
     TStructure(const TString *name, TFieldList *fields)
         : TFieldListCollection(name, fields),
           mDeepestNesting(0),
-          mUniqueId(0)
+          mUniqueId(0),
+          mAtGlobalScope(false)
     {
     }
 
@@ -138,6 +139,16 @@
         return mUniqueId;
     }
 
+    void setAtGlobalScope(bool atGlobalScope)
+    {
+        mAtGlobalScope = atGlobalScope;
+    }
+
+    bool atGlobalScope() const
+    {
+        return mAtGlobalScope;
+    }
+
   private:
     DISALLOW_COPY_AND_ASSIGN(TStructure);
 
@@ -159,6 +170,7 @@
 
     mutable int mDeepestNesting;
     int mUniqueId;
+    bool mAtGlobalScope;
 };
 
 class TInterfaceBlock : public TFieldListCollection
diff --git a/src/compiler/translator/UtilsHLSL.cpp b/src/compiler/translator/UtilsHLSL.cpp
index de0c36c..94e19ac 100644
--- a/src/compiler/translator/UtilsHLSL.cpp
+++ b/src/compiler/translator/UtilsHLSL.cpp
@@ -175,6 +175,13 @@
         return "";
     }
 
+    // For structures at global scope we use a consistent
+    // translation so that we can link between shader stages.
+    if (structure.atGlobalScope())
+    {
+        return Decorate(structure.name());
+    }
+
     return "ss" + str(structure.uniqueId()) + "_" + structure.name();
 }