Defer global initializers when necessary
Move global variable initializers that are not constant expressions to
a function that gets called at the start of main(). This is done
with an AST transformation. This needs to be done because global
variable initializers must be constant in native GL, but ANGLE is more
lenient with what can be put into ESSL 1.00 global initializers to
remain compatible with legacy WebGL content.
Non-constant global variable initializers also caused issues in HLSL
output, since in HLSL output some types of expressions get unfolded
into multiple statements. These include short-circuiting operators and
array initialization. To make sure that these cases are covered, any
initializers that can't be constant folded are deferred, even if they
have the const qualifier.
The old deferring mechanism in OutputHLSL is removed in favor of this
new AST transformation based approach.
BUG=angleproject:819
BUG=angleproject:1205
BUG=angleproject:1350
BUG=596616
TEST=WebGL conformance test
conformance/glsl/misc/global-variable-init.html
Change-Id: I039cc05d6b8c284baeefbdf7f10062cae4bc5716
Reviewed-on: https://chromium-review.googlesource.com/338291
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 77360d2..66da0c2 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -7,6 +7,7 @@
#include "compiler/translator/Cache.h"
#include "compiler/translator/Compiler.h"
#include "compiler/translator/CallDAG.h"
+#include "compiler/translator/DeferGlobalInitializers.h"
#include "compiler/translator/ForLoopUnroll.h"
#include "compiler/translator/Initialize.h"
#include "compiler/translator/InitializeParseContext.h"
@@ -376,6 +377,11 @@
RegenerateStructNames gen(symbolTable, shaderVersion);
root->traverse(&gen);
}
+
+ if (success)
+ {
+ DeferGlobalInitializers(root);
+ }
}
SetGlobalParseContext(NULL);