Mach v0.2 released - Zig game engine & graphics toolkit

Mach is a Zig game engine & graphics toolkit for building high-performance, truly cross-platform, robust & modular games, visualizations, and desktop/mobile GUI apps. Learn more

We’ve been developing Mach for ~2 years; this release includes over a year of work, thousands of commits, and fixes 300 issues.

On your machine in just ~60 seconds

With this Zig nightly version you can run the above demo on your machine in ~60 seconds:

git clone https://github.com/hexops/mach-core
cd mach-core/
zig build run-deferred-rendering

Zero system dependencies to slow you down; only zig is needed, we build and package the few relevant dependencies on our own. known issues

Engine and Core split

We completely split Mach engine and Mach core apart, so that you get to choose your journey and decide if you just want low-level window+input+GPU and nothing else, or prefer to use our higher level engine (which although not ready for use yet, will be very modular itself):

Mach core

mach-core

Mach core aims to be a truly cross-platform way to get window+input+GPU, and nothing else. It supports Linux, Windows, and Mac today, with WebAssembly / browser support in active development, and mobile coming in the future.

It gives you the power of Vulkan, DirectX, Metal, and modern OpenGL in a single concise graphics API and shader language - by compiling Google Chrome’s WebGPU implementation natively using Zig’s build system.

Seamless multi-threading capabilities are provided, which means that your rendering and input handling are trivially decoupled from one another, you get butter-smooth window resizing, and your render loop and input handling can run at different frequencies. For example, a 60FPS render loop while your application handles keyboard & mouse events at a much faster dynamic rate (as fast as the OS can deliver them.)

You can think of Mach core as an alternative to the classic options of SDL, GLFW+OpenGL, etc.

There are 15+ examples in the showcase, and we’re planning a C API so it can be used from other languages as well.

Engine development has begun

Mach engine is not ready for use yet, but we’ve started breaking ground on higher-level engine APIs.

The v0.2 release focuses on deep changes and improvements to our infrastructure, primarily building out the Zig gamedev ecosystem and building foundational packages that we needed for Mach core, the engine, and a game we’re starting to build.

As a result, we’ve finally just broken ground on the engine side of things.

Breaking up our monorepo

Previously, all of Mach’s standalone packages were developed in a single giant monorepo. This was both intimidating for new contributors, and we wanted to better communicate how many standalone Zig gamedev packages we actually provide.

Today, we’re happy to report all standalone packages are now developed in separate repositories and available via the package manager!

Zig package manager

We migrated 100% to the self-hosted Zig compiler and the new experimental Zig package manager, every Git submodule has been banished!

We created pkg.machengine.org - a mirror for downloading Mach packages and Zig downloads as well.

Introducing Wrench the Machanist

Wrench is the Mach engine mascot (artwork contributed by Keyla Jones); and also our infrastructure automation tool, written in Go, to help us with various tasks:

Giving us an overview of our many repositories CI statuses and pull requests:

Sending us pull requests to automatically update our CI pipelines to the latest Zig version, and update our build.zig.zon dependencies - in a fully atomic way across all our repositories at once:

…and much more:

  • Checking our website and docs for broken links and sending us GitHub issues.
  • Performing automatic updates of involved dependencies, such as updating our fork of Google Chrome’s WebGPU implementation, which involves pull requests across a few different repositories, pushing branches, running out-of-band commands, and ultimately presenting us with helpful/pretty diffs so we can just do the human work.
  • A custom CI job runner system, running on a custom mini server with actual GPUs - so we can do screenshot-based testing of graphical applications in the future.

mach-gpu: rewritten for perfection

mach-gpu is the WebGPU interface for Zig, and last year we completely rewrote it, achieving:

  • Zero overhead, using comptime interfaces
  • 100% API coverage
  • Default values for 100% of the API (which makes writing descriptors, and makes examples, look much simpler.)

Audio development

Contributor @alichraghi has been relentless in pushing our audio capabilities (and more) forward

mach-flac mach-sysaudio mach-opus

