[译]Vulkan教程(16)图形管道基础之总结

Conclusion 总结

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:

  • Shader stages: the shader modules that define the functionality of the programmable stages of the graphics pipeline
  • Fixed-function state: all of the structures that define the fixed-function stages of the pipeline, like input assembly, rasterizer, viewport and color blending
  • Pipeline layout: the uniform and push values referenced by the shader that can be updated at draw time
  • Render pass: the attachments referenced by the pipeline stages and their usage

我们现在可以将之前章节的所有结构体和对象组合起来to创建图形管道了!下面是我们有的对象的类型,快速回顾一下:

  • Shader阶段:shader模块that定义可编程阶段的功能of图形管道。
  • 固定功能状态:所有的结构体that定义固定功能阶段of管道,例如输入组装、光栅化、视口和颜色混合。
  • 管道布局:uniform和push值that被shader引用that可以在绘制时更新。
  • Render pass:附件that被管道阶段引用和附件的用法。

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 之前,因为这些在创建过程中还是在被用到。

VkGraphicsPipelineCreateInfo pipelineInfo = {};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount = ;
pipelineInfo.pStages = shaderStages;

We start by referencing the array of VkPipelineShaderStageCreateInfo structs.

开始时,我们引用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.

然后我们引用描述固定功能阶段的所有结构体。

pipelineInfo.layout = pipelineLayout;

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

然后是管道布局,which是一个Vulkan句柄,而不是结构体指针。

pipelineInfo.renderPass = renderPass;
pipelineInfo.subpass = ;

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 = -; // 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 标志也在VkGraphicsPipelineCreateInfoflags 字段指定时用到。

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, , &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 VkPipelineobjects in a single call.

vkCreateGraphicsPipelines 函数实际上有更多的参数that通常的对象创建函数in Vulkan。它被设计to接收多个VkGraphicsPipelineCreateInfo 对象and创建多个VkPipelineobjects对象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

[译]Vulkan教程(16)图形管道基础之总结的更多相关文章

  1. [译]Vulkan教程(15)图形管道基础之RenderPass

    [译]Vulkan教程(15)图形管道基础之RenderPass Render passes Setup 设置 Before we can finish creating the pipeline, ...

  2. [译]Vulkan教程(14)图形管道基础之固定功能

    [译]Vulkan教程(14)图形管道基础之固定功能 Fixed functions 固定功能 The older graphics APIs provided default state for m ...

  3. [译]Vulkan教程(13)图形管道基础之Shader模块

    [译]Vulkan教程(13)图形管道基础之Shader模块 Shader modules Unlike earlier APIs, shader code in Vulkan has to be s ...

  4. [译]Vulkan教程(12)图形管道基础之入门

    [译]Vulkan教程(12)图形管道基础之入门 Introduction 入门 Over the course of the next few chapters we'll be setting u ...

  5. [译]Vulkan教程(04)基础代码

    [译]Vulkan教程(04)基础代码 General structure 通用结构 In the previous chapter you've created a Vulkan project w ...

  6. [译]Vulkan教程(33)多重采样

    [译]Vulkan教程(33)多重采样 Multisampling 多重采样 Introduction 入门 Our program can now load multiple levels of d ...

  7. [译]Vulkan教程(28)Image视图和采样器

    [译]Vulkan教程(28)Image视图和采样器 Image view and sampler - Image视图和采样器 In this chapter we're going to creat ...

  8. [译]Vulkan教程(26)描述符池和set

    [译]Vulkan教程(26)描述符池和set Descriptor pool and sets 描述符池和set Introduction 入门 The descriptor layout from ...

  9. [译]Vulkan教程(18)命令buffers

    [译]Vulkan教程(18)命令buffers Command buffers 命令buffer Commands in Vulkan, like drawing operations and me ...

随机推荐

  1. elasticsearch-6.2.4 + kibana-6.2.4-windows-x86_64安装配置

    1.es和kibana的版本都是6.2.4 elasticsearch-6.2.4 + kibana-6.2.4-windows-x86_64 2.先安装es,下载下来解压, config目录下修改  ...

  2. 基于 Blazui 的 Blazor 后台管理模板 BlazAdmin 正式尝鲜

    简介 BlazAdmin 是一个基于Blazui的后台管理模板,无JS,无TS,非 Silverlight,非 WebForm,一个标签即可使用. 我将在下一篇文章讨论 Blazor 服务器端渲染与客 ...

  3. 【VUE】数组

    [VUE]常用函数 转载:https://www.cnblogs.com/yangchongxing/p/10637087.html 目录 ============================== ...

  4. [权限管理系统篇] (五)-Spring security(授权过程分析)

    欢迎关注公众号[Ccww笔记],原创技术文章第一时间推出 前言 权限管理系统的组件分析以及认证过程的往期文章: Spring security (一)架构框架-Component.Service.Fi ...

  5. React一键复制

    如题,我们怎么在React或者其他的框架中实现一键复制呢,实际上实现一键复制的代码与框架无关,因为他是用的是原生的API,下面我们用React来实现一下    效果: 核心代码: 直接将红框处改为需要 ...

  6. HA: Infinity Stones Vulnhub Walkthrough

    下载地址: https://www.vulnhub.com/entry/ha-infinity-stones,366/ 主机扫描: 目录枚举 我们按照密码规则生成字典:gam,%%@@2012 cru ...

  7. day01-day02 初识java、注释、变量、变量命名、基本数据类型

    1. 初识java 1) 什么是java java是一门高级的计算机编程语言 2) JDK的安装 2.1) 下载2.2) 安装2.3) 验证 3) 环境变量的配置 3.1) 打开环境变量3.2) 配置 ...

  8. 计算属性computed

    computed 在Vue中有多种方法为视图设置值: 1.使用指令直接将数据值绑定到视图 2.使用简单的表达式对内容进行简单的转换 3.使用过滤器对内容进行简单的转换 除此之外,我们还可以使用计算属性 ...

  9. 「专题总结」LCT入门

    上次xuefeng说我的专题总结(初探插头dp)太不适合入门了,所以这次丢一些题解包以外的东西. 关键是我自己也不会...急需梳理一下思路... (让我口胡数据结构???顺便推广一下全世界最短的lct ...

  10. LINUX OS EXERCISE 08

    1 配置crontab计划任务时,记录的格式是什么? 分钟 小时 日期 月份 星期 可执行语句 2 配置crontab计划任务实例. 以root用户身份添加计划任务,每天早上7:30启动sshd服务, ...