Documentation
¶
Overview ¶
+build !amd64,!arm64,!mips64,!sparc64,!riscv
+build amd64 arm64 mips64 sparc64 riscv
Package vma implements a Go wrapper for AMD's VulkanMemoryAllocator library.
Index ¶
- Constants
- Variables
- type Allocation
- type AllocationCreateInfo
- type AllocationInfo
- type Allocator
- func (a *Allocator) AllocateMemory(memoryRequirements *vk.MemoryRequirements, createInfo *AllocationCreateInfo, ...) (Allocation, AllocationInfo, error)
- func (a *Allocator) AllocateMemoryForBuffer(buffer vk.Buffer, createInfo *AllocationCreateInfo, returnInfo bool) (Allocation, AllocationInfo, error)
- func (a *Allocator) AllocateMemoryForImage(image vk.Image, createInfo *AllocationCreateInfo, returnInfo bool) (Allocation, AllocationInfo, error)
- func (a *Allocator) AllocateMemoryPages(memoryRequirements *vk.MemoryRequirements, createInfo *AllocationCreateInfo, ...) ([]Allocation, []AllocationInfo, error)
- func (a *Allocator) BindBufferMemory(allocation Allocation, buffer vk.Buffer) error
- func (a *Allocator) BindBufferMemory2(allocation Allocation, offset vk.DeviceSize, buffer vk.Buffer, ...) error
- func (a *Allocator) BindImageMemory(allocation Allocation, image vk.Image) error
- func (a *Allocator) BindImageMemory2(allocation Allocation, offset vk.DeviceSize, image vk.Image, ...) error
- func (a *Allocator) BuildStatsString(detailedMap bool) string
- func (a *Allocator) CalculateStats() Stats
- func (a *Allocator) CheckCorruption(memoryTypeBits uint32) vk.Result
- func (a *Allocator) CheckPoolCorruption(pool Pool) vk.Result
- func (a *Allocator) CreateBuffer(bufferCreateInfo *vk.BufferCreateInfo, ...) (vk.Buffer, Allocation, AllocationInfo, error)
- func (a *Allocator) CreateImage(imageCreateInfo *vk.ImageCreateInfo, ...) (vk.Image, Allocation, AllocationInfo, error)
- func (a *Allocator) CreateLostAllocation() Allocation
- func (a *Allocator) CreatePool(createInfo *PoolCreateInfo) (Pool, error)
- func (a *Allocator) DefragmentationBegin(info *DefragmentationInfo2) (DefragmentationStats, DefragmentationContext, error)
- func (a *Allocator) DefragmentationEnd(context DefragmentationContext) error
- func (a *Allocator) Destroy()
- func (a *Allocator) DestroyBuffer(buffer vk.Buffer, allocation Allocation)
- func (a *Allocator) DestroyImage(image vk.Image, allocation Allocation)
- func (a *Allocator) DestroyPool(pool Pool)
- func (a *Allocator) FindMemoryTypeIndex(memoryTypeBits uint32, allocationCreateInfo *AllocationCreateInfo) (uint32, error)
- func (a *Allocator) FindMemoryTypeIndexForBufferInfo(bufferCreateInfo *vk.BufferCreateInfo, ...) (uint32, error)
- func (a *Allocator) FindMemoryTypeIndexForImageInfo(imageCreateInfo *vk.ImageCreateInfo, ...) (uint32, error)
- func (a *Allocator) FlushAllocation(allocation Allocation, offset vk.DeviceSize, size vk.DeviceSize)
- func (a *Allocator) FreeMemory(allocation Allocation)
- func (a *Allocator) FreeMemoryPages(allocations []Allocation)
- func (a *Allocator) GetAllocationInfo(allocation Allocation) AllocationInfo
- func (a *Allocator) GetBudget() Budget
- func (a *Allocator) GetMemoryProperties() *vk.PhysicalDeviceMemoryProperties
- func (a *Allocator) GetMemoryTypeProperties(memoryTypeIndex uint32) vk.MemoryPropertyFlags
- func (a *Allocator) GetPhysicalDeviceProperties() *vk.PhysicalDeviceProperties
- func (a *Allocator) GetPoolName(pool Pool) string
- func (a *Allocator) GetPoolStats(pool Pool) PoolStats
- func (a *Allocator) InvalidateAllocation(allocation Allocation, offset vk.DeviceSize, size vk.DeviceSize)
- func (a *Allocator) MakePoolAllocationsLost(pool Pool) int
- func (a *Allocator) MapMemory(allocation Allocation) (uintptr, error)
- func (a *Allocator) NewReadWriter(allocation Allocation, size uint64) (ReadWriter, error)
- func (a *Allocator) NewReadWriterSimple(allocation Allocation) (ReadWriter, error)
- func (a *Allocator) SetAllocationUserData(allocation Allocation, userData unsafe.Pointer)
- func (a *Allocator) SetCurrentFrameIndex(frameIndex uint32)
- func (a *Allocator) SetPoolName(pool Pool, name string)
- func (a *Allocator) TouchAllocation(allocation Allocation) bool
- func (a *Allocator) UnmapMemory(allocation Allocation)
- type AllocatorCreateInfo
- type Budget
- type DefragmentationContext
- type DefragmentationInfo2
- type DefragmentationStats
- type Pool
- type PoolCreateInfo
- type PoolStats
- type ReadWriter
- func (rw *ReadWriter) Buffer() []byte
- func (rw *ReadWriter) Close() error
- func (rw *ReadWriter) Pointer() unsafe.Pointer
- func (rw *ReadWriter) Read(p []byte) (n int, err error)
- func (rw *ReadWriter) ReadAny(v interface{}) (n int, err error)
- func (rw *ReadWriter) ReadToPointer(dstPtr unsafe.Pointer, size uint64) (n int, err error)
- func (rw *ReadWriter) Reset()
- func (rw *ReadWriter) Write(p []byte) (n int, err error)
- func (rw *ReadWriter) WriteAny(v interface{}) (n int, err error)
- func (rw *ReadWriter) WriteFromPointer(srcPtr unsafe.Pointer, size uint64) (n int, err error)
- type StatInfo
- type Stats
Constants ¶
const ( AllocatorCreateExternallySynchronized = C.VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT AllocatorCreateDedicatedAllocation = C.VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT AllocatorCreateBindMemory2 = C.VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT AllocatorCreateMemoryBudget = C.VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT AllocatorCreateAMDDeviceCoherentMemory = C.VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT AllocatorCreateBufferDeviceAddress = C.VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT AllocatorCreateFlagBitsMaxEnum = C.VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM RecordFlushAfterCall = C.VMA_RECORD_FLUSH_AFTER_CALL_BIT RecordFlagBitsMaxEnum = C.VMA_RECORD_FLAG_BITS_MAX_ENUM MemoryUsageUnknown = C.VMA_MEMORY_USAGE_UNKNOWN MemoryUsageGPUOnly = C.VMA_MEMORY_USAGE_GPU_ONLY MemoryUsageCPUOnly = C.VMA_MEMORY_USAGE_CPU_ONLY MemoryUsageCPUToGPU = C.VMA_MEMORY_USAGE_CPU_TO_GPU MemoryUsageGPUToCPU = C.VMA_MEMORY_USAGE_GPU_TO_CPU MemoryUsageCPUCopy = C.VMA_MEMORY_USAGE_CPU_COPY MemoryUsageGPULazilyAllocated = C.VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED MemoryUsageUsageMaxEnum = C.VMA_MEMORY_USAGE_MAX_ENUM AllocationCreateDedicatedMemory = C.VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT AllocationCreateNeverAllocate = C.VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT AllocationCreateMapped = C.VMA_ALLOCATION_CREATE_MAPPED_BIT AllocationCreateCanBecomeLost = C.VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT AllocationCreateCanMakeOtherLost = C.VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT AllocationCreateUserDataCopyString = C.VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT AllocationCreateUpperAddress = C.VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT AllocationCreateDontBind = C.VMA_ALLOCATION_CREATE_DONT_BIND_BIT AllocationCreateStrategyBestFit = C.VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT AllocationCreateStrategyWorstFit = C.VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT AllocationCreateStrategyFirstFit = C.VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT AllocationCreateStrategyMinMemory = C.VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT AllocationCreateStrategyMinTime = C.VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT AllocationCreateStrategyMinFragmentation = C.VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT AllocationCreateStrategyMask = C.VMA_ALLOCATION_CREATE_STRATEGY_MASK AllocationCreateFlagBitsMaxEnum = C.VMA_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM PoolCreateIgnoreBufferImageGranularity = C.VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT PoolCreateLinearAlgorithm = C.VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT PoolCreateBuddyAlgorithm = C.VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT PoolCreateAlgorithmMask = C.VMA_POOL_CREATE_ALGORITHM_MASK PoolCreateFlagBitsMaxEnum = C.VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM DefragmentationFlagIncremental = C.VMA_DEFRAGMENTATION_FLAG_INCREMENTAL DefragmentationFlagBitsMaxEnum = C.VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM )
Variables ¶
var ( // ErrorAlreadyUnmapped is returned when trying to write to an unmapped buffer. ErrorAlreadyUnmapped = errors.New("memory already unmapped") // ErrorBufferIsFull is returned when trying to write to a full buffer. ErrorBufferIsFull = errors.New("attempting to write into a full buffer") )
Functions ¶
This section is empty.
Types ¶
type AllocationCreateInfo ¶
type AllocationInfo ¶
type AllocationInfo C.VmaAllocationInfo
AllocationInfo parameters of VmaAllocation objects, that can be retrieved using function GetAllocationInfo()
func (*AllocationInfo) DeviceMemory ¶
func (a *AllocationInfo) DeviceMemory() vk.DeviceMemory
func (*AllocationInfo) MappedData ¶
func (a *AllocationInfo) MappedData() unsafe.Pointer
func (*AllocationInfo) MemoryType ¶
func (a *AllocationInfo) MemoryType() uint32
func (*AllocationInfo) Offset ¶
func (a *AllocationInfo) Offset() vk.DeviceSize
func (*AllocationInfo) Size ¶
func (a *AllocationInfo) Size() vk.DeviceSize
func (*AllocationInfo) UserData ¶
func (a *AllocationInfo) UserData() unsafe.Pointer
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
Allocator represents main object of this library initialized
func NewAllocator ¶
func NewAllocator(c *AllocatorCreateInfo) (*Allocator, error)
NewAllocator creates a new memory allocator. TODO: is it safe to copy?
func (*Allocator) AllocateMemory ¶
func (a *Allocator) AllocateMemory(memoryRequirements *vk.MemoryRequirements, createInfo *AllocationCreateInfo, returnInfo bool) (Allocation, AllocationInfo, error)
func (*Allocator) AllocateMemoryForBuffer ¶
func (a *Allocator) AllocateMemoryForBuffer(buffer vk.Buffer, createInfo *AllocationCreateInfo, returnInfo bool) (Allocation, AllocationInfo, error)
func (*Allocator) AllocateMemoryForImage ¶
func (a *Allocator) AllocateMemoryForImage(image vk.Image, createInfo *AllocationCreateInfo, returnInfo bool) (Allocation, AllocationInfo, error)
func (*Allocator) AllocateMemoryPages ¶
func (a *Allocator) AllocateMemoryPages(memoryRequirements *vk.MemoryRequirements, createInfo *AllocationCreateInfo, allocationCount int, returnInfo bool) ([]Allocation, []AllocationInfo, error)
func (*Allocator) BindBufferMemory ¶
func (a *Allocator) BindBufferMemory(allocation Allocation, buffer vk.Buffer) error
func (*Allocator) BindBufferMemory2 ¶
func (a *Allocator) BindBufferMemory2(allocation Allocation, offset vk.DeviceSize, buffer vk.Buffer, pNext unsafe.Pointer) error
func (*Allocator) BindImageMemory ¶
func (a *Allocator) BindImageMemory(allocation Allocation, image vk.Image) error
func (*Allocator) BindImageMemory2 ¶
func (a *Allocator) BindImageMemory2(allocation Allocation, offset vk.DeviceSize, image vk.Image, pNext unsafe.Pointer) error
func (*Allocator) BuildStatsString ¶
BuildStatsString builds and returns statistics as string in JSON format. This function can be called safely without needing to manually free the built string.
func (*Allocator) CalculateStats ¶
func (*Allocator) CheckCorruption ¶
func (*Allocator) CheckPoolCorruption ¶
func (*Allocator) CreateBuffer ¶
func (a *Allocator) CreateBuffer(bufferCreateInfo *vk.BufferCreateInfo, allocationCreateInfo *AllocationCreateInfo, returnInfo bool) (vk.Buffer, Allocation, AllocationInfo, error)
func (*Allocator) CreateImage ¶
func (a *Allocator) CreateImage(imageCreateInfo *vk.ImageCreateInfo, allocationCreateInfo *AllocationCreateInfo, returnInfo bool) (vk.Image, Allocation, AllocationInfo, error)
func (*Allocator) CreateLostAllocation ¶
func (a *Allocator) CreateLostAllocation() Allocation
func (*Allocator) CreatePool ¶
func (a *Allocator) CreatePool(createInfo *PoolCreateInfo) (Pool, error)
func (*Allocator) DefragmentationBegin ¶
func (a *Allocator) DefragmentationBegin(info *DefragmentationInfo2) (DefragmentationStats, DefragmentationContext, error)
func (*Allocator) DefragmentationEnd ¶
func (a *Allocator) DefragmentationEnd(context DefragmentationContext) error
func (*Allocator) DestroyBuffer ¶
func (a *Allocator) DestroyBuffer(buffer vk.Buffer, allocation Allocation)
func (*Allocator) DestroyImage ¶
func (a *Allocator) DestroyImage(image vk.Image, allocation Allocation)
func (*Allocator) DestroyPool ¶
func (*Allocator) FindMemoryTypeIndex ¶
func (a *Allocator) FindMemoryTypeIndex(memoryTypeBits uint32, allocationCreateInfo *AllocationCreateInfo) (uint32, error)
func (*Allocator) FindMemoryTypeIndexForBufferInfo ¶
func (a *Allocator) FindMemoryTypeIndexForBufferInfo(bufferCreateInfo *vk.BufferCreateInfo, allocationCreateInfo *AllocationCreateInfo) (uint32, error)
func (*Allocator) FindMemoryTypeIndexForImageInfo ¶
func (a *Allocator) FindMemoryTypeIndexForImageInfo(imageCreateInfo *vk.ImageCreateInfo, allocationCreateInfo *AllocationCreateInfo) (uint32, error)
func (*Allocator) FlushAllocation ¶
func (a *Allocator) FlushAllocation(allocation Allocation, offset vk.DeviceSize, size vk.DeviceSize)
func (*Allocator) FreeMemory ¶
func (a *Allocator) FreeMemory(allocation Allocation)
func (*Allocator) FreeMemoryPages ¶
func (a *Allocator) FreeMemoryPages(allocations []Allocation)
func (*Allocator) GetAllocationInfo ¶
func (a *Allocator) GetAllocationInfo(allocation Allocation) AllocationInfo
func (*Allocator) GetMemoryProperties ¶
func (a *Allocator) GetMemoryProperties() *vk.PhysicalDeviceMemoryProperties
func (*Allocator) GetMemoryTypeProperties ¶
func (a *Allocator) GetMemoryTypeProperties(memoryTypeIndex uint32) vk.MemoryPropertyFlags
func (*Allocator) GetPhysicalDeviceProperties ¶
func (a *Allocator) GetPhysicalDeviceProperties() *vk.PhysicalDeviceProperties
func (*Allocator) GetPoolName ¶
func (*Allocator) GetPoolStats ¶
func (*Allocator) InvalidateAllocation ¶
func (a *Allocator) InvalidateAllocation(allocation Allocation, offset vk.DeviceSize, size vk.DeviceSize)
func (*Allocator) MakePoolAllocationsLost ¶
func (*Allocator) NewReadWriter ¶
func (a *Allocator) NewReadWriter(allocation Allocation, size uint64) (ReadWriter, error)
NewReadWriter returns a new ReadWriter for the allocation. User must keep track of the allocation's size.
func (*Allocator) NewReadWriterSimple ¶
func (a *Allocator) NewReadWriterSimple(allocation Allocation) (ReadWriter, error)
NewReadWriterSimple is identical to ReadWriter, but asks the allocator for the size. Using this function is less efficient than using NewReadWriter. Note that this will use the size of the internal allocation rather than what was asked when creating the buffer/image, so it will most likely be larger than expected.
func (*Allocator) SetAllocationUserData ¶
func (a *Allocator) SetAllocationUserData(allocation Allocation, userData unsafe.Pointer)
func (*Allocator) SetCurrentFrameIndex ¶
func (*Allocator) SetPoolName ¶
func (*Allocator) TouchAllocation ¶
func (a *Allocator) TouchAllocation(allocation Allocation) bool
func (*Allocator) UnmapMemory ¶
func (a *Allocator) UnmapMemory(allocation Allocation)
type AllocatorCreateInfo ¶
type AllocatorCreateInfo struct { VulkanProcAddr unsafe.Pointer PhysicalDevice vk.PhysicalDevice Device vk.Device Instance vk.Instance Flags uint32 PreferredLargeHeapBlockSize vk.DeviceSize // Allocation callbacks are currently not supported. If anybody actually cares, feel free to implement // AllocationCallbacks *vk.AllocationCallbacks // DeviceMemoryCallbacks *DeviceMemoryCallbacks FrameInUseCount uint32 HeapSizeLimit []vk.DeviceSize // RecordSettings *RecordSettings // Function recording is not used. VulkanAPIVersion uint32 // Vulkan version to use, use vk.MakeVersion. Leave as 0 for default. }
type DefragmentationContext ¶
type DefragmentationContext C.VmaDefragmentationContext
DefragmentationContext represents Opaque object that represents started defragmentation process
type DefragmentationInfo2 ¶
type DefragmentationInfo2 struct { Flags uint32 Allocations []Allocation AllocationsChanged []vk.Bool32 Pools []Pool MaxCPUBytesToMove vk.DeviceSize MaxCPUAllocationsToMove uint32 MaxGPUBytesToMove vk.DeviceSize MaxGPUAllocationsToMove uint32 CommandBuffer vk.CommandBuffer }
DefragmentationInfo2 is the parameters for defragmentation. Note that the earlier, deprecated version of this struct is not included in these bindings.
type DefragmentationStats ¶
type DefragmentationStats struct { BytesMoved vk.DeviceSize BytesFreed vk.DeviceSize AllocationsMoved uint32 DeviceMemoryBlocksFreed uint32 }
DefragmentationStats is the statistics returned by function vmaDefragment()
type PoolCreateInfo ¶
type PoolCreateInfo struct { MemoryTypeIndex uint32 Flags uint32 BlockSize vk.DeviceSize MinBlockCount uint MaxBlockCount uint FrameInUseCount uint32 }
PoolCreateInfo describes parameter of created VmaPool
type ReadWriter ¶
type ReadWriter struct {
// contains filtered or unexported fields
}
ReadWriter implements a Go-like interface for accessing mapped memory regions. It should not be copied after creating.
Close must be called to unmap the memory after reading or writing to the buffer.
func (*ReadWriter) Buffer ¶
func (rw *ReadWriter) Buffer() []byte
Buffer returns the underlying buffer as a byte slice. This method should not be used along side Read or Write, as any changes to the returned slice will not be reflected in the ReadWriter's offset.
func (*ReadWriter) Close ¶
func (rw *ReadWriter) Close() error
Close unmaps the memory and should be called for all non-persistent buffers after filling the buffer. Attempting to write to or close an already closed Writer will yield ErrorAlreadyUnmapped.
func (*ReadWriter) Pointer ¶
func (rw *ReadWriter) Pointer() unsafe.Pointer
Pointer returns the pointer to the underlying buffer. This sidesteps all safety features of ReadWriter.
func (*ReadWriter) Read ¶
func (rw *ReadWriter) Read(p []byte) (n int, err error)
Read can be used to read regular byte slices. It will return io.EOF once the buffer has been fully read.
func (*ReadWriter) ReadAny ¶
func (rw *ReadWriter) ReadAny(v interface{}) (n int, err error)
ReadAny reads to an arbitrary type. The function returns the number of bytes read. v must be a slice or a pointer. This function uses runtime reflection, so it is slower than the Read method. ReadAny should not be used for elements containing pointers, maps or slices.
func (*ReadWriter) ReadToPointer ¶
ReadToPointer lets you read directly into an unsafe.Pointer. It is the most efficient but also the least safe option.
func (*ReadWriter) Reset ¶
func (rw *ReadWriter) Reset()
Reset resets the number of elements written, so that the next write or read will start from the beginning.
func (*ReadWriter) Write ¶
func (rw *ReadWriter) Write(p []byte) (n int, err error)
Write can be used to write regular byte slices. It is safe against buffer overflows (assuming you give the correct size when creating it) and will return an ErrorBufferIsFull error when attempting to write a larger slice than the buffer can hold. It will still fill the buffer with what it can hold.
func (*ReadWriter) WriteAny ¶
func (rw *ReadWriter) WriteAny(v interface{}) (n int, err error)
WriteAny writes an arbitrary type into the buffer. The function returns the number of bytes written. v must be a slice or a pointer. This function uses runtime reflection, so it is slower than the Write method. WriteAny should not be used for elements containing pointers, maps or slices.
func (*ReadWriter) WriteFromPointer ¶
WriteFromPointer lets you write directly from an unsafe.Pointer. It is the most efficient but also the least safe option.
type StatInfo ¶
type StatInfo C.VmaStatInfo
StatInfo is the calculated statistics of memory usage in entire allocator