Skip to content

Commit 3837066

Browse files
committed
Some more cleanups to ICPUDescriptorSet.
1 parent 22284fd commit 3837066

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

include/nbl/asset/ICPUDescriptorSet.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ class NBL_API ICPUDescriptorSet final : public IDescriptorSet<ICPUDescriptorSetL
6868
return 0xdeadbeefull;
6969
}
7070

71-
inline SDescriptorInfo* getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const { return m_descriptorInfos[static_cast<uint32_t>(type)]->begin(); }
71+
inline core::SRange<SDescriptorInfo> getDescriptorInfoStorage(const IDescriptor::E_TYPE type) const
72+
{
73+
if (!m_descriptorInfos[static_cast<uint32_t>(type)])
74+
return { nullptr, nullptr };
75+
else
76+
return { m_descriptorInfos[static_cast<uint32_t>(type)]->begin(), m_descriptorInfos[static_cast<uint32_t>(type)]->end() };
77+
}
7278

73-
core::SRange<SDescriptorInfo> getDescriptorInfos(const uint32_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
79+
core::SRange<SDescriptorInfo> getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type = IDescriptor::E_TYPE::ET_COUNT);
7480

7581
core::smart_refctd_ptr<IAsset> clone(uint32_t _depth = ~0u) const override;
7682

include/nbl/video/utilities/IGPUObjectFromAssetConverter.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,12 +1632,12 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
16321632
for (uint32_t t = 0u; t < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); ++t)
16331633
{
16341634
const auto type = static_cast<asset::IDescriptor::E_TYPE>(t);
1635-
if (!cpuds->getDescriptorInfoStorage(type))
1635+
if (cpuds->getDescriptorInfoStorage(type).empty())
16361636
continue;
16371637

16381638
for (uint32_t d = 0u; d < cpuds->getLayout()->getTotalDescriptorCount(type); ++d)
16391639
{
1640-
auto* info = cpuds->getDescriptorInfoStorage(type) + d;
1640+
auto* info = cpuds->getDescriptorInfoStorage(type).begin() + d;
16411641
auto descriptor = info->desc.get();
16421642
if (isBufferDesc(type))
16431643
{
@@ -1722,13 +1722,16 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17221722
write_it->binding = cpuds->getLayout()->getDescriptorRedirect(type).getBindingNumber(b).data;
17231723
write_it->arrayElement = 0u;
17241724

1725-
uint32_t descriptorCount = cpuds->getLayout()->getDescriptorRedirect(type).getCount(b);
1725+
const uint32_t descriptorCount = cpuds->getLayout()->getDescriptorRedirect(type).getCount(b);
17261726
write_it->count = descriptorCount;
17271727
write_it->descriptorType = type;
17281728
write_it->info = &(*info);
17291729

17301730
const uint32_t offset = cpuds->getLayout()->getDescriptorRedirect(type).getStorageOffset(b).data;
17311731

1732+
// It is better to use getDescriptorInfoStorage over getDescriptorInfos, because the latter does a binary search
1733+
// over the bindings, which is not really required given we have the index of binding number (since we're iterating
1734+
// over all the declared bindings).
17321735
auto descriptorInfos = cpuds->getDescriptorInfoStorage(type);
17331736

17341737
// Iterate through each descriptor in this binding to fill the info structs
@@ -1741,8 +1744,8 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17411744
if (buffer)
17421745
{
17431746
info->desc = core::smart_refctd_ptr<video::IGPUBuffer>(buffer->getBuffer());
1744-
info->info.buffer.offset = descriptorInfos[offset + d].info.buffer.offset + buffer->getOffset();
1745-
info->info.buffer.size = descriptorInfos[offset+d].info.buffer.size;
1747+
info->info.buffer.offset = descriptorInfos.begin()[offset+d].info.buffer.offset + buffer->getOffset();
1748+
info->info.buffer.size = descriptorInfos.begin()[offset+d].info.buffer.size;
17461749
}
17471750
else
17481751
{
@@ -1774,7 +1777,7 @@ inline created_gpu_object_array<asset::ICPUDescriptorSet> IGPUObjectFromAssetCon
17741777
const auto imageFormat = static_cast<asset::ICPUImageView*>(info->desc.get())->getCreationParameters().format;
17751778
info->info.image.imageLayout = isDepthOrStencilFormat(imageFormat) ? asset::IImage::EL_DEPTH_STENCIL_READ_ONLY_OPTIMAL : asset::IImage::EL_SHADER_READ_ONLY_OPTIMAL;
17761779

1777-
if (descriptorInfos[offset + d].info.image.sampler)
1780+
if (descriptorInfos.begin()[offset + d].info.image.sampler)
17781781
info->info.image.sampler = gpuSamplers->operator[](smplrRedirs[si++]);
17791782
}
17801783
}

src/nbl/asset/ICPUDescriptorSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace nbl::asset
44
{
55

6-
core::SRange<ICPUDescriptorSet::SDescriptorInfo> ICPUDescriptorSet::getDescriptorInfos(const uint32_t binding, IDescriptor::E_TYPE type)
6+
core::SRange<ICPUDescriptorSet::SDescriptorInfo> ICPUDescriptorSet::getDescriptorInfos(const ICPUDescriptorSetLayout::CBindingRedirect::binding_number_t binding, IDescriptor::E_TYPE type)
77
{
88
if (type == IDescriptor::E_TYPE::ET_COUNT)
99
{

0 commit comments

Comments
 (0)