[译]Vulkan教程(16)图形管道基础之总结html
We can now combine all of the structures and objects from the previous chapters to create the graphics pipeline! Here's the types of objects we have now, as a quick recap:编程
咱们如今能够将以前章节的全部结构体和对象组合起来to建立图形管道了!下面是咱们有的对象的类型,快速回顾一下:数组
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. But before the calls to vkDestroyShaderModule
because these are still to be used during the creation.缓存
全部这些组合起来定义了图形管道的功能,因此咱们能够开始填入VkGraphicsPipelineCreateInfo
结构体at createGraphicsPipeline
函数结尾。可是要在调用vkDestroyShaderModule
以前,由于这些在建立过程当中仍是在被用到。less
VkGraphicsPipelineCreateInfo pipelineInfo = {}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = 2; pipelineInfo.pStages = shaderStages;
We start by referencing the array of VkPipelineShaderStageCreateInfo
structs.ide
开始时,咱们引用VkPipelineShaderStageCreateInfo
结构体的数组。函数
pipelineInfo.pVertexInputState = &vertexInputInfo; pipelineInfo.pInputAssemblyState = &inputAssembly; pipelineInfo.pViewportState = &viewportState; pipelineInfo.pRasterizationState = &rasterizer; pipelineInfo.pMultisampleState = &multisampling; pipelineInfo.pDepthStencilState = nullptr; // Optional pipelineInfo.pColorBlendState = &colorBlending; pipelineInfo.pDynamicState = nullptr; // Optional
Then we reference all of the structures describing the fixed-function stage.布局
而后咱们引用描述固定功能阶段的全部结构体。ui
pipelineInfo.layout = pipelineLayout;
After that comes the pipeline layout, which is a Vulkan handle rather than a struct pointer.this
而后是管道布局,which是一个Vulkan句柄,而不是结构体指针。
pipelineInfo.renderPass = renderPass; pipelineInfo.subpass = 0;
And finally we have the reference to the render pass and the index of the sub pass where this graphics pipeline will be used. It is also possible to use other render passes with this pipeline instead of this specific instance, but they have to be compatible with renderPass
. The requirements for compatibility are described here, but we won't be using that feature in this tutorial.
最后,咱们引用render pass和subpass的索引where图形管道会用到。有可能这个管道还使用另外一个render pass,而不是这个,但它们必须与renderPass
兼容。对于兼容要求在here,但本教程中咱们不会用到这个特性。
pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; // Optional pipelineInfo.basePipelineIndex = -1; // Optional
There are actually two more parameters: basePipelineHandle
and basePipelineIndex
. Vulkan allows you to create a new graphics pipeline by deriving from an existing pipeline. 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. 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
. Right now there is only a single pipeline, so we'll simply specify a null handle and an invalid index. These values are only used if the VK_PIPELINE_CREATE_DERIVATIVE_BIT
flag is also specified in the flags
field of VkGraphicsPipelineCreateInfo
.
其实还有2个参数:basePipelineHandle
和basePipelineIndex
。Vulkan容许你建立新图形管道by继承一个已有的管道。这个管道继承的思想是,它比较省资源when它们不少功能相同with一个现有的管道,and在同一父管道下的管道之间切换也会更快。你能够要么用basePipelineHandle
指定一个现有管道的句柄,要么引用另外一个管道that即将被建立by basePipelineIndex
索引。如今只有一个管道,因此咱们简单地指定一个null句柄和一个无效的索引便可。这些值只会在VK_PIPELINE_CREATE_DERIVATIVE_BIT
标志也在VkGraphicsPipelineCreateInfo
的flags
字段指定时用到。
Now prepare for the final step by creating a class member to hold the VkPipeline
object:
如今准备好最后的步骤by建立一个类成员to记录VkPipeline
对象。
VkPipeline graphicsPipeline;
And finally create the graphics pipeline:
最后建立图形管道:
if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) { throw std::runtime_error("failed to create graphics pipeline!"); }
The vkCreateGraphicsPipelines
function actually has more parameters than the usual object creation functions in Vulkan. It is designed to take multiple VkGraphicsPipelineCreateInfo
objects and create multiple VkPipeline
objects in a single call.
vkCreateGraphicsPipelines
函数实际上有更多的参数that一般的对象建立函数in Vulkan。它被设计to接收多个VkGraphicsPipelineCreateInfo
对象and建立多个VkPipeline
objects对象in一个调用。
The second parameter, for which we've passed the VK_NULL_HANDLE
argument, references an optional VkPipelineCache
object. 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. This makes it possible to significantly speed up pipeline creation at a later time. We'll get into this in the pipeline cache chapter.
第二个参数,咱们传入了VK_NULL_HANDLE
,其引用一个可选的VkPipelineCache
对象。一个管道缓存能够被用于保存和复用数据that与管道建立相关-在屡次调用vkCreateGraphicsPipelines
中,甚至在屡次程序执行中if缓存被保存到了文件中。这样就又可能to显著地加速管道建立at之后。咱们将在后续章节详谈管道缓存。
The graphics pipeline is required for all common drawing operations, so it should also only be destroyed at the end of the program:
图形管道是必要的for全部经常使用绘制操做,因此它只应该在程序结尾时被销毁:
void cleanup() { vkDestroyPipeline(device, graphicsPipeline, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); ... }
Now run your program to confirm that all this hard work has resulted in a successful pipeline creation! We are already getting quite close to seeing something pop up on the screen. In the next couple of chapters we'll set up the actual framebuffers from the swap chain images and prepare the drawing commands.
如今运行你的程序to确认that全部这些艰苦努力成功地建立了管道对象!咱们已经很接近to看到屏幕上显示点东西了。接下来的几章咱们将设置帧缓存from交换链image,并准备绘制命令。
C++ code / Vertex shader / Fragment shader