BsD3D11GpuProgram.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsGpuProgram.h"
  4. namespace BansheeEngine
  5. {
  6. class BS_D3D11_EXPORT D3D11GpuProgram : public GpuProgram
  7. {
  8. static UINT32 GlobalProgramId;
  9. public:
  10. virtual ~D3D11GpuProgram();
  11. const String& getLanguage() const;
  12. GpuParamsPtr createParameters();
  13. /** Sets whether matrix packing in column-major order. */
  14. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  15. /** Gets whether matrix packed in column-major order. */
  16. bool getColumnMajorMatrices() const { return mColumnMajorMatrices; }
  17. /** Sets whether backwards compatibility is enabled. */
  18. void setEnableBackwardsCompatibility(bool enableBackwardsCompatibility) { mEnableBackwardsCompatibility = enableBackwardsCompatibility; }
  19. /** Gets whether backwards compatibility is enabled. */
  20. bool getEnableBackwardsCompatibility() const { return mEnableBackwardsCompatibility; }
  21. const HLSLMicroCode& getMicroCode() const { return mMicrocode; }
  22. VertexDeclarationPtr getInputDeclaration() const { return mInputDeclaration; }
  23. UINT32 getProgramId() const { return mProgramId; }
  24. protected:
  25. D3D11GpuProgram(const String& source, const String& entryPoint, GpuProgramType gptype,
  26. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes, bool isAdjacencyInfoRequired);
  27. /**
  28. * @copydoc GpuProgram::initialize_internal()
  29. */
  30. void initialize_internal();
  31. /**
  32. * @copydoc GpuProgram::destroy_internal()
  33. */
  34. void destroy_internal();
  35. /**
  36. * @brief Loads shader from microcode.
  37. */
  38. virtual void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) = 0;
  39. /**
  40. * @brief Compiles the shader from source and generates the microcode.
  41. */
  42. ID3DBlob* compileMicrocode(const String& profile);
  43. /**
  44. * @brief Reflects the microcode and extracts input/output parameters, and constant
  45. * buffer structures used by the program.
  46. */
  47. void populateParametersAndConstants(ID3DBlob* microcode);
  48. protected:
  49. bool mColumnMajorMatrices;
  50. bool mEnableBackwardsCompatibility;
  51. UINT32 mProgramId;
  52. HLSLMicroCode mMicrocode;
  53. VertexDeclarationPtr mInputDeclaration;
  54. /************************************************************************/
  55. /* SERIALIZATION */
  56. /************************************************************************/
  57. public:
  58. friend class D3D11GpuProgramRTTI;
  59. static RTTITypeBase* getRTTIStatic();
  60. virtual RTTITypeBase* getRTTI() const;
  61. };
  62. class BS_D3D11_EXPORT D3D11GpuVertexProgram : public D3D11GpuProgram
  63. {
  64. public:
  65. ~D3D11GpuVertexProgram();
  66. ID3D11VertexShader* getVertexShader() const;
  67. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  68. protected:
  69. friend class D3D11HLSLProgramFactory;
  70. D3D11GpuVertexProgram(const String& source, const String& entryPoint,
  71. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  72. /**
  73. * @copydoc GpuProgram::destroy_internal().
  74. */
  75. void destroy_internal();
  76. protected:
  77. ID3D11VertexShader* mVertexShader;
  78. /************************************************************************/
  79. /* SERIALIZATION */
  80. /************************************************************************/
  81. public:
  82. friend class D3D11GpuVertexProgramRTTI;
  83. static RTTITypeBase* getRTTIStatic();
  84. virtual RTTITypeBase* getRTTI() const;
  85. };
  86. class BS_D3D11_EXPORT D3D11GpuFragmentProgram : public D3D11GpuProgram
  87. {
  88. public:
  89. ~D3D11GpuFragmentProgram();
  90. ID3D11PixelShader* getPixelShader() const;
  91. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  92. protected:
  93. friend class D3D11HLSLProgramFactory;
  94. D3D11GpuFragmentProgram(const String& source, const String& entryPoint,
  95. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  96. /**
  97. * @copydoc GpuProgram::destroy_internal().
  98. */
  99. void destroy_internal();
  100. protected:
  101. ID3D11PixelShader* mPixelShader;
  102. /************************************************************************/
  103. /* SERIALIZATION */
  104. /************************************************************************/
  105. public:
  106. friend class D3D11GpuFragmentProgramRTTI;
  107. static RTTITypeBase* getRTTIStatic();
  108. virtual RTTITypeBase* getRTTI() const;
  109. };
  110. class BS_D3D11_EXPORT D3D11GpuDomainProgram : public D3D11GpuProgram
  111. {
  112. public:
  113. ~D3D11GpuDomainProgram();
  114. ID3D11DomainShader* getDomainShader() const;
  115. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  116. protected:
  117. friend class D3D11HLSLProgramFactory;
  118. D3D11GpuDomainProgram(const String& source, const String& entryPoint,
  119. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  120. /**
  121. * @copydoc GpuProgram::destroy_internal().
  122. */
  123. void destroy_internal();
  124. protected:
  125. ID3D11DomainShader* mDomainShader;
  126. /************************************************************************/
  127. /* SERIALIZATION */
  128. /************************************************************************/
  129. public:
  130. friend class D3D11GpuDomainProgramRTTI;
  131. static RTTITypeBase* getRTTIStatic();
  132. virtual RTTITypeBase* getRTTI() const;
  133. };
  134. class BS_D3D11_EXPORT D3D11GpuHullProgram : public D3D11GpuProgram
  135. {
  136. public:
  137. ~D3D11GpuHullProgram();
  138. ID3D11HullShader* getHullShader() const;
  139. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  140. protected:
  141. friend class D3D11HLSLProgramFactory;
  142. D3D11GpuHullProgram(const String& source, const String& entryPoint,
  143. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  144. /**
  145. * @copydoc GpuProgram::destroy_internal().
  146. */
  147. void destroy_internal();
  148. protected:
  149. ID3D11HullShader* mHullShader;
  150. /************************************************************************/
  151. /* SERIALIZATION */
  152. /************************************************************************/
  153. public:
  154. friend class D3D11GpuHullProgramRTTI;
  155. static RTTITypeBase* getRTTIStatic();
  156. virtual RTTITypeBase* getRTTI() const;
  157. };
  158. class BS_D3D11_EXPORT D3D11GpuGeometryProgram : public D3D11GpuProgram
  159. {
  160. public:
  161. ~D3D11GpuGeometryProgram();
  162. ID3D11GeometryShader* getGeometryShader() const;
  163. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  164. protected:
  165. friend class D3D11HLSLProgramFactory;
  166. D3D11GpuGeometryProgram(const String& source, const String& entryPoint,
  167. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes,
  168. bool isAdjacencyInfoRequired);
  169. /**
  170. * @copydoc GpuProgram::destroy_internal().
  171. */
  172. void destroy_internal();
  173. protected:
  174. ID3D11GeometryShader* mGeometryShader;
  175. /************************************************************************/
  176. /* SERIALIZATION */
  177. /************************************************************************/
  178. public:
  179. friend class D3D11GpuGeometryProgramRTTI;
  180. static RTTITypeBase* getRTTIStatic();
  181. virtual RTTITypeBase* getRTTI() const;
  182. };
  183. class BS_D3D11_EXPORT D3D11GpuComputeProgram : public D3D11GpuProgram
  184. {
  185. public:
  186. ~D3D11GpuComputeProgram();
  187. ID3D11ComputeShader* getComputeShader() const;
  188. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  189. protected:
  190. friend class D3D11HLSLProgramFactory;
  191. D3D11GpuComputeProgram(const String& source, const String& entryPoint,
  192. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  193. /**
  194. * @copydoc GpuProgram::destroy_internal().
  195. */
  196. void destroy_internal();
  197. protected:
  198. ID3D11ComputeShader* mComputeShader;
  199. /************************************************************************/
  200. /* SERIALIZATION */
  201. /************************************************************************/
  202. public:
  203. friend class D3D11GpuComputeProgramRTTI;
  204. static RTTITypeBase* getRTTIStatic();
  205. virtual RTTITypeBase* getRTTI() const;
  206. };
  207. }