abhijit jagdale
abhijit jagdale

Reputation: 649

How to read contents of VkBuffer after its being filled with data in Vulkan?

Is there any code snippet to do this? I am doing an offscreen rendering to a VkImage and want to dump its result to png. I have created a VkBuffer and doing a vkCmdCopyImageToBuffer, but not sure how to move forward.

Edit: I am creating a VkBuffer with its VkBufferCreateInfo. Not assigning any vkAllocateMemory since I do not want to associate it with any GPU memory. After this I do vkCmdCopyImageToBuffer. So how to do a memcpy assuming the data is copied to VkBuffer.

Upvotes: 0

Views: 1867

Answers (1)

ratchet freak
ratchet freak

Reputation: 48196

You will need to map the memory of the buffer you copied the data into and pull the data from the void*. You have to assign memory to the buffer. The memory you'll want to use must be host visible.

If the memory heap you used for the buffer is not coherent then you need to use vkInvalidateMappedMemoryRanges for the mapped range after the fence is triggered and before you start copying the data out.

Upvotes: 2

Related Questions