forked from vsg-dev/VulkanSceneGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.h
More file actions
173 lines (127 loc) · 6.35 KB
/
Copy pathContext.h
File metadata and controls
173 lines (127 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
/* <editor-fold desc="MIT License">
Copyright(c) 2018 Robert Osfield
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
</editor-fold> */
#include <deque>
#include <memory>
#include <vsg/core/Object.h>
#include <vsg/core/ScratchMemory.h>
#include <vsg/nodes/Group.h>
#include <vsg/vk/BufferData.h>
#include <vsg/vk/Command.h>
#include <vsg/vk/CommandPool.h>
#include <vsg/vk/DescriptorPool.h>
#include <vsg/vk/Fence.h>
#include <vsg/vk/GraphicsPipeline.h>
#include <vsg/vk/Semaphore.h>
#include <vsg/vk/BufferData.h>
#include <vsg/vk/ImageData.h>
namespace vsg
{
struct BufferPreferences
{
VkDeviceSize minimumBufferSize = 16 * 1024 * 1024;
VkDeviceSize minimumBufferDeviceMemorySize = 16 * 1024 * 1024;
VkDeviceSize minimumImageDeviceMemorySize = 16 * 1024 * 1024;
};
class MemoryBufferPools : public Inherit<Object, MemoryBufferPools>
{
public:
MemoryBufferPools(const std::string& name, Device* in_device, BufferPreferences preferences);
std::string name;
ref_ptr<Device> device;
BufferPreferences bufferPreferences;
// transfer data settings
// used by BufferData.cpp, ImageData.cpp
using MemoryPools = std::vector<ref_ptr<DeviceMemory>>;
MemoryPools memoryPools;
using BufferPools = std::vector<ref_ptr<Buffer>>;
BufferPools bufferPools;
VkDeviceSize computeMemoryTotalAvailble() const;
VkDeviceSize computeMemoryTotalReserved() const;
VkDeviceSize computeBufferTotalAvailble() const;
VkDeviceSize computeBufferTotalReserved() const;
BufferData reserveBufferData(VkDeviceSize totalSize, VkDeviceSize alignment, VkBufferUsageFlags bufferUsageFlags, VkSharingMode sharingMode, VkMemoryPropertyFlags memoryProperties);
using DeviceMemoryOffset = std::pair<ref_ptr<DeviceMemory>, VkDeviceSize>;
DeviceMemoryOffset reserveMemory(VkMemoryRequirements memRequirements, VkMemoryPropertyFlags memoryProperties, void* pNextAllocInfo = nullptr);
using CopyPair = std::pair<BufferData, BufferData>;
using CopyQueue = std::deque<CopyPair>;
CopyQueue bufferDataToCopy;
};
class CopyAndReleaseBufferDataCommand : public Command
{
public:
CopyAndReleaseBufferDataCommand(BufferData src, BufferData dest) :
source(src),
destination(dest) {}
BufferData source;
BufferData destination;
void dispatch(CommandBuffer& commandBuffer) const override;
protected:
virtual ~CopyAndReleaseBufferDataCommand();
};
class CopyAndReleaseImageDataCommand : public Command
{
public:
CopyAndReleaseImageDataCommand(BufferData src, ImageData dest, uint32_t numMipMapLevels) :
source(src),
destination(dest),
mipLevels(numMipMapLevels) {}
void dispatch(CommandBuffer& commandBuffer) const override;
BufferData source;
ImageData destination;
uint32_t mipLevels = 1;
protected:
virtual ~CopyAndReleaseImageDataCommand();
};
class BuildAccelerationStructureCommand : public Inherit<Command, BuildAccelerationStructureCommand>
{
public:
BuildAccelerationStructureCommand(Device* device, VkAccelerationStructureInfoNV* info, const VkAccelerationStructureNV& structure, Buffer* instanceBuffer, Allocator* allocator = nullptr);
void compile(Context&) override {}
void dispatch(CommandBuffer& commandBuffer) const override;
ref_ptr<Device> _device;
VkAccelerationStructureInfoNV* _accelerationStructureInfo;
VkAccelerationStructureNV _accelerationStructure;
ref_ptr<Buffer> _instanceBuffer;
// scratch buffer set after compile traversal before dispatch of build commands
ref_ptr<Buffer> _scratchBuffer;
};
class Context
{
public:
Context(Device* in_device, BufferPreferences bufferPreferences = {});
Context(const Context& context);
virtual ~Context();
// used by BufferData.cpp, ComputePipeline.cpp, Descriptor.cpp, Descriptor.cpp, DescriptorSet.cpp, DescriptorSetLayout.cpp, GraphicsPipeline.cpp, ImageData.cpp, PipelineLayout.cpp, ShaderModule.cpp
const uint32_t deviceID = 0;
ref_ptr<Device> device;
// used by GraphicsPipeline.cpp
ref_ptr<RenderPass> renderPass;
ref_ptr<ViewportState> viewport;
// DescriptorSet.cpp
ref_ptr<DescriptorPool> descriptorPool;
// transfer data settings
// used by BufferData.cpp, ImageData.cpp
ref_ptr<Queue> graphicsQueue;
ref_ptr<CommandPool> commandPool;
ref_ptr<CommandBuffer> commandBuffer;
ref_ptr<Fence> fence;
ref_ptr<Semaphore> semaphore;
ref_ptr<ScratchMemory> scratchMemory;
std::vector<ref_ptr<CopyAndReleaseBufferDataCommand>> copyBufferDataCommands;
std::vector<ref_ptr<CopyAndReleaseImageDataCommand>> copyImageDataCommands;
std::vector<ref_ptr<Command>> commands;
void dispatch();
void waitForCompletion();
ref_ptr<CommandBuffer> getOrCreateCommandBuffer();
ref_ptr<MemoryBufferPools> deviceMemoryBufferPools;
ref_ptr<MemoryBufferPools> stagingMemoryBufferPools;
// raytracing
VkDeviceSize scratchBufferSize;
std::vector<ref_ptr<BuildAccelerationStructureCommand>> buildAccelerationStructureCommands;
};
} // namespace vsg