vsg: include/vsg/state/BufferInfo.h Source File

vsg 1.1.9 VulkanSceneGraph library |

Loading...
Searching...
No Matches
BufferInfo.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 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/state/Buffer.h>
16
17#include <cstring>
18
19namespace 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 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override;
37 int compare(const Object& rhs_object) const override;
38
39 void release();
40
43 void copyDataToBuffer();
44
47 void copyDataToBuffer(uint32_t deviceID);
48
49 explicit operator bool() const { return buffer.valid() && data.valid() && range != 0; }
50
51 ref_ptr<Buffer> buffer;
52 VkDeviceSize offset = 0;
53 VkDeviceSize range = 0;
54 ref_ptr<Data> data;
55 ref_ptr<BufferInfo> parent;
56
58 bool requiresCopy(uint32_t deviceID) const
59 {
60 return data && data->differentModifiedCount(copiedModifiedCounts[deviceID]);
61 }
62
64 bool syncModifiedCounts(uint32_t deviceID)
65 {
66 return data && data->getModifiedCount(copiedModifiedCounts[deviceID]);
67 }
68
69 vk_buffer<ModifiedCount> copiedModifiedCounts;
70
71 protected:
72 virtual ~BufferInfo();
73 };
74 VSG_type_name(vsg::BufferInfo);
75
76 using BufferInfoList = std::vector<ref_ptr<BufferInfo>>;
77
78 struct VulkanArrayData
79 {
80 std::vector<VkBuffer> vkBuffers;
81 std::vector<VkDeviceSize> offsets;
82 };
83
85 extern VSG_DECLSPEC void assignVulkanArrayData(uint32_t deviceID, const BufferInfoList& arrays, VulkanArrayData& vkd);
86
87 extern VSG_DECLSPEC ref_ptr<BufferInfo> copyDataToStagingBuffer(Context& context, const Data* data);
88
89 extern VSG_DECLSPEC bool createBufferAndTransferData(Context& context, const BufferInfoList& bufferInfoList, VkBufferUsageFlags usage, VkSharingMode sharingMode);
90
91 extern VSG_DECLSPEC BufferInfoList createHostVisibleBuffer(Device* device, const DataList& dataList, VkBufferUsageFlags usage, VkSharingMode sharingMode);
92
93 extern VSG_DECLSPEC void copyDataListToBuffers(Device* device, BufferInfoList& bufferInfoList);
94
95} // namespace vsg
vsg::Buffer
Definition Buffer.h:26
vsg::BufferInfo
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition BufferInfo.h:27
vsg::BufferInfo::compare
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,...
vsg::BufferInfo::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
vsg::BufferInfo::requiresCopy
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:58
vsg::BufferInfo::copyDataToBuffer
void copyDataToBuffer(uint32_t deviceID)
vsg::BufferInfo::copyDataToBuffer
void copyDataToBuffer()
vsg::BufferInfo::syncModifiedCounts
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:64
vsg::CommandBuffer
CommandBuffer encapsulates VkCommandBuffer.
Definition CommandBuffer.h:27
vsg::Context
Definition Context.h:67
vsg::CopyOp
Definition Object.h:42
vsg::Data
Definition Data.h:110
vsg::Device
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:39
vsg::Object
Definition Object.h:60
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::VulkanArrayData
Definition BufferInfo.h:79
vsg::vk_buffer
vk_buffer that manages a single logical device supported.
Definition vk_buffer.h:28