2 // Copyright (c) 2002-2010 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.
7 #ifndef _SHHANDLE_INCLUDED_
8 #define _SHHANDLE_INCLUDED_
11 // Machine independent part of the compiler private objects
12 // sent as ShHandle to the driver.
14 // This should not be included by driver code.
17 #include "GLSLANG/ShaderLang.h"
19 #include "compiler/ExtensionBehavior.h"
20 #include "compiler/InfoSink.h"
21 #include "compiler/SymbolTable.h"
22 #include "compiler/VariableInfo.h"
27 // The base class used to back handles returned to the driver.
32 virtual ~TShHandleBase();
33 virtual TCompiler* getAsCompiler() { return 0; }
36 // Memory allocator. Allocates and tracks memory required by the compiler.
37 // Deallocates all memory when compiler is destructed.
38 TPoolAllocator allocator;
42 // The base class for the machine dependent compiler to derive from
43 // for managing object code from the compile.
45 class TCompiler : public TShHandleBase {
47 TCompiler(ShShaderType type, ShShaderSpec spec);
49 virtual TCompiler* getAsCompiler() { return this; }
51 bool Init(const ShBuiltInResources& resources);
52 bool compile(const char* const shaderStrings[],
56 // Get results of the last compilation.
57 TInfoSink& getInfoSink() { return infoSink; }
58 const TVariableInfoList& getAttribs() const { return attribs; }
59 const TVariableInfoList& getUniforms() const { return uniforms; }
60 int getMappedNameMaxLength() const;
63 ShShaderType getShaderType() const { return shaderType; }
64 ShShaderSpec getShaderSpec() const { return shaderSpec; }
65 // Initialize symbol-table with built-in symbols.
66 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
67 // Clears the results from the previous compilation.
69 // Returns true if the given shader does not exceed the minimum
70 // functionality mandated in GLSL 1.0 spec Appendix A.
71 bool validateLimitations(TIntermNode* root);
72 // Collect info for all attribs and uniforms.
73 void collectAttribsUniforms(TIntermNode* root);
74 // Map long variable names into shorter ones.
75 void mapLongVariableNames(TIntermNode* root);
76 // Translate to object code.
77 virtual void translate(TIntermNode* root) = 0;
78 // Get built-in extensions with default behavior.
79 const TExtensionBehavior& getExtensionBehavior() const;
82 ShShaderType shaderType;
83 ShShaderSpec shaderSpec;
85 // Built-in symbol table for the given language, spec, and resources.
86 // It is preserved from compile-to-compile.
87 TSymbolTable symbolTable;
88 // Built-in extensions with default behavior.
89 TExtensionBehavior extensionBehavior;
91 // Results of compilation.
92 TInfoSink infoSink; // Output sink.
93 TVariableInfoList attribs; // Active attributes in the compiled shader.
94 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
96 // Pair of long varying varibale name <originalName, mappedName>.
97 TMap<TString, TString> varyingLongNameMap;
101 // This is the interface between the machine independent code
102 // and the machine dependent code.
104 // The machine dependent code should derive from the classes
105 // above. Then Construct*() and Delete*() will create and
106 // destroy the machine dependent objects, which contain the
107 // above machine independent information.
109 TCompiler* ConstructCompiler(
110 ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
111 void DeleteCompiler(TCompiler*);
113 #endif // _SHHANDLE_INCLUDED_