Class VkPhysicalDeviceMemoryProperties
- All Implemented Interfaces:
AutoCloseable,org.lwjgl.system.NativeResource,org.lwjgl.system.Pointer
Description
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:
- 0
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_NV
There 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:
- the set of bit flags returned in the
propertyFlagsmember of X is a strict subset of the set of bit flags returned in thepropertyFlagsmember of Y; or - the
propertyFlagsmembers of X and Y are equal, and X belongs to a memory heap with greater performance (as determined in an implementation-specific manner) ; or - the
propertyFlagsmembers of Y includesMEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDorMEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDand X does not
Note
There 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);
See Also
VkMemoryHeap, VkMemoryType, VkPhysicalDeviceMemoryProperties2, GetPhysicalDeviceMemoryProperties
Layout
struct VkPhysicalDeviceMemoryProperties {
uint32_t memoryTypeCount();
VkMemoryType memoryTypes()[VK_MAX_MEMORY_TYPES];
uint32_t memoryHeapCount();
VkMemoryHeap memoryHeaps()[VK_MAX_MEMORY_HEAPS];
}-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn array ofVkPhysicalDeviceMemoryPropertiesstructs.Nested classes/interfaces inherited from class org.lwjgl.system.Struct
org.lwjgl.system.Struct.StructValidationNested classes/interfaces inherited from interface org.lwjgl.system.Pointer
org.lwjgl.system.Pointer.Default -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe struct alignment in bytes.static final intThe struct member offsets.static final intThe struct member offsets.static final intThe struct member offsets.static final intThe struct member offsets.static final intThe struct size in bytes.Fields inherited from interface org.lwjgl.system.Pointer
BITS32, BITS64, CLONG_SHIFT, CLONG_SIZE, POINTER_SHIFT, POINTER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionVkPhysicalDeviceMemoryProperties(ByteBuffer container) Creates aVkPhysicalDeviceMemoryPropertiesinstance at the current position of the specifiedByteBuffercontainer. -
Method Summary
Modifier and TypeMethodDescriptioncalloc()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemCalloc.calloc(int capacity) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemCalloc.calloc(int capacity, org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.calloc(org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.Deprecated.callocStack(int capacity) Deprecated.callocStack(int capacity, org.lwjgl.system.MemoryStack stack) Deprecated.callocStack(org.lwjgl.system.MemoryStack stack) Deprecated.create()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withBufferUtils.create(int capacity) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withBufferUtils.create(long address) Returns a newVkPhysicalDeviceMemoryPropertiesinstance for the specified memory address.create(long address, int capacity) Create aVkPhysicalDeviceMemoryProperties.Bufferinstance at the specified memory.static @Nullable VkPhysicalDeviceMemoryPropertiescreateSafe(long address) static @Nullable VkPhysicalDeviceMemoryProperties.BuffercreateSafe(long address, int capacity) malloc()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemAlloc.malloc(int capacity) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemAlloc.malloc(int capacity, org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStack.malloc(org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStack.Deprecated.mallocStack(int capacity) Deprecated.mallocStack(int capacity, org.lwjgl.system.MemoryStack stack) Deprecated.mallocStack(org.lwjgl.system.MemoryStack stack) Deprecated.intthe number of valid elements in thememoryHeapsarray.an array ofMAX_MEMORY_HEAPSVkMemoryHeapstructures describing the memory heaps from which memory can be allocated.memoryHeaps(int index) an array ofMAX_MEMORY_HEAPSVkMemoryHeapstructures describing the memory heaps from which memory can be allocated.intthe number of valid elements in thememoryTypesarray.an array ofMAX_MEMORY_TYPESVkMemoryTypestructures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps.memoryTypes(int index) an array ofMAX_MEMORY_TYPESVkMemoryTypestructures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps.static intnmemoryHeapCount(long struct) Unsafe version ofmemoryHeapCount().static VkMemoryHeap.BuffernmemoryHeaps(long struct) Unsafe version ofmemoryHeaps().static VkMemoryHeapnmemoryHeaps(long struct, int index) Unsafe version ofmemoryHeaps.static intnmemoryTypeCount(long struct) Unsafe version ofmemoryTypeCount().static VkMemoryType.BuffernmemoryTypes(long struct) Unsafe version ofmemoryTypes().static VkMemoryTypenmemoryTypes(long struct, int index) Unsafe version ofmemoryTypes.intsizeof()Methods inherited from class org.lwjgl.system.Struct
clear, free, isNull, validate, validateMethods inherited from class org.lwjgl.system.Pointer.Default
address, equals, hashCode, toStringMethods inherited from interface org.lwjgl.system.NativeResource
close, free
-
Field Details
-
SIZEOF
public static final int SIZEOFThe struct size in bytes. -
ALIGNOF
public static final int ALIGNOFThe struct alignment in bytes. -
MEMORYTYPECOUNT
public static final int MEMORYTYPECOUNTThe struct member offsets. -
MEMORYTYPES
public static final int MEMORYTYPESThe struct member offsets. -
MEMORYHEAPCOUNT
public static final int MEMORYHEAPCOUNTThe struct member offsets. -
MEMORYHEAPS
public static final int MEMORYHEAPSThe struct member offsets.
-
-
Constructor Details
-
VkPhysicalDeviceMemoryProperties
Creates aVkPhysicalDeviceMemoryPropertiesinstance at the current position of the specifiedByteBuffercontainer. Changes to the buffer's content will be visible to the struct instance and vice versa.The created instance holds a strong reference to the container object.
-
-
Method Details
-
sizeof
public int sizeof()- Specified by:
sizeofin classorg.lwjgl.system.Struct<VkPhysicalDeviceMemoryProperties>
-
memoryTypeCount
public int memoryTypeCount()the number of valid elements in thememoryTypesarray. -
memoryTypes
an array ofMAX_MEMORY_TYPESVkMemoryTypestructures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps. -
memoryTypes
an array ofMAX_MEMORY_TYPESVkMemoryTypestructures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps. -
memoryHeapCount
public int memoryHeapCount()the number of valid elements in thememoryHeapsarray. -
memoryHeaps
an array ofMAX_MEMORY_HEAPSVkMemoryHeapstructures describing the memory heaps from which memory can be allocated. -
memoryHeaps
an array ofMAX_MEMORY_HEAPSVkMemoryHeapstructures describing the memory heaps from which memory can be allocated. -
malloc
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemAlloc. The instance must be explicitly freed. -
calloc
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemCalloc. The instance must be explicitly freed. -
create
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withBufferUtils. -
create
Returns a newVkPhysicalDeviceMemoryPropertiesinstance for the specified memory address. -
createSafe
-
malloc
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemAlloc. The instance must be explicitly freed.- Parameters:
capacity- the buffer capacity
-
calloc
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemCalloc. The instance must be explicitly freed.- Parameters:
capacity- the buffer capacity
-
create
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withBufferUtils.- Parameters:
capacity- the buffer capacity
-
create
Create aVkPhysicalDeviceMemoryProperties.Bufferinstance at the specified memory.- Parameters:
address- the memory addresscapacity- the buffer capacity
-
createSafe
public static @Nullable VkPhysicalDeviceMemoryProperties.Buffer createSafe(long address, int capacity) -
mallocStack
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)instead. -
callocStack
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)instead. -
mallocStack
@Deprecated public static VkPhysicalDeviceMemoryProperties mallocStack(org.lwjgl.system.MemoryStack stack) Deprecated.Deprecated for removal in 3.4.0. Usemalloc(MemoryStack)instead. -
callocStack
@Deprecated public static VkPhysicalDeviceMemoryProperties callocStack(org.lwjgl.system.MemoryStack stack) Deprecated.Deprecated for removal in 3.4.0. Usecalloc(MemoryStack)instead. -
mallocStack
Deprecated.Deprecated for removal in 3.4.0. Usemalloc(int, MemoryStack)instead. -
callocStack
Deprecated.Deprecated for removal in 3.4.0. Usecalloc(int, MemoryStack)instead. -
mallocStack
@Deprecated public static VkPhysicalDeviceMemoryProperties.Buffer mallocStack(int capacity, org.lwjgl.system.MemoryStack stack) Deprecated.Deprecated for removal in 3.4.0. Usemalloc(int, MemoryStack)instead. -
callocStack
@Deprecated public static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity, org.lwjgl.system.MemoryStack stack) Deprecated.Deprecated for removal in 3.4.0. Usecalloc(int, MemoryStack)instead. -
malloc
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStack.- Parameters:
stack- the stack from which to allocate
-
calloc
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.- Parameters:
stack- the stack from which to allocate
-
malloc
public static VkPhysicalDeviceMemoryProperties.Buffer malloc(int capacity, org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStack.- Parameters:
capacity- the buffer capacitystack- the stack from which to allocate
-
calloc
public static VkPhysicalDeviceMemoryProperties.Buffer calloc(int capacity, org.lwjgl.system.MemoryStack stack) Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.- Parameters:
capacity- the buffer capacitystack- the stack from which to allocate
-
nmemoryTypeCount
public static int nmemoryTypeCount(long struct) Unsafe version ofmemoryTypeCount(). -
nmemoryTypes
Unsafe version ofmemoryTypes(). -
nmemoryTypes
Unsafe version ofmemoryTypes. -
nmemoryHeapCount
public static int nmemoryHeapCount(long struct) Unsafe version ofmemoryHeapCount(). -
nmemoryHeaps
Unsafe version ofmemoryHeaps(). -
nmemoryHeaps
Unsafe version ofmemoryHeaps.
-