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