Class VkPhysicalDeviceMemoryProperties
- java.lang.Object
-
- org.lwjgl.system.Pointer.Default
-
- org.lwjgl.system.Struct
-
- org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,org.lwjgl.system.NativeResource
,org.lwjgl.system.Pointer
public class VkPhysicalDeviceMemoryProperties extends org.lwjgl.system.Struct implements org.lwjgl.system.NativeResource
Structure specifying physical device memory properties.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 toMAX_MEMORY_HEAPS
. Each heap is described by an element of thememoryHeaps
array as aVkMemoryHeap
structure. The number of memory types available across all memory heaps is given bymemoryTypeCount
and is less than or equal toMAX_MEMORY_TYPES
. Each memory type is described by an element of thememoryTypes
array as aVkMemoryType
structure.At least one heap must include
MEMORY_HEAP_DEVICE_LOCAL_BIT
inVkMemoryHeap
::flags
. If there are multiple heaps that all have similar performance characteristics, they may all includeMEMORY_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 itspropertyFlags
set to one of the following values:- 0
MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_CACHED_BIT
MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_CACHED_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_CACHED_BIT
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_CACHED_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT
MEMORY_PROPERTY_PROTECTED_BIT
MEMORY_PROPERTY_PROTECTED_BIT
|MEMORY_PROPERTY_DEVICE_LOCAL_BIT
MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_CACHED_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
MEMORY_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_HOST_VISIBLE_BIT
|MEMORY_PROPERTY_HOST_COHERENT_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
|MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD
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_AMD
MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
|MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD
MEMORY_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_AMD
MEMORY_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_AMD
There must be at least one memory type with both the
MEMORY_PROPERTY_HOST_VISIBLE_BIT
andMEMORY_PROPERTY_HOST_COHERENT_BIT
bits set in itspropertyFlags
. There must be at least one memory type with theMEMORY_PROPERTY_DEVICE_LOCAL_BIT
bit set in itspropertyFlags
. If thedeviceCoherentMemory
feature is enabled, there must be at least one memory type with theMEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
bit set in itspropertyFlags
.For each pair of elements X and Y returned in
memoryTypes
, X must be placed at a lower index position than Y if:- either the set of bit flags returned in the
propertyFlags
member of X is a strict subset of the set of bit flags returned in thepropertyFlags
member of Y; or - the
propertyFlags
members of X and Y are equal, and X belongs to a memory heap with greater performance (as determined in an implementation-specific manner) ; or - or the
propertyFlags
members of X includesMEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD
orMEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD
and Y 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 insteadMEMORY_PROPERTY_DEVICE_LOCAL_BIT
was beforeMEMORY_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
Member documentation
memoryTypeCount
– the number of valid elements in thememoryTypes
array.memoryTypes[VK_MAX_MEMORY_TYPES]
– an array ofVkMemoryType
structures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps
.memoryHeapCount
– the number of valid elements in thememoryHeaps
array.memoryHeaps[VK_MAX_MEMORY_HEAPS]
– an array ofVkMemoryHeap
structures describing the memory heaps from which memory can be allocated.
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 Classes Modifier and Type Class Description static class
VkPhysicalDeviceMemoryProperties.Buffer
An array ofVkPhysicalDeviceMemoryProperties
structs.
-
Field Summary
Fields Modifier and Type Field Description static int
ALIGNOF
The struct alignment in bytes.static int
MEMORYHEAPCOUNT
MEMORYHEAPS
MEMORYTYPECOUNT
MEMORYTYPESThe struct member offsets.static int
SIZEOF
The struct size in bytes.
-
Constructor Summary
Constructors Constructor Description VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)
Creates aVkPhysicalDeviceMemoryProperties
instance at the current position of the specifiedByteBuffer
container.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static VkPhysicalDeviceMemoryProperties
calloc()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withmemCalloc
.static VkPhysicalDeviceMemoryProperties.Buffer
calloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withmemCalloc
.static VkPhysicalDeviceMemoryProperties
callocStack()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the thread-localMemoryStack
and initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties.Buffer
callocStack(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the thread-localMemoryStack
and initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties.Buffer
callocStack(int capacity, org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties
callocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties
create()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withBufferUtils
.static VkPhysicalDeviceMemoryProperties.Buffer
create(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withBufferUtils
.static VkPhysicalDeviceMemoryProperties
create(long address)
Returns a newVkPhysicalDeviceMemoryProperties
instance for the specified memory address.static VkPhysicalDeviceMemoryProperties.Buffer
create(long address, int capacity)
Create aVkPhysicalDeviceMemoryProperties.Buffer
instance at the specified memory.static VkPhysicalDeviceMemoryProperties
createSafe(long address)
static VkPhysicalDeviceMemoryProperties.Buffer
createSafe(long address, int capacity)
static VkPhysicalDeviceMemoryProperties
malloc()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withmemAlloc
.static VkPhysicalDeviceMemoryProperties.Buffer
malloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withmemAlloc
.static VkPhysicalDeviceMemoryProperties
mallocStack()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the thread-localMemoryStack
.static VkPhysicalDeviceMemoryProperties.Buffer
mallocStack(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the thread-localMemoryStack
.static VkPhysicalDeviceMemoryProperties.Buffer
mallocStack(int capacity, org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the specifiedMemoryStack
.static VkPhysicalDeviceMemoryProperties
mallocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the specifiedMemoryStack
.int
memoryHeapCount()
Returns the value of thememoryHeapCount
field.VkMemoryHeap.Buffer
memoryHeaps()
Returns aVkMemoryHeap
.Buffer view of thememoryHeaps
field.VkMemoryHeap
memoryHeaps(int index)
Returns aVkMemoryHeap
view of the struct at the specified index of thememoryHeaps
field.int
memoryTypeCount()
Returns the value of thememoryTypeCount
field.VkMemoryType.Buffer
memoryTypes()
Returns aVkMemoryType
.Buffer view of thememoryTypes
field.VkMemoryType
memoryTypes(int index)
Returns aVkMemoryType
view of the struct at the specified index of thememoryTypes
field.static int
nmemoryHeapCount(long struct)
Unsafe version ofmemoryHeapCount()
.static VkMemoryHeap.Buffer
nmemoryHeaps(long struct)
Unsafe version ofmemoryHeaps()
.static VkMemoryHeap
nmemoryHeaps(long struct, int index)
Unsafe version ofmemoryHeaps
.static int
nmemoryTypeCount(long struct)
Unsafe version ofmemoryTypeCount()
.static VkMemoryType.Buffer
nmemoryTypes(long struct)
Unsafe version ofmemoryTypes()
.static VkMemoryType
nmemoryTypes(long struct, int index)
Unsafe version ofmemoryTypes
.int
sizeof()
-
-
-
Constructor Detail
-
VkPhysicalDeviceMemoryProperties
public VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)
Creates aVkPhysicalDeviceMemoryProperties
instance at the current position of the specifiedByteBuffer
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.
-
-
Method Detail
-
sizeof
public int sizeof()
- Specified by:
sizeof
in classorg.lwjgl.system.Struct
-
memoryTypeCount
public int memoryTypeCount()
Returns the value of thememoryTypeCount
field.
-
memoryTypes
public VkMemoryType.Buffer memoryTypes()
Returns aVkMemoryType
.Buffer view of thememoryTypes
field.
-
memoryTypes
public VkMemoryType memoryTypes(int index)
Returns aVkMemoryType
view of the struct at the specified index of thememoryTypes
field.
-
memoryHeapCount
public int memoryHeapCount()
Returns the value of thememoryHeapCount
field.
-
memoryHeaps
public VkMemoryHeap.Buffer memoryHeaps()
Returns aVkMemoryHeap
.Buffer view of thememoryHeaps
field.
-
memoryHeaps
public VkMemoryHeap memoryHeaps(int index)
Returns aVkMemoryHeap
view of the struct at the specified index of thememoryHeaps
field.
-
malloc
public static VkPhysicalDeviceMemoryProperties malloc()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withmemAlloc
. The instance must be explicitly freed.
-
calloc
public static VkPhysicalDeviceMemoryProperties calloc()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withmemCalloc
. The instance must be explicitly freed.
-
create
public static VkPhysicalDeviceMemoryProperties create()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated withBufferUtils
.
-
create
public static VkPhysicalDeviceMemoryProperties create(long address)
Returns a newVkPhysicalDeviceMemoryProperties
instance for the specified memory address.
-
createSafe
@Nullable public static VkPhysicalDeviceMemoryProperties createSafe(long address)
-
malloc
public static VkPhysicalDeviceMemoryProperties.Buffer malloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withmemAlloc
. The instance must be explicitly freed.- Parameters:
capacity
- the buffer capacity
-
calloc
public static VkPhysicalDeviceMemoryProperties.Buffer calloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withmemCalloc
. The instance must be explicitly freed.- Parameters:
capacity
- the buffer capacity
-
create
public static VkPhysicalDeviceMemoryProperties.Buffer create(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated withBufferUtils
.- Parameters:
capacity
- the buffer capacity
-
create
public static VkPhysicalDeviceMemoryProperties.Buffer create(long address, int capacity)
Create aVkPhysicalDeviceMemoryProperties.Buffer
instance at the specified memory.- Parameters:
address
- the memory addresscapacity
- the buffer capacity
-
createSafe
@Nullable public static VkPhysicalDeviceMemoryProperties.Buffer createSafe(long address, int capacity)
-
mallocStack
public static VkPhysicalDeviceMemoryProperties mallocStack()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the thread-localMemoryStack
.
-
callocStack
public static VkPhysicalDeviceMemoryProperties callocStack()
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the thread-localMemoryStack
and initializes all its bits to zero.
-
mallocStack
public static VkPhysicalDeviceMemoryProperties mallocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the specifiedMemoryStack
.- Parameters:
stack
- the stack from which to allocate
-
callocStack
public static VkPhysicalDeviceMemoryProperties callocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.- Parameters:
stack
- the stack from which to allocate
-
mallocStack
public static VkPhysicalDeviceMemoryProperties.Buffer mallocStack(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the thread-localMemoryStack
.- Parameters:
capacity
- the buffer capacity
-
callocStack
public static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the thread-localMemoryStack
and initializes all its bits to zero.- Parameters:
capacity
- the buffer capacity
-
mallocStack
public static VkPhysicalDeviceMemoryProperties.Buffer mallocStack(int capacity, org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the specifiedMemoryStack
.- Parameters:
stack
- the stack from which to allocatecapacity
- the buffer capacity
-
callocStack
public static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity, org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryProperties.Buffer
instance allocated on the specifiedMemoryStack
and initializes all its bits to zero.- Parameters:
stack
- the stack from which to allocatecapacity
- the buffer capacity
-
nmemoryTypeCount
public static int nmemoryTypeCount(long struct)
Unsafe version ofmemoryTypeCount()
.
-
nmemoryTypes
public static VkMemoryType.Buffer nmemoryTypes(long struct)
Unsafe version ofmemoryTypes()
.
-
nmemoryTypes
public static VkMemoryType nmemoryTypes(long struct, int index)
Unsafe version ofmemoryTypes
.
-
nmemoryHeapCount
public static int nmemoryHeapCount(long struct)
Unsafe version ofmemoryHeapCount()
.
-
nmemoryHeaps
public static VkMemoryHeap.Buffer nmemoryHeaps(long struct)
Unsafe version ofmemoryHeaps()
.
-
nmemoryHeaps
public static VkMemoryHeap nmemoryHeaps(long struct, int index)
Unsafe version ofmemoryHeaps
.
-
-