software

package
v0.29.11 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 20 Imported by: 1

Documentation

Overview

Package software provides a CPU-based software rendering backend.

The software backend implements all HAL interfaces using pure Go CPU rendering. Unlike the noop backend, it actually performs rendering operations in memory, including full SPIR-V shader execution for vertex, fragment, and compute stages.

Use cases:

  • Shader debugging (step through every SPIR-V instruction with breakpoints)
  • CI/CD testing (no GPU required)
  • Headless rendering (servers, screenshot generation)
  • GPU-less fallback (embedded systems)
  • NOT for real-time production rendering — use GPU backends for that

Implemented features:

  • Real data storage for buffers and textures
  • SPIR-V interpreter (~10K LOC): vertex, fragment, compute shaders on CPU
  • Compute shaders: CreateComputePipeline + Dispatch via SPIR-V interpreter
  • Texture sampling (nearest, bilinear, 3 wrap modes)
  • GLSL.std.450 math intrinsics (30+ functions)
  • Control flow (loops, phi, function calls, switch)
  • Atomics and workgroup shared memory
  • Shader debugger (DebugContext, breakpoints, JSON trace, zero overhead when disabled)
  • Buffer/texture copy operations
  • Clear operations
  • Windowed presentation (Windows GDI, Linux X11, macOS CG+Metal)
  • Thread-safe resource access

Limitations:

  • Much slower than GPU backends (CPU-bound, interpreter, not JIT)
  • No hardware acceleration
  • DispatchIndirect not implemented

Always compiled (no build tags required).

Example:

import _ "github.com/gogpu/wgpu/hal/software"

// Software backend is registered automatically
// Adapter name: "Software Renderer"
// Device type: types.DeviceTypeCPU

Backend identifier: types.BackendEmpty

Index

Constants

This section is empty.

Variables

View Source
var ErrComputeRequiresSPIRV = errors.New("software: compute pipeline requires SPIR-V shader (WGSL compilation may have failed)")

ErrComputeRequiresSPIRV indicates that a compute pipeline requires a shader module with SPIR-V bytecode. WGSL shaders must be compilable to SPIR-V via naga for the SPIR-V interpreter to execute them.

Functions

This section is empty.

Types

type API

type API struct{}

API implements hal.Backend for the software backend.

func (API) CreateInstance

func (API) CreateInstance(_ *hal.InstanceDescriptor) (hal.Instance, error)

CreateInstance creates a new software rendering instance. Always succeeds and returns a CPU-based rendering instance.

func (API) Variant

func (API) Variant() gputypes.Backend

Variant returns the backend type identifier.

type Adapter

type Adapter struct{}

Adapter implements hal.Adapter for the software backend.

func (*Adapter) Destroy

func (a *Adapter) Destroy()

Destroy is a no-op for the software adapter.

func (*Adapter) Open

Open creates a software device with the requested features and limits. Always succeeds and returns a device/queue pair.

func (*Adapter) SurfaceCapabilities

func (a *Adapter) SurfaceCapabilities(_ hal.Surface) *hal.SurfaceCapabilities

SurfaceCapabilities returns default surface capabilities.

func (*Adapter) TextureFormatCapabilities

func (a *Adapter) TextureFormatCapabilities(_ gputypes.TextureFormat) hal.TextureFormatCapabilities

TextureFormatCapabilities returns default capabilities for all formats.

type BindGroup added in v0.21.3

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

BindGroup stores bound resources for the software backend. It resolves handle-based entries to concrete software resource pointers.

type Buffer

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

Buffer implements hal.Buffer with real data storage. All software buffers store their data in memory.

func (*Buffer) GetData

func (b *Buffer) GetData() []byte

GetData returns a copy of the buffer data (thread-safe).

func (*Buffer) NativeHandle

func (b *Buffer) NativeHandle() uintptr

NativeHandle returns the buffer's unique ID for handle resolution.

func (*Buffer) WriteData

func (b *Buffer) WriteData(offset uint64, data []byte)

WriteData writes data to the buffer (thread-safe).

type CommandEncoder

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

CommandEncoder implements hal.CommandEncoder for the software backend. It holds a device reference so that compute passes can resolve bind group resources during dispatch.

func (*CommandEncoder) BeginComputePass

func (c *CommandEncoder) BeginComputePass(desc *hal.ComputePassDescriptor) hal.ComputePassEncoder

