• 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 TSymbolTable;
40 class TIntermTyped;
41 
42 float NumericLexFloat32OutOfRangeToInfinity(const std::string &str);
43 
44 // strtof_clamp is like strtof but
45 //   1. it forces C locale, i.e. forcing '.' as decimal point.
46 //   2. it sets the value to infinity if overflow happens.
47 //   3. str should be guaranteed to be in the valid format for a floating point number as defined
48 //      by the grammar in the ESSL 3.00.6 spec section 4.1.4.
49 // Return false if overflow happens.
50 bool strtof_clamp(const std::string &str, float *value);
51 
52 GLenum GLVariableType(const TType &type);
53 GLenum GLVariablePrecision(const TType &type);
54 bool IsVaryingIn(TQualifier qualifier);
55 bool IsVaryingOut(TQualifier qualifier);
56 bool IsVarying(TQualifier qualifier);
57 bool IsMatrixGLType(GLenum type);
58 bool IsGeometryShaderInput(GLenum shaderType, TQualifier qualifier);
59 bool IsTessellationControlShaderInput(GLenum shaderType, TQualifier qualifier);
60 bool IsTessellationControlShaderOutput(GLenum shaderType, TQualifier qualifier);
61 bool IsTessellationEvaluationShaderInput(GLenum shaderType, TQualifier qualifier);
62 InterpolationType GetInterpolationType(TQualifier qualifier);
63 InterpolationType GetFieldInterpolationType(TQualifier qualifier);
64 
65 // Returns array brackets including size with outermost array size first, as specified in GLSL ES
66 // 3.10 section 4.1.9.
67 ImmutableString ArrayString(const TType &type);
68 
69 ImmutableString GetTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap);
70 
71 TType GetShaderVariableBasicType(const sh::ShaderVariable &var);
72 
73 void DeclareGlobalVariable(TIntermBlock *root, const TVariable *variable);
74 
75 bool IsBuiltinOutputVariable(TQualifier qualifier);
76 bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
77 bool CanBeInvariantESSL1(TQualifier qualifier);
78 bool CanBeInvariantESSL3OrGreater(TQualifier qualifier);
79 bool IsShaderOutput(TQualifier qualifier);
80 bool IsOutputESSL(ShShaderOutput output);
81 bool IsOutputGLSL(ShShaderOutput output);
82 bool IsOutputHLSL(ShShaderOutput output);
83 bool IsOutputVulkan(ShShaderOutput output);
84 bool IsOutputMetal(ShShaderOutput output);
85 bool IsOutputMetalDirect(ShShaderOutput output);
86 
87 bool IsInShaderStorageBlock(TIntermTyped *node);
88 
89 GLenum GetImageInternalFormatType(TLayoutImageInternalFormat iifq);
90 // ESSL 1.00 shaders nest function body scope within function parameter scope
91 bool IsSpecWithFunctionBodyNewScope(ShShaderSpec shaderSpec, int shaderVersion);
92 
93 // Helper functions for implicit conversions
94 ImplicitTypeConversion GetConversion(TBasicType t1, TBasicType t2);
95 
96 bool IsValidImplicitConversion(ImplicitTypeConversion conversion, TOperator op);
97 
98 size_t FindFieldIndex(const TFieldList &fieldList, const char *fieldName);
99 }  // namespace sh
100 
101 #endif  // COMPILER_TRANSLATOR_UTIL_H_
102