daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 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. |
| 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 | |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 19 | #include "compiler/ExtensionBehavior.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 20 | #include "compiler/InfoSink.h" |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 21 | #include "compiler/SymbolTable.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 22 | #include "compiler/VariableInfo.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 23 | |
| 24 | class TCompiler; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | |
| 26 | // |
| 27 | // The base class used to back handles returned to the driver. |
| 28 | // |
| 29 | class TShHandleBase { |
| 30 | public: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame^] | 31 | TShHandleBase(); |
| 32 | virtual ~TShHandleBase(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | virtual TCompiler* getAsCompiler() { return 0; } |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame^] | 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; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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: |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 47 | TCompiler(ShShaderType type, ShShaderSpec spec); |
| 48 | virtual ~TCompiler(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | virtual TCompiler* getAsCompiler() { return this; } |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 50 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 51 | bool Init(const ShBuiltInResources& resources); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 61 | protected: |
alokp@chromium.org | 9ecf395 | 2010-10-13 19:28:25 +0000 | [diff] [blame] | 62 | ShShaderType getShaderType() const { return shaderType; } |
| 63 | ShShaderSpec getShaderSpec() const { return shaderSpec; } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 64 | // Initialize symbol-table with built-in symbols. |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 65 | bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 66 | // Clears the results from the previous compilation. |
| 67 | void clearResults(); |
| 68 | // Collect info for all attribs and uniforms. |
| 69 | void collectAttribsUniforms(TIntermNode* root); |
| 70 | // Translate to object code. |
| 71 | virtual void translate(TIntermNode* root) = 0; |
| 72 | |
| 73 | private: |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 74 | ShShaderType shaderType; |
| 75 | ShShaderSpec shaderSpec; |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 76 | |
| 77 | // Built-in symbol table for the given language, spec, and resources. |
| 78 | // It is preserved from compile-to-compile. |
| 79 | TSymbolTable symbolTable; |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 80 | // Built-in extensions with default behavior. |
| 81 | TExtensionBehavior extensionBehavior; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 82 | |
| 83 | // Results of compilation. |
| 84 | TInfoSink infoSink; // Output sink. |
| 85 | TVariableInfoList attribs; // Active attributes in the compiled shader. |
| 86 | TVariableInfoList uniforms; // Active uniforms in the compiled shader. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | // |
| 90 | // This is the interface between the machine independent code |
| 91 | // and the machine dependent code. |
| 92 | // |
| 93 | // The machine dependent code should derive from the classes |
| 94 | // above. Then Construct*() and Delete*() will create and |
| 95 | // destroy the machine dependent objects, which contain the |
| 96 | // above machine independent information. |
| 97 | // |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 98 | TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 99 | void DeleteCompiler(TCompiler*); |
| 100 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 101 | #endif // _SHHANDLE_INCLUDED_ |