BsD3D11GpuProgram.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /** Parses compiler error message and returns the line number at which the error occurred. */
  34. UINT32 parseErrorMessage(const char* message);
  35. protected:
  36. static UINT32 GlobalProgramId;
  37. bool mEnableBackwardsCompatibility;
  38. UINT32 mProgramId;
  39. HLSLMicroCode mMicrocode;
  40. };
  41. /** Implementation of a DX11 vertex shader. */
  42. class BS_D3D11_EXPORT D3D11GpuVertexProgramCore : public D3D11GpuProgramCore
  43. {
  44. public:
  45. ~D3D11GpuVertexProgramCore();
  46. /** Returns internal DX11 vertex shader object. */
  47. ID3D11VertexShader* getVertexShader() const;
  48. protected:
  49. friend class D3D11HLSLProgramFactory;
  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. D3D11GpuFragmentProgramCore(const String& source, const String& entryPoint,
  67. GpuProgramProfile profile);
  68. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  69. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  70. protected:
  71. ID3D11PixelShader* mPixelShader;
  72. };
  73. /** Implementation of a DX11 domain shader. */
  74. class BS_D3D11_EXPORT D3D11GpuDomainProgramCore : public D3D11GpuProgramCore
  75. {
  76. public:
  77. ~D3D11GpuDomainProgramCore();
  78. /** Returns internal DX11 domain shader object. */
  79. ID3D11DomainShader* getDomainShader() const;
  80. protected:
  81. friend class D3D11HLSLProgramFactory;
  82. D3D11GpuDomainProgramCore(const String& source, const String& entryPoint,
  83. GpuProgramProfile profile);
  84. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  85. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  86. protected:
  87. ID3D11DomainShader* mDomainShader;
  88. };
  89. /** Implementation of a DX11 hull shader. */
  90. class BS_D3D11_EXPORT D3D11GpuHullProgramCore : public D3D11GpuProgramCore
  91. {
  92. public:
  93. ~D3D11GpuHullProgramCore();
  94. /** Returns internal DX11 hull shader object. */
  95. ID3D11HullShader* getHullShader() const;
  96. protected:
  97. friend class D3D11HLSLProgramFactory;
  98. D3D11GpuHullProgramCore(const String& source, const String& entryPoint,
  99. GpuProgramProfile profile);
  100. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  101. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  102. protected:
  103. ID3D11HullShader* mHullShader;
  104. };
  105. /** Implementation of a DX11 geometry shader. */
  106. class BS_D3D11_EXPORT D3D11GpuGeometryProgramCore : public D3D11GpuProgramCore
  107. {
  108. public:
  109. ~D3D11GpuGeometryProgramCore();
  110. /** Returns internal DX11 geometry shader object. */
  111. ID3D11GeometryShader* getGeometryShader() const;
  112. protected:
  113. friend class D3D11HLSLProgramFactory;
  114. D3D11GpuGeometryProgramCore(const String& source, const String& entryPoint,
  115. GpuProgramProfile profile, bool isAdjacencyInfoRequired);
  116. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  117. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  118. protected:
  119. ID3D11GeometryShader* mGeometryShader;
  120. };
  121. /** Implementation of a DX11 compute shader. */
  122. class BS_D3D11_EXPORT D3D11GpuComputeProgramCore : public D3D11GpuProgramCore
  123. {
  124. public:
  125. ~D3D11GpuComputeProgramCore();
  126. /** Returns internal DX11 compute shader object. */
  127. ID3D11ComputeShader* getComputeShader() const;
  128. protected:
  129. friend class D3D11HLSLProgramFactory;
  130. D3D11GpuComputeProgramCore(const String& source, const String& entryPoint,
  131. GpuProgramProfile profile);
  132. /** @copydoc D3D11GpuProgramCore::loadFromMicrocode */
  133. void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode) override;
  134. protected:
  135. ID3D11ComputeShader* mComputeShader;
  136. };
  137. /** @} */
  138. }