Skip to content
/ gogpu Public
forked from gogpu/gogpu

Pure Go Graphics Framework — GPU power, Go simplicity

License

Notifications You must be signed in to change notification settings

ppoage/gogpu

 
 

GoGPU Logo

GoGPU

Pure Go GPU Computing Ecosystem
GPU power, Go simplicity. Zero CGO.

CI codecov Go Reference Go Report Card License Go Version Stars Discussions


Status: Active Development

Pure Go backend works on ALL platforms! Windows (Vulkan/DX12), Linux (Vulkan), macOS (Metal).

All 5 GPU backends complete: Vulkan, Metal, DX12, GLES, Software.

Community Testing Welcome — Help us test on your platform!

Star the repo to follow progress!


Key Feature: Choose Your Backend

GoGPU lets you choose between two WebGPU implementations at compile time or runtime:

Backend Library Use Case
Rust wgpu-native via FFI Maximum performance, production apps
Native Go gogpu/wgpu Zero dependencies, simple go build

Build Tags (Compile Time)

# Include both backends (default)
go build ./...

# Only Rust backend (production)
go build -tags rust ./...

# Only Pure Go backend (zero dependencies)
go build -tags purego ./...

Runtime Selection

// Auto-select best available (default)
app := gogpu.NewApp(gogpu.DefaultConfig())

// Explicit Rust backend — max performance
app := gogpu.NewApp(gogpu.DefaultConfig().WithBackend(gogpu.BackendRust))

// Explicit Native Go backend — zero dependencies
app := gogpu.NewApp(gogpu.DefaultConfig().WithBackend(gogpu.BackendGo))

Same API, your choice of backend.


Quick Start

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()
}

~20 lines vs 480+ lines of raw WebGPU code.


Texture Loading

// Load texture from file (PNG, JPEG)
tex, err := renderer.LoadTexture("sprite.png")
defer tex.Destroy()

// Create from Go image
img := image.NewRGBA(image.Rect(0, 0, 128, 128))
tex, err := renderer.NewTextureFromImage(img)

// Create from raw RGBA data
tex, err := renderer.NewTextureFromRGBA(width, height, rgbaPixels)

// With custom options (pixel art, tiling)
opts := gogpu.TextureOptions{
    MagFilter:    types.FilterModeNearest,  // Crisp pixels
    AddressModeU: types.AddressModeRepeat,  // Tiling
}
tex, err := renderer.LoadTextureWithOptions("tile.png", opts)

macOS Platform

Pure Go Cocoa implementation — via goffi Objective-C runtime!

internal/platform/darwin/
├── init.go          # runtime.LockOSThread() for main thread
├── types.go         # CGFloat, CGPoint, CGRect, NSWindowStyleMask
├── objc.go          # Objective-C runtime via goffi
├── selectors.go     # Cached ObjC selectors
├── application.go   # NSApplication lifecycle
├── window.go        # NSWindow, NSView management
├── surface.go       # CAMetalLayer integration
└── ...              # ~1,000 lines total

Main Thread Requirement: macOS Cocoa requires all UI operations on the main thread. GoGPU automatically handles this with runtime.LockOSThread() — no action needed from users.

🧪 Community Testing Requested:

  • macOS 12+ (Monterey and later) on Apple Silicon (M1/M2/M3/M4)
  • Run CGO_ENABLED=0 go build -tags purego ./examples/triangle/ on macOS
  • Report issues at github.com/gogpu/gogpu/issues

Why GoGPU?

This project was inspired by a discussion on r/golang about the state of GUI and graphics development in Go.

GoGPU provides:

  1. Simple API — Hide WebGPU complexity behind intuitive Go code
  2. Dual Backend — Choose performance (Rust) or simplicity (Pure Go)
  3. Zero CGO — No C compiler required
  4. Cross-Platform — Windows, Linux (Wayland), macOS (Cocoa)
Layer Component
Application Your App / GUI
High-Level gogpu/ui (future), gogpu/gg (2D)
Core gogpu/gogpu — GPU abstraction, windowing, input
Backend gpu/backend/rust (wgpu-native) · gpu/backend/native (Pure Go)
Graphics API Vulkan · Metal · DX12 · OpenGL

Installation

go get github.com/gogpu/gogpu

Requirements:


Package Structure

