GPGMM
GPGMM, a General-Purpose GPU Memory Management Library
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
gpgmm::vk Namespace Reference

Classes

struct  GpAllocatorCreateInfo
 Used to create allocator. More...
 
struct  GpResourceAllocationCreateInfo
 

Enumerations

enum  GpAllocatorCreateFlags { GP_ALLOCATOR_CREATE_NONE = 0x0 , GP_ALLOCATOR_CREATE_DISABLE_MEMORY_PREFETCH = 0x4 , GP_ALLOCATOR_CREATE_ALWAYS_ON_DEMAND = 0x8 , GP_ALLOCATOR_CREATE_ALWAYS_IN_BUDGET = 0x10 }
 Configures how allocators should be created. More...
 
enum  GpAllocatorAlgorithm {
  GP_ALLOCATOR_ALGORITHM_DEFAULT = 0 , GP_ALLOCATOR_ALGORITHM_SLAB = 1 , GP_ALLOCATOR_ALGORITHM_BUDDY_SYSTEM = 2 , GP_ALLOCATOR_ALGORITHM_FIXED_POOL = 3 ,
  GP_ALLOCATOR_ALGORITHM_SEGMENTED_POOL = 4
}
 
enum  GpResourceAllocationCreateFlags { GP_ALLOCATION_CREATE_NONE = 0x0 , GP_ALLOCATION_CREATE_NEVER_ALLOCATE_MEMORY = 0x1 , GP_ALLOCATION_CREATE_NEVER_SUBALLOCATE_MEMORY = 0x4 , GP_ALLOCATION_CREATE_ALWAYS_PREFETCH_MEMORY = 0x8 }
 

Functions

GPGMM_EXPORT VkResult gpCreateResourceAllocator (const GpAllocatorCreateInfo &info, GpResourceAllocator *allocatorOut)
 Create allocator used to create and manage video memory for the App specified device and instance.
 
GPGMM_EXPORT void gpDestroyResourceAllocator (GpResourceAllocator allocator)
 Destroy allocator.
 
GPGMM_EXPORT VkResult gpCreateBuffer (GpResourceAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, VkBuffer *pBuffer, const GpResourceAllocationCreateInfo *pAllocationCreateInfo, GpResourceAllocation *allocationOut)
 Create a buffer allocation.
 
GPGMM_EXPORT void gpDestroyBuffer (GpResourceAllocator allocator, VkBuffer buffer, GpResourceAllocation allocation)
 Destroy buffer allocation.
 
GPGMM_EXPORT VkResult gpCreateImage (GpResourceAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, VkImage *pImage, const GpResourceAllocationCreateInfo *pAllocationCreateInfo, GpResourceAllocation *allocationOut)
 Create a image allocation.
 
GPGMM_EXPORT void gpDestroyImage (GpResourceAllocator allocator, VkImage image, GpResourceAllocation allocation)
 Destroy image allocation.
 

Enumeration Type Documentation

◆ GpAllocatorAlgorithm

Specify the algorithms used for allocation.

Enumerator
GP_ALLOCATOR_ALGORITHM_DEFAULT 

Use default allocation mechanism.

Relies on internal heuristics to automatically determine the best allocation mechanism. The
selection of algorithm depends on:

1. The memory properties or flags specified by the user.
2. The size the resource being created.
3. The amount of available memory.

In general, the most-efficent resource allocator will be attempted first (efficent
being defined as fastest service-time to allocate/deallocate with smallest memory
footprint), subject to other constraints. However, since it's impossible to predict all
future memory accesses, allocation techniques that rely on amortization of GPU heaps may not
prove to be faster as expected. Further experimentation is recommended.
GP_ALLOCATOR_ALGORITHM_SLAB 

Use the slab allocation mechanism.

Slab allocation allocates/deallocates in O(1) time using O(N * pageSize) space.

Slab allocation does not suffer from internal fragmentation but could externally fragment
when many unique request sizes are used.
GP_ALLOCATOR_ALGORITHM_BUDDY_SYSTEM 

Use the buddy system mechanism.

Buddy system allocate/deallocates in O(Log2) time using O(1) space.

Buddy system suffers from internal fragmentation (ie. resources are not a power-of-two) but
does not suffer from external fragmentation as much since the device memory size does not
change.

It is recommend to specify a preferredDeviceMemorySize large enough such that multiple
requests can fit within the specified preferredDeviceMemorySize but not too large where
creating the larger device memory becomes a bigger bottleneck.
GP_ALLOCATOR_ALGORITHM_FIXED_POOL 

Recycles device memory of a size being specified.

Fixed pools allocate/deallocate in O(1) time using O(N) space.

Fixed-size pool limits recycling to device memorys equal to
preferredDeviceMemorySize. A preferredDeviceMemorySize of zero is effectively
equivalent to ALLOCATOR_FLAG_ALWAYS_ON_DEMAND.
GP_ALLOCATOR_ALGORITHM_SEGMENTED_POOL 

Recycles device memory of any size using multiple pools.

Segmented pool allocate/deallocates in O(Log2) time using O(N * K) space.

◆ GpAllocatorCreateFlags

Configures how allocators should be created.

Enumerator
GP_ALLOCATOR_CREATE_NONE 

