vsg: include/vsg/app/TransferTask.h Source File

vsg 1.1.10 VulkanSceneGraph library |

Loading...
Searching...
No Matches
TransferTask.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2022 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/io/Logger.h>
16#include <vsg/state/ImageInfo.h>
17#include <vsg/vk/CommandBuffer.h>
18#include <vsg/vk/ResourceRequirements.h>
19#include <vsg/vk/Semaphore.h>
20
21namespace vsg
22{
23
28 class VSG_DECLSPEC TransferTask : public Inherit<Object, TransferTask>
29 {
30 public:
31 explicit TransferTask(Device* in_device, uint32_t numBuffers = 3);
32
33 struct TransferResult
34 {
35 VkResult result = VK_SUCCESS;
36 ref_ptr<Semaphore> dataTransferredSemaphore;
37 };
38
39 enum TransferMask
40 {
41 TRANSFER_NONE = 0,
42 TRANSFER_BEFORE_RECORD_TRAVERSAL = 1 << 0,
43 TRANSFER_AFTER_RECORD_TRAVERSAL = 1 << 1,
44 TRANSFER_ALL = TRANSFER_BEFORE_RECORD_TRAVERSAL | TRANSFER_AFTER_RECORD_TRAVERSAL
45 };
46
48 virtual TransferResult transferData(TransferMask transferMask);
49
50 virtual bool containsDataToTransfer(TransferMask transferMask) const;
51
52 ref_ptr<Device> device;
53
54 void assign(const ResourceRequirements::DynamicData& dynamicData);
55 void assign(const BufferInfoList& bufferInfoList);
56 void assign(const ImageInfoList& imageInfoList);
57
58 ref_ptr<Queue> transferQueue;
59
61 VkDeviceSize minimumStagingBufferSize = 16 * 1024 * 1024;
62
64 ref_ptr<Instrumentation> instrumentation;
65
67 Logger::Level level = Logger::LOGGER_DEBUG;
68
69 void assignTransferConsumedCompletedSemaphore(TransferMask transferMask, ref_ptr<Semaphore> semaphore);
70
71 protected:
72 using OffsetBufferInfoMap = std::map<VkDeviceSize, ref_ptr<BufferInfo>>;
73 using BufferMap = std::map<ref_ptr<Buffer>, OffsetBufferInfoMap>;
74
75 mutable std::mutex _mutex;
76
77 struct TransferBlock : public Inherit<Object, TransferBlock>
78 {
79 ref_ptr<CommandBuffer> transferCommandBuffer;
80 ref_ptr<Fence> fence;
81 ref_ptr<Buffer> staging;
82 void* buffer_data = nullptr;
83 std::vector<VkBufferCopy> copyRegions;
84 bool waitOnFence = false;
85 };
86
87 struct DataToCopy
88 {
89 std::string name;
90 BufferMap dataMap;
91 std::set<ref_ptr<ImageInfo>> imageInfoSet;
92
93 uint32_t frameIndex = 0;
94 std::vector<ref_ptr<TransferBlock>> frames;
95
96 VkDeviceSize dataTotalRegions = 0;
97 VkDeviceSize dataTotalSize = 0;
98 VkDeviceSize imageTotalSize = 0;
99
100 ref_ptr<Semaphore> transferCompleteSemaphore;
101 ref_ptr<Semaphore> transferConsumerCompletedSemaphore;
102
103 bool containsDataToTransfer() const { return !dataMap.empty() || !imageInfoSet.empty(); }
104 };
105
106 DataToCopy _earlyDataToCopy;
107 DataToCopy _lateDataToCopy;
108
109 size_t _bufferCount;
110
111 TransferResult _transferData(DataToCopy& dataToCopy);
112
113 void _transferBufferInfos(DataToCopy& dataToCopy, VkCommandBuffer vk_commandBuffer, TransferBlock& frame, VkDeviceSize& offset);
114
115 void _transferImageInfos(DataToCopy& dataToCopy, VkCommandBuffer vk_commandBuffer, TransferBlock& frame, VkDeviceSize& offset);
116 void _transferImageInfo(VkCommandBuffer vk_commandBuffer, TransferBlock& frame, VkDeviceSize& offset, ImageInfo& imageInfo);
117 };
118 VSG_type_name(vsg::TransferTask);
119
120} // namespace vsg
vsg::Device
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:39
vsg::ImageInfo
ImageInfo class provides the VkDescriptorImageInfo settings used when setting up vsg::/vkDescriptorIm...
Definition ImageInfo.h:23
vsg::TransferTask
Definition TransferTask.h:29
vsg::TransferTask::instrumentation
ref_ptr< Instrumentation > instrumentation
hook for assigning Instrumentation to enable profiling of record traversal.
Definition TransferTask.h:64
vsg::TransferTask::level
Logger::Level level
control for the level of debug infomation emitted by the TransferTask
Definition TransferTask.h:67
vsg::TransferTask::transferData
virtual TransferResult transferData(TransferMask transferMask)
transfer any vsg::Data entries that have been updated to the associated GPU memory.
vsg::TransferTask::minimumStagingBufferSize
VkDeviceSize minimumStagingBufferSize
minimum size to use when allocating staging buffers.
Definition TransferTask.h:61
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::ResourceRequirements::DynamicData
Definition ResourceRequirements.h:64
vsg::TransferTask::DataToCopy
Definition TransferTask.h:88
vsg::TransferTask::TransferBlock
Definition TransferTask.h:78
vsg::TransferTask::TransferResult
Definition TransferTask.h:34