Vulkan-Learn
Learning vulkan C++ binding repo
requirement
- Vulkan
- SDL2
- GLM
- pkgconfig
- download pkg-config and dependencies if Windows
- write
.pc
file- vulkan.pc
- sdl2.pc
- set environment variable
PKG_CONFIG_PATH
- cmake
project structure
/ ├── cmake/ ├── CMakeLists.txt ├── images/ ├── include/ ├── projects/ │ ├── canvas/ │ ├── test/ │ ├── texture/ │ └── triangle/ ├── README.org ├── src/ ├── video/ ├── xmake/ └── xmake.lua
- cmake
- cmake files
- CMakeLists.txt
- cmake project configuration file
- include
- common utility definition
- projects
-
dir target comment canvas VulkanCanvas glslang canvas (learn builtin functions) test VulkanTest test vulkan SDK texture VulkanTexture learn VTF pipeline triangle VulkanTriangle draw a triangle (learn VF pipeline) - src
- common utility implement, target
VulkanBase
- video
- project display
- xmake
- xmake files
- xmake.lua
- xmake project configuration file
.pc file
.pc file is libraries configuration file, it record the library’s
compile-options
, link-options
, and etc. pkg-config can parse .pc file, and
return the library’s information.
Like this, it print the link options
pkg-config --libs vulkan
this command will print the compile options
pkg-config --cflags sdl2
but Windows haven’t .pc file, so we need write .pc files. e.g. vulkan.pc
prefix=/usr exec_prefix=/usr libdir=/usr/lib/x86_64-linux-gnu includedir=/usr/include Name: Vulkan-Loader Description: Vulkan Loader Version: 1.3.204 Libs: -L${libdir} -lvulkan Libs.private: -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc Cflags: -I${includedir}
Good. setup environment variable PKG_CONFIG_PATH
.
build and run
cmake
cmake need to special the source directory, build directory, and build tool
(default is Unix Makefiles
), you can use the below command to generate build script
cmake -S. -Bbuild -GNinja
set build release mode
cmake -S. -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release
use clang toolchains not gcc
cmake -S. -Bbuild -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
Okay, generated the build script, you can build your application
cmake --build build
if you want to special the target, run
cmake --build build --target TARGET_NAME
Nice, generated and built the application, next run it! But cmake not provide
run
command, you must run it manually
build/bin/VulkanTest
xmake
if you want to build the application by xmake, run below command
xmake build
next, special target
xmake build TARGET_NAME
set debug mode or release mode, you need
xmake f --mode=debug
if you want to use clang toolchain
xmake f --toolchain=clang
if you need compile_command
, run
xmake project -k compile_commands
last, run the application
xmake run -w. TARGET_NAME
Shader Input
Canvas
set | binding / id | storage | name | type | offset (in byte) | comment |
---|---|---|---|---|---|---|
push_constant | time | float | 0 | shader playback time (in seconds) | ||
push_constant | extent | vec2 | 8 | viewport resolution (in pixels) | ||
push_constant | mouse | vec2 | 16 | mouse pixel coords | ||
0 | special_constant | PI | float |
C++ technical
- Curiously recurring template pattern (CRTP)
- Structured binding declaration
- Class template argument deduction (CTAD)
- Resource Acquisition Is Initialization (RAII)
- Placeholder type specifiers
LICENSE
3-clause BSD License © Xin ‘Russell’ Liu