Skip to content

Commit 190067a

Browse files
committed
PR reviews
1 parent 6c6046c commit 190067a

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

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

34+
#ifdef _NBL_DEBUG
35+
std::recursive_mutex stAccessVerfier;
36+
#endif // _NBL_DEBUG
37+
38+
constexpr static inline uint32_t MaxDescriptorSetAllocationAlignment = 64u*1024u; // if you need larger alignments then you're not right in the head
39+
constexpr static inline uint32_t MinDescriptorSetAllocationSize = 1u;
3440

3541
public:
3642
// constructors
3743
template<typename... Args>
38-
inline SubAllocatedDescriptorSet(video::IGPUDescriptorSetLayout* layout, const value_type maxAllocatableAlignment, Args&&... args)
44+
inline SubAllocatedDescriptorSet(video::IGPUDescriptorSetLayout* layout)
3945
{
4046
for (uint32_t descriptorType = 0; descriptorType < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); descriptorType++)
4147
{
@@ -56,11 +62,12 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
5662
| IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT))
5763
{
5864
SubAllocDescriptorSetRange range;
59-
range.reservedSize = AddressAllocator::reserved_size(maxAllocatableAlignment, static_cast<size_type>(count), args...);
65+
range.reservedSize = AddressAllocator::reserved_size(MaxDescriptorSetAllocationAlignment, static_cast<size_type>(count), MinDescriptorSetAllocationSize);
6066
range.reservedAllocator = std::shared_ptr<ReservedAllocator>(new ReservedAllocator());
6167
range.addressAllocator = std::shared_ptr<AddressAllocator>(new AddressAllocator(
6268
range.reservedAllocator->allocate(range.reservedSize, _NBL_SIMD_ALIGNMENT),
63-
static_cast<size_type>(0), 0u, maxAllocatableAlignment, static_cast<size_type>(count), std::forward<Args>(args)...
69+
static_cast<size_type>(0), 0u, MaxDescriptorSetAllocationAlignment, static_cast<size_type>(count),
70+
MinDescriptorSetAllocationSize
6471
));
6572
m_allocatableRanges.emplace(binding.data, range);
6673
}
@@ -75,51 +82,55 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
7582
auto& range = m_allocatableRanges[i];
7683
if (range.reservedSize == 0)
7784
continue;
78-
7985
auto ptr = reinterpret_cast<const uint8_t*>(core::address_allocator_traits<AddressAllocator>::getReservedSpacePtr(*range.addressAllocator));
86+
range.addressAllocator->~PoolAddressAllocator();
8087
range.reservedAllocator->deallocate(const_cast<uint8_t*>(ptr), range.reservedSize);
8188
}
8289
}
8390

84-
// amount of bindings in the descriptor set layout used
85-
uint32_t getLayoutBindingCount() { return m_allocatableRanges.size(); }
86-
8791
// whether that binding index can be sub-allocated
88-
bool isBindingAllocatable(uint32_t binding)
89-
{
90-
return m_allocatableRanges.find(binding) != m_allocatableRanges.end();
91-
}
92+
bool isBindingAllocatable(uint32_t binding) { return m_allocatableRanges.find(binding) != m_allocatableRanges.end(); }
9293

93-
AddressAllocator& getBindingAllocator(uint32_t binding)
94+
AddressAllocator* getBindingAllocator(uint32_t binding)
9495
{
9596
auto range = m_allocatableRanges.find(binding);
9697
assert(range != m_allocatableRanges.end());// Check if this binding has an allocator
97-
return *range->second.addressAllocator;
98+
return range->second.addressAllocator.get();
9899
}
99100

100101
// main methods
101102

102103
//! Warning `outAddresses` needs to be primed with `invalid_value` values, otherwise no allocation happens for elements not equal to `invalid_value`
103104
inline void multi_allocate(uint32_t binding, uint32_t count, value_type* outAddresses)
104105
{
105-
auto& allocator = getBindingAllocator(binding);
106+
#ifdef _NBL_DEBUG
107+
std::unique_lock<std::recursive_mutex> tLock(stAccessVerfier,std::try_to_lock_t());
108+
assert(tLock.owns_lock());
109+
#endif // _NBL_DEBUG
110+
111+
auto allocator = getBindingAllocator(binding);
106112
for (uint32_t i=0; i<count; i++)
107113
{
108114
if (outAddresses[i]!=AddressAllocator::invalid_address)
109115
continue;
110116

111-
outAddresses[i] = allocator.alloc_addr(1,1);
117+
outAddresses[i] = allocator->alloc_addr(1,1);
112118
}
113119
}
114120
inline void multi_deallocate(uint32_t binding, uint32_t count, const size_type* addr)
115121
{
116-
auto& allocator = getBindingAllocator(binding);
122+
#ifdef _NBL_DEBUG
123+
std::unique_lock<std::recursive_mutex> tLock(stAccessVerfier,std::try_to_lock_t());
124+
assert(tLock.owns_lock());
125+
#endif // _NBL_DEBUG
126+
127+
auto allocator = getBindingAllocator(binding);
117128
for (uint32_t i=0; i<count; i++)
118129
{
119130
if (addr[i]==AddressAllocator::invalid_address)
120131
continue;
121132

122-
allocator.free_addr(addr[i],1);
133+
allocator->free_addr(addr[i],1);
123134
}
124135
}
125136
};

0 commit comments

Comments
 (0)