[Xiao Mu learns Vulkan] Introduction to Vulkan and development environment configuration

1 Introduction

https://www.vulkan.org/

Vulkan is a next-generation graphics and compute API for efficient, cross-platform access to GPUs.

Vulkan is a cross-platform 2D and 3D drawing application programming interface (API), first announced by the Konas organization at the 2015 Game Developers Conference (GDC). It's called glNext. Designed to provide lower CPU overhead and more direct GPU control, the concept is roughly similar to Direct3D 12 and Mantle.
Insert image description here

As the industry's only open-standard modern GPU API, Vulkan is unique in enabling developers to write applications that are portable to multiple different platforms. Vulkan includes the latest graphics technologies, including ray tracing, and is integrated into production drivers for NVIDIA's NVIDIA GeForce, RTX and Quadro solutions on Windows and Linux, NVIDIA Shield, and the Jetson embedded computing platform using Android or Linux.

Insert image description here

  • Advantages of Vulkan over previous generation APIs:
    • Vulkan API is suitable for graphics cards from high-performance computers to mobile low-power devices;
      Compared with Direct3D 12, Vulkan is similar to its predecessor OpenGL and is supported by multiple operating systems. Vulkan can already run on Windows 7, Windows 8, Windows 10, Tizen, Linux and Android (iOS and macOS have third-party support).
    • Reduce CPU load through batch processing so that the CPU can perform more other computing or rendering tasks.
    • On multi-core CPUs, Vulkan can optimize cores and threads. Direct3D 11 and OpenGL 4 were originally designed for single-core CPUs. Although extensions optimized for multi-core CPUs later appeared, the optimization is still not very good compared with Vulkan.
    • Reduces driver overhead and maintenance work. OpenGL uses the high-level shading language GLSL to write shaders. Different drivers need to execute their own GLSL compiler when the program is running to convert the program's shaders into GPU executable machine code. The Vulkan driver pre-converts the shader language into the intermediate binary format of SPIR-V (Standard Portable Intermediate Representation), which behaves similar to Direct3D's HLSL shader. With shader precompilation, applications load faster and 3D scenes can use a wider variety of shaders. The Vulkan driver only needs to optimize the GPU and generate code, which makes the driver easier to maintain and the driver package smaller (GPU vendors still need to provide OpenGL and OpenCL support in the driver).
    • Unified management of computing and graphics processing, so Vulkan does not need to be used with a separate computing API.

Insert image description here

A new version of the Vulkan specification was released in January 2022, containing important and proven features that developers have requested. On the day of the spec release, NVIDIA launched a fully functional Vulkan 1.3 driver for Windows and Linux. These drivers also support the expanded feature set in the Vulkan Roadmap 2022 milestones.
Insert image description here

2. Download and install

https://www.lunarg.com/vulkan-sdk/
Insert image description here
https://vulkan.lunarg.com/sdk/home#windows
Insert image description here
After downloading the sdk as follows:
Insert image description here
Install VulkanSDK-1.3.261.1-Installer.exe as follows:

  • Installation welcome page
    Insert image description here
  • installation folder
    Insert image description here
  • Select components
    Insert image description here
  • agreement
    Insert image description here
  • Ready to install
    Insert image description here
  • start installation
    Insert image description here
  • Installation completed
    Insert image description here
    The folder after installation is as follows:
    Insert image description here
    Then run vkcube.exe in the Bin directory,
    Insert image description here

You should see a rotating cube, which indicates that your graphics card and driver support Vulkan.
Insert image description here

3. Code examples

3.1 Simple test (glfw+glm)

  • glfw configuration
    GLFW is an open source multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API to create windows, contexts and surfaces, and receive input and events.
    GLFW is written in C language and supports Windows, macOS, X11 and Wayland.
    GLFW is licensed under the zlib/libpng license.
    https://www.glfw.org/
  • glm configuration
    OpenGL Mathematics (GLM) is a header C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specification.
    The classes and functions provided by GLM are designed and implemented with the same naming conventions and functionality as GLSL, so anyone who knows GLSL can use GLM in C++.
    This project is not limited to GLSL functionality. The extension system based on GLSL extension convention provides extended functions: matrix transformation, quaternion, data packet, random number, noise, etc...
    https://github.com/g-truc/glm

Prepare the SDK codes for GLFW and GLM.

  • Header folder:
D:\Program Files\My3rdPartyGit\glm-0.9.9.8;
D:\Program Files\My3rdPartyGit\glfw-3.3.6\include;
D:\VulkanSDK\1.3.261.1\Include;
  • Library folder:
D:\Program Files\My3rdPartyGit\glfw-3.3.6\lib\x64\Debug;
D:\VulkanSDK\1.3.261.1\Lib;
  • Library file:
glfw3.lib;
vulkan-1.lib;

The test project for creating a new console is as follows:

// ConsoleApplication16.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#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;
}

After compilation, run as follows:
Insert image description here

Conclusion

如果您觉得该方法或代码有一点点用处,可以给作者点个赞,或打赏杯咖啡;╮( ̄▽ ̄)╭
如果您感觉方法或代码不咋地//(ㄒoㄒ)//,就在评论处留言,作者继续改进;o_O???
如果您需要相关功能的代码定制化开发,可以留言私信作者;(✿◡‿◡)
感谢各位大佬童鞋们的支持!( ´ ▽´ )ノ ( ´ ▽´)! ! !

Guess you like

Origin blog.csdn.net/hhy321/article/details/133578377