Pyrogenesis trunk
VK_EXT_memory_priority

VK_EXT_memory_priority is a device extension that allows to pass additional "priority" value to Vulkan memory allocations that the implementation may use prefer certain buffers and images that are critical for performance to stay in device-local memory in cases when the memory is over-subscribed, while some others may be moved to the system memory.

VMA offers convenient usage of this extension. If you enable it, you can pass "priority" parameter when creating allocations or custom pools and the library automatically passes the value to Vulkan using this extension.

If you want to use this extension in connection with VMA, follow these steps:

Initialization

1) Call vkEnumerateDeviceExtensionProperties for the physical device. Check if the extension is supported - if returned array of VkExtensionProperties contains "VK_EXT_memory_priority".

2) Call vkGetPhysicalDeviceFeatures2 for the physical device instead of old vkGetPhysicalDeviceFeatures. Attach additional structure VkPhysicalDeviceMemoryPriorityFeaturesEXT to VkPhysicalDeviceFeatures2::pNext to be returned. Check if the device feature is really supported - check if VkPhysicalDeviceMemoryPriorityFeaturesEXT::memoryPriority is true.

3) While creating device with vkCreateDevice, enable this extension - add "VK_EXT_memory_priority" to the list passed as VkDeviceCreateInfo::ppEnabledExtensionNames.

4) While creating the device, also don't set VkDeviceCreateInfo::pEnabledFeatures. Fill in VkPhysicalDeviceFeatures2 structure instead and pass it as VkDeviceCreateInfo::pNext. Enable this device feature - attach additional structure VkPhysicalDeviceMemoryPriorityFeaturesEXT to VkPhysicalDeviceFeatures2::pNext chain and set its member memoryPriority to VK_TRUE.

5) While creating VmaAllocator with vmaCreateAllocator() inform VMA that you have enabled this extension and feature - add VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT to VmaAllocatorCreateInfo::flags.

Usage

When using this extension, you should initialize following member:

It should be a floating-point value between 0.0f and 1.0f, where recommended default is 0.5f. Memory allocated with higher value can be treated by the Vulkan implementation as higher priority and so it can have lower chances of being pushed out to system memory, experiencing degraded performance.

It might be a good idea to create performance-critical resources like color-attachment or depth-stencil images as dedicated and set high priority to them. For example:

imgCreateInfo.imageType = VK_IMAGE_TYPE_2D;
imgCreateInfo.extent.width = 3840;
imgCreateInfo.extent.height = 2160;
imgCreateInfo.extent.depth = 1;
imgCreateInfo.mipLevels = 1;
imgCreateInfo.arrayLayers = 1;
VmaAllocationCreateInfo allocCreateInfo = {};
allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
allocCreateInfo.priority = 1.0f;
VkImage img;
vmaCreateImage(allocator, &imgCreateInfo, &allocCreateInfo, &img, &alloc, nullptr);
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateImage(VmaAllocator VMA_NOT_NULL allocator, const VkImageCreateInfo *VMA_NOT_NULL pImageCreateInfo, const VmaAllocationCreateInfo *VMA_NOT_NULL pAllocationCreateInfo, VkImage VMA_NULLABLE_NON_DISPATCHABLE *VMA_NOT_NULL pImage, VmaAllocation VMA_NULLABLE *VMA_NOT_NULL pAllocation, VmaAllocationInfo *VMA_NULLABLE pAllocationInfo)
Function similar to vmaCreateBuffer().
@ VMA_MEMORY_USAGE_AUTO
Selects best memory type automatically.
Definition: vk_mem_alloc.h:492
@ VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
Set this flag if the allocation should have its own memory block.
Definition: vk_mem_alloc.h:528
uint32_t depth
Definition: vulkan.h:1779
uint32_t height
Definition: vulkan.h:1778
uint32_t width
Definition: vulkan.h:1777
Definition: vulkan.h:2685
VkImageLayout initialLayout
Definition: vulkan.h:2700
uint32_t mipLevels
Definition: vulkan.h:2692
uint32_t arrayLayers
Definition: vulkan.h:2693
VkSampleCountFlagBits samples
Definition: vulkan.h:2694
VkExtent3D extent
Definition: vulkan.h:2691
VkFormat format
Definition: vulkan.h:2690
VkImageType imageType
Definition: vulkan.h:2689
VkImageTiling tiling
Definition: vulkan.h:2695
VkImageUsageFlags usage
Definition: vulkan.h:2696
Parameters of new VmaAllocation.
Definition: vk_mem_alloc.h:1222
float priority
A floating-point value between 0 and 1, indicating the priority of the allocation relative to other m...
Definition: vk_mem_alloc.h:1268
VmaMemoryUsage usage
Intended usage of memory.
Definition: vk_mem_alloc.h:1230
VmaAllocationCreateFlags flags
Use VmaAllocationCreateFlagBits enum.
Definition: vk_mem_alloc.h:1224
Represents single memory allocation.
@ VK_IMAGE_LAYOUT_UNDEFINED
Definition: vulkan.h:813
@ VK_IMAGE_TILING_OPTIMAL
Definition: vulkan.h:828
@ VK_IMAGE_USAGE_SAMPLED_BIT
Definition: vulkan.h:841
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
Definition: vulkan.h:843
@ VK_SAMPLE_COUNT_1_BIT
Definition: vulkan.h:1357
@ VK_IMAGE_TYPE_2D
Definition: vulkan.h:834
@ VK_FORMAT_R8G8B8A8_UNORM
Definition: vulkan.h:544
@ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Definition: vulkan.h:1112

priority member is ignored in the following situations:

  • Allocations created in custom pools: They inherit the priority, along with all other allocation parameters from the parametrs passed in VmaPoolCreateInfo when the pool was created.
  • Allocations created in default pools: They inherit the priority from the parameters VMA used when creating default pools, which means priority == 0.5f.