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.NativeResourceStructure specifying physical device memory properties.Description
The
VkPhysicalDeviceMemoryPropertiesstructure 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
memoryHeapCountand is less than or equal toMAX_MEMORY_HEAPS. Each heap is described by an element of thememoryHeapsarray as aVkMemoryHeapstructure. The number of memory types available across all memory heaps is given bymemoryTypeCountand is less than or equal toMAX_MEMORY_TYPES. Each memory type is described by an element of thememoryTypesarray as aVkMemoryTypestructure.At least one heap must include
MEMORY_HEAP_DEVICE_LOCAL_BITinVkMemoryHeap::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
GetPhysicalDeviceMemoryPropertiesmust have itspropertyFlagsset 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_AMD
There must be at least one memory type with both the
MEMORY_PROPERTY_HOST_VISIBLE_BITandMEMORY_PROPERTY_HOST_COHERENT_BITbits set in itspropertyFlags. There must be at least one memory type with theMEMORY_PROPERTY_DEVICE_LOCAL_BITbit set in itspropertyFlags. If thedeviceCoherentMemoryfeature is enabled, there must be at least one memory type with theMEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDbit 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
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 - or the
propertyFlagsmembers of X includesMEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMDorMEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMDand Y does not
Note
There is no ordering requirement between X and Y elements for the case their
propertyFlagsmembers 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_BITwas 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,GetPhysicalDeviceMemoryPropertiesMember documentation
memoryTypeCount– the number of valid elements in thememoryTypesarray.memoryTypes[VK_MAX_MEMORY_TYPES]– an array ofVkMemoryTypestructures describing the memory types that can be used to access memory allocated from the heaps specified bymemoryHeaps.memoryHeapCount– the number of valid elements in thememoryHeapsarray.memoryHeaps[VK_MAX_MEMORY_HEAPS]– an array ofVkMemoryHeapstructures describing the memory heaps from which memory can be allocated.
Layout
struct VkPhysicalDeviceMemoryProperties { uint32_t memoryTypeCount;VkMemoryTypememoryTypes[VK_MAX_MEMORY_TYPES]; uint32_t memoryHeapCount;VkMemoryHeapmemoryHeaps[VK_MAX_MEMORY_HEAPS]; }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVkPhysicalDeviceMemoryProperties.BufferAn array ofVkPhysicalDeviceMemoryPropertiesstructs.
-
Field Summary
Fields Modifier and Type Field Description static intALIGNOFThe struct alignment in bytes.static intMEMORYHEAPCOUNT
MEMORYHEAPS
MEMORYTYPECOUNT
MEMORYTYPESThe struct member offsets.static intSIZEOFThe struct size in bytes.
-
Constructor Summary
Constructors Constructor Description VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)Creates aVkPhysicalDeviceMemoryPropertiesinstance at the current position of the specifiedByteBuffercontainer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static VkPhysicalDeviceMemoryPropertiescalloc()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemCalloc.static VkPhysicalDeviceMemoryProperties.Buffercalloc(int capacity)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemCalloc.static VkPhysicalDeviceMemoryPropertiescallocStack()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the thread-localMemoryStackand initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties.BuffercallocStack(int capacity)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the thread-localMemoryStackand initializes all its bits to zero.static VkPhysicalDeviceMemoryProperties.BuffercallocStack(int capacity, org.lwjgl.system.MemoryStack stack)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.static VkPhysicalDeviceMemoryPropertiescallocStack(org.lwjgl.system.MemoryStack stack)Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStackand initializes all its bits to zero.static VkPhysicalDeviceMemoryPropertiescreate()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withBufferUtils.static VkPhysicalDeviceMemoryProperties.Buffercreate(int capacity)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withBufferUtils.static VkPhysicalDeviceMemoryPropertiescreate(long address)Returns a newVkPhysicalDeviceMemoryPropertiesinstance for the specified memory address.static VkPhysicalDeviceMemoryProperties.Buffercreate(long address, int capacity)Create aVkPhysicalDeviceMemoryProperties.Bufferinstance at the specified memory.static VkPhysicalDeviceMemoryPropertiescreateSafe(long address)static VkPhysicalDeviceMemoryProperties.BuffercreateSafe(long address, int capacity)static VkPhysicalDeviceMemoryPropertiesmalloc()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemAlloc.static VkPhysicalDeviceMemoryProperties.Buffermalloc(int capacity)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemAlloc.static VkPhysicalDeviceMemoryPropertiesmallocStack()Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the thread-localMemoryStack.static VkPhysicalDeviceMemoryProperties.BuffermallocStack(int capacity)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the thread-localMemoryStack.static VkPhysicalDeviceMemoryProperties.BuffermallocStack(int capacity, org.lwjgl.system.MemoryStack stack)Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the specifiedMemoryStack.static VkPhysicalDeviceMemoryPropertiesmallocStack(org.lwjgl.system.MemoryStack stack)Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStack.intmemoryHeapCount()Returns the value of thememoryHeapCountfield.VkMemoryHeap.BuffermemoryHeaps()Returns aVkMemoryHeap.Buffer view of thememoryHeapsfield.VkMemoryHeapmemoryHeaps(int index)Returns aVkMemoryHeapview of the struct at the specified index of thememoryHeapsfield.intmemoryTypeCount()Returns the value of thememoryTypeCountfield.VkMemoryType.BuffermemoryTypes()Returns aVkMemoryType.Buffer view of thememoryTypesfield.VkMemoryTypememoryTypes(int index)Returns aVkMemoryTypeview of the struct at the specified index of thememoryTypesfield.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()
-
-
-
Constructor Detail
-
VkPhysicalDeviceMemoryProperties
public VkPhysicalDeviceMemoryProperties(java.nio.ByteBuffer container)
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 Detail
-
sizeof
public int sizeof()
- Specified by:
sizeofin classorg.lwjgl.system.Struct
-
memoryTypeCount
public int memoryTypeCount()
Returns the value of thememoryTypeCountfield.
-
memoryTypes
public VkMemoryType.Buffer memoryTypes()
Returns aVkMemoryType.Buffer view of thememoryTypesfield.
-
memoryTypes
public VkMemoryType memoryTypes(int index)
Returns aVkMemoryTypeview of the struct at the specified index of thememoryTypesfield.
-
memoryHeapCount
public int memoryHeapCount()
Returns the value of thememoryHeapCountfield.
-
memoryHeaps
public VkMemoryHeap.Buffer memoryHeaps()
Returns aVkMemoryHeap.Buffer view of thememoryHeapsfield.
-
memoryHeaps
public VkMemoryHeap memoryHeaps(int index)
Returns aVkMemoryHeapview of the struct at the specified index of thememoryHeapsfield.
-
malloc
public static VkPhysicalDeviceMemoryProperties malloc()
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemAlloc. The instance must be explicitly freed.
-
calloc
public static VkPhysicalDeviceMemoryProperties calloc()
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withmemCalloc. The instance must be explicitly freed.
-
create
public static VkPhysicalDeviceMemoryProperties create()
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated withBufferUtils.
-
create
public static VkPhysicalDeviceMemoryProperties create(long address)
Returns a newVkPhysicalDeviceMemoryPropertiesinstance for the specified memory address.
-
createSafe
@Nullable public static VkPhysicalDeviceMemoryProperties createSafe(long address)
-
malloc
public static VkPhysicalDeviceMemoryProperties.Buffer malloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemAlloc. The instance must be explicitly freed.- Parameters:
capacity- the buffer capacity
-
calloc
public static VkPhysicalDeviceMemoryProperties.Buffer calloc(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withmemCalloc. The instance must be explicitly freed.- Parameters:
capacity- the buffer capacity
-
create
public static VkPhysicalDeviceMemoryProperties.Buffer create(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated withBufferUtils.- Parameters:
capacity- the buffer capacity
-
create
public static VkPhysicalDeviceMemoryProperties.Buffer create(long address, int capacity)
Create aVkPhysicalDeviceMemoryProperties.Bufferinstance 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 newVkPhysicalDeviceMemoryPropertiesinstance allocated on the thread-localMemoryStack.
-
callocStack
public static VkPhysicalDeviceMemoryProperties callocStack()
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the thread-localMemoryStackand initializes all its bits to zero.
-
mallocStack
public static VkPhysicalDeviceMemoryProperties mallocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStack.- Parameters:
stack- the stack from which to allocate
-
callocStack
public static VkPhysicalDeviceMemoryProperties callocStack(org.lwjgl.system.MemoryStack stack)
Returns a newVkPhysicalDeviceMemoryPropertiesinstance allocated on the specifiedMemoryStackand 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.Bufferinstance allocated on the thread-localMemoryStack.- Parameters:
capacity- the buffer capacity
-
callocStack
public static VkPhysicalDeviceMemoryProperties.Buffer callocStack(int capacity)
Returns a newVkPhysicalDeviceMemoryProperties.Bufferinstance allocated on the thread-localMemoryStackand 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.Bufferinstance 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.Bufferinstance allocated on the specifiedMemoryStackand 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.
-
-