BsD3D11GpuProgram.h 5.8 KB

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