HatchitGraphics
ht_vkpipeline.h
1 
25 #pragma once
26 
27 #include <ht_pipeline_base.h>
28 
29 #include <ht_vkrenderpass.h>
30 #include <ht_vkshader.h>
31 
32 #include <ht_vulkan.h>
33 
34 #include <cassert>
35 
36 namespace Hatchit {
37 
38  namespace Graphics {
39 
40  namespace Vulkan {
41 
42  class HT_API VKPipeline : public PipelineBase
43  {
44  public:
45  VKPipeline();
46  virtual ~VKPipeline();
47 
48  bool Initialize(const Resource::PipelineHandle& handle, const VkDevice& device, const VkDescriptorPool& descriptorPool);
49 
51  bool VUpdate() override;
52 
53  /* Add a map of existing shader variables into this pipeline
54  * \param shaderVariables the map of existing shader variables you want to add
55  */
56  bool VSetShaderVariables(ShaderVariableChunk* variables) override;
57 
58  bool VSetInt(size_t offset, int data) override;
59  bool VSetDouble(size_t offset, double data) override;
60  bool VSetFloat(size_t offset, float data) override;
61  bool VSetFloat2(size_t offset, Math::Vector2 data) override;
62  bool VSetFloat3(size_t offset, Math::Vector3 data) override;
63  bool VSetFloat4(size_t offset, Math::Vector4 data) override;
64  bool VSetMatrix4(size_t offset, Math::Matrix4 data) override;
65 
66  VkPipeline GetVKPipeline();
67 
68  void BindPipeline(const VkCommandBuffer& commandBuffer);
69 
70  protected:
71  //Input
72  VkDevice m_device;
73  VkDescriptorPool m_descriptorPool;
74  VKRenderPass* m_renderPass;
75 
76  std::vector<VkVertexInputAttributeDescription> m_vertexLayout;
77 
78  uint32_t m_vertexLayoutStride;
79  uint32_t m_instanceLayoutStride;
80 
81  VkPipelineDepthStencilStateCreateInfo m_depthStencilState;
82  VkPipelineRasterizationStateCreateInfo m_rasterizationState;
83  VkPipelineMultisampleStateCreateInfo m_multisampleState;
84 
85  std::vector<VkPipelineShaderStageCreateInfo> m_shaderStages;
86  std::map<Resource::Pipeline::ShaderSlot, Graphics::ShaderHandle> m_shaderHandles;
87 
88  VkPipelineCache m_pipelineCache;
89  VkPipelineLayout m_pipelineLayout; //Given by the root layout
90  VkPipeline m_pipeline;
91 
92  std::vector<BYTE> m_pushData;
93  std::vector<BYTE> m_descriptorData;
94 
95  UniformBlock_vk m_uniformVSBuffer;
96  uint8_t* m_uniformBindPoint;
97  VkDescriptorSet m_descriptorSet; //Descriptor set for data that can't fit into push constants
98 
99  private:
100  bool m_hasVertexAttribs;
101  bool m_hasIndexAttribs;
102 
103  VKRootLayout* m_rootLayout;
104 
105  /* Set the vertex layout
106  * \param vertexLayout A vector of all of the vertex attributes in this layout
107  */
108  void setVertexLayout(const std::vector<Resource::Pipeline::Attribute> vertexLayout);
109 
110  /* Set the instance layout
111  * \param instanceLayout A vector of all of the instance attributes in this layout
112  */
113  void setInstanceLayout(const std::vector<Resource::Pipeline::Attribute> instanceLayout);
114 
115  void setDepthStencilState(const Hatchit::Resource::Pipeline::DepthStencilState& depthStencilState);
116 
117  /* Set the rasterization state for this pipeline
118  * \param rasterState A struct containing rasterization options
119  */
120  void setRasterState(const Hatchit::Resource::Pipeline::RasterizerState& rasterState);
121 
122  /* Set the multisampling state for this pipeline
123  * \param multiState A struct containing multisampling options
124  */
125  void setMultisampleState(const Hatchit::Resource::Pipeline::MultisampleState& multiState);
126 
127  /* Load a shader into a shader slot for the pipeline
128  * \param shaderSlot The slot that you want the shader in; vertex, fragment etc.
129  * \param shader A pointer to the shader that you want to load to the given shader slot
130  */
131  void loadShader(Hatchit::Resource::Pipeline::ShaderSlot shaderSlot, Graphics::ShaderHandle shader);
132 
133  bool preparePipeline();
134 
135  bool prepareDescriptorSet();
136 
137  VkFormat formatFromType(const Resource::ShaderVariable::Type& type) const;
138 
139  void addAttributesToLayout(const std::vector<Resource::Pipeline::Attribute>& attributes, std::vector<VkVertexInputAttributeDescription>& vkAttributes, uint32_t& outStride);
140 
141  VkBlendOp getVKBlendOpFromResourceBlendOp(Resource::RenderTarget::BlendOp blendOp);
142  };
143  }
144  }
145 }
Definition: ht_d3d12material.h:27
Definition: ht_vkrootlayout.h:30
Definition: ht_vkpipeline.h:42
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_color.h:19
Definition: ht_pipeline_base.h:39
Definition: ht_vkrenderpass.h:41
Definition: ht_shadervariablechunk.h:38