Skip to content

Commit 1e8171c

Browse files
committed
try to fit as much as possible even when fail to allocate, go down by half each time
1 parent 6f4ef5b commit 1e8171c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/nbl/ext/DebugDraw/CDrawAABB.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,22 @@ namespace nbl::ext::debug_draw
147147
uint32_t remainingInstancesBytes = numInstances * sizeof(InstanceData);
148148
while (srcIt != aabbInstances.end())
149149
{
150-
uint32_t blockByteSize = hlsl::min<uint32_t>(streaming->max_size(), core::alignUp(remainingInstancesBytes, MaxAlignment));
150+
uint32_t blockByteSize = core::alignUp(remainingInstancesBytes, MaxAlignment);
151151
bool allocated = false;
152152

153153
offset_t blockOffset = SCachedCreationParameters::streaming_buffer_t::invalid_value;
154-
for (uint32_t t = 0; t < 2; t++)
154+
const uint32_t smallestAlloc = hlsl::max<uint32_t>(core::alignUp(sizeof(InstanceData), MaxAlignment), streaming->getAddressAllocator().min_size());
155+
while (blockByteSize >= smallestAlloc)
155156
{
156157
std::chrono::steady_clock::time_point waitTill = std::chrono::steady_clock::now() + std::chrono::milliseconds(1u);
157158
if (streaming->multi_allocate(waitTill, 1, &blockOffset, &blockByteSize, &MaxAlignment) == 0u)
158159
{
159160
allocated = true;
160161
break;
161162
}
163+
162164
streaming->cull_frees();
165+
blockByteSize >>= 1;
163166
}
164167

165168
if (!allocated)

0 commit comments

Comments
 (0)