[譯]Vulkan教程(01)入門html
接下來我將翻譯(https://vulkan-tutorial.com)上的Vulkan教程。這多是我學習Vulkan的最好方式,但不是最理想的方式。git
我會用「driver(驅動程序)」這樣的方式翻譯某些關鍵詞語,在後續的文字中,則只使用英文。這能夠減小歧義,且使譯文易讀。程序員
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.github
本教程講授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.windows
可是,爲了獲得這些好處,你須要付出的代價是,你不得不用冗長得多的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.app
在此獲得的結論是,Vulkan不是給全部人的。它的目標人羣是狂熱的且願意爲之潛心工做的高性能計算機圖形程序員。若是你對遊戲開發(而不是計算機圖形)更感興趣,那麼你可能但願用OpenGL或Direct3D,它們不會爲了支持Vulkan而很快被廢棄。另外一個選擇是使用引擎(例如Unreal或Unity),它們將能使用Vulkan,且對你暴露高級得多的API。less
With that out of the way, let's cover some prerequisites for following this tutorial:編程語言
把上述事情放在一邊,咱們來介紹一些後續教程須要的先決條件:
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計算機圖形基礎知識。例如,本教程不會解釋透視投影背後的數學。你能夠參考這個不錯的在線書來學計算機圖形概念入門知識。其餘一些不錯的計算機圖形學習資源有:
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綁定,它搞定了一些煩人的工做,有助於避免某些錯誤。
If you prefer to read this tutorial as an e-book, then you can download an EPUB or PDF version here:
若是你更喜歡以電子書的形式閱讀本教程,你能夠下載EPUB或PDF版本:
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:
以後,咱們將實現Vulkan程序的全部基礎組件,用以渲染你的第一個三角形。每一章的基本結構以下:
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