Skip to content

Repository files navigation

gputypes

WebGPU type definitions for the gogpu ecosystem.

Overview

gputypes provides all WebGPU enums, structs, and constants as pure Go types with zero dependencies. It serves as the single source of truth for WebGPU types across the entire ecosystem.

Installation

go get github.com/gogpu/gputypes

Requires: Go 1.25+

Why gputypes?

The Problem: Type Incompatibility

Without a shared types package, each project defines its own types:

// Different projects, incompatible types!wgpu.TextureFormat// wgpu's typewebgpu.TextureFormat// go-webgpu's typeborn.TextureFormat// born-ml's type// User must convert everywhere - painful!format:=wgpu.TextureFormat(webgpuFormat)

The Solution: Shared Types

With gputypes, all projects use the same types:

import"github.com/gogpu/gputypes"// All projects use gputypes.TextureFormat// Types are directly compatible - no conversion needed!

Architecture

 gputypes (ZERO deps)
All WebGPU types (100+)
│
┌─────────────────┼─────────────────┐
│ │ │
▼ ▼ ▼
gpucontext wgpu go-webgpu/webgpu
(imports gputypes) (imports) (imports)
│ │ │
└────────┬────────┴────────┬────────┘
│ │
▼ ▼
gogpu born-ml

Types

Based on WebGPU spec and wgpu-types:

Texture & Sampler

  • TextureFormat (97 formats including BC, ETC2, ASTC compressed)
  • TextureUsage, TextureDimension, TextureViewDimension, TextureAspect
  • TextureDescriptor, TextureViewDescriptor, TextureSampleType
  • AddressMode, FilterMode, MipmapFilterMode, CompareFunction
  • SamplerDescriptor, SamplerBindingType

Buffer & Binding

  • BufferUsage, BufferBindingType, BufferMapState, MapMode
  • BufferDescriptor, IndexFormat
  • BindGroupLayoutEntry, BindGroupEntry, BindingResource
  • BufferBindingLayout, SamplerBindingLayout, TextureBindingLayout
  • StorageTextureBindingLayout, PipelineLayoutDescriptor

Shader

  • ShaderStage flags (Vertex, Fragment, Compute)
  • ShaderModuleDescriptor, ShaderSource (WGSL, SPIR-V, GLSL)
  • ProgrammableStage

Pipeline

  • PrimitiveTopology, FrontFace, CullMode, PrimitiveState — zero value of each enum is the WebGPU spec default (TriangleList, CCW, None), so PrimitiveState{} is a valid spec-default configuration
  • BlendState, BlendFactor, BlendOperation, BlendComponent
  • DepthStencilState, StencilOperation, StencilFaceState
  • MultisampleState, ColorTargetState, ColorWriteMask

Vertex

  • VertexFormat (31 formats)
  • VertexStepMode, VertexAttribute, VertexBufferLayout
  • VertexState, FragmentState

Render Pass

  • LoadOp, StoreOp
  • RenderPassColorAttachment, RenderPassDepthStencilAttachment
  • RenderPassDescriptor

Adapter & Device

  • DeviceType, Backend, Backends
  • AdapterInfo, PowerPreference, MemoryHints
  • DeviceDescriptor, RequestAdapterOptions
  • InstanceDescriptor, InstanceFlags
  • Dx12ShaderCompiler, GLBackend

Limits & Features

  • Limits struct with all WebGPU limits (30+ fields)
  • Features flags (20 optional capabilities)
  • DefaultLimits(), DownlevelLimits() helpers

Surface

  • PresentMode (AutoVsync, Fifo, Immediate, Mailbox)
  • CompositeAlphaMode (Auto, Opaque, PreMultiplied, etc.)
  • SurfaceConfiguration, SurfaceCapabilities, SurfaceStatus

Copy Operations

  • ImageSubresourceRange (for partial texture operations)
  • TextureDataLayout, ImageCopyTexture

Geometry & Color

  • Extent3D, Origin3D
  • Color (RGBA float64) with predefined colors

Relationship to gpucontext

PackagePurposeDependencies
gputypesData types (enums, structs, constants)ZERO
gpucontextInterfaces (DeviceProvider, EventSource, Texture)imports gputypes

Why Two Packages?

Aspectgputypesgpucontext
ResponsibilityData definitionsBehavioral contracts
Change frequencyRare (WebGPU spec is stable)Medium (API evolution)
SizeLarge (100+ types)Small (10-15 interfaces)

Principle: Separation of data types from behavioral interfaces.

Why gpucontext imports gputypes?

Interfaces need types in their signatures:

// gpucontext needs gputypes for type-safe interfacestypeDeviceProviderinterface {
SurfaceFormat() gputypes.TextureFormat// ← uses gputypes
}
typeTextureinterface {
Format() gputypes.TextureFormat// ← uses gputypes
}

This ensures type compatibility across all implementations.

Ecosystem

PackageDescriptionUses gputypes
gogpu/gogpuGraphics framework
gogpu/wgpuPure Go WebGPU
gogpu/gg2D graphics library✅ (via gpucontext)
gogpu/gpucontextShared interfaces✅ (imports)
go-webgpu/webgpuRust FFI bindings
born-ml/bornML framework

Comparison with Rust

RustGo (gogpu)Purpose
wgpu-typesgputypesWebGPU type definitions
gpucontextIntegration interfaces (Go-specific)
wgpu-corewgpu/coreWebGPU implementation
wgpu-halwgpu/halHardware abstraction

Status

See CHANGELOG.md for version history and ROADMAP.md for upcoming plans.

License

MIT License — see LICENSE for details.


Part of the gogpu ecosystem — Pure Go GPU Computing.

About

WebGPU type definitions for the gogpu ecosystem

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

6 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages