mach/gpu/README.md
Stephen Gutekanst d5d78a2196 gpu: README: clarify Zig version requirements
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2021-11-21 08:32:03 -07:00

4.4 KiB

mach/gpu, truly cross-platform graphics for Zig Hexops logo

mach/gpu is a truly cross-platform graphics API (desktop, mobile, and web) providing a unified low-level graphics API over Vulkan, Metal, D3D12, and OpenGL (as a best-effort fallback.)

Warning: Under heavy development!

Not everything stated in this README is yet achieved. We're working on it! Of particular note, we are missing:

  • You'll need a version of Zig which includes ObjC++ support: https://github.com/ziglang/zig/pull/10096
  • Cross compilation support
  • Windows support
  • Linux support
  • Android support
  • iOS support
  • Browser support
  • Idiomatic WebGPU wrapper

Features

  • Desktop, mobile, and web support.
  • Cross-compilation & no fuss installation, using zig build, as with all Mach libraries.
  • A modern graphics API similar to Metal, Vulkan, and DirectX 12.
  • Compute shaders
  • Advanced GPU features where hardware support is available:
    • Depth buffer clipping control
    • Depth buffer format control
    • Texture compression (BC, ETC2, and ASTC)
    • Timestamp querying (for GPU profiling)
    • Indirect draw support

Note: Absolute bleeding edge features which have not truly stabilized, such as DirectX 12 Mesh Shaders (which has limited hardware support, does not work across both AMD and NVIDIA cards in Vulkan, etc.) are not supported. You can however always choose to drop down to the underlying native Vulkan/Metal/D3D12 API in conjunction with this abstraction if needed.

A different approach to graphics API abstraction

Most engines today (Unreal, Unity) maintain their own GPU abstraction layer over native graphics APIs at great expense, requiring many years of development and ongoing maintenance.

Many are attempting graphics abstraction layers on their own including Godot (and their custom shading language), SDL's recently announced GPU abstraction layer, sokol_gfx, and others including Blender3D which target varying native graphics APIs. These are admirable efforts, but come at great development costs.

Vulkan, the alleged cross-platform graphics API, in practice requires abstraction layers like MoltenVK on Apple hardware and is often in practice too verbose for use without at least one higher level abstraction layer (often the engine's rendering layer.) With a simpler API like Metal or D3D, however, one could stay closer to the underlying API without introducing secondary and third abstraction layers on top and make smarter choices as a result.

With Mach, we'd rather focus on building great games than yet-another-abstraction-layer, and as it turns out some of the best minds in computer graphics (including the Rust community, Mozilla, Google, Microsoft, Intel, and Apple) have made serious multi-year investments with several full-time engineers into creating a solid abstraction layer for us - we're just being smart and adopting it for our own purpose!

Behind the scenes

mach/gpu is an idiomatic Zig interface to the next-generation WebGPU API, which supersedes WebGL and exposes the common denominator between the latest low-level graphics APIs (Vulkan, Metal, D3D12) in the web.

Despite its name, WebGPU was also built with native support in mind and has substantial investment from Mozilla, Google, Microsoft, Intel, and, critically, Apple:

When targeting WebAssembly, mach/gpu merely calls into the browser's native WebGPU implementation.

When building native Zig binaries, it builds and directly invokes Google Chrome's native WebGPU implementation, Dawn, bypassing the client-server sandboxing model - and using zig build (plus a lot of hand-holding) to support zero-fuss cross compilation & installation without any third-party Google tools, libraries, etc. Just zig and git needed, nothing else.

Read more about why we believe WebGPU may be the future of graphics here