Reputation: 13886
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:
How am I supposed to deal with this?
Upvotes: 1
Views: 827
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