Skip to content

Commit 58c4e90

Browse files
committed
Add writing of descriptors on the allocate method
1 parent 4fd4b8f commit 58c4e90

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
8989
};
9090
std::map<uint32_t, SubAllocDescriptorSetRange> m_allocatableRanges = {};
9191
core::smart_refctd_ptr<video::IGPUDescriptorSet> m_descriptorSet;
92+
core::smart_refctd_ptr<video::ILogicalDevice> m_logicalDevice;
9293

9394
#ifdef _NBL_DEBUG
9495
std::recursive_mutex stAccessVerfier;
@@ -100,7 +101,8 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
100101
public:
101102

102103
// constructors
103-
inline SubAllocatedDescriptorSet(core::smart_refctd_ptr<video::IGPUDescriptorSet>&& descriptorSet)
104+
inline SubAllocatedDescriptorSet(core::smart_refctd_ptr<video::IGPUDescriptorSet>&& descriptorSet,
105+
core::smart_refctd_ptr<video::ILogicalDevice>&& logicalDevice) : m_logicalDevice(std::move(logicalDevice))
104106
{
105107
auto layout = descriptorSet->getLayout();
106108
for (uint32_t descriptorType = 0; descriptorType < static_cast<uint32_t>(asset::IDescriptor::E_TYPE::ET_COUNT); descriptorType++)
@@ -174,20 +176,46 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
174176
bool stAccessVerifyDebugGuard() { return false; }
175177
#endif
176178

179+
video::IGPUDescriptorSet* getDescriptorSet() { return m_descriptorSet.get(); }
180+
177181
//! Warning `outAddresses` needs to be primed with `invalid_value` values, otherwise no allocation happens for elements not equal to `invalid_value`
178-
inline void multi_allocate(uint32_t binding, size_type count, value_type* outAddresses)
182+
inline void multi_allocate(uint32_t binding, size_type count, video::IGPUDescriptorSet::SDescriptorInfo* descriptors, value_type* outAddresses)
179183
{
180184
auto debugGuard = stAccessVerifyDebugGuard();
181185

182186
auto allocator = getBindingAllocator(binding);
187+
188+
std::vector<video::IGPUDescriptorSet::SWriteDescriptorSet> writes;
189+
std::vector<video::IGPUDescriptorSet::SDescriptorInfo> infos;
190+
writes.reserve(count);
191+
infos.reserve(count);
192+
183193
for (size_type i=0; i<count; i++)
184194
{
185195
if (outAddresses[i]!=AddressAllocator::invalid_address)
186196
continue;
187197

188198
outAddresses[i] = allocator->alloc_addr(1,1);
189199
// TODO: should also write something to the descriptor set (or probably leave that to the caller?)
200+
201+
auto& descriptor = descriptors[i];
202+
203+
video::IGPUDescriptorSet::SWriteDescriptorSet write;
204+
{
205+
write.dstSet = m_descriptorSet.get();
206+
write.binding = binding;
207+
write.arrayElement = outAddresses[i];
208+
write.count = 1u;
209+
// descriptors could be a const pointer, but the problem is that this pointer in
210+
// SWriteDescriptorSet.info isn't const
211+
// can we change it?
212+
write.info = &descriptor;
213+
}
214+
infos.push_back(descriptor);
215+
writes.push_back(write);
190216
}
217+
218+
m_logicalDevice->updateDescriptorSets(writes, {});
191219
}
192220
inline void multi_deallocate(uint32_t binding, size_type count, const size_type* addr)
193221
{

0 commit comments

Comments
 (0)