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

Introduction 入门

Over the course of the next few chapters we'll be setting up a graphics pipeline that is configured to draw our first triangle. The graphics pipeline is the sequence of operations that take the vertices and textures of your meshes all the way to the pixels in the render targets. A simplified overview is displayed below:

接下来的几个章节里,我们将设置图形管道,以绘制第一个三角形。图形管道是一系列的操作,它接收网格的顶点和纹理,(处理之)一直到渲染目标的像素上。一个简化的概览图如下所示:

The input assembler collects the raw vertex data from the buffers you specify and may also use an index buffer to repeat certain elements without having to duplicate the vertex data itself.

input assembler 收集原始顶点数据from你指定的buffer,还可能使用一个index buffer to重复某些元素without必须重复顶点数据本身。

The vertex shader is run for every vertex and generally applies transformations to turn vertex positions from model space to screen space. It also passes per-vertex data down the pipeline.

vertex shader 运行for每个顶点,一般施展变换to变换顶点位置from模型空间to屏幕空间。它也传递逐顶点的数据down到pipeline(的后续阶段)。

The tessellation shaders allow you to subdivide geometry based on certain rules to increase the mesh quality. This is often used to make surfaces like brick walls and staircases look less flat when they are nearby.

tessellation shaders 允许你细分几何体 基于某种规则to增加网格质量。这常用于让表面例如砖墙和楼梯看起来不那么平坦when它们靠近(摄像机)。

The geometry shader is run on every primitive (triangle, line, point) and can discard it or output more primitives than came in. This is similar to the tessellation shader, but much more flexible. However, it is not used much in today's applications because the performance is not that good on most graphics cards except for Intel's integrated GPUs.

geometry shader 运行on每个图元(三角形、线、点)and能忽略图元或产生更多图元。这与tessellation shader相似,但是更加可扩展。但是,它在现在的app里应用并不多,因为性能不怎么好on大多数图形卡上,除了Intel的集成GPU。

The rasterization stage discretizes the primitives into fragments. These are the pixel elements that they fill on the framebuffer. Any fragments that fall outside the screen are discarded and the attributes outputted by the vertex shader are interpolated across the fragments, as shown in the figure. Usually the fragments that are behind other primitive fragments are also discarded here because of depth testing.

rasterization 阶段将图元分解为fragment。这是要填入帧缓存的像素候选人。任何落到屏幕外的Fragment都会被忽略,顶点shader输出的属性被插值到Fragment上,如图所示。通常,在其他Fragment后面的Fragment也会被忽略-由于深度测试。

The fragment shader is invoked for every fragment that survives and determines which framebuffer(s) the fragments are written to and with which color and depth values. It can do this using the interpolated data from the vertex shader, which can include things like texture coordinates and normals for lighting.

fragment shader 被调用for每个幸存的Fragment-and决定了Fragment写入哪个帧缓存,写入什么颜色,什么深度值。它可以用插值的数据from顶点shader-which可能包含例如纹理坐标和法线for光照之类的东西。

The color blending stage applies operations to mix different fragments that map to the same pixel in the framebuffer. Fragments can simply overwrite each other, add up or be mixed based upon transparency.

color blending 阶段试试操作to混合不同的Fragment-that映射到帧缓存的同一像素上。Fragment可以简单地覆盖另一个Fragment,加起来or基于透明度来混合。

Stages with a green color are known as fixed-function stages. These stages allow you to tweak their operations using parameters, but the way they work is predefined.

绿色的阶段被称为固定功能阶段。这些阶段允许你用参数修改其操作,但是它们的工作方式是预定义了的。

Stages with an orange color on the other hand are programmable, which means that you can upload your own code to the graphics card to apply exactly the operations you want. This allows you to use fragment shaders, for example, to implement anything from texturing and lighting to ray tracers. These programs run on many GPU cores simultaneously to process many objects, like vertices and fragments in parallel.

橙色的阶段是programmable(可编程的),which意味着你可以上传自己的代码to图形卡to实施你想要的操作。例如,这允许你使用Fragment shader-to实现任何事from纹理贴图和光照to光线追踪。这些程序同时运行在许多GPU核心上to并行处理大量对象,例如顶点和Fragment。

If you've used older APIs like OpenGL and Direct3D before, then you'll be used to being able to change any pipeline settings at will with calls like glBlendFunc and OMSetBlendState. The graphics pipeline in Vulkan is almost completely immutable, so you must recreate the pipeline from scratch if you want to change shaders, bind different framebuffers or change the blend function. The disadvantage is that you'll have to create a number of pipelines that represent all of the different combinations of states you want to use in your rendering operations. However, because all of the operations you'll be doing in the pipeline are known in advance, the driver can optimize for it much better.

