GoGPU: From Idea to 100K Lines in Two Weeks — Building Go's GPU Ecosystem
Source: Dev.to
Introduction
For years I couldn’t understand why Go — a language loved for its simplicity and performance — still doesn’t have a professional GUI ecosystem. Every time I needed graphics in Go, I hit the same walls: CGO requirements, abandoned projects, incomplete solutions. It was frustrating.
Six months ago I started preparing: reading WebGPU specs, studying wgpu and naga source code, and designing the architecture. A Reddit thread where hundreds of developers shared the same frustration became the trigger. I published my first article with a simple triangle demo and started coding.
Two weeks later: 100 000+ lines of pure Go across four repositories, zero CGO, just go build.
Main Framework
The core framework provides a dual‑backend architecture — choose performance or simplicity.
package main
import (
"github.com/gogpu/gogpu"
"github.com/gogpu/gogpu/gmath"
)
func main() {
app := gogpu.NewApp(gogpu.DefaultConfig().
WithTitle("Hello GoGPU").
WithSize(800, 600))
app.OnDraw(func(ctx *gogpu.Context) {
ctx.DrawTriangleColor(gmath.DarkGray)
})
app.Run()
}
Build tags for backend selection
go build ./... # Both backends
go build -tags rust ./... # Rust backend (max performance)
go build -tags purego ./... # Pure Go backend (zero dependencies)
Complete WebGPU Implementation (≈ 57 900 lines)
| Component | Approx. Lines | Description |
|---|---|---|
types/ | ~2 K | WebGPU type definitions |
core/ | ~6 K | Validation and state tracking |
hal/vulkan/ | ~35 K | Vulkan 1.3 backend |
hal/gles/ | ~7.5 K | OpenGL ES backend |
hal/software/ | ~1 K | CPU rendering for CI/CD |
Backends
- Vulkan – Windows, Linux, macOS. Auto‑generated bindings, buddy memory allocator, Vulkan 1.3 dynamic rendering.
- OpenGL ES – Windows (WGL), Linux (EGL).
- Software – Headless rendering; no GPU required (useful for CI/CD).
// CI/CD without GPU
import _ "github.com/gogpu/wgpu/hal/software"
pixels := surface.GetFramebuffer() // CPU‑rendered pixels
WGSL → SPIR‑V Compiler (≈ 16 100 lines)
A pure‑Go compiler with 136 tests.
source := `
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3) {
let index = id.x;
output[index] = input[index] * 2.0;
}
`
spirv, err := naga.Compile(source)
Supports vertex, fragment, and compute shaders, atomics, barriers, texture sampling, 50+ built‑in functions.
Enterprise‑Grade 2D Graphics (≈ 23 400 lines)
Inspired by fogleman/gg, the gg package offers a canvas API with text rendering, images, clipping, 29 blend modes, layers, and linear‑color‑space blending. Test coverage exceeds 80 % for core packages (blend, color, image, text).
ctx := gg.NewContext(800, 600)
ctx.ClearWithColor(gg.White)
// Shapes
ctx.SetColor(gg.Hex("#3498db"))
ctx.DrawCircle(400, 300, 100)
ctx.Fill()
// Text with font fallback
source, _ := text.NewFontSourceFromFile("Roboto.ttf")
ctx.SetFont(source.Face(24))
ctx.DrawString("Hello, GoGPU!", 350, 305)
// Layers with blend modes
ctx.PushLayer(gg.BlendMultiply, 0.7)
ctx.SetColor(gg.Red)
ctx.DrawRectangle(350, 250, 100, 100)
ctx.Fill()
ctx.PopLayer()
ctx.SavePNG("output.png")
Project Metrics
| Metric | Value |
|---|---|
| Total Lines of Code | 106 295 |
| Repositories | 4 |
| Development Time | 2 weeks |
| External Dependencies | 0 |
| CGO Required | No |
| Platforms | Windows, Linux, macOS |
Architecture Overview
┌─────────────────────────────────────┐
│ Your Application │
├─────────────────────────────────────┤
│ gogpu/ui (planned) │ gogpu/gg (2D) │
├─────────────────────────────────────┤
│ gogpu/gogpu (framework) │
│ Windowing, Input, GPU Abstraction │
├─────────────────────────────────────┤
│ Rust Backend (wgpu‑native) │ Pure Go Backend (wgpu) │
├─────────────────────────────────────┤
│ gogpu/naga (WGSL → SPIR‑V) │
├─────────────────────────────────────┤
│ Vulkan │ OpenGL ES │ Software │
└─────────────────────────────────────┘
Benefits for Developers
- Simple builds –
go buildworks out of the box. - Cross‑compilation – trivial with Go’s toolchain.
- Debugging – stays in Go; no native debugger needed.
CI/CD
- Software backend eliminates the need for a GPU.
- Tests run in containers without driver hassles.
Ecosystem Impact
- Native tooling and standard profiling.
- No CGO overhead.
- Future extensions: Metal, DirectX 12 backends, GUI widget toolkit (
gogpu/ui).
Getting Started
go get github.com/gogpu/gg
import "github.com/gogpu/gg"
Explore the repositories:
github.com/gogpu/gogpu– core frameworkgithub.com/gogpu/wgpu– WebGPU implementationgithub.com/gogpu/naga– WGSL → SPIR‑V compilergithub.com/gogpu/gg– 2D graphics library
Star the repos and contribute!
Contributing
- Implement Metal or DirectX 12 backends.
- Improve documentation.
- Add tests or examples.
Acknowledgements
- Michael Fogleman – original
gglibrary. - gfx‑rs – reference implementations of
wgpuandnaga. - r/golang community – for the push I needed.
Years of frustration, six months of preparation, two weeks of coding: 100 000 lines of pure Go graphics code. The GPU ecosystem Go deserves is being built.
GoGPU –