basic-graphics-samples
basic-graphics-samples copied to clipboard
Basic graphics samples using Magma library and Vulkan graphics API
Basic C++ sample usages of Magma library and Vulkan graphics API
Cloning
To clone this repository with external submodules:
git clone --recursive https://github.com/vcoda/basic-graphics-samples.git
or clone this repository only and update submodules manually:
git clone https://github.com/vcoda/basic-graphics-samples.git
cd basic-graphics-samples
git submodule update --init --recursive
Build tools and SDK
Windows
Check that VK_SDK_PATH environment variable is present after SDK installation:
echo %VK_SDK_PATH%
Shaders are automatically compiled using glslangValidator as Custom Build Tool. If you use Visual Studio newer than 2017, change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".
Linux (Ubuntu)
Install GCC and Git (if not available):
sudo apt update
sudo apt install gcc
sudo apt install g++
sudo apt install make
sudo apt install git
Install XCB headers and libraries:
sudo apt install xcb
sudo apt install libxcb-icccm4-dev
For Xlib, install X11 headers and libraries (optional):
sudo apt install libx11-dev
Go to the directory where .run file was saved:
chmod ugo+x vulkansdk-linux-x86_64-<version>.run
./vulkansdk-linux-x86_64-<version>.run
cd VulkanSDK/<version>/
source ./setup-env.sh
Check that Vulkan environment variables are present:
printenv | grep Vulkan
Systems with AMD graphics hardware
Check whether AMDGPU-PRO stack is installed:
dpkg -l amdgpu-pro
If not, download and install it from an official web page:
NOTE: You have to make sure that graphics driver is compatible with current Linux kernel. Some of the driver's libraries are compiled against installed kernel headers, and if kernel API changed since driver release, compilation will fail and driver become malfunction after reboot. I used a combination of AMDGPU-PRO Driver Version 17.10 and Ubuntu 16.04.2 with kernel 4.8.0-36. Also disable system update as it may upgrade kernel to the version that is incompatible with installed graphics driver. Successfull AMDGPU-PRO installation should look like this:
Loading new amdgpu-pro-17.10-446706 DKMS files...
First Installation: checking all kernels...
Building only for 4.8.0-36-generic
Building for architecture x86_64
Building initial module for 4.8.0-36-generic
Done.
Forcing installation of amdgpu-pro
After reboot check that driver stack is installed:
dpkg -l amdgpu-pro
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-====================================================================
ii amdgpu-pro 17.10-446706 amd64 Meta package to install amdgpu Pro components.
Systems with Nvidia graphics hardware
TODO
Building
To build all samples, go to the repo root directory and run make script:
make -j<N>
where N is the number of threads to run with multi-threaded compilation. First, magma and quadric libraries will be built, then samples. To build a particular sample, you can build dependencies separately, then go to the sample's directory and run make script:
cd 01-clear
make
./01-clear
There is debug build by default. For release build, set DEBUG variable to 0, e. g.:
make magma DEBUG=0 -j<N>
Android
macOS and iOS
Samples
01 - Clear framebuffer

02 - Triangle

03 - Vertex buffer

04 - Vertex transform

05 - Mesh

06 - Texture

07 - Texture array

08 - Cubemap texture

09 - Volume texture

10.a - Render to texture

10.b - Render to multisample texture

11 - Occlusion query

12 - Alpha blending

13 - Specialization constants

14 - Push constants

15 - Particles

16 - Immediate mode

17 - ShaderToy

18 - Compute shader

Known issues
- vkCreateSwapchainKHR() may fail on Linux due to unresolved issues with alignment.
Credits
This framework uses a few third-party libraries:
-
Microsoft DirectXMath
Linear algebra library with fantastic CPU optimizations using SSE2/SSE3/SSE4/AVX/AVX2 intrinsics.
I wrote a simple wrapper over it to make its usage more OOP friendly. -
Gliml
Minimalistic image loader library by Andre Weissflog.