[译]Vulkan教程(01)入门

[译]Vulkan教程(01)入门

接下来我将翻译(https://vulkan-tutorial.com)上的Vulkan教程。这可能是我学习Vulkan的最好方式,但不是最理想的方式。

我会用“driver(驱动程序)”这样的方式翻译某些关键词语,在后续的文字中,则只使用英文。这可以减少歧义,且使译文易读。

 

Introduction 入门

About 关于

This tutorial will teach you the basics of using the Vulkan graphics and compute API. Vulkan is a new API by the Khronos group (known for OpenGL) that provides a much better abstraction of modern graphics cards. This new interface allows you to better describe what your application intends to do, which can lead to better performance and less surprising driver behavior compared to existing APIs like OpenGL and Direct3D. The ideas behind Vulkan are similar to those of Direct3D 12 and Metal, but Vulkan has the advantage of being fully cross-platform and allows you to develop for Windows, Linux and Android at the same time.

本教程讲授Vulkan图形和计算API的基本使用。Vulkan是Khronos委员会(他们也是维护OpenGL的那帮人)提出的新的API,它提供了对现代图形卡的更好的抽象描述。这个新的接口,允许你更好地描述你的app(应用程序)想做的事。与已有的API(比如OpenGL和Direct3D)相比,这可以带来更好的性能,可以减少driver(驱动程序)的意外行为。Vulkan背后的思想与Direct3D 12和Metal相似,但是Vulkan有跨平台的优势,允许你同时为Windows、Linux和Android开发。

However, the price you pay for these benefits is that you have to work with a significantly more verbose API. Every detail related to the graphics API needs to be set up from scratch by your application, including initial frame buffer creation and memory management for objects like buffers and texture images. The graphics driver will do a lot less hand holding, which means that you will have to do more work in your application to ensure correct behavior.

但是,为了得到这些好处,你需要付出的代价是,你不得不用冗长得多的API来工作。与图形API相关的每个细节,都需要在你的app中从零开始设置好。这包括:初始化帧缓存,对对象(例如buffer(缓存)和texture image(纹理图像))的内存管理。图形driver的握手行为会少很多,这意味着你不得不在你的app里做更多工作,以确保(driver的)正确行为。

The takeaway message here is that Vulkan is not for everyone. It is targeted at programmers who are enthusiastic about high performance computer graphics, and are willing to put some work in. If you are more interested in game development, rather than computer graphics, then you may wish to stick to OpenGL or Direct3D, which will not be deprecated in favor of Vulkan anytime soon. Another alternative is to use an engine like Unreal Engine or Unity, which will be able to use Vulkan while exposing a much higher level API to you.

在此得到的结论是,Vulkan不是给所有人的。它的目标人群是狂热的且愿意为之潜心工作的高性能计算机图形程序员。如果你对游戏开发(而不是计算机图形)更感兴趣,那么你可能希望用OpenGL或Direct3D,它们不会为了支持Vulkan而很快被废弃。另一个选择是使用引擎(例如Unreal或Unity),它们将能使用Vulkan,且对你暴露高级得多的API。

With that out of the way, let's cover some prerequisites for following this tutorial:

  • A graphics card and driver compatible with Vulkan (NVIDIAAMDIntel)
  • Experience with C++ (familiarity with RAII, initializer lists)
  • A compiler compatible with C++11 (Visual Studio 2013+, GCC 4.8+)
  • Some existing experience with 3D computer graphics

把上述事情放在一边,我们来介绍一些后续教程需要的先决条件:

  • 一个图形卡和兼容Vulkan的driver(NVIDIA、AMD、Intel)
  • 使用C++的经验(熟悉RAII,初始化list)
  • 兼容C++11的编译器(Visual Studio 2013以上,GCC 4.8以上)
  • 3D计算机图形的一些经验

This tutorial will not assume knowledge of OpenGL or Direct3D concepts, but it does require you to know the basics of 3D computer graphics. It will not explain the math behind perspective projection, for example. See this online book for a great introduction of computer graphics concepts. Some other great computer graphics resources are:

本教程不要求读者知道OpenGL或Direct3D里的概念,但要求读者知道3D计算机图形基础知识。例如,本教程不会解释透视投影背后的数学。你可以参考这个不错的在线书来学计算机图形概念入门知识。其他一些不错的计算机图形学习资源有:

  • 光线追踪一周末搞定
  • 基于物理的渲染
  • 用在真实引擎里的开源项目Quake和DOOM 3里的Vulkan

You can use C instead of C++ if you want, but you will have to use a different linear algebra library and you will be on your own in terms of code structuring. We will use C++ features like classes and RAII to organize logic and resource lifetimes. There is also an alternative version of this tutorial available for Rust developers.

如果你喜欢,你可以用C代替C++,但是你将不得不用其他的线性代数库,且自己负责代码结构问题。我们将使用C++的特性(例如类和RAII)来组织逻辑和资源的生命周期。本教程还有一个给Rust开发者的版本。

To make it easier to follow along for developers using other programming languages, and to get some experience with the base API we'll be using the original C API to work with Vulkan. If you are using C++, however, you may prefer using the newer Vulkan-Hpp bindings that abstract some of the dirty work and help prevent certain classes of errors.

为了让使用其他编程语言的开发者更容易跟进,也为了体验基础API,我们将使用原始C语言API来编写Vulkan程序。但如果你用C++,你可能更喜欢这个更新的Vulkan-Hpp绑定,它搞定了一些烦人的工作,有助于避免某些错误。

E-book 电子书

If you prefer to read this tutorial as an e-book, then you can download an EPUB or PDF version here:

如果你更喜欢以电子书的形式阅读本教程,你可以下载EPUB或PDF版本:

Tutorial structure 教程结构

We'll start with an overview of how Vulkan works and the work we'll have to do to get the first triangle on the screen. The purpose of all the smaller steps will make more sense after you've understood their basic role in the whole picture. Next, we'll set up the development environment with the Vulkan SDK, the GLM library for linear algebra operations and GLFW for window creation. The tutorial will cover how to set these up on Windows with Visual Studio, and on Ubuntu Linux with GCC.

首先,我们将大概看一看,Vulkan是如何工作的,如何在屏幕上显示第一个三角形。等你理解了每个小步骤在全局的作用,它们就显得有道理了。然后,我们将配置开发环境,包括Vulkan SDK,用于线性代数操作的GLM库和用于创建窗口的GLFW。本教程会介绍如何在Windows上用Visual Studio做这些,也会介绍如何在Ubuntu Linux上用GCC做这些。

After that we'll implement all of the basic components of a Vulkan program that are necessary to render your first triangle. Each chapter will follow roughly the following structure:

  • Introduce a new concept and its purpose
  • Use all of the relevant API calls to integrate it into your program
  • Abstract parts of it into helper functions

之后,我们将实现Vulkan程序的所有基础组件,用以渲染你的第一个三角形。每一章的基本结构如下:

  • 介绍新概念及其目的
  • 使用相关API,将其集成到你的程序
  • 将其提取封装到辅助函数

Although each chapter is written as a follow-up on the previous one, it is also possible to read the chapters as standalone articles introducing a certain Vulkan feature. That means that the site is also useful as a reference. All of the Vulkan functions and types are linked to the specification, so you can click them to learn more. Vulkan is a very new API, so there may be some shortcomings in the specification itself. You are encouraged to submit feedback to this Khronos repository.

虽然每一章都是作为上一章的续集,读者仍可将其视作单独介绍某个Vulkan特性的文章。也就是说,本网站也当作参考文献来用。说明书中有所有的Vulkan函数和类型,你可以点击链接来了解更多。Vulkan是个很新的API,所以说明书中可能有一些不足。欢迎读者在这个Khronos仓库提交反馈。

As mentioned before, the Vulkan API has a rather verbose API with many parameters to give you maximum control over the graphics hardware. This causes basic operations like creating a texture to take a lot of steps that have to be repeated every time. Therefore we'll be creating our own collection of helper functions throughout the tutorial.

如前所述,Vulkan API十分冗长,参数很多,这给了你对图形硬件的最大控制权力。这导致每次创建纹理都要走很多步骤。因此本教程中我们将创建一些我们自己的辅助函数。

Every chapter will also conclude with a link to the full code listing up to that point. You can refer to it if you have any doubts about the structure of the code, or if you're dealing with a bug and want to compare. All of the code files have been tested on graphics cards from multiple vendors to verify correctness. Each chapter also has a comment section at the end where you can ask any questions that are relevant to the specific subject matter. Please specify your platform, driver version, source code, expected behavior and actual behavior to help us help you.

每章结尾都会给个链接,展示本章的完整代码。如果你对代码结构有疑问,或者你在处理bug,想找个对比,可以参考它。所有的代码文件都已经在多个厂商的图形卡上测试过,以验证其正确性。每章也有评论区,你可以就相关问题提问。请说明你的平台,驱动版本,源代码,期望的行为和实际的行为,好利于我们帮助你。

This tutorial is intended to be a community effort. Vulkan is still a very new API and best practices have not really been established yet. If you have any type of feedback on the tutorial and site itself, then please don't hesitate to submit an issue or pull request to the GitHub repository. You can watch the repository to be notified of updates to the tutorial.

本教程打算成为一个社区的尝试。Vulkan还是个很新的API,最佳实践还没有被发布出来。如果你对本教程或网站本身有任何反馈,请不要犹豫,在Github仓库提交issue或pull request就好。你可以watch这个仓库,这样就会收到本教程的更新。

After you've gone through the ritual of drawing your very first Vulkan powered triangle onscreen, we'll start expanding the program to include linear transformations, textures and 3D models.

在你按惯例经历了在屏幕上用Vulkan绘制你的第一个三角形后,我们将开始扩展这个程序,纳入线性变换,纹理和3D模型。

If you've played with graphics APIs before, then you'll know that there can be a lot of steps until the first geometry shows up on the screen. There are many of these initial steps in Vulkan, but you'll see that each of the individual steps is easy to understand and does not feel redundant. It's also important to keep in mind that once you have that boring looking triangle, drawing fully textured 3D models does not take that much extra work, and each step beyond that point is much more rewarding.

如果你之前玩过图形API,你会知道在第一个几何体显示到屏幕上之前,会有很多个步骤。Vulkan中有很多这样的初始化步骤,但你会看到,每个步骤都很容易理解,也不冗长。要记住重要的一点是,一旦你得到了那个无趣的三角形,渲染有纹理的3D模型就不需要很多其他工作了,而且之后的每一步都会很令人期待。

If you encounter any problems while following the tutorial, then first check the FAQ to see if your problem and its solution is already listed there. If you are still stuck after that, then feel free to ask for help in the comment section of the closest related chapter.

如果你在学习本教程时遇到任何问题,请先看看FAQ里是不是已经有了相应的问题和答案了。如果还是没有解决,请在相关章节的评论区大胆提问。

Ready to dive into the future of high performance graphics APIs? Let's go!

准备好深入未来的高性能图形API了?出发!

 

转载于:https://www.cnblogs.com/bitzhuwei/p/Vulkan-Tutorial-01-Introduction.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vulkan被称为OpenGL的接班人,性能果然是霸气外漏,更能够承载下一个时代的图形渲染编程。 GPU高性能渲染的课题进入了一个新的阶段,对于计算细节的控制,多核CPU多线程渲染以及高性能算法的灵活设计需求日益旺盛。图形程序员需要有更加强力且灵活的工具,来“解锁”我们自身的控制能力,OpenGL的较高度封装性以及单纯的状态机模式显然已经无法适应现代化图形渲染的强烈需求。为什么要学习Vulkan?正如前言所说,Vulkan已经成为了下一个时代的图形渲染主流API,早已经被各大商业引擎(Unreal Engine、Unity3D)所支持。那么我们的同学就有如下问题需要明晰:1 作为游戏程序员我们只学会了UE或者Unity3D,那么就只能作为一个普通的程序员,如果能够结合Vulkan的学习对商用引擎理解更加深刻,就可以更好的发挥引擎威力甚至更改引擎的源代码,实现更多的可能,让你在各大公司之间都“蛇形走位,游刃有余” 2 作为自研引擎工作人员,你可能在工业软件领域从业、也有可能在影视渲染领域从业、也可能在其他的图形系统领域(军工、GIS、BIM)等领域,那么熟练的掌握Vulkan就可以针对自己公司的不同领域需求进行不同的引擎定制开发,从而获得牢不可破的地位,对于自身职业发展有着极大的优势! 总而言之,越早学习Vulkan,就越能与别人拉开差距,让Vulkan称为你升职加薪、壮大不可替代性的核武器! 课程简介:本课程详细讲解了Vulkan从小白到入门的基础理论+实践知识,对于每一个知识点都会带领学员通过代码来实现功能。其中涵盖了计算机图形学基础理论,计算机图形学数学推导,Vulkan基础系统设计理论,基础单元(实例,设备,交换链), 渲染管线,RenderPass, 指令与多线程, 顶点描述与实验, Uniform与描述符, 图像与采样, 深度与反走样,模型与摄像机等内容;课程中会对Vulkan复杂抽象的API进行一次包装层的封装,将相关的API都进行聚合与接口设计,作为游戏或者图形引擎来讲,这是至关重要的第一步。这一个封装步骤,也被称为API-Wrapper,经过包装后的类库,同学可以在此之上根据自己的具体需求进行扩展,从而得到最适合自己的类库内容。本课程为系列化课程,在铸造基石篇章之后,会继续使用本包装类库进行改良,并且实现Vulkan API下的各类效果以及高级特性的开发教学。 课程优势:1 本课程会从计算机图形学的基础渲染管线原理出发,带领0基础的同学对计算机图形学进行快速认知,且对必要的知识点进行筛选提炼,去掉冗余繁杂的教学内容,更加适合新手对Vulkan渲染体系入门了解。 2 本课程会对计算机图形学所涉及的数学知识及如何应用到渲染当中,进行深入的讲解,带领同学对每一行公式展开认识,从三维世界如何映射到二维的屏幕,在学习完毕后会有清晰的知识体系 3 本课程会带领同学认知每一个Vulkan的API,并且在代码当中插入详细的注释,同学们在学习的时候就可以参照源代码进行一系列尝试以及学后复习 4 本课程所设计的包装层,会带领同学一行一行代码实现,现场进行Debug,对于Vulkan常出现的一些问题进行深入探讨与现场纠正  学习所得:1 同学们在学习后可以完全了解从三维世界的抽象物体,如何一步步渲染称为一个屏幕上的像素点。2 同学们在学习后可以完全掌握基础的Vulkan图形API,并且了解Vulkan当中繁多的对象之间相互的联系,从而可以设计更好的图形程序3 同学们在跟随课程进行代码编写后,可以获得一个轻量级的Vulkan底层API封装库(Wrapper),从而可以在此之上封装上层的应用,得到自己的迷你Vulkan图形渲染引擎当然,在达到如上三点之后,如果可以更进一步学习Vulkan的进阶课程,同学们可以获得更好的职业发展,升职加薪之路会更加清晰,成为公司不可替代的强力工程师 本课程含有全套源代码,同学购买后,可以在课程附件当中下载 完全不懂图形学可以学习么?使用层面上来讲是没有问题的,老师在每个api讲解的时候,都会仔细分析api背后的原理,所以可以跟随下来的话,能够编程与原理相融,学会使用 数学不好可以学习么?学习图形类课程,最好能够入门级别的线性代数,具体说就是: 1 向量操作 2 矩阵乘法 3 矩阵的逆、转置 这几个点就足够 学习后对就业面试有什么作用?目前类似Vulkan的渲染知识是一切引擎的基础,只要能够跟随每一节课写代码做下来,游戏公司、工业软件公司等都是非常容易进去的,因为原理层面已经通晓,面试就会特别有优势。同学可以在简历上写熟悉VulkanAPI并且有代码经验,对于建立筛选以及面试都会有很大的帮助,对于薪资也会有大幅度提升
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值