BsD3D11GpuProgram.h 6.1 KB

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