Skip to content

Commit dbf917a

Browse files
committed
In the process of eliminating the AoS SBindings from IDescriptorSetLayout<SamplerType>.
1 parent e55f65e commit dbf917a

File tree

9 files changed

+344
-255
lines changed

9 files changed

+344
-255
lines changed

include/nbl/asset/ICPUDescriptorSet.h

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,31 +171,54 @@ class NBL_API ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetL
171171
}
172172
inline const ICPUDescriptorSetLayout* getLayout() const { return m_layout.get(); }
173173

174-
std::pair<core::SRange<core::smart_refctd_ptr<IDescriptor>>, core::SRange<SDescriptorInfo::SBufferImageInfo>> getDescriptors(const uint32_t binding)
174+
std::pair<core::SRange<core::smart_refctd_ptr<IDescriptor>>, core::SRange<SDescriptorInfo::SBufferImageInfo>> getDescriptors(const uint32_t binding, E_DESCRIPTOR_TYPE type = EDT_COUNT)
175175
{
176-
const auto bindingInfo = std::lower_bound(getLayout()->getBindings().begin(), getLayout()->getBindings().end(), ICPUDescriptorSetLayout::SBinding{binding});
177-
assert(bindingInfo->binding == binding && "binding is not in the descriptor set!");
176+
if (type == EDT_COUNT)
177+
{
178+
for (uint32_t t = 0; t < EDT_COUNT; ++t)
179+
{
180+
const auto possibleType = static_cast<E_DESCRIPTOR_TYPE>(t);
181+
const auto& redirect = getLayout()->getDescriptorRedirect(possibleType);
182+
if (redirect.searchForBinding(binding) != redirect.Invalid)
183+
{
184+
type = possibleType;
185+
break;
186+
}
187+
}
178188

179-
const uint32_t descriptorOffset = getLayout()->getDescriptorOffset(bindingInfo->type, binding);
180-
const uint32_t descriptorCount = bindingInfo->count;
189+
if (type == EDT_COUNT)
190+
return { {nullptr, nullptr}, {nullptr, nullptr} };
191+
}
192+
193+
const auto& redirect = getLayout()->getDescriptorRedirect(type);
194+
const auto bindingNumberIndex = redirect.searchForBinding(binding);
195+
if (bindingNumberIndex == redirect.Invalid)
196+
return { {nullptr, nullptr}, {nullptr, nullptr} };
197+
198+
const auto descriptorOffset = redirect.getStorageOffset(binding, bindingNumberIndex).data;
199+
const auto descriptorCount = redirect.getDescriptorCount(binding, bindingNumberIndex);
181200

182-
auto descriptorsBegin = m_descriptors[bindingInfo->type]->begin() + descriptorOffset;
183-
auto descriptorInfosBegin = m_descriptorInfos[bindingInfo->type]->begin() + descriptorOffset;
201+
auto descriptorsBegin = m_descriptors[type]->begin() + descriptorOffset;
202+
auto descriptorInfosBegin = m_descriptorInfos[type]->begin() + descriptorOffset;
184203

185204
return { {descriptorsBegin, descriptorsBegin+descriptorCount}, {descriptorInfosBegin, descriptorInfosBegin+descriptorCount} };
186205
}
187206

188207
core::SRange<core::smart_refctd_ptr<ICPUSampler>> getMutableSamplers(const uint32_t binding) const
189208
{
190-
const uint32_t offset = getLayout()->getMutableSamplerOffset(binding);
191-
if (offset == ~0u)
209+
const auto& redirect = getLayout()->getSamplerRedirect();
210+
211+
const auto bindingNumberIndex = redirect.searchForBinding(binding);
212+
if (bindingNumberIndex == redirect.Invalid)
192213
return { nullptr, nullptr };
193214

194-
const auto bindingInfo = std::lower_bound(getLayout()->getBindings().begin(), getLayout()->getBindings().end(), ICPUDescriptorSetLayout::SBinding{ binding });
195-
assert(bindingInfo->binding == binding && "binding is not in the descriptor set!");
215+
const auto offset = redirect.getStorageOffset(binding, bindingNumberIndex).data;
216+
assert(offset != redirect.Invalid);
217+
218+
const auto count = redirect.getDescriptorCount(binding, bindingNumberIndex);
196219

197220
auto samplersBegin = m_mutableSamplers->begin() + offset;
198-
return { samplersBegin, samplersBegin + bindingInfo->count };
221+
return { samplersBegin, samplersBegin + count };
199222
}
200223

201224
inline core::smart_refctd_ptr<IDescriptor>* getDescriptorStorage(const E_DESCRIPTOR_TYPE type) const { return m_descriptors[type]->begin(); }

0 commit comments

Comments
 (0)