VkMemoryDedicatedRequirementsKHR structure to the pNext chain of the VkMemoryRequirements2 structure passed as the pMemoryRequirements parameter of a call to vkGetBufferMemoryRequirements2 or vkGetImageMemoryRequirements2. Certain external handle types and external images or buffers may also depend on dedicated allocations on implementations that associate image or buffer metadata with OS-level memory objects.
This extension adds a two small structures to memory requirements querying and memory allocation: a new structure that flags whether an image/buffer should have a dedicated allocation, and a structure indicating the image or buffer that an allocation will be bound to.
All functionality in this extension is included in core Vulkan 1.1, with the KHR suffix omitted. The original type, enum and command names are still available as aliases of the core functionality.
// Create an image with a dedicated allocation based on the
// implementation's preference
VkImageCreateInfo imageCreateInfo =
{
// Image creation parameters
};
VkImage image;
VkResult result = vkCreateImage(
device,
&imageCreateInfo,
NULL, // pAllocator
&image);
VkMemoryDedicatedRequirementsKHR dedicatedRequirements =
{
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR,
.pNext = NULL,
};
VkMemoryRequirements2 memoryRequirements =
{
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
.pNext = &dedicatedRequirements,
};
const VkImageMemoryRequirementsInfo2 imageRequirementsInfo =
{
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
.pNext = NULL,
.image = image
};
vkGetImageMemoryRequirements2(
device,
&imageRequirementsInfo,
&memoryRequirements);
if (dedicatedRequirements.prefersDedicatedAllocation) {
// Allocate memory with VkMemoryDedicatedAllocateInfoKHR::image
// pointing to the image we are allocating the memory for
VkMemoryDedicatedAllocateInfoKHR dedicatedInfo =
{
.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,
.pNext = NULL,
.image = image,
.buffer = VK_NULL_HANDLE,
};
VkMemoryAllocateInfo memoryAllocateInfo =
{
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &dedicatedInfo,
.allocationSize = memoryRequirements.size,
.memoryTypeIndex = FindMemoryTypeIndex(memoryRequirements.memoryTypeBits),
};
VkDeviceMemory memory;
vkAllocateMemory(
device,
&memoryAllocateInfo,
NULL, // pAllocator
&memory);
// Bind the image to the memory
vkBindImageMemory(
device,
image,
memory,
0);
} else {
// Take the normal memory sub-allocation path
}
VK_KHR_dedicated_allocationVK_KHR_get_memory_requirements2| Modifier and Type | Field and Description |
|---|---|
| public static final String | VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME
The extension name. |
| public static final int | VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION
The extension specification version. |
| public static final int | VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR
Extends |
| public static final int | VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
Extends |
| Access | Constructor and Description |
|---|---|
| private |
| VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME | back to summary |
|---|---|
| public static final String VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME The extension name. | |
| VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION | back to summary |
|---|---|
| public static final int VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION The extension specification version. | |
| VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR | back to summary |
|---|---|
| public static final int VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR Extends Enum values: | |
| VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR | back to summary |
|---|---|
| public static final int VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR Extends Enum values: | |
| KHRDedicatedAllocation | back to summary |
|---|---|
| private KHRDedicatedAllocation() | |