Commit 6f591c97 by Olli Etuaho Committed by Commit Bot

Clean up TCompiler members and style

Some dead code and duplicate data are cleaned up from the compiler. Several parameters can be accessed directly from ShBuiltInResources instead of creating a copy in TCompiler. This also encapsulates some TCompiler member functions as private and changes the remaining unprefixed TCompiler member variable names to start with the m prefix. BUG=angleproject:2068 TEST=angle_unittests Change-Id: I6690aaf538b17e0f45460660272a21f82f1808a0 Reviewed-on: https://chromium-review.googlesource.com/c/1267503Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 6d765b07
...@@ -281,19 +281,13 @@ TShHandleBase::~TShHandleBase() ...@@ -281,19 +281,13 @@ TShHandleBase::~TShHandleBase()
} }
TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
: variablesCollected(false), : mVariablesCollected(false),
mGLPositionInitialized(false), mGLPositionInitialized(false),
shaderType(type), mShaderType(type),
shaderSpec(spec), mShaderSpec(spec),
outputType(output), mOutputType(output),
maxUniformVectors(0), mBuiltInFunctionEmulator(),
maxExpressionComplexity(0), mDiagnostics(mInfoSink.info),
maxCallStackDepth(0),
maxFunctionParameters(0),
fragmentPrecisionHigh(false),
clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
builtInFunctionEmulator(),
mDiagnostics(infoSink.info),
mSourcePath(nullptr), mSourcePath(nullptr),
mComputeShaderLocalSizeDeclared(false), mComputeShaderLocalSizeDeclared(false),
mComputeShaderLocalSize(1), mComputeShaderLocalSize(1),
...@@ -313,33 +307,23 @@ bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptio ...@@ -313,33 +307,23 @@ bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptio
// If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API, // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API,
// validate loop and indexing as well (to verify that the shader only uses minimal functionality // validate loop and indexing as well (to verify that the shader only uses minimal functionality
// of ESSL 1.00 as in Appendix A of the spec). // of ESSL 1.00 as in Appendix A of the spec).
return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) || return (IsWebGLBasedSpec(mShaderSpec) && mShaderVersion == 100) ||
(compileOptions & SH_VALIDATE_LOOP_INDEXING); (compileOptions & SH_VALIDATE_LOOP_INDEXING);
} }
bool TCompiler::Init(const ShBuiltInResources &resources) bool TCompiler::Init(const ShBuiltInResources &resources)
{ {
shaderVersion = 100;
maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources);
maxExpressionComplexity = resources.MaxExpressionComplexity;
maxCallStackDepth = resources.MaxCallStackDepth;
maxFunctionParameters = resources.MaxFunctionParameters;
SetGlobalPoolAllocator(&allocator); SetGlobalPoolAllocator(&allocator);
// Generate built-in symbol table. // Generate built-in symbol table.
if (!InitBuiltInSymbolTable(resources)) if (!initBuiltInSymbolTable(resources))
return false; return false;
InitExtensionBehavior(resources, extensionBehavior);
fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); mResources = resources;
clampingStrategy = resources.ArrayIndexClampingStrategy; setResourceString();
hashFunction = resources.HashFunction;
InitExtensionBehavior(resources, mExtensionBehavior);
mArrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
return true; return true;
} }
...@@ -360,7 +344,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -360,7 +344,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
ASSERT(GetGlobalPoolAllocator()); ASSERT(GetGlobalPoolAllocator());
// Reset the extension behavior for each compilation unit. // Reset the extension behavior for each compilation unit.
ResetExtensionBehavior(extensionBehavior); ResetExtensionBehavior(mExtensionBehavior);
// First string is path of source file if flag is set. The actual source follows. // First string is path of source file if flag is set. The actual source follows.
size_t firstSource = 0; size_t firstSource = 0;
...@@ -370,15 +354,15 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -370,15 +354,15 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
++firstSource; ++firstSource;
} }
TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec, TParseContext parseContext(mSymbolTable, mExtensionBehavior, mShaderType, mShaderSpec,
compileOptions, true, &mDiagnostics, getResources()); compileOptions, true, &mDiagnostics, getResources());
parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh); parseContext.setFragmentPrecisionHighOnESSL1(mResources.FragmentPrecisionHigh == 1);
// We preserve symbols at the built-in level from compile-to-compile. // We preserve symbols at the built-in level from compile-to-compile.
// Start pushing the user-defined symbols at global level. // Start pushing the user-defined symbols at global level.
TScopedSymbolTableLevel globalLevel(&symbolTable); TScopedSymbolTableLevel globalLevel(&mSymbolTable);
ASSERT(symbolTable.atGlobalLevel()); ASSERT(mSymbolTable.atGlobalLevel());
// Parse shader. // Parse shader.
if (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, if (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr,
...@@ -410,17 +394,17 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -410,17 +394,17 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
bool TCompiler::checkShaderVersion(TParseContext *parseContext) bool TCompiler::checkShaderVersion(TParseContext *parseContext)
{ {
if (MapSpecToShaderVersion(shaderSpec) < shaderVersion) if (MapSpecToShaderVersion(mShaderSpec) < mShaderVersion)
{ {
mDiagnostics.globalError("unsupported shader version"); mDiagnostics.globalError("unsupported shader version");
return false; return false;
} }
ASSERT(parseContext); ASSERT(parseContext);
switch (shaderType) switch (mShaderType)
{ {
case GL_COMPUTE_SHADER: case GL_COMPUTE_SHADER:
if (shaderVersion < 310) if (mShaderVersion < 310)
{ {
mDiagnostics.globalError("Compute shader is not supported in this shader version."); mDiagnostics.globalError("Compute shader is not supported in this shader version.");
return false; return false;
...@@ -428,7 +412,7 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext) ...@@ -428,7 +412,7 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext)
break; break;
case GL_GEOMETRY_SHADER_EXT: case GL_GEOMETRY_SHADER_EXT:
if (shaderVersion < 310) if (mShaderVersion < 310)
{ {
mDiagnostics.globalError( mDiagnostics.globalError(
"Geometry shader is not supported in this shader version."); "Geometry shader is not supported in this shader version.");
...@@ -436,7 +420,7 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext) ...@@ -436,7 +420,7 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext)
} }
else else
{ {
ASSERT(shaderVersion == 310); ASSERT(mShaderVersion == 310);
if (!parseContext->checkCanUseExtension(sh::TSourceLoc(), if (!parseContext->checkCanUseExtension(sh::TSourceLoc(),
TExtension::EXT_geometry_shader)) TExtension::EXT_geometry_shader))
{ {
...@@ -454,20 +438,17 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext) ...@@ -454,20 +438,17 @@ bool TCompiler::checkShaderVersion(TParseContext *parseContext)
void TCompiler::setASTMetadata(const TParseContext &parseContext) void TCompiler::setASTMetadata(const TParseContext &parseContext)
{ {
shaderVersion = parseContext.getShaderVersion(); mShaderVersion = parseContext.getShaderVersion();
mPragma = parseContext.pragma(); mPragma = parseContext.pragma();
symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll); mSymbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll);
mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared(); mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared();
mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize(); mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize();
mNumViews = parseContext.getNumViews(); mNumViews = parseContext.getNumViews();
// Highp might have been auto-enabled based on shader version if (mShaderType == GL_GEOMETRY_SHADER_EXT)
fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
if (shaderType == GL_GEOMETRY_SHADER_EXT)
{ {
mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType(); mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType();
mGeometryShaderOutputPrimitiveType = parseContext.getGeometryShaderOutputPrimitiveType(); mGeometryShaderOutputPrimitiveType = parseContext.getGeometryShaderOutputPrimitiveType();
...@@ -487,12 +468,12 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -487,12 +468,12 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
} }
if (shouldRunLoopAndIndexingValidation(compileOptions) && if (shouldRunLoopAndIndexingValidation(compileOptions) &&
!ValidateLimitations(root, shaderType, &symbolTable, &mDiagnostics)) !ValidateLimitations(root, mShaderType, &mSymbolTable, &mDiagnostics))
{ {
return false; return false;
} }
if (!ValidateFragColorAndFragData(shaderType, shaderVersion, symbolTable, &mDiagnostics)) if (!ValidateFragColorAndFragData(mShaderType, mShaderVersion, mSymbolTable, &mDiagnostics))
{ {
return false; return false;
} }
...@@ -510,7 +491,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -510,7 +491,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// for float, so float literal statements would end up with no precision which is // for float, so float literal statements would end up with no precision which is
// invalid ESSL. // invalid ESSL.
// After this empty declarations are not allowed in the AST. // After this empty declarations are not allowed in the AST.
PruneNoOps(root, &symbolTable); PruneNoOps(root, &mSymbolTable);
// Create the function DAG and check there is no recursion // Create the function DAG and check there is no recursion
if (!initCallDag(root)) if (!initCallDag(root))
...@@ -524,8 +505,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -524,8 +505,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
} }
// Checks which functions are used and if "main" exists // Checks which functions are used and if "main" exists
functionMetadata.clear(); mFunctionMetadata.clear();
functionMetadata.resize(mCallDag.size()); mFunctionMetadata.resize(mCallDag.size());
if (!tagUsedFunctions()) if (!tagUsedFunctions())
{ {
return false; return false;
...@@ -536,21 +517,20 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -536,21 +517,20 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
pruneUnusedFunctions(root); pruneUnusedFunctions(root);
} }
if (shaderVersion >= 310 && !ValidateVaryingLocations(root, &mDiagnostics, shaderType)) if (mShaderVersion >= 310 && !ValidateVaryingLocations(root, &mDiagnostics, mShaderType))
{ {
return false; return false;
} }
if (shaderVersion >= 300 && shaderType == GL_FRAGMENT_SHADER && if (mShaderVersion >= 300 && mShaderType == GL_FRAGMENT_SHADER &&
!ValidateOutputs(root, getExtensionBehavior(), compileResources.MaxDrawBuffers, !ValidateOutputs(root, getExtensionBehavior(), mResources.MaxDrawBuffers, &mDiagnostics))
&mDiagnostics))
{ {
return false; return false;
} }
// Fail compilation if precision emulation not supported. // Fail compilation if precision emulation not supported.
if (getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision && if (getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision &&
!EmulatePrecision::SupportedInLanguage(outputType)) !EmulatePrecision::SupportedInLanguage(mOutputType))
{ {
mDiagnostics.globalError("Precision emulation not supported for this output type."); mDiagnostics.globalError("Precision emulation not supported for this output type.");
return false; return false;
...@@ -559,20 +539,20 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -559,20 +539,20 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// Clamping uniform array bounds needs to happen after validateLimitations pass. // Clamping uniform array bounds needs to happen after validateLimitations pass.
if (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS) if (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)
{ {
arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); mArrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
} }
if ((compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) && if ((compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) &&
parseContext.isExtensionEnabled(TExtension::OVR_multiview) && parseContext.isExtensionEnabled(TExtension::OVR_multiview) &&
getShaderType() != GL_COMPUTE_SHADER) getShaderType() != GL_COMPUTE_SHADER)
{ {
DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, shaderType, compileOptions, DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, mShaderType, compileOptions,
outputType, &symbolTable); mOutputType, &mSymbolTable);
} }
// This pass might emit short circuits so keep it before the short circuit unfolding // This pass might emit short circuits so keep it before the short circuit unfolding
if (compileOptions & SH_REWRITE_DO_WHILE_LOOPS) if (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)
RewriteDoWhile(root, &symbolTable); RewriteDoWhile(root, &mSymbolTable);
if (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION) if (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION)
AddAndTrueToLoopCondition(root); AddAndTrueToLoopCondition(root);
...@@ -584,21 +564,21 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -584,21 +564,21 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
if (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT) if (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT)
{ {
RemovePow(root, &symbolTable); RemovePow(root, &mSymbolTable);
} }
if (compileOptions & SH_REGENERATE_STRUCT_NAMES) if (compileOptions & SH_REGENERATE_STRUCT_NAMES)
{ {
RegenerateStructNames gen(&symbolTable); RegenerateStructNames gen(&mSymbolTable);
root->traverse(&gen); root->traverse(&gen);
} }
if (shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 && if (mShaderType == GL_FRAGMENT_SHADER && mShaderVersion == 100 && mResources.EXT_draw_buffers &&
compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 && mResources.MaxDrawBuffers > 1 &&
IsExtensionEnabled(extensionBehavior, TExtension::EXT_draw_buffers)) IsExtensionEnabled(mExtensionBehavior, TExtension::EXT_draw_buffers))
{ {
EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables, EmulateGLFragColorBroadcast(root, mResources.MaxDrawBuffers, &mOutputVariables,
&symbolTable, shaderVersion); &mSymbolTable, mShaderVersion);
} }
int simplifyScalarized = (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS) int simplifyScalarized = (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)
...@@ -622,7 +602,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -622,7 +602,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
RemoveArrayLengthMethod(root); RemoveArrayLengthMethod(root);
RemoveUnreferencedVariables(root, &symbolTable); RemoveUnreferencedVariables(root, &mSymbolTable);
// In case the last case inside a switch statement is a certain type of no-op, GLSL compilers in // In case the last case inside a switch statement is a certain type of no-op, GLSL compilers in
// drivers may not accept it. In this case we clean up the dead code from the end of switch // drivers may not accept it. In this case we clean up the dead code from the end of switch
...@@ -635,38 +615,41 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -635,38 +615,41 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// Built-in function emulation needs to happen after validateLimitations pass. // Built-in function emulation needs to happen after validateLimitations pass.
// TODO(jmadill): Remove global pool allocator. // TODO(jmadill): Remove global pool allocator.
GetGlobalPoolAllocator()->lock(); GetGlobalPoolAllocator()->lock();
initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions); initBuiltInFunctionEmulator(&mBuiltInFunctionEmulator, compileOptions);
GetGlobalPoolAllocator()->unlock(); GetGlobalPoolAllocator()->unlock();
builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root); mBuiltInFunctionEmulator.markBuiltInFunctionsForEmulation(root);
bool highPrecisionSupported = mShaderVersion > 100 || mShaderType != GL_FRAGMENT_SHADER ||
mResources.FragmentPrecisionHigh == 1;
if (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS) if (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)
{ {
ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh, &symbolTable); ScalarizeVecAndMatConstructorArgs(root, mShaderType, highPrecisionSupported, &mSymbolTable);
} }
if (shouldCollectVariables(compileOptions)) if (shouldCollectVariables(compileOptions))
{ {
ASSERT(!variablesCollected); ASSERT(!mVariablesCollected);
CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings, CollectVariables(root, &mAttributes, &mOutputVariables, &mUniforms, &mInputVaryings,
&outputVaryings, &uniformBlocks, &shaderStorageBlocks, &inBlocks, &mOutputVaryings, &mUniformBlocks, &mShaderStorageBlocks, &mInBlocks,
hashFunction, &symbolTable, shaderType, extensionBehavior); mResources.HashFunction, &mSymbolTable, mShaderType, mExtensionBehavior);
collectInterfaceBlocks(); collectInterfaceBlocks();
variablesCollected = true; mVariablesCollected = true;
if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS) if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
{ {
useAllMembersInUnusedStandardAndSharedBlocks(root); useAllMembersInUnusedStandardAndSharedBlocks(root);
} }
if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
{ {
int maxUniformVectors = GetMaxUniformVectorsForShaderType(mShaderType, mResources);
// Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec // Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec
// Appendix A, section 7, the shader does not use too many uniforms. // Appendix A, section 7, the shader does not use too many uniforms.
if (!CheckVariablesInPackingLimits(maxUniformVectors, uniforms)) if (!CheckVariablesInPackingLimits(maxUniformVectors, mUniforms))
{ {
mDiagnostics.globalError("too many uniforms"); mDiagnostics.globalError("too many uniforms");
return false; return false;
} }
} }
if ((compileOptions & SH_INIT_OUTPUT_VARIABLES) && (shaderType != GL_COMPUTE_SHADER)) if ((compileOptions & SH_INIT_OUTPUT_VARIABLES) && (mShaderType != GL_COMPUTE_SHADER))
{ {
initializeOutputVariables(root); initializeOutputVariables(root);
} }
...@@ -674,7 +657,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -674,7 +657,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// Removing invariant declarations must be done after collecting variables. // Removing invariant declarations must be done after collecting variables.
// Otherwise, built-in invariant declarations don't apply. // Otherwise, built-in invariant declarations don't apply.
if (RemoveInvariant(shaderType, shaderVersion, outputType, compileOptions)) if (RemoveInvariant(mShaderType, mShaderVersion, mOutputType, compileOptions))
{ {
RemoveInvariantDeclaration(root); RemoveInvariantDeclaration(root);
} }
...@@ -682,8 +665,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -682,8 +665,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
// gl_Position is always written in compatibility output mode. // gl_Position is always written in compatibility output mode.
// It may have been already initialized among other output variables, in that case we don't // It may have been already initialized among other output variables, in that case we don't
// need to initialize it twice. // need to initialize it twice.
if (shaderType == GL_VERTEX_SHADER && !mGLPositionInitialized && if (mShaderType == GL_VERTEX_SHADER && !mGLPositionInitialized &&
((compileOptions & SH_INIT_GL_POSITION) || (outputType == SH_GLSL_COMPATIBILITY_OUTPUT))) ((compileOptions & SH_INIT_GL_POSITION) || (mOutputType == SH_GLSL_COMPATIBILITY_OUTPUT)))
{ {
initializeGLPosition(root); initializeGLPosition(root);
mGLPositionInitialized = true; mGLPositionInitialized = true;
...@@ -696,10 +679,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -696,10 +679,8 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
bool initializeLocalsAndGlobals = bool initializeLocalsAndGlobals =
(compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && !IsOutputHLSL(getOutputType()); (compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && !IsOutputHLSL(getOutputType());
bool canUseLoopsToInitialize = !(compileOptions & SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES); bool canUseLoopsToInitialize = !(compileOptions & SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES);
bool highPrecisionSupported =
shaderType != GL_FRAGMENT_SHADER || compileResources.FragmentPrecisionHigh;
DeferGlobalInitializers(root, initializeLocalsAndGlobals, canUseLoopsToInitialize, DeferGlobalInitializers(root, initializeLocalsAndGlobals, canUseLoopsToInitialize,
highPrecisionSupported, &symbolTable); highPrecisionSupported, &mSymbolTable);
if (initializeLocalsAndGlobals) if (initializeLocalsAndGlobals)
{ {
...@@ -725,7 +706,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, ...@@ -725,7 +706,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
if (getShaderType() == GL_VERTEX_SHADER && (compileOptions & SH_CLAMP_POINT_SIZE)) if (getShaderType() == GL_VERTEX_SHADER && (compileOptions & SH_CLAMP_POINT_SIZE))
{ {
ClampPointSize(root, compileResources.MaxPointSize, &getSymbolTable()); ClampPointSize(root, mResources.MaxPointSize, &getSymbolTable());
} }
if (getShaderType() == GL_FRAGMENT_SHADER && (compileOptions & SH_CLAMP_FRAG_DEPTH)) if (getShaderType() == GL_FRAGMENT_SHADER && (compileOptions & SH_CLAMP_FRAG_DEPTH))
...@@ -751,7 +732,8 @@ bool TCompiler::compile(const char *const shaderStrings[], ...@@ -751,7 +732,8 @@ bool TCompiler::compile(const char *const shaderStrings[],
ShCompileOptions compileOptionsIn) ShCompileOptions compileOptionsIn)
{ {
#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) #if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
DumpFuzzerCase(shaderStrings, numStrings, shaderType, shaderSpec, outputType, compileOptionsIn); DumpFuzzerCase(shaderStrings, numStrings, mShaderType, mShaderSpec, mOutputType,
compileOptionsIn);
#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) #endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
if (numStrings == 0) if (numStrings == 0)
...@@ -772,7 +754,7 @@ bool TCompiler::compile(const char *const shaderStrings[], ...@@ -772,7 +754,7 @@ bool TCompiler::compile(const char *const shaderStrings[],
if (root) if (root)
{ {
if (compileOptions & SH_INTERMEDIATE_TREE) if (compileOptions & SH_INTERMEDIATE_TREE)
OutputTree(root, infoSink.info); OutputTree(root, mInfoSink.info);
if (compileOptions & SH_OBJECT_CODE) if (compileOptions & SH_OBJECT_CODE)
{ {
...@@ -787,7 +769,7 @@ bool TCompiler::compile(const char *const shaderStrings[], ...@@ -787,7 +769,7 @@ bool TCompiler::compile(const char *const shaderStrings[],
return false; return false;
} }
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) bool TCompiler::initBuiltInSymbolTable(const ShBuiltInResources &resources)
{ {
if (resources.MaxDrawBuffers < 1) if (resources.MaxDrawBuffers < 1)
{ {
...@@ -798,10 +780,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -798,10 +780,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
return false; return false;
} }
compileResources = resources; mSymbolTable.initializeBuiltIns(mShaderType, mShaderSpec, resources);
setResourceString();
symbolTable.initializeBuiltIns(shaderType, shaderSpec, resources);
return true; return true;
} }
...@@ -811,112 +790,113 @@ void TCompiler::setResourceString() ...@@ -811,112 +790,113 @@ void TCompiler::setResourceString()
std::ostringstream strstream; std::ostringstream strstream;
// clang-format off // clang-format off
strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs strstream << ":MaxVertexAttribs:" << mResources.MaxVertexAttribs
<< ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors << ":MaxVertexUniformVectors:" << mResources.MaxVertexUniformVectors
<< ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors << ":MaxVaryingVectors:" << mResources.MaxVaryingVectors
<< ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits << ":MaxVertexTextureImageUnits:" << mResources.MaxVertexTextureImageUnits
<< ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits << ":MaxCombinedTextureImageUnits:" << mResources.MaxCombinedTextureImageUnits
<< ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits << ":MaxTextureImageUnits:" << mResources.MaxTextureImageUnits
<< ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors << ":MaxFragmentUniformVectors:" << mResources.MaxFragmentUniformVectors
<< ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers << ":MaxDrawBuffers:" << mResources.MaxDrawBuffers
<< ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives << ":OES_standard_derivatives:" << mResources.OES_standard_derivatives
<< ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external << ":OES_EGL_image_external:" << mResources.OES_EGL_image_external
<< ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3 << ":OES_EGL_image_external_essl3:" << mResources.OES_EGL_image_external_essl3
<< ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external << ":NV_EGL_stream_consumer_external:" << mResources.NV_EGL_stream_consumer_external
<< ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle << ":ARB_texture_rectangle:" << mResources.ARB_texture_rectangle
<< ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers << ":EXT_draw_buffers:" << mResources.EXT_draw_buffers
<< ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh << ":FragmentPrecisionHigh:" << mResources.FragmentPrecisionHigh
<< ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity << ":MaxExpressionComplexity:" << mResources.MaxExpressionComplexity
<< ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth << ":MaxCallStackDepth:" << mResources.MaxCallStackDepth
<< ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters << ":MaxFunctionParameters:" << mResources.MaxFunctionParameters
<< ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended << ":EXT_blend_func_extended:" << mResources.EXT_blend_func_extended
<< ":EXT_frag_depth:" << compileResources.EXT_frag_depth << ":EXT_frag_depth:" << mResources.EXT_frag_depth
<< ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod << ":EXT_shader_texture_lod:" << mResources.EXT_shader_texture_lod
<< ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch << ":EXT_shader_framebuffer_fetch:" << mResources.EXT_shader_framebuffer_fetch
<< ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch << ":NV_shader_framebuffer_fetch:" << mResources.NV_shader_framebuffer_fetch
<< ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch << ":ARM_shader_framebuffer_fetch:" << mResources.ARM_shader_framebuffer_fetch
<< ":OVR_multiview:" << compileResources.OVR_multiview << ":OVR_multiview:" << mResources.OVR_multiview
<< ":EXT_YUV_target:" << compileResources.EXT_YUV_target << ":EXT_YUV_target:" << mResources.EXT_YUV_target
<< ":EXT_geometry_shader:" << compileResources.EXT_geometry_shader << ":EXT_geometry_shader:" << mResources.EXT_geometry_shader
<< ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors << ":MaxVertexOutputVectors:" << mResources.MaxVertexOutputVectors
<< ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors << ":MaxFragmentInputVectors:" << mResources.MaxFragmentInputVectors
<< ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset << ":MinProgramTexelOffset:" << mResources.MinProgramTexelOffset
<< ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset << ":MaxProgramTexelOffset:" << mResources.MaxProgramTexelOffset
<< ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers << ":MaxDualSourceDrawBuffers:" << mResources.MaxDualSourceDrawBuffers
<< ":MaxViewsOVR:" << compileResources.MaxViewsOVR << ":MaxViewsOVR:" << mResources.MaxViewsOVR
<< ":NV_draw_buffers:" << compileResources.NV_draw_buffers << ":NV_draw_buffers:" << mResources.NV_draw_buffers
<< ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision << ":WEBGL_debug_shader_precision:" << mResources.WEBGL_debug_shader_precision
<< ":MinProgramTextureGatherOffset:" << compileResources.MinProgramTextureGatherOffset << ":MinProgramTextureGatherOffset:" << mResources.MinProgramTextureGatherOffset
<< ":MaxProgramTextureGatherOffset:" << compileResources.MaxProgramTextureGatherOffset << ":MaxProgramTextureGatherOffset:" << mResources.MaxProgramTextureGatherOffset
<< ":MaxImageUnits:" << compileResources.MaxImageUnits << ":MaxImageUnits:" << mResources.MaxImageUnits
<< ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms << ":MaxVertexImageUniforms:" << mResources.MaxVertexImageUniforms
<< ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms << ":MaxFragmentImageUniforms:" << mResources.MaxFragmentImageUniforms
<< ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms << ":MaxComputeImageUniforms:" << mResources.MaxComputeImageUniforms
<< ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms << ":MaxCombinedImageUniforms:" << mResources.MaxCombinedImageUniforms
<< ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources << ":MaxCombinedShaderOutputResources:" << mResources.MaxCombinedShaderOutputResources
<< ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0] << ":MaxComputeWorkGroupCountX:" << mResources.MaxComputeWorkGroupCount[0]
<< ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1] << ":MaxComputeWorkGroupCountY:" << mResources.MaxComputeWorkGroupCount[1]
<< ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2] << ":MaxComputeWorkGroupCountZ:" << mResources.MaxComputeWorkGroupCount[2]
<< ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0] << ":MaxComputeWorkGroupSizeX:" << mResources.MaxComputeWorkGroupSize[0]
<< ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1] << ":MaxComputeWorkGroupSizeY:" << mResources.MaxComputeWorkGroupSize[1]
<< ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2] << ":MaxComputeWorkGroupSizeZ:" << mResources.MaxComputeWorkGroupSize[2]
<< ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents << ":MaxComputeUniformComponents:" << mResources.MaxComputeUniformComponents
<< ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits << ":MaxComputeTextureImageUnits:" << mResources.MaxComputeTextureImageUnits
<< ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters << ":MaxComputeAtomicCounters:" << mResources.MaxComputeAtomicCounters
<< ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers << ":MaxComputeAtomicCounterBuffers:" << mResources.MaxComputeAtomicCounterBuffers
<< ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters << ":MaxVertexAtomicCounters:" << mResources.MaxVertexAtomicCounters
<< ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters << ":MaxFragmentAtomicCounters:" << mResources.MaxFragmentAtomicCounters
<< ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters << ":MaxCombinedAtomicCounters:" << mResources.MaxCombinedAtomicCounters
<< ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings << ":MaxAtomicCounterBindings:" << mResources.MaxAtomicCounterBindings
<< ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers << ":MaxVertexAtomicCounterBuffers:" << mResources.MaxVertexAtomicCounterBuffers
<< ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers << ":MaxFragmentAtomicCounterBuffers:" << mResources.MaxFragmentAtomicCounterBuffers
<< ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers << ":MaxCombinedAtomicCounterBuffers:" << mResources.MaxCombinedAtomicCounterBuffers
<< ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize << ":MaxAtomicCounterBufferSize:" << mResources.MaxAtomicCounterBufferSize
<< ":MaxGeometryUniformComponents:" << compileResources.MaxGeometryUniformComponents << ":MaxGeometryUniformComponents:" << mResources.MaxGeometryUniformComponents
<< ":MaxGeometryUniformBlocks:" << compileResources.MaxGeometryUniformBlocks << ":MaxGeometryUniformBlocks:" << mResources.MaxGeometryUniformBlocks
<< ":MaxGeometryInputComponents:" << compileResources.MaxGeometryInputComponents << ":MaxGeometryInputComponents:" << mResources.MaxGeometryInputComponents
<< ":MaxGeometryOutputComponents:" << compileResources.MaxGeometryOutputComponents << ":MaxGeometryOutputComponents:" << mResources.MaxGeometryOutputComponents
<< ":MaxGeometryOutputVertices:" << compileResources.MaxGeometryOutputVertices << ":MaxGeometryOutputVertices:" << mResources.MaxGeometryOutputVertices
<< ":MaxGeometryTotalOutputComponents:" << compileResources.MaxGeometryTotalOutputComponents << ":MaxGeometryTotalOutputComponents:" << mResources.MaxGeometryTotalOutputComponents
<< ":MaxGeometryTextureImageUnits:" << compileResources.MaxGeometryTextureImageUnits << ":MaxGeometryTextureImageUnits:" << mResources.MaxGeometryTextureImageUnits
<< ":MaxGeometryAtomicCounterBuffers:" << compileResources.MaxGeometryAtomicCounterBuffers << ":MaxGeometryAtomicCounterBuffers:" << mResources.MaxGeometryAtomicCounterBuffers
<< ":MaxGeometryAtomicCounters:" << compileResources.MaxGeometryAtomicCounters << ":MaxGeometryAtomicCounters:" << mResources.MaxGeometryAtomicCounters
<< ":MaxGeometryShaderStorageBlocks:" << compileResources.MaxGeometryShaderStorageBlocks << ":MaxGeometryShaderStorageBlocks:" << mResources.MaxGeometryShaderStorageBlocks
<< ":MaxGeometryShaderInvocations:" << compileResources.MaxGeometryShaderInvocations << ":MaxGeometryShaderInvocations:" << mResources.MaxGeometryShaderInvocations
<< ":MaxGeometryImageUniforms:" << compileResources.MaxGeometryImageUniforms; << ":MaxGeometryImageUniforms:" << mResources.MaxGeometryImageUniforms;
// clang-format on // clang-format on
builtInResourcesString = strstream.str(); mBuiltInResourcesString = strstream.str();
} }
void TCompiler::collectInterfaceBlocks() void TCompiler::collectInterfaceBlocks()
{ {
ASSERT(interfaceBlocks.empty()); ASSERT(mInterfaceBlocks.empty());
interfaceBlocks.reserve(uniformBlocks.size() + shaderStorageBlocks.size() + inBlocks.size()); mInterfaceBlocks.reserve(mUniformBlocks.size() + mShaderStorageBlocks.size() +
interfaceBlocks.insert(interfaceBlocks.end(), uniformBlocks.begin(), uniformBlocks.end()); mInBlocks.size());
interfaceBlocks.insert(interfaceBlocks.end(), shaderStorageBlocks.begin(), mInterfaceBlocks.insert(mInterfaceBlocks.end(), mUniformBlocks.begin(), mUniformBlocks.end());
shaderStorageBlocks.end()); mInterfaceBlocks.insert(mInterfaceBlocks.end(), mShaderStorageBlocks.begin(),
interfaceBlocks.insert(interfaceBlocks.end(), inBlocks.begin(), inBlocks.end()); mShaderStorageBlocks.end());
mInterfaceBlocks.insert(mInterfaceBlocks.end(), mInBlocks.begin(), mInBlocks.end());
} }
void TCompiler::clearResults() void TCompiler::clearResults()
{ {
arrayBoundsClamper.Cleanup(); mArrayBoundsClamper.Cleanup();
infoSink.info.erase(); mInfoSink.info.erase();
infoSink.obj.erase(); mInfoSink.obj.erase();
infoSink.debug.erase(); mInfoSink.debug.erase();
mDiagnostics.resetErrorCount(); mDiagnostics.resetErrorCount();
attributes.clear(); mAttributes.clear();
outputVariables.clear(); mOutputVariables.clear();
uniforms.clear(); mUniforms.clear();
inputVaryings.clear(); mInputVaryings.clear();
outputVaryings.clear(); mOutputVaryings.clear();
interfaceBlocks.clear(); mInterfaceBlocks.clear();
uniformBlocks.clear(); mUniformBlocks.clear();
shaderStorageBlocks.clear(); mShaderStorageBlocks.clear();
inBlocks.clear(); mInBlocks.clear();
variablesCollected = false; mVariablesCollected = false;
mGLPositionInitialized = false; mGLPositionInitialized = false;
mNumViews = -1; mNumViews = -1;
...@@ -926,13 +906,13 @@ void TCompiler::clearResults() ...@@ -926,13 +906,13 @@ void TCompiler::clearResults()
mGeometryShaderInvocations = 0; mGeometryShaderInvocations = 0;
mGeometryShaderMaxVertices = -1; mGeometryShaderMaxVertices = -1;
builtInFunctionEmulator.cleanup(); mBuiltInFunctionEmulator.cleanup();
nameMap.clear(); mNameMap.clear();
mSourcePath = nullptr; mSourcePath = nullptr;
symbolTable.clearCompilationResults(); mSymbolTable.clearCompilationResults();
} }
bool TCompiler::initCallDag(TIntermNode *root) bool TCompiler::initCallDag(TIntermNode *root)
...@@ -970,11 +950,11 @@ bool TCompiler::checkCallDepth() ...@@ -970,11 +950,11 @@ bool TCompiler::checkCallDepth()
depths[i] = depth; depths[i] = depth;
if (depth >= maxCallStackDepth) if (depth >= mResources.MaxCallStackDepth)
{ {
// Trace back the function chain to have a meaningful info log. // Trace back the function chain to have a meaningful info log.
std::stringstream errorStream; std::stringstream errorStream;
errorStream << "Call stack too deep (larger than " << maxCallStackDepth errorStream << "Call stack too deep (larger than " << mResources.MaxCallStackDepth
<< ") with the following call chain: " << ") with the following call chain: "
<< record.node->getFunction()->name(); << record.node->getFunction()->name();
...@@ -1028,12 +1008,12 @@ bool TCompiler::tagUsedFunctions() ...@@ -1028,12 +1008,12 @@ bool TCompiler::tagUsedFunctions()
void TCompiler::internalTagUsedFunction(size_t index) void TCompiler::internalTagUsedFunction(size_t index)
{ {
if (functionMetadata[index].used) if (mFunctionMetadata[index].used)
{ {
return; return;
} }
functionMetadata[index].used = true; mFunctionMetadata[index].used = true;
for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees) for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
{ {
...@@ -1089,7 +1069,7 @@ class TCompiler::UnusedPredicate ...@@ -1089,7 +1069,7 @@ class TCompiler::UnusedPredicate
void TCompiler::pruneUnusedFunctions(TIntermBlock *root) void TCompiler::pruneUnusedFunctions(TIntermBlock *root)
{ {
UnusedPredicate isUnused(&mCallDag, &functionMetadata); UnusedPredicate isUnused(&mCallDag, &mFunctionMetadata);
TIntermSequence *sequence = root->getSequence(); TIntermSequence *sequence = root->getSequence();
if (!sequence->empty()) if (!sequence->empty())
...@@ -1101,13 +1081,13 @@ void TCompiler::pruneUnusedFunctions(TIntermBlock *root) ...@@ -1101,13 +1081,13 @@ void TCompiler::pruneUnusedFunctions(TIntermBlock *root)
bool TCompiler::limitExpressionComplexity(TIntermBlock *root) bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
{ {
if (!IsASTDepthBelowLimit(root, maxExpressionComplexity)) if (!IsASTDepthBelowLimit(root, mResources.MaxExpressionComplexity))
{ {
mDiagnostics.globalError("Expression too complex."); mDiagnostics.globalError("Expression too complex.");
return false; return false;
} }
if (!ValidateMaxParameters(root, maxFunctionParameters)) if (!ValidateMaxParameters(root, mResources.MaxFunctionParameters))
{ {
mDiagnostics.globalError("Function has too many parameters."); mDiagnostics.globalError("Function has too many parameters.");
return false; return false;
...@@ -1123,7 +1103,7 @@ bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions) ...@@ -1123,7 +1103,7 @@ bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions)
bool TCompiler::wereVariablesCollected() const bool TCompiler::wereVariablesCollected() const
{ {
return variablesCollected; return mVariablesCollected;
} }
void TCompiler::initializeGLPosition(TIntermBlock *root) void TCompiler::initializeGLPosition(TIntermBlock *root)
...@@ -1132,14 +1112,15 @@ void TCompiler::initializeGLPosition(TIntermBlock *root) ...@@ -1132,14 +1112,15 @@ void TCompiler::initializeGLPosition(TIntermBlock *root)
sh::ShaderVariable var(GL_FLOAT_VEC4); sh::ShaderVariable var(GL_FLOAT_VEC4);
var.name = "gl_Position"; var.name = "gl_Position";
list.push_back(var); list.push_back(var);
InitializeVariables(root, list, &symbolTable, shaderVersion, extensionBehavior, false, false); InitializeVariables(root, list, &mSymbolTable, mShaderVersion, mExtensionBehavior, false,
false);
} }
void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root) void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
{ {
sh::InterfaceBlockList list; sh::InterfaceBlockList list;
for (auto block : uniformBlocks) for (auto block : mUniformBlocks)
{ {
if (!block.staticUse && if (!block.staticUse &&
(block.layout == sh::BLOCKLAYOUT_STD140 || block.layout == sh::BLOCKLAYOUT_SHARED)) (block.layout == sh::BLOCKLAYOUT_STD140 || block.layout == sh::BLOCKLAYOUT_SHARED))
...@@ -1148,15 +1129,15 @@ void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root) ...@@ -1148,15 +1129,15 @@ void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
} }
} }
sh::UseInterfaceBlockFields(root, list, symbolTable); sh::UseInterfaceBlockFields(root, list, mSymbolTable);
} }
void TCompiler::initializeOutputVariables(TIntermBlock *root) void TCompiler::initializeOutputVariables(TIntermBlock *root)
{ {
InitVariableList list; InitVariableList list;
if (shaderType == GL_VERTEX_SHADER || shaderType == GL_GEOMETRY_SHADER_EXT) if (mShaderType == GL_VERTEX_SHADER || mShaderType == GL_GEOMETRY_SHADER_EXT)
{ {
for (auto var : outputVaryings) for (auto var : mOutputVaryings)
{ {
list.push_back(var); list.push_back(var);
if (var.name == "gl_Position") if (var.name == "gl_Position")
...@@ -1168,18 +1149,19 @@ void TCompiler::initializeOutputVariables(TIntermBlock *root) ...@@ -1168,18 +1149,19 @@ void TCompiler::initializeOutputVariables(TIntermBlock *root)
} }
else else
{ {
ASSERT(shaderType == GL_FRAGMENT_SHADER); ASSERT(mShaderType == GL_FRAGMENT_SHADER);
for (auto var : outputVariables) for (auto var : mOutputVariables)
{ {
list.push_back(var); list.push_back(var);
} }
} }
InitializeVariables(root, list, &symbolTable, shaderVersion, extensionBehavior, false, false); InitializeVariables(root, list, &mSymbolTable, mShaderVersion, mExtensionBehavior, false,
false);
} }
const TExtensionBehavior &TCompiler::getExtensionBehavior() const const TExtensionBehavior &TCompiler::getExtensionBehavior() const
{ {
return extensionBehavior; return mExtensionBehavior;
} }
const char *TCompiler::getSourcePath() const const char *TCompiler::getSourcePath() const
...@@ -1189,29 +1171,29 @@ const char *TCompiler::getSourcePath() const ...@@ -1189,29 +1171,29 @@ const char *TCompiler::getSourcePath() const
const ShBuiltInResources &TCompiler::getResources() const const ShBuiltInResources &TCompiler::getResources() const
{ {
return compileResources; return mResources;
} }
const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const
{ {
return arrayBoundsClamper; return mArrayBoundsClamper;
} }
ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
{ {
return clampingStrategy; return mResources.ArrayIndexClampingStrategy;
} }
const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const
{ {
return builtInFunctionEmulator; return mBuiltInFunctionEmulator;
} }
void TCompiler::writePragma(ShCompileOptions compileOptions) void TCompiler::writePragma(ShCompileOptions compileOptions)
{ {
if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL)) if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL))
{ {
TInfoSinkBase &sink = infoSink.obj; TInfoSinkBase &sink = mInfoSink.obj;
if (mPragma.stdgl.invariantAll) if (mPragma.stdgl.invariantAll)
sink << "#pragma STDGL invariant(all)\n"; sink << "#pragma STDGL invariant(all)\n";
} }
...@@ -1219,17 +1201,17 @@ void TCompiler::writePragma(ShCompileOptions compileOptions) ...@@ -1219,17 +1201,17 @@ void TCompiler::writePragma(ShCompileOptions compileOptions)
bool TCompiler::isVaryingDefined(const char *varyingName) bool TCompiler::isVaryingDefined(const char *varyingName)
{ {
ASSERT(variablesCollected); ASSERT(mVariablesCollected);
for (size_t ii = 0; ii < inputVaryings.size(); ++ii) for (size_t ii = 0; ii < mInputVaryings.size(); ++ii)
{ {
if (inputVaryings[ii].name == varyingName) if (mInputVaryings[ii].name == varyingName)
{ {
return true; return true;
} }
} }
for (size_t ii = 0; ii < outputVaryings.size(); ++ii) for (size_t ii = 0; ii < mOutputVaryings.size(); ++ii)
{ {
if (outputVaryings[ii].name == varyingName) if (mOutputVaryings[ii].name == varyingName)
{ {
return true; return true;
} }
......
...@@ -94,8 +94,8 @@ class TCompiler : public TShHandleBase ...@@ -94,8 +94,8 @@ class TCompiler : public TShHandleBase
ShCompileOptions compileOptions); ShCompileOptions compileOptions);
// Get results of the last compilation. // Get results of the last compilation.
int getShaderVersion() const { return shaderVersion; } int getShaderVersion() const { return mShaderVersion; }
TInfoSink &getInfoSink() { return infoSink; } TInfoSink &getInfoSink() { return mInfoSink; }
bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; } bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
const sh::WorkGroupSize &getComputeShaderLocalSize() const { return mComputeShaderLocalSize; } const sh::WorkGroupSize &getComputeShaderLocalSize() const { return mComputeShaderLocalSize; }
...@@ -104,25 +104,25 @@ class TCompiler : public TShHandleBase ...@@ -104,25 +104,25 @@ class TCompiler : public TShHandleBase
// Clears the results from the previous compilation. // Clears the results from the previous compilation.
void clearResults(); void clearResults();
const std::vector<sh::Attribute> &getAttributes() const { return attributes; } const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; }
const std::vector<sh::OutputVariable> &getOutputVariables() const { return outputVariables; } const std::vector<sh::OutputVariable> &getOutputVariables() const { return mOutputVariables; }
const std::vector<sh::Uniform> &getUniforms() const { return uniforms; } const std::vector<sh::Uniform> &getUniforms() const { return mUniforms; }
const std::vector<sh::Varying> &getInputVaryings() const { return inputVaryings; } const std::vector<sh::Varying> &getInputVaryings() const { return mInputVaryings; }
const std::vector<sh::Varying> &getOutputVaryings() const { return outputVaryings; } const std::vector<sh::Varying> &getOutputVaryings() const { return mOutputVaryings; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return interfaceBlocks; } const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return mInterfaceBlocks; }
const std::vector<sh::InterfaceBlock> &getUniformBlocks() const { return uniformBlocks; } const std::vector<sh::InterfaceBlock> &getUniformBlocks() const { return mUniformBlocks; }
const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks() const const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks() const
{ {
return shaderStorageBlocks; return mShaderStorageBlocks;
} }
const std::vector<sh::InterfaceBlock> &getInBlocks() const { return inBlocks; } const std::vector<sh::InterfaceBlock> &getInBlocks() const { return mInBlocks; }
ShHashFunction64 getHashFunction() const { return hashFunction; } ShHashFunction64 getHashFunction() const { return mResources.HashFunction; }
NameMap &getNameMap() { return nameMap; } NameMap &getNameMap() { return mNameMap; }
TSymbolTable &getSymbolTable() { return symbolTable; } TSymbolTable &getSymbolTable() { return mSymbolTable; }
ShShaderSpec getShaderSpec() const { return shaderSpec; } ShShaderSpec getShaderSpec() const { return mShaderSpec; }
ShShaderOutput getOutputType() const { return outputType; } ShShaderOutput getOutputType() const { return mOutputType; }
const std::string &getBuiltInResourcesString() const { return builtInResourcesString; } const std::string &getBuiltInResourcesString() const { return mBuiltInResourcesString; }
bool shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const; bool shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const;
...@@ -140,15 +140,9 @@ class TCompiler : public TShHandleBase ...@@ -140,15 +140,9 @@ class TCompiler : public TShHandleBase
return mGeometryShaderOutputPrimitiveType; return mGeometryShaderOutputPrimitiveType;
} }
sh::GLenum getShaderType() const { return shaderType; } sh::GLenum getShaderType() const { return mShaderType; }
protected: protected:
// Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const ShBuiltInResources &resources);
// Compute the string representation of the built-in resources
void setResourceString();
// Return false if the call depth is exceeded.
bool checkCallDepth();
// Add emulated functions to the built-in function emulator. // Add emulated functions to the built-in function emulator.
virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu, virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu,
ShCompileOptions compileOptions){}; ShCompileOptions compileOptions){};
...@@ -156,20 +150,6 @@ class TCompiler : public TShHandleBase ...@@ -156,20 +150,6 @@ class TCompiler : public TShHandleBase
virtual void translate(TIntermBlock *root, virtual void translate(TIntermBlock *root,
ShCompileOptions compileOptions, ShCompileOptions compileOptions,
PerformanceDiagnostics *perfDiagnostics) = 0; PerformanceDiagnostics *perfDiagnostics) = 0;
// Insert statements to reference all members in unused uniform blocks with standard and shared
// layout. This is to work around a Mac driver that treats unused standard/shared
// uniform blocks as inactive.
void useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root);
// Insert statements to initialize output variables in the beginning of main().
// This is to avoid undefined behaviors.
void initializeOutputVariables(TIntermBlock *root);
// Insert gl_Position = vec4(0,0,0,0) to the beginning of main().
// It is to work around a Linux driver bug where missing this causes compile failure
// while spec says it is allowed.
// This function should only be applied to vertex shaders.
void initializeGLPosition(TIntermBlock *root);
// Return true if the maximum expression complexity is below the limit.
bool limitExpressionComplexity(TIntermBlock *root);
// Get built-in extensions with default behavior. // Get built-in extensions with default behavior.
const TExtensionBehavior &getExtensionBehavior() const; const TExtensionBehavior &getExtensionBehavior() const;
const char *getSourcePath() const; const char *getSourcePath() const;
...@@ -186,28 +166,46 @@ class TCompiler : public TShHandleBase ...@@ -186,28 +166,46 @@ class TCompiler : public TShHandleBase
virtual bool shouldCollectVariables(ShCompileOptions compileOptions); virtual bool shouldCollectVariables(ShCompileOptions compileOptions);
bool wereVariablesCollected() const; bool wereVariablesCollected() const;
std::vector<sh::Attribute> attributes; std::vector<sh::Attribute> mAttributes;
std::vector<sh::OutputVariable> outputVariables; std::vector<sh::OutputVariable> mOutputVariables;
std::vector<sh::Uniform> uniforms; std::vector<sh::Uniform> mUniforms;
std::vector<sh::Varying> inputVaryings; std::vector<sh::Varying> mInputVaryings;
std::vector<sh::Varying> outputVaryings; std::vector<sh::Varying> mOutputVaryings;
std::vector<sh::InterfaceBlock> interfaceBlocks; std::vector<sh::InterfaceBlock> mInterfaceBlocks;
std::vector<sh::InterfaceBlock> uniformBlocks; std::vector<sh::InterfaceBlock> mUniformBlocks;
std::vector<sh::InterfaceBlock> shaderStorageBlocks; std::vector<sh::InterfaceBlock> mShaderStorageBlocks;
std::vector<sh::InterfaceBlock> inBlocks; std::vector<sh::InterfaceBlock> mInBlocks;
private: private:
// Initialize symbol-table with built-in symbols.
bool initBuiltInSymbolTable(const ShBuiltInResources &resources);
// Compute the string representation of the built-in resources
void setResourceString();
// Return false if the call depth is exceeded.
bool checkCallDepth();
// Insert statements to reference all members in unused uniform blocks with standard and shared
// layout. This is to work around a Mac driver that treats unused standard/shared
// uniform blocks as inactive.
void useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root);
// Insert statements to initialize output variables in the beginning of main().
// This is to avoid undefined behaviors.
void initializeOutputVariables(TIntermBlock *root);
// Insert gl_Position = vec4(0,0,0,0) to the beginning of main().
// It is to work around a Linux driver bug where missing this causes compile failure
// while spec says it is allowed.
// This function should only be applied to vertex shaders.
void initializeGLPosition(TIntermBlock *root);
// Return true if the maximum expression complexity is below the limit.
bool limitExpressionComplexity(TIntermBlock *root);
// Creates the function call DAG for further analysis, returning false if there is a recursion // Creates the function call DAG for further analysis, returning false if there is a recursion
bool initCallDag(TIntermNode *root); bool initCallDag(TIntermNode *root);
// Return false if "main" doesn't exist // Return false if "main" doesn't exist
bool tagUsedFunctions(); bool tagUsedFunctions();
void internalTagUsedFunction(size_t index); void internalTagUsedFunction(size_t index);
void initSamplerDefaultPrecision(TBasicType samplerType);
void collectInterfaceBlocks(); void collectInterfaceBlocks();
bool variablesCollected; bool mVariablesCollected;
bool mGLPositionInitialized; bool mGLPositionInitialized;
...@@ -231,9 +229,9 @@ class TCompiler : public TShHandleBase ...@@ -231,9 +229,9 @@ class TCompiler : public TShHandleBase
const TParseContext &parseContext, const TParseContext &parseContext,
ShCompileOptions compileOptions); ShCompileOptions compileOptions);
sh::GLenum shaderType; sh::GLenum mShaderType;
ShShaderSpec shaderSpec; ShShaderSpec mShaderSpec;
ShShaderOutput outputType; ShShaderOutput mOutputType;
struct FunctionMetadata struct FunctionMetadata
{ {
...@@ -242,30 +240,23 @@ class TCompiler : public TShHandleBase ...@@ -242,30 +240,23 @@ class TCompiler : public TShHandleBase
}; };
CallDAG mCallDag; CallDAG mCallDag;
std::vector<FunctionMetadata> functionMetadata; std::vector<FunctionMetadata> mFunctionMetadata;
int maxUniformVectors;
int maxExpressionComplexity;
int maxCallStackDepth;
int maxFunctionParameters;
ShBuiltInResources compileResources; ShBuiltInResources mResources;
std::string builtInResourcesString; std::string mBuiltInResourcesString;
// Built-in symbol table for the given language, spec, and resources. // Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile. // It is preserved from compile-to-compile.
TSymbolTable symbolTable; TSymbolTable mSymbolTable;
// Built-in extensions with default behavior. // Built-in extensions with default behavior.
TExtensionBehavior extensionBehavior; TExtensionBehavior mExtensionBehavior;
bool fragmentPrecisionHigh;
ArrayBoundsClamper arrayBoundsClamper; ArrayBoundsClamper mArrayBoundsClamper;
ShArrayIndexClampingStrategy clampingStrategy; BuiltInFunctionEmulator mBuiltInFunctionEmulator;
BuiltInFunctionEmulator builtInFunctionEmulator;
// Results of compilation. // Results of compilation.
int shaderVersion; int mShaderVersion;
TInfoSink infoSink; // Output sink. TInfoSink mInfoSink; // Output sink.
TDiagnostics mDiagnostics; TDiagnostics mDiagnostics;
const char *mSourcePath; // Path of source file or NULL const char *mSourcePath; // Path of source file or NULL
...@@ -283,8 +274,7 @@ class TCompiler : public TShHandleBase ...@@ -283,8 +274,7 @@ class TCompiler : public TShHandleBase
TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType; TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType;
// name hashing. // name hashing.
ShHashFunction64 hashFunction; NameMap mNameMap;
NameMap nameMap;
TPragma mPragma; TPragma mPragma;
}; };
......
...@@ -141,7 +141,7 @@ void TranslatorGLSL::translate(TIntermBlock *root, ...@@ -141,7 +141,7 @@ void TranslatorGLSL::translate(TIntermBlock *root,
bool hasGLSecondaryFragColor = false; bool hasGLSecondaryFragColor = false;
bool hasGLSecondaryFragData = false; bool hasGLSecondaryFragData = false;
for (const auto &outputVar : outputVariables) for (const auto &outputVar : mOutputVariables)
{ {
if (declareGLFragmentOutputs) if (declareGLFragmentOutputs)
{ {
......
...@@ -686,7 +686,7 @@ void TranslatorVulkan::translate(TIntermBlock *root, ...@@ -686,7 +686,7 @@ void TranslatorVulkan::translate(TIntermBlock *root,
bool usesFragCoord = false; bool usesFragCoord = false;
// Search for the gl_PointCoord usage, if its used, we need to flip the y coordinate. // Search for the gl_PointCoord usage, if its used, we need to flip the y coordinate.
for (const Varying &inputVarying : inputVaryings) for (const Varying &inputVarying : mInputVaryings)
{ {
if (!inputVarying.isBuiltIn()) if (!inputVarying.isBuiltIn())
{ {
...@@ -712,7 +712,7 @@ void TranslatorVulkan::translate(TIntermBlock *root, ...@@ -712,7 +712,7 @@ void TranslatorVulkan::translate(TIntermBlock *root,
bool hasGLFragColor = false; bool hasGLFragColor = false;
bool hasGLFragData = false; bool hasGLFragData = false;
for (const OutputVariable &outputVar : outputVariables) for (const OutputVariable &outputVar : mOutputVariables)
{ {
if (outputVar.name == "gl_FragColor") if (outputVar.name == "gl_FragColor")
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment