CmD3D11GpuProgram.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #include "CmD3D11GpuProgram.h"
  2. #include "CmD3D11Device.h"
  3. #include "CmException.h"
  4. #include "CmDebug.h"
  5. namespace CamelotEngine
  6. {
  7. D3D11GpuProgram::D3D11GpuProgram(GpuProgramType type, const String& profile)
  8. : GpuProgram("", "", profile, type, GPP_NONE)
  9. {
  10. }
  11. void D3D11GpuProgram::loadImpl(void)
  12. {
  13. // Call polymorphic load
  14. loadFromSource();
  15. }
  16. void D3D11GpuProgram::loadFromSource(void)
  17. {
  18. }
  19. D3D11GpuVertexProgram::D3D11GpuVertexProgram(const String& profile)
  20. : D3D11GpuProgram(GPT_VERTEX_PROGRAM, profile)
  21. , mVertexShader(nullptr)
  22. { }
  23. D3D11GpuVertexProgram::~D3D11GpuVertexProgram()
  24. { }
  25. void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  26. {
  27. if (isSupported())
  28. {
  29. // Create the shader
  30. HRESULT hr = device.getD3D11Device()->CreateVertexShader(
  31. static_cast<DWORD*>(microcode->GetBufferPointer()),
  32. microcode->GetBufferSize(),
  33. device.getClassLinkage(),
  34. &mVertexShader);
  35. if (FAILED(hr) || device.hasError())
  36. {
  37. String errorDescription = device.getErrorDescription();
  38. CM_EXCEPT(RenderingAPIException,
  39. "Cannot create D3D11 vertex shader from microcode\nError Description:" + errorDescription);
  40. }
  41. }
  42. else
  43. {
  44. LOGWRN("Unsupported D3D11 vertex shader was not loaded.");
  45. }
  46. }
  47. void D3D11GpuVertexProgram::destroy_internal()
  48. {
  49. SAFE_RELEASE(mVertexShader);
  50. D3D11GpuProgram::destroy_internal();
  51. }
  52. ID3D11VertexShader * D3D11GpuVertexProgram::getVertexShader( void ) const
  53. {
  54. return mVertexShader;
  55. }
  56. D3D11GpuFragmentProgram::D3D11GpuFragmentProgram(const String& profile)
  57. : D3D11GpuProgram(GPT_FRAGMENT_PROGRAM, profile)
  58. , mPixelShader(nullptr)
  59. { }
  60. D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
  61. { }
  62. void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  63. {
  64. if (isSupported())
  65. {
  66. // Create the shader
  67. HRESULT hr = device.getD3D11Device()->CreatePixelShader(
  68. static_cast<DWORD*>(microcode->GetBufferPointer()),
  69. microcode->GetBufferSize(),
  70. device.getClassLinkage(),
  71. &mPixelShader);
  72. if (FAILED(hr) || device.hasError())
  73. {
  74. String errorDescription = device.getErrorDescription();
  75. CM_EXCEPT(RenderingAPIException,
  76. "Cannot create D3D11 pixel shader from microcode.\nError Description:" + errorDescription);
  77. }
  78. }
  79. else
  80. {
  81. LOGWRN("Unsupported D3D11 pixel shader was not loaded.");
  82. }
  83. }
  84. void D3D11GpuFragmentProgram::destroy_internal()
  85. {
  86. SAFE_RELEASE(mPixelShader);
  87. D3D11GpuProgram::destroy_internal();
  88. }
  89. ID3D11PixelShader * D3D11GpuFragmentProgram::getPixelShader( void ) const
  90. {
  91. return mPixelShader;
  92. }
  93. D3D11GpuGeometryProgram::D3D11GpuGeometryProgram(const String& profile)
  94. : D3D11GpuProgram(GPT_GEOMETRY_PROGRAM, profile)
  95. , mGeometryShader(nullptr)
  96. { }
  97. D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
  98. { }
  99. void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  100. {
  101. if (isSupported())
  102. {
  103. // Create the shader
  104. HRESULT hr = device.getD3D11Device()->CreateGeometryShader(
  105. static_cast<DWORD*>(microcode->GetBufferPointer()),
  106. microcode->GetBufferSize(),
  107. device.getClassLinkage(),
  108. &mGeometryShader);
  109. if (FAILED(hr) || device.hasError())
  110. {
  111. String errorDescription = device.getErrorDescription();
  112. CM_EXCEPT(RenderingAPIException,
  113. "Cannot create D3D11 geometry shader from microcode.\nError Description:" + errorDescription);
  114. }
  115. }
  116. else
  117. {
  118. LOGWRN("Unsupported D3D11 geometry shader was not loaded.");
  119. }
  120. }
  121. void D3D11GpuGeometryProgram::destroy_internal()
  122. {
  123. SAFE_RELEASE(mGeometryShader);
  124. D3D11GpuProgram::destroy_internal();
  125. }
  126. ID3D11GeometryShader * D3D11GpuGeometryProgram::getGeometryShader(void) const
  127. {
  128. return mGeometryShader;
  129. }
  130. D3D11GpuDomainProgram::D3D11GpuDomainProgram(const String& profile)
  131. : D3D11GpuProgram(GPT_DOMAIN_PROGRAM, profile)
  132. , mDomainShader(nullptr)
  133. { }
  134. D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
  135. { }
  136. void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  137. {
  138. if (isSupported())
  139. {
  140. // Create the shader
  141. HRESULT hr = device.getD3D11Device()->CreateDomainShader(
  142. static_cast<DWORD*>(microcode->GetBufferPointer()),
  143. microcode->GetBufferSize(),
  144. device.getClassLinkage(),
  145. &mDomainShader);
  146. if (FAILED(hr) || device.hasError())
  147. {
  148. String errorDescription = device.getErrorDescription();
  149. CM_EXCEPT(RenderingAPIException,
  150. "Cannot create D3D11 domain shader from microcode.\nError Description:" + errorDescription);
  151. }
  152. }
  153. else
  154. {
  155. LOGWRN("Unsupported D3D11 domain shader was not loaded.");
  156. }
  157. }
  158. void D3D11GpuDomainProgram::destroy_internal()
  159. {
  160. SAFE_RELEASE(mDomainShader);
  161. D3D11GpuProgram::destroy_internal();
  162. }
  163. ID3D11DomainShader * D3D11GpuDomainProgram::getDomainShader(void) const
  164. {
  165. return mDomainShader;
  166. }
  167. D3D11GpuHullProgram::D3D11GpuHullProgram(const String& profile)
  168. : D3D11GpuProgram(GPT_HULL_PROGRAM, profile)
  169. , mHullShader(nullptr)
  170. { }
  171. D3D11GpuHullProgram::~D3D11GpuHullProgram()
  172. { }
  173. void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  174. {
  175. if (isSupported())
  176. {
  177. // Create the shader
  178. HRESULT hr = device.getD3D11Device()->CreateHullShader(
  179. static_cast<DWORD*>(microcode->GetBufferPointer()),
  180. microcode->GetBufferSize(),
  181. device.getClassLinkage(),
  182. &mHullShader);
  183. if (FAILED(hr) || device.hasError())
  184. {
  185. String errorDescription = device.getErrorDescription();
  186. CM_EXCEPT(RenderingAPIException,
  187. "Cannot create D3D11 hull shader from microcode.\nError Description:" + errorDescription);
  188. }
  189. }
  190. else
  191. {
  192. LOGWRN("Unsupported D3D11 hull shader was not loaded.");
  193. }
  194. }
  195. void D3D11GpuHullProgram::destroy_internal()
  196. {
  197. SAFE_RELEASE(mHullShader);
  198. D3D11GpuProgram::destroy_internal();
  199. }
  200. ID3D11HullShader* D3D11GpuHullProgram::getHullShader(void) const
  201. {
  202. return mHullShader;
  203. }
  204. D3D11GpuComputeProgram::D3D11GpuComputeProgram(const String& profile)
  205. : D3D11GpuProgram(GPT_COMPUTE_PROGRAM, profile)
  206. , mComputeShader(nullptr)
  207. { }
  208. D3D11GpuComputeProgram::~D3D11GpuComputeProgram()
  209. { }
  210. void D3D11GpuComputeProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
  211. {
  212. if (isSupported())
  213. {
  214. // Create the shader
  215. HRESULT hr = device.getD3D11Device()->CreateComputeShader(
  216. static_cast<DWORD*>(microcode->GetBufferPointer()),
  217. microcode->GetBufferSize(),
  218. device.getClassLinkage(),
  219. &mComputeShader);
  220. if (FAILED(hr) || device.hasError())
  221. {
  222. String errorDescription = device.getErrorDescription();
  223. CM_EXCEPT(RenderingAPIException,
  224. "Cannot create D3D11 compute shader from microcode.\nError Description:" + errorDescription);
  225. }
  226. }
  227. else
  228. {
  229. LOGWRN("Unsupported D3D11 compute shader was not loaded.");
  230. }
  231. }
  232. void D3D11GpuComputeProgram::destroy_internal()
  233. {
  234. SAFE_RELEASE(mComputeShader);
  235. D3D11GpuProgram::destroy_internal();
  236. }
  237. ID3D11ComputeShader* D3D11GpuComputeProgram::getComputeShader(void) const
  238. {
  239. return mComputeShader;
  240. }
  241. }