BsD3D11GpuProgram.h 5.4 KB

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