Vulkan教程(12): Graphics pipeline Introduction (图形管线概要)

news2024/9/23 13:28:30

Vulkan官方英文原文:https://vulkan-tutorial.com/Drawing_a_triangle/Graphics_pipeline_basics/Introduction

对应的Vulkan技术规格说明书版本: Vulkan 1.3.2

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) 从你指定的缓冲区中收集原始的顶点数据,也可能用一个索引缓冲区来重复收集特定元素而无需重复自身的顶点数据。

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) 是运行在每一个顶点上,通常用于从物体空间到屏幕空间变换顶点的空间位置。它也逐顶点地将数据沿着管线往下传。

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 shader)允许你基于一定的规则进一步细分几何体以提升模型网格的细节精度。像砖墙和楼梯,当它们靠近的时候,这个技术经常被用于产生表面细节使之看起来不那么平(看起来结构细节更多更真实)。

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)是运行在每一个图元上(例如:三角形,线段,点),并且可以选择抛弃它或者输出比输入进来的图元更多的图元。这类似于细分着色器,但是更灵活。但是在当今的应用程序中它没有被大量使用,这是因为除了Intel集成显卡外在大多数显卡上它的性能没那么好。

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)阶段将图元离散化为片段。这些片段是由一些像素元素组成的,他们填充整个帧缓冲区。任何片段落在屏幕外就被丢弃,(光栅化阶段)由顶点着色器计算输出的属性是片段间插值计算出来的。如上图所示。由于深度测试,通常在其他图元片段后面的片段也会被丢弃。

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)应用于每个没有被丢弃的片段,并且决定片段将颜色和深度数据写入哪些帧缓冲区。片段着色器能利用顶点着色器插值计算得到的数据做到这些事情,其中可以包括像纹理坐标计算和用于光追的法线计算。

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)阶段应用混合不同片段的操作,这些被混合的片段是在帧缓冲区中的对应于相同像素的片段。这些片段可以简单地相互覆盖、叠加或者基于透明度混合。

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.

(上图中)红色阶段是可编程阶段,也就是说你可以将你的相关代码上传到显卡,以便准确的实现你想要的操作。例如,这就允许你使用片段着色器去实现纹理和光追光照的各自操作。这些程序在多个GPU计算单元同时运行,并行处理多个目标任务,例如并行执行多个顶点和片段操作。

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.

假如你以前用过像Opengl和DirectX3D这些旧的API,那么你需要调用像 glBlendFunc 和 OMSetBlendState 这类函数去改变渲染管线的设置。假如你想改变shader,绑定到不同的帧缓冲区或者改变混合功能,由于Vulkan中的图形管线几乎完全不可变,因此你必须从头新建一个管线。(这种机制的)缺点在于你必须创建一些管线,它们表示在你渲染操作中所需的各种不同的状态组合。但是,由于在管线中你要做的所有操作都事先知道,驱动程序可以把这些渲染过程优化的更好。

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.

许多可编程阶段是依据你的需要可选择的。例如,如果你只是绘制基本的几何体,那么细分着色阶段和几何着色阶段可以被去掉。如果你只关心深度值(用于生成阴影贴图: shadow map),那你可以去掉片段着色阶段。

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.

在下个章节,我们将首先创建两个可编程阶段,用于将三角形显示在屏幕上,这两个阶段是:顶点着色和片段着色。固定功能配置像混合模式、视口、光栅化这些设置在之后的章节细说。

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

创建一个 createGraphicsPipeline 函数,在 initVulkan 函数内部的 createImageViews 函数之后调用。

我们将在接下来的章节中使用这个函数。

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

...

void createGraphicsPipeline() {

}

补充一些 Vulkan 的图形管线相关知识:

Dynamic State

请见:https://blog.csdn.net/vily_lei/article/details/128995011

Understanding vulkan objects: https://gpuopen.com/learn/understanding-vulkan-objects/

https://github.com/David-DiGioia/vulkan-diagrams

关于Vulkan Ray Tracing

注:TLAS是顶层加速结构,BLAS是底层加速结构。

Ray tracing in Vulkan consists of building acceleration structures, creating a ray tracing pipeline and shader binding table (SBT), and then tracing the rays with vkCmdTraceRaysKHR(...). There is also ray VK_KHR_ray_query for casting rays in existing shaders and does not require a ray tracing pipeline, but that is not discussed here.