如果你用过旧API例如OpenGL和Direct3D,那么你将习惯于能够修改任何管道配置with调用例如glBlendFunc 和OMSetBlendState。在Vulkan中的图形管道几乎是不可变的,所以你必须重建管道if你想替换shader,绑定不同的帧缓存or修改混合功能。缺点是,你必须创建很多管道that代表所有这些不同的状态组合that你想在你的app中用的。但是,由于你在管道中所有要做的操作都已经提前知道了,驱动可以优化得好的多。

Some of the programmable stages are optional based on what you intend to do. For example, the tessellation and geometry stages can be disabled if you are just drawing simple geometry. If you are only interested in depth values then you can disable the fragment shader stage, which is useful for shadow map generation.

有的可编程阶段是可选的-基于你想做什么。例如,tessellation和geometry阶段可以被忽略if你只想绘制简单的几何体。If你只对深度值感兴趣,那么你可以禁用Fragment sader阶段,which对阴影映射生成有用。

In the next chapter we'll first create the two programmable stages required to put a triangle onto the screen: the vertex shader and fragment shader. The fixed-function configuration like blending mode, viewport, rasterization will be set up in the chapter after that. The final part of setting up the graphics pipeline in Vulkan involves the specification of input and output framebuffers.

下一章,我们将创建2个可编程阶段-用于将三角形显示到屏幕上:顶点shader和Fragment shader。固定功能配置例如混合模式、视口、光栅化会在之后的章节配置。设置Vulkan图形管道的最后部分涉及到对帧缓存input和output的说明。

Create a createGraphicsPipeline function that is called right after createImageViews in initVulkan. We'll work on this function throughout the following chapters.

创建createGraphicsPipeline 函数that在initVulkan函数的createImageViews 之后调用。我们将编写这个函数-在后续几章里。

 void initVulkan() {
createInstance();
setupDebugCallback();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createSwapChain();
createImageViews();
createGraphicsPipeline();
} ... void createGraphicsPipeline() { }

C++ code

[译]Vulkan教程(12)图形管道基础之入门的更多相关文章

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

    [译]Vulkan教程(16)图形管道基础之总结 Conclusion 总结 We can now combine all of the structures and objects from the ...

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

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

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

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

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

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

  5. [译]Vulkan教程(08)逻辑设备和队列

    [译]Vulkan教程(08)逻辑设备和队列 Introduction 入门 After selecting a physical device to use we need to set up a  ...

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

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

  7. [译]Vulkan教程(03)开发环境

    [译]Vulkan教程(03)开发环境 这是我翻译(https://vulkan-tutorial.com)上的Vulkan教程的第3篇. In this chapter we'll set up y ...

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

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

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

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

随机推荐

  1. 浅析Java常量池

    Java常量池 Java常量池其实分为两种:静态常量池和运行时常量池 1.静态常量池 所谓静态常量池,即*.class文件中的常量池,class文件中的常量池不仅仅包含字符串(数字)字面量,还包含类. ...

  2. 016_List/Set/Map

    先写一下3这种遍历方法 for循环 List<Teacher> list = new ArrayList<>(); list.add(new Teacher("张三& ...

  3. python学习-pandas

    import pandas as pd # DataForm 二维数据# print(pd.read_excel("datas.xlsx")) # 多行数据 - 加载表单s = p ...

  4. js方法中参数传过来的值包含括号

    前提,传递的id为变量值,比如从后台获取数据循环,在每个循环里调用shenpi()方法,假设传的id包含括号,例如 20190329100833(更正) 这样的数据,那么直接调用会报错,控制台会报错: ...

  5. BottomNavigationView 的使用

    转载请注明出处:http://blog.csdn.net/wl9739/article/details/52875710 BottomNavigationView 很早之前就在 Material De ...

  6. CCF-CSP题解 201712-3 Crontab

    做完一定要仔仔细细地看一遍题目再交,之后发现坑点只能追悔莫及.比如这次"英文缩写(不区分大小写)"\(OwQ\). 给定多个周期性执行的任务,每个任务调度执行有时间的要求.求给定时 ...

  7. 03-EF Core笔记之查询数据

    EF Core使用Linq进行数据查询. 基本查询 微软提供了一百多个示例来演示查询,地址:https://code.msdn.microsoft.com/101-LINQ-Samples-3fb98 ...

  8. Python爬虫入门CentOS环境安装

    前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:梦想橡皮擦 CentOS环境安装-简介你好,当你打开这个文档的时候,我知 ...

  9. MESSAGE_TYPE_X dump in RSM_DATASTATE_CHECK -6-

    DTP抽数时系统Dump 参考sapnote:2398760 - MESSAGE_TYPE_X dump in RSM_DATASTATE_CHECK -1- to -12- RSM_DATASTAT ...

  10. Python定做一个计算器,小而美哒~

    使用qt designer ,按装anaconda后,在如下路径找到: conda3.05\Library\bin designer.exe文件,双击启动: ​ 创建窗体,命名为XiaoDing,整个 ...