Memory visible to the device, for example images or buffers.
Get the amount of memory - vkGetPhysicalDeviceMemoryProperties
Given a VkPhysicalDevice handle it fills in a VkPhysicalDeviceMemoryProperties structure that describe the memory avaible to the device. There are two arrays in the structure, memoryHeaps and memoryTypes.
Describe a memory resource of a given size. There is one possible flag that can be set and it is VK_MEMORY_HEAP_DEVICE_LOCAL_BIT.
This contains a flags with the properites for the memory type and a index to the heap that this memory type allocate memory from. This is the thing the vkAllocateMemory index into. The possible flags for the memory.
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT: This is set for memory that is most efficient for device access. It is memory local to the device.
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT: Set for memory that can be mapped to the host with vkMapMemory.
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT: If this is set the cache management commands do not need to be used when host access the memory.
VK_MEMORY_PROPERTY_HOST_CACHED_BIT: If set the memory is cached on the host.
How to allocate memory - vkAllocateMemory
Allocate a number of bytes and return a VkDeviceMemory handle for the memory. To select from where the memory is allocted the memoryTypeIndex is used. memoryTypeIndex selects a index in VkPhysicalDeviceMemoryProperties.memoryTypes and that pick the properties of the memory and also the heap.
How to free memory - vkFreeMemory
When memory is freed it's the applications responsibility to make sure it's no longer used by the device. The memory can still be bound to images or buffers as long as they are not used for anything other then being destrtoyed. Release memory is returned to the heap it was allocated from.
The device memory is not directly host accessible. If the memory was allocated with the property VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT it can be mapped to host virtual memory. This is done with vkMapMemory. One can map the whole VkDeviceMemory or a selected range from it. It's up to the application to syncroniuze read and write activity with the activity of the device. Once host access to the memory is no longer needed the application can unmapp the memory by calling vkUnmapMemory. It's an error to map a memory object that is already mapped.
vkFlushMappedMemoryRanges / vkInvalidateMappedMemoryRanges
Host memory is non-device-visible that are used for internal software structures of the vulkan implementation. Commands that might allocate or free memory takes a pointer to a VkAllocationCallbacks structure. If it is NULL the implementation will use it's own memory allocator functions for host memory. If it is set it need to contain application functions to allocate and free memory.
VulkanMemoryAllocator - 2017