Hash :
93b659f9
Author :
Date :
2025-07-04T12:35:29
Remove PoolAllocator push/pop feature PoolAllocator would manage a stack of memory pools upon client calling push() and pop(). This made the code unnecessarily complicated. The feature was only used with nesting of one, to mark the memory unused after a shader compile. Fix by removing the push/pop feature. Instantiate PoolAllocator in places the previous push() was and uninstantiating instead of previous pop(). This removes the feature where the PoolAllocator would hold on to the allocated memory in order to reuse it. This is seen as a progression: the allocator is held by the compiler, the compiler is held by the shader and each shader typically see only one compile. Thus the free pages were just leaking unused until the shader was destroyed. Instead, destructing the PoolAllocator instead of pop() will donate the memory back to platform/OS, where it is likely more useful. To preserve existing Vulkan behavior, add PoolAllocator::reset() which would mark the memory unused but leave them reserved for the PoolAllocator. Removes UB where PageHeader::nextPage would be accessed after ~PageHeader. Bug: angleproject:429513168 Change-Id: I21e58b46e0887380db3a2cab5ce22f0042cfae9e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6701153 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// AllocatorHelperPool:
// Implements the pool allocator helpers used in the command buffers.
//
#include "libANGLE/renderer/vulkan/AllocatorHelperPool.h"
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
namespace rx
{
namespace vk
{
void DedicatedCommandBlockAllocator::resetAllocator()
{
mAllocator.reset();
}
void DedicatedCommandBlockPool::reset(CommandBufferCommandTracker *commandBufferTracker)
{
mCommandBuffer->clearCommands();
mCurrentWritePointer = nullptr;
mCurrentBytesRemaining = 0;
commandBufferTracker->reset();
}
// Initialize the SecondaryCommandBuffer by setting the allocator it will use
angle::Result DedicatedCommandBlockPool::initialize(DedicatedCommandMemoryAllocator *allocator)
{
ASSERT(allocator);
ASSERT(mCommandBuffer->hasEmptyCommands());
mAllocator = allocator;
allocateNewBlock();
// Set first command to Invalid to start
reinterpret_cast<CommandHeaderIDType &>(*mCurrentWritePointer) = 0;
return angle::Result::Continue;
}
bool DedicatedCommandBlockPool::empty() const
{
return mCommandBuffer->checkEmptyForPoolAlloc();
}
void DedicatedCommandBlockPool::allocateNewBlock(size_t blockSize)
{
ASSERT(mAllocator);
mCurrentWritePointer = mAllocator->fastAllocate(blockSize);
mCurrentBytesRemaining = blockSize;
mCommandBuffer->pushToCommands(mCurrentWritePointer);
}
void DedicatedCommandBlockPool::getMemoryUsageStats(size_t *usedMemoryOut,
size_t *allocatedMemoryOut) const
{
mCommandBuffer->getMemoryUsageStatsForPoolAlloc(kBlockSize, usedMemoryOut, allocatedMemoryOut);
}
} // namespace vk
} // namespace rx