Copying data content between images and buffers

Copy commands are special transfer commands that transfer data contents from one memory region to another. These regions could be between buffers objects, image objects, and buffer-to-image and vice versa.

Depending upon the application need, you may need to copy data between buffers and images in various situations. There are four types of copy commands available to accomplish this job:

  • vkCmdCopyBuffer: Data contents are copied from the source buffer to the destination buffer object's device memory
  • vkCmdCopyImage: A specific portion of the source image object is copied to the destination image region
  • vkCmdCopyBufferToImage: Buffer object data contents are copied to the image objects
  • vkCmdCopyImageToBuffer: Image object data contents are copied to the buffer objects

In the optimal tiling implementation, we used vkCmdCopyBufferToImage. The following is the syntax:

void vkCmdCopyBufferToImage( 
             VkCommandBuffer           commandBuffer, 
             VkBuffer                  srcBuffer, 
             VkImage                   dstImage, 
             VkImageLayout             dstImageLayout, 
             uint32_t                  regionCount, 
             const VkBufferImageCopy* pRegions); 

This API accepts six parameters, which are explained in the following table:

Parameters

Description

commandBuffer

The vkCmdCopyImageToBuffer command will be recorded in this command buffer object.

srcBuffer

This refers to the source buffer (VkBuffer) object from where the data contents will be copied.

dstImage

This refers to the destination image (VkImage) object into which a portion of the data contents will be copied.

dstImageLayout

This is the dstImage object's image layout object (VkImageLayout).

regionCount

This is the total count of the copy regions upon which the transfer of data contents will be performed.

pRegions

This field is a pointer to an array of VkBufferCopy holding the regions' specification that will undergo data transfer.

In the next section, we will update the descriptor set with the image object, which contains the image layouts and image views, and render the image object on the 3D cube.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.37.191