Documentation
¶
Overview ¶
Package wgpu provides a safe, ergonomic WebGPU API for Go applications.
This package wraps the lower-level hal/ and core/ packages into a user-friendly API aligned with the W3C WebGPU specification.
Quick Start ¶
Import this package and a backend registration package:
import (
"github.com/gogpu/wgpu"
_ "github.com/gogpu/wgpu/hal/allbackends"
)
instance, err := wgpu.CreateInstance(nil)
// ...
Resource Lifecycle ¶
All GPU resources must be explicitly released with Release(). Resources are reference-counted internally. Using a released resource panics.
Backend Registration ¶
Backends are registered via blank imports:
_ "github.com/gogpu/wgpu/hal/allbackends" // all available backends _ "github.com/gogpu/wgpu/hal/vulkan" // Vulkan only _ "github.com/gogpu/wgpu/hal/noop" // testing
Thread Safety ¶
Instance, Adapter, and Device are safe for concurrent use. Encoders (CommandEncoder, RenderPassEncoder, ComputePassEncoder) are NOT thread-safe.
Index ¶
- Constants
- Variables
- func Logger() *slog.Logger
- func SetLogger(l *slog.Logger)
- type Adapter
- type AdapterInfo
- type AddressMode
- type Backend
- type Backends
- type BindGroup
- type BindGroupDescriptor
- type BindGroupEntry
- type BindGroupLayout
- type BindGroupLayoutDescriptor
- type BindGroupLayoutEntry
- type Buffer
- type BufferDescriptor
- type BufferTextureCopy
- type BufferUsage
- type Color
- type ColorTargetState
- type CommandBuffer
- type CommandEncoder
- func (e *CommandEncoder) BeginComputePass(desc *ComputePassDescriptor) (*ComputePassEncoder, error)
- func (e *CommandEncoder) BeginRenderPass(desc *RenderPassDescriptor) (*RenderPassEncoder, error)
- func (e *CommandEncoder) CopyBufferToBuffer(src *Buffer, srcOffset uint64, dst *Buffer, dstOffset uint64, size uint64)
- func (e *CommandEncoder) CopyTextureToBuffer(src *Texture, dst *Buffer, regions []BufferTextureCopy)
- func (e *CommandEncoder) DiscardEncoding()
- func (e *CommandEncoder) Finish() (*CommandBuffer, error)
- func (e *CommandEncoder) TransitionTextures(barriers []TextureBarrier)
- type CommandEncoderDescriptor
- type CompareFunction
- type CompositeAlphaMode
- type ComputePassDescriptor
- type ComputePassEncoder
- func (p *ComputePassEncoder) Dispatch(x, y, z uint32)
- func (p *ComputePassEncoder) DispatchIndirect(buffer *Buffer, offset uint64)
- func (p *ComputePassEncoder) End() error
- func (p *ComputePassEncoder) SetBindGroup(index uint32, group *BindGroup, offsets []uint32)
- func (p *ComputePassEncoder) SetPipeline(pipeline *ComputePipeline)
- type ComputePipeline
- type ComputePipelineDescriptor
- type CullMode
- type DepthStencilState
- type Device
- func (d *Device) CreateBindGroup(desc *BindGroupDescriptor) (*BindGroup, error)
- func (d *Device) CreateBindGroupLayout(desc *BindGroupLayoutDescriptor) (*BindGroupLayout, error)
- func (d *Device) CreateBuffer(desc *BufferDescriptor) (*Buffer, error)
- func (d *Device) CreateCommandEncoder(desc *CommandEncoderDescriptor) (*CommandEncoder, error)
- func (d *Device) CreateComputePipeline(desc *ComputePipelineDescriptor) (*ComputePipeline, error)
- func (d *Device) CreateFence() (*Fence, error)
- func (d *Device) CreatePipelineLayout(desc *PipelineLayoutDescriptor) (*PipelineLayout, error)
- func (d *Device) CreateRenderPipeline(desc *RenderPipelineDescriptor) (*RenderPipeline, error)
- func (d *Device) CreateSampler(desc *SamplerDescriptor) (*Sampler, error)
- func (d *Device) CreateShaderModule(desc *ShaderModuleDescriptor) (*ShaderModule, error)
- func (d *Device) CreateTexture(desc *TextureDescriptor) (*Texture, error)
- func (d *Device) CreateTextureView(texture *Texture, desc *TextureViewDescriptor) (*TextureView, error)
- func (d *Device) DestroyFence(f *Fence)deprecated
- func (d *Device) Features() Features
- func (d *Device) FreeCommandBuffer(cb *CommandBuffer)
- func (d *Device) GetFenceStatus(f *Fence) (bool, error)
- func (d *Device) HalDevice() hal.Device
- func (d *Device) HalQueue() hal.Queue
- func (d *Device) Limits() Limits
- func (d *Device) PopErrorScope() *GPUError
- func (d *Device) PushErrorScope(filter ErrorFilter)
- func (d *Device) Queue() *Queue
- func (d *Device) Release()
- func (d *Device) ResetFence(f *Fence) error
- func (d *Device) WaitForFence(f *Fence, value uint64, timeout time.Duration) (bool, error)
- func (d *Device) WaitIdle() error
- type DeviceDescriptor
- type DeviceType
- type ErrorFilter
- type Extent3D
- type Features
- type Fence
- type FilterMode
- type FragmentState
- type FrontFace
- type GPUError
- type ImageCopyTexture
- type ImageDataLayout
- type IndexFormat
- type Instance
- type InstanceDescriptor
- type Limits
- type LoadOp
- type MultisampleState
- type Origin3D
- type PipelineLayout
- type PipelineLayoutDescriptor
- type PowerPreference
- type PresentMode
- type PrimitiveState
- type PrimitiveTopology
- type Queue
- func (q *Queue) ReadBuffer(buffer *Buffer, offset uint64, data []byte) error
- func (q *Queue) Submit(commandBuffers ...*CommandBuffer) error
- func (q *Queue) SubmitWithFence(commandBuffers []*CommandBuffer, fence *Fence, submissionIndex uint64) error
- func (q *Queue) WriteBuffer(buffer *Buffer, offset uint64, data []byte) error
- func (q *Queue) WriteTexture(dst *ImageCopyTexture, data []byte, layout *ImageDataLayout, size *Extent3D) error
- type RenderPassColorAttachment
- type RenderPassDepthStencilAttachment
- type RenderPassDescriptor
- type RenderPassEncoder
- func (p *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
- func (p *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, ...)
- func (p *RenderPassEncoder) DrawIndexedIndirect(buffer *Buffer, offset uint64)
- func (p *RenderPassEncoder) DrawIndirect(buffer *Buffer, offset uint64)
- func (p *RenderPassEncoder) End() error
- func (p *RenderPassEncoder) SetBindGroup(index uint32, group *BindGroup, offsets []uint32)
- func (p *RenderPassEncoder) SetBlendConstant(color *Color)
- func (p *RenderPassEncoder) SetIndexBuffer(buffer *Buffer, format IndexFormat, offset uint64)
- func (p *RenderPassEncoder) SetPipeline(pipeline *RenderPipeline)
- func (p *RenderPassEncoder) SetScissorRect(x, y, width, height uint32)
- func (p *RenderPassEncoder) SetStencilReference(reference uint32)
- func (p *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer *Buffer, offset uint64)
- func (p *RenderPassEncoder) SetViewport(x, y, width, height, minDepth, maxDepth float32)
- type RenderPipeline
- type RenderPipelineDescriptor
- type RequestAdapterOptions
- type Sampler
- type SamplerDescriptor
- type ShaderModule
- type ShaderModuleDescriptor
- type ShaderStages
- type StencilFaceState
- type StencilOperation
- type StoreOp
- type Surface
- func (s *Surface) Configure(device *Device, config *SurfaceConfiguration) error
- func (s *Surface) DiscardTexture()
- func (s *Surface) GetCurrentTexture() (*SurfaceTexture, bool, error)
- func (s *Surface) HAL() hal.Surface
- func (s *Surface) Present(texture *SurfaceTexture) error
- func (s *Surface) Release()
- func (s *Surface) SetPrepareFrame(fn core.PrepareFrameFunc)
- func (s *Surface) Unconfigure()
- type SurfaceConfiguration
- type SurfaceTexture
- type Texture
- type TextureAspect
- type TextureBarrier
- type TextureDescriptor
- type TextureDimension
- type TextureFormat
- type TextureRange
- type TextureUsage
- type TextureUsageTransition
- type TextureView
- type TextureViewDescriptor
- type TextureViewDimension
- type VertexBufferLayout
- type VertexState
Constants ¶
const ( StencilOperationKeep = hal.StencilOperationKeep StencilOperationZero = hal.StencilOperationZero StencilOperationReplace = hal.StencilOperationReplace StencilOperationInvert = hal.StencilOperationInvert StencilOperationIncrementClamp = hal.StencilOperationIncrementClamp StencilOperationDecrementClamp = hal.StencilOperationDecrementClamp StencilOperationIncrementWrap = hal.StencilOperationIncrementWrap StencilOperationDecrementWrap = hal.StencilOperationDecrementWrap )
Stencil operation constants.
const ( ErrorFilterValidation = core.ErrorFilterValidation ErrorFilterOutOfMemory = core.ErrorFilterOutOfMemory ErrorFilterInternal = core.ErrorFilterInternal )
const ( BackendVulkan = gputypes.BackendVulkan BackendMetal = gputypes.BackendMetal BackendDX12 = gputypes.BackendDX12 BackendGL = gputypes.BackendGL )
Backend constants
const ( BackendsAll = gputypes.BackendsAll BackendsPrimary = gputypes.BackendsPrimary BackendsVulkan = gputypes.BackendsVulkan BackendsMetal = gputypes.BackendsMetal BackendsDX12 = gputypes.BackendsDX12 BackendsGL = gputypes.BackendsGL )
Backends masks
const ( BufferUsageMapRead = gputypes.BufferUsageMapRead BufferUsageMapWrite = gputypes.BufferUsageMapWrite BufferUsageCopySrc = gputypes.BufferUsageCopySrc BufferUsageCopyDst = gputypes.BufferUsageCopyDst BufferUsageIndex = gputypes.BufferUsageIndex BufferUsageVertex = gputypes.BufferUsageVertex BufferUsageUniform = gputypes.BufferUsageUniform BufferUsageStorage = gputypes.BufferUsageStorage BufferUsageIndirect = gputypes.BufferUsageIndirect BufferUsageQueryResolve = gputypes.BufferUsageQueryResolve )
const ( TextureUsageCopySrc = gputypes.TextureUsageCopySrc TextureUsageCopyDst = gputypes.TextureUsageCopyDst TextureUsageTextureBinding = gputypes.TextureUsageTextureBinding TextureUsageStorageBinding = gputypes.TextureUsageStorageBinding TextureUsageRenderAttachment = gputypes.TextureUsageRenderAttachment )
const ( TextureDimension1D = gputypes.TextureDimension1D TextureDimension2D = gputypes.TextureDimension2D TextureDimension3D = gputypes.TextureDimension3D )
Texture dimension constants
const ( TextureFormatRGBA8Unorm = gputypes.TextureFormatRGBA8Unorm TextureFormatRGBA8UnormSrgb = gputypes.TextureFormatRGBA8UnormSrgb TextureFormatBGRA8Unorm = gputypes.TextureFormatBGRA8Unorm TextureFormatBGRA8UnormSrgb = gputypes.TextureFormatBGRA8UnormSrgb TextureFormatDepth24Plus = gputypes.TextureFormatDepth24Plus TextureFormatDepth32Float = gputypes.TextureFormatDepth32Float )
Commonly used texture format constants
const ( ShaderStageVertex = gputypes.ShaderStageVertex ShaderStageFragment = gputypes.ShaderStageFragment ShaderStageCompute = gputypes.ShaderStageCompute )
const ( PresentModeImmediate = gputypes.PresentModeImmediate PresentModeMailbox = gputypes.PresentModeMailbox PresentModeFifo = gputypes.PresentModeFifo PresentModeFifoRelaxed = gputypes.PresentModeFifoRelaxed )
const ( PowerPreferenceNone = gputypes.PowerPreferenceNone PowerPreferenceLowPower = gputypes.PowerPreferenceLowPower PowerPreferenceHighPerformance = gputypes.PowerPreferenceHighPerformance )
const MaxBindGroups = 8
MaxBindGroups is the maximum number of bind groups allowed by the WebGPU spec. This is the hard cap (wgpu-hal MAX_BIND_GROUPS = 8). Actual device limits may be lower (typically 4 in the WebGPU spec).
Variables ¶
var ( ErrDeviceLost = hal.ErrDeviceLost ErrOutOfMemory = hal.ErrDeviceOutOfMemory ErrSurfaceLost = hal.ErrSurfaceLost ErrSurfaceOutdated = hal.ErrSurfaceOutdated ErrTimeout = hal.ErrTimeout )
Sentinel errors re-exported from HAL.
var ( // ErrReleased is returned when operating on a released resource. ErrReleased = errors.New("wgpu: resource already released") // ErrNoAdapters is returned when no GPU adapters are found. ErrNoAdapters = errors.New("wgpu: no GPU adapters available") // ErrNoBackends is returned when no backends are registered. ErrNoBackends = errors.New("wgpu: no backends registered (import a backend package)") )
Public API sentinel errors.
var ( DefaultLimits = gputypes.DefaultLimits DefaultInstanceDescriptor = gputypes.DefaultInstanceDescriptor )
Default functions (re-exported for convenience)
Functions ¶
func SetLogger ¶ added in v0.21.0
SetLogger configures the logger for the entire wgpu stack (public API, core validation layer, and HAL backends: Vulkan, Metal, DX12, GLES).
By default, wgpu produces no log output. Call SetLogger to enable logging for deep debugging across the full GPU pipeline.
SetLogger is safe for concurrent use. Pass nil to disable logging (restore default silent behavior).
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter represents a physical GPU.
func (*Adapter) RequestDevice ¶
func (a *Adapter) RequestDevice(desc *DeviceDescriptor) (*Device, error)
RequestDevice creates a logical device from this adapter. If desc is nil, default features and limits are used.
type BindGroup ¶
type BindGroup struct {
// contains filtered or unexported fields
}
BindGroup represents bound GPU resources for shader access.
type BindGroupDescriptor ¶
type BindGroupDescriptor struct {
Label string
Layout *BindGroupLayout
Entries []BindGroupEntry
}
BindGroupDescriptor describes a bind group.
type BindGroupEntry ¶
type BindGroupEntry struct {
Binding uint32
Buffer *Buffer // For buffer bindings
Offset uint64 // Buffer offset
Size uint64 // Buffer binding size (0 = rest of buffer)
Sampler *Sampler // For sampler bindings
TextureView *TextureView // For texture bindings
}
BindGroupEntry describes a single resource binding in a bind group. Exactly one of Buffer, Sampler, or TextureView must be set.
type BindGroupLayout ¶
type BindGroupLayout struct {
// contains filtered or unexported fields
}
BindGroupLayout defines the structure of resource bindings for shaders.
func (*BindGroupLayout) Release ¶
func (l *BindGroupLayout) Release()
Release destroys the bind group layout.
type BindGroupLayoutDescriptor ¶
type BindGroupLayoutDescriptor struct {
Label string
Entries []BindGroupLayoutEntry
}
BindGroupLayoutDescriptor describes a bind group layout.
type BindGroupLayoutEntry ¶
type BindGroupLayoutEntry = gputypes.BindGroupLayoutEntry
Bind group types
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer represents a GPU buffer.
type BufferDescriptor ¶
type BufferDescriptor struct {
Label string
Size uint64
Usage BufferUsage
MappedAtCreation bool
}
BufferDescriptor describes buffer creation parameters.
type BufferTextureCopy ¶ added in v0.21.0
type BufferTextureCopy struct {
BufferLayout ImageDataLayout
TextureBase ImageCopyTexture
Size Extent3D
}
BufferTextureCopy defines a buffer-texture copy region.
type ColorTargetState ¶
type ColorTargetState = gputypes.ColorTargetState
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
CommandBuffer holds recorded GPU commands ready for submission. Created by CommandEncoder.Finish().
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
CommandEncoder records GPU commands for later submission.
A command encoder is single-use. After calling Finish(), the encoder cannot be used again. Call Device.CreateCommandEncoder() to create a new one.
NOT thread-safe - do not use from multiple goroutines.
func (*CommandEncoder) BeginComputePass ¶
func (e *CommandEncoder) BeginComputePass(desc *ComputePassDescriptor) (*ComputePassEncoder, error)
BeginComputePass begins a compute pass. The returned ComputePassEncoder records dispatch commands. Call ComputePassEncoder.End() when done.
func (*CommandEncoder) BeginRenderPass ¶
func (e *CommandEncoder) BeginRenderPass(desc *RenderPassDescriptor) (*RenderPassEncoder, error)
BeginRenderPass begins a render pass. The returned RenderPassEncoder records draw commands. Call RenderPassEncoder.End() when done.
func (*CommandEncoder) CopyBufferToBuffer ¶
func (e *CommandEncoder) CopyBufferToBuffer(src *Buffer, srcOffset uint64, dst *Buffer, dstOffset uint64, size uint64)
CopyBufferToBuffer copies data between buffers.
func (*CommandEncoder) CopyTextureToBuffer ¶ added in v0.21.0
func (e *CommandEncoder) CopyTextureToBuffer(src *Texture, dst *Buffer, regions []BufferTextureCopy)
CopyTextureToBuffer copies data from a texture to a buffer. This is used for GPU-to-CPU readback of rendered content.
func (*CommandEncoder) DiscardEncoding ¶ added in v0.21.0
func (e *CommandEncoder) DiscardEncoding()
DiscardEncoding discards the encoder without producing a command buffer. Use this to abandon an in-progress encoding when an error occurs.
func (*CommandEncoder) Finish ¶
func (e *CommandEncoder) Finish() (*CommandBuffer, error)
Finish completes command recording and returns a CommandBuffer. After calling Finish(), the encoder cannot be used again.
func (*CommandEncoder) TransitionTextures ¶ added in v0.21.0
func (e *CommandEncoder) TransitionTextures(barriers []TextureBarrier)
TransitionTextures transitions texture states for synchronization. This is needed on Vulkan for layout transitions between render pass and copy operations (e.g., after MSAA resolve before CopyTextureToBuffer). On Metal, GLES, and software backends this is a no-op.
type CommandEncoderDescriptor ¶
type CommandEncoderDescriptor struct {
Label string
}
CommandEncoderDescriptor describes command encoder creation.
type CompareFunction ¶
type CompareFunction = gputypes.CompareFunction
type CompositeAlphaMode ¶
type CompositeAlphaMode = gputypes.CompositeAlphaMode
type ComputePassDescriptor ¶
type ComputePassDescriptor struct {
Label string
}
ComputePassDescriptor describes a compute pass.
type ComputePassEncoder ¶
type ComputePassEncoder struct {
// contains filtered or unexported fields
}
ComputePassEncoder records compute dispatch commands.
Created by CommandEncoder.BeginComputePass(). Must be ended with End() before the CommandEncoder can be finished.
NOT thread-safe.
func (*ComputePassEncoder) Dispatch ¶
func (p *ComputePassEncoder) Dispatch(x, y, z uint32)
Dispatch dispatches compute work.
func (*ComputePassEncoder) DispatchIndirect ¶
func (p *ComputePassEncoder) DispatchIndirect(buffer *Buffer, offset uint64)
DispatchIndirect dispatches compute work with GPU-generated parameters.
func (*ComputePassEncoder) End ¶
func (p *ComputePassEncoder) End() error
End ends the compute pass.
func (*ComputePassEncoder) SetBindGroup ¶
func (p *ComputePassEncoder) SetBindGroup(index uint32, group *BindGroup, offsets []uint32)
SetBindGroup sets a bind group for the given index.
func (*ComputePassEncoder) SetPipeline ¶
func (p *ComputePassEncoder) SetPipeline(pipeline *ComputePipeline)
SetPipeline sets the active compute pipeline.
type ComputePipeline ¶
type ComputePipeline struct {
// contains filtered or unexported fields
}
ComputePipeline represents a configured compute pipeline.
func (*ComputePipeline) Release ¶
func (p *ComputePipeline) Release()
Release destroys the compute pipeline.
type ComputePipelineDescriptor ¶
type ComputePipelineDescriptor struct {
Label string
Layout *PipelineLayout
Module *ShaderModule
EntryPoint string
}
ComputePipelineDescriptor describes a compute pipeline.
type DepthStencilState ¶
type DepthStencilState struct {
Format TextureFormat
DepthWriteEnabled bool
DepthCompare CompareFunction
StencilFront StencilFaceState
StencilBack StencilFaceState
StencilReadMask uint32
StencilWriteMask uint32
DepthBias int32
DepthBiasSlopeScale float32
DepthBiasClamp float32
}
DepthStencilState describes depth and stencil testing configuration.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a logical GPU device. It is the main interface for creating GPU resources.
Device methods are safe for concurrent use, except Release() which must not be called concurrently with other methods.
func NewDeviceFromHAL ¶ added in v0.21.0
func NewDeviceFromHAL( halDevice hal.Device, halQueue hal.Queue, features Features, limits Limits, label string, ) (*Device, error)
NewDeviceFromHAL creates a Device wrapping existing HAL device and queue objects. This constructor is used by backends that manage their own HAL lifecycle (e.g., the Rust FFI backend via wgpu-native) and need to expose their HAL objects through the wgpu public API.
Ownership of halDevice and halQueue is transferred to the returned Device. The caller must not destroy them directly after this call.
func (*Device) CreateBindGroup ¶
func (d *Device) CreateBindGroup(desc *BindGroupDescriptor) (*BindGroup, error)
CreateBindGroup creates a bind group.
func (*Device) CreateBindGroupLayout ¶
func (d *Device) CreateBindGroupLayout(desc *BindGroupLayoutDescriptor) (*BindGroupLayout, error)
CreateBindGroupLayout creates a bind group layout.
func (*Device) CreateBuffer ¶
func (d *Device) CreateBuffer(desc *BufferDescriptor) (*Buffer, error)
CreateBuffer creates a GPU buffer.
func (*Device) CreateCommandEncoder ¶
func (d *Device) CreateCommandEncoder(desc *CommandEncoderDescriptor) (*CommandEncoder, error)
CreateCommandEncoder creates a command encoder for recording GPU commands.
func (*Device) CreateComputePipeline ¶
func (d *Device) CreateComputePipeline(desc *ComputePipelineDescriptor) (*ComputePipeline, error)
CreateComputePipeline creates a compute pipeline.
func (*Device) CreateFence ¶ added in v0.21.0
CreateFence creates a GPU synchronization fence. The returned fence can be used with Queue.SubmitWithFence to track GPU work completion without blocking.
func (*Device) CreatePipelineLayout ¶
func (d *Device) CreatePipelineLayout(desc *PipelineLayoutDescriptor) (*PipelineLayout, error)
CreatePipelineLayout creates a pipeline layout.
func (*Device) CreateRenderPipeline ¶
func (d *Device) CreateRenderPipeline(desc *RenderPipelineDescriptor) (*RenderPipeline, error)
CreateRenderPipeline creates a render pipeline.
func (*Device) CreateSampler ¶
func (d *Device) CreateSampler(desc *SamplerDescriptor) (*Sampler, error)
CreateSampler creates a texture sampler.
func (*Device) CreateShaderModule ¶
func (d *Device) CreateShaderModule(desc *ShaderModuleDescriptor) (*ShaderModule, error)
CreateShaderModule creates a shader module.
func (*Device) CreateTexture ¶
func (d *Device) CreateTexture(desc *TextureDescriptor) (*Texture, error)
CreateTexture creates a GPU texture.
func (*Device) CreateTextureView ¶
func (d *Device) CreateTextureView(texture *Texture, desc *TextureViewDescriptor) (*TextureView, error)
CreateTextureView creates a view into a texture.
func (*Device) DestroyFence
deprecated
added in
v0.21.0
func (*Device) FreeCommandBuffer ¶ added in v0.21.0
func (d *Device) FreeCommandBuffer(cb *CommandBuffer)
FreeCommandBuffer returns a command buffer to the command pool. This must be called after the GPU has finished using the command buffer. The command buffer handle becomes invalid after this call.
func (*Device) GetFenceStatus ¶ added in v0.21.0
GetFenceStatus returns true if the fence is signaled (non-blocking). This is used for polling completion without blocking.
func (*Device) HalDevice ¶ added in v0.21.0
HalDevice returns the underlying HAL device for advanced use cases. This enables interop with code that needs direct HAL access (e.g., gg GPU accelerator, DeviceProvider interfaces).
Returns nil if the device has been released or has no HAL backend.
func (*Device) HalQueue ¶ added in v0.21.0
HalQueue returns the underlying HAL queue. Returns nil if the device has been released or has no HAL backend.
func (*Device) PopErrorScope ¶
PopErrorScope pops the most recently pushed error scope. Returns the captured error, or nil if no error occurred.
func (*Device) PushErrorScope ¶
func (d *Device) PushErrorScope(filter ErrorFilter)
PushErrorScope pushes a new error scope onto the device's error scope stack.
func (*Device) Release ¶
func (d *Device) Release()
Release releases the device and all associated resources.
func (*Device) ResetFence ¶ added in v0.21.0
ResetFence resets a fence to the unsignaled state. The fence must not be in use by the GPU.
func (*Device) WaitForFence ¶ added in v0.21.0
WaitForFence waits for a fence to reach the specified value. Returns true if the fence reached the value, false if timeout expired.
type DeviceDescriptor ¶
DeviceDescriptor configures device creation.
type DeviceType ¶
type DeviceType = gputypes.DeviceType
type ErrorFilter ¶
type ErrorFilter = core.ErrorFilter
type Fence ¶ added in v0.21.0
type Fence struct {
// contains filtered or unexported fields
}
Fence is a GPU synchronization primitive. Fences allow CPU-GPU synchronization by signaling when submitted work completes.
Fences are created via Device.CreateFence and should be released via Release() when no longer needed.
type FilterMode ¶
type FilterMode = gputypes.FilterMode
type FragmentState ¶
type FragmentState struct {
Module *ShaderModule
EntryPoint string
Targets []ColorTargetState
}
FragmentState describes the fragment shader stage.
type ImageCopyTexture ¶ added in v0.19.7
type ImageCopyTexture struct {
Texture *Texture
MipLevel uint32
Origin Origin3D
Aspect TextureAspect
}
ImageCopyTexture describes a texture subresource and origin for write operations.
type ImageDataLayout ¶ added in v0.19.7
ImageDataLayout describes the layout of image data in a buffer.
type IndexFormat ¶
type IndexFormat = gputypes.IndexFormat
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is the entry point for GPU operations.
Instance methods are safe for concurrent use, except Release() which must not be called concurrently with other methods.
func CreateInstance ¶
func CreateInstance(desc *InstanceDescriptor) (*Instance, error)
CreateInstance creates a new GPU instance. If desc is nil, all available backends are used.
func (*Instance) CreateSurface ¶
CreateSurface creates a rendering surface from platform-specific handles. displayHandle and windowHandle are platform-specific:
- Windows: displayHandle=0, windowHandle=HWND
- macOS: displayHandle=0, windowHandle=NSView*
- Linux/X11: displayHandle=Display*, windowHandle=Window
- Linux/Wayland: displayHandle=wl_display*, windowHandle=wl_surface*
func (*Instance) Release ¶
func (i *Instance) Release()
Release releases the instance and all associated resources.
func (*Instance) RequestAdapter ¶
func (i *Instance) RequestAdapter(opts *RequestAdapterOptions) (*Adapter, error)
RequestAdapter requests a GPU adapter matching the options. If opts is nil, the best available adapter is returned.
type InstanceDescriptor ¶
type InstanceDescriptor struct {
Backends Backends
}
InstanceDescriptor configures instance creation.
type MultisampleState ¶
type MultisampleState = gputypes.MultisampleState
type PipelineLayout ¶
type PipelineLayout struct {
// contains filtered or unexported fields
}
PipelineLayout defines the bind group layout arrangement for a pipeline.
func (*PipelineLayout) Release ¶
func (l *PipelineLayout) Release()
Release destroys the pipeline layout.
type PipelineLayoutDescriptor ¶
type PipelineLayoutDescriptor struct {
Label string
BindGroupLayouts []*BindGroupLayout
}
PipelineLayoutDescriptor describes a pipeline layout.
type PowerPreference ¶
type PowerPreference = gputypes.PowerPreference
type PrimitiveState ¶
type PrimitiveState = gputypes.PrimitiveState
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue handles command submission and data transfers.
func (*Queue) ReadBuffer ¶
ReadBuffer reads data from a GPU buffer.
func (*Queue) Submit ¶
func (q *Queue) Submit(commandBuffers ...*CommandBuffer) error
Submit submits command buffers for execution. This is a synchronous operation - it blocks until the GPU has completed all submitted work.
func (*Queue) SubmitWithFence ¶ added in v0.21.0
func (q *Queue) SubmitWithFence(commandBuffers []*CommandBuffer, fence *Fence, submissionIndex uint64) error
SubmitWithFence submits command buffers for execution with fence-based tracking. Unlike Submit, this method does NOT block until GPU completion. Instead, it signals the provided fence with submissionIndex when the work completes. The caller is responsible for polling or waiting on the fence.
If fence is nil, the submission proceeds without fence signaling. Command buffers must be freed by the caller after the fence signals (use Device.FreeCommandBuffer).
func (*Queue) WriteBuffer ¶
WriteBuffer writes data to a buffer.
func (*Queue) WriteTexture ¶ added in v0.19.7
func (q *Queue) WriteTexture(dst *ImageCopyTexture, data []byte, layout *ImageDataLayout, size *Extent3D) error
WriteTexture writes data to a texture.
type RenderPassColorAttachment ¶
type RenderPassColorAttachment struct {
View *TextureView
ResolveTarget *TextureView
LoadOp LoadOp
StoreOp StoreOp
ClearValue Color
}
RenderPassColorAttachment describes a color attachment.
type RenderPassDepthStencilAttachment ¶
type RenderPassDepthStencilAttachment struct {
View *TextureView
DepthLoadOp LoadOp
DepthStoreOp StoreOp
DepthClearValue float32
DepthReadOnly bool
StencilLoadOp LoadOp
StencilStoreOp StoreOp
StencilClearValue uint32
StencilReadOnly bool
}
RenderPassDepthStencilAttachment describes a depth/stencil attachment.
type RenderPassDescriptor ¶
type RenderPassDescriptor struct {
Label string
ColorAttachments []RenderPassColorAttachment
DepthStencilAttachment *RenderPassDepthStencilAttachment
}
RenderPassDescriptor describes a render pass.
type RenderPassEncoder ¶
type RenderPassEncoder struct {
// contains filtered or unexported fields
}
RenderPassEncoder records draw commands within a render pass.
Created by CommandEncoder.BeginRenderPass(). Must be ended with End() before the CommandEncoder can be finished.
NOT thread-safe.
func (*RenderPassEncoder) Draw ¶
func (p *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
Draw draws primitives.
func (*RenderPassEncoder) DrawIndexed ¶
func (p *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, firstInstance uint32)
DrawIndexed draws indexed primitives.
func (*RenderPassEncoder) DrawIndexedIndirect ¶
func (p *RenderPassEncoder) DrawIndexedIndirect(buffer *Buffer, offset uint64)
DrawIndexedIndirect draws indexed primitives with GPU-generated parameters.
func (*RenderPassEncoder) DrawIndirect ¶
func (p *RenderPassEncoder) DrawIndirect(buffer *Buffer, offset uint64)
DrawIndirect draws primitives with GPU-generated parameters.
func (*RenderPassEncoder) End ¶
func (p *RenderPassEncoder) End() error
End ends the render pass. After this call, the encoder cannot be used again.
func (*RenderPassEncoder) SetBindGroup ¶
func (p *RenderPassEncoder) SetBindGroup(index uint32, group *BindGroup, offsets []uint32)
SetBindGroup sets a bind group for the given index.
func (*RenderPassEncoder) SetBlendConstant ¶
func (p *RenderPassEncoder) SetBlendConstant(color *Color)
SetBlendConstant sets the blend constant color.
func (*RenderPassEncoder) SetIndexBuffer ¶
func (p *RenderPassEncoder) SetIndexBuffer(buffer *Buffer, format IndexFormat, offset uint64)
SetIndexBuffer sets the index buffer.
func (*RenderPassEncoder) SetPipeline ¶
func (p *RenderPassEncoder) SetPipeline(pipeline *RenderPipeline)
SetPipeline sets the active render pipeline.
func (*RenderPassEncoder) SetScissorRect ¶
func (p *RenderPassEncoder) SetScissorRect(x, y, width, height uint32)
SetScissorRect sets the scissor rectangle for clipping.
func (*RenderPassEncoder) SetStencilReference ¶
func (p *RenderPassEncoder) SetStencilReference(reference uint32)
SetStencilReference sets the stencil reference value.
func (*RenderPassEncoder) SetVertexBuffer ¶
func (p *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer *Buffer, offset uint64)
SetVertexBuffer sets a vertex buffer for the given slot.
func (*RenderPassEncoder) SetViewport ¶
func (p *RenderPassEncoder) SetViewport(x, y, width, height, minDepth, maxDepth float32)
SetViewport sets the viewport transformation.
type RenderPipeline ¶
type RenderPipeline struct {
// contains filtered or unexported fields
}
RenderPipeline represents a configured render pipeline.
func (*RenderPipeline) Release ¶
func (p *RenderPipeline) Release()
Release destroys the render pipeline.
type RenderPipelineDescriptor ¶
type RenderPipelineDescriptor struct {
Label string
Layout *PipelineLayout
Vertex VertexState
Primitive PrimitiveState
DepthStencil *DepthStencilState
Multisample MultisampleState
Fragment *FragmentState
}
RenderPipelineDescriptor describes a render pipeline.
type RequestAdapterOptions ¶
type RequestAdapterOptions = gputypes.RequestAdapterOptions
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler represents a texture sampler.
func NewSamplerFromHAL ¶ added in v0.21.0
NewSamplerFromHAL creates a Sampler wrapping an existing HAL sampler.
type SamplerDescriptor ¶
type SamplerDescriptor struct {
Label string
AddressModeU AddressMode
AddressModeV AddressMode
AddressModeW AddressMode
MagFilter FilterMode
MinFilter FilterMode
MipmapFilter FilterMode
LodMinClamp float32
LodMaxClamp float32
Compare CompareFunction
Anisotropy uint16
}
SamplerDescriptor describes sampler creation parameters.
type ShaderModule ¶
type ShaderModule struct {
// contains filtered or unexported fields
}
ShaderModule represents a compiled shader module.
type ShaderModuleDescriptor ¶
type ShaderModuleDescriptor struct {
Label string
WGSL string // WGSL source code
SPIRV []uint32 // SPIR-V bytecode (alternative to WGSL)
}
ShaderModuleDescriptor describes shader module creation parameters.
type StencilFaceState ¶ added in v0.21.0
type StencilFaceState struct {
Compare CompareFunction
FailOp StencilOperation
DepthFailOp StencilOperation
PassOp StencilOperation
}
StencilFaceState describes stencil operations for a face.
type StencilOperation ¶ added in v0.21.0
type StencilOperation = hal.StencilOperation
StencilOperation describes a stencil operation.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface represents a platform rendering surface (e.g., a window).
Surface delegates lifecycle management to core.Surface, which enforces the state machine: Unconfigured -> Configured -> Acquired -> Configured.
func NewSurfaceFromHAL ¶ added in v0.21.0
NewSurfaceFromHAL creates a Surface wrapping an existing HAL surface. This constructor is used by backends that create surfaces externally (e.g., the Rust FFI backend).
Ownership of halSurface is transferred to the returned Surface.
func (*Surface) Configure ¶
func (s *Surface) Configure(device *Device, config *SurfaceConfiguration) error
Configure configures the surface for presentation. Must be called before GetCurrentTexture().
func (*Surface) DiscardTexture ¶ added in v0.21.0
func (s *Surface) DiscardTexture()
DiscardTexture discards the acquired surface texture without presenting it. Use this if rendering failed or was canceled. If no texture is currently acquired, this is a no-op.
func (*Surface) GetCurrentTexture ¶
func (s *Surface) GetCurrentTexture() (*SurfaceTexture, bool, error)
GetCurrentTexture acquires the next texture for rendering. Returns the surface texture and whether the surface is suboptimal.
If a PrepareFrame hook is registered and reports changed dimensions, the surface is automatically reconfigured before acquiring.
func (*Surface) HAL ¶ added in v0.21.0
HAL returns the underlying HAL surface for backward compatibility. Prefer using Surface methods instead of direct HAL access.
func (*Surface) Present ¶
func (s *Surface) Present(texture *SurfaceTexture) error
Present presents a surface texture to the screen.
func (*Surface) SetPrepareFrame ¶ added in v0.21.0
func (s *Surface) SetPrepareFrame(fn core.PrepareFrameFunc)
SetPrepareFrame registers a platform hook called before each GetCurrentTexture. If the hook returns changed=true with new dimensions, the surface is automatically reconfigured. This is the integration point for HiDPI/DPI change handling:
- macOS Metal: read CAMetalLayer.contentsScale
- Windows: handle WM_DPICHANGED
- Wayland: read wl_output.scale
Pass nil to remove the hook.
func (*Surface) Unconfigure ¶
func (s *Surface) Unconfigure()
Unconfigure removes the surface configuration.
type SurfaceConfiguration ¶
type SurfaceConfiguration struct {
Width uint32
Height uint32
Format TextureFormat
Usage TextureUsage
PresentMode PresentMode
AlphaMode CompositeAlphaMode
}
SurfaceConfiguration describes surface settings.
type SurfaceTexture ¶
type SurfaceTexture struct {
// contains filtered or unexported fields
}
SurfaceTexture is a texture acquired from a surface for rendering.
func (*SurfaceTexture) CreateView ¶
func (st *SurfaceTexture) CreateView(desc *TextureViewDescriptor) (*TextureView, error)
CreateView creates a texture view of this surface texture.
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture represents a GPU texture.
func NewTextureFromHAL ¶ added in v0.21.0
func NewTextureFromHAL(halTexture hal.Texture, device *Device, format TextureFormat) *Texture
NewTextureFromHAL creates a Texture wrapping an existing HAL texture. Used for backward compatibility and testing.
func (*Texture) Format ¶
func (t *Texture) Format() TextureFormat
Format returns the texture format.
func (*Texture) HalTexture ¶ added in v0.21.0
HalTexture returns the underlying HAL texture for advanced use cases. This enables interop with code that needs direct HAL access (e.g., gg GPU accelerator texture barriers and copy operations).
Returns nil if the texture has been released.
type TextureAspect ¶
type TextureAspect = gputypes.TextureAspect
type TextureBarrier ¶ added in v0.21.0
type TextureBarrier struct {
Texture *Texture
Range TextureRange
Usage TextureUsageTransition
}
TextureBarrier defines a texture state transition for synchronization. Required on Vulkan for layout transitions between render pass and copy operations. On Metal, GLES, and software backends this is a no-op.
type TextureDescriptor ¶
type TextureDescriptor struct {
Label string
Size Extent3D
MipLevelCount uint32
SampleCount uint32
Dimension TextureDimension
Format TextureFormat
Usage TextureUsage
ViewFormats []TextureFormat
}
TextureDescriptor describes texture creation parameters.
type TextureDimension ¶
type TextureDimension = gputypes.TextureDimension
type TextureFormat ¶
type TextureFormat = gputypes.TextureFormat
type TextureRange ¶ added in v0.21.0
type TextureRange struct {
Aspect TextureAspect
BaseMipLevel uint32
MipLevelCount uint32
BaseArrayLayer uint32
ArrayLayerCount uint32
}
TextureRange specifies a range of texture subresources.
type TextureUsageTransition ¶ added in v0.21.0
type TextureUsageTransition struct {
OldUsage TextureUsage
NewUsage TextureUsage
}
TextureUsageTransition defines a texture usage state transition.
type TextureView ¶
type TextureView struct {
// contains filtered or unexported fields
}
TextureView represents a view into a texture.
func NewTextureViewFromHAL ¶ added in v0.21.0
func NewTextureViewFromHAL(halView hal.TextureView, device *Device) *TextureView
NewTextureViewFromHAL creates a TextureView wrapping an existing HAL texture view.
func (*TextureView) HalTextureView ¶ added in v0.21.0
func (v *TextureView) HalTextureView() hal.TextureView
HalTextureView returns the underlying HAL texture view for advanced use cases. This enables interop with code that needs direct HAL access (e.g., gg GPU accelerator surface rendering).
Returns nil if the view has been released.
type TextureViewDescriptor ¶
type TextureViewDescriptor struct {
Label string
Format TextureFormat
Dimension TextureViewDimension
Aspect TextureAspect
BaseMipLevel uint32
MipLevelCount uint32
BaseArrayLayer uint32
ArrayLayerCount uint32
}
TextureViewDescriptor describes texture view creation parameters.
type TextureViewDimension ¶
type TextureViewDimension = gputypes.TextureViewDimension
type VertexBufferLayout ¶
type VertexBufferLayout = gputypes.VertexBufferLayout
type VertexState ¶
type VertexState struct {
Module *ShaderModule
EntryPoint string
Buffers []VertexBufferLayout
}
VertexState describes the vertex shader stage.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
dx12-test
command
Command dx12-test is an integration test for the DX12 backend.
|
Command dx12-test is an integration test for the DX12 backend. |
|
gles-test
command
Command gles-test is an integration test for the Pure Go GLES backend.
|
Command gles-test is an integration test for the Pure Go GLES backend. |
|
vk-gen
command
Command vk-gen generates Pure Go Vulkan bindings from vk.xml specification.
|
Command vk-gen generates Pure Go Vulkan bindings from vk.xml specification. |
|
vk-test
command
Command vk-test is an integration test for the Pure Go Vulkan backend.
|
Command vk-test is an integration test for the Pure Go Vulkan backend. |
|
vulkan-renderpass-test
command
Command vulkan-renderpass-test validates the hypothesis that Intel Iris Xe driver bug is specific to VK_KHR_dynamic_rendering, not vkCreateGraphicsPipelines.
|
Command vulkan-renderpass-test validates the hypothesis that Intel Iris Xe driver bug is specific to VK_KHR_dynamic_rendering, not vkCreateGraphicsPipelines. |
|
vulkan-triangle
command
Command vulkan-triangle is a full integration test for the Pure Go Vulkan backend.
|
Command vulkan-triangle is a full integration test for the Pure Go Vulkan backend. |
|
wgpu-triangle
command
Command wgpu-triangle tests the wgpu public API rendering pipeline.
|
Command wgpu-triangle tests the wgpu public API rendering pipeline. |
|
wgpu-triangle-mt
command
Command wgpu-triangle tests the wgpu public API rendering pipeline.
|
Command wgpu-triangle tests the wgpu public API rendering pipeline. |
|
Package core provides validation and state management for WebGPU resources.
|
Package core provides validation and state management for WebGPU resources. |
|
track
Package track provides resource state tracking infrastructure.
|
Package track provides resource state tracking infrastructure. |
|
examples
|
|
|
compute-copy
command
Command compute-copy demonstrates GPU buffer copying via a compute shader.
|
Command compute-copy demonstrates GPU buffer copying via a compute shader. |
|
compute-sum
command
Command compute-sum demonstrates a parallel reduction (sum) using a GPU compute shader.
|
Command compute-sum demonstrates a parallel reduction (sum) using a GPU compute shader. |
|
Package hal provides the Hardware Abstraction Layer for WebGPU implementations.
|
Package hal provides the Hardware Abstraction Layer for WebGPU implementations. |
|
allbackends
Package allbackends imports all HAL backend implementations.
|
Package allbackends imports all HAL backend implementations. |
|
dx12
Package dx12 provides a DirectX 12 backend for the HAL.
|
Package dx12 provides a DirectX 12 backend for the HAL. |
|
dx12/d3d12
Package d3d12 provides low-level Direct3D 12 COM bindings for Windows.
|
Package d3d12 provides low-level Direct3D 12 COM bindings for Windows. |
|
dx12/d3dcompile
Package d3dcompile provides Pure Go bindings to d3dcompiler_47.dll.
|
Package d3dcompile provides Pure Go bindings to d3dcompiler_47.dll. |
|
dx12/dxgi
Package dxgi provides low-level DXGI (DirectX Graphics Infrastructure) COM bindings for Windows.
|
Package dxgi provides low-level DXGI (DirectX Graphics Infrastructure) COM bindings for Windows. |
|
gles
Package gles implements the HAL backend for OpenGL ES 3.0 / OpenGL 3.3+.
|
Package gles implements the HAL backend for OpenGL ES 3.0 / OpenGL 3.3+. |
|
gles/egl
Package egl provides EGL (EGL) context management for OpenGL ES on Linux.
|
Package egl provides EGL (EGL) context management for OpenGL ES on Linux. |
|
gles/gl
Package gl provides OpenGL constants and types for the GLES backend.
|
Package gl provides OpenGL constants and types for the GLES backend. |
|
gles/wgl
Package wgl provides Windows OpenGL (WGL) context management.
|
Package wgl provides Windows OpenGL (WGL) context management. |
|
metal
Package metal provides a Metal backend for the HAL.
|
Package metal provides a Metal backend for the HAL. |
|
noop
Package noop provides a no-operation GPU backend.
|
Package noop provides a no-operation GPU backend. |
|
software
Package software provides a CPU-based software rendering backend.
|
Package software provides a CPU-based software rendering backend. |
|
software/raster
Package raster provides CPU-based triangle rasterization for the software backend.
|
Package raster provides CPU-based triangle rasterization for the software backend. |
|
software/shader
Package shader provides callback-based shader execution for the software backend.
|
Package shader provides callback-based shader execution for the software backend. |
|
vulkan
Package vulkan provides Pure Go Vulkan backend for the HAL.
|
Package vulkan provides Pure Go Vulkan backend for the HAL. |
|
vulkan/memory
Package memory provides GPU memory allocation for Vulkan backend.
|
Package memory provides GPU memory allocation for Vulkan backend. |
|
vulkan/vk
Package vk provides Pure Go Vulkan bindings using goffi for FFI calls.
|
Package vk provides Pure Go Vulkan bindings using goffi for FFI calls. |
|
internal
|
|
|
thread
Package thread provides thread abstraction for GPU operations.
|
Package thread provides thread abstraction for GPU operations. |