OGL(Tutorial 50)——Introduction To Vulkan

1 篇文章 0 订阅

http://ogldev.atspace.co.uk/www/tutorial50/tutorial50.html

background
u have probably heard by now quite a bit about Vulkan, the new graphics api from khronos (the non profit organization responsible for the development of opengl). vulkan was announced in feb-2016 and after 24 years with opengl it is a completely new standard and a departure from the current model. i will not go into the many details about the various features of vulkan only to say that in comparison to opengl it is more low level and provides a lot of power and performance opportunities for the developer. but with great power comes great responsibility. the developer has to take charge of various aspects such as command buffer, synchronization and memory managment that were previously the sole responsibility of the driver. through the unique knowledge that the developer 通过开发人员的了解 has about the way the application is structured, the usage of the vulkan api can be tailored in a way to increase the overall performance of the system.

the thing that surprises people the most, about vulkan is the amout of code that must be written only to get the first triangle on the screen. comparing this to the few lines we had to write in opengl in the first few tutorials this is a major change and becomes a challenge when one tries to write a tutorial about it.
therefore, as always with OGLDEV, i will try to present the material step by step. we will develop our first triangle demo in a few tutorials, making additional progress in each one. in addition, instead of laying out the dozens of apis in one long piece of code i will present a simple software design that i hope will make it simpler for u to understand without imposing too much restrictions on your future apps. consider this an educational desing which u are free to throw away later.

we will study the core components of vulkan one by one as we make progress throught the code so at this point i just want to present a diagram of the general picture:

在这里插入图片描述

this diagram is by all means not a complete representation. it includes only the major components that will probably be present in most applications. the connectors between the objects represent the dependencies between them at creation or enumeration time. for example, in order to create a surface u need an instance object and when u enumerate the physical devies on your system u also need an instance. The two colors roughly describe the software design that we will use. The dark red objects will go into something I call the “core” and the light green objects will go into the “app”. We will later see why this makes sense. The application code that you will write will actually inherit from “app” and all of its members will be available for you for further use. I hope this design will provide a solid base to develop future Vulkan tutorials.

System Setup
The first thing we need to do is to make sure your system supports Vulkan and get everything ready for development. You need to verify that your graphics card supports Vulkan and install the latest drivers for it. Since Vulkan is still new it’s best to check for drivers updates often because hardware vendors will probably fix a lot of bugs before everything stabilizes. Since there are many GPUs available I can’t provide much help here. Updating/installing the driver on Windows should be fairly simple. On Linux the process may be a bit more involved. My main development system is Linux Fedora and I have a GT710 card by NVIDIA. NVIDIA provide a binary run file which can only be installed from the command line. Other vendors have their own processes. On Linux you can use the ‘lspci’ to scan your system for devices and see what GPU you have. You can use the ‘-v’, ‘-vv’ and ‘-vvv’ options to get increasingly more info on your devices.

The second thing we need is the Vulkan SDK by Khronos, available here https://vulkan.lunarg.com/ The SDK includes the headers and libraries we need as well as many samples that you can use to get more info beyond what this tutorial provides. At the time of writing this the latest version is 1.0.30.0 and I urge you to update often because the SDK is in active development. That version number will be used throughout the next few sections so make sure you change it according to the version you have.

Windows

Installation on Windows is simpler than on Linux. You just need to get the latest version from here https://vulkan.lunarg.com/sdk/home#windows double click the executable installer and after agreeing to the license agreement and selecting the target directory you are done. I suggest you install the SDK under c:\VulkanSDK to make it compatible with the Visual Studio solution that I provide, but it is not a must. If you install it somewhere else make sure you update the include and link directories in the project files. See details in the next section.

Building and Running
Windows

If you installed the SDK under ‘c:\VulkanSDK’ then the Visual Studio project files I supply should work out of the box. If you haven’t or you want to setup a Visual Studio project from scratch then follow the steps below.

To update the include directory right click on the project in the solution explorer, go to ‘Properties’ and then to ‘Configuration Properties -> C/C++ -> General’. Now you must add ‘c:\VulkanSDK<version>\Include’ to ‘Additional Include Directories’. See example below:
To update the link directory right click on the project in the solution explorer, go to ‘Properties’ and then to ‘Configuration Properties -> Link -> General’. Now you must add ‘c:\VulkanSDK<version>\Bin32’ to ‘Additional Library Directories’. See example below:

While you are still in the linker settings go to ‘Input’ (just one below ‘General’) and add ‘vulkan-1.lib’ to 'Additional Dependencies".

General Comments
Before we get going I have a few comments about some of my design choices with regard to Vulkan:

Source walkthru
I hope that you successfully completed the above procedures and you are now ready to dive into the internals of Vulkan itself. As I said, we are going to develop our first demo in several steps. The first step will be to setup four important Vulkan objects: the instance, surface, physical device and logical device. I’m going to describe this by walking through my software design but you are welcomed to throw this away and just follow the Vulkan calls themselves.

The first thing we need to do is to include the Vulkan headers. I’ve added ogldev_vulkan.h as the primary Vulkan include file in my projects. This will be the only place where I will include the Vulkan header files and everything else will just include this file. Here’s the relevant piece of code:

下载:VulkanSDK-1.1.114.0-Installer.exe
在这里插入图片描述
在这里插入图片描述

C:\Users\user\Documents\Visual Studio 2017\Templates\ProjectTemplates
在这里插入图片描述

在这里插入图片描述
设置正确的sdk:
在这里插入图片描述
建立项目之后,直接编译,竟然成功了。
原因是新版的vulkan项目自带了第三方的库:
在这里插入图片描述
在这里插入图片描述
所以编译成功了。

运行得到:一片白色窗口。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值