From: Mikko Rasa Date: Mon, 20 Dec 2021 21:03:33 +0000 (+0200) Subject: Reset staging buffers in TransferQueue once the transfers are done X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7d221b1fd6194e59bc0783740a2a17ac71fa4da5;p=libs%2Fgl.git Reset staging buffers in TransferQueue once the transfers are done --- diff --git a/source/backends/vulkan/transferqueue.cpp b/source/backends/vulkan/transferqueue.cpp index 8db81020..9fc94140 100644 --- a/source/backends/vulkan/transferqueue.cpp +++ b/source/backends/vulkan/transferqueue.cpp @@ -28,6 +28,7 @@ void TransferQueue::allocate_staging(PendingTransfer &transfer, size_t size) transfer.staging_address = static_cast(i->mapped_address)+transfer.offset; i->used += size; + ++i->async_count; } TransferQueue::PendingTransfer &TransferQueue::prepare_transfer(const void *object, bool ordered, size_t size) @@ -53,6 +54,8 @@ void TransferQueue::finalize_transfer(void *staging) if(i==async_transfers.end() || i->staging_address!=staging) throw key_error(staging); + if(i->buffer_index>=0) + --buffers[i->buffer_index].async_count; insert_transfer(move(*i)); async_transfers.erase(i); } @@ -79,6 +82,7 @@ void TransferQueue::dispatch_transfers(VkCommandBuffer command_buffer) if(transfers.empty()) return; + ++current_frame; for(auto i=transfers.begin(); i!=transfers.end(); ) { auto j = i; @@ -91,11 +95,18 @@ void TransferQueue::dispatch_transfers(VkCommandBuffer command_buffer) { VkBuffer buffer = (i->buffer_index>=0 ? buffers[i->buffer_index].buffer : 0); i->transfer(command_buffer, buffer, i->offset); + if(i->buffer_index>=0) + buffers[i->buffer_index].last_frame = current_frame; } } transfers.clear(); next_orders.clear(); + + unsigned n_frames_in_flight = device.get_n_frames_in_flight(); + for(StagingBuffer &b: buffers) + if(!b.async_count && b.last_frame+n_frames_in_flight transfers; std::vector async_transfers; std::map next_orders; + unsigned current_frame = 0; public: TransferQueue(Device &);