An implementation of the basic triangle drawing example from the Vulkan Tutorial with some changes:
- Vulkan 1.3 direct rendering is used in lieu of render passes;
- the volk dynamic loader is used in lieu of directly linking
the
libvulkan.so
shared library.
The project design was inpsired by Chris Wellons' blog and raylib.
To build the project you will need a C compiler that supports C99 or later,
as well as a GLSL to SPIR-V compiler.
The project supports Linux Wayland targets and Windows targets.
There are ZERO build dependencies beyond the libc
required
by your target (e.g. glibc
or musl
for Linux, or mingw
for Windows).
The project vendors and builds GLFW and volk. Also included are the headers for Vulkan, xkbcommon, Wayland, and the Wayland protocols.
To run the application you will need the Vulkan loader
and a Vulkan driver for your graphics card. To run executables built with
ENABLE_VALIDATION_LAYERS
defined (which it is in the default CFLAGS
)
you will need to have the Vulkan validation layers installed as well.
To run on Linux you will need a Wayland compositor, the Wayland shared libraries, and the xkbcommon shared library. Note that installing virtually any Wayland compositor capable of Vulkan support will also install these libraries by default.
The entire project builds with a single tiny Makefile
.
By default make
will build with gcc and compile shaders with
glslc.
make
./vulkan_app
If you have another compiler, then you can modify the appropriate environment variables to e.g. use clang.
make CC="clang"
./vulkan_app
The project will even build with the awesome and simple cproc compiler1.
make CC="cproc" CFLAGS="-D\"__attribute(x)=\" -D\"__attribute__(x)=\"" \
GLFW_FLAGS="-D\"__attribute(x)=\" -D\"__attribute__(x)=\""
./vulkan_app
You can easily cross-compile a Windows application from Linux with the Mingw-w64 toolchain.
make CC="x86_64-w64-mingw32-gcc" CFLAGS="-std=c99 -O2" LDFLAGS="-mwindows" \
GLFW_CFLAGS="-std=c99 -O2"
You can also cross-compile a Windows application with zig cc (or any clang toolchain set up with a Windows target).
make CC="zig cc -target x86_64-windows-gnu" \
LDFLAGS="-lkernel32 -luser32 -lgdi32 -Wl,--subsystem,windows"
On a Windows machine you can compile and run a Windows application with Mingw-w64.
make CFLAGS="-std=c99 -O2" GLFW_CFLAGS="-std=c11 -O2" LDFLAGS="-mwindows"
./vulkan_app.exe
Or build and run a Windows app with Zig.
make CC="zig cc" LDLFAGS="-lkernel32 -luser32 -lgdi32 -Wl,--subsystem,windows"
mv vulkan_app vulkan_app.exe
./vulkan_app.exe
You can also cross-compile a Linux application from Windows.
make CC="zig cc -target x86_64-linux-gnu" CFLAGS="-std=c99 -O2" \
GLFW_CFLAGS="-std=c99 -O2"
Footnotes
-
A small patch to QBE is required to increase the maximum identifier length. ↩