BsD3D11GpuProgram.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /** @addtogroup D3D11
  9. * @{
  10. */
  11. /** Abstraction of a DirectX 11 shader object. */
  12. class BS_D3D11_EXPORT D3D11GpuProgramCore : public GpuProgramCore
  13. {
  14. public:
  15. virtual ~D3D11GpuProgramCore();
  16. /** Returns compiled shader microcode. */
  17. const HLSLMicroCode& getMicroCode() const { return mMicrocode; }
  18. /** Returns unique GPU program ID. */
  19. UINT32 getProgramId() const { return mProgramId; }
  20. protected:
  21. /** @copydoc GpuProgramCore::GpuProgramCore */
  22. D3D11GpuProgramCore(const String& source, const String& entryPoint, GpuProgramType gptype,
  23. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  24. /** @copydoc GpuProgramCore::initialize */
  25. void initialize() override;
  26. /** Loads the shader from microcode. */
  27. virtual void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) = 0;
  28. /** Compiles the shader from source and generates the microcode. */
  29. ID3DBlob* compileMicrocode(const String& profile);
  30. /**
  31. * Reflects the microcode and extracts input/output parameters, and constant buffer structures used by the program.
  32. */
  33. void populateParametersAndConstants(ID3DBlob* microcode);
  34. protected:
  35. static UINT32 GlobalProgramId;
  36. bool mEnableBackwardsCompatibility;
  37. UINT32 mProgramId;
  38. HLSLMicroCode mMicrocode;
  39. };
  40. /** Implementation of a DX11 vertex shader. */
  41. class BS_D3D11_EXPORT D3D11GpuVertexProgramCore : public D3D11GpuProgramCore
  42. {
  43. public:
  44. ~D3D11GpuVertexProgramCore();
  45. /** Returns internal DX11 vertex shader object. */
  46. ID3D11VertexShader* getVertexShader() const;
  47. protected:
  48. friend class D3D11HLSLProgramFactory;
  49. /** @copydoc GpuProgramCore::GpuProgramCore */
  50. D3D11GpuVertexProgramCore(const String& source, const String& entryPoint,
  51. GpuProgramProfile profile);
  52. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  53. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  54. protected:
  55. ID3D11VertexShader* mVertexShader;
  56. };
  57. /** Implementation of a DX11 pixel shader. */
  58. class BS_D3D11_EXPORT D3D11GpuFragmentProgramCore : public D3D11GpuProgramCore
  59. {
  60. public:
  61. ~D3D11GpuFragmentProgramCore();
  62. /** Returns internal DX11 pixel shader object. */
  63. ID3D11PixelShader* getPixelShader() const;
  64. protected:
  65. friend class D3D11HLSLProgramFactory;
  66. /** @copydoc GpuProgramCore::GpuProgramCore */
  67. D3D11GpuFragmentProgramCore(const String& source, const String& entryPoint,
  68. GpuProgramProfile profile);
  69. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  70. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  71. protected:
  72. ID3D11PixelShader* mPixelShader;
  73. };
  74. /** Implementation of a DX11 domain shader. */
  75. class BS_D3D11_EXPORT D3D11GpuDomainProgramCore : public D3D11GpuProgramCore
  76. {
  77. public:
  78. ~D3D11GpuDomainProgramCore();
  79. /** Returns internal DX11 domain shader object. */
  80. ID3D11DomainShader* getDomainShader() const;
  81. protected:
  82. friend class D3D11HLSLProgramFactory;
  83. /** @copydoc GpuProgramCore::GpuProgramCore */
  84. D3D11GpuDomainProgramCore(const String& source, const String& entryPoint,
  85. GpuProgramProfile profile);
  86. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  87. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  88. protected:
  89. ID3D11DomainShader* mDomainShader;
  90. };
  91. /** Implementation of a DX11 hull shader. */
  92. class BS_D3D11_EXPORT D3D11GpuHullProgramCore : public D3D11GpuProgramCore
  93. {
  94. public:
  95. ~D3D11GpuHullProgramCore();
  96. /** Returns internal DX11 hull shader object. */
  97. ID3D11HullShader* getHullShader() const;
  98. protected:
  99. friend class D3D11HLSLProgramFactory;
  100. /** @copydoc GpuProgramCore::GpuProgramCore */
  101. D3D11GpuHullProgramCore(const String& source, const String& entryPoint,
  102. GpuProgramProfile profile);
  103. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  104. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  105. protected:
  106. ID3D11HullShader* mHullShader;
  107. };
  108. /** Implementation of a DX11 geometry shader. */
  109. class BS_D3D11_EXPORT D3D11GpuGeometryProgramCore : public D3D11GpuProgramCore
  110. {
  111. public:
  112. ~D3D11GpuGeometryProgramCore();
  113. /** Returns internal DX11 geometry shader object. */
  114. ID3D11GeometryShader* getGeometryShader() const;
  115. protected:
  116. friend class D3D11HLSLProgramFactory;
  117. /** @copydoc GpuProgramCore::GpuProgramCore */
  118. D3D11GpuGeometryProgramCore(const String& source, const String& entryPoint,
  119. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  120. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  121. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  122. protected:
  123. ID3D11GeometryShader* mGeometryShader;
  124. };
  125. /** Implementation of a DX11 compute shader. */
  126. class BS_D3D11_EXPORT D3D11GpuComputeProgramCore : public D3D11GpuProgramCore
  127. {
  128. public:
  129. ~D3D11GpuComputeProgramCore();
  130. /** Returns internal DX11 compute shader object. */
  131. ID3D11ComputeShader* getComputeShader() const;
  132. protected:
  133. friend class D3D11HLSLProgramFactory;
  134. /** @copydoc GpuProgramCore::GpuProgramCore */
  135. D3D11GpuComputeProgramCore(const String& source, const String& entryPoint,
  136. GpuProgramProfile profile);
  137. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  138. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  139. protected:
  140. ID3D11ComputeShader* mComputeShader;
  141. };
  142. /** @} */
  143. }