[7d2b0b9] | 1 | #ifndef _GRAPHICS_PIPELINE_VULKAN_H
|
---|
| 2 | #define _GRAPHICS_PIPELINE_VULKAN_H
|
---|
| 3 |
|
---|
| 4 | #include "graphics-pipeline.hpp"
|
---|
| 5 |
|
---|
| 6 | #include <vector>
|
---|
| 7 |
|
---|
[771b33a] | 8 | #include <vulkan/vulkan.h>
|
---|
| 9 |
|
---|
[b794178] | 10 | // TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
|
---|
| 11 | struct DescriptorInfo {
|
---|
| 12 | VkDescriptorType type;
|
---|
| 13 | VkShaderStageFlags stageFlags;
|
---|
| 14 |
|
---|
| 15 | // Only one of the below properties should be set
|
---|
| 16 | vector<VkDescriptorBufferInfo>* bufferDataList;
|
---|
| 17 | VkDescriptorImageInfo* imageData;
|
---|
| 18 | };
|
---|
| 19 |
|
---|
[7d2b0b9] | 20 | class GraphicsPipeline_Vulkan : public GraphicsPipeline {
|
---|
| 21 | public:
|
---|
[87c8f1a] | 22 | GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, VkRenderPass renderPass,
|
---|
| 23 | Viewport viewport, int vertexSize);
|
---|
[7d2b0b9] | 24 | ~GraphicsPipeline_Vulkan();
|
---|
| 25 |
|
---|
[0ae182f] | 26 | void updateRenderPass(VkRenderPass renderPass);
|
---|
| 27 |
|
---|
[87c8f1a] | 28 | template<class VertexType, class IndexType>
|
---|
| 29 | void bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
|
---|
| 30 | VkCommandPool commandPool, VkQueue graphicsQueue);
|
---|
| 31 |
|
---|
| 32 | void createVertexBuffer(const void* bufferData, int vertexSize, VkCommandPool commandPool,
|
---|
| 33 | VkQueue graphicsQueue);
|
---|
| 34 | void createIndexBuffer(const void* bufferData, int indexSize, VkCommandPool commandPool,
|
---|
| 35 | VkQueue graphicsQueue);
|
---|
| 36 |
|
---|
[b794178] | 37 | // Maybe I should rename these to addVertexAttribute (addVaryingAttribute) and addUniformAttribute
|
---|
| 38 |
|
---|
[771b33a] | 39 | void addAttribute(VkFormat format, size_t offset);
|
---|
[b794178] | 40 |
|
---|
| 41 | void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
|
---|
| 42 | void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData);
|
---|
| 43 |
|
---|
[7d2b0b9] | 44 | void createPipeline(string vertShaderFile, string fragShaderFile);
|
---|
[b794178] | 45 | void createDescriptorSetLayout();
|
---|
| 46 | void createDescriptorPool(vector<VkImage>& swapChainImages);
|
---|
| 47 | void createDescriptorSets(vector<VkImage>& swapChainImages);
|
---|
| 48 |
|
---|
[603b5bc] | 49 | void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
|
---|
| 50 |
|
---|
[b794178] | 51 | void cleanup();
|
---|
| 52 | void cleanupBuffers();
|
---|
[7d2b0b9] | 53 |
|
---|
| 54 | private:
|
---|
[b794178] | 55 | VkShaderModule createShaderModule(const vector<char>& code);
|
---|
| 56 | vector<char> readFile(const string& filename);
|
---|
| 57 |
|
---|
[87c8f1a] | 58 | VkPhysicalDevice physicalDevice;
|
---|
[7d2b0b9] | 59 | VkDevice device;
|
---|
[b794178] | 60 | VkRenderPass renderPass;
|
---|
| 61 |
|
---|
| 62 | VkPipeline pipeline;
|
---|
| 63 | VkPipelineLayout pipelineLayout;
|
---|
| 64 |
|
---|
[771b33a] | 65 | VkVertexInputBindingDescription bindingDescription;
|
---|
[b794178] | 66 |
|
---|
[771b33a] | 67 | vector<VkVertexInputAttributeDescription> attributeDescriptions;
|
---|
[b794178] | 68 | vector<DescriptorInfo> descriptorInfoList;
|
---|
[7d2b0b9] | 69 |
|
---|
[b794178] | 70 | VkDescriptorSetLayout descriptorSetLayout;
|
---|
| 71 | VkDescriptorPool descriptorPool;
|
---|
| 72 | vector<VkDescriptorSet> descriptorSets;
|
---|
[87c8f1a] | 73 |
|
---|
| 74 | size_t numVertices;
|
---|
| 75 | size_t vertexCapacity;
|
---|
| 76 | VkBuffer vertexBuffer;
|
---|
| 77 | VkDeviceMemory vertexBufferMemory;
|
---|
| 78 |
|
---|
| 79 | size_t numIndices;
|
---|
| 80 | size_t indexCapacity;
|
---|
| 81 | VkBuffer indexBuffer;
|
---|
| 82 | VkDeviceMemory indexBufferMemory;
|
---|
[7d2b0b9] | 83 | };
|
---|
| 84 |
|
---|
[87c8f1a] | 85 | // TODO: Probably better to template the whole class and to also combine this function
|
---|
| 86 | // and the constructor since I call this right after the constructor anyway
|
---|
| 87 | template<class VertexType, class IndexType>
|
---|
| 88 | void GraphicsPipeline_Vulkan::bindData(const vector<VertexType>& vertices, const vector<IndexType>& indices,
|
---|
| 89 | VkCommandPool commandPool, VkQueue graphicsQueue) {
|
---|
| 90 | numVertices = vertices.size();
|
---|
| 91 | vertexCapacity = numVertices * 2;
|
---|
| 92 | createVertexBuffer(vertices.data(), sizeof(VertexType), commandPool, graphicsQueue);
|
---|
| 93 |
|
---|
| 94 | numIndices = indices.size();
|
---|
| 95 | indexCapacity = numIndices * 2;
|
---|
| 96 | createIndexBuffer(indices.data(), sizeof(IndexType), commandPool, graphicsQueue);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[7d2b0b9] | 99 | #endif // _GRAPHICS_PIPELINE_VULKAN_H
|
---|