BeginComputePass begins a compute pass and returns an encoder. The device reference is passed through so Dispatch can resolve bind group buffer data.

func (*CommandEncoder) BeginEncoding

func (c *CommandEncoder) BeginEncoding(_ string) error

BeginEncoding is a no-op.

func (*CommandEncoder) BeginRenderPass

func (c *CommandEncoder) BeginRenderPass(desc *hal.RenderPassDescriptor) hal.RenderPassEncoder

BeginRenderPass begins a render pass and returns an encoder. If a depth/stencil attachment is present, a persistent stencil buffer is created for the entire pass (matching GPU behavior where the stencil buffer is the attachment texture, not recreated per draw call).

func (*CommandEncoder) ClearBuffer

func (c *CommandEncoder) ClearBuffer(buffer hal.Buffer, offset, size uint64)

ClearBuffer clears a buffer region to zero.

func (*CommandEncoder) CopyBufferToBuffer

func (c *CommandEncoder) CopyBufferToBuffer(src, dst hal.Buffer, regions []hal.BufferCopy)

CopyBufferToBuffer copies data between buffers.

func (*CommandEncoder) CopyBufferToTexture

func (c *CommandEncoder) CopyBufferToTexture(src hal.Buffer, dst hal.Texture, regions []hal.BufferTextureCopy)

CopyBufferToTexture copies data from a buffer to a texture.

func (*CommandEncoder) CopyTextureToBuffer

func (c *CommandEncoder) CopyTextureToBuffer(src hal.Texture, dst hal.Buffer, regions []hal.BufferTextureCopy)

CopyTextureToBuffer copies data from a texture to a buffer.

func (*CommandEncoder) CopyTextureToTexture

func (c *CommandEncoder) CopyTextureToTexture(src, dst hal.Texture, regions []hal.TextureCopy)

CopyTextureToTexture copies data between textures.

func (*CommandEncoder) Destroy added in v0.23.4

func (c *CommandEncoder) Destroy()

Destroy is a no-op for the software backend.

func (*CommandEncoder) DiscardEncoding

func (c *CommandEncoder) DiscardEncoding()

DiscardEncoding is a no-op.

func (*CommandEncoder) EndEncoding

func (c *CommandEncoder) EndEncoding() (hal.CommandBuffer, error)

EndEncoding returns a placeholder command buffer.

func (*CommandEncoder) ResetAll

func (c *CommandEncoder) ResetAll(_ []hal.CommandBuffer)

ResetAll is a no-op.

func (*CommandEncoder) ResolveQuerySet

func (c *CommandEncoder) ResolveQuerySet(_ hal.QuerySet, _, _ uint32, _ hal.Buffer, _ uint64)

ResolveQuerySet is a no-op (query sets not supported in software backend).

func (*CommandEncoder) TransitionBuffers

func (c *CommandEncoder) TransitionBuffers(_ []hal.BufferBarrier)

