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