Zebrafish
Zebrafish

Reputation: 13886

In Vulkan how am I supposed to know if the buffer usage flag TRANSFER_SOURCE needs to be used?

There's a bit of a chicken and the egg issue I'm dealing with. I create a buffer, and if that buffer is going to be allocated to device-local memory then there's the possibility that the memory type I can use for that buffer will NOT be host-visible, and so I need to set the VK_BUFFER_USAGE_TRANSFER_DST_BIT flag on the buffer, and use a host-visible staging buffer. The problem goes like this:

auto bufferUsageBits = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT /* | VK_BUFFER_USAGE_TRANSFER_DST_BIT*/;
// The second flag should be set only if the memory requirements queries later
// tell me there's no device-local AND host-visible memory types
VkBuffer vkBufferHandle;
VK::createBuffer(size, bufferUsageBits, VK_SHARING_MODE_EXCLUSIVE, &vkBufferHandle);

vkGetBufferMemoryRequirements();
// Only know do I now if I need a staging buffer and the buffer I'm creating needs to be transfered to.

I could do two things as far as I can see:

  1. If the device is integrated or CPU type then assume that the buffer won't need the transfer flag set.
  2. Set the flag anyway whether it's integrated/CPU or discrete.

How am I supposed to deal with this?

Upvotes: 1

Views: 827

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473272

If you create a VkBuffer and the memory requirements for it are such that it needs to allow being the destination of a transfer operation, then... create a new VkBuffer with the destination transfer usage bit set (and delete the old one).

It's just a VkBuffer. It doesn't really do anything until its bound to memory. Indeed, it's a good idea in a real application to create multiple speculative buffers to figure out where you intend to arrange your buffer memory usage.

Upvotes: 3

Related Questions