mach-sysaudio started as Zig bindings to Andrew Kelley’s awesome libsoundio library, and ended up being a fully-fledged new library written in Zig to achieve similar goals:

  • Truly cross-platform, low-level, audio IO in Zig - playback and recording with backends for:
    • Linux
      • PulseAudio
      • PipeWire
      • Jack
      • ALSA
    • Windows: WASAPI
    • macOS/iOS: CoreAudio
    • WebAssembly: WebAudio

Then just recently we got mach-flac and mach-opus, which combined give you FLAC (lossless audio) and Opus (lossy audio) via the respective battle-hardeneed xiph.org libraries.

New website

We built a brand new website that will serve us well into the future, featuring:

  • Project roadmap
  • Documentation for Engine, Core, Packages, and more.
  • WebGPU documentation and learning material
  • Offline-viewing support (see link in the footer)
  • All around better design, landing page, etc.

Note: Mobile support isn’t great right now, we’ll fix it later.

Browser support: in development

Chrome has already shipped WebGPU, and others will follow soon. Mach support for WebAssembly is not yet ready, but is coming along nicely:

  • Input, audio, etc. is working already (piano demo, click in the frame and type with your A-Z keys.)
  • mach build is a new CLI command written in Zig which:
    • Starts an HTTP development server
    • Invokes zig build for you when you reload the page
    • Generally provides a nice browser development experience

We currently do not have graphics support in the browser: we are currently doing a full rewrite of mach-sysjs to use a code generation approach to enable Zig and JavaScript to communicate across the WebAssembly boundary, while being able to pass complex types (strings, slices, etc.) instead of just pointers and integers as normal. Once this rewrite is finished, we will generate a gpu.Interface implementation which simply invokes the browser’s JavaScript WebGPU API with minimal overhead.

Dusk: Experimental pure-Zig WebGPU implementation

mach-dusk

Dusk is a highly experimental WebGPU implementation in Zig, aiming to be blazingly fast, lean & mean.

@alichraghi has been quietly working on Dusk tirelessly and consistently over the past year, and we think it may begin to be usable in Mach v0.3. Although it is not usable today, it already features:

Dusk is a long-term bet / investment for us, we intend to always have the option of using Dawn (the Google Chrome WebGPU implementation), and we don’t expect Dusk will be the default very soon. Since both will implement the same gpu.Interface, it’ll just be another backend you can select from at build time.

Learn more about our goals with Dusk here, and feel free to join the #dusk channel in Discord or check out the repository if you’re interested in contributing some Vulkan, Metal, or Direct3D knowledge.

Model loading

mach-model3d provides Zig bindings to Model3D, a compact, featureful model format & alternative to glTF. We may replace this with our own model format in the future, but for now this enables us to load models from Blender in a decent, performant way.

Sprite / 2D examples

mach-core now has a sprite2d example which is ~400 lines and demonstrates loading sprites from a JSON file and sprite atlas, basic keyboard movement, etc.

We’ve already begun making a higher-level API for 2D graphics, as well - though not ready for use yet.

Community

  • Our Discord community grew to over 700+ members, though we aim to keep all valuable information in GitHub issues and on the new website.
  • We attended Software You Can Love in Milan, Italy - gave a talk, had a table full of Zig gamedevs, and gave out some cool stickers
  • We saw a number of new contributors, both one-off and ongoing.
  • Many coffee was drank, and much coding was done over the holidays.

A personal note

I work a normal tech job, and every day after I sign off from work I go online to build Mach, almost like working two jobs. I've been working on Mach double-time like this for over two years now, and dreaming of it for a decade before that.

FOSS is in my roots and I believe we should own our tools, they should empower us-not be part of the 'open source' game which is all too prevelant today (even among 'open source' engines.) Mach needs to be for people like you and me-it needs to genuinely be software you can love.

My dream is one day to live a simple, modest, future earning a living building Mach for you and creating high-quality games for everyone. Please consider sponsoring my work if you believe in my vision.

Thanks

Both to everyone who has contributed and sponsored the project, as well as you for reading this far!