mach/gpu
Stephen Gutekanst aab99b5474 gpu: make requestDevice callback-based, add waitForDevice helper
Previously we were attempting to turn WebGPU async functions, which are
exposed by `webgpu.h` as callbacks, into Zig async functions.

This in practice turns out harder than expected. For example, `Buffer.mapAsync`
/ `wgpuBufferMapAsync` cannot easily be exposed as a Zig async function for a few
reasons:

1. The callback is merely guaranteed to be called once the buffer's content is ready to
   be accessed via `wgpuBufferGetMappedRange` - but there is no strict guarantee about
   when that is. It could be 1-3 frames later, in theory, I believe.
2. The non-deterministic timing means that one would wish to poll "has the async function
   returned?" but this isn't trivial without our own scheduler.
3. Zig has a fair amount of async rework in the future that is coming, and I imagine it
   will be one of the later things that is fully supported by the WebAssembly backend
   (but I am speculating) - so it seems wise to punt on this until later.

Instead, we are now retaining async functions as callback-based ones, with a helper in
this case to wait for the callback to be invoked. For `wgpuBufferMapAsync` we will just
have the callback approach.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
..
.github gpu: initialize project 2022-03-19 00:51:48 -07:00
examples gpu: make requestDevice callback-based, add waitForDevice helper 2022-03-19 00:51:48 -07:00
libs gpu: add gpu-hello-triangle (dawn) example 2022-03-19 00:51:48 -07:00
src gpu: make requestDevice callback-based, add waitForDevice helper 2022-03-19 00:51:48 -07:00
.gitattributes gpu: initialize project 2022-03-19 00:51:48 -07:00
.gitignore gpu: initialize project 2022-03-19 00:51:48 -07:00
build.zig gpu: add run-example build command 2022-03-19 00:51:48 -07:00
LICENSE gpu: initialize project 2022-03-19 00:51:48 -07:00
LICENSE-APACHE gpu: initialize project 2022-03-19 00:51:48 -07:00
LICENSE-MIT gpu: initialize project 2022-03-19 00:51:48 -07:00
README.md gpu: README: note community, where to file issues, contributing 2022-03-19 00:51:48 -07:00

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

mach/gpu provides a truly cross-platform graphics API (desktop, mobile, and web) with unified low-level graphics & compute backed by 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:

  • Android support
  • iOS support
  • Browser support

Features

  • Desktop, mobile, and web support.
  • A modern graphics API similar to Metal, Vulkan, and DirectX 12.
  • Cross-platform shading language
  • Compute shaders
  • Cross-compilation & no fuss installation, using zig build, as with all Mach libraries.
  • 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

Different approach to graphics API abstraction

Most engines today (Unreal, Unity, Godot, etc.) maintain their own GPU abstraction layer over native graphics APIs at great expense, requiring 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 aims to be a cross-platform graphics API, but also requires abstraction layers like MoltenVK on Apple hardware and is often in practice too verbose for use by regular folks 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 as many abstraction layers on top and perhaps make smarter choices as a result.

With Mach, we'd rather focus on building the interesting and innovative bits of an engine rather than burning years on yet-another-graphics-abstraction-layer.

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 targeting native platforms, we build Google Chrome's WebGPU implementation, Dawn, bypassing the client-server sandboxing model and use 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

WebGPU version

The interface and all documentation corresponds to the spec found at:

https://github.com/gpuweb/gpuweb/tree/main/spec

Revision: 3382f327520b4bcd5ea617fa7e7fe60e214f0d96

Tracking this enables us to diff the spec and keep our interface up to date.

Join the community

Join the Mach engine community on Matrix chat to discuss this project, ask questions, get help, etc.

Issues

Issues are tracked in the main Mach repository.

Contributing

Contributions are very welcome. Pull requests must be sent to the main repository to avoid some complex merge conflicts we'd get by accepting contributions in both repositories. Once the changes are merged there, they'll get sync'd to this repository automatically.