daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [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 | |
alokp@chromium.org | ea0e1af | 2010-03-22 19:33:14 +0000 | [diff] [blame] | 17 | #include "GLSLANG/ShaderLang.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 19 | #include "compiler/BuiltInFunctionEmulator.h" |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 20 | #include "compiler/ExtensionBehavior.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 21 | #include "compiler/InfoSink.h" |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 22 | #include "compiler/SymbolTable.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 23 | #include "compiler/VariableInfo.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 24 | |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 25 | class LongNameMap; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | class TCompiler; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 27 | |
| 28 | // |
| 29 | // The base class used to back handles returned to the driver. |
| 30 | // |
| 31 | class TShHandleBase { |
| 32 | public: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 33 | TShHandleBase(); |
| 34 | virtual ~TShHandleBase(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 35 | virtual TCompiler* getAsCompiler() { return 0; } |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | // Memory allocator. Allocates and tracks memory required by the compiler. |
| 39 | // Deallocates all memory when compiler is destructed. |
| 40 | TPoolAllocator allocator; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 44 | // The base class for the machine dependent compiler to derive from |
| 45 | // for managing object code from the compile. |
| 46 | // |
| 47 | class TCompiler : public TShHandleBase { |
| 48 | public: |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 49 | TCompiler(ShShaderType type, ShShaderSpec spec); |
| 50 | virtual ~TCompiler(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 51 | virtual TCompiler* getAsCompiler() { return this; } |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 52 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 53 | bool Init(const ShBuiltInResources& resources); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 54 | bool compile(const char* const shaderStrings[], |
| 55 | const int numStrings, |
| 56 | int compileOptions); |
| 57 | |
| 58 | // Get results of the last compilation. |
| 59 | TInfoSink& getInfoSink() { return infoSink; } |
| 60 | const TVariableInfoList& getAttribs() const { return attribs; } |
| 61 | const TVariableInfoList& getUniforms() const { return uniforms; } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 62 | int getMappedNameMaxLength() const; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 63 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 64 | protected: |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 65 | ShShaderType getShaderType() const { return shaderType; } |
| 66 | ShShaderSpec getShaderSpec() const { return shaderSpec; } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 67 | // Initialize symbol-table with built-in symbols. |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 68 | bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 69 | // Clears the results from the previous compilation. |
| 70 | void clearResults(); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 71 | // Return true if function recursion is detected. |
| 72 | bool detectRecursion(TIntermNode* root); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 73 | // Returns true if the given shader does not exceed the minimum |
| 74 | // functionality mandated in GLSL 1.0 spec Appendix A. |
| 75 | bool validateLimitations(TIntermNode* root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 76 | // Collect info for all attribs and uniforms. |
| 77 | void collectAttribsUniforms(TIntermNode* root); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 78 | // Map long variable names into shorter ones. |
| 79 | void mapLongVariableNames(TIntermNode* root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 80 | // Translate to object code. |
| 81 | virtual void translate(TIntermNode* root) = 0; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 82 | // Get built-in extensions with default behavior. |
| 83 | const TExtensionBehavior& getExtensionBehavior() const; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 84 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 85 | const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const; |
| 86 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 87 | private: |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 88 | ShShaderType shaderType; |
| 89 | ShShaderSpec shaderSpec; |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 90 | |
| 91 | // Built-in symbol table for the given language, spec, and resources. |
| 92 | // It is preserved from compile-to-compile. |
| 93 | TSymbolTable symbolTable; |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 94 | // Built-in extensions with default behavior. |
| 95 | TExtensionBehavior extensionBehavior; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 96 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 97 | BuiltInFunctionEmulator builtInFunctionEmulator; |
| 98 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 99 | // Results of compilation. |
| 100 | TInfoSink infoSink; // Output sink. |
| 101 | TVariableInfoList attribs; // Active attributes in the compiled shader. |
| 102 | TVariableInfoList uniforms; // Active uniforms in the compiled shader. |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 103 | |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 104 | // Cached copy of the ref-counted singleton. |
| 105 | LongNameMap* longNameMap; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | // |
| 109 | // This is the interface between the machine independent code |
| 110 | // and the machine dependent code. |
| 111 | // |
| 112 | // The machine dependent code should derive from the classes |
| 113 | // above. Then Construct*() and Delete*() will create and |
| 114 | // destroy the machine dependent objects, which contain the |
| 115 | // above machine independent information. |
| 116 | // |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 117 | TCompiler* ConstructCompiler( |
| 118 | ShShaderType type, ShShaderSpec spec, ShShaderOutput output); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 119 | void DeleteCompiler(TCompiler*); |
| 120 | |
daniel@transgaming.com | 5cb728c | 2011-05-17 18:34:24 +0000 | [diff] [blame] | 121 | #endif // _SHHANDLE_INCLUDED_ |