Documentation
¶
Overview ¶
Package vulkan provides Pure Go Vulkan backend for the HAL.
This backend uses goffi for cross-platform Vulkan API calls, requiring no CGO. Function pointers are loaded dynamically from vulkan-1.dll (Windows), libvulkan.so.1 (Linux), or MoltenVK (macOS).
Architecture ¶
The backend follows wgpu-hal patterns:
- Instance: VkInstance wrapper with extension loading
- Adapter: VkPhysicalDevice enumeration and capabilities
- Device: VkDevice with queues and memory allocator
- Queue: Command submission and synchronization
- Resources: Buffers, textures, pipelines with Vulkan objects
Memory Management ¶
Unlike OpenGL, Vulkan requires explicit memory allocation. This backend implements a pool-based memory allocator similar to gpu-allocator.
Platform Support ¶
- Windows: vulkan-1.dll + VK_KHR_win32_surface
- Linux: libvulkan.so.1 + VK_KHR_xlib_surface/VK_KHR_xcb_surface (planned)
- macOS: MoltenVK + VK_EXT_metal_surface (planned)
Index ¶
- type Adapter
- func (a *Adapter) Destroy()
- func (a *Adapter) Open(features gputypes.Features, limits gputypes.Limits) (hal.OpenDevice, error)
- func (a *Adapter) SurfaceCapabilities(surface hal.Surface) *hal.SurfaceCapabilities
- func (a *Adapter) TextureFormatCapabilities(format gputypes.TextureFormat) hal.TextureFormatCapabilities
- type Backend
- type BindGroup
- type BindGroupLayout
- type Buffer
- type CommandBuffer
- type CommandEncoder
- func (e *CommandEncoder) BeginComputePass(desc *hal.ComputePassDescriptor) hal.ComputePassEncoder
- func (e *CommandEncoder) BeginEncoding(label string) error
- func (e *CommandEncoder) BeginRenderPass(desc *hal.RenderPassDescriptor) hal.RenderPassEncoder
- func (e *CommandEncoder) ClearBuffer(buffer hal.Buffer, offset, size uint64)
- func (e *CommandEncoder) CopyBufferToBuffer(src, dst hal.Buffer, regions []hal.BufferCopy)
- func (e *CommandEncoder) CopyBufferToTexture(src hal.Buffer, dst hal.Texture, regions []hal.BufferTextureCopy)
- func (e *CommandEncoder) CopyTextureToBuffer(src hal.Texture, dst hal.Buffer, regions []hal.BufferTextureCopy)
- func (e *CommandEncoder) CopyTextureToTexture(src, dst hal.Texture, regions []hal.TextureCopy)
- func (e *CommandEncoder) DiscardEncoding()
- func (e *CommandEncoder) EndEncoding() (hal.CommandBuffer, error)
- func (e *CommandEncoder) ResetAll(commandBuffers []hal.CommandBuffer)
- func (e *CommandEncoder) ResolveQuerySet(querySet hal.QuerySet, firstQuery, queryCount uint32, destination hal.Buffer, ...)
- func (e *CommandEncoder) TransitionBuffers(barriers []hal.BufferBarrier)
- func (e *CommandEncoder) TransitionTextures(barriers []hal.TextureBarrier)
- type ComputePassEncoder
- func (e *ComputePassEncoder) Dispatch(x, y, z uint32)
- func (e *ComputePassEncoder) DispatchIndirect(buffer hal.Buffer, offset uint64)
- func (e *ComputePassEncoder) End()
- func (e *ComputePassEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
- func (e *ComputePassEncoder) SetPipeline(pipeline hal.ComputePipeline)
- type ComputePipeline
- type DescriptorAllocator
- func (a *DescriptorAllocator) Allocate(layout vk.DescriptorSetLayout, counts DescriptorCounts) (vk.DescriptorSet, *DescriptorPool, error)
- func (a *DescriptorAllocator) Destroy()
- func (a *DescriptorAllocator) Free(pool *DescriptorPool, set vk.DescriptorSet) error
- func (a *DescriptorAllocator) Stats() (pools int, allocated, freed uint32)
- type DescriptorAllocatorConfig
- type DescriptorCounts
- type DescriptorPool
- type Device
- func (d *Device) CreateBindGroup(desc *hal.BindGroupDescriptor) (hal.BindGroup, error)
- func (d *Device) CreateBindGroupLayout(desc *hal.BindGroupLayoutDescriptor) (hal.BindGroupLayout, error)
- func (d *Device) CreateBuffer(desc *hal.BufferDescriptor) (hal.Buffer, error)
- func (d *Device) CreateCommandEncoder(desc *hal.CommandEncoderDescriptor) (hal.CommandEncoder, error)
- func (d *Device) CreateComputePipeline(desc *hal.ComputePipelineDescriptor) (hal.ComputePipeline, error)
- func (d *Device) CreateFence() (hal.Fence, error)
- func (d *Device) CreatePipelineLayout(desc *hal.PipelineLayoutDescriptor) (hal.PipelineLayout, error)
- func (d *Device) CreateQuerySet(desc *hal.QuerySetDescriptor) (hal.QuerySet, error)
- func (d *Device) CreateRenderBundleEncoder(_ *hal.RenderBundleEncoderDescriptor) (hal.RenderBundleEncoder, error)
- func (d *Device) CreateRenderPipeline(desc *hal.RenderPipelineDescriptor) (hal.RenderPipeline, error)
- func (d *Device) CreateSampler(desc *hal.SamplerDescriptor) (hal.Sampler, error)
- func (d *Device) CreateShaderModule(desc *hal.ShaderModuleDescriptor) (hal.ShaderModule, error)
- func (d *Device) CreateTexture(desc *hal.TextureDescriptor) (hal.Texture, error)
- func (d *Device) CreateTextureView(texture hal.Texture, desc *hal.TextureViewDescriptor) (hal.TextureView, error)
- func (d *Device) Destroy()
- func (d *Device) DestroyBindGroup(group hal.BindGroup)
- func (d *Device) DestroyBindGroupLayout(layout hal.BindGroupLayout)
- func (d *Device) DestroyBuffer(buffer hal.Buffer)
- func (d *Device) DestroyComputePipeline(pipeline hal.ComputePipeline)
- func (d *Device) DestroyFence(fence hal.Fence)
- func (d *Device) DestroyPipelineLayout(layout hal.PipelineLayout)
- func (d *Device) DestroyQuerySet(querySet hal.QuerySet)
- func (d *Device) DestroyRenderBundle(bundle hal.RenderBundle)
- func (d *Device) DestroyRenderPipeline(pipeline hal.RenderPipeline)
- func (d *Device) DestroySampler(sampler hal.Sampler)
- func (d *Device) DestroyShaderModule(module hal.ShaderModule)
- func (d *Device) DestroyTexture(texture hal.Texture)
- func (d *Device) DestroyTextureView(view hal.TextureView)
- func (d *Device) FreeCommandBuffer(cmdBuffer hal.CommandBuffer)
- func (d *Device) GetFenceStatus(fence hal.Fence) (bool, error)
- func (d *Device) GetRenderPassCache() *RenderPassCache
- func (d *Device) ResetCommandPool() error
- func (d *Device) ResetFence(fence hal.Fence) error
- func (d *Device) Wait(fence hal.Fence, _ uint64, timeout time.Duration) (bool, error)
- func (d *Device) WaitIdle() error
- type Extent3D
- type Fence
- type FramebufferKey
- type Instance
- type PipelineLayout
- type QuerySet
- type Queue
- func (q *Queue) GetTimestampPeriod() float32
- func (q *Queue) Present(surface hal.Surface, texture hal.SurfaceTexture) error
- func (q *Queue) ReadBuffer(buffer hal.Buffer, offset uint64, data []byte) error
- func (q *Queue) Submit(commandBuffers []hal.CommandBuffer, fence hal.Fence, fenceValue uint64) error
- func (q *Queue) SubmitForPresent(commandBuffers []hal.CommandBuffer, swapchain *Swapchain) error
- func (q *Queue) WriteBuffer(buffer hal.Buffer, offset uint64, data []byte) error
- func (q *Queue) WriteTexture(dst *hal.ImageCopyTexture, data []byte, layout *hal.ImageDataLayout, ...) error
- type RenderBundle
- type RenderBundleEncoder
- func (e *RenderBundleEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
- func (e *RenderBundleEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, ...)
- func (e *RenderBundleEncoder) Finish() hal.RenderBundle
- func (e *RenderBundleEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
- func (e *RenderBundleEncoder) SetIndexBuffer(buffer hal.Buffer, format gputypes.IndexFormat, offset uint64)
- func (e *RenderBundleEncoder) SetPipeline(pipeline hal.RenderPipeline)
- func (e *RenderBundleEncoder) SetVertexBuffer(slot uint32, buffer hal.Buffer, offset uint64)
- type RenderPassCache
- type RenderPassEncoder
- func (e *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
- func (e *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, ...)
- func (e *RenderPassEncoder) DrawIndexedIndirect(buffer hal.Buffer, offset uint64)
- func (e *RenderPassEncoder) DrawIndirect(buffer hal.Buffer, offset uint64)
- func (e *RenderPassEncoder) End()
- func (e *RenderPassEncoder) ExecuteBundle(bundle hal.RenderBundle)
- func (e *RenderPassEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
- func (e *RenderPassEncoder) SetBlendConstant(color *gputypes.Color)
- func (e *RenderPassEncoder) SetIndexBuffer(buffer hal.Buffer, format gputypes.IndexFormat, offset uint64)
- func (e *RenderPassEncoder) SetPipeline(pipeline hal.RenderPipeline)
- func (e *RenderPassEncoder) SetScissorRect(x, y, width, height uint32)
- func (e *RenderPassEncoder) SetStencilReference(ref uint32)
- func (e *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer hal.Buffer, offset uint64)
- func (e *RenderPassEncoder) SetViewport(x, y, width, height, minDepth, maxDepth float32)
- type RenderPassKey
- type RenderPipeline
- type Sampler
- type ShaderModule
- type Surface
- type Swapchain
- type SwapchainTexture
- type Texture
- type TextureView
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements hal.Adapter for Vulkan.
func (*Adapter) SurfaceCapabilities ¶
func (a *Adapter) SurfaceCapabilities(surface hal.Surface) *hal.SurfaceCapabilities
SurfaceCapabilities returns surface capabilities.
func (*Adapter) TextureFormatCapabilities ¶
func (a *Adapter) TextureFormatCapabilities(format gputypes.TextureFormat) hal.TextureFormatCapabilities
TextureFormatCapabilities returns capabilities for a texture format.
type Backend ¶
type Backend struct{}
Backend implements hal.Backend for Vulkan.
func (Backend) CreateInstance ¶
CreateInstance creates a new Vulkan instance.
type BindGroup ¶
type BindGroup struct {
// contains filtered or unexported fields
}
BindGroup implements hal.BindGroup for Vulkan.
func (*BindGroup) Handle ¶
func (g *BindGroup) Handle() vk.DescriptorSet
Handle returns the VkDescriptorSet handle.
type BindGroupLayout ¶
type BindGroupLayout struct {
// contains filtered or unexported fields
}
BindGroupLayout implements hal.BindGroupLayout for Vulkan.
func (*BindGroupLayout) Counts ¶
func (l *BindGroupLayout) Counts() DescriptorCounts
Counts returns the descriptor counts for this layout.
func (*BindGroupLayout) Destroy ¶
func (l *BindGroupLayout) Destroy()
Destroy releases the bind group layout.
func (*BindGroupLayout) Handle ¶
func (l *BindGroupLayout) Handle() vk.DescriptorSetLayout
Handle returns the VkDescriptorSetLayout handle.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements hal.Buffer for Vulkan.
func (*Buffer) NativeHandle ¶ added in v0.12.0
NativeHandle returns the raw VkBuffer handle as uintptr.
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
CommandBuffer holds a recorded Vulkan command buffer. Pooled via cmdBufferResultPool to avoid per-frame heap allocation (VK-PERF-004).
func (*CommandBuffer) Destroy ¶
func (c *CommandBuffer) Destroy()
Destroy releases the command buffer resources. Returns the struct to the pool for reuse (VK-PERF-004).
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
CommandEncoder implements hal.CommandEncoder for Vulkan. Pooled via encoderPool to avoid per-frame heap allocation (VK-PERF-003).
func (*CommandEncoder) BeginComputePass ¶
func (e *CommandEncoder) BeginComputePass(desc *hal.ComputePassDescriptor) hal.ComputePassEncoder
BeginComputePass begins a compute pass. Uses sync.Pool for ComputePassEncoder reuse (VK-PERF-005).
func (*CommandEncoder) BeginEncoding ¶
func (e *CommandEncoder) BeginEncoding(label string) error
BeginEncoding begins command recording. Returns an error if the command buffer handle is null (VK-001: prevents SIGSEGV from null VkCommandBuffer dispatch table dereference).
func (*CommandEncoder) BeginRenderPass ¶
func (e *CommandEncoder) BeginRenderPass(desc *hal.RenderPassDescriptor) hal.RenderPassEncoder
BeginRenderPass begins a render pass using VkRenderPass (classic Vulkan approach). This is compatible with Intel drivers that don't properly support dynamic rendering. Supports MSAA render passes with resolve targets and depth/stencil attachments. Uses sync.Pool for RenderPassEncoder reuse (VK-PERF-006).
func (*CommandEncoder) ClearBuffer ¶
func (e *CommandEncoder) ClearBuffer(buffer hal.Buffer, offset, size uint64)
ClearBuffer clears a buffer region to zero.
func (*CommandEncoder) CopyBufferToBuffer ¶
func (e *CommandEncoder) CopyBufferToBuffer(src, dst hal.Buffer, regions []hal.BufferCopy)
CopyBufferToBuffer copies data between buffers.
func (*CommandEncoder) CopyBufferToTexture ¶
func (e *CommandEncoder) CopyBufferToTexture(src hal.Buffer, dst hal.Texture, regions []hal.BufferTextureCopy)
CopyBufferToTexture copies data from a buffer to a texture.
func (*CommandEncoder) CopyTextureToBuffer ¶
func (e *CommandEncoder) CopyTextureToBuffer(src hal.Texture, dst hal.Buffer, regions []hal.BufferTextureCopy)
CopyTextureToBuffer copies data from a texture to a buffer.
func (*CommandEncoder) CopyTextureToTexture ¶
func (e *CommandEncoder) CopyTextureToTexture(src, dst hal.Texture, regions []hal.TextureCopy)
CopyTextureToTexture copies data between textures.
func (*CommandEncoder) DiscardEncoding ¶
func (e *CommandEncoder) DiscardEncoding()
DiscardEncoding discards the encoder and recycles its pool+buffer pair.
func (*CommandEncoder) EndEncoding ¶
func (e *CommandEncoder) EndEncoding() (hal.CommandBuffer, error)
EndEncoding finishes command recording and returns a command buffer. Uses sync.Pool for CommandBuffer reuse (VK-PERF-004). Returns the CommandEncoder to the pool after use.
func (*CommandEncoder) ResetAll ¶
func (e *CommandEncoder) ResetAll(commandBuffers []hal.CommandBuffer)
ResetAll resets command buffers for reuse.
func (*CommandEncoder) ResolveQuerySet ¶ added in v0.16.4
func (e *CommandEncoder) ResolveQuerySet(querySet hal.QuerySet, firstQuery, queryCount uint32, destination hal.Buffer, destinationOffset uint64)
ResolveQuerySet copies query results from a query set into a destination buffer. For timestamp queries, each result is a uint64 (8 bytes). This uses vkCmdCopyQueryPoolResults under the hood.
func (*CommandEncoder) TransitionBuffers ¶
func (e *CommandEncoder) TransitionBuffers(barriers []hal.BufferBarrier)
TransitionBuffers transitions buffer states for synchronization.
func (*CommandEncoder) TransitionTextures ¶
func (e *CommandEncoder) TransitionTextures(barriers []hal.TextureBarrier)
TransitionTextures transitions texture states for synchronization.
type ComputePassEncoder ¶
type ComputePassEncoder struct {
// contains filtered or unexported fields
}
ComputePassEncoder implements hal.ComputePassEncoder for Vulkan.
func (*ComputePassEncoder) Dispatch ¶
func (e *ComputePassEncoder) Dispatch(x, y, z uint32)
Dispatch dispatches compute work.
func (*ComputePassEncoder) DispatchIndirect ¶
func (e *ComputePassEncoder) DispatchIndirect(buffer hal.Buffer, offset uint64)
DispatchIndirect dispatches compute work with GPU-generated parameters.
func (*ComputePassEncoder) End ¶
func (e *ComputePassEncoder) End()
End finishes the compute pass. Writes end-of-pass timestamp if requested, then inserts a global memory barrier so compute shader writes are visible to subsequent commands (transfers, other dispatches, etc.). Without this barrier the GPU may reorder a CopyBufferToBuffer before the compute shader has finished writing, causing stale/zero reads. Returns the encoder to the pool for reuse (VK-PERF-005).
func (*ComputePassEncoder) SetBindGroup ¶
func (e *ComputePassEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
SetBindGroup sets a bind group.
func (*ComputePassEncoder) SetPipeline ¶
func (e *ComputePassEncoder) SetPipeline(pipeline hal.ComputePipeline)
SetPipeline sets the compute pipeline.
type ComputePipeline ¶
type ComputePipeline struct {
// contains filtered or unexported fields
}
ComputePipeline implements hal.ComputePipeline for Vulkan.
func (*ComputePipeline) Destroy ¶
func (p *ComputePipeline) Destroy()
Destroy releases the compute pipeline.
type DescriptorAllocator ¶
type DescriptorAllocator struct {
// contains filtered or unexported fields
}
DescriptorAllocator manages descriptor pool allocation.
Thread-safe. Uses on-demand pool growth strategy with FREE_DESCRIPTOR_SET flag for individual descriptor set freeing. Follows wgpu patterns adapted for Go.
func NewDescriptorAllocator ¶
func NewDescriptorAllocator(device vk.Device, cmds *vk.Commands, config DescriptorAllocatorConfig) *DescriptorAllocator
NewDescriptorAllocator creates a new descriptor allocator.
func (*DescriptorAllocator) Allocate ¶
func (a *DescriptorAllocator) Allocate(layout vk.DescriptorSetLayout, counts DescriptorCounts) (vk.DescriptorSet, *DescriptorPool, error)
Allocate allocates a descriptor set from the given layout.
func (*DescriptorAllocator) Destroy ¶
func (a *DescriptorAllocator) Destroy()
Destroy releases all descriptor pools.
func (*DescriptorAllocator) Free ¶
func (a *DescriptorAllocator) Free(pool *DescriptorPool, set vk.DescriptorSet) error
Free frees a descriptor set back to its pool.
func (*DescriptorAllocator) Stats ¶
func (a *DescriptorAllocator) Stats() (pools int, allocated, freed uint32)
Stats returns allocator statistics.
type DescriptorAllocatorConfig ¶
type DescriptorAllocatorConfig struct {
// InitialPoolSize is the number of sets in the first pool.
// Default: 64
InitialPoolSize uint32
// MaxPoolSize is the maximum sets per pool.
// Default: 4096
MaxPoolSize uint32
// GrowthFactor is the multiplier for each new pool size.
// Default: 2
GrowthFactor uint32
}
DescriptorAllocatorConfig configures the descriptor allocator.
func DefaultDescriptorAllocatorConfig ¶
func DefaultDescriptorAllocatorConfig() DescriptorAllocatorConfig
DefaultDescriptorAllocatorConfig returns sensible defaults.
type DescriptorCounts ¶
type DescriptorCounts struct {
Samplers uint32
SampledImages uint32
StorageImages uint32
UniformBuffers uint32
StorageBuffers uint32
UniformTexelBuffer uint32
StorageTexelBuffer uint32
InputAttachments uint32
}
DescriptorCounts tracks the number of descriptors by type. Used to determine pool sizes for allocation.
func (DescriptorCounts) IsEmpty ¶
func (c DescriptorCounts) IsEmpty() bool
IsEmpty returns true if no descriptors are needed.
func (DescriptorCounts) Multiply ¶
func (c DescriptorCounts) Multiply(factor uint32) DescriptorCounts
Multiply multiplies all counts by a factor.
func (DescriptorCounts) Total ¶
func (c DescriptorCounts) Total() uint32
Total returns the total number of descriptors.
type DescriptorPool ¶
type DescriptorPool struct {
// contains filtered or unexported fields
}
DescriptorPool wraps a VkDescriptorPool with tracking.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device implements hal.Device for Vulkan.
func (*Device) CreateBindGroup ¶
CreateBindGroup creates a bind group.
func (*Device) CreateBindGroupLayout ¶
func (d *Device) CreateBindGroupLayout(desc *hal.BindGroupLayoutDescriptor) (hal.BindGroupLayout, error)
CreateBindGroupLayout creates a bind group layout.
func (*Device) CreateBuffer ¶
CreateBuffer creates a GPU buffer.
func (*Device) CreateCommandEncoder ¶
func (d *Device) CreateCommandEncoder(desc *hal.CommandEncoderDescriptor) (hal.CommandEncoder, error)
CreateCommandEncoder creates a command encoder with its own dedicated VkCommandPool + VkCommandBuffer pair. This per-encoder pool design matches Rust wgpu-hal and eliminates races between pool reset and buffer freeing that caused "Couldn't find VkCommandBuffer Object" crashes (VK-POOL-001). Uses sync.Pool for CommandEncoder struct reuse (VK-PERF-003).
func (*Device) CreateComputePipeline ¶
func (d *Device) CreateComputePipeline(desc *hal.ComputePipelineDescriptor) (hal.ComputePipeline, error)
CreateComputePipeline creates a compute pipeline.
func (*Device) CreateFence ¶
CreateFence creates a synchronization fence.
func (*Device) CreatePipelineLayout ¶
func (d *Device) CreatePipelineLayout(desc *hal.PipelineLayoutDescriptor) (hal.PipelineLayout, error)
CreatePipelineLayout creates a pipeline layout.
func (*Device) CreateQuerySet ¶ added in v0.16.4
CreateQuerySet creates a Vulkan query pool.
func (*Device) CreateRenderBundleEncoder ¶ added in v0.13.0
func (d *Device) CreateRenderBundleEncoder(_ *hal.RenderBundleEncoderDescriptor) (hal.RenderBundleEncoder, error)
CreateRenderBundleEncoder creates a render bundle encoder. Each bundle gets its own dedicated VkCommandPool for secondary command buffer allocation, matching the per-encoder pool pattern (VK-POOL-001).
func (*Device) CreateRenderPipeline ¶
func (d *Device) CreateRenderPipeline(desc *hal.RenderPipelineDescriptor) (hal.RenderPipeline, error)
CreateRenderPipeline creates a render pipeline.
func (*Device) CreateSampler ¶
CreateSampler creates a texture sampler.
func (*Device) CreateShaderModule ¶
func (d *Device) CreateShaderModule(desc *hal.ShaderModuleDescriptor) (hal.ShaderModule, error)
CreateShaderModule creates a shader module.
func (*Device) CreateTexture ¶
CreateTexture creates a GPU texture.
func (*Device) CreateTextureView ¶
func (d *Device) CreateTextureView(texture hal.Texture, desc *hal.TextureViewDescriptor) (hal.TextureView, error)
CreateTextureView creates a view into a texture.
func (*Device) DestroyBindGroup ¶
DestroyBindGroup destroys a bind group.
func (*Device) DestroyBindGroupLayout ¶
func (d *Device) DestroyBindGroupLayout(layout hal.BindGroupLayout)
DestroyBindGroupLayout destroys a bind group layout.
func (*Device) DestroyBuffer ¶
DestroyBuffer destroys a GPU buffer.
func (*Device) DestroyComputePipeline ¶
func (d *Device) DestroyComputePipeline(pipeline hal.ComputePipeline)
DestroyComputePipeline destroys a compute pipeline.
func (*Device) DestroyFence ¶
DestroyFence destroys a fence.
func (*Device) DestroyPipelineLayout ¶
func (d *Device) DestroyPipelineLayout(layout hal.PipelineLayout)
DestroyPipelineLayout destroys a pipeline layout.
func (*Device) DestroyQuerySet ¶ added in v0.16.4
DestroyQuerySet destroys a Vulkan query set.
func (*Device) DestroyRenderBundle ¶ added in v0.13.0
func (d *Device) DestroyRenderBundle(bundle hal.RenderBundle)
DestroyRenderBundle destroys a render bundle. Frees the secondary command buffer from its dedicated pool, then destroys the pool.
func (*Device) DestroyRenderPipeline ¶
func (d *Device) DestroyRenderPipeline(pipeline hal.RenderPipeline)
DestroyRenderPipeline destroys a render pipeline.
func (*Device) DestroySampler ¶
DestroySampler destroys a sampler.
func (*Device) DestroyShaderModule ¶
func (d *Device) DestroyShaderModule(module hal.ShaderModule)
DestroyShaderModule destroys a shader module.
func (*Device) DestroyTexture ¶
DestroyTexture destroys a GPU texture.
func (*Device) DestroyTextureView ¶
func (d *Device) DestroyTextureView(view hal.TextureView)
DestroyTextureView destroys a texture view.
func (*Device) FreeCommandBuffer ¶ added in v0.13.0
func (d *Device) FreeCommandBuffer(cmdBuffer hal.CommandBuffer)
FreeCommandBuffer recycles a command buffer's pool+buffer pair for reuse. Only call this AFTER the GPU has finished using the command buffer (after fence wait). The pool is returned to the free list; it will be reset lazily on next acquire. No vkFreeCommandBuffers call is needed because pool reset restores the buffer.
func (*Device) GetFenceStatus ¶ added in v0.13.0
GetFenceStatus returns true if the fence is signaled (non-blocking). Uses vkGetFenceStatus for efficient polling without blocking.
func (*Device) GetRenderPassCache ¶ added in v0.9.3
func (d *Device) GetRenderPassCache() *RenderPassCache
GetRenderPassCache returns the render pass cache, creating it if needed.
func (*Device) ResetCommandPool ¶ added in v0.9.3
ResetCommandPool resets all recycled command pools. Call this after ensuring all submitted command buffers have completed (e.g., after WaitIdle).
func (*Device) ResetFence ¶ added in v0.13.0
ResetFence resets a fence to the unsignaled state.
type Fence ¶
type Fence struct {
// contains filtered or unexported fields
}
Fence implements hal.Fence for Vulkan.
type FramebufferKey ¶ added in v0.9.3
type FramebufferKey struct {
RenderPass vk.RenderPass
ColorView vk.ImageView // MSAA color view or single-sample color view
ResolveView vk.ImageView // Resolve target (0 if no MSAA)
DepthView vk.ImageView // Depth/stencil view (0 if none)
Width uint32
Height uint32
}
FramebufferKey uniquely identifies a framebuffer configuration. Supports multiple attachments for MSAA (color + resolve + depth/stencil).
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance implements hal.Instance for Vulkan.
func (*Instance) CreateSurface ¶
CreateSurface creates a Vulkan surface from platform-specific handles. On Linux, it auto-detects X11 vs Wayland based on available extensions:
- Wayland: display = wl_display*, window = wl_surface* (from libwayland-client)
- X11: display = Display* (from libX11), window = X11 Window ID
func (*Instance) EnumerateAdapters ¶
func (i *Instance) EnumerateAdapters(surfaceHint hal.Surface) []hal.ExposedAdapter
EnumerateAdapters returns available Vulkan adapters (physical devices).
type PipelineLayout ¶
type PipelineLayout struct {
// contains filtered or unexported fields
}
PipelineLayout implements hal.PipelineLayout for Vulkan.
func (*PipelineLayout) Destroy ¶
func (l *PipelineLayout) Destroy()
Destroy releases the pipeline layout.
func (*PipelineLayout) Handle ¶
func (l *PipelineLayout) Handle() vk.PipelineLayout
Handle returns the VkPipelineLayout handle.
type QuerySet ¶ added in v0.16.4
type QuerySet struct {
// contains filtered or unexported fields
}
QuerySet implements hal.QuerySet for Vulkan.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue implements hal.Queue for Vulkan.
func (*Queue) GetTimestampPeriod ¶
GetTimestampPeriod returns the timestamp period in nanoseconds.
func (*Queue) ReadBuffer ¶ added in v0.15.0
ReadBuffer reads data from a GPU buffer. The buffer must have host-visible memory (created with MapRead usage). Uses fence-based synchronization instead of vkQueueWaitIdle.
Both paths use the unified deviceFence: timeline semaphore (VK-IMPL-001) or binary fence pool (VK-IMPL-003).
func (*Queue) Submit ¶
func (q *Queue) Submit(commandBuffers []hal.CommandBuffer, fence hal.Fence, fenceValue uint64) error
Submit submits command buffers to the GPU.
func (*Queue) SubmitForPresent ¶
func (q *Queue) SubmitForPresent(commandBuffers []hal.CommandBuffer, swapchain *Swapchain) error
SubmitForPresent submits command buffers with swapchain synchronization.
func (*Queue) WriteBuffer ¶
WriteBuffer writes data to a buffer immediately. Uses fence-based synchronization instead of vkQueueWaitIdle to avoid stalling the entire GPU pipeline. Only waits for the last queue submission to complete, which per Khronos benchmarks improves frame times by ~22%.
Both paths use the unified deviceFence: timeline semaphore (VK-IMPL-001) or binary fence pool (VK-IMPL-003).
func (*Queue) WriteTexture ¶
func (q *Queue) WriteTexture(dst *hal.ImageCopyTexture, data []byte, layout *hal.ImageDataLayout, size *hal.Extent3D) error
WriteTexture writes data to a texture immediately. Returns an error if any step fails (VK-003: no more silent error swallowing).
type RenderBundle ¶ added in v0.13.0
type RenderBundle struct {
// contains filtered or unexported fields
}
RenderBundle is a pre-recorded set of render commands.
func (*RenderBundle) Destroy ¶ added in v0.13.0
func (b *RenderBundle) Destroy()
Destroy releases the render bundle resources.
type RenderBundleEncoder ¶ added in v0.13.0
type RenderBundleEncoder struct {
// contains filtered or unexported fields
}
RenderBundleEncoder records commands into a render bundle.
func (*RenderBundleEncoder) Draw ¶ added in v0.13.0
func (e *RenderBundleEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
Draw draws primitives.
func (*RenderBundleEncoder) DrawIndexed ¶ added in v0.13.0
func (e *RenderBundleEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, firstInstance uint32)
DrawIndexed draws indexed primitives.
func (*RenderBundleEncoder) Finish ¶ added in v0.13.0
func (e *RenderBundleEncoder) Finish() hal.RenderBundle
Finish finalizes the bundle and returns it.
func (*RenderBundleEncoder) SetBindGroup ¶ added in v0.13.0
func (e *RenderBundleEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
SetBindGroup sets a bind group for the given index.
func (*RenderBundleEncoder) SetIndexBuffer ¶ added in v0.13.0
func (e *RenderBundleEncoder) SetIndexBuffer(buffer hal.Buffer, format gputypes.IndexFormat, offset uint64)
SetIndexBuffer sets the index buffer.
func (*RenderBundleEncoder) SetPipeline ¶ added in v0.13.0
func (e *RenderBundleEncoder) SetPipeline(pipeline hal.RenderPipeline)
SetPipeline sets the active render pipeline.
func (*RenderBundleEncoder) SetVertexBuffer ¶ added in v0.13.0
func (e *RenderBundleEncoder) SetVertexBuffer(slot uint32, buffer hal.Buffer, offset uint64)
SetVertexBuffer sets a vertex buffer for the given slot.
type RenderPassCache ¶ added in v0.9.3
type RenderPassCache struct {
// contains filtered or unexported fields
}
RenderPassCache caches VkRenderPass and VkFramebuffer objects. This is critical for performance and compatibility with Intel drivers that don't properly support VK_KHR_dynamic_rendering.
func NewRenderPassCache ¶ added in v0.9.3
func NewRenderPassCache(device vk.Device, cmds *vk.Commands) *RenderPassCache
NewRenderPassCache creates a new render pass cache.
func (*RenderPassCache) Destroy ¶ added in v0.9.3
func (c *RenderPassCache) Destroy()
Destroy releases all cached resources.
func (*RenderPassCache) GetOrCreateFramebuffer ¶ added in v0.9.3
func (c *RenderPassCache) GetOrCreateFramebuffer(key FramebufferKey) (vk.Framebuffer, error)
GetOrCreateFramebuffer returns a cached framebuffer or creates a new one.
func (*RenderPassCache) GetOrCreateRenderPass ¶ added in v0.9.3
func (c *RenderPassCache) GetOrCreateRenderPass(key RenderPassKey) (vk.RenderPass, error)
GetOrCreateRenderPass returns a cached render pass or creates a new one.
func (*RenderPassCache) InvalidateFramebuffer ¶ added in v0.9.3
func (c *RenderPassCache) InvalidateFramebuffer(imageView vk.ImageView)
InvalidateFramebuffer removes framebuffers from cache that reference the given image view. Called when swapchain is recreated.
type RenderPassEncoder ¶
type RenderPassEncoder struct {
// contains filtered or unexported fields
}
RenderPassEncoder implements hal.RenderPassEncoder for Vulkan.
func (*RenderPassEncoder) Draw ¶
func (e *RenderPassEncoder) Draw(vertexCount, instanceCount, firstVertex, firstInstance uint32)
Draw draws primitives.
func (*RenderPassEncoder) DrawIndexed ¶
func (e *RenderPassEncoder) DrawIndexed(indexCount, instanceCount, firstIndex uint32, baseVertex int32, firstInstance uint32)
DrawIndexed draws indexed primitives.
func (*RenderPassEncoder) DrawIndexedIndirect ¶
func (e *RenderPassEncoder) DrawIndexedIndirect(buffer hal.Buffer, offset uint64)
DrawIndexedIndirect draws indexed primitives with GPU-generated parameters.
func (*RenderPassEncoder) DrawIndirect ¶
func (e *RenderPassEncoder) DrawIndirect(buffer hal.Buffer, offset uint64)
DrawIndirect draws primitives with GPU-generated parameters.
func (*RenderPassEncoder) End ¶
func (e *RenderPassEncoder) End()
End finishes the render pass. Returns the encoder to the pool for reuse (VK-PERF-006).
func (*RenderPassEncoder) ExecuteBundle ¶
func (e *RenderPassEncoder) ExecuteBundle(bundle hal.RenderBundle)
ExecuteBundle executes a pre-recorded render bundle.
func (*RenderPassEncoder) SetBindGroup ¶
func (e *RenderPassEncoder) SetBindGroup(index uint32, group hal.BindGroup, offsets []uint32)
SetBindGroup sets a bind group.
func (*RenderPassEncoder) SetBlendConstant ¶
func (e *RenderPassEncoder) SetBlendConstant(color *gputypes.Color)
SetBlendConstant sets the blend constant.
func (*RenderPassEncoder) SetIndexBuffer ¶
func (e *RenderPassEncoder) SetIndexBuffer(buffer hal.Buffer, format gputypes.IndexFormat, offset uint64)
SetIndexBuffer sets the index buffer.
func (*RenderPassEncoder) SetPipeline ¶
func (e *RenderPassEncoder) SetPipeline(pipeline hal.RenderPipeline)
SetPipeline sets the render pipeline.
func (*RenderPassEncoder) SetScissorRect ¶
func (e *RenderPassEncoder) SetScissorRect(x, y, width, height uint32)
SetScissorRect sets the scissor rectangle.
func (*RenderPassEncoder) SetStencilReference ¶
func (e *RenderPassEncoder) SetStencilReference(ref uint32)
SetStencilReference sets the stencil reference value.
func (*RenderPassEncoder) SetVertexBuffer ¶
func (e *RenderPassEncoder) SetVertexBuffer(slot uint32, buffer hal.Buffer, offset uint64)
SetVertexBuffer sets a vertex buffer. Uses stack variables instead of slice allocations (VK-PERF-007).
func (*RenderPassEncoder) SetViewport ¶
func (e *RenderPassEncoder) SetViewport(x, y, width, height, minDepth, maxDepth float32)
SetViewport sets the viewport. NOTE: Applies Y-flip for WebGPU/OpenGL coordinate system compatibility (matches Rust wgpu).
type RenderPassKey ¶ added in v0.9.3
type RenderPassKey struct {
ColorFormat vk.Format
ColorLoadOp vk.AttachmentLoadOp
ColorStoreOp vk.AttachmentStoreOp
DepthFormat vk.Format
DepthLoadOp vk.AttachmentLoadOp
DepthStoreOp vk.AttachmentStoreOp
StencilLoadOp vk.AttachmentLoadOp
StencilStoreOp vk.AttachmentStoreOp
SampleCount vk.SampleCountFlagBits
ColorFinalLayout vk.ImageLayout
HasResolve bool // true when MSAA resolve target is present
}
RenderPassKey uniquely identifies a render pass configuration. Used for caching VkRenderPass objects.
type RenderPipeline ¶
type RenderPipeline struct {
// contains filtered or unexported fields
}
RenderPipeline implements hal.RenderPipeline for Vulkan.
func (*RenderPipeline) Destroy ¶
func (p *RenderPipeline) Destroy()
Destroy releases the render pipeline.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler implements hal.Sampler for Vulkan.
func (*Sampler) NativeHandle ¶ added in v0.12.0
NativeHandle returns the raw VkSampler handle as uintptr.
type ShaderModule ¶
type ShaderModule struct {
// contains filtered or unexported fields
}
ShaderModule implements hal.ShaderModule for Vulkan.
func (*ShaderModule) Handle ¶
func (m *ShaderModule) Handle() vk.ShaderModule
Handle returns the VkShaderModule handle.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface implements hal.Surface for Vulkan.
func (*Surface) AcquireTexture ¶
AcquireTexture acquires the next surface texture for rendering. Returns hal.ErrNotReady if no image is available (non-blocking mode).
func (*Surface) Configure ¶
Configure configures the surface for presentation.
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 discards a surface texture without presenting it.
func (*Surface) Unconfigure ¶
Unconfigure removes surface configuration.
type Swapchain ¶
type Swapchain struct {
// contains filtered or unexported fields
}
Swapchain manages Vulkan swapchain for a surface.
type SwapchainTexture ¶
type SwapchainTexture struct {
// contains filtered or unexported fields
}
SwapchainTexture wraps a swapchain image as a SurfaceTexture.
func (*SwapchainTexture) Destroy ¶
func (t *SwapchainTexture) Destroy()
Destroy implements hal.Texture.
func (*SwapchainTexture) NativeHandle ¶ added in v0.12.0
func (t *SwapchainTexture) NativeHandle() uintptr
NativeHandle returns the raw VkImage handle as uintptr.
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture implements hal.Texture for Vulkan.
func (*Texture) NativeHandle ¶ added in v0.12.0
NativeHandle returns the raw VkImage handle as uintptr.
type TextureView ¶
type TextureView struct {
// contains filtered or unexported fields
}
TextureView implements hal.TextureView for Vulkan.
func (*TextureView) Handle ¶
func (v *TextureView) Handle() vk.ImageView
Handle returns the VkImageView handle.
func (*TextureView) NativeHandle ¶ added in v0.12.0
func (v *TextureView) NativeHandle() uintptr
NativeHandle returns the raw VkImageView handle as uintptr.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memory provides GPU memory allocation for Vulkan backend.
|
Package memory provides GPU memory allocation for Vulkan backend. |
|
Package vk provides Pure Go Vulkan bindings using goffi for FFI calls.
|
Package vk provides Pure Go Vulkan bindings using goffi for FFI calls. |