TransitionBuffers is a no-op (software backend doesn't need explicit transitions).

func (*CommandEncoder) TransitionTextures

func (c *CommandEncoder) TransitionTextures(_ []hal.TextureBarrier)

TransitionTextures is a no-op (software backend doesn't need explicit transitions).

type ComputePassEncoder

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

ComputePassEncoder implements hal.ComputePassEncoder for the software backend. It collects pipeline and bind group state, then executes the SPIR-V interpreter on Dispatch. Buffer writes from storage buffer bindings are reflected in-place.

func (*ComputePassEncoder) Dispatch

func (c *ComputePassEncoder) Dispatch(x, y, z uint32)

Dispatch executes the compute shader for x*y*z workgroups.

The implementation:

  1. Gets the parsed SPIR-V module from the pipeline's shader module.
  2. Reads the workgroup size from the entry point's OpExecutionMode LocalSize.
  3. Builds an ExecutionContext with Buffers populated from bound bind groups.
  4. Delegates to Module.DispatchCompute which iterates over all workgroups and invocations, calling ExecuteCompute for each.
  5. Storage buffer writes are reflected in-place through shared []byte slices.

func (*ComputePassEncoder) DispatchIndirect

func (c *ComputePassEncoder) DispatchIndirect(_ hal.Buffer, _ uint64)

DispatchIndirect is not yet implemented in the software backend. Indirect dispatch requires reading the dispatch parameters from a GPU buffer, which is straightforward but not needed for the current use cases.

func (*ComputePassEncoder) End

func (c *ComputePassEncoder) End()

End finishes the compute pass. Currently a no-op since all work is done synchronously in Dispatch.

func (*ComputePassEncoder) SetBindGroup

func (c *ComputePassEncoder) SetBindGroup(index uint32, bg hal.BindGroup, _ []uint32)

SetBindGroup stores a bind group at the given index for compute dispatch.

func (*ComputePassEncoder) SetPipeline

func (c *ComputePassEncoder) SetPipeline(p hal.ComputePipeline)

SetPipeline stores the compute pipeline for subsequent Dispatch calls.

type ComputePipeline added in v0.27.0

type ComputePipeline struct {
	Resource
	// contains filtered or unexported fields
}

ComputePipeline stores compute pipeline configuration for the software backend. It holds a reference to the parsed SPIR-V module and entry point name, which are used by ComputePassEncoder.Dispatch to invoke the SPIR-V interpreter.

type Device

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

Device implements hal.Device for the software backend. It maintains a resource registry for resolving handle-based bind group entries back to typed software resources.

func (*Device) CreateBindGroup

func (d *Device) CreateBindGroup(desc *hal.BindGroupDescriptor) (hal.BindGroup, error)

CreateBindGroup creates a software bind group. It resolves handle-based entries to typed software resources using the device registry.

func (*Device) CreateBindGroupLayout

func (d *Device) CreateBindGroupLayout(_ *hal.BindGroupLayoutDescriptor) (hal.BindGroupLayout, error)

CreateBindGroupLayout creates a software bind group layout.

func (*Device) CreateBuffer

func (d *Device) CreateBuffer(desc *hal.BufferDescriptor) (hal.Buffer, error)

CreateBuffer creates a software buffer with real data storage.

func (*Device) CreateCommandEncoder

func (d *Device) CreateCommandEncoder(_ *hal.CommandEncoderDescriptor) (hal.CommandEncoder, error)

CreateCommandEncoder creates a software command encoder. The encoder holds a device reference so compute passes can resolve bind group resources during dispatch.

func (*Device) CreateComputePipeline

func (d *Device) CreateComputePipeline(desc *hal.ComputePipelineDescriptor) (hal.ComputePipeline, error)

CreateComputePipeline creates a software compute pipeline backed by the SPIR-V interpreter. The shader module must contain SPIR-V bytecode (either provided directly or compiled from WGSL via naga).

func (*Device) CreateFence

func (d *Device) CreateFence() (hal.Fence, error)

CreateFence creates a software fence with atomic counter.

func (*Device) CreatePipelineLayout

func (d *Device) CreatePipelineLayout(_ *hal.PipelineLayoutDescriptor) (hal.PipelineLayout, error)

CreatePipelineLayout creates a software pipeline layout.

func (*Device) CreateQuerySet

func (d *Device) CreateQuerySet(_ *hal.QuerySetDescriptor) (hal.QuerySet, error)

CreateQuerySet is not supported in the software backend.

func (*Device) CreateRenderBundleEncoder

func (d *Device) CreateRenderBundleEncoder(_ *hal.RenderBundleEncoderDescriptor) (hal.RenderBundleEncoder, error)

CreateRenderBundleEncoder is not supported in the software backend.

func (*Device) CreateRenderPipeline

func (d *Device) CreateRenderPipeline(desc *hal.RenderPipelineDescriptor) (hal.RenderPipeline, error)

CreateRenderPipeline creates a software render pipeline.

func (*Device) CreateSampler

func (d *Device) CreateSampler(desc *hal.SamplerDescriptor) (hal.Sampler, error)

CreateSampler creates a software sampler with actual parameters. The sampler is stored in the device registry so CreateBindGroup can resolve the handle back to a SamplerResource for the SPIR-V interpreter.

func (*Device) CreateShaderModule

func (d *Device) CreateShaderModule(desc *hal.ShaderModuleDescriptor) (hal.ShaderModule, error)

CreateShaderModule creates a software shader module. If the source is WGSL, it compiles to SPIR-V via naga for interpretation. If SPIR-V is provided directly, it is stored as-is. Compilation failure is non-fatal: the module falls back to the existing callback-based shader path (fullscreen blit, vertex buffer draw).

func (*Device) CreateTexture

func (d *Device) CreateTexture(desc *hal.TextureDescriptor) (hal.Texture, error)

CreateTexture creates a software texture with real pixel storage.

func (*Device) CreateTextureView

func (d *Device) CreateTextureView(texture hal.Texture, _ *hal.TextureViewDescriptor) (hal.TextureView, error)

CreateTextureView creates a software texture view.

func (*Device) Destroy

func (d *Device) Destroy()

Destroy is a no-op for the software device.

func (*Device) DestroyBindGroup

func (d *Device) DestroyBindGroup(_ hal.BindGroup)

DestroyBindGroup is a no-op.

func (*Device) DestroyBindGroupLayout

func (d *Device) DestroyBindGroupLayout(_ hal.BindGroupLayout)

DestroyBindGroupLayout is a no-op.

func (*Device) DestroyBuffer

func (d *Device) DestroyBuffer(_ hal.Buffer)

DestroyBuffer is a no-op (Go GC handles cleanup).

func (*Device) DestroyComputePipeline

func (d *Device) DestroyComputePipeline(_ hal.ComputePipeline)

DestroyComputePipeline is a no-op.

func (*Device) DestroyFence

func (d *Device) DestroyFence(_ hal.Fence)

DestroyFence is a no-op.

func (*Device) DestroyPipelineLayout

func (d *Device) DestroyPipelineLayout(_ hal.PipelineLayout)

DestroyPipelineLayout is a no-op.

func (*Device) DestroyQuerySet

func (d *Device) DestroyQuerySet(_ hal.QuerySet)

DestroyQuerySet is a no-op for the software device.

func (*Device) DestroyRenderBundle

func (d *Device) DestroyRenderBundle(_ hal.RenderBundle)

DestroyRenderBundle is a no-op for the software device.

func (*Device) DestroyRenderPipeline

func (d *Device) DestroyRenderPipeline(_ hal.RenderPipeline)

DestroyRenderPipeline is a no-op.

func (*Device) DestroySampler

func (d *Device) DestroySampler(_ hal.Sampler)

DestroySampler is a no-op.

func (*Device) DestroyShaderModule

func (d *Device) DestroyShaderModule(_ hal.ShaderModule)

DestroyShaderModule is a no-op.

func (*Device) DestroyTexture

func (d *Device) DestroyTexture(_ hal.Texture)

DestroyTexture is a no-op (Go GC handles cleanup).

func (*Device) DestroyTextureView

func (d *Device) DestroyTextureView(_ hal.TextureView)

DestroyTextureView is a no-op.

func (*Device) FreeCommandBuffer

func (d *Device) FreeCommandBuffer(_ hal.CommandBuffer)

FreeCommandBuffer is a no-op for the software device.

func (*Device) GetFenceStatus

func (d *Device) GetFenceStatus(fence hal.Fence) (bool, error)

GetFenceStatus returns true if the fence is signaled (non-blocking).

func (*Device) MapBuffer added in v0.25.0

func (d *Device) MapBuffer(buffer hal.Buffer, offset, size uint64) (hal.BufferMapping, error)

MapBuffer returns a pointer into the buffer's backing Go slice. Software buffers are always host-visible and coherent.

func (*Device) ResetFence

func (d *Device) ResetFence(fence hal.Fence) error

ResetFence resets a fence to the unsignaled state.

func (*Device) UnmapBuffer added in v0.25.0

func (d *Device) UnmapBuffer(_ hal.Buffer) error

UnmapBuffer is a no-op — software buffers are persistently host-visible.

func (*Device) Wait

func (d *Device) Wait(fence hal.Fence, value uint64, _ time.Duration) (bool, error)

Wait simulates waiting for a fence value. Always returns true immediately (fence reached).

func (*Device) WaitIdle

func (d *Device) WaitIdle() error

WaitIdle is a no-op for the software device.

type Fence

type Fence struct {
	Resource
	// contains filtered or unexported fields
}

Fence implements hal.Fence with an atomic counter for synchronization.

type Instance

type Instance struct{}

Instance implements hal.Instance for the software backend.

func (*Instance) CreateSurface

func (i *Instance) CreateSurface(displayHandle, window uintptr) (hal.Surface, error)

CreateSurface creates a software rendering surface. If a valid window handle is provided, Present() will automatically blit the framebuffer to the window via platform-native APIs (GDI on Windows, XPutImage on Linux X11). If window is 0 (headless mode), Present() is a no-op.

displayHandle is platform-specific: X11 Display* on Linux, 0 elsewhere. windowHandle is the native window: HWND on Windows, X11 Window on Linux.

func (*Instance) Destroy

func (i *Instance) Destroy()

Destroy is a no-op for the software instance.

func (*Instance) EnumerateAdapters

func (i *Instance) EnumerateAdapters(_ hal.Surface) []hal.ExposedAdapter

EnumerateAdapters returns a single default software adapter. The surfaceHint is ignored.

type Queue

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

Queue implements hal.Queue for the software backend.

func (*Queue) GetTimestampPeriod

func (q *Queue) GetTimestampPeriod() float32

GetTimestampPeriod returns 1.0 nanosecond timestamp period.

func (*Queue) PollCompleted added in v0.23.0

func (q *Queue) PollCompleted() uint64

PollCompleted returns the highest submission index known to be completed. Software backend is synchronous — all submissions are immediately complete.

func (*Queue) Present

func (q *Queue) Present(surface hal.Surface, texture hal.SurfaceTexture, damageRects []image.Rectangle) error

Present blits the software-rendered framebuffer to the window. The framebuffer is in BGRA byte order (matching the surface format) after executeFullscreenBlit's RGBA→BGRA swizzle. GDI BI_RGB 32-bit expects BGRA, so no additional conversion is needed — the framebuffer is passed directly. In headless mode (hwnd == 0), this is a no-op.

When damageRects is non-empty, only the specified regions are blitted to the window (partial BitBlt on Windows, partial XPutImage on Linux). This is the damage-aware presentation path for GUI frameworks where only a small region (spinner, cursor blink) changed between frames. Rects are clipped to surface bounds before blitting.

When damageRects is nil or empty, the entire surface is blitted — identical to the legacy full-surface present path.

IMPORTANT: Uses the SurfaceTexture's buffer (captured at AcquireTexture time), NOT s.framebuffer (which may have been replaced by Configure during resize). This prevents race: render draws into acquired buffer, Configure allocates new one, Present must blit the buffer that was actually rendered into.

func (*Queue) SetSwapchainSuppressed added in v0.26.3

func (q *Queue) SetSwapchainSuppressed(_ bool)

SetSwapchainSuppressed is a no-op on the software backend. Software backend has no GPU semaphores. See BUG-WGPU-VK-005 (Vulkan-specific).

func (*Queue) Submit

func (q *Queue) Submit(_ []hal.CommandBuffer) (uint64, error)

Submit simulates command buffer submission. Software backend is synchronous — work is complete immediately.

func (*Queue) SupportsCommandBufferCopies added in v0.23.4

func (q *Queue) SupportsCommandBufferCopies() bool

SupportsCommandBufferCopies returns false for the software backend. Writes are handled directly via memcpy without command buffer batching.

func (*Queue) WriteBuffer

func (q *Queue) WriteBuffer(buffer hal.Buffer, offset uint64, data []byte) error

WriteBuffer performs immediate buffer writes with real data storage.

func (*Queue) WriteTexture

func (q *Queue) WriteTexture(dst *hal.ImageCopyTexture, data []byte, layout *hal.ImageDataLayout, size *hal.Extent3D) error

WriteTexture performs immediate texture writes with real data storage. Respects dst.Origin (destination position), layout.BytesPerRow (source stride), layout.Offset (source data offset), and size (region dimensions).

type RenderPassEncoder

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

RenderPassEncoder implements hal.RenderPassEncoder for the software backend. It tracks pipeline state set during encoding and executes draw calls using the raster/ package for triangle rasterization.

func (*RenderPassEncoder) Draw

func (r *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)

Draw executes a non-indexed draw call. It performs vertex fetch, viewport transform, and triangle rasterization using the raster/ package. If no vertex buffer is bound and a texture is available in a bind group, it performs a fullscreen texture blit. Supports instanced rendering: instanceCount > 1 draws the same vertices multiple times, advancing instance-rate vertex buffers per instance.

func (*RenderPassEncoder) DrawIndexed

func (r *RenderPassEncoder) DrawIndexed(_, _, _ uint32, _ int32, _ uint32)

DrawIndexed is a no-op (indexed drawing not yet implemented).

func (*RenderPassEncoder) DrawIndexedIndirect

func (r *RenderPassEncoder) DrawIndexedIndirect(_ hal.Buffer, _ uint64)

DrawIndexedIndirect is a no-op.

func (*RenderPassEncoder) DrawIndirect

func (r *RenderPassEncoder) DrawIndirect(_ hal.Buffer, _ uint64)

DrawIndirect is a no-op.

func (*RenderPassEncoder) End

func (r *RenderPassEncoder) End()

End finishes the render pass. If no draw calls were issued and LoadOp is Clear, the clear is applied now. MSAA resolve: copies color attachment pixels to resolve target (WebGPU spec).

func (*RenderPassEncoder) ExecuteBundle

func (r *RenderPassEncoder) ExecuteBundle(_ hal.RenderBundle)

ExecuteBundle is a no-op.

func (*RenderPassEncoder) SetBindGroup

func (r *RenderPassEncoder) SetBindGroup(index uint32, bg hal.BindGroup, _ []uint32)

SetBindGroup stores a bind group at the given index.

func (*RenderPassEncoder) SetBlendConstant

func (r *RenderPassEncoder) SetBlendConstant(_ *gputypes.Color)

SetBlendConstant is a no-op (blend constants not yet wired to raster pipeline).

func (*RenderPassEncoder) SetIndexBuffer

func (r *RenderPassEncoder) SetIndexBuffer(buf hal.Buffer, format gputypes.IndexFormat, offset uint64)

SetIndexBuffer stores the index buffer for indexed draw calls.

func (*RenderPassEncoder) SetPipeline

func (r *RenderPassEncoder) SetPipeline(p hal.RenderPipeline)

SetPipeline stores the render pipeline for subsequent draw calls.

func (*RenderPassEncoder) SetScissorRect

func (r *RenderPassEncoder) SetScissorRect(x, y, w, h uint32)

SetScissorRect stores the scissor rectangle.

func (*RenderPassEncoder) SetStencilReference

func (r *RenderPassEncoder) SetStencilReference(ref uint32)

SetStencilReference stores the stencil reference value for subsequent draw calls. The reference value is used by stencil comparison and StencilOpReplace.

func (*RenderPassEncoder) SetVertexBuffer

func (r *RenderPassEncoder) SetVertexBuffer(slot uint32, buf hal.Buffer, offset uint64)

SetVertexBuffer stores a vertex buffer binding at the given slot.

func (*RenderPassEncoder) SetViewport

func (r *RenderPassEncoder) SetViewport(x, y, w, h, minDepth, maxDepth float32)

SetViewport stores the viewport transformation.

func (*RenderPassEncoder) Stats added in v0.27.3

Stats returns render pass statistics after End(). Designed for CI e2e test assertions — zero overhead (fields already tracked during encoding).

type RenderPassStats added in v0.27.3

type RenderPassStats struct {
	DrawCount   uint32
	HasScissor  bool
	ScissorRect image.Rectangle
	Width       uint32
	Height      uint32
	ColorLoadOp gputypes.LoadOp
}

RenderPassStats holds observable state from a completed software render pass. Populated from fields already tracked by RenderPassEncoder — zero additional overhead during rendering. Available via RenderPassEncoder.Stats() after End().

Designed for CI e2e test assertions:

stats := pass.(*software.RenderPassEncoder).Stats()
if stats.DrawCount != 2 { t.Error(...) }
if !stats.HasScissor { t.Error(...) }

See ADR: docs/dev/research/ADR-SOFTWARE-RENDER-PASS-INSTRUMENTATION.md

type RenderPipeline added in v0.21.3

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

RenderPipeline stores render pipeline configuration for the software backend.

type Resource

type Resource struct{}

Resource is a placeholder implementation for most HAL resource gputypes. It implements the hal.Resource interface with a no-op Destroy method.

func (*Resource) AddPendingRef added in v0.23.4

func (r *Resource) AddPendingRef()

func (*Resource) CurrentUsage added in v0.23.4

func (r *Resource) CurrentUsage() gputypes.TextureUsage

CurrentUsage returns 0 — Software backend has no resource state tracking.

func (*Resource) DecPendingRef added in v0.23.4

func (r *Resource) DecPendingRef()

func (*Resource) Destroy

func (r *Resource) Destroy()

Destroy is a no-op.

func (*Resource) NativeHandle

func (r *Resource) NativeHandle() uintptr

NativeHandle returns 0 for software resources (no real GPU handle).

type SamplerResource added in v0.27.1

type SamplerResource struct {
	Resource

	Desc *hal.SamplerDescriptor
	// contains filtered or unexported fields
}

SamplerResource implements hal.Sampler with actual sampler parameters. Used by the SPIR-V interpreter for texture filtering and addressing modes.

func (*SamplerResource) NativeHandle added in v0.27.1

func (s *SamplerResource) NativeHandle() uintptr

NativeHandle returns the sampler's unique ID for handle resolution.

type ShaderModule added in v0.21.3

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

ShaderModule stores shader source for the software backend. When SPIR-V bytecode is available (directly or compiled from WGSL via naga), the parsed Module is cached for use by the SPIR-V interpreter in draw calls.

func (*ShaderModule) ParsedModule added in v0.27.0

func (sm *ShaderModule) ParsedModule() *shader.Module

ParsedModule returns the parsed SPIR-V module, parsing on first access. Returns nil if no SPIR-V bytecode is available.

type Surface

type Surface struct {
	Resource
	// contains filtered or unexported fields
}

Surface implements hal.Surface for the software backend.

func (*Surface) AcquireTexture

func (s *Surface) AcquireTexture(_ hal.Fence) (*hal.AcquiredSurfaceTexture, error)

AcquireTexture returns a surface texture backed by the framebuffer.

func (*Surface) ActualExtent added in v0.28.2

func (s *Surface) ActualExtent() (width, height uint32)

ActualExtent returns the configured surface dimensions. The software backend does not clamp the extent, so these always match the requested values. Returns (0, 0) if the surface is not configured.

func (*Surface) Configure

func (s *Surface) Configure(_ hal.Device, config *hal.SurfaceConfiguration) error

Configure configures the surface with the given settings.

Returns hal.ErrZeroArea if width or height is zero. This commonly happens when the window is minimized or not yet fully visible. Wait until the window has valid dimensions before calling Configure again.

func (*Surface) DiscardTexture

func (s *Surface) DiscardTexture(_ hal.SurfaceTexture)

DiscardTexture is a no-op (framebuffer stays allocated).

func (*Surface) GetFramebuffer

func (s *Surface) GetFramebuffer() []byte

GetFramebuffer returns a copy of the current framebuffer data in RGBA byte order (thread-safe). If the surface format is BGRA, R and B channels are swapped so callers always receive consistent RGBA data. This allows platform blit code to do a single RGBA→BGRA conversion for GDI/X11.

func (*Surface) Unconfigure

func (s *Surface) Unconfigure(_ hal.Device)

Unconfigure removes the surface configuration.

type SurfaceTexture

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

SurfaceTexture implements hal.SurfaceTexture. It shares the framebuffer with the surface.

type Texture

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

Texture implements hal.Texture with real pixel storage.

func (*Texture) Clear

func (t *Texture) Clear(color gputypes.Color)

Clear fills the texture with a color value in the texture's native format. BGRA textures store [B,G,R,A] per pixel; RGBA textures store [R,G,B,A].

func (*Texture) CurrentUsage added in v0.23.4

func (t *Texture) CurrentUsage() gputypes.TextureUsage

CurrentUsage returns 0 — Software backend has no resource state tracking.

func (*Texture) GetData

func (t *Texture) GetData() []byte

GetData returns a copy of the texture data (thread-safe).

func (*Texture) NativeHandle

func (t *Texture) NativeHandle() uintptr

NativeHandle returns the texture's unique ID for handle resolution.

func (*Texture) WriteData

func (t *Texture) WriteData(offset uint64, data []byte)

WriteData writes data to the texture (thread-safe).

type TextureView

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

TextureView implements hal.TextureView. In software backend, views just reference the original texture.

func (*TextureView) NativeHandle

func (v *TextureView) NativeHandle() uintptr

NativeHandle returns the view's unique ID for handle resolution.

Directories

Path Synopsis
Package raster provides CPU-based triangle rasterization for the software backend.
Package raster provides CPU-based triangle rasterization for the software backend.
Package shader provides shader execution for the software backend.
Package shader provides shader execution for the software backend.

Jump to

Keyboard shortcuts

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