wgpu-cr — WebGPU (wgpu-native) bindings for Crystal

I made wgpu-cr: Crystal bindings for wgpu-native (the Rust WebGPU implementation),
in the spirit of wgpu-py. Repo (MIT): GitHub - raj/wgpu-cr: Crystal bindings for wgpu-native (WebGPU) · GitHub

Two levels: a low-level LibWGPU FFI generated from webgpu.h (ABI-exact structs), and
a high-level WGPU with idiomatic helpers (instance/adapter/device requests, buffer mapping,
string views). The native lib is fetched by a postinstall, so shards install just works —
nothing vendored in git.

Working today: GPU compute end-to-end (a WGSL kernel doubling an array, read back to
Crystal), a triangle in a GLFW/Metal window, and the C ↔ Crystal callback plumbing.

require "wgpu"
instance = WGPU.create_instance
adapter  = WGPU.request_adapter(instance)
device   = WGPU.request_device(instance, adapter)
# upload a buffer, run a @compute WGSL kernel, map it back — see examples/compute.cr

Caveats, honestly: the high-level object layer is still thin (much of the render path is
fill-the-descriptor LibWGPU), and only macOS is exercised at runtime — Linux/Windows surface
structs are bound but examples aren't written yet.

I'm building a small ECS game engine on top of it, but wgpu-cr stands alone if you just want
WebGPU compute/rendering from Crystal. Feedback welcome.
7 Likes