From d5503070112a013fe2682d43a456be10259cb11c Mon Sep 17 00:00:00 2001 From: Riley King-Saunders Date: Thu, 10 Jul 2025 00:46:33 +1000 Subject: [PATCH] Updated PipelineBuilder to now allow adding vertex bindings --- include/vulkan/basalt_pipeline.h | 7 +++++-- src/vulkan/basalt_pipeline.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/vulkan/basalt_pipeline.h b/include/vulkan/basalt_pipeline.h index 0fd6be6..4e4bfcf 100644 --- a/include/vulkan/basalt_pipeline.h +++ b/include/vulkan/basalt_pipeline.h @@ -34,11 +34,10 @@ namespace basalt PipelineBuilder& add_dynamic_states(const basalt::darray& states); PipelineBuilder& set_render_pass(VkRenderPass render_pass); PipelineBuilder& add_colour_attachment(VkPipelineColorBlendAttachmentState attachment); + PipelineBuilder& add_vertex_binding(VkVertexInputBindingDescription binding, VkVertexInputAttributeDescription* attributes, u32 num_bindings); Pipeline build(); - basalt::darray shader_modules; - basalt::darray shader_stages; VkPipelineRasterizationStateCreateInfo raster_ci; VkPipelineColorBlendStateCreateInfo colour_blend_ci; @@ -48,6 +47,10 @@ namespace basalt VkPipelineViewportStateCreateInfo viewport_ci; VkPipelineInputAssemblyStateCreateInfo assembly_ci; VkPipelineDynamicStateCreateInfo dynamic_state_ci; + basalt::darray vertex_input_attributes; + basalt::darray vertex_binding_description; + basalt::darray shader_modules; + basalt::darray shader_stages; basalt::darray colour_attachments; basalt::darray dynamic_states; VkViewport viewport; diff --git a/src/vulkan/basalt_pipeline.cpp b/src/vulkan/basalt_pipeline.cpp index ea41be0..c9f6456 100644 --- a/src/vulkan/basalt_pipeline.cpp +++ b/src/vulkan/basalt_pipeline.cpp @@ -6,6 +6,8 @@ basalt::PipelineBuilder::PipelineBuilder(basalt::Device& device, VkExtent2D exte shader_modules(MEMORY_TAG_CLASS_DYNARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY), colour_attachments(MEMORY_TAG_CLASS_DYNARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY), dynamic_states(MEMORY_TAG_CLASS_DYNARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY), + vertex_input_attributes(MEMORY_TAG_CLASS_DYNARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY), + vertex_binding_description(MEMORY_TAG_CLASS_DYNARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY), device(device), previous_pipeline(previous_pipeline) { dynamic_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; @@ -171,6 +173,11 @@ basalt::Pipeline basalt::PipelineBuilder::build() colour_blend_ci.attachmentCount = this->colour_attachments.m_nelements; colour_blend_ci.pAttachments = this->colour_attachments.m_pdata; + vertex_ci.pVertexBindingDescriptions = this->vertex_binding_description.m_pdata; + vertex_ci.vertexBindingDescriptionCount = this->vertex_binding_description.m_nelements; + vertex_ci.pVertexAttributeDescriptions = this->vertex_input_attributes.m_pdata; + vertex_ci.vertexAttributeDescriptionCount = this->vertex_input_attributes.m_nelements; + VkGraphicsPipelineCreateInfo ci = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO }; ci.flags = VK_PIPELINE_CREATE_DERIVATIVE_BIT * (this->previous_pipeline != VK_NULL_HANDLE); ci.basePipelineHandle = this->previous_pipeline; @@ -224,3 +231,10 @@ basalt::PipelineBuilder& basalt::PipelineBuilder::add_colour_attachment(VkPipeli this->colour_attachments.push_back(attachment); return *this; } + +basalt::PipelineBuilder& basalt::PipelineBuilder::add_vertex_binding(VkVertexInputBindingDescription binding, VkVertexInputAttributeDescription* attributes, u32 num_bindings) +{ + this->vertex_input_attributes.push_back(attributes, num_bindings); + this->vertex_binding_description.push_back(binding); + return *this; +}