GoGPU: A Pure Go Graphics Library for GPU Programming
Source: Dev.to
The Problem: Go and Graphics Don’t Mix (Until Now)
If you’ve ever tried graphics programming in Go, you know the pain:
- CGO hell – most libraries require a C compiler.
- Abandoned projects – promising repos with no updates since 2019.
- “Just use Rust/C++” – the default answer in every forum.
A Reddit thread about Go GUI development received hundreds of up‑votes and dozens of comments, all asking:
“Why can’t we have nice things in Go?”
That frustration inspired GoGPU, a pure‑Go GPU computing ecosystem designed to make graphics programming accessible to every Go developer.
Principles
Zero‑CGO
No C compiler required. Pure Go bindings via FFI.
WebGPU‑First
Modern API that works on Vulkan, Metal, DX12, with future WASM support.
Simple by Default
Easy things are easy. Hard things are possible.
Cross‑Platform
Windows today; macOS and Linux coming soon.
Example: Drawing a Colored Triangle
package main
import (
"log"
"github.com/gogpu/gogpu"
"github.com/gogpu/gogpu/math"
)
func main() {
app := gogpu.NewApp(gogpu.DefaultConfig().
WithTitle("GoGPU Triangle").
WithSize(800, 600))
app.OnDraw(func(ctx *gogpu.Context) {
ctx.DrawTriangleColor(math.DarkGray)
})
if err := app.Run(); err != nil {
log.Fatal(err)
}
}
Only 15 lines of Go code – the equivalent raw WebGPU code would be 400–500 lines of boilerplate.
GoGPU handles:
- Window creation and event loop
- GPU device initialization
- Surface configuration
- Shader compilation
- Render pipeline setup
- Frame presentation
You focus on what to draw; GoGPU handles how.
Architecture Overview
┌─────────────────────────────────────────┐
│ Your Application │
│ (15 lines of code) │
├─────────────────────────────────────────┤
│ gogpu/gogpu │
│ Graphics Framework │
├─────────────────────────────────────────┤
│ gogpu/naga │
│ Shader Compiler (WGSL → SPIR‑V) │
├─────────────────────────────────────────┤
│ go-webgpu/webgpu │
│ Pure Go WebGPU Bindings │
├─────────────────────────────────────────┤
│ go-webgpu/goffi │
│ Pure Go FFI (Zero‑CGO) │
├─────────────────────────────────────────┤
│ wgpu-native │
│ Vulkan / Metal / DX12 │
└─────────────────────────────────────────┘
The key innovation is goffi – a pure‑Go FFI library that lets us call native code without CGO, eliminating the need for a C compiler and simplifying builds.
Ecosystem and Dependencies
-
GPU & Graphics
- Born ML – machine‑learning framework with GPU compute
- go-webgpu/webgpu – the WebGPU bindings powering GoGPU
-
Systems & Libraries
- Phoenix TUI – terminal UI framework
- scigolib/hdf5 – scientific computing bindings
- scigolib/matlab – MATLAB‑like operations
- coregx/* – signals, state replication, functional reactive streams, regex utilities
- kolkov/racedetector – race‑condition tools
These battle‑tested projects form the foundation on which GoGPU is built.
Version Milestones
| Version | Milestone | Status |
|---|---|---|
| v0.0.x | Project structure | ✅ Done |
| v0.1.0‑alpha | Triangle rendering | ✅ Done |
| v0.2.0‑alpha | Textures & sprites | 🔄 Next |
| v0.3.0‑alpha | Text rendering | 📋 Planned |
| v0.5.0‑beta | API stabilization | 📋 Planned |
| v1.0.0 | Production ready | 🎯 Goal |
Repository Overview
| Repository | Purpose | Status |
|---|---|---|
gogpu/gogpu | Core graphics framework | Active |
gogpu/naga | Shader compiler | Active |
gogpu/gg | 2D graphics API | Planned |
gogpu/ui | GUI toolkit | Future |
All repositories are hosted under the github.com/gogpu organization.
WebGPU Is the Future
- Cross‑platform by design – same API on Windows, macOS, Linux, and browsers.
- Modern architecture – built on lessons from Vulkan, Metal, and DX12.
- Safe by default – validation prevents common GPU programming errors.
- Browser‑ready – code can run in WASM (future goal).
Current Status
- Version: v0.1.0‑alpha (early development)
- Platform: Windows (macOS/Linux stubs ready)
- API: Still evolving; breaking changes expected.
The architecture is solid, the triangle renders, and the foundation (go‑webgpu) is proven.
Getting Started
git clone https://github.com/gogpu/gogpu
cd gogpu
go run ./examples/triangle
Contributing
Open issues and pull requests are welcome, especially for:
- macOS platform support
- Linux platform support
- Documentation
- More examples
See the repository’s contribution guidelines for details.
Closing
Go deserves a great graphics library. Let’s build it together.
Questions? Drop them in the comments.