Skip to content

Commit d10059f

Browse files
committed
Add some reusable binding API
1 parent cc54740 commit d10059f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
7676
}
7777
}
7878

79+
// amount of bindings in the descriptor set layout used
80+
uint32_t getLayoutBindingCount() { return m_allocatableRanges.size(); }
81+
82+
// whether that binding index can be sub-allocated
83+
bool isBindingAllocatable(uint32_t binding) { return m_allocatableRanges[binding].reservedSize != 0; }
84+
85+
AddressAllocator& getBindingAllocator(uint32_t binding)
86+
{
87+
assert(isBindingAllocatable(binding)); // Check if this binding has an allocator
88+
return *m_allocatableRanges[binding].addressAllocator;
89+
}
90+
7991
// main methods
8092

8193
//! Warning `outAddresses` needs to be primed with `invalid_value` values, otherwise no allocation happens for elements not equal to `invalid_value`
8294
template<typename... Args>
8395
inline void multi_allocate(uint32_t binding, uint32_t count, value_type* outAddresses, const size_type* sizes, const Args&... args)
8496
{
85-
auto& range = m_allocatableRanges[binding];
86-
assert(range.reservedSize); // Check if this binding has an allocator
87-
core::address_allocator_traits<AddressAllocator>::multi_alloc_addr(*range.addressAllocator, count, outAddresses, sizes, 1, args...);
97+
core::address_allocator_traits<AddressAllocator>::multi_alloc_addr(getBindingAllocator(binding), count, outAddresses, sizes, 1, args...);
8898
}
8999
inline void multi_deallocate(uint32_t binding, uint32_t count, const size_type* addr, const size_type* sizes)
90100
{
91101
auto& range = m_allocatableRanges[binding];
92102
assert(range.reservedSize); // Check if this binding has an allocator
93-
core::address_allocator_traits<AddressAllocator>::multi_free_addr(*range.addressAllocator, count, addr, sizes);
103+
core::address_allocator_traits<AddressAllocator>::multi_free_addr(getBindingAllocator(binding), count, addr, sizes);
94104
}
95105
};
96106

0 commit comments

Comments
 (0)