DEV Community

Cover image for GoGPU: A Pure Go Graphics Library for GPU Programming
Andrey Kolkov
Andrey Kolkov

Posted on • Edited on

GoGPU: A Pure Go Graphics Library for GPU Programming

Last updated: 2026-02-12

Join the Discussion: Help shape the future of Go graphics! Share your ideas, report issues, and discuss features at our GitHub Discussions.

Finally, a graphics framework that feels like Go.

TL;DR

  • Problem: Go lacks a professional graphics ecosystem
  • Solution: GoGPU — Pure Go, Zero-CGO, WebGPU-based
  • Result: 380K+ lines of Pure Go code, no Rust, no C
  • GPU: SDF accelerator, compute shaders, 5 WebGPU backends
  • 2D: Vello-inspired rasterizer, 29 blend modes, PDF/SVG export
  • UI: 54K LOC GUI toolkit with signals, layout, Material 3 theme
  • Repo: github.com/gogpu

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

I saw this frustration firsthand in a Reddit thread: "Go deserves more support in GUI development".

So I built it.

The Ecosystem (February 2026)

What started as a simple triangle demo has grown into a complete graphics stack:

Project Description Version LOC
gogpu/gg 2D graphics library v0.27.1 ~155K
gogpu/wgpu Pure Go WebGPU v0.15.0 ~97K
gogpu/ui GUI widget toolkit v0.0.x ~54K
gogpu/naga Shader compiler (WGSL to SPIR-V/MSL/GLSL/HLSL) v0.12.0 ~39K
gogpu/gogpu Graphics framework v0.17.0 ~36K
gogpu/gpucontext Shared GPU interfaces v0.9.0
gogpu/gputypes WebGPU type definitions v0.2.0
gogpu/gg-pdf PDF export for gg v0.1.0
gogpu/gg-svg SVG export for gg v0.1.0

Total: 380K+ lines of Pure Go — no CGO, no Rust, no C.

Show Me the Code

High-Level: 2D Graphics (gogpu/gg)

package main

import (
    "github.com/gogpu/gg"
    "github.com/gogpu/gg/text"
)

func main() {
    // dc = "drawing context" — the convention from fogleman/gg
    dc := gg.NewContext(512, 512)
    dc.ClearWithColor(gg.White)

    // Draw a filled circle
    dc.SetHexColor("#3498db")
    dc.DrawCircle(256, 256, 100)
    dc.Fill()

    // Stroke a rounded rectangle
    dc.SetHexColor("#e74c3c")
    dc.SetLineWidth(3)
    dc.DrawRoundedRectangle(156, 156, 200, 200, 20)
    dc.Stroke()

    // Load font and draw text
    source, _ := text.NewFontSourceFromFile("arial.ttf")
    defer source.Close()

    dc.SetFont(source.Face(32))
    dc.SetRGB(0, 0, 0)
    dc.DrawString("Hello, GoGPU!", 180, 270)

    dc.SavePNG("output.png")
}
Enter fullscreen mode Exit fullscreen mode

GPU Acceleration (opt-in)

import _ "github.com/gogpu/gg/gpu" // opt-in GPU acceleration

dc := gg.NewContext(800, 600)
dc.DrawCircle(400, 300, 100)
dc.Fill() // GPU renders via SDF if shape detected, CPU fallback otherwise
Enter fullscreen mode Exit fullscreen mode

The SDF accelerator auto-detects circles, ellipses, rectangles, and rounded rectangles from path data. Everything else falls back to the CPU rasterizer — transparently, with ~17ns overhead when no GPU is registered.

Low-Level: Triangle (gogpu/gogpu)

package main

import (
    "log"
    "github.com/gogpu/gogpu"
    "github.com/gogpu/gogpu/gmath"
)

func main() {
    app := gogpu.NewApp(gogpu.DefaultConfig().
        WithTitle("GoGPU Triangle").
        WithSize(800, 600))

    app.OnDraw(func(dc *gogpu.Context) {
        dc.DrawTriangleColor(gmath.DarkGray)
    })

    if err := app.Run(); err != nil {
        log.Fatal(err)
    }
}
Enter fullscreen mode Exit fullscreen mode

15 lines vs 400-500 lines of raw WebGPU boilerplate.

Architecture

