BsD3D11GpuProgram.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. * @brief Loads the 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. static UINT32 GlobalProgramId;
  54. bool mColumnMajorMatrices;
  55. bool mEnableBackwardsCompatibility;
  56. UINT32 mProgramId;
  57. HLSLMicroCode mMicrocode;
  58. SPtr<VertexDeclarationCore> mInputDeclaration;
  59. };
  60. /**
  61. * @brief Implementation of a DX11 vertex shader.
  62. */
  63. class BS_D3D11_EXPORT D3D11GpuVertexProgramCore : public D3D11GpuProgramCore
  64. {
  65. public:
  66. ~D3D11GpuVertexProgramCore();
  67. /**
  68. * @brief Returns internal DX11 vertex shader object.
  69. */
  70. ID3D11VertexShader* getVertexShader() const;
  71. protected:
  72. friend class D3D11HLSLProgramFactory;
  73. /**
  74. * @copydoc GpuProgramCore::GpuProgramCore
  75. */
  76. D3D11GpuVertexProgramCore(const String& source, const String& entryPoint,
  77. GpuProgramProfile profile);
  78. /**
  79. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  80. */
  81. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  82. protected:
  83. ID3D11VertexShader* mVertexShader;
  84. };
  85. /**
  86. * @brief Implementation of a DX11 pixel shader.
  87. */
  88. class BS_D3D11_EXPORT D3D11GpuFragmentProgramCore : public D3D11GpuProgramCore
  89. {
  90. public:
  91. ~D3D11GpuFragmentProgramCore();
  92. /**
  93. * @brief Returns internal DX11 pixel shader object.
  94. */
  95. ID3D11PixelShader* getPixelShader() const;
  96. protected:
  97. friend class D3D11HLSLProgramFactory;
  98. /**
  99. * @copydoc GpuProgramCore::GpuProgramCore
  100. */
  101. D3D11GpuFragmentProgramCore(const String& source, const String& entryPoint,
  102. GpuProgramProfile profile);
  103. /**
  104. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  105. */
  106. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  107. protected:
  108. ID3D11PixelShader* mPixelShader;
  109. };
  110. /**
  111. * @brief Implementation of a DX11 domain shader.
  112. */
  113. class BS_D3D11_EXPORT D3D11GpuDomainProgramCore : public D3D11GpuProgramCore
  114. {
  115. public:
  116. ~D3D11GpuDomainProgramCore();
  117. /**
  118. * @brief Returns internal DX11 domain shader object.
  119. */
  120. ID3D11DomainShader* getDomainShader() const;
  121. protected:
  122. friend class D3D11HLSLProgramFactory;
  123. /**
  124. * @copydoc GpuProgramCore::GpuProgramCore
  125. */
  126. D3D11GpuDomainProgramCore(const String& source, const String& entryPoint,
  127. GpuProgramProfile profile);
  128. /**
  129. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  130. */
  131. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  132. protected:
  133. ID3D11DomainShader* mDomainShader;
  134. };
  135. /**
  136. * @brief Implementation of a DX11 hull shader.
  137. */
  138. class BS_D3D11_EXPORT D3D11GpuHullProgramCore : public D3D11GpuProgramCore
  139. {
  140. public:
  141. ~D3D11GpuHullProgramCore();
  142. /**
  143. * @brief Returns internal DX11 hull shader object.
  144. */
  145. ID3D11HullShader* getHullShader() const;
  146. protected:
  147. friend class D3D11HLSLProgramFactory;
  148. /**
  149. * @copydoc GpuProgramCore::GpuProgramCore
  150. */
  151. D3D11GpuHullProgramCore(const String& source, const String& entryPoint,
  152. GpuProgramProfile profile);
  153. /**
  154. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  155. */
  156. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  157. protected:
  158. ID3D11HullShader* mHullShader;
  159. };
  160. /**
  161. * @brief Implementation of a DX11 geometry shader.
  162. */
  163. class BS_D3D11_EXPORT D3D11GpuGeometryProgramCore : public D3D11GpuProgramCore
  164. {
  165. public:
  166. ~D3D11GpuGeometryProgramCore();
  167. /**
  168. * @brief Returns internal DX11 geometry shader object.
  169. */
  170. ID3D11GeometryShader* getGeometryShader() const;
  171. protected:
  172. friend class D3D11HLSLProgramFactory;
  173. /**
  174. * @copydoc GpuProgramCore::GpuProgramCore
  175. */
  176. D3D11GpuGeometryProgramCore(const String& source, const String& entryPoint,
  177. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  178. /**
  179. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  180. */
  181. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  182. protected:
  183. ID3D11GeometryShader* mGeometryShader;
  184. };
  185. /**
  186. * @brief Implementation of a DX11 compute shader.
  187. */
  188. class BS_D3D11_EXPORT D3D11GpuComputeProgramCore : public D3D11GpuProgramCore
  189. {
  190. public:
  191. ~D3D11GpuComputeProgramCore();
  192. /**
  193. * @brief Returns internal DX11 compute shader object.
  194. */
  195. ID3D11ComputeShader* getComputeShader() const;
  196. protected:
  197. friend class D3D11HLSLProgramFactory;
  198. /**
  199. * @copydoc GpuProgramCore::GpuProgramCore
  200. */
  201. D3D11GpuComputeProgramCore(const String& source, const String& entryPoint,
  202. GpuProgramProfile profile);
  203. /**
  204. * @copydoc D3D11GpuProgramCore::loadFromMicrocode
  205. */
  206. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
  207. protected:
  208. ID3D11ComputeShader* mComputeShader;
  209. };
  210. }