Guide · Open source
How to use Vulkan: clone, build and run the C++ examples
Updated · written with AI from the project's own documentation and checked against our catalogue data
Vulkan is a low-level graphics and compute API from Khronos, and the SaschaWillems/Vulkan repository is a large set of small C++ programs that each demonstrate one part of it. This guide shows how to get the code, build it, run the examples and choose the right one to study. By the end you will be able to run a working Vulkan example and find the code for a specific feature.
Quick start
- 1Check prerequisites. Install a C++ compiler with C++20 support and Git.
- 2Clone with submodules. Run the recursive git clone command so external dependencies and assets are included.
- 3Read BUILD.md. Follow the platform-specific build instructions in BUILD.md for your operating system.
- 4Build the examples. Compile the examples using the steps in BUILD.md.
- 5Run from the bin directory. Start an example from the bin directory and check its options with --help.
- 6Pick a GPU and shader type. Use -gl to list devices, -g to choose one, and -s to select glsl, slang or hlsl.
- 7Study the source. Open the example folder for a topic such as the triangle, and compare its shader versions.
What you need before you start
The examples are C++ programs, so you need a C++ compiler that supports C++20 and Git to download the code. The repository is licensed under MIT and is written mainly in GLSL shaders alongside the C++ code.
This is a set of demos rather than a finished application, and the README points to a separate introduction repository for readers new to Vulkan and graphics APIs.
- A C++ compiler with C++20 support
- Git
- Basic familiarity with C++ (the README recommends the separate HowToVulkan repository if you are new to Vulkan)
Clone the repository with submodules
The repository uses submodules for external dependencies and assets, so a fresh clone must be recursive. Existing clones can be updated manually with the submodule commands.
git clone --recursive https://github.com/SaschaWillems/Vulkan.git
git submodule init
git submodule updateBuild the examples
The repository contains what is needed to compile the examples on Windows, Linux, Android, iOS, macOS and OpenHarmony using a C++ compiler that supports C++20. The README does not list the build steps here, so read BUILD.md in the repository for the instructions for your platform.
- Target platforms named in the README: Windows, Linux, Android, iOS, macOS, OpenHarmony
- Platform-specific steps are in BUILD.md
Run an example and use command-line options
Once built, examples run from the bin directory. Run any example with --help to list the available options. Some examples need specific device features, and on a multi-GPU system you may need to pick a GPU with -gl and -g.
- -v, --validation: enable validation layers
- -s, --shaders: choose glsl, slang or hlsl shaders
- -gl, --listgpus: list available Vulkan devices
- -g, --gpu: select the GPU to run on
- -w, --width and -h, --height: set window size
- -f, --fullscreen: start in fullscreen mode
- -vs, --vsync: enable V-Sync
- -b, --benchmark: run in benchmark mode, with -bw, -br, -bf and -bt for its settings
- -rp, --resourcepath: set the folder containing assets and shaders
--help
-gl
-g <index>
-s glslUnderstand the shader setup
Vulkan takes shaders in SPIR-V, an intermediate bytecode. The primary shader language in this repository is GLSL, and most samples also include slang and HLSL versions, so you can compare the same example across the three languages. Rust shader sources are maintained in a separate repository by the Rust GPU project.
- GLSL: primary language, in the shaders/glsl folder
- slang: in shaders/slang
- HLSL: in shaders/hlsl
Choose an example to study
Examples are grouped by topic, from the basic triangle to ray tracing. Start with the verbose triangle example if you want to see the full setup code, then move to later examples where boilerplate is abstracted away.
- Basic triangle using Vulkan 1.0: a verbose starting point that draws a colored triangle
- Basic triangle using Vulkan 1.3: the same idea using dynamic rendering
- Pipelines, descriptor sets, push constants and specialization constants
- Texture mapping, texture arrays, cube maps and 3D textures
- Input attachments, sub passes and offscreen rendering
- Compute shader, geometry shader, tessellation shader and hardware accelerated ray tracing
What people use it for
- Learning Vulkan by reading and running a basic colored triangle example
- Looking up how a specific feature such as push constants or dynamic uniform buffers is used in code
- Comparing the GLSL, slang and HLSL versions of the same example
- Benchmarking an example with the -b options and saving frame times
- Studying ray tracing or compute shader examples as reference code
Frequently asked questions
Is the SaschaWillems Vulkan repository free to use?
Yes. The repository is licensed under MIT, as listed in its metadata. Check the LICENSE file in the repository for the full terms.
What do I need to install to run the Vulkan examples?
You need a C++ compiler that supports C++20 and Git. The examples are compiled from source, so you build them yourself following BUILD.md.
How do I clone the Vulkan examples correctly?
Use git clone --recursive https://github.com/SaschaWillems/Vulkan.git. The repository uses submodules, so a recursive clone is needed for a complete copy.
Why does an example fail or not run on my computer?
The README notes that some examples require specific device features. On a multi-GPU system, use -gl to list devices and -g to select one that supports them.
Is this good for complete beginners to Vulkan?
It is best for programmers who want working reference code. The README points beginners to the separate HowToVulkan repository for an introduction to Vulkan and graphics.
What are the alternatives to these Vulkan examples?
The comparable projects listed are KhronosGroup/Vulkan-Samples, KhronosGroup/Vulkan-Tutorial and nvpro-samples/vk_mini_path_tracer. The README also links the official Khronos Vulkan Samples repository.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use this repository if you are a programmer who wants many small, working Vulkan examples to read and run, and it is especially useful for comparing GLSL, slang and HLSL shaders. Pick something else if you want a finished end-user application, or if you are new to C++ and graphics, where the HowToVulkan introduction or the Khronos tutorials are a better start.
Install options & downloads