]> git.tdb.fi Git - libs/gl.git/commitdiff
Support transfers with no staged data
authorMikko Rasa <tdb@tdb.fi>
Wed, 1 Dec 2021 07:53:10 +0000 (09:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 1 Dec 2021 07:53:10 +0000 (09:53 +0200)
This can be used to transfer data within VRAM, such as for mipmap
generation.

source/backends/vulkan/transferqueue.cpp
source/backends/vulkan/transferqueue.h

index 87afc3c0b516fcefc0ec395fb93e1a4fa63dd3a8..8040f245f5360a33ae31fb6a23b34cd392c8dbf9 100644 (file)
@@ -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);
                }
        }
index b8719d627513bd8962dec3df4c1b52ddd2a8dbc5..b11b4503d59c78a0a60c77c2c905135ad714f57e 100644 (file)
@@ -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<void()> 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<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