zenilib  0.5.3.0
 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 
21 #include "compiler/HashNames.h"
22 #include "compiler/InfoSink.h"
23 #include "compiler/SymbolTable.h"
24 #include "compiler/VariableInfo.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 //
37 
38 //
39 // The base class used to back handles returned to the driver.
40 //
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.
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:
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.
95  // Map long variable names into shorter ones.
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.
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.
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.
109  // Return true if the maximum expression complexity below the limit.
111  // Get built-in extensions with default behavior.
113  // Get the resources set by InitBuiltInSymbolTable
114  const ShBuiltInResources& getResources() const;
115 
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 //
166 
167 #endif // _SHHANDLE_INCLUDED_
TSymbolTable & getSymbolTable()
Definition: ShHandle.h:77
TCompiler(ShShaderType type, ShShaderSpec spec)
Definition: Compiler.cpp:58
bool Init(const ShBuiltInResources &resources)
Definition: Compiler.cpp:77
virtual void translate(TIntermNode *root)=0
virtual TranslatorHLSL * getAsTranslatorHLSL()
Definition: ShHandle.h:46
bool validateLimitations(TIntermNode *root)
Definition: Compiler.cpp:293
bool enforceVertexShaderTimingRestrictions(TIntermNode *root)
Definition: Compiler.cpp:354
std::map< std::string, TBehavior > TExtensionBehavior
TPoolAllocator allocator
Definition: ShHandle.h:51
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
bool enforceTimingRestrictions(TIntermNode *root, bool outputGraph)
Definition: Compiler.cpp:299
int getMappedNameMaxLength() const
Definition: Compiler.cpp:380
khronos_uint64_t(* ShHashFunction64)(const char *, size_t)
Definition: ShaderLang.h:197
ShShaderType getShaderType() const
Definition: ShHandle.h:80
std::map< TPersistString, TPersistString > NameMap
Definition: HashNames.h:17
const BuiltInFunctionEmulator & getBuiltInFunctionEmulator() const
Definition: Compiler.cpp:405
virtual TCompiler * getAsCompiler()
Definition: ShHandle.h:45
bool enforcePackingRestrictions()
Definition: Compiler.cpp:367
virtual ~TCompiler()
Definition: Compiler.cpp:71
const ArrayBoundsClamper & getArrayBoundsClamper() const
Definition: Compiler.cpp:395
void clearResults()
Definition: Compiler.cpp:247
const GLint * attribs
Definition: glew.h:13064
TInfoSink & getInfoSink()
Definition: ShHandle.h:70
void collectAttribsUniforms(TIntermNode *root)
Definition: Compiler.cpp:361
ShArrayIndexClampingStrategy
Definition: ShaderLang.h:175
ShHashFunction64 getHashFunction() const
Definition: ShHandle.h:75
bool isWebGLBasedSpec(ShShaderSpec spec)
Definition: Compiler.cpp:24
ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const
Definition: Compiler.cpp:400
TCompiler * ConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output)
Definition: CodeGen.cpp:16
bool InitBuiltInSymbolTable(const ShBuiltInResources &resources)
Definition: Compiler.cpp:209
void rewriteCSSShader(TIntermNode *root)
Definition: Compiler.cpp:287
bool limitExpressionComplexity(TIntermNode *root)
Definition: Compiler.cpp:325
void mapLongVariableNames(TIntermNode *root)
Definition: Compiler.cpp:373
const TExtensionBehavior & getExtensionBehavior() const
Definition: Compiler.cpp:385
void DeleteCompiler(TCompiler *compiler)
Definition: CodeGen.cpp:36
virtual TCompiler * getAsCompiler()
Definition: ShHandle.h:62
ShShaderSpec getShaderSpec() const
Definition: ShHandle.h:81
ShShaderType
Definition: ShaderLang.h:48
const ShBuiltInResources & getResources() const
Definition: Compiler.cpp:390
std::vector< TVariableInfo > TVariableInfoList
Definition: VariableInfo.h:24
ShShaderOutput
Definition: ShaderLang.h:80
ShShaderSpec
Definition: ShaderLang.h:53
virtual ~TShHandleBase()
Definition: Compiler.cpp:53
bool enforceFragmentShaderTimingRestrictions(const TDependencyGraph &graph)
Definition: Compiler.cpp:347
const TVariableInfoList & getUniforms() const
Definition: ShHandle.h:72
bool compile(const char *const shaderStrings[], size_t numStrings, int compileOptions)
Definition: Compiler.cpp:100
bool detectCallDepth(TIntermNode *root, TInfoSink &infoSink, bool limitCallStackDepth)
Definition: Compiler.cpp:262
const TVariableInfoList & getAttribs() const
Definition: ShHandle.h:71
NameMap & getNameMap()
Definition: ShHandle.h:76