CmD3D11HLSLProgram.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "CmD3D11Prerequisites.h"
  3. #include "CmHighLevelGpuProgram.h"
  4. namespace CamelotEngine
  5. {
  6. class D3D11HLSLProgram : public HighLevelGpuProgram
  7. {
  8. public:
  9. ~D3D11HLSLProgram();
  10. const String& getLanguage() const;
  11. bool isSupported() const;
  12. /** Sets whether matrix packing in column-major order. */
  13. void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
  14. /** Gets whether matrix packed in column-major order. */
  15. bool getColumnMajorMatrices() const { return mColumnMajorMatrices; }
  16. /** Sets whether backwards compatibility is enabled. */
  17. void setEnableBackwardsCompatibility(bool enableBackwardsCompatibility) { mEnableBackwardsCompatibility = enableBackwardsCompatibility; }
  18. /** Gets whether backwards compatibility is enabled. */
  19. bool getEnableBackwardsCompatibility() const { return mEnableBackwardsCompatibility; }
  20. const HLSLMicroCode& getMicroCode() const { return mMicrocode; }
  21. UINT32 getNumInputs() const { return (UINT32)mInputParameters.size(); }
  22. UINT32 getNumOutputs() const { return (UINT32)mOutputParameters.size(); }
  23. const D3D11_SIGNATURE_PARAMETER_DESC& getInputParamDesc(unsigned int index) const { return mInputParameters.at(index); }
  24. const D3D11_SIGNATURE_PARAMETER_DESC& getOutputParamDesc(unsigned int index) const { return mOutputParameters.at(index); }
  25. protected:
  26. friend class D3D11HLSLProgramFactory;
  27. D3D11HLSLProgram(const String& source, const String& entryPoint, const String& language,
  28. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
  29. /**
  30. * @copydoc GpuProgram::loadFromSource()
  31. */
  32. void loadFromSource();
  33. /**
  34. * @copydoc GpuProgram::unload_internal()
  35. */
  36. void unload_internal();
  37. /**
  38. * @copydoc HighLevelGpuProgram::buildConstantDefinitions()
  39. */
  40. void buildConstantDefinitions() const;
  41. private:
  42. bool mColumnMajorMatrices;
  43. bool mEnableBackwardsCompatibility;
  44. HLSLMicroCode mMicrocode;
  45. struct D3D11_VariableDesc
  46. {
  47. String name;
  48. D3D11_SHADER_TYPE_DESC desc;
  49. };
  50. struct D3D11_ShaderBufferDesc
  51. {
  52. D3D11_SHADER_BUFFER_DESC desc;
  53. vector<D3D11_SHADER_VARIABLE_DESC>::type variables;
  54. vector<D3D11_SHADER_TYPE_DESC>::type variableTypes;
  55. };
  56. vector<D3D11_ShaderBufferDesc>::type mShaderBuffers;
  57. vector<D3D11_SIGNATURE_PARAMETER_DESC>::type mInputParameters;
  58. vector<D3D11_SIGNATURE_PARAMETER_DESC>::type mOutputParameters;
  59. vector<HardwareConstantBufferPtr>::type mConstantBuffers;
  60. /**
  61. * @brief Compiles the shader from source and generates the microcode.
  62. */
  63. ID3DBlob* compileMicrocode();
  64. /**
  65. * @brief Reflects the microcode and extracts input/output parameters, and constant
  66. * buffer structures used by the program.
  67. */
  68. void populateParametersAndConstants(ID3DBlob* microcode);
  69. void populateConstantBufferParameters(ID3D11ShaderReflectionConstantBuffer* bufferReflection);
  70. void populateParameterDefinition(const D3D11_SHADER_VARIABLE_DESC& paramDesc, const D3D11_SHADER_TYPE_DESC& d3dDesc, GpuConstantDefinition& def) const;
  71. /**
  72. * @brief Creates constant buffers based on available parameter and constant data.
  73. */
  74. void createConstantBuffers();
  75. };
  76. }