gpu

package
v0.0.0-...-7d0a1c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gpu is Hover's own small binding to wgpu-native v29: the calls the office renderer and the notch spike need, and nothing else. go-webgpu was dropped for it (its v0.5.5 structs no longer matched wgpu-native v29, see docs/development/go-port.md).

Every C struct is in wire.go, and wire_test.go checks their sizes, offsets and the enum numbers against what the C compiler gave for wgpu-native's own webgpu.h. The public API takes Go values; each call builds its wire structs, pins them (so the GC can neither move nor free what the C side reads) and unpins them when the call returns.

Windows calls wgpu_native.dll through syscall (no C compiler). Linux and macOS go through purego (no C compiler either; the Linux app has one for Gio, and purego works with it).

ponytail: only what the office and the spike draw with. A new call is one method here and, if it takes a struct, one wire struct and one line in wire_test.go.

Index

Constants

View Source
const (
	FormatRGBA8Unorm     TextureFormat = 0x16
	FormatRGBA8UnormSrgb TextureFormat = 0x17
	FormatRGBA16Float    TextureFormat = 0x28
	FormatDepth32Float   TextureFormat = 0x30

	TextureCopySrc        TextureUsage = 0x1
	TextureCopyDst        TextureUsage = 0x2
	TextureBinding        TextureUsage = 0x4
	TextureRenderAttachmt TextureUsage = 0x10

	BufferMapRead BufferUsage = 0x1
	BufferCopySrc BufferUsage = 0x4
	BufferCopyDst BufferUsage = 0x8
	BufferIndex   BufferUsage = 0x10
	BufferVertex  BufferUsage = 0x20
	BufferUniform BufferUsage = 0x40

	StageVertex   ShaderStage = 0x1
	StageFragment ShaderStage = 0x2

	SampleFloat SampleType = 2
	SampleDepth SampleType = 4

	IndexUint32 IndexFormat = 2

	VertexFloat32x2 VertexFormat = 0x1d
	VertexFloat32x3 VertexFormat = 0x1e

	PointList    Topology = 1
	TriangleList Topology = 4

	FrontCCW FrontFace = 1

	CullNone  CullMode = 1
	CullFront CullMode = 2
	CullBack  CullMode = 3

	CompareLessEqual Compare = 4

	BlendAdd BlendOp = 1

	FactorOne              BlendFactor = 2
	FactorSrcAlpha         BlendFactor = 5
	FactorOneMinusSrcAlpha BlendFactor = 6

	FilterNearest FilterMode = 1
	FilterLinear  FilterMode = 2

	ClampToEdge AddressMode = 1

	BackendD3D12    BackendType = 4
	BackendMetal    BackendType = 5
	BackendVulkan   BackendType = 6
	BackendOpenGL   BackendType = 7
	BackendOpenGLES BackendType = 8
	AdapterCPU      AdapterType = 3
)

Variables

This section is empty.

Functions

func Init

func Init() error

Init loads wgpu-native (wgpu_native.dll beside the exe or at WGPU_NATIVE_PATH on Windows, libwgpu_native.so / .dylib elsewhere) and makes the callbacks. Later calls return the first result.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

func (Adapter) Info

func (a Adapter) Info() AdapterInfo

ponytail: the info's strings are wgpu-native's and are not freed (a few bytes, once per adapter): wgpuAdapterInfoFreeMembers takes the 96-byte struct by value.

func (Adapter) Release

func (x Adapter) Release()

type AdapterInfo

type AdapterInfo struct {
	Name    string
	Backend BackendType
	Type    AdapterType
}

AdapterInfo is what the office logs and what decides software rendering.

func (AdapterInfo) String

func (i AdapterInfo) String() string

type AdapterType

type AdapterType uint32

type AddressMode

type AddressMode uint32

type BackendType

type BackendType uint32

type BindGroup

type BindGroup struct {
	// contains filtered or unexported fields
}

func (BindGroup) Release

func (x BindGroup) Release()

type BindGroupLayout

type BindGroupLayout struct {
	// contains filtered or unexported fields
}

func (BindGroupLayout) Release

func (x BindGroupLayout) Release()

type Blend

type Blend struct{ Color, Alpha BlendComponent }

type BlendComponent

type BlendComponent struct {
	Op       BlendOp
	Src, Dst BlendFactor
}

type BlendFactor

type BlendFactor uint32

type BlendOp

type BlendOp uint32

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func (Buffer) MapRead

func (b Buffer) MapRead(d *Device, size uint64) error

MapRead maps size bytes of a MAP_READ buffer and waits for it. The bytes are Mapped's until Unmap.

func (Buffer) Mapped

