Pure Go WebGPU Implementation
No Rust. No CGO. Just Go.
Part of the GoGPU ecosystem
wgpu is a complete WebGPU implementation written entirely in Go. It provides direct GPU access through multiple hardware abstraction layer (HAL) backends without requiring Rust, CGO, or any external dependencies.
| Category | Capabilities |
|---|---|
| Backends | Vulkan, Metal, DirectX 12, OpenGL ES, Software |
| Platforms | Windows, Linux, macOS, iOS |
| API | WebGPU-compliant (W3C specification) |
| Shaders | WGSL via gogpu/naga compiler |
| Compute | Full compute shader support |
| Build | Zero CGO, simple go build |
go get github.com/gogpu/wgpuRequirements: Go 1.25+
package main
import (
"fmt"
"github.com/gogpu/wgpu/core"
"github.com/gogpu/wgpu/types"
_ "github.com/gogpu/wgpu/hal/allbackends" // Auto-register platform backends
)
func main() {
// Create instance with platform-appropriate backends
instance := core.NewInstance(&types.InstanceDescriptor{
Backends: types.BackendsAll,
})
// Request high-performance GPU
adapterID, _ := instance.RequestAdapter(&types.RequestAdapterOptions{
PowerPreference: types.PowerPreferenceHighPerformance,
})
// Get adapter info
info, _ := core.GetAdapterInfo(adapterID)
fmt.Printf("GPU: %s (%s)\n", info.Name, info.Backend)
// Create device
deviceID, _ := core.RequestDevice(adapterID, &types.DeviceDescriptor{
Label: "My Device",
})
// Get queue for command submission
queueID, _ := core.GetDeviceQueue(deviceID)
_ = queueID // Ready for rendering
}// Create compute pipeline
pipelineID, _ := core.DeviceCreateComputePipeline(deviceID, &core.ComputePipelineDescriptor{
Label: "Compute Pipeline",
Layout: layoutID,
Compute: core.ProgrammableStage{
Module: shaderModuleID,
EntryPoint: "main",
},
})
// Begin compute pass
encoder, _ := core.DeviceCreateCommandEncoder(deviceID, nil)
computePass := encoder.BeginComputePass(nil)
// Dispatch workgroups
computePass.SetPipeline(pipelineID)
computePass.SetBindGroup(0, bindGroupID, nil)
computePass.Dispatch(64, 1, 1)
computePass.End()
// Submit commands
commands := encoder.Finish(nil)
core.QueueSubmit(queueID, []types.CommandBuffer{commands})wgpu/
├── types/ # WebGPU type definitions
├── core/ # Validation, state tracking, resource management
├── hal/ # Hardware Abstraction Layer
│ ├── allbackends/ # Platform-specific backend auto-registration
│ ├── noop/ # No-op backend (testing)
│ ├── software/ # CPU software rasterizer (~10K LOC)
│ ├── gles/ # OpenGL ES 3.0+ (~7.5K LOC)
│ ├── vulkan/ # Vulkan 1.3 (~27K LOC)
│ ├── metal/ # Metal (~3K LOC)
│ └── dx12/ # DirectX 12 (~12K LOC)
└── cmd/
├── vk-gen/ # Vulkan bindings generator
└── vulkan-triangle/# Integration test
The HAL Backend Integration layer provides unified multi-backend support:
import _ "github.com/gogpu/wgpu/hal/allbackends"
// Platform-specific backends auto-registered:
// - Windows: Vulkan, DX12, GLES
// - Linux: Vulkan, GLES
// - macOS: Metal, Vulkan| Backend | Windows | Linux | macOS | iOS | Notes |
|---|---|---|---|---|---|
| Vulkan | Yes | Yes | Yes | - | MoltenVK on macOS |
| Metal | - | - | Yes | Yes | Native Apple GPU |
| DX12 | Yes | - | - | - | Windows 10+ |
| GLES | Yes | Yes | - | - | OpenGL ES 3.0+ |
| Software | Yes | Yes | Yes | Yes | CPU fallback |
Full Vulkan 1.3 implementation with:
- Auto-generated bindings from official
vk.xml - Buddy allocator for GPU memory (O(log n), minimal fragmentation)
- Dynamic rendering (VK_KHR_dynamic_rendering)
- Classic render pass fallback for Intel compatibility
- wgpu-style swapchain synchronization
- Complete resource management (Buffer, Texture, Pipeline, BindGroup)
Native Apple GPU access via:
- Pure Go Objective-C bridge (goffi)
- Metal API via runtime message dispatch
- CAMetalLayer integration for surface presentation
- MSL shader compilation via naga
Windows GPU access via:
- Pure Go COM bindings (syscall, no CGO)
- DXGI integration for swapchain and adapters
- Flip model with VRR support
- Descriptor heap management
Full-featured CPU rasterizer for headless rendering:
import _ "github.com/gogpu/wgpu/hal/software"
// Use cases:
// - CI/CD testing without GPU
// - Server-side image generation
// - Reference implementation
// - Fallback when GPU unavailableRasterization Features:
- Edge function triangle rasterization (Pineda algorithm)
- Perspective-correct interpolation
- Depth buffer (8 compare functions)
- Stencil buffer (8 operations)
- Blending (13 factors, 5 operations)
- 6-plane frustum clipping (Sutherland-Hodgman)
- 8x8 tile-based parallel rendering
wgpu is the foundation of the GoGPU ecosystem.
| Project | Description |
|---|---|
| gogpu/gogpu | GPU framework with windowing and input |
| gogpu/wgpu | Pure Go WebGPU (this repo) |
| gogpu/naga | Shader compiler (WGSL to SPIR-V, MSL, GLSL) |
| gogpu/gg | 2D graphics library |
| go-webgpu/webgpu | wgpu-native FFI bindings |
| go-webgpu/goffi | Pure Go FFI library |
- ROADMAP.md — Development milestones
- CHANGELOG.md — Release notes
- CONTRIBUTING.md — Contribution guidelines
- pkg.go.dev — API reference
- WebGPU Specification — W3C standard
- wgpu (Rust) — Reference implementation
- Dawn (C++) — Google's implementation
Contributions welcome! See CONTRIBUTING.md for guidelines.
Priority areas:
- Cross-platform testing
- Performance benchmarks
- Documentation improvements
- Bug reports and fixes
MIT License — see LICENSE for details.
wgpu — WebGPU in Pure Go