CmD3D11GpuProgram.cpp 7.1 KB

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