buffer update opt: Skip releaseFreeSlots when no frees are pending (#9437)
This commit is contained in:
@@ -142,7 +142,11 @@ void BufferAllocator::retire(AllocationId id) {
|
||||
InternalSlotNode* targetNode = getNodeById(id);
|
||||
assert_invariant(targetNode != nullptr);
|
||||
|
||||
targetNode->slot.isAllocated = false;
|
||||
Slot& slot = targetNode->slot;
|
||||
slot.isAllocated = false;
|
||||
if (slot.gpuUseCount == 0) {
|
||||
mHasPendingFrees = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferAllocator::acquireGpu(AllocationId id) {
|
||||
@@ -157,10 +161,18 @@ void BufferAllocator::releaseGpu(AllocationId id) {
|
||||
assert_invariant(targetNode != nullptr);
|
||||
assert_invariant(targetNode->slot.gpuUseCount > 0);
|
||||
|
||||
targetNode->slot.gpuUseCount--;
|
||||
Slot& slot = targetNode->slot;
|
||||
slot.gpuUseCount--;
|
||||
if (slot.gpuUseCount == 0 && !slot.isAllocated) {
|
||||
mHasPendingFrees = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferAllocator::releaseFreeSlots() {
|
||||
if (!mHasPendingFrees) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto curr = mSlotPool.begin();
|
||||
while (curr != mSlotPool.end()) {
|
||||
if (!curr->slot.isFree()) {
|
||||
@@ -199,6 +211,7 @@ void BufferAllocator::releaseFreeSlots() {
|
||||
|
||||
curr = next;
|
||||
}
|
||||
mHasPendingFrees = false;
|
||||
}
|
||||
|
||||
BufferAllocator::allocation_size_t BufferAllocator::getTotalSize() const noexcept {
|
||||
|
||||
@@ -113,8 +113,9 @@ private:
|
||||
|
||||
[[nodiscard]] InternalSlotNode* getNodeById(AllocationId id) const noexcept;
|
||||
|
||||
bool mHasPendingFrees = false;
|
||||
allocation_size_t mTotalSize;
|
||||
const allocation_size_t mSlotSize; // Size of a single slot in bytes.
|
||||
const allocation_size_t mSlotSize; // Size of a single slot in bytes
|
||||
std::list<InternalSlotNode> mSlotPool; // All slots, including both allocated and freed
|
||||
std::multimap</*slot size*/allocation_size_t, InternalSlotNode*> mFreeList;
|
||||
std::unordered_map</*slot offset*/allocation_size_t, InternalSlotNode*> mOffsetMap;
|
||||
|
||||
Reference in New Issue
Block a user