Skip to content
openflukePublic

About

Cross-platform Go bindings for WebGPU (supports macOS, Windows, Linux, iOS, Android, and web)

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

WebGPU (openfluke)

Go bindings for WebGPU, maintained by openfluke.

Native builds use wgpu-native v29 with Go-side bindings (no C compatibility shims). The same module also supports the browser via WASM. Targets include Vulkan, Metal, D3D12, and OpenGL ES.

Module: github.com/openfluke/webgpu
Current release: v1.0.6 (ships wgpu-native v29.0.0.0)

Version history

Tag What it was
v1.0.0 Initial openfluke release: v29 Go bindings + v29 static libs
v1.0.2 Do not use — Go proxy cached wrong commit
v1.0.3 Do not use — Go proxy cached wrong commit
v1.0.4 Drops legacy ios/amd64; fixes go get module size limit
v1.0.5 Full enums.go regen from webgpu.h + wgpu.h (v29 values); stops enum drift panics
v1.0.6 Windows arm64 libwgpu_native.a rebuilt as gnullvm (links with Go CGO / llvm-mingw; replaces broken MSVC static)

Monorepo note: wgpu/enums.go must match wgpu/lib/webgpu.h and wgpu/lib/wgpu.h. Regenerate when headers change:

python3 cmd/enums/regen.py

(go generate in cmd/enums also works on Linux; on macOS use regen.py because the C parser chokes on _Float16.)

Drift causes native panics (e.g. Depth write enabled for non-depth format) when creating render pipelines.

What's in v1.0.0

wgpu-native v29 stack

  • Headers: wgpu/lib/webgpu.h, wgpu/lib/wgpu.h (WebGPU C API + wgpu-native extensions)
  • Binaries: prebuilt libwgpu_native.a per target under wgpu/lib/:
Platform Path
macOS darwin/amd64, darwin/arm64
Linux linux/amd64, linux/arm64
Windows windows/amd64 (gnu), windows/arm64 (gnu / gnullvm)
iOS ios/arm64 (device and Apple Silicon simulator)
Android android/arm64, android/arm, android/amd64, android/386

Go binding highlights (native)

Bindings target the v29 C API directly:

  • WGPUStringView for labels, entry points, shader source, messages
  • Async ops via WGPUFuture + wgpuInstanceWaitAny (RequestAdapter, RequestDevice, MapAsync, error scopes, queue work done)
  • wgpuDeviceAddRef, wgpuAdapterGetFeatures, wgpuDeviceGetLimits with maxImmediateSize
  • Shader chains: WGPUShaderSourceWGSL / SPIRV / WGPUShaderSourceGLSL
  • Surfaces: WGPUSurfaceSource* descriptors
  • Texel copy types: WGPUTexelCopyTextureInfo, etc.
  • Push constants → pipeline immediateDataSize / SetImmediates (native extension)
  • Validation error scopes implemented in Go (v29.go)

Tested on real hardware

  • macOS arm64 + Metal — loom / lucy: adapter → device → buffer → GPU forward parity (Apple M5)
  • Windows arm64 — native wgpu-native v29 static lib; GPU path verified

Other platforms have matching v29 libs in-tree; smoke-test on each target you ship.

Install

go get github.com/openfluke/webgpu@v1.0.6

Local development (e.g. from the endgame monorepo):

replace github.com/openfluke/webgpu => ../webgpu

Usage

Native and JS builds use the same import path; build tags select the backend:

import "github.com/openfluke/webgpu/wgpu"
  • //go:build !js — wgpu-native (this README)
  • //go:build js — browser WebGPU via WASM

Examples

boids cube triangle
boids cube triangle

Rebuilding native libs

Vendored artifacts came from official wgpu-native v29 release zips where available. To refresh:

  1. Download matching wgpu-*-release.zip from wgpu-native releases
  2. Copy lib/libwgpu_native.a into the corresponding wgpu/lib/<platform>/<arch>/ directory
  3. Ensure shared headers under wgpu/lib/ stay in sync with that release

Windows arm64 exception: upstream only publishes wgpu-windows-aarch64-msvc-*. That MSVC static lib does not link with Go CGO (llvm-mingw / gnu), which is what Welvet and this module use on Windows. Rebuild a gnullvm static lib instead:

# Needs: rustup target aarch64-pc-windows-gnullvm, llvm-mingw, LLVM (libclang)
.\scripts\build_windows_arm64_gnu.ps1

CI can also rebuild via .github/workflows/build-wgpu.yml (workflow_dispatch).

Lineage

API design and WASM support draw on earlier community work (rajveermalviya/go-webgpu, mokiat/wasmgpu). This repository is maintained independently by openfluke; vendored binaries and the v29 native bindings are openfluke-specific.

References

License

See LICENSE.

About

Cross-platform Go bindings for WebGPU (supports macOS, Windows, Linux, iOS, Android, and web)

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages