PendingTransfer &transfer = *transfers.emplace(j);
transfer.order = order;
- auto i = find_if(buffers, [size](const StagingBuffer &b){ return b.used+size<=b.size; });
- if(i==buffers.end())
+ if(size)
{
- buffers.emplace_back(device, max(default_buffer_size, size));
- i = prev(buffers.end());
- }
+ auto i = find_if(buffers, [size](const StagingBuffer &b){ return b.used+size<=b.size; });
+ if(i==buffers.end())
+ {
+ buffers.emplace_back(device, max(default_buffer_size, size));
+ i = prev(buffers.end());
+ }
- transfer.buffer_index = distance(buffers.begin(), i);
- transfer.offset = i->used;
- transfer.size = size;
+ transfer.buffer_index = distance(buffers.begin(), i);
+ transfer.offset = i->used;
+ transfer.size = size;
- i->used += size;
+ i->used += size;
+ }
order += ordered;
for(; i!=j; ++i)
{
- VkBuffer buffer = buffers[i->buffer_index].buffer;
+ VkBuffer buffer = (i->buffer_index>=0 ? buffers[i->buffer_index].buffer : 0);
i->transfer(command_buffer, buffer, i->offset);
}
}
struct PendingTransfer
{
unsigned order = 0;
- unsigned buffer_index = 0;
+ int buffer_index = -1;
std::size_t offset = 0;
std::size_t size = 0;
std::function<void()> synchronize;
PendingTransfer &pt = prepare_transfer(object, ordered, size);
pt.synchronize = std::forward<S>(synchronize);
pt.transfer = std::forward<T>(transfer);
- return static_cast<char *>(buffers[pt.buffer_index].mapped_address)+pt.offset;
+ return (pt.buffer_index<0 ? 0 : static_cast<char *>(buffers[pt.buffer_index].mapped_address)+pt.offset);
}
} // namespace GL