1*8975f5c5SAndroid Build Coastguard Worker // 2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2002 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_UTIL_H_ 8*8975f5c5SAndroid Build Coastguard Worker #define COMPILER_TRANSLATOR_UTIL_H_ 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Worker #include <stack> 11*8975f5c5SAndroid Build Coastguard Worker 12*8975f5c5SAndroid Build Coastguard Worker #include <GLSLANG/ShaderLang.h> 13*8975f5c5SAndroid Build Coastguard Worker #include "angle_gl.h" 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/HashNames.h" 16*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/ImmutableString.h" 17*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/Operator_autogen.h" 18*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/Types.h" 19*8975f5c5SAndroid Build Coastguard Worker 20*8975f5c5SAndroid Build Coastguard Worker // If overflow happens, clamp the value to UINT_MIN or UINT_MAX. 21*8975f5c5SAndroid Build Coastguard Worker // Return false if overflow happens. 22*8975f5c5SAndroid Build Coastguard Worker bool atoi_clamp(const char *str, unsigned int *value); 23*8975f5c5SAndroid Build Coastguard Worker 24*8975f5c5SAndroid Build Coastguard Worker namespace sh 25*8975f5c5SAndroid Build Coastguard Worker { 26*8975f5c5SAndroid Build Coastguard Worker 27*8975f5c5SAndroid Build Coastguard Worker class TIntermBlock; 28*8975f5c5SAndroid Build Coastguard Worker class TIntermDeclaration; 29*8975f5c5SAndroid Build Coastguard Worker class TSymbolTable; 30*8975f5c5SAndroid Build Coastguard Worker class TIntermTyped; 31*8975f5c5SAndroid Build Coastguard Worker 32*8975f5c5SAndroid Build Coastguard Worker float NumericLexFloat32OutOfRangeToInfinity(const std::string &str); 33*8975f5c5SAndroid Build Coastguard Worker 34*8975f5c5SAndroid Build Coastguard Worker // strtof_clamp is like strtof but 35*8975f5c5SAndroid Build Coastguard Worker // 1. it forces C locale, i.e. forcing '.' as decimal point. 36*8975f5c5SAndroid Build Coastguard Worker // 2. it sets the value to infinity if overflow happens. 37*8975f5c5SAndroid Build Coastguard Worker // 3. str should be guaranteed to be in the valid format for a floating point number as defined 38*8975f5c5SAndroid Build Coastguard Worker // by the grammar in the ESSL 3.00.6 spec section 4.1.4. 39*8975f5c5SAndroid Build Coastguard Worker // Return false if overflow happens. 40*8975f5c5SAndroid Build Coastguard Worker bool strtof_clamp(const std::string &str, float *value); 41*8975f5c5SAndroid Build Coastguard Worker 42*8975f5c5SAndroid Build Coastguard Worker GLenum GLVariableType(const TType &type); 43*8975f5c5SAndroid Build Coastguard Worker GLenum GLVariablePrecision(const TType &type); 44*8975f5c5SAndroid Build Coastguard Worker bool IsVaryingIn(TQualifier qualifier); 45*8975f5c5SAndroid Build Coastguard Worker bool IsVaryingOut(TQualifier qualifier); 46*8975f5c5SAndroid Build Coastguard Worker bool IsVarying(TQualifier qualifier); 47*8975f5c5SAndroid Build Coastguard Worker bool IsMatrixGLType(GLenum type); 48*8975f5c5SAndroid Build Coastguard Worker bool IsGeometryShaderInput(GLenum shaderType, TQualifier qualifier); 49*8975f5c5SAndroid Build Coastguard Worker bool IsTessellationControlShaderInput(GLenum shaderType, TQualifier qualifier); 50*8975f5c5SAndroid Build Coastguard Worker bool IsTessellationControlShaderOutput(GLenum shaderType, TQualifier qualifier); 51*8975f5c5SAndroid Build Coastguard Worker bool IsTessellationEvaluationShaderInput(GLenum shaderType, TQualifier qualifier); 52*8975f5c5SAndroid Build Coastguard Worker InterpolationType GetInterpolationType(TQualifier qualifier); 53*8975f5c5SAndroid Build Coastguard Worker InterpolationType GetFieldInterpolationType(TQualifier qualifier); 54*8975f5c5SAndroid Build Coastguard Worker 55*8975f5c5SAndroid Build Coastguard Worker // Returns array brackets including size with outermost array size first, as specified in GLSL ES 56*8975f5c5SAndroid Build Coastguard Worker // 3.10 section 4.1.9. 57*8975f5c5SAndroid Build Coastguard Worker ImmutableString ArrayString(const TType &type); 58*8975f5c5SAndroid Build Coastguard Worker 59*8975f5c5SAndroid Build Coastguard Worker ImmutableString GetTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap); 60*8975f5c5SAndroid Build Coastguard Worker 61*8975f5c5SAndroid Build Coastguard Worker TType GetShaderVariableBasicType(const sh::ShaderVariable &var); 62*8975f5c5SAndroid Build Coastguard Worker 63*8975f5c5SAndroid Build Coastguard Worker void DeclareGlobalVariable(TIntermBlock *root, const TVariable *variable); 64*8975f5c5SAndroid Build Coastguard Worker 65*8975f5c5SAndroid Build Coastguard Worker bool IsBuiltinOutputVariable(TQualifier qualifier); 66*8975f5c5SAndroid Build Coastguard Worker bool IsBuiltinFragmentInputVariable(TQualifier qualifier); 67*8975f5c5SAndroid Build Coastguard Worker bool CanBeInvariantESSL1(TQualifier qualifier); 68*8975f5c5SAndroid Build Coastguard Worker bool CanBeInvariantESSL3OrGreater(TQualifier qualifier); 69*8975f5c5SAndroid Build Coastguard Worker bool IsShaderOutput(TQualifier qualifier); 70*8975f5c5SAndroid Build Coastguard Worker bool IsFragmentOutput(TQualifier qualifier); 71*8975f5c5SAndroid Build Coastguard Worker bool IsOutputNULL(ShShaderOutput output); 72*8975f5c5SAndroid Build Coastguard Worker bool IsOutputESSL(ShShaderOutput output); 73*8975f5c5SAndroid Build Coastguard Worker bool IsOutputGLSL(ShShaderOutput output); 74*8975f5c5SAndroid Build Coastguard Worker bool IsOutputHLSL(ShShaderOutput output); 75*8975f5c5SAndroid Build Coastguard Worker bool IsOutputSPIRV(ShShaderOutput output); 76*8975f5c5SAndroid Build Coastguard Worker bool IsOutputMSL(ShShaderOutput output); 77*8975f5c5SAndroid Build Coastguard Worker bool IsOutputWGSL(ShShaderOutput output); 78*8975f5c5SAndroid Build Coastguard Worker 79*8975f5c5SAndroid Build Coastguard Worker bool IsInShaderStorageBlock(TIntermTyped *node); 80*8975f5c5SAndroid Build Coastguard Worker 81*8975f5c5SAndroid Build Coastguard Worker GLenum GetImageInternalFormatType(TLayoutImageInternalFormat iifq); 82*8975f5c5SAndroid Build Coastguard Worker // ESSL 1.00 shaders nest function body scope within function parameter scope 83*8975f5c5SAndroid Build Coastguard Worker bool IsSpecWithFunctionBodyNewScope(ShShaderSpec shaderSpec, int shaderVersion); 84*8975f5c5SAndroid Build Coastguard Worker 85*8975f5c5SAndroid Build Coastguard Worker // Whether the given basic type requires precision. 86*8975f5c5SAndroid Build Coastguard Worker bool IsPrecisionApplicableToType(TBasicType type); 87*8975f5c5SAndroid Build Coastguard Worker 88*8975f5c5SAndroid Build Coastguard Worker // Whether this is the name of a built-in that can be redeclared by the shader. 89*8975f5c5SAndroid Build Coastguard Worker bool IsRedeclarableBuiltIn(const ImmutableString &name); 90*8975f5c5SAndroid Build Coastguard Worker 91*8975f5c5SAndroid Build Coastguard Worker size_t FindFieldIndex(const TFieldList &fieldList, const char *fieldName); 92*8975f5c5SAndroid Build Coastguard Worker 93*8975f5c5SAndroid Build Coastguard Worker // A convenience view of a TIntermDeclaration node's children. 94*8975f5c5SAndroid Build Coastguard Worker struct Declaration 95*8975f5c5SAndroid Build Coastguard Worker { 96*8975f5c5SAndroid Build Coastguard Worker TIntermSymbol &symbol; 97*8975f5c5SAndroid Build Coastguard Worker TIntermTyped *initExpr; // Non-null iff declaration is initialized. 98*8975f5c5SAndroid Build Coastguard Worker }; 99*8975f5c5SAndroid Build Coastguard Worker 100*8975f5c5SAndroid Build Coastguard Worker // Returns a `Declaration` view of the given node, for declarator `index` of 101*8975f5c5SAndroid Build Coastguard Worker // the declarations in `declNode`. 102*8975f5c5SAndroid Build Coastguard Worker Declaration ViewDeclaration(TIntermDeclaration &declNode, uint32_t index = 0); 103*8975f5c5SAndroid Build Coastguard Worker 104*8975f5c5SAndroid Build Coastguard Worker } // namespace sh 105*8975f5c5SAndroid Build Coastguard Worker 106*8975f5c5SAndroid Build Coastguard Worker #endif // COMPILER_TRANSLATOR_UTIL_H_ 107