BsD3D11GpuProgram.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsGpuProgram.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Abstraction of a DirectX 11 shader object.
  8. */
  9. class BS_D3D11_EXPORT D3D11GpuProgram : public GpuProgram
  10. {
  11. public:
  12. virtual ~D3D11GpuProgram();
  13. /**
  14. * @copydoc GpuProgram::getLanguage
  15. */
  16. const String& getLanguage() const;
  17. /**
  18. * @copydoc GpuProgram::createParameters
  19. */
  20. GpuParamsPtr createParameters();
  21. /**
  22. * @copydoc GpuProgram::requiresMatrixTranspose
  23. */
  24. virtual bool requiresMatrixTranspose() const { return mColumnMajorMatrices; }
  25. /**
  26. * @brief Returns compiled shader microcode.
  27. */
  28. const HLSLMicroCode& getMicroCode() const { return mMicrocode; }
  29. /**
  30. * @brief Returns GPU program input declaration. Only relevant for vertex programs.
  31. */
  32. VertexDeclarationPtr getInputDeclaration() const { return mInputDeclaration; }
  33. /**
  34. * @brief Returns unique GPU program ID.
  35. */
  36. UINT32 getProgramId() const { return mProgramId; }
  37. protected:
  38. /**
  39. * @copydoc GpuProgram::GpuProgram
  40. */
  41. D3D11GpuProgram(const String& source, const String& entryPoint, GpuProgramType gptype,
  42. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes, bool isAdjacencyInfoRequired);
  43. /**
  44. * @copydoc GpuProgram::initialize_internal
  45. */
  46. void initialize_internal();
  47. /**
  48. * @copydoc GpuProgram::destroy_internal
  49. */
  50. void destroy_internal();
  51. /**
  52. * @brief Loads the shader from microcode.
  53. */
  54. virtual void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) = 0;
  55. /**
  56. * @brief Compiles the shader from source and generates the microcode.
  57. */
  58. ID3DBlob* compileMicrocode(const String& profile);
  59. /**
  60. * @brief Reflects the microcode and extracts input/output parameters, and constant
  61. * buffer structures used by the program.
  62. */
  63. void populateParametersAndConstants(ID3DBlob* microcode);
  64. protected:
  65. static UINT32 GlobalProgramId;
  66. bool mColumnMajorMatrices;
  67. bool mEnableBackwardsCompatibility;
  68. UINT32 mProgramId;
  69. HLSLMicroCode mMicrocode;
  70. VertexDeclarationPtr mInputDeclaration;
  71. /************************************************************************/
  72. /* SERIALIZATION */
  73. /************************************************************************/
  74. public:
  75. friend class D3D11GpuProgramRTTI;
  76. static RTTITypeBase* getRTTIStatic();
  77. virtual RTTITypeBase* getRTTI() const;
  78. };
  79. /**
  80. * @brief Implementation of a DX11 vertex shader.
  81. */
  82. class BS_D3D11_EXPORT D3D11GpuVertexProgram : public D3D11GpuProgram
  83. {
  84. public:
  85. ~D3D11GpuVertexProgram();
  86. /**
  87. * @brief Returns internal DX11 vertex shader object.
  88. */
  89. ID3D11VertexShader* getVertexShader() const;
  90. protected:
  91. friend class D3D11HLSLProgramFactory;
  92. /**
  93. * @copydoc GpuProgram::GpuProgram
  94. */
  95. D3D11GpuVertexProgram(const String& source, const String& entryPoint,
  96. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  97. /**
  98. * @copydoc GpuProgram::destroy_internal().
  99. */
  100. void destroy_internal();
  101. /**
  102. * @copydoc D3D11GpuProgram::loadFromMicrocode
  103. */
  104. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  105. protected:
  106. ID3D11VertexShader* mVertexShader;
  107. /************************************************************************/
  108. /* SERIALIZATION */
  109. /************************************************************************/
  110. public:
  111. friend class D3D11GpuVertexProgramRTTI;
  112. static RTTITypeBase* getRTTIStatic();
  113. virtual RTTITypeBase* getRTTI() const;
  114. };
  115. /**
  116. * @brief Implementation of a DX11 pixel shader.
  117. */
  118. class BS_D3D11_EXPORT D3D11GpuFragmentProgram : public D3D11GpuProgram
  119. {
  120. public:
  121. ~D3D11GpuFragmentProgram();
  122. /**
  123. * @brief Returns internal DX11 pixel shader object.
  124. */
  125. ID3D11PixelShader* getPixelShader() const;
  126. protected:
  127. friend class D3D11HLSLProgramFactory;
  128. /**
  129. * @copydoc GpuProgram::GpuProgram
  130. */
  131. D3D11GpuFragmentProgram(const String& source, const String& entryPoint,
  132. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  133. /**
  134. * @copydoc GpuProgram::destroy_internal().
  135. */
  136. void destroy_internal();
  137. /**
  138. * @copydoc D3D11GpuProgram::loadFromMicrocode
  139. */
  140. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  141. protected:
  142. ID3D11PixelShader* mPixelShader;
  143. /************************************************************************/
  144. /* SERIALIZATION */
  145. /************************************************************************/
  146. public:
  147. friend class D3D11GpuFragmentProgramRTTI;
  148. static RTTITypeBase* getRTTIStatic();
  149. virtual RTTITypeBase* getRTTI() const;
  150. };
  151. /**
  152. * @brief Implementation of a DX11 domain shader.
  153. */
  154. class BS_D3D11_EXPORT D3D11GpuDomainProgram : public D3D11GpuProgram
  155. {
  156. public:
  157. ~D3D11GpuDomainProgram();
  158. /**
  159. * @brief Returns internal DX11 domain shader object.
  160. */
  161. ID3D11DomainShader* getDomainShader() const;
  162. protected:
  163. friend class D3D11HLSLProgramFactory;
  164. /**
  165. * @copydoc GpuProgram::GpuProgram
  166. */
  167. D3D11GpuDomainProgram(const String& source, const String& entryPoint,
  168. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  169. /**
  170. * @copydoc GpuProgram::destroy_internal().
  171. */
  172. void destroy_internal();
  173. /**
  174. * @copydoc D3D11GpuProgram::loadFromMicrocode
  175. */
  176. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  177. protected:
  178. ID3D11DomainShader* mDomainShader;
  179. /************************************************************************/
  180. /* SERIALIZATION */
  181. /************************************************************************/
  182. public:
  183. friend class D3D11GpuDomainProgramRTTI;
  184. static RTTITypeBase* getRTTIStatic();
  185. virtual RTTITypeBase* getRTTI() const;
  186. };
  187. /**
  188. * @brief Implementation of a DX11 hull shader.
  189. */
  190. class BS_D3D11_EXPORT D3D11GpuHullProgram : public D3D11GpuProgram
  191. {
  192. public:
  193. ~D3D11GpuHullProgram();
  194. /**
  195. * @brief Returns internal DX11 hull shader object.
  196. */
  197. ID3D11HullShader* getHullShader() const;
  198. protected:
  199. friend class D3D11HLSLProgramFactory;
  200. /**
  201. * @copydoc GpuProgram::GpuProgram
  202. */
  203. D3D11GpuHullProgram(const String& source, const String& entryPoint,
  204. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  205. /**
  206. * @copydoc GpuProgram::destroy_internal
  207. */
  208. void destroy_internal();
  209. /**
  210. * @copydoc D3D11GpuProgram::loadFromMicrocode
  211. */
  212. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  213. protected:
  214. ID3D11HullShader* mHullShader;
  215. /************************************************************************/
  216. /* SERIALIZATION */
  217. /************************************************************************/
  218. public:
  219. friend class D3D11GpuHullProgramRTTI;
  220. static RTTITypeBase* getRTTIStatic();
  221. virtual RTTITypeBase* getRTTI() const;
  222. };
  223. /**
  224. * @brief Implementation of a DX11 geometry shader.
  225. */
  226. class BS_D3D11_EXPORT D3D11GpuGeometryProgram : public D3D11GpuProgram
  227. {
  228. public:
  229. ~D3D11GpuGeometryProgram();
  230. /**
  231. * @brief Returns internal DX11 geometry shader object.
  232. */
  233. ID3D11GeometryShader* getGeometryShader() const;
  234. protected:
  235. friend class D3D11HLSLProgramFactory;
  236. /**
  237. * @copydoc GpuProgram::GpuProgram
  238. */
  239. D3D11GpuGeometryProgram(const String& source, const String& entryPoint,
  240. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes,
  241. bool isAdjacencyInfoRequired);
  242. /**
  243. * @copydoc GpuProgram::destroy_internal
  244. */
  245. void destroy_internal();
  246. /**
  247. * @copydoc D3D11GpuProgram::loadFromMicrocode
  248. */
  249. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  250. protected:
  251. ID3D11GeometryShader* mGeometryShader;
  252. /************************************************************************/
  253. /* SERIALIZATION */
  254. /************************************************************************/
  255. public:
  256. friend class D3D11GpuGeometryProgramRTTI;
  257. static RTTITypeBase* getRTTIStatic();
  258. virtual RTTITypeBase* getRTTI() const;
  259. };
  260. /**
  261. * @brief Implementation of a DX11 compute shader.
  262. */
  263. class BS_D3D11_EXPORT D3D11GpuComputeProgram : public D3D11GpuProgram
  264. {
  265. public:
  266. ~D3D11GpuComputeProgram();
  267. /**
  268. * @brief Returns internal DX11 compute shader object.
  269. */
  270. ID3D11ComputeShader* getComputeShader() const;
  271. protected:
  272. friend class D3D11HLSLProgramFactory;
  273. /**
  274. * @copydoc GpuProgram::GpuProgram
  275. */
  276. D3D11GpuComputeProgram(const String& source, const String& entryPoint,
  277. GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes);
  278. /**
  279. * @copydoc GpuProgram::destroy_internal
  280. */
  281. void destroy_internal();
  282. /**
  283. * @copydoc D3D11GpuProgram::loadFromMicrocode
  284. */
  285. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  286. protected:
  287. ID3D11ComputeShader* mComputeShader;
  288. /************************************************************************/
  289. /* SERIALIZATION */
  290. /************************************************************************/
  291. public:
  292. friend class D3D11GpuComputeProgramRTTI;
  293. static RTTITypeBase* getRTTIStatic();
  294. virtual RTTITypeBase* getRTTI() const;
  295. };
  296. }