vsg  1.1.0
VulkanSceneGraph library
BufferInfo.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 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/state/Buffer.h>
16 
17 #include <cstring>
18 
19 namespace vsg
20 {
21  // forward declare
22  class Context;
23  class CommandBuffer;
24 
26  class VSG_DECLSPEC BufferInfo : public Inherit<Object, BufferInfo>
27  {
28  public:
29  BufferInfo();
30  explicit BufferInfo(Data* in_data);
31  BufferInfo(Buffer* in_buffer, VkDeviceSize in_offset, VkDeviceSize in_range, Data* in_data = nullptr);
32 
33  BufferInfo(const BufferInfo&) = delete;
34  BufferInfo& operator=(const BufferInfo&) = delete;
35 
36  int compare(const Object& rhs_object) const override;
37 
38  void release();
39 
43 
46  void copyDataToBuffer(uint32_t deviceID);
47 
48  explicit operator bool() const { return buffer.valid() && data.valid() && range != 0; }
49 
50  ref_ptr<Buffer> buffer;
51  VkDeviceSize offset = 0;
52  VkDeviceSize range = 0;
53  ref_ptr<Data> data;
54  ref_ptr<BufferInfo> parent;
55 
57  bool requiresCopy(uint32_t deviceID) const
58  {
59  return data && data->differentModifiedCount(copiedModifiedCounts[deviceID]);
60  }
61 
63  bool syncModifiedCounts(uint32_t deviceID)
64  {
65  return data && data->getModifiedCount(copiedModifiedCounts[deviceID]);
66  }
67 
68  vk_buffer<ModifiedCount> copiedModifiedCounts;
69 
70  protected:
71  virtual ~BufferInfo();
72  };
73  VSG_type_name(vsg::BufferInfo);
74 
75  using BufferInfoList = std::vector<ref_ptr<BufferInfo>>;
76 
78  {
79  std::vector<VkBuffer> vkBuffers;
80  std::vector<VkDeviceSize> offsets;
81  };
82 
84  extern VSG_DECLSPEC void assignVulkanArrayData(uint32_t deviceID, const BufferInfoList& arrays, VulkanArrayData& vkd);
85 
86  extern VSG_DECLSPEC ref_ptr<BufferInfo> copyDataToStagingBuffer(Context& context, const Data* data);
87 
88  extern VSG_DECLSPEC bool createBufferAndTransferData(Context& context, const BufferInfoList& bufferInfoList, VkBufferUsageFlags usage, VkSharingMode sharingMode);
89 
90  extern VSG_DECLSPEC BufferInfoList createHostVisibleBuffer(Device* device, const DataList& dataList, VkBufferUsageFlags usage, VkSharingMode sharingMode);
91 
92  extern VSG_DECLSPEC void copyDataListToBuffers(Device* device, BufferInfoList& bufferInfoList);
93 
94 } // namespace vsg
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition: BufferInfo.h:27
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
bool requiresCopy(uint32_t deviceID) const
return true if the BufferInfo's data has been modified and should be copied to the buffer
Definition: BufferInfo.h:57
void copyDataToBuffer(uint32_t deviceID)
void copyDataToBuffer()
bool syncModifiedCounts(uint32_t deviceID)
return true if the BufferInfo's data has been modified and should be copied to the buffer,...
Definition: BufferInfo.h:63
Definition: Buffer.h:26
Definition: Context.h:67
Definition: Data.h:110
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
Definition: Inherit.h:28
Definition: Object.h:42
Definition: ref_ptr.h:22
Definition: BufferInfo.h:78
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28