1 // 2 // Copyright 2019 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 7 #ifndef COMPILER_TRANSLATOR_VALIDATEAST_H_ 8 #define COMPILER_TRANSLATOR_VALIDATEAST_H_ 9 10 #include "compiler/translator/BaseTypes.h" 11 #include "compiler/translator/Common.h" 12 13 namespace sh 14 { 15 class TDiagnostics; 16 class TIntermNode; 17 18 // The following options (stored in Compiler) tell the validator what to validate. Some validations 19 // are conditional to certain passes. 20 struct ValidateASTOptions 21 { 22 // TODO: add support for the flags marked with TODO. http://anglebug.com/2733 23 24 // Check that every node always has only one parent, 25 bool validateSingleParent = true; 26 // Check that all symbols reference TVariables that have been declared. For built-ins, this 27 // makes sure that the same GLSL built-in uses the same TVariable consistently. 28 bool validateVariableReferences = true; 29 // Whether validateVariableReferences should also include specialization constants. Their 30 // declaration is output after their usage is discovered, so this is disabled until then. 31 bool validateSpecConstReferences = false; 32 // Check that TIntermUnary and TIntermAggregate nodes with a built-in op reference a function 33 // with said op. 34 bool validateBuiltInOps = true; 35 // Check that all EOpCallFunctionInAST have their corresponding function definitions in the AST, 36 // with matching symbol ids. There should also be at least a prototype declaration before the 37 // function is called. 38 bool validateFunctionCall = true; 39 // Check that EOpCallInternalRawFunction is not used. This OP is deprecated and needs to be 40 // removed. http://anglebug.com/6059 41 bool validateNoRawFunctionCalls = true; 42 // Check that there are no null nodes where they are not allowed, for example as children of 43 // TIntermDeclaration or TIntermBlock. 44 bool validateNullNodes = true; 45 // Check that symbols that reference variables have consistent qualifiers and symbol ids with 46 // the variable declaration. The following needs to be validated: 47 // 48 // Implemented: 49 // 50 // - Function parameters having one of EvqParam* qualifiers. 51 // - gl_ClipDistance, gl_CullDistance and gl_LastFragData are correctly qualified even when 52 // redeclared in the shader. 53 // 54 // TODO: 55 // 56 // - Function-local variables must have the EvqTemporary qualifier. 57 // - Symbol references and declarations have identical qualifiers. 58 bool validateQualifiers = true; 59 // Check that every symbol has its precision specified. That includes variables, block members, 60 // function parameters and return values. 61 bool validatePrecision = true; 62 // Check that variable declarations that can't have initializers don't have initializers 63 // (varyings, uniforms for example). 64 bool validateInitializers = true; // TODO 65 // Check that there is only one TFunction with each function name referenced in the nodes (no 66 // two TFunctions with the same name, taking internal/non-internal namespaces into account). 67 bool validateUniqueFunctions = true; // TODO 68 // Check that references to structs are matched with the corresponding struct declaration. 69 bool validateStructUsage = true; 70 // Check that expression nodes have the correct type considering their operand(s). The 71 // following validation is possible: 72 // 73 // Implemented: 74 // 75 // - Binary node that indexes T[] should have type T 76 // 77 // TODO: 78 // 79 // - Function calls (including built-ins) have the same return type in the node and function. 80 // - Unary and binary operators have the correct type based on operands 81 // - Swizzle result has same type as the operand except for vector size 82 // - Ternary operator has the same type as the operands 83 bool validateExpressionTypes = true; 84 // If SeparateDeclarations has been run, check for the absence of multi declarations as well. 85 bool validateMultiDeclarations = false; 86 87 // Once set, disallows any further transformations on the tree. Used before AST post-processing 88 // which requires that the tree remains unmodified. 89 bool validateNoMoreTransformations = false; 90 }; 91 92 // Check for errors and output error messages on the context. 93 // Returns true if there are no errors. 94 bool ValidateAST(TIntermNode *root, TDiagnostics *diagnostics, const ValidateASTOptions &options); 95 96 } // namespace sh 97 98 #endif // COMPILER_TRANSLATOR_VALIDATESWITCH_H_ 99