@@ -34,6 +34,47 @@ namespace inexor::vulkan_renderer::wrapper::pipelines {
3434
3535// TODO: Implement RAII wrapper for ComputePipeline
3636
37+ // / When creating a graphics pipeline, the lifetime of certain data which is used to create the pipeline must be
38+ // / ensured. In particular, the VkGraphicsPipelineCreateInfo struct must not be stored, however, the memory to which the
39+ // / pointers inside of VkGraphicsPipelineCreateInfo point to must be stored. For example, VkGraphicsPipelineCreateInfo
40+ // / has a member VkPipelineViewportStateCreateInfo, which itself has a pointer that point to VkViewport data, for
41+ // / example. This means we must make sure the lifetime of all data that the pointers point to must be preserved.
42+ // / Initially, we collected all the data to create the graphics pipeline in GraphicsPipelineBuilder, and reset all the
43+ // / data of the builder after the build() method has been called. However, this is wrong, because the lifetime of the
44+ // / data ends with calling reset(). This causes some bugs which are hard to find.
45+ struct GraphicsPipelineSetupData {
46+ // @TODO Add whatever we need here!
47+ // This is the underlying data for the create info structures
48+ std::vector<VkPipelineShaderStageCreateInfo> m_shader_stages;
49+ std::vector<VkVertexInputBindingDescription> m_vertex_input_binding_descriptions;
50+ std::vector<VkVertexInputAttributeDescription> m_vertex_input_attribute_descriptions;
51+ std::vector<VkPipelineColorBlendAttachmentState> m_color_blend_attachment_states;
52+ std::vector<VkViewport> m_viewports;
53+ std::vector<VkRect2D> m_scissors;
54+ std::vector<VkPushConstantRange> m_push_constant_ranges;
55+ std::vector<VkDescriptorSetLayout> m_descriptor_set_layouts;
56+ VkRenderPass m_render_pass;
57+ VkFormat m_depth_attachment_format;
58+ VkFormat m_stencil_attachment_format;
59+ std::vector<VkFormat> m_color_attachments;
60+ std::vector<VkDynamicState> m_dynamic_states;
61+ VkPipelineLayout m_pipeline_layout;
62+
63+ // These are the create info structures required to fill the VkGraphicsPipelineCreateInfo
64+ VkPipelineVertexInputStateCreateInfo m_vertex_input_sci;
65+ VkPipelineInputAssemblyStateCreateInfo m_input_assembly_sci;
66+ VkPipelineTessellationStateCreateInfo m_tesselation_sci;
67+ VkPipelineViewportStateCreateInfo m_viewport_sci;
68+ VkPipelineRasterizationStateCreateInfo m_rasterization_sci;
69+ VkPipelineDepthStencilStateCreateInfo m_depth_stencil_sci;
70+ VkPipelineRenderingCreateInfo m_pipeline_rendering_ci;
71+ VkPipelineMultisampleStateCreateInfo m_multisample_sci;
72+ VkPipelineColorBlendStateCreateInfo m_color_blend_sci;
73+ VkPipelineDynamicStateCreateInfo m_dynamic_states_sci;
74+
75+ // @TODO: Implement move constructor for GraphicsPipelineSetupData?
76+ };
77+
3778// / RAII wrapper for graphics pipelines
3879class GraphicsPipeline {
3980 friend class commands ::CommandBuffer;
@@ -42,6 +83,7 @@ class GraphicsPipeline {
4283private:
4384 const Device &m_device;
4485 std::string m_name;
86+ GraphicsPipelineSetupData m_pipeline_setup_data;
4587
4688 VkPipeline m_pipeline;
4789 std::unique_ptr<PipelineLayout> m_pipeline_layout;
@@ -52,12 +94,12 @@ class GraphicsPipeline {
5294 // / @param pipeline_cache The Vulkan pipeline cache
5395 // / @param descriptor_set_layouts The descriptor set layouts in the pipeline layout
5496 // / @param push_constant_ranges The push constant ranges in the pipeline layout
55- // / @param pipeline_ci The pipeline create info
97+ // / @param pipeline_setup_data The graphics pipeline setup data
5698 // / @param name The internal debug name of the graphics pipeline
5799 GraphicsPipeline (const Device &device, const PipelineCache &pipeline_cache,
58100 std::span<const VkDescriptorSetLayout> descriptor_set_layouts,
59101 std::span<const VkPushConstantRange> push_constant_ranges,
60- VkGraphicsPipelineCreateInfo pipeline_ci , std::string name);
102+ GraphicsPipelineSetupData pipeline_setup_data , std::string name);
61103
62104 GraphicsPipeline (const GraphicsPipeline &) = delete ;
63105 GraphicsPipeline (GraphicsPipeline &&) noexcept ;
0 commit comments