Include globals when defering global initializers

Fixes these tests:

GLSLTest.StructWithInitializer/ES2_Metal
GLSLTest.StructWithInitializer/ES3_Metal
GLSLTest.StructWithUniformInitializer/ES2_Metal
GLSLTest.StructWithUniformInitializer/ES3_Metal
GLSLTest_ES3.SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue/ES3_Metal
WebGL2GLSLTest.InitUninitializedLocals/ES3_Metal

Bug: angleproject:5505
Change-Id: Ib8258898c60b9e9ffbb71f0024f8189dc6cf4d5b
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3120093
Commit-Queue: Gregg Tavares <gman@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
This commit is contained in:
Gregg Tavares
2021-08-25 15:56:59 -07:00
committed by Angle LUCI CQ
parent 82423ad138
commit 4c56534f31
3 changed files with 25 additions and 4 deletions

View File

@@ -682,9 +682,24 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
bool highPrecisionSupported = isHighPrecisionSupported();
bool enableNonConstantInitializers = IsExtensionEnabled(
mExtensionBehavior, TExtension::EXT_shader_non_constant_global_initializers);
// forceDeferGlobalInitializers is needed for MSL
// to convert a non-const global. For example:
//
// int someGlobal = 123;
//
// to
//
// int someGlobal;
// void main() {
// someGlobal = 123;
//
// This is because MSL doesn't allow statically initialized globals.
bool forceDeferGlobalInitializers = getOutputType() == SH_MSL_METAL_OUTPUT;
if (enableNonConstantInitializers &&
!DeferGlobalInitializers(this, root, initializeLocalsAndGlobals, canUseLoopsToInitialize,
highPrecisionSupported, &mSymbolTable))
highPrecisionSupported, forceDeferGlobalInitializers,
&mSymbolTable))
{
return false;
}
@@ -978,7 +993,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// be optimized out
if (!enableNonConstantInitializers &&
!DeferGlobalInitializers(this, root, initializeLocalsAndGlobals, canUseLoopsToInitialize,
highPrecisionSupported, &mSymbolTable))
highPrecisionSupported, forceDeferGlobalInitializers,
&mSymbolTable))
{
return false;
}

View File

@@ -38,6 +38,7 @@ void GetDeferredInitializers(TIntermDeclaration *declaration,
bool initializeUninitializedGlobals,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
bool forceDeferGlobalInitializers,
TIntermSequence *deferredInitializersOut,
std::vector<const TVariable *> *variablesToReplaceOut,
TSymbolTable *symbolTable)
@@ -53,7 +54,8 @@ void GetDeferredInitializers(TIntermDeclaration *declaration,
ASSERT(symbolNode);
TIntermTyped *expression = init->getRight();
if (expression->getQualifier() != EvqConst || !expression->hasConstantValue())
if (expression->getQualifier() != EvqConst || !expression->hasConstantValue() ||
forceDeferGlobalInitializers)
{
// For variables which are not constant, defer their real initialization until
// after we initialize uniforms.
@@ -133,6 +135,7 @@ bool DeferGlobalInitializers(TCompiler *compiler,
bool initializeUninitializedGlobals,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
bool forceDeferGlobalInitializers,
TSymbolTable *symbolTable)
{
TIntermSequence deferredInitializers;
@@ -147,7 +150,8 @@ bool DeferGlobalInitializers(TCompiler *compiler,
{
GetDeferredInitializers(declaration, initializeUninitializedGlobals,
canUseLoopsToInitialize, highPrecisionSupported,
&deferredInitializers, &variablesToReplace, symbolTable);
forceDeferGlobalInitializers, &deferredInitializers,
&variablesToReplace, symbolTable);
}
}

View File

@@ -30,6 +30,7 @@ ANGLE_NO_DISCARD bool DeferGlobalInitializers(TCompiler *compiler,
bool initializeUninitializedGlobals,
bool canUseLoopsToInitialize,
bool highPrecisionSupported,
bool forceDeferGlobalInitializers,
TSymbolTable *symbolTable);
} // namespace sh