┌─────────────────────────────────────────────┐
│             Your Application                │
├─────────────────────────────────────────────┤
│         gogpu/ui (GUI Toolkit)              │
│   Signals, Flexbox/Grid, Material 3 Theme   │  ← 54K LOC
├─────────────────────────────────────────────┤
│        gogpu/gg (2D Graphics)               │
│   CPU Rasterizer + GPU SDF Accelerator      │  ← 155K LOC
│   29 Blend Modes, PDF/SVG Export            │
├─────────────────────────────────────────────┤
│        gogpu/gogpu (Framework)              │
│   Windowing, Input, Lifecycle, Textures     │
│   Win32 │ X11 │ Wayland │ Cocoa             │
├─────────────────────────────────────────────┤
│        gogpu/wgpu (Pure Go WebGPU)          │
│   Vulkan │ DX12 │ Metal │ GLES │ Software   │  ← 97K LOC
├─────────────────────────────────────────────┤
│        gogpu/naga (Shader Compiler)         │
│   WGSL → SPIR-V │ MSL │ GLSL │ HLSL         │  ← 39K LOC
└─────────────────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

Key innovation: Everything is Pure Go. No CGO, no wgpu-native dependency.

CPU Core + GPU Accelerator

Based on analysis of 8 enterprise 2D engines (Skia, Cairo, Vello, Blend2D, tiny-skia, piet, Qt RHI, Pathfinder):

CPU rasterization is the core. GPU is an optional accelerator.

gg.Fill() / gg.Stroke()
    │
    ├── GPUAccelerator (if registered via import _ "gg/gpu")
    │      ├── SDF: circles, rects, rrects (hardware-accelerated)
    │      └── Stencil-Then-Cover: general paths (coming soon)
    │
    └── SoftwareRenderer → internal/raster/ (always available)
            ├── Vello-inspired tile rasterizer
            ├── Analytic anti-aliasing
            └── Parallel tile processing
Enter fullscreen mode Exit fullscreen mode

Platform Support

Platform Windowing GPU Backends Status
Windows Win32 Vulkan, DX12 (WIP), GLES Production
Linux X11 Pure Go X11 Vulkan, GLES Production
Linux Wayland Pure Go Wayland Vulkan, GLES Production
macOS Cocoa Metal Production

Pure Go WebGPU Backends

Backend Status Use Case
Vulkan Stable Cross-platform (Windows/Linux/macOS)
Metal Stable macOS/iOS
OpenGL ES Stable Windows + Linux
Software Stable Headless, CI/CD, no GPU required
DX12 WIP Windows native

Shader Compiler (naga)

WGSL source compiles to all major GPU targets:

Target Platforms Status
SPIR-V Vulkan (all platforms) Stable
MSL Metal (macOS/iOS) Stable
GLSL OpenGL 3.3+, ES 3.0+ Stable
HLSL DirectX 11/12 Stable

60+ WGSL built-in functions, atomics, barriers, compute shaders.

GUI Toolkit: gogpu/ui (54K LOC)

No longer just a plan — gogpu/ui is 54K lines of working code with 1,400+ tests.

Component Status Description
Signals Working Fine-grained reactivity — Signal[T], Computed[T], Effect
Layout Engine Working Flexbox, Grid, Stack — constraint-based tree layout
Theme System Working Material 3 tokens, light/dark mode, typography
Focus Management Working Keyboard navigation, tab order, focus ring
Button Working Material 3 themed with press/hover states
Checkbox Working Checked/unchecked/indeterminate
Radio Group Working Exclusive selection with local coordinate layout
Canvas Working Pixel-grid snapping for crisp sub-pixel rendering
Event System Working Pointer events, keyboard events, coordinate translation

What's next for UI: Text Input, Scroll Container, Data Table, Accessibility (AccessKit).

2D Graphics Highlights (gogpu/gg)

Feature Description
GPU SDF Accelerator Auto-detects shapes, renders on GPU via compute shaders
Vello-Inspired Rasterizer Tile-based (16x16), analytic AA, parallel processing
29 Blend Modes Porter-Duff (14) + Advanced Separable (11) + HSL (4)
Premultiplied Alpha Industry-standard compositing (matches Skia, Cairo)
Fluent PathBuilder Method chaining for complex path construction
PDF/SVG Export Via recording backends (gg-pdf, gg-svg)
Text Rendering HarfBuzz shaping, OpenType/TrueType, color fonts
LUT Optimizations 260x faster sRGB conversions
Parallel Rendering TileGrid + WorkerPool for multi-core

What's Next?

GPU Path Rendering

Three-tier architecture for rendering all path types on GPU:

Tier Technique Status
1 SDF Fragment Shader (circles, rects, rrects) Working
2a Direct Convex Fan (single draw call) Planned
2b Stencil-Then-Cover (all general paths) Planned
3 Vello Compute (optimal, all paths) Future

Roadmap

