forked from vsg-dev/VulkanSceneGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescriptorSet.h
More file actions
219 lines (165 loc) · 8.43 KB
/
Copy pathDescriptorSet.h
File metadata and controls
219 lines (165 loc) · 8.43 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#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 <vsg/vk/Command.h>
#include <vsg/vk/Descriptor.h>
#include <vsg/vk/DescriptorPool.h>
#include <vsg/vk/DescriptorSetLayout.h>
#include <vsg/vk/PipelineLayout.h>
namespace vsg
{
class VSG_DECLSPEC DescriptorSet : public Inherit<Object, DescriptorSet>
{
public:
DescriptorSet();
DescriptorSet(ref_ptr<DescriptorSetLayout> descriptorSetLayout, const Descriptors& descriptors);
template<class N, class V>
static void t_traverse(N& ds, V& visitor)
{
if (ds._descriptorSetLayout) ds._descriptorSetLayout->accept(visitor);
for (auto& descriptor : ds._descriptors) descriptor->accept(visitor);
}
void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
void read(Input& input) override;
void write(Output& output) const override;
const DescriptorSetLayout* getDescriptorSetLayout() const { return _descriptorSetLayout; }
const Descriptors& getDescriptors() const { return _descriptors; }
// compile the Vulkan object, context parameter used for Device
void compile(Context& context);
// remove the local reference to the Vulkan implementation
void release(uint32_t deviceID) { _implementation[deviceID] = {}; }
void release() { _implementation.clear(); }
VkDescriptorSet vk(uint32_t deviceID) const { return _implementation[deviceID]->_descriptorSet; }
protected:
virtual ~DescriptorSet();
struct Implementation : public Inherit<Object, Implementation>
{
Implementation(VkDescriptorSet descriptorSet, Device* device, DescriptorPool* descriptorPool, DescriptorSetLayout* descriptorSetLayout);
virtual ~Implementation();
using Result = vsg::Result<Implementation, VkResult, VK_SUCCESS>;
static Result create(Device* device, DescriptorPool* descriptorPool, DescriptorSetLayout* descriptorSetLayout);
void assign(Context& context, const Descriptors& descriptors);
VkDescriptorSet _descriptorSet;
ref_ptr<Device> _device;
ref_ptr<DescriptorPool> _descriptorPool;
ref_ptr<DescriptorSetLayout> _descriptorSetLayout;
Descriptors _descriptors;
};
vk_buffer<ref_ptr<Implementation>> _implementation;
ref_ptr<DescriptorSetLayout> _descriptorSetLayout;
Descriptors _descriptors;
};
VSG_type_name(vsg::DescriptorSet);
using DescriptorSets = std::vector<ref_ptr<DescriptorSet>>;
class VSG_DECLSPEC BindDescriptorSets : public Inherit<StateCommand, BindDescriptorSets>
{
public:
BindDescriptorSets();
BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, uint32_t firstSet, const DescriptorSets& descriptorSets) :
Inherit(1), // slot 1
_bindPoint(bindPoint),
_firstSet(firstSet),
_pipelineLayout(pipelineLayout),
_descriptorSets(descriptorSets)
{
}
BindDescriptorSets(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, const DescriptorSets& descriptorSets) :
Inherit(1), // slot 1
_bindPoint(bindPoint),
_firstSet(0),
_pipelineLayout(pipelineLayout),
_descriptorSets(descriptorSets)
{
}
template<class N, class V>
static void t_traverse(N& bds, V& visitor)
{
if (bds._pipelineLayout) bds._pipelineLayout->accept(visitor);
for (auto& ds : bds._descriptorSets) ds->accept(visitor);
}
void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
void read(Input& input) override;
void write(Output& output) const override;
VkPipelineBindPoint getBindPoint() { return _bindPoint; }
PipelineLayout* getPipelineLayout() { return _pipelineLayout; }
const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; }
uint32_t getFirstSet() { return _firstSet; }
const DescriptorSets& getDescriptorSets() const { return _descriptorSets; }
// compile the Vulkan object, context parameter used for Device
void compile(Context& context) override;
void dispatch(CommandBuffer& commandBuffer) const override;
protected:
virtual ~BindDescriptorSets() {}
VkPipelineBindPoint _bindPoint;
uint32_t _firstSet;
struct VulkanData
{
VkPipelineLayout _vkPipelineLayout = 0;
std::vector<VkDescriptorSet> _vkDescriptorSets;
};
vk_buffer<VulkanData> _vulkanData;
ref_ptr<PipelineLayout> _pipelineLayout;
DescriptorSets _descriptorSets;
};
VSG_type_name(vsg::BindDescriptorSets);
class VSG_DECLSPEC BindDescriptorSet : public Inherit<StateCommand, BindDescriptorSet>
{
public:
BindDescriptorSet();
BindDescriptorSet(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, uint32_t firstSet, DescriptorSet* descriptorSet) :
Inherit(1), // slot 1
_bindPoint(bindPoint),
_firstSet(firstSet),
_pipelineLayout(pipelineLayout),
_descriptorSet(descriptorSet)
{
}
BindDescriptorSet(VkPipelineBindPoint bindPoint, PipelineLayout* pipelineLayout, DescriptorSet* descriptorSet) :
Inherit(1), // slot 1
_bindPoint(bindPoint),
_firstSet(0),
_pipelineLayout(pipelineLayout),
_descriptorSet(descriptorSet)
{
}
template<class N, class V>
static void t_traverse(N& bds, V& visitor)
{
if (bds._pipelineLayout) bds._pipelineLayout->accept(visitor);
if (bds._descriptorSet) bds._descriptorSet->accept(visitor);
}
void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
void read(Input& input) override;
void write(Output& output) const override;
VkPipelineBindPoint getBindPoint() const { return _bindPoint; }
PipelineLayout* getPipelineLayout() { return _pipelineLayout; }
const PipelineLayout* getPipelineLayout() const { return _pipelineLayout; }
uint32_t getFirstSet() const { return _firstSet; }
DescriptorSet* getDescriptorSet() { return _descriptorSet; }
const DescriptorSet* getDescriptorSet() const { return _descriptorSet; }
// compile the Vulkan object, context parameter used for Device
void compile(Context& context) override;
void dispatch(CommandBuffer& commandBuffer) const override;
protected:
virtual ~BindDescriptorSet() {}
VkPipelineBindPoint _bindPoint;
uint32_t _firstSet;
struct VulkanData
{
VkPipelineLayout _vkPipelineLayout = 0;
VkDescriptorSet _vkDescriptorSet;
};
vk_buffer<VulkanData> _vulkanData;
// settings
ref_ptr<PipelineLayout> _pipelineLayout;
ref_ptr<DescriptorSet> _descriptorSet;
};
VSG_type_name(vsg::BindDescriptorSet);
} // namespace vsg