webgpu

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT

Image README

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

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

Project Description
gogpu/wgpu Pure Go WebGPU implementation
gogpu/naga Pure Go shader compiler (WGSL/SPIR-V)
gogpu/gogpu High-level GPU compute framework
gogpu/gg Pure Go graphics library

Dependencies

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.

Image Directories

Path Synopsis
examples
adapter_info command
Package main demonstrates using the Adapter Info API to query GPU capabilities.
Package main demonstrates using the Adapter Info API to query GPU capabilities.
buffer_introspection command
Package main demonstrates using the Buffer Introspection API.
Package main demonstrates using the Buffer Introspection API.
colored-triangle command
Package main demonstrates a colored triangle rendering using go-webgpu with vertex buffers.
Package main demonstrates a colored triangle rendering using go-webgpu with vertex buffers.
compute command
Example: Compute Shader Demonstrates GPU parallel processing using compute shaders.
Example: Compute Shader Demonstrates GPU parallel processing using compute shaders.
cube command
Package main demonstrates a rotating 3D cube with depth buffer using go-webgpu.
Package main demonstrates a rotating 3D cube with depth buffer using go-webgpu.
error_handling command
indirect command
Package main demonstrates GPU-driven rendering using DrawIndirect.
Package main demonstrates GPU-driven rendering using DrawIndirect.
instanced command
Example: Instanced Rendering Demonstrates drawing many objects efficiently using GPU instancing.
Example: Instanced Rendering Demonstrates drawing many objects efficiently using GPU instancing.
mrt command
Package main demonstrates Multiple Render Targets (MRT) using go-webgpu.
Package main demonstrates Multiple Render Targets (MRT) using go-webgpu.
render_bundle command
Package main demonstrates RenderBundle for pre-recording render commands.
Package main demonstrates RenderBundle for pre-recording render commands.
render_debug_markers command
Package main demonstrates using RenderPass Debug Markers for GPU debugging.
Package main demonstrates using RenderPass Debug Markers for GPU debugging.
rotating-triangle command
Package main demonstrates a rotating triangle using uniform buffers with go-webgpu.
Package main demonstrates a rotating triangle using uniform buffers with go-webgpu.
textured-quad command
Package main demonstrates a textured quad rendering using go-webgpu.
Package main demonstrates a textured quad rendering using go-webgpu.
timestamp_query command
Package main demonstrates GPU timestamp queries for profiling.
Package main demonstrates GPU timestamp queries for profiling.
triangle command
Package main demonstrates a simple triangle rendering using go-webgpu.
Package main demonstrates a simple triangle rendering using go-webgpu.
Package wgpu provides Zero-CGO WebGPU bindings for Go.
Package wgpu provides Zero-CGO WebGPU bindings for Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL