1
0
Fork
You've already forked wgpuz
0
WebGPU bindings to Dawn/wgpu-native
  • Zig 94.9%
  • C 4.3%
  • HTML 0.8%
2026年06月26日 10:34:05 -07:00
examples GLFW support and running examples. 2026年03月09日 09:14:46 -07:00
src Format generated bindings. 2026年03月11日 19:16:42 -07:00
.gitignore Initial import. 2026年03月08日 22:26:09 -07:00
build.zig Update dependencies. 2026年06月25日 21:46:14 -07:00
build.zig.zon Update emsdkz. 2026年06月26日 10:34:05 -07:00
LICENSE-APACHE Initial import. 2026年03月08日 22:26:09 -07:00
LICENSE-MIT Initial import. 2026年03月08日 22:26:09 -07:00
README.md Enable emscripten builds and documentation. 2026年03月09日 10:57:55 -07:00

WGPUZ

WebGPU integration and bindings for Zig. Can be used either as a raw C library via the wgpuz.c module, or with lightweight Zig bindings via the wgpuz.wgpu module. Includes optional support for GLFW to configure window surfaces. The GLFW support is found in wgpuz.glfwz.

Getting Started

On the command line.

zig fetch --save=wgpuz git+https://codeberg.org/scriblz/wgpuz

In build.zig

fn(b:*std.Build)void{constwgpuz_dep=b.dependency("wgpuz",.{.target=target,.optimize=optimize,});constmod=b.addModule(...);mod.addImport("wgpuz",wgpuz_dep.module("wgpuz"));}

For usage, see the Examples.

C Library

WGPUZ translates the WebGPU header file and links against Dawn, wgpu-native, or emdawnwebgpu depending on the target OS and build options.

The C API can be accessed directly via wgpuz.c. The C module uses Zig's TranslateC to produce the API.

constwgpuz=@import("wgpuz");constwgpu_c=wgpuz.c;

Supported OS/WebGPU Backend

Yes - supported backend for target OS No - not currently supported, should be added and tested N/A - no planned support

Target OS Dawn wgpu-native
Mac OS Yes No
Windows No No
Linux No No
Emscripten Yes N/A

WGPU Zig Wrapper

WGPUZ generates Zig bindings to WebGPU using bindz. The bindings are very lightweight, and don't require any memory allocations. The bindings are more friendly to work with than directly with the C API. See the code in the examples directory for usage.

GLFW Support

GLFW support is optional and will currently link GLFW to your project if enabled. To enable GLFW support, modify your build.zig file as so:

fn(b:*std.Build)void{constwgpuz_dep=b.dependency("wgpuz",.{.target=target,.optimize=optimize,.glfw_support=true,});}

Enabling GLFW support will link GLFW 3.4 into your project and provide 2 helper functions for working with GLFW/WebGPU. The C API to GLFW is available via wgpuz.c. The support functions are available via wgpuz.glfwz.GlfwUtil. For usage, see examples/main.zig.

GLFW Support Helper Functions

Function Description
createWindowSurface Creates a WebGPU surface from a GLFW Window
configureWindowHdr Configures the underlying Window layer for rendering HDR content

Emscripten Support

Emscripten is a supported build target, simply pass the current build target to the wgpuz dependency, and you should be set. Emscripten support is provided by emsdkz.

Examples

The examples executable allows running an example in a GLFW window. In order to run an example, use the following command on the command line:

zig build examples -- <example name>

For emscripten:

# NOTE: does not work with latest version of Zig
zig build examples -Dtarget=wasm32-emscripten \
 -Dbrowser=chrome \ # optional specify browser to run
 -- <example name>

List of Examples

Example Name Description
triangle A simple triangle with a solid color
rotating_cube A rotating cube with a color gradient