ShHandle.h 6.1 KB

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