• 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.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 IsGeometryShaderInput(GLenum shaderType, TQualifier qualifier);
58 InterpolationType GetInterpolationType(TQualifier qualifier);
59 
60 // Returns array brackets including size with outermost array size first, as specified in GLSL ES
61 // 3.10 section 4.1.9.
62 ImmutableString ArrayString(const TType &type);
63 
64 ImmutableString GetTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap);
65 
66 TType GetShaderVariableBasicType(const sh::ShaderVariable &var);
67 
68 void DeclareGlobalVariable(TIntermBlock *root, const TVariable *variable);
69 
70 bool IsBuiltinOutputVariable(TQualifier qualifier);
71 bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
72 bool CanBeInvariantESSL1(TQualifier qualifier);
73 bool CanBeInvariantESSL3OrGreater(TQualifier qualifier);
74 bool IsShaderOutput(TQualifier qualifier);
75 bool IsOutputESSL(ShShaderOutput output);
76 bool IsOutputGLSL(ShShaderOutput output);
77 bool IsOutputHLSL(ShShaderOutput output);
78 bool IsOutputVulkan(ShShaderOutput output);
79 bool IsOutputMetal(ShShaderOutput output);
80 
81 bool IsInShaderStorageBlock(TIntermTyped *node);
82 
83 GLenum GetImageInternalFormatType(TLayoutImageInternalFormat iifq);
84 // ESSL 1.00 shaders nest function body scope within function parameter scope
85 bool IsSpecWithFunctionBodyNewScope(ShShaderSpec shaderSpec, int shaderVersion);
86 
87 // Helper functions for implicit conversions
88 ImplicitTypeConversion GetConversion(TBasicType t1, TBasicType t2);
89 
90 bool IsValidImplicitConversion(ImplicitTypeConversion conversion, TOperator op);
91 }  // namespace sh
92 
93 #endif  // COMPILER_TRANSLATOR_UTIL_H_
94