DX12Shader.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "DX12Buffer.h"
  3. #include "Shader.h"
  4. struct ID3D12Device;
  5. struct ID3D12GraphicsCommandList;
  6. struct D3D12_INPUT_ELEMENT_DESC;
  7. struct D3D12_ROOT_PARAMETER1;
  8. struct D3D12_CONSTANT_BUFFER_VIEW_DESC;
  9. namespace Framework
  10. {
  11. class DX12Shader : public Shader
  12. {
  13. protected:
  14. ID3D12Device* device;
  15. DX12CopyCommandQueue* copy;
  16. DX12DirectCommandQueue* direct;
  17. unsigned char* shaderByteBuffer;
  18. int byteBufferSize;
  19. public:
  20. DX12Shader(ID3D12Device* device,
  21. DX12CopyCommandQueue* copy,
  22. DX12DirectCommandQueue* direct);
  23. virtual ~DX12Shader();
  24. //! Creates a constant buffer that passes constant data to the shader.
  25. //! A maximum of 14 buffers can be created.
  26. //! zD3d11Device: The device with which the buffer should be created
  27. //! \param size The size of the buffer in bytes
  28. //! \param index The position of the buffer in the buffer array. An
  29. //! existing buffer will be replaced. Buffer 1 cannot be created
  30. //! if buffer 0 has not been created yet, etc.
  31. virtual bool createConstBuffer(int size, int index) override;
  32. //! Sets the compiled shader
  33. //! zD3d11Device: The device with which the shader should be created
  34. //! \param bytes The bytes of the compiled code
  35. //! \param length The length of the byte array
  36. //! \return true if bytes is valid, false otherwise
  37. bool setCompiledByteArray(unsigned char* bytes, int length) override;
  38. //! After calling this function, this shader is used as a pixel shader
  39. //! zD3d11Context: The context object with which the shader should
  40. //! be used
  41. void useShader() override;
  42. //! Returns the compiled bytes
  43. unsigned char* getCompiledShader() const;
  44. //! Returns the number of compiled bytes
  45. int getCompiledLength() const;
  46. //! Creates the RootParameter for a constant buffer
  47. //! \param index The index of the buffer
  48. //! \param view Contains the position and size of the buffer
  49. //! in memory after the call
  50. virtual void getViewDesc(
  51. int index, D3D12_CONSTANT_BUFFER_VIEW_DESC& view);
  52. };
  53. class DX12PixelShader : public DX12Shader
  54. {
  55. public:
  56. DX12PixelShader(ID3D12Device* device,
  57. DX12CopyCommandQueue* copy,
  58. DX12DirectCommandQueue* direct);
  59. };
  60. class DX12VertexShader : public DX12Shader
  61. {
  62. private:
  63. D3D12_INPUT_ELEMENT_DESC* inputLayout;
  64. int inputLayoutSize;
  65. public:
  66. //! Constructor
  67. DX12VertexShader(ID3D12Device* device,
  68. DX12CopyCommandQueue* copy,
  69. DX12DirectCommandQueue* direct);
  70. //! Destructor
  71. ~DX12VertexShader();
  72. //! Creates an input layout for the shader.
  73. //! May only be called after compile.
  74. //! zD3d11Device: The device with which the layout should be created
  75. //! \param descArray An array with initialization data
  76. //! \param anz The number of elements in the array
  77. bool createInputLayout(D3D12_INPUT_ELEMENT_DESC* descArray, int anz);
  78. //! Returns the number of input parameters of the shader
  79. int getInputLayoutSize() const;
  80. //! Returns a list of formats for each input value
  81. D3D12_INPUT_ELEMENT_DESC* zInputLayout() const;
  82. };
  83. } // namespace Framework