Skip to content

Commit 894a47c

Browse files
committed
Keep descriptor writes outside the allocate function
1 parent b326ca7 commit 894a47c

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

include/nbl/video/alloc/SubAllocatedDescriptorSet.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
180180
video::IGPUDescriptorSet* getDescriptorSet() { return m_descriptorSet.get(); }
181181

182182
//! Warning `outAddresses` needs to be primed with `invalid_value` values, otherwise no allocation happens for elements not equal to `invalid_value`
183-
inline size_type try_multi_allocate(uint32_t binding, size_type count, video::IGPUDescriptorSet::SDescriptorInfo* descriptors, value_type* outAddresses)
183+
inline size_type try_multi_allocate(
184+
uint32_t binding,
185+
size_type count,
186+
video::IGPUDescriptorSet::SDescriptorInfo* descriptors,
187+
video::IGPUDescriptorSet::SWriteDescriptorSet* outDescriptorWrites,
188+
value_type* outAddresses
189+
)
184190
{
185191
auto debugGuard = stAccessVerifyDebugGuard();
186192

@@ -217,17 +223,21 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
217223
// can we change it?
218224
write.info = &descriptor;
219225
}
220-
infos.push_back(descriptor);
221-
writes.push_back(write);
226+
outDescriptorWrites[i] = write;
222227
}
223228

224-
// TODO: this goes outside
225-
m_logicalDevice->updateDescriptorSets(writes, {});
226229
return unallocatedSize;
227230
}
228231

229232
template<class Clock=typename std::chrono::steady_clock>
230-
inline size_type multi_allocate(const std::chrono::time_point<Clock>& maxWaitPoint, uint32_t binding, size_type count, video::IGPUDescriptorSet::SDescriptorInfo* descriptors, value_type* outAddresses) noexcept
233+
inline size_type multi_allocate(
234+
const std::chrono::time_point<Clock>& maxWaitPoint,
235+
uint32_t binding,
236+
size_type count,
237+
video::IGPUDescriptorSet::SDescriptorInfo* descriptors,
238+
video::IGPUDescriptorSet::SWriteDescriptorSet* outDescriptorWrites,
239+
value_type* outAddresses
240+
) noexcept
231241
{
232242
auto debugGuard = stAccessVerifyDebugGuard();
233243

@@ -239,7 +249,7 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
239249
auto& eventHandler = range->second.eventHandler;
240250

241251
// try allocate once
242-
size_type unallocatedSize = try_multi_allocate(binding, count, descriptors, outAddresses);
252+
size_type unallocatedSize = try_multi_allocate(binding, count, descriptors, outDescriptorWrites, outAddresses);
243253
if (!unallocatedSize)
244254
return 0u;
245255

@@ -248,22 +258,34 @@ class SubAllocatedDescriptorSet : public core::IReferenceCounted
248258
{
249259
eventHandler.wait(maxWaitPoint, unallocatedSize);
250260

251-
unallocatedSize = try_multi_allocate(binding, unallocatedSize, &descriptors[count - unallocatedSize], &outAddresses[count - unallocatedSize]);
261+
unallocatedSize = try_multi_allocate(
262+
binding,
263+
unallocatedSize,
264+
&descriptors[count - unallocatedSize],
265+
&outDescriptorWrites[count - unallocatedSize],
266+
&outAddresses[count - unallocatedSize]
267+
);
252268
if (!unallocatedSize)
253269
return 0u;
254270
} while(Clock::now()<maxWaitPoint);
255271

256272
return unallocatedSize;
257273
}
258274

259-
inline size_type multi_allocate(uint32_t binding, size_type count, video::IGPUDescriptorSet::SDescriptorInfo* descriptors, value_type* outAddresses) noexcept
275+
inline size_type multi_allocate(
276+
uint32_t binding,
277+
size_type count,
278+
video::IGPUDescriptorSet::SDescriptorInfo* descriptors,
279+
video::IGPUDescriptorSet::SWriteDescriptorSet* outDescriptorWrites,
280+
value_type* outAddresses
281+
) noexcept
260282
{
261283
auto range = m_allocatableRanges.find(binding);
262284
// Check if this binding has an allocator
263285
if (range == m_allocatableRanges.end())
264286
return count;
265287

266-
return multi_allocate(TimelineEventHandlerBase::default_wait(), binding, count, descriptors, outAddresses);
288+
return multi_allocate(TimelineEventHandlerBase::default_wait(), binding, count, descriptors, outDescriptorWrites, outAddresses);
267289
}
268290

269291
inline void multi_deallocate(uint32_t binding, size_type count, const size_type* addr)

0 commit comments

Comments
 (0)