From c71397c146d87984b723dfde8105fe7a25fbc197 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 29 Sep 2025 15:38:21 +0200 Subject: [PATCH 1/2] Use vk::StructureChain on pipeline creation. --- attachments/12_graphics_pipeline_complete.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/attachments/12_graphics_pipeline_complete.cpp b/attachments/12_graphics_pipeline_complete.cpp index 7ca1313c..41f7b44c 100644 --- a/attachments/12_graphics_pipeline_complete.cpp +++ b/attachments/12_graphics_pipeline_complete.cpp @@ -326,15 +326,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + { .stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } [[nodiscard]] vk::raii::ShaderModule createShaderModule(const std::vector& code) const { From 301facc86e19d279537b4149b259992eb59de5ba Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Thu, 2 Oct 2025 11:53:40 +0200 Subject: [PATCH 2/2] Carry usage of vk::StructureChain on pipeline creation into all chapters --- attachments/12_graphics_pipeline_complete.cpp | 2 +- attachments/14_command_buffers.cpp | 25 +++++++---- attachments/15_hello_triangle.cpp | 25 +++++++---- attachments/16_frames_in_flight.cpp | 25 +++++++---- attachments/17_swap_chain_recreation.cpp | 25 +++++++---- attachments/18_vertex_input.cpp | 25 +++++++---- attachments/19_vertex_buffer.cpp | 25 +++++++---- attachments/20_staging_buffer.cpp | 25 +++++++---- attachments/21_index_buffer.cpp | 25 +++++++---- attachments/22_descriptor_layout.cpp | 25 +++++++---- attachments/23_descriptor_sets.cpp | 25 +++++++---- attachments/24_texture_image.cpp | 25 +++++++---- attachments/25_sampler.cpp | 25 +++++++---- attachments/26_texture_mapping.cpp | 25 +++++++---- attachments/27_depth_buffering.cpp | 15 +++---- attachments/28_model_loading.cpp | 15 +++---- attachments/29_mipmapping.cpp | 15 +++---- attachments/30_multisampling.cpp | 15 +++---- attachments/31_compute_shader.cpp | 12 +++--- attachments/32_ecosystem_utilities.cpp | 31 ++++++-------- attachments/33_vulkan_profiles.cpp | 41 +++++++------------ attachments/36_multiple_objects.cpp | 15 +++---- attachments/37_multithreading.cpp | 10 ++--- attachments/38_ray_tracing.cpp | 18 +++----- 24 files changed, 284 insertions(+), 230 deletions(-) diff --git a/attachments/12_graphics_pipeline_complete.cpp b/attachments/12_graphics_pipeline_complete.cpp index 41f7b44c..b5277399 100644 --- a/attachments/12_graphics_pipeline_complete.cpp +++ b/attachments/12_graphics_pipeline_complete.cpp @@ -327,7 +327,7 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); vk::StructureChain pipelineCreateInfoChain = { - { .stageCount = 2, + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, diff --git a/attachments/14_command_buffers.cpp b/attachments/14_command_buffers.cpp index 864edec0..63b5dfb5 100644 --- a/attachments/14_command_buffers.cpp +++ b/attachments/14_command_buffers.cpp @@ -330,15 +330,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/15_hello_triangle.cpp b/attachments/15_hello_triangle.cpp index 2e9ebb60..b0b57bc4 100644 --- a/attachments/15_hello_triangle.cpp +++ b/attachments/15_hello_triangle.cpp @@ -340,15 +340,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/16_frames_in_flight.cpp b/attachments/16_frames_in_flight.cpp index 2c129802..afcb4613 100644 --- a/attachments/16_frames_in_flight.cpp +++ b/attachments/16_frames_in_flight.cpp @@ -344,15 +344,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/17_swap_chain_recreation.cpp b/attachments/17_swap_chain_recreation.cpp index 7fc4ef75..4ff13a70 100644 --- a/attachments/17_swap_chain_recreation.cpp +++ b/attachments/17_swap_chain_recreation.cpp @@ -371,15 +371,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/18_vertex_input.cpp b/attachments/18_vertex_input.cpp index 010059b4..45ed5adc 100644 --- a/attachments/18_vertex_input.cpp +++ b/attachments/18_vertex_input.cpp @@ -388,15 +388,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/19_vertex_buffer.cpp b/attachments/19_vertex_buffer.cpp index d50a5e0c..3c7ad2c6 100644 --- a/attachments/19_vertex_buffer.cpp +++ b/attachments/19_vertex_buffer.cpp @@ -392,15 +392,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/20_staging_buffer.cpp b/attachments/20_staging_buffer.cpp index 2b056975..5903ecff 100644 --- a/attachments/20_staging_buffer.cpp +++ b/attachments/20_staging_buffer.cpp @@ -392,15 +392,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/21_index_buffer.cpp b/attachments/21_index_buffer.cpp index d727fce9..2aeda55a 100644 --- a/attachments/21_index_buffer.cpp +++ b/attachments/21_index_buffer.cpp @@ -400,15 +400,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/22_descriptor_layout.cpp b/attachments/22_descriptor_layout.cpp index 4addf1ec..d10d6bc8 100644 --- a/attachments/22_descriptor_layout.cpp +++ b/attachments/22_descriptor_layout.cpp @@ -423,15 +423,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/23_descriptor_sets.cpp b/attachments/23_descriptor_sets.cpp index ed2839b4..95101dc1 100644 --- a/attachments/23_descriptor_sets.cpp +++ b/attachments/23_descriptor_sets.cpp @@ -428,15 +428,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/24_texture_image.cpp b/attachments/24_texture_image.cpp index 9773cceb..e846b431 100644 --- a/attachments/24_texture_image.cpp +++ b/attachments/24_texture_image.cpp @@ -435,15 +435,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/25_sampler.cpp b/attachments/25_sampler.cpp index b2571173..5e3ce8c0 100644 --- a/attachments/25_sampler.cpp +++ b/attachments/25_sampler.cpp @@ -440,15 +440,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/26_texture_mapping.cpp b/attachments/26_texture_mapping.cpp index 30cda574..a22d18af 100644 --- a/attachments/26_texture_mapping.cpp +++ b/attachments/26_texture_mapping.cpp @@ -446,15 +446,22 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, .pStages = shaderStages, - .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, - .pViewportState = &viewportState, .pRasterizationState = &rasterizer, - .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, - .pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr }; - - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, + .pStages = shaderStages, + .pVertexInputState = &vertexInputInfo, + .pInputAssemblyState = &inputAssembly, + .pViewportState = &viewportState, + .pRasterizationState = &rasterizer, + .pMultisampleState = &multisampling, + .pColorBlendState = &colorBlending, + .pDynamicState = &dynamicState, + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } + }; + + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/27_depth_buffering.cpp b/attachments/27_depth_buffering.cpp index ebb596a6..fe950282 100644 --- a/attachments/27_depth_buffering.cpp +++ b/attachments/27_depth_buffering.cpp @@ -490,13 +490,9 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); vk::Format depthFormat = findDepthFormat(); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainSurfaceFormat.format, - .depthAttachmentFormat = depthFormat - }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -507,10 +503,11 @@ class HelloTriangleApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = pipelineLayout, - .renderPass = nullptr + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/28_model_loading.cpp b/attachments/28_model_loading.cpp index 5c72ab66..1b57f963 100644 --- a/attachments/28_model_loading.cpp +++ b/attachments/28_model_loading.cpp @@ -494,13 +494,9 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout(device, pipelineLayoutInfo); vk::Format depthFormat = findDepthFormat(); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainSurfaceFormat.format, - .depthAttachmentFormat = depthFormat - }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -511,10 +507,11 @@ class HelloTriangleApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = pipelineLayout, - .renderPass = nullptr + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/29_mipmapping.cpp b/attachments/29_mipmapping.cpp index 4a0455f0..e08a721e 100644 --- a/attachments/29_mipmapping.cpp +++ b/attachments/29_mipmapping.cpp @@ -494,13 +494,9 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout(device, pipelineLayoutInfo); vk::Format depthFormat = findDepthFormat(); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainSurfaceFormat.format, - .depthAttachmentFormat = depthFormat - }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -511,10 +507,11 @@ class HelloTriangleApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = pipelineLayout, - .renderPass = nullptr + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/30_multisampling.cpp b/attachments/30_multisampling.cpp index bd5a4d06..bc5e8e40 100644 --- a/attachments/30_multisampling.cpp +++ b/attachments/30_multisampling.cpp @@ -503,13 +503,9 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout(device, pipelineLayoutInfo); vk::Format depthFormat = findDepthFormat(); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainSurfaceFormat.format, - .depthAttachmentFormat = depthFormat - }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -520,10 +516,11 @@ class HelloTriangleApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = pipelineLayout, - .renderPass = nullptr + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/31_compute_shader.cpp b/attachments/31_compute_shader.cpp index e2ef808a..4e11f366 100644 --- a/attachments/31_compute_shader.cpp +++ b/attachments/31_compute_shader.cpp @@ -466,9 +466,8 @@ class ComputeShaderApplication { vk::PipelineLayoutCreateInfo pipelineLayoutInfo; pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -477,11 +476,12 @@ class ComputeShaderApplication { .pMultisampleState = &multisampling, .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, - .layout = *pipelineLayout, - .subpass = 0 + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createComputePipeline() { diff --git a/attachments/32_ecosystem_utilities.cpp b/attachments/32_ecosystem_utilities.cpp index ce1747e1..878d6825 100644 --- a/attachments/32_ecosystem_utilities.cpp +++ b/attachments/32_ecosystem_utilities.cpp @@ -728,8 +728,8 @@ class HelloTriangleApplication { pipelineLayout = vk::raii::PipelineLayout(device, pipelineLayoutInfo); - vk::GraphicsPipelineCreateInfo pipelineInfo{ - .stageCount = 2, + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -739,27 +739,22 @@ class HelloTriangleApplication { .pDepthStencilState = &depthStencil, .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, - .layout = pipelineLayout + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = findDepthFormat() } }; - // Configure pipeline based on dynamic rendering support - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo; if (appInfo.dynamicRenderingSupported) { - std::cout << "Configuring pipeline for dynamic rendering\n"; - pipelineRenderingCreateInfo.colorAttachmentCount = 1; - pipelineRenderingCreateInfo.pColorAttachmentFormats = &swapChainSurfaceFormat.format; - pipelineRenderingCreateInfo.depthAttachmentFormat = findDepthFormat(); - - pipelineInfo.pNext = &pipelineRenderingCreateInfo; - pipelineInfo.renderPass = nullptr; - } else { - std::cout << "Configuring pipeline for traditional render pass\n"; - pipelineInfo.pNext = nullptr; - pipelineInfo.renderPass = *renderPass; - pipelineInfo.subpass = 0; + std::cout << "Configuring pipeline for dynamic rendering\n"; + } + else + { + std::cout << "Configuring pipeline for traditional render pass\n"; + pipelineCreateInfoChain.unlink(); + pipelineCreateInfoChain.get().renderPass = *renderPass; } - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/33_vulkan_profiles.cpp b/attachments/33_vulkan_profiles.cpp index 3f15a6dd..d1ec8309 100644 --- a/attachments/33_vulkan_profiles.cpp +++ b/attachments/33_vulkan_profiles.cpp @@ -701,8 +701,10 @@ class HelloTriangleApplication { pipelineLayout = device.createPipelineLayout(pipelineLayoutInfo); - vk::GraphicsPipelineCreateInfo pipelineInfo{ - .stageCount = 2, + // Configure pipeline based on whether we're using the KHR roadmap 2022 profile + // With the KHR roadmap 2022 profile, we can use dynamic rendering + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -712,35 +714,22 @@ class HelloTriangleApplication { .pDepthStencilState = &depthStencil, .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, - .layout = *pipelineLayout + .layout = pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = findDepthFormat() } }; - // Configure pipeline based on whether we're using the KHR roadmap 2022 profile if (appInfo.profileSupported) { - // With the KHR roadmap 2022 profile, we can use dynamic rendering - vk::Format colorFormat = swapChainSurfaceFormat.format; - vk::Format depthFormat = findDepthFormat(); - - vk::PipelineRenderingCreateInfo renderingInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &colorFormat, - .depthAttachmentFormat = depthFormat - }; - - pipelineInfo.pNext = &renderingInfo; - pipelineInfo.renderPass = nullptr; - - std::cout << "Creating pipeline with dynamic rendering (KHR roadmap 2022 profile)" << std::endl; - } else { - // Without the profile, use traditional render pass if dynamic rendering is not available - pipelineInfo.pNext = nullptr; - pipelineInfo.renderPass = *renderPass; - pipelineInfo.subpass = 0; - - std::cout << "Creating pipeline with traditional render pass (fallback)" << std::endl; + std::cout << "Creating pipeline with dynamic rendering (KHR roadmap 2022 profile)" << std::endl; + } + else + { + std::cout << "Creating pipeline with traditional render pass (fallback)" << std::endl; + pipelineCreateInfoChain.unlink(); + pipelineCreateInfoChain.get().renderPass = *renderPass; } - graphicsPipeline = device.createGraphicsPipeline(nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createFramebuffers() { diff --git a/attachments/36_multiple_objects.cpp b/attachments/36_multiple_objects.cpp index dc1ae802..5cd6ec31 100644 --- a/attachments/36_multiple_objects.cpp +++ b/attachments/36_multiple_objects.cpp @@ -740,13 +740,9 @@ class VulkanApplication { pipelineLayout = vk::raii::PipelineLayout(device, pipelineLayoutInfo); vk::Format depthFormat = findDepthFormat(); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainSurfaceFormat.format, - .depthAttachmentFormat = depthFormat - }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -757,10 +753,11 @@ class VulkanApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = *pipelineLayout, - .renderPass = nullptr + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() { diff --git a/attachments/37_multithreading.cpp b/attachments/37_multithreading.cpp index 49f1720a..35038604 100644 --- a/attachments/37_multithreading.cpp +++ b/attachments/37_multithreading.cpp @@ -680,9 +680,8 @@ class MultithreadedApplication { vk::PipelineLayoutCreateInfo pipelineLayoutInfo; pipelineLayout = vk::raii::PipelineLayout( device, pipelineLayoutInfo ); - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format }; - vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -692,10 +691,11 @@ class MultithreadedApplication { .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, .layout = *pipelineLayout, - .subpass = 0 + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createComputePipeline() { diff --git a/attachments/38_ray_tracing.cpp b/attachments/38_ray_tracing.cpp index 0c4b6f3e..13b7b022 100644 --- a/attachments/38_ray_tracing.cpp +++ b/attachments/38_ray_tracing.cpp @@ -659,15 +659,8 @@ class HelloTriangleApplication { * This new struct replaces what previously was the render pass in the pipeline creation. * Note how this structure is now linked in .pNext below, and .renderPass is not used. */ - vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ - .colorAttachmentCount = 1, - .pColorAttachmentFormats = &swapChainImageFormat, - .depthAttachmentFormat = depthFormat - }; - - vk::GraphicsPipelineCreateInfo pipelineInfo{ - .pNext = &pipelineRenderingCreateInfo, - .stageCount = 2, + vk::StructureChain pipelineCreateInfoChain = { + {.stageCount = 2, .pStages = shaderStages, .pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly, @@ -677,11 +670,12 @@ class HelloTriangleApplication { .pDepthStencilState = &depthStencil, .pColorBlendState = &colorBlending, .pDynamicState = &dynamicState, - .layout = pipelineLayout, - .renderPass = nullptr + .layout = *pipelineLayout, + .renderPass = nullptr }, + {.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainImageFormat, .depthAttachmentFormat = depthFormat } }; - graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo); + graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get()); } void createCommandPool() {