8.2. Host Access to Device Memory Objects¶
Memory objects created with vkAllocateMemory
are not directly host accessible.
由 vkAllocateMemory
创建的 Memory object 并不是直接 host accessiable 。
Memory objects created with the memory property VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
are
considered mappable. Memory objects must be mappable in order to be successfully mapped on
the host.
创建 Memory objects 时指定了 memory 属性 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
被认为是可映射的( mappable )。要能够成功映射到 host , Memory object 必须是可映射的。
To retrieve a host virtual address pointer to a region of a mappable memory object, call
要获取一个指向可映射 memory object 的 host 虚拟地址指针,调用:
VkResult vkMapMemory(
VkDevice device,
VkDeviceMemory memory,
VkDeviceSize offset,
VkDeviceSize size,
VkMemoryMapFlags flags,
void** ppData);
vkMapMemory
does not check whether the device memory is currently in use before returning the
host-accessible pointer. The application must guarantee that any previously submitted command
that writes to this range has completed before the host reads from or writes to that range, and that
any previously submitted command that reads from that range has completed before the host
writes to that region (see here for details on fulfilling such a guarantee). If the device memory was
allocated without the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
set, these guarantees must be made for
an extended range: the application must round down the start of the range to the nearest multiple
of VkPhysicalDeviceLimits::nonCoherentAtomSize
, and round the end of the range up to the nearest
multiple of VkPhysicalDeviceLimits::nonCoherentAtomSize
.
While a range of device memory is mapped for host access, the application is responsible for synchronizing both device and host access to that memory range.
void vkGetImageSubresourceLayout(
VkDevice device,
VkImage image,
const VkImageSubresource* pSubresource,
VkSubresourceLayout* pLayout);
typedef struct VkImageSubresource {
VkImageAspectFlags aspectMask;
uint32_t mipLevel;
uint32_t arrayLayer;
} VkImageSubresource;
typedef struct VkSubresourceLayout {
VkDeviceSize offset;
VkDeviceSize size;
VkDeviceSize rowPitch;
VkDeviceSize arrayPitch;
VkDeviceSize depthPitch;
} VkSubresourceLayout;