public class VkPhysicalDeviceMemoryProperties
extends org.lwjgl.system.Struct
implements org.lwjgl.system.NativeResource
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_AMDThere 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 X includes MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD or MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD and Y 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
memoryTypeCount – the number of valid elements in the memoryTypes array.memoryTypes[VK_MAX_MEMORY_TYPES] – an array of MAX_MEMORY_TYPES VkMemoryType structures describing the memory types that can be used to access memory allocated from the heaps specified by memoryHeaps.memoryHeapCount – the number of valid elements in the memoryHeaps array.memoryHeaps[VK_MAX_MEMORY_HEAPS] – an array of MAX_MEMORY_HEAPS VkMemoryHeap structures describing the memory heaps from which memory can be allocated.
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 |
|---|---|
static class |
VkPhysicalDeviceMemoryProperties.Buffer
An array of
VkPhysicalDeviceMemoryProperties structs. |
| Modifier and Type | Field and Description |
|---|---|
static int |
ALIGNOF
The struct alignment in bytes.
|
static int |
MEMORYHEAPCOUNT
The struct member offsets.
|
static int |
MEMORYHEAPS
The struct member offsets.
|
static int |
MEMORYTYPECOUNT
The struct member offsets.
|
static int |
MEMORYTYPES
The struct member offsets.
|
static int |
SIZEOF
The struct size in bytes.
|
| Constructor and Description |
|---|
VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)
Creates a
VkPhysicalDeviceMemoryProperties instance at the current position of the specified ByteBuffer container. |
| Modifier and Type | Method and Description |
|---|---|
static VkPhysicalDeviceMemoryProperties |
calloc()
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated with memCalloc. |
static VkPhysicalDeviceMemoryProperties.Buffer |
calloc(int capacity)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with memCalloc. |
static VkPhysicalDeviceMemoryProperties |
callocStack()
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated on the thread-local MemoryStack and initializes all its bits to zero. |
static VkPhysicalDeviceMemoryProperties.Buffer |
callocStack(int capacity)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the thread-local MemoryStack and initializes all its bits to zero. |
static VkPhysicalDeviceMemoryProperties.Buffer |
callocStack(int capacity,
org.lwjgl.system.MemoryStack stack)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero. |
static VkPhysicalDeviceMemoryProperties |
callocStack(org.lwjgl.system.MemoryStack stack)
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated on the specified MemoryStack and initializes all its bits to zero. |
static VkPhysicalDeviceMemoryProperties |
create()
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated with BufferUtils. |
static VkPhysicalDeviceMemoryProperties.Buffer |
create(int capacity)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with BufferUtils. |
static VkPhysicalDeviceMemoryProperties |
create(long address)
Returns a new
VkPhysicalDeviceMemoryProperties instance for the specified memory address. |
static VkPhysicalDeviceMemoryProperties.Buffer |
create(long address,
int capacity)
Create a
VkPhysicalDeviceMemoryProperties.Buffer instance at the specified memory. |
static VkPhysicalDeviceMemoryProperties |
createSafe(long address)
|
static VkPhysicalDeviceMemoryProperties.Buffer |
createSafe(long address,
int capacity)
|
static VkPhysicalDeviceMemoryProperties |
malloc()
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated with memAlloc. |
static VkPhysicalDeviceMemoryProperties.Buffer |
malloc(int capacity)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with memAlloc. |
static VkPhysicalDeviceMemoryProperties |
mallocStack()
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated on the thread-local MemoryStack. |
static VkPhysicalDeviceMemoryProperties.Buffer |
mallocStack(int capacity)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the thread-local MemoryStack. |
static VkPhysicalDeviceMemoryProperties.Buffer |
mallocStack(int capacity,
org.lwjgl.system.MemoryStack stack)
Returns a new
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the specified MemoryStack. |
static VkPhysicalDeviceMemoryProperties |
mallocStack(org.lwjgl.system.MemoryStack stack)
Returns a new
VkPhysicalDeviceMemoryProperties instance allocated on the specified MemoryStack. |
int |
memoryHeapCount()
Returns the value of the
memoryHeapCount field. |
VkMemoryHeap.Buffer |
memoryHeaps()
Returns a
VkMemoryHeap.Buffer view of the memoryHeaps field. |
VkMemoryHeap |
memoryHeaps(int index)
Returns a
VkMemoryHeap view of the struct at the specified index of the memoryHeaps field. |
int |
memoryTypeCount()
Returns the value of the
memoryTypeCount field. |
VkMemoryType.Buffer |
memoryTypes()
Returns a
VkMemoryType.Buffer view of the memoryTypes field. |
VkMemoryType |
memoryTypes(int index)
Returns a
VkMemoryType view of the struct at the specified index of the memoryTypes field. |
static int |
nmemoryHeapCount(long struct)
Unsafe version of
memoryHeapCount(). |
static VkMemoryHeap.Buffer |
nmemoryHeaps(long struct)
Unsafe version of
memoryHeaps(). |
static VkMemoryHeap |
nmemoryHeaps(long struct,
int index)
Unsafe version of
memoryHeaps. |
static int |
nmemoryTypeCount(long struct)
Unsafe version of
memoryTypeCount(). |
static VkMemoryType.Buffer |
nmemoryTypes(long struct)
Unsafe version of
memoryTypes(). |
static VkMemoryType |
nmemoryTypes(long struct,
int index)
Unsafe version of
memoryTypes. |
int |
sizeof() |
public static final int SIZEOF
public static final int ALIGNOF
public static final int MEMORYTYPECOUNT
public static final int MEMORYTYPES
public static final int MEMORYHEAPCOUNT
public static final int MEMORYHEAPS
public VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)
VkPhysicalDeviceMemoryProperties instance at the current position of the specified ByteBuffer container. 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.
public int sizeof()
sizeof in class org.lwjgl.system.Structpublic int memoryTypeCount()
memoryTypeCount field.public VkMemoryType.Buffer memoryTypes()
VkMemoryType.Buffer view of the memoryTypes field.public VkMemoryType memoryTypes(int index)
VkMemoryType view of the struct at the specified index of the memoryTypes field.public int memoryHeapCount()
memoryHeapCount field.public VkMemoryHeap.Buffer memoryHeaps()
VkMemoryHeap.Buffer view of the memoryHeaps field.public VkMemoryHeap memoryHeaps(int index)
VkMemoryHeap view of the struct at the specified index of the memoryHeaps field.public static VkPhysicalDeviceMemoryProperties malloc()
VkPhysicalDeviceMemoryProperties instance allocated with memAlloc. The instance must be explicitly freed.public static VkPhysicalDeviceMemoryProperties calloc()
VkPhysicalDeviceMemoryProperties instance allocated with memCalloc. The instance must be explicitly freed.public static VkPhysicalDeviceMemoryProperties create()
VkPhysicalDeviceMemoryProperties instance allocated with BufferUtils.public static VkPhysicalDeviceMemoryProperties create(long address)
VkPhysicalDeviceMemoryProperties instance for the specified memory address.@Nullable public static VkPhysicalDeviceMemoryProperties createSafe(long address)
public static VkPhysicalDeviceMemoryProperties.Buffer malloc(int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with memAlloc. The instance must be explicitly freed.capacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer calloc(int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with memCalloc. The instance must be explicitly freed.capacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer create(int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated with BufferUtils.capacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer create(long address, int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance at the specified memory.address - the memory addresscapacity - the buffer capacity@Nullable public static VkPhysicalDeviceMemoryProperties.Buffer createSafe(long address, int capacity)
public static VkPhysicalDeviceMemoryProperties mallocStack()
VkPhysicalDeviceMemoryProperties instance allocated on the thread-local MemoryStack.public static VkPhysicalDeviceMemoryProperties callocStack()
VkPhysicalDeviceMemoryProperties instance allocated on the thread-local MemoryStack and initializes all its bits to zero.public static VkPhysicalDeviceMemoryProperties mallocStack(org.lwjgl.system.MemoryStack stack)
VkPhysicalDeviceMemoryProperties instance allocated on the specified MemoryStack.stack - the stack from which to allocatepublic static VkPhysicalDeviceMemoryProperties callocStack(org.lwjgl.system.MemoryStack stack)
VkPhysicalDeviceMemoryProperties instance allocated on the specified MemoryStack and initializes all its bits to zero.stack - the stack from which to allocatepublic static VkPhysicalDeviceMemoryProperties.Buffer mallocStack(int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the thread-local MemoryStack.capacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the thread-local MemoryStack and initializes all its bits to zero.capacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer mallocStack(int capacity, org.lwjgl.system.MemoryStack stack)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the specified MemoryStack.stack - the stack from which to allocatecapacity - the buffer capacitypublic static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity, org.lwjgl.system.MemoryStack stack)
VkPhysicalDeviceMemoryProperties.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero.stack - the stack from which to allocatecapacity - the buffer capacitypublic static int nmemoryTypeCount(long struct)
memoryTypeCount().public static VkMemoryType.Buffer nmemoryTypes(long struct)
memoryTypes().public static VkMemoryType nmemoryTypes(long struct, int index)
memoryTypes.public static int nmemoryHeapCount(long struct)
memoryHeapCount().public static VkMemoryHeap.Buffer nmemoryHeaps(long struct)
memoryHeaps().public static VkMemoryHeap nmemoryHeaps(long struct, int index)
memoryHeaps.Copyright LWJGL. All Rights Reserved. License terms.