Documentation
¶
Overview ¶
Package wgpu provides a GPU-accelerated rendering backend using gogpu/wgpu.
This backend leverages WebGPU for hardware-accelerated 2D graphics rendering. It uses the gogpu/wgpu Pure Go WebGPU implementation, which supports Vulkan, Metal, and DX12 backends depending on the platform.
Architecture Overview ¶
The wgpu backend implements a vello-style GPU rendering pipeline:
Scene Commands -> Decoder -> HybridPipeline (Flatten → Coarse → Fine) -> GPU -> Composite
Key components:
- WGPUBackend: Main entry point implementing backend.RenderBackend
- GPUSceneRenderer: Scene-to-GPU pipeline with HybridPipeline rasterization
- HybridPipeline: 3-stage path rasterization (Flatten, Coarse, Fine)
- MemoryManager: GPU texture memory with LRU eviction (configurable budget)
- TextureAtlas: Shelf-packing for efficient GPU memory usage
- PipelineCache: Pre-compiled GPU pipelines for all 29 blend modes
- ShaderModules: WGSL compute shaders for tile rasterization and blending
HybridPipeline (vello-style) ¶
Scene rendering uses a 3-stage tile-based pipeline inspired by Linebender's vello:
- Flatten: Bezier curves are flattened to line segments using Wang's formula
- Coarse: Line segments are binned into 4×4 pixel tiles with winding info
- Fine: Each tile's coverage is computed with anti-aliased edges
The pipeline automatically selects GPU or CPU execution per stage based on workload size. This hybrid approach provides optimal performance across different path complexities.
Example tile data for a circle:
Tile(X=10, Y=5): Coverage[16]=[32, 128, 255, 255, ...] // 4×4 pixel coverage Tile(X=11, Y=5): Coverage[16]=[255, 255, 255, 192, ...] // Adjacent tile ... (sparse tiles only where path intersects)
Blend Modes ¶
All 29 standard blend modes are supported via WGSL shaders:
Standard modes:
- Normal, Multiply, Screen, Overlay
- Darken, Lighten, ColorDodge, ColorBurn
- HardLight, SoftLight, Difference, Exclusion
HSL modes:
- Hue, Saturation, Color, Luminosity
Porter-Duff compositing:
- Clear, Copy, Destination
- SourceOver, DestinationOver
- SourceIn, DestinationIn
- SourceOut, DestinationOut
- SourceAtop, DestinationAtop
- Xor, Plus
Registration and Selection ¶
The wgpu backend is automatically registered when this package is imported:
import _ "github.com/gogpu/gg/backend/wgpu"
The backend will be preferred over the software backend when available. If GPU initialization fails, the system will fall back to software rendering.
Basic Usage ¶
Automatic backend selection (recommended):
b := backend.Default() // Returns wgpu if available, otherwise software
if err := b.Init(); err != nil {
log.Fatal(err)
}
defer b.Close()
Explicit wgpu backend selection:
b := backend.Get(backend.BackendWGPU)
if b == nil {
log.Fatal("wgpu backend not available")
}
if err := b.Init(); err != nil {
log.Fatal(err)
}
defer b.Close()
Rendering Scenes ¶
Build and render a scene:
// Create scene using SceneBuilder
builder := scene.NewSceneBuilder()
builder.FillRect(0, 0, 800, 600, scene.SolidBrush(gg.White))
builder.FillCircle(400, 300, 100, scene.SolidBrush(gg.Red))
// Add a blended layer
builder.Layer(scene.BlendMultiply, 0.8, nil, func(lb *scene.SceneBuilder) {
lb.FillRect(300, 200, 200, 200, scene.SolidBrush(gg.Blue))
})
s := builder.Build()
// Render to pixmap
pm := gg.NewPixmap(800, 600)
if err := b.RenderScene(pm, s); err != nil {
log.Printf("Render error: %v", err)
}
// Save result
pm.SavePNG("output.png")
Direct Scene Construction ¶
Lower-level scene construction:
s := scene.NewScene() rect := scene.NewRectShape(10, 10, 80, 80) s.Fill(scene.FillNonZero, scene.IdentityAffine(), scene.SolidBrush(gg.Red), rect) circle := scene.NewCircleShape(50, 50, 30) s.Fill(scene.FillNonZero, scene.TranslateAffine(100, 0), scene.SolidBrush(gg.Blue), circle) pm := gg.NewPixmap(200, 100) b.RenderScene(pm, s)
Performance Characteristics ¶
The GPU backend excels at:
- Large canvases (1080p and above)
- Many shapes with the same blend mode
- Complex layer compositing
- Parallel processing of independent draws
Software backend may be faster for:
- Small canvases (< 256x256)
- Single shape renders
- Frequent GPU-CPU data transfers
Memory Management ¶
The backend uses an LRU-based memory manager with configurable budget:
// Configure via GPUSceneRendererConfig
config := GPUSceneRendererConfig{
Width: 1920,
Height: 1080,
MaxLayers: 16, // Maximum layer stack depth
MemoryBudgetMB: 256, // GPU texture memory budget
}
When memory budget is exceeded, least-recently-used textures are evicted.
Current Status (v0.16.0) ¶
The GPU pipeline uses vello-style HybridPipeline architecture. The following components are fully implemented and tested:
- HybridPipeline: 3-stage path rasterization (Flatten → Coarse → Fine)
- Tile-based sparse coverage (4×4 pixel tiles)
- GPU/CPU automatic selection per stage
- Fill rule support (NonZero, EvenOdd)
- Anti-aliased coverage calculation
- Pipeline cache for all blend modes
- WGSL compute shaders (flatten.wgsl, coarse.wgsl, fine.wgsl)
- Memory management with LRU eviction
- Layer stack management
- Clip region support
GPU compute shader execution uses CPU fallback until HAL bridge is complete. This will be enabled when core↔HAL device/queue bridge is implemented:
- HAL device/queue wiring to HybridPipeline
- Texture readback (for downloading GPU results to CPU)
- Buffer mapping (for uploading vertex/uniform data)
All data flow through the pipeline is correct and tested.
Requirements ¶
- Go 1.25+ (for generic features)
- gogpu/wgpu module (github.com/gogpu/wgpu)
- A GPU that supports Vulkan, Metal, or DX12 (for actual GPU rendering)
Thread Safety ¶
WGPUBackend and GPUSceneRenderer are safe for concurrent use from multiple goroutines. Internal synchronization is handled via mutexes.
Error Handling ¶
Common errors returned by this package:
- ErrNotInitialized: Backend must be initialized before use
- ErrNoGPU: No compatible GPU found
- ErrDeviceLost: GPU device was lost (requires re-initialization)
- ErrNilTarget: Target pixmap is nil
- ErrNilScene: Scene is nil
- ErrRendererClosed: Renderer has been closed
- ErrEmptyScene: Scene contains no draw commands
Benchmarking ¶
Run benchmarks to compare GPU vs Software performance:
go test -bench=. ./backend/wgpu/...
Key benchmarks:
- BenchmarkClear1080p: Full canvas clear comparison
- BenchmarkRect100: 100 rectangles comparison
- BenchmarkCircle50: Circle rendering comparison
- BenchmarkLayers4: Layer compositing comparison
- BenchmarkPipelineCreation: GPU pipeline cache performance
Related Packages ¶
- github.com/gogpu/gg: Core 2D graphics library
- github.com/gogpu/gg/scene: Scene graph and retained mode API
- github.com/gogpu/gg/backend: Backend interface and registry
- github.com/gogpu/wgpu: Pure Go WebGPU implementation
References ¶
- W3C WebGPU Specification: https://www.w3.org/TR/webgpu/
- gogpu Organization: https://github.com/gogpu
- gogpu/wgpu: https://github.com/gogpu/wgpu
Package wgpu provides GPU-accelerated rendering using WebGPU.
Package wgpu provides GPU-accelerated rendering using WebGPU.
Package wgpu provides GPU-accelerated rendering using WebGPU.
Package wgpu provides GPU-accelerated rendering backend using WebGPU.
Package wgpu provides GPU-accelerated rendering using WebGPU.
Index ¶
- Constants
- Variables
- func BlendModeToShader(mode scene.BlendMode) uint32
- func BlendTileSIMD(buffer []uint8, bufferStride int, baseX, baseY int, coverage *TileCoverage16, ...)
- func CheckDeviceLimits(deviceID core.DeviceID) error
- func CheckGPUComputeSupport(device hal.Device) bool
- func FillRuleToGPU(rule scene.FillStyle) uint32
- func FinalizeTileSIMD(tileWinding *TileWinding16, coverage *TileCoverage16, fillRule scene.FillStyle)
- func GetBlendShaderSource() string
- func GetBlitShaderSource() string
- func GetCompositeShaderSource() string
- func GetMSDFTextShaderSource() string
- func GetStripShaderSource() string
- func InitTileWindingSIMD(tileWinding *TileWinding16, backdrop float32)
- func PixelToTile(px, py int32) (tx, ty int32)
- func PixelToTileF(px, py float32) (tx, ty int32)
- func ProcessSegmentSIMD(line LineSegment, tileX, tileY uint16, tileWinding *TileWinding16)
- func ShaderToBlendMode(shaderMode uint32) scene.BlendMode
- func ValidateBlendModeMapping() error
- type ActiveEdge
- type ActiveEdgeTable
- func (aet *ActiveEdgeTable) Active() []ActiveEdge
- func (aet *ActiveEdgeTable) InsertEdge(e *Edge, y float32)
- func (aet *ActiveEdgeTable) Len() int
- func (aet *ActiveEdgeTable) RemoveExpired(y float32)
- func (aet *ActiveEdgeTable) Reset()
- func (aet *ActiveEdgeTable) SortByX()
- func (aet *ActiveEdgeTable) UpdateX(y float32)
- type AtlasRegion
- type BindGroupBuilder
- type BlendParams
- type CoarseRasterizer
- func (cr *CoarseRasterizer) CalculateBackdrop() []int32
- func (cr *CoarseRasterizer) Entries() []CoarseTileEntry
- func (cr *CoarseRasterizer) EntriesAtLocation(x, y uint16) []CoarseTileEntry
- func (cr *CoarseRasterizer) Grid() *TileGrid
- func (cr *CoarseRasterizer) NewIterator() *CoarseTileIterator
- func (cr *CoarseRasterizer) Rasterize(segments *SegmentList)
- func (cr *CoarseRasterizer) Reset()
- func (cr *CoarseRasterizer) Segments() *SegmentList
- func (cr *CoarseRasterizer) SortEntries()
- func (cr *CoarseRasterizer) TileColumns() uint16
- func (cr *CoarseRasterizer) TileRows() uint16
- type CoarseTileEntry
- type CoarseTileIterator
- type CommandBuffer
- type CommandEncoder
- func (e *CommandEncoder) BeginComputePass() *ComputePass
- func (e *CommandEncoder) BeginRenderPass(target *GPUTexture, clearTarget bool) *RenderPass
- func (e *CommandEncoder) CopyTextureToBuffer(src *GPUTexture, dst StubBufferID, bytesPerRow uint32)
- func (e *CommandEncoder) CopyTextureToTexture(src, dst *GPUTexture, width, height int)
- func (e *CommandEncoder) Finish() StubCommandBufferID
- func (e *CommandEncoder) PassCount() int
- type CompositeParams
- type ComputeCommandBuilder
- func (b *ComputeCommandBuilder) Dispatch(x, y, z uint32) *ComputeCommandBuilder
- func (b *ComputeCommandBuilder) DispatchForSize(size, groupSize uint32) *ComputeCommandBuilder
- func (b *ComputeCommandBuilder) Finish() StubCommandBufferID
- func (b *ComputeCommandBuilder) SetBindGroup(index uint32, bindGroup StubBindGroupID) *ComputeCommandBuilder
- func (b *ComputeCommandBuilder) SetPipeline(pipeline StubComputePipelineID) *ComputeCommandBuilder
- type ComputePass
- func (p *ComputePass) DispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ uint32)
- func (p *ComputePass) DispatchWorkgroupsForSize(workSize, workgroupSize uint32)
- func (p *ComputePass) End()
- func (p *ComputePass) SetBindGroup(index uint32, bindGroup StubBindGroupID)
- func (p *ComputePass) SetPipeline(pipeline StubComputePipelineID)
- type Edge
- type EdgeList
- type FineRasterizer
- func (fr *FineRasterizer) FillRule() scene.FillStyle
- func (fr *FineRasterizer) Grid() *TileGrid
- func (fr *FineRasterizer) Rasterize(coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32)
- func (fr *FineRasterizer) RenderToBuffer(buffer []uint8, width, height int, stride int, color [4]uint8)
- func (fr *FineRasterizer) RenderToBufferSIMD(buffer []uint8, width, height int, stride int, color [4]uint8)
- func (fr *FineRasterizer) Reset()
- func (fr *FineRasterizer) SetFillRule(rule scene.FillStyle)
- type FlattenContext
- type GPUAffineTransform
- type GPUCoarseConfig
- type GPUCoarseRasterizer
- func (r *GPUCoarseRasterizer) Destroy()
- func (r *GPUCoarseRasterizer) GetTileEntries(coarse *CoarseRasterizer) []GPUTileSegmentRef
- func (r *GPUCoarseRasterizer) IsInitialized() bool
- func (r *GPUCoarseRasterizer) IsShaderReady() bool
- func (r *GPUCoarseRasterizer) Rasterize(segments *SegmentList) ([]GPUTileSegmentRef, error)
- func (r *GPUCoarseRasterizer) SPIRVCode() []uint32
- func (r *GPUCoarseRasterizer) TileColumns() uint16
- func (r *GPUCoarseRasterizer) TileRows() uint16
- type GPUCursorState
- type GPUFineConfig
- type GPUFineRasterizer
- func (r *GPUFineRasterizer) Destroy()
- func (r *GPUFineRasterizer) IsInitialized() bool
- func (r *GPUFineRasterizer) IsShaderReady() bool
- func (r *GPUFineRasterizer) Rasterize(coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32, ...) ([]uint8, error)
- func (r *GPUFineRasterizer) SPIRVCode() []uint32
- type GPUFlattenConfig
- type GPUFlattenRasterizer
- func (r *GPUFlattenRasterizer) ComputeCursorStates(path *scene.Path) []GPUCursorState
- func (r *GPUFlattenRasterizer) ConvertPathToGPU(path *scene.Path) ([]GPUPathElement, []float32)
- func (r *GPUFlattenRasterizer) Destroy()
- func (r *GPUFlattenRasterizer) EstimateSegmentCount(path *scene.Path, transform scene.Affine, tolerance float32) int
- func (r *GPUFlattenRasterizer) Flatten(path *scene.Path, transform scene.Affine, tolerance float32) (*SegmentList, error)
- func (r *GPUFlattenRasterizer) FlattenWithContext(path *scene.Path, transform scene.Affine, tolerance float32) *SegmentList
- func (r *GPUFlattenRasterizer) IsInitialized() bool
- func (r *GPUFlattenRasterizer) IsShaderReady() bool
- func (r *GPUFlattenRasterizer) MaxPaths() int
- func (r *GPUFlattenRasterizer) MaxSegments() int
- func (r *GPUFlattenRasterizer) SPIRVCode() []uint32
- func (r *GPUFlattenRasterizer) SetTolerance(tolerance float32)
- func (r *GPUFlattenRasterizer) Tolerance() float32
- type GPUInfo
- type GPUPathElement
- type GPURasterizer
- type GPURasterizerStats
- type GPURenderer
- type GPUSceneRenderer
- func (r *GPUSceneRenderer) Close()
- func (r *GPUSceneRenderer) Height() int
- func (r *GPUSceneRenderer) LayerDepth() int
- func (r *GPUSceneRenderer) MemoryStats() MemoryStats
- func (r *GPUSceneRenderer) RenderScene(s *scene.Scene) error
- func (r *GPUSceneRenderer) RenderSceneWithContext(ctx context.Context, s *scene.Scene) error
- func (r *GPUSceneRenderer) RenderToPixmap(target *gg.Pixmap, s *scene.Scene) error
- func (r *GPUSceneRenderer) RenderToPixmapWithContext(ctx context.Context, target *gg.Pixmap, s *scene.Scene) error
- func (r *GPUSceneRenderer) Resize(width, height int) error
- func (r *GPUSceneRenderer) Width() int
- type GPUSceneRendererConfig
- type GPUSegment
- type GPUSegmentCount
- type GPUTexture
- func (t *GPUTexture) Close()
- func (t *GPUTexture) DownloadPixmap() (*gg.Pixmap, error)
- func (t *GPUTexture) Format() TextureFormat
- func (t *GPUTexture) Height() int
- func (t *GPUTexture) IsReleased() bool
- func (t *GPUTexture) Label() string
- func (t *GPUTexture) SetMemoryManager(m *MemoryManager)
- func (t *GPUTexture) SizeBytes() uint64
- func (t *GPUTexture) String() string
- func (t *GPUTexture) TextureID() core.TextureID
- func (t *GPUTexture) UploadPixmap(pixmap *gg.Pixmap) error
- func (t *GPUTexture) UploadRegion(x, y int, pixmap *gg.Pixmap) error
- func (t *GPUTexture) ViewID() core.TextureViewID
- func (t *GPUTexture) Width() int
- type GPUTileInfo
- type GPUTileSegmentRef
- type GridRasterParams
- type HybridFineRasterizer
- func (h *HybridFineRasterizer) Destroy()
- func (h *HybridFineRasterizer) FillRule() scene.FillStyle
- func (h *HybridFineRasterizer) Grid() *TileGrid
- func (h *HybridFineRasterizer) IsGPUAvailable() bool
- func (h *HybridFineRasterizer) Rasterize(coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32)
- func (h *HybridFineRasterizer) Reset()
- func (h *HybridFineRasterizer) SetFillRule(rule scene.FillStyle)
- func (h *HybridFineRasterizer) Stats() GPURasterizerStats
- type HybridFineRasterizerConfig
- type HybridPipeline
- func (p *HybridPipeline) Destroy()
- func (p *HybridPipeline) Grid() *TileGrid
- func (p *HybridPipeline) IsGPUAvailable() bool
- func (p *HybridPipeline) IsStageGPUAvailable(stage PipelineStage) bool
- func (p *HybridPipeline) RasterizePath(path *scene.Path, transform scene.Affine, fillRule scene.FillStyle) *TileGrid
- func (p *HybridPipeline) Reset()
- func (p *HybridPipeline) ResetStats()
- func (p *HybridPipeline) SetFillRule(rule scene.FillStyle)
- func (p *HybridPipeline) SetTolerance(tolerance float32)
- func (p *HybridPipeline) Stats() HybridPipelineStats
- type HybridPipelineConfig
- type HybridPipelineStats
- type IndexFormat
- type LayerDescriptor
- type LineSegment
- func (s *LineSegment) Bounds() (minX, minY, maxX, maxY float32)
- func (s *LineSegment) CrossesTileRow(tileY int32) bool
- func (s *LineSegment) DeltaX() float32
- func (s *LineSegment) DeltaY() float32
- func (s *LineSegment) InverseSlope() float32
- func (s *LineSegment) IsHorizontal() bool
- func (s *LineSegment) IsVertical() bool
- func (s *LineSegment) Slope() float32
- func (s *LineSegment) TileXRange(tileY int32) (minTileX, maxTileX int32)
- func (s *LineSegment) XAtY(y float32) float32
- func (s *LineSegment) YAtX(x float32) float32
- type MemoryManager
- func (m *MemoryManager) AllocTexture(config TextureConfig) (*GPUTexture, error)
- func (m *MemoryManager) Close()
- func (m *MemoryManager) Contains(tex *GPUTexture) bool
- func (m *MemoryManager) FreeTexture(tex *GPUTexture) error
- func (m *MemoryManager) SetBudget(megabytes int) error
- func (m *MemoryManager) Stats() MemoryStats
- func (m *MemoryManager) Textures() []*GPUTexture
- func (m *MemoryManager) TouchTexture(tex *GPUTexture)
- type MemoryManagerConfig
- type MemoryStats
- type PipelineCache
- func (pc *PipelineCache) BlendPipelineCount() int
- func (pc *PipelineCache) Close()
- func (pc *PipelineCache) CreateBlendBindGroup(tex *GPUTexture, params *BlendParams) StubBindGroupID
- func (pc *PipelineCache) CreateBlitBindGroup(tex *GPUTexture) StubBindGroupID
- func (pc *PipelineCache) CreateStripBindGroup(headerBuffer StubBufferID, coverageBuffer StubBufferID, outputTex *GPUTexture, ...) StubBindGroupID
- func (pc *PipelineCache) GetBlendLayout() StubBindGroupLayoutID
- func (pc *PipelineCache) GetBlendPipeline(mode scene.BlendMode) StubPipelineID
- func (pc *PipelineCache) GetBlitLayout() StubBindGroupLayoutID
- func (pc *PipelineCache) GetBlitPipeline() StubPipelineID
- func (pc *PipelineCache) GetCompositePipeline() StubPipelineID
- func (pc *PipelineCache) GetStripLayout() StubBindGroupLayoutID
- func (pc *PipelineCache) GetStripPipeline() StubComputePipelineID
- func (pc *PipelineCache) IsInitialized() bool
- func (pc *PipelineCache) WarmupBlendPipelines()
- type PipelineStage
- type QueueSubmitter
- type RectAllocator
- type RenderCommandBuilder
- func (b *RenderCommandBuilder) Draw(vertexCount, instanceCount uint32) *RenderCommandBuilder
- func (b *RenderCommandBuilder) DrawFullScreen() *RenderCommandBuilder
- func (b *RenderCommandBuilder) Finish() StubCommandBufferID
- func (b *RenderCommandBuilder) SetBindGroup(index uint32, bindGroup StubBindGroupID) *RenderCommandBuilder
- func (b *RenderCommandBuilder) SetPipeline(pipeline StubPipelineID) *RenderCommandBuilder
- type RenderPass
- func (p *RenderPass) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
- func (p *RenderPass) DrawFullScreenTriangle()
- func (p *RenderPass) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, ...)
- func (p *RenderPass) End()
- func (p *RenderPass) SetBindGroup(index uint32, bindGroup StubBindGroupID)
- func (p *RenderPass) SetIndexBuffer(buffer StubBufferID, format IndexFormat)
- func (p *RenderPass) SetPipeline(pipeline StubPipelineID)
- func (p *RenderPass) SetVertexBuffer(slot uint32, buffer StubBufferID)
- func (p *RenderPass) Target() *GPUTexture
- type SegmentList
- func (sl *SegmentList) Add(seg LineSegment)
- func (sl *SegmentList) AddLine(x0, y0, x1, y1 float32, winding int8)
- func (sl *SegmentList) Bounds() (minX, minY, maxX, maxY float32)
- func (sl *SegmentList) Len() int
- func (sl *SegmentList) Reset()
- func (sl *SegmentList) Segments() []LineSegment
- func (sl *SegmentList) SegmentsInTileRow(tileY int32) []LineSegment
- func (sl *SegmentList) SortByTileY()
- func (sl *SegmentList) TileYRange() (minTileY, maxTileY int32)
- type ShaderModuleID
- type ShaderModules
- type SparseStrip
- type SparseStripsConfig
- type SparseStripsPool
- type SparseStripsRasterizer
- func (ssr *SparseStripsRasterizer) FillRule() scene.FillStyle
- func (ssr *SparseStripsRasterizer) GetStats() Stats
- func (ssr *SparseStripsRasterizer) Grid() *TileGrid
- func (ssr *SparseStripsRasterizer) Height() uint16
- func (ssr *SparseStripsRasterizer) RasterizePath(path *scene.Path, transform scene.Affine, tolerance float32)
- func (ssr *SparseStripsRasterizer) RasterizeToStrips(path *scene.Path, transform scene.Affine, tolerance float32)
- func (ssr *SparseStripsRasterizer) RenderStripsToBuffer(buffer []uint8, stride int, color [4]uint8)
- func (ssr *SparseStripsRasterizer) RenderToBuffer(buffer []uint8, stride int, color [4]uint8)
- func (ssr *SparseStripsRasterizer) Reset()
- func (ssr *SparseStripsRasterizer) Segments() *SegmentList
- func (ssr *SparseStripsRasterizer) SetFillRule(rule scene.FillStyle)
- func (ssr *SparseStripsRasterizer) SetSize(width, height uint16)
- func (ssr *SparseStripsRasterizer) Strips() *StripRenderer
- func (ssr *SparseStripsRasterizer) Width() uint16
- type Stats
- type StripParams
- type StripRenderer
- func (sr *StripRenderer) Alphas() []uint8
- func (sr *StripRenderer) RenderTiles(coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32)
- func (sr *StripRenderer) Reset()
- func (sr *StripRenderer) SetAliasMode(enabled bool)
- func (sr *StripRenderer) SetFillRule(rule scene.FillStyle)
- func (sr *StripRenderer) Strips() []SparseStrip
- type StubBindGroupID
- type StubBindGroupLayoutID
- type StubBufferID
- type StubCommandBufferID
- type StubCommandEncoderID
- type StubComputePassID
- type StubComputePipelineID
- type StubPipelineID
- type StubRenderPassID
- type StubSamplerID
- type TextBatch
- type TextPipeline
- func (p *TextPipeline) Close()
- func (p *TextPipeline) Config() TextPipelineConfig
- func (p *TextPipeline) GetOrCreateAtlasBindGroup(atlasIndex int, atlasTexture *GPUTexture) (StubBindGroupID, error)
- func (p *TextPipeline) Init() error
- func (p *TextPipeline) InvalidateAllAtlasBindGroups()
- func (p *TextPipeline) InvalidateAtlasBindGroup(atlasIndex int)
- func (p *TextPipeline) IsInitialized() bool
- func (p *TextPipeline) RenderText(pass *RenderPass, quads []TextQuad, atlasIndex int, color gg.RGBA, ...) error
- func (p *TextPipeline) RenderTextBatch(pass *RenderPass, batches []TextBatch, atlasIndex int) error
- type TextPipelineConfig
- type TextQuad
- type TextRenderer
- type TextRendererConfig
- type TextUniforms
- type TextVertex
- type TextureAtlas
- func (a *TextureAtlas) AllocCount() int
- func (a *TextureAtlas) Allocate(width, height int) (AtlasRegion, error)
- func (a *TextureAtlas) AllocateAndUpload(pixmap *gg.Pixmap) (AtlasRegion, error)
- func (a *TextureAtlas) Close()
- func (a *TextureAtlas) Height() int
- func (a *TextureAtlas) IsClosed() bool
- func (a *TextureAtlas) Reset()
- func (a *TextureAtlas) Texture() *GPUTexture
- func (a *TextureAtlas) Upload(region AtlasRegion, pixmap *gg.Pixmap) error
- func (a *TextureAtlas) Utilization() float64
- func (a *TextureAtlas) Width() int
- type TextureAtlasConfig
- type TextureConfig
- type TextureFormat
- type Tile
- type TileCoord
- type TileCoverage16
- type TileGrid
- func (g *TileGrid) Bounds() (minX, minY, maxX, maxY int32)
- func (g *TileGrid) FillRule() scene.FillStyle
- func (g *TileGrid) ForEach(fn func(*Tile))
- func (g *TileGrid) ForEachInRow(y int32, fn func(*Tile))
- func (g *TileGrid) ForEachSorted(fn func(*Tile))
- func (g *TileGrid) Get(x, y int32) *Tile
- func (g *TileGrid) GetOrCreate(x, y int32) *Tile
- func (g *TileGrid) Has(x, y int32) bool
- func (g *TileGrid) PixelBounds() scene.Rect
- func (g *TileGrid) Reset()
- func (g *TileGrid) SetFillRule(rule scene.FillStyle)
- func (g *TileGrid) TileCount() int
- type TilePool
- type TileWinding16
- type WGPUBackend
- func (b *WGPUBackend) Close()
- func (b *WGPUBackend) Device() core.DeviceID
- func (b *WGPUBackend) GPUInfo() *GPUInfo
- func (b *WGPUBackend) Init() error
- func (b *WGPUBackend) IsInitialized() bool
- func (b *WGPUBackend) Name() string
- func (b *WGPUBackend) NewRenderer(width, height int) gg.Renderer
- func (b *WGPUBackend) Queue() core.QueueID
- func (b *WGPUBackend) RenderScene(target *gg.Pixmap, s *scene.Scene) error
Constants ¶
const ( // DefaultAtlasSize is the default atlas dimension (2048x2048). DefaultAtlasSize = 2048 // MinAtlasSize is the minimum atlas dimension (256x256). MinAtlasSize = 256 // DefaultShelfPadding is the padding between shelves. DefaultShelfPadding = 1 )
Default atlas settings.
const ( // DefaultMaxMemoryMB is the default maximum GPU memory budget (256 MB). DefaultMaxMemoryMB = 256 // DefaultEvictionThreshold is when eviction starts (80% of budget). DefaultEvictionThreshold = 0.8 // MinMemoryMB is the minimum allowed memory budget (16 MB). MinMemoryMB = 16 )
Default memory limits.
const ( // Standard blend modes (0-11) ShaderBlendNormal uint32 = 0 ShaderBlendMultiply uint32 = 1 ShaderBlendScreen uint32 = 2 ShaderBlendOverlay uint32 = 3 ShaderBlendDarken uint32 = 4 ShaderBlendLighten uint32 = 5 ShaderBlendColorDodge uint32 = 6 ShaderBlendColorBurn uint32 = 7 ShaderBlendHardLight uint32 = 8 ShaderBlendSoftLight uint32 = 9 ShaderBlendDifference uint32 = 10 ShaderBlendExclusion uint32 = 11 // HSL blend modes (12-15) ShaderBlendHue uint32 = 12 ShaderBlendSaturation uint32 = 13 ShaderBlendColor uint32 = 14 ShaderBlendLuminosity uint32 = 15 // Porter-Duff modes (16-28) ShaderBlendClear uint32 = 16 ShaderBlendCopy uint32 = 17 ShaderBlendDestination uint32 = 18 ShaderBlendSourceOver uint32 = 19 ShaderBlendDestinationOver uint32 = 20 ShaderBlendSourceIn uint32 = 21 ShaderBlendDestinationIn uint32 = 22 ShaderBlendSourceOut uint32 = 23 ShaderBlendDestinationOut uint32 = 24 ShaderBlendSourceAtop uint32 = 25 ShaderBlendDestinationAtop uint32 = 26 ShaderBlendXor uint32 = 27 ShaderBlendPlus uint32 = 28 )
Blend mode constants matching scene.BlendMode values. These are used for GPU shader uniform values.
const DefaultCoarseThreshold = 100
DefaultCoarseThreshold is the minimum segments for GPU coarse rasterization.
const DefaultFineThreshold = 100
DefaultFineThreshold is the minimum tile entries for GPU fine rasterization.
const DefaultFlattenThreshold = 50
DefaultFlattenThreshold is the minimum path elements for GPU flattening.
const DefaultGPUSegmentThreshold = 100
DefaultGPUSegmentThreshold is the minimum number of segments to use GPU. Below this threshold, CPU is typically faster due to GPU dispatch overhead.
const DefaultTextureUsage = types.TextureUsageCopySrc | types.TextureUsageCopyDst | types.TextureUsageTextureBinding
DefaultTextureUsage is the default usage for textures created without specific flags.
const FlattenMaxSegmentsPerCurve = 64
FlattenMaxSegmentsPerCurve is the maximum segments generated per curve.
const FlattenTolerance = 0.25
FlattenTolerance is the default tolerance for curve flattening. Smaller values produce more accurate curves but more segments.
const TileHeight = TileSize
TileHeight is the height of a tile in pixels (matches TileSize).
const TileMask = TileSize - 1
TileMask is TileSize - 1 for efficient modulo.
const TileShift = 2
TileShift is log2(TileSize) for efficient division.
const TileSize = 4
TileSize is the width and height of a tile in pixels. 4×4 is optimal for cache efficiency and SIMD processing.
const TileWidth = TileSize
TileWidth is the width of a tile in pixels (matches TileSize).
Variables ¶
var ( // ErrAtlasFull is returned when the atlas cannot fit the requested region. ErrAtlasFull = errors.New("wgpu: texture atlas is full") // ErrAtlasClosed is returned when operating on a closed atlas. ErrAtlasClosed = errors.New("wgpu: texture atlas is closed") // ErrRegionOutOfBounds is returned when a region is outside atlas bounds. ErrRegionOutOfBounds = errors.New("wgpu: region is outside atlas bounds") )
Atlas-related errors.
var ( // ErrNotInitialized is returned when operations are called before Init. ErrNotInitialized = errors.New("wgpu: backend not initialized") // ErrNoGPU is returned when no GPU adapter is available. ErrNoGPU = errors.New("wgpu: no GPU adapter available") // ErrDeviceLost is returned when the GPU device is lost. ErrDeviceLost = errors.New("wgpu: GPU device lost") // ErrNotImplemented is returned for stub operations not yet implemented. ErrNotImplemented = errors.New("wgpu: operation not implemented") // ErrInvalidDimensions is returned when width or height is invalid. ErrInvalidDimensions = errors.New("wgpu: invalid dimensions") // ErrNilTarget is returned when target pixmap is nil. ErrNilTarget = errors.New("wgpu: nil target pixmap") // ErrNilScene is returned when scene is nil. ErrNilScene = errors.New("wgpu: nil scene") )
Package errors for wgpu backend.
var ( // ErrMemoryBudgetExceeded is returned when allocation would exceed budget. ErrMemoryBudgetExceeded = errors.New("wgpu: memory budget exceeded") // ErrMemoryManagerClosed is returned when operating on a closed manager. ErrMemoryManagerClosed = errors.New("wgpu: memory manager closed") // ErrTextureNotFound is returned when a texture is not found in the manager. ErrTextureNotFound = errors.New("wgpu: texture not found in manager") )
Memory management errors.
var ( // ErrRendererClosed is returned when operating on a closed renderer. ErrRendererClosed = errors.New("wgpu: renderer closed") // ErrEmptyScene is returned when rendering an empty scene. ErrEmptyScene = errors.New("wgpu: empty scene") // ErrLayerStackUnderflow is returned when popping more layers than pushed. ErrLayerStackUnderflow = errors.New("wgpu: layer stack underflow") )
Renderer-specific errors.
var ( // ErrNilTextPipeline is returned when operating on a nil pipeline. ErrNilTextPipeline = errors.New("wgpu: text pipeline is nil") // ErrTextPipelineNotInitialized is returned when pipeline is not initialized. ErrTextPipelineNotInitialized = errors.New("wgpu: text pipeline not initialized") // ErrNoQuadsToRender is returned when RenderText is called with empty quads. ErrNoQuadsToRender = errors.New("wgpu: no quads to render") // ErrQuadBufferOverflow is returned when too many quads are submitted. ErrQuadBufferOverflow = errors.New("wgpu: quad buffer overflow") // ErrInvalidAtlasIndex is returned when referencing invalid atlas. ErrInvalidAtlasIndex = errors.New("wgpu: invalid atlas index") )
Text rendering errors.
var ( // ErrTextureReleased is returned when operating on a released texture. ErrTextureReleased = errors.New("wgpu: texture has been released") // ErrTextureSizeMismatch is returned when pixmap size doesn't match texture. ErrTextureSizeMismatch = errors.New("wgpu: pixmap size does not match texture") // ErrNilPixmap is returned when pixmap is nil. ErrNilPixmap = errors.New("wgpu: pixmap is nil") // ErrTextureReadbackNotSupported is returned when readback is not available. ErrTextureReadbackNotSupported = errors.New("wgpu: texture readback not supported (stub)") )
Texture-related errors.
var ErrNilBackend = errors.New("wgpu: backend is nil")
ErrNilBackend is returned when backend is nil.
Functions ¶
func BlendModeToShader ¶
BlendModeToShader converts a scene.BlendMode to the shader constant value. The values are designed to match directly, so this is primarily for type safety.
func BlendTileSIMD ¶ added in v0.15.0
func BlendTileSIMD( buffer []uint8, bufferStride int, baseX, baseY int, coverage *TileCoverage16, color [4]uint8, )
BlendTileSIMD performs alpha blending for a 4×4 tile using SIMD. Uses U16x16 for processing all 16 pixels at once.
func CheckDeviceLimits ¶
CheckDeviceLimits verifies that the device meets minimum requirements. This can be used to validate GPU capabilities before rendering.
func CheckGPUComputeSupport ¶ added in v0.15.0
CheckGPUComputeSupport checks if GPU compute shaders are supported. This can be used to determine if GPU rasterization is viable before creating a rasterizer.
func FillRuleToGPU ¶ added in v0.15.0
FillRuleToGPU converts scene.FillStyle to GPU constant.
func FinalizeTileSIMD ¶ added in v0.15.0
func FinalizeTileSIMD( tileWinding *TileWinding16, coverage *TileCoverage16, fillRule scene.FillStyle, )
FinalizeTileSIMD converts winding values to coverage using SIMD. Supports both NonZero and EvenOdd fill rules.
func GetBlendShaderSource ¶
func GetBlendShaderSource() string
GetBlendShaderSource returns the WGSL source for the blend shader.
func GetBlitShaderSource ¶
func GetBlitShaderSource() string
GetBlitShaderSource returns the WGSL source for the blit shader.
func GetCompositeShaderSource ¶
func GetCompositeShaderSource() string
GetCompositeShaderSource returns the WGSL source for the composite shader.
func GetMSDFTextShaderSource ¶ added in v0.11.0
func GetMSDFTextShaderSource() string
GetMSDFTextShaderSource returns the WGSL source for the MSDF text shader.
func GetStripShaderSource ¶
func GetStripShaderSource() string
GetStripShaderSource returns the WGSL source for the strip shader.
func InitTileWindingSIMD ¶ added in v0.15.0
func InitTileWindingSIMD(tileWinding *TileWinding16, backdrop float32)
InitTileWindingSIMD initializes tile winding from backdrop using SIMD.
func PixelToTile ¶ added in v0.15.0
PixelToTile converts pixel coordinates to tile coordinates. Uses arithmetic shift which provides floor division for negative numbers.
func PixelToTileF ¶ added in v0.15.0
PixelToTileF converts float pixel coordinates to tile coordinates. Uses floor semantics for correct handling of negative coordinates.
func ProcessSegmentSIMD ¶ added in v0.15.0
func ProcessSegmentSIMD( line LineSegment, tileX, tileY uint16, tileWinding *TileWinding16, )
ProcessSegmentSIMD processes a line segment's contribution to a tile using SIMD. This is a vectorized version of processSegment for the FineRasterizer.
func ShaderToBlendMode ¶
ShaderToBlendMode converts a shader blend mode constant to scene.BlendMode.
func ValidateBlendModeMapping ¶
func ValidateBlendModeMapping() error
ValidateBlendModeMapping verifies that shader constants match scene.BlendMode values. Returns an error if any mismatch is found.
Types ¶
type ActiveEdge ¶
ActiveEdge holds an edge with its current X position.
type ActiveEdgeTable ¶
type ActiveEdgeTable struct {
// contains filtered or unexported fields
}
ActiveEdgeTable manages active edges during scanline conversion.
func NewActiveEdgeTable ¶
func NewActiveEdgeTable() *ActiveEdgeTable
NewActiveEdgeTable creates a new active edge table.
func (*ActiveEdgeTable) Active ¶
func (aet *ActiveEdgeTable) Active() []ActiveEdge
Active returns the list of active edges for iteration.
func (*ActiveEdgeTable) InsertEdge ¶
func (aet *ActiveEdgeTable) InsertEdge(e *Edge, y float32)
InsertEdge adds an edge to the active list.
func (*ActiveEdgeTable) Len ¶
func (aet *ActiveEdgeTable) Len() int
Len returns the number of active edges.
func (*ActiveEdgeTable) RemoveExpired ¶
func (aet *ActiveEdgeTable) RemoveExpired(y float32)
RemoveExpired removes edges that end at or before the given Y.
func (*ActiveEdgeTable) Reset ¶
func (aet *ActiveEdgeTable) Reset()
Reset clears the active edge table.
func (*ActiveEdgeTable) SortByX ¶
func (aet *ActiveEdgeTable) SortByX()
SortByX sorts active edges by their current X position.
func (*ActiveEdgeTable) UpdateX ¶
func (aet *ActiveEdgeTable) UpdateX(y float32)
UpdateX updates X positions for all active edges at the new Y.
type AtlasRegion ¶
type AtlasRegion struct {
// X is the left edge of the region.
X int
// Y is the top edge of the region.
Y int
// Width is the region width.
Width int
// Height is the region height.
Height int
}
AtlasRegion represents a rectangular region in a texture atlas.
func (AtlasRegion) Contains ¶
func (r AtlasRegion) Contains(x, y int) bool
Contains returns true if the point (x, y) is inside the region.
func (AtlasRegion) IsValid ¶
func (r AtlasRegion) IsValid() bool
IsValid returns true if the region has valid dimensions.
func (AtlasRegion) String ¶
func (r AtlasRegion) String() string
String returns a string representation of the region.
type BindGroupBuilder ¶
type BindGroupBuilder struct {
// contains filtered or unexported fields
}
BindGroupBuilder helps construct bind groups for rendering.
func NewBindGroupBuilder ¶
func NewBindGroupBuilder(device core.DeviceID, layout StubBindGroupLayoutID) *BindGroupBuilder
NewBindGroupBuilder creates a new bind group builder.
func (*BindGroupBuilder) Build ¶
func (b *BindGroupBuilder) Build() StubBindGroupID
Build creates the bind group. Currently returns a stub.
type BlendParams ¶
type BlendParams struct {
Mode uint32 // Blend mode enum value
Alpha float32 // Layer opacity (0.0 - 1.0)
Padding [2]float32
}
BlendParams represents the uniform buffer structure for blend shaders. This matches the BlendParams struct in blend.wgsl.
type CoarseRasterizer ¶ added in v0.15.0
type CoarseRasterizer struct {
// contains filtered or unexported fields
}
CoarseRasterizer performs coarse rasterization of line segments into tiles. It bins segments into the tiles they intersect and tracks winding information.
func NewCoarseRasterizer ¶ added in v0.15.0
func NewCoarseRasterizer(width, height uint16) *CoarseRasterizer
NewCoarseRasterizer creates a new coarse rasterizer for the given dimensions.
func (*CoarseRasterizer) CalculateBackdrop ¶ added in v0.15.0
func (cr *CoarseRasterizer) CalculateBackdrop() []int32
CalculateBackdrop calculates the backdrop winding for fine rasterization. Returns a slice of backdrop values indexed by [y * columns + x].
func (*CoarseRasterizer) Entries ¶ added in v0.15.0
func (cr *CoarseRasterizer) Entries() []CoarseTileEntry
Entries returns the coarse tile entries.
func (*CoarseRasterizer) EntriesAtLocation ¶ added in v0.15.0
func (cr *CoarseRasterizer) EntriesAtLocation(x, y uint16) []CoarseTileEntry
EntriesAtLocation returns all entries at the given tile location.
func (*CoarseRasterizer) Grid ¶ added in v0.15.0
func (cr *CoarseRasterizer) Grid() *TileGrid
Grid returns the tile grid after rasterization.
func (*CoarseRasterizer) NewIterator ¶ added in v0.15.0
func (cr *CoarseRasterizer) NewIterator() *CoarseTileIterator
NewIterator creates an iterator for the coarse tile entries.
func (*CoarseRasterizer) Rasterize ¶ added in v0.15.0
func (cr *CoarseRasterizer) Rasterize(segments *SegmentList)
Rasterize performs coarse rasterization of segments into tiles. It determines which tiles each segment intersects and calculates winding.
func (*CoarseRasterizer) Reset ¶ added in v0.15.0
func (cr *CoarseRasterizer) Reset()
Reset clears the rasterizer state for reuse.
func (*CoarseRasterizer) Segments ¶ added in v0.15.0
func (cr *CoarseRasterizer) Segments() *SegmentList
Segments returns the segment list.
func (*CoarseRasterizer) SortEntries ¶ added in v0.15.0
func (cr *CoarseRasterizer) SortEntries()
SortEntries sorts the entries for efficient rendering. Tiles are sorted by Y, then X, then line index.
func (*CoarseRasterizer) TileColumns ¶ added in v0.15.0
func (cr *CoarseRasterizer) TileColumns() uint16
TileColumns returns the number of tile columns.
func (*CoarseRasterizer) TileRows ¶ added in v0.15.0
func (cr *CoarseRasterizer) TileRows() uint16
TileRows returns the number of tile rows.
type CoarseTileEntry ¶ added in v0.15.0
type CoarseTileEntry struct {
X uint16 // Tile X coordinate
Y uint16 // Tile Y coordinate
LineIdx uint32 // Index into segment list
Winding bool // True if segment contributes winding at this tile
}
CoarseTileEntry represents a tile with its associated line segment. This is used during the coarse rasterization phase before fine rasterization.
type CoarseTileIterator ¶ added in v0.15.0
type CoarseTileIterator struct {
// contains filtered or unexported fields
}
CoarseTileIterator provides iteration over coarse tiles in sorted order.
func (*CoarseTileIterator) HasNext ¶ added in v0.15.0
func (it *CoarseTileIterator) HasNext() bool
HasNext returns true if there are more entries.
func (*CoarseTileIterator) Next ¶ added in v0.15.0
func (it *CoarseTileIterator) Next() *CoarseTileEntry
Next returns the next tile entry or nil if done.
func (*CoarseTileIterator) Reset ¶ added in v0.15.0
func (it *CoarseTileIterator) Reset()
Reset resets the iterator to the beginning.
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
CommandBuffer represents a finished command buffer ready for submission.
func NewCommandBuffer ¶
func NewCommandBuffer(id StubCommandBufferID) *CommandBuffer
NewCommandBuffer wraps a command buffer ID.
func (*CommandBuffer) ID ¶
func (b *CommandBuffer) ID() StubCommandBufferID
ID returns the underlying command buffer ID.
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
CommandEncoder wraps GPU command encoding operations. It provides a high-level interface for building command buffers that can be submitted to the GPU queue.
CommandEncoder accumulates render passes and compute passes, then produces a command buffer when Finish is called.
func NewCommandEncoder ¶
func NewCommandEncoder(device core.DeviceID) *CommandEncoder
NewCommandEncoder creates a new command encoder for the given device.
func (*CommandEncoder) BeginComputePass ¶
func (e *CommandEncoder) BeginComputePass() *ComputePass
BeginComputePass begins a new compute pass.
func (*CommandEncoder) BeginRenderPass ¶
func (e *CommandEncoder) BeginRenderPass(target *GPUTexture, clearTarget bool) *RenderPass
BeginRenderPass begins a new render pass targeting the specified texture. If clearTarget is true, the texture is cleared to transparent before drawing.
func (*CommandEncoder) CopyTextureToBuffer ¶
func (e *CommandEncoder) CopyTextureToBuffer(src *GPUTexture, dst StubBufferID, bytesPerRow uint32)
CopyTextureToBuffer copies a texture to a buffer for readback.
func (*CommandEncoder) CopyTextureToTexture ¶
func (e *CommandEncoder) CopyTextureToTexture(src, dst *GPUTexture, width, height int)
CopyTextureToTexture copies a region from one texture to another.
func (*CommandEncoder) Finish ¶
func (e *CommandEncoder) Finish() StubCommandBufferID
Finish completes the command encoder and returns the command buffer. The encoder cannot be used after calling Finish.
func (*CommandEncoder) PassCount ¶
func (e *CommandEncoder) PassCount() int
PassCount returns the number of passes recorded.
type CompositeParams ¶
type CompositeParams struct {
LayerCount uint32 // Number of layers to composite
Width uint32 // Output width
Height uint32 // Output height
Padding uint32 // Alignment padding
}
CompositeParams represents the uniform buffer structure for composite shaders. This matches the CompositeParams struct in composite.wgsl.
type ComputeCommandBuilder ¶
type ComputeCommandBuilder struct {
// contains filtered or unexported fields
}
ComputeCommandBuilder provides a fluent API for building compute commands.
func NewComputeCommandBuilder ¶
func NewComputeCommandBuilder(device core.DeviceID) *ComputeCommandBuilder
NewComputeCommandBuilder creates a new compute command builder.
func (*ComputeCommandBuilder) Dispatch ¶
func (b *ComputeCommandBuilder) Dispatch(x, y, z uint32) *ComputeCommandBuilder
Dispatch dispatches workgroups.
func (*ComputeCommandBuilder) DispatchForSize ¶
func (b *ComputeCommandBuilder) DispatchForSize(size, groupSize uint32) *ComputeCommandBuilder
DispatchForSize calculates and dispatches for a work size.
func (*ComputeCommandBuilder) Finish ¶
func (b *ComputeCommandBuilder) Finish() StubCommandBufferID
Finish ends the pass and returns the command buffer.
func (*ComputeCommandBuilder) SetBindGroup ¶
func (b *ComputeCommandBuilder) SetBindGroup(index uint32, bindGroup StubBindGroupID) *ComputeCommandBuilder
SetBindGroup sets a bind group.
func (*ComputeCommandBuilder) SetPipeline ¶
func (b *ComputeCommandBuilder) SetPipeline(pipeline StubComputePipelineID) *ComputeCommandBuilder
SetPipeline sets the compute pipeline.
type ComputePass ¶
type ComputePass struct {
// contains filtered or unexported fields
}
ComputePass represents an active compute pass for dispatch commands.
func (*ComputePass) DispatchWorkgroups ¶
func (p *ComputePass) DispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ uint32)
DispatchWorkgroups dispatches compute work. workgroupCountX/Y/Z: number of workgroups in each dimension
func (*ComputePass) DispatchWorkgroupsForSize ¶
func (p *ComputePass) DispatchWorkgroupsForSize(workSize, workgroupSize uint32)
DispatchWorkgroupsForSize calculates and dispatches workgroups for a given work size. workSize: total number of work items workgroupSize: number of items per workgroup (typically 64 or 256)
func (*ComputePass) SetBindGroup ¶
func (p *ComputePass) SetBindGroup(index uint32, bindGroup StubBindGroupID)
SetBindGroup sets a bind group at the specified index.
func (*ComputePass) SetPipeline ¶
func (p *ComputePass) SetPipeline(pipeline StubComputePipelineID)
SetPipeline sets the compute pipeline for subsequent dispatch calls.
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
Edge represents a line segment for scanline conversion. Edges are derived from path segments (lines, curves flattened to lines) and used by the Active Edge Table algorithm.
func NewEdge ¶
NewEdge creates a new edge from two points. Returns nil if the edge is horizontal (no Y extent).
func NewEdgeWithWinding ¶
NewEdgeWithWinding creates a new edge with explicit winding.
func (*Edge) IsActiveAt ¶
IsActiveAt returns true if the edge is active at the given Y coordinate. An edge is active when yMin <= y < yMax.
type EdgeList ¶
type EdgeList struct {
// contains filtered or unexported fields
}
EdgeList is a collection of edges with utility methods.
func (*EdgeList) SortByYMin ¶
func (el *EdgeList) SortByYMin()
SortByYMin sorts edges by their minimum Y coordinate.
type FineRasterizer ¶ added in v0.15.0
type FineRasterizer struct {
// contains filtered or unexported fields
}
FineRasterizer performs fine rasterization with analytic anti-aliasing. It calculates exact sub-pixel coverage for each tile based on the segments that cross it and the fill rule.
func NewFineRasterizer ¶ added in v0.15.0
func NewFineRasterizer(width, height uint16) *FineRasterizer
NewFineRasterizer creates a new fine rasterizer for the given dimensions.
func (*FineRasterizer) FillRule ¶ added in v0.15.0
func (fr *FineRasterizer) FillRule() scene.FillStyle
FillRule returns the current fill rule.
func (*FineRasterizer) Grid ¶ added in v0.15.0
func (fr *FineRasterizer) Grid() *TileGrid
Grid returns the tile grid with computed coverage.
func (*FineRasterizer) Rasterize ¶ added in v0.15.0
func (fr *FineRasterizer) Rasterize( coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32, )
Rasterize performs fine rasterization on coarse tile entries. It calculates analytic anti-aliased coverage for each pixel.
func (*FineRasterizer) RenderToBuffer ¶ added in v0.15.0
func (fr *FineRasterizer) RenderToBuffer( buffer []uint8, width, height int, stride int, color [4]uint8, )
RenderToBuffer renders the tile grid to a pixel buffer. The buffer is in RGBA format with the given stride (bytes per row).
func (*FineRasterizer) RenderToBufferSIMD ¶ added in v0.15.0
func (fr *FineRasterizer) RenderToBufferSIMD( buffer []uint8, width, height int, stride int, color [4]uint8, )
RenderToBufferSIMD renders the tile grid using SIMD-optimized blending.
func (*FineRasterizer) Reset ¶ added in v0.15.0
func (fr *FineRasterizer) Reset()
Reset clears the rasterizer state for reuse.
func (*FineRasterizer) SetFillRule ¶ added in v0.15.0
func (fr *FineRasterizer) SetFillRule(rule scene.FillStyle)
SetFillRule sets the fill rule for coverage calculation.
type FlattenContext ¶ added in v0.15.0
type FlattenContext struct {
// contains filtered or unexported fields
}
FlattenContext provides reusable state for path flattening. Use this to reduce allocations when flattening multiple paths.
func NewFlattenContext ¶ added in v0.15.0
func NewFlattenContext() *FlattenContext
NewFlattenContext creates a new flattening context.
func (*FlattenContext) FlattenPathTo ¶ added in v0.15.0
func (ctx *FlattenContext) FlattenPathTo(path *scene.Path, transform scene.Affine, tolerance float32)
FlattenPathTo flattens a path into the context's segment list.
This avoids allocating a new SegmentList for each path.
func (*FlattenContext) Reset ¶ added in v0.15.0
func (ctx *FlattenContext) Reset()
Reset clears the context for reuse.
func (*FlattenContext) Segments ¶ added in v0.15.0
func (ctx *FlattenContext) Segments() *SegmentList
Segments returns the flattened segments.
type GPUAffineTransform ¶ added in v0.15.0
type GPUAffineTransform struct {
A float32 // Scale X
B float32 // Shear Y
C float32 // Shear X
D float32 // Scale Y
E float32 // Translate X
F float32 // Translate Y
Padding1 float32
Padding2 float32
}
GPUAffineTransform represents an affine transform for GPU. Must match AffineTransform in flatten.wgsl. Matrix layout (column-major): | a c e | | b d f | | 0 0 1 |
func ConvertAffineToGPU ¶ added in v0.15.0
func ConvertAffineToGPU(t scene.Affine) GPUAffineTransform
ConvertAffineToGPU converts a scene.Affine to GPU format.
type GPUCoarseConfig ¶ added in v0.15.0
type GPUCoarseConfig struct {
ViewportWidth uint32 // Viewport width in pixels
ViewportHeight uint32 // Viewport height in pixels
TileColumns uint32 // Number of tile columns
TileRows uint32 // Number of tile rows
SegmentCount uint32 // Number of segments to process
MaxEntries uint32 // Maximum number of tile entries
Padding1 uint32 // Padding for alignment
Padding2 uint32 // Padding for alignment
}
GPUCoarseConfig contains GPU coarse rasterization configuration. Must match CoarseConfig in coarse.wgsl.
type GPUCoarseRasterizer ¶ added in v0.15.0
type GPUCoarseRasterizer struct {
// contains filtered or unexported fields
}
GPUCoarseRasterizer performs coarse rasterization (tile binning) on the GPU. It creates compute pipelines and manages GPU buffers for segment-to-tile mapping.
func NewGPUCoarseRasterizer ¶ added in v0.15.0
func NewGPUCoarseRasterizer(device hal.Device, queue hal.Queue, width, height uint16) (*GPUCoarseRasterizer, error)
NewGPUCoarseRasterizer creates a new GPU coarse rasterizer. Returns an error if GPU compute is not supported.
func (*GPUCoarseRasterizer) Destroy ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) Destroy()
Destroy releases all GPU resources.
func (*GPUCoarseRasterizer) GetTileEntries ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) GetTileEntries(coarse *CoarseRasterizer) []GPUTileSegmentRef
GetTileEntries returns tile entries from a CoarseRasterizer. This is a convenience method that converts CPU coarse entries to GPU format.
func (*GPUCoarseRasterizer) IsInitialized ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) IsInitialized() bool
IsInitialized returns whether the rasterizer is initialized.
func (*GPUCoarseRasterizer) IsShaderReady ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) IsShaderReady() bool
IsShaderReady returns whether the shader compiled successfully.
func (*GPUCoarseRasterizer) Rasterize ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) Rasterize(segments *SegmentList) ([]GPUTileSegmentRef, error)
Rasterize performs coarse rasterization on the GPU. It takes segments and produces tile entries.
Note: Phase 6.2 implementation. Full GPU dispatch requires buffer binding which needs HAL API extensions. Currently falls back to CPU-computed entries.
func (*GPUCoarseRasterizer) SPIRVCode ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) SPIRVCode() []uint32
SPIRVCode returns the compiled SPIR-V code (for debugging/verification).
func (*GPUCoarseRasterizer) TileColumns ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) TileColumns() uint16
TileColumns returns the number of tile columns.
func (*GPUCoarseRasterizer) TileRows ¶ added in v0.15.0
func (r *GPUCoarseRasterizer) TileRows() uint16
TileRows returns the number of tile rows.
type GPUCursorState ¶ added in v0.15.0
type GPUCursorState struct {
CurX float32 // Current cursor X
CurY float32 // Current cursor Y
StartX float32 // Subpath start X (for Close)
StartY float32 // Subpath start Y (for Close)
}
GPUCursorState tracks the cursor position per path element. Must match CursorState in flatten.wgsl.
type GPUFineConfig ¶ added in v0.15.0
type GPUFineConfig struct {
ViewportWidth uint32 // Viewport width in pixels
ViewportHeight uint32 // Viewport height in pixels
TileColumns uint32 // Number of tile columns
TileRows uint32 // Number of tile rows
TileCount uint32 // Number of tiles to process
FillRule uint32 // 0 = NonZero, 1 = EvenOdd
Padding1 uint32 // Padding for alignment
Padding2 uint32 // Padding for alignment
}
GPUFineConfig contains GPU fine rasterization configuration. Must match Config in fine.wgsl.
type GPUFineRasterizer ¶ added in v0.15.0
type GPUFineRasterizer struct {
// contains filtered or unexported fields
}
GPUFineRasterizer performs fine rasterization on the GPU. It creates compute pipelines and manages GPU buffers for coverage calculation.
Note: This is Phase 6.1 implementation. Full GPU buffer binding requires HAL API extensions to expose buffer handles. Currently this serves as infrastructure and data flow verification.
func NewGPUFineRasterizer ¶ added in v0.15.0
func NewGPUFineRasterizer(device hal.Device, queue hal.Queue, width, height uint16) (*GPUFineRasterizer, error)
NewGPUFineRasterizer creates a new GPU fine rasterizer. Returns an error if GPU compute is not supported.
func (*GPUFineRasterizer) Destroy ¶ added in v0.15.0
func (r *GPUFineRasterizer) Destroy()
Destroy releases all GPU resources.
func (*GPUFineRasterizer) IsInitialized ¶ added in v0.15.0
func (r *GPUFineRasterizer) IsInitialized() bool
IsInitialized returns whether the rasterizer is initialized.
func (*GPUFineRasterizer) IsShaderReady ¶ added in v0.15.0
func (r *GPUFineRasterizer) IsShaderReady() bool
IsShaderReady returns whether the shader compiled successfully.
func (*GPUFineRasterizer) Rasterize ¶ added in v0.15.0
func (r *GPUFineRasterizer) Rasterize( coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32, fillRule scene.FillStyle, ) ([]uint8, error)
Rasterize performs fine rasterization on the GPU. It takes the coarse rasterizer output and produces coverage values.
Note: Phase 6.1 implementation. Full GPU dispatch requires buffer binding which needs HAL API extensions. Currently falls back to CPU-computed coverage.
func (*GPUFineRasterizer) SPIRVCode ¶ added in v0.15.0
func (r *GPUFineRasterizer) SPIRVCode() []uint32
SPIRVCode returns the compiled SPIR-V code (for debugging/verification).
type GPUFlattenConfig ¶ added in v0.15.0
type GPUFlattenConfig struct {
ElementCount uint32 // Number of path elements
Tolerance float32 // Flattening tolerance
MaxSegments uint32 // Maximum total segments
TileSize uint32 // Tile size in pixels
ViewportWidth uint32 // Viewport width
ViewportHeight uint32 // Viewport height
Padding1 uint32
Padding2 uint32
}
GPUFlattenConfig contains GPU flattening configuration. Must match FlattenConfig in flatten.wgsl.
type GPUFlattenRasterizer ¶ added in v0.15.0
type GPUFlattenRasterizer struct {
// contains filtered or unexported fields
}
GPUFlattenRasterizer performs curve flattening on the GPU. It converts Bezier curves to monotonic line segments using Wang's formula.
Note: Phase 6.3 implementation. Full GPU dispatch requires additional cursor tracking infrastructure. Currently provides CPU fallback using the existing flatten.go algorithms.
func NewGPUFlattenRasterizer ¶ added in v0.15.0
func NewGPUFlattenRasterizer(device hal.Device, queue hal.Queue, maxPaths, maxSegments int) (*GPUFlattenRasterizer, error)
NewGPUFlattenRasterizer creates a new GPU flatten rasterizer. maxPaths: Maximum number of path elements to process maxSegments: Maximum number of output segments
func (*GPUFlattenRasterizer) ComputeCursorStates ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) ComputeCursorStates(path *scene.Path) []GPUCursorState
ComputeCursorStates computes cursor states for each path element. This tracks the cursor position (curX, curY) and subpath start (startX, startY) for each element, which is needed by the GPU shader.
func (*GPUFlattenRasterizer) ConvertPathToGPU ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) ConvertPathToGPU(path *scene.Path) ([]GPUPathElement, []float32)
ConvertPathToGPU converts a scene.Path to GPU buffer format. Returns elements and points arrays suitable for GPU upload.
func (*GPUFlattenRasterizer) Destroy ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) Destroy()
Destroy releases all GPU resources.
func (*GPUFlattenRasterizer) EstimateSegmentCount ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) EstimateSegmentCount(path *scene.Path, transform scene.Affine, tolerance float32) int
EstimateSegmentCount estimates the number of segments for a path. Uses Wang's formula to estimate without actually flattening.
func (*GPUFlattenRasterizer) Flatten ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) Flatten(path *scene.Path, transform scene.Affine, tolerance float32) (*SegmentList, error)
Flatten flattens a path to monotonic line segments. Uses CPU fallback (matching existing flatten.go algorithm).
Parameters:
- path: The input path to flatten
- transform: Affine transformation to apply to all points
- tolerance: Flattening tolerance (use 0 for default)
Returns a SegmentList containing all flattened line segments.
func (*GPUFlattenRasterizer) FlattenWithContext ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) FlattenWithContext( path *scene.Path, transform scene.Affine, tolerance float32, ) *SegmentList
FlattenWithContext flattens a path using a provided context for efficiency. This avoids allocating a new SegmentList for each path.
func (*GPUFlattenRasterizer) IsInitialized ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) IsInitialized() bool
IsInitialized returns whether the rasterizer is initialized.
func (*GPUFlattenRasterizer) IsShaderReady ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) IsShaderReady() bool
IsShaderReady returns whether the shader compiled successfully.
func (*GPUFlattenRasterizer) MaxPaths ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) MaxPaths() int
MaxPaths returns the maximum number of path elements.
func (*GPUFlattenRasterizer) MaxSegments ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) MaxSegments() int
MaxSegments returns the maximum number of output segments.
func (*GPUFlattenRasterizer) SPIRVCode ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) SPIRVCode() []uint32
SPIRVCode returns the compiled SPIR-V code (for debugging/verification).
func (*GPUFlattenRasterizer) SetTolerance ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) SetTolerance(tolerance float32)
SetTolerance sets the flattening tolerance.
func (*GPUFlattenRasterizer) Tolerance ¶ added in v0.15.0
func (r *GPUFlattenRasterizer) Tolerance() float32
Tolerance returns the current flattening tolerance.
type GPUInfo ¶
type GPUInfo struct {
// Name is the GPU name (e.g., "NVIDIA GeForce RTX 3080").
Name string
// Vendor is the GPU vendor.
Vendor string
// DeviceType is the type of GPU (discrete, integrated, etc.).
DeviceType types.DeviceType
// Backend is the graphics API in use (Vulkan, Metal, DX12).
Backend types.Backend
// Driver is the driver version string.
Driver string
}
GPUInfo contains information about the selected GPU.
type GPUPathElement ¶ added in v0.15.0
type GPUPathElement struct {
Verb uint32 // Path verb type (0=MoveTo, 1=LineTo, 2=QuadTo, 3=CubicTo, 4=Close)
PointStart uint32 // Start index in points array
PointCount uint32 // Number of points for this element
Padding uint32
}
GPUPathElement represents a path element for GPU processing. Must match PathElement in flatten.wgsl.
type GPURasterizer ¶ added in v0.15.0
type GPURasterizer interface {
// Rasterize performs fine rasterization and returns coverage values.
Rasterize(
coarse *CoarseRasterizer,
segments *SegmentList,
backdrop []int32,
fillRule scene.FillStyle,
) ([]uint8, error)
// Destroy releases GPU resources.
Destroy()
}
GPURasterizer is the interface for GPU-accelerated rasterization.
type GPURasterizerStats ¶ added in v0.15.0
type GPURasterizerStats struct {
// GPUAvailable indicates if GPU is available
GPUAvailable bool
// TotalCalls is the total number of rasterization calls
TotalCalls uint64
// GPUCalls is the number of calls that used GPU
GPUCalls uint64
// CPUCalls is the number of calls that used CPU
CPUCalls uint64
// SegmentThreshold is the threshold for GPU usage
SegmentThreshold int
}
GPURasterizerStats contains statistics about GPU rasterization.
type GPURenderer ¶
type GPURenderer struct {
// contains filtered or unexported fields
}
GPURenderer is a GPU-backed renderer for immediate mode drawing. It implements the gg.Renderer interface.
Note: This is a stub implementation. The actual GPU rendering will be implemented in TASK-110.
func (*GPURenderer) Close ¶
func (r *GPURenderer) Close()
Close releases renderer resources. Note: This is a stub implementation.
func (*GPURenderer) Fill ¶
Fill fills a path with the given paint. Note: This is a stub implementation.
type GPUSceneRenderer ¶
type GPUSceneRenderer struct {
// contains filtered or unexported fields
}
GPUSceneRenderer renders scenes using GPU acceleration. It implements the full render pipeline: scene decoding, path rasterization, coverage calculation, and layer compositing.
The renderer uses HybridPipeline which automatically selects between GPU and CPU execution for each stage based on workload size.
GPUSceneRenderer is safe for concurrent use from multiple goroutines.
func NewGPUSceneRenderer ¶
func NewGPUSceneRenderer(backend *WGPUBackend, config GPUSceneRendererConfig) (*GPUSceneRenderer, error)
NewGPUSceneRenderer creates a new GPU scene renderer. The renderer is configured for the specified dimensions.
Returns an error if the backend is not initialized or configuration is invalid.
func (*GPUSceneRenderer) Close ¶
func (r *GPUSceneRenderer) Close()
Close releases all renderer resources.
func (*GPUSceneRenderer) Height ¶
func (r *GPUSceneRenderer) Height() int
Height returns the renderer height.
func (*GPUSceneRenderer) LayerDepth ¶
func (r *GPUSceneRenderer) LayerDepth() int
LayerDepth returns the current layer stack depth.
func (*GPUSceneRenderer) MemoryStats ¶
func (r *GPUSceneRenderer) MemoryStats() MemoryStats
MemoryStats returns GPU memory usage statistics.
func (*GPUSceneRenderer) RenderScene ¶
func (r *GPUSceneRenderer) RenderScene(s *scene.Scene) error
RenderScene renders a complete scene to the internal target texture. After rendering, use DownloadPixmap to retrieve the result.
For cancellable rendering, use RenderSceneWithContext.
func (*GPUSceneRenderer) RenderSceneWithContext ¶ added in v0.13.0
RenderSceneWithContext renders a complete scene to the internal target texture with cancellation support.
The context can be used to cancel long-running renders. When canceled, the function returns ctx.Err() and the texture may contain partial results.
func (*GPUSceneRenderer) RenderToPixmap ¶
RenderToPixmap renders a scene directly to a pixmap. This is a convenience method that renders and downloads in one call.
For cancellable rendering, use RenderToPixmapWithContext.
func (*GPUSceneRenderer) RenderToPixmapWithContext ¶ added in v0.13.0
func (r *GPUSceneRenderer) RenderToPixmapWithContext(ctx context.Context, target *gg.Pixmap, s *scene.Scene) error
RenderToPixmapWithContext renders a scene directly to a pixmap with cancellation support. This is a convenience method that renders and downloads in one call.
The context can be used to cancel long-running renders. When canceled, the function returns ctx.Err() and the target may contain partial results.
func (*GPUSceneRenderer) Resize ¶
func (r *GPUSceneRenderer) Resize(width, height int) error
Resize resizes the renderer to new dimensions. All layer textures are released and the target texture is reallocated.
func (*GPUSceneRenderer) Width ¶
func (r *GPUSceneRenderer) Width() int
Width returns the renderer width.
type GPUSceneRendererConfig ¶
type GPUSceneRendererConfig struct {
// Width is the render target width in pixels.
Width int
// Height is the render target height in pixels.
Height int
// MaxLayers is the maximum layer stack depth (default: 16).
MaxLayers int
// MemoryBudgetMB is the texture memory budget in MB (default: 128).
MemoryBudgetMB int
}
GPUSceneRendererConfig holds configuration for creating a GPUSceneRenderer.
type GPUSegment ¶ added in v0.15.0
type GPUSegment struct {
X0 float32 // Start X coordinate
Y0 float32 // Start Y coordinate
X1 float32 // End X coordinate
Y1 float32 // End Y coordinate
Winding int32 // Winding direction: +1 or -1
TileY0 int32 // Starting tile Y (precomputed)
TileY1 int32 // Ending tile Y (precomputed)
Padding int32 // Padding for alignment
}
GPUSegment is the GPU-compatible layout of LineSegment. Must match the Segment struct in fine.wgsl.
type GPUSegmentCount ¶ added in v0.15.0
type GPUSegmentCount struct {
Count uint32 // Number of segments for this element
Offset uint32 // Prefix sum offset
Padding1 uint32
Padding2 uint32
}
GPUSegmentCount holds segment count per path element. Must match SegmentCount in flatten.wgsl.
type GPUTexture ¶
type GPUTexture struct {
// contains filtered or unexported fields
}
GPUTexture represents a GPU texture resource. It wraps the underlying wgpu texture and provides a high-level interface for texture operations including upload and download.
GPUTexture is safe for concurrent read access. Write operations (Upload, Close) should be synchronized externally.
func CreateTexture ¶
func CreateTexture(backend *WGPUBackend, config TextureConfig) (*GPUTexture, error)
CreateTexture creates a new GPU texture with the given configuration. The texture is uninitialized and should be filled with UploadPixmap.
Note: This is a stub implementation. The actual GPU texture creation will be implemented when wgpu texture support is complete.
func CreateTextureFromPixmap ¶
func CreateTextureFromPixmap(backend *WGPUBackend, pixmap *gg.Pixmap, label string) (*GPUTexture, error)
CreateTextureFromPixmap creates a GPU texture from a pixmap, uploading the pixel data immediately.
func (*GPUTexture) Close ¶
func (t *GPUTexture) Close()
Close releases the GPU texture resources. The texture should not be used after Close is called.
func (*GPUTexture) DownloadPixmap ¶
func (t *GPUTexture) DownloadPixmap() (*gg.Pixmap, error)
DownloadPixmap downloads pixel data from GPU to a new Pixmap. This operation requires the texture to have CopySrc usage.
Note: This is a stub implementation that returns an error. GPU readback requires staging buffers and synchronization.
func (*GPUTexture) Format ¶
func (t *GPUTexture) Format() TextureFormat
Format returns the texture format.
func (*GPUTexture) Height ¶
func (t *GPUTexture) Height() int
Height returns the texture height in pixels.
func (*GPUTexture) IsReleased ¶
func (t *GPUTexture) IsReleased() bool
IsReleased returns true if the texture has been released.
func (*GPUTexture) SetMemoryManager ¶
func (t *GPUTexture) SetMemoryManager(m *MemoryManager)
SetMemoryManager sets the memory manager for tracking. This is called internally when allocating through MemoryManager.
func (*GPUTexture) SizeBytes ¶
func (t *GPUTexture) SizeBytes() uint64
SizeBytes returns the texture size in bytes.
func (*GPUTexture) String ¶
func (t *GPUTexture) String() string
String returns a string representation of the texture.
func (*GPUTexture) TextureID ¶
func (t *GPUTexture) TextureID() core.TextureID
TextureID returns the underlying wgpu texture ID. Returns a zero ID for stub textures.
func (*GPUTexture) UploadPixmap ¶
func (t *GPUTexture) UploadPixmap(pixmap *gg.Pixmap) error
UploadPixmap uploads pixel data from a Pixmap to the GPU texture. The pixmap dimensions must match the texture dimensions.
Note: This is a stub implementation. The actual GPU upload will be implemented when wgpu queue.WriteTexture is available.
func (*GPUTexture) UploadRegion ¶
func (t *GPUTexture) UploadRegion(x, y int, pixmap *gg.Pixmap) error
UploadRegion uploads pixel data to a region of the texture. This is useful for texture atlas updates.
Note: This is a stub implementation.
func (*GPUTexture) ViewID ¶
func (t *GPUTexture) ViewID() core.TextureViewID
ViewID returns the texture view ID. Returns a zero ID for stub textures.
func (*GPUTexture) Width ¶
func (t *GPUTexture) Width() int
Width returns the texture width in pixels.
type GPUTileInfo ¶ added in v0.15.0
type GPUTileInfo struct {
TileX uint32 // Tile X coordinate
TileY uint32 // Tile Y coordinate
StartIdx uint32 // Start index in tile_segments
Count uint32 // Number of segments for this tile
Backdrop int32 // Accumulated winding from left
Padding1 uint32 // Padding for alignment
Padding2 uint32 // Padding for alignment
Padding3 uint32 // Padding for alignment
}
GPUTileInfo contains tile processing information. Must match TileInfo in fine.wgsl.
type GPUTileSegmentRef ¶ added in v0.15.0
type GPUTileSegmentRef struct {
TileX uint32 // Tile X coordinate
TileY uint32 // Tile Y coordinate
SegmentIdx uint32 // Index into segments array
WindingFlag uint32 // Whether this contributes winding (0 or 1)
}
GPUTileSegmentRef maps a segment to a tile. Must match TileSegmentRef in fine.wgsl.
type GridRasterParams ¶ added in v0.16.0
type GridRasterParams struct {
Color [4]float32 // Fill color (RGBA normalized)
TargetWidth int32 // Target texture width
TargetHeight int32 // Target texture height
TileCount int32 // Number of tiles in grid
}
GridRasterParams contains parameters for tile grid rasterization.
type HybridFineRasterizer ¶ added in v0.15.0
type HybridFineRasterizer struct {
// contains filtered or unexported fields
}
HybridFineRasterizer automatically selects between GPU and CPU rasterization based on workload size and GPU availability.
func NewHybridFineRasterizer ¶ added in v0.15.0
func NewHybridFineRasterizer(width, height uint16, config HybridFineRasterizerConfig) *HybridFineRasterizer
NewHybridFineRasterizer creates a hybrid rasterizer that automatically selects between GPU and CPU based on workload.
func (*HybridFineRasterizer) Destroy ¶ added in v0.15.0
func (h *HybridFineRasterizer) Destroy()
Destroy releases all resources.
func (*HybridFineRasterizer) FillRule ¶ added in v0.15.0
func (h *HybridFineRasterizer) FillRule() scene.FillStyle
FillRule returns the current fill rule.
func (*HybridFineRasterizer) Grid ¶ added in v0.15.0
func (h *HybridFineRasterizer) Grid() *TileGrid
Grid returns the tile grid with computed coverage.
func (*HybridFineRasterizer) IsGPUAvailable ¶ added in v0.15.0
func (h *HybridFineRasterizer) IsGPUAvailable() bool
IsGPUAvailable returns whether GPU rasterization is available.
func (*HybridFineRasterizer) Rasterize ¶ added in v0.15.0
func (h *HybridFineRasterizer) Rasterize( coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32, )
Rasterize performs fine rasterization, automatically selecting GPU or CPU.
func (*HybridFineRasterizer) Reset ¶ added in v0.15.0
func (h *HybridFineRasterizer) Reset()
Reset clears the rasterizer state for reuse.
func (*HybridFineRasterizer) SetFillRule ¶ added in v0.15.0
func (h *HybridFineRasterizer) SetFillRule(rule scene.FillStyle)
SetFillRule sets the fill rule for coverage calculation.
func (*HybridFineRasterizer) Stats ¶ added in v0.15.0
func (h *HybridFineRasterizer) Stats() GPURasterizerStats
Stats returns statistics about rasterization calls. Note: Currently returns static info; could track actual call counts.
type HybridFineRasterizerConfig ¶ added in v0.15.0
type HybridFineRasterizerConfig struct {
// Device and Queue for GPU operations (nil to use CPU only)
Device hal.Device
Queue hal.Queue
// SegmentThreshold is the minimum segments to use GPU (0 = use default)
SegmentThreshold int
// ForceGPU forces GPU even for small workloads (for testing)
ForceGPU bool
// ForceCPU disables GPU entirely (for testing/fallback)
ForceCPU bool
}
HybridFineRasterizerConfig configures the hybrid rasterizer.
type HybridPipeline ¶ added in v0.15.0
type HybridPipeline struct {
// contains filtered or unexported fields
}
HybridPipeline integrates all three GPU shaders into a unified pipeline: Flatten (path -> segments) -> Coarse (segments -> tile bins) -> Fine (tile bins -> coverage)
The pipeline automatically selects GPU or CPU for each stage based on workload size and GPU availability.
func NewHybridPipeline ¶ added in v0.15.0
func NewHybridPipeline(width, height uint16, config HybridPipelineConfig) *HybridPipeline
NewHybridPipeline creates a new hybrid pipeline that integrates all GPU stages.
func (*HybridPipeline) Destroy ¶ added in v0.15.0
func (p *HybridPipeline) Destroy()
Destroy releases all GPU resources.
func (*HybridPipeline) Grid ¶ added in v0.15.0
func (p *HybridPipeline) Grid() *TileGrid
Grid returns the tile grid with computed coverage.
func (*HybridPipeline) IsGPUAvailable ¶ added in v0.15.0
func (p *HybridPipeline) IsGPUAvailable() bool
IsGPUAvailable returns whether any GPU stage is available.
func (*HybridPipeline) IsStageGPUAvailable ¶ added in v0.15.0
func (p *HybridPipeline) IsStageGPUAvailable(stage PipelineStage) bool
IsStageGPUAvailable returns whether a specific stage has GPU available.
func (*HybridPipeline) RasterizePath ¶ added in v0.15.0
func (p *HybridPipeline) RasterizePath( path *scene.Path, transform scene.Affine, fillRule scene.FillStyle, ) *TileGrid
RasterizePath runs the full pipeline: path -> segments -> tile bins -> coverage.
Parameters:
- path: The input path to rasterize
- transform: Affine transformation to apply
- fillRule: Fill rule for coverage calculation
Returns the tile grid with computed coverage.
func (*HybridPipeline) Reset ¶ added in v0.15.0
func (p *HybridPipeline) Reset()
Reset clears all rasterizer state for reuse.
func (*HybridPipeline) ResetStats ¶ added in v0.15.0
func (p *HybridPipeline) ResetStats()
ResetStats resets all statistics counters.
func (*HybridPipeline) SetFillRule ¶ added in v0.15.0
func (p *HybridPipeline) SetFillRule(rule scene.FillStyle)
SetFillRule sets the fill rule for coverage calculation.
func (*HybridPipeline) SetTolerance ¶ added in v0.15.0
func (p *HybridPipeline) SetTolerance(tolerance float32)
SetTolerance sets the flattening tolerance.
func (*HybridPipeline) Stats ¶ added in v0.15.0
func (p *HybridPipeline) Stats() HybridPipelineStats
Stats returns statistics about pipeline execution.
type HybridPipelineConfig ¶ added in v0.15.0
type HybridPipelineConfig struct {
// Device and Queue for GPU operations (nil to use CPU only)
Device hal.Device
Queue hal.Queue
// Stage-specific thresholds (0 = use defaults)
FlattenThreshold int // Min path elements for GPU flatten
CoarseThreshold int // Min segments for GPU coarse
FineThreshold int // Min tile entries for GPU fine
// MaxPaths is the maximum path elements for flatten (0 = default 1024)
MaxPaths int
// MaxSegments is the maximum segments for flatten (0 = default MaxPaths * 64)
MaxSegments int
// Force flags for testing
ForceGPU bool // Force GPU for all stages (ignores thresholds)
ForceCPU bool // Force CPU for all stages (disables GPU)
// Tolerance for curve flattening (0 = use default)
Tolerance float32
}
HybridPipelineConfig configures the hybrid pipeline.
type HybridPipelineStats ¶ added in v0.15.0
type HybridPipelineStats struct {
// GPU availability per stage
FlattenGPUAvailable bool
CoarseGPUAvailable bool
FineGPUAvailable bool
// Call counts per stage
FlattenTotalCalls uint64
FlattenGPUCalls uint64
FlattenCPUCalls uint64
CoarseTotalCalls uint64
CoarseGPUCalls uint64
CoarseCPUCalls uint64
FineTotalCalls uint64
FineGPUCalls uint64
FineCPUCalls uint64
// Thresholds
FlattenThreshold int
CoarseThreshold int
FineThreshold int
// Last operation details
LastPathElements int
LastSegmentCount int
LastTileEntryCount int
LastFlattenUsedGPU bool
LastCoarseUsedGPU bool
LastFineUsedGPU bool
}
HybridPipelineStats contains statistics about pipeline execution.
type IndexFormat ¶
type IndexFormat uint32
IndexFormat specifies the format of index buffer elements.
const ( // IndexFormatUint16 uses 16-bit unsigned integers. IndexFormatUint16 IndexFormat = 0 // IndexFormatUint32 uses 32-bit unsigned integers. IndexFormatUint32 IndexFormat = 1 )
type LayerDescriptor ¶
type LayerDescriptor struct {
TextureIdx uint32 // Index into layer textures
BlendMode uint32 // Blend mode for this layer
Alpha float32 // Layer opacity
Padding float32 // Alignment padding
}
LayerDescriptor represents a single layer for compositing. This matches the Layer struct in composite.wgsl.
type LineSegment ¶ added in v0.15.0
type LineSegment struct {
// Start point (X0, Y0) and end point (X1, Y1).
// For monotonic segments, Y0 <= Y1 (always going down).
X0, Y0, X1, Y1 float32
// Winding direction: +1 for left-to-right, -1 for right-to-left.
// Determined by original path direction before monotonic split.
Winding int8
// TileY0, TileY1 are the tile row range this segment spans.
// Precomputed for efficient coarse rasterization.
TileY0, TileY1 int32
}
LineSegment represents a monotonic line segment for tile processing. A monotonic segment has consistent Y direction (always going down or up). This simplifies tile intersection calculations.
func NewLineSegment ¶ added in v0.15.0
func NewLineSegment(x0, y0, x1, y1 float32, winding int8) LineSegment
NewLineSegment creates a new line segment, ensuring Y0 <= Y1. The winding is adjusted if the segment is flipped.
func (*LineSegment) Bounds ¶ added in v0.15.0
func (s *LineSegment) Bounds() (minX, minY, maxX, maxY float32)
Bounds returns the bounding box of the segment.
func (*LineSegment) CrossesTileRow ¶ added in v0.15.0
func (s *LineSegment) CrossesTileRow(tileY int32) bool
CrossesTileRow returns true if the segment crosses the given tile row.
func (*LineSegment) DeltaX ¶ added in v0.15.0
func (s *LineSegment) DeltaX() float32
DeltaX returns the X distance of the segment.
func (*LineSegment) DeltaY ¶ added in v0.15.0
func (s *LineSegment) DeltaY() float32
DeltaY returns the Y distance of the segment.
func (*LineSegment) InverseSlope ¶ added in v0.15.0
func (s *LineSegment) InverseSlope() float32
InverseSlope returns dy/dx. Returns a large value for vertical segments.
func (*LineSegment) IsHorizontal ¶ added in v0.15.0
func (s *LineSegment) IsHorizontal() bool
IsHorizontal returns true if the segment is approximately horizontal.
func (*LineSegment) IsVertical ¶ added in v0.15.0
func (s *LineSegment) IsVertical() bool
IsVertical returns true if the segment is approximately vertical.
func (*LineSegment) Slope ¶ added in v0.15.0
func (s *LineSegment) Slope() float32
Slope returns the slope (dx/dy) of the segment. Returns 0 for horizontal segments.
func (*LineSegment) TileXRange ¶ added in v0.15.0
func (s *LineSegment) TileXRange(tileY int32) (minTileX, maxTileX int32)
TileXRange returns the range of tile columns this segment touches at a given tile row.
func (*LineSegment) XAtY ¶ added in v0.15.0
func (s *LineSegment) XAtY(y float32) float32
XAtY returns the X coordinate at a given Y. Assumes Y is within the segment's Y range.
func (*LineSegment) YAtX ¶ added in v0.15.0
func (s *LineSegment) YAtX(x float32) float32
YAtX returns the Y coordinate at a given X. Assumes X is within the segment's X range.
type MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager tracks GPU memory allocations and enforces budget limits. It provides LRU eviction when the memory budget is exceeded.
MemoryManager is safe for concurrent use.
func NewMemoryManager ¶
func NewMemoryManager(backend *WGPUBackend, config MemoryManagerConfig) *MemoryManager
NewMemoryManager creates a new memory manager for GPU memory tracking. The backend parameter is used for texture creation operations.
func (*MemoryManager) AllocTexture ¶
func (m *MemoryManager) AllocTexture(config TextureConfig) (*GPUTexture, error)
AllocTexture allocates a new texture with the given configuration. If the allocation would exceed the memory budget, LRU eviction is triggered. Returns an error if the allocation cannot be satisfied even after eviction.
func (*MemoryManager) Close ¶
func (m *MemoryManager) Close()
Close releases all managed textures and closes the memory manager. The manager should not be used after Close is called.
func (*MemoryManager) Contains ¶
func (m *MemoryManager) Contains(tex *GPUTexture) bool
Contains returns true if the texture is managed by this manager.
func (*MemoryManager) FreeTexture ¶
func (m *MemoryManager) FreeTexture(tex *GPUTexture) error
FreeTexture releases a texture and returns its memory to the pool. The texture is closed and should not be used after this call.
func (*MemoryManager) SetBudget ¶
func (m *MemoryManager) SetBudget(megabytes int) error
SetBudget updates the memory budget. If the new budget is lower than current usage, eviction may be triggered.
func (*MemoryManager) Stats ¶
func (m *MemoryManager) Stats() MemoryStats
Stats returns current memory usage statistics.
func (*MemoryManager) Textures ¶
func (m *MemoryManager) Textures() []*GPUTexture
Textures returns a slice of all managed textures. The returned slice is a copy and can be safely modified.
func (*MemoryManager) TouchTexture ¶
func (m *MemoryManager) TouchTexture(tex *GPUTexture)
TouchTexture updates the last-used time of a texture, moving it to the front of the LRU list. Call this when a texture is used for rendering.
type MemoryManagerConfig ¶
type MemoryManagerConfig struct {
// MaxMemoryMB is the maximum memory budget in megabytes.
// Defaults to DefaultMaxMemoryMB if <= 0.
MaxMemoryMB int
// EvictionThreshold is the usage fraction at which eviction starts.
// Defaults to DefaultEvictionThreshold if <= 0.
EvictionThreshold float64
}
MemoryManagerConfig holds configuration for creating a MemoryManager.
type MemoryStats ¶
type MemoryStats struct {
// TotalBytes is the total memory budget in bytes.
TotalBytes uint64
// UsedBytes is the currently allocated memory in bytes.
UsedBytes uint64
// AvailableBytes is the remaining memory budget.
AvailableBytes uint64
// TextureCount is the number of allocated textures.
TextureCount int
// EvictionCount is the total number of textures evicted.
EvictionCount uint64
// Utilization is the percentage of budget used (0.0 to 1.0).
Utilization float64
}
MemoryStats contains GPU memory usage statistics.
func (MemoryStats) String ¶
func (s MemoryStats) String() string
String returns a human-readable string of memory stats.
type PipelineCache ¶
type PipelineCache struct {
// contains filtered or unexported fields
}
PipelineCache caches compiled GPU pipelines for rendering operations. It manages bind group layouts and pipelines for blit, blend, strip rasterization, and compositing operations.
PipelineCache is safe for concurrent read access. Pipeline creation is synchronized internally.
func NewPipelineCache ¶
func NewPipelineCache(device core.DeviceID, shaders *ShaderModules) (*PipelineCache, error)
NewPipelineCache creates a new pipeline cache for the given device. It initializes all base pipelines using the provided shader modules.
Returns an error if pipeline creation fails.
func (*PipelineCache) BlendPipelineCount ¶
func (pc *PipelineCache) BlendPipelineCount() int
BlendPipelineCount returns the number of cached blend pipelines. Useful for debugging and monitoring.
func (*PipelineCache) Close ¶
func (pc *PipelineCache) Close()
Close releases all pipeline resources.
func (*PipelineCache) CreateBlendBindGroup ¶
func (pc *PipelineCache) CreateBlendBindGroup(tex *GPUTexture, params *BlendParams) StubBindGroupID
CreateBlendBindGroup creates a bind group for blend operations.
func (*PipelineCache) CreateBlitBindGroup ¶
func (pc *PipelineCache) CreateBlitBindGroup(tex *GPUTexture) StubBindGroupID
CreateBlitBindGroup creates a bind group for blit operations.
func (*PipelineCache) CreateStripBindGroup ¶
func (pc *PipelineCache) CreateStripBindGroup( headerBuffer StubBufferID, coverageBuffer StubBufferID, outputTex *GPUTexture, params *StripParams, ) StubBindGroupID
CreateStripBindGroup creates a bind group for strip compute operations.
func (*PipelineCache) GetBlendLayout ¶
func (pc *PipelineCache) GetBlendLayout() StubBindGroupLayoutID
GetBlendLayout returns the bind group layout for blend operations.
func (*PipelineCache) GetBlendPipeline ¶
func (pc *PipelineCache) GetBlendPipeline(mode scene.BlendMode) StubPipelineID
GetBlendPipeline returns the pipeline for the specified blend mode. Pipelines are created on demand and cached.
func (*PipelineCache) GetBlitLayout ¶
func (pc *PipelineCache) GetBlitLayout() StubBindGroupLayoutID
GetBlitLayout returns the bind group layout for blit operations.
func (*PipelineCache) GetBlitPipeline ¶
func (pc *PipelineCache) GetBlitPipeline() StubPipelineID
GetBlitPipeline returns the blit pipeline.
func (*PipelineCache) GetCompositePipeline ¶
func (pc *PipelineCache) GetCompositePipeline() StubPipelineID
GetCompositePipeline returns the compositing pipeline.
func (*PipelineCache) GetStripLayout ¶
func (pc *PipelineCache) GetStripLayout() StubBindGroupLayoutID
GetStripLayout returns the bind group layout for strip compute.
func (*PipelineCache) GetStripPipeline ¶
func (pc *PipelineCache) GetStripPipeline() StubComputePipelineID
GetStripPipeline returns the strip rasterization compute pipeline.
func (*PipelineCache) IsInitialized ¶
func (pc *PipelineCache) IsInitialized() bool
IsInitialized returns true if the cache has been initialized.
func (*PipelineCache) WarmupBlendPipelines ¶
func (pc *PipelineCache) WarmupBlendPipelines()
WarmupBlendPipelines pre-creates pipelines for commonly used blend modes. This avoids pipeline compilation stutter during first use.
type PipelineStage ¶ added in v0.15.0
type PipelineStage uint8
PipelineStage represents which stage of the pipeline is being executed.
const ( // StageFlatten is the path flattening stage (path -> segments). StageFlatten PipelineStage = iota // StageCoarse is the coarse rasterization stage (segments -> tile bins). StageCoarse // StageFine is the fine rasterization stage (tile bins -> coverage). StageFine )
func (PipelineStage) String ¶ added in v0.15.0
func (s PipelineStage) String() string
String returns a human-readable name for the pipeline stage.
type QueueSubmitter ¶
type QueueSubmitter struct {
// contains filtered or unexported fields
}
QueueSubmitter submits command buffers to a GPU queue.
func NewQueueSubmitter ¶
func NewQueueSubmitter(queue core.QueueID) *QueueSubmitter
NewQueueSubmitter creates a new queue submitter.
func (*QueueSubmitter) Submit ¶
func (s *QueueSubmitter) Submit(buffers ...*CommandBuffer)
Submit submits command buffers to the queue.
func (*QueueSubmitter) WriteBuffer ¶
func (s *QueueSubmitter) WriteBuffer(buffer StubBufferID, offset uint64, data []byte)
WriteBuffer writes data to a GPU buffer.
func (*QueueSubmitter) WriteTexture ¶
func (s *QueueSubmitter) WriteTexture(texture *GPUTexture, data []byte)
WriteTexture writes data to a GPU texture.
type RectAllocator ¶
type RectAllocator struct {
// contains filtered or unexported fields
}
RectAllocator implements a simple shelf-packing algorithm for allocating rectangular regions within a fixed-size area.
The shelf-packing algorithm works by dividing the atlas into horizontal "shelves". Each new rectangle is placed on the current shelf if it fits, or a new shelf is created below.
func NewRectAllocator ¶
func NewRectAllocator(width, height, padding int) *RectAllocator
NewRectAllocator creates a new rectangular region allocator.
func (*RectAllocator) AllocCount ¶
func (a *RectAllocator) AllocCount() int
AllocCount returns the number of successful allocations.
func (*RectAllocator) Allocate ¶
func (a *RectAllocator) Allocate(width, height int) AtlasRegion
Allocate finds space for a rectangle of the given size. Returns an invalid region if the rectangle cannot be allocated.
func (*RectAllocator) Reset ¶
func (a *RectAllocator) Reset()
Reset clears all allocations, making the entire area available again.
func (*RectAllocator) UsedArea ¶
func (a *RectAllocator) UsedArea() int
UsedArea returns the total area of allocated rectangles.
func (*RectAllocator) Utilization ¶
func (a *RectAllocator) Utilization() float64
Utilization returns the fraction of area used (0.0 to 1.0).
type RenderCommandBuilder ¶
type RenderCommandBuilder struct {
// contains filtered or unexported fields
}
RenderCommandBuilder provides a fluent API for building render commands.
func NewRenderCommandBuilder ¶
func NewRenderCommandBuilder(device core.DeviceID, target *GPUTexture, clearTarget bool) *RenderCommandBuilder
NewRenderCommandBuilder creates a new render command builder.
func (*RenderCommandBuilder) Draw ¶
func (b *RenderCommandBuilder) Draw(vertexCount, instanceCount uint32) *RenderCommandBuilder
Draw issues a draw call.
func (*RenderCommandBuilder) DrawFullScreen ¶
func (b *RenderCommandBuilder) DrawFullScreen() *RenderCommandBuilder
DrawFullScreen draws a full-screen triangle.
func (*RenderCommandBuilder) Finish ¶
func (b *RenderCommandBuilder) Finish() StubCommandBufferID
Finish ends the pass and returns the command buffer.
func (*RenderCommandBuilder) SetBindGroup ¶
func (b *RenderCommandBuilder) SetBindGroup(index uint32, bindGroup StubBindGroupID) *RenderCommandBuilder
SetBindGroup sets a bind group.
func (*RenderCommandBuilder) SetPipeline ¶
func (b *RenderCommandBuilder) SetPipeline(pipeline StubPipelineID) *RenderCommandBuilder
SetPipeline sets the render pipeline.
type RenderPass ¶
type RenderPass struct {
// contains filtered or unexported fields
}
RenderPass represents an active render pass for draw commands. Draw commands can only be issued while a render pass is active.
func (*RenderPass) Draw ¶
func (p *RenderPass) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
Draw issues a non-indexed draw call. vertexCount: number of vertices to draw instanceCount: number of instances to draw firstVertex: offset into the vertex buffer firstInstance: instance ID offset
func (*RenderPass) DrawFullScreenTriangle ¶
func (p *RenderPass) DrawFullScreenTriangle()
DrawFullScreenTriangle is a convenience method for drawing a full-screen triangle. This is commonly used for post-processing effects and texture blits. Uses 3 vertices with no instance or offset.
func (*RenderPass) DrawIndexed ¶
func (p *RenderPass) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, firstInstance uint32)
DrawIndexed issues an indexed draw call.
func (*RenderPass) End ¶
func (p *RenderPass) End()
End finishes the render pass. No more draw calls can be issued after this.
func (*RenderPass) SetBindGroup ¶
func (p *RenderPass) SetBindGroup(index uint32, bindGroup StubBindGroupID)
SetBindGroup sets a bind group at the specified index.
func (*RenderPass) SetIndexBuffer ¶
func (p *RenderPass) SetIndexBuffer(buffer StubBufferID, format IndexFormat)
SetIndexBuffer sets the index buffer for indexed drawing.
func (*RenderPass) SetPipeline ¶
func (p *RenderPass) SetPipeline(pipeline StubPipelineID)
SetPipeline sets the render pipeline for subsequent draw calls.
func (*RenderPass) SetVertexBuffer ¶
func (p *RenderPass) SetVertexBuffer(slot uint32, buffer StubBufferID)
SetVertexBuffer sets a vertex buffer at the specified slot.
func (*RenderPass) Target ¶
func (p *RenderPass) Target() *GPUTexture
Target returns the render target texture.
type SegmentList ¶ added in v0.15.0
type SegmentList struct {
// contains filtered or unexported fields
}
SegmentList is a collection of line segments.
func FlattenPath ¶ added in v0.15.0
FlattenPath flattens a path to monotonic line segments. It converts Bezier curves to line segments and ensures all segments are monotonic in Y (Y0 <= Y1).
Parameters:
- path: The input path to flatten
- transform: Affine transformation to apply to all points
- tolerance: Flattening tolerance (use FlattenTolerance for default)
Returns a SegmentList containing all flattened line segments.
func NewSegmentList ¶ added in v0.15.0
func NewSegmentList() *SegmentList
NewSegmentList creates a new empty segment list.
func (*SegmentList) Add ¶ added in v0.15.0
func (sl *SegmentList) Add(seg LineSegment)
Add adds a segment to the list.
func (*SegmentList) AddLine ¶ added in v0.15.0
func (sl *SegmentList) AddLine(x0, y0, x1, y1 float32, winding int8)
AddLine adds a line segment from (x0,y0) to (x1,y1).
func (*SegmentList) Bounds ¶ added in v0.15.0
func (sl *SegmentList) Bounds() (minX, minY, maxX, maxY float32)
Bounds returns the bounding box of all segments.
func (*SegmentList) Len ¶ added in v0.15.0
func (sl *SegmentList) Len() int
Len returns the number of segments.
func (*SegmentList) Reset ¶ added in v0.15.0
func (sl *SegmentList) Reset()
Reset clears the list for reuse.
func (*SegmentList) Segments ¶ added in v0.15.0
func (sl *SegmentList) Segments() []LineSegment
Segments returns the slice of segments.
func (*SegmentList) SegmentsInTileRow ¶ added in v0.15.0
func (sl *SegmentList) SegmentsInTileRow(tileY int32) []LineSegment
SegmentsInTileRow returns segments that cross a given tile row. The list should be sorted by TileY0 for efficient access.
func (*SegmentList) SortByTileY ¶ added in v0.15.0
func (sl *SegmentList) SortByTileY()
SortByTileY sorts segments by their starting tile Y coordinate. This enables efficient row-by-row processing.
func (*SegmentList) TileYRange ¶ added in v0.15.0
func (sl *SegmentList) TileYRange() (minTileY, maxTileY int32)
TileYRange returns the range of tile rows that segments span.
type ShaderModuleID ¶
type ShaderModuleID uint64
ShaderModuleID represents a compiled shader module handle. This is a placeholder type that will be replaced with the actual wgpu core.ShaderModuleID once shader compilation is implemented.
const InvalidShaderModule ShaderModuleID = 0
InvalidShaderModule represents an invalid/uninitialized shader module.
type ShaderModules ¶
type ShaderModules struct {
// Blit is the simple texture copy shader
Blit ShaderModuleID
// Blend is the 29-mode blend shader
Blend ShaderModuleID
// Strip is the strip rasterization compute shader
Strip ShaderModuleID
// Composite is the final layer compositing shader
Composite ShaderModuleID
}
ShaderModules holds compiled shader modules for all rendering operations.
func CompileShaders ¶
func CompileShaders(deviceID uint64) (*ShaderModules, error)
CompileShaders compiles all WGSL shaders and returns the shader modules. This function currently returns stub module IDs since gogpu/wgpu shader compilation is not yet fully implemented. The WGSL sources are validated for correct syntax.
Parameters:
- deviceID: The GPU device ID to use for compilation (currently unused)
Returns:
- *ShaderModules: Compiled shader module handles
- error: Compilation error if shader sources are invalid
func (*ShaderModules) IsValid ¶
func (s *ShaderModules) IsValid() bool
IsValid returns true if all shader modules are initialized.
type SparseStrip ¶ added in v0.15.0
type SparseStrip struct {
X uint16 // X coordinate in pixels
Y uint16 // Y coordinate in pixels
AlphaIdx uint32 // Index into alpha buffer
FillGap bool // Whether to fill gap before this strip
}
SparseStrip represents a sparse strip for efficient rendering. A strip is a horizontal run of tiles with the same Y coordinate. This is different from the legacy Strip type in strips.go.
type SparseStripsConfig ¶ added in v0.15.0
type SparseStripsConfig struct {
Width uint16
Height uint16
FillRule scene.FillStyle
Tolerance float32 // Flattening tolerance (0 uses default)
}
SparseStripsConfig configures the sparse strips rasterizer.
func DefaultConfig ¶ added in v0.15.0
func DefaultConfig(width, height uint16) SparseStripsConfig
DefaultConfig returns a default configuration.
type SparseStripsPool ¶ added in v0.15.0
type SparseStripsPool struct {
// contains filtered or unexported fields
}
SparseStripsPool manages pooled rasterizers for reuse.
func NewSparseStripsPool ¶ added in v0.15.0
func NewSparseStripsPool() *SparseStripsPool
NewSparseStripsPool creates a new pool.
func (*SparseStripsPool) Get ¶ added in v0.15.0
func (p *SparseStripsPool) Get(config SparseStripsConfig) *SparseStripsRasterizer
Get retrieves a rasterizer from the pool or creates a new one.
func (*SparseStripsPool) Put ¶ added in v0.15.0
func (p *SparseStripsPool) Put(ssr *SparseStripsRasterizer)
Put returns a rasterizer to the pool.
type SparseStripsRasterizer ¶ added in v0.15.0
type SparseStripsRasterizer struct {
// contains filtered or unexported fields
}
SparseStripsRasterizer is the main entry point for vello-style sparse strips rendering. It orchestrates the complete pipeline: flatten -> coarse -> fine -> render.
The sparse strips algorithm works by: 1. Flattening Bezier curves to monotonic line segments 2. Coarse rasterization: binning segments into tiles they intersect 3. Fine rasterization: calculating analytic anti-aliased coverage per pixel 4. Rendering: outputting coverage as strips for efficient GPU rendering
func NewSparseStripsRasterizer ¶ added in v0.15.0
func NewSparseStripsRasterizer(config SparseStripsConfig) *SparseStripsRasterizer
NewSparseStripsRasterizer creates a new sparse strips rasterizer.
func (*SparseStripsRasterizer) FillRule ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) FillRule() scene.FillStyle
FillRule returns the current fill rule.
func (*SparseStripsRasterizer) GetStats ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) GetStats() Stats
GetStats returns statistics about the current rasterization state.
func (*SparseStripsRasterizer) Grid ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Grid() *TileGrid
Grid returns the tile grid with computed coverage.
func (*SparseStripsRasterizer) Height ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Height() uint16
Height returns the viewport height.
func (*SparseStripsRasterizer) RasterizePath ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) RasterizePath( path *scene.Path, transform scene.Affine, tolerance float32, )
RasterizePath rasterizes a single path to the tile grid.
func (*SparseStripsRasterizer) RasterizeToStrips ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) RasterizeToStrips( path *scene.Path, transform scene.Affine, tolerance float32, )
RasterizeToStrips rasterizes a path and generates sparse strips.
func (*SparseStripsRasterizer) RenderStripsToBuffer ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) RenderStripsToBuffer( buffer []uint8, stride int, color [4]uint8, )
RenderStripsToBuffer renders strips to a pixel buffer.
func (*SparseStripsRasterizer) RenderToBuffer ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) RenderToBuffer( buffer []uint8, stride int, color [4]uint8, )
RenderToBuffer renders the rasterized coverage to a pixel buffer.
func (*SparseStripsRasterizer) Reset ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Reset()
Reset clears the rasterizer state for reuse with new geometry.
func (*SparseStripsRasterizer) Segments ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Segments() *SegmentList
Segments returns the flattened segments.
func (*SparseStripsRasterizer) SetFillRule ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) SetFillRule(rule scene.FillStyle)
SetFillRule sets the fill rule for rendering.
func (*SparseStripsRasterizer) SetSize ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) SetSize(width, height uint16)
SetSize changes the rasterizer viewport dimensions.
func (*SparseStripsRasterizer) Strips ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Strips() *StripRenderer
Strips returns the strip renderer with generated strips.
func (*SparseStripsRasterizer) Width ¶ added in v0.15.0
func (ssr *SparseStripsRasterizer) Width() uint16
Width returns the viewport width.
type Stats ¶ added in v0.15.0
type Stats struct {
SegmentCount int
TileEntryCount int
ActiveTileCount int
StripCount int
AlphaByteCount int
}
Stats contains statistics about the rasterization process.
type StripParams ¶
type StripParams struct {
Color [4]float32 // Fill color (premultiplied RGBA)
TargetWidth int32 // Output texture width
TargetHeight int32 // Output texture height
StripCount int32 // Number of strips to process
Padding int32 // Alignment padding
}
StripParams represents the uniform buffer structure for strip shaders. This matches the StripParams struct in strip.wgsl.
type StripRenderer ¶ added in v0.15.0
type StripRenderer struct {
// contains filtered or unexported fields
}
StripRenderer renders tiles as sparse strips.
func NewStripRenderer ¶ added in v0.15.0
func NewStripRenderer() *StripRenderer
NewStripRenderer creates a new strip renderer.
func (*StripRenderer) Alphas ¶ added in v0.15.0
func (sr *StripRenderer) Alphas() []uint8
Alphas returns the alpha buffer.
func (*StripRenderer) RenderTiles ¶ added in v0.15.0
func (sr *StripRenderer) RenderTiles( coarse *CoarseRasterizer, segments *SegmentList, backdrop []int32, )
RenderTiles converts tiles to strips for efficient rendering.
func (*StripRenderer) Reset ¶ added in v0.15.0
func (sr *StripRenderer) Reset()
Reset clears the renderer state for reuse.
func (*StripRenderer) SetAliasMode ¶ added in v0.15.0
func (sr *StripRenderer) SetAliasMode(enabled bool)
SetAliasMode enables or disables aliased (non-anti-aliased) rendering.
func (*StripRenderer) SetFillRule ¶ added in v0.15.0
func (sr *StripRenderer) SetFillRule(rule scene.FillStyle)
SetFillRule sets the fill rule.
func (*StripRenderer) Strips ¶ added in v0.15.0
func (sr *StripRenderer) Strips() []SparseStrip
Strips returns the strips.
type StubBindGroupID ¶
type StubBindGroupID uint64
StubBindGroupID is a placeholder for actual wgpu BindGroupID.
type StubBindGroupLayoutID ¶
type StubBindGroupLayoutID uint64
StubBindGroupLayoutID is a placeholder for actual wgpu BindGroupLayoutID.
type StubBufferID ¶
type StubBufferID uint64
StubBufferID is a placeholder for actual wgpu BufferID.
type StubCommandBufferID ¶
type StubCommandBufferID uint64
StubCommandBufferID is a placeholder for actual wgpu CommandBufferID.
type StubCommandEncoderID ¶
type StubCommandEncoderID uint64
StubCommandEncoderID is a placeholder for actual wgpu CommandEncoderID.
type StubComputePassID ¶
type StubComputePassID uint64
StubComputePassID is a placeholder for actual wgpu ComputePassID.
type StubComputePipelineID ¶
type StubComputePipelineID uint64
StubComputePipelineID is a placeholder for actual wgpu ComputePipelineID.
type StubPipelineID ¶
type StubPipelineID uint64
StubPipelineID is a placeholder for actual wgpu RenderPipelineID. This will be replaced with core.RenderPipelineID when wgpu support is complete.
const InvalidPipelineID StubPipelineID = 0
InvalidPipelineID represents an invalid/uninitialized pipeline.
type StubRenderPassID ¶
type StubRenderPassID uint64
StubRenderPassID is a placeholder for actual wgpu RenderPassID.
type StubSamplerID ¶ added in v0.11.0
type StubSamplerID uint64
StubSamplerID is a placeholder for actual wgpu SamplerID.
type TextBatch ¶ added in v0.11.0
TextBatch represents a batch of text quads with shared rendering parameters.
type TextPipeline ¶ added in v0.11.0
type TextPipeline struct {
// contains filtered or unexported fields
}
TextPipeline handles GPU-accelerated MSDF text rendering. It manages the render pipeline, bind groups, and vertex buffers for rendering text using multi-channel signed distance fields.
TextPipeline is safe for concurrent use after initialization.
func NewTextPipeline ¶ added in v0.11.0
func NewTextPipeline(device core.DeviceID, config TextPipelineConfig) (*TextPipeline, error)
NewTextPipeline creates a new text rendering pipeline. The pipeline must be initialized before use.
func NewTextPipelineDefault ¶ added in v0.11.0
func NewTextPipelineDefault(device core.DeviceID) (*TextPipeline, error)
NewTextPipelineDefault creates a text pipeline with default configuration.
func (*TextPipeline) Close ¶ added in v0.11.0
func (p *TextPipeline) Close()
Close releases all pipeline resources.
func (*TextPipeline) Config ¶ added in v0.11.0
func (p *TextPipeline) Config() TextPipelineConfig
Config returns the pipeline configuration.
func (*TextPipeline) GetOrCreateAtlasBindGroup ¶ added in v0.11.0
func (p *TextPipeline) GetOrCreateAtlasBindGroup(atlasIndex int, atlasTexture *GPUTexture) (StubBindGroupID, error)
GetOrCreateAtlasBindGroup gets or creates a bind group for an atlas texture.
func (*TextPipeline) Init ¶ added in v0.11.0
func (p *TextPipeline) Init() error
Init initializes the text pipeline, compiling shaders and creating GPU resources.
func (*TextPipeline) InvalidateAllAtlasBindGroups ¶ added in v0.11.0
func (p *TextPipeline) InvalidateAllAtlasBindGroups()
InvalidateAllAtlasBindGroups removes all cached bind groups.
func (*TextPipeline) InvalidateAtlasBindGroup ¶ added in v0.11.0
func (p *TextPipeline) InvalidateAtlasBindGroup(atlasIndex int)
InvalidateAtlasBindGroup removes a cached bind group for an atlas. Call this when an atlas texture is updated.
func (*TextPipeline) IsInitialized ¶ added in v0.11.0
func (p *TextPipeline) IsInitialized() bool
IsInitialized returns true if the pipeline has been initialized.
func (*TextPipeline) RenderText ¶ added in v0.11.0
func (p *TextPipeline) RenderText( pass *RenderPass, quads []TextQuad, atlasIndex int, color gg.RGBA, transform gg.Matrix, ) error
RenderText renders text quads using the specified atlas. All quads are rendered in a single draw call for efficiency.
Parameters:
- pass: The render pass to record commands into
- quads: Text quads to render (position and UV for each glyph)
- atlasIndex: Index of the MSDF atlas texture to use
- color: Text color (RGBA, will be premultiplied)
- transform: 2D affine transform matrix (gg.Matrix)
Note: This is a stub implementation that validates inputs and prepares vertex data. Actual GPU rendering will be implemented when wgpu is ready.
func (*TextPipeline) RenderTextBatch ¶ added in v0.11.0
func (p *TextPipeline) RenderTextBatch( pass *RenderPass, batches []TextBatch, atlasIndex int, ) error
RenderTextBatch renders multiple text batches efficiently. Each batch can have different color and transform but shares the same atlas.
type TextPipelineConfig ¶ added in v0.11.0
type TextPipelineConfig struct {
// InitialQuadCapacity is the initial vertex buffer capacity in quads.
// Default: 256
InitialQuadCapacity int
// MaxQuadCapacity is the maximum number of quads per draw call.
// Default: 16384
MaxQuadCapacity int
// DefaultPxRange is the default MSDF pixel range.
// Default: 4.0
DefaultPxRange float32
}
TextPipelineConfig holds configuration for the text pipeline.
func DefaultTextPipelineConfig ¶ added in v0.11.0
func DefaultTextPipelineConfig() TextPipelineConfig
DefaultTextPipelineConfig returns default configuration.
type TextQuad ¶ added in v0.11.0
type TextQuad struct {
// Position of quad corners in screen/clip space
X0, Y0, X1, Y1 float32
// UV coordinates in MSDF atlas [0, 1]
U0, V0, U1, V1 float32
}
TextQuad represents a single glyph quad for rendering. Each glyph is rendered as a textured quad with position and UV coordinates.
type TextRenderer ¶ added in v0.11.0
type TextRenderer struct {
// contains filtered or unexported fields
}
TextRenderer provides a higher-level API for rendering text. It combines TextPipeline with AtlasManager for convenient text rendering.
func NewTextRenderer ¶ added in v0.11.0
func NewTextRenderer(backend *WGPUBackend, config TextRendererConfig) (*TextRenderer, error)
NewTextRenderer creates a new text renderer.
func (*TextRenderer) AtlasManager ¶ added in v0.11.0
func (r *TextRenderer) AtlasManager() *msdf.AtlasManager
AtlasManager returns the underlying atlas manager.
func (*TextRenderer) Close ¶ added in v0.11.0
func (r *TextRenderer) Close()
Close releases all renderer resources.
func (*TextRenderer) Init ¶ added in v0.11.0
func (r *TextRenderer) Init() error
Init initializes the text renderer.
func (*TextRenderer) Pipeline ¶ added in v0.11.0
func (r *TextRenderer) Pipeline() *TextPipeline
Pipeline returns the underlying text pipeline.
func (*TextRenderer) SyncAtlases ¶ added in v0.11.0
func (r *TextRenderer) SyncAtlases() error
SyncAtlases uploads dirty atlases to GPU.
type TextRendererConfig ¶ added in v0.11.0
type TextRendererConfig struct {
// PipelineConfig for the underlying text pipeline.
PipelineConfig TextPipelineConfig
// AtlasConfig for the MSDF atlas manager.
AtlasConfig msdf.AtlasConfig
}
TextRendererConfig holds configuration for TextRenderer.
func DefaultTextRendererConfig ¶ added in v0.11.0
func DefaultTextRendererConfig() TextRendererConfig
DefaultTextRendererConfig returns default configuration.
type TextUniforms ¶ added in v0.11.0
type TextUniforms struct {
// Transform matrix (4x4 for alignment, row-major)
// Maps local coordinates to clip space [-1, 1]
Transform [16]float32
// Text color (RGBA, premultiplied alpha)
Color [4]float32
// MSDF parameters:
// [0]: px_range (distance range in pixels)
// [1]: atlas_size (texture size)
// [2]: outline_width (for outline effect)
// [3]: reserved
MSDFParams [4]float32
}
TextUniforms represents the uniform buffer for text shaders. Matches the TextUniforms struct in msdf_text.wgsl.
type TextVertex ¶ added in v0.11.0
type TextVertex struct {
// Position in local/screen space
X, Y float32
// UV coordinates in atlas
U, V float32
}
TextVertex represents a single vertex for text rendering. Matches the VertexInput struct in msdf_text.wgsl.
type TextureAtlas ¶
type TextureAtlas struct {
// contains filtered or unexported fields
}
TextureAtlas manages a texture atlas for efficient batching of small images. It combines multiple small textures into a single large GPU texture to reduce draw calls and texture binding changes.
TextureAtlas is safe for concurrent use.
func NewTextureAtlas ¶
func NewTextureAtlas(backend *WGPUBackend, config TextureAtlasConfig) (*TextureAtlas, error)
NewTextureAtlas creates a new texture atlas with the given configuration.
func (*TextureAtlas) AllocCount ¶
func (a *TextureAtlas) AllocCount() int
AllocCount returns the number of allocated regions.
func (*TextureAtlas) Allocate ¶
func (a *TextureAtlas) Allocate(width, height int) (AtlasRegion, error)
Allocate finds space for a rectangle of the given size. Returns an invalid region (Width/Height == 0) if the atlas is full.
func (*TextureAtlas) AllocateAndUpload ¶
func (a *TextureAtlas) AllocateAndUpload(pixmap *gg.Pixmap) (AtlasRegion, error)
AllocateAndUpload combines Allocate and Upload into a single operation. This is a convenience method for adding new images to the atlas.
func (*TextureAtlas) Close ¶
func (a *TextureAtlas) Close()
Close releases the atlas resources. The atlas should not be used after Close is called.
func (*TextureAtlas) Height ¶
func (a *TextureAtlas) Height() int
Height returns the atlas height in pixels.
func (*TextureAtlas) IsClosed ¶
func (a *TextureAtlas) IsClosed() bool
IsClosed returns true if the atlas has been closed.
func (*TextureAtlas) Reset ¶
func (a *TextureAtlas) Reset()
Reset clears all allocations, making the entire atlas available again. Note: This does not clear the texture data, just the allocation tracking.
func (*TextureAtlas) Texture ¶
func (a *TextureAtlas) Texture() *GPUTexture
Texture returns the underlying GPU texture.
func (*TextureAtlas) Upload ¶
func (a *TextureAtlas) Upload(region AtlasRegion, pixmap *gg.Pixmap) error
Upload copies pixel data from a pixmap to a region of the atlas. The pixmap dimensions must match the region dimensions.
func (*TextureAtlas) Utilization ¶
func (a *TextureAtlas) Utilization() float64
Utilization returns the fraction of atlas area used (0.0 to 1.0).
func (*TextureAtlas) Width ¶
func (a *TextureAtlas) Width() int
Width returns the atlas width in pixels.
type TextureAtlasConfig ¶
type TextureAtlasConfig struct {
// Width is the atlas width in pixels. Defaults to DefaultAtlasSize.
Width int
// Height is the atlas height in pixels. Defaults to DefaultAtlasSize.
Height int
// Padding is the spacing between regions. Defaults to DefaultShelfPadding.
Padding int
// Label is an optional debug label.
Label string
}
TextureAtlasConfig holds configuration for creating a TextureAtlas.
type TextureConfig ¶
type TextureConfig struct {
// Width is the texture width in pixels.
Width int
// Height is the texture height in pixels.
Height int
// Format is the pixel format.
Format TextureFormat
// Label is an optional debug label.
Label string
// Usage flags (default: CopySrc | CopyDst | TextureBinding)
Usage types.TextureUsage
}
TextureConfig holds configuration for creating a new texture.
type TextureFormat ¶
type TextureFormat uint8
TextureFormat represents the pixel format of a GPU texture.
const ( // TextureFormatRGBA8 is the standard RGBA format with 8 bits per channel. TextureFormatRGBA8 TextureFormat = iota // TextureFormatBGRA8 is BGRA format, often used for surface presentation. TextureFormatBGRA8 // TextureFormatR8 is single-channel 8-bit format, used for masks. TextureFormatR8 )
func (TextureFormat) BytesPerPixel ¶
func (f TextureFormat) BytesPerPixel() int
BytesPerPixel returns the number of bytes per pixel for the format.
func (TextureFormat) String ¶
func (f TextureFormat) String() string
String returns a human-readable name for the format.
func (TextureFormat) ToWGPUFormat ¶
func (f TextureFormat) ToWGPUFormat() types.TextureFormat
ToWGPUFormat converts to wgpu types.TextureFormat. This will be used when actual GPU texture creation is implemented.
type Tile ¶ added in v0.15.0
type Tile struct {
// X, Y are tile coordinates (not pixel coordinates).
// Pixel coordinates are (X * TileSize, Y * TileSize).
X, Y int32
// Coverage holds 4×4 = 16 anti-aliased coverage values (0-255).
// Index = row * TileSize + col
Coverage [TileSize * TileSize]uint8
// Backdrop is the winding number entering this tile from the left.
// Used for propagating fill state across tile boundaries.
Backdrop int16
// SegmentCount tracks how many segments cross this tile.
// Used for optimization: tiles with 0 segments use backdrop only.
SegmentCount int16
}
Tile represents a 4×4 pixel tile with coverage data. This is the core unit of the sparse strips algorithm.
The coverage array stores anti-aliased alpha values for each pixel in row-major order: [row0: 0-3, row1: 4-7, row2: 8-11, row3: 12-15]
func (*Tile) FillSolid ¶ added in v0.15.0
FillSolid fills the entire tile with a single coverage value.
func (*Tile) GetCoverage ¶ added in v0.15.0
GetCoverage returns the coverage value for a pixel within the tile.
func (*Tile) IsSolid ¶ added in v0.15.0
IsSolid returns true if all coverage values are 255 (fully opaque).
func (*Tile) PixelX ¶ added in v0.15.0
PixelX returns the pixel X coordinate of the tile's top-left corner.
func (*Tile) PixelY ¶ added in v0.15.0
PixelY returns the pixel Y coordinate of the tile's top-left corner.
func (*Tile) SetCoverage ¶ added in v0.15.0
SetCoverage sets the coverage value for a pixel within the tile. px, py are pixel offsets within the tile (0-3).
type TileCoord ¶ added in v0.15.0
type TileCoord struct {
X, Y int32
}
TileCoord represents tile coordinates for hashing.
type TileCoverage16 ¶ added in v0.15.0
type TileCoverage16 [16]uint8
TileCoverage16 holds coverage values for a 4×4 tile.
func ProcessMultipleSegmentsSIMD ¶ added in v0.15.0
func ProcessMultipleSegmentsSIMD( lines []LineSegment, lineIndices []uint32, tileX, tileY uint16, backdrop float32, fillRule scene.FillStyle, ) TileCoverage16
ProcessMultipleSegmentsSIMD processes multiple segments for a single tile. This batches segment processing to maximize SIMD utilization.
type TileGrid ¶ added in v0.15.0
type TileGrid struct {
// contains filtered or unexported fields
}
TileGrid is a sparse collection of non-empty tiles. It uses a hashmap for O(1) tile lookup by coordinates.
func NewTileGrid ¶ added in v0.15.0
func NewTileGrid() *TileGrid
NewTileGrid creates a new empty tile grid.
func RasterizePath ¶ added in v0.15.0
func RasterizePath( path *scene.Path, transform scene.Affine, width, height uint16, fillRule scene.FillStyle, ) *TileGrid
RasterizePath is a convenience function that rasterizes a path using a pooled rasterizer.
func (*TileGrid) Bounds ¶ added in v0.15.0
Bounds returns the bounding rectangle in tile coordinates.
func (*TileGrid) ForEachInRow ¶ added in v0.15.0
ForEachInRow iterates over tiles in a specific row, sorted by X.
func (*TileGrid) ForEachSorted ¶ added in v0.15.0
ForEachSorted iterates over tiles sorted by Y, then X. This is important for correct backdrop propagation.
func (*TileGrid) GetOrCreate ¶ added in v0.15.0
GetOrCreate returns the tile at the given coordinates, creating if needed.
func (*TileGrid) PixelBounds ¶ added in v0.15.0
PixelBounds returns the bounding rectangle in pixel coordinates.
func (*TileGrid) Reset ¶ added in v0.15.0
func (g *TileGrid) Reset()
Reset clears the grid for reuse.
func (*TileGrid) SetFillRule ¶ added in v0.15.0
SetFillRule sets the fill rule for coverage calculation.
type TilePool ¶ added in v0.15.0
type TilePool struct {
// contains filtered or unexported fields
}
TilePool manages a pool of reusable tiles.
func NewTilePool ¶ added in v0.15.0
func NewTilePool() *TilePool
NewTilePool creates a new tile pool.
type TileWinding16 ¶ added in v0.15.0
type TileWinding16 [16]float32
TileWinding16 holds winding values for a 4×4 tile in SIMD-friendly layout. All 16 pixels stored contiguously for vectorized operations.
type WGPUBackend ¶
type WGPUBackend struct {
// contains filtered or unexported fields
}
WGPUBackend is a GPU-accelerated rendering backend using gogpu/wgpu. It implements the backend.RenderBackend interface.
The backend manages GPU resources including instance, adapter, device, and queue. It supports both immediate mode rendering (via NewRenderer) and retained mode rendering (via RenderScene).
func NewWGPUBackend ¶
func NewWGPUBackend() *WGPUBackend
NewWGPUBackend creates a new WGPU rendering backend. The backend must be initialized with Init() before use.
func (*WGPUBackend) Close ¶
func (b *WGPUBackend) Close()
Close releases all backend resources. The backend should not be used after Close is called.
func (*WGPUBackend) Device ¶
func (b *WGPUBackend) Device() core.DeviceID
Device returns the GPU device ID. Returns a zero ID if the backend is not initialized.
func (*WGPUBackend) GPUInfo ¶
func (b *WGPUBackend) GPUInfo() *GPUInfo
GPUInfo returns information about the selected GPU. Returns nil if the backend is not initialized.
func (*WGPUBackend) Init ¶
func (b *WGPUBackend) Init() error
Init initializes the backend by creating GPU resources. This includes creating an instance, requesting an adapter, creating a device, and getting the command queue.
Returns an error if GPU initialization fails.
func (*WGPUBackend) IsInitialized ¶
func (b *WGPUBackend) IsInitialized() bool
IsInitialized returns true if the backend has been initialized.
func (*WGPUBackend) NewRenderer ¶
func (b *WGPUBackend) NewRenderer(width, height int) gg.Renderer
NewRenderer creates a renderer for immediate mode rendering. The renderer is sized for the given dimensions.
Note: This is a stub implementation that returns a GPURenderer. The actual GPU rendering will be implemented in TASK-110.
func (*WGPUBackend) Queue ¶
func (b *WGPUBackend) Queue() core.QueueID
Queue returns the GPU queue ID. Returns a zero ID if the backend is not initialized.
func (*WGPUBackend) RenderScene ¶
RenderScene renders a scene to the target pixmap using retained mode. This method is optimized for complex scenes with many draw operations.
The implementation uses GPUSceneRenderer for tessellation, strip rasterization, and layer compositing on the GPU. When wgpu texture readback is fully implemented, results will be downloaded to the target pixmap. Currently, data flows through the GPU pipeline as stubs.