Fix deferring global array initialization

The initial implementation of DeferGlobalInitializers did not take
HLSL corner cases into account. In particular, in case there was a
const-qualified array variable with an initializer that contained
elements that weren't constant folded, initialization would not be
deferred and the global scope of HLSL output would contain a call to
angle_construct_into_*().

On the other hand, deferring global initializers was also done in
cases where it wasn't necessary. Initializers of non-const qualified
array variables that could be written as HLSL literals by HLSL output
were unnecessarily deferred.

This patch fixes both of these issues: Now all global initializers are
potential candidates for deferral instead of just those where the
symbol has the EvqGlobal qualifier, and initializers that are
constructors taking only constant unions as parameters are not
unnecessarily deferred.

BUG=angleproject:1205
BUG=541551
TEST=angle_end2end_tests

Change-Id: I4027059e0e5f39c8a5a48b5c97a3fceaac6b6f8a
Reviewed-on: https://chromium-review.googlesource.com/339201
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/IntermTraverse.cpp b/src/compiler/translator/IntermTraverse.cpp
index 7b588ca..b785c40 100644
--- a/src/compiler/translator/IntermTraverse.cpp
+++ b/src/compiler/translator/IntermTraverse.cpp
@@ -390,6 +390,8 @@
 
         if (node->getOp() == EOpSequence)
             pushParentBlock(node);
+        else if (node->getOp() == EOpFunction)
+            mInGlobalScope = false;
 
         for (auto *child : *sequence)
         {
@@ -406,6 +408,8 @@
 
         if (node->getOp() == EOpSequence)
             popParentBlock();
+        else if (node->getOp() == EOpFunction)
+            mInGlobalScope = true;
 
         decrementDepth();
     }
@@ -481,6 +485,8 @@
         {
             if (node->getOp() == EOpSequence)
                 pushParentBlock(node);
+            else if (node->getOp() == EOpFunction)
+                mInGlobalScope = false;
 
             // Find the built-in function corresponding to this op so that we can determine the
             // in/out qualifiers of its parameters.
@@ -533,6 +539,8 @@
 
             if (node->getOp() == EOpSequence)
                 popParentBlock();
+            else if (node->getOp() == EOpFunction)
+                mInGlobalScope = true;
         }
 
         decrementDepth();