在 Windows 系統(tǒng)上配置 Visual Studio 的 Vulkan 開發(fā)環(huán)境
Vulkan Tutorial
https://vulkan-tutorial.com/
Development environment - Windows
https://vulkan-tutorial.com/Development_environment
1 Vulkan - Cross platform 3D Graphics
https://www.vulkan.org/
Vulkan is a new generation graphics and compute API that 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 是一個(gè)低開銷、跨平臺(tái)的 3D graphics and computing 的應(yīng)用程序接口 (API)。Vulkan 針對全平臺(tái)實(shí)時(shí) 3D 圖形程序而設(shè)計(jì),并提供高性能與更均衡的 CPU 與 GPU 利用率。Vulkan 是一個(gè)底層 API,而且能執(zhí)行并行任務(wù),Vulkan 還能更好地分配多個(gè) CPU 核心的使用。
Vulkan was first announced by the non-profit Khronos Group at GDC 2015. 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 在 2015 年游戲開發(fā)者大會(huì) (GDC) 上發(fā)表。正式宣布 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 構(gòu)建,AMD 將其捐贈(zèng)給 Khronos Group,給予該組織開發(fā)底層 API 的基礎(chǔ),使其像 OpenGL 一樣成為行業(yè)標(biāo)準(zhǔn)。
Vulkan offers lower overhead, more direct control over the GPU, and lower CPU usage.
Vulkan 旨在提供更低的 CPU 開銷與更直接的 GPU 控制。
console [k?n?s??l]:vt. 安慰,撫慰,慰藉 n. (機(jī)器、電子設(shè)備等的) 控制臺(tái),操縱臺(tái),儀表板
consortium [k?n?s??(r)ti?m]:n. 聯(lián)盟,(合作進(jìn)行某項(xiàng)工程的) 財(cái)團(tuán),銀團(tuán),聯(lián)營企業(yè)
1.1 Vulkan GPU Resources - SDKs
https://www.vulkan.org/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.
開發(fā) Vulkan 應(yīng)用程序所需的最重要組件是 SDK。它包括頭文件、標(biāo)準(zhǔn)校驗(yàn)層、調(diào)試工具和 Vulkan 函數(shù)加載器。加載器在運(yùn)行時(shí)查詢驅(qū)動(dòng)程序支持的函數(shù),類似于 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 的網(wǎng)站上免費(fèi)下載。
-
Vulkan SDK for Windows, Linux, and macOS
https://vulkan.lunarg.com/
LunarG has developed the quintessential developer SDK including build tools, documentation, libraries and more.
-
Android NDK
https://developer.android.com/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
https://github.com/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
https://github.com/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. 要點(diǎn),要素,實(shí)質(zhì),必需品 adj. 完全必要的,必不可少的,極其重要的,本質(zhì)的
1.2 下載 Vulkan SDK (Windows)
https://vulkan.lunarg.com/
https://vulkan.lunarg.com/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 系統(tǒng)上查詢 GPU / CPU 對 Vulkan 的支持信息
https://yongqiang.blog.csdn.net/article/details/129093546
1.4 安裝 Vulkan SDK (Windows)
- VulkanSDK-1.3.216.0-Installer.exe
解除鎖定
- 雙擊 VulkanSDK-1.3.216.0-Installer.exe
D:\VulkanSDK\1.3.216.0
- Vulkan SDK 1.3.216.0 安裝程序
- 完成
- 安裝目錄
D:\VulkanSDK\1.3.216.0
- 運(yùn)行
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 the Bin
directory and run the vkcube.exe
demo. You should see the following:
安裝 Vulkan SDK 之后,我們需要驗(yàn)證顯卡和驅(qū)動(dòng)程序是否正確支持 Vulkan。在安裝 SDK 的目錄,打開 Bin
目錄并運(yùn)行 vkcube.exe
可執(zhí)行文件。
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.
如果出現(xiàn)一條錯(cuò)誤消息,請確保驅(qū)動(dòng)程序是最新的,包括 Vulkan 運(yùn)行時(shí)并且顯卡支持 Vulkan。
There is another program in this directory that will be useful for development. The glslangValidator.exe
and glslc.exe
programs will be used to compile shaders from the human-readable GLSL to bytecode. The Bin
directory also contains the binaries of the Vulkan loader and the validation layers, while the Lib
directory contains the libraries. Lastly, there’s the Include
directory that contains the Vulkan headers.
此目錄中還有另一個(gè)程序?qū)﹂_發(fā)有用。glslangValidator.exe
and glslc.exe
程序?qū)⒂糜趯?shaders 從人類可讀的 GLSL 編譯為字節(jié)碼。Bin
目錄還包含 Vulkan 加載器和校驗(yàn)層的二進(jìn)制文件,而 Lib
目錄包含庫。 最后,還有包含 Vulkan 頭文件的Include
目錄。
2 Graphics Library Framework (GLFW)
https://www.glfw.org/
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) 是一個(gè)開源輕量級工具程序庫。GLFW 的主要功能是創(chuàng)建并管理窗口和上下文,同時(shí)還提供了處理手柄、鍵盤、鼠標(biāo)輸入的功能。
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 是一個(gè)平臺(tái)無關(guān)的 API,不包含用于創(chuàng)建窗口以顯示渲染結(jié)果的工具。為了跨平臺(tái)和避免陷入 Win32 細(xì)節(jié)中去,我們將使用 GLFW 庫創(chuàng)建窗口,它支持 Windows、Linux 和 MacOS。有其他庫可完成類似功能,如 SDL,但 GLFW 的優(yōu)勢在于,除了窗口創(chuàng)建之外,它還抽象出 Vulkan 中其他一些特定于平臺(tái)的內(nèi)容。
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 the Lib32
directory instead of Lib
.
我們將使用 64 位二進(jìn)制文件,當(dāng)然也可以選擇以 32 位模式構(gòu)建。在這種情況下,請確保鏈接到 Lib32
目錄而不是 Lib
中的 Vulkan SDK 二進(jìn)制文件。
2.1 下載 GLFW
https://www.glfw.org/download.html
The current version is 3.3.8, which was released on July 22, 2022.
- 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++ 2010-2019 and the 2022 preview, MinGW-w64 and plain MinGW.
Binaries for Visual C++ 2010 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.
https://github.com/glfw/glfw
https://www.glfw.org/docs/latest/compile.html
3 OpenGL Mathematics (GLM)
https://github.com/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 不包含用于線性代數(shù)運(yùn)算的庫,因此我們必須下載一個(gè)。GLM 是一個(gè)很好的庫,專為與圖形 API 一起使用而設(shè)計(jì),也常與 OpenGL 一起使用。
GLM is a header-only library.
GLM 是一個(gè)只有頭文件的庫。
3.1 下載 GLM
https://github.com/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 2017 or 2019.
4.1 新建 ThirdParty 文件夾
4.2 將 GLFW 和 GLM 文件夾復(fù)制到 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 2015 - 創(chuàng)建項(xiàng)目
File -> New -> Project -> Win32 Console Application
Start Visual Studio and create a new Win32 Console Application
project by entering a name and pressing OK
.
Name: VulkanTest
Location: D:\vulkan_workspace\
Make sure that Console Application (.exe)
is selected as application type so that we have a place to print debug messages to, and check Empty Project
to prevent Visual Studio from adding boilerplate code.
我們選擇使用 Console Application (.exe)
應(yīng)用程序類型,這樣做我們就可以直接將調(diào)試信息輸出到控制臺(tái)窗口上。我們將 Empty Project
選項(xiàng)打勾來阻止 Visual Studio 添加模板代碼。
Press OK
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 2015 - 配置項(xiàng)目屬性
Open the project properties dialog and ensure that All Configurations
is selected, because most of the settings apply to both Debug
and Release
mode.
打開項(xiàng)目屬性對話框并確保選擇 All Configurations
,因?yàn)榇蠖鄶?shù)設(shè)置都適用于 Debug
and Release
模式。
Project -> VulkanTest Property (All Configurations - All Platforms)
- 附加包含目錄 (Additional Include Directories)
Go to C/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\Include
D:\VulkanSDK\1.3.216.0\ThirdParty\glm
D:\VulkanSDK\1.3.216.0\ThirdParty\glfw-3.3.8.bin.WIN64\include
- 附加庫目錄 (Additional Library Directories)
Next, open the editor for library directories under Linker -> General
, And add the locations of the object files for Vulkan and GLFW:
D:\VulkanSDK\1.3.216.0\Lib
D:\VulkanSDK\1.3.216.0\ThirdParty\glfw-3.3.8.bin.WIN64\lib-vc2015
- 附加依賴項(xiàng) (Additional Dependencies)
Go to Linker -> Input
and press <Edit...>
in the Additional Dependencies
dropdown box. Enter the names of the Vulkan and GLFW object files:
vulkan-1.lib
glfw3.lib
Finally, ensure that you are actually compiling in 64 bit mode (確認(rèn)我們的代碼在 64 位模式下編譯):
Press F5
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.cpp
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Debug\VulkanTest.exe
1> 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.cpp
1> Generating code
1> All 21 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1> Finished generating code
1> VulkanTest.vcxproj -> D:\vulkan_workspace\VulkanTest\x64\Release\VulkanTest.exe
1> 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.文章來源:http://www.zghlxwxcb.cn/news/detail-494611.html
References
https://yongqiang.blog.csdn.net/
Vulkan Tutorial https://vulkan-tutorial.com/
Vulkan 教程 https://geek-docs.com/vulkan/vulkan-tutorial/vulkan-tutorial-index.html文章來源地址http://www.zghlxwxcb.cn/news/detail-494611.html
到了這里,關(guān)于在 Windows 系統(tǒng)上配置 Visual Studio 的 Vulkan 開發(fā)環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!