If you are new to low-level graphics programming or you would like to learn about zig-gamedev framework I recommend starting with intro applications.
This repository contains a collection of sample applications and libraries written in Zig programming language and using DirectX 12 for rendering. Prebuilt binaries for all sample applications can be found in Releases. Project is under active development, see Roadmap and Progress Reports for the details.
I build game development stuff in Zig full-time. As a sample of my work please see this video. If you like my project and my mission to promote the language, please consider supporting me.
- Zero dependency except Zig compiler (master) - no Visual Studio/Build Tools/Windows SDK is needed - this repo + Zig compiler package (60 MB) is enough to start developing (any debugger can be used)
- Building is as easy as running
zig build
(see: Building) - zmath lib - fast SIMD math library for game developers (cross-platform and standalone)
- zbullet lib - C API for Bullet physics library (cross-platform and standalone)
- graphics lib - helper library for working with DirectX 12
- audio lib - helper library for working with XAudio2
- pix lib - support for GPU profiling with PIX
- tracy lib - support for CPU profiling with Tracy
- Interop with Direct2D and DirectWrite for high-quality vector graphics and text rendering
- Uses some great C/C++ libraries which are seamlessly built by
zig cc
compiler (see: external/src)
Some of the sample applications are listed below. More can be found in samples directory.
-
rasterization: This sample application shows how GPU rasterizes triangles in slow motion.
-
physically based rendering: This sample implements physically based shading and image based lighting to achive realistic looking rendering results.
-
simple raytracer: This sample implements basic hybrid renderer. It uses rasterization to resolve primary rays and raytracing (DXR) for shadow rays.
-
mesh shader test: This sample shows how to use DirectX 12 Mesh Shader.
-
virtual physics lab: This sample application demonstrates how to use full 3D physics engine in your Zig programs.
-
audio playback test: This sample demonstrates how to decode .mp3 file using Microsoft Media Foundation and play it back using Windows Audio Session API (WASAPI).
-
DirectML convolution test: This sample demonstrates how to perform GPU-accelerated convolution operation using DirectML.
As mentioned above, the only dependency needed to build this project is Zig compiler, neither Visual Studio nor Windows SDK has to be installed.
Zig compiler consists of a single ~60MB .zip file that needs to be downloaded separately. Latest development build of the compiler must be used (master) you can download prebuilt binaries here.
To build a sample application (assuming zig.exe is in the PATH):
- Open terminal window.
- 'cd' to sample application root directory (for example,
cd samples/simple_raytracer
). - Run
zig build
command. - Sample application will be build, assets and build artifacts will be copied to
samples/<sample_name>/zig-out/bin
directory.
Behind the scenes zig build
command performs following steps:
zig cc
builds all C/C++ libraries that application uses (imgui, cgltf).- DirectX Shader Compiler (which can be found in external/bin/dxc directory) is invoked to build all HLSL shaders.
- Zig code is compiled.
- Everything is linked together into single executable.
- Assets and build artifacts are copied to destination directory.
You can look at samples/simple_raytracer/build.zig file to see how those steps are implemented in Zig build script.
All sample applications support following build options:
-Drelease-safe=[bool]
- Optimizations on and safety on-Drelease-fast=[bool]
- Optimizations on and safety off-Denable-pix=[bool]
- PIX markers and events enabled-Denable-dx-debug=[bool]
- Direct3D 12, Direct2D, DXGI debug layers enabled-Denable-dx-gpu-debug=[bool]
- Direct3D 12 GPU-Based Validation enabled (requires -Denable-dx-debug=true)-Dtracy=[path/to/tracy/source]
- Tracy profiler zones enabled
Examples:
zig build -Denable-dx-debug=true -Drelease-fast=true
zig build -Dtracy="C:/Development/tools/Tracy/tracy-0.7.8"
To build and run an application you can use:
zig build run
<- Builds and runs debug build.
zig build run -Drelease-fast=true -Denable-dx-debug=true
<- Builds and runs release build with DirectX debug layers enabled.
This project uses DirectX 12 Agility SDK which allows to always use latest DirectX 12 features regardless of Windows version installed (this works from Windows 10 November 2019). In particular, following Windows versions are supported:
- Windows 10 May 2021 (Build 19043) or newer
- Windows 10 October 2020 (Build 19042.789+)
- Windows 10 May 2020 (Build 19041.789+)
- Windows 10 November 2019 (Build 18363.1350+)
Thanks to all people who sponsor zig-gamedev project! In particular, these fine folks sponsor zig-gamedev for $25/month or more:
- mzet (mzet-)
- Zig Software Foundation (ziglang)
- Ian (LinuXY)
- Simon A. Nielsen Knights (tauoverpi)
- shintales (shintales)