BsD3D11GpuProgram.h 5.6 KB

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