没有合适的资源?快使用搜索试试~ 我知道了~
首页Vulkan Tutorial
Vulkan 官方手册,英文原版。 Vulkan是一个跨平台的2D和3D绘图应用程序接口(API) 同 OpenGL® 一样,Vulkan™ 也由 Khronos 集团开发。它是 AMD Mantle 的后续版本,继承了前者强大的低开销架构,使软件开发人员能够全面获取 Radeon™ GPU 与多核 CPU 的性能、效率和功能 相对于 OpenGL,Vulkan™ 大幅降低了 CPU 在提供重要特性、性能和影像质量时的“API 开销”[2] (CPU 在分析游戏的硬件需求时所执行的后台工作),而且可以使用通常通过 OpenGL 无法访问的 GPU 硬件特性。
资源详情
资源评论
资源推荐

Vulkan Tutorial
Alexander Overvoorde
May 2017
Contents
Introduction 5
About . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Tutorial structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Overview 7
Origin of Vulkan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
What it takes to draw a triangle . . . . . . . . . . . . . . . . . . . . . 8
Step 1 - Instance and physical device selection . . . . . . . . . . . 9
Step 2 - Logical device and queue families . . . . . . . . . . . . . 9
Step 3 - Window surface and swap chain . . . . . . . . . . . . . . 9
Step 4 - Image views and framebuffers . . . . . . . . . . . . . . . 10
Step 5 - Render passes . . . . . . . . . . . . . . . . . . . . . . . . 10
Step 6 - Graphics pipeline . . . . . . . . . . . . . . . . . . . . . . 10
Step 7 - Command pools and command buffers . . . . . . . . . . 11
Step 8 - Main loop . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
API concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Coding conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Validation layers . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Vulkan SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
GLFW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
GLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Setting up Visual Studio . . . . . . . . . . . . . . . . . . . . . . . 19
Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Vulkan SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
GLFW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
GLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Setting up a makefile project . . . . . . . . . . . . . . . . . . . . 29
Base code 33
General structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1

Resource management . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Integrating GLFW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Instance 39
Creating an instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Checking for extension support . . . . . . . . . . . . . . . . . . . . . . 41
Validation layers 42
What are validation layers? . . . . . . . . . . . . . . . . . . . . . . . . 42
Using validation layers . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Message callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Physical devices and queue families 49
Selecting a physical device . . . . . . . . . . . . . . . . . . . . . . . . . 49
Base device suitability checks . . . . . . . . . . . . . . . . . . . . . . . 50
Queue families . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Logical device and queues 54
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Specifying the queues to be created . . . . . . . . . . . . . . . . . . . . 55
Specifying used device features . . . . . . . . . . . . . . . . . . . . . . 55
Creating the logical device . . . . . . . . . . . . . . . . . . . . . . . . . 56
Retrieving queue handles . . . . . . . . . . . . . . . . . . . . . . . . . 57
Window surface 57
Window surface creation . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Querying for presentation support . . . . . . . . . . . . . . . . . . . . 59
Creating the presentation queue . . . . . . . . . . . . . . . . . . . . . 60
Swap chain 61
Checking for swap chain support . . . . . . . . . . . . . . . . . . . . . 61
Querying details of swap chain support . . . . . . . . . . . . . . . . . . 63
Choosing the right settings for the swap chain . . . . . . . . . . . . . . 65
Surface format . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Presentation mode . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Swap extent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Creating the swap chain . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Retrieving the swap chain images . . . . . . . . . . . . . . . . . . . . . 71
Image views 72
Graphics pipeline basics 74
Shader modules 77
Vertex shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Fragment shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
2

Per-vertex colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Compiling the shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Loading a shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Creating shader modules . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Shader stage creation . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Fixed functions 87
Vertex input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Input assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Viewports and scissors . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Rasterizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Multisampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Depth and stencil testing . . . . . . . . . . . . . . . . . . . . . . . . . 92
Color blending . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Dynamic state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Pipeline layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Render passes 95
Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Attachment description . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Subpasses and attachment references . . . . . . . . . . . . . . . . . . . 97
Render pass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Graphics pipeline construction 99
Framebuffers 101
Command buffers 103
Command pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Command buffer allocation . . . . . . . . . . . . . . . . . . . . . . . . 104
Starting command buffer recording . . . . . . . . . . . . . . . . . . . . 106
Starting a render pass . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Basic drawing commands . . . . . . . . . . . . . . . . . . . . . . . . . 107
Finishing up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Rendering and presentation 108
Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Acquiring an image from the swap chain . . . . . . . . . . . . . . . . . 110
Submitting the command buffer . . . . . . . . . . . . . . . . . . . . . . 111
Subpass dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Swap chain recreation 116
3

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Recreating the swap chain . . . . . . . . . . . . . . . . . . . . . . . . . 116
Window resizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Suboptimal or out-of-date swap chain . . . . . . . . . . . . . . . . . . 118
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Vertex shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Vertex data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Binding descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Attribute descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Pipeline vertex input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Buffer creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Memory requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Memory allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Filling the vertex buffer . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Binding the vertex buffer . . . . . . . . . . . . . . . . . . . . . . . . . 128
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Transfer queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Abstracting buffer creation . . . . . . . . . . . . . . . . . . . . . . . . 131
Using a staging buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Index buffer 135
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Index buffer creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Using an index buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Descriptor layout and buffer 140
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Vertex shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Descriptor set layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Uniform buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Updating uniform data . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Descriptor pools and sets 147
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Descriptor pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Using a descriptor set . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Multiple descriptor sets . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Images 152
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Image library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Loading an image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Staging image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
4

Texture image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Layout transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Copying images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Preparing the texture image . . . . . . . . . . . . . . . . . . . . . . . . 166
Transition barrier masks . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Texture image view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Samplers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Updating the descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Texture coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
3D geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Depth image and view . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Render pass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Framebuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Clear values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Depth and stencil state . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Handling window resize . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Loading models 193
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Sample mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Loading vertices and indices . . . . . . . . . . . . . . . . . . . . . . . . 195
Vertex deduplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
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.
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
5
剩余200页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0