GoGPU: From Idea to 100K Lines in Two Weeks — Building Go's GPU Ecosystem

Published: (December 16, 2025 at 07:57 PM EST)
3 min read
Source: Dev.to

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)

ComponentApprox. LinesDescription
types/~2 KWebGPU type definitions
core/~6 KValidation and state tracking
hal/vulkan/~35 KVulkan 1.3 backend
hal/gles/~7.5 KOpenGL ES backend
hal/software/~1 KCPU 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

MetricValue
Total Lines of Code106 295
Repositories4
Development Time2 weeks
External Dependencies0
CGO RequiredNo
PlatformsWindows, 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 buildsgo build works 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 framework
  • github.com/gogpu/wgpu – WebGPU implementation
  • github.com/gogpu/naga – WGSL → SPIR‑V compiler
  • github.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 gg library.
  • gfx‑rs – reference implementations of wgpu and naga.
  • 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

Back to Blog

Related posts

Read more »

OBS Studio Gets a New Renderer

Article URL: https://obsproject.com/blog/obs-studio-gets-a-new-renderer Comments URL: https://news.ycombinator.com/item?id=46305428 Points: 44 Comments: 11...