Home | History | Annotate | Download | only in Include
      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 
     46 #define SH_EXPORTING
     47 #include "../Public/ShaderLang.h"
     48 #include "../MachineIndependent/Versions.h"
     49 #include "InfoSink.h"
     50 
     51 class TCompiler;
     52 class TLinker;
     53 class TUniformMap;
     54 
     55 //
     56 // The base class used to back handles returned to the driver.
     57 //
     58 class TShHandleBase {
     59 public:
     60     TShHandleBase() { }
     61     virtual ~TShHandleBase() { }
     62     virtual TCompiler* getAsCompiler() { return 0; }
     63     virtual TLinker* getAsLinker() { return 0; }
     64     virtual TUniformMap* getAsUniformMap() { return 0; }
     65 };
     66 
     67 //
     68 // The base class for the machine dependent linker to derive from
     69 // for managing where uniforms live.
     70 //
     71 class TUniformMap : public TShHandleBase {
     72 public:
     73     TUniformMap() { }
     74     virtual ~TUniformMap() { }
     75     virtual TUniformMap* getAsUniformMap() { return this; }
     76     virtual int getLocation(const char* name) = 0;
     77     virtual TInfoSink& getInfoSink() { return infoSink; }
     78     TInfoSink infoSink;
     79 };
     80 
     81 class TIntermNode;
     82 
     83 //
     84 // The base class for the machine dependent compiler to derive from
     85 // for managing object code from the compile.
     86 //
     87 class TCompiler : public TShHandleBase {
     88 public:
     89     TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
     90     virtual ~TCompiler() { }
     91     EShLanguage getLanguage() { return language; }
     92     virtual TInfoSink& getInfoSink() { return infoSink; }
     93 
     94     virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
     95 
     96     virtual TCompiler* getAsCompiler() { return this; }
     97     virtual bool linkable() { return haveValidObjectCode; }
     98 
     99     TInfoSink& infoSink;
    100 protected:
    101     TCompiler& operator=(TCompiler&);
    102 
    103     EShLanguage language;
    104     bool haveValidObjectCode;
    105 };
    106 
    107 //
    108 // Link operations are based on a list of compile results...
    109 //
    110 typedef glslang::TVector<TCompiler*> TCompilerList;
    111 typedef glslang::TVector<TShHandleBase*> THandleList;
    112 
    113 //
    114 // The base class for the machine dependent linker to derive from
    115 // to manage the resulting executable.
    116 //
    117 
    118 class TLinker : public TShHandleBase {
    119 public:
    120     TLinker(EShExecutable e, TInfoSink& iSink) :
    121         infoSink(iSink),
    122         executable(e),
    123         haveReturnableObjectCode(false),
    124         appAttributeBindings(0),
    125         fixedAttributeBindings(0),
    126 		excludedAttributes(0),
    127 		excludedCount(0),
    128         uniformBindings(0) { }
    129     virtual TLinker* getAsLinker() { return this; }
    130     virtual ~TLinker() { }
    131     virtual bool link(TCompilerList&, TUniformMap*) = 0;
    132     virtual bool link(THandleList&) { return false; }
    133     virtual void setAppAttributeBindings(const ShBindingTable* t)   { appAttributeBindings = t; }
    134     virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
    135 	virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
    136 	virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
    137     virtual ShBindingTable* getUniformBindings() const  { return uniformBindings; }
    138     virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
    139     virtual TInfoSink& getInfoSink() { return infoSink; }
    140     TInfoSink& infoSink;
    141 protected:
    142     TLinker& operator=(TLinker&);
    143     EShExecutable executable;
    144     bool haveReturnableObjectCode;  // true when objectCode is acceptable to send to driver
    145 
    146     const ShBindingTable* appAttributeBindings;
    147     const ShBindingTable* fixedAttributeBindings;
    148 	const int* excludedAttributes;
    149 	int excludedCount;
    150     ShBindingTable* uniformBindings;                // created by the linker
    151 };
    152 
    153 //
    154 // This is the interface between the machine independent code
    155 // and the machine dependent code.
    156 //
    157 // The machine dependent code should derive from the classes
    158 // above. Then Construct*() and Delete*() will create and
    159 // destroy the machine dependent objects, which contain the
    160 // above machine independent information.
    161 //
    162 TCompiler* ConstructCompiler(EShLanguage, int);
    163 
    164 TShHandleBase* ConstructLinker(EShExecutable, int);
    165 TShHandleBase* ConstructBindings();
    166 void DeleteLinker(TShHandleBase*);
    167 void DeleteBindingList(TShHandleBase* bindingList);
    168 
    169 TUniformMap* ConstructUniformMap();
    170 void DeleteCompiler(TCompiler*);
    171 
    172 void DeleteUniformMap(TUniformMap*);
    173 
    174 #endif // _SHHANDLE_INCLUDED_
    175