vsg  1.1.0
VulkanSceneGraph library
TransferTask.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2022 Robert Osfield
6 
7 Permission 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 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE 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/app/CommandGraph.h>
16 #include <vsg/app/Window.h>
17 #include <vsg/io/DatabasePager.h>
18 #include <vsg/nodes/Group.h>
19 #include <vsg/vk/CommandBuffer.h>
20 
21 namespace 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 
34  virtual VkResult transferDynamicData();
35 
36  virtual bool containsDataToTransfer() const;
37 
38  ref_ptr<Device> device;
39  Semaphores waitSemaphores;
40  Semaphores signalSemaphores;
41 
43  void advance();
44 
45  void assign(const ResourceRequirements::DynamicData& dynamicData);
46  void assign(const BufferInfoList& bufferInfoList);
47  void assign(const ImageInfoList& imageInfoList);
48 
49  ref_ptr<Queue> transferQueue;
50  ref_ptr<Semaphore> currentTransferCompletedSemaphore;
51 
52  protected:
53  using OffsetBufferInfoMap = std::map<VkDeviceSize, ref_ptr<BufferInfo>>;
54  using BufferMap = std::map<ref_ptr<Buffer>, OffsetBufferInfoMap>;
55 
56  size_t index(size_t relativeFrameIndex = 0) const;
57 
58  VkDeviceSize _dynamicDataTotalRegions = 0;
59  VkDeviceSize _dynamicDataTotalSize = 0;
60  VkDeviceSize _dynamicImageTotalSize = 0;
61  BufferMap _dynamicDataMap;
62  std::set<ref_ptr<ImageInfo>> _dynamicImageInfoSet;
63 
64  size_t _currentFrameIndex;
65  std::vector<size_t> _indices;
66 
67  struct Frame
68  {
69  ref_ptr<CommandBuffer> transferCommandBuffer;
70  ref_ptr<Semaphore> transferCompleteSemaphore;
71  ref_ptr<Buffer> staging;
72  void* buffer_data = nullptr;
73  std::vector<VkBufferCopy> copyRegions;
74  };
75 
76  std::vector<Frame> _frames;
77 
78  void _transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset);
79 
80  void _transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset);
81  void _transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset, ImageInfo& imageInfo);
82  };
83  VSG_type_name(vsg::TransferTask);
84 
85 } // namespace vsg
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
ImageInfo class provides the VkDescriptorImageInfo settings used when setting up vsg::/vkDescriptorIm...
Definition: ImageInfo.h:23
Definition: Inherit.h:28
Definition: TransferTask.h:29
virtual VkResult transferDynamicData()
transfer any vsg::Data entries that have been updated to the associated GPU memory.
void advance()
advance the currentFrameIndex
Definition: ref_ptr.h:22
Definition: ResourceRequirements.h:56
Definition: TransferTask.h:68