Documentation
¶
Overview ¶
Package vulkan is a pure-Go (no cgo) binding to the part of Vulkan a compute workload needs: the loader, an instance with the optional Khronos validation layer, a physical-device pick, one device and one compute queue, host-visible coherent buffers, shader modules from SPIR-V words, compute pipelines with their descriptor sets, command buffers, dispatch and fences.
It calls the system loader libvulkan.so.1 through purego, so a binary built with CGO_ENABLED=0 can be cross-compiled and copied to a machine that has a Vulkan driver. It is Linux 64-bit only (amd64, arm64); elsewhere Open returns ErrUnsupported. There is no window-system integration and no graphics pipeline.
Threading: a queue is externally synchronised, so a Device and everything made from it belong to one goroutine at a time.
Close order: close buffers, pipelines, shaders, command buffers and fences before their Device, and the Device before the Instance.
Index ¶
- Constants
- Variables
- func Pick(infos []DeviceInfo, f Filter) (int, error)
- type Binding
- type Buffer
- type BufferUsage
- type CommandBuffer
- type DescriptorKind
- type Device
- func (d *Device) Close() error
- func (d *Device) Info() DeviceInfo
- func (d *Device) NewBuffer(size uint64, usage BufferUsage) (*Buffer, error)
- func (d *Device) NewCommandBuffer() (*CommandBuffer, error)
- func (d *Device) NewComputePipeline(sh *Shader, entry string, bindings []Binding) (*Pipeline, error)
- func (d *Device) NewShader(words []uint32) (*Shader, error)
- func (d *Device) Submit(c *CommandBuffer) (*Fence, error)
- type DeviceInfo
- type DeviceType
- type Error
- type Fence
- type Filter
- type Instance
- type Options
- type PhysicalDevice
- type Pipeline
- type Result
- type Shader
- type Version
Constants ¶
const ( UsageStorage = BufferUsage(vk.BufferUsageStorageBufferBit) UsageUniform = BufferUsage(vk.BufferUsageUniformBufferBit) UsageTransferSrc = BufferUsage(vk.BufferUsageTransferSrcBit) UsageTransferDst = BufferUsage(vk.BufferUsageTransferDstBit) )
The usages a compute workload needs.
const ( DeviceTypeOther = DeviceType(vk.PhysicalDeviceTypeOther) DeviceTypeIntegrated = DeviceType(vk.PhysicalDeviceTypeIntegratedGpu) DeviceTypeDiscrete = DeviceType(vk.PhysicalDeviceTypeDiscreteGpu) DeviceTypeVirtual = DeviceType(vk.PhysicalDeviceTypeVirtualGpu) DeviceTypeCPU = DeviceType(vk.PhysicalDeviceTypeCpu) )
The device types, in the registry's numbering.
const ( VendorAMD uint32 = 0x1002 VendorNVIDIA uint32 = 0x10de VendorIntel uint32 = 0x8086 )
Well-known PCI vendor identifiers.
const ( StorageBuffer = DescriptorKind(vk.DescriptorTypeStorageBuffer) UniformBuffer = DescriptorKind(vk.DescriptorTypeUniformBuffer) )
The kinds a compute shader here uses.
Variables ¶
var ( ErrOutOfHostMemory = &Error{Result: Result(vk.ErrorOutOfHostMemory)} ErrOutOfDeviceMemory = &Error{Result: Result(vk.ErrorOutOfDeviceMemory)} ErrInitializationFailed = &Error{Result: Result(vk.ErrorInitializationFailed)} ErrDeviceLost = &Error{Result: Result(vk.ErrorDeviceLost)} ErrMemoryMapFailed = &Error{Result: Result(vk.ErrorMemoryMapFailed)} ErrLayerNotPresent = &Error{Result: Result(vk.ErrorLayerNotPresent)} ErrExtensionNotPresent = &Error{Result: Result(vk.ErrorExtensionNotPresent)} ErrFeatureNotPresent = &Error{Result: Result(vk.ErrorFeatureNotPresent)} ErrIncompatibleDriver = &Error{Result: Result(vk.ErrorIncompatibleDriver)} ErrTooManyObjects = &Error{Result: Result(vk.ErrorTooManyObjects)} ErrFragmentedPool = &Error{Result: Result(vk.ErrorFragmentedPool)} ErrOutOfPoolMemory = &Error{Result: Result(vk.ErrorOutOfPoolMemory)} ErrUnknown = &Error{Result: Result(vk.ErrorUnknown)} )
The VkResult errors a compute client can meet. errors.Is(err, ErrDeviceLost) is true for any *Error that carries that code.
var ( // ErrUnsupported means this platform has no binding (it is Linux, 64-bit // only) or the Vulkan loader library is not installed. ErrUnsupported = errors.ErrUnsupported // ErrNoDevice means no physical device matches the filter. ErrNoDevice = errors.New("vulkan: no matching physical device") // ErrTooLarge means a size exceeds a limit of the device or of the process. ErrTooLarge = errors.New("vulkan: size exceeds a device limit") // ErrInvalid means an argument the binding refuses before calling Vulkan. ErrInvalid = errors.New("vulkan: invalid argument") // ErrNoMemoryType means the device offers no host-visible coherent memory // for the buffer. ErrNoMemoryType = errors.New("vulkan: no host-visible coherent memory type") // ErrClosed means the object, or the device it belongs to, was closed. ErrClosed = errors.New("vulkan: object is closed") )
Errors of this package that are not a VkResult.
Functions ¶
Types ¶
type Binding ¶
type Binding struct {
Binding uint32
Kind DescriptorKind
}
Binding declares one binding of descriptor set 0.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a VkBuffer bound to host-visible, host-coherent memory that stays mapped for its whole life.
func (*Buffer) Bytes ¶
Bytes is the mapped memory: len(Bytes()) is the size asked for. It is valid until Close, and writes by the host are visible to the device at the next submission (the memory is coherent).
type CommandBuffer ¶
type CommandBuffer struct {
// contains filtered or unexported fields
}
CommandBuffer is a primary command buffer with a command pool of its own.
func (*CommandBuffer) Begin ¶
func (c *CommandBuffer) Begin() error
Begin starts recording. Beginning an already recording buffer is ErrInvalid. The buffer is recorded for one submission at a time (reset by Begin).
func (*CommandBuffer) Close ¶
func (c *CommandBuffer) Close()
Close destroys the command pool, which frees the buffer. It is safe to call twice, and a no-op once the device is closed. No submission may be pending.
func (*CommandBuffer) Dispatch ¶
func (c *CommandBuffer) Dispatch(p *Pipeline, x, y, z uint32) error
Dispatch records: bind the pipeline and its descriptor set, dispatch x*y*z workgroups, then a barrier that makes the shader's writes visible to the host, so the mapped buffers can be read after the fence. The counts are checked against maxComputeWorkGroupCount.
type DescriptorKind ¶
type DescriptorKind int32
DescriptorKind is the kind of resource bound at a binding.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a VkDevice with one compute queue.
func (*Device) Close ¶
Close waits for the queue to go idle and destroys the device. The caller has closed everything made from it. It is safe to call twice.
func (*Device) NewBuffer ¶
func (d *Device) NewBuffer(size uint64, usage BufferUsage) (*Buffer, error)
NewBuffer creates a buffer of size bytes. The size is checked against the device limits first; every handle made on the way is destroyed on an error.
func (*Device) NewCommandBuffer ¶
func (d *Device) NewCommandBuffer() (*CommandBuffer, error)
NewCommandBuffer creates a command pool on the compute queue family and one command buffer from it. On an error nothing is left alive.
func (*Device) NewComputePipeline ¶
func (d *Device) NewComputePipeline(sh *Shader, entry string, bindings []Binding) (*Pipeline, error)
NewComputePipeline builds the descriptor set layout for bindings, the pipeline layout, the pipeline for entry point entry of sh, and a descriptor set. On an error nothing is left alive.
type DeviceInfo ¶
type DeviceInfo struct {
Index int // position in the enumeration
Name string
Type DeviceType
VendorID uint32
DeviceID uint32
APIVersion Version
DriverVersion uint32 // vendor-specific encoding; Mesa drivers use Version's
DriverName string // from VkPhysicalDeviceDriverProperties
DriverInfo string
// Limits the binding checks before it allocates or dispatches.
MaxStorageBufferRange uint32
MaxUniformBufferRange uint32
MaxMemoryAllocationSize uint64
MaxComputeWorkGroupCount [3]uint32
}
DeviceInfo is what a physical device reports.
type Error ¶
Error is a Vulkan call that returned a negative VkResult. Use errors.Is with the sentinels below to test for one code, or errors.As to read the call.
type Fence ¶
type Fence struct {
// contains filtered or unexported fields
}
Fence is a VkFence that signals when a submission completes.
type Filter ¶
type Filter struct {
VendorID uint32 // 0 for any vendor
Types []DeviceType // empty for any type
}
Filter narrows Pick. The zero Filter accepts every device.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is a VkInstance.
func (*Instance) Close ¶
Close destroys the instance and closes the loader. It is safe to call twice.
func (*Instance) Devices ¶
func (in *Instance) Devices() ([]*PhysicalDevice, error)
Devices lists the physical devices.
type Options ¶
type Options struct {
// ApplicationName is reported to the driver. It may be empty.
ApplicationName string
// Validation enables VK_LAYER_KHRONOS_validation. When the layer is not
// installed Open fails with ErrLayerNotPresent: a validation run that
// silently validated nothing would prove nothing.
Validation bool
}
Options configures Open.
type PhysicalDevice ¶
type PhysicalDevice struct {
Info DeviceInfo
// contains filtered or unexported fields
}
PhysicalDevice is a VkPhysicalDevice. It needs no Close.
func (*PhysicalDevice) Open ¶
func (pd *PhysicalDevice) Open() (*Device, error)
Open creates a device with one compute queue on this physical device.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is a compute pipeline with its layout, and one descriptor set (set 0) allocated from a pool of its own.
func (*Pipeline) Bind ¶
Bind points a binding of the pipeline's descriptor set at a whole buffer. The binding must be declared by the pipeline, and the buffer must have the usage that kind of binding needs. Bind before recording the dispatch that uses it, and not while a submission that uses the set is in flight.
type Result ¶
type Result int32
Result is a VkResult. Negative values are errors, zero is success, positive values are successful statuses (VK_NOT_READY, VK_TIMEOUT, VK_INCOMPLETE).
type Shader ¶
type Shader struct {
// contains filtered or unexported fields
}
Shader is a VkShaderModule.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
vkgen
command
Command vkgen generates the Go mirrors of the Vulkan structures that go-gfx/vulkan uses from the Khronos registry (vk.xml).
|
Command vkgen generates the Go mirrors of the Vulkan structures that go-gfx/vulkan uses from the Khronos registry (vk.xml). |
|
internal
|
|
|
native
Package native opens the system Vulkan loader, libvulkan.so.1, through purego and resolves the entry points of internal/vk's function tables.
|
Package native opens the system Vulkan loader, libvulkan.so.1, through purego and resolves the entry points of internal/vk's function tables. |
|
vkgen
Package vkgen reads the Khronos registry (vk.xml) and generates the Go mirrors of the Vulkan structures, enumerations and handles that go-gfx/vulkan calls.
|
Package vkgen reads the Khronos registry (vk.xml) and generates the Go mirrors of the Vulkan structures, enumerations and handles that go-gfx/vulkan calls. |