gogpu/
├── app.go                 # Application lifecycle
├── config.go              # Configuration with builder pattern
├── context.go             # Drawing context API
├── renderer.go            # Backend-agnostic rendering
├── texture.go             # Texture loading API
├── shader.go              # Built-in WGSL shaders
├── gpu/                   # Backend abstraction layer
│   ├── backend.go         # Backend interface
│   ├── registry.go        # Backend registration (auto-discovery)
│   ├── types/             # Standalone types (wgpu-types pattern)
│   │   ├── handles.go     # Instance, Device, Texture, Sampler, etc.
│   │   ├── enums.go       # TextureFormat, PresentMode, etc.
│   │   └── descriptors.go # SamplerDescriptor, BindGroup, etc.
│   └── backend/
│       ├── rust/          # Rust backend (wgpu-native)
│       │   └── init.go    # Auto-registration (build tags)
│       └── native/        # Native Go backend (Vulkan via gogpu/wgpu)
│           └── init.go    # Auto-registration (build tags)
├── window/                # Window configuration
├── input/                 # Keyboard, mouse input
├── gmath/                 # Vec2, Vec3, Vec4, Mat4, Color
├── examples/              # Example applications
│   ├── triangle/         # Simple triangle demo
│   └── texture/          # Texture API demo
└── internal/
    └── platform/          # Platform abstraction (Win32, etc.)

Roadmap

See ROADMAP.md for the full roadmap.

Completed:

  • All 5 GPU backends — Vulkan, Metal, DX12, GLES, Software
  • All 4 shader backends — SPIR-V, MSL, GLSL, HLSL
  • Cross-platform windowing — Win32, Cocoa, X11, Wayland
  • Pure Go backend for ALL platforms — Windows, Linux, macOS

In Progress:

  • GUI toolkit (gogpu/ui)
  • Compute shader pipeline
  • Performance optimization

Ecosystem

Project Description Purpose
gogpu/gogpu Graphics framework (this repo) GPU abstraction, windowing, input
gogpu/wgpu Pure Go WebGPU Vulkan, Metal, GLES, Software backends
gogpu/naga Shader compiler WGSL → SPIR-V, MSL, GLSL
gogpu/gg 2D graphics Canvas API, scene graph, GPU text
gogpu/ui GUI toolkit Widgets, layouts, themes (planned)
go-webgpu/webgpu FFI bindings wgpu-native integration

Note: Always use the latest versions. Check each repository for current releases.

wgpu Backends

The Pure Go WebGPU implementation (gogpu/wgpu) now includes:

Backend Status Features
Software ✅ Done Full rasterizer, depth/stencil, blending, clipping, parallel
OpenGL ES ✅ Done Windows (WGL) + Linux (EGL)
Vulkan ✅ Done Cross-platform (Windows/Linux/macOS), Vulkan 1.3
Metal ✅ Done macOS/iOS via goffi Objective-C bridge
DX12 ✅ Done Windows via Pure Go COM syscall

Software backend enables headless rendering:

go build -tags software ./...  # CPU-only, no GPU needed

Vulkan backend now implements the complete HAL Device interface including:

  • Buffer, Texture, TextureView, Sampler
  • ShaderModule, Pipeline, BindGroup
  • CommandEncoder, RenderPass, ComputePass
  • Fence synchronization, WriteTexture

Announcement

Read our launch announcement on Dev.to: GoGPU: A Pure Go Graphics Library for GPU Programming


Contributing

Contributions are welcome! This is an early-stage project, so there's lots to do.

Join the discussion: GitHub Discussions — Share ideas, ask questions, help shape the gogpu/ui GUI toolkit!

Areas where we need help:

  • 🧪 macOS testing — Test on real macOS systems (Monterey+)
  • 🧪 Linux X11 testing — Test on X11 systems (Ubuntu, Fedora, etc.)
  • 🧪 Linux Wayland testing — Test on Wayland compositors
  • 🧪 DX12 testing — Test on Windows with DirectX 12
  • Documentation and examples
git clone https://github.com/gogpu/gogpu
cd gogpu
go build ./...
go test ./...

Acknowledgments

Special Thanks

Professor Ancha Baranova — This project would not have been possible without her invaluable help and support. Her assistance was crucial in bringing this ecosystem to life.

Inspiration

Contributors

Thanks to our community testers who help improve GoGPU:

  • @ppoage — macOS ARM64 testing (M1/M4), Issue #24 investigation
  • @Nickrocky — macOS testing and feedback

License

MIT License — see LICENSE for details.


GoGPU — Building the GPU computing ecosystem Go deserves

About

Pure Go Graphics Framework — GPU power, Go simplicity

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.5%
  • Shell 1.5%