BsD3D11GpuProgram.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 D3D11GpuProgramCore : public GpuProgramCore
  10. {
  11. public:
  12. virtual ~D3D11GpuProgramCore();
  13. /**
  14. * @copydoc GpuProgramCore::hasColumnMajorMatrices
  15. */
  16. bool hasColumnMajorMatrices() const { return mColumnMajorMatrices; }
  17. /**
  18. * @brief Returns compiled shader microcode.
  19. */
  20. const HLSLMicroCode& getMicroCode() const { return mMicrocode; }
  21. /**
  22. * @brief Returns GPU program input declaration. Only relevant for vertex programs.
  23. */
  24. SPtr<VertexDeclarationCore> getInputDeclaration() const { return mInputDeclaration; }
  25. /**
  26. * @brief Returns unique GPU program ID.
  27. */
  28. UINT32 getProgramId() const { return mProgramId; }
  29. protected:
  30. /**
  31. * @copydoc GpuProgramCore::GpuProgramCore
  32. */
  33. D3D11GpuProgramCore(const String& source, const String& entryPoint, GpuProgramType gptype,
  34. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  35. /**
  36. * @copydoc GpuProgramCore::initialize
  37. */
  38. void initialize();
  39. /**
  40. * @copydoc GpuProgramCore::destroy
  41. */
  42. void destroy();
  43. /**
  44. * @brief Loads the shader from microcode.
  45. */
  46. virtual void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) = 0;
  47. /**
  48. * @brief Compiles the shader from source and generates the microcode.
  49. */
  50. ID3DBlob* compileMicrocode(const String& profile);
  51. /**
  52. * @brief Reflects the microcode and extracts input/output parameters, and constant
  53. * buffer structures used by the program.
  54. */
  55. void populateParametersAndConstants(ID3DBlob* microcode);
  56. protected:
  57. static UINT32 GlobalProgramId;
  58. bool mColumnMajorMatrices;
  59. bool mEnableBackwardsCompatibility;
  60. UINT32 mProgramId;
  61. HLSLMicroCode mMicrocode;
  62. SPtr<VertexDeclarationCore> mInputDeclaration;
  63. };
  64. /**
  65. * @brief Implementation of a DX11 vertex shader.
  66. */
  67. class BS_D3D11_EXPORT D3D11GpuVertexProgramCore : public D3D11GpuProgramCore
  68. {
  69. public:
  70. ~D3D11GpuVertexProgramCore();
  71. /**
  72. * @brief Returns internal DX11 vertex shader object.
  73. */
  74. ID3D11VertexShader* getVertexShader() const;
  75. protected:
  76. friend class D3D11HLSLProgramFactory;
  77. /**
  78. * @copydoc GpuProgramCore::GpuProgramCore
  79. */
  80. D3D11GpuVertexProgramCore(const String& source, const String& entryPoint,
  81. GpuProgramProfile profile);
  82. /**
  83. * @copydoc GpuProgramCore::destroy
  84. */
  85. void destroy();
  86. /**
  87. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  88. */
  89. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  90. protected:
  91. ID3D11VertexShader* mVertexShader;
  92. };
  93. /**
  94. * @brief Implementation of a DX11 pixel shader.
  95. */
  96. class BS_D3D11_EXPORT D3D11GpuFragmentProgramCore : public D3D11GpuProgramCore
  97. {
  98. public:
  99. ~D3D11GpuFragmentProgramCore();
  100. /**
  101. * @brief Returns internal DX11 pixel shader object.
  102. */
  103. ID3D11PixelShader* getPixelShader() const;
  104. protected:
  105. friend class D3D11HLSLProgramFactory;
  106. /**
  107. * @copydoc GpuProgramCore::GpuProgramCore
  108. */
  109. D3D11GpuFragmentProgramCore(const String& source, const String& entryPoint,
  110. GpuProgramProfile profile);
  111. /**
  112. * @copydoc GpuProgramCore::destroy
  113. */
  114. void destroy();
  115. /**
  116. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  117. */
  118. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  119. protected:
  120. ID3D11PixelShader* mPixelShader;
  121. };
  122. /**
  123. * @brief Implementation of a DX11 domain shader.
  124. */
  125. class BS_D3D11_EXPORT D3D11GpuDomainProgramCore : public D3D11GpuProgramCore
  126. {
  127. public:
  128. ~D3D11GpuDomainProgramCore();
  129. /**
  130. * @brief Returns internal DX11 domain shader object.
  131. */
  132. ID3D11DomainShader* getDomainShader() const;
  133. protected:
  134. friend class D3D11HLSLProgramFactory;
  135. /**
  136. * @copydoc GpuProgramCore::GpuProgramCore
  137. */
  138. D3D11GpuDomainProgramCore(const String& source, const String& entryPoint,
  139. GpuProgramProfile profile);
  140. /**
  141. * @copydoc GpuProgramCore::destroy
  142. */
  143. void destroy();
  144. /**
  145. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  146. */
  147. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  148. protected:
  149. ID3D11DomainShader* mDomainShader;
  150. };
  151. /**
  152. * @brief Implementation of a DX11 hull shader.
  153. */
  154. class BS_D3D11_EXPORT D3D11GpuHullProgramCore : public D3D11GpuProgramCore
  155. {
  156. public:
  157. ~D3D11GpuHullProgramCore();
  158. /**
  159. * @brief Returns internal DX11 hull shader object.
  160. */
  161. ID3D11HullShader* getHullShader() const;
  162. protected:
  163. friend class D3D11HLSLProgramFactory;
  164. /**
  165. * @copydoc GpuProgramCore::GpuProgramCore
  166. */
  167. D3D11GpuHullProgramCore(const String& source, const String& entryPoint,
  168. GpuProgramProfile profile);
  169. /**
  170. * @copydoc GpuProgramCore::destroy
  171. */
  172. void destroy();
  173. /**
  174. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  175. */
  176. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  177. protected:
  178. ID3D11HullShader* mHullShader;
  179. };
  180. /**
  181. * @brief Implementation of a DX11 geometry shader.
  182. */
  183. class BS_D3D11_EXPORT D3D11GpuGeometryProgramCore : public D3D11GpuProgramCore
  184. {
  185. public:
  186. ~D3D11GpuGeometryProgramCore();
  187. /**
  188. * @brief Returns internal DX11 geometry shader object.
  189. */
  190. ID3D11GeometryShader* getGeometryShader() const;
  191. protected:
  192. friend class D3D11HLSLProgramFactory;
  193. /**
  194. * @copydoc GpuProgramCore::GpuProgramCore
  195. */
  196. D3D11GpuGeometryProgramCore(const String& source, const String& entryPoint,
  197. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  198. /**
  199. * @copydoc GpuProgramCore::destroy
  200. */
  201. void destroy();
  202. /**
  203. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  204. */
  205. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  206. protected:
  207. ID3D11GeometryShader* mGeometryShader;
  208. };
  209. /**
  210. * @brief Implementation of a DX11 compute shader.
  211. */
  212. class BS_D3D11_EXPORT D3D11GpuComputeProgramCore : public D3D11GpuProgramCore
  213. {
  214. public:
  215. ~D3D11GpuComputeProgramCore();
  216. /**
  217. * @brief Returns internal DX11 compute shader object.
  218. */
  219. ID3D11ComputeShader* getComputeShader() const;
  220. protected:
  221. friend class D3D11HLSLProgramFactory;
  222. /**
  223. * @copydoc GpuProgramCore::GpuProgramCore
  224. */
  225. D3D11GpuComputeProgramCore(const String& source, const String& entryPoint,
  226. GpuProgramProfile profile);
  227. /**
  228. * @copydoc GpuProgramCore::destroy
  229. */
  230. void destroy();
  231. /**
  232. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  233. */
  234. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  235. protected:
  236. ID3D11ComputeShader* mComputeShader;
  237. };
  238. }