John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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/ExtensionBehavior.h" |
| 20 | #include "compiler/InfoSink.h" |
| 21 | #include "compiler/SymbolTable.h" |
| 22 | #include "compiler/VariableInfo.h" |
| 23 | |
| 24 | class TCompiler; |
| 25 | |
| 26 | // |
| 27 | // The base class used to back handles returned to the driver. |
| 28 | // |
| 29 | class TShHandleBase { |
| 30 | public: |
| 31 | TShHandleBase(); |
| 32 | virtual ~TShHandleBase(); |
| 33 | virtual TCompiler* getAsCompiler() { return 0; } |
| 34 | |
| 35 | protected: |
| 36 | // Memory allocator. Allocates and tracks memory required by the compiler. |
| 37 | // Deallocates all memory when compiler is destructed. |
| 38 | TPoolAllocator allocator; |
| 39 | }; |
| 40 | |
| 41 | // |
| 42 | // The base class for the machine dependent compiler to derive from |
| 43 | // for managing object code from the compile. |
| 44 | // |
| 45 | class TCompiler : public TShHandleBase { |
| 46 | public: |
| 47 | TCompiler(ShShaderType type, ShShaderSpec spec); |
| 48 | virtual ~TCompiler(); |
| 49 | virtual TCompiler* getAsCompiler() { return this; } |
| 50 | |
| 51 | bool Init(const ShBuiltInResources& resources); |
| 52 | bool compile(const char* const shaderStrings[], |
| 53 | const int numStrings, |
| 54 | int compileOptions); |
| 55 | |
| 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 | |
| 61 | protected: |
| 62 | ShShaderType getShaderType() const { return shaderType; } |
| 63 | ShShaderSpec getShaderSpec() const { return shaderSpec; } |
| 64 | // Initialize symbol-table with built-in symbols. |
| 65 | bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); |
| 66 | // Clears the results from the previous compilation. |
| 67 | void clearResults(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 68 | // Return true if function recursion is detected or call depth exceeded. |
| 69 | bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 70 | // Returns true if the given shader does not exceed the minimum |
| 71 | // functionality mandated in GLSL 1.0 spec Appendix A. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 72 | bool validateLimitations(TIntermNode *root); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 73 | // Collect info for all attribs and uniforms. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 74 | void collectAttribsUniforms(TIntermNode *root); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 75 | // Translate to object code. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 76 | virtual void translate(TIntermNode *root) = 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 77 | // Get built-in extensions with default behavior. |
| 78 | const TExtensionBehavior& getExtensionBehavior() const; |
| 79 | |
| 80 | private: |
| 81 | ShShaderType shaderType; |
| 82 | ShShaderSpec shaderSpec; |
| 83 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 84 | unsigned int maxCallStackDepth; |
| 85 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 86 | // Built-in symbol table for the given language, spec, and resources. |
| 87 | // It is preserved from compile-to-compile. |
| 88 | TSymbolTable symbolTable; |
| 89 | // Built-in extensions with default behavior. |
| 90 | TExtensionBehavior extensionBehavior; |
| 91 | |
| 92 | // Results of compilation. |
| 93 | TInfoSink infoSink; // Output sink. |
| 94 | TVariableInfoList attribs; // Active attributes in the compiled shader. |
| 95 | TVariableInfoList uniforms; // Active uniforms in the compiled shader. |
| 96 | }; |
| 97 | |
| 98 | // |
| 99 | // This is the interface between the machine independent code |
| 100 | // and the machine dependent code. |
| 101 | // |
| 102 | // The machine dependent code should derive from the classes |
| 103 | // above. Then Construct*() and Delete*() will create and |
| 104 | // destroy the machine dependent objects, which contain the |
| 105 | // above machine independent information. |
| 106 | // |
| 107 | TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec); |
| 108 | void DeleteCompiler(TCompiler*); |
| 109 | |
| 110 | #endif // _SHHANDLE_INCLUDED_ |