Skip to content

Commit e36c60d

Browse files
authored
Align docu in 03_Render_passes.adoc.adoc and 04_Conclusion.adoc and the sources in 12_graphics_pipeline_complete.cpp (#343)
1 parent cf1a148 commit e36c60d

2 files changed

Lines changed: 37 additions & 38 deletions

File tree

en/03_Drawing_a_triangle/02_Graphics_pipeline_basics/03_Render_passes.adoc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ To use dynamic rendering, we need to specify the formats of the attachments that
1717
vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainImageFormat };
1818
----
1919

20-
This structure specifies that we'll be using one color attachment with the format of our swap chain images. We then include this structure in the `pNext` chain of the `vk::GraphicsPipelineCreateInfo` structure:
20+
This structure specifies that we'll be using one color attachment with the format of our swap chain images. We then include this structure in the `vk::StructureChain`, starting with the `vk::GraphicsPipelineCreateInfo` structure:
2121

2222
[,c++]
2323
----
24-
vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo,
25-
.stageCount = 2, .pStages = shaderStages,
26-
.pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly,
27-
.pViewportState = &viewportState, .pRasterizationState = &rasterizer,
28-
.pMultisampleState = &multisampling, .pColorBlendState = &colorBlending,
29-
.pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr };
24+
vk::StructureChain<vk::GraphicsPipelineCreateInfo, vk::PipelineRenderingCreateInfo> pipelineCreateInfoChain = {
25+
{.stageCount = 2,
26+
.pStages = shaderStages,
27+
.pVertexInputState = &vertexInputInfo,
28+
.pInputAssemblyState = &inputAssembly,
29+
.pViewportState = &viewportState,
30+
.pRasterizationState = &rasterizer,
31+
.pMultisampleState = &multisampling,
32+
.pColorBlendState = &colorBlending,
33+
.pDynamicState = &dynamicState,
34+
.layout = pipelineLayout,
35+
.renderPass = nullptr},
36+
{.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format}};
3037
----
3138

3239
Note that the `renderPass` parameter is set to `nullptr` because we're using dynamic rendering instead of a traditional render pass.

en/03_Drawing_a_triangle/02_Graphics_pipeline_basics/04_Conclusion.adoc

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,53 @@ Here are the types of objects we have now, as a quick recap:
1010
* Pipeline layout: the uniform and push values referenced by the shader that can be updated at draw time
1111
* Dynamic rendering: the formats of the attachments that will be used during rendering
1212

13-
All of these combined fully define the functionality of the graphics pipeline, so we can now begin filling in the `VkGraphicsPipelineCreateInfo` structure at the end of the `createGraphicsPipeline` function.
13+
All of these combined fully define the functionality of the graphics pipeline, so we can now begin filling in the `vk::GraphicsPipelineCreateInfo` structure at the end of the `createGraphicsPipeline` function.
1414

1515
[,c++]
1616
----
17-
vk::GraphicsPipelineCreateInfo pipelineInfo({}, 2, shaderStages);
17+
vk::StructureChain<vk::GraphicsPipelineCreateInfo, vk::PipelineRenderingCreateInfo> pipelineCreateInfoChain = {
18+
{.stageCount = 2,
19+
.pStages = shaderStages,
1820
----
1921

20-
We start by referencing the array of `VkPipelineShaderStageCreateInfo` structs.
22+
We start by referencing the array of `vk::PipelineShaderStageCreateInfo` structs.
2123

2224
[,c++]
2325
----
24-
vk::GraphicsPipelineCreateInfo pipelineInfo({}, 2, shaderStages, &vertexInputInfo, &inputAssembly, {}, &viewportState, &rasterizer, &multisampling, {}, &colorBlending,
25-
&dynamicState);
26+
.pVertexInputState = &vertexInputInfo,
27+
.pInputAssemblyState = &inputAssembly,
28+
.pViewportState = &viewportState,
29+
.pRasterizationState = &rasterizer,
30+
.pMultisampleState = &multisampling,
31+
.pColorBlendState = &colorBlending,
32+
.pDynamicState = &dynamicState,
2633
----
2734

2835
Then we reference all the structures describing the fixed-function stage.
2936

3037
[,c++]
3138
----
32-
vk::GraphicsPipelineCreateInfo pipelineInfo({}, 2, shaderStages, &vertexInputInfo, &inputAssembly, {}, &viewportState, &rasterizer, &multisampling, {}, &colorBlending,
33-
&dynamicState, *pipelineLayout);
39+
.layout = pipelineLayout,
3440
----
3541

3642
After that comes the pipeline layout, which is a Vulkan handle rather than a struct pointer.
3743

3844
[,c++]
3945
----
40-
vk::PipelineRenderingCreateInfo pipelineRenderingCreateInfo{ .colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainImageFormat };
41-
vk::GraphicsPipelineCreateInfo pipelineInfo{ .pNext = &pipelineRenderingCreateInfo,
42-
.stageCount = 2, .pStages = shaderStages,
43-
.pVertexInputState = &vertexInputInfo, .pInputAssemblyState = &inputAssembly,
44-
.pViewportState = &viewportState, .pRasterizationState = &rasterizer,
45-
.pMultisampleState = &multisampling, .pColorBlendState = &colorBlending,
46-
.pDynamicState = &dynamicState, .layout = pipelineLayout, .renderPass = nullptr };
46+
.renderPass = nullptr},
47+
{.colorAttachmentCount = 1, .pColorAttachmentFormats = &swapChainSurfaceFormat.format}};
4748
----
4849

