The VkPhysicalDeviceMemoryProperties structure describes a number of memory heaps as well as a number of memory types that can be used to access memory allocated in those heaps. Each heap describes a memory resource of a particular size, and each memory type describes a set of memory properties (e.g. host cached vs. uncached) that can be used with a given memory heap. Allocations using a particular memory type will consume resources from the heap indicated by that memory type’s heap index. More than one memory type may share each heap, and the heaps and memory types provide a mechanism to advertise an accurate size of the physical memory resources while allowing the memory to be used with a variety of different properties.
The number of memory heaps is given by memoryHeapCount and is less than or equal to MAX_MEMORY_HEAPS. Each heap is described by an element of the memoryHeaps array as a VkMemoryHeap structure. The number of memory types available across all memory heaps is given by memoryTypeCount and is less than or equal to MAX_MEMORY_TYPES. Each memory type is described by an element of the memoryTypes array as a VkMemoryType structure.
At least one heap must include MEMORY_HEAP_DEVICE_LOCAL_BIT in VkMemoryHeap::flags. If there are multiple heaps that all have similar performance characteristics, they may all include MEMORY_HEAP_DEVICE_LOCAL_BIT. In a unified memory architecture (UMA) system there is often only a single memory heap which is considered to be equally “local” to the host and to the device, and such an implementation must advertise the heap as device-local.
Each memory type returned by GetPhysicalDeviceMemoryProperties must have its propertyFlags set to one of the following values:
MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BITMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BITMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BITMEMORY_PROPERTY_DEVICE_LOCAL_BITMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BITMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BITMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BITMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_LAZILY_ALLOCATED_BITMEMORY_PROPERTY_PROTECTED_BITMEMORY_PROPERTY_PROTECTED_BIT | MEMORY_PROPERTY_DEVICE_LOCAL_BITMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDMEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_CACHED_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT | MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDMEMORY_PROPERTY_DEVICE_LOCAL_BIT | MEMORY_PROPERTY_RDMA_CAPABLE_BIT_NVThere must be at least one memory type with both the MEMORY_PROPERTY_HOST_VISIBLE_BIT and MEMORY_PROPERTY_HOST_COHERENT_BIT bits set in its propertyFlags. There must be at least one memory type with the MEMORY_PROPERTY_DEVICE_LOCAL_BIT bit set in its propertyFlags. If the deviceCoherentMemory feature is enabled, there must be at least one memory type with the MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD bit set in its propertyFlags.
For each pair of elements X and Y returned in memoryTypes, X must be placed at a lower index position than Y if:
propertyFlags member of X is a strict subset of the set of bit flags returned in the propertyFlags member of Y; orpropertyFlags members of X and Y are equal, and X belongs to a memory heap with greater performance (as determined in an implementation-specific manner) ; orpropertyFlags members of Y includes MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD or MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD and X does notThere is no ordering requirement between X and Y elements for the case their propertyFlags members are not in a subset relation. That potentially allows more than one possible way to order the same set of memory types. Notice that the list of all allowed memory property flag combinations is written in a valid order. But if instead MEMORY_PROPERTY_DEVICE_LOCAL_BIT was before MEMORY_PROPERTY_HOST_VISIBLE_BIT | MEMORY_PROPERTY_HOST_COHERENT_BIT, the list would still be in a valid order.
There may be a performance penalty for using device coherent or uncached device memory types, and using these accidentally is undesirable. In order to avoid this, memory types with these properties always appear at the end of the list; but are subject to the same rules otherwise.
This ordering requirement enables applications to use a simple search loop to select the desired memory type along the lines of:
// Find a memory in `memoryTypeBitsRequirement` that includes all of `requiredProperties`
int32_t findProperties(const VkPhysicalDeviceMemoryProperties* pMemoryProperties,
uint32_t memoryTypeBitsRequirement,
VkMemoryPropertyFlags requiredProperties) {
const uint32_t memoryCount = pMemoryProperties->memoryTypeCount;
for (uint32_t memoryIndex = 0; memoryIndex < memoryCount; ++memoryIndex) {
const uint32_t memoryTypeBits = (1 << memoryIndex);
const bool isRequiredMemoryType = memoryTypeBitsRequirement & memoryTypeBits;
const VkMemoryPropertyFlags properties =
pMemoryProperties->memoryTypes[memoryIndex].propertyFlags;
const bool hasRequiredProperties =
(properties & requiredProperties) == requiredProperties;
if (isRequiredMemoryType && hasRequiredProperties)
return static_cast<int32_t>(memoryIndex);
}
// failed to find memory type
return -1;
}
// Try to find an optimal memory type, or if it does not exist try fallback memory type
// `device` is the VkDevice
// `image` is the VkImage that requires memory to be bound
// `memoryProperties` properties as returned by vkGetPhysicalDeviceMemoryProperties
// `requiredProperties` are the property flags that must be present
// `optimalProperties` are the property flags that are preferred by the application
VkMemoryRequirements memoryRequirements;
vkGetImageMemoryRequirements(device, image, &memoryRequirements);
int32_t memoryType =
findProperties(&memoryProperties, memoryRequirements.memoryTypeBits, optimalProperties);
if (memoryType == -1) // not found; try fallback properties
memoryType =
findProperties(&memoryProperties, memoryRequirements.memoryTypeBits, requiredProperties);
VkMemoryHeap, VkMemoryType, VkPhysicalDeviceMemoryProperties2, GetPhysicalDeviceMemoryProperties
struct VkPhysicalDeviceMemoryProperties {
uint32_t memoryTypeCount;
VkMemoryType memoryTypes[VK_MAX_MEMORY_TYPES];
uint32_t memoryHeapCount;
VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS];
}
| Modifier and Type | Class and Description |
|---|---|
| public static class | VkPhysicalDeviceMemoryProperties.
An array of |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | ALIGNOF
The struct alignment in bytes. |
| public static final int | MEMORYHEAPCOUNT
The struct member offsets. |
| public static final int | MEMORYHEAPS
The struct member offsets. |
| public static final int | MEMORYTYPECOUNT
The struct member offsets. |
| public static final int | MEMORYTYPES
The struct member offsets. |
| public static final int | SIZEOF
The struct size in bytes. |
| Access | Constructor and Description |
|---|---|
| protected | |
| public | VkPhysicalDeviceMemoryProperties(ByteBuffer container)
Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties. | calloc(int
the buffer capacity capacity)Returns a new |
| public static VkPhysicalDeviceMemoryProperties | calloc(MemoryStack
the stack from which to allocate stack)Returns a new |
| public static VkPhysicalDeviceMemoryProperties. | calloc(int
the buffer capacity capacity, MemoryStack the stack from which to allocate stack)Returns a new |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties. | |
| public static VkPhysicalDeviceMemoryProperties. | |
| protected VkPhysicalDeviceMemoryProperties | create(long
the struct memory address address, ByteBuffer an optional container buffer, to be referenced strongly by the struct instance. container)Implements abstract org. the constructor, but returns the exact type of the Struct subclass.
|
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties | create(long address)
Returns a new |
| public static VkPhysicalDeviceMemoryProperties. | create(int
the buffer capacity capacity)Returns a new |
| public static VkPhysicalDeviceMemoryProperties. | create(long
the memory address address, int the buffer capacity capacity)Create a |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties. | |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties. | malloc(int
the buffer capacity capacity)Returns a new |
| public static VkPhysicalDeviceMemoryProperties | malloc(MemoryStack
the stack from which to allocate stack)Returns a new |
| public static VkPhysicalDeviceMemoryProperties. | malloc(int
the buffer capacity capacity, MemoryStack the stack from which to allocate stack)Returns a new |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties | |
| public static VkPhysicalDeviceMemoryProperties. | |
| public static VkPhysicalDeviceMemoryProperties. | |
| public int | |
| public VkMemoryHeap. | memoryHeaps()
an array of |
| public VkMemoryHeap | memoryHeaps(int index)
an array of |
| public int | |
| public VkMemoryType. | memoryTypes()
an array of |
| public VkMemoryType | memoryTypes(int index)
an array of |
| public static int | |
| public static VkMemoryHeap. | |
| public static VkMemoryHeap | |
| public static int | |
| public static VkMemoryType. | |
| public static VkMemoryType | |
| public int |
| ALIGNOF | back to summary |
|---|---|
| public static final int ALIGNOF The struct alignment in bytes. | |
| MEMORYHEAPCOUNT | back to summary |
|---|---|
| public static final int MEMORYHEAPCOUNT The struct member offsets. | |
| MEMORYHEAPS | back to summary |
|---|---|
| public static final int MEMORYHEAPS The struct member offsets. | |
| MEMORYTYPECOUNT | back to summary |
|---|---|
| public static final int MEMORYTYPECOUNT The struct member offsets. | |
| MEMORYTYPES | back to summary |
|---|---|
| public static final int MEMORYTYPES The struct member offsets. | |
| SIZEOF | back to summary |
|---|---|
| public static final int SIZEOF The struct size in bytes. | |
| VkPhysicalDeviceMemoryProperties | back to summary |
|---|---|
| protected VkPhysicalDeviceMemoryProperties(long address, ByteBuffer container) | |
| VkPhysicalDeviceMemoryProperties | back to summary |
|---|---|
| public VkPhysicalDeviceMemoryProperties(ByteBuffer container) Creates a The created instance holds a strong reference to the container object. | |
| calloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties calloc() Returns a new | |
| calloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Returns a new
| |
| calloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties calloc(MemoryStack stack) Returns a new
| |
| calloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Returns a new
| |
| callocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties callocStack()
Deprecated
Deprecated for removal in 3.4.0. Use
| |
| callocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties callocStack(MemoryStack stack)
Deprecated
Deprecated for removal in 3.4.0. Use
| |
| callocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Deprecated
Deprecated for removal in 3.4.0. Use
| |
| callocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Deprecated
Deprecated for removal in 3.4.0. Use
| |
| create | back to summary |
|---|---|
| protected VkPhysicalDeviceMemoryProperties create(long address, ByteBuffer container) Implements abstract org. Doc from org. Similar to Effectively, every
| |
| create | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties create() Returns a new | |
| create | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties create(long address) Returns a new | |
| create | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Returns a new
| |
| create | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Create a
| |
| createSafe | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties createSafe(long address) Like
| |
| createSafe | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Like
| |
| malloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties malloc() Returns a new | |
| malloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Returns a new
| |
| malloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties malloc(MemoryStack stack) Returns a new
| |
| malloc | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Returns a new
| |
| mallocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties mallocStack()
Deprecated
Deprecated for removal in 3.4.0. Use
| |
| mallocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties mallocStack(MemoryStack stack)
Deprecated
Deprecated for removal in 3.4.0. Use
| |
| mallocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Deprecated
Deprecated for removal in 3.4.0. Use
| |
| mallocStack | back to summary |
|---|---|
| public static VkPhysicalDeviceMemoryProperties. Deprecated
Deprecated for removal in 3.4.0. Use
| |
| memoryHeapCount | back to summary |
|---|---|
| public int memoryHeapCount() the number of valid elements in the
| |
| memoryHeaps | back to summary |
|---|---|
| public VkMemoryHeap. an array of
| |
| memoryHeaps | back to summary |
|---|---|
| public VkMemoryHeap memoryHeaps(int index) an array of | |
| memoryTypeCount | back to summary |
|---|---|
| public int memoryTypeCount() the number of valid elements in the
| |
| memoryTypes | back to summary |
|---|---|
| public VkMemoryType. an array of
| |
| memoryTypes | back to summary |
|---|---|
| public VkMemoryType memoryTypes(int index) an array of | |
| nmemoryHeapCount | back to summary |
|---|---|
| public static int nmemoryHeapCount(long struct) Unsafe version of | |
| nmemoryHeaps | back to summary |
|---|---|
| public static VkMemoryHeap. Unsafe version of | |
| nmemoryHeaps | back to summary |
|---|---|
| public static VkMemoryHeap nmemoryHeaps(long struct, int index) Unsafe version of | |
| nmemoryTypeCount | back to summary |
|---|---|
| public static int nmemoryTypeCount(long struct) Unsafe version of | |
| nmemoryTypes | back to summary |
|---|---|
| public static VkMemoryType. Unsafe version of | |
| nmemoryTypes | back to summary |
|---|---|
| public static VkMemoryType nmemoryTypes(long struct, int index) Unsafe version of | |
| sizeof | back to summary |
|---|---|
| public int sizeof() Implements abstract org. Doc from org. Returns
| |
VkPhysicalDeviceMemoryProperties structs.
| Modifier and Type | Field and Description |
|---|---|
| private static final VkPhysicalDeviceMemoryProperties |
| Access | Constructor and Description |
|---|---|
| public | Buffer(ByteBuffer container)
Creates a new |
| public | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected VkPhysicalDeviceMemoryProperties | |
| public int | |
| public VkMemoryHeap. | |
| public VkMemoryHeap | Returns: aVkMemoryHeap view of the struct at the specified index of the VkPhysicalDeviceMemoryProperties#memoryHeaps field.
|
| public int | |
| public VkMemoryType. | |
| public VkMemoryType | Returns: aVkMemoryType view of the struct at the specified index of the VkPhysicalDeviceMemoryProperties#memoryTypes field.
|
| protected VkPhysicalDeviceMemoryProperties. |
| ELEMENT_FACTORY | back to summary |
|---|---|
| private static final VkPhysicalDeviceMemoryProperties ELEMENT_FACTORY | |
| Buffer | back to summary |
|---|---|
| public Buffer(ByteBuffer container) Creates a new Changes to the container's content will be visible to the struct buffer instance and vice versa. The two buffers' position, limit, and mark values
will be independent. The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided
by The created buffer instance holds a strong reference to the container object. | |
| Buffer | back to summary |
|---|---|
| public Buffer(long address, int cap) | |
| Buffer | back to summary |
|---|---|
| pack-priv Buffer(long address, ByteBuffer container, int mark, int pos, int lim, int cap) | |
| getElementFactory | back to summary |
|---|---|
| protected VkPhysicalDeviceMemoryProperties getElementFactory() Implements abstract org.
| |
| memoryHeapCount | back to summary |
|---|---|
public int memoryHeapCount()
| |
| memoryHeaps | back to summary |
|---|---|
public VkMemoryHeap.
| |
| memoryHeaps | back to summary |
|---|---|
public VkMemoryHeap memoryHeaps(int index)
| |
| memoryTypeCount | back to summary |
|---|---|
public int memoryTypeCount()
| |
| memoryTypes | back to summary |
|---|---|
public VkMemoryType.
| |
| memoryTypes | back to summary |
|---|---|
public VkMemoryType memoryTypes(int index)
| |
| self | back to summary |
|---|---|
| protected VkPhysicalDeviceMemoryProperties. Implements abstract org.
| |