zenilib: zenilib/jni/external/angle/src/compiler/ShHandle.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ShHandle.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2012 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 _SHHANDLE_INCLUDED_
8 #define _SHHANDLE_INCLUDED_
9
10 //
11 // Machine independent part of the compiler private objects
12 // sent as ShHandle to the driver.
13 //
14 // This should not be included by driver code.
15 //
16
17 #include "GLSLANG/ShaderLang.h"
18
19 #include "compiler/BuiltInFunctionEmulator.h"
20 #include "compiler/ExtensionBehavior.h"
21 #include "compiler/HashNames.h"
22 #include "compiler/InfoSink.h"
23 #include "compiler/SymbolTable.h"
24 #include "compiler/VariableInfo.h"
25 #include "third_party/compiler/ArrayBoundsClamper.h"
26
27 class LongNameMap;
28 class TCompiler;
29 class TDependencyGraph;
30 class TranslatorHLSL;
31
32 //
33 // Helper function to identify specs that are based on the WebGL spec,
34 // like the CSS Shaders spec.
35 //
36 bool isWebGLBasedSpec(ShShaderSpec spec);
37
38 //
39 // The base class used to back handles returned to the driver.
40 //
41 class TShHandleBase {
42 public:
43 TShHandleBase();
44 virtual ~TShHandleBase();
45 virtual TCompiler* getAsCompiler() { return 0; }
46 virtual TranslatorHLSL* getAsTranslatorHLSL() { return 0; }
47
48 protected:
49 // Memory allocator. Allocates and tracks memory required by the compiler.
50 // Deallocates all memory when compiler is destructed.
51 TPoolAllocator allocator;
52 };
53
54 //
55 // The base class for the machine dependent compiler to derive from
56 // for managing object code from the compile.
57 //
58 class TCompiler : public TShHandleBase {
59 public:
60 TCompiler(ShShaderType type, ShShaderSpec spec);
61 virtual ~TCompiler();
62 virtual TCompiler* getAsCompiler() { return this; }
63
64 bool Init(const ShBuiltInResources& resources);
65 bool compile(const char* const shaderStrings[],
66 size_t numStrings,
67 int compileOptions);
68
69 // Get results of the last compilation.
70 TInfoSink& getInfoSink() { return infoSink; }
71 const TVariableInfoList& getAttribs() const { return attribs; }
72 const TVariableInfoList& getUniforms() const { return uniforms; }
73 int getMappedNameMaxLength() const;
74
75 ShHashFunction64 getHashFunction() const { return hashFunction; }
76 NameMap& getNameMap() { return nameMap; }
77 TSymbolTable& getSymbolTable() { return symbolTable; }
78
79 protected:
80 ShShaderType getShaderType() const { return shaderType; }
81 ShShaderSpec getShaderSpec() const { return shaderSpec; }
82 // Initialize symbol-table with built-in symbols.
83 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
84 // Clears the results from the previous compilation.
85 void clearResults();
86 // Return true if function recursion is detected or call depth exceeded.
87 bool detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth);
88 // Rewrites a shader's intermediate tree according to the CSS Shaders spec.
89 void rewriteCSSShader(TIntermNode* root);
90 // Returns true if the given shader does not exceed the minimum
91 // functionality mandated in GLSL 1.0 spec Appendix A.
92 bool validateLimitations(TIntermNode* root);
93 // Collect info for all attribs and uniforms.
94 void collectAttribsUniforms(TIntermNode* root);
95 // Map long variable names into shorter ones.
96 void mapLongVariableNames(TIntermNode* root);
97 // Translate to object code.
98 virtual void translate(TIntermNode* root) = 0;
99 // Returns true if, after applying the packing rules in the GLSL 1.017 spec
100 // Appendix A, section 7, the shader does not use too many uniforms.
101 bool enforcePackingRestrictions();
102 // Returns true if the shader passes the restrictions that aim to prevent timing attacks.
103 bool enforceTimingRestrictions(TIntermNode* root, bool outputGraph);
104 // Returns true if the shader does not use samplers.
105 bool enforceVertexShaderTimingRestrictions(TIntermNode* root);
106 // Returns true if the shader does not use sampler dependent values to affect control
107 // flow or in operations whose time can depend on the input values.
108 bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph);
109 // Return true if the maximum expression complexity below the limit.
110 bool limitExpressionComplexity(TIntermNode* root);
111 // Get built-in extensions with default behavior.
112 const TExtensionBehavior& getExtensionBehavior() const;
113 // Get the resources set by InitBuiltInSymbolTable
114 const ShBuiltInResources& getResources() const;
115
116 const ArrayBoundsClamper& getArrayBoundsClamper() const;
117 ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const;
118 const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const;
119
120 private:
121 ShShaderType shaderType;
122 ShShaderSpec shaderSpec;
123
124 int maxUniformVectors;
125 int maxExpressionComplexity;
126 int maxCallStackDepth;
127
128 ShBuiltInResources compileResources;
129
130 // Built-in symbol table for the given language, spec, and resources.
131 // It is preserved from compile-to-compile.
132 TSymbolTable symbolTable;
133 // Built-in extensions with default behavior.
134 TExtensionBehavior extensionBehavior;
135 bool fragmentPrecisionHigh;
136
137 ArrayBoundsClamper arrayBoundsClamper;
138 ShArrayIndexClampingStrategy clampingStrategy;
139 BuiltInFunctionEmulator builtInFunctionEmulator;
140
141 // Results of compilation.
142 TInfoSink infoSink; // Output sink.
143 TVariableInfoList attribs; // Active attributes in the compiled shader.
144 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
145
146 // Cached copy of the ref-counted singleton.
147 LongNameMap* longNameMap;
148
149 // name hashing.
150 ShHashFunction64 hashFunction;
151 NameMap nameMap;
152 };
153
154 //
155 // This is the interface between the machine independent code
156 // and the machine dependent code.
157 //
158 // The machine dependent code should derive from the classes
159 // above. Then Construct*() and Delete*() will create and
160 // destroy the machine dependent objects, which contain the
161 // above machine independent information.
162 //
163 TCompiler* ConstructCompiler(
164 ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
165 void DeleteCompiler(TCompiler*);
166
167 #endif // _SHHANDLE_INCLUDED_
TCompiler::getSymbolTable
TSymbolTable & getSymbolTable()
Definition: ShHandle.h:77
TCompiler::TCompiler
TCompiler(ShShaderType type, ShShaderSpec spec)
Definition: Compiler.cpp:58
TCompiler::Init
bool Init(const ShBuiltInResources &resources)
Definition: Compiler.cpp:77
TCompiler::translate
virtual void translate(TIntermNode *root)=0
TShHandleBase::getAsTranslatorHLSL
virtual TranslatorHLSL * getAsTranslatorHLSL()
Definition: ShHandle.h:46
TCompiler::validateLimitations
bool validateLimitations(TIntermNode *root)
Definition: Compiler.cpp:293
TCompiler::enforceVertexShaderTimingRestrictions
bool enforceVertexShaderTimingRestrictions(TIntermNode *root)
Definition: Compiler.cpp:354
TExtensionBehavior
std::map< std::string, TBehavior > TExtensionBehavior
Definition: ExtensionBehavior.h:35
TShHandleBase::allocator
TPoolAllocator allocator
Definition: ShHandle.h:51
type
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
TShHandleBase::TShHandleBase
TShHandleBase()
Definition: Compiler.cpp:48
TCompiler::enforceTimingRestrictions
bool enforceTimingRestrictions(TIntermNode *root, bool outputGraph)
Definition: Compiler.cpp:299
TCompiler::getMappedNameMaxLength
int getMappedNameMaxLength() const
Definition: Compiler.cpp:380
ShHashFunction64
khronos_uint64_t(* ShHashFunction64)(const char *, size_t)
Definition: ShaderLang.h:197
TCompiler::getShaderType
ShShaderType getShaderType() const
Definition: ShHandle.h:80
TSymbolTable
Definition: SymbolTable.h:237
ArrayBoundsClamper.h
ShaderLang.h
ArrayBoundsClamper
Definition: ArrayBoundsClamper.h:34
NameMap
std::map< TPersistString, TPersistString > NameMap
Definition: HashNames.h:17
TCompiler::getBuiltInFunctionEmulator
const BuiltInFunctionEmulator & getBuiltInFunctionEmulator() const
Definition: Compiler.cpp:405
TShHandleBase::getAsCompiler
virtual TCompiler * getAsCompiler()
Definition: ShHandle.h:45
LongNameMap
Definition: MapLongVariableNames.h:21
TCompiler::enforcePackingRestrictions
bool enforcePackingRestrictions()
Definition: Compiler.cpp:367
TCompiler::~TCompiler
virtual ~TCompiler()
Definition: Compiler.cpp:71
TranslatorHLSL
Definition: TranslatorHLSL.h:13
TCompiler::getArrayBoundsClamper
const ArrayBoundsClamper & getArrayBoundsClamper() const
Definition: Compiler.cpp:395
TCompiler::clearResults
void clearResults()
Definition: Compiler.cpp:247
attribs
const GLint * attribs
Definition: glew.h:13064
TCompiler::getInfoSink
TInfoSink & getInfoSink()
Definition: ShHandle.h:70
TCompiler::collectAttribsUniforms
void collectAttribsUniforms(TIntermNode *root)
Definition: Compiler.cpp:361
ShArrayIndexClampingStrategy
ShArrayIndexClampingStrategy
Definition: ShaderLang.h:175
VariableInfo.h
TCompiler::getHashFunction
ShHashFunction64 getHashFunction() const
Definition: ShHandle.h:75
isWebGLBasedSpec
bool isWebGLBasedSpec(ShShaderSpec spec)
Definition: Compiler.cpp:24
TCompiler::getArrayIndexClampingStrategy
ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const
Definition: Compiler.cpp:400
BuiltInFunctionEmulator
Definition: BuiltInFunctionEmulator.h:20
TShHandleBase
Definition: ShHandle.h:41
ConstructCompiler
TCompiler * ConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output)
Definition: CodeGen.cpp:16
TCompiler::InitBuiltInSymbolTable
bool InitBuiltInSymbolTable(const ShBuiltInResources &resources)
Definition: Compiler.cpp:209
TCompiler::rewriteCSSShader
void rewriteCSSShader(TIntermNode *root)
Definition: Compiler.cpp:287
TCompiler::limitExpressionComplexity
bool limitExpressionComplexity(TIntermNode *root)
Definition: Compiler.cpp:325
TCompiler::mapLongVariableNames
void mapLongVariableNames(TIntermNode *root)
Definition: Compiler.cpp:373
TPoolAllocator
Definition: PoolAlloc.h:116
TDependencyGraph
Definition: DependencyGraph.h:139
HashNames.h
TCompiler::getExtensionBehavior
const TExtensionBehavior & getExtensionBehavior() const
Definition: Compiler.cpp:385
DeleteCompiler
void DeleteCompiler(TCompiler *compiler)
Definition: CodeGen.cpp:36
TCompiler::getAsCompiler
virtual TCompiler * getAsCompiler()
Definition: ShHandle.h:62
sort_controllers.output
tuple output
Definition: sort_controllers.py:10
ShBuiltInResources
Definition: ShaderLang.h:203
TCompiler
Definition: ShHandle.h:58
ExtensionBehavior.h
TCompiler::getShaderSpec
ShShaderSpec getShaderSpec() const
Definition: ShHandle.h:81
ShShaderType
ShShaderType
Definition: ShaderLang.h:48
TIntermNode
Definition: intermediate.h:206
InfoSink.h
TCompiler::getResources
const ShBuiltInResources & getResources() const
Definition: Compiler.cpp:390
TVariableInfoList
std::vector< TVariableInfo > TVariableInfoList
Definition: VariableInfo.h:24
SymbolTable.h
ShShaderOutput
ShShaderOutput
Definition: ShaderLang.h:80
ShShaderSpec
ShShaderSpec
Definition: ShaderLang.h:53
TShHandleBase::~TShHandleBase
virtual ~TShHandleBase()
Definition: Compiler.cpp:53
TCompiler::enforceFragmentShaderTimingRestrictions
bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph &graph)
Definition: Compiler.cpp:347
TCompiler::getUniforms
const TVariableInfoList & getUniforms() const
Definition: ShHandle.h:72
TCompiler::compile
bool compile(const char *const shaderStrings[], size_t numStrings, int compileOptions)
Definition: Compiler.cpp:100
TCompiler::detectCallDepth
bool detectCallDepth(TIntermNode *root, TInfoSink &infoSink, bool limitCallStackDepth)
Definition: Compiler.cpp:262
TCompiler::getAttribs
const TVariableInfoList & getAttribs() const
Definition: ShHandle.h:71
TCompiler::getNameMap
NameMap & getNameMap()
Definition: ShHandle.h:76
TInfoSink
Definition: InfoSink.h:108
BuiltInFunctionEmulator.h