607
607

Reputation: 73

Transfer image data to GPU via an image object?

I create an image object and bind a memory that has VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT tag. Then, I map the memory and copy the image data into the pointer. Finally, I unmap the memory and transfer the image to the GPU. Is that right?

What is the difference between copying CPU data to the GPU via a VkImage and a VkBuffer?

Upvotes: 1

Views: 354

Answers (1)

Columbo
Columbo

Reputation: 6766

What is the difference between copying CPU data to the GPU via a VkImage and a VkBuffer?

If we're talking about using a staging allocation during transfer of data from CPU to GPU then basically, copying via a VkBuffer is the correct way to do it. Copying via VkImage may work in limited cases, but you'll almost certainly find yourself removing that code at a later date.

The problem with copying via a VkImage is that your temporary staging allocation is subject to the driver's limitations on host-visible images. You might find it works well enough for your first attempts to get something on screen, but you'll soon run into device-specific limitations that prevent VkImage staging buffers working for mipmaps, compressed textures, array textures or anything remotely exotic.

Basically a VkBuffer is the correct tool for the job of being a staging buffer for texture data. A host visible VkImage is not intended for staging, I believe it's largely intended to be useful for situations where you want to display a stream of images that were generated on the CPU (e.g. displaying video frames that were CPU decoded, or displaying output from a software renderer)

Upvotes: 1

Related Questions