Skip to content

Commit 6c6046c

Browse files
committed
Use map
1 parent 28611be commit 6c6046c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
2929
std::shared_ptr<ReservedAllocator> reservedAllocator;
3030
size_t reservedSize;
3131
};
32-
std::vector<SubAllocDescriptorSetRange> m_allocatableRanges = {};
32+
std::unordered_map<uint32_t, SubAllocDescriptorSetRange> m_allocatableRanges = {};
3333

3434

3535
public:
@@ -50,26 +50,20 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
5050
auto count = redirect.getCount(storageIndex);
5151
auto flags = redirect.getCreateFlags(storageIndex);
5252

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;
6053
// Only bindings with these flags will be allocatable
6154
if (flags.hasFlags(core::bitflag(IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_AFTER_BIND_BIT)
6255
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_UPDATE_UNUSED_WHILE_PENDING_BIT
6356
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT))
6457
{
58+
SubAllocDescriptorSetRange range;
6559
range.reservedSize = AddressAllocator::reserved_size(maxAllocatableAlignment, static_cast<size_type>(count), args...);
6660
range.reservedAllocator = std::shared_ptr<ReservedAllocator>(new ReservedAllocator());
6761
range.addressAllocator = std::shared_ptr<AddressAllocator>(new AddressAllocator(
6862
range.reservedAllocator->allocate(range.reservedSize, _NBL_SIMD_ALIGNMENT),
6963
static_cast<size_type>(0), 0u, maxAllocatableAlignment, static_cast<size_type>(count), std::forward<Args>(args)...
7064
));
65+
m_allocatableRanges.emplace(binding.data, range);
7166
}
72-
m_allocatableRanges.insert(m_allocatableRanges.begin() + binding.data, range);
7367
}
7468
}
7569
}
@@ -91,12 +85,16 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
9185
uint32_t getLayoutBindingCount() { return m_allocatableRanges.size(); }
9286

9387
// whether that binding index can be sub-allocated
94-
bool isBindingAllocatable(uint32_t binding) { return m_allocatableRanges[binding].reservedSize != 0; }
88+
bool isBindingAllocatable(uint32_t binding)
89+
{
90+
return m_allocatableRanges.find(binding) != m_allocatableRanges.end();
91+
}
9592

9693
AddressAllocator& getBindingAllocator(uint32_t binding)
9794
{
98-
assert(isBindingAllocatable(binding)); // Check if this binding has an allocator
99-
return *m_allocatableRanges[binding].addressAllocator;
95+
auto range = m_allocatableRanges.find(binding);
96+
assert(range != m_allocatableRanges.end());// Check if this binding has an allocator
97+
return *range->second.addressAllocator;
10098
}
10199

102100
// main methods

0 commit comments

Comments
 (0)