func (b Buffer) Mapped(size uint64) []byte

Mapped is the mapped bytes. They are wgpu-native's and are gone after Unmap.

func (Buffer) Release

func (x Buffer) Release()

func (Buffer) Unmap

func (b Buffer) Unmap()

type BufferUsage

type BufferUsage uint64

type Color

type Color struct{ R, G, B, A float64 }

type ColorAttachment

type ColorAttachment struct {
	View  TextureView
	Clear Color
}

ColorAttachment is cleared to Clear and stored.

type CommandBuffer

type CommandBuffer struct {
	// contains filtered or unexported fields
}

func (CommandBuffer) Release

func (x CommandBuffer) Release()

type CommandEncoder

type CommandEncoder struct {
	// contains filtered or unexported fields
}

func (CommandEncoder) CopyTextureToBuffer

func (e CommandEncoder) CopyTextureToBuffer(t Texture, b Buffer, bytesPerRow, w, h uint32)

CopyTextureToBuffer copies a whole w x h texture into a buffer, rows bytesPerRow apart (a multiple of 256).

func (CommandEncoder) Finish

func (e CommandEncoder) Finish() CommandBuffer

Finish ends the encoder (and releases it) and returns its commands.

func (CommandEncoder) Release

func (x CommandEncoder) Release()

func (CommandEncoder) RenderPass

func (e CommandEncoder) RenderPass(label string, color *ColorAttachment, depth *DepthAttachment) RenderPass

RenderPass begins a pass. Color may be nil: a depth-only pass (the shadow map).

type Compare

type Compare uint32

type CullMode

type CullMode uint32

type DepthAttachment

type DepthAttachment struct {
	View  TextureView
	Clear float32
}

DepthAttachment is cleared to Clear and stored.

type DepthState

type DepthState struct {
	Format  TextureFormat
	Write   bool
	Compare Compare
}

type Device

type Device struct {
	Queue Queue
	// contains filtered or unexported fields
}

Device is a device, its queue and the id its error callbacks report under.

func (*Device) BindGroup

func (d *Device) BindGroup(layout BindGroupLayout, entries ...GroupEntry) BindGroup

func (*Device) BindGroupLayout

func (d *Device) BindGroupLayout(entries ...LayoutEntry) BindGroupLayout

func (*Device) Buffer

func (d *Device) Buffer(usage BufferUsage, size uint64) Buffer

func (*Device) BufferWith

func (d *Device) BufferWith(usage BufferUsage, data []byte) Buffer

BufferWith makes a buffer holding data (COPY_DST is added to its usage). Its size is rounded up to 4 bytes, as a buffer write needs.

func (*Device) CheckShader

func (d *Device) CheckShader(inst Instance, label, wgsl string) string

CheckShader compiles WGSL inside a validation error scope and returns wgpu's message, or "" when it compiled.

func (*Device) Encoder

func (d *Device) Encoder() CommandEncoder

func (*Device) Errors

func (d *Device) Errors() []string

Errors returns and forgets the errors the device reported outside an error scope (a validation error, a lost device), oldest first.

func (*Device) PipelineLayout

func (d *Device) PipelineLayout(layouts ...BindGroupLayout) PipelineLayout

func (*Device) Poll

func (d *Device) Poll(wait bool)

Poll waits for the queue's work (wait) or only collects what has finished; map callbacks fire in it.

func (*Device) Release

func (d *Device) Release()

func (*Device) RenderPipeline

func (d *Device) RenderPipeline(p PipelineDesc) RenderPipeline

func (*Device) Sampler

func (d *Device) Sampler(s SamplerDesc) Sampler

func (*Device) ShaderModule

func (d *Device) ShaderModule(label, wgsl string) ShaderModule

func (*Device) Texture

func (d *Device) Texture(t TextureDesc) Texture

type FilterMode

type FilterMode uint32

type FrontFace

type FrontFace uint32

type GroupEntry

type GroupEntry struct {
	Binding uint32
	Buffer  Buffer
	Offset  uint64
	// Size 0 is the whole buffer.
	Size    uint64
	Sampler Sampler
	View    TextureView
}

GroupEntry is one resource of a bind group: a buffer range, a sampler or a view.

type IndexFormat

type IndexFormat uint32

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

func CreateInstance

func CreateInstance() (Instance, error)

