Skip to content

Commit 347ff63

Browse files
committed
Work on using descriptor set layout directly
1 parent d10059f commit 347ff63

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

include/nbl/asset/IDescriptorSetLayout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class IDescriptorSetLayout : public virtual core::IReferenceCounted // TODO: tr
118118
return m_stageFlags[index.data];
119119
}
120120

121+
inline core::bitflag<typename SBinding::E_CREATE_FLAGS> getCreateFlags(const storage_range_index_t index) const
122+
{
123+
assert(index.data < m_count);
124+
return m_createFlags[index.data];
125+
}
126+
121127
inline uint32_t getCount(const storage_range_index_t index) const
122128
{
123129
assert(index.data < m_count);

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
2525

2626
protected:
2727
struct SubAllocDescriptorSetRange {
28-
video::IGPUDescriptorSetLayout::SBinding binding;
2928
std::shared_ptr<AddressAllocator> addressAllocator;
3029
std::shared_ptr<ReservedAllocator> reservedAllocator;
3130
size_t reservedSize;
@@ -36,31 +35,64 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
3635
public:
3736
// constructors
3837
template<typename... Args>
39-
inline SubAllocatedDescriptorSet(const std::span<const video::IGPUDescriptorSetLayout::SBinding> bindings,
40-
const value_type maxAllocatableAlignment, Args&&... args)
38+
inline SubAllocatedDescriptorSet(video::IGPUDescriptorSetLayout* layout, const value_type maxAllocatableAlignment, Args&&... args)
4139
{
42-
m_allocatableRanges.reserve(bindings.size());
43-
44-
for (auto& binding : bindings)
40+
for (uint32_t descriptorType = 0; descriptorType < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); descriptorType++)
4541
{
46-
SubAllocDescriptorSetRange range;
47-
range.binding = binding;
48-
range.reservedSize = 0;
49-
// Only bindings with these flags will be allocatable
50-
if (binding.createFlags.hasFlags(core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
51-
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
52-
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT))
42+
auto descType = static_cast<asset::IDescriptor::E_TYPE>(descriptorType);
43+
auto& redirect = layout->getDescriptorRedirect(descType);
44+
45+
for (uint32_t i = 0; i < redirect.getBindingCount(); i++)
5346
{
54-
range.reservedSize = AddressAllocator::reserved_size(maxAllocatableAlignment, static_cast<size_type>(binding.count), args...);
55-
range.reservedAllocator = std::shared_ptr<ReservedAllocator>(new ReservedAllocator());
56-
range.addressAllocator = std::shared_ptr<AddressAllocator>(new AddressAllocator(
57-
range.reservedAllocator->allocate(range.reservedSize, _NBL_SIMD_ALIGNMENT),
58-
static_cast<size_type>(0), 0u, maxAllocatableAlignment, static_cast<size_type>(binding.count), std::forward<Args>(args)...
59-
));
47+
auto binding = redirect.getBinding(i);
48+
auto storageIndex = redirect.findBindingStorageIndex(binding);
49+
50+
auto count = redirect.getCount(storageIndex);
51+
auto flags = redirect.getCreateFlags(storageIndex);
52+
53+
for (uint32_t j = m_allocatableRanges.size(); j < binding.data; j++)
54+
{
55+
m_allocatableRanges.push_back({});
56+
}
57+
58+
SubAllocDescriptorSetRange range;
59+
range.reservedSize = 0;
60+
// Only bindings with these flags will be allocatable
61+
if (flags.hasFlags(core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
62+
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
63+
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT))
64+
{
65+
range.reservedSize = AddressAllocator::reserved_size(maxAllocatableAlignment, static_cast<size_type>(count), args...);
66+
range.reservedAllocator = std::shared_ptr<ReservedAllocator>(new ReservedAllocator());
67+
range.addressAllocator = std::shared_ptr<AddressAllocator>(new AddressAllocator(
68+
range.reservedAllocator->allocate(range.reservedSize, _NBL_SIMD_ALIGNMENT),
69+
static_cast<size_type>(0), 0u, maxAllocatableAlignment, static_cast<size_type>(count), std::forward<Args>(args)...
70+
));
71+
}
72+
m_allocatableRanges.insert(m_allocatableRanges.begin() + binding.data, range);
6073
}
61-
m_allocatableRanges.push_back(range);
6274
}
6375

76+
// for (auto& binding : bindings)
77+
// {
78+
// SubAllocDescriptorSetRange range;
79+
// range.binding = binding;
80+
// range.reservedSize = 0;
81+
// // Only bindings with these flags will be allocatable
82+
// if (binding.createFlags.hasFlags(core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
83+
// | IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
84+
// | IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT))
85+
// {
86+
// range.reservedSize = AddressAllocator::reserved_size(maxAllocatableAlignment, static_cast<size_type>(binding.count), args...);
87+
// range.reservedAllocator = std::shared_ptr<ReservedAllocator>(new ReservedAllocator());
88+
// range.addressAllocator = std::shared_ptr<AddressAllocator>(new AddressAllocator(
89+
// range.reservedAllocator->allocate(range.reservedSize, _NBL_SIMD_ALIGNMENT),
90+
// static_cast<size_type>(0), 0u, maxAllocatableAlignment, static_cast<size_type>(binding.count), std::forward<Args>(args)...
91+
// ));
92+
// }
93+
// m_allocatableRanges.push_back(range);
94+
// }
95+
6496
}
6597

6698
~SubAllocatedDescriptorSet()

0 commit comments

Comments
 (0)