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 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 19 | #include "compiler/InfoSink.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 20 | |
| 21 | class TCompiler; |
| 22 | class TLinker; |
| 23 | class TUniformMap; |
| 24 | |
| 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 | virtual TLinker* getAsLinker() { return 0; } |
| 35 | virtual TUniformMap* getAsUniformMap() { return 0; } |
| 36 | }; |
| 37 | |
| 38 | // |
| 39 | // The base class for the machine dependent linker to derive from |
| 40 | // for managing where uniforms live. |
| 41 | // |
| 42 | class TUniformMap : public TShHandleBase { |
| 43 | public: |
| 44 | TUniformMap() { } |
| 45 | virtual ~TUniformMap() { } |
| 46 | virtual TUniformMap* getAsUniformMap() { return this; } |
| 47 | virtual int getLocation(const char* name) = 0; |
| 48 | virtual TInfoSink& getInfoSink() { return infoSink; } |
| 49 | TInfoSink infoSink; |
| 50 | }; |
| 51 | class TIntermNode; |
| 52 | |
| 53 | // |
| 54 | // The base class for the machine dependent compiler to derive from |
| 55 | // for managing object code from the compile. |
| 56 | // |
| 57 | class TCompiler : public TShHandleBase { |
| 58 | public: |
alokp@chromium.org | 29cd91a | 2010-07-16 19:30:45 +0000 | [diff] [blame] | 59 | TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s), haveValidObjectCode(false) { } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 60 | virtual ~TCompiler() { } |
alokp@chromium.org | 613ef31 | 2010-07-21 18:54:22 +0000 | [diff] [blame^] | 61 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 62 | EShLanguage getLanguage() { return language; } |
alokp@chromium.org | 613ef31 | 2010-07-21 18:54:22 +0000 | [diff] [blame^] | 63 | EShSpec getSpec() { return spec; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 64 | virtual TInfoSink& getInfoSink() { return infoSink; } |
| 65 | |
| 66 | virtual bool compile(TIntermNode* root) = 0; |
| 67 | |
| 68 | virtual TCompiler* getAsCompiler() { return this; } |
| 69 | virtual bool linkable() { return haveValidObjectCode; } |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 70 | |
| 71 | TInfoSink infoSink; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 72 | protected: |
| 73 | EShLanguage language; |
alokp@chromium.org | 29cd91a | 2010-07-16 19:30:45 +0000 | [diff] [blame] | 74 | EShSpec spec; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 75 | bool haveValidObjectCode; |
| 76 | }; |
| 77 | |
| 78 | // |
| 79 | // Link operations are base on a list of compile results... |
| 80 | // |
| 81 | typedef TVector<TCompiler*> TCompilerList; |
| 82 | typedef TVector<TShHandleBase*> THandleList; |
| 83 | |
| 84 | // |
| 85 | // The base class for the machine dependent linker to derive from |
| 86 | // to manage the resulting executable. |
| 87 | // |
| 88 | |
| 89 | class TLinker : public TShHandleBase { |
| 90 | public: |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 91 | TLinker(EShExecutable e) : |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 92 | executable(e), |
| 93 | haveReturnableObjectCode(false), |
| 94 | appAttributeBindings(0), |
| 95 | fixedAttributeBindings(0), |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 96 | excludedAttributes(0), |
| 97 | excludedCount(0), |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 98 | uniformBindings(0) { } |
| 99 | virtual TLinker* getAsLinker() { return this; } |
| 100 | virtual ~TLinker() { } |
| 101 | virtual bool link(TCompilerList&, TUniformMap*) = 0; |
| 102 | virtual bool link(THandleList&) { return false; } |
| 103 | virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; } |
| 104 | virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; } |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 105 | virtual void getAttributeBindings(ShBindingTable const **t) const = 0; |
| 106 | virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 107 | virtual ShBindingTable* getUniformBindings() const { return uniformBindings; } |
| 108 | virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here |
| 109 | virtual TInfoSink& getInfoSink() { return infoSink; } |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 110 | TInfoSink infoSink; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 111 | protected: |
| 112 | EShExecutable executable; |
| 113 | bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver |
| 114 | |
| 115 | const ShBindingTable* appAttributeBindings; |
| 116 | const ShBindingTable* fixedAttributeBindings; |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 117 | const int* excludedAttributes; |
| 118 | int excludedCount; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 119 | ShBindingTable* uniformBindings; // created by the linker |
| 120 | }; |
| 121 | |
| 122 | // |
| 123 | // This is the interface between the machine independent code |
| 124 | // and the machine dependent code. |
| 125 | // |
| 126 | // The machine dependent code should derive from the classes |
| 127 | // above. Then Construct*() and Delete*() will create and |
| 128 | // destroy the machine dependent objects, which contain the |
| 129 | // above machine independent information. |
| 130 | // |
alokp@chromium.org | 29cd91a | 2010-07-16 19:30:45 +0000 | [diff] [blame] | 131 | TCompiler* ConstructCompiler(EShLanguage, EShSpec); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 132 | |
| 133 | TShHandleBase* ConstructLinker(EShExecutable, int); |
| 134 | void DeleteLinker(TShHandleBase*); |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 135 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 136 | TUniformMap* ConstructUniformMap(); |
| 137 | void DeleteCompiler(TCompiler*); |
| 138 | |
| 139 | void DeleteUniformMap(TUniformMap*); |
| 140 | |
| 141 | #endif // _SHHANDLE_INCLUDED_ |