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
- func (b *Buffer) Label() string
- func (b *Buffer) Map(ctx context.Context, mode MapMode, offset, size uint64) error
- func (b *Buffer) MapAsync(mode MapMode, offset, size uint64) (*MapPending, error)
- func (b *Buffer) MapState() MapState
- func (b *Buffer) MappedRange(offset, size uint64) (*MappedRange, error)
- func (b *Buffer) Release()
- func (b *Buffer) Size() uint64
- func (b *Buffer) Unmap() error
- func (b *Buffer) Usage() BufferUsage
- 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) ClearBuffer(buffer *Buffer, offset, size uint64)
- func (e *CommandEncoder) CopyBufferToBuffer(src *Buffer, srcOffset uint64, dst *Buffer, dstOffset uint64, size uint64)
- func (e *CommandEncoder) CopyBufferToTexture(src *Buffer, dst *Texture, regions []BufferTextureCopy)
- func (e *CommandEncoder) CopyTextureToBuffer(src *Texture, dst *Buffer, regions []BufferTextureCopy)
- func (e *CommandEncoder) CopyTextureToTexture(src, dst *Texture, regions []TextureCopy)
- 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)
- func (d *Device) Features() Features
- func (d *Device) FreeCommandBuffer(_ *CommandBuffer)
- func (d *Device) GetFenceStatus(_ *Fence) (bool, error)
- func (d *Device) HalDevice() any
- func (d *Device) Limits() Limits
- func (d *Device) Poll(pollType PollType) bool
- func (d *Device) PopErrorScope() *GPUError
- func (d *Device) PushErrorScope(filter ErrorFilter)
- func (d *Device) Queue() *Queue
- func (d *Device) Release()
- func (d *Device) ResetFence(_ *Fence) error
- func (d *Device) WaitForFence(_ *Fence, _ uint64, _ 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 LateBufferBindingInfo
- type LateSizedBufferGroup
- type Limits
- type LoadOp
- type MapMode
- type MapPending
- type MapState
- type MappedRange
- type MultisampleState
- type Origin3D
- type PipelineLayout
- type PipelineLayoutDescriptor
- type PollType
- type PowerPreference
- type PresentMode
- type PrimitiveState
- type PrimitiveTopology
- type Queue
- func (q *Queue) LastSubmissionIndex() uint64
- func (q *Queue) Poll() uint64
- func (q *Queue) SetSwapchainSuppressed(_ bool)
- func (q *Queue) Submit(commandBuffers ...*CommandBuffer) (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) ActualExtent() (width, height uint32)
- func (s *Surface) Configure(device *Device, config *SurfaceConfiguration) error
- func (s *Surface) DiscardTexture()
- func (s *Surface) GetCurrentTexture() (*SurfaceTexture, bool, error)
- func (s *Surface) Present(_ *SurfaceTexture) error
- func (s *Surface) PresentWithDamage(st *SurfaceTexture, _ []image.Rectangle) error
- func (s *Surface) Release()
- func (s *Surface) Unconfigure()
- type SurfaceCapabilities
- type SurfaceConfiguration
- type SurfaceTexture
- type Texture
- type TextureAspect
- type TextureBarrier
- type TextureCopy
- 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 = gputypes.StencilOperationKeep StencilOperationZero = gputypes.StencilOperationZero StencilOperationReplace = gputypes.StencilOperationReplace StencilOperationInvert = gputypes.StencilOperationInvert StencilOperationIncrementClamp = gputypes.StencilOperationIncrementClamp StencilOperationDecrementClamp = gputypes.StencilOperationDecrementClamp StencilOperationIncrementWrap = gputypes.StencilOperationIncrementWrap StencilOperationDecrementWrap = gputypes.StencilOperationDecrementWrap )
Stencil operation constants (webgpu.h spec values).
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 HAL hard cap on bind groups (wgpu-hal MAX_BIND_GROUPS = 8). Devices may support up to 8, but only MinBindGroups (4) is guaranteed.
const MinBindGroups = 4
MinBindGroups is the minimum guaranteed number of bind groups per WebGPU spec. All compliant devices support at least 4 bind groups. Portable code should use no more than MinBindGroups.
Variables ¶
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)") // ErrDeviceLost is returned when the GPU device is lost. ErrDeviceLost = errors.New("wgpu: device lost") // ErrOutOfMemory is returned when the GPU is out of memory. ErrOutOfMemory = errors.New("wgpu: out of memory") // ErrSurfaceLost is returned when the surface is lost. ErrSurfaceLost = errors.New("wgpu: surface lost") // ErrSurfaceOutdated is returned when the surface is outdated. ErrSurfaceOutdated = errors.New("wgpu: surface outdated") // ErrTimeout is returned when an operation times out. ErrTimeout = errors.New("wgpu: timeout") )
Public API sentinel errors.
var ( ErrDrawMissingPipeline = errors.New("wgpu: draw called without SetPipeline") ErrDrawMissingBindGroup = errors.New("wgpu: draw called with missing bind group") ErrDrawIncompatibleBindGroup = errors.New("wgpu: draw called with incompatible bind group layout") ErrDrawMissingVertexBuffer = errors.New("wgpu: draw called with insufficient vertex buffers") ErrDrawMissingIndexBuffer = errors.New("wgpu: DrawIndexed called without SetIndexBuffer") ErrDrawMissingBlendConstant = errors.New("wgpu: draw called without SetBlendConstant (pipeline uses constant blend factor)") ErrDrawLateBufferTooSmall = errors.New("wgpu: bound buffer smaller than shader-required minimum") ErrDispatchMissingPipeline = errors.New("wgpu: dispatch called without SetPipeline") ErrDispatchMissingBindGroup = errors.New("wgpu: dispatch called with missing bind group") ErrDispatchIncompatibleBindGroup = errors.New("wgpu: dispatch called with incompatible bind group layout") ErrDispatchLateBufferTooSmall = errors.New("wgpu: dispatch: bound buffer smaller than shader-required minimum") ErrDispatchWorkgroupCountExceeded = errors.New("wgpu: dispatch workgroup count exceeds device limit") ErrDrawIndexFormatMismatch = errors.New("wgpu: index buffer format does not match pipeline strip index format") ErrDrawIndirectBufferUsage = errors.New("wgpu: indirect draw buffer missing INDIRECT usage") ErrDrawIndirectOffsetAlignment = errors.New("wgpu: indirect draw buffer offset not 4-byte aligned") ErrDispatchIndirectBufferUsage = errors.New("wgpu: indirect dispatch buffer missing INDIRECT usage") ErrDispatchIndirectOffsetAlignment = errors.New("wgpu: indirect dispatch buffer offset not 4-byte aligned") ErrDrawIndirectBufferOverrun = errors.New("wgpu: indirect draw args exceed buffer size") ErrDispatchIndirectBufferOverrun = errors.New("wgpu: indirect dispatch args exceed buffer size") )
Draw-time validation sentinel errors.
var ( ErrMapAlreadyPending = errors.New("wgpu: buffer map already pending") ErrMapAlreadyMapped = errors.New("wgpu: buffer is already mapped") ErrMapNotMapped = errors.New("wgpu: buffer is not mapped") ErrMapRangeOverlap = errors.New("wgpu: mapped range overlaps existing") ErrMapRangeDetached = errors.New("wgpu: mapped range detached (buffer unmapped)") ErrMapAlignment = errors.New("wgpu: map offset/size not aligned") ErrMapCanceled = errors.New("wgpu: map canceled") ErrBufferDestroyed = errors.New("wgpu: buffer destroyed") ErrMapDeviceLost = errors.New("wgpu: device lost during map") ErrMapInvalidMode = errors.New("wgpu: buffer not created with required MAP_READ/MAP_WRITE usage") ErrMapRangeOverflow = errors.New("wgpu: map range exceeds buffer size") )
Typed buffer mapping errors.
var ( DefaultLimits = gputypes.DefaultLimits DefaultInstanceDescriptor = gputypes.DefaultInstanceDescriptor )
Default functions (re-exported for convenience)
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter represents a physical GPU. On browser, this wraps a GPUAdapter via internal/browser.Adapter.
func (*Adapter) GetSurfaceCapabilities ¶ added in v0.23.0
func (a *Adapter) GetSurfaceCapabilities(surface *Surface) *SurfaceCapabilities
GetSurfaceCapabilities returns the capabilities of a surface for this adapter.
On browser, capabilities are statically defined per the WebGPU spec:
- Formats: rgba8unorm, bgra8unorm, rgba16float (preferred format first)
- PresentModes: Fifo only (browser controls VSync)
- AlphaModes: Opaque only (browser default)
The preferred format is obtained from navigator.gpu.getPreferredCanvasFormat() and placed first in the formats list.
Matches Rust wgpu SurfaceInterface::get_capabilities for WebSurface.
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
Offset uint64
Size uint64
Sampler *Sampler
TextureView *TextureView
}
BindGroupEntry describes a single resource binding in a bind group.
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.
func (*Buffer) Label ¶
Label returns the buffer's debug label. Browser WebGPU does not expose label on the object; returns empty string.
func (*Buffer) Map ¶ added in v0.25.0
Map blocks until a CPU-visible mapping is established for the given byte range, or until ctx is canceled.
The buffer must have been created with BufferUsageMapRead or BufferUsageMapWrite matching mode. offset must be a multiple of 8 and size must be a multiple of 4 (WebGPU MAP_ALIGNMENT).
After Map succeeds, call MappedRange to obtain a byte view and Unmap when finished:
if err := buf.Map(ctx, wgpu.MapModeRead, 0, size); err != nil {
return err
}
defer buf.Unmap()
rng, _ := buf.MappedRange(0, size)
data := rng.Bytes()
On the browser, Map spawns a goroutine that calls GPUBuffer.mapAsync (a JS Promise) via AwaitPromise. The ctx parameter allows cancellation.
func (*Buffer) MapAsync ¶ added in v0.25.0
func (b *Buffer) MapAsync(mode MapMode, offset, size uint64) (*MapPending, error)
MapAsync initiates a buffer map without blocking the caller.
Returns a *MapPending handle that resolves once the browser's GPUBuffer.mapAsync Promise settles. The caller can poll with Status() or block with Wait(ctx).
Validation errors (alignment, usage mismatch, range overflow, already-mapped state) surface synchronously.
func (*Buffer) MapState ¶ added in v0.25.0
MapState returns the current mapping state of the buffer.
func (*Buffer) MappedRange ¶ added in v0.25.0
func (b *Buffer) MappedRange(offset, size uint64) (*MappedRange, error)
MappedRange returns a safe view over the mapped region [offset, offset+size).
The buffer must be in the Mapped state (Map or MapAsync resolved, or the buffer was created with MappedAtCreation: true). The returned MappedRange is invalidated by Unmap.
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. On browser, this wraps a GPUCommandBuffer via internal/browser.CommandBuffer.
func (*CommandBuffer) Release ¶ added in v0.24.1
func (cb *CommandBuffer) Release()
Release releases a CommandBuffer that will NOT be submitted to the GPU.
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
CommandEncoder records GPU commands for later submission. On browser, this wraps a GPUCommandEncoder via internal/browser.CommandEncoder.
func (*CommandEncoder) BeginComputePass ¶
func (e *CommandEncoder) BeginComputePass(desc *ComputePassDescriptor) (*ComputePassEncoder, error)
BeginComputePass begins a compute pass.
func (*CommandEncoder) BeginRenderPass ¶
func (e *CommandEncoder) BeginRenderPass(desc *RenderPassDescriptor) (*RenderPassEncoder, error)
BeginRenderPass begins a render pass.
func (*CommandEncoder) ClearBuffer ¶ added in v0.28.0
func (e *CommandEncoder) ClearBuffer(buffer *Buffer, offset, size uint64)
ClearBuffer clears a buffer region to zero.
func (*CommandEncoder) CopyBufferToBuffer ¶
func (e *CommandEncoder) CopyBufferToBuffer(src *Buffer, srcOffset uint64, dst *Buffer, dstOffset uint64, size uint64)
CopyBufferToBuffer copies data between buffers.
func (*CommandEncoder) CopyBufferToTexture ¶ added in v0.28.0
func (e *CommandEncoder) CopyBufferToTexture(src *Buffer, dst *Texture, regions []BufferTextureCopy)
CopyBufferToTexture copies data from a buffer to a texture.
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.
func (*CommandEncoder) CopyTextureToTexture ¶ added in v0.26.5
func (e *CommandEncoder) CopyTextureToTexture(src, dst *Texture, regions []TextureCopy)
CopyTextureToTexture copies data between textures.
func (*CommandEncoder) DiscardEncoding ¶ added in v0.21.0
func (e *CommandEncoder) DiscardEncoding()
DiscardEncoding discards the encoder without producing a command buffer.
func (*CommandEncoder) Finish ¶
func (e *CommandEncoder) Finish() (*CommandBuffer, error)
Finish completes command recording and returns a CommandBuffer.
func (*CommandEncoder) TransitionTextures ¶ added in v0.21.0
func (e *CommandEncoder) TransitionTextures(barriers []TextureBarrier)
TransitionTextures transitions texture states for synchronization. On browser, this is a no-op — the browser WebGPU API handles barriers internally.
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. On browser, this wraps a GPUComputePassEncoder via internal/browser.ComputePassEncoder.
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) GetBindGroupLayout ¶ added in v0.28.0
func (p *ComputePipeline) GetBindGroupLayout(index uint32) *BindGroupLayout
GetBindGroupLayout returns the bind group layout at the given index. This wraps GPUComputePipeline.getBindGroupLayout(index) for "auto" layouts.
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
// Constants are pipeline-overridable constants (WebGPU spec).
// Browser passes these to GPUDevice.createComputePipeline() constants dict.
Constants map[string]float64
// ZeroInitializeWorkgroupMemory controls workgroup memory zero-init.
// Browser ignores this (WebGPU spec mandates zero-init in browser).
ZeroInitializeWorkgroupMemory *bool
}
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. On browser, this wraps a GPUDevice via internal/browser.Device.
func NewDeviceFromHAL ¶ added in v0.21.0
NewDeviceFromHAL is not supported in the browser. The browser backend uses navigator.gpu (WebGPU JS API), not Go HAL.
func (*Device) CreateBindGroup ¶
func (d *Device) CreateBindGroup(desc *BindGroupDescriptor) (*BindGroup, error)
CreateBindGroup creates a bind group from the given descriptor.
func (*Device) CreateBindGroupLayout ¶
func (d *Device) CreateBindGroupLayout(desc *BindGroupLayoutDescriptor) (*BindGroupLayout, error)
CreateBindGroupLayout creates a bind group layout from the given descriptor.
func (*Device) CreateBuffer ¶
func (d *Device) CreateBuffer(desc *BufferDescriptor) (*Buffer, error)
CreateBuffer creates a GPU buffer from the given descriptor.
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 from the given descriptor.
func (*Device) CreateFence ¶ added in v0.21.0
CreateFence creates a GPU synchronization fence. On browser, fences are not needed (browser auto-polls). Returns a no-op fence for API compatibility.
func (*Device) CreatePipelineLayout ¶
func (d *Device) CreatePipelineLayout(desc *PipelineLayoutDescriptor) (*PipelineLayout, error)
CreatePipelineLayout creates a pipeline layout from the given descriptor.
func (*Device) CreateRenderPipeline ¶
func (d *Device) CreateRenderPipeline(desc *RenderPipelineDescriptor) (*RenderPipeline, error)
CreateRenderPipeline creates a render pipeline from the given descriptor.
func (*Device) CreateSampler ¶
func (d *Device) CreateSampler(desc *SamplerDescriptor) (*Sampler, error)
CreateSampler creates a texture sampler from the given descriptor.
func (*Device) CreateShaderModule ¶
func (d *Device) CreateShaderModule(desc *ShaderModuleDescriptor) (*ShaderModule, error)
CreateShaderModule creates a shader module from the given descriptor. On browser, WGSL code goes directly to the browser's createShaderModule. SPIR-V bytecode is not supported in the browser (browser only accepts WGSL).
func (*Device) CreateTexture ¶
func (d *Device) CreateTexture(desc *TextureDescriptor) (*Texture, error)
CreateTexture creates a GPU texture from the given descriptor.
func (*Device) CreateTextureView ¶
func (d *Device) CreateTextureView(texture *Texture, desc *TextureViewDescriptor) (*TextureView, error)
CreateTextureView creates a view into a texture.
func (*Device) DestroyFence ¶ added in v0.21.0
DestroyFence destroys a fence. No-op on browser — fences are JS-managed.
func (*Device) FreeCommandBuffer ¶ added in v0.21.0
func (d *Device) FreeCommandBuffer(_ *CommandBuffer)
FreeCommandBuffer is a no-op on browser — JS GC handles GPU resource cleanup. This exists for API compatibility with the native backend where command buffers must be explicitly freed after GPU submission completes.
func (*Device) GetFenceStatus ¶ added in v0.21.0
GetFenceStatus returns true (signaled). Browser fences resolve via JS Promises.
func (*Device) HalDevice ¶ added in v0.21.0
HalDevice returns nil on browser — there is no HAL layer. The browser backend talks directly to the browser WebGPU API. This exists for API compatibility with the native backend.
func (*Device) Poll ¶ added in v0.25.0
Poll drives the per-device pending-map triage loop. On browser, the GPU is polled automatically by the browser event loop. Returns true (devices are always considered polled in browser).
func (*Device) PopErrorScope ¶
PopErrorScope pops the most recently pushed error scope. Phase 2 — not yet implemented for browser.
func (*Device) PushErrorScope ¶
func (d *Device) PushErrorScope(filter ErrorFilter)
PushErrorScope pushes a new error scope onto the device's error scope stack. Phase 2 — not yet implemented for browser.
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. No-op on browser — fences auto-reset.
func (*Device) WaitForFence ¶ added in v0.21.0
WaitForFence returns immediately on browser — GPU sync is handled by JS event loop.
type DeviceDescriptor ¶
DeviceDescriptor configures device creation.
type DeviceType ¶
type DeviceType = gputypes.DeviceType
type ErrorFilter ¶
type ErrorFilter int
ErrorFilter selects which errors an error scope captures.
const ( ErrorFilterValidation ErrorFilter = 0 ErrorFilterOutOfMemory ErrorFilter = 1 ErrorFilterInternal ErrorFilter = 2 )
type Fence ¶ added in v0.21.0
type Fence struct {
// contains filtered or unexported fields
}
Fence is a GPU synchronization primitive. On browser, fences are no-ops — the browser auto-polls GPU completion via its internal event loop. This type exists for API compatibility.
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. On browser, this wraps navigator.gpu via internal/browser.Instance.
func CreateInstance ¶
func CreateInstance(desc *InstanceDescriptor) (*Instance, error)
CreateInstance creates a new GPU instance. On browser, this accesses navigator.gpu. The desc parameter is accepted for API compatibility but Backends/Flags are ignored (browser has one backend).
func (*Instance) CreateSurface ¶
CreateSurface creates a rendering surface from an HTML canvas element.
On browser, displayHandle is ignored and windowHandle is treated as a numeric canvas element ID (data-raw-handle attribute lookup). If windowHandle is 0, the first <canvas> element in the document is used.
For direct js.Value canvas access, use CreateSurfaceFromCanvas instead.
Matches Rust wgpu InstanceInterface::create_surface for WebSurface which uses RawWindowHandle::Web to query the DOM by data-raw-handle attribute.
func (*Instance) CreateSurfaceFromCanvas ¶ added in v0.28.0
CreateSurfaceFromCanvas creates a rendering surface from a js.Value canvas.
This is the browser-specific entry point that accepts a direct canvas reference (HTMLCanvasElement or OffscreenCanvas). Use this when you have a canvas js.Value from JavaScript interop.
Matches Rust wgpu's SurfaceTarget::Canvas variant which takes an HtmlCanvasElement directly.
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
Flags gputypes.InstanceFlags
}
InstanceDescriptor configures instance creation. On browser, Backends and Flags are accepted for API compatibility but ignored — the browser has exactly one WebGPU backend.
type LateBufferBindingInfo ¶ added in v0.25.4
LateBufferBindingInfo records the actual buffer binding size for a layout entry with MinBindingSize == 0.
type LateSizedBufferGroup ¶ added in v0.25.4
type LateSizedBufferGroup struct {
ShaderSizes []uint64
}
LateSizedBufferGroup holds the shader-required minimum buffer sizes for bind group entries whose layout specifies MinBindingSize == 0.
type MapMode ¶ added in v0.25.0
type MapMode uint32
MapMode selects the type of access requested for a buffer mapping.
type MapPending ¶ added in v0.25.0
type MapPending struct {
// contains filtered or unexported fields
}
MapPending is a handle to an in-flight Buffer.MapAsync on the browser.
The browser backend uses a goroutine + channel pattern: MapAsync spawns a goroutine that calls AwaitPromise on the GPUBuffer.mapAsync JS Promise. The result (nil on success, error on rejection) is sent to the done channel.
This differs from the native backend (which uses core.MapWaiter + Device.Poll) because browser WebGPU resolves promises via the JS event loop, not via explicit GPU polling.
func (*MapPending) Release ¶ added in v0.25.0
func (p *MapPending) Release()
Release discards the MapPending handle. Calling this while the map is still in flight is allowed; the JS Promise continues to resolve but its completion is not observable through this handle anymore.
func (*MapPending) Status ¶ added in v0.25.0
func (p *MapPending) Status() (ready bool, err error)
Status returns the current state of the pending map without blocking.
- (true, nil) -- mapping is ready; call Buffer.MappedRange.
- (false, nil) -- still pending; the JS event loop has not resolved the Promise yet.
- (true, err) -- mapping failed; the buffer is back in the Unmapped state and err describes why.
func (*MapPending) Wait ¶ added in v0.25.0
func (p *MapPending) Wait(ctx context.Context) error
Wait blocks until the pending map resolves or ctx is canceled.
If ctx is canceled before the JS Promise resolves, Wait returns ctx.Err(). The mapping remains Pending -- the caller should normally follow up with Buffer.Unmap to cancel it.
type MapState ¶ added in v0.25.0
type MapState uint8
MapState reports the current mapping state of a buffer.
type MappedRange ¶ added in v0.25.0
type MappedRange struct {
// contains filtered or unexported fields
}
MappedRange is a safe view over a region of a mapped GPU buffer.
On the browser backend, MappedRange lazily copies data from the JS ArrayBuffer into a Go byte slice on first Bytes() call (read path), or provides a staging slice for writes that is flushed back to JS on Flush(). This matches the Rust wgpu WebBufferMappedRange pattern: actual_mapping (JS Uint8Array) + temporary_mapping (Rust/WASM heap copy).
The MappedRange is invalidated when the owning buffer is unmapped.
func (*MappedRange) Bytes ¶ added in v0.25.0
func (m *MappedRange) Bytes() []byte
Bytes returns the mapped data as a read-only byte slice.
The data is lazily copied from the JS ArrayBuffer on the first call. The returned slice is valid until the owning buffer is unmapped. After Unmap, Bytes() returns nil.
func (*MappedRange) BytesMut ¶ added in v0.28.0
func (m *MappedRange) BytesMut() []byte
BytesMut returns a mutable byte slice for writing into the mapped region.
The returned slice is a Go-heap copy. Changes are NOT visible on the GPU until Flush() is called (or the buffer is unmapped, which auto-flushes dirty ranges). This matches the Rust wgpu pattern where Drop on WebBufferMappedRange writes back if temporary_mapping_modified is true.
func (*MappedRange) Flush ¶ added in v0.28.0
func (m *MappedRange) Flush() error
Flush writes the cached data back to the JS ArrayBuffer. Only needed after BytesMut(); Bytes()-only usage does not require Flush.
This is the Go equivalent of the Rust WebBufferMappedRange Drop handler that copies temporary_mapping back to actual_mapping when modified.
func (*MappedRange) Len ¶ added in v0.25.0
func (m *MappedRange) Len() int
Len returns the size of the mapped range in bytes.
func (*MappedRange) Offset ¶ added in v0.25.0
func (m *MappedRange) Offset() uint64
Offset returns the byte offset of the mapped range within its buffer.
func (*MappedRange) Release ¶ added in v0.25.0
func (m *MappedRange) Release()
Release invalidates the MappedRange. After Release, Bytes() returns nil. If dirty data has not been flushed, Release auto-flushes it to JS.
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 PollType ¶ added in v0.25.0
type PollType uint8
PollType selects the blocking behavior of Device.Poll.
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. On browser, this wraps a GPUQueue via internal/browser.Queue.
func (*Queue) LastSubmissionIndex ¶ added in v0.23.6
LastSubmissionIndex returns the most recent submission index. On browser, submission indices are not tracked. Returns 0.
func (*Queue) Poll ¶ added in v0.23.0
Poll returns the last completed submission index. On browser, the GPU is polled automatically. Returns 0.
func (*Queue) SetSwapchainSuppressed ¶ added in v0.26.3
SetSwapchainSuppressed is a no-op on the browser backend. WebGPU browser API handles swapchain synchronization internally.
func (*Queue) Submit ¶
func (q *Queue) Submit(commandBuffers ...*CommandBuffer) (uint64, error)
Submit submits command buffers for execution. Returns 0 for the submission index (browser does not track indices). Matches Rust wgpu WebQueue::submit which collects into js_sys::Array.
func (*Queue) WriteBuffer ¶
WriteBuffer writes data to a buffer. Uses js.CopyBytesToJS for Go-to-JS data transfer (same pattern as Rust's Uint8Array::from(data).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. Matches Rust wgpu WebQueue::write_texture layout: offset/bytesPerRow/rowsPerImage are set on a GPUTexelCopyBufferLayout JS object.
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. On browser, this wraps a GPURenderPassEncoder via internal/browser.RenderPassEncoder.
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) 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. Offset is in bytes. Pass 0 for size to use the rest of the buffer.
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) GetBindGroupLayout ¶ added in v0.28.0
func (p *RenderPipeline) GetBindGroupLayout(index uint32) *BindGroupLayout
GetBindGroupLayout returns the bind group layout at the given index. This wraps GPURenderPipeline.getBindGroupLayout(index) for "auto" layouts.
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 struct {
// PowerPreference indicates power consumption preference.
PowerPreference PowerPreference
// ForceFallbackAdapter forces the use of a fallback (software) adapter.
ForceFallbackAdapter bool
// CompatibleSurface, if non-nil, indicates that the adapter must support
// rendering to this surface. For GLES backends, this triggers deferred
// adapter enumeration using the surface's GL context.
CompatibleSurface *Surface
}
RequestAdapterOptions controls adapter selection.
Following the WebGPU spec, CompatibleSurface is a typed *Surface pointer (not a raw handle). Backends that require a surface for adapter enumeration (e.g., GLES/OpenGL which needs a GL context) use this to perform deferred enumeration when RequestAdapter is called.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler represents a texture sampler.
func NewSamplerFromHAL ¶ added in v0.21.0
NewSamplerFromHAL is not supported in the browser.
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 = gputypes.StencilOperation
StencilOperation describes a stencil operation. Canonical definition in gputypes (webgpu.h spec-compliant values).
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface represents a platform rendering surface. On browser, this wraps an HTMLCanvasElement + GPUCanvasContext.
Matches Rust wgpu WebSurface which holds a Canvas enum, a GpuCanvasContext, and an optional Gpu reference.
func NewSurfaceFromHAL ¶ added in v0.21.0
NewSurfaceFromHAL is not supported in the browser.
func (*Surface) ActualExtent ¶ added in v0.28.2
ActualExtent returns the configured surface dimensions. On browser, the canvas dimensions are always used as-is (no driver clamping). Returns (0, 0) if the surface is not configured.
func (*Surface) Configure ¶
func (s *Surface) Configure(device *Device, config *SurfaceConfiguration) error
Configure configures the surface for presentation.
Must be called before GetCurrentTexture(). Sets the canvas dimensions and calls GPUCanvasContext.configure() with the device, format, usage, and alpha mode.
On browser, PresentMode is ignored (browser always uses FIFO / VSync).
Matches Rust wgpu SurfaceInterface::configure for WebSurface.
func (*Surface) DiscardTexture ¶ added in v0.21.0
func (s *Surface) DiscardTexture()
DiscardTexture discards the acquired surface texture without presenting it.
On browser, this is a NO-OP. The browser does not support discarding a surface texture -- it will be presented regardless when the event loop runs. Matches Rust wgpu where WebSurfaceOutputDetail::texture_discard() 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 (always false on browser). The texture is automatically presented when the command buffer using it is submitted and control returns to the browser event loop.
Matches Rust wgpu SurfaceInterface::get_current_texture for WebSurface.
func (*Surface) Present ¶
func (s *Surface) Present(_ *SurfaceTexture) error
Present presents a surface texture to the screen.
On browser, this is a NO-OP. The swapchain is presented automatically when control returns to the browser event loop. This matches Rust wgpu where WebSurfaceOutputDetail::present() is an empty function.
func (*Surface) PresentWithDamage ¶ added in v0.28.1
func (s *Surface) PresentWithDamage(st *SurfaceTexture, _ []image.Rectangle) error
PresentWithDamage presents a surface texture, optionally with damage rects. On browser, damage rects are ignored — the browser composites the full canvas. This method exists for API compatibility with the native backend.
func (*Surface) Unconfigure ¶
func (s *Surface) Unconfigure()
Unconfigure removes the surface configuration. After this call, GetCurrentTexture() will fail until Configure is called again.
type SurfaceCapabilities ¶ added in v0.23.0
type SurfaceCapabilities struct {
Formats []TextureFormat
PresentModes []PresentMode
AlphaModes []CompositeAlphaMode
}
SurfaceCapabilities describes what a surface supports on this adapter.
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.
On browser, the texture is automatically presented when the command buffer using it is submitted and control returns to the browser event loop.
func (*SurfaceTexture) CreateView ¶
func (st *SurfaceTexture) CreateView(desc *TextureViewDescriptor) (*TextureView, error)
CreateView creates a texture view of this surface texture.
Pass nil for desc to create a default view (all mips, all layers, same format).
func (*SurfaceTexture) Texture ¶ added in v0.28.0
func (st *SurfaceTexture) Texture() *Texture
Texture returns the underlying Texture. This is useful for operations that need direct texture access (e.g., creating additional views).
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture represents a GPU texture.
func NewTextureFromHAL ¶ added in v0.21.0
func NewTextureFromHAL(_ any, _ *Device, _ TextureFormat) *Texture
NewTextureFromHAL is not supported in the browser.
func (*Texture) Format ¶
func (t *Texture) Format() TextureFormat
Format returns the texture format.
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.
type TextureCopy ¶ added in v0.26.5
type TextureCopy struct {
Source ImageCopyTexture
Destination ImageCopyTexture
Size Extent3D
}
TextureCopy describes a texture-to-texture copy region.
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(_ any, _ *Device) *TextureView
NewTextureViewFromHAL is not supported in the browser.
func (*TextureView) Release ¶
func (v *TextureView) Release()
Release marks the texture view for destruction.
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
¶
- adapter_browser.go
- bind_browser.go
- buffer_browser.go
- computepass_browser.go
- descriptor_browser.go
- device_browser.go
- doc.go
- encoder_browser.go
- error_browser.go
- fence_browser.go
- gpucontext_sentinel.go
- instance_browser.go
- logger_browser.go
- map_pending_browser.go
- map_types_browser.go
- mapped_range_browser.go
- pipeline_browser.go
- queue_browser.go
- renderpass_browser.go
- sampler_browser.go
- shader_browser.go
- surface_browser.go
- texture_browser.go
- types.go
- wrap_browser.go
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. |
|
sw-test
command
Command sw-test validates the software rasterizer backend.
|
Command sw-test validates the software rasterizer backend. |
|
sw-triangle
command
Command sw-triangle renders a red triangle on a blue background using ONLY the software rasterizer backend.
|
Command sw-triangle renders a red triangle on a blue background using ONLY the software rasterizer 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
|
|
|
browser-compute
command
|
|
|
browser-test
command
|
|
|
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-particles
command
Command compute-particles demonstrates a GPU particle simulation using a compute shader.
|
Command compute-particles demonstrates a GPU particle simulation using 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. |
|
software-test
command
Command software-test verifies the SPIR-V interpreter on the software backend.
|
Command software-test verifies the SPIR-V interpreter on the software backend. |
|
triangle-headless
command
Command triangle-headless renders a triangle to an offscreen texture and writes the result to a PNG file.
|
Command triangle-headless renders a triangle to an offscreen texture and writes the result to a PNG file. |
|
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 shader execution for the software backend.
|
Package shader provides 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. |