BsD3D11GpuProgram.h 7.9 KB

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