Quarter Focus Status
Q1 2026 GPU SDF Accelerator, Architecture, Ecosystem Done
Q1 2026 GPU Path Rendering (Stencil-Then-Cover) In Progress
Q1-Q2 UI Toolkit (signals, layout, theme, widgets) In Progress
Q2 UI: Text Input, Scroll, Data Table Planned
Q3 UI: Accessibility (AccessKit), Docking Planned
Q4 Stabilization, Documentation, Benchmarks Planned

The GoGPU Series

All articles documenting the GoGPU journey:

  1. GoGPU: A Pure Go Graphics Library for GPU Programming — You are here
  2. GoGPU: From Idea to 100K Lines in Two Weeks — The rapid development story
  3. Building a Shader Compiler in Pure Go: naga — WGSL to SPIR-V/MSL/GLSL/HLSL
  4. Pure Go 2D Graphics Library with GPU Acceleration: Introducing gogpu/gg — 2D graphics API
  5. GPU Compute Shaders in Pure Go: gogpu/gg v0.15.3 — Sparse Strips GPU compute
  6. Go 1.26 Meets 2026 with a Professional Graphics Ecosystem — February 2026 update

Join Us — While You Can Shape the Future

This is the perfect time to get involved.

The API is still evolving. Before v1.0.0 freezes the interface, your feedback directly shapes the project:

  • Your ideas matterShare in Discussions
  • Cross-platform testers needed — Help us validate on real hardware
  • UI development — Signals, widgets, layouts — contributions welcome
  • Your name in history — Be part of building Go's GPU ecosystem

How You Can Help

Test on Your Platform

git clone https://github.com/gogpu/gogpu
cd gogpu
go build ./examples/triangle/
./triangle
Enter fullscreen mode Exit fullscreen mode

Report issues at github.com/gogpu/gogpu/issues

Star the Repos

Contribute

PRs welcome! Especially needed:

  • Cross-platform testing (especially macOS, Linux Wayland, NVIDIA GPUs)
  • UI widget development (signals, widgets, layouts)
  • Documentation and tutorials
  • Real-world usage examples
  • Compute shader examples

Links


Go deserves a great graphics ecosystem. We're building it.

Questions? Drop them in the comments or join the discussion.

Top comments (4)

Collapse
 
dave_73b515f1bcf8870 profile image
dave_73b515f1bcf8870

As soon as Text Rendering is available, I will be using this as the rendering engine for Bellina (a GUI library in Go).

Collapse
 
kolkov profile image
Andrey Kolkov • Edited

Thanks for your comment. Try github.com/gogpu/gg and the text rendering should work. There might be some bugs, but I've only tested it so far.

Collapse
 
andres36_f046592b42556601 profile image
ANDRES36

I'm also been working on a experimental GUI library, currently using raylib because I don't know GPU programming, how hard would it be to use gogpu compared to raylib? Raylib is great but it redraws everything and my library is meant to be a retained mode gui, I want to redraw only the updated regions to keep GPU usage low. reddit.com/r/raylib/comments/1puyi...

Thread Thread
 
kolkov profile image
Andrey Kolkov • Edited

Hi ANDRES36! Great to hear about your GUI library project!

Your approach with raylib is interesting. Here's a quick comparison:

  | Aspect               | raylib (your approach)   | gogpu/gg                                |
  |----------------------|--------------------------|-----------------------------------------|
  | Rendering            | Immediate mode           | Retained mode (scene graph)             |
  | Backend              | OpenGL                   | WebGPU (Vulkan/Metal/GLES)              |
  | Dependencies         | CGO (C library)          | Pure Go (zero CGO)                      |
  | GPU acceleration     | Via OpenGL               | GPU path rendering via Sparse Strips    |
Enter fullscreen mode Exit fullscreen mode

What gogpu/gg offers for GUI building (v0.14.0):

  • Scene graph with dirty region tracking (only redraw what changed)
  • Layers with per-layer opacity and independent transformations
  • Alpha masks for compositing effects (new in v0.14.0)
  • 29 blend modes (Porter-Duff + Advanced + HSL)
  • Fluent PathBuilder for shape construction

gogpu/ui (in planning):
We're designing a signals-based GUI toolkit on top of gogpu/gg. Think Angular/SolidJS reactivity but for native desktop apps. Enterprise features like docking, virtualization, accessibility are planned.

Your HTML/CSS reverse-engineering approach is clever! If you're interested in comparing notes or potentially collaborating on retained-mode patterns, join our discussion:
👉 github.com/orgs/gogpu/discussions/18

The Pure Go ecosystem means easy cross-compilation: GOOS=linux go build — no C toolchain needed.