go-webgpu

March 2, 2026 · View on GitHub

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

GitHub Release Go Version Go Reference GitHub Actions Codecov 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.

FeatureStatus
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)

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.

To use a custom library location:

export WGPU_NATIVE_PATH=/path/to/libwgpu_native.so

Type System

This library uses gputypes for WebGPU type definitions, ensuring compatibility with the gogpu ecosystem and webgpu.h specification.

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

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

ExampleDescription
triangleBasic triangle rendering
colored-triangleVertex colors and buffers
textured-quadTextures, samplers, index buffers
rotating-triangleUniform buffers, animation
cube3D rendering with depth buffer
instancedInstanced rendering (25 objects in 1 draw call)
computeCompute shader parallel processing
indirectGPU-driven rendering (DrawIndirect)
render_bundlePre-recorded draw commands
timestamp_queryGPU profiling with timestamps
mrtMultiple Render Targets
error_handlingError 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      │
└─────────────────────────────────────────┘

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 — Pure Go GPU ecosystem

ProjectDescription
gogpu/wgpuPure Go WebGPU implementation
gogpu/nagaPure Go shader compiler (WGSL/SPIR-V)
gogpu/gogpuHigh-level GPU compute framework
gogpu/ggPure Go graphics library

Dependencies

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.