在 Windows 系统上配置 Visual Studio 的 Vulkan 开发环境
Vulkan Tutorial
https://vulkan-/
Development environment - Windows
https://vulkan-/Development_environment
1 Vulkan - Cross platform 3D Graphics
/
Vulkan is a new generation graphics and compute APIthat provides high-efficiency, cross-platform access to modern graphics processing units (GPUs), which are used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms. The Vulkan API was created by the Khronos Group, a consortium of technology hardware and software companies.
Vulkan is a low-overhead, cross-platform API, open standard for 3D graphics and computing.Vulkan targets high-performance real-time 3D graphics applications, such as video games and interactive media. Vulkan is intended to offer higher performance and more efficient CPU and GPU usage compared to older OpenGL and Direct3D 11 APIs. It provides a considerably lower-level API for the application than the older APIs, making Vulkan comparable to Apple’s Metal API and Microsoft’s Direct3D 12 and harder to use than the higher-level OpenGL and Direct3D 11 APIs. In addition to its lower CPU usage, Vulkan is designed to allow developers to better distribute work among multiple CPU cores.
Vulkan 是一个低开销、跨平台的 3D graphics and computing 的应用程序接口 (API)。Vulkan 针对全平台实时 3D 图形程序而设计,并提供高性能与更均衡的 CPU 与 GPU 利用率。Vulkan 是一个底层 API,而且能执行并行任务,Vulkan 还能更好地分配多个 CPU 核心的使用。
Vulkan was first announced by the non-profit Khronos Group at GDC .The Vulkan API was initially referred to as the “next generation OpenGL initiative
”, or “OpenGL next
” by Khronos, but use of those names was discontinued when “Vulkan” was announced.
Vulkan 由 Khronos Group 在 年游戏开发者大会 (GDC) 上发表。正式宣布 Vulkan 之后这些名字就没有再使用了。
Vulkan is derived from and built upon components of AMD’s Mantle API, which was donated by AMD to Khronos with the intent of giving Khronos a foundation on which to begin developing a low-level API that they could standardize across the industry.
Vulkan 基于 AMD’s Mantle API 构建,AMD 将其捐赠给 Khronos Group,给予该组织开发底层 API 的基础,使其像 OpenGL 一样成为行业标准。
Vulkan offers lower overhead, more direct control over the GPU, and lower CPU usage.
Vulkan 旨在提供更低的 CPU 开销与更直接的 GPU 控制。
console [kənˈsəʊl]:vt. 安慰,抚慰,慰藉 n. (机器、电子设备等的) 控制台,操纵台,仪表板consortium [kənˈsɔː(r)tiəm]:n. 联盟,(合作进行某项工程的) 财团,银团,联营企业
1.1 Vulkan GPU Resources - SDKs
/tools
Essentials tools, documentation and libraries for every Vulkan developer.
The most important component you’ll need for developing Vulkan applications is the SDK. It includes the headers, standard validation layers, debugging tools and a loader for the Vulkan functions. The loader looks up the functions in the driver at runtime, similarly to GLEW for OpenGL.
开发 Vulkan 应用程序所需的最重要组件是 SDK。它包括头文件、标准校验层、调试工具和 Vulkan 函数加载器。加载器在运行时查询驱动程序支持的函数,类似于 OpenGL 的 GLEW。
You don’t have to create an account, but it will give you access to some additional documentation that may be useful to you.
Vulkan SDK 可以从 LunarG 的网站上免费下载。
Vulkan SDK for Windows, Linux, and macOS
/
LunarG has developed the quintessential developer SDK including build tools, documentation, libraries and more.
Android NDK
/ndk/guides/graphics
Google gives you everything you need to incorporate Vulkan into your Android games and other apps where graphics performance is key.
Visit the Android developer website to download the API, samples, and documentation: resources to help you hit the ground running.
Arm Mali SDK
/ARM-software/vulkan-sdk
ARM’s Vulkan Software Development Kit is a collection of resources to help you build Vulkan applications for a platform with a Mali GPU and an ARM processor. You can use it for creating new applications, training, and exploration of implementation possibilities.
PowerVR SDK
/powervr-graphics/Native_SDK
The PowerVR SDK is an open source codebase to help with the development of graphics applications for PowerVR and other platforms. It consists of two main parts: the Framework and a set of examples.
quintessential [.kwɪntɪ'senʃ(ə)l]:adj. 精髓的,最完美的essential [ɪ'senʃ(ə)l]:n. 要点,要素,实质,必需品 adj. 完全必要的,必不可少的,极其重要的,本质的
1.2 下载 Vulkan SDK (Windows)
/
/sdk/home
Version 1.3.216.0:
SDK - SDK Installer
VulkanSDK-1.3.216.0-Installer.exe (94MB)
SDK Config - Config.json
config.json (0MB)
Runtime - Runtime Installer
VulkanRT-1.3.216.0-Installer.exe (1MB)
Runtime zip - Zip file of the runtime components
VulkanRT-1.3.216.0-Components.zip (10MB)
1.3 Windows 系统上查询 GPU / CPU 对 Vulkan 的支持信息
https://yongqiang./article/details/129093546
1.4 安装 Vulkan SDK (Windows)
VulkanSDK-1.3.216.0-Installer.exe解除锁定
双击 VulkanSDK-1.3.216.0-Installer.exeD:\VulkanSDK\1.3.216.0
Vulkan SDK 1.3.216.0 安装程序 完成 安装目录D:\VulkanSDK\1.3.216.0
运行D:\VulkanSDK\1.3.216.0\Bin\vkcube.exe
Proceed through the installation and pay attention to the install location of the SDK. The first thing we’ll do is verify that your graphics card and driver properly support Vulkan. Go to the directory where you installed the SDK, open theBin
directory and run thevkcube.exe
demo. You should see the following:
安装 Vulkan SDK 之后,我们需要验证显卡和驱动程序是否正确支持 Vulkan。在安装 SDK 的目录,打开Bin
目录并运行vkcube.exe
可执行文件。
If you receive an error message then ensure that your drivers are up-to-date, include the Vulkan runtime and that your graphics card is supported.
如果出现一条错误消息,请确保驱动程序是最新的,包括 Vulkan 运行时并且显卡支持 Vulkan。
There is another program in this directory that will be useful for development. TheglslangValidator.exe
andglslc.exe
programs will be used to compile shaders from the human-readable GLSL to bytecode. TheBin
directory also contains the binaries of the Vulkan loader and the validation layers, while theLib
directory contains the libraries. Lastly, there’s theInclude
directory that contains the Vulkan headers.
此目录中还有另一个程序将对开发有用。glslangValidator.exe
andglslc.exe
程序将用于将 shaders 从人类可读的 GLSL 编译为字节码。Bin
目录还包含 Vulkan 加载器和校验层的二进制文件,而Lib
目录包含库。 最后,还有包含 Vulkan 头文件的Include
目录。
2 Graphics Library Framework (GLFW)
/
GLFW (Graphics Library Framework) is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop.It provides a simple API for creating windows, contexts and surfaces, receiving input and events.
GLFW (Graphics Library Framework) 是一个开源轻量级工具程序库。GLFW 的主要功能是创建并管理窗口和上下文,同时还提供了处理手柄、键盘、鼠标输入的功能。
GLFW is written in C and supports Windows, macOS, X11 and Wayland.
GLFW is licensed under the zlib/libpng license.
Vulkan by itself is a platform agnostic API and does not include tools for creating a window to display the rendered results. To benefit from the cross-platform advantages of Vulkan and to avoid the horrors of Win32, we’ll use the GLFW library to create a window, which supports Windows, Linux and MacOS. There are other libraries available for this purpose, like SDL, but the advantage of GLFW is that it also abstracts away some of the other platform-specific things in Vulkan besides just window creation.
Vulkan 是一个平台无关的 API,不包含用于创建窗口以显示渲染结果的工具。为了跨平台和避免陷入 Win32 细节中去,我们将使用 GLFW 库创建窗口,它支持 Windows、Linux 和 MacOS。有其他库可完成类似功能,如 SDL,但 GLFW 的优势在于,除了窗口创建之外,它还抽象出 Vulkan 中其他一些特定于平台的内容。
We’ll be using the 64-bit binaries, but you can of course also choose to build in 32 bit mode. In that case make sure to link with the Vulkan SDK binaries in theLib32
directory instead ofLib
.
我们将使用 64 位二进制文件,当然也可以选择以 32 位模式构建。在这种情况下,请确保链接到Lib32
目录而不是Lib
中的 Vulkan SDK 二进制文件。
2.1 下载 GLFW
/download.html
The current version is 3.3.8, which was released on July 22, .
Source package
This package contains the complete source code with CMake build files, documentation, examples and test programs. It is the recommended download for all platforms and offers the most control.
The master branch is our integration branch for the next feature release while the 3.3-stable branch only adds bug fixes for patch releases.
Windows pre-compiled binaries
These packages contain the GLFW header files, documentation and release mode static libraries, DLLs and import libraries for Visual C++ - and the preview, MinGW-w64 and plain MinGW.
Binaries for Visual C++ and plain MinGW are only available in the 32-bit package.
64-bit Windows binaries:glfw-3.3.8.bin.WIN64.zip
32-bit Windows binaries:glfw-3.3.8.bin.WIN32.zip
glfw-3.3.8.bin.WIN64.zip
解压为glfw-3.3.8.bin.WIN64
D:\vulkan_sdk\glfw-3.3.8.bin.WIN64\glfw-3.3.8.bin.WIN64
macOS pre-compiled binaries
This package contains the GLFW header files, documentation and release mode static and dynamic libraries for macOS 10.8 and later. Both Intel, ARM and Universal binaries are included.
Linux and BSD binaries
Check if your package system provides GLFW 3.3.8 or another version new enough to be useful to you.
If not, please download and compile GLFW from source. A source package is available above, or you could clone it from GitHub.
/glfw/glfw
/docs/latest/compile.html
3 OpenGL Mathematics (GLM)
/g-truc/glm
OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.
GLM provides classes and functions designed and implemented with the same naming conventions and functionality than GLSL so that anyone who knows GLSL, can use GLM as well in C++.
Unlike DirectX 12, Vulkan does not include a library for linear algebra operations, so we’ll have to download one. GLM is a nice library that is designed for use with graphics APIs and is also commonly used with OpenGL.
与 DirectX 12 不同,Vulkan 不包含用于线性代数运算的库,因此我们必须下载一个。GLM 是一个很好的库,专为与图形 API 一起使用而设计,也常与 OpenGL 一起使用。
GLM is a header-only library.
GLM 是一个只有头文件的库。
3.1 下载 GLM
/g-truc/glm/releases
GLM is written in C++98 but can take advantage of C++11 when supported by the compiler.
glm-0.9.9.8.zip
解压为glm-0.9.9.8
D:\vulkan_sdk\glm-0.9.9.8\glm
4 配置 Visual Studio
For complete C++17 support, you need to use either Visual Studio or .
4.1 新建 ThirdParty 文件夹
4.2 将 GLFW 和 GLM 文件夹复制到 ThirdParty 文件夹
D:\VulkanSDK\1.3.216.0\ThirdParty
D:\VulkanSDK\1.3.216.0\ThirdParty\glfw-3.3.8.bin.WIN64
D:\VulkanSDK\1.3.216.0\ThirdParty\glm
4.3 Visual Studio - 创建项目
File -> New -> Project -> Win32 Console Application
Start Visual Studio and create a newWin32 Console Application
project by entering a name and pressingOK
.
Name:VulkanTest
Location:D:\vulkan_workspace\
Make sure thatConsole Application (.exe)
is selected as application type so that we have a place to print debug messages to, and checkEmpty Project
to prevent Visual Studio from adding boilerplate code.
我们选择使用Console Application (.exe)
应用程序类型,这样做我们就可以直接将调试信息输出到控制台窗口上。我们将Empty Project
选项打勾来阻止 Visual Studio 添加模板代码。
PressOK
to create the project and add a C++ source file.
D:\vulkan_workspace\VulkanTest\VulkanTest\main.cpp
#define GLFW_INCLUDE_VULKAN#include <GLFW/glfw3.h>#define GLM_FORCE_RADIANS#define GLM_FORCE_DEPTH_ZERO_TO_ONE#include <glm/vec4.hpp>#include <glm/mat4x4.hpp>#include <iostream>int main() {glfwInit();glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);uint32_t extensionCount = 0;vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);std::cout << extensionCount << " extensions supported\n";glm::mat4 matrix;glm::vec4 vec;auto test = matrix * vec;while (!glfwWindowShouldClose(window)) {glfwPollEvents();}glfwDestroyWindow(window);glfwTerminate();return 0;}
4.4 Visual Studio - 配置项目属性
Open the project properties dialog and ensure thatAll Configurations
is selected, because most of the settings apply to bothDebug
andRelease
mode.
打开项目属性对话框并确保选择All Configurations
,因为大多数设置都适用于Debug
andRelease
模式。
Project -> VulkanTest Property (All Configurations - All Platforms)
附加包含目录 (Additional Include Directories)
Go toC/C++ -> General -> Additional Include Directories
and press<Edit...>
in the dropdown box.
Add the header directories for Vulkan, GLFW and GLM:
D:\VulkanSDK\1.3.216.0\IncludeD:\VulkanSDK\1.3.216.0\ThirdParty\glmD:\VulkanSDK\1.3.216.0\ThirdParty\glfw-3.3.8.bin.WIN64\include
附加库目录 (Additional Library Directories)
Next, open the editor for library directories underLinker -> General
, And add the locations of the object files for Vulkan and GLFW:
D:\VulkanSDK\1.3.216.0\LibD:\VulkanSDK\1.3.216.0\ThirdParty\glfw-3.3.8.bin.WIN64\lib-vc
附加依赖项 (Additional Dependencies)
Go toLinker -> Input
and press<Edit...>
in theAdditional Dependencies
dropdown box. Enter the names of the Vulkan and GLFW object files:
vulkan-1.libglfw3.lib
Finally, ensure that you are actually compiling in 64 bit mode (确认我们的代码在 64 位模式下编译):
PressF5
to compile and run the project and you should see a command prompt and a window pop up like this:
1>------ Rebuild All started: Project: VulkanTest, Configuration: Debug x64 ------1> main.cpp1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Debug\VulkanTest.exe1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Debug\VulkanTest.pdb (Full PDB)========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
1>------ Rebuild All started: Project: VulkanTest, Configuration: Release x64 ------1> main.cpp1> Generating code1> All 21 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.1> Finished generating code1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Release\VulkanTest.exe1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Release\VulkanTest.pdb (Full PDB)========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
The number of extensions should be non-zero.
References
https://yongqiang./
Vulkan Tutorialhttps://vulkan-/
Vulkan 教程https://geek-/vulkan/vulkan-tutorial/vulkan-tutorial-index.html