Mapping, updating and unmapping host-visible memory
For images and buffers that are used during rendering, it is recommended to bind a memory that is located on the graphics hardware (device-local memory). This gives us the best performance. But we can't access such memory directly, and we need to use intermediate (staging) resources which mediate the data transfer between a GPU (device) and a CPU (host).
Staging resources, on the other hand, need to use memory that is host-visible. To upload data to such memory, or to read data from it, we need to map it.
How to do it...
- Take the handle of a created logical device and store it in a variable of type
VkDevice
namedlogical_device
. - Select a memory object that was allocated on a memory type with a
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
property. Store the memory object's handle in a variable of typeVkDeviceMemory
namedmemory_object
. - Choose a memory region that should be mapped and updated. Store the offset (in bytes) from the beginning of a memory...