Home > Enterprise >  How does Vulkan's memory domain operation work
How does Vulkan's memory domain operation work

Time:02-02

I read some code example about copying images between cpu&gpu using VK_PIPELINE_STAGE_HOST_BIT. (For simplicity I'll use phsuedo code below) For gpu->cpu It is like: 1.vkCmdCopyImage(..., src_img, ... dst_img, ...); 2.vkCmdPipelineBarrier(...,VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT,...);

For cpu->gpu it is like:

  1. vkCmdPipelineBarrier(...,VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,...);
  2. vkCmdCopyImage(..., src_img, ... dst_img, ...);

I can understand the cpu->gpu part, as we need to use the barrier to make the src_img visible to gpu, so we do the barrier first, then copy src_img to dst_img. But for gpu->cpu, it does the copy first and then the barrier later. I wonder without using the barrier to make the src_img visible to the host first, how can the image copy succeed? FYI, the code example is from here, https://cpp.hotexamples.com/site/file?hash=0xf064d23ec4332e7951809e5112a592758b3c2c71a4560a9e77da0176b1a9193a Please refer to function CopyToImage and function CopyFromImage

CodePudding user response:

I wonder without using the barrier to make the src_img visible to the host first, how can the image copy succeed?

Because the host isn't reading the source image; it's reading the destination image, the one being copied to. The copy command is reading the source image, since the copy command is the one copying the image.


the dest image is in the host memory

No, it is in device memory. You know that because the memory is encapsulated via a VkDeviceMemory object, was allocated via device memory allocation commands, and will be freed by a device memory deallocation command.

This particular allocation of memory is shared with the host, but it belongs to the device.

The copy operation is a device operation. The barrier exposes the results of that operation to the host.

  • Related