• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Keeps track of whether an implicit conversion from int/uint to float is possible.
28 // These conversions are supported in desktop GLSL shaders only.
29 // Also keeps track of which side of operation should be converted.
30 enum class ImplicitTypeConversion
31 {
32     Same,
33     Left,
34     Right,
35     Invalid,
36 };
37 
38 class TIntermBlock;
39 class TIntermDeclaration;
40 class TSymbolTable;
41 class TIntermTyped;
42 
43 float NumericLexFloat32OutOfRangeToInfinity(const std::string &str);
44 
45 // strtof_clamp is like strtof but
46 //   1. it forces C locale, i.e. forcing '.' as decimal point.
47 //   2. it sets the value to infinity if overflow happens.
48 //   3. str should be guaranteed to be in the valid format for a floating point number as defined
49 //      by the grammar in the ESSL 3.00.6 spec section 4.1.4.
50 // Return false if overflow happens.
51 bool strtof_clamp(const std::string &str, float *value);
52 
53 GLenum GLVariableType(const TType &type);
54 GLenum GLVariablePrecision(const TType &type);
55 bool IsVaryingIn(TQualifier qualifier);
56 bool IsVaryingOut(TQualifier qualifier);
57 bool IsVarying(TQualifier qualifier);
58 bool IsMatrixGLType(GLenum type);
59 bool IsGeometryShaderInput(GLenum shaderType, TQualifier qualifier);
60 bool IsTessellationControlShaderInput(GLenum shaderType, TQualifier qualifier);
61 bool IsTessellationControlShaderOutput(GLenum shaderType, TQualifier qualifier);
62 bool IsTessellationEvaluationShaderInput(GLenum shaderType, TQualifier qualifier);
63 InterpolationType GetInterpolationType(TQualifier qualifier);
64 InterpolationType GetFieldInterpolationType(TQualifier qualifier);
65 
66 // Returns array brackets including size with outermost array size first, as specified in GLSL ES
67 // 3.10 section 4.1.9.
68 ImmutableString ArrayString(const TType &type);
69 
70 ImmutableString GetTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap);
71 
72 TType GetShaderVariableBasicType(const sh::ShaderVariable &var);
73 
74 void DeclareGlobalVariable(TIntermBlock *root, const TVariable *variable);
75 
76 bool IsBuiltinOutputVariable(TQualifier qualifier);
77 bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
78 bool CanBeInvariantESSL1(TQualifier qualifier);
79 bool CanBeInvariantESSL3OrGreater(TQualifier qualifier);
80 bool IsShaderOutput(TQualifier qualifier);
81 bool IsFragmentOutput(TQualifier qualifier);
82 bool IsOutputESSL(ShShaderOutput output);
83 bool IsOutputGLSL(ShShaderOutput output);
84 bool IsOutputHLSL(ShShaderOutput output);
85 bool IsOutputSPIRV(ShShaderOutput output);
86 bool IsOutputMSL(ShShaderOutput output);
87 bool IsOutputWGSL(ShShaderOutput output);
88 
89 bool IsInShaderStorageBlock(TIntermTyped *node);
90 
91 GLenum GetImageInternalFormatType(TLayoutImageInternalFormat iifq);
92 // ESSL 1.00 shaders nest function body scope within function parameter scope
93 bool IsSpecWithFunctionBodyNewScope(ShShaderSpec shaderSpec, int shaderVersion);
94 
95 // Helper functions for implicit conversions
96 ImplicitTypeConversion GetConversion(TBasicType t1, TBasicType t2);
97 
98 bool IsValidImplicitConversion(ImplicitTypeConversion conversion, TOperator op);
99 
100 // Whether the given basic type requires precision.
101 bool IsPrecisionApplicableToType(TBasicType type);
102 
103 // Whether this is the name of a built-in that can be redeclared by the shader.
104 bool IsRedeclarableBuiltIn(const ImmutableString &name);
105 
106 size_t FindFieldIndex(const TFieldList &fieldList, const char *fieldName);
107 
108 // A convenience view of a TIntermDeclaration node's children.
109 struct Declaration
110 {
111     TIntermSymbol &symbol;
112     TIntermTyped *initExpr;  // Non-null iff declaration is initialized.
113 };
114 
115 // Returns a `Declaration` view of the given node, for declarator `index` of
116 // the declarations in `declNode`.
117 Declaration ViewDeclaration(TIntermDeclaration &declNode, uint32_t index = 0);
118 
119 }  // namespace sh
120 
121 #endif  // COMPILER_TRANSLATOR_UTIL_H_
122