• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 //    Redistributions of source code must retain the above copyright
10 //    notice, this list of conditions and the following disclaimer.
11 //
12 //    Redistributions in binary form must reproduce the above
13 //    copyright notice, this list of conditions and the following
14 //    disclaimer in the documentation and/or other materials provided
15 //    with the distribution.
16 //
17 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
18 //    contributors may be used to endorse or promote products derived
19 //    from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33 //
34 
35 #ifndef _SHHANDLE_INCLUDED_
36 #define _SHHANDLE_INCLUDED_
37 
38 //
39 // Machine independent part of the compiler private objects
40 // sent as ShHandle to the driver.
41 //
42 // This should not be included by driver code.
43 //
44 
45 #define SH_EXPORTING
46 #include "../Public/ShaderLang.h"
47 #include "../MachineIndependent/Versions.h"
48 #include "InfoSink.h"
49 
50 class TCompiler;
51 class TLinker;
52 class TUniformMap;
53 
54 //
55 // The base class used to back handles returned to the driver.
56 //
57 class TShHandleBase {
58 public:
TShHandleBase()59     TShHandleBase() { pool = new glslang::TPoolAllocator; }
~TShHandleBase()60     virtual ~TShHandleBase() { delete pool; }
getAsCompiler()61     virtual TCompiler* getAsCompiler() { return 0; }
getAsLinker()62     virtual TLinker* getAsLinker() { return 0; }
getAsUniformMap()63     virtual TUniformMap* getAsUniformMap() { return 0; }
getPool()64     virtual glslang::TPoolAllocator* getPool() const { return pool; }
65 private:
66     glslang::TPoolAllocator* pool;
67 };
68 
69 //
70 // The base class for the machine dependent linker to derive from
71 // for managing where uniforms live.
72 //
73 class TUniformMap : public TShHandleBase {
74 public:
TUniformMap()75     TUniformMap() { }
~TUniformMap()76     virtual ~TUniformMap() { }
getAsUniformMap()77     virtual TUniformMap* getAsUniformMap() { return this; }
78     virtual int getLocation(const char* name) = 0;
getInfoSink()79     virtual TInfoSink& getInfoSink() { return infoSink; }
80     TInfoSink infoSink;
81 };
82 
83 class TIntermNode;
84 
85 //
86 // The base class for the machine dependent compiler to derive from
87 // for managing object code from the compile.
88 //
89 class TCompiler : public TShHandleBase {
90 public:
TCompiler(EShLanguage l,TInfoSink & sink)91     TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
~TCompiler()92     virtual ~TCompiler() { }
getLanguage()93     EShLanguage getLanguage() { return language; }
getInfoSink()94     virtual TInfoSink& getInfoSink() { return infoSink; }
95 
96     virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
97 
getAsCompiler()98     virtual TCompiler* getAsCompiler() { return this; }
linkable()99     virtual bool linkable() { return haveValidObjectCode; }
100 
101     TInfoSink& infoSink;
102 protected:
103     TCompiler& operator=(TCompiler&);
104 
105     EShLanguage language;
106     bool haveValidObjectCode;
107 };
108 
109 //
110 // Link operations are based on a list of compile results...
111 //
112 typedef glslang::TVector<TCompiler*> TCompilerList;
113 typedef glslang::TVector<TShHandleBase*> THandleList;
114 
115 //
116 // The base class for the machine dependent linker to derive from
117 // to manage the resulting executable.
118 //
119 
120 class TLinker : public TShHandleBase {
121 public:
TLinker(EShExecutable e,TInfoSink & iSink)122     TLinker(EShExecutable e, TInfoSink& iSink) :
123         infoSink(iSink),
124         executable(e),
125         haveReturnableObjectCode(false),
126         appAttributeBindings(0),
127         fixedAttributeBindings(0),
128         excludedAttributes(0),
129         excludedCount(0),
130         uniformBindings(0) { }
getAsLinker()131     virtual TLinker* getAsLinker() { return this; }
~TLinker()132     virtual ~TLinker() { }
133     virtual bool link(TCompilerList&, TUniformMap*) = 0;
link(THandleList &)134     virtual bool link(THandleList&) { return false; }
setAppAttributeBindings(const ShBindingTable * t)135     virtual void setAppAttributeBindings(const ShBindingTable* t)   { appAttributeBindings = t; }
setFixedAttributeBindings(const ShBindingTable * t)136     virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
137     virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
setExcludedAttributes(const int * attributes,int count)138     virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
getUniformBindings()139     virtual ShBindingTable* getUniformBindings() const  { return uniformBindings; }
getObjectCode()140     virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
getInfoSink()141     virtual TInfoSink& getInfoSink() { return infoSink; }
142     TInfoSink& infoSink;
143 protected:
144     TLinker& operator=(TLinker&);
145     EShExecutable executable;
146     bool haveReturnableObjectCode;  // true when objectCode is acceptable to send to driver
147 
148     const ShBindingTable* appAttributeBindings;
149     const ShBindingTable* fixedAttributeBindings;
150     const int* excludedAttributes;
151     int excludedCount;
152     ShBindingTable* uniformBindings;                // created by the linker
153 };
154 
155 //
156 // This is the interface between the machine independent code
157 // and the machine dependent code.
158 //
159 // The machine dependent code should derive from the classes
160 // above. Then Construct*() and Delete*() will create and
161 // destroy the machine dependent objects, which contain the
162 // above machine independent information.
163 //
164 TCompiler* ConstructCompiler(EShLanguage, int);
165 
166 TShHandleBase* ConstructLinker(EShExecutable, int);
167 TShHandleBase* ConstructBindings();
168 void DeleteLinker(TShHandleBase*);
169 void DeleteBindingList(TShHandleBase* bindingList);
170 
171 TUniformMap* ConstructUniformMap();
172 void DeleteCompiler(TCompiler*);
173 
174 void DeleteUniformMap(TUniformMap*);
175 
176 #endif // _SHHANDLE_INCLUDED_
177