Most of the work of building the acceleration structures is done by the driver, but the application developer is responsible for placing instances within a top-level acceleration structure (TLAS), grouping their primitives into bottom-level acceleration structures (BLASes) and within that BLAS grouping the primitives into geometries. How this is done can have a significant impact on performance. I've written an article on GPUOpen that goes into detail of best practices for ray tracing performance.

The first diagram shows the Vulkan objects needed to build a BLAS.

Note that almost no implementation supports VkPhysicalDeviceAccelerationStructureFeaturesKHR::accelerationStructureHostCommands so most likely you will need to build the acceleration structures on the device, as pictured in the diagrams. This makes compacting BLASes more complicated because it requires two queue submissions. The process to compact a BLAS is as follows:

Add VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR flag to VkAccelerationStructureBuildGeometryInfoKHR::flags for original acceleration structure that is built.

Create original acceleration structure.

Create VkQueryPool with a VkQueryPoolCreateInfo::queryType of VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR.

Query the compacted size with vkCmdWriteAccelerationStructuresPropertiesKHR(...).

Submit the command buffer then get the query results with vkGetQueryPoolResults(...).

Create a VkAccelerationStructureKHR with a VkBuffer with compacted size from query.

Start recording a new command buffer.

Copy the original acceleration structure to the compacted one using vkCmdCopyAccelerationStructureKHR(...) with VkCopyAccelerationStructureInfoKHR::mode set to VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR.

Submit command buffer.

The next diagram shows the Vulkan objects needed to build a TLAS.

Lastly, the ray tracing pipeline and shader binding table.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/341173.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

你知道MySQL中like 关键字也能用索引嘛?

上篇文章中,我和大家分享了索引的两个使用规则: 索引上不要使用函数运算。使用覆盖索引避免回表。 当然,凡事有个度,用哪一种策略也要结合具体的项目来定,不能为了 SQL 优化而抛弃了业务。 在前文的基础上&#xff0…

Mac安装Homebrew排坑大全..

官网:https://brew.sh/BACKGROUND: 安装Homebrew嘎嘎报错!question one网络不通,需要配置一下github.com的hostError:fatal: unable to access https://github.com/Homebrew/homebrew-core/: error:02FFF036:system library:func(…

电子电气架构——基于CANoe实现两路CAN线间网关仿真

基于CANoe实现两路CAN线间网关仿真 魔都的天气也很魔性,白天酷热无比,现在晚上九点又狂风大作,凉爽宜人。 天气的不可预见性与个人生活极其相似,都有随机、不可控的成分,自己能做的就是不懊悔昨天已发生,不寄托于未来未发生,只想过好当下这时光。 老规矩,分享一段喜…

【不知道是啥】浅保存哈

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注…

Linux系统安全之iptables防火墙

目录 一.iptables防火墙基本介绍 二.iptables的四表五链 三.iptables的配置 1.iptables的安装 2.iptables防火墙的配置方法 四.添加、查看、删除规则 1.查看(fliter)表中的所有链 iptables -L 2.使用数字形式(fliter)表所有链 查看输出结果 iptables -nL 3.清空表中所…

算法刷题打卡第88天:字母板上的路径

字母板上的路径 难度:中等 我们从一块字母板上的位置 (0, 0) 出发,该坐标对应的字符为 board[0][0]。 在本题里,字母板为board ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "…

【Java|golang】1138. 字母板上的路径

我们从一块字母板上的位置 (0, 0) 出发,该坐标对应的字符为 board[0][0]。 在本题里,字母板为board [“abcde”, “fghij”, “klmno”, “pqrst”, “uvwxy”, “z”],如下所示。 我们可以按下面的指令规则行动: 如果方格存…

【计组】理解Disruptor--《计算机组成原理》(十五)

Disruptor 的开发语言,并不是很多人心目中最容易做到性能极限的 C/C,而是性能受限于 JVM 的 Java。其实只要通晓硬件层面的原理,即使是像 Java 这样的高级语言,也能够把 CPU 的性能发挥到极限。 一、Padding Cache Line&#xff…

mysql中mvcc实现机制和原理

