1 // 2 // Copyright 2002 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 #ifndef COMPILER_TRANSLATOR_PARSECONTEXT_H_ 7 #define COMPILER_TRANSLATOR_PARSECONTEXT_H_ 8 9 #include "compiler/preprocessor/Preprocessor.h" 10 #include "compiler/translator/Compiler.h" 11 #include "compiler/translator/Declarator.h" 12 #include "compiler/translator/Diagnostics.h" 13 #include "compiler/translator/DirectiveHandler.h" 14 #include "compiler/translator/FunctionLookup.h" 15 #include "compiler/translator/QualifierTypes.h" 16 #include "compiler/translator/SymbolTable.h" 17 18 namespace sh 19 { 20 21 struct TMatrixFields 22 { 23 bool wholeRow; 24 bool wholeCol; 25 int row; 26 int col; 27 }; 28 29 // 30 // The following are extra variables needed during parsing, grouped together so 31 // they can be passed to the parser without needing a global. 32 // 33 class TParseContext : angle::NonCopyable 34 { 35 public: 36 TParseContext(TSymbolTable &symt, 37 TExtensionBehavior &ext, 38 sh::GLenum type, 39 ShShaderSpec spec, 40 ShCompileOptions options, 41 bool checksPrecErrors, 42 TDiagnostics *diagnostics, 43 const ShBuiltInResources &resources, 44 ShShaderOutput outputType); 45 ~TParseContext(); 46 47 bool anyMultiviewExtensionAvailable(); getPreprocessor()48 const angle::pp::Preprocessor &getPreprocessor() const { return mPreprocessor; } getPreprocessor()49 angle::pp::Preprocessor &getPreprocessor() { return mPreprocessor; } getScanner()50 void *getScanner() const { return mScanner; } setScanner(void * scanner)51 void setScanner(void *scanner) { mScanner = scanner; } getShaderVersion()52 int getShaderVersion() const { return mShaderVersion; } getShaderType()53 sh::GLenum getShaderType() const { return mShaderType; } getShaderSpec()54 ShShaderSpec getShaderSpec() const { return mShaderSpec; } numErrors()55 int numErrors() const { return mDiagnostics->numErrors(); } 56 void error(const TSourceLoc &loc, const char *reason, const char *token); 57 void error(const TSourceLoc &loc, const char *reason, const ImmutableString &token); 58 void warning(const TSourceLoc &loc, const char *reason, const char *token); 59 60 // If isError is false, a warning will be reported instead. 61 void outOfRangeError(bool isError, 62 const TSourceLoc &loc, 63 const char *reason, 64 const char *token); 65 getTreeRoot()66 TIntermBlock *getTreeRoot() const { return mTreeRoot; } 67 void setTreeRoot(TIntermBlock *treeRoot); 68 getFragmentPrecisionHigh()69 bool getFragmentPrecisionHigh() const 70 { 71 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300; 72 } setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)73 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh) 74 { 75 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh; 76 } 77 isEarlyFragmentTestsSpecified()78 bool isEarlyFragmentTestsSpecified() const { return mEarlyFragmentTestsSpecified; } 79 setLoopNestingLevel(int loopNestintLevel)80 void setLoopNestingLevel(int loopNestintLevel) { mLoopNestingLevel = loopNestintLevel; } 81 incrLoopNestingLevel()82 void incrLoopNestingLevel() { ++mLoopNestingLevel; } decrLoopNestingLevel()83 void decrLoopNestingLevel() { --mLoopNestingLevel; } 84 incrSwitchNestingLevel()85 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; } decrSwitchNestingLevel()86 void decrSwitchNestingLevel() { --mSwitchNestingLevel; } 87 isComputeShaderLocalSizeDeclared()88 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; } 89 sh::WorkGroupSize getComputeShaderLocalSize() const; 90 getNumViews()91 int getNumViews() const { return mNumViews; } 92 enterFunctionDeclaration()93 void enterFunctionDeclaration() { mDeclaringFunction = true; } 94 exitFunctionDeclaration()95 void exitFunctionDeclaration() { mDeclaringFunction = false; } 96 declaringFunction()97 bool declaringFunction() const { return mDeclaringFunction; } 98 99 TIntermConstantUnion *addScalarLiteral(const TConstantUnion *constantUnion, 100 const TSourceLoc &line); 101 102 // This method is guaranteed to succeed, even if no variable with 'name' exists. 103 const TVariable *getNamedVariable(const TSourceLoc &location, 104 const ImmutableString &name, 105 const TSymbol *symbol); 106 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location, 107 const ImmutableString &name, 108 const TSymbol *symbol); 109 110 // Look at a '.' field selector string and change it into offsets for a vector. 111 bool parseVectorFields(const TSourceLoc &line, 112 const ImmutableString &compString, 113 int vecSize, 114 TVector<int> *fieldOffsets); 115 116 void assignError(const TSourceLoc &line, const char *op, const TType &left, const TType &right); 117 void unaryOpError(const TSourceLoc &line, const char *op, const TType &operand); 118 void binaryOpError(const TSourceLoc &line, 119 const char *op, 120 const TType &left, 121 const TType &right); 122 123 // Check functions - the ones that return bool return false if an error was generated. 124 125 bool checkIsNotReserved(const TSourceLoc &line, const ImmutableString &identifier); 126 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type); 127 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node); 128 void checkIsConst(TIntermTyped *node); 129 void checkIsScalarInteger(TIntermTyped *node, const char *token); 130 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token); 131 bool checkConstructorArguments(const TSourceLoc &line, 132 const TIntermSequence &arguments, 133 const TType &type); 134 135 // Returns a sanitized array size to use (the size is at least 1). 136 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr); 137 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier); 138 bool checkArrayElementIsNotArray(const TSourceLoc &line, const TPublicType &elementType); 139 bool checkArrayOfArraysInOut(const TSourceLoc &line, 140 const TPublicType &elementType, 141 const TType &arrayType); 142 bool checkIsNonVoid(const TSourceLoc &line, 143 const ImmutableString &identifier, 144 const TBasicType &type); 145 bool checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type); 146 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType); 147 bool checkIsNotOpaqueType(const TSourceLoc &line, 148 const TTypeSpecifierNonArray &pType, 149 const char *reason); 150 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType); 151 void checkLocationIsNotSpecified(const TSourceLoc &location, 152 const TLayoutQualifier &layoutQualifier); 153 void checkStd430IsForShaderStorageBlock(const TSourceLoc &location, 154 const TLayoutBlockStorage &blockStorage, 155 const TQualifier &qualifier); 156 void checkIsParameterQualifierValid(const TSourceLoc &line, 157 const TTypeQualifierBuilder &typeQualifierBuilder, 158 TType *type); 159 160 // Check if at least one of the specified extensions can be used, and generate error/warning as 161 // appropriate according to the spec. 162 // This function is only needed for a few different small constant sizes of extension array, and 163 // we want to avoid unnecessary dynamic allocations. That's why checkCanUseOneOfExtensions is a 164 // template function rather than one taking a vector. 165 template <size_t size> 166 bool checkCanUseOneOfExtensions(const TSourceLoc &line, 167 const std::array<TExtension, size> &extensions); 168 bool checkCanUseExtension(const TSourceLoc &line, TExtension extension); 169 170 // Done for all declarations, whether empty or not. 171 void declarationQualifierErrorCheck(const sh::TQualifier qualifier, 172 const sh::TLayoutQualifier &layoutQualifier, 173 const TSourceLoc &location); 174 // Done for the first non-empty declarator in a declaration. 175 void nonEmptyDeclarationErrorCheck(const TPublicType &publicType, 176 const TSourceLoc &identifierLocation); 177 // Done only for empty declarations. 178 void emptyDeclarationErrorCheck(const TType &type, const TSourceLoc &location); 179 180 void checkCanUseLayoutQualifier(const TSourceLoc &location); 181 bool checkLayoutQualifierSupported(const TSourceLoc &location, 182 const ImmutableString &layoutQualifierName, 183 int versionRequired); 184 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location, 185 const TLayoutQualifier &layoutQualifier); 186 void functionCallRValueLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall); 187 void checkInvariantVariableQualifier(bool invariant, 188 const TQualifier qualifier, 189 const TSourceLoc &invariantLocation); 190 void checkInputOutputTypeIsValidES3(const TQualifier qualifier, 191 const TPublicType &type, 192 const TSourceLoc &qualifierLocation); 193 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier); 194 void checkTCSOutVarIndexIsValid(TIntermBinary *binaryExpression, const TSourceLoc &location); pragma()195 const TPragma &pragma() const { return mDirectiveHandler.pragma(); } extensionBehavior()196 const TExtensionBehavior &extensionBehavior() const 197 { 198 return mDirectiveHandler.extensionBehavior(); 199 } 200 201 bool isExtensionEnabled(TExtension extension) const; 202 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); 203 void handlePragmaDirective(const TSourceLoc &loc, 204 const char *name, 205 const char *value, 206 bool stdgl); 207 208 // Returns true on success. *initNode may still be nullptr on success in case the initialization 209 // is not needed in the AST. 210 bool executeInitializer(const TSourceLoc &line, 211 const ImmutableString &identifier, 212 TType *type, 213 TIntermTyped *initializer, 214 TIntermBinary **initNode); 215 TIntermNode *addConditionInitializer(const TPublicType &pType, 216 const ImmutableString &identifier, 217 TIntermTyped *initializer, 218 const TSourceLoc &loc); 219 TIntermNode *addLoop(TLoopType type, 220 TIntermNode *init, 221 TIntermNode *cond, 222 TIntermTyped *expr, 223 TIntermNode *body, 224 const TSourceLoc &loc); 225 226 // For "if" test nodes. There are three children: a condition, a true path, and a false path. 227 // The two paths are in TIntermNodePair code. 228 TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &loc); 229 230 void addFullySpecifiedType(TPublicType *typeSpecifier); 231 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder, 232 const TPublicType &typeSpecifier); 233 234 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType, 235 const TSourceLoc &identifierOrTypeLocation, 236 const ImmutableString &identifier); 237 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &elementType, 238 const TSourceLoc &identifierLocation, 239 const ImmutableString &identifier, 240 const TSourceLoc &indexLocation, 241 const TVector<unsigned int> &arraySizes); 242 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType, 243 const TSourceLoc &identifierLocation, 244 const ImmutableString &identifier, 245 const TSourceLoc &initLocation, 246 TIntermTyped *initializer); 247 248 // Parse a declaration like "type a[n] = initializer" 249 // Note that this does not apply to declarations like "type[n] a = initializer" 250 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &elementType, 251 const TSourceLoc &identifierLocation, 252 const ImmutableString &identifier, 253 const TSourceLoc &indexLocation, 254 const TVector<unsigned int> &arraySizes, 255 const TSourceLoc &initLocation, 256 TIntermTyped *initializer); 257 258 TIntermGlobalQualifierDeclaration *parseGlobalQualifierDeclaration( 259 const TTypeQualifierBuilder &typeQualifierBuilder, 260 const TSourceLoc &identifierLoc, 261 const ImmutableString &identifier, 262 const TSymbol *symbol); 263 264 void parseDeclarator(TPublicType &publicType, 265 const TSourceLoc &identifierLocation, 266 const ImmutableString &identifier, 267 TIntermDeclaration *declarationOut); 268 void parseArrayDeclarator(TPublicType &elementType, 269 const TSourceLoc &identifierLocation, 270 const ImmutableString &identifier, 271 const TSourceLoc &arrayLocation, 272 const TVector<unsigned int> &arraySizes, 273 TIntermDeclaration *declarationOut); 274 void parseInitDeclarator(const TPublicType &publicType, 275 const TSourceLoc &identifierLocation, 276 const ImmutableString &identifier, 277 const TSourceLoc &initLocation, 278 TIntermTyped *initializer, 279 TIntermDeclaration *declarationOut); 280 281 // Parse a declarator like "a[n] = initializer" 282 void parseArrayInitDeclarator(const TPublicType &elementType, 283 const TSourceLoc &identifierLocation, 284 const ImmutableString &identifier, 285 const TSourceLoc &indexLocation, 286 const TVector<unsigned int> &arraySizes, 287 const TSourceLoc &initLocation, 288 TIntermTyped *initializer, 289 TIntermDeclaration *declarationOut); 290 291 TIntermNode *addEmptyStatement(const TSourceLoc &location); 292 293 void parseDefaultPrecisionQualifier(const TPrecision precision, 294 const TPublicType &type, 295 const TSourceLoc &loc); 296 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder); 297 298 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction, 299 const TSourceLoc &location); 300 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype, 301 TIntermBlock *functionBody, 302 const TSourceLoc &location); 303 void parseFunctionDefinitionHeader(const TSourceLoc &location, 304 const TFunction *function, 305 TIntermFunctionPrototype **prototypeOut); 306 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function); 307 TFunction *parseFunctionHeader(const TPublicType &type, 308 const ImmutableString &name, 309 const TSourceLoc &location); 310 311 TFunctionLookup *addNonConstructorFunc(const ImmutableString &name, const TSymbol *symbol); 312 TFunctionLookup *addConstructorFunc(const TPublicType &publicType); 313 314 TParameter parseParameterDeclarator(const TPublicType &publicType, 315 const ImmutableString &name, 316 const TSourceLoc &nameLoc); 317 318 TParameter parseParameterArrayDeclarator(const ImmutableString &name, 319 const TSourceLoc &nameLoc, 320 const TVector<unsigned int> &arraySizes, 321 const TSourceLoc &arrayLoc, 322 TPublicType *elementType); 323 324 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, 325 const TSourceLoc &location, 326 TIntermTyped *indexExpression); 327 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression, 328 const TSourceLoc &dotLocation, 329 const ImmutableString &fieldString, 330 const TSourceLoc &fieldLocation); 331 332 // Parse declarator for a single field 333 TDeclarator *parseStructDeclarator(const ImmutableString &identifier, const TSourceLoc &loc); 334 TDeclarator *parseStructArrayDeclarator(const ImmutableString &identifier, 335 const TSourceLoc &loc, 336 const TVector<unsigned int> *arraySizes); 337 338 void checkDoesNotHaveDuplicateFieldName(const TFieldList::const_iterator begin, 339 const TFieldList::const_iterator end, 340 const ImmutableString &name, 341 const TSourceLoc &location); 342 TFieldList *addStructFieldList(TFieldList *fields, const TSourceLoc &location); 343 TFieldList *combineStructFieldLists(TFieldList *processedFields, 344 const TFieldList *newlyAddedFields, 345 const TSourceLoc &location); 346 TFieldList *addStructDeclaratorListWithQualifiers( 347 const TTypeQualifierBuilder &typeQualifierBuilder, 348 TPublicType *typeSpecifier, 349 const TDeclaratorList *declaratorList); 350 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, 351 const TDeclaratorList *declaratorList); 352 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine, 353 const TSourceLoc &nameLine, 354 const ImmutableString &structName, 355 TFieldList *fieldList); 356 357 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder, 358 const TSourceLoc &nameLine, 359 const ImmutableString &blockName, 360 TFieldList *fieldList, 361 const ImmutableString &instanceName, 362 const TSourceLoc &instanceLine, 363 const TVector<unsigned int> *arraySizes, 364 const TSourceLoc &arraySizesLine); 365 366 void parseLocalSize(const ImmutableString &qualifierType, 367 const TSourceLoc &qualifierTypeLine, 368 int intValue, 369 const TSourceLoc &intValueLine, 370 const std::string &intValueString, 371 size_t index, 372 sh::WorkGroupSize *localSize); 373 void parseNumViews(int intValue, 374 const TSourceLoc &intValueLine, 375 const std::string &intValueString, 376 int *numViews); 377 void parseInvocations(int intValue, 378 const TSourceLoc &intValueLine, 379 const std::string &intValueString, 380 int *numInvocations); 381 void parseMaxVertices(int intValue, 382 const TSourceLoc &intValueLine, 383 const std::string &intValueString, 384 int *numMaxVertices); 385 void parseVertices(int intValue, 386 const TSourceLoc &intValueLine, 387 const std::string &intValueString, 388 int *numVertices); 389 void parseIndexLayoutQualifier(int intValue, 390 const TSourceLoc &intValueLine, 391 const std::string &intValueString, 392 int *index); 393 TLayoutQualifier parseLayoutQualifier(const ImmutableString &qualifierType, 394 const TSourceLoc &qualifierTypeLine); 395 TLayoutQualifier parseLayoutQualifier(const ImmutableString &qualifierType, 396 const TSourceLoc &qualifierTypeLine, 397 int intValue, 398 const TSourceLoc &intValueLine); 399 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc); 400 TStorageQualifierWrapper *parseGlobalStorageQualifier(TQualifier qualifier, 401 const TSourceLoc &loc); 402 TStorageQualifierWrapper *parseVaryingQualifier(const TSourceLoc &loc); 403 TStorageQualifierWrapper *parseInQualifier(const TSourceLoc &loc); 404 TStorageQualifierWrapper *parseOutQualifier(const TSourceLoc &loc); 405 TStorageQualifierWrapper *parseInOutQualifier(const TSourceLoc &loc); 406 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, 407 TLayoutQualifier rightQualifier, 408 const TSourceLoc &rightQualifierLocation); 409 410 // Performs an error check for embedded struct declarations. 411 void enterStructDeclaration(const TSourceLoc &line, const ImmutableString &identifier); 412 void exitStructDeclaration(); 413 414 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field); 415 416 TIntermSwitch *addSwitch(TIntermTyped *init, 417 TIntermBlock *statementList, 418 const TSourceLoc &loc); 419 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc); 420 TIntermCase *addDefault(const TSourceLoc &loc); 421 422 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); 423 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); 424 TIntermTyped *addBinaryMath(TOperator op, 425 TIntermTyped *left, 426 TIntermTyped *right, 427 const TSourceLoc &loc); 428 TIntermTyped *addBinaryMathBooleanResult(TOperator op, 429 TIntermTyped *left, 430 TIntermTyped *right, 431 const TSourceLoc &loc); 432 TIntermTyped *addAssign(TOperator op, 433 TIntermTyped *left, 434 TIntermTyped *right, 435 const TSourceLoc &loc); 436 437 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); 438 439 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); 440 TIntermBranch *addBranch(TOperator op, TIntermTyped *expression, const TSourceLoc &loc); 441 442 void appendStatement(TIntermBlock *block, TIntermNode *statement); 443 444 void checkTextureGather(TIntermAggregate *functionCall); 445 void checkTextureOffset(TIntermAggregate *functionCall); 446 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall); 447 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition, 448 const TIntermAggregate *functionCall); 449 void checkAtomicMemoryBuiltinFunctions(TIntermAggregate *functionCall); 450 void checkInterpolationFS(TIntermAggregate *functionCall); 451 452 // fnCall is only storing the built-in op, and function name or constructor type. arguments 453 // has the arguments. 454 TIntermTyped *addFunctionCallOrMethod(TFunctionLookup *fnCall, const TSourceLoc &loc); 455 456 TIntermTyped *addTernarySelection(TIntermTyped *cond, 457 TIntermTyped *trueExpression, 458 TIntermTyped *falseExpression, 459 const TSourceLoc &line); 460 getGeometryShaderMaxVertices()461 int getGeometryShaderMaxVertices() const { return mGeometryShaderMaxVertices; } getGeometryShaderInvocations()462 int getGeometryShaderInvocations() const 463 { 464 return (mGeometryShaderInvocations > 0) ? mGeometryShaderInvocations : 1; 465 } getGeometryShaderInputPrimitiveType()466 TLayoutPrimitiveType getGeometryShaderInputPrimitiveType() const 467 { 468 return mGeometryShaderInputPrimitiveType; 469 } getGeometryShaderOutputPrimitiveType()470 TLayoutPrimitiveType getGeometryShaderOutputPrimitiveType() const 471 { 472 return mGeometryShaderOutputPrimitiveType; 473 } getTessControlShaderOutputVertices()474 int getTessControlShaderOutputVertices() const { return mTessControlShaderOutputVertices; } getTessEvaluationShaderInputPrimitiveType()475 TLayoutTessEvaluationType getTessEvaluationShaderInputPrimitiveType() const 476 { 477 return mTessEvaluationShaderInputPrimitiveType; 478 } getTessEvaluationShaderInputVertexSpacingType()479 TLayoutTessEvaluationType getTessEvaluationShaderInputVertexSpacingType() const 480 { 481 return mTessEvaluationShaderInputVertexSpacingType; 482 } getTessEvaluationShaderInputOrderingType()483 TLayoutTessEvaluationType getTessEvaluationShaderInputOrderingType() const 484 { 485 return mTessEvaluationShaderInputOrderingType; 486 } getTessEvaluationShaderInputPointType()487 TLayoutTessEvaluationType getTessEvaluationShaderInputPointType() const 488 { 489 return mTessEvaluationShaderInputPointType; 490 } 491 getOutputType()492 ShShaderOutput getOutputType() const { return mOutputType; } 493 494 // TODO(jmadill): make this private 495 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed 496 497 private: 498 class AtomicCounterBindingState; 499 constexpr static size_t kAtomicCounterSize = 4; 500 // UNIFORM_ARRAY_STRIDE for atomic counter arrays is an implementation-dependent value which 501 // can be queried after a program is linked according to ES 3.10 section 7.7.1. This is 502 // controversial with the offset inheritance as described in ESSL 3.10 section 4.4.6. Currently 503 // we treat it as always 4 in favour of the original interpretation in 504 // "ARB_shader_atomic_counters". 505 // TODO(jie.a.chen@intel.com): Double check this once the spec vagueness is resolved. 506 // Note that there may be tests in AtomicCounter_test that will need to be updated as well. 507 constexpr static size_t kAtomicCounterArrayStride = 4; 508 509 void markStaticReadIfSymbol(TIntermNode *node); 510 511 // Returns a clamped index. If it prints out an error message, the token is "[]". 512 int checkIndexLessThan(bool outOfRangeIndexIsError, 513 const TSourceLoc &location, 514 int index, 515 int arraySize, 516 const char *reason); 517 518 bool declareVariable(const TSourceLoc &line, 519 const ImmutableString &identifier, 520 const TType *type, 521 TVariable **variable); 522 523 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line, 524 const ImmutableString &identifier, 525 TType *type); 526 527 TParameter parseParameterDeclarator(TType *type, 528 const ImmutableString &name, 529 const TSourceLoc &nameLoc); 530 531 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation, 532 const TPublicType &elementType); 533 // Done for all atomic counter declarations, whether empty or not. 534 void atomicCounterQualifierErrorCheck(const TPublicType &publicType, 535 const TSourceLoc &location); 536 537 // Assumes that multiplication op has already been set based on the types. 538 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right); 539 540 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line, 541 TQualifier qualifier, 542 const TType &type); 543 544 void checkInternalFormatIsNotSpecified(const TSourceLoc &location, 545 TLayoutImageInternalFormat internalFormat); 546 void checkMemoryQualifierIsNotSpecified(const TMemoryQualifier &memoryQualifier, 547 const TSourceLoc &location); 548 void checkAtomicCounterOffsetDoesNotOverlap(bool forceAppend, 549 const TSourceLoc &loc, 550 TType *type); 551 void checkAtomicCounterOffsetAlignment(const TSourceLoc &location, const TType &type); 552 553 void checkIndexIsNotSpecified(const TSourceLoc &location, int index); 554 void checkBindingIsValid(const TSourceLoc &identifierLocation, const TType &type); 555 void checkBindingIsNotSpecified(const TSourceLoc &location, int binding); 556 void checkOffsetIsNotSpecified(const TSourceLoc &location, int offset); 557 void checkImageBindingIsValid(const TSourceLoc &location, 558 int binding, 559 int arrayTotalElementCount); 560 void checkSamplerBindingIsValid(const TSourceLoc &location, 561 int binding, 562 int arrayTotalElementCount); 563 void checkBlockBindingIsValid(const TSourceLoc &location, 564 const TQualifier &qualifier, 565 int binding, 566 int arraySize); 567 void checkAtomicCounterBindingIsValid(const TSourceLoc &location, int binding); 568 569 void checkUniformLocationInRange(const TSourceLoc &location, 570 int objectLocationCount, 571 const TLayoutQualifier &layoutQualifier); 572 void checkAttributeLocationInRange(const TSourceLoc &location, 573 int objectLocationCount, 574 const TLayoutQualifier &layoutQualifier); 575 576 void checkYuvIsNotSpecified(const TSourceLoc &location, bool yuv); 577 578 void checkEarlyFragmentTestsIsNotSpecified(const TSourceLoc &location, bool earlyFragmentTests); 579 580 void checkNoncoherentIsSpecified(const TSourceLoc &location, bool noncoherent); 581 582 void checkNoncoherentIsNotSpecified(const TSourceLoc &location, bool noncoherent); 583 584 bool checkUnsizedArrayConstructorArgumentDimensionality(const TIntermSequence &arguments, 585 TType type, 586 const TSourceLoc &line); 587 588 void checkCombinedClipCullDistanceIsValid(const TSourceLoc &line, 589 const ImmutableString &identifier, 590 const int arraySize); 591 592 // Check texture offset is within range. 593 void checkSingleTextureOffset(const TSourceLoc &line, 594 const TConstantUnion *values, 595 size_t size, 596 int minOffsetValue, 597 int maxOffsetValue); 598 599 // Will set the size of the outermost array according to geometry shader input layout. 600 void checkGeometryShaderInputAndSetArraySize(const TSourceLoc &location, 601 const ImmutableString &token, 602 TType *type); 603 604 // Similar, for tessellation shaders. 605 void checkTessellationShaderUnsizedArraysAndSetSize(const TSourceLoc &location, 606 const ImmutableString &token, 607 TType *type); 608 609 // Will size any unsized array type so unsized arrays won't need to be taken into account 610 // further along the line in parsing. 611 void checkIsNotUnsizedArray(const TSourceLoc &line, 612 const char *errorMessage, 613 const ImmutableString &token, 614 TType *arrayType); 615 616 TIntermTyped *addBinaryMathInternal(TOperator op, 617 TIntermTyped *left, 618 TIntermTyped *right, 619 const TSourceLoc &loc); 620 TIntermTyped *createUnaryMath(TOperator op, 621 TIntermTyped *child, 622 const TSourceLoc &loc, 623 const TFunction *func); 624 625 TIntermTyped *addMethod(TFunctionLookup *fnCall, const TSourceLoc &loc); 626 TIntermTyped *addConstructor(TFunctionLookup *fnCall, const TSourceLoc &line); 627 TIntermTyped *addNonConstructorFunctionCall(TFunctionLookup *fnCall, const TSourceLoc &loc); 628 629 // Return either the original expression or the folded version of the expression in case the 630 // folded node will validate the same way during subsequent parsing. 631 TIntermTyped *expressionOrFoldedResult(TIntermTyped *expression); 632 633 // Return true if the checks pass 634 bool binaryOpCommonCheck(TOperator op, 635 TIntermTyped *left, 636 TIntermTyped *right, 637 const TSourceLoc &loc); 638 639 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function, 640 const TSourceLoc &location, 641 bool insertParametersToSymbolTable); 642 643 void setAtomicCounterBindingDefaultOffset(const TPublicType &declaration, 644 const TSourceLoc &location); 645 646 bool checkPrimitiveTypeMatchesTypeQualifier(const TTypeQualifier &typeQualifier); 647 bool parseGeometryShaderInputLayoutQualifier(const TTypeQualifier &typeQualifier); 648 bool parseGeometryShaderOutputLayoutQualifier(const TTypeQualifier &typeQualifier); 649 void setGeometryShaderInputArraySize(unsigned int inputArraySize, const TSourceLoc &line); 650 651 bool parseTessControlShaderOutputLayoutQualifier(const TTypeQualifier &typeQualifier); 652 bool parseTessEvaluationShaderInputLayoutQualifier(const TTypeQualifier &typeQualifier); 653 654 // Set to true when the last/current declarator list was started with an empty declaration. The 655 // non-empty declaration error check will need to be performed if the empty declaration is 656 // followed by a declarator. 657 bool mDeferredNonEmptyDeclarationErrorCheck; 658 659 sh::GLenum mShaderType; // vertex/fragment/geometry/etc shader 660 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES/WebGL/etc. 661 ShCompileOptions mCompileOptions; // Options passed to TCompiler 662 int mShaderVersion; 663 TIntermBlock *mTreeRoot; // root of parse tree being created 664 int mLoopNestingLevel; // 0 if outside all loops 665 int mStructNestingLevel; // incremented while parsing a struct declaration 666 int mSwitchNestingLevel; // 0 if outside all switch statements 667 const TType 668 *mCurrentFunctionType; // the return type of the function that's currently being parsed 669 bool mFunctionReturnsValue; // true if a non-void function has a return 670 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared 671 // without precision, explicit or implicit. 672 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling 673 // ESSL1. 674 bool mEarlyFragmentTestsSpecified; // true if layout(early_fragment_tests) in; is specified. 675 TLayoutMatrixPacking mDefaultUniformMatrixPacking; 676 TLayoutBlockStorage mDefaultUniformBlockStorage; 677 TLayoutMatrixPacking mDefaultBufferMatrixPacking; 678 TLayoutBlockStorage mDefaultBufferBlockStorage; 679 TString mHashErrMsg; 680 TDiagnostics *mDiagnostics; 681 TDirectiveHandler mDirectiveHandler; 682 angle::pp::Preprocessor mPreprocessor; 683 void *mScanner; 684 int mMinProgramTexelOffset; 685 int mMaxProgramTexelOffset; 686 687 int mMinProgramTextureGatherOffset; 688 int mMaxProgramTextureGatherOffset; 689 690 // keep track of local group size declared in layout. It should be declared only once. 691 bool mComputeShaderLocalSizeDeclared; 692 sh::WorkGroupSize mComputeShaderLocalSize; 693 // keep track of number of views declared in layout. 694 int mNumViews; 695 int mMaxNumViews; 696 int mMaxImageUnits; 697 int mMaxCombinedTextureImageUnits; 698 int mMaxUniformLocations; 699 int mMaxUniformBufferBindings; 700 int mMaxVertexAttribs; 701 int mMaxAtomicCounterBindings; 702 int mMaxShaderStorageBufferBindings; 703 704 // keeps track whether we are declaring / defining a function 705 bool mDeclaringFunction; 706 707 // Track the state of each atomic counter binding. 708 std::map<int, AtomicCounterBindingState> mAtomicCounterBindingStates; 709 710 // Track the geometry shader global parameters declared in layout. 711 TLayoutPrimitiveType mGeometryShaderInputPrimitiveType; 712 TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType; 713 int mGeometryShaderInvocations; 714 int mGeometryShaderMaxVertices; 715 int mMaxGeometryShaderInvocations; 716 int mMaxGeometryShaderMaxVertices; 717 unsigned int mGeometryInputArraySize; 718 719 int mMaxPatchVertices; 720 int mTessControlShaderOutputVertices; 721 TLayoutTessEvaluationType mTessEvaluationShaderInputPrimitiveType; 722 TLayoutTessEvaluationType mTessEvaluationShaderInputVertexSpacingType; 723 TLayoutTessEvaluationType mTessEvaluationShaderInputOrderingType; 724 TLayoutTessEvaluationType mTessEvaluationShaderInputPointType; 725 726 // Track when we add new scope for func body in ESSL 1.00 spec 727 bool mFunctionBodyNewScope; 728 729 ShShaderOutput mOutputType; 730 }; 731 732 int PaParseStrings(size_t count, 733 const char *const string[], 734 const int length[], 735 TParseContext *context); 736 737 } // namespace sh 738 739 #endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_ 740