CmD3D11HLSLProgram.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "CmD3D11HLSLProgram.h"
  2. #include "CmRenderSystemManager.h"
  3. #include "CmRenderSystem.h"
  4. #include "CmException.h"
  5. namespace CamelotEngine
  6. {
  7. D3D11HLSLProgram::D3D11HLSLProgram(const String& source, const String& entryPoint, const String& language,
  8. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
  9. : HighLevelGpuProgram(source, entryPoint, language, gptype, profile, isAdjacencyInfoRequired),
  10. mColumnMajorMatrices(true), mEnableBackwardsCompatibility(false)
  11. {
  12. }
  13. D3D11HLSLProgram::~D3D11HLSLProgram()
  14. {
  15. unloadHighLevel();
  16. }
  17. const String& D3D11HLSLProgram::getLanguage() const
  18. {
  19. static String name = "hlsl";
  20. return name;
  21. }
  22. bool D3D11HLSLProgram::isSupported() const
  23. {
  24. RenderSystem* rs = RenderSystemManager::getActive();
  25. return rs->getCapabilities_internal()->isShaderProfileSupported(getSyntaxCode()) && HighLevelGpuProgram::isSupported();
  26. }
  27. ID3DBlob* D3D11HLSLProgram::compileMicrocode()
  28. {
  29. // TODO - Preprocessor defines aren't supported
  30. UINT compileFlags = 0;
  31. #if defined(CM_DEBUG_MODE)
  32. compileFlags |= D3DCOMPILE_DEBUG;
  33. compileFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
  34. #endif
  35. if (mColumnMajorMatrices)
  36. compileFlags |= D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR;
  37. else
  38. compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
  39. if (mEnableBackwardsCompatibility)
  40. compileFlags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
  41. ID3DBlob* microCode = nullptr;
  42. ID3DBlob* errors = nullptr;
  43. HRESULT hr = D3DCompile(
  44. mSource.c_str(), // [in] Pointer to the shader in memory.
  45. mSource.size(), // [in] Size of the shader in memory.
  46. nullptr, // [in] The name of the file that contains the shader code.
  47. nullptr, // [in] Optional. Pointer to a NULL-terminated array of macro definitions. See D3D_SHADER_MACRO. If not used, set this to NULL.
  48. nullptr, // [in] Optional. Pointer to an ID3DInclude Interface interface for handling include files. Setting this to NULL will cause a compile error if a shader contains a #include.
  49. mEntryPoint.c_str(),// [in] Name of the shader-entrypoint function where shader execution begins.
  50. mSyntaxCode.c_str(),// [in] A string that specifies the shader model; can be any profile in shader model 4 or higher.
  51. compileFlags, // [in] Effect compile flags - no D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY at the first try...
  52. 0, // [in] Effect compile flags
  53. &microCode, // [out] A pointer to an ID3DBlob Interface which contains the compiled shader, as well as any embedded debug and symbol-table information.
  54. &errors // [out] A pointer to an ID3DBlob Interface which contains a listing of errors and warnings that occurred during compilation. These errors and warnings are identical to the the debug output from a debugger.
  55. );
  56. if (FAILED(hr))
  57. {
  58. String message = "Cannot assemble D3D11 high-level shader. Errors:\n" +
  59. String(static_cast<const char*>(errors->GetBufferPointer()));
  60. SAFE_RELEASE(errors);
  61. CM_EXCEPT(RenderingAPIException, message);
  62. }
  63. SAFE_RELEASE(errors);
  64. return microCode;
  65. }
  66. const HLSLMicroCode& D3D11HLSLProgram::getMicroCode() const
  67. {
  68. CM_EXCEPT(NotImplementedException, "Not implemented");
  69. }
  70. unsigned int D3D11HLSLProgram::getNumInputs() const
  71. {
  72. CM_EXCEPT(NotImplementedException, "Not implemented");
  73. }
  74. unsigned int D3D11HLSLProgram::getNumOutputs() const
  75. {
  76. CM_EXCEPT(NotImplementedException, "Not implemented");
  77. }
  78. const D3D11_SIGNATURE_PARAMETER_DESC& D3D11HLSLProgram::getInputParamDesc(unsigned int index) const
  79. {
  80. CM_EXCEPT(NotImplementedException, "Not implemented");
  81. }
  82. const D3D11_SIGNATURE_PARAMETER_DESC& D3D11HLSLProgram::getOutputParamDesc(unsigned int index) const
  83. {
  84. CM_EXCEPT(NotImplementedException, "Not implemented");
  85. }
  86. }