DX12Shader.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "DX12Buffer.h"
  3. #include "Shader.h"
  4. struct ID3D12Device5;
  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. ID3D12Device5* device;
  15. DX12CopyCommandQueue* copy;
  16. DX12DirectCommandQueue* direct;
  17. unsigned char* shaderByteBuffer;
  18. int byteBufferSize;
  19. public:
  20. DX12Shader(ID3D12Device5* 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. } // namespace Framework