CmD3D11GpuProgram.cpp 7.1 KB

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