目录 1.什么是mvcc? 2.mvcc中的快照读和当前读有什么区别和联系? 3.mvcc的作用是什么? 4.mvcc的实现机制和原理是什么? 1.什么是mvcc? mvcc全称是(Multi-Version Concurrency Control) 多版本并发控制,是数据库管理过程中的一种并发控制…

keras+IMDB情感分析

目录简介IDMB数据集数据预处理数据加载数据清洗保存经过清洗后的数据训练测试数据集分割文字编码词嵌入模型构建模型训练训练效果模型评分模型预测及混淆矩阵查看F1 Score、召回率等信息预测新的影评总结本博客参考: 【python自然语言处理 周元哲著】 【keras中文文…

数据库索引篇(二叉树/B-Tree)对比结构讲解

我们可以先看一下 二叉树的一个结构 简单将数据分成左右两侧 左侧小于36 右侧大于36 在下面再以这种方式继续划分 但二叉树的结构就有一个非常大的弊端 如果我们后续插入的数据全部小于 或 大于36 他就会 变成这样 一个链表 查询效率大大降低 因为 比如 你想找什么数据 都会…

岁月闲思——时间给我地思考

岁月闲思——时间给我地思考 2022年6月10日,明天又一个周末,成人地时间总是让人感觉一天很慢,一周以及一年反而很快。 下班到家,吃过长辈做的手工凉皮,得空坐在电脑面前敲击点文字,记录下时间留给自己地印…

Docker--consul

目录 前言 一、Consul 简介 1.1、 consul 概述 1.2 、consul 的两种模式 1.3、consul 提供的一些关键特性 二、Consul 容器服务更新与发现 三、consul 部署 3.2、查看集群信息 四、registrator服务器 consul-template 五、consul 多节点 前言 服务注册与发现是微服…

软件测试面试十大必考题目(通用)

目录 (1) 为什么想进本公司? (2) 喜欢这份工作的哪一点? (3) 自己的优缺点为何? (4) 对公司的了解有多少? (5&#xf…

C++创建多线程的方法总结

下个迭代有个任务很有趣,用大量的线程去访问一个接口,直至其崩溃为止,这就需要多线程的知识,这也不是什么难事,总结一下C中的多线程方法:std、boost、pthread、windows api。 目录 一、多线程预备知识 二…

图解浏览器渲染页面详细过程

渲染详细过程 产生渲染任务,开启渲染流程 当浏览器的网络线程收到 HTML 文档后,会产生一个渲染任务,并将其传递给渲染主线程的消息队列。 在事件循环机制的作用下,渲染主线程取出消息队列中的渲染任务,开启渲染流程。…

IDEA 常用快捷键回顾

一 Alt 数字键 1. Alt 1: 打开项目 2. Alt 2: 打开Favorites 3. Alt 3: 打开Find 4. Alt 4: 打开Run 5. Alt 5: 打开Debug 6. Alt 6: 打开当前所在文件 7. Alt 7: 打开Structure 8. Alt 8: 打开Services 9. Alt 9: 打开Git日志 二 Ctrl 其他键 1. Ctrl…

【Flink】详解JobGraph

概述 JobGraph 是 StreamGraph 优化后的产物,客户端会将优化后的 JobGraph 发送给 JM。接下来的文章涉及到一些前置知识点,没有看前几期的小伙伴最好看一下前几期: 【Flink】详解StreamGraph【Flink】浅谈Flink架构和调度【Flink】详解Flin…

【Flutter入门到进阶】Dart进阶篇---进阶用法

1 Dart对象扩展 1.1 extension 1.1.1 介绍 可以在不更改类或创建子类的情况下,向类添加扩展功能的一种方式。灵活使用 extension 对基础类进行扩展,对开发效率有显著提升。 1.1.2 需求 在开发项目中碰到需求:将单位为分的数值转换成单位为…

RabbitMQ(黑马spring cloud笔记)

MQ 目录MQ一、同步通讯和异步通讯1. 同步通讯2. 异步通讯二、RabbitMQ1. 部署2. 架构3. 常见消息模型3.1 基本消息队列(Basic Queue)3.2 工作消息队列(Work Queue)3.3 发布订阅(Publish、Subscribe)4. 消息…