Initialize uninitialized GLSL arrays in a for loop
Previously, creating nodes for initializing each single array element
could result in memory bloat during translation when dealing with
large arrays. The resulting shader could also end up very long.
Initialize most arrays using a simple for loop instead. The loop is
compatible with ESSL 1.00 Appendix A limitations.
An exception is made for fragment outputs, so that they are not
indexed by non-constant values.
On some platforms using the a loop to initialize variables can cause
problems, so we also have a compiler flag for turning this behavior
off. The flag was already added earlier for a staggered rollout of
this functionality.
BUG=chromium:735497
TEST=angle_unittests, angle_end2end_tests, WebGL conformance tests
Change-Id: Iec727821d8137db56b440ddbe007879b1b55f61f
Reviewed-on: https://chromium-review.googlesource.com/707195
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/InitializeVariables.h b/src/compiler/translator/InitializeVariables.h
index 536d0cc..1a7b3c0 100644
--- a/src/compiler/translator/InitializeVariables.h
+++ b/src/compiler/translator/InitializeVariables.h
@@ -18,12 +18,20 @@
typedef std::vector<sh::ShaderVariable> InitVariableList;
+// For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of
+// a large number of initializers where it can make sense, such as for initializing large arrays.
+
// Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
// may be an array, struct or any combination of these, as long as it contains only basic types.
-TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol);
+TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
+ bool canUseLoopsToInitialize,
+ TSymbolTable *symbolTable);
// Initialize all uninitialized local variables, so that undefined behavior is avoided.
-void InitializeUninitializedLocals(TIntermBlock *root, int shaderVersion);
+void InitializeUninitializedLocals(TIntermBlock *root,
+ int shaderVersion,
+ bool canUseLoopsToInitialize,
+ TSymbolTable *symbolTable);
// This function can initialize all the types that CreateInitCode is able to initialize. All
// variables must be globals which can be found in the symbol table. For now it is used for the
@@ -35,9 +43,10 @@
// enabled extensions.
void InitializeVariables(TIntermBlock *root,
const InitVariableList &vars,
- const TSymbolTable &symbolTable,
+ TSymbolTable *symbolTable,
int shaderVersion,
- const TExtensionBehavior &extensionBehavior);
+ const TExtensionBehavior &extensionBehavior,
+ bool canUseLoopsToInitialize);
} // namespace sh