Skip to content

go-webgpu/webgpu

go-webgpu

Zero-CGO WebGPU bindings for Go — GPU-accelerated graphics and compute in pure Go

GitHub Release Go Version Go Reference GitHub Actions Go Report Card License GitHub Stars GitHub Issues

Pure Go WebGPU bindings using goffi + 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 v24.0.3.1 (download)

Installation

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.

Quick Start

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 Basic triangle rendering
colored-triangle Vertex colors and buffers
textured-quad Textures, samplers, index buffers
rotating-triangle Uniform buffers, animation
cube 3D rendering with depth buffer
instanced Instanced rendering (25 objects in 1 draw call)
compute Compute shader parallel processing
indirect GPU-driven rendering (DrawIndirect)
render_bundle Pre-recorded draw commands
timestamp_query GPU profiling with timestamps
mrt Multiple Render Targets
error_handling Error scopes API

Run examples:

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      │
└─────────────────────────────────────────┘

Dependencies

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.