EtrediaEmpires/frontend/include/PipelineFactory.hpp
legatt 389ed599c8 Pipeline factory and materials
- AssetManager uses static assets ID from path hash
- PipelineFactory creates Vulkan pipelines using PipelineConfig structure depending on AssetMaterial and creation flags
- AssetMaterial describes pipelines (e.g. used shaders)
- Materials are described with JSON in sources with path references to other assets
- AssetMaterial is parsed from binary file with asset IDs in references
- compile_config tool compiles material JSON file to binary file with path references replaced with asset IDs
- Allocator supports type's constructors with arguments
- NativeFileSystem: fixed empty bufferSize and buffer trash
2025-08-29 13:13:11 +03:00

64 lines
1.8 KiB
C++

#pragma once
#include "AssetData.hpp"
#include <vulkan/vulkan.hpp>
#include <vector>
#define PIPELINE_CREATE_NEW 0
#define PIPELINE_CREATE_DERIVED (1 << 0)
struct PipelineConfig
{
VkPipelineVertexInputStateCreateInfo vertexInputConfig;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyConfig;
VkPipelineViewportStateCreateInfo viewportStateConfig;
VkPipelineRasterizationStateCreateInfo rasterizerConfig;
VkPipelineMultisampleStateCreateInfo multisamplingConfig;
VkPipelineDepthStencilStateCreateInfo depthStencilConfig;
// SRC - new color, DST - old color
std::vector<VkPipelineColorBlendAttachmentState> colorBlendAttachmentConfigs;
VkPipelineColorBlendStateCreateInfo colorBlendConfig;
VkPipelineDynamicStateCreateInfo dynamicStateConfig;
VkPipelineLayoutCreateInfo pipelineLayoutConfig;
VkViewport defaultViewport;
VkRect2D defaultScissors;
std::vector<VkDynamicState> dynamicStates;
std::vector<VkAttachmentDescription> colorAttachmentConfigs;
std::vector<VkAttachmentReference> colorAttachmentRefs;
std::vector<VkSubpassDescription> subpassConfigs;
VkRenderPassCreateInfo renderPassConfig;
VkGraphicsPipelineCreateInfo pipelineConfig;
PipelineConfig Copy() const;
};
struct Pipeline
{
VkPipeline instance;
VkPipelineLayout layout;
VkRenderPass renderPass;
};
class PipelineFactory
{
public:
PipelineFactory(const AssetMaterial &baseMaterial, VkDevice &device, VkExtent2D &surfaceExtent, VkFormat &surfaceFormat);
~PipelineFactory();
PipelineConfig &Request(const AssetMaterial &material, uint32_t flags);
private:
PipelineConfig basePipelineConfig;
Pipeline basePipeline;
std::vector<Pipeline> pipelines;
VkDevice &device;
VkExtent2D &surfaceExtent;
VkFormat &surfaceFormat;
void Create(const AssetMaterial &material, uint32_t flags);
};