49-
Note that we're using dynamic rendering instead of a traditional render pass, so we set the `renderPass` parameter to `nullptr` and include a `vk::PipelineRenderingCreateInfo` structure in the `pNext` chain. This structure specifies the formats of the attachments that will be used during rendering.
50+
Note that we're using dynamic rendering instead of a traditional render pass, so we set the `renderPass` parameter to `nullptr` and include a `vk::PipelineRenderingCreateInfo` structure in the `vk::StructureChain`. This structure specifies the formats of the attachments that will be used during rendering.
5051

51-
[,c++]
52-
----
53-
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional
54-
pipelineInfo.basePipelineIndex = -1; // Optional
55-
----
56-
57-
There are actually two more parameters: `basePipelineHandle` and `basePipelineIndex`.
52+
There are actually two more members in the vk::GraphicsPipelineCreateInfo: `basePipelineHandle` and `basePipelineIndex`.
5853
Vulkan allows you to create a new graphics pipeline by deriving from an existing pipeline.
5954
The idea of pipeline derivatives is that it is less expensive to set up pipelines when they have much functionality in common with an existing pipeline and switching between pipelines from the same parent can also be done quicker.
6055
You can either specify the handle of an existing pipeline with `basePipelineHandle` or reference another pipeline that is about to be created by index with `basePipelineIndex`.
61-
Right now there is only a single pipeline, so we'll simply specify a null handle and an invalid index.
62-
These values are only used if the `VK_PIPELINE_CREATE_DERIVATIVE_BIT` flag is also specified in the `flags` field of `VkGraphicsPipelineCreateInfo`.
56+
These values are only used if the `vk::PipelineCreateFlagBits::eDerivative` flag is also specified in the `flags` field of `vk::GraphicsPipelineCreateInfo`.
57+
Right now there is only a single pipeline, so we'll ignore those members.
6358

64-
Now prepare for the final step by creating a class member to hold the `VkPipeline` object:
59+
Now prepare for the final step by creating a class member to hold the `vk::raii::Pipeline` object:
6560

6661
[,c++]
6762
----
@@ -72,14 +67,11 @@ And finally, create the graphics pipeline:
7267

7368
[,c++]
7469
----
75-
graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineInfo);
70+
graphicsPipeline = vk::raii::Pipeline(device, nullptr, pipelineCreateInfoChain.get<vk::GraphicsPipelineCreateInfo>());
7671
----
7772

78-
The `vkCreateGraphicsPipelines` function actually has more parameters than the usual object creation functions in Vulkan.
79-
It is designed to take multiple `VkGraphicsPipelineCreateInfo` objects and create multiple `VkPipeline` objects in a single call.
80-
81-
The second parameter, for which we've passed the `VK_NULL_HANDLE` argument, references an optional `VkPipelineCache` object.
82-
A pipeline cache can be used to store and reuse data relevant to pipeline creation across multiple calls to `vkCreateGraphicsPipelines` and even across program executions if the cache is stored to a file.
73+
The second parameter, for which we've passed the `nullptr` argument, references an optional `vk::raii::PipelineCache` object.
74+
A pipeline cache can be used to store and reuse data relevant to pipeline creation across multiple calls to `vk::raii::Pipeline` constructors and even across program executions if the cache is stored to a file.
8375
This makes it possible to significantly speed up pipeline creation at a later time.
8476
We'll get into this in the pipeline cache chapter.
8577

0 commit comments

Comments
 (0)