From: Mikko Rasa Date: Wed, 1 Dec 2021 07:53:10 +0000 (+0200) Subject: Support transfers with no staged data X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5c35768c310847df816d216eecf8fa2e93f5f8b8;p=libs%2Fgl.git Support transfers with no staged data This can be used to transfer data within VRAM, such as for mipmap generation. --- diff --git a/source/backends/vulkan/transferqueue.cpp b/source/backends/vulkan/transferqueue.cpp index 87afc3c0..8040f245 100644 --- a/source/backends/vulkan/transferqueue.cpp +++ b/source/backends/vulkan/transferqueue.cpp @@ -23,18 +23,21 @@ TransferQueue::PendingTransfer &TransferQueue::prepare_transfer(void *object, bo 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; @@ -56,7 +59,7 @@ void TransferQueue::dispatch_transfers(VkCommandBuffer command_buffer) 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); } } diff --git a/source/backends/vulkan/transferqueue.h b/source/backends/vulkan/transferqueue.h index b8719d62..b11b4503 100644 --- a/source/backends/vulkan/transferqueue.h +++ b/source/backends/vulkan/transferqueue.h @@ -31,7 +31,7 @@ private: 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 synchronize; @@ -63,7 +63,7 @@ void *TransferQueue::prepare_transfer(void *object, bool ordered, std::size_t si PendingTransfer &pt = prepare_transfer(object, ordered, size); pt.synchronize = std::forward(synchronize); pt.transfer = std::forward(transfer); - return static_cast(buffers[pt.buffer_index].mapped_address)+pt.offset; + return (pt.buffer_index<0 ? 0 : static_cast(buffers[pt.buffer_index].mapped_address)+pt.offset); } } // namespace GL