CreateInstance makes an instance. On Windows it asks for DX12 only: a device on its own also woke Vulkan and OpenGL on every graphics card (the Rust office's note), and DX12 is what WARP, the runner's CPU adapter, speaks.

func (Instance) Release

func (x Instance) Release()

func (Instance) RequestAdapter

func (inst Instance) RequestAdapter(fallback bool) (Adapter, error)

RequestAdapter asks for a low-power adapter; fallback asks for the CPU one (WARP on Windows, llvmpipe on Linux).

func (Instance) RequestDevice

func (inst Instance) RequestDevice(a Adapter, label string) (*Device, error)

type LayoutEntry

type LayoutEntry struct {
	Binding    uint32
	Visibility ShaderStage
	// Uniform: a uniform buffer; Dynamic: it takes a dynamic offset; MinSize: 0 for any.
	Uniform bool
	Dynamic bool
	MinSize uint64
	Sampler bool
	// Texture: its sample type (SampleFloat, SampleDepth), 0 for none.
	Texture SampleType
}

LayoutEntry is one binding of a bind group layout: a uniform buffer, a filtering sampler or a 2D texture.

type PipelineDesc

type PipelineDesc struct {
	Label    string
	Layout   PipelineLayout
	Module   ShaderModule
	VS, FS   string
	Buffers  []VertexLayout
	Targets  []Target
	Topology Topology
	Front    FrontFace
	Cull     CullMode
	Depth    *DepthState
}

PipelineDesc describes a render pipeline. A zero Layout is the automatic one; an empty FS is no fragment stage (a depth-only pass).

type PipelineLayout

type PipelineLayout struct {
	// contains filtered or unexported fields
}

func (PipelineLayout) Release

func (x PipelineLayout) Release()

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func (Queue) Submit

func (q Queue) Submit(cmds ...CommandBuffer)

Submit sends the commands and releases them: a submitted command buffer can't be used again, and one never released keeps its device alive (wgpu-core holds the device in it), so a dropped office kept its whole device, about 350 MB a time on an NVIDIA card.

func (Queue) WriteBuffer

func (q Queue) WriteBuffer(b Buffer, offset uint64, data []byte)

func (Queue) WriteTexture

func (q Queue) WriteTexture(t Texture, data []byte, bytesPerRow, w, h uint32)

WriteTexture fills a whole w x h texture from tightly packed rows (bytesPerRow apart).

type RenderPass

type RenderPass struct {
	// contains filtered or unexported fields
}

func (RenderPass) Draw

func (p RenderPass) Draw(vertices, instances, firstVertex, firstInstance uint32)

func (RenderPass) DrawIndexed

func (p RenderPass) DrawIndexed(indices, instances, firstIndex uint32, baseVertex int32, firstInstance uint32)

func (RenderPass) End

func (p RenderPass) End()

End ends the pass and releases it.

func (RenderPass) SetBindGroup

func (p RenderPass) SetBindGroup(index uint32, g BindGroup, offsets ...uint32)

func (RenderPass) SetIndexBuffer

func (p RenderPass) SetIndexBuffer(b Buffer, f IndexFormat)

func (RenderPass) SetPipeline

func (p RenderPass) SetPipeline(pl RenderPipeline)

func (RenderPass) SetVertexBuffer

func (p RenderPass) SetVertexBuffer(slot uint32, b Buffer)

type RenderPipeline

type RenderPipeline struct {
	// contains filtered or unexported fields
}

func (RenderPipeline) Release

func (x RenderPipeline) Release()

type SampleType

type SampleType uint32

type Sampler

type Sampler struct {
	// contains filtered or unexported fields
}

func (Sampler) Release

func (x Sampler) Release()

type SamplerDesc

type SamplerDesc struct {
	Mag, Min FilterMode
	AddressU AddressMode
	AddressV AddressMode
}

type ShaderModule

type ShaderModule struct {
	// contains filtered or unexported fields
}

func (ShaderModule) Release

func (x ShaderModule) Release()

type ShaderStage

type ShaderStage uint64

type Target

type Target struct {
	Format TextureFormat
	// Blend nil writes the colour as it is.
	Blend *Blend
}

type Texture

type Texture struct {
	// contains filtered or unexported fields
}

func (Texture) Release

func (x Texture) Release()

func (Texture) View

func (t Texture) View() TextureView

View is the texture's default view.

type TextureDesc

type TextureDesc struct {
	Label  string
	W, H   uint32
	Format TextureFormat
	Usage  TextureUsage
}

type TextureFormat

type TextureFormat uint32

type TextureUsage

type TextureUsage uint64

type TextureView

type TextureView struct {
	// contains filtered or unexported fields
}

func (TextureView) Release

func (x TextureView) Release()

type Topology

type Topology uint32

type VertexAttr

type VertexAttr struct {
	Format   VertexFormat
	Offset   uint64
	Location uint32
}

type VertexFormat

type VertexFormat uint32

type VertexLayout

type VertexLayout struct {
	Stride uint64
	Attrs  []VertexAttr
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL