CmD3D11HLSLProgram.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /**
  60. * @brief Compiles the shader from source and generates the microcode.
  61. */
  62. ID3DBlob* compileMicrocode();
  63. /**
  64. * @brief Reflects the microcode and extracts input/output parameters, and constant
  65. * buffer structures used by the program.
  66. */
  67. void populateParametersAndConstants(ID3DBlob* microcode);
  68. //void populateConstantBufferParameters(ID3D11ShaderReflectionConstantBuffer* bufferReflection);
  69. //void populateParameterDefinition(const D3D11_SHADER_VARIABLE_DESC& paramDesc, const D3D11_SHADER_TYPE_DESC& d3dDesc, GpuConstantDefinition& def) const;
  70. /**
  71. * @brief Creates constant buffers based on available parameter and constant data.
  72. */
  73. void createConstantBuffers();
  74. /************************************************************************/
  75. /* SERIALIZATION */
  76. /************************************************************************/
  77. public:
  78. friend class D3D11HLSLProgramRTTI;
  79. static RTTITypeBase* getRTTIStatic();
  80. virtual RTTITypeBase* getRTTI() const;
  81. };
  82. }