-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathIGPUDescriptorSet.cpp
More file actions
209 lines (164 loc) · 8.73 KB
/
IGPUDescriptorSet.cpp
File metadata and controls
209 lines (164 loc) · 8.73 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
#include "nbl/video/IGPUDescriptorSet.h"
#include "nbl/video/IDescriptorPool.h"
namespace nbl::video
{
IGPUDescriptorSet::IGPUDescriptorSet(core::smart_refctd_ptr<const IGPUDescriptorSetLayout>&& layout, core::smart_refctd_ptr<IDescriptorPool>&& pool, IDescriptorPool::SStorageOffsets&& offsets)
: base_t(std::move(layout)), IBackendObject(std::move(core::smart_refctd_ptr<const ILogicalDevice>(pool->getOriginDevice()))), m_version(0ull), m_pool(std::move(pool)), m_storageOffsets(std::move(offsets))
{
for (auto i = 0u; i < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++i)
{
// There is no descriptor of such type in the set.
if (m_storageOffsets.data[i] == ~0u)
continue;
const auto type = static_cast<asset::IDescriptor::E_TYPE>(i);
// Default-construct the core::smart_refctd_ptr<IDescriptor>s because even if the user didn't update the descriptor set with ILogicalDevice::updateDescriptorSet we
// won't have uninitialized memory and destruction wouldn't crash in ~IGPUDescriptorSet.
auto descriptors = getAllDescriptors(type);
assert(descriptors);
std::uninitialized_default_construct_n(descriptors, m_layout->getTotalDescriptorCount(type));
}
const auto mutableSamplerCount = m_layout->getTotalMutableSamplerCount();
if (mutableSamplerCount > 0)
{
auto mutableSamplers = getAllMutableSamplers();
assert(mutableSamplers);
std::uninitialized_default_construct_n(mutableSamplers, mutableSamplerCount);
}
}
IGPUDescriptorSet::~IGPUDescriptorSet()
{
if (!isZombie())
m_pool->deleteSetStorage(m_storageOffsets.getSetOffset());
}
asset::IDescriptor::E_TYPE IGPUDescriptorSet::validateWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write) const
{
assert(write.dstSet == this);
const char* debugName = getDebugName();
// screw it, we'll need to replace the descriptor writing with update templates of descriptor buffer soon anyway
const auto descriptorType = getBindingType(write.binding);
auto* descriptors = getDescriptors(descriptorType,write.binding);
if (!descriptors)
{
if (debugName)
m_pool->m_logger.log("Descriptor set (%s, %p) doesn't allow descriptor of such type at binding %u.", system::ILogger::ELL_ERROR, debugName, this, write.binding);
else
m_pool->m_logger.log("Descriptor set (%p) doesn't allow descriptor of such type at binding %u.", system::ILogger::ELL_ERROR, this, write.binding);
return asset::IDescriptor::E_TYPE::ET_COUNT;
}
core::smart_refctd_ptr<video::IGPUSampler>* mutableSamplers = nullptr;
if (descriptorType==asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER && write.info->info.image.sampler)
{
if (m_layout->getImmutableSamplerRedirect().getCount(IGPUDescriptorSetLayout::CBindingRedirect::binding_number_t{ write.binding }) != 0)
{
if (debugName)
m_pool->m_logger.log("Descriptor set (%s, %p) doesn't allow immutable samplers at binding %u, but immutable samplers found.", system::ILogger::ELL_ERROR, debugName, this, write.binding);
else
m_pool->m_logger.log("Descriptor set (%p) doesn't allow immutable samplers at binding %u, but immutable samplers found.", system::ILogger::ELL_ERROR, this, write.binding);
return asset::IDescriptor::E_TYPE::ET_COUNT;
}
for (uint32_t i=0; i<write.count; ++i)
{
auto* sampler = write.info[i].info.image.sampler.get();
if (!sampler || !sampler->isCompatibleDevicewise(write.dstSet))
{
const char* samplerDebugName = sampler->getDebugName();
if (samplerDebugName && debugName)
m_pool->m_logger.log("Sampler (%s, %p) does not exist or is not device-compatible with descriptor set (%s, %p).", system::ILogger::ELL_ERROR, samplerDebugName, sampler, debugName, write.dstSet);
else
m_pool->m_logger.log("Sampler (%p) does not exist or is not device-compatible with descriptor set (%p).", system::ILogger::ELL_ERROR, sampler, write.dstSet);
return asset::IDescriptor::E_TYPE::ET_COUNT;
}
}
mutableSamplers = getMutableSamplers(write.binding);
if (!mutableSamplers)
{
if (debugName)
m_pool->m_logger.log("Descriptor set (%s, %p) doesn't allow mutable samplers at binding %u.", system::ILogger::ELL_ERROR, debugName, this, write.binding);
else
m_pool->m_logger.log("Descriptor set (%p) doesn't allow mutable samplers at binding %u.", system::ILogger::ELL_ERROR, this, write.binding);
return asset::IDescriptor::E_TYPE::ET_COUNT;
}
}
return descriptorType;
}
void IGPUDescriptorSet::processWrite(const IGPUDescriptorSet::SWriteDescriptorSet& write, const asset::IDescriptor::E_TYPE type)
{
assert(write.dstSet == this);
auto* descriptors = getDescriptors(type,write.binding);
assert(descriptors);
core::smart_refctd_ptr<video::IGPUSampler>* mutableSamplers = nullptr;
if (type==asset::IDescriptor::E_TYPE::ET_COMBINED_IMAGE_SAMPLER && write.info->info.image.sampler)
{
mutableSamplers = getMutableSamplers(write.binding);
assert(mutableSamplers);
}
for (auto j=0; j<write.count; ++j)
{
descriptors[j] = write.info[j].desc;
if (mutableSamplers)
mutableSamplers[j] = write.info[j].info.image.sampler;
}
incrementVersion();
}
void IGPUDescriptorSet::dropDescriptors(const IGPUDescriptorSet::SDropDescriptorSet& drop)
{
assert(drop.dstSet == this);
const auto descriptorType = getBindingType(drop.binding);
auto* dstDescriptors = drop.dstSet->getDescriptors(descriptorType, drop.binding);
auto* dstSamplers = drop.dstSet->getMutableSamplers(drop.binding);
if (dstDescriptors)
for (uint32_t i = 0; i < drop.count; i++)
dstDescriptors[drop.arrayElement + i] = nullptr;
if (dstSamplers)
for (uint32_t i = 0; i < drop.count; i++)
dstSamplers[drop.arrayElement + i] = nullptr;
// we only increment the version to detect UPDATE-AFTER-BIND and automagically invalidate descriptor sets
// so, only if we do the path that writes descriptors, do we want to increment version
if (getOriginDevice()->getEnabledFeatures().nullDescriptor)
{
incrementVersion();
}
}
bool IGPUDescriptorSet::validateCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy) const
{
assert(copy.dstSet == this);
const char* srcDebugName = copy.srcSet->getDebugName();
const char* dstDebugName = copy.dstSet->getDebugName();
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
{
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
auto* srcDescriptors = copy.srcSet->getDescriptors(type, copy.srcBinding);
auto* dstDescriptors = copy.dstSet->getDescriptors(type, copy.dstBinding);
auto* srcSamplers = copy.srcSet->getMutableSamplers(copy.srcBinding);
auto* dstSamplers = copy.dstSet->getMutableSamplers(copy.dstBinding);
if ((!srcDescriptors != !dstDescriptors) || (!srcSamplers != !dstSamplers))
{
if (srcDebugName && dstDebugName)
m_pool->m_logger.log("Incompatible copy from descriptor set (%s, %p) at binding %u to descriptor set (%s, %p) at binding %u.", system::ILogger::ELL_ERROR, srcDebugName, copy.srcSet, copy.srcBinding, dstDebugName, copy.dstSet, copy.dstBinding);
else
m_pool->m_logger.log("Incompatible copy from descriptor set (%p) at binding %u to descriptor set (%p) at binding %u.", system::ILogger::ELL_ERROR, copy.srcSet, copy.srcBinding, copy.dstSet, copy.dstBinding);
return false;
}
}
return true;
}
void IGPUDescriptorSet::processCopy(const IGPUDescriptorSet::SCopyDescriptorSet& copy)
{
assert(copy.dstSet == this);
for (uint32_t t = 0; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
{
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
auto* srcDescriptors = copy.srcSet->getDescriptors(type, copy.srcBinding);
auto* dstDescriptors = copy.dstSet->getDescriptors(type, copy.dstBinding);
assert(!(!srcDescriptors != !dstDescriptors));
auto* srcSamplers = copy.srcSet->getMutableSamplers(copy.srcBinding);
auto* dstSamplers = copy.dstSet->getMutableSamplers(copy.dstBinding);
assert(!(!srcSamplers != !dstSamplers));
if (srcDescriptors && dstDescriptors)
std::copy_n(srcDescriptors, copy.count, dstDescriptors);
if (srcSamplers && dstSamplers)
std::copy_n(srcSamplers, copy.count, dstSamplers);
}
incrementVersion();
}
}