[WIP] Refactor project

There are many problems with the way the current version is provided
and maintained. This commit or series of commits will fix this.
This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent f5ab5f3f27
commit 173a82b9d1
63 files changed
+2663 -2239

No files matched your search

+159
View File
@@ -0,0 +1,159 @@
/**
* @file pipeline_builder.h
* @author Piotr Krygier (everyonecancode@gmail.com)
* @brief Builder for vulkan pipeline
* @version 0.1
* @date 2024-03-01
*
* @copyright Copyright (c) 2024
*
*/
#ifndef PIPELINE_BUILDER_H
#define PIPELINE_BUILDER_H
#include <vulkan/vulkan.h>
#include "graphics_context.h"
#include "utilities/commons.h"
#include "utilities/linked_list.h"
#include "utilities/stack.h"
#define MAX_SHADER_STAGES 12U
RSE_LINKED_LIST_DEFINE(vertex_bindinlist_t, VkVertexInputBindingDescription);
RSE_LINKED_LIST_DEFINE(shader_attribute_list_t,
VkVertexInputAttributeDescription);
RSE_LINKED_LIST_DEFINE(dynamic_state_list_t, VkDynamicState);
RSE_LINKED_LIST_DEFINE(pipeline_infos_list_t, VkGraphicsPipelineCreateInfo);
RSE_STACK_DEFINE(required_dynamic_states_t, VkDynamicState, 16U);
struct binding_info_t {
uint32_t binding;
VkDescriptorType descriptor_type;
VkShaderStageFlags stage_flags;
};
struct pipeline_t {
VkPipeline pipeline;
uint8_t id;
/* Shader stages */
size_t shader_stages_count;
VkPipelineShaderStageCreateInfo shader_stages[MAX_SHADER_STAGES];
/* Input assembly */
VkPipelineInputAssemblyStateCreateInfo input_assembly;
/* Viewport state */
VkPipelineViewportStateCreateInfo viewport_state;
/* Rasterizer */
VkPipelineRasterizationStateCreateInfo rasterizer;
/* Multisampling */
VkPipelineMultisampleStateCreateInfo multisampling;
/* Color blending */
VkPipelineColorBlendAttachmentState color_blend_attachment;
VkPipelineColorBlendStateCreateInfo color_blending;
/* Depth stencil */
VkPipelineDepthStencilStateCreateInfo depth_stencil;
struct vertex_bindinlist_t* vertex_bindings;
struct shader_attribute_list_t* shader_attributes;
struct dynamic_state_list_t* dynamic_states;
struct required_dynamic_states_t required_dynamic_states;
};
/**
* @brief Initialize pipeline builder
*
* @param[out] pipeline Pipeline to initialize. Must be NULL
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_builder_init(struct pipeline_t* pipeline);
/**
* @brief Add shader stages to pipeline
*
* @param[in] context Graphics context handle
* @param[in] pipeline Pipeline to build
* @param[in] shader_path Path to the shader file
* @param[in] shader_stage Shader stage to add
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_shader_stage(struct graphics_context_t* context, struct pipeline_t* pipeline, const char* shader_path, const VkShaderStageFlagBits shader_stage);
/**
* @brief Add vertex input binding to pipeline
*
* @param[in] pipeline Pipeline to build
* @param[in] binding Binding point for vertex data
* @param[in] stride Stride between vertex data elements in bytes
* @param[in] input_rate Input rate for vertex data
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_vertex_input_binding(struct pipeline_t* pipeline, const uint8_t binding, const uint8_t stride,
const VkVertexInputRate input_rate);
/**
* @brief Add vertex attribute to shader in pipeline
*
* @param[in] pipeline Pipeline to build
* @param[in] binding Binding point for vertex data
* @param[in] location Location of the attribute in shader
* @param[in] format Format of the attribute
* @param[in] offset Offset of the attribute in bytes
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_vertex_input_attribute(struct pipeline_t* pipeline, const uint8_t binding,
const uint8_t location,
const VkFormat format,
const uint8_t offset);
/**
* @brief Add dynamic state to pipeline
*
* @param[in] pipeline Pipeline to build
* @param[in] dynamic_state Dynamic state to add
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_dynamic_state(struct pipeline_t* pipeline, const VkDynamicState dynamic_state);
/**
* @brief Add required dynamic state to pipeline
*
* @param[in] context Graphics context handle
* @param[in] binding_infos Binding infos to add
* @param[in] binding_count Number of binding infos
* @param[out] descriptor_set_index Index of descriptor set
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t pipeline_add_descriptor_layout(struct graphics_context_t* context,
struct binding_info_t* binding_infos,
size_t binding_count,
size_t* descriptor_set_index);
/**
* @brief Build pipeline from added components. This function should be called after adding all necessary components. After call, pipeline is ready to be used and all added components are cleared, ready for next pipeline to be built.
*
* param[in/out] context Graphics context handle
* @param[in] pipeline Pipelines list to build
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t build_pipelines(struct graphics_context_t* context,
struct pipeline_infos_list_t* pipelines);
/**
* @brief Add pipeline to list of pipelines
*
* @param[in] context Graphics context handle
* @param[in] pipeline Pipeline to add
* @param[out] pipelines List of pipelines
* @return RSE_SUCCESS on success, error code otherwise
*/
rse_err_t add_pipeline(const struct graphics_context_t* context, struct pipeline_t* pipeline, struct pipeline_infos_list_t* pipelines);
/**
* @brief Destroy all pipelines
*
* @param[in] context Graphics context handle
*/
void destroy_pipelines(struct graphics_context_t* context);
#endif /* PIPELINE_BUILDER_H */