A minimal, modern C++ template for Vulkan projects using C++20 modules.
- ✅ C++20 Modules - Uses
import vulkan_hpp;instead of legacy headers - ✅ Modern CMake 4.1 - Clean, explicit configuration
- ✅ Slang Shaders - First-class shader language support with SPIR-V compilation
- ✅ Vendored Dependencies - GLFW and GLM as git submodules
- ✅ Ninja Build - Fast, parallel builds
- ✅ Minimal & Opinionated - Linux only, no cross-platform bloat
- Linux (this template is Arch Linux-specific)
- Vulkan SDK - Install via
pacman -S vulkan-devel vulkan-headers vulkan-tools - CMake 4.1+ -
pacman -S cmake - Ninja -
pacman -S ninja - Clang 20+ or GCC 15+ -
pacman -S clangorpacman -S gcc - Git - For submodules
- Slang Compiler - For shader compilation (included in some Vulkan SDKs)
- mise - For managing
VULKAN_SDKenvironment variable (seemise.toml)
On GitHub:
# Clone from template
gh repo create my-vulkan-app --template toni6/vulkan-template --public --clone
cd my-vulkan-appOr manually:
git clone https://github.com/toni6/vulkan-template.git my-vulkan-app
cd my-vulkan-app
rm -rf .git
git initgit submodule add https://github.com/glfw/glfw.git vendor/glfw
git submodule add https://github.com/g-truc/glm.git vendor/glm
git submodule update --init --recursive
# Pin to stable versions
cd vendor/glfw && git checkout 3.4 && cd ../..
cd vendor/glm && git checkout 1.0.1 && cd ../..
git add vendor/
git commit -m "Add vendored dependencies"# Configure
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
# Build
ninja -C build
# Run
./build/appvulkan-template/
├── CMakeLists.txt # Main build configuration
├── mise.toml # Optional: environment setup
├── src/
│ └── main.cpp # Your Vulkan application
├── shaders/
│ └── shader.slang # Slang shader source
├── vendor/ # Git submodules
│ ├── glfw/
│ └── glm/
└── build/ # Build artifacts (generated)
├── app # Compiled executable
├── shaders/
│ └── slang.spv # Compiled SPIR-V
└── compile_commands.json
# Full rebuild
ninja -C build
# Shader-only rebuild
ninja -C build slang_shaders
# Clean build
ninja -C build -t clean && ninja -C build
# Verbose output
ninja -C build -vThe project generates compile_commands.json for LSP/clangd:
# Symlink to project root for editors
ln -sf build/compile_commands.json .For Zed editor, update .zed/settings.json:
{
"lsp": {
"clangd": {
"binary": {
"path": "/usr/bin/clangd",
"arguments": ["-background-index", "--compile-commands-dir=build"]
}
}
}
}Shaders are automatically compiled during the build:
# Edit shader
vim shaders/shader.slang
# Rebuild (shaders recompile automatically)
ninja -C build
# Force recompile
touch shaders/shader.slang && ninja -C buildShader entry points:
vertMain- Vertex shaderfragMain- Fragment shader
Using mise for environment management:
# Install mise
curl https://mise.run | sh
# Activate in shell
mise install
mise trust
# VULKAN_SDK is now set automatically
echo $VULKAN_SDKOr manually:
export VULKAN_SDK=/path/to/vulkansdk
export PATH=$VULKAN_SDK/bin:$PATH
export LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH# Vulkan C++ module is built automatically
target_link_libraries(app PRIVATE Vulkan::cppm glfw glm::glm)In your code:
import vulkan_hpp; // Modern C++ Vulkan API
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>- Standard: C++20 with modules
- Warnings:
-Wall -Wextra -Wpedantic
Edit CMakeLists.txt:
add_executable(app
src/main.cpp
src/renderer.cpp
src/window.cpp
)Add to shaders/shader.slang and update CMakeLists.txt entry points:
-entry computeMain -stage compute# Use GCC instead of Clang
cmake -B build -G Ninja -DCMAKE_CXX_COMPILER=g++# Install to /usr/local/bin
cmake --install build
# Or specify prefix
cmake --install build --prefix ~/.localThis is a template repository. Fork it and make it your own!
Public domain / Unlicense - use freely for any purpose.
After creating a new repo from this template:
- Replace this README with your project-specific documentation
- Update
CMakeLists.txtproject name:project(your_project_name LANGUAGES CXX) - Replace
src/main.cppwith your application code - Add your own shaders in
shaders/ - Commit and push!
Happy Vulkan coding! 🌋