BsD3D9GpuProgram.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsGpuProgram.h"
  4. #include "BsD3D9Resource.h"
  5. #include "BsD3D9EmulatedParamBlocks.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Available optimization levels when compiling a GPU program.
  10. */
  11. enum OptimizationLevel
  12. {
  13. OPT_DEFAULT,
  14. OPT_NONE,
  15. OPT_0,
  16. OPT_1,
  17. OPT_2,
  18. OPT_3
  19. };
  20. /**
  21. * @brief DirectX 9 implementation of a GPU program.
  22. */
  23. class BS_D3D9_EXPORT D3D9GpuProgram : public GpuProgram, public D3D9Resource
  24. {
  25. public:
  26. virtual ~D3D9GpuProgram();
  27. /**
  28. * @copydoc GpuProgram::requiresMatrixTranspose
  29. */
  30. virtual bool requiresMatrixTranspose() const { return mColumnMajorMatrices; }
  31. /**
  32. * @brief Sets the preprocessor defines use to compile the program.
  33. */
  34. void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
  35. /**
  36. * @brief Sets whether matrix packing in column-major order.
  37. */
  38. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  39. /**
  40. * @brief Sets optimization level to use when compiling the shader.
  41. */
  42. void setOptimizationLevel(OptimizationLevel opt) { mOptimisationLevel = opt; }
  43. /**
  44. * @copydoc GpuProgram::createParameters
  45. */
  46. GpuParamsPtr createParameters();
  47. /**
  48. * @copydoc GpuProgram::getLanguage
  49. */
  50. const String& getLanguage() const;
  51. protected:
  52. friend class D3D9HLSLProgramFactory;
  53. D3D9GpuProgram(const String& source, const String& entryPoint,
  54. GpuProgramType gptype, GpuProgramProfile profile,
  55. const Vector<HGpuProgInclude>* includes);
  56. /**
  57. * @copydoc GpuProgram::initialize_internal
  58. */
  59. void initialize_internal();
  60. /**
  61. * @copydoc GpuProgram::destroy_internal
  62. */
  63. void destroy_internal();
  64. /**
  65. * @brief Loads the GPU program from compiled microcode.
  66. */
  67. virtual void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode) = 0;
  68. protected:
  69. OptimizationLevel mOptimisationLevel;
  70. String mPreprocessorDefines;
  71. Vector<D3D9EmulatedParamBlock> mBlocks;
  72. bool mColumnMajorMatrices;
  73. ID3DXBuffer* mMicrocode;
  74. /************************************************************************/
  75. /* SERIALIZATION */
  76. /************************************************************************/
  77. public:
  78. friend class D3D9GpuProgramRTTI;
  79. static RTTITypeBase* getRTTIStatic();
  80. virtual RTTITypeBase* getRTTI() const;
  81. };
  82. /**
  83. * @brief DirectX 9 implementation of a vertex GPU program.
  84. */
  85. class BS_D3D9_EXPORT D3D9GpuVertexProgram : public D3D9GpuProgram
  86. {
  87. public:
  88. ~D3D9GpuVertexProgram();
  89. /**
  90. * @brief Returns internal DX9 vertex shader object.
  91. */
  92. IDirect3DVertexShader9* getVertexShader();
  93. /**
  94. * @copydoc D3D9Resource::notifyOnDeviceCreate
  95. */
  96. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  97. /**
  98. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  99. */
  100. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  101. protected:
  102. friend class D3D9HLSLProgramFactory;
  103. D3D9GpuVertexProgram(const String& source, const String& entryPoint, GpuProgramProfile profile,
  104. const Vector<HGpuProgInclude>* includes);
  105. /**
  106. * @copydoc D3D9GpuProgram::destroy_internal.
  107. */
  108. void destroy_internal();
  109. /**
  110. * @copydoc D3D9GpuProgram::loadFromMicrocode
  111. */
  112. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  113. protected:
  114. Map<IDirect3DDevice9*, IDirect3DVertexShader9*> mMapDeviceToVertexShader;
  115. /************************************************************************/
  116. /* SERIALIZATION */
  117. /************************************************************************/
  118. public:
  119. friend class D3D9GpuVertexProgramRTTI;
  120. static RTTITypeBase* getRTTIStatic();
  121. virtual RTTITypeBase* getRTTI() const;
  122. };
  123. /** Direct3D implementation of low-level fragment programs. */
  124. class BS_D3D9_EXPORT D3D9GpuFragmentProgram : public D3D9GpuProgram
  125. {
  126. public:
  127. ~D3D9GpuFragmentProgram();
  128. /**
  129. * @brief Returns internal DX9 pixel shader object.
  130. */
  131. IDirect3DPixelShader9* getPixelShader();
  132. /**
  133. * @copydoc D3D9Resource::notifyOnDeviceCreate
  134. */
  135. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  136. /**
  137. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  138. */
  139. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  140. protected:
  141. friend class D3D9HLSLProgramFactory;
  142. D3D9GpuFragmentProgram(const String& source, const String& entryPoint, GpuProgramProfile profile,
  143. const Vector<HGpuProgInclude>* includes);
  144. /**
  145. * @copydoc D3D9GpuProgram::destroy_internal.
  146. */
  147. void destroy_internal();
  148. /**
  149. * @copydoc D3D9GpuProgram::loadFromMicrocode
  150. */
  151. void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
  152. protected:
  153. Map<IDirect3DDevice9*, IDirect3DPixelShader9*> mMapDeviceToPixelShader;
  154. /************************************************************************/
  155. /* SERIALIZATION */
  156. /************************************************************************/
  157. public:
  158. friend class D3D9GpuFragmentProgramRTTI;
  159. static RTTITypeBase* getRTTIStatic();
  160. virtual RTTITypeBase* getRTTI() const;
  161. };
  162. typedef std::shared_ptr<D3D9GpuProgram> D3D9GpuProgramPtr;
  163. }