Disables all allocator flags.

GP_ALLOCATOR_CREATE_DISABLE_MEMORY_PREFETCH 

Disables pre-fetching of GPU memory.

Should be only used for debugging and testing purposes.
GP_ALLOCATOR_CREATE_ALWAYS_ON_DEMAND 

Tell GPGMM to allocate exactly what is needed, and to de-allocate memory immediately once no longer needed (instead of re-using it).

This is very slow and not recommended for general use but may be useful for running with the minimal possible GPU memory footprint or debugging OOM failures.

GP_ALLOCATOR_CREATE_ALWAYS_IN_BUDGET 

Creates resource within budget.

Requires the device extension VK_EXT_memory_budget to be supported before use.
The instance specified in GpAllocatorCreateInfo is also required to support
VK_KHR_get_physical_device_properties2.

◆ GpResourceAllocationCreateFlags

Additional controls that modify allocations.

Enumerator
GP_ALLOCATION_CREATE_NONE 

Disables all allocation flags.

Enabled by default.
GP_ALLOCATION_CREATE_NEVER_ALLOCATE_MEMORY 

Disallow creating new device memory when creating a resource.

Forbids creating new device memory when creating a resource. The created resource
must use existing device memory or error. Effectively disables creating
standalone allocations whose memory cannot be reused.
GP_ALLOCATION_CREATE_NEVER_SUBALLOCATE_MEMORY 

Disallow creating multiple resource allocations from the same device memory.

The created resource will always be allocated with it's own device memory.
GP_ALLOCATION_CREATE_ALWAYS_PREFETCH_MEMORY 

Prefetch memory for the next resource allocation.

The call to prefetch is deferred to a seperate background thread by GPGMM which runs
when the current allocation requested is completed. By default, GPGMM will automatically
trigger prefetching based on heurstics. Prefetching enables more performance when
allocating for large contiguous allocations. Should not be used with
GP_ALLOCATION_CREATE_NEVER_ALLOCATE_MEMORY.

Function Documentation

◆ gpCreateBuffer()

GPGMM_EXPORT VkResult gpgmm::vk::gpCreateBuffer ( GpResourceAllocator allocator,
const VkBufferCreateInfo * pBufferCreateInfo,
VkBuffer * pBuffer,
const GpResourceAllocationCreateInfo * pAllocationCreateInfo,
GpResourceAllocation * allocationOut )

Create a buffer allocation.

Parameters
allocatorA GpResourceAllocator used to create the buffer and allocation.
pBufferCreateInfoA pointer to a VkBufferCreateInfo that describes the buffer to create.
pBufferA pointer to a VkBuffer that will be created using the allocation.
pAllocationCreateInfoA pointer to a GpResourceAllocationCreateInfo that describes the allocation.
[out]allocationOutA pointer to GpResourceAllocation that represents the buffer allocation.

◆ gpCreateImage()

GPGMM_EXPORT VkResult gpgmm::vk::gpCreateImage ( GpResourceAllocator allocator,
const VkImageCreateInfo * pImageCreateInfo,
VkImage * pImage,
const GpResourceAllocationCreateInfo * pAllocationCreateInfo,
GpResourceAllocation * allocationOut )

Create a image allocation.

Parameters
allocatorA GpResourceAllocator used to create the image and allocation.
pImageCreateInfoA pointer to a VkImageCreateInfo that describes the image to create.
pImageA pointer to a VkImage that will be created using the allocation.
pAllocationCreateInfoA pointer to a GpResourceAllocationCreateInfo that describes the allocation.
[out]allocationOutA pointer to GpResourceAllocation that represents the image allocation.

◆ gpCreateResourceAllocator()

GPGMM_EXPORT VkResult gpgmm::vk::gpCreateResourceAllocator ( const GpAllocatorCreateInfo & info,
GpResourceAllocator * allocatorOut )

Create allocator used to create and manage video memory for the App specified device and instance.

Parameters
infoA reference to GpAllocatorCreateInfo structure that describes the allocator.
[out]allocatorOutPointer to a memory block that receives a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator. If NULL is passed and allocator creating would succeed, VK_INCOMPLETE is returned.

◆ gpDestroyBuffer()

GPGMM_EXPORT void gpgmm::vk::gpDestroyBuffer ( GpResourceAllocator allocator,
VkBuffer buffer,
GpResourceAllocation allocation )

Destroy buffer allocation.

Parameters
allocatorA GpResourceAllocator used to create the buffer and allocation.
bufferA VkBuffer that was also created by the allocator.
allocationA GpResourceAllocation that was created by the allocator.

◆ gpDestroyImage()

GPGMM_EXPORT void gpgmm::vk::gpDestroyImage ( GpResourceAllocator allocator,
VkImage image,
GpResourceAllocation allocation )

Destroy image allocation.

Parameters
allocatorA GpResourceAllocator used to create the image and allocation.
imageA VkImage that was also created by the allocator.
allocationA GpResourceAllocation that was created by the allocator.

◆ gpDestroyResourceAllocator()

GPGMM_EXPORT void gpgmm::vk::gpDestroyResourceAllocator ( GpResourceAllocator allocator)

Destroy allocator.

Parameters
allocatorA GpResourceAllocator to destroy.