1 #ifndef MSP_GL_VULKAN_TRANSFERQUEUE_H_
2 #define MSP_GL_VULKAN_TRANSFERQUEUE_H_
21 unsigned memory_id = 0;
24 void *mapped_address = 0;
25 unsigned async_count = 0;
26 unsigned last_frame = 0;
28 StagingBuffer(Device &, std::size_t);
29 StagingBuffer(StagingBuffer &&);
33 struct PendingTransfer
35 const void *object = 0;
37 int buffer_index = -1;
38 std::size_t offset = 0;
40 void *staging_address = 0;
41 std::function<void()> synchronize;
42 std::function<void(VkCommandBuffer, VkBuffer, std::size_t)> transfer;
46 std::size_t default_buffer_size = 16*1048576;
47 std::vector<StagingBuffer> buffers;
48 std::vector<PendingTransfer> transfers;
49 std::vector<PendingTransfer> async_transfers;
50 std::map<const void *, unsigned> next_orders;
51 unsigned current_frame = 0;
54 TransferQueue(Device &);
56 template<typename S, typename T>
57 void *prepare_transfer(const void *, bool, std::size_t, S &&, T &&);
59 template<typename S, typename T>
60 void prepare_transfer(const void *o, bool r, S &&s, T &&t)
61 { prepare_transfer(o, r, 0, std::forward<S>(s), std::forward<T>(t)); }
63 void finalize_transfer(void *);
66 void allocate_staging(PendingTransfer &, std::size_t);
67 PendingTransfer &prepare_transfer(const void *, bool, std::size_t);
68 PendingTransfer &insert_transfer(PendingTransfer &&);
71 void dispatch_transfers(VkCommandBuffer);
74 template<typename S, typename T>
75 void *TransferQueue::prepare_transfer(const void *object, bool ordered, std::size_t size, S &&synchronize, T &&transfer)
77 PendingTransfer &pt = prepare_transfer(object, ordered, size);
78 pt.synchronize = std::forward<S>(synchronize);
79 pt.transfer = std::forward<T>(transfer);
80 return pt.staging_address;