1*8975f5c5SAndroid Build Coastguard Worker // 2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2019 The ANGLE Project Authors. All rights reserved. 3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file. 5*8975f5c5SAndroid Build Coastguard Worker // 6*8975f5c5SAndroid Build Coastguard Worker 7*8975f5c5SAndroid Build Coastguard Worker #ifndef COMPILER_TRANSLATOR_VALIDATEAST_H_ 8*8975f5c5SAndroid Build Coastguard Worker #define COMPILER_TRANSLATOR_VALIDATEAST_H_ 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/BaseTypes.h" 11*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/Common.h" 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard Worker namespace sh 14*8975f5c5SAndroid Build Coastguard Worker { 15*8975f5c5SAndroid Build Coastguard Worker class TDiagnostics; 16*8975f5c5SAndroid Build Coastguard Worker class TIntermNode; 17*8975f5c5SAndroid Build Coastguard Worker 18*8975f5c5SAndroid Build Coastguard Worker // The following options (stored in Compiler) tell the validator what to validate. Some validations 19*8975f5c5SAndroid Build Coastguard Worker // are conditional to certain passes. 20*8975f5c5SAndroid Build Coastguard Worker struct ValidateASTOptions 21*8975f5c5SAndroid Build Coastguard Worker { 22*8975f5c5SAndroid Build Coastguard Worker // TODO: add support for the flags marked with TODO. http://anglebug.com/42261441 23*8975f5c5SAndroid Build Coastguard Worker 24*8975f5c5SAndroid Build Coastguard Worker // Check that every node always has only one parent, 25*8975f5c5SAndroid Build Coastguard Worker bool validateSingleParent = true; 26*8975f5c5SAndroid Build Coastguard Worker // Check that all symbols reference TVariables that have been declared. For built-ins, this 27*8975f5c5SAndroid Build Coastguard Worker // makes sure that the same GLSL built-in uses the same TVariable consistently. 28*8975f5c5SAndroid Build Coastguard Worker bool validateVariableReferences = true; 29*8975f5c5SAndroid Build Coastguard Worker // Whether validateVariableReferences should also include specialization constants. Their 30*8975f5c5SAndroid Build Coastguard Worker // declaration is output after their usage is discovered, so this is disabled until then. 31*8975f5c5SAndroid Build Coastguard Worker bool validateSpecConstReferences = false; 32*8975f5c5SAndroid Build Coastguard Worker // Validate that: 33*8975f5c5SAndroid Build Coastguard Worker // 34*8975f5c5SAndroid Build Coastguard Worker // - TIntermUnary only contains unary operators 35*8975f5c5SAndroid Build Coastguard Worker // - TIntermBinary only contains binary operators 36*8975f5c5SAndroid Build Coastguard Worker // - TIntermBranch only contains branch operators 37*8975f5c5SAndroid Build Coastguard Worker // - EOpInitialize is only used in TIntermDeclaration 38*8975f5c5SAndroid Build Coastguard Worker bool validateOps = true; 39*8975f5c5SAndroid Build Coastguard Worker // Check that TIntermUnary and TIntermAggregate nodes with a built-in op reference a function 40*8975f5c5SAndroid Build Coastguard Worker // with said op. 41*8975f5c5SAndroid Build Coastguard Worker bool validateBuiltInOps = true; 42*8975f5c5SAndroid Build Coastguard Worker // Check that all EOpCallFunctionInAST have their corresponding function definitions in the AST, 43*8975f5c5SAndroid Build Coastguard Worker // with matching symbol ids. There should also be at least a prototype declaration before the 44*8975f5c5SAndroid Build Coastguard Worker // function is called. 45*8975f5c5SAndroid Build Coastguard Worker bool validateFunctionCall = true; 46*8975f5c5SAndroid Build Coastguard Worker // Check that EOpCallInternalRawFunction is not used. This OP is deprecated and needs to be 47*8975f5c5SAndroid Build Coastguard Worker // removed. http://anglebug.com/42264589 48*8975f5c5SAndroid Build Coastguard Worker bool validateNoRawFunctionCalls = true; 49*8975f5c5SAndroid Build Coastguard Worker // Check that there are no null nodes where they are not allowed, for example as children of 50*8975f5c5SAndroid Build Coastguard Worker // TIntermDeclaration or TIntermBlock. 51*8975f5c5SAndroid Build Coastguard Worker bool validateNullNodes = true; 52*8975f5c5SAndroid Build Coastguard Worker // Check that symbols that reference variables have consistent qualifiers and symbol ids with 53*8975f5c5SAndroid Build Coastguard Worker // the variable declaration. The following needs to be validated: 54*8975f5c5SAndroid Build Coastguard Worker // 55*8975f5c5SAndroid Build Coastguard Worker // Implemented: 56*8975f5c5SAndroid Build Coastguard Worker // 57*8975f5c5SAndroid Build Coastguard Worker // - Function parameters having one of EvqParam* qualifiers. 58*8975f5c5SAndroid Build Coastguard Worker // - No const qualifier on opaque function parameters. 59*8975f5c5SAndroid Build Coastguard Worker // - gl_ClipDistance, gl_CullDistance and gl_LastFragData are correctly qualified even when 60*8975f5c5SAndroid Build Coastguard Worker // redeclared in the shader. 61*8975f5c5SAndroid Build Coastguard Worker // 62*8975f5c5SAndroid Build Coastguard Worker // TODO: 63*8975f5c5SAndroid Build Coastguard Worker // 64*8975f5c5SAndroid Build Coastguard Worker // - Function-local variables must have the EvqTemporary qualifier. 65*8975f5c5SAndroid Build Coastguard Worker // - Symbol references and declarations have identical qualifiers. 66*8975f5c5SAndroid Build Coastguard Worker bool validateQualifiers = true; 67*8975f5c5SAndroid Build Coastguard Worker // Check that every symbol has its precision specified. That includes variables, block members, 68*8975f5c5SAndroid Build Coastguard Worker // function parameters and return values. 69*8975f5c5SAndroid Build Coastguard Worker bool validatePrecision = true; 70*8975f5c5SAndroid Build Coastguard Worker // Check that variable declarations that can't have initializers don't have initializers 71*8975f5c5SAndroid Build Coastguard Worker // (varyings, uniforms for example). 72*8975f5c5SAndroid Build Coastguard Worker bool validateInitializers = true; // TODO 73*8975f5c5SAndroid Build Coastguard Worker // Check that there is only one TFunction with each function name referenced in the nodes (no 74*8975f5c5SAndroid Build Coastguard Worker // two TFunctions with the same name, taking internal/non-internal namespaces into account). 75*8975f5c5SAndroid Build Coastguard Worker bool validateUniqueFunctions = true; // TODO 76*8975f5c5SAndroid Build Coastguard Worker // Check that references to structs are matched with the corresponding struct declaration. 77*8975f5c5SAndroid Build Coastguard Worker bool validateStructUsage = true; 78*8975f5c5SAndroid Build Coastguard Worker // Check that expression nodes have the correct type considering their operand(s). The 79*8975f5c5SAndroid Build Coastguard Worker // following validation is possible: 80*8975f5c5SAndroid Build Coastguard Worker // 81*8975f5c5SAndroid Build Coastguard Worker // Implemented: 82*8975f5c5SAndroid Build Coastguard Worker // 83*8975f5c5SAndroid Build Coastguard Worker // - Binary node that indexes T[] should have type T 84*8975f5c5SAndroid Build Coastguard Worker // - Binary nodes with EOpIndexDirect* should have a constant as the right node 85*8975f5c5SAndroid Build Coastguard Worker // - Switch nodes should have an integer type in the selector 86*8975f5c5SAndroid Build Coastguard Worker // 87*8975f5c5SAndroid Build Coastguard Worker // TODO: 88*8975f5c5SAndroid Build Coastguard Worker // 89*8975f5c5SAndroid Build Coastguard Worker // - Function calls (including built-ins) have the same return type in the node and function. 90*8975f5c5SAndroid Build Coastguard Worker // - Unary and binary operators have the correct type based on operands 91*8975f5c5SAndroid Build Coastguard Worker // - Swizzle result has same type as the operand except for vector size 92*8975f5c5SAndroid Build Coastguard Worker // - Ternary operator has the same type as the operands 93*8975f5c5SAndroid Build Coastguard Worker // - Case expressions have the same type as the switch selector 94*8975f5c5SAndroid Build Coastguard Worker bool validateExpressionTypes = true; 95*8975f5c5SAndroid Build Coastguard Worker // If SeparateDeclarations has been run, check for the absence of multi declarations as well. 96*8975f5c5SAndroid Build Coastguard Worker bool validateMultiDeclarations = false; 97*8975f5c5SAndroid Build Coastguard Worker // If PruneNoOps has been run, check that no statements are ever added after branches in the 98*8975f5c5SAndroid Build Coastguard Worker // same block. Those statements would be dead code. 99*8975f5c5SAndroid Build Coastguard Worker bool validateNoStatementsAfterBranch = false; 100*8975f5c5SAndroid Build Coastguard Worker // Check that swizzle is not applied to swizzle. Swizzles of swizzles are folded in 101*8975f5c5SAndroid Build Coastguard Worker // TIntermSwizzle::fold. 102*8975f5c5SAndroid Build Coastguard Worker bool validateNoSwizzleOfSwizzle = true; 103*8975f5c5SAndroid Build Coastguard Worker // Check that constructors' types don't have qualifiers such as invariant, row_major etc. 104*8975f5c5SAndroid Build Coastguard Worker bool validateNoQualifiersOnConstructors = true; 105*8975f5c5SAndroid Build Coastguard Worker 106*8975f5c5SAndroid Build Coastguard Worker // Once set, disallows any further transformations on the tree. Used before AST post-processing 107*8975f5c5SAndroid Build Coastguard Worker // which requires that the tree remains unmodified. 108*8975f5c5SAndroid Build Coastguard Worker bool validateNoMoreTransformations = false; 109*8975f5c5SAndroid Build Coastguard Worker }; 110*8975f5c5SAndroid Build Coastguard Worker 111*8975f5c5SAndroid Build Coastguard Worker // Check for errors and output error messages on the context. 112*8975f5c5SAndroid Build Coastguard Worker // Returns true if there are no errors. 113*8975f5c5SAndroid Build Coastguard Worker bool ValidateAST(TIntermNode *root, TDiagnostics *diagnostics, const ValidateASTOptions &options); 114*8975f5c5SAndroid Build Coastguard Worker 115*8975f5c5SAndroid Build Coastguard Worker } // namespace sh 116*8975f5c5SAndroid Build Coastguard Worker 117*8975f5c5SAndroid Build Coastguard Worker #endif // COMPILER_TRANSLATOR_VALIDATESWITCH_H_ 118