https://github.com/go-webgpu/webgpu
Zero-CGO WebGPU bindings for Go — GPU-accelerated graphics and compute in pure Go
https://github.com/go-webgpu/webgpu
directx12 ffi gamedev go golang gpu graphics metal vulkan webgpu wgpu zero-cgo
Last synced: 2 months ago
JSON representation
Zero-CGO WebGPU bindings for Go — GPU-accelerated graphics and compute in pure Go
- Host: GitHub
- URL: https://github.com/go-webgpu/webgpu
- Owner: go-webgpu
- License: mit
- Created: 2025-11-15T20:13:45.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-12-29T09:43:47.000Z (5 months ago)
- Last Synced: 2026-01-01T08:35:09.374Z (4 months ago)
- Topics: directx12, ffi, gamedev, go, golang, gpu, graphics, metal, vulkan, webgpu, wgpu, zero-cgo
- Language: Go
- Homepage: https://pkg.go.dev/github.com/go-webgpu/webgpu
- Size: 163 KB
- Stars: 13
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# go-webgpu
> **Zero-CGO WebGPU bindings for Go — GPU-accelerated graphics and compute in pure Go**
[](https://github.com/go-webgpu/webgpu/releases/latest)
[](https://go.dev/dl/)
[](https://pkg.go.dev/github.com/go-webgpu/webgpu)
[](https://github.com/go-webgpu/webgpu/actions)
[](https://goreportcard.com/report/github.com/go-webgpu/webgpu)
[](LICENSE)
[](https://github.com/go-webgpu/webgpu/stargazers)
[](https://github.com/go-webgpu/webgpu/issues)
Pure Go WebGPU bindings using [goffi](https://github.com/go-webgpu/goffi) + [wgpu-native](https://github.com/gfx-rs/wgpu-native). No CGO required.
## Status
**Beta** — Comprehensive API ready for testing and feedback.
| Feature | Status |
|---------|--------|
| Instance, Adapter, Device | ✅ |
| Buffers (vertex, index, uniform, storage) | ✅ |
| Textures, Samplers, Storage Textures | ✅ |
| Render Pipelines | ✅ |
| Compute Pipelines | ✅ |
| Depth Buffer | ✅ |
| MRT (Multiple Render Targets) | ✅ |
| Instanced Rendering | ✅ |
| Indirect Drawing (GPU-driven) | ✅ |
| RenderBundle (pre-recorded commands) | ✅ |
| Cross-Platform Surface (Win/Linux/macOS) | ✅ |
| Error Handling (error scopes) | ✅ |
| QuerySet (GPU timestamps) | ✅ |
| BindGroupLayout (explicit) | ✅ |
| 3D Math (Mat4, Vec3) | ✅ |
## Requirements
- Go 1.25+
- wgpu-native v27.0.4.0 ([download](https://github.com/gfx-rs/wgpu-native/releases))
## Installation
```bash
go get github.com/go-webgpu/webgpu
```
Download wgpu-native and place `wgpu_native.dll` (Windows) or `libwgpu_native.so` (Linux) in your project directory or system PATH.
## Type System
This library uses [gputypes](https://github.com/gogpu/gputypes) for WebGPU type definitions, ensuring compatibility with the [gogpu ecosystem](https://github.com/gogpu) and webgpu.h specification.
```go
import (
"github.com/go-webgpu/webgpu/wgpu"
"github.com/gogpu/gputypes"
)
// Use gputypes for WebGPU enums
config.Format = gputypes.TextureFormatBGRA8Unorm
buffer.Usage = gputypes.BufferUsageVertex | gputypes.BufferUsageCopyDst
```
## Quick Start
```go
package main
import (
"fmt"
"log"
"github.com/go-webgpu/webgpu/wgpu"
)
func main() {
// Initialize library
if err := wgpu.Init(); err != nil {
log.Fatal(err)
}
// Create WebGPU instance
instance, err := wgpu.CreateInstance(nil)
if err != nil {
log.Fatal(err)
}
defer instance.Release()
// Request GPU adapter
adapter, err := instance.RequestAdapter(nil)
if err != nil {
log.Fatal(err)
}
defer adapter.Release()
fmt.Printf("Adapter: %#x\n", adapter.Handle())
}
```
## Examples
| Example | Description |
|---------|-------------|
| [triangle](examples/triangle) | Basic triangle rendering |
| [colored-triangle](examples/colored-triangle) | Vertex colors and buffers |
| [textured-quad](examples/textured-quad) | Textures, samplers, index buffers |
| [rotating-triangle](examples/rotating-triangle) | Uniform buffers, animation |
| [cube](examples/cube) | 3D rendering with depth buffer |
| [instanced](examples/instanced) | Instanced rendering (25 objects in 1 draw call) |
| [compute](examples/compute) | Compute shader parallel processing |
| [indirect](examples/indirect) | GPU-driven rendering (DrawIndirect) |
| [render_bundle](examples/render_bundle) | Pre-recorded draw commands |
| [timestamp_query](examples/timestamp_query) | GPU profiling with timestamps |
| [mrt](examples/mrt) | Multiple Render Targets |
| [error_handling](examples/error_handling) | Error scopes API |
Run examples:
```bash
cd examples/triangle && go run .
```
## Architecture
```
┌─────────────────────────────────────────┐
│ Your Go Application │
├─────────────────────────────────────────┤
│ go-webgpu (this package) │
│ - Zero CGO │
│ - Pure Go FFI via goffi │
├─────────────────────────────────────────┤
│ wgpu-native (Rust WebGPU) │
├─────────────────────────────────────────┤
│ Vulkan / Metal / DX12 / OpenGL │
└─────────────────────────────────────────┘
```
## Looking for Pure Go WebGPU?
This project uses FFI bindings to wgpu-native. If you're looking for a **100% Pure Go** WebGPU implementation (no native dependencies), check out:
👉 **[github.com/gogpu](https://github.com/gogpu)** — Pure Go GPU ecosystem
| Project | Description |
|---------|-------------|
| [gogpu/wgpu](https://github.com/gogpu/wgpu) | Pure Go WebGPU implementation |
| [gogpu/naga](https://github.com/gogpu/naga) | Pure Go shader compiler (WGSL/SPIR-V) |
| [gogpu/gogpu](https://github.com/gogpu/gogpu) | High-level GPU compute framework |
| [gogpu/gg](https://github.com/gogpu/gg) | Pure Go graphics library |
## Dependencies
- [goffi](https://github.com/go-webgpu/goffi) — Pure Go FFI for callbacks
- [wgpu-native](https://github.com/gfx-rs/wgpu-native) — Rust WebGPU implementation
- [golang.org/x/sys](https://pkg.go.dev/golang.org/x/sys) — Platform-specific syscalls
## License
MIT
## Contributing
Contributions welcome! Please open an issue or PR.